//________________________________________________________ void GFHistManager::ColourStatsBoxes(GFHistArray *hists) const { // colours stats boxes like hists' line colors and moves the next to each other if (!hists) return; Double_t x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2; for (Int_t iH = 0; iH < hists->GetEntriesFast(); ++iH) { TH1 *h = hists->At(iH); if (!h) continue; TObject *statObj = h->GetListOfFunctions()->FindObject("stats"); if (statObj && statObj->InheritsFrom(TPaveStats::Class())) { TPaveStats *stats = static_cast<TPaveStats*>(statObj); stats->SetLineColor(hists->At(iH)->GetLineColor()); stats->SetTextColor(hists->At(iH)->GetLineColor()); stats->SetX1NDC(x1); stats->SetX2NDC(x2); stats->SetY1NDC(y1); stats->SetY2NDC(y2); y2 = y1 - 0.005; // shift down 2 y1 = y2 - (fStatsY2 - fStatsY1); // shift down 1 if (y1 < 0.) { y1 = fStatsY1; y2 = fStatsY2; // restart y-positions x2 = x1 - 0.005; // shift left 2 x1 = x2 - (fStatsX2 - fStatsX1); // shift left 1 if (x1 < 0.) { // give up, start again: x1 = fStatsX1, x2 = fStatsX2, y1 = fStatsY1, y2 = fStatsY2; } } } else if (gStyle->GetOptStat() != 0) { // failure in case changed in list via TExec.... this->Warning("ColourStatsBoxes", "No stats found for %s", hists->At(iH)->GetName()); } } }
// Resize any histograms (they all inherit from h1) stat box. Uses NDC coordinates (e.g. 0.65, 0.5) bool resizeStatBox( TCanvas *c1, TH1* h1, float x1, float y1, float x2=-1, float y2=-1, TString newname = "", int color = -1, TString oldname = "", int iDebug = 0 ) { if( !c1 || !h1 ) {cerr<<"Null pointer given to resizeStatBox!"<<endl; return 0;} c1->Update(); if( oldname.Length() <= 0 ) oldname = "stats"; if( iDebug > 20 ) print_list_of_functions( *h1 ); TPaveStats *stats = (TPaveStats*) h1->FindObject( oldname ); if( iDebug ) cout<<"Found old name (\""<<oldname<<"\"? "<<( stats != 0 )<<endl; if( (!stats) && newname.Length() > 0 ){ // maybe it was already renamed stats = (TPaveStats*) h1->FindObject( newname ); if( iDebug ) cout<<"Found new name (\""<<newname<<"\"? "<<(stats != 0)<<endl; } if( !stats ) {cerr<<"Can't find stat box"<<endl; return 0;} stats->SetX1NDC( x1 ); stats->SetY1NDC( y1 ); if( x2 >= 0 ) stats->SetX2NDC( x2 ); if( y2 >= 0 ) stats->SetY2NDC( y2 ); if( newname.Length() > 0 ) { stats->SetName( newname ); if( iDebug ) cout<<"SetName to "<<newname<<endl; } if( color != -1 ) stats->SetTextColor (color); stats->Draw(); // maybe, just maybe, this will finally make them appear every time, even with draw "same" return 1; }
void repositionStatbox(std::string name) { // Reposition and resize statbox TH2F *h = (TH2F*)gDirectory->GetList()->FindObject(name.c_str()); TPaveStats *st = (TPaveStats*)h->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(0.63); st->SetY1NDC(0.72); st->SetX2NDC(0.99); st->SetY2NDC(0.99); st->Draw(); }
void SetStatPad(TH1* hst,float x1,float x2,float y1,float y2) { TPaveStats* pad = GetStatPad(hst); if (!pad) return; pad->SetX1NDC( x1 ); pad->SetX2NDC( x2 ); pad->SetY1NDC( y1 ); pad->SetY2NDC( y2 ); // gPad->Modified(); }
// --------------------------------------------------------------------------------------------- // The SLAC version bool relocateStatBox (float x1, float y1, float x2=-1, float y2=-1, TString newname = "") { TPaveStats *st = (TPaveStats*)gPad->GetPrimitive("stats"); if (0 == st) {cerr<<"Can't find stat box in pad"<<endl; return 0;} if (newname.Length() > 0) st->SetName(newname); st->SetX1NDC(x1); if (x2 != -1) st->SetX2NDC(x2); st->SetY1NDC(y1); if (y2 != -1) st->SetY2NDC(y2); st->Draw(); return 1; }
bool resizeStatBox (TCanvas *c1, TGraph* g1, float x1, float y1, float x2=-1, float y2=-1) { if (!c1 || !g1) {cerr<<"Null pointer given to resizeStatBox!"<<endl; return 0;} c1->Update(); TPaveStats *stats = (TPaveStats*) g1->FindObject("stats"); if (!stats) {cerr<<"Can't find stat box"<<endl; return 0;} stats->SetX1NDC(x1); stats->SetY1NDC(y1); if (x2 >= 0) stats->SetX2NDC(x2); if (y2 >= 0) stats->SetY2NDC(y2); return 1; }
// überladen: Statbox-Größen manuell eingeben void drawStatBox(int& step, TH1D* histo, int color = -1, double statboxHeight = 0.1, double statboxSpacing = 0.15){ TPaveStats* statBox = dynamic_cast<TPaveStats*>( histo->GetListOfFunctions()->FindObject("stats") ); if(color == -1) color = step+1; statBox->SetX1NDC(0.80); statBox->SetX2NDC(0.99); statBox->SetY2NDC(0.95-step*statboxSpacing); statBox->SetY1NDC(0.95-step*statboxSpacing-statboxHeight); statBox->SetTextColor(color); statBox->Draw(); step++; }
TPaveStats* SetStPadPos(TH1* hst,float x1,float x2,float y1,float y2, Int_t stl, Int_t col) { TPaveStats* pad = GetStPad(hst); if (!pad) return 0; pad->SetX1NDC( x1 ); pad->SetX2NDC( x2 ); pad->SetY1NDC( y1 ); pad->SetY2NDC( y2 ); if (stl>=0) pad->SetFillStyle(stl); if (col>=0) pad->SetTextColor(col); pad->SetFillColor(0); // gPad->Modified(); return pad; }
// Statistik-Boxen an den Rand der Canvas malen, automatische Größenanpassung void drawStatBox(TH1D* histo, int& step, int nSteps, double FrameSize, int color = -1, int style = 0){ TPaveStats* statBox = dynamic_cast<TPaveStats*>( histo->GetListOfFunctions()->FindObject("stats") ); double statboxSpacing = FrameSize / nSteps; // gleichmaessiges Aufteilen der Statboxes ueber den Rand double statboxHeight = 0.1 * statboxSpacing * (9.+1./nSteps);; // 1/10 Abstand, (9/10+Abstand/nSteps) Statbox if(color == -1) color = step+1; statBox->SetX1NDC(0.80); statBox->SetX2NDC(0.99); statBox->SetY2NDC(0.95-step*statboxSpacing); statBox->SetY1NDC(0.95-step*statboxSpacing-statboxHeight); statBox->SetFillColor(color); statBox->SetFillStyle(style); statBox->Draw(); step++; }
//========================================== //========================================== void plotPair(TH1F *h1,TH1F *h0 ) { h1->Draw(); // edit fonts/sizes TAxis *ax =h1->GetYaxis(); float ss=ax->GetTitleSize(); //printf("ss=%f\n",ss); ax->SetTitleSize(2*ss); ax->SetTitleOffset(0.5); ax =h1->GetXaxis(); ax->SetTitleSize(1.5*ss); ax->SetLabelSize(1.5*ss); ax->SetTitleOffset(0.7); // edit fonts/sizes DONE gPad->Update(); //scale hint1 to the pad coordinates Float_t rightmax = 1.1*h0->GetMaximum(); Float_t scale = gPad->GetUymax()/rightmax; h0->Scale(scale); h0->Draw("same"); //draw an axis on the right side TGaxis *axis = new TGaxis(gPad->GetUxmax(),gPad->GetUymin(), gPad->GetUxmax(), gPad->GetUymax(),0,rightmax,510,"-R"); int col=h0->GetLineColor(); axis->SetLineColor(col); axis->SetTextColor(col); axis->SetLabelColor(col); axis ->SetTitle("LCP yield"); axis->SetTitleSize(2*ss); axis->SetTitleOffset(.5); axis->Draw(); TPaveStats *st =( TPaveStats *)gPad->GetPrimitive("stats"); st->SetX1NDC(0.35); st->SetX2NDC(0.5); st->SetY1NDC(0.7); st->SetY2NDC(1.); }
void n_photons(){ gStyle->SetOptStat(2210); TString filename = TString("/Users/scook/code/MuSIC/simulation/") + TString("MuSIC_5_detector_sim/MuSIC5/output/output_from_hep_batch/") + TString("optical_processes.root"); TFile* file = new TFile(filename.Data(), "READ"); TTree* mppc = (TTree*) file->Get("mppc"); TH1F* hist = new TH1F("h", "Number of detected photons", 1000, 0, 1000); hist->GetXaxis()->SetTitle("Number of photons"); hist->GetYaxis()->SetTitle("Count"); n_photons_t branch; mppc->SetBranchAddress("mppc_x", branch.x); mppc->SetBranchAddress("mppc_y", branch.y); mppc->SetBranchAddress("mppc_z", branch.z); mppc->SetBranchAddress("mppc_hits", &branch.nhits); for(int entry = 0; entry < mppc->GetEntries(); ++entry) { mppc->GetEntry(entry); int count = 0; for(Int_t hit = 0; hit < branch.nhits; ++hit) { bool correct_z = 3635.0 < branch.z[hit] && branch.z[hit] < 3640.0; bool correct_y = 97.0 < branch.y[hit] && branch.y[hit] < 102.0; if(correct_z && correct_y) { ++count; } } if (count > 0) hist->Fill(count); } TCanvas* can = new TCanvas("c1","c1",1436,856); can->SetLogx(); can->SetLogy(); hist->Draw(); can->Update(); TPaveStats* stats = (TPaveStats*) hist->FindObject("stats"); stats->SetX1NDC(0.65); stats->SetX2NDC(0.90); stats->SetY1NDC(0.70); stats->SetY2NDC(0.90); can->Update(); can->SaveAs("n_photons.png"); can->SaveAs("n_photons.svg"); }
int main(int argc, char** argv){ if(argc!=2){ std::cerr << "### Usage like ... \n ./gaus2d 10000(imax)" << std::endl ; return EXIT_FAILURE ; } else{/* DO NOT ANYTHING */} TApplication app( "app", &argc, argv ); double x ; double y ; int imax = atoi(argv[1]) ; TString title("2D Gaussian") ; TString titleimax(argv[1]) ; title += titleimax ; TCanvas *c1 = new TCanvas("c1", "c1", 600, 600) ; gStyle->SetOptStat("enRM") ; c1->SetTicks(1,1) ; c1->SetGrid(1,1) ; c1->SetRightMargin(0.15) ; TH2D *hist = new TH2D("hist",title,100, -5., 5., 100, -5., 5.) ; TF2 *gausfunc = new TF2("gausfunc","[0]*TMath::Exp( - TMath::Sqrt( TMath::Power((x-[1])/[2],2)/2. + TMath::Power((y-[3])/[4],2)/2. ))", -5., 5., -5., 5.) ; gausfunc->SetParameters(1., 0., 0.5, 0., 0.5) ; gausfunc->SetNpx(300) ; gausfunc->SetNpy(300) ; gRandom->SetSeed(unsigned(time(NULL))) ; for(int i =0 ; i< imax ; i++){ gausfunc->GetRandom2(x,y) ; hist->Fill(x,y) ; } hist->Draw("colz") ; gPad->Update(); TPaveStats *st = (TPaveStats*)hist->FindObject("stats") ; st->SetX1NDC(0.60) ; st->SetX2NDC(0.85) ; st->SetY1NDC(0.70) ; st->SetY2NDC(0.90) ; c1->SaveAs("gaus2dc1.eps") ; app.Run() ; delete c1 ; delete hist ; delete gausfunc ; return EXIT_SUCCESS ; }
void MakeNiceStatBox(TH1* histo){ TObject *statObj; TPaveStats *stats; statObj = histo->GetListOfFunctions()->FindObject("stats"); stats= static_cast<TPaveStats*>(statObj); stats->SetFillColor(10); stats->SetLineWidth(1); stats->SetShadowColor(0); stats->SetTextFont(42); stats->SetTextSize(0.05); //stats->SetLineColor(LineColors); //stats->SetTextColor(LineColors); stats->SetX1NDC(0.615); stats->SetY1NDC(0.747); stats->SetX2NDC(0.979); stats->SetY2NDC(0.986); }
pqPoint HitCollection::drawHits(bool fit, bool draw, bool rz) { unsigned int hits_n = hitCollection.size(); TGraph hits_h(hits_n); hits_h.SetTitle("Hits"); for (unsigned int hit_i = 0; hit_i < hits_n; hit_i++) { hits_h.SetPoint(hit_i, hitCollection[hit_i].x, hitCollection[hit_i].y); } TCanvas c("c", "c", 600, 600); hits_h.GetXaxis()->SetLimits(-1.1*zmax, 1.1*zmax); hits_h.GetYaxis()->SetRangeUser(0., 1.1*rmax); hits_h.GetXaxis()->SetTitle("x[cm]"); hits_h.GetYaxis()->SetTitle("y[cm]"); hits_h.Draw("A*"); pqPoint pqpoint; if (fit) { gStyle->SetOptFit(10001); string pol1("[1]*x + [0]"); if (rz) pol1 = "1./[1]*x - [0]/[1]"; TF1 * fitfun = new TF1("fitfun", pol1.c_str()); fitfun->SetParNames("q","p"); fitfun->SetParameters(1., 1.); hits_h.Fit(fitfun, draw ? "" : "q"); c.Update(); pqpoint.p = fitfun->GetParameter("p"); // pqpoint.p = atan(fun->GetParameter("p")); pqpoint.q = fitfun->GetParameter("q"); pqpoint.w = 1.; } else pqpoint.w = -1.; TPaveStats *st = (TPaveStats*)hits_h.FindObject("stats"); st->SetY1NDC(0.72); st->SetY2NDC(0.87); st->SetX1NDC(0.13); st->SetX2NDC(0.28); if (draw) c.Print(Form("figs/hits_%s.pdf", name.c_str())); return pqpoint; }
int makeInvMassHistosNoBGKK(){ //Set global style stuff gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetCanvasColor(kWhite); gStyle->SetCanvasBorderMode(0); gStyle->SetPadBorderMode(0); gStyle->SetTitleBorderSize(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1); gStyle->SetErrorX(0); gStyle->SetTitleW(0.9); gStyle->SetTitleSize(0.05, "xyz"); gStyle->SetTitleSize(0.06, "h"); int NUM_PT_BINS = 20; int NUM_MASS_BINS = 1000; double MASS_LOW = 0.0; double MASS_HIGH = 2.0; string particles [8]; particles[0] = "K*^{+} + K*^{0}"; particles[1] = "K*^{-} + #bar{K}*^{0}"; particles[2] = "K*^{+}"; particles[3] = "K*^{-}"; particles[4] = "K*^{0}"; particles[5] = "#bar{K}*^{0}"; particles[6] = "K*^{0} + #bar{K}*^{0}"; particles[7] = "K*^{+} + K*^{-}"; //at decay point // string folder = "/Users/jtblair/Downloads/kstar_data/decayed/pt02/"; //reconstructed string folder = "/Users/jtblair/Downloads/kstar_data/reconstructed/pt02/"; string files[20]; files[0] = "invm_[0.0,0.2].dat"; files[1] = "invm_[0.2,0.4].dat"; files[2] = "invm_[0.4,0.6].dat"; files[3] = "invm_[0.6,0.8].dat"; files[4] = "invm_[0.8,1.0].dat"; files[5] = "invm_[1.0,1.2].dat"; files[6] = "invm_[1.2,1.4].dat"; files[7] = "invm_[1.4,1.6].dat"; files[8] = "invm_[1.6,1.8].dat"; files[9] = "invm_[1.8,2.0].dat"; files[10] = "invm_[2.0,2.2].dat"; files[11] = "invm_[2.2,2.4].dat"; files[12] = "invm_[2.4,2.6].dat"; files[13] = "invm_[2.6,2.8].dat"; files[14] = "invm_[2.8,3.0].dat"; files[15] = "invm_[3.0,3.2].dat"; files[16] = "invm_[3.2,3.4].dat"; files[17] = "invm_[3.4,3.6].dat"; files[18] = "invm_[3.6,3.8].dat"; files[19] = "invm_[3.8,4.0].dat"; /* string files[8]; files[0] = "invm_[0.0,0.5].dat"; files[1] = "invm_[0.5,1.0].dat"; files[2] = "invm_[1.0,1.5].dat"; files[3] = "invm_[1.5,2.0].dat"; files[4] = "invm_[2.0,2.5].dat"; files[5] = "invm_[2.5,3.0].dat"; files[6] = "invm_[3.0,3.5].dat"; files[7] = "invm_[3.5,4.0].dat"; */ Int_t PARTICLE_NUM = 5; TFile *output = new TFile("20170721_KKbarAdded2_fixedwidth42_recon_pf100_scaled_error05.root", "RECREATE"); TH1D *kstar0mass = new TH1D("kstar0mass", Form("Fit value of M*_{0} vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0width = new TH1D("kstar0width", Form("#Gamma_{tot}(M=M*_{0}) vs p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS, 0.0, 4.0); TH1D *kstar0collWidth = new TH1D("kstar0collWidth", Form("Fit value of #Gamma_{coll} component vs. p_{T} for %s", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); TH1D *kstar0decWidth = new TH1D("kstar0decWidth", Form("#Gamma_{dec}(M=M*_{0}) component vs. p_{T} for %s;p_{T} (GeV/c);Width (GeV/c^2)", particles[PARTICLE_NUM].c_str()), NUM_PT_BINS,0.0, 4.0); kstar0mass->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0mass->GetYaxis()->SetTitle("Mass (GeV/c^{2})"); kstar0width->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0width->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0collWidth->GetXaxis()->SetTitle("p_{T} (GeV/c)"); kstar0collWidth->GetYaxis()->SetTitle("Width (GeV/c^2)"); kstar0mass->SetStats(kFALSE); kstar0width->SetStats(kFALSE); kstar0collWidth->SetStats(kFALSE); kstar0decWidth->SetStats(kFALSE); TF1 *massline = new TF1("massline", "[0]", 0.0, 4.0); massline->SetParameter(0, 0.892); massline->SetLineColor(2); massline->SetLineStyle(7); TF1 *widthline = new TF1("widthline", "[0]", 0.0, 4.0); widthline->SetParameter(0, 0.042); double mass = 0.0, width = 0.0, collWidth = 0.0, massBG=0.0; double massError = 0.0, widthError= 0.0, collWidthError = 0.0, massBGError=0.0; TCanvas *canvas[9]; TCanvas *diffCanvas[9]; TPaveStats *st; TPad *pad; //ofstream integrals; //integrals.open("kstarbar_integrals.txt"); for(int nfile = 0; nfile < NUM_PT_BINS; nfile++){ double meanPT = (double)(nfile*2+1)/10.0; string filename = folder+files[nfile]; string ptLower = filename.substr(filename.find("[")+1, 3); string ptHigher = filename.substr(filename.find(",")+1, 3); TH1D* histos[8]; TH1D* newHistos[8]; TH1D* diffHistos[8]; TH1D* bg[8]; for(int i=0; i<8; i++){ if(nfile<5){ histos[i] = new TH1D(Form("ptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin0%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); }else{ histos[i] = new TH1D(Form("ptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), NUM_MASS_BINS, MASS_LOW, MASS_HIGH); newHistos[i] = new TH1D(Form("newptbin%dparticle%d",nfile*2+1, i), Form("Invariant Mass for (%s), %s < p_{T} < %s",particles[i].c_str(), ptLower.c_str(), ptHigher.c_str()), 250, MASS_LOW, MASS_HIGH); } histos[i]->GetXaxis()->SetTitle("Invariant Mass (GeV/c^{2})"); histos[i]->GetYaxis()->SetTitle("Counts"); } ifstream input; input.open(filename.c_str()); string line = ""; if(input.good()){ getline(input, line); } double massBin=0.0; double invMass[8]; for(int i=0; i<8; i++){ invMass[i] = 0.0; } int lineNumber = 1; while(1){ input >> massBin >> invMass[0] >> invMass[1] >> invMass[2] >> invMass[3] >> invMass[4] >> invMass[5] >> invMass[6] >> invMass[7]; if(!input.good())break; for(int i =0; i<8; i++){ histos[i]->SetBinContent(lineNumber, invMass[i]/500.0); } if(lineNumber > 440 && lineNumber < 460 && nfile==6){ // printf("mass: %.12f invMass[6]: %.12f\n", massBin, invMass[6]); } lineNumber++; } printf("****** Fits for file: %s ******\n", filename.c_str()); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ //add the K*0 distribution to the K*0bar (K*0 = 4 for decay, K*0 = 3 for reconstructed) histos[i]->Add(histos[3]); if(nfile==0){ canvas[i] = new TCanvas(Form("c%i", i),Form("c%i", i), 0,0,900,900); canvas[i]->Divide(5,4); diffCanvas[i] = new TCanvas(Form("diffC%i", i),Form("diffC%i", i), 0,0,900,900); diffCanvas[i]->Divide(5,4); } //rebin //histos[i]->Sumw2(); histos[i]->Rebin(4); //Fixing the errors to a percentage of the signal region: for(int ibin=1; ibin < histos[i]->GetNbinsX(); ibin++){ histos[i]->SetBinError(ibin, histos[i]->GetBinContent((int)(0.892*(250.0/2.0)))*0.05); newHistos[i]->SetBinContent(ibin, histos[i]->GetBinContent(ibin)); newHistos[i]->SetBinError(ibin, histos[i]->GetBinError(ibin)); } pad = (TPad*)canvas[i]->cd(nfile+1); histos[i]->SetLineColor(1); histos[i]->SetLineWidth(1); histos[i]->GetXaxis()->SetRangeUser(0.7, 1.2); histos[i]->GetYaxis()->SetRangeUser(0, 1.5*histos[i]->GetBinContent(histos[i]->GetMaximumBin())); //histos[i]->SetStats(kFALSE); //histos[i]->Draw("HIST"); printf("mean PT: %f\n", meanPT); TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), FitFunRelBW, 0.68, 1.05, 5); //TF1 *fit = new TF1(Form("fitPTbin%d00particle%d", nfile*2+1, i), "gaus(0)", 0.86, 0.92); fit->SetParNames("BW Area", "Mass", "Width", "PT", "Temp"); fit->SetParameters(TMath::Power(10.0, (float)(nfile)/1.7), 0.89, 0.1, 0.5, 0.130); //fit->SetParNames("BW Area", "Mass", "Width"); //fit->SetParameters(100, 0.89, 0.0474); //fit->SetParLimits(0, -10, 1.5e9); Float_t max = histos[i]->GetXaxis()->GetBinCenter(histos[i]->GetMaximumBin()); //if(max < 0.91 && max > 0.892){ // fit->SetParLimits(1, max-0.001, max+0.001); //}else{ fit->SetParLimits(1, 0.82, 0.98); //} //fit->SetParLimits(2, 0.005, 0.15); fit->FixParameter(2, 0.042); fit->FixParameter(3, meanPT); //fit->SetParLimits(4, 0.05, 0.2); fit->FixParameter(4, 0.100001); fit->SetLineColor(2); printf("%s\n", fit->GetName()); histos[i]->Fit(Form("fitPTbin%d00particle%d", nfile*2+1, i), "BRIM", "SAME"); TVirtualFitter *fitter = TVirtualFitter::GetFitter(); histos[i]->SetStats(1); histos[i]->Draw(); gPad->Update(); pad->Update(); st = (TPaveStats*)histos[i]->FindObject("stats"); st->SetX1NDC(0.524); st->SetY1NDC(0.680); st->SetX2NDC(0.884); st->SetY2NDC(0.876); //fit->Draw("SAME"); //histos[i]->Draw(); gPad->Update(); pad->Update(); printf("\n"); diffHistos[i] = (TH1D*)histos[i]->Clone(Form("diffPTbin%d00particl%d", nfile*2+1, i)); diffHistos[i]->Add(fit, -1); diffCanvas[i]->cd(nfile+1); diffHistos[i]->Draw("HIST E"); diffHistos[i]->Write(); //counting bins Float_t integral = histos[i]->Integral(1, 500)*500.0; //integrals << integral <<" \n"; histos[i]->Write(); fit->Write(); //Do mass and width vs. pT plots just for K*0 if(i==PARTICLE_NUM){ mass = fit->GetParameter(1); massError = fit->GetParError(1); collWidth = fit->GetParameter(2); collWidthError = fit->GetParError(2); width = Gamma(mass, collWidth); kstar0mass->SetBinContent(nfile+1, mass); kstar0mass->SetBinError(nfile+1, massError); kstar0width->SetBinContent(nfile+1, width); Double_t widthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1) + fitter->GetCovarianceMatrixElement(2,2) + 2.0*GammaDerivative(mass)*fitter->GetCovarianceMatrixElement(1,2)); kstar0width->SetBinError(nfile+1, widthError); kstar0collWidth->SetBinContent(nfile+1, collWidth); kstar0collWidth->SetBinError(nfile+1, collWidthError); kstar0decWidth->SetBinContent(nfile+1, width - collWidth); Double_t decWidthError = TMath::Sqrt((GammaDerivative(mass)**2)*fitter->GetCovarianceMatrixElement(1,1)); kstar0decWidth->SetBinError(nfile+1, decWidthError); if(nfile==4){ TCanvas *singlecanvas = new TCanvas("singlecanvas", "singlecanvas", 0,0,600,600); singlecanvas->cd(); printf("Got here! \n"); histos[i]->Draw("HIST E SAME"); fit->SetLineColor(8); fit->SetLineStyle(1); fit->Draw("SAME"); if(fitter){ printf("sig11: %f, sig12: %f, sig21: %f, sig22: %f GammaDer(0.8): %f GammaDer(0.85): %f GammaDer(0.9): %f\n", TMath::Sqrt(fitter->GetCovarianceMatrixElement(1,1)), fitter->GetCovarianceMatrixElement(2,1), fitter->GetCovarianceMatrixElement(1,2), TMath::Sqrt(fitter->GetCovarianceMatrixElement(2,2)), GammaDerivative(0.8), GammaDerivative(0.85), GammaDerivative(0.9)); } } } } printf("************************************************************\n"); } //integrals.close(); /* TH2D *gammaPlot = new TH2D("gammaPlot", "#Gamma_{tot}(M_{0}*);M_{0}*;#Gamma_{coll};#Gamma_{tot}", 100, 0.82, 0.9, 100, 0.0, 0.08); for(int im = 0; im<100; im++){ for(int ig = 0; ig < 100; ig++){ gammaPlot->SetBinContent(im+1, ig+1, Gamma(((0.9-0.82)/(100.0))*((double)(im)) + 0.82, ((0.08)/100.0)*((double)(ig)))); } } TH1D *gammaMassDpnd = gammaPlot->ProjectionX("gammaMassDpnd"); */ TCanvas *masscanvas = new TCanvas("masscanvas", "masscanvas", 50,50, 600, 600); masscanvas->cd(); kstar0mass->Draw(); massline->Draw("SAME"); masscanvas->Write(); for(int i=PARTICLE_NUM; i<PARTICLE_NUM+1; i++){ canvas[i]->Write(); } kstar0mass->Write(); kstar0collWidth->Write(); kstar0decWidth->Write(); kstar0width->Write(); // gammaPlot->Write(); // gammaMassDpnd->Write(); }
void produceTF() { gROOT->SetBatch(); setTDRStyle(); TChain ch("trGEN"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hut-MadGraph5-pythia8/data.root"); ch.Add("runTEST_MERGED/ST_FCNC-TH_Tleptonic_HTobb_eta_hct-MadGraph5-pythia8/data.root"); float dMetPx, dMetPy; float dTopLepBJetPx, dTopLepBJetPy, dTopLepBJetPz, dTopLepBJetE; float dHiggsBJet1Px, dHiggsBJet1Py, dHiggsBJet1Pz, dHiggsBJet1E; float dHiggsBJet2Px, dHiggsBJet2Py, dHiggsBJet2Pz, dHiggsBJet2E; float dElecPx, dElecPy, dElecPz, dElecE; float dMuonPx, dMuonPy, dMuonPz, dMuonE; float TopLepWM, TopLepRecM, TopHadRecM, HiggsRecM; ch.SetBranchAddress("dMetPx",&dMetPx); ch.SetBranchAddress("dMetPy",&dMetPy); ch.SetBranchAddress("dTopLepBJetPx",&dTopLepBJetPx); ch.SetBranchAddress("dTopLepBJetPy",&dTopLepBJetPy); ch.SetBranchAddress("dTopLepBJetPz",&dTopLepBJetPz); ch.SetBranchAddress("dTopLepBJetE",&dTopLepBJetE); ch.SetBranchAddress("dHiggsBJet1Px",&dHiggsBJet1Px); ch.SetBranchAddress("dHiggsBJet1Py",&dHiggsBJet1Py); ch.SetBranchAddress("dHiggsBJet1Pz",&dHiggsBJet1Pz); ch.SetBranchAddress("dHiggsBJet1E",&dHiggsBJet1E); ch.SetBranchAddress("dHiggsBJet2Px",&dHiggsBJet2Px); ch.SetBranchAddress("dHiggsBJet2Py",&dHiggsBJet2Py); ch.SetBranchAddress("dHiggsBJet2Pz",&dHiggsBJet2Pz); ch.SetBranchAddress("dHiggsBJet2E",&dHiggsBJet2E); ch.SetBranchAddress("dElecPx",&dElecPx); ch.SetBranchAddress("dElecPy",&dElecPy); ch.SetBranchAddress("dElecPz",&dElecPz); ch.SetBranchAddress("dElecE",&dElecE); ch.SetBranchAddress("dMuonPx",&dMuonPx); ch.SetBranchAddress("dMuonPy",&dMuonPy); ch.SetBranchAddress("dMuonPz",&dMuonPz); ch.SetBranchAddress("dMuonE",&dMuonE); ch.SetBranchAddress("TopLepWM",&TopLepWM); ch.SetBranchAddress("TopLepRecM",&TopLepRecM); ch.SetBranchAddress("HiggsRecM",&HiggsRecM); int nHist = 0; TH1D *h[1000]; std::string hName[1000]; std::string hLab[1000]; TFile *fOut = new TFile("pdf.root","RECREATE"); h[nHist] = new TH1D("h_TopLepRecM","h_TopLepRecM",100,80.,260.); h[nHist]->Sumw2(); hName[nHist] = "TopLepRecM"; hLab[nHist] = "m(t) [GeV]"; nHist++; h[nHist] = new TH1D("h_TopLepWM","h_TopLepWM",100,60.,100.); h[nHist]->Sumw2(); hName[nHist] = "TopLepWM"; hLab[nHist] = "m(W) [GeV]"; nHist++; h[nHist] = new TH1D("h_HiggsRecM","h_HiggsRecM",100,20.,220.); h[nHist]->Sumw2(); hName[nHist] = "HiggsRecM"; hLab[nHist] = "m(H) [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPx","h_dMetPx",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPx"; hLab[nHist] = "MetPx_{gen} - MetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMetPy","h_dMetPy",100,-140.,140.); h[nHist]->Sumw2(); hName[nHist] = "dMetPy"; hLab[nHist] = "MetPy_{gen} - MetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPx","h_dBJetPx",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPx"; hLab[nHist] = "BJetPx_{gen} - BJetPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPy","h_dBJetPy",100,-60.,60.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPy"; hLab[nHist] = "BJetPy_{gen} - BJetPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetPz","h_dBJetPz",100,-80.,80.); h[nHist]->Sumw2(); hName[nHist] = "dBJetPz"; hLab[nHist] = "BJetPz_{gen} - BJetPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dBJetE","h_dBJetE",100,-300.,120.); h[nHist]->Sumw2(); hName[nHist] = "dBJetE"; hLab[nHist] = "BJetE_{gen} - BJetE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPx","h_dElecPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPx"; hLab[nHist] = "ElecPx_{gen} - ElecPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPy","h_dElecPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dElecPy"; hLab[nHist] = "ElecPy_{gen} - ElecPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecPz","h_dElecPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecPz"; hLab[nHist] = "ElecPz_{gen} - ElecPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dElecE","h_dElecE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dElecE"; hLab[nHist] = "ElecE_{gen} - ElecE_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPx","h_dMuonPx",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPx"; hLab[nHist] = "MuonPx_{gen} - MuonPx_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPy","h_dMuonPy",100,-5.,5.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPy"; hLab[nHist] = "MuonPy_{gen} - MuonPy_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonPz","h_dMuonPz",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonPz"; hLab[nHist] = "MuonPz_{gen} - MuonPz_{reco} [GeV]"; nHist++; h[nHist] = new TH1D("h_dMuonE","h_dMuonE",100,-6.,6.); h[nHist]->Sumw2(); hName[nHist] = "dMuonE"; hLab[nHist] = "MuonE_{gen} - MuonE_{reco} [GeV]"; nHist++; int nev = ch.GetEntries(); TRandom3 *rnd = new TRandom3(); for(int i=0;i<nev;i++) { ch.GetEntry(i); for(int ih=0;ih<nHist;ih++) { if( hName[ih] == "TopLepRecM" ) h[ih]->Fill(TopLepRecM); else if( hName[ih] == "TopLepWM" ) h[ih]->Fill(TopLepWM); else if( hName[ih] == "HiggsRecM" ) h[ih]->Fill(HiggsRecM); else if( hName[ih] == "dMetPx" ) h[ih]->Fill(dMetPx); else if( hName[ih] == "dMetPy" ) h[ih]->Fill(dMetPy); else if( hName[ih] == "dBJetPx" ) {h[ih]->Fill(dHiggsBJet1Px);h[ih]->Fill(dHiggsBJet2Px);h[ih]->Fill(dTopLepBJetPx);} else if( hName[ih] == "dBJetPy" ) {h[ih]->Fill(dHiggsBJet1Py);h[ih]->Fill(dHiggsBJet2Py);h[ih]->Fill(dTopLepBJetPy);} else if( hName[ih] == "dBJetPz" ) {h[ih]->Fill(dHiggsBJet1Pz);h[ih]->Fill(dHiggsBJet2Pz);h[ih]->Fill(dTopLepBJetPz);} else if( hName[ih] == "dBJetE" ) {h[ih]->Fill(dHiggsBJet1E);h[ih]->Fill(dHiggsBJet2E);h[ih]->Fill(dTopLepBJetE);} else if( hName[ih] == "dElecPx" ) {h[ih]->Fill(dElecPx);} else if( hName[ih] == "dElecPy" ) {h[ih]->Fill(dElecPy);} else if( hName[ih] == "dElecPz" ) {h[ih]->Fill(dElecPz);} else if( hName[ih] == "dElecE" ) {h[ih]->Fill(dElecE);} else if( hName[ih] == "dMuonPx" ) {h[ih]->Fill(dMuonPx);} else if( hName[ih] == "dMuonPy" ) {h[ih]->Fill(dMuonPy);} else if( hName[ih] == "dMuonPz" ) {h[ih]->Fill(dMuonPz);} else if( hName[ih] == "dMuonE" ) {h[ih]->Fill(dMuonE);} } } delete rnd; // Plots TCanvas *c1 = new TCanvas(); c1->Draw(); c1->cd(); TPad *c1_1; gStyle->SetHistTopMargin(0); for(int i=0;i<nHist;i++) { // addbin(h[i]); h[i]->Scale(1./h[i]->Integral()); h[i]->Scale(1./h[i]->GetMaximum()); h[i]->SetLineWidth(2); h[i]->SetLineColor(kRed); h[i]->SetMarkerColor(kRed); h[i]->SetMarkerStyle(20); h[i]->Draw("hist e1"); h[i]->GetXaxis()->SetTitle(hLab[i].c_str()); // h[i]->GetYaxis()->SetTitle("Normalized to unity"); float max = h[i]->GetMaximum(); h[i]->SetMaximum(1.2*max); if( hName[i] == "TopLepWM" || hName[i] == "TopLepM" ) { std::string funcName = hName[i]+"_Fit"; TF1 *func = new TF1(funcName.c_str(),BW,h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins()),3); double mean = 80.4; if( hName[i] == "TopLepM" ) mean = 173.0; double sigma = 2.0; if( hName[i] == "TopLepM" ) sigma = 2.0; func->SetParameter(0,mean); func->SetParName(0,"mean"); func->SetParameter(1,sigma); func->SetParName(1,"sigma"); func->SetParameter(2,1.0); func->SetParName(2,"constant"); func->FixParameter(2,1.); h[i]->Fit(funcName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->Write(); std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"gaus(0)",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->Write(); } if( hName[i] == "dMetPx" || hName[i] == "dMetPy" ) { double mean = 0.; double sigma = 50.; std::string funcGausName = hName[i]+"_Gaus"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); funcGaus->SetParameter(3,0.5); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dBJetPx" || hName[i] == "dBJetPy" || hName[i] == "dBJetPz" || hName[i] == "dBJetE" ) { double mean = 0.; double sigma = 20.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[12]*(gaus(0)+gaus(3)+gaus(6)+gaus(9))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(12,1.0); funcGaus->SetParameter(0,1.0); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(0,0.6); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(0,0.6); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(3,0.3); if( hName[i] == "dBJetE" ) funcGaus->SetParameter(5,sigma*4); if( hName[i] == "dBJetPy" ) funcGaus->SetParameter(3,0.2); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); if( hName[i] == "dBJetPz" ) funcGaus->SetParameter(8,sigma/3.); funcGaus->SetParameter(9,0.5); funcGaus->SetParameter(10,mean); funcGaus->SetParameter(11,sigma); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); if( hName[i] == "dBJetE" ) { c1->Update(); TPaveStats *st = (TPaveStats*)h[i]->FindObject("stats"); st->SetX1NDC(0.20); st->SetX2NDC(0.47); } fit->Draw("same"); fit->SetParameter(12,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dElecPx" || hName[i] == "dElecPy" || hName[i] == "dElecPz" || hName[i] == "dElecE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dElecPz" ) funcGaus->SetParameter(3,0.15); if( hName[i] == "dElecE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "dMuonPx" || hName[i] == "dMuonPy" || hName[i] == "dMuonPz" || hName[i] == "dMuonE" ) { double mean = 0.; double sigma = 1.; std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(0,0.8); funcGaus->SetParameter(3,0.3); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); if( hName[i] == "dMuonPz" ) funcGaus->SetParameter(3,0.2); if( hName[i] == "dMuonE" ) funcGaus->SetParameter(3,0.1); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } if( hName[i] == "HiggsRecM" || hName[i] == "TopLepRecM" ) { double mean = 125.; double sigma = 10.; if( hName[i] == "TopLepRecM" ) { mean = 170; sigma = 20; } std::string funcGausName = hName[i]+"_Fit"; TF1 *funcGaus = new TF1(funcGausName.c_str(),"[9]*(gaus(0)+gaus(3)+gaus(6))",h[i]->GetXaxis()->GetBinLowEdge(1), h[i]->GetXaxis()->GetBinUpEdge(h[i]->GetXaxis()->GetNbins())); funcGaus->FixParameter(9,1.0); funcGaus->SetParameter(0,1); funcGaus->SetParameter(1,mean); funcGaus->SetParameter(2,sigma); if( hName[i] != "TopLepRecM" ) funcGaus->FixParameter(0,0.7); funcGaus->SetParameter(3,0.3); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(3,0.7); if( hName[i] == "TopLepRecM" ) funcGaus->SetParameter(4,150); funcGaus->SetParameter(4,mean); funcGaus->SetParameter(5,sigma*2.); funcGaus->SetParameter(6,1.); funcGaus->SetParameter(7,mean); funcGaus->SetParameter(8,sigma/2.); h[i]->Fit(funcGausName.c_str(),"QR"); TF1 *fit = h[i]->GetFunction(funcGausName.c_str()); fit->SetLineColor(1); fit->Draw("same"); fit->SetParameter(9,1./fit->GetMaximum()); fit->Write(); } std::string figName = "pics/"+hName[i]+".eps"; c1->Print(figName.c_str()); c1->Clear(); } fOut->Write(); fOut->Close(); gApplication->Terminate(); }
void simple_overlay() { //open function bracket const int num_hists = 43; TH1F *first_histogram[num_hists]; TH1F *second_histogram[num_hists]; string first_hname[num_hists]= { "Energy_Positron","Energy_Neutrino", "Energy_First_a01", "Energy_Second_a01", "Energy_Tau_1", "Energy_Tau_2", "Energy_Tau_3", "Energy_Tau_4", "PT_Positron","PT_Neutrino", "PT_First_a01", "PT_Second_a01", "PT_Tau_1", "PT_Tau_2", "PT_Tau_3", "PT_Tau_4", "Eta_Tau_1","Eta_Tau_2", "Eta_Tau_3", "Eta_Tau_4", "DeltaEta_Tau_12", "DeltaEta_Tau_13", "DeltaEta_Tau_14", "DeltaEta_Tau_23", "DeltaEta_Tau_24", "DeltaEta_Tau_34", "DeltaPhi_Tau_12", "DeltaPhi_Tau_13", "DeltaPhi_Tau_14", "DeltaPhi_Tau_23", "DeltaPhi_Tau_24", "DeltaPhi_Tau_34", "DeltaR_Tau_12", "DeltaR_Tau_13", "DeltaR_Tau_14", "DeltaR_Tau_23", "DeltaR_Tau_24", "DeltaR_Tau_34", "Invariant_Mass_Pair12", "Invariant_Mass_Pair14", "Invariant_Mass_Pair32", "Invariant_Mass_Pair34", "Invariant_Mass_4_Taus"}; // enter info for histograms here string second_hname[num_hists]= { "energy_ele_hist","energy_nu_hist","energy_a1_hist","energy_a2_hist","energy_tau1_hist","energy_tau2_hist","energy_tau3_hist", "energy_tau4_hist", "pT_ele_hist","pT_nu_hist","pT_a1_hist","pT_a2_hist","pT_tau1_hist","pT_tau2_hist","pT_tau3_hist", "pT_tau4_hist", "eta_tau1", "eta_tau2", "eta_tau3", "eta_tau4", "deleta_tau12", "deleta_tau13", "deleta_tau14", "deleta_tau23", "deleta_tau24", "deleta_tau34", "delphi_tau12", "delphi_tau13", "delphi_tau14", "delphi_tau23", "delphi_tau24", "delphi_tau34", "delR_tau12", "delR_tau13", "delR_tau14", "delR_tau23", "delR_tau24", "delR_tau34", "mass_12", "mass_14", "mass_32", "mass_34", "mass_1234"}; TFile *first_file = new TFile("Entries_3000_Histograms_h01_115_a01_9.root"); //put name of one file here TFile *second_file = new TFile("KinematicsPlots_NewBinning.root"); //put name of other file here for (int i=0; i < num_hists; i++) { TIter next(first_file->GetListOfKeys()); TKey *key; string hName; while((key=(TKey*)next())) { hName = key->GetName(); if (hName.find(first_hname[i]) != -1) { first_histogram[i] = (TH1F*)(first_file->Get(hName.c_str())); cout << "first_hname[" << i << "]" << first_hname[i] << endl; break; } } TIter next(second_file->GetListOfKeys()); while((key=(TKey*)next())) { hName = key->GetName(); if (hName.find(second_hname[i]) != -1) { second_histogram[i] = (TH1F*)(second_file->Get(hName.c_str())); cout << "second_hname[" << i << "]" << first_hname[i] << endl; break; } } TCanvas *c1 = new TCanvas(); double statXstart[5] = {.8,.8,.8,.8,.8}; double statXend[5] = {1.,1.,1.,1.,1.}; double statYstart[5] = {.80,.70,.60,.50,.40}; double statYend[5] = {.70,.60,.50,.40,.30}; Color_t color_array[15] = {kBlue+1,kRed+0,kViolet,kAzure+10,kGreen+2,kBlue+1,kRed+0,kViolet,kAzure+10,kGreen+2,kBlue+1,kRed+0,kViolet,kAzure+10,kGreen+2}; size_t name_length; TPaveText *title = new TPaveText(0.306092,0.9390678,0.693908,0.995,"blNDC"); gStyle->SetOptTitle(0); title->SetBorderSize(0); title->SetFillColor(kWhite); title->SetTextFont(42); TPaveStats *st; string directory = "Francesca_Overlaid_Tau_Histograms"; gSystem->MakeDirectory(directory.c_str()); directory = directory + "/"; c1->cd(); gStyle->SetOptStat("nmre"); gStyle->SetStatH(0.03); gStyle->SetStatW(0.20); //TH1F *first_histogram = new TH1F(first_histogram_title, first_histogram_title, 200, 0., 500); //TH1F *second_histogram = new TH1F(second_histogram_title, second_histogram_title, 200, 0., 500); first_histogram[i]->SetLineColor(color_array[0]); first_histogram[i]->SetLineWidth(2); first_histogram[i]->SetTitle(first_hname[i].c_str()); // WHAT DOES THIS DO? eg. does it just set the name for hist title, or also for legend title? first_histogram[i]->SetName(first_hname[i].c_str()); // WHAT DOES THIS DO? eg. does it just set name for legend title? first_histogram[i]->Draw(); gPad->Update(); st = (TPaveStats*)first_histogram[i]->FindObject("stats"); st->SetX1NDC(statXstart[0]); st->SetX2NDC(statXend[0]); st->SetY1NDC(statYstart[0]); st->SetY2NDC(statYend[0]); second_histogram[i]->SetLineColor(color_array[1]); second_histogram[i]->SetLineWidth(2); second_histogram[i]->SetTitle(second_hname[i].c_str()); second_histogram[i]->SetName(second_hname[i].c_str()); second_histogram[i]->Draw("sames"); gPad->Update(); st = (TPaveStats*)second_histogram[i]->FindObject("stats"); st->SetX1NDC(statXstart[1]); st->SetX2NDC(statXend[1]); st->SetY1NDC(statYstart[1]); st->SetY2NDC(statYend[1]); c1->BuildLegend(.85,.8,1.,1.); c1->SetTitle("Dwarves"); title->Clear(); //this clears the title for the histogram title->AddText((first_hname[i]).c_str()); //this adds text to the TPaveText box that we created before the loop title->Draw(); //this draws the TPaveText box with the new text... e.g. it makes our new title c1->SaveAs((directory + first_hname[i] + ".png").c_str()); } //close for loop } //close function bracket
void DrawAllHistos(TString filename,Bool_t isMC,TString format){ // setTDRStyle("logredblue"); std::vector<TH1F*> h1vec; std::vector<TH2F*> h2vec; h1vec.clear(); h2vec.clear(); TFile *file = TFile::Open(filename); // to get the names of the conditions TObjArray *conditions_from_name = filename.Tokenize("_"); TString sa = conditions_from_name->At(1)->GetName(); TString sb = conditions_from_name->At(3)->GetName(); sb.ReplaceAll(".root",""); file->cd(); TDirectory *stardir = gDirectory; TObject *thesourcedir; TIter nextdir(stardir->GetListOfKeys()); while((thesourcedir=nextdir())){ TString dirName = thesourcedir->GetName(); stardir->cd(dirName); TDirectory *current_sourcedir = gDirectory; TH1::AddDirectory(kFALSE); std::cout << "*************************" <<std::endl; std::cout << "Reading Directory: " << dirName <<std::endl; TObject *obj; TIter next(current_sourcedir->GetListOfKeys()); while ((obj=next())) { TString objName =obj->GetName(); if(objName.Contains("pfx")) continue; if (objName.Contains("h2") && !objName.Contains("pfx")) { //std::cout << "Reading: " << obj->GetName() <<std::endl; TH2F* h2 = (TH2F*)file->Get(dirName+"/"+objName); h2->SetName(objName+dirName); h2vec.push_back(h2); TCanvas *c = new TCanvas(h2->GetName(),h2->GetName(),800,600); c->cd(); gPad->SetTopMargin(0.08); gPad->SetRightMargin(0.15); h2->SetStats(kFALSE); h2->Draw("colz"); c->Draw(); c->cd(); TProfile *hpfx_tmp = (TProfile*) h2->ProfileX("_pfx",1,-1,"o"); hpfx_tmp->SetStats(kFALSE); //hpfx_tmp->SetMarkerColor(kBlack); hpfx_tmp->SetMarkerColor(kRed); hpfx_tmp->SetMarkerSize(1.2); hpfx_tmp->SetMarkerStyle(20); hpfx_tmp->Draw("psame"); c->Draw(); cmsPrel(60.,sa,sb, isMC); TString canvName = h2->GetName(); c->cd()->SetLogz(); c->SaveAs(canvName+"."+format); } else { TH1F* h1 = (TH1F*)file->Get(dirName+"/"+objName); h1->SetName(objName+dirName); h1vec.push_back(h1); TCanvas *c = new TCanvas(h1->GetName(),h1->GetName(),600,600); c->cd()->SetLogy(); h1->SetMarkerColor(kBlack); h1->SetMarkerStyle(20); h1->SetLineWidth(1.5); h1->SetFillColor(393); //h1->SetFillStyle(3005); h1->Draw("hist"); h1->Draw("e1same"); c->Draw(); TObject *statObj; TPaveStats *stats; statObj = h1->GetListOfFunctions()->FindObject("stats"); stats= static_cast<TPaveStats*>(statObj); stats->SetFillColor(10); stats->SetLineWidth(1); stats->SetShadowColor(0); stats->SetTextFont(42); stats->SetTextSize(0.025); //stats->SetLineColor(LineColors); //stats->SetTextColor(LineColors); stats->SetX1NDC(0.75); stats->SetY1NDC(0.72); stats->SetX2NDC(0.97); stats->SetY2NDC(0.92); stats->Draw("same"); cmsPrel(60.,sa,sb,isMC); TString canvName = h1->GetName(); c->SaveAs(canvName+"."+format); } } } }
//------------------------------------------------------------------------------ void PlotAlignmentValidation::plotSubDetResiduals(bool plotNormHisto,unsigned int subDetId) { setNiceStyle(); gStyle->SetOptStat(11111); gStyle->SetOptFit(0000); TCanvas *c = new TCanvas("c", "c", 600,600); c->SetTopMargin(0.15); TString histoName= ""; if (plotNormHisto) {histoName= "h_NormXprime";} else histoName= "h_Xprime_"; switch (subDetId){ case 1 : histoName+="TPBBarrel_0";break; case 2 : histoName+="TPEendcap_1";break; case 3 : histoName+="TPEendcap_2";break; case 4 : histoName+="TIBBarrel_0";break; case 5 : histoName+="TIDEndcap_1";break; case 6 : histoName+="TIDEndcap_2";break; case 7 : histoName+="TOBBarrel_3";break; case 8 : histoName+="TECEndcap_4";break; case 9 : histoName+="TECEndcap_5";break; } int tmpcounter = 0; TH1 *sumHisto = 0; for(std::vector<TkOfflineVariables*>::iterator it = sourceList.begin(); it != sourceList.end(); ++it) { if (tmpcounter == 0 ) { TFile *f= (*it)->getFile(); sumHisto =(TH1*) f->FindKeyAny(histoName)->ReadObj();//FindObjectAny(histoName.Data()); sumHisto->SetLineColor(tmpcounter+1); sumHisto->SetLineStyle(tmpcounter+1); sumHisto->GetFunction("tmp")->SetBit(TF1::kNotDraw); sumHisto->Draw(); //get statistic box coordinate to plot all boxes one below the other //gStyle->SetStatY(0.91); //gStyle->SetStatW(0.15); //gStyle->SetStatBorderSize(1); //gStyle->SetStatH(0.10); tmpcounter++; } else { sumHisto = (TH1*) (*it)->getFile()->FindObjectAny(histoName); sumHisto->SetLineColor(tmpcounter+1); sumHisto->SetLineStyle(tmpcounter+1); sumHisto->GetFunction("tmp")->SetBit(TF1::kNotDraw); //hstack->Add(sumHisto); c->Update(); tmpcounter++; } TObject *statObj = sumHisto->GetListOfFunctions()->FindObject("stats"); if (statObj && statObj->InheritsFrom(TPaveStats::Class())) { TPaveStats *stats = static_cast<TPaveStats*>(statObj); stats->SetLineColor(tmpcounter+1); stats->SetTextColor(tmpcounter+1); stats->SetFillColor(10); stats->SetX1NDC(0.91-tmpcounter*0.1); stats->SetX2NDC(0.15); stats->SetY1NDC(1); stats->SetY2NDC(0.10); sumHisto->Draw("sames"); } } //hstack->Draw("nostack"); char PlotName[1000]; sprintf( PlotName, "%s/%s.eps", outputDir.c_str(), histoName.Data() ); c->Print(PlotName); //delete c; //c=0; }
// ----------------------------------------------------------------------------- // Create plots void plot( std::string& path, std::string& type, std::string& sample, std::string& dir, std::string& histo, double lumi, bool scale ) { std::string canvas_name = histo + "_" + dir + "_" + type + "_" + sample; // Create canvas TCanvas* canvas = new TCanvas(canvas_name.c_str(),""); canvas->SetFillColor(0); canvas->SetFrameBorderMode(0); canvas->SetFrameFillColor(0); canvas->SetTopMargin(0.10); canvas->SetBottomMargin(0.12); canvas->SetLeftMargin(0.12); canvas->SetRightMargin(0.15); // Retrieve histogram std::string file_name = path + type + "_" + sample + ".root"; TFile* f = new TFile(file_name.c_str(),"READ"); TDirectory* d = (TDirectory*)f->Get(dir.c_str()); TH2D* his = (TH1*)d->Get(histo.c_str()); if ( !his ) return; //his->Rebin2D(2,2); if ( true ) { gPad->SetLogz(); } if ( scale ) his->Scale( lumi / 100. ); his->SetMaximum(1.e4); his->SetMinimum(1.e-5); //his->SetMinimum( his->GetMinimum(1.e-12) ); // his->SetMaximum( 20000. ); // his->SetMinimum( 2.e-4 ); // his->SetMaximum( 20000. ); // his->SetMinimum( 20. ); double xmin = his->GetXaxis()->GetXmin(); double xmax = his->GetXaxis()->GetXmax(); double ymin = his->GetYaxis()->GetXmin(); double ymax = his->GetYaxis()->GetXmax(); // Reset title std::string title = ";" + std::string(his->GetXaxis()->GetTitle()) + ";" + std::string(his->GetYaxis()->GetTitle()); his->SetTitle(title.c_str()); his->GetXaxis()->SetTitle("x_{2}"); his->GetXaxis()->SetTitleOffset(1.2); his->GetYaxis()->SetTitle("x_{1}"); his->GetYaxis()->SetTitleOffset(1.4); his->Draw("COLZ"); gPad->Update(); // Lumi if (1) { std::stringstream ss; ss << "#int L dt = " << lumi << " pb^{-1}"; double xpos = 0.05 * (xmax-xmin)+xmin; double ypos = 0.25 * (ymax-ymin)+ymin; TLatex* text1 = new TLatex(xpos,ypos,ss.str().c_str()); text1->SetTextAlign(12); text1->SetTextSize(0.035); text1->Draw(); } // Jet type if (1) { double xpos = 0.05 * (xmax-xmin)+xmin; double ypos = 0.15 * (ymax-ymin)+ymin; TText* text2 = new TText(xpos,ypos,type.c_str()); text2->SetTextAlign(12); text2->SetTextSize(0.035); text2->Draw(); } // Sample if (1) { double xpos = 0.05 * (xmax-xmin)+xmin; double ypos = 0.10 * (ymax-ymin)+ymin; TText* text3 = new TText(xpos,ypos,sample.c_str()); text3->SetTextAlign(12); text3->SetTextSize(0.035); text3->Draw(); } // Stats gStyle->SetOptStat("i"); his->SetStats(1); TPaveStats* stats = (TPaveStats*)his->GetListOfFunctions()->FindObject("stats"); std::string stats_pos = "br"; if ( stats ) { stats->SetFillColor(0); stats->SetLineColor(0); stats->SetShadowColor(0); if ( stats_pos == "tr" ) { stats->SetX1NDC(0.60); stats->SetY1NDC(0.68); stats->SetX2NDC(0.83); stats->SetY2NDC(0.88); } else if ( stats_pos == "br" ) { stats->SetX1NDC(0.60); stats->SetY1NDC(0.18); stats->SetX2NDC(0.83); stats->SetY2NDC(0.28); } else { stats->SetX1NDC(0.60); stats->SetY1NDC(0.68); stats->SetX2NDC(0.83); stats->SetY2NDC(0.88); } } // Scale gStyle->SetPalette(1); TPaletteAxis* palette = (TPaletteAxis*)his->GetListOfFunctions()->FindObject("palette"); if ( palette ) { palette->SetY1NDC(0.2); palette->SetY2NDC(0.8); } canvas->Modified(); canvas->cd(); canvas->SetSelected(canvas); canvas->SaveAs(std::string(canvas_name+".png").c_str()); //canvas->Write(); }
void plot_variables(std::string root_file, TString variable_name, vector<double> &mean_of_fit, vector<double> &meanError_of_fit, vector<double> &sigma_of_fit, vector<double> &sigmaError_of_fit ) { // -------------------- // open histogram TString path = "root_files/" + root_file ; // TString path = "root_files_test2/" + root_file ; TFile *f = TFile::Open( path ); TH1F* h_variable[7]; for(int i=1; i<7; i++) { TString histo_name = "h_" + variable_name + Form("_ch%d",i); h_variable[i] = (TH1F*)f->FindObjectAny(histo_name); } // -------------------- // draw each one in pdf // Clone TH1F* h_variable_clone1[7]; for(int i=1; i<7; i++) { h_variable_clone1[i] = (TH1F*)h_variable[i]->Clone(""); } // set style TString config_name; if ( root_file.find("Pad1Tri_Ele100um_100GeV_600HV") != std::string::npos ) config_name = "Pad1Tri_Ele100um_100GeV_600HV"; else if( root_file.find("Pad1Tri_Ele100um_150GeV_800HV") != std::string::npos ) config_name = "Pad1Tri_Ele100um_150GeV_800HV"; else if( root_file.find("Pad1Tri_Ele200um_100GeV_600HV") != std::string::npos ) config_name = "Pad1Tri_Ele200um_100GeV_600HV"; else if( root_file.find("Pad1Tri_Ele200um_150GeV_800HV") != std::string::npos ) config_name = "Pad1Tri_Ele200um_150GeV_800HV"; else if( root_file.find("Pad1Tri_Ele300um_100GeV_600HV") != std::string::npos ) config_name = "Pad1Tri_Ele300um_100GeV_600HV"; else if( root_file.find("Pad1Tri_Ele300um_150GeV_800HV") != std::string::npos ) config_name = "Pad1Tri_Ele300um_150GeV_800HV"; else if( root_file.find("Pad3Tri_Ele100um_150GeV_800HV") != std::string::npos ) config_name = "Pad3Tri_Ele100um_150GeV_800HV"; else if( root_file.find("Pad3Tri_Ele200um_150GeV_800HV") != std::string::npos ) config_name = "Pad3Tri_Ele200um_150GeV_800HV"; else if( root_file.find("Pad3Tri_Ele300um_150GeV_800HV") != std::string::npos ) config_name = "Pad3Tri_Ele300um_150GeV_800HV"; TString channel_name[7]; if( root_file.find("Pad1Tri") != std::string::npos ) { channel_name[0] = ""; channel_name[1] = "SiPad1"; channel_name[2] = "SiPad2"; channel_name[3] = "SiPad3"; channel_name[4] = "SiPad4"; channel_name[5] = "SiPad5"; channel_name[6] = "SiPad6"; } if( root_file.find("Pad3Tri") != std::string::npos ) { channel_name[0] = ""; channel_name[1] = "SiPad3"; channel_name[2] = "SiPad1"; channel_name[3] = "SiPad2"; channel_name[4] = "SiPad4"; channel_name[5] = "SiPad5"; channel_name[6] = "SiPad6"; } for(int i=1; i<7; i++) { TString title = config_name +","+ channel_name[i]; h_variable_clone1[i]->SetTitle(title); h_variable_clone1[i]->SetStats(1); SetStyle_histo( h_variable_clone1[i] , variable_name ); } // Fit in Gaussian mean_of_fit.push_back(-99);// set dummy for i=0 meanError_of_fit.push_back(-99);// set dummy for i=0 sigma_of_fit.push_back(-99);// set dummy for i=0 sigmaError_of_fit.push_back(-99);// set dummy for i=0 gStyle->SetOptFit(1111); for(int i=1; i<7; i++) { double Rmin = h_variable_clone1[i]->GetMean() - 3* h_variable_clone1[i]->GetRMS(); double Rmax = h_variable_clone1[i]->GetMean() + 3* h_variable_clone1[i]->GetRMS(); h_variable_clone1[i]->Fit("gaus","R","", Rmin , Rmax); TF1 *fit = h_variable_clone1[i]->GetFunction("gaus"); mean_of_fit.push_back( fit->GetParameter(1) ); meanError_of_fit.push_back( fit->GetParError(1) ); sigma_of_fit.push_back( fit->GetParameter(2) ); sigmaError_of_fit.push_back( fit->GetParError(2) ); } // draw and save TString save_name = save_path +"/"+config_name+"_"+variable_name+".pdf"; TCanvas *c1 = new TCanvas("c1","c1",200,10,700,500); for(int i=1; i<7; i++) { c1->cd(); h_variable_clone1[i]->Draw(); c1->Update(); if (variable_name == "pedestal" && h_variable_clone1[i]->GetMean()>3685) { cout<<"hello"<<endl; double newx1 = 0.2; double newx2 = 0.5 ; double newy1 = 0.4; double newy2 = 0.9 ; TPaveStats *st =(TPaveStats*) h_variable_clone1[i]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); } c1->Update(); if (i==1 ) { c1->Print(save_name +"("); } // else if(i==6 ){c1->Print(save_name +")");} else { c1->Print(save_name ); } } // -------------------- // compare different SiPad // Clone TH1F* h_variable_clone2[7]; for(int i=1; i<7; i++) { h_variable_clone2[i] = (TH1F*)h_variable[i]->Clone(""); } // set style double y_range_max =0; for(int i=1; i<7; i++) { TString title = config_name +", compare different SiPad"; h_variable_clone2[i]->SetTitle(title); h_variable_clone2[i]->SetStats(0); h_variable_clone2[i]->Scale(1/h_variable_clone2[i]->Integral() ); SetStyle_histo( h_variable_clone2[i] , variable_name ); h_variable_clone2[i]->SetLineWidth(2); if(i==1) h_variable_clone2[i]->SetLineColor(kPink); if(i==2) h_variable_clone2[i]->SetLineColor(kOrange-3); if(i==3) h_variable_clone2[i]->SetLineColor(kGreen+2); if(i==4) h_variable_clone2[i]->SetLineColor(kAzure+10); if(i==5) h_variable_clone2[i]->SetLineColor(kBlue); if(i==6) h_variable_clone2[i]->SetLineColor(kMagenta+2); double max_temp = h_variable_clone2[i]->GetBinContent( h_variable_clone2[i]->GetMaximumBin() ); if( max_temp > y_range_max ) y_range_max = max_temp; } // cout<<"y_range_max: "<< y_range_max << endl; h_variable_clone2[1]->GetYaxis()->SetRangeUser(0 , y_range_max*1.2 ); // draw and save TCanvas *c2 = new TCanvas("c2","c2",200,10,700,500); TLegend *leg; if (variable_name == "pedestal") { leg = new TLegend(0.36,0.6,0.51,0.9); } else { leg = new TLegend(0.75,0.6,0.9,0.9); } for(int i=1; i<7; i++) { c2->cd(); if(i==1) { h_variable_clone2[i]->Draw() ; } else { h_variable_clone2[i]->Draw("same"); } leg->AddEntry( h_variable_clone2[i] , channel_name[i] ,"l"); leg->Draw(); } c2->Print( save_name + ")" ); }
void CompHist(TH1 *h1, TH1 *href, int run1, int runref) { if (!h1 || !href || h1->Integral()==0 || href->Integral()==0) return; // first check if both histograms are compatible Stat_t s[TH1F::kNstat]; h1->GetStats(s);// s[1] sum of squares of weights, s[0] sum of weights Double_t sumBinContent1 = s[0]; Double_t effEntries1 = (s[1] ? s[0] * s[0] / s[1] : 0.0); href->GetStats(s);// s[1] sum of squares of weights, s[0] sum of weights Double_t sumBinContent2 = s[0]; Double_t effEntries2 = (s[1] ? s[0] * s[0] / s[1] : 0.0); float pval_chi2=1, pval_ks=1,pval_ad=1; bool iswt = (sumBinContent1==0 || effEntries1==0 || sumBinContent2==0 || effEntries2==0 || TMath::Abs(sumBinContent1 - effEntries1) != 0 || TMath::Abs(sumBinContent2 - effEntries2) != 0); if (iswt) { // weighted histograms pval_chi2 = h1->Chi2Test(href,"WW"); // pval_ks = h1->KolmogorovTest(href); } else { // unweighted histograms pval_ks = h1->KolmogorovTest(href); pval_ad = h1->AndersonDarlingTest(href); // double int1 = h1->Integral(); // double intref = href->Integral(); // if (int1==0 || intref==0) return; // h1->Scale(1./int1); // href->Scale(1./intref); // pval_chi2 = h1->Chi2Test(href,"NORM UU"); } if (pval_chi2>minpval && pval_ks>minpval) return; // looks like we have a discrepancy! let's plot the histograms and print the output cout << h1->GetTitle() << ": p-val(chi2) = " << pval_chi2 << ", p-val(KS) = " << pval_ks << ", pval_ad = " << pval_ad << endl; TCanvas *c1 = new TCanvas(); href->SetLineColor(kRed); href->SetMarkerColor(kRed); if (!iswt) href->DrawNormalized(); else href->Draw(); c1->Update(); // Retrieve the stat box TPaveStats *ps = (TPaveStats*)c1->GetPrimitive("stats"); ps->SetName("statsref"); ps->SetTextColor(kRed); ps->SetX1NDC(0.8); ps->SetX2NDC(1.); ps->SetY1NDC(0.6); ps->SetY2NDC(0.8); h1->SetLineColor(kBlack); h1->SetMarkerColor(kBlack); if (!iswt) h1->DrawNormalized("sames"); else h1->Draw("sames"); c1->Update(); TPaveStats *psref = (TPaveStats*)c1->GetPrimitive("stats"); psref->SetName("stats1"); psref->SetX1NDC(0.8); psref->SetX2NDC(1.); psref->SetY1NDC(0.8); psref->SetY2NDC(1.); c1->Modified(); c1->Update(); TLatex *txt = new TLatex(); if (!iswt) txt->DrawLatexNDC(0.02,0.02,Form("p(KS) = %f, p(AD) = %f",pval_ks,pval_ad)); else txt->DrawLatexNDC(0.02,0.02,Form("p(#chi^{2}) = %f",pval_chi2)); c1->SaveAs(Form("%s_%i_%i.png",h1->GetName(),run1,runref)); delete c1; }
void pileup(){ TFile f("/data/ndpc3/b/dmorse/RA3/AnalysisOutput/Pileup/cms525v3_jec2012/hist_Data2012B_Filter_JsonNVertexOne25GeVBarrelPho_Photon_cms525v3_jec2012_Runs190456-195947_Pileup.root"); f.cd(); TCanvas *c1 = new TCanvas("c1","",800,600); gStyle->SetOptStat(0); gStyle->SetFitFormat("5.3f"); TH1F *h_rho25 = (TH1F*)f.Get("rho25"); h_rho25->GetXaxis()->SetRangeUser(0,50); h_rho25->Draw("histo"); c1->Print("Plots/Pileup/rho25.png"); c1->Print("Plots/Pileup/rho25.pdf"); c1->SetLogz(1); TPaveText *Text; Text = new TPaveText(.25,.65,.55,.79,"NDC"); Text->AddText("CMS Preliminary 2012"); Text->SetFillStyle(4000); Text->SetFillColor(0); Text->SetBorderSize(0); Text->AddText("#sqrt{s} = 8 TeV, #intL = 4.04 fb^{-1}"); TH2F* h_EcalDR03 = (TH2F*)f.Get("EcalIsoVsRho25DR03_ee"); h_EcalDR03->GetYaxis()->SetRangeUser(-25,70); h_EcalDR03->GetXaxis()->SetRangeUser(0,40); h_EcalDR03->SetTitle(""); h_EcalDR03->GetYaxis()->SetTitle("Ecal Isolation (DR03)"); h_EcalDR03->GetXaxis()->SetTitle("Rho25 (E_{T} / unit area)"); h_EcalDR03->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/Figure5_EcalIsoVsRho25DR03_ee.png"); c1->Print("Plots/Pileup/Figure5_EcalIsoVsRho25DR03_ee.pdf"); TH2F* h_HcalDR03 = (TH2F*)f.Get("HcalIsoVsRho25DR03_ee"); h_HcalDR03->GetYaxis()->SetRangeUser(-3,45); h_HcalDR03->GetXaxis()->SetRangeUser(0,40); h_HcalDR03->SetTitle(""); h_HcalDR03->GetYaxis()->SetTitle("Hcal Isolation (DR03)"); h_HcalDR03->GetXaxis()->SetTitle("Rho25 (E_{T} / unit area)"); h_HcalDR03->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/Figure5_HcalIsoVsRho25DR03_ee.png"); c1->Print("Plots/Pileup/Figure5_HcalIsoVsRho25DR03_ee.pdf"); TH2F* h_TrackDR03 = (TH2F*)f.Get("TrackIsoVsRho25DR03_ee"); h_TrackDR03->GetYaxis()->SetRangeUser(-3,80); h_TrackDR03->GetXaxis()->SetRangeUser(0,40); h_TrackDR03->SetTitle(""); h_TrackDR03->GetYaxis()->SetTitle("Track Isolation (DR03)"); h_TrackDR03->GetXaxis()->SetTitle("Rho25 (E_{T} / unit area)"); h_TrackDR03->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/Figure5_TrackIsoVsRho25DR03_ee.png"); c1->Print("Plots/Pileup/Figure5_TrackIsoVsRho25DR03_ee.pdf"); TH2F* h_HOverE = (TH2F*)f.Get("HOverEVsRho25_ee"); h_HOverE->GetYaxis()->SetRangeUser(0,.16); h_HOverE->GetXaxis()->SetRangeUser(0,40); h_HOverE->SetTitle(""); h_HOverE->GetXaxis()->SetTitle("Rho25 (E_{T} / unit area)"); h_HOverE->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/Figure5_HOverEVsRho25_ee.png"); c1->Print("Plots/Pileup/Figure5_HOverEVsRho25_ee.pdf"); TH2F* h_HOverEAfterIso = (TH2F*)f.Get("HOverEAfterIsoVsRho25_ee"); h_HOverEAfterIso->GetYaxis()->SetRangeUser(0,.16); h_HOverEAfterIso->GetXaxis()->SetRangeUser(0,40); h_HOverEAfterIso->SetTitle(""); h_HOverEAfterIso->GetXaxis()->SetTitle("Rho25 (E_{T} / unit area)"); h_HOverEAfterIso->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/Figure5_HOverEAfterIsoVsRho25_ee.png"); c1->Print("Plots/Pileup/Figure5_HOverEAfterIsoVsRho25_ee.pdf"); h_EcalDR03->ProfileX("ecal_pfx",0,450); ecal_pfx->GetYaxis()->SetTitle("Average Ecal Isolation (DR03)"); ecal_pfx->GetYaxis()->SetRangeUser(0,4.6); ecal_pfx->Fit("pol1","","",0,45); ecal_pfx->Draw(); c1->Update(); TPaveStats *st = (TPaveStats*)ecal_pfx->FindObject("stats"); st->SetName("ecalStats"); st->SetTextSize(.04); st->SetX1NDC(.25);st->SetX2NDC(.55); st->SetY1NDC(.52);st->SetY2NDC(.65); Text->Draw(); c1->Print("Plots/Pileup/Figure6_EcalIsoVsRho25_ee_pfx.png"); c1->Print("Plots/Pileup/Figure6_EcalIsoVsRho25_ee_pfx.pdf"); h_HcalDR03->ProfileX("hcal_pfx",0,450); hcal_pfx->GetYaxis()->SetTitle("Average Hcal Isolation (DR03)"); hcal_pfx->GetYaxis()->SetRangeUser(0.1,1.5); hcal_pfx->Fit("pol1","","",0,45); hcal_pfx->Draw(); c1->Update(); TPaveStats *st = (TPaveStats*)hcal_pfx->FindObject("stats"); st->SetName("hcalStats"); st->SetTextSize(.04); st->SetX1NDC(.25);st->SetX2NDC(.55); st->SetY1NDC(.52);st->SetY2NDC(.65); Text->Draw(); c1->Print("Plots/Pileup/Figure6_HcalIsoVsRho25_ee_pfx.png"); c1->Print("Plots/Pileup/Figure6_HcalIsoVsRho25_ee_pfx.pdf"); h_TrackDR03->ProfileX("track_pfx",0,450); track_pfx->GetYaxis()->SetTitle("Average Track Isolation (DR03)"); track_pfx->GetYaxis()->SetRangeUser(0.1,1.2); track_pfx->Fit("pol1","","",0,30); track_pfx->Draw(); c1->Update(); TPaveStats *st = (TPaveStats*)track_pfx->FindObject("stats"); st->SetName("trackStats"); st->SetTextSize(.04); st->SetX1NDC(.25);st->SetX2NDC(.55); st->SetY1NDC(.52);st->SetY2NDC(.65); Text->Draw(); c1->Print("Plots/Pileup/Figure6_TrackIsoVsRho25_ee_pfx.png"); c1->Print("Plots/Pileup/Figure6_TrackIsoVsRho25_ee_pfx.pdf"); gStyle->SetFitFormat("5.6f"); h_HOverE->ProfileX("hovere_pfx",0,450); hovere_pfx->GetYaxis()->SetTitle("Average H/E"); hovere_pfx->Fit("pol1","","",0,45); hovere_pfx->Draw(); Text->Draw(); c1->Print("Plots/Pileup/Figure6_HOverEIsoVsRho25_ee_pfx.png"); c1->Print("Plots/Pileup/Figure6_HOverEIsoVsRho25_ee_pfx.pdf"); h_HOverEAfterIso->ProfileX("hovereafteriso_pfx",0,450); hovereafteriso_pfx->GetYaxis()->SetTitle("Average H/E After Combined Isolation (DR03) < 6.0"); hovereafteriso_pfx->Fit("pol1","","",0,45); hovereafteriso_pfx->Draw(); Text->Draw(); c1->Print("Plots/Pileup/Figure6_HOverEAfterIsoVsRho25_ee_pfx.png"); c1->Print("Plots/Pileup/Figure6_HOverEAfterIsoVsRho25_ee_pfx.pdf"); TH2F* h_chargedHadron = (TH2F*)f.Get("chargedHadronIsoVsRho25_ee"); h_chargedHadron->GetYaxis()->SetRangeUser(-3,120); h_chargedHadron->GetXaxis()->SetRangeUser(0,40); h_chargedHadron->SetTitle(""); h_chargedHadron->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/chargedHadronIso_ee.png"); h_chargedHadron->ProfileX("chargedHad_pfx",0,450); chargedHad_pfx->GetYaxis()->SetTitle("Average chargedHadron Isolation"); chargedHad_pfx->GetYaxis()->SetRangeUser(0.4,2); chargedHad_pfx->Fit("pol1","","",0,50); chargedHad_pfx->Draw(); c1->Update(); TPaveStats *st = (TPaveStats*)chargedHad_pfx->FindObject("stats"); st->SetName("hcalStats"); st->SetTextSize(.04); st->SetX1NDC(.21);st->SetX2NDC(.55); st->SetY1NDC(.52);st->SetY2NDC(.65); Text->Draw(); c1->Print("Plots/Pileup/chargedHadronIso_ee_pfx.png"); TH2F* h_neutralHadron = (TH2F*)f.Get("neutralHadronIsoVsRho25_ee"); h_neutralHadron->GetYaxis()->SetRangeUser(-3,40); h_neutralHadron->GetXaxis()->SetRangeUser(0,40); h_neutralHadron->SetTitle(""); h_neutralHadron->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/neutralHadronIso_ee.png"); h_neutralHadron->ProfileX("neutralHad_pfx",0,450); neutralHad_pfx->GetYaxis()->SetTitle("Average neutralHadron Isolation"); neutralHad_pfx->GetYaxis()->SetRangeUser(0,1.2); neutralHad_pfx->Fit("pol1","","",0,50); neutralHad_pfx->Draw(); c1->Update(); TPaveStats *st = (TPaveStats*)neutralHad_pfx->FindObject("stats"); st->SetName("hcalStats"); st->SetTextSize(.04); st->SetX1NDC(.21);st->SetX2NDC(.55); st->SetY1NDC(.52);st->SetY2NDC(.65); Text->Draw(); c1->Print("Plots/Pileup/neutralHadronIso_ee_pfx.png"); TH2F* h_photon = (TH2F*)f.Get("photonIsoVsRho25_ee"); h_photon->GetYaxis()->SetRangeUser(-3,100); h_photon->GetXaxis()->SetRangeUser(0,40); h_photon->SetTitle(""); h_photon->Draw("colz"); Text->Draw(); c1->Print("Plots/Pileup/photonIso_ee.png"); h_photon->ProfileX("photon_pfx",0,450); photon_pfx->GetYaxis()->SetTitle("Average photon Isolation"); //photon_pfx->GetYaxis()->SetRangeUser(0,1.2); photon_pfx->Fit("pol1","","",0,50); photon_pfx->Draw(); c1->Update(); TPaveStats *st = (TPaveStats*)photon_pfx->FindObject("stats"); st->SetName("hcalStats"); st->SetTextSize(.04); st->SetX1NDC(.21);st->SetX2NDC(.55); st->SetY1NDC(.52);st->SetY2NDC(.65); Text->Draw(); c1->Print("Plots/Pileup/photonIso_ee_pfx.png"); f.Close(); }
int CaloL3(const char *ctype="Calo") { bool iSave=false; double minx=1.0; LoadStyle(); gStyle->SetOptStat(1); gStyle->SetOptFit(1); //string outdir="txtfiles/"; string outdir="junk/"; cout << " # of bins in pt : " << nbins << endl; //return 0; TVirtualFitter::SetDefaultFitter("Minuit"); TH1F *hrsp[knj][nbins]; TGraphErrors *grsp[knj], *gcor[knj]; TH1F *hMean[knj], *hRMS[knj]; //TFile *fin = new TFile("jra_hiF_akcalo_ppReco_757p1_dijet.root","r"); //TFile *fin = new TFile("jra_hiF_akcalo_ppReco_757p1_dijet_fulleta_fullpt.root","r"); TFile *fin = new TFile("jra_hiF_akcalo_ppReco_757p1_HcalRespCorrs_v4_00_mc_dijet.root","r"); double refptmin=0; double refptmax=1000; TLegend *l0 = getLegend(0.6349664,0.3265565,0.8491835,0.7128335); l0->SetHeader(Form("Anti-k_{T}, %s",ctype)); TLegend *l1 = getLegend(0.1500646,0.5052258,0.3653091,0.7490942); l1->SetHeader(""); TF1 *fgaus=0; TH1F *hrefpt=0, *hjetpt=0; int njmin=0; int njmax=knj; for(int i=njmin; i<njmax; i++){ grsp[i] = new TGraphErrors(nbins); gcor[i] = new TGraphErrors(nbins); //grsp[i]->SetName(Form("L3RspVsRefPt_%d",i)); grsp[i]->SetName(Form("L3RspVsRefPt_%s",calgo[i])); grsp[i]->SetTitle(Form("L3RspVsRefPt %s",calgo[i])); grsp[i]->SetLineColor(1); grsp[i]->SetMarkerColor(1); grsp[i]->SetMarkerStyle(20); grsp[i]->SetMarkerSize(1.2); //gcor[i]->SetName(Form("L3CorVsJetPt_%d",i)); gcor[i]->SetName(Form("L3CorVsJetPt_%s",calgo[i])); gcor[i]->SetTitle(Form("L3CorVsJetPt %s",calgo[i])); gcor[i]->SetLineColor(1); gcor[i]->SetMarkerColor(1); gcor[i]->SetMarkerStyle(20); gcor[i]->SetMarkerSize(1.2); hMean [i] = new TH1F(Form("hMean_%d",i),Form("%s%s",calgo[i],ctype),nbins,ptbins); hMean [i]->SetMarkerColor(1); hMean [i]->SetMarkerStyle(20); hMean [i]->SetLineColor(1); hMean [i]->GetXaxis()->SetMoreLogLabels(); hMean [i]->GetXaxis()->SetNoExponent(); hRMS [i] = new TH1F(Form("hRMS_%d",i),Form("%s%s",calgo[i],ctype),nbins,ptbins); hRMS [i]->SetMarkerColor(1); hRMS [i]->SetMarkerStyle(20); hRMS [i]->SetLineColor(1); std::ostringstream strs; //strs << "ak" << i+1 << "CaloJetAnalyzer/"; strs << calgo[i] << "CaloJetAnalyzer/"; cout << " Running for : " << strs.str().c_str() << endl; for(int j=0; j<nbins; j++){ if(ptbins[j]<minx)continue; //if(j<2)continue; std::ostringstream spt; spt << ptbins[j] << "to" << ptbins[j+1]; //cout << " ptbins : " << ptbins[j] << endl; std::string sone (strs.str()+"RefPt_Barrel_RefPt"+spt.str()); std::string stwo (strs.str()+"JetPt_Barrel_RefPt"+spt.str()); std::string sthree(strs.str()+"RelRsp_Barrel_RefPt"+spt.str()); hrefpt = (TH1F*)fin->Get(sone.c_str()); hjetpt = (TH1F*)fin->Get(stwo.c_str()); hrsp[i][j] = (TH1F*)fin->Get(sthree.c_str()); //hrsp[i][j]->Rebin(2); assert(hrefpt->GetEntries()>0 && hjetpt->GetEntries()>0); // if( ptbins[j] < 30.0 ){ // SetHistRange(hrsp[i][j]); // } double refpt =hrefpt->GetMean(); double erefpt =hrefpt->GetMeanError(); double jetpt =hjetpt->GetMean(); double ejetpt =hjetpt->GetMeanError(); hrsp[i][j]->SetLineColor(1); hrsp[i][j]->SetMarkerColor(1); hrsp[i][j]->SetMarkerStyle(20); if(j==0)l0->AddEntry(hrsp[i][j],Form("R = %0.1f",(i+1)*0.1),"p"); //if(i==0)cout <<" refpt : " << refpt << " rawpt : " << jetpt << endl; //if(j<10)hrsp[i][j]->Rebin(2); //hrsp[i][j]->Rebin(5); double norm = hrsp[i][j]->GetMaximumStored(); double rms = hrsp[i][j]->GetRMS(); double peak = hrsp[i][j]->GetMean(); //double peak = (GetPeak(hrsp[i][j]) + hrsp[i][j]->GetMean())/2.; double epeak = hrsp[i][j]->GetMeanError(); // double tmppeak = GetPeak(hrsp[i][j]); // fgaus = new TF1("fgaus","gaus", 0.07, 1.2); // fgaus->SetParameters(norm, peak, 0.15); // //fgaus->SetParLimits(1, peak - 1.5*rms, peak + 1.5*rms); // int fitstatus = hrsp[i][j]->Fit(fgaus,"QR"); // peak = (fgaus==0) ? hrsp[i][j]->GetMean() : fgaus->GetParameter(1); // epeak = (fgaus==0) ? hrsp[i][j]->GetMeanError() : fgaus->GetParError(1); // if(i==0)fit_dscb(hrsp[i][j], 1.03, minx, 5, Form("%s%s",calgo[i],ctype), 0.17, 1.70); // else if(i==5)fit_dscb(hrsp[i][j], 1.00, minx, 5, Form("%s%s",calgo[i],ctype), 0.05, 1.45); // else fit_dscb(hrsp[i][j], 1.03, minx, 5, Form("%s%s",calgo[i],ctype), 0.10, 1.50); if(i==0)fit_dscb(hrsp[i][j], 1.03, minx, 5, Form("%s%s",calgo[i],ctype), 0.17, 1.70); else if(i !=5 )fit_dscb(hrsp[i][j], 1.03, minx, 5, Form("%s%s",calgo[i],ctype), 0.10, 1.50); //! pp reco // if( i==0 )fit_dscb(hrsp[i][j], 0.85, minx, 5, Form("%s%s",calgo[i],ctype)); // else if(i==1)fit_dscb(hrsp[i][j], 1.03, minx, 5, Form("%s%s",calgo[i],ctype)); // else if(i==2)fit_dscb(hrsp[i][j], 1.00, minx, 5, Form("%s%s",calgo[i],ctype)); // else if(i==3)fit_dscb(hrsp[i][j], 1.05, minx, 5, Form("%s%s",calgo[i],ctype)); // else if(i==4)fit_dscb(hrsp[i][j], 1.05, minx, 5, Form("%s%s",calgo[i],ctype)); // else fit_dscb(hrsp[i][j], 1.00, minx, 5, Form("%s%s",calgo[i],ctype)); //! HI reco // if( i==0 )fit_dscb(hrsp[i][j], 0.75, minx, 5, Form("ak%d%s",i+1,ctype)); // else if(i==1)fit_dscb(hrsp[i][j], 0.95, minx, 5, Form("ak%d%s",i+1,ctype)); // else if(i==2)fit_dscb(hrsp[i][j], 1.45, minx, 5, Form("ak%d%s",i+1,ctype)); // else if(i==3 || i==4)fit_dscb(hrsp[i][j], 1.50, minx, 4, Form("ak%d%s",i+1,ctype)); // else fit_dscb(hrsp[i][j], 1.30, minx, 5, Form("ak%d%s",i+1,ctype)); TF1* frelrsp = (TF1*)hrsp[i][j]->GetListOfFunctions()->Last(); peak = (frelrsp==0) ? hrsp[i][j]->GetMean() : frelrsp->GetParameter(1); epeak = (frelrsp==0) ? hrsp[i][j]->GetMeanError() : frelrsp->GetParError(1); //cout << " peak : " << peak << " mean : " << hrsp[i][j]->GetMean() << " " << frelrsp->GetParameter(1) << endl; double cor = 1.0/peak; double ecor = cor*cor*epeak; //if(i==0)cout <<ptbins[j] << " ratio of " << refpt/jetpt << " " << cor << " " << ftemp->Eval(jetpt) << " " << 1/ ftemp->Eval(jetpt) << endl; grsp[i]->SetPoint (j, refpt, peak); grsp[i]->SetPointError(j, erefpt, epeak); gcor[i]->SetPoint (j, jetpt, cor); gcor[i]->SetPointError(j, ejetpt, ecor); } } if( gPad )gPad->Close(); //hrsp[0][0]->Draw("p"); //return 0; int ipad=0; //! 0 - 20 GeV TCanvas *c98[knj]; for(int nj=njmin;nj<njmax;nj++){ c98[nj] = new TCanvas(Form("c99_%d",nj),Form("Fine %s Fitting plots",calgo[nj]),100,102,1399,942); c98[nj]->Divide(6,3,0,0); //c98[nj]->Divide(10,5,0,0); //c98[nj]->Divide(6,5,0,0); //c98[nj]->Divide(7,4,0,0); //c98[nj]->Divide(6,4,0,0); ipad=0; for(int ip=0;ip<nbins;ip++){ if(ptbins[ip]<minx)continue; c98[nj]->cd(++ipad); gPad->SetLeftMargin(0.15); gPad->SetRightMargin(0.01); gPad->SetBottomMargin(0.15); gPad->SetLogy(); //if(ipad%10==0)gPad->SetRightMargin(0.02); //if(ipad%(ip+1)==0)gPad->SetLeftMargin(0.15); //hrsp[nj][ip]->SetMaximum(hrsp[nj][ip]->GetMaximum() + 0.25*hrsp[nj][ip]->GetMaximum()); hrsp[nj][ip]->SetMaximum(hrsp[nj][ip]->Integral()*2e-00); hrsp[nj][ip]->SetMinimum(hrsp[nj][ip]->Integral()*1e-07); hrsp[nj][ip]->SetTitle(0); hrsp[nj][ip]->GetXaxis()->SetTitle("<reco jet p_{T} / gen jet p_{T}>"); hrsp[nj][ip]->GetXaxis()->SetTitleFont(42); hrsp[nj][ip]->GetXaxis()->SetLabelFont(42); hrsp[nj][ip]->GetXaxis()->SetLabelSize(0.08); hrsp[nj][ip]->GetXaxis()->SetTitleSize(0.07); hrsp[nj][ip]->GetXaxis()->SetNdivisions(507); hrsp[nj][ip]->GetYaxis()->SetTitle(""); hrsp[nj][ip]->GetYaxis()->SetTitleFont(42); hrsp[nj][ip]->GetYaxis()->SetLabelFont(42); hrsp[nj][ip]->GetYaxis()->SetLabelSize(0.08); hrsp[nj][ip]->GetYaxis()->SetNdivisions(507); hrsp[nj][ip]->SetMarkerStyle(20); hrsp[nj][ip]->SetMarkerColor(1); hrsp[nj][ip]->SetLineColor(1); hrsp[nj][ip]->SetMarkerSize(1.1); hrsp[nj][ip]->Draw("hist"); TF1 *fdscb = (TF1*)hrsp[nj][ip]->GetFunction("fdscb"); if(fdscb){ fdscb->SetLineWidth(1); fdscb->SetLineColor(2); fdscb->SetLineColor(2); fdscb->Draw("lsame"); } TF1 *fgaus = (TF1*)hrsp[nj][ip]->GetFunction("fgaus"); if(fgaus){ fgaus->SetLineWidth(1); fgaus->SetLineColor(4); fgaus->Draw("lsame"); } // TF1 *fdg = (TF1*)hrsp[nj][ip]->GetFunction("fdgaus"); // if(fdg){ // TF1 *fg1 = (TF1*)hrsp[nj][ip]->GetFunction("fg1"); // TF1 *fg2 = (TF1*)hrsp[nj][ip]->GetFunction("fg2"); // fdg->Draw("lsame"); // fg1->Draw("lsame"); // fg2->Draw("lsame"); // } std::ostringstream strs; strs << ptbins[ip] << "< p_{T} (GeV/c) <" << ptbins[ip+1]; std::string spt = strs.str(); if(ipad==1){drawText2(Form("%s%s",calgo[nj],ctype),0.28,0.90,18); drawText2(spt.c_str(),0.22,0.80,15); } else drawText2(spt.c_str(),0.17,0.80,15); } //if(nj!=0)c98[nj]->Close(); //if( strcmp(calgo[nj],"ak4")!=0 )c98[nj]->Close(); } //return 0; cout << endl; cout << endl; cout << "Fitting the L3 Response " << endl; //cout << endl; //cout << endl; TF1 *fitrsp=0, *fitcor=0; std::string fcn_rsp=""; std::string fcn_cor=""; //! Org // fcn_rsp="[0]-[1]/(pow(log10(x),[2])+[3])"; // fcn_cor="[0]+[1]/(pow(log10(x),[2])+[3])"; //! Using this one //fcn_rsp="[0]-[1]/(pow(log10(x),[2])+[3])+[4]/x"; //fcn_cor="[0]+[1]/(pow(log10(x),[2])+[3])-[4]/x"; fcn_rsp="[0]-[1]/(pow(log10(x),[2])+[3])+[4]/x+[5]/x/x"; fcn_cor="[0]+[1]/(pow(log10(x),[2])+[3])-[4]/x-[5]/x/x"; // double *rawpt = 0; // double *genpt = 0; TCanvas *c11 = new TCanvas("c11","L3 Response",1217,707/*1531,683*/); c11->Divide(3,2); TCanvas *c12 = new TCanvas("c12","L3 Corrections",1217,707/*1531,683*/); c12->Divide(3,2); for(int i=njmin; i<njmax; i++){ c11->cd(i+1); fitrsp = new TF1("fitrsp",fcn_rsp.c_str(), minx, grsp[i]->GetX()[grsp[i]->GetN()-1]); fitrsp->SetParameter(0,1.0); fitrsp->SetParameter(1,1.0); fitrsp->SetParameter(2,1.0); fitrsp->SetParameter(3,1.0); fitrsp->SetParameter(4,1.0); fitrsp->SetParameter(5,1.0); grsp[i]->Fit(fitrsp,"QR"); //if( i<knj )grsp[i]->Fit(fitrsp,"QR","",grsp[i]->GetX()[1],grsp[i]->GetX()[grsp[i]->GetN()-1]); //else grsp[i]->Fit(fitrsp,"QR"); grsp[i]->SetMaximum(1.2); grsp[i]->SetMinimum(0.2); grsp[i]->Draw("ap"); gPad->SetLogx(); gPad->SetLeftMargin(0.15); gPad->SetBottomMargin(0.15); gPad->Update(); grsp[i]->GetXaxis()->SetTitle("< Ref p_{T} > (GeV/c)"); grsp[i]->GetXaxis()->SetTitleFont(42); grsp[i]->GetXaxis()->SetLabelFont(42); grsp[i]->GetXaxis()->SetLabelSize(0.06); grsp[i]->GetXaxis()->SetTitleSize(0.06); grsp[i]->GetXaxis()->SetNdivisions(507); grsp[i]->GetXaxis()->SetNoExponent(); grsp[i]->GetXaxis()->SetMoreLogLabels(); grsp[i]->GetYaxis()->SetTitle("L3 Response"); grsp[i]->GetYaxis()->SetTitleFont(42); grsp[i]->GetYaxis()->SetLabelFont(42); grsp[i]->GetYaxis()->SetLabelSize(0.06); grsp[i]->GetYaxis()->SetTitleSize(0.06); grsp[i]->GetYaxis()->SetNdivisions(507); grsp[i]->GetYaxis()->SetRangeUser(0,1.160); //grsp[i]->GetXaxis()->SetRangeUser(15,600); drawText2(Form("%s%s",calgo[i],ctype),0.20,0.78,21); TPaveStats *strsp = (TPaveStats*)grsp[i]->FindObject("stats"); strsp->SetX1NDC(0.46); strsp->SetY1NDC(0.18); strsp->SetX2NDC(0.87); strsp->SetY2NDC(0.59); strsp->Draw(); //delete fitrsp; //continue; c12->cd(i+1); //cout << endl; //cout << endl; // cout << "Fitting the L3 Corrections " << endl; // cout << endl; fitcor = new TF1("fitcor",fcn_cor.c_str(), minx, gcor[i]->GetX()[gcor[i]->GetN()-1]); fitcor->SetParameter(0,1.0); fitcor->SetParameter(1,1.0); fitcor->SetParameter(2,1.0); fitcor->SetParameter(3,1.0); fitcor->SetParameter(4,1.0); fitcor->SetParameter(5,1.0); gcor[i]->Fit(fitcor,"QR"); //if(i<knj)gcor[i]->Fit(fitcor,"QR","",gcor[i]->GetX()[1],gcor[i]->GetX()[gcor[i]->GetN()-1]); //else gcor[i]->Fit(fitcor,"QR"); string algn=Form("%d",i+1); string era="JEC_pp_PYTHIA_TuneCUETP8M1_5020GeV_patch3"; //string era="JEC_pp_HIReco_PYTHIA_TuneCUETP8M1_5020GeV_patch3"; string txtfilename = outdir+era+"_L3Absolute_AK"+algn+"Calo.txt"; ofstream outf(txtfilename.c_str()); //outf.setf(ios::left); //cout<<"{1 JetEta 1 JetPt "<<fcn_cor<<" Correction L3Absolute}"<<endl; outf<<"{1 JetEta 1 JetPt "<<fcn_cor<<" Correction L3Absolute}"<<endl; // cout<<setw(12)<<-3.000 // eta_min // <<setw(12)<<+3.000 // eta_max // <<setw(12)<<fitcor->GetNpar()+2 // number of parameters + 2 // <<setw(12)<<7.0 // minimum pT // <<setw(11)<<1000.0; // maximum pT outf<<setw(12)<<-3.000 // eta_min <<setw(12)<<+3.000 // eta_max <<setw(12)<<fitcor->GetNpar()+2 // number of parameters + 2 <<setw(12)<<7.0 // minimum pT <<setw(12)<<1000.0; // maximum pT for(int p=0; p<fitcor->GetNpar(); p++){ //cout<<setw(12)<<fitcor->GetParameter(p); // p0-p4 outf<<setw(12)<<fitcor->GetParameter(p); // p0-p4 } outf.close(); //cout<<endl; // if(i==0)cout <<Form("if(i==%d)fl3cor->SetParameters(",i); // else cout <<Form("else if(i==%d)fl3cor->SetParameters(",i); // for(int p=0; p<fitcor->GetNpar(); p++){ // if(p==fitcor->GetNpar()-1)cout<<setw(12)<<fitcor->GetParameter(p); // p0-p4 // else cout<<setw(12)<<fitcor->GetParameter(p)<<","; // p0-p4 // } // cout <<");"<<endl; // rawpt = gcor[i]->GetX(); // genpt = grsp[i]->GetX(); // for(int ix=0; ix<gcor[i]->GetN(); ix++){ // double cor_fac = fitcor->Eval(rawpt[ix]); // double corrpt = cor_fac*rawpt[ix]; // //std::cout << " genpt : " << genpt[ix] << " rawpt : " << rawpt[ix] << " corrpt : " << corrpt << " cor_fac : " << cor_fac << std::endl; // std::cout << genpt[ix] << " : " << (fabs(corrpt - genpt[ix])/genpt[ix])*100. << std::endl; // } // gcor[i]->GetXaxis()->SetRangeUser(15,600); gcor[i]->SetMaximum(3.35); gcor[i]->SetMinimum(0.89); gcor[i]->Draw("ap"); gPad->SetLogx(); gPad->SetLeftMargin(0.15); gPad->SetBottomMargin(0.15); gPad->Update(); gcor[i]->GetXaxis()->SetTitle("< raw jet p_{T} > (GeV/c)"); gcor[i]->GetXaxis()->SetTitleFont(42); gcor[i]->GetXaxis()->SetLabelFont(42); gcor[i]->GetXaxis()->SetLabelSize(0.06); gcor[i]->GetXaxis()->SetTitleSize(0.06); gcor[i]->GetXaxis()->SetNdivisions(507); gcor[i]->GetXaxis()->SetNoExponent(); gcor[i]->GetXaxis()->SetMoreLogLabels(); gcor[i]->GetYaxis()->SetTitle("L3 Correction"); gcor[i]->GetYaxis()->SetTitleFont(42); gcor[i]->GetYaxis()->SetLabelFont(42); gcor[i]->GetYaxis()->SetLabelSize(0.06); gcor[i]->GetYaxis()->SetTitleSize(0.06); gcor[i]->GetYaxis()->SetNdivisions(507); gcor[i]->GetXaxis()->SetMoreLogLabels(); gcor[i]->GetXaxis()->SetNoExponent(); drawText2(Form("%s%s",calgo[i],ctype),0.20,0.78,21); TPaveStats *stcor = (TPaveStats*)gcor[i]->FindObject("stats"); stcor->SetX1NDC(0.48); stcor->SetY1NDC(0.53); stcor->SetX2NDC(0.89); stcor->SetY2NDC(0.89); stcor->Draw(); // cout << endl; //delete fitcor; } if(iSave){ c12->SaveAs("CorrectionPlots/L3Absolute_Corrections_ppReco_CaloJets_757p1.pdf"); } TFile *fout = new TFile("l3calo_input.root","RECREATE"); for(int nj=njmin;nj<njmax;nj++){ fout->mkdir(Form("%sCaloJetAnalyzer",calgo[nj]),Form("%sCaloJetAnalyzer",calgo[nj])); fout->cd(Form("%sCaloJetAnalyzer",calgo[nj])); grsp[nj]->Write(); gcor[nj]->Write(); fout->cd("../"); } fout->Close(); return 0; }
int analyzer() { // gROOT->Macro("/afs/cern.ch/user/a/amartell/public/setStyle.C"); // need to set these configurable from cfg and change into a vector std::string inputFolder = "/store/group/upgrade/HGCAL/TimingTB_H2_Apr2016/recoTrees/"; // std::string runN = "3772";// d=200 micrometer // std::string runN = "3737";// d=120 micrometer // TChain* tree = new TChain("H4treeReco"); // tree->Add(("root://eoscms/"+inputFolder+"RECO_"+runN+".root").c_str()); std::string runN; TChain* tree = new TChain("H4treeReco"); runN = "3737"; tree->Add(("root://eoscms/"+inputFolder+"RECO_"+runN+".root").c_str()); runN = "3751"; tree->Add(("root://eoscms/"+inputFolder+"RECO_"+runN+".root").c_str()); runN = "3752"; tree->Add(("root://eoscms/"+inputFolder+"RECO_"+runN+".root").c_str()); runN = "3753"; tree->Add(("root://eoscms/"+inputFolder+"RECO_"+runN+".root").c_str()); Long64_t nentries = tree->GetEntries(); std::cout << " Tree loaded events = " << nentries << std::endl; //Tree variables UInt_t nwc; Float_t wc_recox[16], wc_recoy[16]; UInt_t maxch; Float_t group[100],ch[100]; Float_t pedestal[100], pedestalRMS[100], pedestalSlope[100]; Float_t wave_max[100], wave_max_aft[100], wave_aroundmax[100][50], time_aroundmax[100][50]; Float_t charge_integ[100], charge_integ_max[100], charge_integ_fix[100]; Float_t charge_integ_smallw[100], charge_integ_smallw_noise[100], charge_integ_largew[100], charge_integ_largew_noise[100]; Float_t t_max[100], t_max_frac30[100], t_max_frac50[100], t_at_threshold[100], t_over_threshold[100]; //Read tree tree->SetBranchAddress("nwc", &nwc); tree->SetBranchAddress("wc_recox", wc_recox); tree->SetBranchAddress("wc_recoy", wc_recoy); tree->SetBranchAddress("maxch", &maxch); tree->SetBranchAddress("group", group); tree->SetBranchAddress("ch", ch); tree->SetBranchAddress("pedestal", pedestal); tree->SetBranchAddress("pedestalRMS", pedestalRMS); tree->SetBranchAddress("pedestalSlope", pedestalSlope); tree->SetBranchAddress("wave_max", wave_max); tree->SetBranchAddress("wave_max_aft", wave_max_aft); tree->SetBranchAddress("wave_aroundmax", wave_aroundmax); tree->SetBranchAddress("time_aroundmax", time_aroundmax); tree->SetBranchAddress("charge_integ", charge_integ); tree->SetBranchAddress("charge_integ_max", charge_integ_max); tree->SetBranchAddress("charge_integ_fix", charge_integ_fix); tree->SetBranchAddress("charge_integ_smallw", charge_integ_smallw); tree->SetBranchAddress("charge_integ_largew", charge_integ_largew); tree->SetBranchAddress("charge_integ_smallw_noise", charge_integ_smallw_noise); tree->SetBranchAddress("charge_integ_largew_noise", charge_integ_largew_noise); tree->SetBranchAddress("t_max", t_max); tree->SetBranchAddress("t_max_frac30", t_max_frac30); tree->SetBranchAddress("t_max_frac50", t_max_frac50); tree->SetBranchAddress("t_at_threshold", t_at_threshold); tree->SetBranchAddress("t_over_threshold", t_over_threshold); //Histos => needs to expand const int N_channel = 8; // maxch = 8 TString SiPad_name[N_channel] = {"Trigger","SiPad6","SiPad5","SiPad4","SiPad1","SiPad2","SiPad3","Not_Revelent"}; TH1F* h_wave_max[N_channel]; TH1F* h_charge_integ[N_channel]; TH2F* h_WaveMax_to_ChargeInteg[N_channel]; TH2F* h_WC_0[N_channel]; for(int channel=0; channel<N_channel; channel++){ TString h_name1 = "h_wave_max_" + SiPad_name[channel] ; TString h_name2 = "h_charge_integ_" + SiPad_name[channel] ; TString h_name3 = "h_WaveMax_to_ChargeInteg_"+ SiPad_name[channel] ; TString h_name4 = "h_WireChamber_0_weighted_to_" + SiPad_name[channel] ; int NBins_wave_max = 75 ; double L_wave_max = -50 ; double H_wave_max = 700; int NBins_charge_integ = 55; double L_charge_integ = -1000; double H_charge_integ = 10000; h_wave_max[channel] = new TH1F(h_name1, h_name1, NBins_wave_max , L_wave_max , H_wave_max ); h_charge_integ[channel] = new TH1F(h_name2, h_name2, NBins_charge_integ , L_charge_integ,H_charge_integ ); h_WaveMax_to_ChargeInteg[channel] = new TH2F(h_name3 ,h_name3, NBins_wave_max , L_wave_max , H_wave_max , NBins_charge_integ, L_charge_integ, H_charge_integ); h_WC_0[channel] = new TH2F(h_name4 ,h_name4, 60, -12, 18, 48, -20, 4); }// end channel loop int channel_fix =4;// fix channel-4 for SiPad-1 in time measurement // int channel_fix =1;// SiPad-6 TH1F* h_TimeFrac30_Diff_Xto1[N_channel]; int N_bin_TimeDiff = 400; double time_low = -20; double time_high = 20; TH2F* h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[N_channel]; for(int channel=0; channel<N_channel; channel++){ if(channel==0 || channel==7){continue;} if(channel == channel_fix ){continue;} // TString h_name5 = Form("h_TimeFrac30_Diff_Pad%d_to_Pad%d",channel,channel_fix ); TString h_name5 = "h_TimeFrac30_Diff_" + SiPad_name[channel] + "_to_" + SiPad_name[channel_fix]; h_TimeFrac30_Diff_Xto1[channel] = new TH1F(h_name5, h_name5, N_bin_TimeDiff ,time_low ,time_high ); // TString h_name6 = Form("h_TimeFrac30_Diff_Pad%d_to_Pad%d_vs_WaveMax_Pad%d",channel,channel_fix,channel ); TString h_name6 = "h_TimeFrac30_Diff_" + SiPad_name[channel] + "_to_" + SiPad_name[channel_fix] + "_vs_WaveMax_" + SiPad_name[channel]; // TString h_name6 = "h_TimeFrac30_Diff_" + SiPad_name[channel] + "_to_" + SiPad_name[channel_fix] + "_vs_WaveMax_" + SiPad_name[channel_fix]; h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel] = new TH2F(h_name6,h_name6, N_bin_TimeDiff, time_low, time_high, 75, -50, 700); } TH2F* h_WC_0_no_weight = new TH2F("h_WC_0_no_weight" ,"h_WC_0_no_weight", 60,-12,18, 48,-20,4); TH2F* h_WC_1_no_weight = new TH2F("h_WC_1_no_weight" ,"h_WC_1_no_weight", 60,-12,18, 48,-20,4); //TGraph for wave/time around max const int nTGraph = 16; TGraph* gr[nTGraph][N_channel]; int fill_times =0; int channel_around_max = 4;// show wave/time around max of SiPad-1 int event_index[nTGraph] = {0}; int Max_event_times_to_read ; // Max_event_times_to_read = 1000; Max_event_times_to_read = -1; if (Max_event_times_to_read==-1){ cout<<"number of events used: "<< nentries << endl;} else{ cout<<"number of events used: "<< Max_event_times_to_read << endl;} /* // first event loop to find the X_mean_diff and Y_mean_diff for (Long64_t jentry=0; jentry<nentries; ++jentry){ if(jentry> Max_event_times_to_read && Max_event_times_to_read!=-1 ) break; if (jentry % 5000 == 0) fprintf(stderr, "Processing event %lli of %lli\n", jentry + 1, nentries ); tree->GetEntry(jentry); // find acceptance region h_WC_0_no_weight->Fill(wc_recox[0], wc_recoy[0]); h_WC_1_no_weight->Fill(wc_recox[1], wc_recoy[1]); }// end event loop cout<<"WC_0_X_mean: "<< h_WC_0_no_weight->GetMean(1) << endl; cout<<"WC_0_Y_mean: "<< h_WC_0_no_weight->GetMean(2) << endl; cout<<"WC_1_X_mean: "<< h_WC_1_no_weight->GetMean(1) << endl; cout<<"WC_1_Y_mean: "<< h_WC_1_no_weight->GetMean(2) << endl; double WC_X_mean_diff = h_WC_0_no_weight->GetMean(1) - h_WC_1_no_weight->GetMean(1); double WC_Y_mean_diff = h_WC_0_no_weight->GetMean(2) - h_WC_1_no_weight->GetMean(2); */ // double WC_X_mean_diff = -3.15949; // double WC_Y_mean_diff = -0.726348; double WC_X_mean_diff = -3.351; // Binghuan's value double WC_Y_mean_diff = -0.706; // Binghuan's value cout<<"WC_X_mean_diff: "<< WC_X_mean_diff << endl; cout<<"WC_Y_mean_diff: "<< WC_Y_mean_diff << endl; //loop over entries for (Long64_t jentry=0; jentry<nentries; ++jentry){ if(jentry> Max_event_times_to_read && Max_event_times_to_read!=-1 ) break; if (jentry % 5000 == 0) fprintf(stderr, "Processing event %lli of %lli\n", jentry + 1, nentries ); //readout the event tree->GetEntry(jentry); // cout<<"pedestal[4]: "<< pedestal[4]<< endl; // cout<<"pedestalRMS[4]: "<< pedestalRMS[4]<< endl; // selection to be in the high acceptance region of both wire chambers bool fiducial_cut_basic = false; if(abs(wc_recox[0]-wc_recox[1] - WC_X_mean_diff ) <1 && abs(wc_recoy[0]-wc_recoy[1] - WC_Y_mean_diff) < 1){ fiducial_cut_basic = true; } // cut on SiPad region bool SiPad_region_cut = false; if( wc_recox[0] >-4 && wc_recox[0] <16 && wc_recoy[0] >-19 && wc_recoy[0] <-7 ){ SiPad_region_cut = true;} // ------------------------------------------------- // wave_max v.s charge correlation for(int channel=0; channel<N_channel; channel++){ if(channel==0 || channel==7){continue;} // if (!fiducial_cut_basic)continue; // if(wave_max[channel]<0){ // cout<<"jentry: "<< jentry << endl; // cout<<"channel: "<< channel << endl; // cout<<"wave_max[channel]: "<< wave_max[channel] << endl; // } if(wave_max[channel]<0)continue; // if(wave_max[channel]<150)continue; // if(wave_max[channel]>150)continue; // if(! SiPad_region_cut ) {continue;} // inside the region if( SiPad_region_cut ) {continue;} // outside the region h_WC_0[channel] -> Fill( wc_recox[0] , wc_recoy[0] , wave_max[channel] ); // if(! SiPad_region_cut ) {continue;} // inside the region // if( SiPad_region_cut ) {continue;} // outside the region // if(wave_max[channel]<150)continue; h_wave_max[channel] ->Fill( wave_max[channel] ); h_charge_integ[channel] ->Fill( charge_integ[channel] ); h_WaveMax_to_ChargeInteg[channel] ->Fill( wave_max[channel] , charge_integ[channel] ); }// end channel loop // ------------------------------------------------- // time measurement v.s wave_max double wave_max_threshold; // wave_max_threshold = 0; // wave_max_threshold = 150; // wave_max_threshold = 250; // wave_max_threshold = 350; // wave_max_threshold = 450; // wave_max_threshold = 550; // wave_max_threshold = 650; // wave_max_threshold = 750; wave_max_threshold = 850; for(int channel=0; channel<N_channel; channel++){ if(channel==0 || channel==7){continue;} if(channel == channel_fix){continue;} if (!fiducial_cut_basic)continue; if(wave_max[ channel_fix ]< wave_max_threshold){continue;} double t_frac30_diff = t_max_frac30[channel] - t_max_frac30[channel_fix] ; h_TimeFrac30_Diff_Xto1[channel]->Fill( t_frac30_diff ); h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->Fill( t_frac30_diff , wave_max[ channel ] ); } // ------------------------------------------------- // fill 10 event's wave/time around max (plot channel 1 ) if (fill_times < nTGraph && wave_max[channel_around_max]>0 && fiducial_cut_basic // && wave_max[channel_around_max]>150 // && SiPad_region_cut && (wave_max[channel_around_max]<150 && !SiPad_region_cut) // inverted cut ){ double wave_around_max[50] = {0}; double time_around_max[50] = {0}; for (int sample=0;sample<50;sample++){ wave_around_max[sample] = wave_aroundmax[channel_around_max][sample]; time_around_max[sample] = time_aroundmax[channel_around_max][sample]; time_around_max[sample] = time_around_max[sample] *1000000000; }// end sample loop gr[fill_times][channel_around_max] = new TGraph(50,time_around_max,wave_around_max); event_index[fill_times] = jentry; // cout<<"event_index[fill_times]: "<< event_index[fill_times] << endl; fill_times = fill_times + 1; }// end if }// end event loop // save TString path_name = "/afs/cern.ch/user/y/yuchang/www/HGCAL_TestBeam/Correlation_and_TimeMeasurement/" ; TString save_name = "WaveMax_to_ChargeInteg_correlation"; save_name = path_name + save_name + ".pdf"; TCanvas *c1 = new TCanvas("c1","",200,10,700,500); double newx1 = 0.5; double newx2 = 0.7; double newy1 = 0.7; double newy2 = 0.9; for(int channel=0; channel<N_channel; channel++){ c1->cd(); h_wave_max[channel] ->GetXaxis()->SetTitle("wave_max"); h_wave_max[channel] ->GetYaxis()->SetTitle("number of events"); h_charge_integ[channel] ->GetXaxis()->SetTitle("charge_integ"); h_charge_integ[channel] ->GetYaxis()->SetTitle("number of events"); h_WaveMax_to_ChargeInteg[channel]->GetXaxis()->SetTitle("wave_max"); h_WaveMax_to_ChargeInteg[channel]->GetYaxis()->SetTitle("charge_integ"); h_WaveMax_to_ChargeInteg[channel]->GetYaxis()->SetTitleOffset(1.3); double cor_factor = h_WaveMax_to_ChargeInteg[channel]->GetCorrelationFactor(); TString cor_legend_text = Form("correlation= %.3f" , cor_factor ); if (channel==0 || channel==7) continue; if (channel==1){ h_wave_max[channel] ->Draw(); c1->Print(save_name +"("); h_charge_integ[channel] ->Draw(); c1->Print(save_name ); h_WaveMax_to_ChargeInteg[channel] ->Draw() ; c1->Update(); TPaveStats *st =(TPaveStats*) h_WaveMax_to_ChargeInteg[channel]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); TLegend *leg = new TLegend(0.1,0.8,0.4,0.9); leg->SetHeader(cor_legend_text); leg->Draw(); c1->Update(); c1->Print(save_name); h_WaveMax_to_ChargeInteg[channel] ->Draw("colz"); leg->Draw(); c1->Update(); c1->Print(save_name); } if (channel!=1 && channel!=6){ h_wave_max[channel] ->Draw(); c1->Print(save_name ); h_charge_integ[channel] ->Draw(); c1->Print(save_name ); h_WaveMax_to_ChargeInteg[channel] ->Draw() ; c1->Update(); TPaveStats *st =(TPaveStats*) h_WaveMax_to_ChargeInteg[channel]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); TLegend *leg = new TLegend(0.1,0.8,0.4,0.9); leg->SetHeader(cor_legend_text); leg->Draw(); c1->Update(); c1->Print(save_name); h_WaveMax_to_ChargeInteg[channel] ->Draw("colz"); leg->Draw(); c1->Update(); c1->Print(save_name); } if (channel==6){ h_wave_max[channel] ->Draw(); c1->Print(save_name ); h_charge_integ[channel] ->Draw(); c1->Print(save_name ); h_WaveMax_to_ChargeInteg[channel] ->Draw() ; c1->Update(); TPaveStats *st =(TPaveStats*) h_WaveMax_to_ChargeInteg[channel]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); TLegend *leg = new TLegend(0.1,0.8,0.4,0.9); leg->SetHeader(cor_legend_text); leg->Draw(); c1->Update(); c1->Print(save_name); h_WaveMax_to_ChargeInteg[channel] ->Draw("colz"); leg->Draw(); c1->Update(); c1->Print(save_name +")"); } }// end channel //------------------------ TString save_name2 = "wave_and_time_aroundmax"; save_name2 = path_name + save_name2 + ".pdf"; for (int fill_times=0 ; fill_times < nTGraph ; fill_times++){ TCanvas *c2 = new TCanvas("c2","",200,10,700,500); c2->cd(); TString gr_title = "wave & time around max of " + SiPad_name[channel_around_max]; gr[fill_times][channel_around_max]->GetYaxis()->SetRangeUser(-50, 500); gr[fill_times][channel_around_max]->SetTitle(gr_title); gr[fill_times][channel_around_max]->GetXaxis()->SetTitle("time [ns]"); gr[fill_times][channel_around_max]->GetYaxis()->SetTitle("wave amplitude"); gr[fill_times][channel_around_max]->Draw(); TString event_number = Form("the %d-th event" , event_index[fill_times] ); TLegend *leg = new TLegend(0.1,0.8,0.4,0.9); leg->SetHeader(event_number); leg->Draw(); // cout<<"fill_times:"<< fill_times<<endl; if(fill_times == 0) {c2->Print(save_name2 +"(");} if(fill_times == nTGraph-1) {c2->Print(save_name2 +")");} if(fill_times != 0 && fill_times != nTGraph-1) {c2->Print(save_name2 );} } //------------------------ TString save_name3 = "wire_chamber_0_weighted_position"; save_name3 = path_name + save_name3 + ".pdf"; newx1= 0.7 ;newx2 =0.9 ; newy1 =0.7 ;newy2 =0.9 ; double Color_high = 10; for(int channel=0; channel<N_channel; channel++){ if(channel==0 || channel==7 )continue; double temp = h_WC_0[channel]->GetMaximum(); // cout<<"h_WC_0[channel]->GetMaximum(): "<< temp << endl; if(temp > Color_high){Color_high = temp;} } cout<<"Color_high: "<< Color_high << endl; TCanvas *c3 = new TCanvas("c3","",200,10,700,500); for(int channel=0; channel<N_channel; channel++){ h_WC_0[channel]->GetXaxis()->SetTitle("wc_recox[0] [mm]"); h_WC_0[channel]->GetYaxis()->SetTitle("wc_recoy[0] [mm]"); c3->cd(); h_WC_0[channel]->GetZaxis()->SetRangeUser(0, Color_high); h_WC_0[channel]->Draw("colz"); c3->Update(); TPaveStats *st =(TPaveStats*) h_WC_0[channel]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); if(channel==0 || channel==7) continue; if(channel==1){c3->Print(save_name3 +"(");} if(channel==6){c3->Print(save_name3 +")");} if(channel!=1 && channel!=6){c3->Print(save_name3 );} } //------------------------ TString save_name4 = "time_frac30_diff_to_wavemax"; save_name4 = path_name + save_name4 + ".pdf"; TCanvas *c4 = new TCanvas("c4","",200,10,700,500); int counter_plot =1; for(int channel=0; channel<N_channel; channel++){ if(channel==0 || channel==7 || channel== channel_fix) continue; // cout<<"counter_plot: "<< counter_plot << endl; // cout<<"channel: "<< channel << endl; h_TimeFrac30_Diff_Xto1[channel]->GetXaxis()->SetTitle("timefrac30diff [ns]"); h_TimeFrac30_Diff_Xto1[channel]->GetYaxis()->SetTitle("number of events"); h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->GetXaxis()->SetTitle("timefrac30diff [ns]"); h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->GetYaxis()->SetTitle("wave_max"); c4->cd(); double cor_factor2 = h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->GetCorrelationFactor(); TString cor_legend_text2 = Form("correlation= %.3f" , cor_factor2 ); if(counter_plot==1){ h_TimeFrac30_Diff_Xto1[channel]->Draw();c4->Print(save_name4 +"("); h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->Draw("colz"); c4->Update(); TPaveStats *st =(TPaveStats*) h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); TLegend *leg = new TLegend(0.1,0.8,0.4,0.9); leg->SetHeader(cor_legend_text2); leg->Draw(); c4->Print(save_name4 ); } if(counter_plot==5){ h_TimeFrac30_Diff_Xto1[channel]->Draw();c4->Print(save_name4 ); h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->Draw("colz"); c4->Update(); TPaveStats *st =(TPaveStats*) h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); TLegend *leg = new TLegend(0.1,0.8,0.4,0.9); leg->SetHeader(cor_legend_text2); leg->Draw(); c4->Print(save_name4 +")"); } if(counter_plot!=1 && counter_plot!=5){ h_TimeFrac30_Diff_Xto1[channel]->Draw();c4->Print(save_name4 ); h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->Draw("colz"); c4->Update(); TPaveStats *st =(TPaveStats*) h_TimeFrac30_Diff_Xto1_vs_WaveMax_ch1[channel]->GetListOfFunctions()->FindObject("stats"); st->SetX1NDC(newx1); st->SetX2NDC(newx2); st->SetY1NDC(newy1); st->SetY2NDC(newy2); TLegend *leg = new TLegend(0.1,0.8,0.4,0.9); leg->SetHeader(cor_legend_text2); leg->Draw(); c4->Print(save_name4 ); } counter_plot++; } //------------------------ TString save_name5 = "wire_chamber_position_no_weight"; save_name5 = path_name + save_name5 + ".pdf"; newx1= 0.7 ;newx2 =0.9 ; newy1 =0.7 ;newy2 =0.9 ; double max_value1 = h_WC_0_no_weight->GetMaximum(); double max_value2 = h_WC_1_no_weight->GetMaximum(); if(max_value1 > max_value2 ){Color_high = max_value1 ;} if(max_value1 < max_value2 ){Color_high = max_value2 ;} h_WC_0_no_weight->GetXaxis()->SetTitle("wc_recox[0] [mm]"); h_WC_0_no_weight->GetYaxis()->SetTitle("wc_recoy[0] [mm]"); h_WC_1_no_weight->GetXaxis()->SetTitle("wc_recox[1] [mm]"); h_WC_1_no_weight->GetYaxis()->SetTitle("wc_recoy[1] [mm]"); TCanvas *c5 = new TCanvas("c5","",200,10,700,500); c5->cd(); h_WC_0_no_weight->GetZaxis()->SetRangeUser(0, Color_high); h_WC_0_no_weight->Draw("colz"); c5->Update(); TPaveStats *st_wc_1 =(TPaveStats*) h_WC_0_no_weight->GetListOfFunctions()->FindObject("stats"); st_wc_1->SetX1NDC(newx1); st_wc_1->SetX2NDC(newx2); st_wc_1->SetY1NDC(newy1); st_wc_1->SetY2NDC(newy2); c5->Print(save_name5 +"("); h_WC_1_no_weight->GetZaxis()->SetRangeUser(0, Color_high); h_WC_1_no_weight->Draw("colz"); c5->Update(); TPaveStats *st_wc_2 =(TPaveStats*) h_WC_1_no_weight->GetListOfFunctions()->FindObject("stats"); st_wc_2->SetX1NDC(newx1); st_wc_2->SetX2NDC(newx2); st_wc_2->SetY1NDC(newy1); st_wc_2->SetY2NDC(newy2); c5->Print(save_name5 +")"); // end return 0; }
void many_plots2(int first = 5808, int last = 11688, int mask = 0x801E) { TH1D *h[12][2]; int i, j; char str[64]; TCanvas *cv[2]; TPaveStats *st; float y, dy; gROOT->SetStyle("Plain"); gStyle->SetOptStat(1000000); gStyle->SetOptFit(); TFile *fRoot = new TFile("many_plots.root", "RECREATE"); HPainter *p = new HPainter(mask, first, last); p->SetFile(fRoot); if (!p->IsOpen()) { printf("Something wrong with data files.\n"); return; } TCut cVeto("gtFromVeto > 60"); TCut cIso("(gtFromPrevious > 45 && gtToNext > 80 && EventsBetween == 0) || (gtFromPrevious == gtFromVeto)"); TCut cX("PositronX[0] < 0 || (PositronX[0] > 2 && PositronX[0] < 94)"); TCut cY("PositronX[1] < 0 || (PositronX[1] > 2 && PositronX[1] < 94)"); TCut cZ("PositronX[2] > 3.5 && PositronX[2] < 95.5"); TCut cXYZ = cX && cY && cZ; TCut cR("Distance < 100 && DistanceZ > -40 && DistanceZ < 40"); TCut cT10("gtDiff > 1"); TCut cT20("gtDiff > 2"); TCut cT200("gtDiff < 20"); // strong cut TCut cGamma("AnnihilationEnergy < 1.5 && AnnihilationGammas < 9"); TCut cPe("PositronEnergy > 1"); TCut cXY("PositronX[0]>=0 && PositronX[1]>=0"); TCut cN4("NeutronEnergy > 4 && NeutronHits >= 5"); for (i=0; i<2; i++) { sprintf(str, "hR%d", i); h[0][i] = new TH1D(str, "Distance between positron and neutron;R, cm;mHz", 40, 0, 160); sprintf(str, "hRZ%d", i); h[1][i] = new TH1D(str, "Distance between positron and neutron, projection Z;R_{z}, cm;mHz", 100, -100, 100); sprintf(str, "hT%d", i); h[2][i] = new TH1D(str, "Time between positron and neutron;T, us;mHz", 50, 0, 50); sprintf(str, "hX%d", i); h[3][i] = new TH1D(str, "Positron vertex X;X, cm;mHz", 25, 0, 100); sprintf(str, "hY%d", i); h[4][i] = new TH1D(str, "Positron vertex Y;Y, cm;mHz", 25, 0, 100); sprintf(str, "hZ%d", i); h[5][i] = new TH1D(str, "Positron vertex Z;Z, cm;mHz", 100, 0, 100); sprintf(str, "hNE%d", i); h[6][i] = new TH1D(str, "Energy detected in neutron capture;E_{n}, MeV;mHz", 50, 0, 10); sprintf(str, "hNN%d", i); h[7][i] = new TH1D(str, "Number of hits in SiPM for neutron capture;N_{n};mHz", 20, 0, 20); sprintf(str, "hGE%d", i); h[8][i] = new TH1D(str, "Energy beyond positron cluster;E_{#gamma}, MeV;mHz", 15, 0, 3); sprintf(str, "hGN%d", i); h[9][i] = new TH1D(str, "Number of SiPM hits out of positron cluster;N_{#gamma};mHz", 10, 0, 10); sprintf(str, "hE%d", i); h[10][i] = new TH1D(str, "Positorn kinetic energy;E, MeV;mHz", 40, 0, 8); sprintf(str, "hEC%d", i); h[11][i] = new TH1D(str, "Positorn kinetic energy, strong background cuts;E, MeV;mHz", 40, 0, 8); } printf("Histograms are created\n"); p->Project(h[0][0], "Distance", cVeto && cIso && cT20 && cGamma && cPe && cXYZ); p->Project(h[0][1], "Distance", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ); printf("Distance.\n"); p->Project(h[1][0], "DistanceZ", cVeto && cIso && cT20 && cGamma && cPe && cXYZ); p->Project(h[1][1], "DistanceZ", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ); printf("DistanceZ.\n"); p->Project(h[2][0], "gtDiff", cVeto && cIso && cT10 && cGamma && cPe && cXYZ && cR); p->Project(h[2][1], "gtDiff", !cVeto && cIso && cT10 && cGamma && cPe && cXYZ && cR); printf("gtDiff.\n"); p->Project(h[3][0], "PositronX[0]+2", cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR && "PositronX[0] >= 0"); p->Project(h[3][1], "PositronX[0]+2", !cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR && "PositronX[0] >= 0"); printf("X.\n"); p->Project(h[4][0], "PositronX[1]+2", cVeto && cIso && cT20 && cGamma && cPe && cX && cZ && cR && "PositronX[1] >= 0"); p->Project(h[4][1], "PositronX[1]+2", !cVeto && cIso && cT20 && cGamma && cPe && cX && cZ && cR && "PositronX[1] >= 0"); printf("Y.\n"); p->Project(h[5][0], "PositronX[2]+0.5", cVeto && cIso && cT20 && cGamma && cPe && cX && cY && cR); p->Project(h[5][1], "PositronX[2]+0.5", !cVeto && cIso && cT20 && cGamma && cPe && cX && cY && cR); printf("Z.\n"); p->Project(h[6][0], "NeutronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR); p->Project(h[6][1], "NeutronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cY && cZ && cR); printf("NE.\n"); p->Project(h[7][0], "NeutronHits", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); p->Project(h[7][1], "NeutronHits", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); printf("NN.\n"); p->Project(h[8][0], "AnnihilationEnergy", cVeto && cIso && cT20 && cPe && cXYZ && cR); p->Project(h[8][1], "AnnihilationEnergy", !cVeto && cIso && cT20 && cPe && cXYZ && cR); printf("AE.\n"); p->Project(h[9][0], "AnnihilationGammas", cVeto && cIso && cT20 && cPe && cXYZ && cR); p->Project(h[9][1], "AnnihilationGammas", !cVeto && cIso && cT20 && cPe && cXYZ && cR); printf("AG.\n"); p->Project(h[10][0], "PositronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); p->Project(h[10][1], "PositronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR); p->Project(h[11][0], "PositronEnergy", cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR && cN4 && cT200); p->Project(h[11][1], "PositronEnergy", !cVeto && cIso && cT20 && cGamma && cPe && cXYZ && cR && cN4 && cT200); printf("Projections are done\n"); for (i=0; i<12; i++) { for (j=0; j<2; j++) h[i][j]->SetLineWidth(4); h[i][0]->SetLineColor(kGreen); h[i][1]->SetLineColor(kRed); h[i][0]->SetMinimum(0); h[i][1]->SetMinimum(0); } // h[1][0]->Fit("gaus", "0"); // h[1][1]->Fit("gaus", "0"); // TF1 *fdec = new TF1("FDEC", "[0]*(exp(-x/[1]) - exp(-x/[2]))", 3); // fdec->SetParNames("Const", "t_{CAPTURE}", "t_{THERM}"); // fdec->SetParameters(h[2][0]->Integral()/4, 15, 5); // h[2][0]->Fit("FDEC", "0", "", 2, 50); for (i=0; i<2; i++) { sprintf(str, "CV%d", i); cv[i] = new TCanvas(str, "Plots", 1800, 1200); cv[i]->Divide(3, 2); for (j=0; j<6; j++) { cv[i]->cd(j+1); h[6*i+j][0]->Draw(); h[6*i+j][1]->Draw("sames"); gPad->Update(); if (i == 0 && j == 1) { st = (TPaveStats *) h[6*i+j][0]->FindObject("stats"); st->SetOptStat(1100); st->SetLineColor(kGreen); st->SetTextColor(kGreen); y = st->GetY1NDC(); dy = st->GetY2NDC() - y; st->SetX1NDC(0.72); st = (TPaveStats *) h[6*i+j][1]->FindObject("stats"); st->SetOptStat(1100); st->SetLineColor(kRed); st->SetTextColor(kRed); st->SetX1NDC(0.72); st->SetY2NDC(y); st->SetY1NDC(y - dy); } else { st = (TPaveStats *) h[6*i+j][0]->FindObject("stats"); st->SetLineColor(kGreen); st->SetTextColor(kGreen); y = st->GetY1NDC(); dy = st->GetY2NDC() - y; st->SetX1NDC(0.72); st->SetY1NDC(y + dy/2); st = (TPaveStats *) h[6*i+j][1]->FindObject("stats"); st->SetLineColor(kRed); st->SetTextColor(kRed); st->SetX1NDC(0.72); st->SetY2NDC(y + dy/2); } if (h[6*i+j][0]->GetMaximum() > h[6*i+j][1]->GetMaximum()) { h[6*i+j][0]->Draw(); h[6*i+j][1]->Draw("sames"); } else { h[6*i+j][1]->Draw(); h[6*i+j][0]->Draw("sames"); } gPad->Update(); } cv[i]->Update(); } fRoot->cd(); for (i=0; i<12; i++) for (j=0; j<2; j++) h[i][j]->Write(); fRoot->Close(); }
void loopdir( TFile *f1 ) { TIter next( f1->GetListOfKeys() ); TKey *k; //histos inside the file. TCanvas *c = new TCanvas( "c", "canvas", 800, 800 ); while( ( k = ( TKey * )next() ) ) { //loop over histos TClass *cl = gROOT->GetClass( k->GetClassName() ); std::cout << k->GetName() << std::endl; if( !cl->InheritsFrom( "TH1" ) ) { continue; } //make sure it is a histogram! TH1 *h1 = ( TH1 * )k->ReadObj(); //get handle on histo, cast as TH1 h1->SetBit( TH1::kNoTitle ); //don't print title std::ostringstream title; title << h1->GetName(); // std::cout << h1->GetName() << std::endl; // std::cout << (title.str().find("un")) << std::endl; // std::cout << (title.str().size()) << std::endl; // std::cout << ((title.str().find("un"))>title.str().size()) << std::endl; if( ( title.str().find( "hOverE" ) ) < title.str().size() ) { c->SetLogx(); std::cout << "[SETTING LOG X|" << std::endl; } else { c->SetLogx( 0 ); } if( ( title.str().find( "un" ) ) < title.str().size() ) {continue;} //if it contains "un", it is the 53x unmatched electrons. We use this later, when plotting vs the regular 53x electrons. so skip them now and access later. //std::cout << (title.str().find("5")) << std::endl; // PLOTS 53X vs 70X if( ( title.str().find( "5" ) ) < title.str().size() ) { // make sure the histo title contains 5. These are the regular 53x histos. c->cd(); TPad *pad1 = new TPad( "pad1", "pad1", 0, 0.3, 1, 1.0 ); //create pad for distributions pad1->SetBottomMargin( 0.05 ); pad1->SetGridx(); // Vertical grid pad1->Draw(); // Draw the upper pad: pad1 pad1->cd(); // pad1 becomes the current pad h1->SetStats( 0 ); // No statistics on upper plot // used to zoom to a more sensible range float xlo = 0; float xhi = 0; //find sensble lower axis range for( int n = 0 ; n < h1->GetNbinsX(); n++ ) { //std::cout << h1->GetBinContent(n) << std::endl; //if(n %1 ==0) std::cout << "test " << n << " " << h1->GetBinCenter(n) << " " << h1->GetBinContent(n) << std::endl; if( h1->GetBinContent( n ) < h1->GetEntries() / 10000 ) {continue ;} //basically picks out first bin with more than 100 events. xlo = h1->GetBinCenter( n - 1 ); break; } // find sensible upper axis range for( int n = h1->GetNbinsX(); n > -1 * h1->GetNbinsX() ; n-- ) { //std::cout << h1->GetBinContent(n) << std::endl; if( h1->GetBinContent( n ) < h1->GetEntries() / 10000 ) { continue; } //basically picks out first bin with more than 100 events. xhi = h1->GetBinCenter( n + 1 ); break; } // std::cout << xlo << " " << xhi << std::endl;; // if ((title.str().find("FBrem"))< title.str().size()){ // h1->GetXaxis()->SetRangeUser(0.01,xhi); // } // if ((title.str().find("hOverE"))< title.str().size()){ // h1->GetXaxis()->SetRangeUser(0.01,xhi); // std::cout << "hOverE" << std::endl; // }else{ h1->GetXaxis()->SetRangeUser( xlo, xhi ); // } if( ( title.str().find( "graph" ) ) < title.str().size() ) { h1->Draw( "h" ); } else { h1->DrawNormalized( "h" ); } std::string title2 = title.str().replace( title.str().find( "5" ), 1, "7" ); std::cout << title2 << std::endl; TKey *k2 = ( f1->GetKey( title2.c_str() ) ); //grab equivalent 70x histo TH1 *h2 = ( TH1 * )k2->ReadObj(); //cast as Th1 if( ( title.str().find( "graph" ) ) < title.str().size() ) { h2->Draw( "h same" ); // plot on same graph } else { h2->DrawNormalized( "h same" ); // plot on same graph } // Plot the ratio plot below c->cd(); // Go back to the main canvas before defining pad2 TPad *pad2 = new TPad( "pad2", "pad2", 0, 0.05, 1, 0.3 ); pad2->SetTopMargin( 0 ); pad2->SetBottomMargin( 0.2 ); pad2->SetGridx(); // vertical grid pad2->Draw(); pad2->cd(); // pad2 becomes the current pad TH1F *h3 = ( TH1F * )h1->Clone( "h3" ); //make raio plot h3->SetLineColor( kBlack ); h3->SetMarkerSize( 0.1 ); h3->Sumw2(); h3->SetStats( 0 ); // No statistics on lower plot Double_t factor = ( h2->GetEntries() ) / ( h1->GetEntries() ); h3->Divide( h1, h2, factor, 1. ); //h3->Divide(h2); double max = h3->GetMaximum(); double min = h3->GetMinimum(); h3->SetMarkerStyle( 21 ); h3->SetMinimum( min ); // Define Y .. h3->SetMaximum( max ); // .. range h3->Draw( "ep" ); // Draw the ratio plot h1->GetYaxis()->SetTitleSize( 20 ); h1->GetYaxis()->SetTitleFont( 43 ); h1->GetYaxis()->SetTitleOffset( 1.55 ); h3->GetYaxis()->SetTitle( "ratio 53x/70x " ); h3->GetYaxis()->SetNdivisions( 505 ); h3->GetYaxis()->SetTitleSize( 20 ); h3->GetYaxis()->SetTitleFont( 43 ); h3->GetYaxis()->SetTitleOffset( 1.55 ); h3->GetYaxis()->SetLabelFont( 43 ); // Absolute font size in pixel (precision 3) h3->GetYaxis()->SetLabelSize( 15 ); // X axis ratio plot settings h3->GetXaxis()->SetTitle( title.str().replace( title.str().find( "5" ), 1, "" ).c_str() ); h3->GetXaxis()->SetTitleSize( 20 ); h3->GetXaxis()->SetTitleFont( 43 ); h3->GetXaxis()->SetTitleOffset( 4. ); h3->GetXaxis()->SetLabelFont( 43 ); // Absolute font size in pixel (precision 3) h3->GetXaxis()->SetLabelSize( 15 ); double w = h3->GetBinWidth( 0 ); int N = h3->GetNbinsX(); TLine *l = new TLine( 0, 0, 0, 0 ); l->SetLineColor( kRed ); //l->DrawLine(h3->GetBinCenter(0)-0.49*w,1,h3->GetBinCenter(N)+0.5*w,1); l->DrawLine( xlo, 1, xhi, 1 ); c->cd(); pad1->cd(); if( ( title.str().find( "Pt" ) ) < title.str().size() ) { TLegend *leg = new TLegend( 0.7, 0.7, 0.9, 0.9 ); leg->AddEntry( h1, "PFCHS (legacy vtx)", "l" ); leg->AddEntry( h2, "PUPPI (legacy vtx)", "l" ); leg->AddEntry( h3, "ratio", "lep" ); leg->Draw(); } else { TLegend *leg = new TLegend( 0.1, 0.7, 0.3, 0.9 ); leg->AddEntry( h1, "PFCHS (legacy vtx)", "l" ); leg->AddEntry( h2, "PUPPI (legacy vtx)", "l" ); leg->AddEntry( h3, "ratio", "lep" ); leg->Draw(); } // std::cout << << " " << << std:: endl; // save pdf std::ostringstream saveas; saveas << "Plots/" << h1->GetName() << ".pdf" ; c->Print( saveas.str().c_str() ); std::cout << "print" << std::endl; } /* // 53X matched vs 53X unmatched //basically same as above if ((title.str().find("5"))< title.str().size()){ c->cd(); TPad *pad1 = new TPad("pad1", "pad1", 0, 0.3, 1, 1.0); pad1->SetBottomMargin(0.05); pad1->SetGridx(); // Vertical grid pad1->Draw(); // Draw the upper pad: pad1 pad1->cd(); // pad1 becomes the current pad h1->SetStats(0); // No statistics on upper plot // float w1 = h1->GetBinWidth(0); float xlo =0; float xhi =0; for (int n = 0 ; n < h1->GetNbinsX(); n++) { //std::cout << h1->GetBinContent(n) << std::endl; //if(n %1 ==0) std::cout << "test " << n << " " << h1->GetBinCenter(n) << " " << h1->GetBinContent(n) << std::endl; if (h1->GetBinContent(n) < h1->GetEntries()/10000 ) {continue ;} xlo = h1->GetBinCenter(n-1); break; } for (int n = h1->GetNbinsX(); n> -1*h1->GetNbinsX() ; n--) { //std::cout << h1->GetBinContent(n) << std::endl; if (h1->GetBinContent(n) < h1->GetEntries()/10000 ) continue; xhi = h1->GetBinCenter(n+1); break; } // std::cout << xlo << " " << xhi << std::endl;; if ((title.str().find("FBrem"))< title.str().size()){ h1->GetXaxis()->SetRangeUser(0.001,xhi); } if ((title.str().find("hOverE"))< title.str().size()){ h1->GetXaxis()->SetRangeUser(0.001,xhi); } h1->GetXaxis()->SetRangeUser(xlo,xhi); h1->DrawNormalized("h"); std::string title2 = title.str().replace(title.str().find("5"), 1, "5_un"); TKey *k2 =(f1->GetKey(title2.c_str())); TH1 *h2 =(TH1*)k2->ReadObj(); h2->DrawNormalized("h same"); // h1->GetYaxis()->SetLabelSize(0.); // TGaxis *axis = new TGaxis( -5, 20, -5, 220, 20,220,510,""); // axis->SetLabelFont(43); // Absolute font size in pixel (precision 3) // axis->SetLabelSize(15); // axis->Draw(); c->cd(); // Go back to the main canvas before defining pad2 TPad *pad2 = new TPad("pad2", "pad2", 0, 0.05, 1, 0.3); pad2->SetTopMargin(0); pad2->SetBottomMargin(0.2); pad2->SetGridx(); // vertical grid pad2->Draw(); pad2->cd(); // pad2 becomes the current pad TH1F *h3 = (TH1F*)h1->Clone("h3"); h3->SetLineColor(kBlack); h3->SetMarkerSize(0.1); h3->Sumw2(); h3->SetStats(0); // No statistics on lower plot Double_t factor = (h2->GetEntries())/(h1->GetEntries()); h3->Divide(h1,h2, factor, 1.); h3->SetMarkerStyle(21); double max = h3->GetMaximum(); double min = h3->GetMinimum(); h3->GetYaxis()->SetRangeUser(min,max); // Define Y .. h3->Draw("ep"); // Draw the ratio plot h1->GetYaxis()->SetTitleSize(20); h1->GetYaxis()->SetTitleFont(43); h1->GetYaxis()->SetTitleOffset(1.55); h3->GetYaxis()->SetTitle("ratio h1/h2 "); h3->GetYaxis()->SetNdivisions(505); h3->GetYaxis()->SetTitleSize(20); h3->GetYaxis()->SetTitleFont(43); h3->GetYaxis()->SetTitleOffset(1.55); h3->GetYaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) h3->GetYaxis()->SetLabelSize(15); // X axis ratio plot settings h3->GetXaxis()->SetTitle(title.str().replace(title.str().find("5"), 1, "").c_str()); h3->GetXaxis()->SetTitleSize(20); h3->GetXaxis()->SetTitleFont(43); h3->GetXaxis()->SetTitleOffset(4.); h3->GetXaxis()->SetLabelFont(43); // Absolute font size in pixel (precision 3) h3->GetXaxis()->SetLabelSize(15); double w = h3->GetBinWidth(0); int N = h3->GetNbinsX(); TLine *l = new TLine(0,0,0,0); l->SetLineColor(kRed); //l->DrawLine(h3->GetBinCenter(0)-0.49*w,1,h3->GetBinCenter(N)+0.5*w,1); l->DrawLine(xlo,1,xhi,1); c->cd(); pad1->cd(); if ((title.str().find("Pt"))< title.str().size()){ TLegend *leg = new TLegend(0.7,0.7,0.9,0.9); leg->AddEntry(h1,"53X","l"); leg->AddEntry(h2,"53X unmatched","l"); leg->AddEntry(h3,"ratio","lep"); leg->Draw(); }else { TLegend *leg = new TLegend(0.1,0.7,0.3,0.9); leg->AddEntry(h1,"53X","l"); leg->AddEntry(h2,"53X unmatched","l"); leg->AddEntry(h3,"ratio","lep"); leg->Draw(); } // std::cout << << " " << << std:: endl; std::ostringstream saveas; saveas << "Plots/" << h1->GetName()<<"_un.pdf" ; c->Print(saveas.str().c_str()); std::cout <<"print" << std::endl; }*/ //PLOT DELTA of 53X and 70X if( ( title.str().find( "diff" ) ) < title.str().size() ) { c->cd(); h1->SetStats( 1 ); // No statistics on upper plot //std::string title2 = title.str().replace(title.str().find("5"), 1, "_diff"); //TKey *k2 =(f1->GetKey(title2.c_str())); // TH1 *h2 =(TH1*)k2->ReadObj(); // float w1 = h1->GetBinWidth(0); float xlo = 0; float xhi = 0; for( int n = 0 ; n < h1->GetNbinsX(); n++ ) { //std::cout << h1->GetBinContent(n) << std::endl; //if(n %1 ==0) std::cout << "test " << n << " " << h1->GetBinCenter(n) << " " << h1->GetBinContent(n) << std::endl; if( h1->GetBinContent( n ) < h1->GetEntries() / 100 ) {continue ;} xlo = h1->GetBinCenter( n - 1 ); break; } for( int n = h1->GetNbinsX(); n > -1 * h1->GetNbinsX() ; n-- ) { //std::cout << h1->GetBinContent(n) << std::endl; if( h1->GetBinContent( n ) < h1->GetEntries() / 100 ) { continue; } xhi = h1->GetBinCenter( n + 1 ); break; } xlo = std::max( std::fabs( xlo ), std::fabs( xhi ) ); xhi = xlo; xlo = -xlo; //std::cout << xlo << " " << xhi << std::endl;; h1->GetXaxis()->SetRangeUser( xlo, xhi ); // h1->DrawNormalized("h"); h1->GetXaxis()->SetTitle( title.str().replace( title.str().find( "_diff" ), 5, "" ).insert( 0, "#Delta" ).c_str() ); h1->GetYaxis()->SetTitleSize( 20 ); h1->GetYaxis()->SetTitleFont( 43 ); h1->GetYaxis()->SetTitleOffset( 1.55 ); h1->Draw( "h" ); gPad->Update(); TPaveStats *st = ( TPaveStats * )h1->FindObject( "stats" ); st->SetX1NDC( 0.1 ); st->SetX2NDC( 0.3 ); st->SetY1NDC( 0.7 ); st->SetY2NDC( 0.9 ); // std::cout << << " " << << std:: endl; std::ostringstream saveas; saveas << "Plots/" << h1->GetName() << ".pdf" ; c->Print( saveas.str().c_str() ); std::cout << "print" << std::endl; c->Clear(); } } // c.Print("hsimple.ps]"); }
void FitDijetMass_Data() { TFile *inf = new TFile("MassResults_ak7calo.root"); TH1F *hCorMassDen = (TH1F*) inf->Get("DiJetMass"); hCorMassDen->SetXTitle("Corrected Dijet Mass (GeV)"); hCorMassDen->SetYTitle("Events/GeV"); hCorMassDen->GetYaxis()->SetTitleOffset(1.5); hCorMassDen->SetMarkerStyle(20); hCorMassDen->GetXaxis()->SetRangeUser(120.,900.); gROOT->ProcessLine(".L tdrstyle.C"); setTDRStyle(); tdrStyle->SetErrorX(0.5); tdrStyle->SetPadRightMargin(0.08); tdrStyle->SetLegendBorderSize(0); gStyle->SetOptFit(1111); tdrStyle->SetOptStat(0); TCanvas* c2 = new TCanvas("c2","DijetMass", 500, 500); /////// perform 4 parameters fit TF1 *func = new TF1("func", "[0]*((1-x/7000.+[3]*(x/7000)^2)^[1])/(x^[2])", 100., 1000.); func->SetParameter(0, 1.0e+08); func->SetParameter(1, -1.23); func->SetParameter(2, 4.13); func->SetParameter(3, 1.0); func->SetLineColor(4); func->SetLineWidth(3); TVirtualFitter::SetMaxIterations( 10000 ); TVirtualFitter *fitter; TMatrixDSym* cov_matrix; int fitStatus = hCorMassDen->Fit("func","LLI","",130.0, 800.0); // QCD fit TH1F *hFitUncertainty = hCorMassDen->Clone("hFitUncertainty"); hFitUncertainty->SetLineColor(5); hFitUncertainty->SetFillColor(5); hFitUncertainty->SetMarkerColor(5); if (fitStatus == 0) { fitter = TVirtualFitter::GetFitter(); double* m_elements = fitter->GetCovarianceMatrix(); cov_matrix = new TMatrixDSym( func->GetNumberFreeParameters(),m_elements); cov_matrix->Print(); double x, y, e; for(int i=0;i<hFitUncertainty->GetNbinsX();i++) { x = hFitUncertainty->GetBinCenter(i+1); y = func->Eval(x); e = QCDFitUncertainty( func, *cov_matrix, x); hFitUncertainty->SetBinContent(i+1,y); hFitUncertainty->SetBinError(i+1,e); } } hCorMassDen->Draw("ep"); gPad->Update(); TPaveStats *st = (TPaveStats*)hCorMassDen->FindObject("stats"); st->SetName("stats1"); st->SetX1NDC(0.3); //new x start position st->SetX2NDC(0.6); //new x end position st->SetTextColor(4); hCorMassDen->GetListOfFunctions()->Add(st); /////// perform 2 parameters fit TF1 *func2 = new TF1("func2", "[0]*(1-x/7000.)/(x^[1])", 100., 1000.); func2->SetParameter(0, 10000.); func2->SetParameter(1, 5.0); func2->SetLineWidth(3); fitStatus = hCorMassDen->Fit("func2","LLI","",130.0, 800.0); // QCD fit TH1F *hFitUncertainty2 = hCorMassDen->Clone("hFitUncertainty2"); hFitUncertainty2->SetLineColor(kGray); hFitUncertainty2->SetFillColor(kGray); hFitUncertainty2->SetMarkerColor(kGray); if (fitStatus == 0) { fitter = TVirtualFitter::GetFitter(); double* m_elements = fitter->GetCovarianceMatrix(); cov_matrix = new TMatrixDSym( func2->GetNumberFreeParameters(),m_elements); cov_matrix->Print(); double x, y, e; for(int i=0;i<hFitUncertainty2->GetNbinsX();i++) { x = hFitUncertainty2->GetBinCenter(i+1); y = func2->Eval(x); e = QCDFitUncertainty( func2, *cov_matrix, x); hFitUncertainty2->SetBinContent(i+1,y); hFitUncertainty2->SetBinError(i+1,e); } } hFitUncertainty->Draw("E3 same"); hCorMassDen->Draw("ep sames"); hFitUncertainty2->Draw("E3 same"); hCorMassDen->Draw("ep sames"); func2->Draw("same"); c2->SetLogy(1); /* TH1F *hCorMass = hCorMassDen->Clone("hCorMass"); for(int i=0; i<hCorMass->GetNbinsX(); i++){ hCorMass->SetBinContent(i+1, hCorMassDen->GetBinContent(i+1) * hCorMassDen->GetBinWidth(i+1)); hCorMass->SetBinError(i+1, hCorMassDen->GetBinError(i+1) * hCorMassDen->GetBinWidth(i+1)); } // Our observable is the invariant mass RooRealVar invMass("invMass", "Corrected dijet mass", 100., 1000.0, "GeV"); RooDataHist data( "data", "", invMass, hCorMass); ////////////////////////////////////////////// // make QCD model RooRealVar p0("p0", "# events", 600.0, 0.0, 10000000000.); RooRealVar p1("p1","p1", 3.975, -10., 10.) ; RooRealVar p2("p2","p2", 5.302, 4., 8.) ; RooRealVar p3("p3","p3", -1.51, -100., 100.) ; // // define QCD line shape RooGenericPdf qcdModel("qcdModel", "pow(1-@0/7000.+@3*(@0/7000.)*(@0/7000.),@1)*pow(@0/7000.,-@2)", RooArgList(invMass,p1,p2,p3)); // full model RooAddPdf model("model","qcd",RooArgList(qcdModel), RooArgList(p0)); //plot sig candidates, full model, and individual componenets // __ _ _ // / _(_) |_ // | |_| | __| // | _| | |_ // |_| |_|\__| // Important: fit integrating f(x) over ranges defined by X errors, rather // than taking point at center of bin RooFitResult* fit = model.fitTo(data, Minos(kFALSE), Extended(kTRUE), SumW2Error(kFALSE),Save(kTRUE), Range(130.,800.), Integrate(kTRUE) ); // to perform chi^2 minimization fit instead // RooFitResult* fit = model.chi2FitTo(data, Extended(kTRUE), // Save(),Range(50.,526.),Integrate(kTRUE) ); fit->Print(); //plot data TCanvas* cdataNull = new TCanvas("cdataNull","fit to dijet mass",500,500); RooPlot* frame1 = invMass.frame() ; data.plotOn(frame1, DataError(RooAbsData::SumW2) ) ; model.plotOn(frame1, LineColor(kBlue)) ; model.plotOn(frame1, VisualizeError(*fit, 1),FillColor(kYellow)) ; data.plotOn(frame1, DataError(RooAbsData::SumW2) ) ; model.plotOn(frame1, LineColor(kBlue)) ; model.paramOn(frame1, Layout(0.4, 0.85, 0.92)); TPaveText* dataPave = (TPaveText*) frame1->findObject("model_paramBox"); dataPave->SetY1(0.77); gPad->SetLogy(); frame1->GetYaxis()->SetNoExponent(); frame1->GetYaxis()->SetRangeUser(5E-2,5E+4); frame1->GetYaxis()->SetTitle("Events / bin"); frame1->GetYaxis()->SetTitleOffset(1.35); frame1->SetTitle("fit to data with QCD lineshape"); frame1->Draw() ; // S h o w r e s i d u a l a n d p u l l d i s t s // ------------------------------------------------------- //// Construct a histogram with the residuals of the data w.r.t. the curve RooHist* hresid = frame1->residHist() ; // Create a new frame to draw the residual distribution and add the distribution to the frame RooPlot* frame2 = invMass.frame(Title("Residual Distribution")) ; frame2->addPlotable(hresid,"P") ; ///// Construct a histogram with the pulls of the data w.r.t the curve RooHist* hpull = frame1->pullHist() ; //// Create a new frame to draw the pull distribution and add the distribution to the frame RooPlot* frame3 = invMass.frame(Title("Pull Distribution")) ; frame3->addPlotable(hpull,"P") ; TCanvas* cResidual = new TCanvas("cResidual","Residual Distribution",1000,500); cResidual->Divide(2) ; cResidual->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ; cResidual->cd(2) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ; */ }