// Reload histograms int dmRestoreHistograms(TObject *tdm,TList *keys) { TDecayMode *dm = (TDecayMode*)tdm; dm->histograms = new TObjArray(); TIter nexthist(keys); TKey *key_hist=0; char name[129]; while(key_hist=(TKey*)nexthist()) { int cycle=-10; if(strcmp(key_hist->GetClassName(),"TH1D")==0) { TH1D *h=0; int cycleh=key_hist->GetCycle(); if(cycleh<cycle) { cout<<"Skipping..."<<endl; continue; } if(cycle<cycleh) cycle=cycleh; h=(TH1D*)key_hist->ReadObj(); if(!h) { cout<<"Cannot read: "<<key_hist->GetName()<<endl; exit(-2); } TH1D *h1=new TH1D(*h); dm->histograms->Add(h1); } } return 0; }
// Merge same modes int dmMerge(TObject *a1, TObject *b1,TList *keys) { TDecayMode *a=(TDecayMode*)a1; TDecayMode *b=(TDecayMode*)b1; TIter nexthist(keys); TKey *key_hist=0; while(key_hist=(TKey*)nexthist()) { int cycle=-10; if(strcmp(key_hist->GetClassName(),"TH1D")==0) { TH1D *h=0; int cycleh=key_hist->GetCycle(); if(cycleh<cycle) { cout<<"Skipping..."<<endl; continue; } if(cycle<cycleh) cycle=cycleh; h=(TH1D*)key_hist->ReadObj(); if(!h) { cout<<"Cannot read: "<<key_hist->GetName()<<endl; exit(-2); } TH1D *eh = (TH1D*) a->histograms->FindObject(h->GetName()); if(!eh) continue; if(eh->GetNbinsX()!=h->GetNbinsX() || eh->GetXaxis()->GetXmax()!=h->GetXaxis()->GetXmax()) return -1; eh->Add(h); } } a->SetNEntries(a->GetNEntries()+b->GetNEntries()); a->SetSumw(a->GetSumw()+b->GetSumw()); a->SetSumw2(a->GetSumw2()+b->GetSumw2()); return 0; }
// Save to .root file void SaveOutput(TString name,TList &list) { TFile *out = new TFile(name,"RECREATE"); TDirectory *pwd = gDirectory; for(int i=0;i<list.GetSize();i++) { TDecayMode *dm = list.At(i); TDirectory *subdir = out->mkdir(dm->GetName()); subdir->cd(); subdir->Append(dm); subdir->Append(dm->histograms); pwd->cd(); } if(!genDesc) cout<<"WARNING! No Generator description in files!"<<endl; else out->Append(genDesc); if(userHisto) { TDecayMode *uh = (TDecayMode*) userHisto; cout<<"INFO: Appending user histograms"<<endl; TDirectoryFile *histos = out->mkdir("USER_HISTOGRAMS"); TIter nexthist(uh->histograms); TKey *key_hist=0; TH1D *h; while(h=(TH1D*)nexthist()) histos->Append(h); } out->Write(); out->Close(); delete out; }
int findHistInt2 (double t) { int j, jn; if ( t >= histtime[indexhist]) return(indexhist); if ( t < histtime[starthist]) error("illegal input in lagvalue - lag, %g, too large, at time = %g\n", t, histtime[indexhist]); /* find embracing time starting from beginning */ j = starthist; jn = nexthist(j); while (histtime[jn]<t) { j = jn; jn = nexthist(j); } return(j); }
void updatehist(double t, double *y, double *dY, double *rwork, int *iwork) { int j, ii; double ss[2]; indexhist = nexthist(indexhist); ii = indexhist * offset; /* interpolMethod = Hermite */ if (interpolMethod == 1) { for (j = 0; j < n_eq; j++) histvar [ii + j ] = y[j]; /* higherOrder, livermores */ } else if (interpolMethod == 2) { histord[indexhist] = iwork[lo]; for (j = 0; j < offset; j++) histvar[ii + j] = rwork[lyh + j]; histhh [indexhist] = rwork[lhh]; /* higherOrder, radau */ } else if (interpolMethod == 3) { for (j = 0; j < 4 * n_eq; j++) histvar[ii + j] = rwork[j]; F77_CALL(getconra) (ss); for (j = 0; j < 2; j++) histvar[ii + 4*n_eq + j] = ss[j]; } ii = indexhist * n_eq; for (j = 0; j < n_eq; j++) histdvar[ii + j] = dY[j]; histtime [indexhist] = t; if (endreached == 1) /* starthist stays 0 until end reached... */ starthist = nexthist(starthist); }
double past(int i, int interval, double t, int val) /* finds past values (val=1) or past derivatives (val=2)*/ { int j, jn, nq, ip; double t0, t1, y0, y1, dy0, dy1, res, hh; double *Yh; /* error checking */ if ( i >= n_eq) error("illegal input in lagvalue - var nr too high, %i", i+1); /* equal to current value... */ if ( interval == indexhist && t == histtime[interval]) { if (val == 1) res = histvar [interval * offset + i ]; else res = histdvar [interval * offset + i ]; /* within last interval - for now: just extrapolate last value */ } else if ( interval == indexhist && interpolMethod == 1) { if (val == 1) { t0 = histtime[interval]; y0 = histvar [interval * offset + i ]; dy0 = histdvar [interval * n_eq + i ]; res = y0 + dy0*(t-t0); } else res = histdvar [interval * n_eq + i ]; /* Hermite interpolation */ } else if (interpolMethod == 1) { j = interval; jn = nexthist(j); t0 = histtime[j]; t1 = histtime[jn]; y0 = histvar [j * n_eq + i ]; y1 = histvar [jn * n_eq + i ]; dy0 = histdvar [j * n_eq + i ]; dy1 = histdvar [jn * n_eq + i ]; if (val == 1) res = Hermite (t0, t1, y0, y1, dy0, dy1, t); else res = dHermite (t0, t1, y0, y1, dy0, dy1, t); /* dense interpolation - livermore solvers */ } else if (interpolMethod == 2) { j = interval; jn = nexthist(j); t0 = histtime[j]; t1 = histtime[jn]; nq = histord [j]; if (nq == 0) { y0 = histvar [j * offset + i ]; y1 = histvar [jn * offset + i ]; dy0 = histdvar [j * n_eq + i ]; dy1 = histdvar [jn * n_eq + i ]; if (val == 1) res = Hermite (t0, t1, y0, y1, dy0, dy1, t); else res = dHermite (t0, t1, y0, y1, dy0, dy1, t); } else { Yh = &histvar [j * offset]; hh = histhh[j]; res = interpolate(i+1, val-1, t0, hh, t, Yh, nq); } /* dense interpolation - radau - gets all values (i not used) */ } else { // if (val == 2) // error("radau interpol = 2 does not work for lagderiv"); j = interval; Yh = &histvar [j * offset]; histsave = &histvar [j * offset + 4*n_eq]; ip = i+1; F77_CALL(contr5alone) (&ip, &n_eq, &t, Yh, &offset, histsave, &res, &val); } return(res); }