void flavor_ana(int doMC=1, const char * JecType = "abs", const char * inFile0Name="../outputs/jetSkimRelValQCD_Pt_80_120_sw354-JEC_Summer09_7TeV_ReReco332.root", const char * inFile1Name="djtree_JEC_Summer09_7TeV_ReReco332.root") { // Define Inputs cout << "======= Inputs: ========" << endl; //cout << "Inclusive jets: " << inFile0Name << endl; //cout << "Dijets: " << inFile1Name << endl; //TFile * inFile0 = new TFile(inFile0Name); //TFile * inFile1 = new TFile(inFile1Name); TFile * inFile0 = new TFile("../outputs/jetSkimRelValQCD_Pt_80_120_sw354-JEC_Summer09_7TeV_ReReco332.root"); TFile * inFile1 = new TFile(Form("djtree_JEC_Summer09_7TeV_ReReco332_%s.root",JecType)); TTree * Events; inFile0->GetObject("Events",Events); TTree * djtree; inFile1->GetObject("djtree",djtree); aliases(Events); // === Dijets === cout << endl << "================ dijets ==============" << endl; Int_t numPreSelEvtl = djtree->GetEntries("vz>-99"); cout << "Events:" << endl; cout << "- with none-fake vtx: " << numPreSelEvtl << endl; // - selection - TCut evtSelDj("nlpet>80 && nlpet<120 && alpet>80 && jdphi>2.8"); TCut evtSelDj2("nlpet>80 && nlpet<120 && alpet>80 && jdphi>3.0"); Int_t numSelEvt1 = djtree->GetEntries(evtSelDj); cout << "- Passing sel: " << numSelEvt1 << endl; Int_t numSelEvt2 = djtree->GetEntries(evtSelDj2); cout << "- Passing diphi sel: " << numSelEvt2 << endl; // === flavor studies === TProfile * hNrJFlav = new TProfile("hNrJFlav","flavor",10,85,110); hNrJFlav->SetMarkerColor(kRed); hNrJFlav->SetLineColor(kRed); hNrJFlav->SetMarkerStyle(kOpenCircle); hNrJFlav->SetMinimum(0.); hNrJFlav->SetMaximum(0.7); hNrJFlav->SetTitle(";p_{T}^{gen jet};q jet fraction"); TProfile * hAwJFlav = (TProfile*)hNrJFlav->Clone("hAwJFlav"); hAwJFlav->SetMarkerColor(kBlue); hAwJFlav->SetLineColor(kBlue); TCanvas * cJFlav = new TCanvas("cJFlav","cJFlav",500,500); TCut matParton("nlpstat>-99&&alpstat>-99"); djtree->Draw("(abs(nlpid)<6):nlpet>>hNrJFlav",evtSelDj&&matParton,"prof"); djtree->Draw("(abs(alpid)<6):alpet>>hAwJFlav",evtSelDj&&matParton,"prof same"); TLegend *leg2 = new TLegend(0.605,0.216,0.905,0.369,NULL,"brNDC"); leg2->SetFillColor(0); leg2->SetBorderSize(0); leg2->SetTextSize(0.03); leg2->AddEntry(hNrJFlav,"Di-Jets, Near Jet","p"); leg2->AddEntry(hAwJFlav,"Di-Jets, Away Jet","p"); leg2->Draw(); cJFlav->Print("plots/cDJFlavor.gif"); }
// ---------------------------------------------------------------------- void nmod(const int offset = 400) { c0.Clear(); c0.Divide(2,8); tl->SetTextSize(0.2); tl->SetNDC(kTRUE); tl->SetTextAngle(90); gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gROOT->ForceStyle(); double min(-1), max(-1); if (offset == 600) { min = 120; max = 200; } TProfile *p; for (int i = 0; i < 16; ++i) { c0.cd(i+1); p = (TProfile*)gFile->Get(Form("p%i", offset+i)); if (min > -1) { p->SetMinimum(min); p->SetMaximum(max); } p->Draw(); tl->DrawLatex(0.2, 0.11, Form("Chip %i", i)); } if (offset == 400) c0.SaveAs("ped-nmod.ps"); if (offset == 500) c0.SaveAs("gain-nmod.ps"); if (offset == 600) c0.SaveAs("noise-nmod.ps"); if (offset == 700) c0.SaveAs("pedgain-nmod.ps"); }
void makePlots (string configFilePath){ if (( nHistList % inputRootFile.size() == 0 )) { for (int i=0; i<numHistos; i++) { TCanvas *c = new TCanvas(theHistNameStrings.at(i).c_str(), "", 81,58,500,602); TH1* h_mc; // histograms for MC TH1* h_mc_clone; // histograms for MC TH1* h_data; // histogram to store data points TH1* h_data_clone; TLegend *legend = new TLegend(0.2, 0.85-.035*inputLegend.size(), 0.5, 0.90,NULL,"brNDC"); int whichHisto = 0; for (int j=1;j<inputRootFile.size();j++) { whichHisto=j*numHistos; int a = 0; bool foundHisto = false; if (theHistNameStrings.at(i) == theHistNameStrings.at(i+whichHisto)) { foundHisto=true; a=i; } else { for (a = 0; a < numHistos; a++) { if (theHistNameStrings.at(i) == theHistNameStrings.at(a+whichHisto)) { foundHisto = true; break; } } } //----------------------------------------------------------- string hist2name = listHistos->At(a+whichHisto)->GetName(); if (foundHisto == true) { h_data = (TH1*)listHistos->At(i); h_data->SetMarkerStyle(inputMarkerStyle.at(0)); h_data = SetStyleh(h_data); h_data->Sumw2(); int thelineStyle = inputSetLineStyle.at(j); int thelineWidth = inputSetLineWidth.at(j); int setcolor = inputColor.at(j); int marker = inputMarkerStyle.at(j); h_data->SetMarkerColor(inputColor.at(0)); h_data->SetLineColor(inputColor.at(0)); if (j == 1) { if ( h_data->IsA()->InheritsFrom( "TH2" ) ) { //n.b. that ProfileX will do nothing if the //name you choose is alreayd taken! so each //profileX needs a unique name TString profileName = TString::Format("%s_data_pfx",h_data->GetName()); TProfile *dataProf = ((TH2*)h_data)->ProfileX(profileName.Data()); dataProf->SetMinimum(h_data->GetMinimum()); //min/max values were stored in the original hist dataProf->SetMaximum(h_data->GetMaximum()); dataProf->Draw(""); //profileX cretaes a clone, so no need to //clone again here. Need to set the hist //name so root doesn't complain TString cloneName = TString::Format("%s_data_pfx_clone",h_data->GetName()); TString cloneName2 = TString::Format("%s_data_pfx_clone_px",h_data->GetName()); h_data_clone = ((TH2*)h_data)->ProfileX(cloneName.Data())->ProjectionX(cloneName2.Data()); } else { //1d case Float_t ymaxc = gPad->GetUymax(); //h_data->SetMaximum(ymaxc+0.15*ymaxc); h_data->Draw("ep1"); h_data_clone = (TH1*)h_data->Clone(); } //h_data->SetLineColor(1); h_data->SetLineStyle(thelineStyle); h_data->SetLineWidth(thelineWidth); float rms_data = h_data->GetRMS(); float mean_data = h_data->GetMean(); std::stringstream legend_data; legend_data.str(""); legend_data << inputLegend.at(0).c_str() << ": mean=" << setprecision(3) <<mean_data <<", rms=" << setprecision(3) <<rms_data<< endl; legend->AddEntry(h_data,legend_data.str().c_str(), "lep"); } h_mc = (TH1*)listHistos->At(a+whichHisto); h_mc = SetStyleh(h_mc); h_mc->SetName(hist2name.c_str()); //cout<<"NAME "<<h_mc->GetName()<<endl; // Style string processlegend = (inputLegend.at(j)).c_str(); h_mc->SetLineStyle(thelineStyle); h_mc->SetLineWidth(thelineWidth); h_mc->SetLineColor(setcolor); h_mc->SetMarkerStyle(marker); h_mc->SetMarkerColor(setcolor); string processlegend = (inputLegend.at(j)).c_str(); if ( h_mc->IsA()->InheritsFrom( "TH2" ) ) { TString profileName = TString::Format("%s_mc_pfx", h_mc->GetName()); ((TH2*)h_mc)->ProfileX(profileName.Data())->Draw("SAME"); //profileX cretaes a clone, so no need to //clone again here. Need to set the hist //name so root doesn't complain TString cloneName = TString::Format("%s_mc_pfx_clone",h_mc->GetName()); TString cloneName2 = TString::Format("%s_mc_pfx_clone_px",h_mc->GetName()); h_mc_clone = ((TH2*)h_mc)->ProfileX(cloneName.Data())->ProjectionX(cloneName2.Data()); } else { //1d case Float_t ymaxc = gPad->GetUymax(); h_mc->SetMaximum(ymaxc+0.15*ymaxc); h_mc->Draw("epsame"); h_mc_clone = (TH1*)h_mc->Clone(); } h_mc_clone->SetMarkerStyle(marker); h_mc_clone->SetMarkerColor(setcolor); float rms_mc = h_mc->GetRMS(); float mean_mc = h_mc->GetMean(); std::stringstream legend_mc; legend_mc.str(""); legend_mc << processlegend.c_str() << " - "<< "mean: " << setprecision(3) <<mean_mc <<" , rms: " << setprecision(3) <<rms_mc<< endl; legend->AddEntry(h_mc, legend_mc.str().c_str(), "lep"); }// close if (foundHisto) legend->SetTextFont(42); legend->SetTextSize(.04); legend->SetMargin(0.15); legend->SetLineColor(1); legend->SetLineStyle(1); legend->SetLineWidth(1); legend->SetFillColor(0); legend->SetFillStyle(0); legend->SetBorderSize(0); legend->SetFillColor(kWhite); legend->Draw(); c->cd(); if (j == 1) { float startxbin = h_data_clone->GetXaxis()->GetBinWidth(h_data_clone->GetXaxis()->GetFirst()) * (h_data_clone->GetXaxis()->GetFirst() - 1); float lastxbin = h_data_clone->GetXaxis()->GetBinCenter(h_data_clone->GetXaxis()->GetNbins()); double x1 = 0; double x2 = lastxbin + h_data_clone->GetXaxis()->GetBinWidth(h_data_clone->GetXaxis()->GetNbins())/2.; if (h_data_clone->GetXaxis()->GetBinCenter(0) <= 0) x1 = h_data_clone->GetXaxis()->GetBinCenter(0) + h_data_clone->GetXaxis()->GetBinWidth(0)/2. + startxbin; else x1 = h_data_clone->GetXaxis()->GetBinCenter(0) - h_data_clone->GetXaxis()->GetBinWidth(0)/2. - startxbin; } } // close for loop inputRootFile TFile *hfile = (TFile*)gROOT->FindObject(HistosOutputRootFile.c_str()); if (hfile) {hfile->Close();} hfile = new TFile(HistosOutputRootFile.c_str(),"UPDATE"); for (int o = 0; o < inputHistoName.size(); o++) { if ( c->GetName() == inputHistoName.at(o) ) { string save = configFilePath+"/"+inputHistoName.at(o)+".pdf"; c->SaveAs(save.c_str()); c->Write(); break; } } hfile->Close(); c->Close(); } // close foor loop numHistos } // close if numHistos % inputRootFile.size() == 0 } // close makePlots function
void makePlot(char* canv) { t->SetBranchAddress("LM_PX1", &intree.LM_PX1); t->SetBranchAddress("LM_PX2", &intree.LM_PX2); t->SetBranchAddress("LM_PY1", &intree.LM_PY1); t->SetBranchAddress("LM_PY2", &intree.LM_PY2); t->SetBranchAddress("LM_P2_Integral", &intree.LM_P2_Integral); t->SetBranchAddress("time", &intree.timeline); t->Print(); if(entries<=0) entries = t->GetEntries(); char title[100]=0; sprintf(title,"%s runs 1100-1107",canv); TProfile *prof = new TProfile(title,title,24,0,entries); TProfile *prof1 = new TProfile(title,title,24,0,entries); TProfile *prof2 = new TProfile(title,title,24,0,entries); /************************************** * read entries ************************************** */ Double_t *ratio = new Double_t[entries]; Double_t *parmean = new Double_t[entries]; Double_t *p1 = new Double_t[entries]; Double_t *p2 = new Double_t[entries]; for (int j = 0; j < entries; ++j){ gSystem->Sleep (sleep); t->GetEntry(j); ratio[j] = intree.LM_PY1/intree.LM_PY2; p1[j] = intree.LM_PY1; p2[j] = intree.LM_PY2; //cout<<"entry "<<j<<" peak2 "<<intree.LM_PY2<<endl; } Double_t mean = TMath::Mean(entries,ratio); Double_t mean1 = TMath::Mean(entries,p1); Double_t mean2 = TMath::Mean(entries,p2); for (int j = 0; j < entries; ++j){ prof->Fill(j,(ratio[j]/mean-1)*100); prof1->Fill(j,(p1[j]/mean1-1)*100); prof2->Fill(j,(p2[j]/mean2-1)*100); } TCanvas *c1 = new TCanvas(canv,"frascatirun",900,700); c1->cd(); char axisXname[100]; sprintf(axisXname,"Time (Entries) (total: %i)",entries); prof->SetXTitle(axisXname); prof->SetYTitle("Variation (%)"); prof->SetMaximum(1); prof->SetMinimum(-1); prof->SetMarkerColor(4); prof->SetMarkerSize(1); prof->SetMarkerStyle(8); prof->SetStats(kFALSE); prof->Draw(); prof1->SetMarkerColor(5); prof1->SetMarkerSize(1); prof1->SetMarkerStyle(6); prof1->Draw("same"); prof2->SetMarkerColor(1); prof2->SetMarkerSize(1); prof2->SetMarkerStyle(7); prof2->Draw("same"); /* TLegend leg = new TLegend(0.1,0.7,0.48,0.9); leg->SetHeader("The Legend Title"); leg->AddEntry(h1,"Histogram filled with random numbers","f"); leg->AddEntry("f1","Function abs(#frac{sin(x)}{x})","l"); leg->AddEntry("gr","Graph with error bars","lep"); leg->Draw("same"); */ }