// C/C++ headers // #include #include #include #include #include // // ROOT headers // #include #include #include #include #include #include #include #include #include #include #include #include #include #include // // RunInfo header // #include #include #include #include "PrimaryInfo.h" using namespace std; using TMath::Pi; //This program generate trajectories, which are going in acceptance void Usage (); Bool_t IsInside(Trajectory *t, Double_t fiducial, float *xmin, float *xmax, float *ymin, float *ymax){ for(Int_t i = 0; inpoint; i++){ if( !(((xmin[i]+fiducial)x[i])*(t->x[i]<(xmax[i]-fiducial))) ) return kFALSE; if( !(((ymin[i]+fiducial)y[i])*(t->y[i]<(ymax[i]-fiducial))) ) return kFALSE; //cout<<"XMIN:"<Dump(); return kTRUE; } void DoHistogramFromGraph(TGraph* g, TH1F* htemplate, Double_t factor){ //TH1F* hout = (TH1F*) htemplate->Clone(name); htemplate->Reset(); int n = htemplate->GetNbinsX(); for(int bin=1; bin<=n; bin++) { htemplate->SetBinContent(bin, g->Eval(htemplate->GetBinCenter(bin))*factor); Double_t *gx = g->GetX(); int p = 0; Double_t x = htemplate->GetBinCenter(bin); for(p=1; pGetN(); p++) if((gx[p-1] <= x) && (gx[p] > x)) break; Double_t gey = g->GetErrorY(p-1)*factor; //cout<<"gx: "<< hout->GetBinCenter(bin)<<"gy: "<GetBinContent(bin)<SetBinError(bin, gey); //cout<<"gx: "<< htemplate->GetBinCenter(bin)<<"gy: "<GetBinContent(bin)<GetXaxis(); int bins = axis->GetNbins(); Axis_t xmin = axis->GetXmin(); Axis_t xmax = axis->GetXmax(); if (xmin==0) { xmin = 1e-6; cout<<"Warning: low edge of histogram set from 0 to 1e-6"<Set(bins, new_bins); delete new_bins; } int main(int argc, char * argv[] ){ TStopwatch timer; timer.Start(); TString DataPATH = gSystem->Getenv("PWD"); TString inputfilename, outputfilename; TFile* rfin = 0; TFile* rfout = 0; TTree* primaries = 0; PrimaryInfo *p = 0; Double_t fiducial, Z, Rmin, Rmax, R; Int_t PDG; fiducial=Z=Rmin=Rmax=R=0.; Int_t nev; TF1 *frigflat = 0; TH1F * flux = new TH1F("flux", "flux", 2000, 0.4, 1000.); enum mode {SPECTRA, FLATBIN, SINGLEPOINT}; mode md; TString innf(argv[5]); switch(argc){ case 7: if(innf.Contains(".root")) md = SPECTRA; else md = SINGLEPOINT; break; case 8: md = FLATBIN; break; default: Usage(); return 0; break; } nev = atoi(argv[1]); Z = atof(argv[2]); PDG = atoi(argv[3]); fiducial = atof(argv[4]); TSystemDirectory *workdir = 0; switch(md){ case SPECTRA: inputfilename = TString(argv[5]); outputfilename = TString(argv[6]); workdir=new TSystemDirectory("workdir",DataPATH); rfin = new TFile(inputfilename); if (rfin){ cout<<"Generating spectra from file: "<Get("outlist"); //flux = (TH1F*)outlist->At(5); //CHANGE THIS IF NEED TGraphAsymmErrors *gr1 = (TGraphAsymmErrors*)rfin->Get("gflux"); //TH1F * temp = new TH1F("template", "template", 40, 0.4, 250.); BinLogX(flux); DoHistogramFromGraph(gr1, flux, 100000.); rfin->Close(); //cout<<"test"<GetBinCenter(10)<GetBranch("PRIM")) primaries ->Branch("PRIM","PrimaryInfo", &p,32000,99); else primaries->GetBranch("PRIM")->SetAddress(&p); //Loading field, Initialization TRandom3 *ran = new TRandom3(0); TF1 *ftheta = new TF1("ftheta","sin(x)*cos(x)",0.,acos(-1.)/4.); ftheta->SetNpx(99999); cout<<"Load Magnetic Field... "<LoadField(getenv("PAM_FIELD")); track->SetTrackingMode(0); cout<<"Magnetic Field Loaded. "<Uniform(XMINGEN, XMAXGEN); y = ran->Uniform(YMINGEN, YMAXGEN); z = ZINP-ZCAL-CALS3-ZSPEBP-HORMG; theta = ftheta->GetRandom(); phi = ran->Uniform(0.,2.*acos(-1.)); switch(md){ case SPECTRA: mom = Z*flux->GetRandom(); break; case FLATBIN: mom = Z*frigflat->GetRandom(); break; case SINGLEPOINT: mom = Z*R; break; default: break; } al[0] = x; al[1] = y; al[2] = sin(theta); al[3] = phi; al[4] = Z/mom; t->DoTrack(al, z); if(IsInside(t,fiducial, xmin, xmax, ymin, ymax)){ p->X0 = x; p->Y0 = y; p->Z0 = ZINP; p->Theta = theta; p->Phi = phi; p->P0 = mom; p->PDG=PDG; //He-4 primaries->Fill(); goodev++; } totev++; if( ((totev%10000)==0) || (goodev==nev) ) cout<<"-> "<Write(); if(md==SPECTRA) flux->Write(); rfout->Close(); Double_t gf = Double_t(goodev)/Double_t(totev)*(XMAXGEN-XMINGEN)*(YMAXGEN-YMINGEN)*TMath::Pi()/2.; Double_t err_gf = (Double_t)1./TMath::Sqrt(goodev)*gf; cout<<"GF="<