int main (int argc, char** argv) { gRandom->SetSeed (time (0)) ; TF1 pol2pie ("pol2pie", "-1*(x-5)*(x-5) + 70", 0., 10.) ; TF1 flatFunc ("flatFunc", "3", 0., 10.) ; typedef struct { Float_t x,y ; } VARS; static VARS vars ; TTree al ("sample","bkg test sample") ; al.Branch ("vars",&vars,"x/F:y/f") ; for (int i = 0 ; i < 10000 ; ++i) { vars.x = pol2pie.GetRandom () ; vars.y = flatFunc.GetRandom () ; al.Fill () ; } TFile out (argv[1],"recreate") ; al.Write () ; out.Close () ; return 0 ; }
void test(){ TH1D* h = new TH1D("","",1000,-5,5); for(int i=0;i<1e5;i++){ if(i%10000==0) cout<<i<<endl; // TF1 * f = new TF1("f","x",0,1); TF1 *f = new TF1("f","exp(-(x-2.1)^2/6.3)+exp(-(x+2.1)^2/6.3)",-2.4,2.4); //TRandom3 *r1 = new TRandom3(0); //double x = r1->Rndm(); double x = f->GetRandom(); //TRandom3 *r2 = new TRandom3(0); //double y = r1->Rndm(); double y = f->GetRandom(); h->Fill(x-y); } h->Draw(); }
//g++ `root-config --cflags --libs` altgraph.C -o altgraph.out void altgraph() { TH1F *h1 = new TH1F("h1","gaussian",100,-5,10); Float_t sigma,mpv; sigma = 3.; mpv = 2.; TF1 *fgaus = new TF1("fgaus","exp(-((x-[0])/[1])^2)*(x>0)",-5,10); fgaus->SetParameter(0,mpv); fgaus->SetParameter(1,sigma); h1->FillRandom("fgaus",1000000); TCanvas *c1 = new TCanvas(); h1->Draw(); for(int p=0; p<20; p++) cout<<fgaus->GetRandom()<<endl; c1->SaveAs("alt.pdf"); }
void GetRandomTest(){ double k0=1.39; double k1 = 0.425; double theta0 = 3.41; double theta1 = 1.30; int iNpart=2; double k_=k0+k1*(iNpart-2); double theta_=theta0+theta1*TMath::Log(iNpart-1); TF1 *f = new TF1("f","TMath::GammaDist(x,[0],0,[1])",0,200); f->SetParameters(k1,theta_); cout<<"Value at 0 = "<<f->Eval(0)<<endl; cout<<"Value at 1e-11 = "<<f->Eval(1e-11)<<endl; cout<<"Integral 1= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl; f->SetRange(1e-12,200); cout<<"Integral 2= "<<f->Integral(f->GetXmin(),f->GetXmax())<<endl; cout<<"fXmin = "<<f->GetXmin()<<"\tfXmax = "<<f->GetXmax()<<"\tfNpx = "<<f->GetNpx()<<endl; f->SetNpx(1e5); TCanvas *c1 = new TCanvas(); c1->SetLogy(); cout<<"f mean = "<<f->Mean(0,200)<<endl; cout<<"math mean = "<<f->GetParameter(0)*f->GetParameter(1)<<endl; TH1D* h = new TH1D("h","h",1000,0,200); for(int i=0;i<1e6;i++){ double para = f->GetRandom(); h->Fill(para); } h->Scale(1.0/h->Integral()*1000/200); h->GetYaxis()->SetRangeUser(1e-10,1); h->SetMarkerStyle(24); h->SetMarkerColor(4); h->SetMarkerSize(1.1); TLegend *leg = new TLegend(0.6,0.7,0.8,0.9); leg->SetFillColor(0); leg->SetFillStyle(0); leg->SetBorderSize(0); leg->SetTextFont(42); leg->SetTextSize(0.03); leg->AddEntry(f,"function","lp"); leg->AddEntry(h,"filled histogram","lp"); h->Draw("P"); f->Draw("same"); leg->Draw("same"); cout<<"h mean = "<<h->GetMean(1)<<endl; c1->Print("TestGetRandom.png"); }
void Chi(int num, double* arr) { //double chi[3] = arr; //double* pointer = χ //if(num > -1) { TF1* f = new TF1("f", "5*(TMath::Power(x,-4))",1,100); TH1D* h1 = new TH1D("h1","h1", 100, -0.5, 99.5); for(int i = 0; i < 1000000; i++) { h1->Fill(f->GetRandom(1,100)); //cout << f.GetRandom(1,100) << endl; } //cout << __FILE__ << __LINE__<< endl; TF1* pwrLw = new TF1("pwrLw", "[0]*TMath::Power(x,[1])",1,1000);//changed to 0 parameter pwrLw->SetParameter(0,5); pwrLw->SetParameter(1,-4); //cout << pwrLw->GetParameter(0) << "\t" << pwrLw->GetParameter(1) << endl; //cout << __FILE__ << __LINE__<< endl; h1->Fit("pwrLw","0","",2,25); TF1* func = h1->GetFunction("pwrLw"); double chi = func->GetChisquare(); double dof = func->GetNDF(); arr[0] = chi/dof; double par0 = func->GetParameter(0); double par1 = func->GetParameter(1); //cout << par0 << "\t" << par1 << endl; arr[1] = CalcChiSqr(h1,par0,par1,2,25); //chi[2] = CalcChiSqr(h1,5,-4,2,25); //cout << "Outputing values from Chi()" << endl; //cout << arr[0] << "\t" << arr[1] << endl;//"\t" << chi[2] << endl; //DoCleanUp(h1, f, pwrLw); } //arr = chi; //return chi; }
void createTBevents(int input){ printf("Starting Simulation of data\n"); //creating the output file char outputFileName[100] = {"OutputFile.root"}; printf("Creating output file: %s \n",outputFileName); TFile * outputFile = new TFile(outputFileName,"RECREATE"); //Counter for event number unsigned int eventNr; //Counter for total number of hits unsigned int hitsTotal = 0; short int col, row, adc; short int ladder = 2; short int mod = 3; short int disk = 2; short int blade = 2; short int panel = 2; //create the tree to store the data TTree *bpixTree[3]; char title[30]; for (int i=1; i<4; i++){ sprintf(title,"BPIX_Digis_Layer%1d",i); bpixTree[i-1]= new TTree(title,title); bpixTree[i-1]->Branch("Event", &eventNr, "Event/i"); bpixTree[i-1]->Branch("Ladder", &ladder, "Ladder/S"); bpixTree[i-1]->Branch("Module", &mod, "Module/S"); bpixTree[i-1]->Branch("adc", &adc, "adc/S"); bpixTree[i-1]->Branch("col", &col, "col/S"); bpixTree[i-1]->Branch("row", &row, "row/S"); } //Maximum number of events. Events does not correspond with Hits unsigned int maxEventNr = input; //Number of Hits per Event //This should be randomized later and be dependant on the rate double meanHitsPerEvent = 2; //Maximum particle flux [MHz cm^-2] int maxParticleFlux = 500; //number of hits in current event int hitsInEvent = -1; //create a random number generator TRandom3 * random = new TRandom3(); TRandom3 * randomrow = new TRandom3(); TRandom3 * randomcol = new TRandom3(); TRandom3 * randomadc = new TRandom3(); //using custom function to distribute values //values used from http://ntucms1.cern.ch/pixel_dev/flux/v8/016031/fitspot_bin_11.pdf TF1 * fx = new TF1("xfunc", "[0]*exp(2.59349*exp(-0.5*((-x+3.24273/.15+[1]/.15)/7.07486*.15)**2)+2.07765*exp(-0.5*((-x+9.33060e-01/.15+[1]/.15)/2.24067*.15)**2)-4.21847)",0, 52); fx->SetParameters(1,337.0); fx->SetParameters(2,1.74); TF1 * fy = new TF1("yfunc", AsyGaus,0,80,4); fy->SetParNames("mean","sigma1","sigma2","amplitude"); fy->SetParameter("mean",43); fy->SetParameter("sigma1",11.4); fy->SetParameter("sigma2",15.0); fy->SetParameter("amplitude",347.0); TF1 * fadc = new TF1("adcfunc", langaufun,0,400,4); fadc->SetParNames("scale","mpv","area","sigma"); fadc->SetParameter("scale",19); fadc->SetParameter("mvp",220); fadc->SetParameter("area",10000); fadc->SetParameter("sigma",30); while (eventNr < maxEventNr){ //printf("eventNr: %d \n",eventNr); //Function used for fitting according to Xin an Stefano //Start by generating the number of hits per event //following a poisson distribution random->SetSeed(0); hitsInEvent = random->Poisson(meanHitsPerEvent); //printf("hitsInEvent %d \n", hitsInEvent); hitsTotal += hitsInEvent; if(hitsInEvent < 0){ printf("ERROR: Number of hits in event is negative!!!\n"); break; } //distribute the hits in the event over the roc accorsing to gaus distribution /* for(int i = 0; i < hitsInEvent; ++i){ //random row value randomrow->SetSeed(0); row = randomrow->Gaus(40,10); //random column value randomcol->SetSeed(0); col = randomcol->Gaus(25,8); //printf("row: %d | col: %d | adc: %d\n",row,col,adc); bpixTree[2]->Fill(); } */ for(int i = 0; i < hitsInEvent; ++i){ //random row value row = fy->GetRandom(); //random column value col = fx->GetRandom(); //random adc value adc = fadc->GetRandom(); //printf("row: %d | col: %d | adc: %d\n",row,col,adc); bpixTree[1]->Fill(); } ++ eventNr; } printf("Total number of Hits: %d\n",hitsTotal); printf("Writing output file: %s \n", outputFileName); outputFile->cd(); outputFile->Write(); outputFile->Close(); printf("DONE!\n"); }
void proSTEGvnwithnfv3() { int mult = atoi(getenv("MULT")); int tot_num=50000; //50k events double MeanMult=(double)mult; double RMSMult=10; int ifile = atoi(getenv("IFILE")); //simple toy event generator //TFile f(Form("/lio/lfs/cms/store/user/qixu/flow/NewSTEG/pPbDataV205m%d/vndata_50k_%d.root",mult,ifile), "RECREATE","ROOT file with histograms & tree"); TFile f(Form("/tmp/xuq7/pPbDataV205m%d/vndata_50k_%d.root",mult,ifile), "RECREATE","ROOT file with histograms & tree"); // TFile f(Form("vndata_50k_%d.root",mult,ifile), "RECREATE","ROOT file with histograms & tree"); TTree *tree = new TTree("tree","Event tree with a few branches"); // tree->Branch("npg", &b_npg, "npg/I"); // # of particles; // tree->Branch("phirg", &b_phirg, "phirg/F"); // RP angle; tree->Branch("n", &b_n, "n/I"); // same as npg; tree->Branch("ptg", &b_ptg, "ptg[n]/F"); // ; tree->Branch("etag", &b_etag, "etag[n]/F"); tree->Branch("phig", &b_phig, "phig[n]/F"); TF1 *EtaDistr = new TF1("EtaDistr","exp(-(x-2.1)^2/6.3)+exp(-(x+2.1)^2/6.3)",-4,4); //TF1 *PhiDistr = new TF1("PhiDistr","1+2*[0]*cos(x)+2*[1]*cos(2*x)+2*[2]*cos(3*x)+2*[3]*cos(4*x)+2*[4]*cos(5*x)+2*[5]*cos(6*x)",0,2.*TMath::Pi()); TF1 *PhiDistr = new TF1("PhiDistr","1+2*[0]*cos(2*x)+2*[1]*cos(3*x)+2*[2]*cos(4*x)+2*[3]*cos(5*x)+2*[4]*cos(6*x)",0,2.*TMath::Pi()); //TF1 *PtDistr = new TF1("PtDistr","exp (-(x/.40))+0.0015*exp (-(x/1.5))", 0.2,10); //V~0.12 //TF1 *PtDistr = new TF1("PtDistr","exp (-(x/0.90))+0.15*exp (-(x/15))", 0.1,10); //V~=0.06 TF1 *PtDistr = new TF1("PtDistr","0.03*(exp (-(x/0.594540))+0.00499506*exp (-(x/1.89391)))", 0.3,6.0); //Real Data // TF1 *PtDistr = new TF1("PtDistr","[0]*x*TMath::Power(1+(sqrt(x*x+[1]*[1])-[1]/[2]),-[3])",0.2,10); //PtDistr->SetParameters(118.836,-0.335972,0.759243,118.836); //Real data fit with Tsallis //TF1 *V1vsEta = new TF1("V1vsEta","-exp(-(x+1)^2)/20-x/30+exp(-(x-1)^2)/20",-2.4,2.4); //TF1 *V2vsPt = new TF1("V2vsPt","((x/3)^1.8/(1+(x/3)^1.8))*(.00005+(1/x)^0.8)",0.2,10); //TF1 *V2vsPt = new TF1("V2vsPt","((x/[0])^[1]/(1+(x/[2])^[3]))*(.00005+(1/x)^[4])",0.1,10); // V2vsPt->SetParameters(4.81159,1.80783,3.69272,3.11889,0.931485); //Real data V~0.05 // V2vsPt->SetParameters(5,1.8,3,1.8,0.8); //V~0.06 TF1 *V2vsPt = new TF1("V2vsPt","((x/3.31699)^2.35142/(1+(x/3.49188)^3.54429))*(.00005+(1/x)^1.50600)",0.3,6.0); TF1 *V3vsPt = new TF1("V3vsPt","((x/3.2)^2.3/(1+(x/3.4)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); TF1 *V4vsPt = new TF1("V4vsPt","((x/4.8)^2.1/(1+(x/3.4)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); TF1 *V5vsPt = new TF1("V5vsPt","((x/6.0)^3.2/(1+(x/11.4)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); TF1 *V6vsPt = new TF1("V6vsPt","((x/5.6)^2.4/(1+(x/4.7)^2.1))*(.00005+(1/x)^1.4)",0.3,6.0); UInt_t iniseed = SetSeedOwn(); gRandom->SetSeed(iniseed); TRandom3 *rnd = new TRandom3(0); double v1, v2, v3, v4, v5, v6, ph, myphi, mypt, myeta, phi0, Psi; int nnf,k; double neta, nphi, npt; int slicept; for(int i=0; i<tot_num; i++){ Psi = rnd->Uniform(0.0,2.*TMath::Pi()); //Psi=0; b_phirg = Psi; b_npg = rnd->Gaus(MeanMult,RMSMult); int b_npgsame = (int)b_npg * 0.10; n = 0; for(int j=0; j<b_npg;j++ ){ mypt = PtDistr->GetRandom(); myeta = EtaDistr->GetRandom(); //v1=V1vsEta->Eval(myeta); v2=V2vsPt->Eval(mypt); v3=V3vsPt->Eval(mypt); v4=V4vsPt->Eval(mypt); v5=V5vsPt->Eval(mypt); v6=V6vsPt->Eval(mypt); b_etag[n] = myeta; b_ptg[n] = mypt; //PhiDistr->SetParameters(v1,v2,v3,v4,v5,v6); PhiDistr->SetParameters(v2,v3,v4,v5,v6); myphi = PhiDistr->GetRandom(); // randon selection dn/dphi myphi = myphi+Psi; // angle in lab frame -- needed for correct cumulant v2 if (myphi>2.*TMath::Pi()) myphi=myphi-2.*TMath::Pi(); // 0 - 2*Pi b_phig[n] = myphi; // save angle in lab frame n++; } if(i%10==0){ for(int j=0;j<b_npgsame;j++){ mypt = PtDistr->GetRandom(); myeta = EtaDistr->GetRandom(); b_ptg[n] = mypt; b_etag[n] = myeta; myphi = rnd->Gaus(Psi, 0.3); if (myphi>2.*TMath::Pi()) myphi=myphi-2.*TMath::Pi(); // 0 - 2*Pi b_phig[n] = myphi; n++; } } if (i%10000 == 0) cout << i << " " << "events processed" << endl; b_n = n; tree->Fill(); } // End of loop over events cout << "writing tree" << endl; tree->Write(); cout << "writing to file" << endl; f.Write(); cout << "closing file" << endl; f.Close(); cout << "THE END" << endl; }
// Evaluates a transfer function attached to an object // the tf is a TF1* in a TFType->TF1* map in the object // the tf is a function of the reconstructed Energy (pt) through tf->Eval(Erec) // The generator energy is set via tf->SetParameter(0, Egen) // type - the hypothesis for the object to be tested, e.g. qReco (reconstructed light quark) double MEM::transfer_function2( void* obj, //either MEM::Object or TF1 const double *x, const TFType::TFType& type, int& out_of_range, const double& cutoff, const bool& smear, const int& debug){ double w = 1.0; TF1* tf = nullptr; MEM::Object* _obj = nullptr; //x[0] -> Egen switch( type ){ //W(Erec | Egen) = TF1(Erec, par0:Egen) case TFType::bReco: case TFType::qReco: _obj = (MEM::Object*)obj; tf = _obj->getTransferFunction(type); //set gen tf->SetParameter(0, x[0]); //eval with x - reco w *= tf->Eval(_obj->p4().Pt()); if( smear ) w = tf->GetRandom(); #ifdef DEBUG_MODE if( debug&DebugVerbosity::integration) cout << "\t\ttransfer_function2: Evaluate W(" << x[0] << " | " << _obj->p4().Pt() << ", TFType::qReco) = " << w << endl; #endif break; //In case jets have a cut E > Emin //W_loss(Egen) = \int_0^Emin W(Erec | Egen) dErec //In case jets have a cut pt > ptmin //W_loss(ptgen) = \int_0^ptmin W(ptrec | ptgen) dptrec //FIXME pt to be implemented case TFType::bLost: case TFType::qLost: tf = (TF1*)obj; //eval at x - gen w *= tf->Eval(x[0]); #ifdef DEBUG_MODE if( debug&DebugVerbosity::integration) cout << "\t\ttransfer_function2: Evaluate W(" << x[0] << ", TFType::qLost) = " << w << endl; #endif break; case TFType::Unknown: w *= 1.; #ifdef DEBUG_MODE if( debug&DebugVerbosity::integration) cout << "\t\ttransfer_function2: Evaluate W = 1 " << endl; #endif break; default: break; } return w; }
void toymc(double ptmin = 290., double ptmax = 320., double lumi = 0, double *nevts = 0, double *mean = 0, double *err = 0) { gStyle->SetOptStat(1110); gStyle->SetOptFit(); TF1 *cb1 = new TF1("cb1",crystal_ball, 0., 2., 5); TF1 *cb1x = new TF1("cb1x",crystal_ball_x, 0., 2., 5); TF1 *g = new TF1("g","gaus",0.,2.); TF1 *cb2 = new TF1("cb2",crystal_ball, 0., 2., 5); TF1 *cb2x = new TF1("cb2x",crystal_ball_x, 0., 2., 5); TF1 *cb3 = new TF1("cb3",crystal_ball, 0., 2., 5); TF1 *cb3x = new TF1("cb3x",crystal_ball_x, 0., 2., 5); TF1 *cb4 = new TF1("cb4",crystal_dipole, 0., 2., 5); TF1 *cb4x = new TF1("cb4x",crystal_dipole_x, 0., 2., 5); double mu = 0.70; // mu1*mu2 double mu1 = 0.95; double mu2 = mu/0.95; double mu3 = 1.00; double mu4 = 1.00; // Sigmas are relative widths so remember to multiply by mean double sig = 0.12; // sqrt(sig1**2 + sig2**2) double sig1 = 0.06; double sig2 = sqrt(sig*sig-sig1*sig1); double sig3 = 0.025; double sig4 = 0.030; double a1 = 0.7;//1.2; double n1 = 15.; double a2 = 1.7; double n2 = 15.; double a3 = 1.0; double n3 = 25.; double a4 = 0.8; double n4 = 35.; const bool photbin = false;//true; // Bin in calo photon pT, not parton pT double binmin = ptmin;//290; double binmax = ptmax;//320; double genmin = binmin*0.93;//0.9; double genmax = binmax*1.40;//1.20; //TF1 *xsec = new TF1("xsec","7.729e+10*pow(x,-3.104)*exp(-0.003991*x)", TF1 *xsec = new TF1("xsec", cross_section, 0., 14000., 5); xsec->SetParameters(7.729e+10, -3.104, -0.003991, genmin, genmax); xsec->SetNpx(1000); // Estimate average pT and number of events in bin TF1 *xsec_x = new TF1("xsec_x", cross_section_x, 0., 14000., 5); xsec_x->SetParameters(7.729e+10, -3.104, -0.003991, genmin, genmax); xsec_x->SetNpx(1000); double pt = xsec_x->Integral(binmin,binmax) / xsec->Integral(binmin,binmax); double nev = xsec->Integral(binmin, binmax) * lumi; if (nev==0) { nev = 5000000; lumi = nev / xsec->Integral(binmin, binmax); } cout << Form("Processing bin %1.0f-%1.0f with average pT=%1.0f" " and lumi=%1.1f pb-1 (nev=%1.3g)", binmin, binmax, pt, lumi, nev) << endl; cb1->SetParameters(1., mu1, sig1*mu1, a1, n1); // Gen/Part cb1x->SetParameters(1., mu1, sig1*mu1, a1, n1); // Gen/Part //g->SetParameters(1., mu2, sig2*mu2); // Calo/Gen cb2->SetParameters(1., mu2, sig2*mu2, a2, n2); // Calo/Part cb2x->SetParameters(1., mu2, sig2*mu2, a2, n2); // Calo/Part cb3->SetParameters(1., mu3, sig3*mu3, a3, n3); // Calo/Phot cb3x->SetParameters(1., mu3, sig3*mu3, a3, n3); // Calo/Phot cb4->SetParameters(1., mu4, sig4*mu4, a4, n4); // Part/Part cb4x->SetParameters(1., mu4, sig4*mu4, a4, n4); // Part/Part double mu1x = cb1x->Integral(0.,2.) / cb1->Integral(0.,2.); double mu2x = cb2x->Integral(0.,2.) / cb2->Integral(0.,2.); double mu3x = cb3x->Integral(0.,2.) / cb3->Integral(0.,2.); double mu4x = cb4x->Integral(0.,2.) / cb4->Integral(0.,2.); TH1D *xsec0 = new TH1D("xsec0","PtHat",1000,0.7*genmin,1.3*genmax); TH1D *xsec1 = new TH1D("xsec1","PartPtPho",1000,0.7*genmin,1.3*genmax); TH1D *xsec2 = new TH1D("xsec2","PhotPt",1000,0.7*genmin,1.3*genmax); TH1D *xsec3 = new TH1D("xsec3","PhotPt",1000,0.7*genmin,1.3*genmax); TH1D *h1 = new TH1D("h1","GenPart",400,0.,2.); TH1D *h2 = new TH1D("h2","CaloGen",400,0.,2.); TH1D *h3 = new TH1D("h3","Phot",400,0.,2.); TH1D *h4 = new TH1D("h4","Part",400,0.,2.); TH1D *h12 = new TH1D("h12","CaloPart",400,0.,2.); TH1D *h123 = new TH1D("h123","CaloPhot",400,0.,2.); TH1D *h1234 = new TH1D("h1234","RmeasSig",400,0.,2.); const double pthat0 = 300.; const int nit = 5000000; for (int i = 0; i != nit; ++i) { double pthat = pthat0; //if (photbin) pthat = xsec->GetRandom(genmin, genmax); // Is the parton balancing model ok? // Should we rather simulate a "second jet", which either // the photon or jet can loose? (No gains allowed vs pthat) // parton balance double part = cb4->GetRandom(); // jet side //double part1 = cb4->GetRandom(); //double partpt1 = part1 * pthat; double partpt1 = (1.+min(part-1.,0.)) * pthat; double genpart = cb1->GetRandom(); double genpt = genpart * partpt1; //double calogen = g->GetRandom(); double calogen = cb2->GetRandom(); double calopt = calogen * genpt; double calpart = calopt / partpt1; // photon side //double part2 = cb4->GetRandom(); //double partpt2 = part2 * pthat; double partpt2 = (1.+min(1.-part,0.)) * pthat; double phot = cb3->GetRandom(); double photpt1 = phot * partpt1; // parton pT's perfectly balanced double calphot1 = calopt / photpt1; // parton pT's perfectly balanced double photpt2 = phot * partpt2; // account for parton imbalance double calphot2 = calopt / photpt2; // account for parton imbalance xsec0->Fill(pthat); xsec1->Fill(partpt2); xsec2->Fill(photpt2); //if (photbin && if (photpt2 >= binmin && photpt2 < binmax) { //if (true) { xsec3->Fill(photpt2); h1->Fill(genpart); h2->Fill(calogen); h3->Fill(phot); h4->Fill(partpt1/partpt2);//part2); h12->Fill(calpart); h123->Fill(calphot1); h1234->Fill(calphot2); } } double m1 = h1->GetMean(); double m2 = h2->GetMean(); double m3 = h3->GetMean(); double m4 = h4->GetMean(); double m12 = h12->GetMean(); double m123 = h123->GetMean(); double m1234 = h1234->GetMean(); double s12 = h12->GetRMS() / m12; double s123 = h123->GetRMS() / m123; double s1234 = h1234->GetRMS() / m1234; g->SetRange(mu1*(1.-sig1),mu1*(1+sig1)); h1->Fit(g, "QR"); double p1 = g->GetParameter(1); g->SetRange(mu2*(1.-sig2),mu2*(1+sig2)); h2->Fit(g, "QR"); double p2 = g->GetParameter(1); g->SetRange(mu3*(1.-sig3),mu3*(1+sig3)); h3->Fit(g, "QR"); double p3 = g->GetParameter(1); g->SetRange(mu4*(1.-sig4),mu4*(1+sig4)); h4->Fit(g, "QR"); double p4 = g->GetParameter(1); g->SetRange(m12*(1.-s12),m12*(1+s12)); h12->Fit(g, "QRN"); g->SetRange(g->GetParameter(1)-g->GetParameter(2), g->GetParameter(1)+g->GetParameter(2)); h12->Fit(g, "QR"); double p12 = g->GetParameter(1); g->SetRange(m123*(1.-s123),m123*(1+s123)); h123->Fit(g, "QRN"); g->SetRange(g->GetParameter(1)-g->GetParameter(2), g->GetParameter(1)+g->GetParameter(2)); h123->Fit(g, "QR"); double p123 = g->GetParameter(1); g->SetRange(m1234*(1.-s1234),m1234*(1+s1234)); h1234->Fit(g, "QRN"); g->SetRange(g->GetParameter(1)-g->GetParameter(2), g->GetParameter(1)+g->GetParameter(2)); h1234->Fit(g, "QR"); double p1234 = g->GetParameter(1); cout << Form("for GenPart,\n" "mean_in = %1.3g, peak_in = %1.3g, diff = %+1.3f%%\n" "mean_mc = %1.3g, peak_mc = %1.3g, diff = %+1.3f%%\n" "diff = %+1.3f%%, diff = %+1.3f%%,(diff = %+1.3f%%)\n", mu1x, mu1, 100.*(mu1x/mu1-1.), m1, p1, 100.*(m1/p1-1.), 100.*(m1/mu1x-1.), 100.*(p1/mu1-1.), 100.*(p1/mu1x-1.)) << endl; cout << Form("for CaloGen,\n" "mean_in = %1.3g, peak_in = %1.3g, diff = %+1.3f%%\n" "mean_mc = %1.3g, peak_mc = %1.3g, diff = %+1.3f%%\n" "diff = %+1.3f%%, diff = %+1.3f%%,(diff = %+1.3f%%)\n", mu2x, mu2, 100.*(mu2x/mu2-1.), m2, p2, 100.*(m2/p2-1.), 100.*(m2/mu2x-1.), 100.*(p2/mu2-1.), 100.*(p2/mu2x-1.)) << endl; double mean_in = mu1x*mu2x; double peak_in = mu1*mu2; cout << Form("for CaloPart,\n" "mean_in = %1.3g, peak_in = %01.03g, diff = %+1.3f%%\n" "mean_mc = %1.3g, peak_mc = %01.03g, diff = %+1.3f%%\n" "diff = %+1.3f%%, diff = %+1.3f%%,(diff = %+1.3f%%)\n", mean_in, peak_in, 100.*(mean_in/peak_in-1.), m12, p12, 100.*(m12/p12-1.), 100.*(m12/mean_in-1.), 100.*(p12/peak_in-1.), 100.*(p12/mean_in-1.)) << endl; cout << "-------------------------------------" << endl << endl; cout << Form("for Phot,\n" "mean_in = %1.3g, peak_in = %1.3g, diff = %+1.3f%%\n" "mean_mc = %1.3g, peak_mc = %1.3g, diff = %+1.3f%%\n" "diff = %+1.3f%%, diff = %+1.3f%%,(diff = %+1.3f%%)\n", mu3x, mu3, 100.*(mu3x/mu3-1.), m3, p3, 100.*(m3/p3-1.), 100.*(m3/mu3x-1.),100.*(p3/mu3-1.), 100.*(p3/mu3x-1.)) << endl; mean_in = mu1x*mu2x/mu3x; peak_in = mu1*mu2/mu3; cout << Form("for CaloPhot,\n" "mean_in = %1.3g, peak_in = %01.03g, diff = %+1.3f%%\n" "mean_mc = %1.3g, peak_mc = %01.03g, diff = %+1.3f%%\n" "diff = %+1.3f%%, diff = %+1.3f%%,(diff = %+1.3f%%)\n", mean_in, peak_in, 100.*(mean_in/peak_in-1.), m123, p123, 100.*(m123/p123-1.), 100.*(m123/mean_in-1.), 100.*(p123/peak_in-1.), 100.*(p123/mean_in-1.)) << endl; cout << "-------------------------------------" << endl << endl; cout << Form("for Part,\n" "mean_in = %1.3g, peak_in = %1.3g, diff = %+1.3f%%\n" "mean_mc = %1.3g, peak_mc = %1.3g, diff = %+1.3f%%\n" "diff = %+1.3f%%, diff = %+1.3f%%,(diff = %+1.3f%%)\n", mu4x, mu4, 100.*(mu4x/mu4-1.), m4, p4, 100.*(m4/p4-1.), 100.*(m4/mu4x-1.),100.*(p4/mu4-1.), 100.*(p4/mu4x-1.)) << endl; mean_in = mu1x*mu2x/(mu3x*mu4x); peak_in = mu1*mu2/(mu3/mu4); cout << Form("for RmeasSig,\n" "mean_in = %1.3g, peak_in = %01.03g, diff = %+1.3f%%\n" "mean_mc = %1.3g, peak_mc = %01.03g, diff = %+1.3f%%\n" "diff = %+1.3f%%, diff = %+1.3f%%,(diff = %+1.3f%%)\n", mean_in, peak_in, 100.*(mean_in/peak_in-1.), m1234, p1234, 100.*(m1234/p1234-1.), 100.*(m1234/mean_in-1.), 100.*(p1234/peak_in-1.), 100.*(p1234/mean_in-1.)) << endl; //cout << Form("m1 = %1.3g, m2 = %1.3g", m1, m2) << endl; //cout << Form("m12 = %1.3g, mu = %1.3g, rel.diff = %1.3g%%", // m12, mu, 100.*(m12/mu - 1.)) << endl; TCanvas *c = (TCanvas*)gROOT->FindObject("c1"); if (c) delete c; c = new TCanvas("c1","c1",900,900); c->Divide(3,3); c->cd(1); gPad->SetLogy(); h2->Draw(); c->cd(2); gPad->SetLogy(); h1->Draw(); c->cd(3); gPad->SetLogy(); h12->Draw(); c->cd(4); gPad->SetLogy(); xsec0->SetLineColor(kBlack); xsec0->Draw(); xsec1->SetLineColor(kBlue); xsec1->Draw("SAME"); xsec2->SetLineColor(kRed); xsec2->Draw("SAME"); c->cd(5); gPad->SetLogy(); h3->Draw(); c->cd(6); gPad->SetLogy(); h123->Draw(); c->cd(7); TH1D *xsec1r = (TH1D*)xsec1->Clone("xsec1r"); xsec1r->Divide(xsec1,xsec0); xsec1r->Draw(); xsec1r->SetMaximum(1.1); TH1D *xsec2r1 = (TH1D*)xsec2->Clone("xsec2r1"); xsec2r1->Divide(xsec2,xsec1); xsec2r1->Draw("SAME"); TH1D *xsec2r0 = (TH1D*)xsec2->Clone("xsec2r0"); xsec2r0->SetLineColor(kBlack); xsec2r0->Divide(xsec2,xsec0); xsec2r0->Draw("SAME"); TH1D *xsec3r0 = (TH1D*)xsec3->Clone("xsec3r0"); xsec3r0->Divide(xsec3,xsec0); xsec3r0->SetFillStyle(3001); xsec3r0->SetFillColor(kRed); xsec3r0->Draw("SAME"); c->cd(8); gPad->SetLogy(); h4->Draw(); c->cd(9); gPad->SetLogy(); h1234->Draw(); c->cd(0); }
void anaJetTrackRpA() { std::cout << "start working\n"; TFile *fcrel3 ; TH1D *C_rel ; //for ak3PF jets, applied for pPb data only // TFile* fcrel3 = TFile::Open("/afs/cern.ch/user/d/dgulhan/public/Corrections/Casym_pPb_double_hcalbins_algo_ak3PF_pt100_140_jet80_alphahigh_20_phicut250.root", "readonly"); //for akPu3PF jets and pPb data if(coll=="PPb") fcrel3 = TFile::Open(Form("/afs/cern.ch/user/d/dgulhan/public/Corrections/Casym_pPb_double_hcalbins_algo_%s_pt100_140_jet80_alphahigh_20_phicut250.root", algo.Data()), "readonly"); if(coll=="PbP") fcrel3 = TFile::Open(Form("/afs/cern.ch/user/d/dgulhan/public/Corrections/Casym_Pbp_double_hcalbins_algo_%s_pt100_140_jet80_alphahigh_20_phicut250.root", algo.Data()), "readonly"); if(fcrel3) C_rel=(TH1D*)fcrel3->Get("C_asym"); // fcrel3->Close(); TrigName=getenv("TRIG"); hist_class *my_hists = new hist_class("pfjet"); cout <<my_hists->IsMC<<endl ; cout <<"analysis trig = " <<TrigName <<endl ; //this function is to correct for UE subtraction (we are using akPu3PF algorithm) TF1 * fUE ; TF1 * fgaus ; fgaus=new TF1("fgaus","gaus(0)",-20,20); if(my_hists->IsMC==kTRUE){ fUE = new TF1("fUE","[0]/pow(x,[1])"); // //for ak3PF jets // fUE->SetParameters(0.4183,0.4244); // //for akPu3PF jets if(algo=="akPu3PF") fUE->SetParameters(1.052,0.5261); else fUE->SetParameters(0.4183,0.4244); //for gauss smearing fgaus->SetParameters(1,0,1); } else { fUE = new TF1("fUE","1-[0]/pow(x,[1])",20,300); // //for ak3PF jets // fUE->SetParameters(0.8648,0.8167); // //for akPu3PF jets if(algo=="akPu3PF") fUE->SetParameters(0.3015,0.8913); else fUE->SetParameters(0.8648,0.8167); } TF1 * fVz = new TF1("fVx","[0]+[1]*x+[2]*TMath::Power(x,2)+[3]*TMath::Power(x,3)+[4]*TMath::Power(x,4)", -15., 15.); fVz->SetParameters(1.60182e+00,1.08425e-03,-1.29156e-02,-7.24899e-06,2.80750e-05); if(my_hists->IsMC==kTRUE){ pthat=atoi(getenv("PTHAT")) ; ptmax=atoi(getenv("PTMAX")) ; cout <<"pthat = " <<pthat <<" pthatmax =" <<ptmax <<endl ; } if(my_hists->IsMC!=kTRUE){ if(coll=="HI") dataPath="/net/hidsk0001/d00/scratch/yjlee/merge/pbpbDijet_v20" ;//mit PbPb data path else { /* if(TrigName=="Jet20") dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/krajczar/inbound/mnt/hadoop/cms/store/user/krajczar/pPb_Jet20_Full_v1" ; else if(TrigName=="Jet40" || TrigName=="Jet60") dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/krajczar/inbound/mnt/hadoop/cms/store/user/krajczar/pPb_Jet40Jet60_Full_v1" ; else dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/yjlee/pPb2013/promptReco"; */ if(TrigName=="Jet80" || TrigName=="Jet100") dataPath="root://eoscms//eos/cms/store/group/phys_heavyions/yjlee/pPb2013/promptReco"; else dataPath="root://eoscms//eos/cms/store/caf/user/ymao"; } } //data Path else { //MC analysis if(coll=="HI") { if(pthat==50||pthat==80||pthat==100||pthat==170) dataPath= Form("/mnt/hadoop/cms/store/user/yenjie/HiForest_v27/"); //MIT MC normial else dataPath= Form("/mnt/hadoop/cms/store/user/yenjie/HiForest_v28/"); //MIT MC normial } else if(coll=="PPb") // dataPath=Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Hijing_Pythia_pt%d/HiForest_v77_merged01", pthat); dataPath=Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Signal_Pythia_pt%d/HiForest_v77_v2_merged01", pthat); else if(coll=="PbP") dataPath=Form("/mnt/hadoop/cms/store/user/dgulhan/Pbp/HP05/prod24/Hijing_Pythia_pt%d/HiForest_v84_merged02", pthat); else if(coll=="PP2011") dataPath= Form("/net/hisrv0001/home/zhukova/scratch/HIHighPt/forest/pthat%d", pthat); //lxplus path for pp else { if(pthat==220) dataPath= Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Signal_Pythia_pt%d/HiForest_v77_v2_merged02", pthat); //2013 pp tracking for 5.02TeV else dataPath= Form("/mnt/hadoop/cms/store/user/dgulhan/pPb/HP04/prod16/Signal_Pythia_pt%d/HiForest_v77_v2_merged01", pthat); //2013 pp tracking for 5.02TeV } } if(my_hists->IsMC!=kTRUE){ //real data analysis if(coll=="HI") intputFile="promptskim-hihighpt-hltjet80-pt90-v20.root" ; //full dataset else if(coll=="PP2011") intputFile="hiForest2_pp_ppreco_415_90percent.root"; //! 2011 pp data rereco else if(coll=="PbPb") intputFile="PbPHiForest2_PbPbPAHighPtJet80_cent50-100_pprereco.root"; else if(coll=="PPb"){ if(TrigName=="Jet20") // intputFile="mergedJet20_KK.root" ; intputFile="mergedJet20_pPb_Jet20_Full_UsingKKForest_v1.root" ; else if(TrigName=="Jet40" || TrigName=="Jet60") // intputFile="mergedJet40Jet60_KK.root" ; intputFile="mergedJet40Jet60_pPb_Jet40Jet60_Full_UsingKKForest_v1.root" ; else if(TrigName=="Jet80" || TrigName=="Jet100") intputFile="PA2013_HiForest_PromptReco_JSonPPb_forestv77.root" ; else // intputFile="PA2013_HiForest_PromptReco_KrisztianMB_JSonPPb_forestv84.root" ; intputFile="mergedMB_pPb_SingleTrack_Full_UsingKKForest_v1.root" ; } else if(coll=="PbP"){ if(TrigName=="Jet20") // intputFile="mergedJet20_KK.root" ; intputFile="mergedJet20_pPb_Jet20_Full_UsingKKForest_v1.root" ; else if(TrigName=="Jet40" || TrigName=="Jet60") // intputFile="mergedJet40Jet60_KK.root" ; intputFile="mergedJet40Jet60_pPb_Jet40Jet60_Full_UsingKKForest_v1.root" ; else if(TrigName=="Jet80" || TrigName=="Jet100") intputFile="PA2013_HiForest_PromptReco_JSonPbp_JECdb_forestv84.root" ; else // intputFile="PA2013_HiForest_PromptReco_KrisztianMB_JSonPPb_forestv84.root" ; intputFile="mergedMB_pPb_SingleTrack_Full_UsingKKForest_v1.root" ; } else // intputFile="PP2013_HiForest_PromptReco_JsonPP_Jet80_HIReco_forestv84_v2.root"; //! 2013 pp data with HI tracking intputFile="PP2013_HiForest_PromptReco_JsonPP_Jet80_PPReco_forestv82.root"; //! 2013 pp data with pp tracking } else { //MC sample if(coll=="HI"){ if(pthat==50||pthat==80||pthat==100||pthat==170) intputFile=Form("Dijet%d_HydjetDrum_v27_mergedV1.root", pthat); else intputFile=Form("Dijet%d_HydjetDrum_v28_mergedV1.root", pthat); } else if(coll=="PPb") // intputFile=Form("pt%d_HP04_prod16_v77_merged_forest_0.root", pthat); intputFile=Form("pt%d_HP04_hiforest77_hiSignal.root", pthat); else if(coll=="PbP") intputFile=Form("pt%d_HP05_prod24_v84_merged_forest_0.root", pthat); else if(coll=="PP2011") intputFile=Form("mergedFile.root"); // 2011 pp MC else intputFile=Form("pt%d_HP04_hiforest77_hiSignal.root", pthat); // ! 2013 pp 5.02TeV MC with pp tracking } TString inname=Form("%s/%s", dataPath.Data(),intputFile.Data()); // Define the input file and HiForest HiForest * c ; if(coll=="PP" || coll=="PP2011") c = new HiForest(inname,"forest",cPP); else if(coll=="PPb" || coll=="PbP") c = new HiForest(inname,"forest",cPPb); else c = new HiForest(inname,"forest",cPbPb); c->doTrackCorrections = false; c->doTrackingSeparateLeadingSubleading = false; c->InitTree(); // cout << "start working222222\n"; // TFile *my_file=TFile::Open(Form("%s/%s", dataPath.Data(),intputFile.Data())); cout <<"Input file" << inname<<endl ; /* TrackCorrector corr("trackCorrections_HIN12017v4_HijingCombined.root"); if(doTrackCorrections){ corr.load("trkCorr_HIN12017"); corr.setOption1(true); corr.setOption2(true); } */ TrackCorrector2D corr("/afs/cern.ch/work/y/ymao/analysis/AsymmetryPA/Corrections/trackCorrections_HIN12017v5_XSecWeighted.root"); if(doTrackCorrections) corr.load("trkCorr_HIN12017"); Evts * offSel = &(c->evt); Skims * my_skim = &(c->skim); Hlts * trigSel = &(c->hlt); //jet tree // if(coll=="HI") Jets * my_ct = &(c->akPu4PF); // Jets * my_ct = &(c->akPu4Calo); // else // Jets * my_ct = &(c->ak3PF); // Jets * jetthres = &(c->icPu5); //track tree Tracks * my_tr = &(c->track); //GenParticle tree GenParticles * my_GenPart = &(c->genparticle); int curr_bin = nbin-1 ; int Nevents[nbin] = {0} ; Int_t Nevt_40_60[nbin] = {0} ; Int_t Nevt_60_75[nbin] = {0} ; Int_t Nevt_75_95[nbin] = {0} ; Int_t Nevt_95_120[nbin] = {0} ; Int_t Nevt_120[nbin] = {0} ; cout <<"Number of events ="<<c->GetEntries()<<endl ; for(int evi = 0; evi < c->GetEntries(); evi++) { c->GetEntry(evi); int noise_evt = my_skim->pHBHENoiseFilter ; // int ecal_noise = my_skim->phiEcalRecHitSpikeFilter ; // if(ecal_noise==0) continue ; double vz = offSel->vz ; int hiBin = offSel->hiBin ; weight = 1. ; int pileup_Gplus ; double HFbin ; HFbin = (offSel->hiHFplusEta4)+(offSel->hiHFminusEta4); /* if(coll=="PPb") HFbin = (offSel->hiHFplus); else HFbin = (offSel->hiHFminus); */ if(my_hists->IsMC!=kTRUE){ int evt_sel ; pileup_Gplus = my_skim->pVertexFilterCutGplus ; if(coll=="PbPb"|| coll=="HI"|| coll=="PP2011") evt_sel = my_skim->pcollisionEventSelection ; else evt_sel = my_skim->pPAcollisionEventSelectionPA; // if(evt_sel==0) continue ; if(!evt_sel) continue ; //for 0-90% selection using HF sum energy at |eta|>4 // if(HFbin<2.87) continue ; //for 0-90% selection using HF sum energy at eta>4 // if(HFbin<2.66) continue ; } if(my_hists->IsMC!=kTRUE){ // if(noise_evt==0) continue ; if(!noise_evt) continue ; int jetTr2 ; if(coll=="HI"|| coll=="PbPb") jetTr2 = trigSel->HLT_HIJet80_v1 ; else if (coll=="PP2011") jetTr2 = trigSel->HLT_Jet60_v1 ; else { // jetTr2 = trigSel->HLT_PAJet80_NoJetID_v1 ; if(TrigName=="Jet20") jetTr2 = trigSel->HLT_PAJet20_NoJetID_v1 ; else if(TrigName=="Jet40") jetTr2 = trigSel->HLT_PAJet40_NoJetID_v1 ; else if(TrigName=="Jet60") jetTr2 = trigSel->HLT_PAJet60_NoJetID_v1 ; else if(TrigName=="Jet80") jetTr2 = trigSel->HLT_PAJet80_NoJetID_v1 ; else if(TrigName=="Jet100") jetTr2 = trigSel->HLT_PAJet100_NoJetID_v1 ; else jetTr2 = trigSel->HLT_PAZeroBiasPixel_SingleTrack_v1 ; } if(!jetTr2) continue ; int run=offSel->run ; if( !(my_skim->phfPosFilter1 && my_skim->phfNegFilter1 && my_skim->pBeamScrapingFilter && my_skim->pprimaryvertexFilter)) continue ; if(coll=="PPb"){ // if( my_skim->phfPosFilter1==0 || my_skim->phfNegFilter1==0 ||my_skim->pBeamScrapingFilter==0 || my_skim->pprimaryvertexFilter==0) continue ; if(!pileup_Gplus) continue ; if(run>211256) continue ; if(run<210676) continue ; //remove the runs with old alignment } if(coll=="PbP"){ if(pileup_Gplus==0) continue ; if(run<=211256) continue ; } } // if(evi%10000==1)cout <<" coll = " <<coll <<" weight = " <<weight <<" evt = " <<evi <<endl ; if(TMath::Abs(vz)>15.) continue ; if(my_hists->IsMC==kTRUE) weight*=fVz->Eval(vz); //run selection if(my_hists->IsMC!=kTRUE && coll=="PPb") { if(offSel->run<210676 ||offSel->run>211256) //211256: last pPb run (Pb goes to +eta) continue; } bool event_accepted = true; /* if(!(my_skim->pPAcollisionEventSelectionPA && my_skim->phfPosFilter1 && my_skim->phfNegFilter1 && my_skim->pBeamScrapingFilter && my_skim->pprimaryvertexFilter && my_skim->pVertexFilterCutGplus && TMath::Abs(offSel->vz)<15. ) ) event_accepted = false; */ if(event_accepted == false) continue; /* //if there is no jets or no PF candidates, skip the event if(my_ct->nref==0) continue ; */ //put the higher pthat cut if(my_hists->IsMC==kTRUE && my_ct->pthat>ptmax) continue ; if(my_ct->pthat>ptmax) cout <<"pthat =" <<my_ct->pthat <<endl ; if(coll=="HI"|| coll=="PP2011") my_hists->CenBin->Fill(hiBin*2.5); else my_hists->CenBin->Fill(hiBin); my_hists->Vertex->Fill(vz); // cout <<"vz =" <<vz <<endl ; if(coll=="HI"){ double centrality = hiBin*2.5 ; // my_hists->CenBin->Fill(offSel->hiBin); for(int ibin = 0 ; ibin <nbin; ibin++){ if(centrality >=centr[ibin] && centrality<centr[ibin+1]) curr_bin = ibin ; } } else if(coll=="PPb" || coll=="PbP"){ double centrality = HFbin ; for(int ibin = 0 ; ibin <nbin; ibin++){ if(centrality <hfEta4[ibin] && centrality>=hfEta4[ibin+1]) curr_bin = ibin ; } } else { curr_bin=nbin-1 ; // weight = 1. ; } // weight = 1. ; // cout << " cent_bin:" <<curr_bin <<endl ; if(evi%10000==1)cout <<" coll = " <<coll <<" weight = " <<weight <<" evt = " <<evi <<endl ; //cout << "start working222222\n"; // cout << "still working222222\n"; if(my_hists->IsMC==kFALSE)my_hists->VertexWt->Fill(vz+0.4847, weight); else my_hists->VertexWt->Fill(vz, weight); if(coll=="HI"|| coll=="PP2011") my_hists->CenBinWt->Fill(offSel->hiBin*2.5,weight); else my_hists->CenBinWt->Fill(offSel->hiBin,weight); //Tracks for event weights; eta-pt cut removed int trackMult = 0; for(int j=0;j<my_tr->nTrk;j++) { if(!((my_tr->highPurity[j]) && (fabs(my_tr->trkDz1[j]/my_tr->trkDzError1[j])<3) && (fabs(my_tr->trkDxy1[j]/my_tr->trkDxyError1[j])<3) && (my_tr->trkPtError[j]/my_tr->trkPt[j]<0.1) )) continue; trackMult++; } // Don't analyze 0 multiplicity events; correction added later if(trackMult==0) continue; // double evtWeight = 1.; // evtWeight = corr.getEventWeight(trackMult); weight*=corr.getEventWeight(trackMult); my_hists->NEvents[curr_bin]->Fill(1, weight); //Jets for event classification int jetMult = 0; double leadingJet = -999.; for(int j4i = 0; j4i < my_ct->nref ; j4i++) { // if( my_hists->IsMC==kTRUE && my_ct->subid[j4i] != 0) continue; if(TMath::Abs(my_ct->jteta[j4i])>3.) continue ; jetMult++; if (my_ct->rawpt[j4i]<15) continue; if (my_ct->jtpt[j4i]>leadingJet) { leadingJet = my_ct->jtpt[j4i]; } } /* if(leadingJet<0.) continue ; // Don't analyze 0 multiplicity events; correction added later if(trackMult==0) continue; */ //Tracks for event classification: same as for analysis bool jetAbove = false ; bool jetAbove40 = false; bool jetAbove60 = false; bool jetAbove75 = false; bool jetAbove95 = false; bool jetAbove120 = false; if(leadingJet>40. ){ jetAbove40 = true ; } if(leadingJet>60. ){ jetAbove60 = true ; } if(leadingJet>75. ){ jetAbove75 = true ; } if(leadingJet>95. ){ jetAbove95 = true ; } if(leadingJet>120. ){ jetAbove120 = true ; } if(!jetAbove40) Nevents[curr_bin]++ ; else if(jetAbove40 && !jetAbove60) Nevt_40_60[curr_bin]++; else if(jetAbove60 && !jetAbove75) Nevt_60_75[curr_bin]++; else if(jetAbove75 && !jetAbove95) Nevt_75_95[curr_bin]++; else if(jetAbove95 && !jetAbove120) Nevt_95_120[curr_bin]++; // if(jetAbove120) Nevt_120[curr_bin]++; else Nevt_120[curr_bin]++; if(TrigName=="Jet20") jetAbove = jetAbove40 && !jetAbove60 ; else if(TrigName=="Jet40") jetAbove = jetAbove60 && !jetAbove75 ; else if(TrigName=="Jet60") jetAbove = jetAbove75 && !jetAbove95 ; else if(TrigName=="Jet80") jetAbove = jetAbove95 && !jetAbove120 ; else if(TrigName=="Jet100") jetAbove = jetAbove120 ; else jetAbove = !jetAbove40 ; if(!jetAbove) continue ; // for inclusive jet analysis for(int j4i = 0; j4i < my_ct->nref ; j4i++) { double jetweight = 1; double jet_pt= my_ct->jtpt[j4i]; double raw_pt= my_ct->rawpt[j4i]; double jet_eta = my_ct->jteta[j4i]; if (my_ct->rawpt[j4i]<15) continue; int dEtaBin = -1. ; // if( my_hists->IsMC==kTRUE && my_ct->subid[j4i] != 0) continue; //for jet kinematcis cuts if(TMath::Abs(jet_eta)<=3.){ my_hists->jetptJES[curr_bin]->Fill(jet_pt, raw_pt/jet_pt, weight); if( my_hists->IsMC!=kTRUE ) jetweight*=(fUE->Eval(jet_pt))*C_rel->GetBinContent(C_rel->FindBin(jet_eta)); else jetweight*=((fUE->Eval(jet_pt))*fgaus->GetRandom()+1); my_hists->jetptEta[curr_bin]->Fill(jet_pt*jetweight, jet_eta, weight); if(coll=="PPb"){ if(TMath::Abs(jet_eta+0.465)<=1.) my_hists->jetpt[curr_bin]->Fill(jet_pt*jetweight, weight); } if(coll=="PbP"){ if(TMath::Abs(jet_eta-0.465)<=1.) my_hists->jetpt[curr_bin]->Fill(jet_pt*jetweight, weight); } if((jet_pt*jetweight)>100.) my_hists->jetEta[curr_bin]->Fill(jet_eta, weight); for(Int_t ieta = 0 ; ieta <netabin; ieta++){ if(coll=="PPb"){ if((jet_eta+0.465)>deta[ieta]&&(jet_eta+0.465)<=deta[ieta+1]) dEtaBin = ieta ; } else if(coll=="PbP"){ if((jet_eta-0.465)>deta[ieta]&&(jet_eta-0.465)<=deta[ieta+1]) dEtaBin = ieta ; } else { if((jet_eta+0.465)>deta[ieta]&&(jet_eta+0.465)<=deta[ieta+1]) dEtaBin = ieta ; } } //assign the eta bin for jets if(dEtaBin!=-1){ my_hists->jetptEtaBin[curr_bin][dEtaBin]->Fill(jet_pt*jetweight, weight); my_hists->NjetsEtaBin[curr_bin][dEtaBin]->Fill(1); } }// for jet kinematics cuts } //! jet loop /* //Leading Jets seach, for tracking efficiency double leadingJetPt = -1. ; Int_t leadingJetIndex = -1 ; for(int j = 0; j < my_ct->nref ; j++) { if (fabs(my_ct->jteta[j])>2.5) continue; if (my_ct->rawpt[j]<15) continue; // if( my_hists->IsMC==kTRUE && my_ct->subid[j] != 0) continue; if (my_ct->jtpt[j]>leadingJetPt) { leadingJetPt = my_ct->jtpt[j]; leadingJetIndex = j; } } if(leadingJetPt==-1) //for corrections leadingJetPt=10.; */ //for inclusive track analysis, without jet selection and requirement for(int itr = 0 ; itr < my_tr->nTrk ; itr++){ double tr_pt = my_tr->trkPt[itr]; double tr_phi = my_tr->trkPhi[itr]; double tr_eta = my_tr->trkEta[itr]; if(TMath::Abs(tr_eta)>2.4) continue ; // if(my_tr->trkPtError[itr]/my_tr->trkPt[itr]>=0.1 || TMath::Abs(my_tr->trkDz1[itr]/my_tr->trkDzError1[itr])>=3.0 ||TMath::Abs(my_tr->trkDxy1[itr]/my_tr->trkDxyError1[itr])>=3.0) continue ; //ridge cut for tracks if(!((my_tr->highPurity[itr]) && (fabs(my_tr->trkDz1[itr]/my_tr->trkDzError1[itr])<3) && (fabs(my_tr->trkDxy1[itr]/my_tr->trkDxyError1[itr])<3) && (my_tr->trkPtError[itr]/my_tr->trkPt[itr]<0.1) )) continue; Int_t TrkEtaBin = -1 ; for(Int_t ieta = 0 ; ieta <ntrketabin; ieta++){ if(coll=="PPb"){ if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else if(coll=="PbP"){ if((tr_eta-0.465)>dtrketa[ieta]&&(tr_eta-0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } if((my_tr->highPurity[itr])){ // if(tr_pt<trackcut) continue ; double trkweight=1. ; if(doTrackCorrections){ // if(corrMet=="Hist")trkweight = c->getTrackCorrection(itr); // else trkweight = c->getTrackCorrectionPara(itr); // trkweight = corr.getWeight(tr_pt,tr_eta,leadingJetPt); trkweight = corr.getWeight(tr_pt,tr_eta,0.); } my_hists->inctrkpt[curr_bin]->Fill(tr_pt, weight*trkweight); if(coll=="PPb"){ if(TMath::Abs(tr_eta+0.465)<=1.) my_hists->inctrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } else if(coll=="PbP"){ if( TMath::Abs(tr_eta-0.465)<=1.) my_hists->inctrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } else { if(TMath::Abs(tr_eta+0.465)<=1.) my_hists->inctrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); } my_hists->Ntrack[curr_bin]->Fill(1); if(TrkEtaBin!=-1) my_hists->inctrkptEtaBin[curr_bin][TrkEtaBin]->Fill(tr_pt, weight*trkweight); if(TrkEtaBin!=-1) my_hists->NtrkEtaBin[curr_bin][TrkEtaBin]->Fill(1); } //! high purity track cuts } //! inclusive track loop // for jet-track analysis TVector3 jet_vec; TVector3 track_vec; for(int j4i = 0; j4i < my_ct->nref ; j4i++) { jet_vec.SetPtEtaPhi(0, 0, 0); track_vec.SetPtEtaPhi(0, 0, 0); double jetweight = 1; double jet_pt= my_ct->jtpt[j4i]; double jet_eta = my_ct->jteta[j4i]; double jet_phi = my_ct->jtphi[j4i]; if (my_ct->rawpt[j4i]<15) continue; int dEtaBin = -1. ; // if( my_hists->IsMC==kTRUE && my_ct->subid[j4i]!= 0) continue; //for jet kinematcis cuts if(TMath::Abs(jet_eta)<=3.){ if( my_hists->IsMC!=kTRUE ) jetweight*=(fUE->Eval(jet_pt))*C_rel->GetBinContent(C_rel->FindBin(jet_eta)); else jetweight*=((fUE->Eval(jet_pt))*fgaus->GetRandom()+1); jet_vec.SetPtEtaPhi(jet_pt, jet_eta, jet_phi); // for track loop in each jet, do jet-track analysis for(int itr = 0 ; itr < my_tr->nTrk ; itr++){ double tr_pt = my_tr->trkPt[itr]; double tr_phi = my_tr->trkPhi[itr]; double tr_eta = my_tr->trkEta[itr]; if(TMath::Abs(tr_eta)>2.4) continue ; if(!((my_tr->highPurity[itr]) && (fabs(my_tr->trkDz1[itr]/my_tr->trkDzError1[itr])<3) && (fabs(my_tr->trkDxy1[itr]/my_tr->trkDxyError1[itr])<3) && (my_tr->trkPtError[itr]/my_tr->trkPt[itr]<0.1) )) continue; Int_t TrkEtaBin = -1 ; for(Int_t ieta = 0 ; ieta <ntrketabin; ieta++){ if(coll=="PPb"){ if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else if(coll=="PbP"){ if((tr_eta-0.465)>dtrketa[ieta]&&(tr_eta-0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } else if((tr_eta+0.465)>dtrketa[ieta]&&(tr_eta+0.465)<=dtrketa[ieta+1]) TrkEtaBin = ieta ; } track_vec.SetPtEtaPhi(tr_pt, tr_eta, tr_phi); if((my_tr->highPurity[itr])){ // if(tr_pt<trackcut) continue ; double trkweight=1. ; double dr = jet_vec.DeltaR(track_vec); if(dr>conesize) continue ; if(doTrackCorrections){ // if(corrMet=="Hist")trkweight = c->getTrackCorrection(itr); // else trkweight = c->getTrackCorrectionPara(itr); // trkweight = corr.getWeight(tr_pt,tr_eta,leadingJetPt); trkweight = corr.getWeight(tr_pt,tr_eta,0.); } my_hists->jettrkpt[curr_bin]->Fill(jet_pt*jetweight, tr_pt, weight*trkweight); if(coll=="PPb" && TMath::Abs(tr_eta+0.465)<=1.) my_hists->jettrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); if(coll=="PbP" && TMath::Abs(tr_eta-0.465)<=1.) my_hists->jettrkptM1P1[curr_bin]->Fill(tr_pt, weight*trkweight); if(TrkEtaBin!=-1) my_hists->jettrkPtEtaBin[curr_bin][TrkEtaBin]->Fill(tr_pt, weight*trkweight); } //! high purity track cuts } //end of track loop } //jet kinematics } //jet loop if(my_hists->IsMC==kTRUE&&DoGenAna){ //using the sim track to calculate the tracking efficiency for(int ipart = 0 ; ipart < my_tr->nParticle ; ipart++){ //sim track loop double gen_pt = my_tr->pPt[ipart]; double gen_phi = my_tr->pPhi[ipart]; double gen_eta = my_tr->pEta[ipart]; // if(gen_pt<trackcut)continue ; if(TMath::Abs(gen_eta)>2.4)continue ; if(my_tr->pNRec[ipart]>0&&((my_tr->mtrkQual[ipart]))) { if((my_tr->mtrkPtError[ipart]/my_tr->mtrkPt[ipart]<0.1 && TMath::Abs(my_tr->mtrkDz1[ipart]/my_tr->mtrkDzError1[ipart])<3.0 && TMath::Abs(my_tr->mtrkDxy1[ipart]/my_tr->mtrkDxyError1[ipart])<3.0)){ my_hists->incgenmatchpt[curr_bin]->Fill(gen_pt, weight); } //tracking cut } // matching hist my_hists->incgenpartpt[curr_bin]->Fill(gen_pt,weight); } //! sim track loop } //only runs on MC my_hists->NevtCounter[curr_bin]->SetBinContent(1, Nevents[curr_bin]*weight); my_hists->JetAbove40[curr_bin]->SetBinContent(1, Nevt_40_60[curr_bin]*weight); my_hists->JetAbove60[curr_bin]->SetBinContent(1, Nevt_60_75[curr_bin]*weight); my_hists->JetAbove75[curr_bin]->SetBinContent(1, Nevt_75_95[curr_bin]*weight); my_hists->JetAbove95[curr_bin]->SetBinContent(1, Nevt_95_120[curr_bin]*weight); my_hists->JetAbove120[curr_bin]->SetBinContent(1, Nevt_120[curr_bin]*weight); } ///event loop my_hists->Write(); // my_hists->Delete(); // delete my_hists; std::cout << "working done\n"; }
TestProblem AtlasDiJetMass(const int Nt, const int Nr, double tbins[], double rbins[], const double apar, const double bpar, const int nEvents, const double evtWeight) { // From "Fully Bayesian Unfolding" by G. Choudalakis. // see arXiv:1201.4612v4 // Recommended binning: // double bins[Nt+1] = {0}; // for (int j=0; j<=Nt; j++) // bins[j] = 500*TMath::Exp(0.15*j); static int id = 0; id++; TestProblem t; TRandom3 ran; // Mass distribution dN/dM TF1 *mass = new TF1("mass_dist", "TMath::Power(1.-x/7000,6.0)/TMath::Power(x/7000,4.8)", tbins[0], tbins[Nt]); // Generate test problem by MC convolution TH1D *hT = new TH1D("hT", "Truth mass dist. #hat{T}", Nt, tbins); TH1D *hTmc = new TH1D("hTmc", "MC Truth mass dist. #tilde{T}", Nt, tbins); TH1D *hD = new TH1D("hD", "Measured mass dist.", Nr, rbins); TH2D *hM = new TH2D("hM", "Migration matrix", Nr, rbins, Nt, tbins); hM->SetTitle(Form("%d x %d migration matrix M_{tr};" "mass (observed);mass (true)", Nr, Nt)); hT->SetLineWidth(2); hD->SetLineWidth(2); std::cout << Form("Generating test problem...") << std::flush; // Fill histos with MC events. // The response matrix gets more statistics than the data. double xt, xm, sigma; for (int i=0; i<nEvents; i++) { xt = mass->GetRandom(); sigma = apar*TMath::Sqrt(xt) + bpar*xt; xm = xt + ran.Gaus(0, sigma); hM->Fill(xm, xt); hTmc->Fill(xt, evtWeight); hD->Fill(xm, evtWeight); } // Simulate Poisson fluctuations in real data (integer content, empty bins) for (int r=1; r<=Nr; r++) hD->SetBinContent(r, ran.Poisson(hD->GetBinContent(r))); // The true truth \hat{T} double totmass = mass->Integral(tbins[0],tbins[Nt]); for (int j=1; j<=Nt; j++) { hT->SetBinContent(j, evtWeight*nEvents*mass->Integral(tbins[j-1], tbins[j])/totmass); hT->SetBinError(j, 0); } cout << "Done." << endl; // Projection of migration matrix to truth axis. hMt is the // numerator for efficiency. Bin contents should be counts // here. Elements are normalized to contain probabilities only after // projection & division by T-tilde. TH1D *hMt = hM->ProjectionY("hMt",1,Nr); TH1D *heff = (TH1D *)hMt->Clone("heff"); heff->Divide(hTmc); heff->Scale(evtWeight); hM->Scale(1./nEvents); hMt->Scale(1./nEvents); t.Response = hM; t.xTruth = hT; t.xTruthEst = hTmc; t.xIni = hMt; t.bNoisy = hD; t.eff = heff; return t; }
void reingold_ROOThomework(){ // Initalizing the Canvas TCanvas *c1 = new TCanvas("c1" , "Homework Plots" , 800 , 600 ); c1 -> Divide(3,3); // Defining the function with three Gaussians on a quadratic background. TF1 *func = new TF1("func", "pol2(0) + gaus(3) + gaus(6) + gaus(9)" , 0 , 100 ); Double_t param[12] = {9 , 1 , -0.01 , 100 , 20 , 1 , 100 , 50 , 1 , 100 , 80 , 1}; func->SetParameters(param); // quad, lin, const, A, mu, std , ... // Generting and filling the histograms TH1F *h0 = new TH1F("h0" , "Original Spectrum" , 100 , 0 , 100 ); for ( Int_t i = 0 ; i < 2000 ; i++ ){ Float_t rand = func->GetRandom(); h0->Fill(rand); } for ( Int_t j = 1 ; j < 4 ; j++ ){ c1->cd(j); h0->Draw(); } // Fitting the background using ShowBackground() c1->cd(4); TH1 *hPeaks = (TH1*) h0->Clone(); TH1 *hBkgrd = (TH1*) h0->Clone(); hPeaks->SetName("hPeaks"); hBkgrd->SetName("hBkgrd"); hBkgrd = h0->ShowBackground(15); h0->Draw(); hBkgrd->Draw("same"); hPeaks->Add(hBkgrd,-1); c1->cd(7); hPeaks->Draw(); // Fitting the background without excluding the peaks c1->cd(5); TH1F *hPeaks2 = (TH1F*) h0->Clone(); TH1F *hBkg2 = (TH1F*) h0->Clone(); hPeaks2->SetName("hPeaks2"); hBkg2->SetName("hBkg2"); TF1 *quadBack = new TF1("quadBack" , "pol2(0)" , 0 , 100 ); hBkg2->Fit(quadBack,"R+"); hBkg2->Draw(); c1->cd(8); hPeaks2->Add(quadBack , -1 ); hPeaks2->Draw(); // Fitting the background excluding the peaks c1->cd(6); TH1F *hPeaks3 = (TH1F*) h0->Clone(); TH1F *hBkg3 = (TH1F*) h0->Clone(); hPeaks3->SetName("hPeaks3"); hBkg3->SetName("hBkg3"); TF1 *quadBack2 = new TF1("quadBack2" , fQuad , 0 , 100 ,3); hBkg3->Fit(quadBack2,"R+"); hBkg3->Draw(); c1->cd(9); hPeaks3->Add(quadBack2 , -1 ); hPeaks3->Draw(); }
//void testFit(int count=3,Double_t ptmin=30.,Double_t ptmax=40,TString sample="PbPb") void compareUpgrade(int option=2) { int count; Double_t ptmin; Double_t ptmax; TString sample; int nmin,nmax,mymaxhisto; if (option==1) {count=3; ptmin=30.; ptmax=40; sample="PbPb"; mymaxhisto=2000; }; if (option==2) {count=1; ptmin=2.; ptmax=3; sample="PbPbMB"; mymaxhisto=600000;}; TCanvas* c= new TCanvas(Form("c%d",count),"",600,600); TFile *file=new TFile(Form("FitsFiles/Fits_%s_%d.root",sample.Data(), count)); TH1D* h = (TH1D*)file->Get(Form("h-%d",count)); TH1D* hMCSignal = (TH1D*)file->Get(Form("hMCSignal-%d",count)); TH1D* hMCSwapped = (TH1D*)file->Get(Form("hMCSwapped-%d",count)); TF1* f = new TF1(Form("f%d",count),"[0]*([7]*([9]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[9])*Gaus(x,[1],[10])/(sqrt(2*3.14159)*[10]))+(1-[7])*Gaus(x,[1],[8])/(sqrt(2*3.14159)*[8]))+[3]+[4]*x+[5]*x*x+[6]*x*x*x", 1.7, 2.0); f->SetParLimits(4,-1000,1000); f->SetParLimits(10,0.001,0.05); f->SetParLimits(2,0.01,0.1); f->SetParLimits(8,0.02,0.2); f->SetParLimits(7,0,1); f->SetParLimits(9,0,1); f->SetParameter(0,setparam0); f->SetParameter(1,setparam1); f->SetParameter(2,setparam2); f->SetParameter(10,setparam10); f->SetParameter(9,setparam9); f->FixParameter(8,setparam8); f->FixParameter(7,1); f->FixParameter(1,fixparam1); f->FixParameter(3,0); f->FixParameter(4,0); f->FixParameter(5,0); f->FixParameter(6,0); h->GetEntries(); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSignal->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(1,f->GetParameter(1)); f->FixParameter(2,f->GetParameter(2)); f->FixParameter(10,f->GetParameter(10)); f->FixParameter(9,f->GetParameter(9)); f->FixParameter(7,0); f->ReleaseParameter(8); f->SetParameter(8,setparam8); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); hMCSwapped->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); f->FixParameter(7,hMCSignal->Integral(0,1000)/(hMCSwapped->Integral(0,1000)+hMCSignal->Integral(0,1000))); f->FixParameter(8,f->GetParameter(8)); f->ReleaseParameter(3); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(6); f->SetLineColor(kRed); /* TCanvas*mycanvas=new TCanvas("mycanvas","mycanvas",1000,500); mycanvas->Divide(2,1); mycanvas->cd(1); hMCSignal->Draw(); mycanvas->cd(2); hMCSwapped->Draw(); mycanvas->SaveAs("mycanvas.pdf"); */ h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"q","",minhisto,maxhisto); f->ReleaseParameter(1); //f->ReleaseParameter(2); // you need to release these two parameters if you want to perform studies on the sigma shape //f->ReleaseParameter(10); // you need to release these two parameters if you want to perform studies on the sigma shape h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L q","",minhisto,maxhisto); h->Fit(Form("f%d",count),"L m","",minhisto,maxhisto); std::cout<<"parameter 10="<<f->GetParameter(10)<<std::endl; TF1* background = new TF1(Form("background%d",count),"[0]+[1]*x+[2]*x*x+[3]*x*x*x"); background->SetParameter(0,f->GetParameter(3)); background->SetParameter(1,f->GetParameter(4)); background->SetParameter(2,f->GetParameter(5)); background->SetParameter(3,f->GetParameter(6)); background->SetLineColor(4); background->SetRange(minhisto,maxhisto); background->SetLineStyle(2); TF1* mass = new TF1(Form("fmass%d",count),"[0]*([3]*([4]*Gaus(x,[1],[2])/(sqrt(2*3.14159)*[2])+(1-[4])*Gaus(x,[1],[5])/(sqrt(2*3.14159)*[5])))"); mass->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2),f->GetParameter(7),f->GetParameter(9),f->GetParameter(10)); mass->SetParError(0,f->GetParError(0)); mass->SetParError(1,f->GetParError(1)); mass->SetParError(2,f->GetParError(2)); mass->SetParError(3,f->GetParError(7)); mass->SetParError(4,f->GetParError(9)); mass->SetParError(5,f->GetParError(10)); mass->SetFillColor(kOrange-3); mass->SetFillStyle(3002); mass->SetLineColor(kOrange-3); mass->SetLineWidth(3); mass->SetLineStyle(2); TF1* massSwap = new TF1(Form("fmassSwap%d",count),"[0]*(1-[2])*Gaus(x,[1],[3])/(sqrt(2*3.14159)*[3])"); massSwap->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(7),f->GetParameter(8)); massSwap->SetParError(0,f->GetParError(0)); massSwap->SetParError(1,f->GetParError(1)); massSwap->SetParError(2,f->GetParError(7)); massSwap->SetParError(3,f->GetParError(8)); massSwap->SetFillColor(kGreen+4); massSwap->SetFillStyle(3005); massSwap->SetLineColor(kGreen+4); massSwap->SetLineWidth(3); massSwap->SetLineStyle(1); h->SetXTitle("m_{#piK} (GeV/c^{2})"); h->SetYTitle("Entries / (5 MeV/c^{2})"); h->GetXaxis()->CenterTitle(); h->GetYaxis()->CenterTitle(); h->SetAxisRange(0,h->GetMaximum()*1.4*1.2,"Y"); h->GetXaxis()->SetTitleOffset(1.3); h->GetYaxis()->SetTitleOffset(1.8); h->GetXaxis()->SetLabelOffset(0.007); h->GetYaxis()->SetLabelOffset(0.007); h->GetXaxis()->SetTitleSize(0.045); h->GetYaxis()->SetTitleSize(0.045); h->GetXaxis()->SetTitleFont(42); h->GetYaxis()->SetTitleFont(42); h->GetXaxis()->SetLabelFont(42); h->GetYaxis()->SetLabelFont(42); h->GetXaxis()->SetLabelSize(0.04); h->GetYaxis()->SetLabelSize(0.04); h->SetMarkerSize(0.8); h->SetMarkerStyle(20); h->SetStats(0); h->Draw("e"); background->Draw("same"); mass->SetRange(minhisto,maxhisto); mass->Draw("same"); massSwap->SetRange(minhisto,maxhisto); massSwap->Draw("same"); f->Draw("same"); Double_t yield = mass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldtotal = f->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldErr = mass->Integral(minhisto,maxhisto)/binwidthmass*mass->GetParError(0)/mass->GetParameter(0); std::cout<<"yield signal="<<yield<<std::endl; std::cout<<"total counts="<<yieldtotal<<std::endl; TLegend* leg = new TLegend(0.65,0.58,0.82,0.88,NULL,"brNDC"); leg->SetBorderSize(0); leg->SetTextSize(0.04); leg->SetTextFont(42); leg->SetFillStyle(0); leg->AddEntry(h,"Data","pl"); leg->AddEntry(f,"Fit","l"); leg->AddEntry(mass,"D^{0}+#bar{D^{#lower[0.2]{0}}} Signal","f"); leg->AddEntry(massSwap,"K-#pi swapped","f"); leg->AddEntry(background,"Combinatorial","l"); leg->Draw("same"); TLatex Tl; Tl.SetNDC(); Tl.SetTextAlign(12); Tl.SetTextSize(0.04); Tl.SetTextFont(42); Tl.DrawLatex(0.18,0.93, "#scale[1.25]{CMS} Performance"); Tl.DrawLatex(0.65,0.93, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TLatex* tex; tex = new TLatex(0.22,0.78,Form("%.1f < p_{T} < %.1f GeV/c",ptmin,ptmax)); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.22,0.83,"|y| < 1.0"); tex->SetNDC(); tex->SetTextFont(42); tex->SetTextSize(0.04); tex->SetLineWidth(2); tex->Draw(); h->GetFunction(Form("f%d",count))->Delete(); TH1F* histo_copy_nofitfun = ( TH1F * ) h->Clone("histo_copy_nofitfun"); histo_copy_nofitfun->Draw("esame"); TH1D* hTest = new TH1D("hTest","",nbinsmasshisto,minhisto,maxhisto); for (int m=0;m<yieldtotal;m++){ double r = f->GetRandom(); hTest->Fill(r); } TF1* ffaketotal=(TF1*)f->Clone("ffake"); TF1* ffakemass=(TF1*)mass->Clone("ffakemass"); TF1* ffakebackground=(TF1*)background->Clone("ffakebackground"); TF1* ffakemassSwap=(TF1*)massSwap->Clone("ffakemassSwap"); Double_t yieldtotal_original = ffaketotal->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldmass_original = ffakemass->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldbackground_original = ffakebackground->Integral(minhisto,maxhisto)/binwidthmass; Double_t yieldswapped_original = ffakemassSwap->Integral(minhisto,maxhisto)/binwidthmass; TH1D* hTestFake = new TH1D("hTestFake","",nbinsmasshisto,minhisto,maxhisto); ffakemass->SetParameter(2,ffaketotal->GetParameter(2)*0.8); ffakemass->SetParameter(10,ffaketotal->GetParameter(10)*0.8); Double_t yieldmass_modified= ffakemass->Integral(minhisto,maxhisto)/binwidthmass; cout<<"mass original="<<yieldmass_original<<endl; cout<<"mass modified="<<yieldmass_modified<<endl; for (int m=0;m<yieldmass_original*scalefactor;m++){ double r = ffakemass->GetRandom(); hTestFake->Fill(r); } for (int m=0;m<(int)(yieldbackground_original*scalefactor*bkgreduction);m++){ double r = ffakebackground->GetRandom(); hTestFake->Fill(r); } for (int m=0;m<(int)(yieldswapped_original*scalefactor*bkgreduction);m++){ double r = ffakemassSwap->GetRandom(); hTestFake->Fill(r); } TCanvas*c2=new TCanvas("c2","c2",500,500); c2->cd(); hTest->SetMaximum(2000); hTest->SetXTitle("m_{#piK} (GeV/c^{2})"); hTest->SetYTitle("Entries / (5 MeV/c^{2})"); hTest->GetXaxis()->CenterTitle(); hTest->GetYaxis()->CenterTitle(); hTest->SetAxisRange(0,hTest->GetMaximum()*1.*1.2,"Y"); hTest->GetXaxis()->SetTitleOffset(1.3); hTest->GetYaxis()->SetTitleOffset(1.8); hTest->GetXaxis()->SetLabelOffset(0.007); hTest->GetYaxis()->SetLabelOffset(0.007); hTest->GetXaxis()->SetTitleSize(0.045); hTest->GetYaxis()->SetTitleSize(0.045); hTest->GetXaxis()->SetTitleFont(42); hTest->GetYaxis()->SetTitleFont(42); hTest->GetXaxis()->SetLabelFont(42); hTest->GetYaxis()->SetLabelFont(42); hTest->GetXaxis()->SetLabelSize(0.04); hTest->GetYaxis()->SetLabelSize(0.04); hTest->SetMarkerSize(0.8); hTest->SetMarkerStyle(20); hTest->SetStats(0); hTest->Draw("e"); hTest->SetLineColor(1); hTest->SetMarkerColor(1); hTestFake->SetLineColor(2); hTestFake->SetMarkerColor(2); hTest->Draw("ep"); hTestFake->Draw("epsame"); TLegend* myleg = new TLegend(0.2177419,0.6292373,0.6633065,0.7266949,NULL,"brNDC"); myleg->SetBorderSize(0); myleg->SetTextSize(0.04); myleg->SetTextFont(42); myleg->SetFillStyle(0); myleg->AddEntry(hTest,"Current CMS, |y|<1, L_{int}=0.5/nb","pl"); myleg->AddEntry(hTestFake,"Upgraded CMS, |y|<2, L_{int}=1.5/nb","l"); myleg->Draw("same"); TLatex* mytex; mytex = new TLatex(0.22,0.83,Form("%.0f < p_{T} < %.0f GeV/c",ptmin,ptmax)); mytex->SetNDC(); mytex->SetTextFont(42); mytex->SetTextSize(0.04); mytex->SetLineWidth(2); mytex->Draw(); TLatex* mychannel; mychannel = new TLatex(0.22,0.765,"D^{0} #rightarrow K#pi"); mychannel->SetNDC(); mychannel->SetTextFont(42); mychannel->SetTextSize(0.055); mychannel->SetLineWidth(2); mychannel->Draw(); TLatex myTl; myTl.SetNDC(); myTl.SetTextAlign(12); myTl.SetTextSize(0.04); myTl.SetTextFont(42); myTl.DrawLatex(0.2,0.90, "#scale[1.25]{CMS} Performance"); myTl.DrawLatex(0.63,0.90, Form("%s #sqrt{s_{NN}} = 5.02 TeV",collisionsystem.Data())); TFile*foutput=new TFile(Form("foutput_%s.root",sample.Data()),"recreate"); foutput->cd(); hTest->SetName("hTest"); hTestFake->SetName("hTestFake"); hTest->SetMaximum(mymaxhisto); hTest->Write(); hTestFake->SetMaximum(mymaxhisto); hTestFake->Write(); hMCSignal->Write(); hMCSwapped->Write(); c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.pdf",sample.Data())); c2->SaveAs(Form("PlotsUpgrade/canvasPerformance%s.png",sample.Data())); }
void toyMC_sigFixTail(int runIeta=-1, int runIpt=-1){ cout << "ROOT version = " << gROOT->GetVersion() << endl; // gSystem->mkdir("toysPlot"); char tmp[1000]; TH1D* htoyResult_pull[nEtaBin][nPtBin]; TH1D* htoyResult_bias[nEtaBin][nPtBin]; TFile* finFile = new TFile("/afs/cern.ch/user/s/syu/scratch0/sigSys/template_comb3Iso_template.root"); TH1D* hTemplate = (TH1D*)finFile->FindObjectAny("h_EB_comb3Iso_EGdata_pt21"); hTemplate->Reset(); char* dec[2] = {"EB","EE"}; for(int ieta=0; ieta<nEtaBin; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ htoyResult_pull[ieta][ipt] = new TH1D(Form("hpull_%s_pt_%d", dec[ieta], (int)fBinsPt[ipt]), "",50,-5.0,5.0); htoyResult_bias[ieta][ipt] = new TH1D(Form("hbias_%s_pt_%d", dec[ieta], (int)fBinsPt[ipt]), "",100,-0.5,0.5); } } TH1D* hfit_sig; TH1D* hfit_bkg; TH1D* hTemplate_S[nEtaBin][nPtBin]; TH1D* hTemplate_B[nEtaBin][nPtBin]; TH1D* hdata_data[nEtaBin][nPtBin]; TH1D* htemp; for(int ieta=0; ieta< nEtaBin; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ if(runIeta>=0 && ieta!=runIeta)continue; if(runIpt>=0 && ipt!=runIpt)continue; // getting histograms from data root file sprintf(tmp,"h_%s_comb3Iso_EGdata_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hdata_data[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hdata_data[ieta][ipt]->Rebin(REBINNINGS_DATA); // filling unbinned data htemp = (TH1D*)hdata_data[ieta][ipt]->Clone("htemp"); htemp->Reset(); sprintf(tmp,"h_%s_comb3Iso_sig_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hTemplate_S[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hTemplate_S[ieta][ipt]->Rebin(REBINNINGS_TEMP); if(ieta==0 && fBinsPt[ipt]>=50) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],50); else if(ieta==0 ) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],(int)fBinsPt[ipt]); else if(ieta==1 && fBinsPt[ipt]>=60) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],60); else if(ieta==1) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hTemplate_B[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); // if((ieta==0 && ipt<8) || // (ieta==1 && ipt<9)) hTemplate_B[ieta][ipt]->Rebin(REBINNINGS_TEMP); const int NRETURN = 3*NPAR; Double_t myFitPar[NRETURN]={0}; Double_t* FuncFitResult; FuncFitResult = Ifit("/afs/cern.ch/user/s/syu/scratch0/sigSys/EGdata_comb3Iso_et.dat", hTemplate_S[ieta][ipt],hTemplate_B[ieta][ipt], hdata_data[ieta][ipt], myFitPar, (int)fBinsPt[ipt], dec[ieta],2); Double_t nsig_input = FuncFitResult[0]; Double_t nsigerr_input = FuncFitResult[1]; Double_t nbkg_input = FuncFitResult[2]; Double_t nbkgerr_input = FuncFitResult[3]; Double_t nsig_input5GeV = FuncFitResult[4]; Double_t nsigerr_input5GeV = FuncFitResult[5]; Double_t sigFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) sigFitPar[ipar] = myFitPar[ipar]; Double_t bkgFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) bkgFitPar[ipar] = myFitPar[ipar+NPAR]; Double_t sumFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) sumFitPar[ipar] = myFitPar[ipar+NPAR*2]; TF1* fsig = new TF1("fsig", exp_conv, fit_lo, fit_hi, 11); fsig->SetParameters(sigFitPar); fsig->SetParameter(0,1.0); mySigPDFnorm = fsig->Integral(fit_lo,fit_hi); cout << "mySigPDFnorm = " << mySigPDFnorm << endl; TF1* fbkg = new TF1("fbkg", expinv_power, fit_lo, fit_hi, 11); fbkg->SetParameters(bkgFitPar); fbkg->SetParameter(4,1.0); myBkgPDFnorm = fbkg->Integral(fit_lo, fit_hi); cout << "myBkgPDFnorm = " << myBkgPDFnorm << endl; TF1* fsum = new TF1("fsum",mysum_norm, fit_lo, fit_hi,11); fsum->SetParameters(sumFitPar); cout << "Using nsig_input = " << nsig_input << endl; cout << "Using nbkg_input = " << nbkg_input << endl; cout << "Using nsig_input5GeV = " << nsig_input5GeV << endl; fsum->SetParameter(0, nsig_input*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(4, nbkg_input*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetLineColor(2); fsum->SetNpx(2500); // cout << "fsum integral = " << fsum->Integral(fit_lo,fit_hi) << endl; // for(int ipar=0; ipar<NPAR; ipar++)cout << "fsum par " << ipar << " = " << fsum->GetParameter(ipar) << endl; // FILE *infile = fopen("EGdata_comb3Iso_et.dat","r"); // float xdata, xdata1, xdata2; // for (int i=0;i<datapoint;i++){ // fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2); // if( xdata1 >= fBinsPt[ipt] && xdata1 < fBinsPt[ipt+1] && xdata<20.) { // if(TMath::Abs(xdata2)<1.45) { // htemp->Fill(xdata); // } // } // } // TCanvas* myCanvas = new TCanvas("myCanvas","myCanvas"); // htemp->Draw(); // fsum->Draw("same"); // // loops over toys for(int iexp=0; iexp<NEXP; iexp++){ TH1D* htoyMC_data = (TH1D*)hdata_data[ieta][ipt]->Clone("htoyMC_data"); htoyMC_data->Reset(); TH1D* htoyMC_sig = (TH1D*)hTemplate_S[ieta][ipt]->Clone("htoyMC_sig"); // htoyMC_sig->Reset(); TH1D* htoyMC_bkg = (TH1D*)hTemplate_B[ieta][ipt]->Clone("htoyMC_bkg"); // htoyMC_bkg->Reset(); UInt_t nowSeed = (unsigned long)gSystem->Now(); gRandom->SetSeed(nowSeed); int nsiggen = gRandom->Poisson(nsig_input); int nbkggen = gRandom->Poisson(nbkg_input); int ndata = nsiggen + nbkggen; // reset toy MC data htoyMC_data->Reset(); ofstream fout; std::string toyData = Form("/afs/cern.ch/user/s/syu/scratch0/sigSys/toy_%d_%d.dat",ieta,ipt); fout.open(toyData.data()); for(int ieve=0; ieve < nsiggen; ieve++) { Double_t xvalue = fsig->GetRandom(fit_lo,fit_hi); fout << xvalue << " " << 0.5*(fBinsPt[ipt]+fBinsPt[ipt+1]) << " " << fBinsEta[ieta] << endl; htoyMC_data->Fill(xvalue); } for(int ieve=0; ieve < nbkggen; ieve++) { Double_t xvalue = fbkg->GetRandom(fit_lo,fit_hi); fout << xvalue << " " << 0.5*(fBinsPt[ipt]+fBinsPt[ipt+1]) << " " << fBinsEta[ieta] << endl; htoyMC_data->Fill(xvalue); } fout.close(); // htoyMC_data->FillRandom("fsig",nsiggen); // htoyMC_data->FillRandom("fbkg",nbkggen); // htoyMC_data->Draw(); // cout << "Generated ndata = " << ndata << "\t nsiggen = " << nsiggen << " \t nbkggen = " << // nbkggen << endl; Double_t* toyFitResult; Double_t toyMyFitPar[NRETURN]={0}; toyFitResult = Ifit(toyData.data(), htoyMC_sig, htoyMC_bkg, htoyMC_data, toyMyFitPar, (int)fBinsPt[ipt], dec[ieta],2); Double_t nsigtoyfit = toyFitResult[0]; Double_t errnsigtoyfit = toyFitResult[1]; Double_t nbkgtoyfit = toyFitResult[2]; Double_t errnbkgtoyfit = toyFitResult[3]; Double_t nsigtoyfit_5GeV = toyFitResult[4]; Double_t errnsigtoyfit_5GeV = toyFitResult[5]; Double_t toySumFitPar[NPAR]={0}; for(int ipar=0; ipar<NPAR; ipar++) toySumFitPar[ipar] = toyMyFitPar[ipar+NPAR*2]; fsum->SetParameters(toySumFitPar); fsum->SetParameter(0, nsigtoyfit*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(4, nbkgtoyfit*hdata_data[ieta][ipt]->GetBinWidth(2)); // fsum->SetParameter(0, (float)nsiggen*hdata_data[ieta][ipt]->GetBinWidth(2)); // fsum->SetParameter(4, (float)nbkggen*hdata_data[ieta][ipt]->GetBinWidth(2)); // if(iexp%20==0){ // TCanvas* myCanvas = new TCanvas("myCanvas","SHIT"); // htoyMC_data->SetMaximum(htoyMC_data->GetMaximum()*1.5); // htoyMC_data->Draw(); // fsum->Draw("same"); // myCanvas->Print(Form("toysPlot/fit_%03i.gif",iexp)); // delete myCanvas; // } // cout << "fsum integral = " << fsum->Integral(-1,20) << endl; // for(int ipar=0; ipar<NPAR; ipar++)cout << "fsum par " << ipar << " = " << fsum->GetParameter(ipar) << endl; // cout << "Total data = " << nsiggen + nbkggen << endl; // cout << "toyMC_data->Integral() = " << htoyMC_data->Integral() << endl; // cout << "Expected nsig = " << nsiggen << " and Fitted nsig = " << nsigtoyfit << endl; // cout << "Expected nbkg = " << nbkggen << " and Fitted nbkg = " << nbkgtoyfit << endl; // cout << "Input nsig = " << nsig_input << endl; Double_t pull = (nsigtoyfit_5GeV - nsig_input5GeV)/errnsigtoyfit_5GeV; htoyResult_pull[ieta][ipt]->Fill(pull); Double_t bias = (nsigtoyfit_5GeV - nsig_input5GeV)/nsig_input5GeV; htoyResult_bias[ieta][ipt]->Fill(bias); } // end loops of toys TCanvas* myToyCanvas = new TCanvas("myToyCanvas","",1000,500); myToyCanvas->Divide(2,1); myToyCanvas->cd(1); htoyResult_pull[ieta][ipt]->SetFillColor(kAzure-4); htoyResult_pull[ieta][ipt]->SetFillStyle(1001); htoyResult_pull[ieta][ipt]->Draw(); myToyCanvas->cd(2); htoyResult_bias[ieta][ipt]->SetFillColor(kViolet-9); htoyResult_bias[ieta][ipt]->SetFillStyle(1001); htoyResult_bias[ieta][ipt]->Draw(); delete fsig; delete fbkg; } // end of loop over pt bins } TFile* outFile = new TFile(Form("/afs/cern.ch/user/s/syu/scratch0/sigSys/fixsigtail_%s_pt%d.root", dec[runIeta], (int)fBinsPt[runIpt]), "recreate"); for(int ieta=0; ieta < nEtaBin; ieta++){ for(int ipt=0; ipt < nPtBin; ipt++){ if(htoyResult_pull[ieta][ipt]->GetEntries()>0) htoyResult_pull[ieta][ipt]->Write(); if(htoyResult_bias[ieta][ipt]->GetEntries()>0) htoyResult_bias[ieta][ipt]->Write(); } } outFile->Close(); }
void process_event() { bool WithProj = true; double x_cm = 0; double y_cm = 0; //Compute centroid for(unsigned int j=0; j<particles_targ.size(); j++) { x_cm += particles_targ[j].x; y_cm += particles_targ[j].y; } double Count = (double) particles_targ.size(); if (WithProj) { for(unsigned int j=0; j<particles_proj.size(); j++) { x_cm += particles_proj[j].x; y_cm += particles_proj[j].y; } Count += (double) particles_proj.size(); } x_cm = x_cm/Count; y_cm = y_cm/Count; //Shift origin to centroid for(unsigned int j=0; j<particles_targ.size(); j++) { particles_targ[j].x = particles_targ[j].x - x_cm; particles_targ[j].y = particles_targ[j].y - y_cm; } if (WithProj) { //Shift origin to centroid for(unsigned int j=0; j<particles_proj.size(); j++) { particles_proj[j].x = particles_proj[j].x - x_cm; particles_proj[j].y = particles_proj[j].y - y_cm; } } //Compute eccentricity //JLN - Option to do with blurred Gaussian distributions... (does not change above x_cm,y_cm calculation) bool NucleonSmear = true; double SmearSigma = 0.4; // units of fm TF1 *fradius = new TF1("fradius","x*TMath::Exp(-x*x/(2*[0]*[0]))",0.0,2.0); fradius->SetParameter(0,SmearSigma); TF1 *fphi = new TF1("fphi","1.0",0.0,2.0*TMath::Pi()); int SmearSamplings = 100; if (NucleonSmear) Count = 0; double qx_2 = 0; double qy_2 = 0; double qx_3 = 0; double qy_3 = 0; double phi = 0; double rsq = 0; double r = 0; double e2 = 0; double e3 = 0; //Loop over all particles in the target nucleus and compute eccentricity for(unsigned int i=0; i<particles_targ.size(); i++) { if (!NucleonSmear) { r = get_r(particles_targ[i].x,particles_targ[i].y); phi = get_phi(particles_targ[i].x,particles_targ[i].y); qx_2 += r*r*TMath::Cos(2*phi); qy_2 += r*r*TMath::Sin(2*phi); qx_3 += r*r*TMath::Cos(3*phi); qy_3 += r*r*TMath::Sin(3*phi); rsq += r*r; } if (NucleonSmear) { for (int is=0;is<SmearSamplings;is++) { double rtemp = fradius->GetRandom(); double phitemp = fphi->GetRandom(); double xtemp = particles_targ[i].x + rtemp*TMath::Sin(phitemp); double ytemp = particles_targ[i].y + rtemp*TMath::Cos(phitemp); r = TMath::Sqrt(xtemp*xtemp + ytemp*ytemp); phi = TMath::ATan2(ytemp,xtemp); qx_2 += r*r*TMath::Cos(2*phi); qy_2 += r*r*TMath::Sin(2*phi); qx_3 += r*r*TMath::Cos(3*phi); qy_3 += r*r*TMath::Sin(3*phi); rsq += r*r; Count = Count + 1; // noting this is a double } } } if (WithProj) { for(unsigned int i=0; i<particles_proj.size(); i++) { if (!NucleonSmear) { r = get_r(particles_proj[i].x,particles_proj[i].y); phi = get_phi(particles_proj[i].x,particles_proj[i].y); qx_2 += r*r*TMath::Cos(2*phi); qy_2 += r*r*TMath::Sin(2*phi); qx_3 += r*r*TMath::Cos(3*phi); qy_3 += r*r*TMath::Sin(3*phi); rsq += r*r; } if (NucleonSmear) { for (int is=0;is<SmearSamplings;is++) { double rtemp = fradius->GetRandom(); double phitemp = fphi->GetRandom(); double xtemp = particles_proj[i].x + rtemp*TMath::Sin(phitemp); double ytemp = particles_proj[i].y + rtemp*TMath::Cos(phitemp); r = TMath::Sqrt(xtemp*xtemp + ytemp*ytemp); phi = TMath::ATan2(ytemp,xtemp); qx_2 += r*r*TMath::Cos(2*phi); qy_2 += r*r*TMath::Sin(2*phi); qx_3 += r*r*TMath::Cos(3*phi); qy_3 += r*r*TMath::Sin(3*phi); rsq += r*r; Count = Count + 1; // noting this is a double } } } } qx_2 = qx_2/Count; qy_2 = qy_2/Count; qx_3 = qx_3/Count; qy_3 = qy_3/Count; rsq = rsq /Count; e2 = TMath::Sqrt(qx_2*qx_2 + qy_2*qy_2)/rsq; e3 = TMath::Sqrt(qx_3*qx_3 + qy_3*qy_3)/rsq; psi_2 = (TMath::ATan2(qy_2,qx_2) + TMath::Pi())/2; psi_3 = (TMath::ATan2(qy_3,qx_3) + TMath::Pi())/3; psi2_file << psi_2 << "\n"; psi3_file << psi_3 << "\n"; epsilon2_file << e2 << "\n"; //cout << "e2 = " << e2 << endl; //cout << "psi_2 = " << psi_2 << endl; if (Count == 1) e2 = 0.0; //Accumulate event-by-event eccentricity to compute average for all events epsilon_2 += e2; epsilon_3 += e3; //Accumulate event-by-event psi2/3 to compute average for all events psi_2_accum += psi_2; psi_3_accum += psi_3; }
void Fragment(Int_t nev=0, Int_t debug=0) { gROOT->Reset(); Float_t b; Int_t nspectp, nspectn, nspectpfree, nspectnfree; Int_t zz[100], nn[100], nalpha, NFrag, ztot, ntot, ndeu; void spectator(Float_t, Int_t*, Int_t*); TH2F *hsp = new TH2F("hsp","Spectator protons vs b",50,0.,20.,90,0.,90.); hsp -> SetXTitle("b (fm)"); hsp -> SetYTitle("Num. of spectator protons"); TH2F *hsn = new TH2F("hsn","Spectator neutrons vs b",50,0.,20.,130,0.,130.); hsn -> SetXTitle("b (fm)"); hsn -> SetYTitle("Num. of spectator neutrons"); TH2F *hFragp = new TH2F("hFragp","Free spectator protons vs b",50,0.,20.,60,0.,60.); hFragp -> SetXTitle("b (fm)"); hFragp -> SetYTitle("Num. of free spectator protons"); TH2F *hFragn = new TH2F("hFragn","Free spectator neutrons vs b",50,0.,20.,80,0.,80.); hFragn -> SetXTitle("b (fm)"); hFragn -> SetYTitle("Num. of free spectator neutrons"); TF1 *funb = new TF1("funb","x",0,20); for(Int_t ievent=0; ievent<nev; ievent++){ if(ievent%1000==0){printf("Processing event %d\n",ievent);} b= Float_t(funb->GetRandom()); spectator(b, &nspectp, &nspectn); hsp -> Fill(b,nspectp); hsn -> Fill(b,nspectn); AliZDCFragment *gallio = new AliZDCFragment(b); for(Int_t j=0; j<=99; j++){ zz[j] =0; nn[j] =0; } // // Generation of fragments gallio->GenerateIMF(); nalpha = gallio->GetNalpha(); NFrag = gallio->GetFragmentNum(); // // Attach neutrons ztot = gallio->GetZtot(); ntot = gallio->GetNtot(); gallio->AttachNeutrons(); // nspectpfree = (nspectp-ztot-2*nalpha); nspectnfree = (nspectn-ntot-2*nalpha); // Removing deuterons ndeu = (Int_t) (nspectnfree*gallio->DeuteronNumber()); nspectpfree -= ndeu; nspectnfree -= ndeu; // hFragp -> Fill(b, nspectpfree); hFragn -> Fill(b, nspectnfree); // // Print if(debug == 1){ printf("\n b = %f",b); printf(" #spect p = %d, #spect n = %d\n",nspectp,nspectn); printf(" #spect p free = %d, #spect n free = %d\n",nspectpfree,nspectnfree); printf(" #fragments = %f ",NFrag); /*for(Int_t i=0; i<NFrag; i++){ printf("\n ZZ[%d] = %d, NN[%d] = %d\n",i,zz[i],i,nn[i]); }*/ printf(" NAlpha = %d, Ztot = %d, Ntot = %d\n\n",nalpha,ztot,ntot); } delete gallio; } //Event loop TProfile *profsp = hsp->ProfileX("profsp",-1,-1,"s"); TProfile *profsn = hsn->ProfileX("profsn",-1,-1,"s"); TProfile *profFragp = hFragp->ProfileX("profFragp",-1,-1,"s"); TProfile *profFragn = hFragn->ProfileX("profFragn",-1,-1,"s"); //*********************************************************** // #### ROOT initialization gROOT->Reset(); gStyle->SetCanvasColor(10); gStyle->SetFrameFillColor(10); gStyle->SetPalette(1); gStyle->SetOptStat(0); // TCanvas *c1 = new TCanvas("c1","Fragmentation I",0,0,700,700); c1->cd(); c1->SetFillColor(kAzure+7); c1->Divide(2,2); c1->cd(1); hsp -> Draw("colz"); c1->cd(2); hsn -> Draw("colz"); c1->cd(3); hFragp -> Draw("colz"); c1->cd(4); hFragn -> Draw("colz"); // c1->Print("Fragment1.gif"); // TCanvas *c2 = new TCanvas("c2","Fragmentation II",300,10,700,700); c2->cd(); c2->SetFillColor(kAzure+10); c2->Divide(2,2); c2->cd(1); profsp ->SetLineColor(kRed); profsp ->SetLineWidth(2); profsp -> Draw("colz"); c2->cd(2); profsn ->SetLineColor(kRed); profsn ->SetLineWidth(2); profsn -> Draw("colz"); c2->cd(3); profFragp -> Draw("colz"); profFragp ->SetLineColor(kAzure); profFragp ->SetLineWidth(2); c2->cd(4); profFragn -> Draw("colz"); profFragn ->SetLineColor(kAzure); profFragn ->SetLineWidth(2); // c1->Print("Fragment2.gif"); }
void toyMC_bkgTemp(int runIeta=-1, int runIpt=-1) { cout << "ROOT version = " << gROOT->GetVersion() << endl; // gSystem->mkdir("toysPlot"); char tmp[1000]; TH1D* htoyResult_pull[nEtaBin][nPtBin]; TH1D* htoyResult_bias[nEtaBin][nPtBin]; TFile *fsumFile = new TFile("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/proj_comb_comb3Iso_template.root"); TFile* finFile = new TFile("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/template_comb3Iso_template.root"); TFile* zeeFile = new TFile("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/anadipho_Zee_Vg_3pb.root"); TH1D* hTemplate = (TH1D*)finFile->FindObjectAny("h_EB_comb3Iso_EGdata_pt21"); hTemplate->Reset(); char* dec[2] = {"EB","EE"}; for(int ieta=0; ieta<nEtaBin; ieta++) { for(int ipt=0; ipt < nPtBin; ipt++) { htoyResult_pull[ieta][ipt] = new TH1D(Form("hpull_%s_pt_%d", dec[ieta], (int)fBinsPt[ipt]), "",50,-5.0,5.0); htoyResult_bias[ieta][ipt] = new TH1D(Form("hbias_%s_pt_%d", dec[ieta], (int)fBinsPt[ipt]), "",100,-0.5,0.5); } } TH1D* hfit_sig; TH1D* hfit_bkg; TH1D* hTemplate_S[nEtaBin][nPtBin]; TH1D* hTemplate_B[nEtaBin][nPtBin]; TH1D* hZeeTemplate_S[nEtaBin]; TH1D* hdata_data[nEtaBin][nPtBin]; TH1D* htemp; TH1D* hTemplate_ShiftB[nEtaBin][nPtBin]; for(int ieta=0; ieta< nEtaBin; ieta++) { // getting a different signal template if(ieta==0) { sprintf(tmp,"h_%s_combIso",dec[ieta]); cout << "looking for histogram " << tmp << " in file " << zeeFile->GetName() << endl; hZeeTemplate_S[ieta]= (TH1D*)zeeFile->FindObjectAny(tmp); hZeeTemplate_S[ieta]->Rebin(REBINNINGS_TEMP); } else { sprintf(tmp,"h_%s_comb3Iso_sig_sum_SIG",dec[ieta]); //no pt dep. cout << "looking for histogram " << tmp << " in file " << fsumFile->GetName() << endl; hZeeTemplate_S[ieta]= (TH1D*)fsumFile->FindObjectAny(tmp); hZeeTemplate_S[ieta]->Rebin(REBINNINGS_TEMP); } for(int ipt=0; ipt < nPtBin; ipt++) { if(runIeta>=0 && ieta!=runIeta)continue; if(runIpt>=0 && ipt!=runIpt)continue; // getting histograms from data root file sprintf(tmp,"h_%s_comb3Iso_EGdata_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hdata_data[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hdata_data[ieta][ipt]->Rebin(REBINNINGS_DATA); // filling unbinned data htemp = (TH1D*)hdata_data[ieta][ipt]->Clone("htemp"); htemp->Reset(); sprintf(tmp,"h_%s_comb3Iso_sig_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hTemplate_S[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hTemplate_S[ieta][ipt]->Rebin(REBINNINGS_TEMP); if(ieta==0 && fBinsPt[ipt]>=50) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],50); else if(ieta==0 ) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],(int)fBinsPt[ipt]); else if(ieta==1 && fBinsPt[ipt]>=60) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],60); else if(ieta==1) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hTemplate_B[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hTemplate_B[ieta][ipt]->Rebin(REBINNINGS_TEMP); // getting a different background template if(ieta==0 && fBinsPt[ipt]>=50) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],50); else if(ieta==0 ) sprintf(tmp,"h_%s_comb3IsoSB_EGdata_pt%d",dec[ieta],(int)fBinsPt[ipt]); else if(ieta==1 && fBinsPt[ipt]>=60) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],60); else if(ieta==1) sprintf(tmp,"h_%s_comb3Iso_bkg_pt%d",dec[ieta],(int)fBinsPt[ipt]); cout << "looking for histogram " << tmp << " in file " << finFile->GetName() << endl; hTemplate_ShiftB[ieta][ipt] = (TH1D*)finFile->FindObjectAny(tmp); hTemplate_ShiftB[ieta][ipt]->Rebin(REBINNINGS_TEMP); const int NRETURN = 3*NPAR; Double_t myFitPar[NRETURN]= {0}; Double_t* FuncFitResult; FuncFitResult = Ifit("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/EGdata_comb3Iso_et.dat", hZeeTemplate_S[ieta],hTemplate_ShiftB[ieta][ipt], hdata_data[ieta][ipt], myFitPar, (int)fBinsPt[ipt], dec[ieta],2); Double_t nsig_input = FuncFitResult[0]; Double_t nsigerr_input = FuncFitResult[1]; Double_t nbkg_input = FuncFitResult[2]; Double_t nbkgerr_input = FuncFitResult[3]; Double_t nsig_input5GeV = FuncFitResult[4]; Double_t nsigerr_input5GeV = FuncFitResult[5]; // force the parameters since EE pt=40 fails if(ieta==1 && ipt==5) { nsig_input = 3172.0; nbkg_input = 10031.0; nsig_input5GeV = 3158.7; Double_t tempPar[NRETURN]= { 22517.049862, 0.900766, 0.044772, 0.191920, 313.878244, -0.545069, -0.281830, 0.026143, 2.549494, 0., 0., 22517.049862, 0.900766, 0.044772, 0.191920, 313.878244, -0.545069, -0.281830, 0.026143, 2.549494, 0., 0., 22517.049862, 0.900766, 0.044772, 0.191920, 313.878244, -0.545069, -0.281830, 0.026143, 2.549494, 0., 0. }; for(int ipar=0; ipar <NRETURN; ipar++) myFitPar[ipar] = tempPar[ipar]; } // end if EE, Et=40 GeV Double_t sigFitPar[NPAR]= {0}; for(int ipar=0; ipar<NPAR; ipar++) sigFitPar[ipar] = myFitPar[ipar]; Double_t bkgFitPar[NPAR]= {0}; for(int ipar=0; ipar<NPAR; ipar++) bkgFitPar[ipar] = myFitPar[ipar+NPAR]; Double_t sumFitPar[NPAR]= {0}; for(int ipar=0; ipar<NPAR; ipar++) sumFitPar[ipar] = myFitPar[ipar+NPAR*2]; TF1* fsig = new TF1("fsig", exp_conv, fit_lo, fit_hi, 11); fsig->SetParameters(sigFitPar); fsig->SetParameter(0,1.0); mySigPDFnorm = fsig->Integral(fit_lo,fit_hi); cout << "mySigPDFnorm = " << mySigPDFnorm << endl; TF1* fbkg = new TF1("fbkg", expinv_power, fit_lo, fit_hi, 11); fbkg->SetParameters(bkgFitPar); fbkg->SetParameter(4,1.0); cout << "Current parameter = " << fbkg->GetParameter(5) << endl; myBkgPDFnorm = fbkg->Integral(fit_lo, fit_hi); cout << "myBkgPDFnorm = " << myBkgPDFnorm << endl; TF1* fsum = new TF1("fsum",mysum_norm, fit_lo, fit_hi,11); fsum->SetParameters(sumFitPar); nsig_input = fNsigPt[ieta][ipt]; cout << "Using nsig_input = " << nsig_input << endl; cout << "Using nbkg_input = " << nbkg_input << endl; cout << "Using nsig_input5GeV = " << nsig_input5GeV << endl; fsum->SetParameter(0, nsig_input*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(4, nbkg_input*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetLineColor(2); fsum->SetNpx(2500); // cout << "fsum integral = " << fsum->Integral(fit_lo,fit_hi) << endl; // for(int ipar=0; ipar<NPAR; ipar++)cout << "fsum par " << ipar << " = " << fsum->GetParameter(ipar) << endl; // FILE *infile = fopen("/afs/cern.ch/user/s/syu/scratch0/LxplusArea/EGdata_comb3Iso_et.dat","r"); // Double_t xdata, xdata1, xdata2; // combined isolation, pt, eta // int flag = 1; // while (flag!=-1){ // flag =fscanf(infile,"%f %f %f",&xdata, &xdata1, &xdata2); // if( xdata1 >= fBinsPt[ipt] && xdata1 < fBinsPt[ipt+1] && xdata<20.) { // if((ieta==0 && TMath::Abs(xdata2)<1.5) || // (ieta==1 && TMath::Abs(xdata2)>1.5) ) { // htemp->Fill(xdata); // } // } // }// keep reading files as long as text exists // TCanvas* myCanvas = new TCanvas("myCanvas","myCanvas"); // htemp->Draw(); // fsum->Draw("same"); // // loops over toys for(int iexp=0; iexp<NEXP; iexp++) { TH1D* htoyMC_data = (TH1D*)hdata_data[ieta][ipt]->Clone("htoyMC_data"); htoyMC_data->Reset(); TH1D* htoyMC_sig = (TH1D*)hZeeTemplate_S[ieta]->Clone("htoyMC_sig"); TH1D* htoyMC_bkg = (TH1D*)hTemplate_B[ieta][ipt]->Clone("htoyMC_bkg"); UInt_t nowSeed = (unsigned long)gSystem->Now(); gRandom->SetSeed(nowSeed); int nsiggen = gRandom->Poisson(nsig_input); int nbkggen = gRandom->Poisson(nbkg_input); int ndata = nsiggen + nbkggen; // reset toy MC data htoyMC_data->Reset(); ofstream fout; std::string toyData = Form("/tmp/syu/changeBkgTemptoy_%d_%d.dat",ieta,ipt); fout.open(toyData.data()); for(int ieve=0; ieve < nsiggen; ieve++) { Double_t xvalue = fsig->GetRandom(fit_lo,fit_hi); fout << xvalue << " " << 0.5*(fBinsPt[ipt]+fBinsPt[ipt+1]) << " " << fBinsEta[ieta] << endl; htoyMC_data->Fill(xvalue); } for(int ieve=0; ieve < nbkggen; ieve++) { Double_t xvalue = fbkg->GetRandom(fit_lo,fit_hi); fout << xvalue << " " << 0.5*(fBinsPt[ipt]+fBinsPt[ipt+1]) << " " << fBinsEta[ieta] << endl; htoyMC_data->Fill(xvalue); } fout.close(); Double_t* toyFitResult; Double_t toyMyFitPar[NRETURN]= {0}; toyFitResult = Ifit(toyData.data(), htoyMC_sig, htoyMC_bkg, htoyMC_data, toyMyFitPar, (int)fBinsPt[ipt], dec[ieta],2); Double_t nsigtoyfit = toyFitResult[0]; Double_t errnsigtoyfit = toyFitResult[1]; Double_t nbkgtoyfit = toyFitResult[2]; Double_t errnbkgtoyfit = toyFitResult[3]; Double_t nsigtoyfit_5GeV = toyFitResult[4]; Double_t errnsigtoyfit_5GeV = toyFitResult[5]; if(errnsigtoyfit < 1e-6 || errnbkgtoyfit < 1e-6 || nsigtoyfit < 1e-6 || nbkgtoyfit < 1e-6 || nsig_input < 1e-6 || fabs(nsigtoyfit - nsig_input)<1e-4)continue; Double_t toySumFitPar[NPAR]= {0}; for(int ipar=0; ipar<NPAR; ipar++) toySumFitPar[ipar] = toyMyFitPar[ipar+NPAR*2]; // fsum->SetParameters(toySumFitPar); // fsum->SetParameter(0, nsigtoyfit*hdata_data[ieta][ipt]->GetBinWidth(2)); // fsum->SetParameter(4, nbkgtoyfit*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(0, (Double_t)nsiggen*hdata_data[ieta][ipt]->GetBinWidth(2)); fsum->SetParameter(4, (Double_t)nbkggen*hdata_data[ieta][ipt]->GetBinWidth(2)); // if(iexp%20==0){ TCanvas* myCanvas = new TCanvas("myCanvas","SHIT"); htoyMC_data->SetMaximum(htoyMC_data->GetMaximum()*1.5); htoyMC_data->Draw(); fsum->Draw("same"); // myCanvas->Print(Form("toysPlot/fit_%03i.gif",iexp)); // delete myCanvas; // } // cout << "fsum integral = " << fsum->Integral(-1,20) << endl; // for(int ipar=0; ipar<NPAR; ipar++)cout << "fsum par " << ipar << " = " << fsum->GetParameter(ipar) << endl; Double_t pull = (nsigtoyfit - nsig_input)/errnsigtoyfit; Double_t bias = (nsigtoyfit - nsig_input)/nsig_input; htoyResult_pull[ieta][ipt]->Fill(pull); htoyResult_bias[ieta][ipt]->Fill(bias); } // end loops of toys delete fsig; delete fbkg; } // end of loop over pt bins } TFile* outFile = new TFile(Form("changBkgTemp_%s_pt%d.root", dec[runIeta], (int)fBinsPt[runIpt]), "recreate"); for(int ieta=0; ieta < nEtaBin; ieta++) { for(int ipt=0; ipt < nPtBin; ipt++) { if(htoyResult_pull[ieta][ipt]->GetEntries()>0) htoyResult_pull[ieta][ipt]->Write(); if(htoyResult_bias[ieta][ipt]->GetEntries()>0) htoyResult_bias[ieta][ipt]->Write(); } } outFile->Close(); }
void fitX(TString infname="/data/twang/BfinderRun2/DoubleMu/BfinderData_pp_20151202_bPt0jpsiPt0tkPt0p5/finder_pp_merged.root") { TFile *inf = new TFile(infname.Data()); TTree *ntmix = (TTree*) inf->Get("Bfinder/ntmix"); TH1D *h = new TH1D("h","",40,3.6,4); TCut cutTrk = "1"; //original YJ //TCut cutTrk = "Btrk1PixelHit>=2&&Btrk1StripHit>=7&&Btrk1Chi2ndf<5&&Btrk2PixelHit>=2&&Btrk2StripHit>=7&&Btrk2Chi2ndf<5"; TCut cutTotal="Btype==7&&Bpt>10&&abs(Beta)<10&&sqrt((Bmumueta-Btrk1Eta)*(Bmumueta-Btrk1Eta)+(Bmumuphi-Btrk1Phi)*(Bmumuphi-Btrk1Phi))<9999"&&cutTrk; TCanvas *c = new TCanvas("c","",750,600); ntmix->Draw("Bmass>>h",cutTotal); TFile*output=new TFile("histoX.root","recreate"); output->cd(); h->Write(); output->Close(); h->Sumw2(); TF1 *f = new TF1("f","[0]+[1]*x+[2]*x*x+[8]*x*x*x+[9]*x*x*x*x+[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f->SetLineColor(4); f->SetParameters(-2.2597e4,1.326e4,-1.727e3,50,3.686,0.00357,1,3.8725,0.0054); f->FixParameter(4,3.686); f->FixParameter(5,0.00357); f->FixParameter(7,3.8725); h->Fit("f","LL"); h->Fit("f",""); h->Fit("f","LL"); h->Fit("f","LL","",3.65,3.94); h->Fit("f","LL","",3.65,3.94); f->ReleaseParameter(4); f->ReleaseParameter(5); f->ReleaseParameter(7); h->Fit("f","LL","",3.65,3.94); h->SetXTitle("m(J/#psi#pi^{+}#pi^{-}) [GeV]"); h->SetYTitle("Entries"); h->SetStats(0); h->SetAxisRange(0,h->GetMaximum()*1.3 ,"Y"); TF1 *f2 = new TF1("f2","[0]+[1]*x+[2]*x*x+0*Gaus(x,[4],[5])+0*Gaus(x,[7],[5])"); f2->SetParameter(0,f->GetParameter(0)); f2->SetParameter(1,f->GetParameter(1)); f2->SetParameter(2,f->GetParameter(2)); TF1 *f3 = new TF1("f3","[3]*Gaus(x,[4],[5])+[6]*Gaus(x,[7],[5])"); f3->SetParameter(3,f->GetParameter(3)); f3->SetParameter(4,f->GetParameter(4)); f3->SetParameter(5,f->GetParameter(5)); f3->SetParameter(6,f->GetParameter(6)); f3->SetParameter(7,f->GetParameter(7)); f3->SetParameter(8,f->GetParameter(8)); f->SetLineColor(4); f2->SetLineColor(4); f3->SetRange(3.65,3.94); f2->SetRange(3.65,3.94); f2->SetLineStyle(2); f3->SetLineStyle(2); f2->Draw("same"); f3->SetLineColor(2); f3->SetFillStyle(3004); f3->SetFillColor(2); f3->Draw("same"); TLatex *l = new TLatex(3.7,70./80*h->GetMaximum(),"#psi(2S)"); l->Draw(); TLatex *l2 = new TLatex(3.875,50./80*h->GetMaximum(),"X(3872)"); l2->Draw(); TLatex *l3 = new TLatex(3.812,70./80*h->GetMaximum(),"CMS Preliminary"); l3->Draw(); TLatex *l4 = new TLatex(3.78,60./80*h->GetMaximum(),"pp #sqrt{s_{NN}}=5.02 TeV"); l4->Draw(); cout<<ntmix->GetEntries()<<endl; TH1D *hProj = (TH1D*)h->Clone("hProj"); hProj->Clear(); f->SetRange(3.6,4); for (int i=0;i<h->GetEntries()*11;i++) { hProj->Fill(f->GetRandom()); } TCanvas *c2 = new TCanvas("c2","",750,600); hProj->SetTitle("Estimated Projection"); hProj->Draw("e"); }
float SmearingTool::PTsmear(float PTmuonGen, float ETAmuonGen, float CHARGEmuonGen, float PTmuonReco, int Ismear, TString ParVar,float ParSig){ //Ismear = 1 - Smear with RND (no RECO use), Ismear = 2 - Smear with SF for RECO and GEN if(Ismear != 1 && Ismear != 2)std::cout << "ERROR SmearingTool::PTsmear: set Ismear to 1 or 2 for smearing" << std::endl; const int NPThist = (sizeof(PTbin)/sizeof(float)-1); const int NETAhist = (sizeof(ETAbin)/sizeof(float)-1); //const int Nhist = NPThist*NETAhist; ////// Make smearing for single muon from Gen level PostFSR: float PTmuonSmear = -10.; float meanVar = 0; float sigVar = 0;//for sig1 and sig2 float Asig2Var = 0; if(ParVar == "mean")meanVar = ParSig; if(ParVar == "sig1" || ParVar == "sig2")sigVar = ParSig; if(ParVar == "Asig2Var")Asig2Var = ParSig; int iK_cand = -1; for(int iPT = 0; iPT < NPThist; iPT++){ for(int iETA = 0; iETA < NETAhist; iETA++){ int iK = iPT + iETA*NPThist; // smear muons which out of range PT and ETA float PTcutDown = PTbin[iPT]; float PTcutUp = PTbin[iPT+1]; if(iPT == 0 && PTmuonGen < PTbin[0])PTcutDown = PTmuonGen-0.001; if(iPT == (NPThist-1) && PTmuonGen > PTbin[NPThist])PTcutUp = PTmuonGen+0.001; float ETAcutDown = ETAbin[iETA]; float ETAcutUp = ETAbin[iETA+1]; if(iETA == 0 && ETAmuonGen < ETAbin[0])ETAcutDown = ETAmuonGen-0.001; if(iETA == (NETAhist-1) && ETAmuonGen >= ETAbin[NETAhist])ETAcutUp = ETAmuonGen+0.001; if(PTmuonGen >= PTcutDown && PTmuonGen < PTcutUp && ETAmuonGen >= ETAcutDown && ETAmuonGen < ETAcutUp) iK_cand = iK; }} ///// Set Scale Factor float ScaleFactor = 1.; if (fabs(ETAmuonGen) < 0.8) ScaleFactor = 1.01; if (fabs(ETAmuonGen) >= 0.8 && fabs(ETAmuonGen) < 1.2) ScaleFactor = 1.07; if (fabs(ETAmuonGen) >= 1.2) ScaleFactor = 1.08; TF1* fitDoubleGauss = new TF1("fitDoubleGauss", DoubleGauss, -0.1, 0.1, 5); fitDoubleGauss->SetParameter(4,1.); if(iK_cand > -1 && Ismear == 1 && CHARGEmuonGen < 0){ float meanCorr = mean[iK_cand] + meanVar*ERRmean[iK_cand]; float sig1Corr = sig1[iK_cand] + sigVar*ERRsig1[iK_cand]; if(sig1Corr < 0.005) sig1Corr = 0.005; float sig2Corr = sig2[iK_cand] + sigVar*ERRsig2[iK_cand]; if(sig2Corr < 0.005) sig2Corr = 0.005; float Asig2Corr = Asig2[iK_cand] + Asig2Var*ERRAsig2[iK_cand]; if(Asig2Corr < 0.) Asig2Corr = 0.; fitDoubleGauss->SetParameter(0,meanCorr); fitDoubleGauss->SetParameter(1,ScaleFactor*sig1Corr); fitDoubleGauss->SetParameter(2,Asig2Corr); fitDoubleGauss->SetParameter(3,ScaleFactor*sig2Corr); Double_t resSim = fitDoubleGauss->GetRandom(); PTmuonSmear = PTmuonGen*(1+resSim); } if(iK_cand > -1 && Ismear == 1 && CHARGEmuonGen > 0){ float meanCorr = meanMuPlus[iK_cand] + meanVar*ERRmeanMuPlus[iK_cand]; float sig1Corr = sig1MuPlus[iK_cand] + sigVar*ERRsig1MuPlus[iK_cand]; if(sig1Corr < 0.005) sig1Corr = 0.005; float sig2Corr = sig2MuPlus[iK_cand] + sigVar*ERRsig2MuPlus[iK_cand]; if(sig2Corr < 0.005) sig2Corr = 0.005; float Asig2Corr = Asig2MuPlus[iK_cand] + Asig2Var*ERRAsig2MuPlus[iK_cand]; if(Asig2Corr < 0.) Asig2Corr = 0.; fitDoubleGauss->SetParameter(0,meanCorr); fitDoubleGauss->SetParameter(1,ScaleFactor*sig1Corr); fitDoubleGauss->SetParameter(2,Asig2Corr); fitDoubleGauss->SetParameter(3,ScaleFactor*sig2Corr); Double_t resSim = fitDoubleGauss->GetRandom(); PTmuonSmear = PTmuonGen*(1+resSim); } delete fitDoubleGauss; if(iK_cand > -1 && Ismear == 2){ PTmuonSmear = PTmuonGen + ScaleFactor*(PTmuonReco - PTmuonGen); } ////// End Smearing parametrization for single muon: return PTmuonSmear; }//end PTsmear function
void fitToys2(){ int count=0,countNotFail=0; gStyle->SetOptStat(0); TCanvas *c1 = new TCanvas("c1","c1",800,600);c1->cd(); //TCanvas *c2 = new TCanvas("c2","c2",800,600);c2->cd(); //c1->cd(); TF1* fit = new TF1("fit","[0]*pow(x,[1])",103,163); fit->SetParameters(1.28542e+08,-3.90422); fit->SetParError(0,1.27534e+09); fit->SetParError(1,2.06166); TH1F* h_counts = new TH1F("h_counts","",2,0,2); TH1F* h_HiggsWindowFit = new TH1F("h_HiggsWindowFit","# events in Higgs window from fit",80,0,40); TH1F* h_pull = new TH1F("h_pull","(fit - generated)/(fit error)",160,-8,8); TH1F* h_pull_fail = new TH1F("h_pull_fail","(fit - generated)/(fit error)",160,-8,8); TH1F* h_pull_lowErr = new TH1F("h_pull_lowErr","(fit - generated)/(fit error)",160,-8,8); TH1F* h_pull_highErr = new TH1F("h_pull_highErr","(fit - generated)/(fit error)",160,-8,8); TH1F* h_diff = new TH1F("h_diff","(fit - generated)",160,-40,40); TH1F* h_pullU = new TH1F("h_pullU","(fit - generated)/(fit error)",160,-8,8); TH1F* h_diffU = new TH1F("h_diffU","(fit - generated)",160,-40,40); TH1F* h_pullL = new TH1F("h_pullL","(fit - generated)/(fit error)",160,-8,8); TH1F* h_diffL = new TH1F("h_diffL","(fit - generated)",160,-40,40); h_pullL->SetLineColor(kRed);h_pullL->SetMarkerColor(kRed); h_diffL->SetLineColor(kRed);h_diffL->SetMarkerColor(kRed); h_pullU->SetLineColor(kBlue);h_pullU->SetMarkerColor(kBlue); h_diffU->SetLineColor(kBlue);h_diffU->SetMarkerColor(kBlue); h_pull_fail->SetFillColor(kRed); // TRandom3 rr; for(int j=0;j<10;j++){ TH1F* h = new TH1F("h","",60,103,163); for(int i=0;i<5200;i++){ //for(int i=0;i<rr.Poisson(52);i++){ h->Fill(fit->GetRandom(103,163)); } //h->Draw("PE"); reject=true; TF1* fitCurve = new TF1("fitCurve",fpow,103,163,2); Double_t avg_l = h->Integral(h->FindBin(103),h->FindBin(118))/float(118-103),avg_u = h->Integral(h->FindBin(133),h->FindBin(163))/float(163-133),avgX_l=(118-103)/2.,avgX_u=(163-133)/2.; cout<<avg_l<<" "<<avg_u<<" "<<avgX_l<<" "<<avgX_u<<endl; Double_t param1= (log(avg_l) - log(avg_u))/(log(avgX_l) - log(avgX_u)); Double_t param0= /*7e14;*/avg_l/pow(avgX_l, param1); cout<<"param0: "<<param0<<" param1: "<<param1<<endl; fitCurve->SetParameter(0,param0); fitCurve->SetParameter(1,param1); int status = h->Fit(fitCurve,"L","",103,163); //Then to get the result TFitResultPtr fitResult = h->Fit(fitCurve,"SLLMEV0","",103,163); TMatrixDSym cov = fitResult->GetCovarianceMatrix(); fitResult->Print("V"); h->GetXaxis()->SetRangeUser(100,164.9); reject=false; float YieldBinWidth=h->GetBinWidth(1); Double_t PowYieldSig = h->Integral(h->FindBin(120),h->FindBin(131-.1))/YieldBinWidth; Double_t PowYieldSigFit = fitCurve->Integral(120,131)/YieldBinWidth; Double_t PowYieldSigFitErr = fitCurve->IntegralError(120,131,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; Double_t PowSBloYield = h->Integral(h->FindBin(103),h->FindBin(118-.1))/YieldBinWidth; Double_t PowSBloYieldFit = fitCurve->Integral(103,118)/YieldBinWidth; Double_t PowSBloYieldFitErr = fitCurve->IntegralError(103,118,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; Double_t PowSBhiYield = h->Integral(h->FindBin(133),h->FindBin(163-.1))/YieldBinWidth; Double_t PowSBhiYieldFit = fitCurve->Integral(133,163)/YieldBinWidth; Double_t PowSBhiYieldFitErr = fitCurve->IntegralError(133,163,fitResult->GetParams(),cov.GetMatrixArray() )/YieldBinWidth; cout<<"gMinuit->fStatus : "<< gMinuit->fStatus <<" gMinuit->fCstatu : "<< gMinuit->fCstatu<<endl; cout<<" low sideband yield from histo: "<<PowSBloYield<<" and from fit: "<<PowSBloYieldFit<<" +- "<<PowSBloYieldFitErr<<endl; cout<<" higgs window yield from histo: "<<PowYieldSig <<" and from fit: "<<PowYieldSigFit<<" +- "<<PowYieldSigFitErr<<endl; cout<<" high sideband yield from histo: "<<PowSBhiYield<<" and from fit: "<<PowSBhiYieldFit<<" +- "<<PowSBhiYieldFitErr<<endl; reject=true; TString str = (TString)gMinuit->fCstatu; cout<<"str: "<<str; h_counts->Fill(0); if(str.Contains("FAILURE")){ double pull_fail = (PowYieldSigFit-9.11)/PowYieldSigFitErr; h_pull_fail->Fill(pull_fail); // continue; } h_counts->Fill(1); double pull = (PowYieldSigFit-9.11)/PowYieldSigFitErr; double pull_lowErr = (PowYieldSigFit-(9.11-1.6))/PowYieldSigFitErr; double pull_highErr = (PowYieldSigFit-(9.11+1.6))/PowYieldSigFitErr; double diff = (PowYieldSigFit-9.11); double pullL = (PowSBloYieldFit-PowSBloYield)/PowSBloYieldFitErr; double diffL = (PowSBloYieldFit-PowSBloYield); double pullU = (PowSBhiYieldFit-PowSBhiYield)/PowSBhiYieldFitErr; double diffU = (PowSBhiYieldFit-PowSBhiYield); h_pull->Fill(pull); h_pull_lowErr->Fill(pull_lowErr); h_pull_highErr->Fill(pull_highErr); h_diff->Fill(diff); h_pullU->Fill(pullU); h_diffU->Fill(diffU); h_pullL->Fill(pullL); h_diffL->Fill(diffL); h_HiggsWindowFit->Fill(PowYieldSigFit); } /* TFile fout("InvarMassFitToys.root","RECREATE"); fout.cd(); h_diff->Write(); h_diffL->Write(); h_diffU->Write(); h_pull->Write(); h_pull_lowErr->Write(); h_pull_highErr->Write(); h_pullL->Write(); h_pullU->Write(); h_HiggsWindowFit->Write(); h_counts->Write(); fout.Close(); */ //h->Draw(); h_diffU->Draw();h_diff->Draw("SAMES");h_diffL->Draw("SAMES"); TLegend *legd = new TLegend(.6,.55,.8,.85,"","brNDC"); legd->SetFillStyle(0);legd->SetBorderSize(0); legd->AddEntry(h_diff,"Higgs window","l"); legd->AddEntry(h_diffL,"lower sideband","l"); legd->AddEntry(h_diffU,"upper sideband","l"); legd->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff.pdf"); //c2->cd(); h_pullU->Draw();h_pull->Draw("SAMES");h_pullL->Draw("SAMES"); legd->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull.pdf"); h_diff->Fit("gaus");h_diff->SetTitle("Higgs window (fit - generated) with Gaussian fit"); h_diff->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff_gausFit.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__diff_gausFit.pdf"); h_pull->Fit("gaus");h_pull->SetTitle("Higgs window pull with Gaussian fit");//h_pull_fail->Fit("gaus"); h_pull->Draw();//h_pull_fail->Draw("SAMES"); c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull_gausFit_withFail.png"); c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__pull_gausFit_withFail.pdf"); h_HiggsWindowFit->Fit("gaus"); h_HiggsWindowFit->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__HiggsWindow_gausFit.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__HiggsWindow_gausFit.pdf"); h_counts->Draw(); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__counts.png"); //c1->Print("Plots/Higgs/Exclusive_WeDataInvMassFit_toys__counts.pdf"); }
int main(int argc, char* argv[]) { TApplication theApp(srcName.Data(), &argc, argv); //============================================================================= if (argc<5) return -1; TString sPath = argv[1]; if (sPath.IsNull()) return -1; TString sFile = argv[2]; if (sFile.IsNull()) return -1; TString sJetR = argv[3]; if (sJetR.IsNull()) return -1; TString sSjeR = argv[4]; if (sSjeR.IsNull()) return -1; //============================================================================= sPath.ReplaceAll("#", "/"); //============================================================================= double dJetR = -1.; if (sJetR=="JetR02") dJetR = 0.2; if (sJetR=="JetR03") dJetR = 0.3; if (sJetR=="JetR04") dJetR = 0.4; if (sJetR=="JetR05") dJetR = 0.5; if (dJetR<0.) return -1; cout << "Jet R = " << dJetR << endl; //============================================================================= double dSjeR = -1.; if (sSjeR=="SjeR01") dSjeR = 0.1; if (sSjeR=="SjeR02") dSjeR = 0.2; if (sSjeR=="SjeR03") dSjeR = 0.3; if (sSjeR=="SjeR04") dSjeR = 0.4; if (dSjeR<0.) return -1; cout << "Sub-jet R = " << dSjeR << endl; //============================================================================= const int multiLHC = 3000; const double dJetsPtMin = 0.001; const double dCutEtaMax = 1.6; const double dJetEtaMax = 1.; const double dJetAreaRef = TMath::Pi() * dJetR * dJetR; fastjet::GhostedAreaSpec areaSpc(dCutEtaMax); fastjet::JetDefinition jetsDef(fastjet::antikt_algorithm, dJetR, fastjet::BIpt_scheme, fastjet::Best); //fastjet::AreaDefinition areaDef(fastjet::active_area,areaSpc); fastjet::AreaDefinition areaDef(fastjet::active_area_explicit_ghosts,areaSpc); fastjet::JetDefinition bkgsDef(fastjet::kt_algorithm, 0.2, fastjet::BIpt_scheme, fastjet::Best); fastjet::AreaDefinition aBkgDef(fastjet::active_area_explicit_ghosts, areaSpc); fastjet::Selector selectJet = fastjet::SelectorAbsEtaMax(dJetEtaMax); fastjet::Selector selectRho = fastjet::SelectorAbsEtaMax(dCutEtaMax-0.2); fastjet::Selector selecHard = fastjet::SelectorNHardest(2); fastjet::Selector selectBkg = selectRho * (!(selecHard)); fastjet::JetMedianBackgroundEstimator bkgsEstimator(selectBkg, bkgsDef, aBkgDef); //fastjet::Subtractor bkgSubtractor(&bkgsEstimator); fastjet::JetDefinition subjDef(fastjet::kt_algorithm, dSjeR, fastjet::BIpt_scheme, fastjet::Best); //============================================================================= TRandom3 *r3 = new TRandom3(0); TF1 *fBkg = BackgroundSpec(); //============================================================================= std::vector<fastjet::PseudoJet> fjInputVac; std::vector<fastjet::PseudoJet> fjInputHyd; //============================================================================= TList *list = new TList(); TH1D *hWeightSum = new TH1D("hWeightSum", "", 1, 0., 1.); list->Add(hWeightSum); //============================================================================= HepMC::IO_GenEvent ascii_in(Form("%s/%s.hepmc",sPath.Data(),sFile.Data()), std::ios::in); HepMC::GenEvent *evt = ascii_in.read_next_event(); while (evt) { fjInputVac.resize(0); fjInputHyd.resize(0); double dXsect = evt->cross_section()->cross_section() / 1e9; double dWeight = evt->weights().back(); double dNorm = dWeight * dXsect; hWeightSum->Fill(0.5, dWeight); int iCount = 0; TLorentzVector vPseudo; for (HepMC::GenEvent::particle_const_iterator p=evt->particles_begin(); p!=evt->particles_end(); ++p) if ((*p)->status()==1) { vPseudo.SetPtEtaPhiM((*p)->momentum().perp(), (*p)->momentum().eta(), (*p)->momentum().phi(), 0.); if ((TMath::Abs(vPar.Eta())<dCutEtaMax)) { fjInputVac.push_back(fastjet::PseudoJet(vPseudo.Px(), vPseudo.Py(), vPseudo.Pz(), vPseudo.E())); fjInputVac.back().set_user_info(new UserInfoTrk(false)); fjInputVac.back().set_user_index(iCount); iCount+=1; } } //============================================================================= for (int i=0; i<=multiLHC; i++) { double dPt = fBkg->GetRandom(fgkPtBkgMin, fgkPtBkgMax); if (dPt<0.001) continue; vPseudo.SetPtEtaPhiM(dPt, r3->Uniform(-1.*dCutEtaMax,dCutEtaMax), r3->Uniform(0.,TMath::TwoPi()), 0.); fjInputHyd.push_back(fastjet::PseudoJet(vPseudo.Px(), vPseudo.Py(), vPseudo.Pz(), vPseudo.E())); fjInputHyd.back().set_user_info(new UserInfoTrk(true)); fjInputHyd.back().set_user_index(-10); } fjInputHyd.insert(fjInputHyd.end(), fjInputVac.begin(),fjInputVac.end()); //============================================================================= fastjet::ClusterSequenceArea clustSeq(fjInputVac, jetsDef, areaDef); std::vector<fastjet::PseudoJet> includJetsPy = clustSeq.inclusive_jets(dJetsPtMin); // std::vector<fastjet::PseudoJet> subtedJetsPy = bkgSubtractor(includJetsPy); std::vector<fastjet::PseudoJet> selectJetsPy = selectJet(includJetsPy); // std::vector<fastjet::PseudoJet> sortedJetsPy = fastjet::sorted_by_pt(selectJetsPy); for (int j=0; j<selectJetsPy.size(); j++) { SetJetUserInfo(selectJetsPy[j]); selectJetsPy[j].set_user_index(j); } //============================================================================= bkgsEstimator.set_particles(fjInputHyd); double dBkgRhoHd = bkgsEstimator.rho(); double dBkgRmsHd = bkgsEstimator.sigma(); fastjet::ClusterSequenceArea clustSeqHd(fjInputHyd, jetsDef, areaDef); std::vector<fastjet::PseudoJet> includJetsHd = clustSeqHd.inclusive_jets(dJetsPtMin); std::vector<fastjet::PseudoJet> selectJetsHd = selectJet(includJetsHd); for (int j=0; j<selectJetsHd.size(); j++) { SetJetUserInfo(selectJetsHd[j]); selectJetsHd[j].set_user_index(j); if (selectJetsHd[j].user_info<UserInfoJet>().IsBkg()) continue; for (int i=0; i<selectJetsPy.size(); i++) { if (CalcDeltaR(selectJetsHd[j],selectJetsPy[i])>0.8) continue; DoTrkMatch(selectJetsHd[j], selectJetsPy[i]); } } //============================================================================= for (int j=0; j<sortedJets.size(); j++) { double dJet = sortedJets[j].pt(); hJet->Fill(dJet, dNorm); //============================================================================= fastjet::Filter trimmer(subjDef, fastjet::SelectorPtFractionMin(0.)); fastjet::PseudoJet trimmdJet = trimmer(sortedJets[j]); std::vector<fastjet::PseudoJet> trimmdSj = trimmdJet.pieces(); double nIsj = 0.; double d1sj = -1.; int k1sj = -1; double d2sj = -1.; int k2sj = -1; for (int i=0; i<trimmdSj.size(); i++) { double dIsj = trimmdSj[i].pt(); if (dIsj<0.001) continue; hJetIsj->Fill(dJet, dIsj, dNorm); hJetIsz->Fill(dJet, dIsj/dJet, dNorm); if (dIsj>d1sj) { d2sj = d1sj; k2sj = k1sj; d1sj = dIsj; k1sj = i; } else if (dIsj>d2sj) { d2sj = dIsj; k2sj = i; } nIsj += 1.; } hJetNsj->Fill(dJet, nIsj, dNorm); if (d1sj>0.) { hJet1sj->Fill(dJet, d1sj, dNorm); hJet1sz->Fill(dJet, d1sj/dJet, dNorm); } if (d2sj>0.) { hJet2sj->Fill(dJet, d2sj, dNorm); hJet2sz->Fill(dJet, d2sj/dJet, dNorm); } if ((d1sj>0.) && (d2sj>0.)) { TVector3 v1sj; v1sj.SetPtEtaPhi(d1sj, trimmdSj[k1sj].eta(), trimmdSj[k1sj].phi()); TVector3 v2sj; v2sj.SetPtEtaPhi(d2sj, trimmdSj[k2sj].eta(), trimmdSj[k2sj].phi()); double dsj = d1sj - d2sj; double dsz = dsj / dJet; double dsr = v1sj.DeltaR(v2sj) / 2. / dJetR; hJetDsj->Fill(dJet, dsj, dNorm); hJetDsz->Fill(dJet, dsz, dNorm); hJetDsr->Fill(dJet, dsz, dsr, dNorm); } } //============================================================================= delete evt; ascii_in >> evt; } //============================================================================= TFile *file = TFile::Open(Form("%s.root",sFile.Data()), "NEW"); list->Write(); file->Close(); //============================================================================= cout << "DONE" << endl; return 0; }
// test of unuran passing as input a distribution object( a BreitWigner) distribution void testDistr1D() { cout << "\nTest 1D Continous distributions\n\n"; TH1D * h1 = new TH1D("h1BW","Breit-Wigner distribution from Unuran",100,-10,10); TH1D * h2 = new TH1D("h2BW","Breit-Wigner distribution from GetRandom",100,-10,10); TF1 * f = new TF1("distrFunc",distr,-10,10,2); double par[2] = {1,0}; // values are gamma and mean f->SetParameters(par); TF1 * fc = new TF1("cdfFunc",cdf,-10,10,2); fc->SetParameters(par); // create Unuran 1D distribution object TUnuranContDist dist(f); // to use a different random number engine do: TRandom2 * random = new TRandom2(); int logLevel = 2; TUnuran unr(random,logLevel); // select unuran method for generating the random numbers std::string method = "tdr"; //std::string method = "method=auto"; // "method=hinv" // set the cdf for some methods like hinv that requires it // dist.SetCdf(fc); //cout << "unuran method is " << method << endl; if (!unr.Init(dist,method) ) { cout << "Error initializing unuran" << endl; return; } TStopwatch w; w.Start(); int n = NGEN; for (int i = 0; i < n; ++i) { double x = unr.Sample(); h1->Fill( x ); } w.Stop(); cout << "Time using Unuran method " << unr.MethodName() << "\t=\t " << w.CpuTime() << endl; w.Start(); for (int i = 0; i < n; ++i) { double x = f->GetRandom(); h2->Fill( x ); } w.Stop(); cout << "Time using TF1::GetRandom() \t=\t " << w.CpuTime() << endl; c1->cd(++izone); h1->Draw(); c1->cd(++izone); h2->Draw(); std::cout << " chi2 test of UNURAN vs GetRandom generated histograms: " << std::endl; h1->Chi2Test(h2,"UUP"); }