void mbfit(){ gROOT->ProcessLine(".x /home/jholzbau/rootlogon.C"); TString var = "setfit"; TH1::SetDefaultSumw2(); //Plan is to plot SET for CAFE and PMCS, Then with SET-MBSET for PMCS vs CAFE, Then with scaled MBSET (event by event depending on SET or MBSET value or something) //run3 files // TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_20130703_152033/pythia_zee_run2b3_default_tree_20130703_152033_20130703_152344_23/ZRootTree3.root"; // TString rootfile2 = "/prj_root/7055/wmass2/jenny/mbtreecafe2/WMASS_MC_RUN2B3_zee_ovl_12p8M_1372882719_default_tree2_20130703151839-15902467.d0cabsrv1.fnal.gov/ZRootTree2.root"; //TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_20130703_152033/run3.root"; //TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_vtxcut_redo_20130716_142720/result.root"; // TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_vtxcut_redo_20130726_085527/tree.root"; TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_mbtest_inclusiveweight_NEWmblib_pow04mbprob_TREE_20130726_085527/tree.root"; TString rootfile2 = "/prj_root/7055/wmass2/jenny/mbtreecafe2/run3.root"; Double_t xmin = 0; Double_t xmax = 300; Int_t nbin = 250; TH1D *tcafe = new TH1D("topcafe", "topcafe", nbin, xmin, xmax); TH1D *tpmcs = new TH1D("toppmcs", "toppmcs", nbin, xmin, xmax); TH1D *tpmcsd = new TH1D("toppmcsd", "toppmcsd", nbin, xmin, xmax); TH1D *tpmcsmb = new TH1D("toppmcsmb", "toppmcsmb", nbin, xmin, xmax); TH1D *tpmcsother = new TH1D("toppmcsother", "toppmcsother", nbin, xmin, xmax); TH1D *tcafesum = new TH1D("topcafesum", "topcafesum", nbin, xmin, xmax); TH1D *tpmcssum = new TH1D("toppmcssum", "toppmcssum", nbin, xmin, xmax); TH1D *tpmcsmbsum = new TH1D("toppmcsmbsum", "toppmcsmbsum", nbin, xmin, xmax); TH1D *tpmcsothersum = new TH1D("toppmcsothersum", "toppmcsothersum", nbin, xmin, xmax); TH1D *t = new TH1D("top", "top", nbin, xmin, xmax); TH1D *b = new TH1D("bottom", "bottom", nbin, xmin, xmax); TH2D *mbandset = new TH2D("mbandset", "mbandset", nbin, xmin, xmax, nbin, xmin, xmax); TH2D *otherandset = new TH2D("otherandset", "otherandset", nbin, xmin, xmax, nbin, xmin, xmax); TH1D *cafemb = new TH1D("cafemb", "cafemb", 500, 0, 125); TH1D *pmcsmb = new TH1D("pmcsmb", "pmcsmb", 500, 0, 125); TH1D *ratio = new TH1D("ratio", "ratio", 500, 0, 125); //TH1D *t = new TH1D("top", "top", 100, 0, 150); //TH1D *b = new TH1D("bottom", "bottom", 100, 0, 150); TTree *tree1(0); TFile *input1(0); TTree *tree2(0); TFile *input2(0); if (!gSystem->AccessPathName( rootfile1 )) { cout << "accessing " << rootfile1 << endl; input1 = TFile::Open( rootfile1 ); } else{ cout<< "problem accessing "<<rootfile1<< endl; exit(0); } tree1 = (TTree*)input1->Get(TreeName1); int nentries = tree1->GetEntries(); cout<<nentries<<" in tree"<<endl; if (!gSystem->AccessPathName( rootfile2 )) { cout << "accessing " << rootfile2 << endl; input2 = TFile::Open( rootfile2 ); } else{ cout<< "problem accessing "<<rootfile2<< endl; exit(0); } tree2 = (TTree*)input2->Get(TreeName2); int nentries2 = tree2->GetEntries(); cout<<nentries2<<" in tree"<<endl; // if(nentries > 1000000) nentries = 1000000; // if(nentries > 630000) nentries = 630000; // if(nentries2 > 630000) nentries2 = 630000; // if(nentries2 > 1000000) nentries2 = 1000000; float em_e[10]; float em_pt[10]; float em_eta[10]; float em_phi[10]; float em_deteta[10]; tree2->SetBranchAddress("em_pt", em_pt); tree2->SetBranchAddress("em_e", em_e); tree2->SetBranchAddress("em_eta", em_eta); tree2->SetBranchAddress("em_phi", em_phi); tree2->SetBranchAddress("em_deteta", em_deteta); // for (int j = 0; j < nentries2; j++){ // tree2->GetEntry(j); // tree2->GetLeaf("nelec")->GetValue(0) > 0 && // if((fabs(em_deteta[0]) < 1.1 ) && (fabs(em_deteta[1]) < 1.1 ) && tree2->GetLeaf("Ptz")->GetValue(0) < 3 && tree2->GetLeaf("Luminosity")->GetValue(0) < 3){ // tcafe->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0)); // tcafesum->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0), tree2->GetLeaf("ScalarEt")->GetValue(0)); // } // } float em_e1[10]; float em_pt1[10]; float em_eta1[10]; float em_phi1[10]; float em_deteta1[10]; tree1->SetBranchAddress("em_pt", em_pt1); tree1->SetBranchAddress("em_e", em_e1); tree1->SetBranchAddress("em_eta", em_eta1); tree1->SetBranchAddress("em_phi", em_phi1); tree1->SetBranchAddress("em_deteta", em_deteta1); // cout<<"here"<<endl; // nentries = 100000; double pmcsmbz = 0; double pmcsset = 0; double test = 0; double test2 = 0; double test3 = 0; double wgt = 0; for (int i = 0; i < nentries; i++){ //Need to do an iterative correction. Start with scale, adjust mb. then apply linear correction, refit. etc. This way approximation that cafe and pmcs set is the same during subtraction is better //Should be able to do cafe-pmcs and use weight on mb to make mb account for difference in shape (neg weight issue? scale first?) tree1->GetEntry(i); if((fabs(em_deteta1[0]) < 1.1 ) && (fabs(em_deteta1[1]) < 1.1 ) && tree1->GetLeaf("Ptz")->GetValue(0) < 3 && tree1->GetLeaf("Luminosity")->GetValue(0) < 20){ // cout<<i<<" of "<<nentries<<endl; // cout<<tree1->GetLeaf("ScalarEt")->GetValue(0)<<" "<<ratiotest->FindBin(tree1->GetLeaf("ScalarEt")->GetValue(0))<<endl; // cout<<ratiotest->GetBinContent(ratiotest->FindBin(tree1->GetLeaf("ScalarEt")->GetValue(0)))<<endl; // cout<<ratiotest->GetBinContent(20)<<endl; pmcsmbz = tree1->GetLeaf("MBScalarEt")->GetValue(0); wgt =1; // if(tree1->GetLeaf("MBScalarEt")->GetValue(0) < 5 ){ // if (tree1->GetLeaf("MBScalarEt")->GetValue(0) < 2.5 && tree1->GetLeaf("MBScalarEt")->GetValue(0) > 0.5) wgt = 2.5/tree1->GetLeaf("MBS//calarEt")->GetValue(0); // else wgt = tree1->GetLeaf("MBScalarEt")->GetValue(0)/5.0; // } if (tree1->GetLeaf("MBScalarEt")->GetValue(0) > 0.5 && tree1->GetLeaf("MBScalarEt")->GetValue(0) < 5 ){ wgt = 1.3; } /** //fixes 30-50 GeV part of curve if(tree1->GetLeaf("MBScalarEt")->GetValue(0) < 10 ){ wgt =0.5; } **/ // wgt = 0; //}else if (tree1->GetLeaf("MBScalarEt")->GetValue(0) < 1 ){ // wgt = 1 + int(gRandom->Gaus(1,2)); // cout<<gRandom->Gaus(2.5,2)<<endl; // } // }else if (tree1->GetLeaf("MBScalarEt")->GetValue(0) < 10 ){ // wgt = 2.0; // } // wgt = TMath::Power(pmcsmbz, 0.5/(10/(TMath::Sqrt(pmcsmbz)))) ; // wgt = TMath::Power(pmcsmbz, 0.5/(10/(TMath::Sqrt(pmcsmbz)))) + 0.2*pmcsmbz;// + pmcsmbz - 0.09*pmcsmbz*pmcsmbz; // wgt = (TMath::Power(pmcsmbz, 0.5)* (0.5 * (1. + TMath::Erf((pmcsmbz-.5)/(TMath::Sqrt(2)*5))))) / ((1+TMath::Exp(-1*TMath::Power(pmcsmbz/2, 2.0)))); //wgt = int( (TMath::Power(pmcsmbz, 0.4)) ); // wgt = (TMath::Power(pmcsmbz, 0.70 - tree1->GetLeaf("Luminosity")->GetValue(0)/50)); // if(tree1->GetLeaf("MBScalarEt")->GetValue(0) < 15){ // wgt = wgt*2.0/tree1->GetLeaf("MBScalarEt")->GetValue(0); //} // / (0.5 * (1. + TMath::Erf((pmcsmbz-.5)/(TMath::Sqrt(2)*1.0)))); // + (0.5 * (1. + TMath::Erf((pmcsmbz-.5)/(TMath::Sqrt(2)*5)))); //0.5 is good for upper region, 0.75 for middle //cout<<TMath::Power(pmcsmbz, 0.5/(10/(TMath::Sqrt(pmcsmbz))))<<" "<<(0.01 * (1. + TMath::Erf((pmcsmbz-5)/(TMath::Sqrt(2)))))<<endl; //wgt = 0.582 * (1. + TMath::Erf((pmcsmbz-1.0935)/(TMath::Sqrt(2)*4.3111))); // wgt = wgt*(0.53 * (1. + TMath::Erf((pmcsmbz-0.288)/(TMath::Sqrt(2)*4.0453)))); // wgt = wgt*(0.489 * (1. + TMath::Erf((pmcsmbz+0.305)/(TMath::Sqrt(2)*4.89144)))); /** //works ok-ish but doesn't work as weight (obviously...) pmcsmbz = tree1->GetLeaf("MBScalarEt")->GetValue(0)*1.5; pmcsmbz = pmcsmbz*(0.544657 * (1. + TMath::Erf((pmcsmbz-0.6808)/(TMath::Sqrt(2)*3.18052)))); pmcsmbz = pmcsmbz*(0.530694 * (1. + TMath::Erf((pmcsmbz-0.726896)/(TMath::Sqrt(2)*1.0429)))); pmcsmbz = pmcsmbz*(0.480563 * (1. + TMath::Erf((pmcsmbz-0.321864)/(TMath::Sqrt(2)*0.536511)))); **/ // pmcsmbz = pmcsmbz*(0.342784 * (1. + TMath::Erf((pmcsmbz-0.167683)/(TMath::Sqrt(2)*0.540161)))); //pmcsmbz = pmcsmbz*(0.9587 + 0.00365*pmcsmbz); // pmcsmbz = pmcsmbz*(0.903 + 0.007296*pmcsmbz + 0.00003*pmcsmbz*pmcsmbz - 0.00000119*pmcsmbz*pmcsmbz*pmcsmbz);//*ratiotest2->FindBin(tree1->GetLeaf("MBScalarEt")->GetValue(0)); // if (tree1->GetLeaf("ScalarEt")->GetValue(0) > 30) pmcsmbz = tree1->GetLeaf("MBScalarEt")->GetValue(0)*1.0*(0.42 + 0.0071*tree1->GetLeaf("ScalarEt")->GetValue(0));//*ratiotest->GetBinContent(ratiotest->FindBin(tree1->GetLeaf("MBScalarEt")->GetValue(0)));//1.4; //cout<<pmcsmbz<<endl; // pmcsmbz = pmcsmbz/(-0.00249 - (0.0003136*pmcsmbz) + (0.00121*pmcsmbz*pmcsmbz)); // if (pmcsmbz < 50) pmcsmbz = pmcsmbz/(-0.00005 - (0.00196*pmcsmbz) + (0.00132*pmcsmbz*pmcsmbz)); //cout<<pmcsmbz<<" new "<<endl; //below way over corrects... obviously not compensating for "other" correctly... // if (pmcsmbz > 0) pmcsmbz = pmcsmbz* ((0.5 * (1. + TMath::Erf((pmcsmbz-8.36)/(TMath::Sqrt(2)*4.9))))); // if (pmcsmbz > 0) pmcsmbz = TMath::Sqrt(pmcsmbz);// * (1/(0.5 * (1. + TMath::Erf((pmcsmbz-8.36)/(sqrt(2)*4.9))))); // else pmcsmbz = 0; pmcsset = tree1->GetLeaf("ScalarEt")->GetValue(0) - tree1->GetLeaf("MBScalarEt")->GetValue(0) + pmcsmbz; tpmcs->Fill(pmcsset, wgt);//minus mb plus mb tpmcsd->Fill(pmcsset); tpmcsother->Fill(pmcsset -pmcsmbz, wgt); tpmcsmb->Fill(pmcsmbz, wgt); pmcsmb->Fill(pmcsmbz, wgt); tpmcssum->Fill(pmcsset, pmcsset);//minus mb plus mb tpmcsothersum->Fill(pmcsset, pmcsset -pmcsmbz); tpmcsmbsum->Fill(pmcsset, pmcsmbz); test += pmcsset; test2 += pmcsset -pmcsmbz; test3 += pmcsmbz; //cout<<pmcsset<<" "<<pmcsset -pmcsmbz<<" "<<pmcsmbz<<endl; b->Fill(pmcsset, pmcsmbz); t->Fill(pmcsset, pmcsmbz - pmcsset); mbandset->Fill(pmcsset, pmcsmbz, wgt); otherandset->Fill(pmcsset, pmcsset -pmcsmbz, wgt); // tpmcs->Fill(pmcsmbz); // tpmcs->Fill((pmcsset - pmcsmbz) + (pmcsmbz*(1.25 + 0.005*pmcsmbz- 0.0002*pmcsmbz*pmcsmbz))); // tpmcs->Fill((pmcsset - pmcsmbz) + (pmcsmbz + (0.052 - 0.019*pmcsmbz+ 0.0018*pmcsmbz*pmcsmbz))); // tpmcs->Fill((pmcsset - pmcsmbz) + (pmcsmbz * (0.052 - 0.019*pmcsmbz+ 0.0018*pmcsmbz*pmcsmbz))); // tpmcs->Fill((pmcsset - pmcsmbz) + (1.6*pmcsmbz + (0.2 - 0.065*pmcsmbz+ 0.0023*pmcsmbz*pmcsmbz))); //uncomment top before using // tpmcs->Fill((pmcsset - pmcsmbz) + (pmcsmbz * (1.018 + 0.0319*pmcsmbz - 0.00228*pmcsmbz*pmcsmbz + 0.00008*pmcsmbz*pmcsmbz*pmcsmbz))); } } TH1D *tmp; int binz = 0; for (int j = 0; j < nentries2; j++){ tree2->GetEntry(j); // tree2->GetLeaf("nelec")->GetValue(0) > 0 && if((fabs(em_deteta[0]) < 1.1 ) && (fabs(em_deteta[1]) < 1.1 ) && tree2->GetLeaf("Ptz")->GetValue(0) < 3 && tree2->GetLeaf("Luminosity")->GetValue(0) < 20){ tcafe->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0)); tcafesum->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0), tree2->GetLeaf("ScalarEt")->GetValue(0)); binz = tpmcs->FindBin(tree2->GetLeaf("ScalarEt")->GetValue(0)); tmp = otherandset->ProjectionY("test"+j, binz, binz, ""); cafemb->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0) - tmp->GetRandom()); } } // for(int i = 0; i < nbin+1; i++){ // tmp = otherandset->ProjectionY("test"+i, i, i, ""); // cafemb->Fill(tcafe->GetXaxis()->GetBinCenter(i) - tmp->GetRandom()); // } TCanvas *c5 = new TCanvas("c5","c5",800,800); cafemb->Draw(); pmcsmb->Scale(cafemb->Integral()/pmcsmb->Integral()); pmcsmb->SetLineColor(kBlue); pmcsmb->Draw("same"); c5->Update(); TCanvas *c4 = new TCanvas("c4","c4",800,800); tpmcsmbsum->Scale(tcafesum->Integral()/tpmcssum->Integral());//orget enertries? tpmcsothersum->Scale(tcafesum->Integral()/tpmcssum->Integral()); tpmcssum->Scale(tcafesum->Integral()/tpmcssum->Integral()); tpmcssum->Draw(); tcafesum->SetMarkerColor(kRed); tcafesum->SetLineColor(kRed); tcafesum->Draw("same"); tpmcsmbsum->SetLineColor(kBlue); tpmcsmbsum->Draw("same"); tpmcsothersum->SetLineColor(kGreen); tpmcsothersum->Draw("same"); c4->Update(); c4->Print("PlotSETPTPMCS_RecoVarAfterFITSUM_"+var+".eps"); c4->Print("PlotSETPTPMCS_RecoVarAfterFITSUM_"+var+".gif"); TCanvas *c3 = new TCanvas("c3","c3",800,800); tpmcsmb->Scale(tcafe->Integral()/tpmcs->Integral()); tpmcsother->Scale(tcafe->Integral()/tpmcs->Integral()); tpmcs->Scale(tcafe->Integral()/tpmcs->Integral()); tpmcsd->Scale(tcafe->Integral()/tpmcsd->Integral()); tpmcs->Draw(); tpmcsd->SetMarkerColor(kMagenta); tpmcsd->SetLineColor(kMagenta); tpmcsd->Draw("same"); tcafe->SetMarkerColor(kRed); tcafe->SetLineColor(kRed); tcafe->Draw("same"); tpmcsmb->SetLineColor(kBlue); tpmcsmb->Draw("same"); tpmcsother->SetLineColor(kGreen); tpmcsother->Draw("same"); cout<<test<<" "<<test2<<" "<<test3<<endl; cout<<tpmcs->Integral()<<" "<<tpmcsmb->Integral()<<" "<<tpmcsother->Integral()<<endl; c3->Update(); c3->Print("PlotSETPTPMCS_RecoVarAfterFIT_"+var+".eps"); c3->Print("PlotSETPTPMCS_RecoVarAfterFIT_"+var+".gif"); TCanvas *c1 = new TCanvas("c1","c1",800,800); t->Scale(tcafe->Integral()/t->Integral()); //Would have to randomly get a SET value from CAFe distribution (treat it like pdf) and subtract the setother from PMCS to get cafemb, event by event. // for(int i = 0; i < nbin+1; i++){ // t->SetBinContent(i, tcafe->GetXaxis()->GetBinCenter() - t->GetXaxis()->GetBinCenter() t->Add(tcafe); b->Scale(t->Integral()/b->Integral()); b->Draw(); t->SetMarkerColor(kRed); t->SetLineColor(kRed); t->Draw("same"); c1->Update(); c1->Print("PlotSETPTPMCS_MB_"+var+".eps"); c1->Print("PlotSETPTPMCS_MB_"+var+".gif"); TCanvas *c2 = new TCanvas("c2","c2",800,800); //for ratio want (cafe(set+mbset) - pmcs(set))/pmcsmb // ratio->Divide(t, b,1.0,1.0,"B"); // ratio->Divide(tpmcs, tcafe,1.0,1.0,"B"); ratio->Divide(cafemb, pmcsmb,1.0,1.0,"B"); ratio->Draw(); TF1 *func = new TF1("func",fitexp,0,125,3); // func->SetParameter(0, 0.0); // func->SetParameter(1, 30000); // func->SetParameter(2, 300000); // func->SetParameter(3, 0.1); func->SetParameter(0, 10.0); func->SetParameter(1, 10.0); func->SetParameter(2, 0.6); // func->SetParameter(2, 0.0015); // func->SetParameter(3, 0.0015); // func->FixParameter(0, 11); // func->FixParameter(1, 40); // func->FixParameter(2, 250000); //func->FixParameter(3, 5); // t->Fit("func", "+R"); // t->Draw(); ratio->Fit("func", "+R"); ratio->Draw(); c2->Update(); c2->Print("PlotSETPTPMCS_Ratio_"+var+".eps"); c2->Print("PlotSETPTPMCS_Ratio_"+var+".gif"); TCanvas *c6 = new TCanvas("c6","c6",800,800); mbandset->Draw("colz"); c6->Update(); c6->Print("PlotSETPTPMCS_MBandSET_"+var+".eps"); c6->Print("PlotSETPTPMCS_MBandSET_"+var+".gif"); }
TH2D * TrackTrackSignal(double pttriglow , double pttrighigh , double ptasslow , double ptasshigh, int centmin, int centmax, double vzrange) { Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D * hTrackTrackSignal = new TH2D(Form("signal_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",100,-5,5,75,-pi,2*pi); double ntottrig = 0; int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { if(jentry%1000==0) cout<<jentry-cent_index_start[centmin]<<"/"<<n_entries_in_cent_range<<endl; c->GetEntry(jentry); // if(c->evt->hiBin < centmin) continue; // if(c->evt->hiBin >= centmax) break; if(fabs(c->evt->vz)>vzrange) continue; int ntrig = 0 , nass = 0; vector<double> trigtrkEta; vector<double> trigtrkPhi; vector<double> trigtrkIndex; vector<double> asstrkEta; vector<double> asstrkPhi; vector<double> asstrkIndex; for(int i = 0 ; i < c->track->nTrk ; ++i) { if( c->track->trkPt[i]<pttriglow || c->track->trkPt[i]>pttrighigh || fabs(c->track->trkEta[i])>maxetatrg ) continue; ++ntrig; trigtrkEta.push_back(c->track->trkEta[i]); trigtrkPhi.push_back(c->track->trkPhi[i]); trigtrkIndex.push_back(i); } for(int j = 0 ; j < c->track->nTrk ; ++j) { if( c->track->trkPt[j]<ptasslow || c->track->trkPt[j]>ptasshigh || fabs(c->track->trkEta[j])>maxetaass) continue; ++nass; asstrkEta.push_back(c->track->trkEta[j]); asstrkPhi.push_back(c->track->trkPhi[j]); asstrkIndex.push_back(j); } for(int i = 0 ; i < ntrig ; ++i) { ntottrig += 1; for(int j = 0 ; j < nass ; ++j) { if(trigtrkIndex[i]==asstrkIndex[j]) continue; double deta = fabs(trigtrkEta[i]-asstrkEta[j]); double dphi = fabs(trigtrkPhi[i]-asstrkPhi[j]); if( dphi > pi ) dphi = 2*pi - dphi; hTrackTrackSignal->Fill(deta,dphi); hTrackTrackSignal->Fill(-deta,dphi); hTrackTrackSignal->Fill(deta,-dphi); hTrackTrackSignal->Fill(-deta,-dphi); hTrackTrackSignal->Fill(deta,(2*pi)-dphi); hTrackTrackSignal->Fill(-deta,(2*pi)-dphi); } } // if(jentry>100) break; } hTrackTrackSignal->Scale(1/ntottrig); return hTrackTrackSignal; }
void CaloHitAna::Loop(bool useProtonCut) { if (fChain == 0) return; TFile *fcut = TFile::Open("qpid_cuts.root", "read"); if(!fcut) { cerr << "Could not open qpid_cuts.root for reading!\n"; return; } TCutG *cut_proton = dynamic_cast<TCutG*>(fcut->Get("qpid_proton")); if(!cut_proton) { cerr << "Could not find TCutG qpid_proton!\n"; return; } TCutG *cut_pspx = dynamic_cast<TCutG*>(fcut->Get("pspx_zminus2")); if(!cut_pspx) { cerr << "Could not find TCutG pspx_zminus1\n"; return; } fcut->Close(); delete fcut; TH2D *hee = new TH2D("evse", "E1 vs E2", 200, 0, 400000, 200, 0, 400000); TH2D *htt = new TH2D("thetavstheta", "Theta 1 vs Theta 2", 16, 27.2, 61.9, 16, 27.2, 61.9); TH2D *hpp = new TH2D("phivsphi", "Phi 1 vs Phi 2", 180, 0, 180, 180, 180, 360); TH1D *hsumtheta = new TH1D("hSumTheta", "Sum Theta", 180, 0, 180); TH1D *hdiffphi = new TH1D("hDiffPhi", "Dela Phi", 180, 0, 180); TH1D *hegamma = new TH1D("hEgamma", "Gamma Energy", 1000, 0, 10000); Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; int i; int idxEmax1, idxEmax2; Double_t sumTheta, eGamma; for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; if(CaloHit_ < 2) continue; // Only take Z-1 events if(!cut_pspx->IsInside(Pspx04e, Pspx05e)) continue; idxEmax1 = -1; idxEmax2 = -1; for(i = 0; i < CaloHit_; i++) { // Only consider completely stopped protons if(cut_proton->IsInside(CaloHit_fNf[i], CaloHit_fNs[i]) && CaloHit_fPhi[i] < TMath::Pi() && (idxEmax1 == -1 || CaloHit_fEnergy[i] > CaloHit_fEnergy[idxEmax1])) { // Petal 1 idxEmax1 = i; } else if(cut_proton->IsInside(CaloHit_fNf[i], CaloHit_fNs[i]) && CaloHit_fPhi[i] >= TMath::Pi() && (idxEmax2 == -1 || CaloHit_fEnergy[i] > CaloHit_fEnergy[idxEmax2])) { // Petal 2 idxEmax2 = i; } // if(idxEmax1 == -1 || CaloHit_fEnergy[i] > CaloHit_fEnergy[idxEmax1]) // { // idxEmax2 = idxEmax1; // idxEmax1 = i; // } // else if(idxEmax2 == -1 || CaloHit_fEnergy[i] > CaloHit_fEnergy[idxEmax2]) // idxEmax2 = i; } if(idxEmax1 != -1 && idxEmax2 != -1) { sumTheta = (CaloHit_fTheta[idxEmax1] + CaloHit_fTheta[idxEmax2]) * 180.0 / TMath::Pi(); htt->Fill(CaloHit_fTheta[idxEmax1] * 180.0 / TMath::Pi(), CaloHit_fTheta[idxEmax2] * 180.0 / TMath::Pi()); hpp->Fill(CaloHit_fPhi[idxEmax1] * 180.0 / TMath::Pi(), CaloHit_fPhi[idxEmax2] * 180.0 / TMath::Pi()); hsumtheta->Fill(sumTheta); hdiffphi->Fill((CaloHit_fPhi[idxEmax2] - CaloHit_fPhi[idxEmax1]) * 180.0 / TMath::Pi()); if(sumTheta >= 70.0 && sumTheta <= 90.0) { hee->Fill(CaloHit_fEnergy[idxEmax1], CaloHit_fEnergy[idxEmax2]); // Try to find coincident gammas if(CaloHit_ > 2) { for(i = 0; i < CaloHit_; i++) { if(i != idxEmax1 && i != idxEmax2 && (eGamma = Doppler(CaloHit_fEnergy[i], CaloHit_fTheta[i])) < 10000) // ToDo: Doppler correction hegamma->Fill(eGamma); } } } } } }
void Parity_pi(int cen=1) { //main_function struct StRefMultCorr refmultCorrUtil = StRefMultCorr("refmult") ; delete gRandom; gRandom = new TRandom3(0); float Eweight = 1; const int Phibin = 80; char fname[200]; float PsiShiftE1=0,PsiShiftE2=0,PsiShiftE3=0,PsiShiftE4=0; float PsiShiftW1=0,PsiShiftW2=0,PsiShiftW3=0,PsiShiftW4=0; float PsiShiftf1=0,PsiShiftf2=0,PsiShiftf3=0,PsiShiftf4=0; float PsiShiftb1=0,PsiShiftb2=0,PsiShiftb3=0,PsiShiftb4=0; float PsiShiftF1=0,PsiShiftF2=0,PsiShiftF3=0,PsiShiftF4=0; const int order = 1; float PhiMean[4*order]= {0,}; float PhiWgtFF[Phibin][4],PhiWgtRF[Phibin][4]; TProfile2D *TPCmean_FF, *TPCmean_RF; TH2D *TPCPhi_FF, *TPCPhi_RF; TProfile2D *Read_TPC_EP_full, *Read_TPC_EP_east, *Read_TPC_EP_west, *Read_TPC_EP_for, *Read_TPC_EP_bac; sprintf(fname,"cen%d.weight_pi_minbias5.root",cen); TFile *fWgt=new TFile(fname,"READ"); if(!fWgt->IsOpen()) cout<<"no phi weight files!"<<endl; if(fWgt->IsOpen()) { TPCmean_FF = (TProfile2D*)fWgt->Get("TPCmeanPhi_FF"); TPCmean_RF = (TProfile2D*)fWgt->Get("TPCmeanPhi_RF"); TPCPhi_FF = (TH2D*)fWgt->Get("Hist_Phi_FF"); TPCPhi_RF = (TH2D*)fWgt->Get("Hist_Phi_RF"); Read_TPC_EP_full = (TProfile2D*)fWgt->Get("pTPC_EP_full"); Read_TPC_EP_east = (TProfile2D*)fWgt->Get("pTPC_EP_east"); Read_TPC_EP_west = (TProfile2D*)fWgt->Get("pTPC_EP_west"); Read_TPC_EP_for = (TProfile2D*)fWgt->Get("pTPC_EP_for"); Read_TPC_EP_bac = (TProfile2D*)fWgt->Get("pTPC_EP_bac"); for(int j=0; j<4; j++) { float PhiMeanFF = TPCPhi_FF->ProjectionX("",j+1,j+1)->GetSum()/(float)Phibin; float PhiMeanRF = TPCPhi_RF->ProjectionX("",j+1,j+1)->GetSum()/(float)Phibin; for(int i=0; i<Phibin; i++) { PhiWgtFF[i][j] = (TPCPhi_FF->GetBinContent(i+1,j+1)>0)? PhiMeanFF/(TPCPhi_FF->GetBinContent(i+1,j+1)):1; PhiWgtRF[i][j] = (TPCPhi_RF->GetBinContent(i+1,j+1)>0)? PhiMeanRF/(TPCPhi_RF->GetBinContent(i+1,j+1)):1; //cout<<" PhiWgt= "<<PhiWgt[i][j]; } } } else { for(int j=0; j<4; j++) for(int i=0; i<Phibin; i++) { PhiWgtFF[i][j] = 1; PhiWgtRF[i][j] = 1; } } /* //prepare the files int nfile = 0; TChain* chain = new TChain("StrangenessDst"); std::ifstream inlist(InputFileList); if(!inlist)cout<<" can't open file "<<endl; //prepare the files char *fileName=new char[200]; while(!inlist.eof()) { inlist.getline(fileName,200,'\n'); if(!inlist.eof()) nfile += chain->Add(fileName); } */ TChain* chain = new TChain("StrangenessDst"); int nfile = 0; nfile += chain->Add("/media/Disk_Chen/Data/200GeV_run11/data_minbias5_new/*.flow.nt.root"); cout <<"Added "<<nfile<<" files"<<endl; cout<<"# entries in chain: "<<chain->GetEntries()<<endl; char fname_out[200]; sprintf(fname_out,"cen%d.ntuple_result_Parity_pi_minbias5_eff.root",cen); TFile fout(fname_out,"RECREATE"); //defining variables Float_t PVtxz, VPDvz, Bz, psi_E, psi_W, mod_E, mod_W, ZDCe, ZDCw, ZDCcoin, BBCco; //run, event info Int_t Run, Day, Day2, Day3, Event, Trigger, RefMult, TOFMult, Centrality, NPTracks; // Float_t Charge, ndEdx, nSigma_p, nSigma_pi, DCAGlobal, Eta, Theta, Phi, Pt; //track info //defining histograms TH1D* hEventTally = new TH1D("EventTally","Event Tally",10,0,1); hEventTally->SetBit(TH1::kCanRebin); hEventTally->SetStats(0); TProfile *Ref_Day3 = new TProfile("Ref_Day3","RefMult vs Run",100000,80000,180000,-0.5,999.5); TProfile *TOF_Day3 = new TProfile("TOF_Day3","TOFMult vs Run",100000,80000,180000,0,5000); TProfile *NPT_Day3 = new TProfile("NPT_Day3","NPTracks vs Run",100000,80000,180000,0,2000); TProfile *TPC_Day3_cos2 = new TProfile("TPC_Day3_cos2","cos(2*psi) vs Run", 100000,80000,180000,-1,1); TProfile *TPC_Day3_sin2 = new TProfile("TPC_Day3_sin2","sin(2*psi) vs Run", 100000,80000,180000,-1,1); TH1D *Hist_RefMult = new TH1D("Hist_RefMult","Hist_RefMult",1000,-0.5,999.5); TH1D *Hist_TOFMult = new TH1D("Hist_TOFMult","Hist_TOFMult",5000,-0.5,4999.5); TProfile *p_RefMult = new TProfile("p_RefMult","p_RefMult",50,0.5,1000.5, 0,1000, ""); TProfile *p_TOFMult = new TProfile("p_TOFMult","p_TOFMult",50,0.5,5000.5, 0,5000, ""); TH1D *hBz = new TH1D("hBz","magnetic field",10, -10, 10); TH1D *hTrigger = new TH1D("hTrigger","hTrigger",400, 0.5, 400.5); TH1D *hCentrality = new TH1D("hCentrality","hCentrality",10,0,10); TH1D *hVertexZ = new TH1D("hVertexZ","hVertexZ",100,-100,100); TH2D *hMult_Vz = new TH2D("hMult_Vz","hMult_Vz",1000,-0.5,999.5,100,-100,100); TH2D *hMult_Vz_new = new TH2D("hMult_Vz_new","hMult_Vz_new",1000,-0.5,999.5,100,-100,100); TH1D *hBBC_coin = new TH1D("hBBC_coin","hBBC_coin",120,0,60000); TProfile2D *pTPCmeanPhi_FF = new TProfile2D("TPCmeanPhi_FF","TPCmeanPhi_FF", 8*order,0.5,8*order+0.5,10000,8000,18000,-1,1,""); TProfile2D *pTPCmeanPhi_RF = new TProfile2D("TPCmeanPhi_RF","TPCmeanPhi_RF", 8*order,0.5,8*order+0.5,10000,8000,18000,-1,1,""); TH1D* Hist_proton = new TH1D("Hist_proton","Hist_proton",50,-0.5,49.5); TH1D* Hist_pbar = new TH1D("Hist_pbar","Hist_pbar",50,-0.5,49.5); TH1D* Hist_netP = new TH1D("Hist_netP","Hist_netP",99,-49.5,49.5); TH2D *hEtaPtDist = new TH2D("EtaPtDist","EtaPtDist",26, -1.3, 1.3,300,0,15); TH2D* Hist_Phi = new TH2D("Hist_Phi","Hist_Phi",Phibin,-PI,PI,4,0.5,4.5); TH2D* Hist_TPC_EP_east = new TH2D("Hist_TPC_EP_east","Hist_TPC_EP_east",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_west = new TH2D("Hist_TPC_EP_west","Hist_TPC_EP_west",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_for = new TH2D("Hist_TPC_EP_for","Hist_TPC_EP_for",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_bac = new TH2D("Hist_TPC_EP_bac","Hist_TPC_EP_bac",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_full = new TH2D("Hist_TPC_EP_full","Hist_TPC_EP_full",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_east_flat = new TH2D("Hist_TPC_EP_east_flat","Hist_TPC_EP_east_flat",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_west_flat = new TH2D("Hist_TPC_EP_west_flat","Hist_TPC_EP_west_flat",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_for_flat = new TH2D("Hist_TPC_EP_for_flat","Hist_TPC_EP_for_flat",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_bac_flat = new TH2D("Hist_TPC_EP_bac_flat","Hist_TPC_EP_bac_flat",36,0,PI,100,80,180); TH2D* Hist_TPC_EP_full_flat = new TH2D("Hist_TPC_EP_full_flat","Hist_TPC_EP_full_flat",36,0,PI,100,80,180); TProfile2D* pTPC_EP_east = new TProfile2D("pTPC_EP_east","pTPC_EP_east",4,0.5,4.5,100,80,180,-1,1,""); TProfile2D* pTPC_EP_west = new TProfile2D("pTPC_EP_west","pTPC_EP_west",4,0.5,4.5,100,80,180,-1,1,""); TProfile2D* pTPC_EP_for = new TProfile2D("pTPC_EP_for","pTPC_EP_for",4,0.5,4.5,100,80,180,-1,1,""); TProfile2D* pTPC_EP_bac = new TProfile2D("pTPC_EP_bac","pTPC_EP_bac",4,0.5,4.5,100,80,180,-1,1,""); TProfile2D* pTPC_EP_full = new TProfile2D("pTPC_EP_full","pTPC_EP_full",4,0.5,4.5,100,80,180,-1,1,""); TH1F* Hist_dif_count = new TH1F("Hist_dif_count","Hist_dif_count",500,-250,250); TH1F* Hist_ful_count = new TH1F("Hist_ful_count","Hist_ful_count",1000,0,1000); TH1D* Hist_Pt = new TH1D("Hist_Pt","Hist_Pt",300,0,15); TH1D* Hist_Pt_TOF = new TH1D("Hist_Pt_TOF","Hist_Pt_TOF",300,0,15); TH1D* rc; TH2D* Hist_Phi_FF = new TH2D("Hist_Phi_FF","Hist_Phi_FF",Phibin,-PI,PI,4,0.5,4.5); TH2D* Hist_Phi_RF = new TH2D("Hist_Phi_RF","Hist_Phi_RF",Phibin,-PI,PI,4,0.5,4.5); TH2D* Hist_Phi_FF_new = new TH2D("Hist_Phi_FF_new","Hist_Phi_FF_new",Phibin,-PI,PI,4,0.5,4.5); TH2D* Hist_Phi_RF_new = new TH2D("Hist_Phi_RF_new","Hist_Phi_RF_new",Phibin,-PI,PI,4,0.5,4.5); TProfile *Hist_cos = new TProfile("Hist_cos","Hist_cos",2,0.5,2.5,-1,1,""); TProfile2D *Hist_cos_RefMult = new TProfile2D("Hist_cos_RefMult","Hist_cos_RefMult",2,0.5,2.5, 50,0.5,1000.5,-1,1,""); TProfile2D *Hist_cos_TOFMult = new TProfile2D("Hist_cos_TOFMult","Hist_cos_TOFMult",2,0.5,2.5, 50,0.5,5000.5,-1,1,""); TProfile2D *Hist_cos_ZDC = new TProfile2D("Hist_cos_ZDC","Hist_cos_ZDC",2,0.5,2.5, 50,0.5,20000.5,-1,1,""); TProfile2D *Hist_cos_BBC_RefMult = new TProfile2D("Hist_cos_BBC_RefMult","Hist_cos_BBC_RefMult",60,0,60000, 50,0.5,1000.5,-1,1,""); TH1D* hDpt = new TH1D("hDpt","hDpt",200,0,2); TH1D* hQinv = new TH1D("hQinv","hQinv",1000,0,10); TH1D* hQinv2 = new TH1D("hQinv2","hQinv2",1100,-1,10); TProfile *p_v2_RefMult_obs = new TProfile("p_v2_RefMult_obs","p_v2_RefMult_obs",50,0.5, 1000.5,-100,100,""); TProfile *p_v2_TOFMult_obs = new TProfile("p_v2_TOFMult_obs","p_v2_TOFMult_obs",50,0.5,5000.5,-100,100,""); TProfile *p_v2_ZDC_obs = new TProfile("p_v2_ZDC_obs","p_v2_ZDC_obs",50,0.5,20000.5,-100,100,""); TProfile2D *p_v2_BBC_RefMult_obs = new TProfile2D("p_v2_BBC_RefMult_obs","p_v2_BBC_RefMult_obs",60,0,60000,50,0.5, 1000.5,-100,100,""); TProfile *p_RefMult_ZDC_obs = new TProfile("p_RefMult_ZDC_obs","p_RefMult_ZDC_obs",50,0.5,20000.5,0,1000,""); TProfile *p_TOFMult_ZDC_obs = new TProfile("p_TOFMult_ZDC_obs","p_TOFMult_ZDC_obs",50,0.5,20000.5,0,5000,""); TProfile *pParity_int_obs1 = new TProfile("Parity_int_obs1","Parity_int_obs1",4,0.5,4.5,-100,100,""); TProfile *pParity_int_obs2 = new TProfile("Parity_int_obs2","Parity_int_obs2",4,0.5,4.5,-100,100,""); TProfile *pParity_int_obs3 = new TProfile("Parity_int_obs3","Parity_int_obs3",4,0.5,4.5,-100,100,""); TProfile *pParity_int_r_obs1 = new TProfile("Parity_int_r_obs1","Parity_int_r_obs1",4,0.5,4.5,-1600,1600,""); TProfile *pParity_int_r_obs2 = new TProfile("Parity_int_r_obs2","Parity_int_r_obs2",4,0.5,4.5,-1600,1600,""); TProfile *pParity_int_r_obs3 = new TProfile("Parity_int_r_obs3","Parity_int_r_obs3",4,0.5,4.5,-1600,1600,""); TProfile *pParity_int_rr_obs1 = new TProfile("Parity_int_rr_obs1","Parity_int_rr_obs1",4,0.5,4.5,-1600,1600,""); TProfile *pParity_int_rr_obs2 = new TProfile("Parity_int_rr_obs2","Parity_int_rr_obs2",4,0.5,4.5,-1600,1600,""); TProfile *pParity_int_rr_obs3 = new TProfile("Parity_int_rr_obs3","Parity_int_rr_obs3",4,0.5,4.5,-1600,1600,""); TProfile *pParity_int_s_obs1 = new TProfile("Parity_int_s_obs1","Parity_int_s_obs1",4,0.5,4.5,-100,100,""); TProfile *pParity_int_s_obs2 = new TProfile("Parity_int_s_obs2","Parity_int_s_obs2",4,0.5,4.5,-100,100,""); TProfile *pParity_int_s_obs3 = new TProfile("Parity_int_s_obs3","Parity_int_s_obs3",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ss_obs1 = new TProfile("Parity_int_ss_obs1","Parity_int_ss_obs1",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ss_obs2 = new TProfile("Parity_int_ss_obs2","Parity_int_ss_obs2",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ss_obs3 = new TProfile("Parity_int_ss_obs3","Parity_int_ss_obs3",4,0.5,4.5,-100,100,""); TProfile *pParity_int_w_obs1 = new TProfile("Parity_int_w_obs1","Parity_int_w_obs1",4,0.5,4.5,-100,100,""); TProfile *pParity_int_w_obs2 = new TProfile("Parity_int_w_obs2","Parity_int_w_obs2",4,0.5,4.5,-100,100,""); TProfile *pParity_int_w_obs3 = new TProfile("Parity_int_w_obs3","Parity_int_w_obs3",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ww_obs1 = new TProfile("Parity_int_ww_obs1","Parity_int_ww_obs1",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ww_obs2 = new TProfile("Parity_int_ww_obs2","Parity_int_ww_obs2",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ww_obs3 = new TProfile("Parity_int_ww_obs3","Parity_int_ww_obs3",4,0.5,4.5,-100,100,""); TProfile *pParity_int_same_run = new TProfile("Parity_int_same_run","Parity_int_same_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_rr_same_run = new TProfile("Parity_int_rr_same_run","Parity_int_rr_same_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_ss_same_run = new TProfile("Parity_int_ss_same_run","Parity_int_ss_same_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_ww_same_run = new TProfile("Parity_int_ww_same_run","Parity_int_ww_same_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_oppo_run = new TProfile("Parity_int_oppo_run","Parity_int_oppo_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_rr_oppo_run = new TProfile("Parity_int_rr_oppo_run","Parity_int_rr_oppo_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_ss_oppo_run = new TProfile("Parity_int_ss_oppo_run","Parity_int_ss_oppo_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_ww_oppo_run = new TProfile("Parity_int_ww_oppo_run","Parity_int_ww_oppo_run",10000,8000,18000,-100,100,""); TProfile *pParity_int_ss_ran_obs1 = new TProfile("Parity_int_ss_ran_obs1","Parity_int_ss_ran_obs1",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ss_ran_obs2 = new TProfile("Parity_int_ss_ran_obs2","Parity_int_ss_ran_obs2",4,0.5,4.5,-100,100,""); TProfile *pParity_int_ss_ran_obs3 = new TProfile("Parity_int_ss_ran_obs3","Parity_int_ss_ran_obs3",4,0.5,4.5,-100,100,""); TProfile2D *pParity_eta_ss_obs1 = new TProfile2D("Parity_eta_ss_obs1","Parity_eta_ss_obs1",12,0.5,12.5,20,-1,1,-100,100,""); TProfile2D *pParity_eta_ss_obs2 = new TProfile2D("Parity_eta_ss_obs2","Parity_eta_ss_obs2",12,0.5,12.5,20,-1,1,-100,100,""); TProfile2D *pParity_eta_ss_obs3 = new TProfile2D("Parity_eta_ss_obs3","Parity_eta_ss_obs3",12,0.5,12.5,20,-1,1,-100,100,""); TProfile2D *pParity_Deta_ss_obs1 = new TProfile2D("Parity_Deta_ss_obs1","Parity_Deta_ss_obs1",12,0.5,12.5,20,0,2,-100,100,""); TProfile2D *pParity_Deta_ss_obs2 = new TProfile2D("Parity_Deta_ss_obs2","Parity_Deta_ss_obs2",12,0.5,12.5,20,0,2,-100,100,""); TProfile2D *pParity_Deta_ss_obs3 = new TProfile2D("Parity_Deta_ss_obs3","Parity_Deta_ss_obs3",12,0.5,12.5,20,0,2,-100,100,""); TProfile2D *pParity_pt_ss_obs1 = new TProfile2D("Parity_pt_ss_obs1","Parity_pt_ss_obs1",12,0.5,12.5,20,0,2.0,-100,100,""); TProfile2D *pParity_pt_ss_obs2 = new TProfile2D("Parity_pt_ss_obs2","Parity_pt_ss_obs2",12,0.5,12.5,20,0,2.0,-100,100,""); TProfile2D *pParity_pt_ss_obs3 = new TProfile2D("Parity_pt_ss_obs3","Parity_pt_ss_obs3",12,0.5,12.5,20,0,2.0,-100,100,""); TProfile2D *pParity_Dpt_ss_obs1 = new TProfile2D("Parity_Dpt_ss_obs1","Parity_Dpt_ss_obs1",12,0.5,12.5,200,0,2.0,-100,100,""); TProfile2D *pParity_Dpt_ss_obs2 = new TProfile2D("Parity_Dpt_ss_obs2","Parity_Dpt_ss_obs2",12,0.5,12.5,200,0,2.0,-100,100,""); TProfile2D *pParity_Dpt_ss_obs3 = new TProfile2D("Parity_Dpt_ss_obs3","Parity_Dpt_ss_obs3",12,0.5,12.5,200,0,2.0,-100,100,""); TProfile2D *pParity_Q_ss_obs1 = new TProfile2D("Parity_Q_ss_obs1","Parity_Q_ss_obs1",4,0.5,4.5,500,0,5.0,-100,100,""); TProfile2D *pParity_Q_ss_obs2 = new TProfile2D("Parity_Q_ss_obs2","Parity_Q_ss_obs2",4,0.5,4.5,500,0,5.0,-100,100,""); TProfile2D *pParity_Q_ss_obs3 = new TProfile2D("Parity_Q_ss_obs3","Parity_Q_ss_obs3",4,0.5,4.5,500,0,5.0,-100,100,""); TProfile *pParity_noHBT_ss_obs2 = new TProfile("Parity_noHBT_ss_obs2","Parity_noHBT_ss_obs2",4,0.5,4.5,-100,100,""); TProfile *pParity_noHBT_ss_obs3 = new TProfile("Parity_noHBT_ss_obs3","Parity_noHBT_ss_obs3",4,0.5,4.5,-100,100,""); Int_t nentries = chain->GetEntries(); // nentries = 50000; //loop through events for(int i = 0; i < nentries; i++) { if((i+1)%1000==0) cout<<"Processing entry == "<< i+1 <<" == out of "<<nentries<<".\n"; chain->GetEntry(i); TLeaf* leaf_RunId = chain->GetLeaf("mRunId"); TLeaf* leaf_EventId = chain->GetLeaf("mEventId"); TLeaf* leaf_Trigger = chain->GetLeaf("mTrigger"); TLeaf* leaf_Bz = chain->GetLeaf("mBfield"); TLeaf* leaf_PrimaryVertexZ = chain->GetLeaf("mPrimaryVertexPositionZ"); TLeaf* leaf_VPDVz = chain->GetLeaf("mVPDEWdiff"); TLeaf* leaf_RefMult = chain->GetLeaf("mRefMult"); TLeaf* leaf_TOFMult = chain->GetLeaf("mTOFmult"); TLeaf* leaf_Centrality = chain->GetLeaf("mCentrality"); TLeaf* leaf_ZDC_EP = chain->GetLeaf("mZDC_EP"); TLeaf* leaf_ZDC = chain->GetLeaf("mZDC"); TLeaf* leaf_ZDCcoin = chain->GetLeaf("mZDCCoin"); TLeaf* leaf_BBCco = chain->GetLeaf("mBBCCoin"); TLeaf* leaf_NoTracks = chain->GetLeaf("mNumberOfV0s"); Run = (int)leaf_RunId->GetValue(0); Event = (int)leaf_EventId->GetValue(0); Trigger = (int)leaf_Trigger->GetValue(0); Bz = leaf_Bz->GetValue(0); PVtxz = leaf_PrimaryVertexZ->GetValue(0); VPDvz = leaf_VPDVz->GetValue(0); RefMult = (int)leaf_RefMult->GetValue(0); TOFMult = (int)leaf_TOFMult->GetValue(0); NPTracks= (int)leaf_NoTracks->GetValue(0); ZDCw = leaf_ZDC->GetValue(1) + leaf_ZDC->GetValue(2) + leaf_ZDC->GetValue(3); ZDCe = leaf_ZDC->GetValue(5) + leaf_ZDC->GetValue(6) + leaf_ZDC->GetValue(7); ZDCcoin = leaf_ZDCcoin->GetValue(0); BBCco = leaf_BBCco->GetValue(0); psi_E = leaf_ZDC_EP->GetValue(0); psi_W = leaf_ZDC_EP->GetValue(2); mod_E = leaf_ZDC_EP->GetValue(1); mod_W = leaf_ZDC_EP->GetValue(3); Centrality = leaf_Centrality->GetValue(0); Day = (int)((Run-12000000)/1000); Day2 = (int)((Run-12000000)/10); Day3 = (int)((Run-12000000)/1); int Bad =0; for(int jj=0; jj<12; jj++) if(Day2== bad_Ref_day2[jj]) { Bad = 1; break; } if(Day3<=138024) { for(int jj=0; jj<Nrun_MB1; jj++) if(Day3 == bad_Ref_day3_MB1[jj]) { Bad = 1; break; } } else if(Day3<=145020) { for(int jj=0; jj<Nrun_MB2; jj++) if(Day3 == bad_Ref_day3_MB2[jj]) { Bad = 1; break; } } else if(Day3<=154021) {} else if(Day3<=165031) { for(int jj=0; jj<Nrun_MB5; jj++) if(Day3 == bad_Ref_day3_MB5[jj]) { Bad = 1; break; } } else { for(int jj=0; jj<Nrun_MB6; jj++) if(Day3 == bad_Ref_day3_MB6[jj]) { Bad = 1; break; } } if(Bad) continue; //bad run if(RefMult) { float gM = 0.9995 + 21.89/(4.191*RefMult-18.17) - 2.723e-5*(4.191*RefMult-18.17); Eweight = gM + 0.0009326*(gM-1)*PVtxz; } hBz->Fill(Bz); hTrigger->Fill(Trigger); if((Trigger%5)<2) continue; Centrality = 0; for(int j=0; j<9; j++) if(RefMult>cenDef[j]) Centrality = j+1; refmultCorrUtil.init(Run); if ( refmultCorrUtil.isBadRun(Run) ) continue; refmultCorrUtil.initEvent(RefMult, PVtxz, ZDCcoin) ; Int_t cent9 = 1 + refmultCorrUtil.getCentralityBin9() ; Eweight = refmultCorrUtil.getWeight(); if((i+1)%1000==0) cout<<Centrality<<" "<<Eweight<<endl; Centrality = cent9; hVertexZ->Fill(PVtxz); hEventTally->Fill("Total Event",1); if(TOFMult < -100+3.0*RefMult) continue; //remove pile-up if(TOFMult > 180 +5.2*RefMult) continue; if(TMath::Abs(PVtxz) > Vz_cut) continue; //Z-vertex cut; track quality cut done in PkNtupleMaker if((PVtxz-VPDvz)>3 || (PVtxz-VPDvz)<-3) continue; Ref_Day3->Fill(Day3,RefMult); TOF_Day3->Fill(Day3,TOFMult); NPT_Day3->Fill(Day3,NPTracks); Hist_RefMult->Fill(RefMult); Hist_TOFMult->Fill(TOFMult); if(RefMult>10) { p_RefMult->Fill(RefMult,RefMult,Eweight); p_TOFMult->Fill(TOFMult,TOFMult,Eweight); } hCentrality->Fill(Centrality,Eweight); hMult_Vz->Fill(RefMult,PVtxz); hMult_Vz_new->Fill(RefMult,PVtxz,Eweight); if(cen && Centrality != cen) continue; hBBC_coin->Fill(BBCco); p_RefMult_ZDC_obs->Fill(ZDCe+ZDCw,RefMult,Eweight); p_TOFMult_ZDC_obs->Fill(ZDCe+ZDCw,TOFMult,Eweight); TLeaf* leaf_PtV0 = chain->GetLeaf("fV0s.mPtV0"); TLeaf* leaf_EtaV0 = chain->GetLeaf("fV0s.mEtaV0"); TLeaf* leaf_PhiV0 = chain->GetLeaf("fV0s.mPhiV0"); TLeaf* leaf_ChargeV0 = chain->GetLeaf("fV0s.mChargeV0"); TLeaf* leaf_DCAglobalV0 = chain->GetLeaf("fV0s.mDcaV0"); TLeaf* leaf_ndEdxV0 = chain->GetLeaf("fV0s.mndEdxV0"); TLeaf* leaf_TofFlagV0 = chain->GetLeaf("fV0s.mTofFlagV0"); TLeaf* leaf_TofYLocalV0 = chain->GetLeaf("fV0s.mTofYLocalV0"); TLeaf* leaf_TofM2V0 = chain->GetLeaf("fV0s.mTofM2V0"); TLeaf* leaf_nSigmaPV0 = chain->GetLeaf("fV0s.mnSigma_pV0"); TLeaf* leaf_nSigmaPiV0 = chain->GetLeaf("fV0s.mnSigma_piV0"); TLeaf* leaf_nSigmaKV0 = chain->GetLeaf("fV0s.mnSigma_kV0"); TLeaf* leaf_nSigmaEV0 = chain->GetLeaf("fV0s.mnSigma_eV0"); int Np = 0, Npbar = 0; int Ntof = 0; //TPC EP reconstruction TVector2 mQ, mQ1, mQ2, mQ3, mQ4; Double_t mQx=0., mQy=0., mQx1=0., mQy1=0., mQx2=0., mQy2=0., mQx3=0., mQy3=0., mQx4=0., mQy4=0.; int Fcount = 0, Ecount = 0, Wcount =0; for(int trk = 0; trk < NPTracks; trk++) { float EtaAsso = leaf_EtaV0->GetValue(trk); float PtAsso = leaf_PtV0->GetValue(trk); float PhiAsso = leaf_PhiV0->GetValue(trk); float DCAglAsso = leaf_DCAglobalV0->GetValue(trk); float ChargeAsso= leaf_ChargeV0->GetValue(trk); nSigma_p = leaf_nSigmaPV0->GetValue(trk); float nSigma_K = leaf_nSigmaKV0->GetValue(trk); float nSigma_e = leaf_nSigmaEV0->GetValue(trk); float TOFflag = leaf_TofFlagV0->GetValue(trk); if(TOFflag>0) Ntof++; // also nSigma_e>1 if(PtAsso>0.4 && PtAsso<1 && DCAglAsso<1 && EtaAsso>-1 && EtaAsso<1 && nSigma_p>-2 && nSigma_p<2 && nSigma_K>2 && nSigma_e >1 && ChargeAsso >0) Np++; if(PtAsso>0.4 && PtAsso<1 && DCAglAsso<1 && EtaAsso>-1 && EtaAsso<1 && nSigma_p>-2 && nSigma_p<2 && nSigma_K>2 && nSigma_e >1 && ChargeAsso <0) Npbar++; if(PtAsso > pt_asso_up || PtAsso < pt_asso_lo) continue; if(DCAglAsso > DcaCut) continue; if(EtaAsso>EtaCut || EtaAsso<-EtaCut) continue; if(opt_TOF ==1 && TOFflag<1) continue; Fcount++; int n = (int)((PhiAsso+PI)/2./PI*Phibin); int fl = (PVtxz > 0)? ((ChargeAsso > 0)? 1:2):((ChargeAsso > 0)? 3:4); Hist_Phi->Fill(PhiAsso,fl,PtAsso); float W_phi = (EtaAsso>0)? PhiWgtFF[n][fl-1]:PhiWgtRF[n][fl-1]; mQx += W_phi*PtAsso * cos(PhiAsso * 2.); mQy += W_phi*PtAsso * sin(PhiAsso * 2.); if(EtaAsso>0 && PVtxz>0 && ChargeAsso > 0) Hist_Phi_FF->Fill(PhiAsso,1,Eweight); if(EtaAsso>0 && PVtxz>0 && ChargeAsso < 0) Hist_Phi_FF->Fill(PhiAsso,2,Eweight); if(EtaAsso<0 && PVtxz>0 && ChargeAsso > 0) Hist_Phi_RF->Fill(PhiAsso,1,Eweight); if(EtaAsso<0 && PVtxz>0 && ChargeAsso < 0) Hist_Phi_RF->Fill(PhiAsso,2,Eweight); if(EtaAsso>0 && PVtxz<0 && ChargeAsso > 0) Hist_Phi_FF->Fill(PhiAsso,1+2,Eweight); if(EtaAsso>0 && PVtxz<0 && ChargeAsso < 0) Hist_Phi_FF->Fill(PhiAsso,2+2,Eweight); if(EtaAsso<0 && PVtxz<0 && ChargeAsso > 0) Hist_Phi_RF->Fill(PhiAsso,1+2,Eweight); if(EtaAsso<0 && PVtxz<0 && ChargeAsso < 0) Hist_Phi_RF->Fill(PhiAsso,2+2,Eweight); } if(Ntof<2) continue; int net_Np = Np - Npbar; Hist_proton->Fill(Np); Hist_pbar->Fill(Npbar); Hist_netP->Fill(net_Np); int iTrack[Fcount], Scount = Fcount/2 -1; for(int q=0; q<Fcount; q++) iTrack[q] = q; random_shuffle(iTrack,iTrack+Fcount); Fcount = 0; for(int trk = 0; trk < NPTracks; trk++) { float EtaAsso = leaf_EtaV0->GetValue(trk); float PtAsso = leaf_PtV0->GetValue(trk); float PhiAsso = leaf_PhiV0->GetValue(trk); float DCAglAsso = leaf_DCAglobalV0->GetValue(trk); float ChargeAsso= leaf_ChargeV0->GetValue(trk); float TOFflag = leaf_TofFlagV0->GetValue(trk); if(PtAsso > pt_asso_up || PtAsso < pt_asso_lo) continue; if(DCAglAsso > DcaCut) continue; if(EtaAsso>EtaCut || EtaAsso<-EtaCut) continue; if(opt_TOF ==1 && TOFflag<1) continue; int n = (int)((PhiAsso+PI)/2./PI*Phibin); int fl = (PVtxz > 0)? ((ChargeAsso > 0)? 1:2):((ChargeAsso > 0)? 3:4); float W_phi = (EtaAsso>0)? PhiWgtFF[n][fl-1]:PhiWgtRF[n][fl-1]; if(iTrack[Fcount] > Scount) { mQx1 +=W_phi*PtAsso*cos(PhiAsso*2.); mQy1 +=W_phi*PtAsso*sin(PhiAsso * 2.); Ecount++; } else { mQx2 += W_phi*PtAsso * cos(PhiAsso * 2.); mQy2 += W_phi*PtAsso * sin(PhiAsso * 2.); Wcount++; } if(EtaAsso> 0.1) { mQx3 +=W_phi*PtAsso*cos(PhiAsso*2.); mQy3 +=W_phi*PtAsso*sin(PhiAsso * 2.); } if(EtaAsso<-0.1) { mQx4 +=W_phi*PtAsso*cos(PhiAsso*2.); mQy4 +=W_phi*PtAsso*sin(PhiAsso * 2.); } Fcount++; } if(mQx1==0 || mQy1==0 || mQx2==0 || mQy2==0) continue; if(mQx3==0 || mQy3==0 || mQx4==0 || mQy4==0) continue; mQ.Set(mQx, mQy); mQ1.Set(mQx1, mQy1); mQ2.Set(mQx2, mQy2); mQ3.Set(mQx3, mQy3); mQ4.Set(mQx4, mQy4); float TPC_EP_full = 0.5*mQ.Phi(); float TPC_EP_east = 0.5*mQ1.Phi(); float TPC_EP_west = 0.5*mQ2.Phi(); float TPC_EP_for = 0.5*mQ3.Phi(); float TPC_EP_bac = 0.5*mQ4.Phi(); Hist_TPC_EP_full->Fill(TPC_EP_full,Day); Hist_TPC_EP_east->Fill(TPC_EP_east,Day); Hist_TPC_EP_west->Fill(TPC_EP_west,Day); Hist_TPC_EP_for->Fill(TPC_EP_for,Day); Hist_TPC_EP_bac->Fill(TPC_EP_bac,Day); pTPC_EP_east->Fill(1,Day,cos(2*TPC_EP_east)); pTPC_EP_east->Fill(2,Day,sin(2*TPC_EP_east)); pTPC_EP_east->Fill(3,Day,cos(4*TPC_EP_east)); pTPC_EP_east->Fill(4,Day,sin(4*TPC_EP_east)); pTPC_EP_west->Fill(1,Day,cos(2*TPC_EP_west)); pTPC_EP_west->Fill(2,Day,sin(2*TPC_EP_west)); pTPC_EP_west->Fill(3,Day,cos(4*TPC_EP_west)); pTPC_EP_west->Fill(4,Day,sin(4*TPC_EP_west)); pTPC_EP_for->Fill(1,Day,cos(2*TPC_EP_for)); pTPC_EP_for->Fill(2,Day,sin(2*TPC_EP_for)); pTPC_EP_for->Fill(3,Day,cos(4*TPC_EP_for)); pTPC_EP_for->Fill(4,Day,sin(4*TPC_EP_for)); pTPC_EP_bac->Fill(1,Day,cos(2*TPC_EP_bac)); pTPC_EP_bac->Fill(2,Day,sin(2*TPC_EP_bac)); pTPC_EP_bac->Fill(3,Day,cos(4*TPC_EP_bac)); pTPC_EP_bac->Fill(4,Day,sin(4*TPC_EP_bac)); if(fWgt->IsOpen() && Read_TPC_EP_east->GetEntries()) { PsiShiftE1 = Read_TPC_EP_east->GetBinContent(1,Day-79); PsiShiftE2 = Read_TPC_EP_east->GetBinContent(2,Day-79); PsiShiftE3 = Read_TPC_EP_east->GetBinContent(3,Day-79); PsiShiftE4 = Read_TPC_EP_east->GetBinContent(4,Day-79); } if(fWgt->IsOpen() && Read_TPC_EP_west->GetEntries()) { PsiShiftW1 = Read_TPC_EP_west->GetBinContent(1,Day-79); PsiShiftW2 = Read_TPC_EP_west->GetBinContent(2,Day-79); PsiShiftW3 = Read_TPC_EP_west->GetBinContent(3,Day-79); PsiShiftW4 = Read_TPC_EP_west->GetBinContent(4,Day-79); } if(fWgt->IsOpen() && Read_TPC_EP_for->GetEntries()) { PsiShiftf1 = Read_TPC_EP_for->GetBinContent(1,Day-79); PsiShiftf2 = Read_TPC_EP_for->GetBinContent(2,Day-79); PsiShiftf3 = Read_TPC_EP_for->GetBinContent(3,Day-79); PsiShiftf4 = Read_TPC_EP_for->GetBinContent(4,Day-79); } if(fWgt->IsOpen() && Read_TPC_EP_bac->GetEntries()) { PsiShiftb1 = Read_TPC_EP_bac->GetBinContent(1,Day-79); PsiShiftb2 = Read_TPC_EP_bac->GetBinContent(2,Day-79); PsiShiftb3 = Read_TPC_EP_bac->GetBinContent(3,Day-79); PsiShiftb4 = Read_TPC_EP_bac->GetBinContent(4,Day-79); } float TPC_EP_east_new = TPC_EP_east, TPC_EP_west_new = TPC_EP_west; float TPC_EP_for_new = TPC_EP_for, TPC_EP_bac_new = TPC_EP_bac; TPC_EP_east_new += 2*(-PsiShiftE2*cos(2*TPC_EP_east)+PsiShiftE1*sin(2*TPC_EP_east))/(float)2 + 2*(-PsiShiftE4*cos(4*TPC_EP_east)+PsiShiftE3*sin(4*TPC_EP_east))/(float)4; TPC_EP_west_new += 2*(-PsiShiftW2*cos(2*TPC_EP_west)+PsiShiftW1*sin(2*TPC_EP_west))/(float)2 + 2*(-PsiShiftW4*cos(4*TPC_EP_west)+PsiShiftW3*sin(4*TPC_EP_west))/(float)4; TPC_EP_for_new += 2*(-PsiShiftf2*cos(2*TPC_EP_for)+PsiShiftf1*sin(2*TPC_EP_for))/(float)2 + 2*(-PsiShiftf4*cos(4*TPC_EP_for)+PsiShiftf3*sin(4*TPC_EP_for))/(float)4; TPC_EP_bac_new += 2*(-PsiShiftb2*cos(2*TPC_EP_bac)+PsiShiftb1*sin(2*TPC_EP_bac))/(float)2 + 2*(-PsiShiftb4*cos(4*TPC_EP_bac)+PsiShiftb3*sin(4*TPC_EP_bac))/(float)4; if(TPC_EP_east_new>PI) TPC_EP_east_new -= PI; if(TPC_EP_east_new< 0) TPC_EP_east_new += PI; if(TPC_EP_west_new>PI) TPC_EP_west_new -= PI; if(TPC_EP_west_new< 0) TPC_EP_west_new += PI; if(TPC_EP_for_new>PI) TPC_EP_for_new -= PI; if(TPC_EP_for_new< 0) TPC_EP_for_new += PI; if(TPC_EP_bac_new>PI) TPC_EP_bac_new -= PI; if(TPC_EP_bac_new< 0) TPC_EP_bac_new += PI; Hist_TPC_EP_east_flat->Fill(TPC_EP_east_new,Day); Hist_TPC_EP_west_flat->Fill(TPC_EP_west_new,Day); Hist_TPC_EP_for_flat->Fill(TPC_EP_for_new,Day); Hist_TPC_EP_bac_flat->Fill(TPC_EP_bac_new,Day); mQx = mQ1.Mod()*cos(2*TPC_EP_east_new) + mQ2.Mod()*cos(2*TPC_EP_west_new); mQy = mQ1.Mod()*sin(2*TPC_EP_east_new) + mQ2.Mod()*sin(2*TPC_EP_west_new); if(mQx==0 || mQy==0) continue; mQ.Set(mQx, mQy); TPC_EP_full = 0.5*mQ.Phi(); pTPC_EP_full->Fill(1,Day,cos(2*TPC_EP_full)); pTPC_EP_full->Fill(2,Day,sin(2*TPC_EP_full)); pTPC_EP_full->Fill(3,Day,cos(4*TPC_EP_full)); pTPC_EP_full->Fill(4,Day,sin(4*TPC_EP_full)); if(fWgt->IsOpen() && Read_TPC_EP_full->GetEntries()) { PsiShiftF1 = Read_TPC_EP_full->GetBinContent(1,Day-79); PsiShiftF2 = Read_TPC_EP_full->GetBinContent(2,Day-79); PsiShiftF3 = Read_TPC_EP_full->GetBinContent(3,Day-79); PsiShiftF4 = Read_TPC_EP_full->GetBinContent(4,Day-79); } float TPC_EP_full_new = TPC_EP_full; TPC_EP_full_new += 2*(-PsiShiftF2*cos(2*TPC_EP_full)+PsiShiftF1*sin(2*TPC_EP_full))/(float)2 + 2*(-PsiShiftF4*cos(4*TPC_EP_full)+PsiShiftF3*sin(4*TPC_EP_full))/(float)4; if(TPC_EP_full_new>PI) TPC_EP_full_new -= PI; if(TPC_EP_full_new< 0) TPC_EP_full_new += PI; Hist_TPC_EP_full_flat->Fill(TPC_EP_full_new,Day); mQx = mQ.Mod()*cos(2*TPC_EP_full_new); mQy = mQ.Mod()*sin(2*TPC_EP_full_new); Hist_cos->Fill(1,cos(2.*TPC_EP_for_new-2.*TPC_EP_bac_new), Eweight); Hist_cos->Fill(2,cos(2.*TPC_EP_east_new-2.*TPC_EP_west_new), Eweight); Hist_cos_RefMult->Fill(1,RefMult,cos(2.*TPC_EP_for_new-2.*TPC_EP_bac_new), Eweight); Hist_cos_RefMult->Fill(2,RefMult,cos(2.*TPC_EP_east_new-2.*TPC_EP_west_new), Eweight); Hist_cos_TOFMult->Fill(1,TOFMult,cos(2.*TPC_EP_for_new-2.*TPC_EP_bac_new), Eweight); Hist_cos_TOFMult->Fill(2,TOFMult,cos(2.*TPC_EP_east_new-2.*TPC_EP_west_new), Eweight); Hist_cos_ZDC->Fill(1,ZDCe+ZDCw,cos(2.*TPC_EP_for_new-2.*TPC_EP_bac_new), Eweight); Hist_cos_ZDC->Fill(2,ZDCe+ZDCw,cos(2.*TPC_EP_east_new-2.*TPC_EP_west_new), Eweight); Hist_cos_BBC_RefMult->Fill(BBCco,RefMult,cos(2.*TPC_EP_for_new-2.*TPC_EP_bac_new), Eweight); Hist_dif_count->Fill(Ecount - Wcount); Hist_ful_count->Fill(Ecount + Wcount); TPC_Day3_cos2->Fill(Day3, cos(2*TPC_EP_full)); TPC_Day3_sin2->Fill(Day3, sin(2*TPC_EP_full)); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //loop through matched primary tracks for(int trki = 0; trki < NPTracks; trki++) { Pt = leaf_PtV0->GetValue(trki); Eta = leaf_EtaV0->GetValue(trki); Theta = 2.*atan(exp(-Eta)); Charge = leaf_ChargeV0->GetValue(trki); Phi = leaf_PhiV0->GetValue(trki); ndEdx = leaf_ndEdxV0->GetValue(trki); DCAGlobal = leaf_DCAglobalV0->GetValue(trki); nSigma_p = leaf_nSigmaPV0->GetValue(trki); nSigma_pi = leaf_nSigmaPiV0->GetValue(trki); float TOFflag = leaf_TofFlagV0->GetValue(trki); float En = sqrt(0.1396*0.1396+pow(Pt*cosh(Eta),2)); float TofYLocal = leaf_TofYLocalV0->GetValue(trki); float TofM2 = leaf_TofM2V0->GetValue(trki); if(DCAGlobal > DcaCut) continue; if(Pt < pt_trig_lo || Pt > pt_trig_up) continue; if(Eta > EtaCut || Eta < -EtaCut) continue; Hist_Pt->Fill(Pt,Eweight); if(TOFflag>0) Hist_Pt_TOF->Fill(Pt,Eweight); if(ndEdx<15||nSigma_pi<-2 || nSigma_pi>2) continue; if(TOFflag<1||TofYLocal<-1.8||TofYLocal>1.8||TofM2<-0.01 || TofM2>0.1) continue; hEtaPtDist->Fill(Eta,Pt,Eweight); //Corrections if(fWgt->IsOpen() && (TPCmean_FF->GetEntries() || TPCmean_RF->GetEntries())) { for(int k=1; k<5; k++) { for(int kk=0; kk<order; kk++) { if(Eta>0 && PVtxz>0) PhiMean[k-1+4*kk] = TPCmean_FF->GetBinContent(k+8*kk,Day2-7999); if(Eta<0 && PVtxz>0) PhiMean[k-1+4*kk] = TPCmean_RF->GetBinContent(k+8*kk,Day2-7999); if(Eta>0 && PVtxz<0) PhiMean[k-1+4*kk] = TPCmean_FF->GetBinContent(k+4+8*kk,Day2-7999); if(Eta<0 && PVtxz<0) PhiMean[k-1+4*kk] = TPCmean_RF->GetBinContent(k+4+8*kk,Day2-7999); } } } float cos1 =0, cos2=0, sin1=0, sin2=0, Phi_new = Phi; // Recentering parameters if(Eta>0 && PVtxz>0) { if(Charge > 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_FF->Fill(1+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_FF->Fill(2+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } if(Charge < 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_FF->Fill(3+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_FF->Fill(4+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } } if(Eta<0 && PVtxz>0) { if(Charge > 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_RF->Fill(1+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_RF->Fill(2+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } if(Charge < 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_RF->Fill(3+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_RF->Fill(4+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } } if(Eta>0 && PVtxz<0) { if(Charge > 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_FF->Fill(1+4+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_FF->Fill(2+4+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } if(Charge < 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_FF->Fill(3+4+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_FF->Fill(4+4+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } } if(Eta<0 && PVtxz<0) { if(Charge > 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_RF->Fill(1+4+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_RF->Fill(2+4+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } if(Charge < 0) { for(int kk=0; kk<order; kk++) { pTPCmeanPhi_RF->Fill(3+4+8*kk,Day2,cos(kk*Phi+Phi),Eweight); pTPCmeanPhi_RF->Fill(4+4+8*kk,Day2,sin(kk*Phi+Phi),Eweight); } } } } //Track } // Event rc = (TH1D*)Hist_Pt_TOF->Clone(); rc->SetName("rc"); rc->Divide(Hist_Pt); fout.Write(); char fname_new[200]; sprintf(fname_new,"cen%d.weight_pi_minbias5_new.root",cen); TFile *fWgtNew = new TFile(fname_new,"RECREATE"); pTPCmeanPhi_FF->Write(); pTPCmeanPhi_RF->Write(); Hist_Phi_FF->Write(); Hist_Phi_RF->Write(); pTPC_EP_east->Write(); pTPC_EP_west->Write(); pTPC_EP_for->Write(); pTPC_EP_bac->Write(); pTPC_EP_full->Write(); rc->Write(); fWgtNew->Close(); return; }
TH2D * JetTrackSignal(int jetindex, double leadingjetptlow , double leadingjetpthigh , double subleadingjetptlow , double subleadingjetpthigh , double ptasslow , double ptasshigh, int centmin, int centmax, float ajmin , float ajmax , int doptweight , int mccommand , double jetamin , double jetamax , double vzrange, double dijetdphicut) { if(mccommand==2) doptweight=0; TH2D::SetDefaultSumw2(true); c->LoadNoTrees(); c->hasEvtTree = true; c->hasHltTree = true; c->hasTrackTree = true; c->hasAkPu3JetTree = true; c->hasSkimTree = true; Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D * hJetTrackSignal; cout<<"before first exit"<<endl; if(jetindex==0) //leading jet { hJetTrackSignal = new TH2D(Form("signal_leadingjet%d_%d_ass%d_%d_cmin%d_cmax%d_ajmin%d_ajmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax,(int)(ajmin*100),(int)(ajmax*100)),";#Delta#eta;#Delta#phi",100*3,-5,5,75*3,-pi,2*pi); } else if(jetindex==1) //subleading jet { hJetTrackSignal = new TH2D(Form("signal_subleadingjet%d_%d_ass%d_%d_cmin%d_cmax%d_ajmin%d_ajmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax,(int)(ajmin*100),(int)(ajmax*100)),";#Delta#eta;#Delta#phi",100*3,-5,5,75*3,-pi,2*pi); } else //leading jet { cout<<"Error: only jetindex 0 and 1 currently supported (leading + subleading jet)"<<endl; exit(1); } double ntottrig = 0; int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; cout<<"before event for loop "<<n_entries_in_cent_range<<endl; // for (Long64_t jentry=0; jentry<10000;jentry++) { for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { if(jentry%1000==0) cout<<jentry-cent_index_start[centmin]<<"/"<<n_entries_in_cent_range<<endl; c->GetEntry(jentry); //! jet cuts, vz range, more than 2 jettss, dijetdphi 7/8 pi, both jet |eta| < 2, pt range cuts, aj cuts // cout<<mccommand<<endl; if(mccommand==0) { if(!c->selectEvent()) continue; if(!c->hlt->HLT_HIJet80_v1) continue; } if( fabs(c->evt->vz) > vzrange ) continue; // if( c->akPu3PF->nref < 2 ) continue; // double dijetdphi = fabs(c->akPu3PF->jtphi[0] - c->akPu3PF->jtphi[1]); // if( dijetdphi > pi ) dijetdphi = 2*pi - dijetdphi; // if( dijetdphi > dijet_dphi_CUT ) continue; int jetindex = -1; while(true) { // cout<<"here"<<endl; jetindex++; if( jetindex == c->akPu3PF->nref ) break; if( c->akPu3PF->jtpt[jetindex] > leadingjetpthigh ) continue; if( c->akPu3PF->jtpt[jetindex] < leadingjetptlow ) break; if( fabs(c->akPu3PF->jteta[jetindex]) > jetamax || fabs(c->akPu3PF->jteta[jetindex]) < jetamin ) continue; if ((c->akPu3PF->trackMax[jetindex]/c->akPu3PF->jtpt[jetindex])<0.01) continue; // if(jentry%1000==0) cout<<"here"<<endl; double jeteta = c->akPu3PF->jteta[jetindex]; double jetphi = c->akPu3PF->jtphi[jetindex]; int ntrig = 1 , nass = 0; vector<double> asstrkEta(c->track->nTrk); vector<double> asstrkPhi(c->track->nTrk); vector<double> asstrkPt(c->track->nTrk); vector<double> asstrkIndex(c->track->nTrk); if(mccommand<2) { for(int j = 0 ; j < c->track->nTrk ; ++j) { if( c->track->trkPt[j]<ptasslow || c->track->trkPt[j]>ptasshigh || fabs(c->track->trkEta[j])>maxetaass) continue; if( c->track->trkAlgo[j]<4 || c->track->highPurity[j]) { ++nass; asstrkEta.push_back(c->track->trkEta[j]); asstrkPhi.push_back(c->track->trkPhi[j]); asstrkPt.push_back(c->track->trkPt[j]); asstrkIndex.push_back(j); } } } else { for(int j = 0 ; j < c->track->nParticle ; ++j) { if( c->track->pPt[j]<ptasslow || c->track->pPt[j]>ptasshigh || fabs(c->track->pEta[j])>maxetaass) continue; ++nass; asstrkEta.push_back(c->track->pEta[j]); asstrkPhi.push_back(c->track->pPhi[j]); asstrkPt.push_back(c->track->pPt[j]); asstrkIndex.push_back(j); } } for(int i = 0 ; i < ntrig ; ++i) { ntottrig += 1; for(int j = 0 ; j < nass ; ++j) { double deta = fabs(jeteta-asstrkEta[j]); double dphi = fabs(jetphi-asstrkPhi[j]); // double ptw = asstrkPt[j]; if( dphi > pi ) dphi = 2*pi - dphi; double effweight = 1; if(doptweight!=0) effweight = c->getTrackCorrection(asstrkIndex[j]); // if(jentry%1000==0) cout<<effweight<<endl; // { hJetTrackSignal->Fill(deta,dphi,effweight); hJetTrackSignal->Fill(-deta,dphi,effweight); hJetTrackSignal->Fill(deta,-dphi,effweight); hJetTrackSignal->Fill(-deta,-dphi,effweight); hJetTrackSignal->Fill(deta,(2*pi)-dphi,effweight); hJetTrackSignal->Fill(-deta,(2*pi)-dphi,effweight); // } // else // { // hJetTrackSignal->Fill(deta,dphi,effweight); // hJetTrackSignal->Fill(-deta,dphi,effweight); // hJetTrackSignal->Fill(deta,-dphi,effweight); // hJetTrackSignal->Fill(-deta,-dphi,effweight); // hJetTrackSignal->Fill(deta,(2*pi)-dphi,effweight); // hJetTrackSignal->Fill(-deta,(2*pi)-dphi,effweight); // } } } } // if(jentry>100) break; } if( ntottrig != 0 ) hJetTrackSignal->Scale(1/ntottrig); c->ResetBooleans(); return hJetTrackSignal; }
TCanvas *plot_occupancy(Int_t adc_cut=40, Int_t adc_neighbor_cut=10000, Int_t multiplicity_cut=12, Int_t tdc_min=750, Int_t tdc_width=300){ TString cut, draw, draw1, title; title.Form("run_%d_Occupancy",run); Int_t nbin=196; Int_t min=1, max=197; Int_t nbinm=11; Int_t minm=-1, maxm=10; TH1D *hoccupancy = new TH1D("hoccupancy","hoccupancy",nbin,min,max); TH1D *hmultiplicity = new TH1D("hmultiplicity","hmultiplicity",nbinm,minm,maxm); TH2D *heatmap = new TH2D("heatmap","heatmap",nbin,min,max,nbinm,minm,maxm); TCanvas *cOCCUPANCY= new TCanvas("cOCCUPANCY",title,xcanvas,ycanvas); Int_t nentries=n_events_to_analyze; TString tmpentry; MyStyle->SetStatX(0.9); MyStyle->SetStatY(0.9); MyStyle->SetStatW(0.2); setPaddleIndices(); for (Int_t id=1;id<=nentries;id++){ T->GetEntry(id); Int_t nmultiplicity=0; Int_t good_paddle[500]; for(Int_t icount=0;icount<500;icount++){good_paddle[icount]=-1;} for(Int_t pmt=0; pmt<NUMPMT;pmt++){ Int_t ipaddle = (pmt+1)*NUMPADDLE+1; for(Int_t pixel=0; pixel<NUMPIXEL;pixel++){ Int_t index = pmt*NUMPIXEL+pixel; if (pixel!=pixel1[pmt]-1&&pixel!=pixel2[pmt]-1){ ipaddle--; if (tdcl[index]>tdc_min&&tdcl[index]<tdc_min+tdc_width){ nmultiplicity++; if (ipaddle == 1){ if (adc_c[index]>adc_cut && adc_c[paddleindex[ipaddle+1]] < adc_neighbor_cut ){ good_paddle[nmultiplicity-1]=ipaddle; } }else if (ipaddle == NUMPMT*NUMPADDLE){ if (adc_c[index]>adc_cut && adc_c[paddleindex[ipaddle-1]] < adc_neighbor_cut ){ good_paddle[nmultiplicity-1]=ipaddle; } }else{ if (adc_c[index]>adc_cut && adc_c[paddleindex[ipaddle-1]] < adc_neighbor_cut && adc_c[paddleindex[ipaddle+1]] < adc_neighbor_cut ){ good_paddle[nmultiplicity-1]=ipaddle; } } } } } } if(nmultiplicity>0&&nmultiplicity<=multiplicity_cut){ for(Int_t icount=0;icount<nmultiplicity;icount++){ hoccupancy->Fill(good_paddle[icount]); heatmap->Fill(good_paddle[icount],nmultiplicity); } } hmultiplicity->Fill(nmultiplicity); } cOCCUPANCY->Clear(); cOCCUPANCY->Divide(1,2) ; title.Form("run_%d_OCCUPANCY_tdc_min_%d_max_%d.png", run,tdc_min,tdc_min+tdc_width); cOCCUPANCY->Print(title); cOCCUPANCY->cd(1); //gPad->SetLogy(); hoccupancy->Draw(); hoccupancy->GetXaxis()->SetNdivisions(NUMPMT,NUMPMT,0,0); hoccupancy->SetLineColor(kBlue); gPad->SetGridx(); TVirtualPad *c1_1 = cOCCUPANCY->cd(2); c1_1->Divide(2,1); c1_1->cd(1); hmultiplicity->Draw(); hmultiplicity->SetLineColor(kBlue); c1_1->cd(2); heatmap->Draw("COLZ"); heatmap->GetXaxis()->SetNdivisions(NUMPMT,NUMPMT,0,0); gPad->SetGridx(); return cOCCUPANCY; }
// LOOP function // Note that looping through millions of events will take several minutes regardless of what you ask it to do with them. void Loop(){ // These booleans are used to decide whether to add an EVENT (rather than a hit) to a histogram bool left_showermax = false; bool hit_showermax = false; bool hit_lead = false; bool left_lead = false; // Here we define doubles to store data in double primary_e_1 = 0; double primary_r_1 = 0; double exit_count_showermax = 0; double exit_count_lead = 0; double incident_count = 0; double sum_showermax_energy = 0; double sum_energy_post_lead = 0; double sum_incident_energy = 0; // basic check to make sure we actually pulled in something if (fChain == 0) return; // Counter used to print progress to terminal while the function is running int events_crunched = 0; // create a stopwatch, which starts timing clock_t start_time = clock(); // This for loop iterates through all events, events can register hits but are not themselves hits for (Long64_t event = 0; event < fChain->GetEntries(); fChain->GetEntry(event++)) { // This is the timer code, which is extremely useful because it tells you relative information on how long it takes to process each event, and how changing geometry affects this. // Furthermore it prevents the terminal from freezing for an hour, and lets you know quickly if the script is actually processing or if it's hung up on something. events_crunched++; int remainder = events_crunched % 100000; if( remainder == 0){ clock_t runtime = clock(); clock_t net_time = (runtime - start_time); double real_time = ((double)net_time)/CLOCKS_PER_SEC; double avg_per_sec = events_crunched / real_time; std::cout << " " << events_crunched << " events processed at average rate of " << avg_per_sec << " events per second." << std::endl; }; // reset booleans left_showermax = false; hit_showermax = false; primary_e_1 = 0; primary_r_1 = 0; exit_count_showermax = 0; hit_lead = false; left_lead = false; incident_count = 0; sum_showermax_energy = 0; sum_energy_post_lead = 0; sum_incident_energy = 0; exit_count_lead = 0; // Use 'if' statements to select what cuts you want on events, perform any analysis // outside the loop in the function below. // // Looping should be linear time, passing through each event and hit only once. // Script runtime will increase with each comparison if( hit->size() > 0){ for (size_t i = 0; i < hit->size(); i++) { // Ideally nest as many statements as possible to // reduce absolute number of comparisons // // Note that Fill can take a second argument (or third for TH2) that is a weight. It seems like ev is defined as a remoll event in remolltypes.hh, so it's actually a struct with various attributes. // The first cut should be the particle id in this case electrons, nest all other cuts for that particle within it to save time. // // *NOTE* positrons should be included in future simulations, simply change the line below to if(hit->at(i).pid == 11 || hit->at(i).pid == -11){ // if(hit->at(i).pid == 11){ // Unless you intend to look at backsplashing particles, put a cut to only count particles moving forward in the lab frame i.e. pz > 0 // Front of showermax if(hit->at(i).det == 30 && hit->at(i).pz > 0){ h_hit_e_showermax_front->Fill(hit->at(i).p, rate); // A particle with track id 1 or 2 seems to refer to one of the moller scattered electrons, there are no particles with trid 0, 3, 4, or 5 // and trid 1 and 2 seem to correspond to mother track id 0 which means they came from the particle gun. This also places a 1 MeV minimum energy constraint if((hit->at(i).trid == 1 || hit->at(i).trid == 2) && hit->at(i).p > 1){ // The precise z coordinates were implemented due to a bug, they can probably be removed without consequence since the bug was due to a very strange batch of data // rather than anything in the actual code. if(hit->at(i).z > 29073.98 && hit->at(i).z < 29074.02){ hit_showermax = true; primary_e_1 = hit->at(i).p; primary_r_1 = hit->at(i).r; } } } // back of showermax else if(hit->at(i).det == 31 && hit->at(i).pz > 0 && hit->at(i).p > 1){ if(hit_showermax == true){ exit_count_showermax++; left_showermax = true; sum_showermax_energy += hit->at(i).p; } } // pre-lead else if(hit->at(i).det == 4050 && hit->at(i).pz > 0 && hit->at(i).p > 1){ // Since there can be multiple incident electrons per event, we can't look at them individually // as such we manually "bin" the incident and exiting electrons based on the primary that ultimately produced them // Furthermore, we only look at those primaries that had electrons leave the lead // We make an assumption that hits are stored in the tree logically, i.e. a hit after the showermax will be before a hit incident on the lead if(left_showermax == true){ hit_lead = true; incident_count++; sum_incident_energy += hit->at(i).p; } } // post-lead else if(hit->at(i).det == 4051 && hit->at(i).pz > 0 && hit->at(i).p > 1){ if(hit_lead == true){ exit_count_lead++; left_lead = true; sum_energy_post_lead += hit->at(i).p; } } }; } } // This is where the hit iteration ends and we check the booleans to decide which histograms to fill, before the next event is looped over. h_ev_showermax_exit_hits->Fill(exit_count_showermax,rate); if(hit_showermax == true){ h_ev_e_showermax_front->Fill(primary_e_1,rate); h_ev_r_showermax_front->Fill(primary_r_1,rate); if(left_showermax == true){ h_ev_e_showermax_thru->Fill(primary_e_1,rate); h_ev_r_showermax_thru->Fill(primary_r_1,rate); h_ev_showermax_exit_from_primary_hits->Fill(exit_count_showermax,rate); h_ev_e_leaving_showermax->Fill(sum_showermax_energy,rate); h_ev_e_primary_vs_number_of_hits_showermax->Fill(primary_e_1, exit_count_showermax, rate); h_ev_e_primary_vs_e_leaving_showermax->Fill(primary_e_1, sum_showermax_energy, rate); // Given that an electron has to have left the showermax for hit_lead to be true it makes sense to continue nesting if(hit_lead == true){ h_ev_e_incident_lead->Fill(sum_incident_energy, rate); if(left_lead == true){ h_ev_e_incident_vs_number_of_hits_lead->Fill(sum_incident_energy,exit_count_lead, rate); h_ev_hits_incident_vs_hits_leaving_lead->Fill(incident_count,exit_count_lead,rate); h_ev_e_leaving_lead->Fill(sum_energy_post_lead, rate); h_ev_e_incident_vs_e_leaving_lead->Fill(sum_incident_energy,sum_energy_post_lead, rate); } } } } } };
TH2D * HFTrackSignal(double pttriglow , double pttrighigh , double ptasslow , double ptasshigh, int centmin, int centmax, int nmin, int nmax, double vzrange) { Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D * hTrackTrackSignal = new TH2D(Form("signal_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",33,0,8,48,-pi,2*pi); hmult = new TH1D(Form("hmult_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";N",300,0,300); hpttrg = new TH1D(Form("hpttrg_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";p_{T}",100,0,10); hetatrg = new TH1D(Form("hetatrg_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#eta",100,-5,5); hphitrg = new TH1D(Form("hphitrg_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#phi",100,-pi,pi); hmulttrg = new TH1D(Form("hmulttrg_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#N in p_{T} range",300,0,300); hptass = new TH1D(Form("hptass_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";p_{T}",100,0,10); hetaass = new TH1D(Form("hetaass_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#eta",100,-5,5); hphiass = new TH1D(Form("hphiass_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#phi",100,-pi,pi); cout<<"nmin: "<<nmin<<" nmax: "<<nmax<<endl; hdz = new TH1D("hdz_highpurity",Form(";dz %d #leq N < %d",nmin,nmax),1000,-100,100); hdz_dzerr = new TH1D("hdz_dzerr_highpurity",Form(";dz/dzerr %d #leq N < %d",nmin,nmax),1000,-50,50); hdxy = new TH1D("hdxy_highpurity",Form(";dxy %d #leq N < %d",nmin,nmax),1000,-50,50); hdxy_dxyerr = new TH1D("hdxy_dxyerr_highpurity",Form(";dxy/dxyerr %d #leq N < %d",nmin,nmax),1000,-50,50); hpterr_pt = new TH1D("hpterr_pt_highpurity",Form(";pterror/pt %d #leq N < %d",nmin,nmax),1000,0,1); hnhits = new TH1D("hnhits_highpurity",Form(";nhits %d #leq N < %d",nmin,nmax),80,0,80); hchi2ndof = new TH1D("hchi2ndof_highpurity",Form(";chi2/ndof %d #leq N < %d",nmin,nmax),1000,0,10); hetaphi = new TH2D("hetaphi_highpurity",Form(";#eta %d #leq N < %d;#phi",nmin,nmax),50,-2.5,2.5,62,-pi,pi); int nmult = 0; int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; // for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { for (Long64_t jentry=0; jentry<nentries;jentry++) { if(jentry%1000==0) { cout<<jentry<<"/"<<nentries<<endl; } // if(jentry==9999) break; c->GetEntry(jentry); // if(c->evt.hiBin < centmin) continue; // if(c->evt.hiBin >= centmax) break; // if(!(c->skim.phfPosFilter1&&c->skim.phfNegFilter1&&c->skim.phltPixelClusterShapeFilter&&c->skim.pprimaryvertexFilter)) continue; if(skipevent(vzrange,211256)) continue; // if(c->evt.run!=202792) continue; // if(c->evt.lumi<317 || c->evt.lumi>1014) continue; int thismult = 0; for(int i = 0 ; i < c->track.nTrk ; ++i) { if(c->track.trkPt[i]>0.4&&fabs(c->track.trkEta[i])<2.4&&c->track.highPurity[i]&&fabs(c->track.trkDz1[i]/c->track.trkDzError1[i])<3&&fabs(c->track.trkDxy1[i]/c->track.trkDxyError1[i])<3&&c->track.trkPtError[i]/c->track.trkPt[i]<0.1) thismult++; } hmult->Fill(thismult); // cout<<thismult<<endl; if(thismult<nmin || thismult>=nmax) { cout<<"WARNING: different mult in input file. nmin "<<nmin<<", nmax "<<nmax<<", thismult "<<thismult<<", nTrk "<<c->track.nTrk<<endl; continue; } nmult++; int ntrig = 0 , nass = 0; vector<double> trigtrkEta; vector<double> trigtrkPhi; vector<double> trigtrkIndex; vector<double> asstrkEta; vector<double> asstrkPhi; vector<double> asstrkIndex; for(int i = 0 ; i < c->track.nTrk ; ++i) { hetaphi->Fill(c->track.trkEta[i],c->track.trkPhi[i]); hdz->Fill(c->track.trkDz1[i]); hdxy->Fill(c->track.trkDxy1[i]); hdz_dzerr->Fill(c->track.trkDz1[i]/c->track.trkDzError1[i]); hdxy_dxyerr->Fill(c->track.trkDxy1[i]/c->track.trkDxyError1[i]); hpterr_pt->Fill(c->track.trkPtError[i]/c->track.trkPt[i]); hnhits->Fill(c->track.trkNHit[i]); hchi2ndof->Fill(c->track.trkChi2[i]/c->track.trkNdof[i]); if( c->track.trkPt[i]<pttriglow || c->track.trkPt[i]>pttrighigh || fabs(c->track.trkEta[i])>maxetatrg ) continue; bool considertrack = false; if(mytrackquality==0&&fabs(c->track.trkEta[i])<2.4&&c->track.highPurity[i]&&fabs(c->track.trkDz1[i]/c->track.trkDzError1[i])<3&&fabs(c->track.trkDxy1[i]/c->track.trkDxyError1[i])<3&&c->track.trkPtError[i]/c->track.trkPt[i]<0.1) { considertrack=true; } else if(mytrackquality==1) { considertrack=true; } else if(mytrackquality==2&&!(fabs(c->track.trkEta[i])<2.4&&c->track.highPurity[i]&&fabs(c->track.trkDz1[i]/c->track.trkDzError1[i])<3&&fabs(c->track.trkDxy1[i]/c->track.trkDxyError1[i])<3&&c->track.trkPtError[i]/c->track.trkPt[i]<0.1)) { considertrack=true; } if(considertrack) { ++ntrig; trigtrkEta.push_back(c->track.trkEta[i]); trigtrkPhi.push_back(c->track.trkPhi[i]); trigtrkIndex.push_back(i); hpttrg->Fill(c->track.trkPt[i]); hetatrg->Fill(c->track.trkEta[i]); hphitrg->Fill(c->track.trkPhi[i]); } } if(ntrig<2) continue; for(int j = 0 ; j < c->tower.n ; ++j) { if( c->tower.et[j]<ptasslow || c->tower.et[j]>ptasshigh ) continue; // bool considertrack = false; // if(mytrackquality==0&&fabs(c->track.trkEta[j])<2.4&&c->track.highPurity[j]&&fabs(c->track.trkDz1[j]/c->track.trkDzError1[j])<3&&fabs(c->track.trkDxy1[j]/c->track.trkDxyError1[j])<3&&c->track.trkPtError[j]/c->track.trkPt[j]<0.1) // { // considertrack=true; // } // else if(mytrackquality==1) // { // considertrack=true; // } // else if(mytrackquality==2&&!(fabs(c->track.trkEta[j])<2.4&&c->track.highPurity[j]&&fabs(c->track.trkDz1[j]/c->track.trkDzError1[j])<3&&fabs(c->track.trkDxy1[j]/c->track.trkDxyError1[j])<3&&c->track.trkPtError[j]/c->track.trkPt[j]<0.1)) // { // considertrack=true; // } // if(considertrack) // { ++nass; asstrkEta.push_back(c->tower.eta[j]); asstrkPhi.push_back(c->tower.phi[j]); asstrkIndex.push_back(j); hptass->Fill(c->tower.et[j]); hetaass->Fill(c->tower.eta[j]); hphiass->Fill(c->tower.phi[j]); // } } hmulttrg->Fill(ntrig); for(int i = 0 ; i < ntrig ; ++i) { if(ntrig>1) ntottrig += 1; double double_ntrig = ntrig; for(int j = 0 ; j < nass ; ++j) { if(trigtrkIndex[i]==asstrkIndex[j]) continue; // double deta = fabs(trigtrkEta[i]-asstrkEta[j]); double dphi = fabs(trigtrkPhi[i]-asstrkPhi[j]); double deta = trigtrkEta[i]-asstrkEta[j]; if(deta<=0) { deta *= -1.0; if( dphi > pi ) dphi = 2*pi - dphi; hTrackTrackSignal->Fill(deta,dphi,1./double_ntrig); hTrackTrackSignal->Fill(-deta,dphi,1./double_ntrig); hTrackTrackSignal->Fill(deta,-dphi,1./double_ntrig); hTrackTrackSignal->Fill(-deta,-dphi,1./double_ntrig); hTrackTrackSignal->Fill(deta,(2*pi)-dphi,1./double_ntrig); hTrackTrackSignal->Fill(-deta,(2*pi)-dphi,1./double_ntrig); } } } // if(jentry>100) break; } // if(ntottrig!=0) hTrackTrackSignal->Scale(1/ntottrig); hTrackTrackSignal->Scale(1/4.0); //! since we only fill one quadrant cout<<"nmult "<<nmult<<endl; return hTrackTrackSignal; }
void draw5(){ gStyle->SetOptStat("mre"); // TFile* f = TFile::Open("testing/corInterp/latestNums/generateAngularResolutionTreePlots_352_2016-02-21_15-38-05.root"); //generateAngularResolutionTreePlots_352_2016-02-19_18-01-52.root"); TChain* c = new TChain("angResTree"); UInt_t l3TrigPatternH; c->SetBranchAddress("l3TrigPatternH", &l3TrigPatternH); Double_t phiExpected; c->SetBranchAddress("phiExpected", &phiExpected); // c->Add("newLindaNumbers_4steps_WAISHPOL_NEW11_cosminV3_nfixedBug_2016_02_05_time_15_42_15/*.root"); c->Add("newLindaNumbers_4steps_WAISHPOL_NEW11_cosminV3_nfixedBug_2016_02_05_time_15_42_15/generateAngularResolutionTreePlots_352*.root"); const Long64_t numEntries = c->GetEntries(); ProgressBar p(numEntries); TH2D* h = new TH2D("h", "#phi_{expected} vs. L3 triggered #phi-sectors; #phi_{expected} (Degrees); #phi-sector", 360, 0, 360, NUM_PHI, 0, NUM_PHI); TH1D* h2 = new TH1D("h2", "Angle between triggered #phi-sector center and #phi_{expected}; #delta#phi (Degrees); Events / bin", 360, -180, 180); TH1D* h3 = new TH1D("h3", "#phi-sectors triggered; #phi-sector; Number of triggers", NUM_PHI, 0, NUM_PHI); TH1D* h4 = new TH1D("h4", "#delta#phi-sectors; #phi-sector; Number of triggers", 5, -2, 3); for(Long64_t entry=0; entry < numEntries; entry++){ c->GetEntry(entry); for(int phi=0; phi<NUM_PHI; phi++){ Int_t l3 = RootTools::getBit(phi, l3TrigPatternH); if(l3){ h->Fill(phiExpected, phi); Double_t deltaPhiThingy = RootTools::getDeltaAngleDeg(phiExpected + 45, 22.5*phi); h2->Fill(deltaPhiThingy); h3->Fill(phi); if(deltaPhiThingy <= -11.25){ h4->Fill(-1); } else if(deltaPhiThingy > 11.25){ h4->Fill(1); } else{ h4->Fill(0); } } } p++; } new TCanvas(); h->Draw("colz"); new TCanvas(); h2->Draw(); new TCanvas(); h4->Draw(); for(int binx=1; binx<=h4->GetNbinsX(); binx++){ h4->GetXaxis()->SetBinLabel(binx, TString::Format("%d", -3 + binx)); } h4->GetXaxis()->SetLabelOffset(.01); }
void GradeCorrelation(double prob = 0.10, int nCut = 50) { std::cout << "Starting Grade Correlation..." << std::endl; TBenchmark* myBenchmark = new TBenchmark(); myBenchmark->Start("NormMap"); // Get the student TTree prepared in another macro. if (MyFunctions::gradeNormMap.size() == 0) MyFunctions::BuildGradeNormMap(); myBenchmark->Stop("NormMap"); std::cout << "Made GradeNormMap..." << std::endl; // Just a quick look at the data in the Students TTree TFile* f = new TFile("Students.root"); TTree* studentTree = (TTree*)f->Get("Students"); Student* student = 0; studentTree->SetBranchAddress("student", &student); Long64_t nentries = studentTree->GetEntriesFast(); std::cout << "Entries in Students TTree = " << nentries << std::endl; // We want to loop over students and look at pairs of courses taken in different semesters to see if there is // any correlation between graede performance. std::map<std::pair<TString, TString>, CorrelationCalculator> corrMap; // nentries = 1000; myBenchmark->Start("Main Loop"); int nPairAll = 0; for (Long64_t jentry = 0; jentry < nentries; ++jentry) { studentTree->GetEntry(jentry); if (jentry % 1000 == 0) std::cout << "At student " << jentry << std::endl; // std::cout << "Looking at student " << student->Id() << std::endl; student->Finalize(); // Regenerates non-persisted references int nTerms = student->Enrollments().size(); // std::cout << "nTerms = " << nTerms << std::endl; for (int iTerm = 0; iTerm < nTerms - 1; ++iTerm) { const Student::Enrollment iEnrollment = student->Enrollments()[iTerm]; if (!MyFunctions::regularSemester(iEnrollment.term)) continue; for (Student::Grade iGrade : iEnrollment.grades) { if (!MyFunctions::ValidGrade(iGrade.grade)) continue; // Get a prediction for this grade using norm-corrected grades // std::cout << "1" << std::endl; double prediction_i = student->CourseGradePrediction(iGrade, Student::DISTRIBUTION); // std::cout << "2" << std::endl; double delta_i = iGrade.quality - prediction_i; // Find next regular term only bool foundRegTerm = false; for (int jTerm = iTerm + 1; jTerm < nTerms && !foundRegTerm; ++jTerm) { const Student::Enrollment jEnrollment = student->Enrollments()[jTerm]; if (!MyFunctions::regularSemester(jEnrollment.term)) continue; foundRegTerm = true; for (Student::Grade jGrade : jEnrollment.grades) { if (jGrade.course == iGrade.course) continue; if (!MyFunctions::ValidGrade(jGrade.grade)) continue; double prediction_j = student->CourseGradePrediction(jGrade, Student::DISTRIBUTION); double delta_j = jGrade.quality - prediction_j; corrMap[std::make_pair(iGrade.course, jGrade.course)].Add(delta_i, delta_j); ++nPairAll; } } } } } myBenchmark->Stop("Main Loop"); std::cout << "nPairAll = " << nPairAll << std::endl; std::cout << "Unique Pairs = " << corrMap.size() << std::endl; TH1D* rHist = new TH1D("rHist", "Correlation Coefficient, #rho", 120, -1.2, 1.2); TH1D* pHist = new TH1D("pHist", "Probablity Distribution", 100, 0., 1.); TH1D* nHist = new TH1D("nHist", "Number of entries", 100, 0., 2000.); TH2D* pVrHist = new TH2D("pVrHist", "Prob vs. #rho", 100, -1., 1., 100, 0., 1.); myBenchmark->Start("Prune"); for (auto iter = corrMap.begin(); iter != corrMap.end();) { if (iter->second.n() < nCut) { corrMap.erase(iter++); continue; } double p = iter->second.p(); double r = iter->second.r(); // Test for nan? if (p != p) { std::cout << "Found p = nan: n = " << iter->second.n() << std::endl; corrMap.erase(iter++); continue; } if (p < 0.) { corrMap.erase(iter++); continue; } rHist->Fill(r); pHist->Fill(p); nHist->Fill(iter->second.n()); pVrHist->Fill(r, p); if (p < 1. - prob && p > prob) { corrMap.erase(iter++); } else { std::cout << "r = " << iter->second.r() << ", p = " << p << std::endl; ++iter; } } myBenchmark->Stop("Prune"); std::cout << "Post Cut = " << corrMap.size() << std::endl; myBenchmark->Start("Sort"); std::vector<std::pair<std::pair<TString, TString>, CorrelationCalculator>> corrVec(corrMap.begin(), corrMap.end()); std::sort(corrVec.begin(), corrVec.end(), &sortFunc); myBenchmark->Stop("Sort"); int printTop = 50; int printed = 0; for (auto const& entry : corrVec) { std::cout << entry.first.first << " : " << entry.first.second << "\t, n = " << entry.second.n() << "\t, r = " << entry.second.r() << "\t, p = " << entry.second.p() << std::endl; ++printed; if (printed >= printTop) break; } TCanvas* c1 = new TCanvas("c1", "Grade Correlation", 1600, 1200); c1->Divide(2,2); c1->cd(1); TF1* myGaus = new TF1("myGaus", "gaus", -1., 1.); myGaus->SetParameters(600., 0., 0.2); myGaus->FixParameter(1, 0.); rHist->Fit(myGaus, "0B", "", -1., 0.); rHist->DrawCopy(); myGaus->DrawCopy("SAME"); c1->cd(2); pHist->DrawCopy(); c1->cd(3); nHist->DrawCopy(); c1->cd(4); pVrHist->DrawCopy(); float rt, cp; myBenchmark->Summary(rt, cp); }
TH2D * HFTrackBackground(double pttriglow , double pttrighigh , double ptasslow , double ptasshigh, int centmin, int centmax, int nmin, int nmax, double vzrange) { Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D * hTrackTrackBackground = new TH2D(Form("background_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",33,0,8,48,-pi,2*pi); int nmult = 0; int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; // for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { for (Long64_t jentry=0; jentry<nentries;jentry++) { if(jentry%1000==0) { cout<<jentry<<"/"<<nentries<<endl; } // if(jentry==9999) break; c->GetEntry(jentry); // if(c->evt.hiBin < centmin) continue; // if(c->evt.hiBin >= centmax) break; // if(!(c->skim.phfPosFilter1&&c->skim.phfNegFilter1&&c->skim.phltPixelClusterShapeFilter&&c->skim.pprimaryvertexFilter)) continue; // if(fabs(c->evt.vz)>vzrange) continue; if(skipevent(vzrange,211256)) continue; // if(c->evt.run!=202792) continue; // if(c->evt.lumi<317 || c->evt.lumi>1014) continue; int thismult = 0; for(int i = 0 ; i < c->track.nTrk ; ++i) { if(c->track.trkPt[i]>0.4&&fabs(c->track.trkEta[i])<2.4&&c->track.highPurity[i]&&fabs(c->track.trkDz1[i]/c->track.trkDzError1[i])<3&&fabs(c->track.trkDxy1[i]/c->track.trkDxyError1[i])<3&&c->track.trkPtError[i]/c->track.trkPt[i]<0.1) thismult++; } // cout<<thismult<<endl; if(thismult<nmin || thismult>=nmax) { cout<<"WARNING: different mult in input file. nmin "<<nmin<<", nmax "<<nmax<<", thismult "<<thismult<<", nTrk "<<c->track.nTrk<<endl; continue; } nmult++; int ntrig = 0 , nass = 0; vector<double> trigtrkEta; vector<double> trigtrkPhi; vector<double> trigtrkIndex; vector<double> asstrkEta; vector<double> asstrkPhi; vector<double> asstrkIndex; for(int i = 0 ; i < c->track.nTrk ; ++i) { if( c->track.trkPt[i]<pttriglow || c->track.trkPt[i]>pttrighigh || fabs(c->track.trkEta[i])>maxetatrg ) continue; bool considertrack = false; if(mytrackquality==0&&fabs(c->track.trkEta[i])<2.4&&c->track.highPurity[i]&&fabs(c->track.trkDz1[i]/c->track.trkDzError1[i])<3&&fabs(c->track.trkDxy1[i]/c->track.trkDxyError1[i])<3&&c->track.trkPtError[i]/c->track.trkPt[i]<0.1) { considertrack=true; } else if(mytrackquality==1) { considertrack=true; } else if(mytrackquality==2&&!(fabs(c->track.trkEta[i])<2.4&&c->track.highPurity[i]&&fabs(c->track.trkDz1[i]/c->track.trkDzError1[i])<3&&fabs(c->track.trkDxy1[i]/c->track.trkDxyError1[i])<3&&c->track.trkPtError[i]/c->track.trkPt[i]<0.1)) { considertrack=true; } if(considertrack) { ++ntrig; trigtrkEta.push_back(c->track.trkEta[i]); trigtrkPhi.push_back(c->track.trkPhi[i]); trigtrkIndex.push_back(i); } } if(ntrig<2) continue; for(int imix = 1 ; imix < 11 ; ++imix) { if(jentry+10 > nentries) break; c->GetEntry(jentry+imix); for(int j = 0 ; j < c->tower.n ; ++j) { if( c->tower.et[j]<ptasslow || c->tower.et[j]>ptasshigh ) continue; // bool considertrack = false; // if(mytrackquality==0&&fabs(c->track.trkEta[j])<2.4&&c->track.highPurity[j]&&fabs(c->track.trkDz1[j]/c->track.trkDzError1[j])<3&&fabs(c->track.trkDxy1[j]/c->track.trkDxyError1[j])<3&&c->track.trkPtError[j]/c->track.trkPt[j]<0.1) // { // considertrack=true; // } // else if(mytrackquality==1) // { // considertrack=true; // } // else if(mytrackquality==2&&!(fabs(c->track.trkEta[j])<2.4&&c->track.highPurity[j]&&fabs(c->track.trkDz1[j]/c->track.trkDzError1[j])<3&&fabs(c->track.trkDxy1[j]/c->track.trkDxyError1[j])<3&&c->track.trkPtError[j]/c->track.trkPt[j]<0.1)) // { // considertrack=true; // } // if(considertrack) // { ++nass; asstrkEta.push_back(c->tower.eta[j]); asstrkPhi.push_back(c->tower.phi[j]); asstrkIndex.push_back(j); // } } for(int i = 0 ; i < ntrig ; ++i) { if(ntrig>1) ntottrig += 1; double double_ntrig = ntrig; for(int j = 0 ; j < nass ; ++j) { if(trigtrkIndex[i]==asstrkIndex[j]) continue; // double deta = fabs(trigtrkEta[i]-asstrkEta[j]); double dphi = fabs(trigtrkPhi[i]-asstrkPhi[j]); double deta = trigtrkEta[i]-asstrkEta[j]; if(deta<=0) { deta *= -1.0; if( dphi > pi ) dphi = 2*pi - dphi; hTrackTrackBackground->Fill(deta,dphi,1./double_ntrig); hTrackTrackBackground->Fill(-deta,dphi,1./double_ntrig); hTrackTrackBackground->Fill(deta,-dphi,1./double_ntrig); hTrackTrackBackground->Fill(-deta,-dphi,1./double_ntrig); hTrackTrackBackground->Fill(deta,(2*pi)-dphi,1./double_ntrig); hTrackTrackBackground->Fill(-deta,(2*pi)-dphi,1./double_ntrig); } } } } // if(jentry>100) break; } // if(ntottrig!=0) hTrackTrackBackground->Scale(1/ntottrig); // hTrackTrackBackground->Scale(1/4.0); //! since we only fill one quadrant cout<<"nmult "<<nmult<<endl; return hTrackTrackBackground; }
void L1q1trigger(){ const TString l1_input = "~/scratch1/DiHadronCorrelations/L1UpgradeAnalyzer.root"; TFile *lFile = TFile::Open(l1_input); Int_t l1Up_evt, l1Up_run, l1Up_et, l1Up_q2; TTree *l1UpTree = (TTree*)lFile->Get("L1UpgradeAnalyzer/L1UpgradeTree"); l1UpTree->SetBranchStatus("*",0); l1UpTree->SetBranchStatus("event",1); l1UpTree->SetBranchStatus("run",1); l1UpTree->SetBranchStatus("centrality_hwPt",1); l1UpTree->SetBranchStatus("v2_hwPt",1); l1UpTree->SetBranchAddress("event",&l1Up_evt); l1UpTree->SetBranchAddress("run",&l1Up_run); l1UpTree->SetBranchAddress("centrality_hwPt",&l1Up_et); l1UpTree->SetBranchAddress("v2_hwPt",&l1Up_q2); const TString forest_input = "~/scratch1/DiHadronCorrelations/outputs_312/HIData_Minbias_2760GeV/ebyeflow_promptreco_pt009.root"; TFile *fFile = TFile::Open(forest_input); TTree *fTree = (TTree*)fFile->Get("ebyeflow_ana_HI/q2ntuple"); Float_t f_evt, f_run, f_lumi, hiBin; float hiHF,q2hf; fTree->SetBranchStatus("*",0); fTree->SetBranchStatus("evtnum",1); fTree->SetBranchStatus("run",1); fTree->SetBranchStatus("lumi",1); fTree->SetBranchStatus("cent",1); fTree->SetBranchStatus("q2hf",1); fTree->SetBranchStatus("hf",1); fTree->SetBranchAddress("evtnum",&f_evt); fTree->SetBranchAddress("run",&f_run); fTree->SetBranchAddress("lumi",&f_lumi); fTree->SetBranchAddress("cent",&hiBin); fTree->SetBranchAddress("hf",&hiHF); fTree->SetBranchAddress("q2hf",&q2hf); map<long, int> kmap; map<long, int> kmapcal; cout << "Filling the map..." << endl; int l1up_entries = l1UpTree->GetEntries(); //int l_entries = lEvtTree->GetEntries(); for(long j = 0; j < l1up_entries; ++j){ if(j % 10000 == 0) printf("%ld / %d\n",j,l1up_entries); l1UpTree->GetEntry(j); long key = makeKey(l1Up_run, l1Up_evt); pair<long,int> p(key,j); kmap.insert(p); kmapcal.insert(p); } cout << "map filled!!!" << endl; //q2 histos TH2D* q2CorrHist = new TH2D("q2CorrHist",";offline q_{2};online q_{2}",1000,0.,1.0,1000,0.0,1.0); TH2D* HFCorrHist = new TH2D("HFCorrHist",";offline HF E_{T} sum (GeV); online HF E_{T} sum (GeV)",100,0.,8000.0,100,0.0,8000.0); TH2D* q2HFCorrHist = new TH2D("q2HFCorrHist",";online HF*q^{2}_{2} (GeV); online HF E_{T} sum (GeV)",300,0.,30000.0,100,0.0,8000.0); Float_t q2On = 0.0; int entries = fTree->GetEntries(); for(long int j = 1; j < entries; ++j){ if(j % 10000 == 0) printf("%ld / %d \n",j,entries); fTree->GetEntry(j); long keycal = makeKey(f_run, f_evt); map<long,int>::const_iterator gotcal = kmapcal.find(keycal); if(gotcal == kmapcal.end()){ continue; } else { l1UpTree->GetEntry(gotcal->second); kmapcal.erase(keycal); if(l1Up_et == 0) continue; //q2 part q2On = sqrt(l1Up_q2)/l1Up_et; // if(l1Up_run<182060 && l1Up_run>182050 & l1Up_et<2839 && l1Up_et>1198) // if(l1Up_et<2839 && l1Up_et>1198) { q2CorrHist->Fill(q2hf,q2On); HFCorrHist->Fill(hiHF,l1Up_et); q2HFCorrHist->Fill(l1Up_q2,l1Up_et); } q2On = 0.0; } } TCanvas* c = new TCanvas("c","c",800,400); c->Divide(2,1); c->cd(1); c->GetPad(1)->SetLogz(); q2CorrHist->Rebin2D(2,2); q2CorrHist->Draw("colz"); TProfile* hprof = q2CorrHist->ProfileX("prof",-1,-1,"e"); hprof->Draw("PEsame"); c->cd(2); c->GetPad(2)->SetLogz(); HFCorrHist->Draw("colz"); TCanvas* c1 = new TCanvas("c1","c1",500,500); q2HFCorrHist->Draw("colz"); }
// LOOP function // Note that looping through millions of events will take several minutes regardless of what you ask it to do with them. void Loop(){ double primary_e_1 = 0; double primary_r_1 = 0; double exit_count_showermax = 0; double exit_count_lead = 0; double incident_count = 0; double sum_showermax_energy = 0; double sum_energy_post_lead = 0; double sum_incident_energy = 0; if (fChain == 0) return; // Counter used to print progress to terminal while the function is running int events_crunched = 0; // create a stopwatch, which starts timing clock_t start_time = clock(); // This for loop iterates through all events, events can register hits but are not themselves hits for (Long64_t event = 0; event < fChain->GetEntries(); fChain->GetEntry(event++)) { events_crunched++; int remainder = events_crunched % 100000; if( remainder == 0){ clock_t runtime = clock(); clock_t net_time = (runtime - start_time); double real_time = ((double)net_time)/CLOCKS_PER_SEC; double avg_per_sec = events_crunched / real_time; std::cout << " " << events_crunched << " events processed at average rate of " << avg_per_sec << " events per second." << std::endl; }; // reset doubles primary_e_1 = 0; primary_r_1 = 0; exit_count_showermax = 0; incident_count = 0; sum_showermax_energy = 0; sum_energy_post_lead = 0; sum_incident_energy = 0; exit_count_lead = 0; // Use 'if' statements to select what cuts you want on events, perform any analysis // outside the loop in the function below. // // Looping should be linear time, passing through each event and hit only once. // Script runtime will increase with each comparison if( hit->size() > 0){ for (size_t i = 0; i < hit->size(); i++) { // Ideally nest as many statements as possible to // reduce absolute number of comparisons // // Note that Fill can take a second argument (or third for TH2) that is a weight. It seems like ev is defined as a remoll event in remolltypes.hh, so it's actually a struct with various attributes. // // Could include pi+'s however it's probably not even worth the extra check every loop. if(hit->at(i).pid == -211){ // Main Detector if(hit->at(i).det == 28){ if(hit->at(i).pz > 0 && hit->at(i).r > 600){ h_hit_r_moller_det->Fill(hit->at(i).r, rate); }; } // Front of showermax else if(hit->at(i).det == 30 && hit->at(i).pz > 0){ h_hit_e_showermax_front->Fill(hit->at(i).p, rate); // A particle with track id 1 or 2 seems to refer to one of the moller scattered electrons, there are no particles with trid 0, 3, 4, or 5 // and trid 1 and 2 seem to correspond to mother track id 0 which means they came from the particle gun. This also places a 1 MeV minimum energy constraint if((hit->at(i).trid == 1 || hit->at(i).trid == 2) && hit->at(i).p > 1){ if(hit->at(i).z > 29073.98 && hit->at(i).z < 29074.02){ primary_e_1 = hit->at(i).p; primary_r_1 = hit->at(i).r; // Note that an x-y plot was added in this script h_x_y_showermax_incident->Fill(hit->at(i).x,hit->at(i).y,rate); } } } // Back of showermax else if(hit->at(i).det == 31 && hit->at(i).pz > 0 && hit->at(i).p > 1){ // because the booleans have been removed we need to fill the plots at their respective detectors, this would be the typical method for an analysis script exit_count_showermax++; sum_showermax_energy += hit->at(i).p; h_ev_e_showermax_front->Fill(primary_e_1,rate); h_ev_r_showermax_front->Fill(primary_r_1,rate); } // pre-lead else if(hit->at(i).det == 4050 && hit->at(i).pz > 0 && hit->at(i).p > 1){ // Again, booleans have been removed so plots are filled as they come up incident_count++ sum_incident_energy += hit->at(i).p; h_x_y_lead_incident->Fill(hit->at(i).x,hit->at(i).y,rate); h_ev_e_showermax_thru->Fill(primary_e_1,rate); h_ev_r_showermax_thru->Fill(primary_r_1,rate); h_ev_showermax_exit_from_primary_hits->Fill(exit_count_showermax,rate); h_ev_e_leaving_showermax->Fill(sum_showermax_energy,rate); h_ev_e_primary_vs_number_of_hits_showermax->Fill(primary_e_1, exit_count_showermax, rate); h_ev_e_primary_vs_e_leaving_showermax->Fill(primary_e_1, sum_showermax_energy, rate); } // post-lead else if(hit->at(i).det == 4051 && hit->at(i).pz > 0 && hit->at(i).p > 1){ exit_count_lead++; sum_energy_post_lead += hit->at(i).p; h_x_y_lead_exiting->Fill(hit->at(i).x,hit->at(i).y,rate); h_ev_e_incident_lead->Fill(sum_incident_energy, rate); h_ev_e_incident_vs_number_of_hits_lead->Fill(sum_incident_energy,exit_count_lead, rate); h_ev_hits_incident_vs_hits_leaving_lead->Fill(incident_count,exit_count_lead,rate); h_ev_e_leaving_lead->Fill(sum_energy_post_lead, rate); h_ev_e_incident_vs_e_leaving_lead->Fill(sum_incident_energy,sum_energy_post_lead, rate); } }; } } // The only plot that is filled outside the loop is the number of exit hits, there is no particular reason for it to be here other than that I didn't move it. h_ev_showermax_exit_hits->Fill(exit_count_showermax,rate); } };
void plot_xtalE(){ gStyle->SetOptStat(0); gStyle->SetOptFit(0); gStyle->SetTitleSize(0.08,"t"); // a list of runs corresponding to xtal0 to xtal53 int runlist[54] = {3295,3296,3297,3369,3300,3301,3302,3303,3368, 3244,3245,3246,3247,3248,3249,3250,3251,3252, 3240,3239,3238,3237,3236,3235,3232,3234,3233, 3267,3266,3265,3263,3258,3257,3256,3254,3253, 3268,3272,3274,3275,3276,3277,3278,3281,3283, 3294,3293,3292,3289,3288,3287,3286,3285,3284}; // for(int i=0;i<54;i++){ // runlist[i] = 3305; // } ofstream outfile("energycalibration.fcl"); TCanvas *c1 = new TCanvas("c1","c1",1800,1200); TH2D *xtalEnergy = new TH2D("xtalEnergy","xtalEnergy",9,0,9,6,0,6); outfile << "// constants from runs" <<endl;; for(int i=0;i<54;i++){ outfile << runlist[i] << " "; if(i%9==8 && i!=53) { outfile << endl; outfile << "// ";} } outfile << "\nBEGIN_PROLOG" << endl; outfile << "xtal_energy_response: {" << endl; double mean[54]; double rms[54]; double norm[54]; double index[54]; c1->Divide(9,6); for(int i=0;i<54;i++){ index[i]=i; c1->cd(54-i); c1->cd(54-i)->SetLogz(); //if(i==3 || i==8 || i==9) continue; // these are runs where the beams are at the wrong place TFile *file = new TFile(Form("run%d.root",runlist[i])); TH2D *beamEnergy2D = (TH2D*)file->Get("beamEnergy2D"); beamEnergy2D->Draw("colz text"); beamEnergy2D->SetMarkerSize(1); beamEnergy2D->SetMaximum(3000); beamEnergy2D->SetMinimum(1); beamEnergy2D->SetTitle(Form("Run %d",runlist[i])); double maxE = beamEnergy2D->GetMaximum(); int maxBin = beamEnergy2D->GetMaximumBin(); int x,y,z; beamEnergy2D->GetBinXYZ(maxBin,x,y,z); cout<<x<<" "<<y<<" "<<z<<" "<<(y-1)*9+9-x<<endl; int xtalNum = (y-1)*9+9-x; TH1D *beamEnergy = (TH1D*)file->Get(Form("beamEnergy%02d",xtalNum)); TH1D *beamTime = (TH1D*)file->Get(Form("beamTime%02d",xtalNum)); TH1D *beamTimeEnergy = (TH1D*)file->Get(Form("beamTimeEnergy%02d",xtalNum)); TH1D *syncEnergy = (TH1D*)file->Get(Form("syncEnergy%02d",xtalNum)); beamEnergy->Draw(); TF1 *fit = new TF1("fit","gaus(0)",1500,2800); fit->SetParLimits(1,1700,2500); fit->SetParLimits(2,50,150); fit->SetParameters(100,2100,100); beamEnergy->Fit("fit","REM"); norm[i]=fit->GetParameter(0); mean[i]=fit->GetParameter(1); rms[i]=fit->GetParameter(2); TF1 *refit = new TF1("refit","gaus(0)",mean[i]-2*rms[i], mean[i]+2*rms[i]); refit->SetParameters(norm[i],mean[i],rms[i]); beamEnergy->Fit("refit","REM"); norm[i]=refit->GetParameter(0); mean[i]=refit->GetParameter(1); rms[i]=refit->GetParameter(2); outfile << Form("xtal%d : %f",i,mean[i]) << endl; xtalEnergy->Fill(8-i%9,i/9,mean[i]); TText *text = new TText(0.15,0.75,Form("E%d=%.1f",xtalNum,mean[i])); text->SetTextSize(0.09); text->SetTextColor(2); text->SetNDC(); beamEnergy->GetListOfFunctions()->Add(text); } outfile << "}" << endl; outfile << "END_PROLOG" << endl; TCanvas *c2 = new TCanvas("c2","c2",900,600); xtalEnergy->Draw("colz text"); xtalEnergy->SetMarkerSize(1.5); xtalEnergy->SetMaximum(2500); xtalEnergy->SetMinimum(1700); TCanvas *c3 = new TCanvas("c3","c3",900,600); TGraph *g1 = new TGraph(54,index,mean); g1->SetMarkerStyle(20); g1->Draw("AP"); double avg=0; for(int i=0;i<54;i++){ if(mean[i]>0){ avg += mean[i]/54.; } } cout<<avg<<endl; TLine *linem5 = new TLine(0,0.95*avg,54,0.95*avg); TLine *linep5 = new TLine(0,1.05*avg,54,1.05*avg); linem5->SetLineWidth(2); linem5->SetLineStyle(7); linem5->SetLineColor(2); linep5->SetLineWidth(2); linep5->SetLineColor(2); linep5->SetLineStyle(7); linem5->Draw("same"); linep5->Draw("same"); TLine *line1 = new TLine(0,0.9*avg,54,0.9*avg); line1->SetLineWidth(2); line1->SetLineColor(4); line1->Draw("same"); TLine *line2 = new TLine(0,1.1*avg,54,1.1*avg); line2->SetLineWidth(2); line2->SetLineColor(4); line2->Draw("same"); TLegend *leg = new TLegend(0.7,0.1,0.9,0.3); leg->AddEntry(linem5,"#pm 5%","l"); leg->AddEntry(line1,"#pm 10%","l"); leg->Draw(); }
void Eloss() { TString dir = getenv("VMCWORKDIR"); TString fFileNamebase; std::ifstream* ElossData; fFileNamebase = dir+"/macro/Simulation/data/109Pd_Eloss.txt"; ElossData = new std::ifstream(fFileNamebase.Data()); if(ElossData->fail()){ std::cout<<cRED<<" = No file found! Please, check the path. Current :"<<fFileNamebase.Data()<<cNORMAL<<std::endl; } TCanvas *c1 = new TCanvas(); c1->Draw(); c1->Divide(1,2); TH2D *Bragg = new TH2D("Bragg", "Bragg", 1000, 0,500, 1000, 0, 1); TH2D *Interpolate = new TH2D("Interpolate","Interpolate", 1000, 0,200000, 100, 0, 1); Double_t Eloss_elec, Eloss_nuc,SRIM_energy; Double_t x = 0; //microns Double_t x1 = 0; Double_t x0 = 0; Double_t Z = 46; Double_t A = 109; Double_t step = 1; //microns Double_t energy = 190000; //keV Double_t e1, e2, e3, dE1, dE2, dE3; Double_t param0, param1, param2,param3,param4,param5,param6; std::vector<std::tuple<Double_t,Double_t,Double_t>> SRIM_table; std::cout<<cGREEN<<"Extracting data. Please wait...."<<cNORMAL<<std::endl; while (!ElossData->eof()){ //Fill vector with datafile *ElossData>>SRIM_energy>>Eloss_elec>>Eloss_nuc; //keV >> keV/micron >> keV/micron SRIM_table.push_back(std::make_tuple(SRIM_energy, Eloss_elec, Eloss_nuc)); Interpolate->Fill(SRIM_energy, Eloss_elec); }//EndWhile /*for (Int_t n = 0; n < SRIM_table.size(); n++){ std::cout <<' '<< std::get<0> (SRIM_table.at(n))<<' '<<std::get<1> (SRIM_table.at(n))<<' '<<std::get<2> (SRIM_table.at(n))<<std::endl; }//EndFor */ /*Int_t counter = SRIM_table.size()-3; Double_t nuc_Loss, elec_Loss, total_Loss; e1 = std::get<0> (SRIM_table.at(counter)); e2 = std::get<0> (SRIM_table.at(counter-1)); e3 = std::get<0> (SRIM_table.at(counter-2)); dE1 = std::get<1> (SRIM_table.at(counter)); dE2 = std::get<1> (SRIM_table.at(counter-1)); dE3 = std::get<1> (SRIM_table.at(counter-2)); Interpolate->Fill(e1, dE1); Interpolate->Fill(e2, dE2); Interpolate->Fill(e3, dE3); Interpolate->Fit("enFit"); param0 = enFit->GetParameter(0); param1 = enFit->GetParameter(1); while (energy>20){ if(energy>std::get<0> (SRIM_table.at(counter))){ elec_Loss = param0*energy+param1; x+=step; //nuc_Loss = (std::get<2> (SRIM_table.at(counter+1)))*step; //elec_Loss = (std::get<1> (SRIM_table.at(counter+1)))*step; total_Loss = elec_Loss; //+nuc_Loss; energy -= total_Loss; Bragg->Fill(x/1000, total_Loss*10); std::cout<<energy<<" "<<total_Loss<<" "<<x<<std::endl; } else{ counter-=1; Interpolate->Reset(); e1 = std::get<0> (SRIM_table.at(counter)); e2 = std::get<0> (SRIM_table.at(counter-1)); e3 = std::get<0> (SRIM_table.at(counter-2)); dE1 = std::get<1> (SRIM_table.at(counter)); dE2 = std::get<1> (SRIM_table.at(counter-1)); dE3 = std::get<1> (SRIM_table.at(counter-2)); Interpolate->Fill(e1, dE1); Interpolate->Fill(e2, dE2); Interpolate->Fill(e3, dE3); Interpolate->Fit("enFit"); param0 = enFit->GetParameter(0); param1 = enFit->GetParameter(1); } }//EndWhile */ TF1 *enFit = new TF1("enFit", "[0]+[1]*x+[2]*pow(x,2)+[3]*pow(x,3)+[4]*pow(x,4)+[5]*pow(x,5)+[6]*pow(x,6)", 0 , 200000); enFit->SetParameters(1,1,1,1,1,1); Interpolate->Fit("enFit"); param0 = enFit->GetParameter(0); param1 = enFit->GetParameter(1); param2 = enFit->GetParameter(2); param3 = enFit->GetParameter(3); param4 = enFit->GetParameter(4); param5 = enFit->GetParameter(5); param6 = enFit->GetParameter(6); Double_t inter,loss; std::cout<<"Calculating..................."<<std::endl; while(energy>0){ x+=step; inter = param0+ param1*energy+param2*pow(energy,2)+param3*pow(energy,3)+param4*pow(energy,4)+param5*pow(energy,5)+param6*pow(energy,6); loss = inter*step; energy -= loss; Bragg->Fill(x/1000, loss); //mm, keV } std::cout<<cRED<<"Range: "<<x/1000<<" mm"<<cNORMAL<<std::endl; TF1 *brFit = new TF1("brFit", "[0]+[1]*x+[2]*pow(x,2)+[3]*pow(x,3)+[4]*pow(x,4)+[5]*pow(x,5)+[6]*pow(x,6)", 0 , 500); enFit->SetParameters(1,1,1,1,1,1); Bragg->Fit("brFit"); c1->cd(1); Bragg->Draw(); brFit->Draw("Same"); /*c1->cd(2); Interpolate->Draw(); enFit->Draw("same"); */ } //EndMacro
int main (int argc, char* argv[]) { if (argc < 2) { cout << argv[0] << "" << endl; return 0; } string dataDir = ""; string limitFile = ""; string outFile = ""; double m1step = 0; double m1min = 0; double m1max = 0; double m2step = 0; double m2min = 0; double m2max = 0; if (string(argv[1]) == "coNLSP") { limitFile = "limits/limits_coNLSP_v1.txt"; outFile = "exclusions/exclusions_coNLSP_v1.root"; m1step = 25; m1min = 550; m1max = 1400; m2step = 50; m2min = 2000; m2max = 2400; } else if (string(argv[1]) == "HeavyHiggs_OpenSearch") { limitFile = "limits/limits_HeavyHiggs_OpenSearch.txt"; outFile = "exclusions/exclusions_HeavyHiggs_OpenSearch.root"; m1step = 50; m1min = 300; m1max = 950; m2step = 50; m2min = 0; m2max = 0; } else if (string(argv[1]) == "HeavyHiggs_RPV2012") { limitFile = "limits/limits_HeavyHiggs_RPV2012.txt"; outFile = "exclusions/exclusions_HeavyHiggs_RPV2012.root"; m1step = 50; m1min = 300; m1max = 950; m2step = 50; m2min = 0; m2max = 0; } else if (string(argv[1]) == "AtoZhiggs_RPV2012") { limitFile = "limits/limits_AtoZhiggs_RPV2012.txt"; outFile = "exclusions/exclusions_AtoZhiggs_RPV2012.root"; m1step = 50; m1min = 300; m1max = 1000; m2step = 50; m2min = 0; m2max = 0; } else if (string(argv[1]) == "HeavyHiggs_RPV2012_19p4ifb") { limitFile = "limits/limits_HeavyHiggs_RPV2012_19p4ifb.txt"; outFile = "exclusions/exclusions_HeavyHiggs_RPV2012_19p4ifb.root"; m1step = 50; m1min = 300; m1max = 1000; m2step = 50; m2min = 0; m2max = 0; } else if (string(argv[1]) == "HeavyHiggs_RPV2012_19p4ifb_NoTau") { limitFile = "limits/limits_HeavyHiggs_RPV2012_19p4ifb_NoTau.txt"; outFile = "exclusions/exclusions_HeavyHiggs_RPV2012_19p4ifb_NoTau.root"; m1step = 50; m1min = 300; m1max = 1000; m2step = 50; m2min = 0; m2max = 0; }else if (string(argv[1]) == "T1tttt") { limitFile = "limits/limits_T1tttt_v1.txt"; outFile = "exclusions/exclusions_T1tttt_v1.root"; m1step = 25; m1min = 800; m1max = 1100; m2step = 25; m2min = 0; m2max = 750; } else if (string(argv[1]) == "StopLRPV_lambda122") { limitFile = "limits/limits_StopLRPV_lambda122.txt"; outFile = "exclusions/exclusions_StopLRPV_lambda122.root"; m1step = 50; m1min = 250; m1max = 1000; m2step = 25; m2min = 0; m2max = 0; } else if (string(argv[1]) == "StopLRPV_lambda123") { limitFile = "limits/limits_StopLRPV_lambda123.txt"; outFile = "exclusions/exclusions_StopLRPV_lambda123.root"; m1step = 50; m1min = 250; m1max = 1000; m2step = 25; m2min = 0; m2max = 0; } else if (string(argv[1]) == "StopLRPV_lambda233") { limitFile = "limits/limits_StopLRPV_lambda233.txt"; outFile = "exclusions/exclusions_StopLRPV_lambda233.root"; m1step = 50; m1min = 250; m1max = 1000; m2step = 25; m2min = 0; m2max = 0; } else if (string(argv[1]) == "LeptonicRPV_lambda233") { limitFile = "limits/limits_LeptonicRPV_lambda233.txt"; outFile = "exclusions/exclusions_LeptonicRPV_lambda233.root"; m1step = 100; m1min = 1000; m1max = 2200; m2step = 100; m2min = 800; m2max = 2400; } else if (string(argv[1]) == "mSUGRA_LRPV_lambda122") { limitFile = "limits/limits_mSUGRA_LRPV_lambda122_v2.txt"; outFile = "exclusions/exclusions_mSUGRA_LRPV_lambda122_v2.root"; m1step = 25; m1min = 100; m1max = 1300; m2step = 2; m2min = 2; m2max = 26; } else if (string(argv[1]) == "bprime") { limitFile = "/cms/thomassen/2012/EWKino/Statistics/bprime/limits.txt"; outFile = "exclusions_bprime.root"; m1step = 50; m1min = 500; m1max = 700; m2step = 0.1; m2min = 0; m2max = 1; } else if (string(argv[1]) == "StopHiggs") { limitFile = "limits/slide_combined_full_noreweight_chargino250.out"; outFile = "exclusions/exclusions_slide_combined_full_noreweight_chargino250.root"; m1step = 50; m1min = 200; m1max = 800; m2step = 0.1; m2min = 0; m2max = 1; } else { cout << "Unknown keyword " << argv[1] << endl; return -1; } if(m1max < m1min || m2max < m2min) return -1; int m1bins = (int)((m1max - m1min) / m1step + 1); int m2bins = (int)((m2max - m2min) / m2step + 1); m1max = m1min + (m1bins - 1) * m1step; m2max = m2min + (m2bins - 1) * m2step; TH2D* hObs = new TH2D ("hObs", limitFile.c_str() , m1bins, m1min - m1step/2., m1max + m1step/2. , m2bins, m2min - m2step/2., m2max + m2step/2.); hObs->GetXaxis()->SetTitle("m_{1}"); hObs->GetYaxis()->SetTitle("m_{2}"); TH2D* hExp = new TH2D(*hObs); hExp->SetName("hExp"); TH2D* hExp1p = new TH2D(*hObs); hExp1p->SetName("hExp1p"); TH2D* hExp1m = new TH2D(*hObs); hExp1m->SetName("hExp1m"); TH2D* hExp2p = new TH2D(*hObs); hExp2p->SetName("hExp2p"); TH2D* hExp2m = new TH2D(*hObs); hExp2m->SetName("hExp2m"); cout << "[PT] Reading limits from " << limitFile << " ..." << endl; ifstream in (limitFile.c_str()); while(in) { string line; getline(in, line); if(!in) break; double m1; double m2; float limit[6]; if(line[0] == '#') continue; sscanf (line.c_str(),"%lf:%lf cls: %f %f ( %f : %f ) ( %f : %f )", &m1, &m2, limit, limit+1, limit+2, limit+3, limit+4, limit+5); //cout << m1 << " " << m2 << " " << limit[0] << " " << limit[1] << " " << limit[2] << " " << limit[3] << " " << limit[4] << " " << limit[5] << endl; if(m1 < m1min || m2 < m2min || m1 > m1max || m2 > m2max) continue; if(!(m1 >= m1min && m1 <= m1max && (fmod(m1 - m1min, m1step) == 0 || fmod(m1 - m1min, m1step) - m1step < 1E-12)) || !(m2 >= m2min && m2 <= m2max && (fmod(m2 - m2min, m2step) == 0 || fmod(m2 - m2min, m2step) - m2step < 1E-12))) { cout << "[PT] Skipping point (" << m1 << "," << m2 << ") because it is not on the grid" << endl; continue; } if(hObs->GetBinContent(hObs->FindFixBin(m1, m2)) != 0 || hExp->GetBinContent(hExp->FindFixBin(m1, m2)) != 0) { cout << "[PT] ERROR: The point (" << m1 << "," << m2 << ") was already filled." << endl; return -1; } hObs->Fill(m1, m2, limit[0]); hExp->Fill(m1, m2, limit[1]); hExp1p->Fill(m1, m2, limit[2]); hExp1m->Fill(m1, m2, limit[3]); hExp2p->Fill(m1, m2, limit[4]); hExp2m->Fill(m1, m2, limit[5]); } TFile f(outFile.c_str(), "RECREATE"); hObs->Write(); hExp->Write(); hExp1p->Write(); hExp1m->Write(); hExp2p->Write(); hExp2m->Write(); f.Close(); cout << "Output file produced: " << outFile << endl; return 0; }
void frameViewerAngles_Mall(char* arg){ //Take the arguments and save them into respective strings std::string infileName; std::string inF; std::string inPrefix; std::string runs, layers; std::string runCount; std::istringstream stm(arg); inPrefix = "/home/p180f/Do_Jo_Ol_Ma/Analysis/MainProcedure/testMain/rawRoot/"; while (true) { if (std::getline(stm, layers, ' ')) { //load the input root files TChain *chain = new TChain("fourChamTree"); for (int i=0; ; i++) { runCount = std::to_string(i); inF = "run" + runCount + "_" + layers + "layers.root"; infileName = inPrefix + inF; ifstream fin; fin.open(infileName.c_str()); if (!fin.fail()) { fin.close(); chain->Add(infileName.c_str()); std::cout << "Got " << inF << std::endl; } else break; } //define frame arrays int frame[480][640]={0}; const int width = 480; const int height = 640; //define picture numbers for each tree // (in case they are needed) int pNum = 0; //get branch info from these guyz chain->SetBranchAddress("pNum", &pNum); chain->SetBranchAddress("frame", &frame); //define analysis variables Double_t ang[3] = {0}; Double_t angD = 0; Double_t x[4] = {0}; Double_t y[4] = {0}; Double_t x_int[1]; Double_t x_diff= 0; Double_t y_int[1]; Double_t m0 = 0; Double_t m1 = 0; Double_t b0 = 0; Double_t b1 = 0; Double_t const Pi = 3.14159265359; Double_t convert = 180 / Pi; TH2D *frameHisto = new TH2D("frameHisto","Muon Tracking by Line Fitting",width,0,width,height,0,height); //histogram for the stacked images TH1D *chamber1x = new TH1D("chamber1x", "Chamber 1x", width, 0, width); TH1D *chamber1y = new TH1D("chamber1y", "Chamber 1y", height, 0, height); TH1D *chamber2x = new TH1D("chamber2x", "Chamber 2x", width, 0, width); TH1D *chamber2y = new TH1D("chamber2y", "Chamber 2y", height, 0, height); TH1D *chamber3x = new TH1D("chamber3x", "Chamber 3x", width, 0, width); TH1D *chamber3y = new TH1D("chamber3y", "Chamber 3y", height, 0, height); TH1D *chamber4x = new TH1D("chamber4x", "Chamber 4x", width, 0, width); TH1D *chamber4y = new TH1D("chamber4y", "Chamber 4y", height, 0, height); TCanvas *pc2 = new TCanvas("pc2","Frame",0,0,800,800); pc2->cd(); frameHisto->SetStats(false); frameHisto->GetXaxis()->SetTitle("X position (px)"); frameHisto->GetXaxis()->CenterTitle(); frameHisto->GetYaxis()->SetTitle("Y position (px)"); frameHisto->GetYaxis()->CenterTitle(); Int_t nentries = chain->GetEntries(); int count = 0; for (Int_t i=0; i<nentries; i++) { chain->GetEntry(i); for (int x=0; x<width; x++) { for (int y=0; y<height; y++) { frameHisto->Fill(x, y, frame[x][y]); if (frame[x][y]>0) { if (y>580 && y<610) { chamber1x->Fill(x, frame[x][y]); chamber1y->Fill(y, frame[x][y]); } else if (y>400 && y<440) { chamber2x->Fill(x, frame[x][y]); chamber2y->Fill(y, frame[x][y]); } else if (y>240 && y<280) { chamber3x->Fill(x, frame[x][y]); chamber3y->Fill(y, frame[x][y]); } else if (y>50 && y<100) { chamber4x->Fill(x, frame[x][y]); chamber4y->Fill(y, frame[x][y]); } } } } //Get the means and fill the x, y coordinates x[0] = chamber1x->GetMean(); y[0] = chamber1y->GetMean(); x[1] = chamber2x->GetMean(); y[1] = chamber2y->GetMean(); x[2] = chamber3x->GetMean(); y[2] = chamber3y->GetMean(); x[3] = chamber4x->GetMean(); y[3] = chamber4y->GetMean(); Double_t x_pos = 0; Double_t y_pos = 0; //Calculate slopes and intercepts m0 = ((y[1]-y[0])/(x[1]-x[0])); m1 = ((y[3]-y[2])/(x[3]-x[2])); b0 = (y[0]-(m0*x[0])); b1 = (y[2]-(m1*x[2])); //Calculate the intersection coordinates x_int[0] = ((b1-b0)/(m0-m1)); y_int[0] = ((m0*x_int[0])+b0); //Calculate the angle ang[0] = atan(m0)*convert; ang[1] = atan(m1)*convert; //Calculate the rough difference in x in medium x_diff = ((340-b0)/m0) - ((340-b1)/m1); // std::cout << "ang[0], frame" << i << " = " << ang[0]<< std::endl; // std::cout << "ang[1], frame" << i << " = " << ang[1]<< std::endl; // cin.ignore(); //Make array of xdiff RMS Double_t x_diffRMS[5] = {41.06, 45.03, 43.29, 40.71, 34.25}; Double_t xRMS[4] = {0}; xRMS[0] = chamber1x->GetRMS(); xRMS[1] = chamber2x->GetRMS(); xRMS[2] = chamber3x->GetRMS(); xRMS[3] = chamber4x->GetRMS(); if(ang[0] < 0) ang[0] += 180; if(ang[1] < 0) ang[1] += 180; ang[2] = (ang[1]-ang[0]); //OTHER WAY TO FIND THE ANGLES Double_t x_comp[2] = {(x[3]-x[2]), (x[1]-x[0])}; Double_t y_comp[2] = {(y[3]-y[2]), (y[1]-y[0])}; Double_t vec_mag[2]; vec_mag[0] = TMath::Sqrt(x_comp[0]*x_comp[0]+y_comp[0]*y_comp[0]); vec_mag[1] = TMath::Sqrt(x_comp[1]*x_comp[1]+y_comp[1]*y_comp[1]); Double_t cosArg = ((x_comp[0]*x_comp[1]+y_comp[0]*y_comp[1])/(vec_mag[0]*vec_mag[1])); angD = acos(cosArg)*convert; if (x_comp[1]<x_comp[0]) { angD*=-1; } Double_t x_RMS[4]; x_RMS[0] = chamber1x->GetRMS(); x_RMS[1] = chamber2x->GetRMS(); x_RMS[2] = chamber3x->GetRMS(); x_RMS[3] = chamber4x->GetRMS(); std::cout << "Processing frame number: " << pNum << "\r"; if (x_RMS[0]>5 && x_RMS[1]>5 && x_RMS[2]>5 && x_RMS[3]>5) { //find new x points from given ymin, ymax double x_min[2]; double x_max[2]; double y_min[2] = {0,0}; double y_max[2] = {640,640}; x_min[0] = (y_min[0] - b0) / m0; x_max[0] = (y_max[0] - b0) / m0; x_min[1] = (y_min[1] - b1) / m1; x_max[1] = (y_max[1] - b1) / m1; TLine *line0 = new TLine(x_min[0], y_min[0], x_max[0], y_max[0]); TLine *line1 = new TLine(x_min[1], y_min[1], x_max[1], y_max[1]); TGraph *intersect = new TGraph(1, x_int, y_int); pc2->cd(); frameHisto->Draw("COLZ"); line0->Draw(); line1->Draw(); intersect->Draw("F1*"); gPad->Update(); //wait for user input to advance to next event std::cout << "Frame Number=" << pNum << std::endl; std::cout << "Press enter to advance to the next frame" << std::endl; std::cout << "x[0] RMS = " << x_RMS[0] << std::endl; std::cout << "x[1] RMS = " << x_RMS[1] << std::endl; std::cout << "x[2] RMS = " << x_RMS[2] << std::endl; std::cout << "x[3] RMS = " << x_RMS[3] << std::endl; std::cin.ignore(); //clear the old frame from the histogram frameHisto->Reset(); chamber1x->Reset(); chamber1y->Reset(); chamber2x->Reset(); chamber2y->Reset(); chamber3x->Reset(); chamber3y->Reset(); chamber4x->Reset(); chamber4y->Reset(); } } } else { break; } } std::cout << "Complete!\n"; }
void RecHit2RecHit(const char *infile1, const char *infile2, const char *outfile, const char *flag1 = "single", const char *flag2 = "single", const char *process = "full"){ bool debug = false; bool threshold = true; TTreeReader *tReader1, *tReader2; int nSkims = 10; bool skim = false; int cntSkimHB1 = 0; int cntSkimHB2 = 0; int cntSkimHE1 = 0; int cntSkimHE2 = 0; int cntSkimHE3 = 0; if(!strcmp(process,"skim")) skim = true; if(!strcmp(flag1,"single")){ TFile *f1 = new TFile(infile1); if(f1->IsZombie()){ cout << "Root file: " << infile1 << " not found!" << endl; return; } tReader1 = new TTreeReader("RecHitTree",f1); if(debug) cout << "Created tReader1 from " << infile1 << endl; } else if(!strcmp(flag1,"list")){ ifstream in1; in1.open(infile1); if(!in1.is_open()){ cout << "Cannot open list file: " << infile1 << endl; return; } TChain *chain1 = new TChain("RecHitTree"); string line1; while(in1.good()){ if(!std::getline(in1,line1)) break; // We read a line from the file if(!chain1->Add(line1.c_str())){ cout << "Problem loading tree from " << line1 << endl; }else{ cout << "Adding file: " << line1 << "..." << endl; } } in1.close(); tReader1 = new TTreeReader((TTree *)chain1); cout << "Finished loading files." << endl; } else { cout << "Unknown option: " << flag1 << endl; return; } if(!strcmp(flag2,"single")){ TFile *f2 = new TFile(infile2); if(f2->IsZombie()){ cout << "Root file: " << infile2 << " not found!" << endl; return; } tReader2 = new TTreeReader("RecHitTree",f2); cout << "Created tReader2 from " << infile2 << endl; } else if(!strcmp(flag2,"list")){ ifstream in2; in2.open(infile2); if(!in2.is_open()){ cout << "Cannot open list file: " << infile2 << endl; return; } TChain *chain2 = new TChain("RecHitTree"); string line2; while(in2.good()){ if(!std::getline(in2,line2)) break; // We read a line from the file if(!chain2->Add(line2.c_str())){ cout << "Problem loading tree from " << line2 << endl; }else{ cout << "Adding file: " << line2 << "..." << endl; } } in2.close(); tReader2 = new TTreeReader((TTree *)chain2); cout << "Finished loading files." << endl; } else { cout << "Unknown option: " << flag2 << endl; return; } TFile *fout = new TFile(outfile, "NEW"); if(fout->IsZombie()){ cout << "Root file: " << outfile << " cannot be created!" << endl; return; } //Define the branchs to be read TTreeReaderValue<Int_t> eventID1(*tReader1, "event"); TTreeReaderValue<Int_t> lumiID1(*tReader1, "lumi"); TTreeReaderValue<Int_t> runID1(*tReader1, "run"); TTreeReaderValue<std::vector<float>> readRecHitsHB1_En1(*tReader1, "recHitHB1_En"); TTreeReaderValue<std::vector<float>> readRecHitsHB1_EnRAW1(*tReader1, "recHitHB1_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHB1_ieta1(*tReader1, "recHitHB1_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHB1_iphi1(*tReader1, "recHitHB1_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHB1_time1(*tReader1, "recHitHB1_time"); TTreeReaderValue<std::vector<float>> readRecHitsHB2_En1(*tReader1, "recHitHB2_En"); TTreeReaderValue<std::vector<float>> readRecHitsHB2_EnRAW1(*tReader1, "recHitHB2_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHB2_ieta1(*tReader1, "recHitHB2_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHB2_iphi1(*tReader1, "recHitHB2_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHB2_time1(*tReader1, "recHitHB2_time"); TTreeReaderValue<std::vector<float>> readRecHitsHE1_En1(*tReader1, "recHitHE1_En"); TTreeReaderValue<std::vector<float>> readRecHitsHE1_EnRAW1(*tReader1, "recHitHE1_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHE1_ieta1(*tReader1, "recHitHE1_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHE1_iphi1(*tReader1, "recHitHE1_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHE1_time1(*tReader1, "recHitHE1_time"); TTreeReaderValue<std::vector<float>> readRecHitsHE2_En1(*tReader1, "recHitHE2_En"); TTreeReaderValue<std::vector<float>> readRecHitsHE2_EnRAW1(*tReader1, "recHitHE2_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHE2_ieta1(*tReader1, "recHitHE2_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHE2_iphi1(*tReader1, "recHitHE2_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHE2_time1(*tReader1, "recHitHE2_time"); TTreeReaderValue<std::vector<float>> readRecHitsHE3_En1(*tReader1, "recHitHE3_En"); TTreeReaderValue<std::vector<float>> readRecHitsHE3_EnRAW1(*tReader1, "recHitHE3_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHE3_ieta1(*tReader1, "recHitHE3_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHE3_iphi1(*tReader1, "recHitHE3_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHE3_time1(*tReader1, "recHitHE3_time"); TTreeReaderValue<std::vector<float>> readRecHitsHF1_En1(*tReader1, "recHitHF1_En"); TTreeReaderValue<std::vector<int>> readRecHitsHF1_ieta1(*tReader1, "recHitHF1_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHF1_iphi1(*tReader1, "recHitHF1_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHF1_time1(*tReader1, "recHitHF1_time"); TTreeReaderValue<std::vector<float>> readRecHitsHF2_En1(*tReader1, "recHitHF2_En"); TTreeReaderValue<std::vector<int>> readRecHitsHF2_ieta1(*tReader1, "recHitHF2_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHF2_iphi1(*tReader1, "recHitHF2_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHF2_time1(*tReader1, "recHitHF2_time"); TTreeReaderValue<std::vector<float>> readRecHitsHO_En1(*tReader1, "recHitHO_En"); TTreeReaderValue<std::vector<int>> readRecHitsHO_ieta1(*tReader1, "recHitHO_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHO_iphi1(*tReader1, "recHitHO_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHO_time1(*tReader1, "recHitHO_time"); //Tree2 TTreeReaderValue<Int_t> eventID2(*tReader2, "event"); TTreeReaderValue<Int_t> lumiID2(*tReader2, "lumi"); TTreeReaderValue<Int_t> runID2(*tReader2, "run"); TTreeReaderValue<std::vector<float>> readRecHitsHB1_En2(*tReader2, "recHitHB1_En"); TTreeReaderValue<std::vector<float>> readRecHitsHB1_EnRAW2(*tReader2, "recHitHB1_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHB1_ieta2(*tReader2, "recHitHB1_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHB1_iphi2(*tReader2, "recHitHB1_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHB1_time2(*tReader2, "recHitHB1_time"); TTreeReaderValue<std::vector<float>> readRecHitsHB2_En2(*tReader2, "recHitHB2_En"); TTreeReaderValue<std::vector<float>> readRecHitsHB2_EnRAW2(*tReader2, "recHitHB2_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHB2_ieta2(*tReader2, "recHitHB2_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHB2_iphi2(*tReader2, "recHitHB2_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHB2_time2(*tReader2, "recHitHB2_time"); TTreeReaderValue<std::vector<float>> readRecHitsHE1_En2(*tReader2, "recHitHE1_En"); TTreeReaderValue<std::vector<float>> readRecHitsHE1_EnRAW2(*tReader2, "recHitHE1_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHE1_ieta2(*tReader2, "recHitHE1_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHE1_iphi2(*tReader2, "recHitHE1_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHE1_time2(*tReader2, "recHitHE1_time"); TTreeReaderValue<std::vector<float>> readRecHitsHE2_En2(*tReader2, "recHitHE2_En"); TTreeReaderValue<std::vector<float>> readRecHitsHE2_EnRAW2(*tReader2, "recHitHE2_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHE2_ieta2(*tReader2, "recHitHE2_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHE2_iphi2(*tReader2, "recHitHE2_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHE2_time2(*tReader2, "recHitHE2_time"); TTreeReaderValue<std::vector<float>> readRecHitsHE3_En2(*tReader2, "recHitHE3_En"); TTreeReaderValue<std::vector<float>> readRecHitsHE3_EnRAW2(*tReader2, "recHitHE3_EnRAW"); TTreeReaderValue<std::vector<int>> readRecHitsHE3_ieta2(*tReader2, "recHitHE3_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHE3_iphi2(*tReader2, "recHitHE3_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHE3_time2(*tReader2, "recHitHE3_time"); TTreeReaderValue<std::vector<float>> readRecHitsHF1_En2(*tReader2, "recHitHF1_En"); TTreeReaderValue<std::vector<int>> readRecHitsHF1_ieta2(*tReader2, "recHitHF1_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHF1_iphi2(*tReader2, "recHitHF1_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHF1_time2(*tReader2, "recHitHF1_time"); TTreeReaderValue<std::vector<float>> readRecHitsHF2_En2(*tReader2, "recHitHF2_En"); TTreeReaderValue<std::vector<int>> readRecHitsHF2_ieta2(*tReader2, "recHitHF2_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHF2_iphi2(*tReader2, "recHitHF2_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHF2_time2(*tReader2, "recHitHF2_time"); TTreeReaderValue<std::vector<float>> readRecHitsHO_En2(*tReader2, "recHitHO_En"); TTreeReaderValue<std::vector<int>> readRecHitsHO_ieta2(*tReader2, "recHitHO_ieta"); TTreeReaderValue<std::vector<int>> readRecHitsHO_iphi2(*tReader2, "recHitHO_iphi"); TTreeReaderValue<std::vector<float>> readRecHitsHO_time2(*tReader2, "recHitHO_time"); fout->cd(); TH2D *recHitEnergyHB = new TH2D("recHitEnergyHB","recHitEnergyHB",300,-20,100,300,-20,100); TH2D *recHitEnergyHE = new TH2D("recHitEnergyHE","recHitEnergyHE",550,-20,200,550,-20,200); TH2D *recHitEnergyHF = new TH2D("recHitEnergyHF","recHitEnergyHF",650,-100,1200,650,-100,1200); TH2D *recHitEnergyHO = new TH2D("recHitEnergyHO","recHitEnergyHO",300,-20,100,300,-20,100); TH2D *recHitEnergyRAWHB = new TH2D("recHitEnergyRAWHB","recHitEnergyRAWHB",300,-20,100,300,-20,100); TH2D *recHitEnergyRAWHE = new TH2D("recHitEnergyRAWHE","recHitEnergyRAWHE",550,-20,200,550,-20,200); TH2D *recHitEnergyHB1 = new TH2D("recHitEnergyHB1","recHitEnergyHB1",300,-20,100,300,-20,100); TH2D *recHitEnergyHB2 = new TH2D("recHitEnergyHB2","recHitEnergyHB2",300,-20,100,300,-20,100); TH2D *recHitEnergyHE1 = new TH2D("recHitEnergyHE1","recHitEnergyHE1",550,-20,200,550,-20,200); TH2D *recHitEnergyHE2 = new TH2D("recHitEnergyHE2","recHitEnergyHE2",550,-20,200,550,-20,200); TH2D *recHitEnergyHE3 = new TH2D("recHitEnergyHE3","recHitEnergyHE3",550,-20,200,550,-20,200); TH2D *recHitEnergyRAWHB1 = new TH2D("recHitEnergyRAWHB1","recHitEnergyRAWHB1",300,-20,100,300,-20,100); TH2D *recHitEnergyRAWHB2 = new TH2D("recHitEnergyRAWHB2","recHitEnergyRAWHB2",300,-20,100,300,-20,100); TH2D *recHitEnergyRAWHE1 = new TH2D("recHitEnergyRAWHE1","recHitEnergyRAWHE1",550,-20,200,550,-20,200); TH2D *recHitEnergyRAWHE2 = new TH2D("recHitEnergyRAWHE2","recHitEnergyRAWHE2",550,-20,200,550,-20,200); TH2D *recHitEnergyRAWHE3 = new TH2D("recHitEnergyRAWHE3","recHitEnergyRAWHE3",550,-20,200,550,-20,200); TH2D *recHitEnergyHF1 = new TH2D("recHitEnergyHF1","recHitEnergyHF1",650,-100,1200,650,-100,1200); TH2D *recHitEnergyHF2 = new TH2D("recHitEnergyHF2","recHitEnergyHF2",650,-100,1200,650,-100,1200); TH2D *recHitTimingHB = new TH2D("recHitTimingHB","recHitTimingHB",350,-48,92,350,-48,90); TH2D *recHitTimingHB1 = new TH2D("recHitTimingHB1","recHitTimingHB1",350,-48,92,350,-48,90); TH2D *recHitTimingHB2 = new TH2D("recHitTimingHB2","recHitTimingHB2",350,-48,92,350,-48,90); TH2D *recHitTimingHE = new TH2D("recHitTimingHE","recHitTimingHE",350,-48,92,350,-48,90); TH2D *recHitTimingHE1 = new TH2D("recHitTimingHE1","recHitTimingHE1",350,-48,92,350,-48,90); TH2D *recHitTimingHE2 = new TH2D("recHitTimingHE2","recHitTimingHE2",350,-48,92,350,-48,90); TH2D *recHitTimingHE3 = new TH2D("recHitTimingHE3","recHitTimingHE3",350,-48,92,350,-48,90); TH2D *recHitTimingHF = new TH2D("recHitTimingHF","recHitTimingHF",350,-48,92,350,-48,90); TH2D *recHitTimingHF1 = new TH2D("recHitTimingHF1","recHitTimingHF1",350,-48,92,350,-48,90); TH2D *recHitTimingHF2 = new TH2D("recHitTimingHF2","recHitTimingHF2",350,-48,92,350,-48,90); TH2D *recHitTimingHO = new TH2D("recHitTimingHO","recHitTimingHO",350,-48,92,350,-48,90); TProfile *meanEnergy_vs_ieta_HB_1 = new TProfile("meanEnergy_vs_ieta_HB_1","meanEnergy_vs_ieta_HB_1",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HB_2 = new TProfile("meanEnergy_vs_ieta_HB_2","meanEnergy_vs_ieta_HB_2",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HB1_1 = new TProfile("meanEnergy_vs_ieta_HB1_1","meanEnergy_vs_ieta_HB1_1",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HB1_2 = new TProfile("meanEnergy_vs_ieta_HB1_2","meanEnergy_vs_ieta_HB1_2",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HB2_1 = new TProfile("meanEnergy_vs_ieta_HB2_1","meanEnergy_vs_ieta_HB2_1",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HB2_2 = new TProfile("meanEnergy_vs_ieta_HB2_2","meanEnergy_vs_ieta_HB2_2",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE_1 = new TProfile("meanEnergy_vs_ieta_HE_1","meanEnergy_vs_ieta_HE_1",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE_2 = new TProfile("meanEnergy_vs_ieta_HE_2","meanEnergy_vs_ieta_HE_2",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE1_1 = new TProfile("meanEnergy_vs_ieta_HE1_1","meanEnergy_vs_ieta_HE1_1",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE1_2 = new TProfile("meanEnergy_vs_ieta_HE1_2","meanEnergy_vs_ieta_HE1_2",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE2_1 = new TProfile("meanEnergy_vs_ieta_HE2_1","meanEnergy_vs_ieta_HE2_1",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE2_2 = new TProfile("meanEnergy_vs_ieta_HE2_2","meanEnergy_vs_ieta_HE2_2",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE3_1 = new TProfile("meanEnergy_vs_ieta_HE3_1","meanEnergy_vs_ieta_HE3_1",71,-30.5,30.5); TProfile *meanEnergy_vs_ieta_HE3_2 = new TProfile("meanEnergy_vs_ieta_HE3_2","meanEnergy_vs_ieta_HE3_2",71,-30.5,30.5); cout << "Filling histograms..." << endl; //We loop over all of the events and fill the histograms int numRecHits = 0; int recHitIeta = 0; int recHitIphi = 0; float recHitEnergy = 0; long tree2BookMark = 0; bool matched = false; bool wrapped = false; //This might be a bit of a kludge... long tree2first; if(!tReader2->Next()){ cout << "No branches can be read from the tree given in " << infile2 << "!" << endl; return; } else { tree2first = tReader2->GetCurrentEntry(); } //Let's track some information about the trees int tree1Events = 0; int matchedEvents = 0; int unmatchedEvents = 0; bool continueLoop = true; while(tReader1->Next()&&continueLoop){ if(debug && (tree1Events > 5000)) break; tree1Events++; if(debug) cout << "Processing event: " << tree1Events << ", " << *runID1 << ":" << *lumiID1 << ":" << *eventID1 << endl; //We look for a matching event in the second tree //Book mark the current event, if we come back here, there is not a matching RecHit tree2BookMark = tReader2->GetCurrentEntry(); matched = false; wrapped = false; //We iterate over Tree2 until we find a match or discover no matches. while(!matched && !(wrapped && (tree2BookMark == tReader2->GetCurrentEntry()))){ if((*eventID1 == *eventID2)&&(*runID1 == *runID2)){ //Mark these events as matching, the break out of the loop matched = true; break; } else if(!matched){ //Advance tree2 and check whether we have reached the end //wrap around to the beginning if(!tReader2->Next()){ wrapped = true; tReader2->SetEntry(tree2first); } } } //If we couldn't find the a matching event, we procede to the next if(!matched){ cout << "No matching event in " << infile2 << " for event " << *runID1 << ":" << *lumiID1 << ":" << *eventID1 << ". Proceding to next event." << endl; unmatchedEvents++; continue; } else { matchedEvents++; } if(tree1Events % 500 == 0) cout << "Added " << tree1Events << " events." << endl; if(skim) continueLoop = false; //Now for each subdet and depth, we will match the recHits bool rmatched = false; int v2BookMark = 0; for(int idx1 = 0; idx1 < (*readRecHitsHB1_En1).size(); idx1++){ //We enforce the cut on RecHit energy if(skim && cntSkimHB1 >= nSkims){ break; } else { continueLoop = true; } if(skim && ((*readRecHitsHB1_En1).at(idx1) < 20)) continue; int ieta1 = (*readRecHitsHB1_ieta1).at(idx1); int iphi1 = (*readRecHitsHB1_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHB1_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHB1_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHB1_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ if(skim){ if(abs((*readRecHitsHB1_En1).at(idx1) - (*readRecHitsHB1_En2).at(idx1)) > 5){ cntSkimHB1++; cout << *runID1 << ":" << *lumiID1 << ":" << *eventID1 << ", HB1, iEta: " << ieta1 << " iPhi: " << iphi1 << endl; cout << "M2 Energy, 1st Dataset: " << (*readRecHitsHB1_En1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHB1_En2).at(v2BookMark) << endl; cout << "M0 Energy, 1st Dataset: " << (*readRecHitsHB1_EnRAW1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHB1_EnRAW2).at(v2BookMark) << endl; cout << "Timing, 1st Dataset: " << (*readRecHitsHB1_time1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHB1_time2).at(v2BookMark) << endl; } } else { //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHB1->GetBinWidth(1); double enRawWidth = 2; // recHitEnergyRAWHB1->GetBinWidth(1); double timeWidth = 1; // recHitTimingHB1->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHB1_En1).at(idx1); double En2 = (*readRecHitsHB1_En2).at(v2BookMark); if(threshold && (En1 < 5 || En2 < 5)) continue; double EnRaw1 = (*readRecHitsHB1_EnRAW1).at(idx1); double EnRaw2 = (*readRecHitsHB1_EnRAW2).at(v2BookMark); double time1 = (*readRecHitsHB1_time1).at(idx1); double time2 = (*readRecHitsHB1_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHB->Fill(En1,En2); recHitEnergyHB1->Fill(En1,En2); meanEnergy_vs_ieta_HB_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HB_2->Fill(ieta1,En2); meanEnergy_vs_ieta_HB1_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HB1_2->Fill(ieta1,En2); } if(true){ //if(abs(EnRaw1 - EnRaw2) > enRawWidth/2){ recHitEnergyRAWHB->Fill(EnRaw1,EnRaw2); recHitEnergyRAWHB1->Fill(EnRaw1,EnRaw2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHB->Fill(time1,time2); recHitTimingHB1->Fill(time1,time2); } } //if(skim) } //if(rmatched) }//Loop over HB1 rmatched = false; v2BookMark = 0; for(int idx1 = 0; idx1 < (*readRecHitsHB2_En1).size(); idx1++){ //We enforce the cut on RecHit energy if(skim && cntSkimHB2 >= nSkims){ break; } else { continueLoop = true; } if(skim && ((*readRecHitsHB2_En1).at(idx1) < 20)) continue; int ieta1 = (*readRecHitsHB2_ieta1).at(idx1); int iphi1 = (*readRecHitsHB2_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHB2_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHB2_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHB2_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ if(skim){ if(abs((*readRecHitsHB2_En1).at(idx1) - (*readRecHitsHB2_En2).at(idx1)) > 5){ cntSkimHB2++; cout << *runID1 << ":" << *lumiID1 << ":" << *eventID1 << ", HB2, iEta: " << ieta1 << " iPhi: " << iphi1 << endl; cout << "M2 Energy, 1st Dataset: " << (*readRecHitsHB2_En1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHB2_En2).at(v2BookMark) << endl; cout << "M0 Energy, 1st Dataset: " << (*readRecHitsHB2_EnRAW1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHB2_EnRAW2).at(v2BookMark) << endl; cout << "Timing, 1st Dataset: " << (*readRecHitsHB2_time1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHB2_time2).at(v2BookMark) << endl; } } else { //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHB2->GetBinWidth(1); double enRawWidth = 2; // recHitEnergyRAWHB2->GetBinWidth(1); double timeWidth = 1; // recHitTimingHB2->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHB2_En1).at(idx1); double En2 = (*readRecHitsHB2_En2).at(v2BookMark); if(threshold && (En1 < 5 || En2 < 5)) continue; double EnRaw1 = (*readRecHitsHB2_EnRAW1).at(idx1); double EnRaw2 = (*readRecHitsHB2_EnRAW2).at(v2BookMark); double time1 = (*readRecHitsHB2_time1).at(idx1); double time2 = (*readRecHitsHB2_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHB->Fill(En1,En2); recHitEnergyHB2->Fill(En1,En2); meanEnergy_vs_ieta_HB_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HB_2->Fill(ieta1,En2); meanEnergy_vs_ieta_HB2_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HB2_2->Fill(ieta1,En2); } if(true){ //if(abs(EnRaw1 - EnRaw2) > enRawWidth/2){ recHitEnergyRAWHB->Fill(EnRaw1,EnRaw2); recHitEnergyRAWHB2->Fill(EnRaw1,EnRaw2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHB->Fill(time1,time2); recHitTimingHB2->Fill(time1,time2); } }//if(skim) } //if(rmatched) }//Loop over HB2 rmatched = false; v2BookMark = 0; for(int idx1 = 0; idx1 < (*readRecHitsHE1_En1).size(); idx1++){ //We enforce the cut on RecHit energy if(skim && cntSkimHE1 >= nSkims){ break; } else { continueLoop = true; } if(skim && ((*readRecHitsHE1_En1).at(idx1) < 20)) continue; int ieta1 = (*readRecHitsHE1_ieta1).at(idx1); int iphi1 = (*readRecHitsHE1_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHE1_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHE1_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHE1_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ if(skim){ if(abs((*readRecHitsHE1_En1).at(idx1) - (*readRecHitsHE1_En2).at(idx1)) > 5){ cntSkimHE1++; cout << *runID1 << ":" << *lumiID1 << ":" << *eventID1 << ", HE1, iEta: " << ieta1 << " iPhi: " << iphi1 << endl; cout << "M2 Energy, 1st Dataset: " << (*readRecHitsHE1_En1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE1_En2).at(v2BookMark) << endl; cout << "M0 Energy, 1st Dataset: " << (*readRecHitsHE1_EnRAW1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE1_EnRAW2).at(v2BookMark) << endl; cout << "Timing, 1st Dataset: " << (*readRecHitsHE1_time1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE1_time2).at(v2BookMark) << endl; } } else { //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHE1->GetBinWidth(1); double enRawWidth = 2; // recHitEnergyRAWHE1->GetBinWidth(1); double timeWidth = 1; // recHitTimingHE1->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHE1_En1).at(idx1); double En2 = (*readRecHitsHE1_En2).at(v2BookMark); if(threshold && (En1 < 5 || En2 < 5)) continue; double EnRaw1 = (*readRecHitsHE1_EnRAW1).at(idx1); double EnRaw2 = (*readRecHitsHE1_EnRAW2).at(v2BookMark); double time1 = (*readRecHitsHE1_time1).at(idx1); double time2 = (*readRecHitsHE1_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHE->Fill(En1,En2); recHitEnergyHE1->Fill(En1,En2); meanEnergy_vs_ieta_HE_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HE_2->Fill(ieta1,En2); meanEnergy_vs_ieta_HE1_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HE1_2->Fill(ieta1,En2); } if(true){ //if(abs(EnRaw1 - EnRaw2) > enRawWidth/2){ recHitEnergyRAWHE->Fill(EnRaw1,EnRaw2); recHitEnergyRAWHE1->Fill(EnRaw1,EnRaw2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHE->Fill(time1,time2); recHitTimingHE1->Fill(time1,time2); } }//if(skim) } //if(rmatched) }//Loop over HE1 rmatched = false; v2BookMark = 0; for(int idx1 = 0; idx1 < (*readRecHitsHE2_En1).size(); idx1++){ //We enforce the cut on RecHit energy if(skim && cntSkimHE2 >= nSkims){ break; } else { continueLoop = true; } if(skim && ((*readRecHitsHE2_En1).at(idx1) < 20)) continue; int ieta1 = (*readRecHitsHE2_ieta1).at(idx1); int iphi1 = (*readRecHitsHE2_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHE2_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHE2_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHE2_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ if(skim){ if(abs((*readRecHitsHE2_En1).at(idx1) - (*readRecHitsHE2_En2).at(idx1)) > 5){ cntSkimHE2++; cout << *runID1 << ":" << *lumiID1 << ":" << *eventID1 << ", HE2, iEta: " << ieta1 << " iPhi: " << iphi1 << endl; cout << "M2 Energy, 1st Dataset: " << (*readRecHitsHE2_En1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE2_En2).at(v2BookMark) << endl; cout << "M0 Energy, 1st Dataset: " << (*readRecHitsHE2_EnRAW1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE2_EnRAW2).at(v2BookMark) << endl; cout << "Timing, 1st Dataset: " << (*readRecHitsHE2_time1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE2_time2).at(v2BookMark) << endl; } } else { //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHE2->GetBinWidth(1); double enRawWidth = 2; // recHitEnergyRAWHE2->GetBinWidth(1); double timeWidth = 1; // recHitTimingHE2->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHE2_En1).at(idx1); double En2 = (*readRecHitsHE2_En2).at(v2BookMark); if(threshold && (En1 < 5 || En2 < 5)) continue; double EnRaw1 = (*readRecHitsHE2_EnRAW1).at(idx1); double EnRaw2 = (*readRecHitsHE2_EnRAW2).at(v2BookMark); double time1 = (*readRecHitsHE2_time1).at(idx1); double time2 = (*readRecHitsHE2_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHE->Fill(En1,En2); recHitEnergyHE2->Fill(En1,En2); meanEnergy_vs_ieta_HE_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HE_2->Fill(ieta1,En2); meanEnergy_vs_ieta_HE2_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HE2_2->Fill(ieta1,En2); } if(true){ //if(abs(EnRaw1 - EnRaw2) > enRawWidth/2){ recHitEnergyRAWHE->Fill(EnRaw1,EnRaw2); recHitEnergyRAWHE2->Fill(EnRaw1,EnRaw2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHE->Fill(time1,time2); recHitTimingHE2->Fill(time1,time2); } }//if(skim) } //if(rmatched) }//Loop over HE2 rmatched = false; v2BookMark = 0; for(int idx1 = 0; idx1 < (*readRecHitsHE3_En1).size(); idx1++){ //We enforce the cut on RecHit energy if(skim && cntSkimHE3 >= nSkims){ break; } else { continueLoop = true; } if(skim && ((*readRecHitsHE3_En1).at(idx1) < 20)) continue; int ieta1 = (*readRecHitsHE3_ieta1).at(idx1); int iphi1 = (*readRecHitsHE3_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHE3_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHE3_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHE3_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ if(skim){ if(abs((*readRecHitsHE3_En1).at(idx1) - (*readRecHitsHE3_En2).at(idx1)) > 5){ cntSkimHE3++; cout << *runID1 << ":" << *lumiID1 << ":" << *eventID1 << ", HE3, iEta: " << ieta1 << " iPhi: " << iphi1 << endl; cout << "M2 Energy, 1st Dataset: " << (*readRecHitsHE3_En1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE3_En2).at(v2BookMark) << endl; cout << "M0 Energy, 1st Dataset: " << (*readRecHitsHE3_EnRAW1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE3_EnRAW2).at(v2BookMark) << endl; cout << "Timing, 1st Dataset: " << (*readRecHitsHE3_time1).at(idx1) << ", 2nd Dataset: " << (*readRecHitsHE3_time2).at(v2BookMark) << endl; } } else { //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHE3->GetBinWidth(1); double enRawWidth = 2; // recHitEnergyRAWHE3->GetBinWidth(1); double timeWidth = 1; // recHitTimingHE3->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHE3_En1).at(idx1); double En2 = (*readRecHitsHE3_En2).at(v2BookMark); if(threshold && (En1 < 5 || En2 < 5)) continue; double EnRaw1 = (*readRecHitsHE3_EnRAW1).at(idx1); double EnRaw2 = (*readRecHitsHE3_EnRAW2).at(v2BookMark); double time1 = (*readRecHitsHE3_time1).at(idx1); double time2 = (*readRecHitsHE3_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHE->Fill(En1,En2); recHitEnergyHE3->Fill(En1,En2); meanEnergy_vs_ieta_HE_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HE_2->Fill(ieta1,En2); meanEnergy_vs_ieta_HE3_1->Fill(ieta1,En1); meanEnergy_vs_ieta_HE3_2->Fill(ieta1,En2); } if(true){ //if(abs(EnRaw1 - EnRaw2) > enRawWidth/2){ recHitEnergyRAWHE->Fill(EnRaw1,EnRaw2); recHitEnergyRAWHE3->Fill(EnRaw1,EnRaw2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHE->Fill(time1,time2); recHitTimingHE3->Fill(time1,time2); } }//if(skim) } //if(rmatched) }//Loop over HE3 rmatched = false; v2BookMark = 0; if(!skim) for(int idx1 = 0; idx1 < (*readRecHitsHF1_En1).size(); idx1++){ int ieta1 = (*readRecHitsHF1_ieta1).at(idx1); int iphi1 = (*readRecHitsHF1_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHF1_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHF1_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHF1_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHF1->GetBinWidth(1); double timeWidth = 1; // recHitTimingHF1->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHF1_En1).at(idx1); double En2 = (*readRecHitsHF1_En2).at(v2BookMark); double time1 = (*readRecHitsHF1_time1).at(idx1); double time2 = (*readRecHitsHF1_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHF->Fill(En1,En2); recHitEnergyHF1->Fill(En1,En2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHF->Fill(time1,time2); recHitTimingHF1->Fill(time1,time2); } } //if(rmatched) }//Loop over HF1 rmatched = false; v2BookMark = 0; if(!skim) for(int idx1 = 0; idx1 < (*readRecHitsHF2_En1).size(); idx1++){ int ieta1 = (*readRecHitsHF2_ieta1).at(idx1); int iphi1 = (*readRecHitsHF2_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHF2_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHF2_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHF2_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHF2->GetBinWidth(1); double timeWidth = 1; // recHitTimingHF2->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHF2_En1).at(idx1); double En2 = (*readRecHitsHF2_En2).at(v2BookMark); double time1 = (*readRecHitsHF2_time1).at(idx1); double time2 = (*readRecHitsHF2_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHF->Fill(En1,En2); recHitEnergyHF2->Fill(En1,En2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHF->Fill(time1,time2); recHitTimingHF2->Fill(time1,time2); } } //if(rmatched) }//Loop over HF2 rmatched = false; v2BookMark = 0; if(!skim) for(int idx1 = 0; idx1 < (*readRecHitsHO_En1).size(); idx1++){ int ieta1 = (*readRecHitsHO_ieta1).at(idx1); int iphi1 = (*readRecHitsHO_iphi1).at(idx1); rmatched = false; //assuming that the ordering of the recHits might be similar between releases, this might save us time. //in other words, instead of starting from the begining each time, we are going to look in the second vector //where we left off. int v2Size = (*readRecHitsHO_En2).size(); for(int idx2 = 0; idx2 < v2Size; idx2++){ int ieta2 = (*readRecHitsHO_ieta2).at((v2BookMark + idx2) % v2Size); int iphi2 = (*readRecHitsHO_iphi2).at((v2BookMark + idx2) % v2Size); if( (ieta1 == ieta2) && (iphi1 == iphi2) ){ rmatched = true; v2BookMark = (v2BookMark +idx2) % v2Size; break; //We don't need to test any of the other recHits } } if(rmatched){ //Get the histogram bin width, for decision on comparison double enWidth = 2; // recHitEnergyHO->GetBinWidth(1); double timeWidth = 1; // recHitTimingHO->GetBinWidth(1); //Fill the Histograms double En1 = (*readRecHitsHO_En1).at(idx1); double En2 = (*readRecHitsHO_En2).at(v2BookMark); double time1 = (*readRecHitsHO_time1).at(idx1); double time2 = (*readRecHitsHO_time2).at(v2BookMark); if(true){ //if(abs(En1 - En2) > enWidth/2){ recHitEnergyHO->Fill(En1,En2); } if(true){ //if(abs(time1 - time2) > timeWidth/2){ recHitTimingHO->Fill(time1,time2); } } //if(rmatched) }//Loop over HO } //Loop over events fout->Write(); }
// ----------------------------------------------------------------------------- // void rob() { // Binning int xbins = 100; int ybins = 100; double xmax = 1.0; double xmin = 0.0; // double xrange = xmax - xmin; // xmax += xrange / xbins / 2; // xmin -= xrange / xbins / 2; // //xbins++; double ymax = 1.0; double ymin = 0.0; // double yrange = ymax - ymin; // ymax += yrange / ybins / 2; // ymin -= yrange / ybins / 2; // //ybins++; std::cout << " Binning: " << " xbins: " << xbins << " ybins: " << xbins << " xmin: " << xmin << " xmax: " << xmax << " ymin: " << ymin << " ymax: " << ymax << std::endl; // Examples values of pt1, pt2, mht, x1, x2, x3, sigma and alpha_t // double pt1 = 50.; // double pt2 = 50.; // double mht = 50.; // double x1 = ( 2. * pt1 ) / ( pt1 + pt2 + mht ); // double x2 = ( 2. * pt2 ) / ( pt1 + pt2 + mht ); // double x3 = 2 - x1 - x2; // double sigma = ( x1*x1 + x2*x2 ) / ( (1-x1) * (1-x2) ); // double alpha_t = x2 / ( 2 * sqrt(x1+x2-1) ); // std::cout << " pt1: " << pt1 // << " pt2: " << pt2 // << " mht: " << mht // << " x1: " << x1 // << " x2: " << x2 // << " x3: " << x3 // << " sigma: " << sigma // << " alpha_t: " << alpha_t // << std::endl; // Cross section TCanvas* c1 = new TCanvas( "Contours", "" ); //c1->SetGridx(1); //c1->SetGridy(1); TPad* pad = new TPad("pad","",0.,0.,1.,1.); pad->SetGrid(); pad->Draw(); pad->cd(); pad->SetLogz(1); TH1F* hr = pad->DrawFrame(0.,0.,1.,1.); const int nx = 3; const int ny = 10; double pt[nx] = { 30., 50., 100. }; double ht[ny]; for ( int ii = 0; ii < ny; ++ii ) { ht[ii] = 150. + ii * 50.; } double ratio[nx][ny]; double xbin_centre = ( ( xmax - xmin ) / xbins ) / 2.; double ybin_centre = ( ( ymax - ymin ) / ybins ) / 2.; TH2D* his = new TH2D("Contours","",xbins,xmin,xmax,ybins,ymin,ymax); for ( int ii = 0; ii < nx; ++ii ) { for ( int jj = 0; jj < ny; ++jj ) { double x3 = ( 2. * pt[ii] ) / ( ht[jj] + pt[ii] ); double n = 0.; double d = 0.; for ( int xbin = 0; xbin < xbins; ++xbin ) { for ( int ybin = 0; ybin < ybins; ++ybin ) { double x2 = ( ( xmax - xmin ) / xbins ) * xbin + xmin; double x1 = ( ( ymax - ymin ) / ybins ) * ybin + ymin; double val = ( x1*x1 + x2*x2 ) / ( ( 1 - x1 ) * ( 1 - x2 ) ); if ( x1 < x2 || // jet ordering by Pt x1 + x2 > 2. || // from relation "x1 + x2 + x3 = 2" x1 > 1.0 || // from "lost jet" and relation "xmiss = -x1 -x2" x1 + x2 < 1. // from "lost jet" and relation "xmiss = -x1 -x2" ) { continue; } if ( ( x1 + x2 ) < ( 2 - x3 ) ) { continue; } d += val; double alpha_t = x2 / ( 2 * sqrt(x1+x2-1) ); if ( alpha_t > 0.5 ) n+= val; if ( ii == 2 && jj == 9 ) { his->Fill( x2+xbin_centre, x1+ybin_centre, val ); } } } double r = 0.; if ( d > 0. ) { r = n/d; } ratio[ii][jj] = r; std::cout << " Pt: " << pt[ii] << " ht: " << ht[jj] << " x3: " << x3 << " r: " << r << " n: " << n << " d: " << d << std::endl; } } gStyle->SetPalette(1); his->SetMaximum( his->GetMaximum() ); his->SetMinimum( his->GetMinimum(1.e-12) ); his->Draw("COLZsame"); // c1->cd(); // TPad* overlay = new TPad("overlay","",0.,0.,1.,1.); // overlay->SetFillStyle(4000); // overlay->SetFillColor(0); // overlay->SetFrameFillStyle(4000); // overlay->Draw(); // overlay->cd(); // Double_t pxmin = pad->GetUxmin(); // Double_t pymin = pad->GetUymin(); // Double_t pxmax = pad->GetUxmax(); // Double_t pymax = pad->GetUymax(); // TH1F* hframe = overlay->DrawFrame(pxmin,pymin,pxmax,pymax); // TMultiGraph* mg = new TMultiGraph(); // for ( Int_t i = 0; i < 10; i++ ) { // Double_t alpha_t = 0.5 + i*0.01; // const Int_t n_ = 100; // Double_t x1_[n_]; // Double_t x2_[n_]; // for ( Int_t j = 0; j < 100; j++ ) { // x2_[j] = j*0.01; // Double_t temp = ( x2_[j] - 2. * alpha_t * alpha_t ) / ( 2. * alpha_t ); // x1_[j] = temp * temp + 1 - alpha_t * alpha_t; // } // TGraph* gr = new TGraph(n_,x2_,x1_); // mg->Add(gr,"l"); // } // mg->Draw(); // TCanvas* c2 = new TCanvas( "Contours1", "" ); // c2->cd(); // TMultiGraph* mg2 = new TMultiGraph(); // for ( Int_t ii = 0; ii < 3; ii++ ) { // TGraph* gr = new TGraph(ny,ht,ratio[ii]); // mg2->Add(gr,"l"); // } // mg2->Draw("a"); // c1->cd(); // c1->SaveAs("c1.png"); // c2->cd(); // c2->SaveAs("c2.png"); }
TH2D * JetTrackSignal(int jetindex, double leadingjetptlow , double leadingjetpthigh , double subleadingjetptlow , double subleadingjetpthigh , double ptasslow , double ptasshigh, int centmin, int centmax, double vzrange, double dijetdphicut) { Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D * hJetTrackSignal; cout<<"before first exit"<<endl; if(jetindex==0) //leading jet { hJetTrackSignal = new TH2D(Form("signal_leadingjet%d_%d_ass%d_%d_cmin%d_cmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",100,-5,5,75,-pi,2*pi); } else if(jetindex==1) //subleading jet { hJetTrackSignal = new TH2D(Form("signal_subleadingjet%d_%d_ass%d_%d_cmin%d_cmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",100,-5,5,75,-pi,2*pi); } else //leading jet { cout<<"Error: only jetindex 0 and 1 currently supported (leading + subleading jet)"<<endl; exit(1); } double ntottrig = 0; int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; cout<<"before event for loop "<<n_entries_in_cent_range<<endl; // for (Long64_t jentry=0; jentry<10000;jentry++) { for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { if(jentry%1000==0) cout<<jentry-cent_index_start[centmin]<<"/"<<n_entries_in_cent_range<<endl; c->GetEntry(jentry); //! jet cuts, vz range, more than 2 jettss, dijetdphi 7/8 pi, both jet |eta| < 2, pt range cuts, aj cuts if( fabs(c->evt->vz) > vzrange ) continue; if( c->icPu5->nref < 2 ) continue; double dijetdphi = fabs(c->icPu5->jtphi[0] - c->icPu5->jtphi[1]); if( dijetdphi > pi ) dijetdphi = 2*pi - dijetdphi; if( dijetdphi > dijet_dphi_CUT ) continue; if( c->icPu5->jteta[0] > jet_eta_CUT || c->icPu5->jteta[1] > jet_eta_CUT ) continue; if( c->icPu5->jtpt[0] > leadingjetpthigh || c->icPu5->jtpt[0] < leadingjetptlow ) continue; if( c->icPu5->jtpt[1] > subleadingjetpthigh || c->icPu5->jtpt[1] < subleadingjetptlow ) continue; double aj = ( c->icPu5->jtpt[0] - c->icPu5->jtpt[1] ) / ( c->icPu5->jtpt[0] + c->icPu5->jtpt[1] ); // if( aj < 0.12 ) continue; double jeteta = c->icPu5->jteta[jetindex]; double jetphi = c->icPu5->jtphi[jetindex]; int ntrig = 1 , nass = 0; vector<double> asstrkEta; vector<double> asstrkPhi; vector<double> asstrkIndex; for(int j = 0 ; j < c->track->nTrk ; ++j) { if( c->track->trkPt[j]<ptasslow || c->track->trkPt[j]>ptasshigh || fabs(c->track->trkEta[j])>maxetaass) continue; if( c->track->trkAlgo[j]<4 || c->track->highPurity[j]) { ++nass; asstrkEta.push_back(c->track->trkEta[j]); asstrkPhi.push_back(c->track->trkPhi[j]); asstrkIndex.push_back(j); } } for(int i = 0 ; i < ntrig ; ++i) { ntottrig += 1; for(int j = 0 ; j < nass ; ++j) { double deta = fabs(jeteta-asstrkEta[j]); double dphi = fabs(jetphi-asstrkPhi[j]); if( dphi > pi ) dphi = 2*pi - dphi; hJetTrackSignal->Fill(deta,dphi); hJetTrackSignal->Fill(-deta,dphi); hJetTrackSignal->Fill(deta,-dphi); hJetTrackSignal->Fill(-deta,-dphi); hJetTrackSignal->Fill(deta,(2*pi)-dphi); hJetTrackSignal->Fill(-deta,(2*pi)-dphi); } } // if(jentry>100) break; } hJetTrackSignal->Scale(1/ntottrig); return hJetTrackSignal; }
void SimplePlot2D(){ //string filename = "data/scan_CH1-64_unmasked.root"; //string filename = "data/scan_CH1-50_masked.root"; string filename = "test.root"; string varXname = "VMM #"; string varYname = "CH #"; // delay count stuff int CH = 21; double delays[5]; double count_tot[5]; double count_right[5]; for(int i = 0; i < 5; i++){ delays[i] = double(i)*5.; count_tot[i] = 0.; count_right[i] = 0.; } /////////////////////////////////////////////////////// TChain* tree = new TChain("MMFE8","MMFE8"); tree->AddFile(filename.c_str()); MMFE8Base* base = new MMFE8Base(tree); int N = tree->GetEntries(); TH2D* hist = new TH2D("hist","hist", 8, 0.5, 8.5, 64, 0.5,64.5); TH2D* histN = (TH2D*) hist->Clone("norm"); TH2D* histchch = new TH2D("histchch","histchch", 64, 0.5, 64.5, 64, 0.5,64.5); TH2D* histDelay = new TH2D("histN","histN", 31, 9.5, 40.5, 5,-0.5, 4.5); TH2D* histDelayD = new TH2D("histD","histD", 31, 9.5, 40.5, 5,-0.5, 4.5); for(int i = 0; i < N; i++){ base->GetEntry(i); if(base->CHpulse == CH){ //count_tot[base->Delay] += 1.; count_tot[(base->TPDAC-80)/20] += 1.; if(base->CHpulse == base->CHword) //count_right[base->Delay] += base->TDO; count_right[(base->TPDAC-80)/20] += base->PDO; } //histDelayD->Fill(base->CHpulse,base->Delay); histDelayD->Fill(base->CHpulse,(base->TPDAC-80)/20); if(base->CHpulse == base->CHword) //histDelay->Fill(base->CHpulse,base->Delay,base->TDO); histDelay->Fill(base->CHpulse,(base->TPDAC-80)/20,base->PDO); if((base->CHpulse != base->CHword || true) && base->VMM == 6) histchch->Fill(base->CHpulse,base->CHword); if(base->CHpulse != base->CHword) continue; hist->Fill(base->VMM,base->CHpulse,base->PDO); histN->Fill(base->VMM,base->CHpulse); } for(int x = 0; x < 8; x++){ for(int y = 0; y < 64; y++){ double v = hist->GetBinContent(x+1,y+1); double N = histN->GetBinContent(x+1,y+1); hist->SetBinContent(x+1,y+1,v/max(int(N),1)); } } TLatex l; //l.NDC(); TCanvas* can = new TCanvas("can","can",600,500); can->SetTopMargin(0.05); can->SetLeftMargin(0.12); can->SetRightMargin(0.15); gStyle->SetOptStat(0); gStyle->SetOptTitle(0); can->Draw(); can->SetGridx(); can->SetGridy(); can->cd(); hist->Draw("COLZ"); hist->GetXaxis()->SetTitle(varXname.c_str()); hist->GetXaxis()->CenterTitle(); hist->GetYaxis()->SetTitle(varYname.c_str()); hist->GetYaxis()->CenterTitle(); hist->GetYaxis()->SetTitleOffset(1.4); hist->GetYaxis()->CenterTitle(); //hist->GetYaxis()->SetRangeUser(0.,hist->GetMaximum()*1.1) ; TCanvas* canN = new TCanvas("canN","canN",600,500); canN->SetTopMargin(0.05); canN->SetLeftMargin(0.12); canN->SetRightMargin(0.15); canN->Draw(); canN->SetGridx(); canN->SetGridy(); canN->cd(); histN->Draw("COLZ"); histN->GetXaxis()->SetTitle(varXname.c_str()); histN->GetXaxis()->CenterTitle(); histN->GetYaxis()->SetTitle(varYname.c_str()); histN->GetYaxis()->CenterTitle(); histN->GetYaxis()->SetTitleOffset(1.4); histN->GetYaxis()->CenterTitle(); TCanvas* canchch = new TCanvas("canchch","canchch",600,500); canchch->SetTopMargin(0.05); canchch->SetLeftMargin(0.12); canchch->SetRightMargin(0.15); canchch->Draw(); canchch->SetGridx(); canchch->SetGridy(); canchch->cd(); histchch->Draw("COLZ"); histchch->GetXaxis()->SetTitle("CH pulsed"); histchch->GetXaxis()->CenterTitle(); histchch->GetYaxis()->SetTitle("CH data"); histchch->GetYaxis()->CenterTitle(); histchch->GetYaxis()->SetTitleOffset(1.4); histchch->GetYaxis()->CenterTitle(); histchch->GetZaxis()->SetTitle("Number of data events"); histchch->GetZaxis()->SetTitleOffset(1.4); histchch->GetZaxis()->CenterTitle(); l.DrawLatex(.54,65.2,"VMM 2"); TCanvas* can_delay = new TCanvas("can_delay","can_delay",600,500); can_delay->Draw(); can_delay->cd(); for(int i = 0; i < 5; i++) count_tot[i] = count_right[i]/count_tot[i]; TGraph* gr = new TGraph(5,delays,count_tot); gr->SetMarkerSize(4); gr->SetMarkerStyle(5); gr->Draw("AP"); histDelay->Divide(histDelayD); TCanvas* canDelay = new TCanvas("canDelay","canDelay",600,500); canDelay->SetTopMargin(0.05); canDelay->SetLeftMargin(0.12); canDelay->SetRightMargin(0.15); canDelay->Draw(); canDelay->SetGridx(); canDelay->SetGridy(); canDelay->cd(); histDelay->Draw("COLZ"); histDelay->GetXaxis()->SetTitle("CH pulsed"); histDelay->GetXaxis()->CenterTitle(); histDelay->GetYaxis()->SetTitle("Delay Count"); histDelay->GetYaxis()->CenterTitle(); histDelay->GetYaxis()->SetTitleOffset(1.4); histDelay->GetYaxis()->CenterTitle(); histDelay->GetZaxis()->SetTitle("Fraction zeroes"); histDelay->GetZaxis()->SetTitleOffset(1.4); histDelay->GetZaxis()->CenterTitle(); }
TH2D * JetTrackBackground(int jetindex, double leadingjetptlow , double leadingjetpthigh , double subleadingjetptlow , double subleadingjetpthigh , double ptasslow , double ptasshigh, int centmin, int centmax, double vzrange, double dijetdphicut, int statfactor) { Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D * hJetTrackBackground; if(jetindex==0) //leading jet { hJetTrackBackground = new TH2D(Form("background_leadingjet%d_%d_ass%d_%d_cmin%d_cmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",100,-5,5,75,-pi,2*pi); } else if(jetindex==1) //subleading jet { hJetTrackBackground = new TH2D(Form("background_subleadingjet%d_%d_ass%d_%d_cmin%d_cmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",100,-5,5,75,-pi,2*pi); } else //leading jet { cout<<"Error: only jetindex 0 and 1 currently supported (leading + subleading jet)"<<endl; exit(1); } //! loop through all events in the centrality range to fill the mixed event background distribution int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; // for (Long64_t jentry=0; jentry<10000;jentry++) { for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { if(jentry%1000==0) cout<<jentry-cent_index_start[centmin]<<"/"<<n_entries_in_cent_range<<endl; c->GetEntry(jentry); //! skip events outside our vz range if(fabs(c->evt->vz)>vzrange) continue; int ntrackinptrange = 0; //! construct vectors of all tracks passing our cuts in this event if( c->icPu5->nref < 2 ) continue; double dijetdphi = fabs(c->icPu5->jtphi[0] - c->icPu5->jtphi[1]); if( dijetdphi > pi ) dijetdphi = 2*pi - dijetdphi; if( dijetdphi > dijet_dphi_CUT ) continue; if( c->icPu5->jteta[0] > jet_eta_CUT || c->icPu5->jteta[1] > jet_eta_CUT ) continue; if( c->icPu5->jtpt[0] > leadingjetpthigh || c->icPu5->jtpt[0] < leadingjetptlow ) continue; if( c->icPu5->jtpt[1] > subleadingjetpthigh || c->icPu5->jtpt[1] < subleadingjetptlow ) continue; double aj = ( c->icPu5->jtpt[0] - c->icPu5->jtpt[1] ) / ( c->icPu5->jtpt[0] + c->icPu5->jtpt[1] ); // if( aj > 0.12 ) continue; double thisjeteta = c->icPu5->jteta[jetindex]; double thisjetphi = c->icPu5->jtphi[jetindex]; int thiscent = c->evt->hiBin; //! loop through the next n events to pair with this event int mixentry = jentry; for(int k = 0 ; k < statfactor ; ++k) { mixentry++; //! stop the loop when we reach the end of the file or of this centrality bin if(mixentry==nentries) break; c->GetEntry(mixentry); if(c->evt->hiBin != thiscent) break; if(fabs(c->evt->vz)>vzrange) continue; int fillcount = 0; //! for each passed track in the original event pair all the passed tracks in the new event and fill deta dphi for(int j = 0 ; j < c->track->nTrk ; ++j) { if( c->track->trkPt[j]<ptasslow || c->track->trkPt[j]>ptasshigh || fabs(c->track->trkEta[j])>maxetaass) continue; if( c->track->trkAlgo[j]<4 || c->track->highPurity[j]) { double deta = fabs(thisjeteta - c->track->trkEta[j]); double dphi = fabs(thisjetphi - c->track->trkPhi[j]); if( dphi > pi ) dphi = 2*pi - dphi; hJetTrackBackground->Fill(deta,dphi); hJetTrackBackground->Fill(-deta,dphi); hJetTrackBackground->Fill(deta,-dphi); hJetTrackBackground->Fill(-deta,-dphi); hJetTrackBackground->Fill(deta,(2*pi)-dphi); hJetTrackBackground->Fill(-deta,(2*pi)-dphi); fillcount++; } } } } return hJetTrackBackground; }
TH2D * TrackTrackBackground(double pttriglow , double pttrighigh , double ptasslow, double ptasshigh, int centmin, int centmax, double vzrange, int statfactor) { Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D * hTrackTrackBackground = new TH2D(Form("background_trg%d_%d_ass%d_%d_cmin%d_cmax%d",(int)pttriglow,(int)pttrighigh,(int)ptasslow,(int)ptasshigh,centmin,centmax),";#Delta#eta;#Delta#phi",100,-5,5,75,-pi,2*pi); //! loop through all events in the centrality range to fill the mixed event background distribution int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { if(jentry%1000==0) cout<<jentry-cent_index_start[centmin]<<"/"<<n_entries_in_cent_range<<endl; c->GetEntry(jentry); //! skip events outside our vz range if(fabs(c->evt->vz)>vzrange) continue; int ntrackinptrange = 0; //! construct vectors of all tracks passing our cuts in this event vector<double> thistrkEta; vector<double> thistrkPhi; for(int i = 0 ; i < c->track->nTrk ; ++i) { if( c->track->trkPt[i]<pttriglow || c->track->trkPt[i]>pttrighigh || fabs(c->track->trkEta[i])>maxetatrg ) continue; ++ntrackinptrange; thistrkEta.push_back(c->track->trkEta[i]); thistrkPhi.push_back(c->track->trkPhi[i]); } int thiscent = c->evt->hiBin; //! loop through the next n events to pair with this event int mixentry = jentry; for(int k = 0 ; k < statfactor ; ++k) { mixentry++; //! stop the loop when we reach the end of the file or of this centrality bin if(mixentry==nentries) break; c->GetEntry(mixentry); if(c->evt->hiBin != thiscent) break; if(fabs(c->evt->vz)>vzrange) continue; int fillcount = 0; //! for each passed track in the original event pair all the passed tracks in the new event and fill deta dphi int ntrkhere = 0; for(int i = 0 ; i < ntrackinptrange ; ++i) { ntrkhere = 0; for(int j = 0 ; j < c->track->nTrk ; ++j) { if( c->track->trkPt[j]<ptasslow || c->track->trkPt[j]>ptasshigh || fabs(c->track->trkEta[j])>maxetaass) continue; double deta = fabs(thistrkEta[i] - c->track->trkEta[j]); double dphi = fabs(thistrkPhi[i] - c->track->trkPhi[j]); if( dphi > pi ) dphi = 2*pi - dphi; hTrackTrackBackground->Fill(deta,dphi); hTrackTrackBackground->Fill(-deta,dphi); hTrackTrackBackground->Fill(deta,-dphi); hTrackTrackBackground->Fill(-deta,-dphi); hTrackTrackBackground->Fill(deta,(2*pi)-dphi); hTrackTrackBackground->Fill(-deta,(2*pi)-dphi); fillcount++; ntrkhere++; } } // cout<<"stat "<<statfactor<<" ntrackinptrange "<<ntrackinptrange<<" ntrkhere "<<ntrkhere<<" fillcount "<<fillcount<<endl; } } return hTrackTrackBackground; }
void SinglePionEfficiency::Loop() { // In a ROOT session, you can do: // Root > .L SinglePionEfficiency.C // Root > SinglePionEfficiency t // Root > t.GetEntry(12); // Fill t data members with entry number 12 // Root > t.Show(); // Show values of entry 12 // Root > t.Show(16); // Read and show values of entry 16 // Root > t.Loop(); // Loop on all entries // // This is the loop skeleton where: // jentry is the global entry number in the chain // ientry is the entry number in the current Tree // Note that the argument to GetEntry must be: // jentry for TChain::GetEntry // ientry for TTree::GetEntry and TBranch::GetEntry // // To read only selected branches, Insert statements like: // METHOD1: // fChain->SetBranchStatus("*",0); // disable all branches // fChain->SetBranchStatus("branchname",1); // activate branchname // METHOD2: replace line // fChain->GetEntry(jentry); //read all branches //by b_branchname->GetEntry(ientry); //read only this branch if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); Long64_t nbytes = 0, nb = 0; // number of pt bins and intervals const Int_t nptbins = 12; const Int_t nptcuts = nptbins+1; // 0 1 2 3 4 5 6 7 8 9 10 11 Double_t pt[nptcuts]={0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 40., 50.0}; // number of eta bins and intervals const Int_t netabins = 12; const Int_t netacuts = netabins+1; // 0 1 2 3 4 5 6 7 8 9 10 11 Double_t eta[netacuts]={0.0, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6, 1.8, 2.0, 2.2, 2.4}; cout <<" Eta bins " << endl; // prepare eta points for graph Float_t etagr[netabins], eetagr[netabins]; for(Int_t i = 0; i < netabins; i++) { etagr[i] = 0.5*(eta[i]+eta[i+1]); eetagr[i] = 0.5*(eta[i+1]-eta[i]); cout <<" i = " << i <<" Eta = " << etagr[i] <<" err Eta = " << eetagr[i] << endl; } // prepare for graph Float_t ptgr[nptbins], eptgr[nptbins]; for(Int_t i = 0; i < nptbins; i++) { ptgr[i] = 0.5*(pt[i]+pt[i+1]); eptgr[i] = 0.5*(pt[i+1]-pt[i]); cout <<" i = " << i <<" pT = " << ptgr[i] <<" err pT = " << eptgr[i] << endl; } TH2D* hResp = new TH2D("hResp","Resp",nptbins, pt, netabins, eta); // histos for energy losses TH1F* hEnTrkNotInter[netabins]; const char* namesEnTrkNotInter[netabins] = {"hEnTrkNotInter1", "hEnTrkNotInter2", "hEnTrkNotInter3", "hEnTrkNotInter4", "hEnTrkNotInter5", "hEnTrkNotInter6", "hEnTrkNotInter7", "hEnTrkNotInter8", "hEnTrkNotInter9", "hEnTrkNotInter10", "hEnTrkNotInter11", "hEnTrkNotInter12"}; const char* titleEnTrkNotInter[netabins] = {"EnTrkNotInter1", "EnTrkNotInter2", "EnTrkNotInter3", "EnTrkNotInter4", "EnTrkNotInter5", "EnTrkNotInter6", "EnTrkNotInter7", "EnTrkNotInter8", "EnTrkNotInter9", "EnTrkNotInter10", "EnTrkNotInter11", "EnTrkNotInter12"}; TH1F* hEnTrkInter[netabins]; const char* namesEnTrkInter[netabins] = {"hEnTrkInter1", "hEnTrkInter2", "hEnTrkInter3", "hEnTrkInter4", "hEnTrkInter5", "hEnTrkInter6", "hEnTrkInter7", "hEnTrkInter8", "hEnTrkInter9", "hEnTrkInter10", "hEnTrkInter11", "hEnTrkInter12"}; const char* titleEnTrkInter[netabins] = {"EnTrkInter1", "EnTrkInter2", "EnTrkInter3", "EnTrkInter4", "EnTrkInter5", "EnTrkInter6", "EnTrkInter7", "EnTrkInter8", "EnTrkInter9", "EnTrkInter10", "EnTrkInter11", "EnTrkInter12"}; for(Int_t ih=0; ih < netabins; ih++) { hEnTrkNotInter[ih] = new TH1F(namesEnTrkNotInter[ih], titleEnTrkNotInter[ih], 40, -1., 3.); hEnTrkInter[ih] = new TH1F(namesEnTrkInter[ih], titleEnTrkInter[ih], 40, -1., 3.); } // // ===> for pi- and pi+ // N total and N reco tracks // find how to write output in file //~/scratch0/CMSSW_TEST/cmssw134gammajet/src/JetMETCorrections/GammaJet/src/GammaJetAnalysis.cc // total number of analized MC tracks Int_t ntrk[netabins][nptbins] = { {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; // number of found tracks Int_t ntrkreco[netabins][nptbins] = { {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; // number of lost tracks Int_t ntrklost[netabins][nptbins] = { {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; // number of tracks with impact point on calo Int_t ntrkrecor[netabins][nptbins] = { {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; // trk efficiency and error Float_t trkeff[netabins][nptbins], etrkeff[netabins][nptbins]; // response in 11x11 crystals + 5x5 HCAL around IP in ECAL Double_t response[netabins][nptbins] = { {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; // response for found tracks in cone 0.5 around MC track direction at vertex Double_t responseFoundTrk[netabins][nptbins] = { {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; // response for lost tracks in cone 0.5 around MC track direction at vertex Double_t responseLostTrk[netabins][nptbins] = { {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0,0,0,0}, }; // average response in 11x11 crystals + 5x5 HCAL around IP in ECAL Double_t responseF[netabins][nptbins]; // average response for found tracks in cone 0.5 around MC track direction at vertex Double_t responseFoundTrkF[netabins][nptbins]; // average response for lost tracks in cone 0.5 around MC track direction at vertex Double_t responseLostTrkF[netabins][nptbins]; // ratio of responses of lost and found tracks Double_t leak[netabins][nptbins]; Double_t drTrkcut = 0.01; Double_t purityTrkcut = 0.75; // for (Long64_t jentry=0; jentry<nentries;jentry++) { Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; nb = fChain->GetEntry(jentry); nbytes += nb; // if (Cut(ientry) < 0) continue; // counting events for efficiency calculation for(Int_t ieta = 0; ieta < netabins; ieta++) { for(Int_t ipt = 0; ipt < nptbins; ipt++) { // ==> pi+ if(fabs(etaSim1) >= eta[ieta] && fabs(etaSim1) < eta[ieta+1]) { // checking leakage if(ptSim1 > 10. && ptSim1 < 10000.) { if(drTrk2 < 0.01 && purityTrk2 == 1) { hEnTrkNotInter[ieta]->Fill(etCalo1/ptSim1); } else { hEnTrkInter[ieta]->Fill(etCalo1/ptSim1); } } // end of checking leakage if(ptSim1 >= pt[ipt] && ptSim1 < pt[ipt+1]) { ntrk[ieta][ipt] = ntrk[ieta][ipt]+1; // number of reco tracks if(drTrk1 < drTrkcut && purityTrk1 >= purityTrkcut) { ntrkreco[ieta][ipt] = ntrkreco[ieta][ipt]+1; // response for found tracks responseFoundTrk[ieta][ipt] = responseFoundTrk[ieta][ipt] + etCalo1/ptSim1; // Double_t theta = 2.*atan(exp(-etaSim1)); Double_t eSim1 = ptSim1/sin(theta); if(e1ECAL11x11 > -1000. && e1HCAL5x5 > -1000. && fabs(etaSim1) < 1000.) { ntrkrecor[ieta][ipt] = ntrkrecor[ieta][ipt]+1; Double_t e_ecal11 = e1ECAL11x11/eSim1; Double_t e_hcal5 = e1HCAL5x5/eSim1; Double_t e_ecalhcal11x5 = e_ecal11 + e_hcal5; response[ieta][ipt] = response[ieta][ipt] + e_ecalhcal11x5; } } else { // response for lost tracks ntrklost[ieta][ipt] = ntrklost[ieta][ipt]+1; responseLostTrk[ieta][ipt] = responseLostTrk[ieta][ipt] + etCalo1/ptSim1; // } } } // ==> pi- if(fabs(etaSim2) >= eta[ieta] && fabs(etaSim2) < eta[ieta+1]) { // checking leakage if(ptSim2 > 10. && ptSim2 < 1000.) { if(drTrk2 < 0.01 && purityTrk2 == 1) { hEnTrkNotInter[ieta]->Fill(etCalo2/ptSim2); } else { hEnTrkInter[ieta]->Fill(etCalo2/ptSim2); } } // end of checking leakage if(ptSim2 >= pt[ipt] && ptSim2 < pt[ipt+1]) { ntrk[ieta][ipt] = ntrk[ieta][ipt]+1; // number of reco tracks if(drTrk2 < drTrkcut && purityTrk2 >= purityTrkcut) { ntrkreco[ieta][ipt] = ntrkreco[ieta][ipt]+1; // response for found tracks responseFoundTrk[ieta][ipt] = responseFoundTrk[ieta][ipt] + etCalo2/ptSim2; // Double_t theta = 2.*atan(exp(-etaSim2)); Double_t eSim2 = ptSim2/sin(theta); if(e2ECAL11x11 > -1000. && e2HCAL5x5 > -1000. && fabs(etaSim2) < 1000.) { ntrkrecor[ieta][ipt] = ntrkrecor[ieta][ipt]+1; Double_t e_ecal11 = e2ECAL11x11/eSim2; Double_t e_hcal5 = e2HCAL5x5/eSim2; Double_t e_ecalhcal11x5 = e_ecal11 + e_hcal5; response[ieta][ipt] = response[ieta][ipt] + e_ecalhcal11x5; } } else { // response for lost tracks ntrklost[ieta][ipt] = ntrklost[ieta][ipt]+1; responseLostTrk[ieta][ipt] = responseLostTrk[ieta][ipt] + etCalo2/ptSim2; // } } } } } } // calculate efficiencfy, full graph and write output stream ofstream myoutput_eff("CMSSW_167_TrackNonEff.txt"); ofstream myoutput_eff1("CMSSW_167_TrackNonEff_one.txt"); ofstream myoutput_leak("CMSSW_167_TrackLeakage.txt"); ofstream myoutput_leak1("CMSSW_167_TrackLeakage_one.txt"); ofstream myoutput_resp("CMSSW_167_response.txt"); // calculate map of leackage for(Int_t ieta = 0; ieta < netabins; ieta++) { for(Int_t ipt = 0; ipt < nptbins; ipt++) { // found tracks if(ntrkreco[ieta][ipt] != 0) { responseFoundTrkF[ieta][ipt] = responseFoundTrk[ieta][ipt]/ntrkreco[ieta][ipt]; } else { responseFoundTrkF[ieta][ipt] = responseFoundTrkF[ieta][ipt-1]; } // lost tracks if(ntrklost[ieta][ipt] != 0) { responseLostTrkF[ieta][ipt] = responseLostTrk[ieta][ipt]/ntrklost[ieta][ipt]; } else { responseLostTrkF[ieta][ipt] = responseLostTrkF[ieta][ipt-1]; } } } for(Int_t ieta = 0; ieta <= netabins; ieta++) { for(Int_t ipt = 0; ipt <= nptbins; ipt++) { if(ieta < netabins && ipt < nptbins) { leak[ieta][ipt] = responseLostTrkF[ieta][ipt]/responseFoundTrkF[ieta][ipt]; cout <<" ieta = " << ieta <<" eta = " << eta[ieta] <<" ipt = " << ipt <<" pt = " << pt[ipt] <<" ntrkreco = " << ntrkreco[ieta][ipt] <<" ntrklost = " << ntrklost[ieta][ipt] <<" responseFoundTrk = " << responseFoundTrkF[ieta][ipt] <<" responseLostTrk = " << responseLostTrkF[ieta][ipt] <<" leak = " << leak[ieta][ipt] << endl; myoutput_leak << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << leak[ieta][ipt] << endl; myoutput_leak1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1. " << endl; } if(ipt == nptbins && ieta < netabins) { myoutput_leak << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << leak[ieta][ipt-1] << endl; myoutput_leak1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1. " << endl; } if(ipt < nptbins && ieta == netabins) { myoutput_leak << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << leak[ieta-1][ipt] << endl; myoutput_leak1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1. " << endl; } if(ipt == nptbins && ieta == netabins) { myoutput_leak << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << leak[ieta-1][ipt-1] << endl; myoutput_leak1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1. " << endl; } } } // calculate map of response and tracker efficiency cout <<" " << endl; cout <<" " << endl; cout <<" " << endl; for(Int_t ieta = 0; ieta <= netabins; ieta++) { for(Int_t ipt = 0; ipt <= nptbins; ipt++) { if(ieta < netabins && ipt < nptbins) { if(ntrk[ieta][ipt] != 0 && ntrkrecor[ieta][ipt] != 0) { trkeff[ieta][ipt] = 1.*ntrkreco[ieta][ipt]/ntrk[ieta][ipt]; etrkeff[ieta][ipt] = sqrt( trkeff[ieta][ipt]*(1.-trkeff[ieta][ipt])/ntrk[ieta][ipt] ); responseF[ieta][ipt] = response[ieta][ipt]/ntrkrecor[ieta][ipt]; cout <<" ieta = " << ieta <<" eta = " << eta[ieta] <<" ipt = " << ipt <<" pt = " << pt[ipt] <<" ntrkreco = " << ntrkreco[ieta][ipt] <<" ntrkrecor = " << ntrkrecor[ieta][ipt] <<" ntrk = " << ntrk[ieta][ipt] <<" eff = " << trkeff[ieta][ipt] <<" +/- " << etrkeff[ieta][ipt] <<" response = " << responseF[ieta][ipt] << endl; hResp->Fill(pt[ipt],eta[ieta],responseF[ieta][ipt]); myoutput_eff << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << trkeff[ieta][ipt] << endl; myoutput_resp << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << responseF[ieta][ipt] << endl; myoutput_eff1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1." << endl; } else { trkeff[ieta][ipt] = trkeff[ieta][ipt-1]; responseF[ieta][ipt] = responseF[ieta][ipt-1]; hResp->Fill(pt[ipt],eta[ieta],responseF[ieta][ipt]); myoutput_eff << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << trkeff[ieta][ipt] << endl; myoutput_resp << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << responseF[ieta][ipt] << endl; myoutput_eff1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1." << endl; } } if(ipt == nptbins && ieta < netabins) { myoutput_eff << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << trkeff[ieta][ipt-1] << endl; myoutput_resp << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << responseF[ieta][ipt-1] << endl; myoutput_eff1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1." << endl; } if(ipt < nptbins && ieta == netabins) { myoutput_eff << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << trkeff[ieta-1][ipt] << endl; myoutput_resp << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << responseF[ieta-1][ipt] << endl; myoutput_eff1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1." << endl; } if(ipt == nptbins && ieta == netabins) { myoutput_eff << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << trkeff[ieta-1][ipt-1] << endl; myoutput_resp << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << responseF[ieta-1][ipt-1] << endl; myoutput_eff1 << ieta << " " << ipt << " " << eta[ieta] << " " << pt[ipt] << " " << " 1." << endl; } } } // // plot leakage graph Float_t leakage[netabins], eleakage[netabins]; Float_t MeanNotInter[netabins], MeanErrorNotInter[netabins]; Float_t MeanInter[netabins], MeanErrorInter[netabins]; for(Int_t ih=0; ih < netabins; ih++) { // hEnTrkNotInter[ih]->Write(); // hEnTrkInter[ih]->Write(); MeanNotInter[ih] = hEnTrkNotInter[ih]->GetMean(); MeanErrorNotInter[ih] = hEnTrkNotInter[ih]->GetMeanError(); MeanInter[ih] = hEnTrkInter[ih]->GetMean(); MeanErrorInter[ih] = hEnTrkInter[ih]->GetMeanError(); leakage[ih] = MeanInter[ih]/MeanNotInter[ih]; eleakage[ih] = leakage[ih] * sqrt( (MeanErrorNotInter[ih]/MeanNotInter[ih])*(MeanErrorNotInter[ih]/MeanNotInter[ih]) + (MeanErrorInter[ih]/MeanInter[ih])*(MeanErrorInter[ih]/MeanInter[ih])); cout <<" ieta = " << ih <<" MeanNotInter = " << MeanNotInter[ih] <<" +/- " << MeanErrorNotInter[ih] <<" MeanInter = " << MeanInter[ih] <<" +/- " << MeanErrorInter[ih] <<" leakage = " << leakage[ih] <<" +/- " << eleakage[ih] << endl; } TGraph *gleak = new TGraphErrors(netabins,etagr,leakage, eetagr,eleakage); TGraph *eMeanNotInter = new TGraphErrors(netabins,etagr,MeanNotInter, eetagr,MeanErrorNotInter); TGraph *eMeanInter = new TGraphErrors(netabins,etagr,MeanInter, eetagr,MeanErrorInter); // vs Eta setTDRStyle(0,0); TCanvas* c3 = new TCanvas("X","Y",1); c3->Divide(1,2); c3->cd(1); TAxis* xaxis = eMeanNotInter->GetXaxis(); eMeanNotInter->GetXaxis()->SetTitle("#eta"); eMeanNotInter->GetYaxis()->SetTitle("calo E_{T}^{raw reco} in cone 0.5/p_{T}^{MC}"); xaxis->SetLimits(0.0,2.4); eMeanNotInter->SetMarkerStyle(21); // eMeanNotInter->SetMaximum(0.95); // eMeanNotInter->SetMinimum(0.55); eMeanNotInter->SetMaximum(1.); eMeanNotInter->SetMinimum(0.); eMeanNotInter->Draw("AP"); eMeanInter->SetMarkerStyle(24); eMeanInter->Draw("P"); TLatex *t = new TLatex(); t->SetTextSize(0.08); t->DrawLatex(0.2,0.9,"CMSSW_1_6_9"); TLegend *leg = new TLegend(0.2,0.2,0.8,0.4,NULL,"brNDC"); leg->SetFillColor(10); leg->AddEntry(eMeanNotInter,"recontructed tracks 2 < p_{T}^{#pi^{#pm}} < 10 GeV","P"); leg->AddEntry(eMeanInter,"not reconstructed tracks 2 < p_{T}^{#pi^{#pm}} < 10 GeV","P"); leg->Draw(); c3->cd(2); TAxis* xaxis = gleak->GetXaxis(); gleak->GetXaxis()->SetTitle("#eta"); gleak->GetYaxis()->SetTitle("ratio = <E_{T for lost tracks}^{raw reco} / E_{T for found tracks}^{raw reco}>"); xaxis->SetLimits(0.0,2.4); gleak->SetMarkerStyle(21); gleak->SetMaximum(1.0); // leak->SetMinimum(0.7); gleak->SetMinimum(0.5); gleak->Draw("AP"); TLatex *t = new TLatex(); t->SetTextSize(0.08); // t->DrawLatex(0.1,0.75,"<E_{T for lost tracks}^{raw reco} / E_{T for found tracks}^{raw reco}> for p_{T}^{#pi^{#pm}} >2 GeV"); c3->SaveAs("eMean_vs_eta_pt2-10.gif"); c3->SaveAs("eMean_vs_eta_pt2-10.eps"); // original distribtions setTDRStyle(0,0); gStyle->SetOptFit(0); TCanvas* c4 = new TCanvas("X","Y",1); hEnTrkNotInter[0]->GetYaxis()->SetTitle(""); hEnTrkNotInter[0]->GetXaxis()->SetTitle("calo E_{T}^{raw reco} in cone 0.5/p_{T}^{MC}"); Double_t scale = 1./hEnTrkNotInter[0]->Integral(); hEnTrkNotInter[0]->Scale(scale); hEnTrkNotInter[0]->SetLineWidth(4); hEnTrkNotInter[0]->SetMaximum(0.14); // hEnTrkNotInter[0]->SetMinimum(0.55); // Fitting Int_t binMax = hEnTrkNotInter[0]->GetMaximumBin(); TAxis* xaxis = hEnTrkNotInter[0]->GetXaxis(); Double_t binCenter = xaxis->GetBinCenter(binMax); Double_t rms = hEnTrkNotInter[0]->GetRMS(); Double_t rFitMin = binCenter - 1.5 * rms; Double_t rFitMax = binCenter + 1.5 * rms; hEnTrkNotInter[0]->Fit("gaus","","",rFitMin,rFitMax); TF1 *fit = hEnTrkNotInter[0]->GetFunction("gaus"); fit->SetLineWidth(4); fit->SetLineStyle(2); fit->Draw("same"); scale = 1./hEnTrkInter[0]->Integral(); hEnTrkInter[0]->Scale(scale); hEnTrkInter[0]->SetLineWidth(2); // Fitting Int_t binMax = hEnTrkInter[0]->GetMaximumBin(); TAxis* xaxis = hEnTrkInter[0]->GetXaxis(); Double_t binCenter = xaxis->GetBinCenter(binMax); Double_t rms = hEnTrkNotInter[0]->GetRMS(); Double_t rFitMin = binCenter - 1.5 * rms; Double_t rFitMax = binCenter + 1.5 * rms; hEnTrkInter[0]->Fit("gaus","","same",rFitMin,rFitMax); TF1 *fit = hEnTrkInter[0]->GetFunction("gaus"); fit->SetLineWidth(2); fit->SetLineStyle(2); fit->Draw("same"); TLatex *t = new TLatex(); t->SetTextSize(0.08); t->DrawLatex(0.2,0.9,"CMSSW_1_6_9"); TLegend *leg = new TLegend(0.15,0.7,0.9,0.9,NULL,"brNDC"); leg->SetFillColor(10); leg->AddEntry(hEnTrkNotInter[0],"recontructed tracks 2< p_{T}^{#pi^{#pm}} < 10 GeV, 0<#eta<0.2","L"); leg->AddEntry(hEnTrkInter[0],"not reconstructed tracks 2< p_{T}^{#pi^{#pm}} < 10 GeV, 0<#eta<0.2","L"); leg->Draw(); c4->SaveAs("eMean_at_eta0.gif"); c4->SaveAs("eMean_at_eta0.eps"); // original distribtions setTDRStyle(0,0); gStyle->SetOptFit(0); TCanvas* c5 = new TCanvas("X","Y",1); hEnTrkNotInter[9]->GetYaxis()->SetTitle(""); hEnTrkNotInter[9]->GetXaxis()->SetTitle("calo E_{T}^{raw reco} in cone 0.5/p_{T}^{MC}"); Double_t scale = 1./hEnTrkNotInter[9]->Integral(); hEnTrkNotInter[9]->Scale(scale); hEnTrkNotInter[9]->SetLineWidth(4); hEnTrkNotInter[9]->SetMaximum(0.17); // hEnTrkNotInter[9]->SetMinimum(0.55); // Fitting Int_t binMax = hEnTrkNotInter[9]->GetMaximumBin(); TAxis* xaxis = hEnTrkNotInter[9]->GetXaxis(); Double_t binCenter = xaxis->GetBinCenter(binMax); Double_t rms = hEnTrkNotInter[9]->GetRMS(); Double_t rFitMin = binCenter - 1.5 * rms; Double_t rFitMax = binCenter + 1.5 * rms; hEnTrkNotInter[9]->Fit("gaus","","",rFitMin,rFitMax); TF1 *fit = hEnTrkNotInter[9]->GetFunction("gaus"); fit->SetLineWidth(4); fit->SetLineStyle(2); fit->Draw("same"); scale = 1./hEnTrkInter[9]->Integral(); hEnTrkInter[9]->Scale(scale); hEnTrkInter[9]->SetLineWidth(2); // Fitting Int_t binMax = hEnTrkInter[9]->GetMaximumBin(); TAxis* xaxis = hEnTrkInter[9]->GetXaxis(); Double_t binCenter = xaxis->GetBinCenter(binMax); Double_t rms = hEnTrkNotInter[9]->GetRMS(); Double_t rFitMin = binCenter - 1.2 * rms; Double_t rFitMax = binCenter + 1.5 * rms; hEnTrkInter[9]->Fit("gaus","","same",rFitMin,rFitMax); TF1 *fit = hEnTrkInter[9]->GetFunction("gaus"); fit->SetLineWidth(2); fit->SetLineStyle(2); fit->Draw("same"); TLatex *t = new TLatex(); t->SetTextSize(0.08); t->DrawLatex(0.2,0.9,"CMSSW_1_6_9"); TLegend *leg = new TLegend(0.15,0.7,0.9,0.9,NULL,"brNDC"); leg->SetFillColor(10); leg->AddEntry(hEnTrkNotInter[9],"recontructed tracks p_{T}^{#pi^{#pm}} > 2 GeV, 1.8<#eta<2.0","L"); leg->AddEntry(hEnTrkInter[9],"not reconstructed tracks p_{T}^{#pi^{#pm}} > 2 GeV, 1.8<#eta<2.0","L"); leg->Draw(); c5->SaveAs("eMean_at_eta1.9.gif"); c5->SaveAs("eMean_at_eta1.9.eps"); TFile efile("response.root","recreate"); hResp->Write(); efile.Close(); }
TH2D * JetTrackBackground(int jetindex, double leadingjetptlow , double leadingjetpthigh , double subleadingjetptlow , double subleadingjetpthigh , double ptasslow , double ptasshigh, int centmin, int centmax, float ajmin , float ajmax , int doptweight , int mccommand , double jetamin , double jetamax , double vzrange, double dijetdphicut, int statfactor ) { if(mccommand==2) doptweight=0; Long64_t nentries = c->GetEntries(); Long64_t nbytes = 0, nb = 0; TH2D::SetDefaultSumw2(true); TH2D * hJetTrackBackground; if(jetindex==0) //leading jet { hJetTrackBackground = new TH2D(Form("background_leadingjet%d_%d_ass%d_%d_cmin%d_cmax%d_ajmin%d_ajmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax,(int)(ajmin*100),(int)(ajmax*100)),";#Delta#eta;#Delta#phi",100*3,-5,5,75*3,-pi,2*pi); } else if(jetindex==1) //subleading jet { hJetTrackBackground = new TH2D(Form("background_subleadingjet%d_%d_ass%d_%d_cmin%d_cmax%d_ajmin%d_ajmax%d",(int)leadingjetptlow,(int)leadingjetpthigh,(int)ptasslow,(int)ptasshigh,centmin,centmax,(int)(ajmin*100),(int)(ajmax*100)),";#Delta#eta;#Delta#phi",100*3,-5,5,75*3,-pi,2*pi); } else //leading jet { cout<<"Error: only jetindex 0 and 1 currently supported (leading + subleading jet)"<<endl; exit(1); } //! loop through all events in the centrality range to fill the mixed event background distribution int n_entries_in_cent_range = cent_index_start[centmax] - cent_index_start[centmin]; // for (Long64_t jentry=0; jentry<10000;jentry++) { for (Long64_t jentry=cent_index_start[centmin]; jentry<cent_index_start[centmax];jentry++) { if(jentry%1000==0) cout<<jentry-cent_index_start[centmin]<<"/"<<n_entries_in_cent_range<<endl; c->GetEntry(jentry); //! skip events outside our vz range if(mccommand==0) { if(!c->selectEvent()) continue; if(!c->hlt->HLT_HIJet80_v1) continue; } if( fabs(c->evt->vz) > vzrange ) continue; // if( c->akPu3PF->nref < 2 ) continue; // double dijetdphi = fabs(c->akPu3PF->jtphi[0] - c->akPu3PF->jtphi[1]); // if( dijetdphi > pi ) dijetdphi = 2*pi - dijetdphi; // if( dijetdphi > dijet_dphi_CUT ) continue; int jetindex = -1; while(true) { jetindex++; if( jetindex == c->akPu3PF->nref ) break; if( c->akPu3PF->jtpt[jetindex] > leadingjetpthigh ) continue; if( c->akPu3PF->jtpt[jetindex] < leadingjetptlow ) break; if( fabs(c->akPu3PF->jteta[jetindex]) > jetamax || fabs(c->akPu3PF->jteta[jetindex]) < jetamin ) continue; if ((c->akPu3PF->trackMax[jetindex]/c->akPu3PF->jtpt[jetindex])<0.01) continue; double thisjeteta = c->akPu3PF->jteta[jetindex]; double thisjetphi = c->akPu3PF->jtphi[jetindex]; int thiscent = c->evt->hiBin; //! loop through the next n events to pair with this event int mixentry = jentry; for(int k = 0 ; k < statfactor ; ++k) { mixentry++; //! stop the loop when we reach the end of the file or of this centrality bin if(mixentry==nentries) break; c->GetEntry(mixentry); if(c->evt->hiBin != thiscent) break; if(fabs(c->evt->vz)>vzrange) continue; int fillcount = 0; //! for each passed track in the original event pair all the passed tracks in the new event and fill deta dphi if(mccommand<2) { for(int j = 0 ; j < c->track->nTrk ; ++j) { if( c->track->trkPt[j]<ptasslow || c->track->trkPt[j]>ptasshigh || fabs(c->track->trkEta[j])>maxetaass) continue; if( c->track->trkAlgo[j]<4 || c->track->highPurity[j]) { double deta = fabs(thisjeteta - c->track->trkEta[j]); double dphi = fabs(thisjetphi - c->track->trkPhi[j]); // double effweight = c->getTrackCorrection(j); if( dphi > pi ) dphi = 2*pi - dphi; double effweight = 1; if(doptweight!=0) effweight = c->getTrackCorrection(j); hJetTrackBackground->Fill(deta,dphi,effweight); hJetTrackBackground->Fill(-deta,dphi,effweight); hJetTrackBackground->Fill(deta,-dphi,effweight); hJetTrackBackground->Fill(-deta,-dphi,effweight); hJetTrackBackground->Fill(deta,(2*pi)-dphi,effweight); hJetTrackBackground->Fill(-deta,(2*pi)-dphi,effweight); fillcount++; } } } else { for(int j = 0 ; j < c->track->nParticle ; ++j) { if( c->track->pPt[j]<ptasslow || c->track->pPt[j]>ptasshigh || fabs(c->track->pEta[j])>maxetaass) continue; double deta = fabs(thisjeteta - c->track->pEta[j]); double dphi = fabs(thisjetphi - c->track->pPhi[j]); // double effweight = c->getTrackCorrection(j); if( dphi > pi ) dphi = 2*pi - dphi; if(doptweight==0) { hJetTrackBackground->Fill(deta,dphi); hJetTrackBackground->Fill(-deta,dphi); hJetTrackBackground->Fill(deta,-dphi); hJetTrackBackground->Fill(-deta,-dphi); hJetTrackBackground->Fill(deta,(2*pi)-dphi); hJetTrackBackground->Fill(-deta,(2*pi)-dphi); } else { // hJetTrackBackground->Fill(deta,dphi,effweight); // hJetTrackBackground->Fill(-deta,dphi,effweight); // hJetTrackBackground->Fill(deta,-dphi,effweight); // hJetTrackBackground->Fill(-deta,-dphi,effweight); // hJetTrackBackground->Fill(deta,(2*pi)-dphi,effweight); // hJetTrackBackground->Fill(-deta,(2*pi)-dphi,effweight); } fillcount++; } } } } } c->ResetBooleans(); return hJetTrackBackground; }
void make2Dplot_MAX(TString setup, TString dir, int num, int MLSP,TString opt){ gStyle->SetOptStat(0); gStyle->SetCanvasColor(0); gStyle->SetPadColor(0); gStyle->SetMarkerStyle(15); gStyle->SetMarkerSize(0.25); gStyle->SetTextFont(42); gStyle->SetMarkerColor(37); if (num <3) {gStyle->SetPaintTextFormat("4.1f");} TString BDT =""; char cadena[128]; // Crea un fichero de salida ofstream fs(setup+".txt"); fs.setf(ios::fixed); fs.precision(1); TH2D* TwoDPlot = new TH2D("","",26,157.5, 812.5, 28, 12.5,712.5); for(int x=175; x<=800; x+=25){ // for(int x=175; x<=225; x+=25){ for(int y=25; y<=700; y+=25){ if (x - y > 99){ BDT = signalregiont2bw025(x,y); // cout << BDT << endl; double array[1] = { FOM(setup,BDT,dir,x,y,num) }; double arraycut[1]= { FOM(setup,BDT,dir,x,y,1) }; double temp = 0.; int mvaval = 0; double tempcut=0.; // Get the maximum of each point for all MVAs for(int i=0;i<1;i++){ if(arraycut[i]>temp){ temp = arraycut[i]; mvaval = i; tempcut=array[i]; } } if (num ==1) {TwoDPlot->Fill(x,y,temp);} if (num ==2) {TwoDPlot->Fill(x,y,tempcut);} if (num ==3) { if (BDT=="BDT1") mvaval=1; if (BDT=="BDT3") mvaval=3; if (BDT=="BDT4") mvaval=4; TwoDPlot->Fill(x,y,mvaval);} // createTableCLs(x,y,temp); } } } fs.close(); TCanvas c1("c1","c1",800,600); c1.SetLeftMargin(0.1706731); c1.SetRightMargin(0.1983173); c1.SetTopMargin(0.04895105); c1.SetBottomMargin(0.1416084); c1.Range(-289.7381,-191.8196,1334.643,1074.487); TwoDPlot->SetMarkerSize(1.); TwoDPlot->SetMarkerColor(kWhite); TwoDPlot->Draw("COLZ TEXT"); TwoDPlot->GetYaxis()->SetTitle("LSP mass"); TwoDPlot->GetXaxis()->SetTitle("Stop mass"); if (num==0) {TwoDPlot->GetZaxis()->SetTitle("Entries"); TwoDPlot->GetZaxis()->SetRangeUser(0,5000);} if (num==1) {TwoDPlot->GetZaxis()->SetTitle("FOM"); TwoDPlot->GetZaxis()->SetRangeUser(0,15);} if (num==2) {TwoDPlot->GetZaxis()->SetTitle("Optimal cut point"); TwoDPlot->GetZaxis()->SetRangeUser(0,1);} if (num==3) {TwoDPlot->GetZaxis()->SetTitle("Best performing BDT training"); TwoDPlot->GetZaxis()->SetRangeUser(0,6);} TFile* f = new TFile(dir+"_"+opt+".root","RECREATE"); TwoDPlot->Write("twodplot"); f->Write(); f->Close(); TLatex l1; l1.SetTextAlign(12); l1.SetTextSize(0.04); l1.SetNDC(); l1.DrawLatex(0.155, 0.98, "CMS Simulation, 20 fb^{-1}"); l1.DrawLatex(0.7, 0.98, "#sqrt{s} = 8 TeV"); l1.SetTextSize(0.03); if (num==3){ tex = new TLatex(0.7449749,0.8251748,"BDT1"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextFont(42); tex->SetTextSize(0.03); tex->SetTextAngle(41.15586); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.7449749,0.7097902,"BDT2"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextFont(42); tex->SetTextSize(0.03); tex->SetTextAngle(41.15586); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.7437186,0.5891608,"BDT3"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextFont(42); tex->SetTextSize(0.03); tex->SetTextAngle(41.15586); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.7424623,0.4755245,"BDT4"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextFont(42); tex->SetTextSize(0.03); tex->SetTextAngle(41.15586); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.7424623,0.3583916,"BDT5"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextFont(42); tex->SetTextSize(0.03); tex->SetTextAngle(41.15586); tex->SetLineWidth(2); tex->Draw(); tex = new TLatex(0.7424623,0.2447552,"BDT6"); tex->SetNDC(); tex->SetTextAlign(12); tex->SetTextFont(42); tex->SetTextSize(0.03); tex->SetTextAngle(41.15586); tex->SetLineWidth(2); tex->Draw(); } TString dataset_name; TString datasetnombre; if (dir == "T2bw025") {dataset_name = "t2bw_025";} if (dir == "T2bw050") {dataset_name = "t2bw_050";} if (dir == "T2bw075") {dataset_name = "t2bw_075";} if (dir == "T2tt") {dataset_name = "t2tt_all";} if (dir == "T2tt") {datasetnombre = "t2tt_half";} //if (num==0) c1.Print("~/www/STOP/BDTTraining/08TeV/"+dataset_name+"/"+setup+"/Entries_Lara.png"); //if (num==1) c1.Print("~/www/STOP/BDTTraining/08TeV/"+dataset_name+"/"+setup+"/FOM_Lara.png"); //if (num==2) c1.Print("~/www/STOP/BDTTraining/08TeV/"+dataset_name+"/"+setup+"/OptimalCut_Lara.png"); //if (num==3) c1.Print("~/www/STOP/BDTTraining/08TeV/"+dataset_name+"/"+setup+"/BestBDT_Lara.png"); if (num==0) c1.Print("~/www/STOP/BDTTraining/8TeV/"+dataset_name+"_half/BestSet/Entries_Lara_SR_fixcut.png"); if (num==1) c1.Print("~/www/STOP/BDTTraining/8TeV/"+dataset_name+"_half/BestSet/FOM_Lara_SR_fixcut.png"); if (num==2) c1.Print("~/www/STOP/BDTTraining/8TeV/"+dataset_name+"_half/BestSet/OptimalCut_Lara_SR_fixcut.png"); if (num==3) c1.Print("~/www/STOP/BDTTraining/8TeV/"+dataset_name+"_half/BestSet/BestBDT_Lara_SR_fixcut.png"); }
// get jet "histograms" from filename which is expected to be made of repeated // blocks as follows: // jet# eta phi pt ... // ipart eta phi pt // ipart eta phi pt // ... // #END JetHist::JetHist (const string & filename, double etamax, int nbins) { ifstream file(filename.c_str()); string line; //double etamax=6; //double etamax=5; double phimax = 2*3.14159265; //int nbins=40; // construct a histogram for the background to the jets ostringstream bname; bname << filename <<"-background"; _background = new TH2D(bname.str().c_str(),bname.str().c_str(), 2*nbins,-etamax,etamax,nbins,0.0,phimax); //_background = new TH2D(bname.str().c_str(),bname.str().c_str(), // 2*nbins,-etamax,etamax,2,0.0,phimax); _background->SetFillColor(kWhite); // these were supposed to have labelled the axes, but it doesn't work. _background->GetXaxis()->SetTitle("#eta"); _background->GetYaxis()->SetTitle("#phi"); _background->GetZaxis()->SetTitle("p_{#perp}"); stack.Add(_background); while (getline(file,line)) { if (line.substr(0,1) != " ") { // all interesting lines start with space? // extract a comment if there is one if (line.substr(0,2) == "# ") { _comment = line.substr(2,line.length()-2); } continue; } ostringstream name; name << filename<<"-jet-"<< _jets.size(); TH2D * hist = new TH2D(name.str().c_str(),name.str().c_str(), 2*nbins,-etamax,etamax,nbins,0.0,phimax); int i; double eta, phi, pt; //cout << filename <<": jet "<<_jets.size()<<endl; bool have_line = true; while (have_line || getline(file,line)) { have_line = false; if (line.substr(0,4) == "#END") {break;} istringstream sline(line); sline >> i >> eta >> phi >> pt; //cout << i << " "<<eta<<" "<<phi<<" "<<pt<<endl; hist->Fill(eta,phi,pt); // fill at phi,eta with weight pt // workaround for bug in stacks: fill all lower elements of the stack // with a fake amount -- this, miraculously will lead to correct coloring // of the top of the stack! //for (unsigned int j = 0; j < _jets.size(); j++) { // _jets[j]->Fill(phi,eta,1e-7); //} } // give it a colour (whatever that means...) //hist->SetFillColor(_jets.size()); int njet = _jets.size(); //hist->SetFillColor(njet+2); hist->SetFillColor(njet%50+2); // %50 seems tomake to diff to many-jet case //if (njet == 0) hist->SetFillColor(kRed); //else if (njet == 1) hist->SetFillColor(kBlue); //else hist->SetFillColor(kGreen); // add it to the list of jets (so we can delete it later...) _jets.push_back(hist); // put it onto the stack stack.Add(hist); //if (njet == 2) break; //break; } }
void ztree::ffgammajet(std::string outfname, int centmin, int centmax, float phoetmin, float phoetmax, std::string gen) { string tag = outfname; string s_alpha = gen; if (fChain == 0) return; Long64_t nentries = fChain->GetEntriesFast(); TFile * fout = new TFile(Form("%s_%s_%s_%d_%d.root",outfname.data(),tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),"recreate"); TH2D * hsubept = new TH2D(Form("hsubept_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),100,-0.5,99.5,100,0,100); TH2D * hsubept_refcone = new TH2D(Form("hsubept_refcone_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),100,-0.5,99.5,100,0,100); TH1D * hjetpt = new TH1D(Form("hjetpt_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";jet p_{T};"),20,0,500); TH1D * hjetgendphi = new TH1D(Form("hjetgendphi_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#DeltaR_{gen,reco};"),20,0,0.1); TH1D * hgammaff = new TH1D(Form("hgammaff_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";z;"),20,0,1); TH1D * hgammaffxi = new TH1D(Form("hgammaffxi_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); TH1D * hgammaffxi_refcone = new TH1D(Form("hgammaffxi_refcone_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); TH1D * hgammaphoffxi = new TH1D(Form("hgammaphoffxi_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); TH1D * hgammaphoffxi_refcone = new TH1D(Form("hgammaphoffxi_refcone_%s_%s_%d_%d",tag.data(),s_alpha.data(),abs(centmin),abs(centmax)),Form(";#xi=ln(1/z);"),10,0,5); Long64_t nbytes = 0, nb = 0; cout<<phoetmin<<" "<<phoetmax<<endl; for (Long64_t jentry=0; jentry<nentries;jentry++) { if(jentry%10000==0) { cout<<jentry<<"/"<<nentries<<endl; } Long64_t ientry = LoadTree(jentry); if (ientry < 0) break; // cout<<njet<<endl; // if(jentry > 10000) break; nb = fChain->GetEntry(jentry); nbytes += nb; if(hiBin < centmin || hiBin >= centmax) continue; //centrality cut if(nPho!=1) continue; if(gen.compare("gen")==0) { if(mcEt[pho_genMatchedIndex[0]]<phoetmin || mcEt[pho_genMatchedIndex[0]]>phoetmax) continue; } else { if(phoEt[0]*phoCorr[0]<phoetmin || phoEt[0]*phoCorr[0]>phoetmax) continue; } if(weight==0) weight=1; // cout<<njet<<endl; if(gen.compare("gen")==0) { for (int ijet = 0; ijet < njet; ijet++) { if( nPho==2 ) continue; if( jetpt[ijet]<40 ) continue; //jet pt Cut if( fabs(jeteta[ijet]) > 1.6) continue; //jeteta Cut if( fabs(jeteta[ijet]) < 0.3) continue; //jeteta Cut for reflected cone if( jetID[ijet]==0 ) continue; //redundant in this skim (all true) if( acos(cos(jetphi[ijet] - phoPhi[0])) < 7 * pi / 8 ) continue; hjetpt->Fill(jetpt[ijet]); float denrecodphi = acos(cos(jetphi[ijet] - gjetphi[ijet])); hjetgendphi->Fill(denrecodphi); for(int igen = 0 ; igen < mult ; ++igen) { if(!(abs(pdg[igen])==11 || abs(pdg[igen])==13 || abs(pdg[igen])==211 || abs(pdg[igen])==2212 || abs(pdg[igen])==321)) continue; if(sube[igen] != 0) continue; float dr = genjettrk_dr(igen,ijet); float dr_refcone = genrefconetrk_dr(igen,ijet); if(dr<0.3) { float z = pt[igen]/gjetpt[ijet]; float zpho = pt[igen]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaff->Fill(z); hgammaffxi->Fill(xi); hgammaphoffxi->Fill(xipho); hsubept->Fill(sube[igen],pt[igen]); // cout<<jetpt[ijet]<<endl; } if(dr_refcone<0.3) { float z = pt[igen]/gjetpt[ijet]; float zpho = pt[igen]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaffxi_refcone->Fill(xi); hgammaphoffxi_refcone->Fill(xipho); hsubept_refcone->Fill(sube[igen],pt[igen]); } } } } else { for (int ijet = 0; ijet < njet; ijet++) { if( nPho==2 ) continue; if( jetpt[ijet]<40 ) continue; //jet pt Cut if( fabs(jeteta[ijet]) > 1.6) continue; //jeteta Cut if( fabs(jeteta[ijet]) < 0.3) continue; //jeteta Cut for reflected cone if( jetID[ijet]==0 ) continue; //redundant in this skim (all true) if( acos(cos(jetphi[ijet] - phoPhi[0])) < 7 * pi / 8 ) continue; hjetpt->Fill(jetpt[ijet]); for (int itrk = 0; itrk < nTrk; itrk++) { float dr = jettrk_dr(itrk,ijet); // float dr = genjetrecotrk_dr(itrk,ijet); float dr_refcone = refconetrk_dr(itrk,ijet); // float dr_refcone = genrefconerecotrk_dr(itrk,ijet); if(dr<0.3) { float z = trkPt[itrk]/jetpt[ijet]; float zpho = trkPt[itrk]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaff->Fill(z,trkWeight[itrk]); hgammaffxi->Fill(xi,trkWeight[itrk]); hgammaphoffxi->Fill(xipho,trkWeight[itrk]); // hgammaff->Fill(z); // hgammaffxi->Fill(xi); // hgammaphoffxi->Fill(xipho); // cout<<jetpt[ijet]<<endl; } if(dr_refcone<0.3) { float z = trkPt[itrk]/jetpt[ijet]; float zpho = trkPt[itrk]/phoEt[0]; float xi = log(1.0/z); float xipho = log(1.0/zpho); hgammaffxi_refcone->Fill(xi,trkWeight[itrk]); hgammaphoffxi_refcone->Fill(xipho,trkWeight[itrk]); // hgammaffxi_refcone->Fill(xi); // hgammaphoffxi_refcone->Fill(xipho); } } // photons: normal mode power mode // pho 40 trigger // photon spike cuts etc // phoet > 35 // phoet > 40 after correction // haven't made it yet // phoeta < 1.44 // sumiso < 1 GeV // h/em < 0.1 // sigmaetaeta < 0.01 // jets: // some pt // jeteta < 1.6 // some id cuts // none yet but we'll add some // ak3pupf jets // delphi > 7 pi / 8 } } } fout->Write(); fout->Close(); }
void RPCSeedValidator(string FileName) { gStyle->SetOptStat(""); gStyle->SetOptTitle(0); if(debug) cout << FileName << endl; string theFileName = "../" + FileName; TFile* RootFile = TFile::Open(theFileName.c_str()); string OutputPlotNameFix = ".eps"; string FinalOutput = FileName + "_"; unsigned int EventNumber; int SimTrackId; int SimTrackType; double SimTrackMomentum; double SimTrackDirectionPhi; int SimTrackCharge; int SimTrackvalid; bool PassSegmentFilter; double SimMomentumPtatRef; double SimDirectionPhiatRef; double SimDirectionEtaatRef; double SimBendingPhi; double SimBendingEntryPositionX; double SimBendingEntryPositionY; double SimBendingEntryPositionZ; double SimBendingLeavePositionX; double SimBendingLeavePositionY; double SimBendingLeavePositionZ; unsigned int SeedNumber; int SeedCharge; double SeedPurity; double SeedQuality; double RecMomentumPtatRef; double RecDirectionPhiatRef; double RecDirectionEtaatRef; double RecBendingPhi; double RecBendingEntryPositionX; double RecBendingEntryPositionY; double RecBendingEntryPositionZ; double RecBendingLeavePositionX; double RecBendingLeavePositionY; double RecBendingLeavePositionZ; double RecBendingLastPhi; TTree* T0 = (TTree*)RootFile->Get("ExTree"); T0->SetBranchAddress("EventNumber", &EventNumber); T0->SetBranchAddress("SimTrackId", &SimTrackId); T0->SetBranchAddress("SimTrackType", &SimTrackType); T0->SetBranchAddress("SimTrackMomentum", &SimTrackMomentum); T0->SetBranchAddress("SimTrackDirectionPhi", &SimTrackDirectionPhi); T0->SetBranchAddress("SimTrackCharge", &SimTrackCharge); T0->SetBranchAddress("SimTrackValid", &SimTrackvalid); T0->SetBranchAddress("PassSegmentFilter", &PassSegmentFilter); T0->SetBranchAddress("SimMomentumPtatRef", &SimMomentumPtatRef); T0->SetBranchAddress("SimDirectionPhiatRef", &SimDirectionPhiatRef); T0->SetBranchAddress("SimDirectionEtaatRef", &SimDirectionEtaatRef); T0->SetBranchAddress("SimBendingPhi", &SimBendingPhi); T0->SetBranchAddress("SimBendingEntryPositionX", &SimBendingEntryPositionX); T0->SetBranchAddress("SimBendingEntryPositionY", &SimBendingEntryPositionY); T0->SetBranchAddress("SimBendingEntryPositionZ", &SimBendingEntryPositionZ); T0->SetBranchAddress("SimBendingLeavePositionX", &SimBendingLeavePositionX); T0->SetBranchAddress("SimBendingLeavePositionY", &SimBendingLeavePositionY); T0->SetBranchAddress("SimBendingLeavePositionZ", &SimBendingLeavePositionZ); T0->SetBranchAddress("SeedNumber", &SeedNumber); T0->SetBranchAddress("SeedCharge", &SeedCharge); T0->SetBranchAddress("SeedPurity", &SeedPurity); T0->SetBranchAddress("SeedQuality", &SeedQuality); T0->SetBranchAddress("RecMomentumPtatRef", &RecMomentumPtatRef); T0->SetBranchAddress("RecDirectionPhiatRef", &RecDirectionPhiatRef); T0->SetBranchAddress("RecDirectionEtaatRef", &RecDirectionEtaatRef); T0->SetBranchAddress("RecBendingPhi", &RecBendingPhi); T0->SetBranchAddress("RecBendingEntryPositionX", &RecBendingEntryPositionX); T0->SetBranchAddress("RecBendingEntryPositionY", &RecBendingEntryPositionY); T0->SetBranchAddress("RecBendingEntryPositionZ", &RecBendingEntryPositionZ); T0->SetBranchAddress("RecBendingLeavePositionX", &RecBendingLeavePositionX); T0->SetBranchAddress("RecBendingLeavePositionY", &RecBendingLeavePositionY); T0->SetBranchAddress("RecBendingLeavePositionZ", &RecBendingLeavePositionZ); T0->SetBranchAddress("RecBendingLastPhi", &RecBendingLastPhi); TH1D* SimTrackvalidHist = (TH1D*) new TH1D("SimTrackvalidHist", "SimTrackvalidHist", 2, 0, 2); TH1D* SeedPtforSimTrackvalidHist = (TH1D*) new TH1D("SeedPtforSimTrackvalidHist", "SeedPtforSimTrackvalidHist", 100, 0, 100); TH1D* SeeddeltaPtforSimTrackvalidHist = (TH1D*) new TH1D("SeeddeltaPtforSimTrackvalidHist", "SeeddeltaPtforSimTrackvalidHist", 150, -3., 3.); TH1D* SeeddeltaPhiforSimTrackvalidHist = (TH1D*) new TH1D("SeeddeltaPhiforSimTrackvalidHist", "SeeddeltaPhiforSimTrackvalidHist", 628, -3.14/6, 3.14/6); TH1D* SeeddeltaEtaforSimTrackvalidHist = (TH1D*) new TH1D("SeeddeltaEtaforSimTrackvalidHist", "SeeddeltaEtaforSimTrackvalidHist", 200, -1., 1.); TH1D* SeedPurityforSimTrackvalidHist = (TH1D*) new TH1D("SeedPurityforSimTrackvalidHist", "SeedPurityforSimTrackvalidHist", 20, 0, 2); TH1D* ChargeCheckforSimTrackvalidHist = (TH1D*) new TH1D("ChargeCheckforSimTrackvalidHist", "ChargeCheckforSimTrackvalidHist", 5, -2.5, 2.5); TH1D* SeedNumberforSimTrackvalidHist = (TH1D*) new TH1D("SeedNumberforSimTrackvalidHist", "SeedNumberforSimTrackvalidHist", 30, 0, 30); TH1D* SeedEfficiencyforSimTrackvalidHist = (TH1D*) new TH1D("SeedEfficiencyforSimTrackvalidHist", "SeedEfficiencyforSimTrackvalidHist", 2, 0, 2); TH1D* SeedNumberforSimTrackinvalidHist = (TH1D*) new TH1D("SeedNumberforSimTrackinvalidHist", "SeedNumberforSimTrackinvalidHist", 20, 0, 20); TH1D* SeedEfficiencyforSimTrackinvalidHist = (TH1D*) new TH1D("SeedEfficiencyforSimTrackinvalidHist", "SeedEfficiencyforSimTrackinvalidHist", 2, 0, 2); TH1D* RecBendingLastPhiHist = (TH1D*) new TH1D("RecBendingLastPhiHist", "RecBendingLastPhiHist", 628, -3.14/2, 3.14/2); TH1D* SeedEfficiencyHist = (TH1D*) new TH1D("SeedEfficiency", "SeedEfficiency", 2, 0, 2); TH2D* RecBendingPhi2PtHist = new TH2D("RecBendingPhi2PtHist", "RecBendingPhi2PtHist", 2000, -100, 100, 628, -3.14/4, 3.14/4); TH2D* PtRatoofRecBendingPhiHist = new TH2D("", "", 628, -3.14/4, 3.14/4, 2000, -100, 100); TObjArray* SimReverseBending = (TObjArray*) new TObjArray(); unsigned int LastSeedNumber = -1; unsigned int LastSimTrackvalid = 0; bool LastPassSegmentFilter = false; bool LastPurityFull = false; int Nentries = T0->GetEntries(); for(int i = 0; i < Nentries; i++) { T0->GetEntry(i); if(debug) cout << "SimTrackId: " << SimTrackId << ", SimTrackType: " << SimTrackType << ", PassSegmentFilter: " << PassSegmentFilter << ", SeedNumber: " << SeedNumber << ", SeedPurity: " << SeedPurity << ", SeedCharge: " << SeedCharge << ", SimTrackCharge: " << SimTrackCharge << ", SimBendingPhi: " << SimBendingPhi << ", RecBendingPhi: " << RecBendingPhi << ", RecBendingLastPhi: " << RecBendingLastPhi << ", RecMomentumPtatRef: " << RecMomentumPtatRef << ", SimMomentumPtatRef: " << SimMomentumPtatRef << ", LastSeedNumber: " << LastSeedNumber << endl; //if(SimTrackMomentum > 20.0) //continue; if(SeedNumber != 0) { if(SimTrackvalid == 1 && SeedPurity == 1. && PassSegmentFilter == true) { SeedPtforSimTrackvalidHist->Fill(RecMomentumPtatRef); SeeddeltaPtforSimTrackvalidHist->Fill((RecMomentumPtatRef-SimMomentumPtatRef)/SimMomentumPtatRef); SeeddeltaPhiforSimTrackvalidHist->Fill(RecDirectionPhiatRef-SimDirectionPhiatRef); SeeddeltaEtaforSimTrackvalidHist->Fill(RecDirectionEtaatRef-SimDirectionEtaatRef); RecBendingPhi2PtHist->Fill(SimMomentumPtatRef*SimTrackCharge, RecBendingPhi); double PtRato = SimMomentumPtatRef / RecMomentumPtatRef; if(debug) cout << "PtRato: " << PtRato << ", at RecBendingPhi: " << RecBendingPhi << endl; PtRatoofRecBendingPhiHist->Fill(RecBendingPhi, PtRato); RecBendingLastPhiHist->Fill((RecBendingLastPhi == 0. ? 0 : RecBendingLastPhi/fabs(RecBendingLastPhi))*SimTrackCharge); SeedPurityforSimTrackvalidHist->Fill(SeedPurity); ChargeCheckforSimTrackvalidHist->Fill(SeedCharge*SimTrackCharge); /* if(SeedPurity == 1) { //SeedPtforSimTrackvalidHist->Fill(RecMomentumPtatRef); //SeeddeltaPtforSimTrackvalidHist->Fill(RecMomentumPtatRef-SimMomentumPtatRef); RecBendingPhi2PtHist->Fill(SimMomentumPtatRef*SimTrackCharge, RecBendingPhi); double PtRato = SimMomentumPtatRef / RecMomentumPtatRef; if(debug) cout << "PtRato: " << PtRato << ", at RecBendingPhi: " << RecBendingPhi << endl; PtRatoofRecBendingPhiHist->Fill(RecBendingPhi, PtRato); RecBendingLastPhiHist->Fill((RecBendingLastPhi == 0. ? 0 : RecBendingLastPhi/fabs(RecBendingLastPhi))*SimTrackCharge); } */ if(SeedCharge*SimTrackCharge == -1) { if(debug) cout << "R1: " << sqrt(SimBendingEntryPositionX*SimBendingEntryPositionX+SimBendingEntryPositionY*SimBendingEntryPositionY) << ", R2: " << sqrt(SimBendingLeavePositionX*SimBendingLeavePositionX+SimBendingLeavePositionY*SimBendingLeavePositionY) << endl; TLine* SimSegment = new TLine(SimBendingEntryPositionX, SimBendingEntryPositionY, SimBendingLeavePositionX, SimBendingLeavePositionY); SimReverseBending->AddLast(SimSegment); } LastPurityFull = true; } } else { if(LastSeedNumber != -1) { if(LastSimTrackvalid == 1 && LastPassSegmentFilter == true) { if(debug) cout << "Filling valid track efficiency " << LastSeedNumber << endl; SeedNumberforSimTrackvalidHist->Fill(LastSeedNumber); SeedEfficiencyforSimTrackvalidHist->Fill(LastPurityFull==true?1:0); } else { SeedNumberforSimTrackinvalidHist->Fill(LastSeedNumber); SeedEfficiencyforSimTrackinvalidHist->Fill(LastPurityFull==true?1:0); } LastPurityFull = false; } } LastPassSegmentFilter = PassSegmentFilter; LastSeedNumber = SeedNumber; LastSimTrackvalid = SimTrackvalid; } if(LastSeedNumber != -1) { if(LastSimTrackvalid == 1 && LastPassSegmentFilter == true) { SeedNumberforSimTrackvalidHist->Fill(LastSeedNumber); SeedEfficiencyforSimTrackvalidHist->Fill(LastPurityFull==true?1:0); } else { SeedNumberforSimTrackinvalidHist->Fill(LastSeedNumber); SeedEfficiencyforSimTrackinvalidHist->Fill(LastPurityFull == true?1:0); } } TCanvas* SimTrackvalidCanvas = new TCanvas("SimTrackvalidCanvas", "SimTrackvalidCanvas", 800, 600); SimTrackvalidCanvas->cd(); SimTrackvalidHist->Draw(); string SimTrackvalidCanvasName = FinalOutput + "SimTrackvalid" + OutputPlotNameFix; SimTrackvalidCanvas->SaveAs(SimTrackvalidCanvasName.c_str()); TCanvas* SeedPtforSimTrackvalidCanvas = new TCanvas("SeedPtforSimTrackvalidCanvas", "SeedPtforSimTrackvalidCanvas", 800, 600); SeedPtforSimTrackvalidCanvas->cd(); SeedPtforSimTrackvalidHist->Draw(); string SeedPtforSimTrackvalidCanvasName = FinalOutput + "SeedPtforSimTrackvalid" + OutputPlotNameFix; SeedPtforSimTrackvalidCanvas->SaveAs(SeedPtforSimTrackvalidCanvasName.c_str()); TCanvas* SeeddeltaPtforSimTrackvalidCanvas = new TCanvas("SeeddeltaPtforSimTrackvalidCanvas", "SeeddeltaPtforSimTrackvalidCanvas", 800, 600); SeeddeltaPtforSimTrackvalidCanvas->cd(); SeeddeltaPtforSimTrackvalidHist->SetStats(1); gStyle->SetOptFit(0111); //SeeddeltaPtforSimTrackvalidHist->Fit("gaus", "", "", -1., 1.); SeeddeltaPtforSimTrackvalidHist->GetXaxis()->SetTitle("(recPt-simPt)/simPt"); SeeddeltaPtforSimTrackvalidHist->GetXaxis()->CenterTitle(); SeeddeltaPtforSimTrackvalidHist->Draw(); string SeeddeltaPtforSimTrackvalidCanvasName = FinalOutput + "SeeddeltaPtforSimTrackvalid" + OutputPlotNameFix; SeeddeltaPtforSimTrackvalidCanvas->SaveAs(SeeddeltaPtforSimTrackvalidCanvasName.c_str()); TCanvas* SeeddeltaPhiforSimTrackvalidCanvas = new TCanvas("SeeddeltaPhiforSimTrackvalidCanvas", "SeeddeltaPhiforSimTrackvalidCanvas", 800, 600); SeeddeltaPhiforSimTrackvalidCanvas->cd(); SeeddeltaPhiforSimTrackvalidHist->SetStats(1); SeeddeltaPhiforSimTrackvalidHist->GetXaxis()->SetTitle("(recPhi-simPhi)"); SeeddeltaPhiforSimTrackvalidHist->GetXaxis()->CenterTitle(); SeeddeltaPhiforSimTrackvalidHist->Draw(); string SeeddeltaPhiforSimTrackvalidCanvasName = FinalOutput + "SeeddeltaPhiforSimTrackvalid" + OutputPlotNameFix; SeeddeltaPhiforSimTrackvalidCanvas->SaveAs(SeeddeltaPhiforSimTrackvalidCanvasName.c_str()); TCanvas* SeeddeltaEtaforSimTrackvalidCanvas = new TCanvas("SeeddeltaEtaforSimTrackvalidCanvas", "SeeddeltaEtaforSimTrackvalidCanvas", 800, 600); SeeddeltaEtaforSimTrackvalidCanvas->cd(); SeeddeltaEtaforSimTrackvalidHist->SetStats(1); SeeddeltaEtaforSimTrackvalidHist->GetXaxis()->SetTitle("(recEta-simEta)"); SeeddeltaEtaforSimTrackvalidHist->GetXaxis()->CenterTitle(); SeeddeltaEtaforSimTrackvalidHist->Draw(); string SeeddeltaEtaforSimTrackvalidCanvasName = FinalOutput + "SeeddeltaEtaforSimTrackvalid" + OutputPlotNameFix; SeeddeltaEtaforSimTrackvalidCanvas->SaveAs(SeeddeltaEtaforSimTrackvalidCanvasName.c_str()); TCanvas* SeedPurityforSimTrackvalidCanvas = new TCanvas("SeedPurityforSimTrackvalidCanvas", "SeedPurityforSimTrackvalidCanvas", 800, 600); SeedPurityforSimTrackvalidCanvas->cd(); SeedPurityforSimTrackvalidHist->Draw(); string SeedPurityforSimTrackvalidCanvasName = FinalOutput + "SeedPurityforSimTrackvalid" + OutputPlotNameFix; SeedPurityforSimTrackvalidCanvas->SaveAs(SeedPurityforSimTrackvalidCanvasName.c_str()); TCanvas* ChargeCheckforSimTrackvalidCanvas = new TCanvas("ChargeCheckforSimTrackvalidCanvas", "ChargeCheckforSimTrackvalidCanvas", 800, 600); ChargeCheckforSimTrackvalidCanvas->cd(); double HistEntries = ChargeCheckforSimTrackvalidHist->GetEntries() / 100.; ChargeCheckforSimTrackvalidHist->Scale(1./HistEntries); ChargeCheckforSimTrackvalidHist->GetXaxis()->SetTitle("simCharge*recCharge"); ChargeCheckforSimTrackvalidHist->GetXaxis()->CenterTitle(1); ChargeCheckforSimTrackvalidHist->GetYaxis()->SetTitle("fraction %"); ChargeCheckforSimTrackvalidHist->GetYaxis()->CenterTitle(1); ChargeCheckforSimTrackvalidHist->Draw(); string ChargeCheckforSimTrackvalidCanvasName = FinalOutput + "ChargeCheckforSimTrackvalid" + OutputPlotNameFix; ChargeCheckforSimTrackvalidCanvas->SaveAs(ChargeCheckforSimTrackvalidCanvasName.c_str()); TCanvas* SeedNumberforSimTrackvalidCanvas = new TCanvas("SeedNumberforSimTrackvalidCanvas", "SeedNumberforSimTrackvalidCanvas", 800, 600); SeedNumberforSimTrackvalidCanvas->cd(); SeedNumberforSimTrackvalidHist->Draw(); string SeedNumberforSimTrackvalidCanvasName = FinalOutput + "SeedNumberforSimTrackvalid" + OutputPlotNameFix; SeedNumberforSimTrackvalidCanvas->SaveAs(SeedNumberforSimTrackvalidCanvasName.c_str()); TCanvas* SeedEfficiencyforSimTrackvalidCanvas = new TCanvas("SeedEfficiencyforSimTrackvalidCanvas", "SeedEfficiencyforSimTrackvalidCanvas", 800, 600); SeedEfficiencyforSimTrackvalidCanvas->cd(); SeedEfficiencyforSimTrackvalidHist->Draw(); string SeedEfficiencyforSimTrackvalidCanvasName = FinalOutput + "SeedEfficiencyforSimTrackvalid" + OutputPlotNameFix; SeedEfficiencyforSimTrackvalidCanvas->SaveAs(SeedEfficiencyforSimTrackvalidCanvasName.c_str()); TCanvas* SeedNumberforSimTrackinvalidCanvas = new TCanvas("SeedNumberforSimTrackinvalidCanvas", "SeedNumberforSimTrackinvalidCanvas", 800, 600); SeedNumberforSimTrackinvalidCanvas->cd(); SeedNumberforSimTrackinvalidHist->Draw(); string SeedNumberforSimTrackinvalidCanvasName = FinalOutput + "SeedNumberforSimTrackinvalid" + OutputPlotNameFix; SeedNumberforSimTrackinvalidCanvas->SaveAs(SeedNumberforSimTrackinvalidCanvasName.c_str()); TCanvas* SeedEfficiencyforSimTrackinvalidCanvas = new TCanvas("SeedEfficiencyforSimTrackinvalidCanvas", "SeedEfficiencyforSimTrackinvalidCanvas", 800, 600); SeedEfficiencyforSimTrackinvalidCanvas->cd(); SeedEfficiencyforSimTrackinvalidHist->Draw(); string SeedEfficiencyforSimTrackinvalidCanvasName = FinalOutput + "SeedEfficiencyforSimTrackinvalid" + OutputPlotNameFix; SeedEfficiencyforSimTrackinvalidCanvas->SaveAs(SeedEfficiencyforSimTrackinvalidCanvasName.c_str()); double SeedEfficiencyforSimTrackinvalid = 100. * SeedEfficiencyforSimTrackinvalidHist->GetMean(); double SeedEfficiencyforSimTrackvalid = 100. * SeedEfficiencyforSimTrackvalidHist->GetMean(); SeedEfficiencyHist->SetBinContent(1, SeedEfficiencyforSimTrackinvalid); SeedEfficiencyHist->SetBinContent(2, SeedEfficiencyforSimTrackvalid); SeedEfficiencyHist->GetXaxis()->SetBinLabel(1, "for invalid simTrack"); SeedEfficiencyHist->GetXaxis()->SetBinLabel(2, "for valid simTrack"); TCanvas* SeedEfficiencyCanvas = new TCanvas("SeedEfficiencyCanvas", "SeedEfficiencyCanvas", 800, 600); SeedEfficiencyCanvas->cd(); SeedEfficiencyHist->GetYaxis()->SetTitle("Efficiency %"); SeedEfficiencyHist->GetYaxis()->CenterTitle(1); SeedEfficiencyHist->SetMarkerStyle(3); SeedEfficiencyHist->SetMarkerSize(3); SeedEfficiencyHist->Draw("P"); string SeedEfficiencyCanvasName = FinalOutput + "SeedEfficiency" + OutputPlotNameFix; SeedEfficiencyCanvas->SaveAs(SeedEfficiencyCanvasName.c_str()); TCanvas* RecBendingPhi2PtCanvas = new TCanvas("RecBendingPhi2PtCanvas", "RecBendingPhi2PtCanvas", 800, 600); RecBendingPhi2PtCanvas->cd(); RecBendingPhi2PtHist->Draw(); string RecBendingPhi2PtCanvasName = FinalOutput + "RecBendingPhi2Pt" + OutputPlotNameFix; RecBendingPhi2PtCanvas->SaveAs(RecBendingPhi2PtCanvasName.c_str()); TCanvas* PtRatoofRecBendingPhiCanvas = new TCanvas("PtRatoofRecBendingPhiCanvas", "PtRatoofRecBendingPhiCanvas", 800, 600); PtRatoofRecBendingPhiCanvas->cd(); PtRatoofRecBendingPhiHist->Draw(); string PtRatoofRecBendingPhiCanvasName = FinalOutput + "PtRatoofRecBendingPhi" + OutputPlotNameFix; PtRatoofRecBendingPhiCanvas->SaveAs(PtRatoofRecBendingPhiCanvasName.c_str()); TCanvas* RecBendingLastPhiCanvas = new TCanvas("RecBendingLastPhiCanvas", "RecBendingLastPhiCanvas", 800, 600); RecBendingLastPhiCanvas->cd(); RecBendingLastPhiHist->Draw(); string RecBendingLastPhiCanvasName = FinalOutput + "RecBendingLastPhi" + OutputPlotNameFix; RecBendingLastPhiCanvas->SaveAs(RecBendingLastPhiCanvasName.c_str()); Int_t linsav = gStyle->GetLineWidth(); gStyle->SetLineWidth(2); TCanvas* SimReverseBendingCanvas = new TCanvas("SimReverseBendingCanvas", "SimReverseBendingCanvas", 800, 800); SimReverseBendingCanvas->cd(); TPad* SimReverseBendingPad = new TPad("SimReverseBendingPad", "SimReverseBendingPad", 0, 0, 1, 1); SimReverseBendingPad->Draw(); SimReverseBendingPad->cd(); SimReverseBendingPad->Range(-800, -800, 800, 800); unsigned int segmentNumber = SimReverseBending->GetEntries(); cout << "Number of segments: " << segmentNumber << endl; for(unsigned int j = 0; j < segmentNumber; j++) { ((TLine*)(SimReverseBending->At(j)))->Print(); ((TLine*)(SimReverseBending->At(j)))->Draw("SAME"); } string SimReverseBendingCanvasName = FinalOutput + "SimReverseBending" + OutputPlotNameFix; SimReverseBendingCanvas->SaveAs(SimReverseBendingCanvasName.c_str()); }
void makeTable2(int nbins = 100, const string label = "HFtowersPlusTrunc", const char * tag = "CentralityTable_HFplus100_PA2012B_v538x01_offline", bool isMC = false, int runNum = 1) { TH1D::SetDefaultSumw2(); //Intput files with HiTrees const int nTrees = 1; //string inFileNames[nTrees] = {"/tmp/azsigmon/HiForest_pPb_Hijing_NEWFIX_v2.root"}; //string inFileNames[nTrees] = {"/tmp/azsigmon/HiForest_pPb_Epos_336800.root"}; string inFileNames[nTrees] = {"/tmp/azsigmon/PA2013_HiForest_Express_r0_pilot_minbias_v0.root"}; TChain * t = new TChain("hiEvtAnalyzer/HiTree"); for (int i = 0; i<nTrees; i++) { t->Add(inFileNames[i].data()); } //Output files and tables TFile * outFile = new TFile("out/datatables_Glauber2012B_d20130121_v5.root","recreate"); //TFile * outFile = new TFile("out/tables_Ampt_d20121115_v3.root","update"); //TFile * outFile = new TFile("out/tables_Epos_d20121115_v3.root","update"); //TFile * outFile = new TFile("out/tables_Hijing_d20130119_v4.root","update"); TDirectory* dir = outFile->mkdir(tag); dir->cd(); TNtuple * nt = new TNtuple("nt","","value:bin:b:npart:ncoll:nhard"); CentralityBins * bins = new CentralityBins(Form("run%d",runNum), tag, nbins); bins->table_.reserve(nbins); ofstream txtfile("out/output.txt"); txtfile << "First input tree: " << inFileNames[0].data() << endl; //For data extra inputfile with Glauber centrality table and efficiency file TFile * effFile; TH1F * hEff; TFile * inputMCfile; CentralityBins* inputMCtable; if(!isMC){ //effFile = new TFile("out/efficiencies_Ampt.root","read"); //effFile = new TFile("out/efficiencies_Hijing.root","read"); effFile = new TFile("out/efficiencies_EposLHC_v2.root","read"); hEff = (TH1F*)effFile->Get(Form("%s/hEff",label.data())); //inputMCfile = new TFile("out/tables_Glauber2012_AmptResponse_d20121115_v3.root","read"); //inputMCfile = new TFile("out/tables_Glauber2012_HijingResponse_d20121115_v3.root","read"); inputMCfile = new TFile("out/tables_Glauber2012B_EposLHCResponse_d20130118_v4.root","read"); inputMCtable = (CentralityBins*)inputMCfile->Get(Form("CentralityTable_%s_SmearedGlauber_v4/run1",label.data())); //txtfile << "Using AMPT efficiency and AMPT smeared Glauber table" << endl << endl; txtfile << "Using EPOS efficiency and EPOS smeared Glauber table" << endl << endl; //txtfile << "Using HIJING efficiency and HIJING smeared Glauber table" << endl << endl; } //Setting up variables and branches double binboundaries[nbins+1]; vector<float> values; TH1F * hist; if(!isMC) hist = new TH1F("hist","",hEff->GetNbinsX(),hEff->GetBinLowEdge(1),hEff->GetBinLowEdge(hEff->GetNbinsX())); float vtxZ, b, npart, ncoll, nhard, hf, hfplus, hfpluseta4, hfminuseta4, hfminus, hfhit, ee, eb; int run, npix, npixtrks, ntrks; t->SetBranchAddress("vz",&vtxZ); t->SetBranchAddress("run",&run); if(isMC){ t->SetBranchAddress("b",&b); t->SetBranchAddress("Npart", &npart); t->SetBranchAddress("Ncoll", &ncoll); t->SetBranchAddress("Nhard", &nhard); } t->SetBranchAddress("hiHF", &hf); t->SetBranchAddress("hiHFplus", &hfplus); t->SetBranchAddress("hiHFplusEta4", &hfpluseta4); t->SetBranchAddress("hiHFminus", &hfminus); t->SetBranchAddress("hiHFminusEta4", &hfminuseta4); t->SetBranchAddress("hiHFhit", &hfhit); t->SetBranchAddress("hiEE", &ee); t->SetBranchAddress("hiEB", &eb); t->SetBranchAddress("hiNpix", &npix); t->SetBranchAddress("hiNpixelTracks", &npixtrks); t->SetBranchAddress("hiNtracks", &ntrks); //t->SetBranchAddress("hiNtracksOffline", &ntrks); bool binB = label.compare("b") == 0; bool binNpart = label.compare("Npart") == 0; bool binNcoll = label.compare("Ncoll") == 0; bool binNhard = label.compare("Nhard") == 0; bool binHF = label.compare("HFtowers") == 0; bool binHFplus = label.compare("HFtowersPlus") == 0; bool binHFminus = label.compare("HFtowersMinus") == 0; bool binHFplusTrunc = label.compare("HFtowersPlusTrunc") == 0; bool binHFminusTrunc = label.compare("HFtowersMinusTrunc") == 0; bool binNpix = label.compare("PixelHits") == 0; bool binNpixTrks = label.compare("PixelTracks") == 0; bool binNtrks = label.compare("Tracks") == 0; //Event loop unsigned int Nevents = t->GetEntries(); txtfile << "Number of events = " << Nevents << endl << endl; for(unsigned int iev = 0; iev < Nevents; iev++) { if(iev%10000 == 0) cout<<"Processing event: " << iev << endl; t->GetEntry(iev); //if(run!=runNum) continue; float parameter = -1; if(binB) parameter = b; if(binNpart) parameter = npart; if(binNcoll) parameter = ncoll; if(binNhard) parameter = nhard; if(binHF) parameter = hf; if(binHFplus) parameter = hfplus; if(binHFminus) parameter = hfminus; if(binHFplusTrunc) parameter = hfpluseta4; if(binHFminusTrunc) parameter = hfminuseta4; if(binNpix) parameter = npix; if(binNpixTrks) parameter = npixtrks; if(binNtrks) parameter = ntrks; values.push_back(parameter); if(!isMC) { hist->Fill(parameter); } } //Sorting the centrality variable vector if(binB) sort(values.begin(),values.end(),descend); else sort(values.begin(),values.end()); //Finding the bin boundaries txtfile << "-------------------------------------" << endl; txtfile << label.data() << " based cuts are: " << endl; txtfile << "("; int size = values.size(); binboundaries[nbins] = values[size-1]; if(isMC) { for(int i = 0; i < nbins; i++) { int entry = (int)(i*(size/nbins)); if(entry < 0 || i == 0) binboundaries[i] = 0; else binboundaries[i] = values[entry]; } } else { TH1F * corr = (TH1F*)hist->Clone("corr"); //TCanvas *c1 = new TCanvas(); //c1->SetLogy(); //corr->DrawCopy("hist"); for (int j=1; j<corr->GetNbinsX(); j++) { if (hEff->GetBinContent(j) != 0) { corr->SetBinContent(j,corr->GetBinContent(j)/hEff->GetBinContent(j)); corr->SetBinError(j,corr->GetBinError(j)/hEff->GetBinContent(j)); } } //corr->SetLineColor(2); //corr->DrawCopy("hist same"); //cout << "total integral = " << corr->Integral(); float prev = 0; binboundaries[0] = 0; int j = 1; for (int i = 1; i < corr->GetNbinsX(); i++) { if(j>=nbins) continue; float a = corr->Integral(1,i,""); a = a/corr->Integral(); //if(i<100) cout << i << " bin in x fraction of total integral = " << a << " j = " << j << endl; if (a > (float)j/nbins && prev < (float)j/nbins) { binboundaries[j] = corr->GetBinLowEdge(i+1); j++; } prev = a; } } for(int i = 0; i < nbins; i++) { if(binboundaries[i] < 0) binboundaries[i] = 0; txtfile << binboundaries[i] << ", "; } txtfile << binboundaries[nbins] << ")" << endl << "-------------------------------------" << endl; //***Determining Glauber results for MC and filling the table*** if(isMC) { dir->cd(); TH2D* hNpart = new TH2D("hNpart","",nbins,binboundaries,40,0,40); TH2D* hNcoll = new TH2D("hNcoll","",nbins,binboundaries,40,0,40); TH2D* hNhard = new TH2D("hNhard","",nbins,binboundaries,50,0,50); TH2D* hb = new TH2D("hb","",nbins,binboundaries,600,0,30); for(unsigned int iev = 0; iev < Nevents; iev++) { if( iev % 5000 == 0 ) cout<<"Processing event : " << iev << endl; t->GetEntry(iev); float parameter = -1; if(binB) parameter = b; if(binNpart) parameter = npart; if(binNcoll) parameter = ncoll; if(binNhard) parameter = nhard; if(binHF) parameter = hf; if(binHFplus) parameter = hfplus; if(binHFminus) parameter = hfminus; if(binHFplusTrunc) parameter = hfpluseta4; if(binHFminusTrunc) parameter = hfminuseta4; if(binNpix) parameter = npix; if(binNpixTrks) parameter = npixtrks; if(binNtrks) parameter = ntrks; hNpart->Fill(parameter,npart); hNcoll->Fill(parameter,ncoll); hNhard->Fill(parameter,nhard); hb->Fill(parameter,b); int bin = hNpart->GetXaxis()->FindBin(parameter) - 1; if(bin < 0) bin = 0; if(bin >= nbins) bin = nbins - 1; nt->Fill(parameter,bin,b,npart,ncoll,nhard); } TF1* fGaus = new TF1("fb","gaus(0)",0,2); fitSlices(hNpart,fGaus); fitSlices(hNcoll,fGaus); fitSlices(hNhard,fGaus); fitSlices(hb,fGaus); TH1D* hNpartMean = (TH1D*)gDirectory->Get("hNpart_1"); TH1D* hNpartSigma = (TH1D*)gDirectory->Get("hNpart_2"); TH1D* hNcollMean = (TH1D*)gDirectory->Get("hNcoll_1"); TH1D* hNcollSigma = (TH1D*)gDirectory->Get("hNcoll_2"); TH1D* hNhardMean = (TH1D*)gDirectory->Get("hNhard_1"); TH1D* hNhardSigma = (TH1D*)gDirectory->Get("hNhard_2"); TH1D* hbMean = (TH1D*)gDirectory->Get("hb_1"); TH1D* hbSigma = (TH1D*)gDirectory->Get("hb_2"); txtfile<<"-------------------------------------"<<endl; txtfile<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl; for(int i = 0; i < nbins; i++){ int ii = nbins-i; bins->table_[i].n_part_mean = hNpartMean->GetBinContent(ii); bins->table_[i].n_part_var = hNpartSigma->GetBinContent(ii); bins->table_[i].n_coll_mean = hNcollMean->GetBinContent(ii); bins->table_[i].n_coll_var = hNcollSigma->GetBinContent(ii); bins->table_[i].b_mean = hbMean->GetBinContent(ii); bins->table_[i].b_var = hbSigma->GetBinContent(ii); bins->table_[i].n_hard_mean = hNhardMean->GetBinContent(ii); bins->table_[i].n_hard_var = hNhardSigma->GetBinContent(ii); bins->table_[i].bin_edge = binboundaries[ii-1]; txtfile << i << " " << hNpartMean->GetBinContent(ii) << " " << hNpartSigma->GetBinContent(ii) << " " << hNcollMean->GetBinContent(ii) << " " << hNcollSigma->GetBinContent(ii) << " " << hbMean->GetBinContent(ii) << " " <<hbSigma->GetBinContent(ii) << " " << binboundaries[ii-1] << " " <<endl; } txtfile<<"-------------------------------------"<<endl; } //***end of MC part*** else { //***Data table with inputMCtable*** txtfile<<"-------------------------------------"<<endl; txtfile<<"# Bin NpartMean NpartSigma NcollMean NcollSigma bMean bSigma BinEdge"<<endl; for(int i = 0; i < nbins; i++){ int ii = nbins-i; bins->table_[i].n_part_mean = inputMCtable->NpartMeanOfBin(i); bins->table_[i].n_part_var = inputMCtable->NpartSigmaOfBin(i); bins->table_[i].n_coll_mean = inputMCtable->NcollMeanOfBin(i); bins->table_[i].n_coll_var = inputMCtable->NcollSigmaOfBin(i); bins->table_[i].b_mean = inputMCtable->bMeanOfBin(i); bins->table_[i].b_var = inputMCtable->bSigmaOfBin(i); bins->table_[i].n_hard_mean = inputMCtable->NhardMeanOfBin(i); bins->table_[i].n_hard_var = inputMCtable->NhardSigmaOfBin(i); bins->table_[i].ecc2_mean = inputMCtable->eccentricityMeanOfBin(i); bins->table_[i].ecc2_var = inputMCtable->eccentricitySigmaOfBin(i); bins->table_[i].bin_edge = binboundaries[ii-1]; txtfile << i << " " << bins->table_[i].n_part_mean << " " << bins->table_[i].n_part_var << " " << bins->table_[i].n_coll_mean << " " << bins->table_[i].n_coll_var << " " <<bins->table_[i].b_mean << " " << bins->table_[i].b_var << " " << bins->table_[i].n_hard_mean << " " << bins->table_[i].n_hard_var << " " << bins->table_[i].bin_edge << " " << endl; } txtfile<<"-------------------------------------"<<endl; } //***end of Data part*** outFile->cd(); dir->cd(); bins->Write(); nt->Write(); bins->Delete(); outFile->Write(); txtfile.close(); }