TH2F* ZMassVsDRHist2D(TString name, TString bininfo, DiMuPlottingSystem* dps) { // Plot a 2D hist of the dimuon mass vs ZPt for either positive or negative reco muons. // This function uses the DiMuonPlottingSystem class which facilitates the application of cuts. // Get the titles and units straight. TString xtitle = TString("dR"); TString title = TString ("Z Mass vs "); title+=xtitle; xtitle+= TString(""); TString ytitle = TString("Z Mass (GeV)"); // Initialize some pointers to be filled. h2 takes in reco2 info which will be added to reco1 info in order to get // all of the positive or all of the negative reco muons. TH2F* h = 0; TString dR = TString("((reco1.phi - reco2.phi)**2 + (reco1.eta - reco2.eta)**2 )**0.5"); h = dps->hist2D("recoCandMass:"+dR, bininfo, ""); // Print out the number of muons in the different histograms to make sure they add up right. std::cout << "nentries: " << h->GetEntries() << std::endl; // Set the title info for the histogram. h->SetTitle(title); h->GetXaxis()->SetTitle(xtitle); h->GetYaxis()->SetTitle(ytitle); h->SetName(name); std::cout << "xtitle: " << h->GetXaxis()->GetTitle() << std::endl; std::cout << "title: " << h->GetTitle() << std::endl; h->Draw("colz"); std::cout << "nxbins: " << h->GetXaxis()->GetNbins() << std::endl; std::cout << "nybins: " << h->GetYaxis()->GetNbins() << std::endl; std::cout << "nbinsx: " << h->GetNbinsX() << std::endl; return h; }
int main(int argc, char** argv){ ///================================================== ///==== Draw Distribution with and without scale ==== ///================================================== ///=============================================================================== gROOT->Reset(); gROOT->SetStyle("Plain"); gStyle->SetPalette(1); gStyle->SetOptStat(0); gStyle->SetOptFit(0); const Int_t __NRGBs = 5; const Int_t __NCont = 76; Double_t __stops[__NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 }; Double_t __red[__NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 }; Double_t __green[__NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 }; Double_t __blue[__NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 }; TColor::CreateGradientColorTable(__NRGBs, __stops, __red, __green, __blue, __NCont); gStyle->SetNumberContours(__NCont); ///=============================================================================== if(argc != 2) { std::cerr << ">>>>> analysis.cpp::usage: " << argv[0] << " configFileName" << std::endl ; return 1; } // Parse the config file parseConfigFile (argv[1]) ; std::string treeNameDATA = gConfigParser -> readStringOption("InputDATA::treeName"); std::string inputFileDATA = gConfigParser -> readStringOption("InputDATA::inputFile"); double luminosity = gConfigParser -> readDoubleOption("InputDATA::luminosity"); std::cout << ">>>>> InputDATA::treeName " << treeNameDATA << std::endl; std::cout << ">>>>> InputDATA::inputFile " << inputFileDATA << std::endl; std::cout << ">>>>> InputDATA::luminosity " << luminosity << std::endl; std::string treeNameMC = gConfigParser -> readStringOption("InputMC::treeName"); std::vector< std::string > inputFileMC = gConfigParser -> readStringListOption("InputMC::inputFile"); std::vector< std::string > inputSampleMC = gConfigParser -> readStringListOption("InputMC::nameSample"); std::vector< double > xSecAndEfficiency = gConfigParser -> readDoubleListOption("InputMC::xsecEff"); std::cout << ">>>>> InputMC::treeName " << treeNameMC << std::endl; std::cout << ">>>>> InputMC::inputFile size " << inputFileMC.size() << std::endl; if (inputFileMC.size() != xSecAndEfficiency.size() || inputFileMC.size() != inputSampleMC.size()) { std::cerr << " >>>> Error: different number of samples and cross sections" << std::endl; return 0; } int nMC = inputFileMC.size(); for (int iMC = 0; iMC < nMC; iMC++) { std::cout << ">>>>> InputMC::inputFile[" << iMC << "] = " << inputSampleMC.at(iMC) << " => " << inputFileMC.at(iMC) << " : " << xSecAndEfficiency.at(iMC) << " : " << luminosity * xSecAndEfficiency.at(iMC) << std::endl; } int binX = gConfigParser -> readIntOption("Options::binX"); double minX = gConfigParser -> readDoubleOption("Options::minX"); double maxX = gConfigParser -> readDoubleOption("Options::maxX"); std::string variableX = gConfigParser -> readStringOption("Options::variableX"); std::cout << ">>>>> Options::binX " << binX << std::endl; std::cout << ">>>>> Options::minX " << minX << std::endl; std::cout << ">>>>> Options::maxX " << maxX << std::endl; std::cout << ">>>>> Options::variableX " << variableX.c_str() << std::endl; int binY = gConfigParser -> readIntOption("Options::binY"); double minY = gConfigParser -> readDoubleOption("Options::minY"); double maxY = gConfigParser -> readDoubleOption("Options::maxY"); std::string variableY = gConfigParser -> readStringOption("Options::variableY"); std::cout << ">>>>> Options::binY " << binY << std::endl; std::cout << ">>>>> Options::minY " << minY << std::endl; std::cout << ">>>>> Options::maxY " << maxY << std::endl; std::cout << ">>>>> Options::variableY " << variableY.c_str() << std::endl; int binRatio = gConfigParser -> readIntOption("Options::binRatio"); double minRatio = gConfigParser -> readDoubleOption("Options::minRatio"); double maxRatio = gConfigParser -> readDoubleOption("Options::maxRatio"); std::cout << ">>>>> Options::minRatio " << minRatio << std::endl; std::cout << ">>>>> Options::maxRatio " << maxRatio << std::endl; std::string outputFile = gConfigParser -> readStringOption("Output::outputFile"); std::cout << ">>>>> Output::outputFile " << outputFile << std::endl; // TString AdditionalCut = Form("eta > 1.5");// || eta < -1.5)");// && eleFBrem<0.5"); TString AdditionalCut = Form("eta < -1.5");// || eta < -1.5)");// && eleFBrem<0.5"); // TString AdditionalCut = Form("(eta > 1.5 || eta < -1.5)");// && abs(eleFBrem)<1"); EColor vColor[100] = { kBlue,(EColor)(kBlue+1),(EColor) (kBlue+2), kRed,(EColor) (kRed+1),(EColor) (kRed+2), kGreen,(EColor) (kGreen+1),(EColor) (kGreen+2), kTeal,(EColor) (kTeal+1), kOrange,(EColor) (kOrange+1), kMagenta,(EColor) (kMagenta+1),(EColor) (kViolet),(EColor) (kYellow),(EColor) (kGray)}; ///==== DATA ==== TFile* fileInDATA = new TFile(inputFileDATA.c_str(),"READ"); ///==== W ==== TFile* fileInMC[nMC]; for (int iMC = 0; iMC < nMC; iMC++) { fileInMC[iMC] = new TFile(inputFileMC.at(iMC).c_str(),"READ"); } ///==== output ==== TFile* outFile = new TFile(outputFile.c_str(),"RECREATE"); outFile->cd(); ///==== Prepare input trees ==== TLegend* leg = new TLegend(0.55,0.7,0.95,0.95); leg->SetFillColor(0); TLegend* legDown = new TLegend(0.55,0.1,0.95,0.35); legDown->SetFillColor(0); TTree* MyTreeDATA = (TTree*) fileInDATA->Get(treeNameDATA.c_str()); int initialNumber; TH2F* HistoDATA = new TH2F("DATA","DATA",binX,minX,maxX,binY,minY,maxY); TH1F* HistoRatioDATA = new TH1F("RatioDATA","RatioDATA",binRatio,minRatio,maxRatio); TString DrawDATA = Form("%s:%s >> DATA",variableY.c_str(),variableX.c_str()); MyTreeDATA->Draw(DrawDATA.Data(),AdditionalCut.Data()); HistoDATA->SetMarkerSize(1); HistoDATA->SetMarkerStyle(20); HistoDATA->GetXaxis()->SetTitle(variableX.c_str()); HistoDATA->GetYaxis()->SetTitle(variableY.c_str()); leg->AddEntry(HistoDATA,HistoDATA->GetTitle(),"p"); legDown->AddEntry(HistoDATA,HistoDATA->GetTitle(),"p"); DrawDATA = Form("(%s) / (%s) >> RatioDATA",variableY.c_str(),variableX.c_str()); MyTreeDATA->Draw(DrawDATA.Data(),AdditionalCut.Data()); HistoRatioDATA->SetMarkerSize(1); HistoRatioDATA->SetMarkerStyle(20); HistoRatioDATA->GetXaxis()->SetTitle(Form("(%s)/(%s)",variableY.c_str(),variableX.c_str())); TH2F* HistoMC[nMC]; TH1F* HistoRatioMC[nMC]; TH2F* HistoMC_SUM = new TH2F("HistoMC_SUM","HistoMC_SUM",binX,minX,maxX,binY,minY,maxY); TH1F* HistoRatioMC_SUM = new TH1F("HistoRatioMC_SUM","HistoRatioMC_SUM",binRatio,minRatio,maxRatio); SetColorAndStyleHisto(*(HistoRatioMC_SUM),kBlue); TTree* MyTreeMC[nMC]; THStack* hsMC = new THStack("hsMC","hsMC"); double MC_Expected = 0; for (int iMC = 0; iMC < nMC; iMC++) { // for (int iMC = nMC-1; iMC >= 0; iMC--) { MyTreeMC[iMC] = (TTree*) fileInMC[iMC]->Get(treeNameMC.c_str()); MyTreeMC[iMC]->SetBranchAddress("initialNumber",&initialNumber); MyTreeMC[iMC]->GetEntry(0); xSecAndEfficiency.at(iMC) = xSecAndEfficiency.at(iMC) / initialNumber; ///==== normalize to initial number of events HistoMC[iMC] = new TH2F(inputSampleMC.at(iMC).c_str(),inputSampleMC.at(iMC).c_str(),binX,minX,maxX,binY,minY,maxY); HistoRatioMC[iMC] = new TH1F(Form("%s_Ratio",inputSampleMC.at(iMC).c_str()),Form("%s_Ratio",inputSampleMC.at(iMC).c_str()),binRatio,minRatio,maxRatio); TString Draw = Form("%s:%s >> %s",variableY.c_str(),variableX.c_str(),inputSampleMC.at(iMC).c_str()); MyTreeMC[iMC]->Draw(Draw.Data(),AdditionalCut.Data()); Draw = Form("(%s) / (%s) >> %s",variableY.c_str(),variableX.c_str(),Form("%s_Ratio",inputSampleMC.at(iMC).c_str())); MyTreeMC[iMC]->Draw(Draw.Data(),AdditionalCut.Data()); HistoRatioMC[iMC]->GetXaxis()->SetTitle(Form("(%s)/(%s)",variableY.c_str(),variableX.c_str())); std::cout << ">>>>>> " << inputSampleMC.at(iMC) << " : " << xSecAndEfficiency.at(iMC) << " : " << luminosity << " : " << HistoMC[iMC]->GetEntries() << " = " << luminosity * xSecAndEfficiency.at(iMC) * HistoMC[iMC]->GetEntries() << std::endl; std::cout << " >> " << Draw.Data() << std::endl; std::cout << " >> " << HistoMC[iMC]->GetEntries() << " Entries" << std::endl; MC_Expected += luminosity * xSecAndEfficiency.at(iMC) * HistoMC[iMC]->GetEntries(); HistoMC[iMC]->Scale(luminosity * xSecAndEfficiency.at(iMC)); // / HistoMC[iMC]->GetEntries()); HistoRatioMC[iMC]->Scale(luminosity * xSecAndEfficiency.at(iMC)); // / HistoMC[iMC]->GetEntries()); SetColorAndStyleHisto(*(HistoMC[iMC]),vColor[iMC]); SetColorAndStyleHisto(*(HistoRatioMC[iMC]),vColor[iMC]); HistoMC[iMC]->GetXaxis()->SetTitle(variableX.c_str()); HistoMC[iMC]->GetYaxis()->SetTitle(variableY.c_str()); HistoMC_SUM->Add(HistoMC[iMC]); HistoMC_SUM->GetXaxis()->SetTitle(variableX.c_str()); HistoMC_SUM->GetYaxis()->SetTitle(variableY.c_str()); HistoRatioMC_SUM->Add(HistoRatioMC[iMC]); HistoRatioMC_SUM->GetXaxis()->SetTitle(Form("(%s)/(%s)",variableY.c_str(),variableX.c_str())); hsMC->Add(HistoMC[iMC]); if (iMC == 0) hsMC->Add(HistoMC[iMC]); leg->AddEntry(HistoMC[iMC],HistoMC[iMC]->GetTitle(),"f"); legDown->AddEntry(HistoMC[iMC],HistoMC[iMC]->GetTitle(),"f"); } ///==== make fit ==== TH1D* htemp_prof = smartGausProfileXSQRTN(HistoDATA,2); TGraphErrors grH = buildGEfromH_Personalized(*htemp_prof); grH.SetMarkerStyle(22); grH.SetMarkerSize(0.7); grH.SetMarkerColor(kBlue); grH.SetFillColor(kBlue); grH.SetFillStyle(3335); grH.SetLineWidth(1); grH.SetLineColor(kBlue); grH.GetXaxis()->SetTitle(variableX.c_str()); grH.GetYaxis()->SetTitle(variableY.c_str()); ///---------------------- ///---- Plot results ---- ///---------------------- std::cerr << " MC expected : DATA = " << MC_Expected << " : " << HistoDATA->GetEntries() << std::endl; std::cerr << " HistoDATA->GetMaximum() = " << HistoDATA->GetMaximum() << std::endl; std::cerr << " HistoDATA->GetEntries() = " << HistoDATA->GetEntries() << std::endl; outFile->cd(); TCanvas cResultDistro("cResultDistro","cResultDistro",900,900); cResultDistro.Divide(2,2); cResultDistro.cd(1); HistoDATA->DrawClone("colz"); gPad->SetGrid(); TString tLumiName = Form("#int L = %.4f pb^{-1}",luminosity); TLatex tLumi(1.5 * HistoDATA->GetMean(1),0.2 * HistoDATA->GetMaximum(),tLumiName.Data()); tLumi.DrawClone(); cResultDistro.cd(2); HistoRatioMC_SUM->Draw(); HistoRatioDATA->Draw("E1same"); TString tEleName = Form("%d electrons",(int) HistoDATA->GetEntries()); TLatex tEle(2.0 * HistoRatioDATA->GetMean(1),0.3 * HistoRatioDATA->GetMaximum(),tEleName.Data()); tEle.DrawClone(); gPad->SetGrid(); cResultDistro.cd(3); grH.Draw("APL"); double minFit = gConfigParser -> readDoubleOption("Options::minFit"); double maxFit = gConfigParser -> readDoubleOption("Options::maxFit"); std::cout << ">>>>> Options::minFit " << minFit << std::endl; std::cout << ">>>>> Options::maxFit " << maxFit << std::endl; TF1* funz = new TF1 ("funz","pol1",minFit,maxFit); // funz->FixParameter(0,0); funz->SetParameter(0,0); funz->SetParameter(1,1); grH.Fit("funz","RMQ"); std::cerr << " Y = [0] + [1] * X " << std::endl; std::cerr << " [0] = " << funz->GetParameter(0) << " +/- " << funz->GetParError(0) << std::endl; std::cerr << " [1] = " << funz->GetParameter(1) << " +/- " << funz->GetParError(1) << std::endl; double coeffDATA = funz->GetParameter(1); double errCoeffDATA = funz->GetParError(1); gPad->SetGrid(); cResultDistro.cd(4); HistoRatioMC_SUM->Draw(); HistoRatioDATA->Draw("E1same"); tEle.DrawClone(); gPad->SetGrid(); gPad->SetLogy(); TString nameImage = Form("%s_%s_%d.png",variableY.c_str(),variableX.c_str(),1); cResultDistro.SaveAs(nameImage.Data()); TString nameImageRoot = Form("%s_%s_%d.root",variableY.c_str(),variableX.c_str(),1); cResultDistro.SaveAs(nameImageRoot.Data()); TCanvas cResultDistroMC("cResultDistroMC","cResultDistroMC",800,800); cResultDistroMC.Divide(2,2); // cResultDistroMC.Divide(2,nMC); // for (int iMC = 0; iMC < nMC; iMC++) { // cResultDistroMC.cd(2*iMC+1); // HistoMC[iMC]->DrawClone("colz"); // HistoDATA->DrawClone("BOXsame"); // cResultDistroMC.cd(2*iMC+2); // HistoRatioMC[iMC]->DrawNormalized(""); // HistoRatioDATA->DrawNormalized("E1same"); // } cResultDistroMC.cd(1); HistoMC_SUM->DrawClone("colz"); HistoDATA->DrawClone("BOXsame"); gPad->SetGrid(); ///==== make fit ==== cResultDistroMC.cd(3); TH1D* MChtemp_prof = smartGausProfileXSQRTN(HistoMC_SUM,2); TGraphErrors MCgrH = buildGEfromH_Personalized(*MChtemp_prof); MCgrH.SetMarkerStyle(22); MCgrH.SetMarkerSize(0.7); MCgrH.SetMarkerColor(kRed); MCgrH.SetFillColor(kRed); MCgrH.SetFillStyle(3335); MCgrH.SetLineWidth(1); MCgrH.SetLineColor(kRed); MCgrH.GetXaxis()->SetTitle(variableX.c_str()); MCgrH.GetYaxis()->SetTitle(variableY.c_str()); funz->SetParameter(0,0); funz->SetParameter(1,1); MCgrH.Fit("funz","RMQ"); std::cerr << " ================= " << std::endl; std::cerr << " ======= MC ====== " << std::endl; std::cerr << " Y = [0] + [1] * X " << std::endl; std::cerr << " [0] = " << funz->GetParameter(0) << " +/- " << funz->GetParError(0) << std::endl; std::cerr << " [1] = " << funz->GetParameter(1) << " +/- " << funz->GetParError(1) << std::endl; double coeffMC = funz->GetParameter(1); double errCoeffMC = funz->GetParError(1); MCgrH.Draw("APL"); gPad->SetGrid(); cResultDistroMC.cd(4); MCgrH.Draw("APL"); grH.Draw("PLSAME"); gPad->SetGrid(); TString nameImageLog = Form("%s_%s_%d_MC.png",variableY.c_str(),variableX.c_str(),1); cResultDistroMC.SaveAs(nameImageLog.Data()); std::cerr << " 1 - alpha = " << coeffDATA / coeffMC << " +/- " << sqrt( (errCoeffDATA/coeffMC)*(errCoeffDATA/coeffMC) + (errCoeffMC*coeffDATA/coeffMC/coeffMC)*(errCoeffMC*coeffDATA/coeffMC/coeffMC) ) << std::endl; std::cerr << " alpha = " << 1-coeffDATA / coeffMC << " +/- " << sqrt( (errCoeffDATA/coeffMC)*(errCoeffDATA/coeffMC) + (errCoeffMC*coeffDATA/coeffMC/coeffMC)*(errCoeffMC*coeffDATA/coeffMC/coeffMC) ) << std::endl; // TCanvas cResultDistro_1("cResultDistro_1","cResultDistro_1",800,800); // HistoRatioMC_SUM->Draw(); // HistoRatioDATA->Draw("E1same"); // tEle.DrawClone(); // gPad->SetGrid(); // gPad->SetLogy(); }
void rulevisHists( TDirectory *rfdir, TDirectory *vardir, TDirectory *corrdir, TMVAGlob::TypeOfPlot type) { // if (rfdir==0) return; if (vardir==0) return; if (corrdir==0) return; // const TString rfName = rfdir->GetName(); const TString maintitle = rfName + " : Rule Importance"; const TString rfNameOpt = "_RF2D_"; const TString outfname[TMVAGlob::kNumOfMethods] = { "rulevisHists", "rulevisHists_decorr", "rulevisCorr_pca", "rulevisCorr_gaussdecorr" }; const TString outputName = outfname[type]+"_"+rfdir->GetName(); // TIter rfnext(rfdir->GetListOfKeys()); TKey *rfkey; Double_t rfmax; Double_t rfmin; Bool_t allEmpty=kTRUE; Bool_t first=kTRUE; while ((rfkey = (TKey*)rfnext())) { // make sure, that we only look at histograms TClass *cl = gROOT->GetClass(rfkey->GetClassName()); if (!cl->InheritsFrom("TH2F")) continue; TH2F *hrf = (TH2F*)rfkey->ReadObj(); TString hname= hrf->GetName(); if (hname.Contains("__RF_")){ // found a new RF plot Double_t valmin = hrf->GetMinimum(); Double_t valmax = hrf->GetMaximum(); if (first) { rfmin=valmin; rfmax=valmax; first = kFALSE; } else { if (valmax>rfmax) rfmax=valmax; if (valmin<rfmin) rfmin=valmin; } if (hrf->GetEntries()>0) allEmpty=kFALSE; } } if (first) { cout << "ERROR: no RF plots found..." << endl; return; } const Int_t nContours = 100; Double_t contourLevels[nContours]; Double_t dcl = (rfmax-rfmin)/Double_t(nContours-1); // for (Int_t i=0; i<nContours; i++) { contourLevels[i] = rfmin+dcl*Double_t(i); } /////////////////////////// vardir->cd(); // how many plots are in the directory? Int_t noPlots = ((vardir->GetListOfKeys())->GetEntries()) / 2; // define Canvas layout here! // default setting Int_t xPad; // no of plots in x Int_t yPad; // no of plots in y Int_t width; // size of canvas Int_t height; switch (noPlots) { case 1: xPad = 1; yPad = 1; width = 500; height = 0.7*width; break; case 2: xPad = 2; yPad = 1; width = 600; height = 0.7*width; break; case 3: xPad = 3; yPad = 1; width = 900; height = 0.4*width; break; case 4: xPad = 2; yPad = 2; width = 600; height = width; break; default: xPad = 3; yPad = 2; width = 800; height = 0.7*width; break; } Int_t noPad = xPad * yPad ; // this defines how many canvases we need const Int_t noCanvas = 1 + (Int_t)((noPlots - 0.001)/noPad); TCanvas **c = new TCanvas*[noCanvas]; for (Int_t ic=0; ic<noCanvas; ic++) c[ic] = 0; // counter variables Int_t countCanvas = 0; Int_t countPad = 1; // loop over all objects in directory TIter next(vardir->GetListOfKeys()); TKey *key; TH1F *sigCpy=0; TH1F *bgdCpy=0; // Bool_t first = kTRUE; while ((key = (TKey*)next())) { // make sure, that we only look at histograms TClass *cl = gROOT->GetClass(key->GetClassName()); if (!cl->InheritsFrom("TH1")) continue; sig = (TH1F*)key->ReadObj(); TString hname= sig->GetName(); // check for all signal histograms if (hname.Contains("__S")){ // found a new signal plot // sigCpy = new TH1F(*sig); // create new canvas if ((c[countCanvas]==NULL) || (countPad>noPad)) { char cn[20]; sprintf( cn, "rulehist%d_", countCanvas+1 ); TString cname(cn); cname += rfdir->GetName(); c[countCanvas] = new TCanvas( cname, maintitle, countCanvas*50+200, countCanvas*20, width, height ); // style c[countCanvas]->Divide(xPad,yPad); countPad = 1; } // save canvas to file TPad *cPad = (TPad *)(c[countCanvas]->GetPad(countPad)); c[countCanvas]->cd(countPad); countPad++; // find the corredponding background histo TString bgname = hname; bgname.ReplaceAll("__S","__B"); hkey = vardir->GetKey(bgname); bgd = (TH1F*)hkey->ReadObj(); if (bgd == NULL) { cout << "ERROR!!! couldn't find backgroung histo for" << hname << endl; exit; } TString rfname = hname; rfname.ReplaceAll("__S","__RF"); TKey *hrfkey = rfdir->GetKey(rfname); TH2F *hrf = (TH2F*)hrfkey->ReadObj(); Double_t wv = hrf->GetMaximum(); // if (rfmax>0.0) // hrf->Scale(1.0/rfmax); hrf->SetMinimum(rfmin); // make sure it's zero -> for palette axis hrf->SetMaximum(rfmax); // make sure max is 1.0 -> idem hrf->SetContour(nContours,&contourLevels[0]); // this is set but not stored during plot creation in MVA_Factory // TMVAGlob::SetSignalAndBackgroundStyle( sigK, bgd ); sig->SetFillStyle(3002); sig->SetFillColor(1); sig->SetLineColor(1); sig->SetLineWidth(2); bgd->SetFillStyle(3554); bgd->SetFillColor(1); bgd->SetLineColor(1); bgd->SetLineWidth(2); // chop off "signal" TString title(hrf->GetTitle()); title.ReplaceAll("signal",""); // finally plot and overlay Float_t sc = 1.1; if (countPad==2) sc = 1.3; sig->SetMaximum( TMath::Max( sig->GetMaximum(), bgd->GetMaximum() )*sc ); Double_t smax = sig->GetMaximum(); if (first) { hrf->SetTitle( maintitle ); first = kFALSE; } else { hrf->SetTitle( "" ); } hrf->Draw("colz ah"); TMVAGlob::SetFrameStyle( hrf, 1.2 ); sig->Draw("same ah"); bgd->Draw("same ah"); // draw axis using range [0,smax] hrf->GetXaxis()->SetTitle( title ); hrf->GetYaxis()->SetTitleOffset( 1.30 ); hrf->GetYaxis()->SetTitle("Events"); hrf->GetYaxis()->SetLimits(0,smax); hrf->Draw("same axis"); cPad->SetRightMargin(0.13); cPad->Update(); // Draw legend if (countPad==2){ TLegend *legend= new TLegend( cPad->GetLeftMargin(), 1-cPad->GetTopMargin()-.18, cPad->GetLeftMargin()+.4, 1-cPad->GetTopMargin() ); legend->AddEntry(sig,"Signal","F"); legend->AddEntry(bgd,"Background","F"); legend->Draw("same"); legend->SetBorderSize(1); legend->SetMargin( 0.3 ); legend->SetFillColor(19); legend->SetFillStyle(1); } // save canvas to file if (countPad > noPad) { c[countCanvas]->Update(); TString fname = Form( "plots/%s_c%i", outputName.Data(), countCanvas+1 ); TMVAGlob::imgconv( c[countCanvas], fname ); // TMVAGlob::plot_logo(); // don't understand why this doesn't work ... :-( countCanvas++; } } } if (countPad <= noPad) { c[countCanvas]->Update(); TString fname = Form( "plots/%s_c%i", outputName.Data(), countCanvas+1 ); TMVAGlob::imgconv( c[countCanvas], fname ); } }
/* EXAMPLE root .L particleDrawer.C++ particleDrawer("../test/test.root",11,2) */ void particleDrawer(TString filename, int entry = 0, int PVAssoc = 2, bool debug = false) { cout << "particleDrawer::Setting the TDR style ... "; setTDRStyle(); cout << "DONE" << endl; cout << "particleDrawer::Drawing the default (TDR) frame ... " << endl; TH1D* frame = new TH1D(); frame->GetXaxis()->SetLimits(-5,5); frame->GetXaxis()->SetTitle("#eta"); frame->GetYaxis()->SetRangeUser(-TMath::Pi(),TMath::Pi()); frame->GetYaxis()->SetTitle("#phi"); TCanvas* c = tdrCanvas("particleBasedEvent",frame,4,0,true); c->GetPad(0)->SetLogz(); cout << "\r\r\r\r\r\r" << flush; cout << setw(52) << " " << "DONE" << endl << endl; cout << "particleDrawer::Opening the input file (" << filename << " ) ... "; TFile* inFile = TFile::Open(filename,"READ"); assert(inFile!=NULL); cout << "DONE" << endl; cout << "particleDrawer::Getting the input trees ... "; TTree* puppiTree = (TTree*)inFile->Get("puppiReader/puppiTree"); assert(puppiTree!=NULL); TTree* jetTree = (TTree*)inFile->Get("nt_AK4PFchs/t"); assert(jetTree!=NULL); cout << "DONE" << endl; cout << "particleDrawer::Making the ntuples ... "; puppiNtuple* pNtuple = new puppiNtuple(puppiTree); validatorNtuple* jNtuple = new validatorNtuple(jetTree); cout << "DONE" << endl; cout << "particleDrawer::Getting entry " << entry << " for puppiTree ... "; puppiTree->GetEntry(entry); cout << "DONE" << endl; cout << "particleDrawer::Filling the histograms ... "; TH2F* hPU = new TH2F("hPU","hPU",50,-5,5,60,-TMath::Pi(),TMath::Pi()); TH2F* hHard = new TH2F("hHard","hHard",50,-5,5,60,-TMath::Pi(),TMath::Pi()); for(unsigned int iparticle=0; iparticle<(*pNtuple->px).size(); iparticle++) { TLorentzVector tempVect((*pNtuple->px)[iparticle],(*pNtuple->py)[iparticle], (*pNtuple->pz)[iparticle],(*pNtuple->e)[iparticle]); if((*pNtuple->fromPV)[iparticle]<PVAssoc) { if(debug) cout << "Filling PU::fromPV = " << (*pNtuple->fromPV)[iparticle] << endl; hPU->Fill(tempVect.Eta(),tempVect.Phi(),tempVect.Pt()); } else { if(debug) cout << "Filling hard-scatter:: fromPV = " << (*pNtuple->fromPV)[iparticle] << endl; hHard->Fill(tempVect.Eta(),tempVect.Phi(),tempVect.Pt()); } } if(debug) { cout << "hPU->GetEntries() = " << hPU->GetEntries() << endl; cout << "hHard->GetEntries() = " << hHard->GetEntries() << endl; } else cout << "DONE" << endl; cout << "particleDrawer::Drawing the histograms ... "; //tdrDraw(hPU,"BOX",kFullSquare,kNone,kSolid,kGray,kNone,kNone); //tdrDraw(hHard,"colz"); THStack* stack = new THStack("stack","stack"); hPU->SetLineStyle(kSolid); hPU->SetLineColor(kGray); hPU->SetFillStyle(1001); hPU->SetFillColor(kNone); hPU->SetMarkerStyle(kFullSquare); hPU->SetMarkerColor(kNone); if(hHard->GetEntries()>0) stack->Add(hHard,"colz"); if(hPU->GetEntries()>0) stack->Add(hPU,"BOX"); tdrDraw(stack,"nostack"); set_plot_style(); c->Update(); c->RedrawAxis(); cout << "DONE" << endl; cout << "particleDrawer::Getting entry " << entry << " for jetTree ... "; jetTree->GetEntry(entry); cout << "DONE" << endl; cout << "particleDrawer::Drawing the jets ... " << endl; vector<JetCircle> jets; for(unsigned int ijet=0; ijet<jNtuple->nref; ijet++) { if((*jNtuple->jtpt)[ijet]<20) continue; double RJet = TMath::Sqrt((*jNtuple->jtarea)[ijet]/TMath::Pi()); jets.push_back(JetCircle((*jNtuple->jteta)[ijet],(*jNtuple->jtphi)[ijet],RJet,(*jNtuple->jtpt)[ijet])); } for(unsigned int ijet=0; ijet<jets.size(); ijet++) { for(unsigned int jjet=ijet+1; jjet<jets.size(); jjet++) { if(check_overlap(jets[ijet].getX(),jets[ijet].getY(),jets[ijet].getRadius(), jets[jjet].getX(),jets[jjet].getY(),jets[jjet].getRadius())) { cout << "Jet " << ijet << " overlaps with jet " << jjet << endl; if(jets[ijet].getPt()>jets[jjet].getPt()) { //find angle for jjet; jets[jjet].findAngles(jets[ijet]); } else if(jets[ijet].getPt()<jets[jjet].getPt()) { //find angle for ijet jets[ijet].findAngles(jets[jjet]); } else { //must find angle for both jets //then must draw a straight line between the two intersection points jets[jjet].findAngles(jets[ijet]); jets[ijet].findAngles(jets[jjet]); //NEED TO COMPLETE THIS FUNCTION. CURRENTLY DOESNOT DRAW LINE BETWEEN THE JETS. } cout << "Jet " << ijet << ": \n" << jets[ijet] << endl; cout << "Jet " << jjet << ": \n" << jets[jjet] << endl; } } } for(unsigned int ijet=0; ijet<jets.size(); ijet++) { loadbar2(ijet+1, jets.size()); TEllipse* cJet = new TEllipse(jets[ijet].getX(),jets[ijet].getY(), jets[ijet].getRadius(),jets[ijet].getRadius(), jets[ijet].getStartAngle(),jets[ijet].getEndAngle()); cJet->SetFillStyle(0); cJet->SetFillColor(kNone); cJet->SetLineStyle(kSolid); cJet->SetLineColor(kRed); cJet->SetLineWidth(3); cJet->Draw("only same"); } //cout << "\r\r\r\r" << flush; //cout << setw(37) << " " << "DONE" << endl << endl; cout << "particleDrawer::Saving the canvas ... "; TString name = Form("particleMap_entry%i_PVAssoc%i",entry,PVAssoc); c->SaveAs(name+".png"); c->SaveAs(name+".pdf"); c->SaveAs(name+".C"); cout << "DONE" << endl; }
/** * Loads a histogram from a ROOT-file, scales it, and either returns it as \c * returnedHistogram or adds it to \c returnedHistogram . The first if * \c returnedHistogram is \c NULL otherwise the latter. * * @param histogramName * name of the histogram. * @param inputFilename * name of the ROOT-file. * @param scale * scale factor for histogram. * @param returnedHistogram * the returned histogram (input, pass-by-reference does not work). * @param debug * switch on debug output, defaults to \c false * * @return * the returned histogram (output, pass-by-reference does not work). */ void LoadHistogramTH2F(const TString& histogramName, const TString& inputFilename, double scale, TH2F*& returnedHistogram, bool debug = false) { // {{{ TFile inputFile(inputFilename); if (!inputFile.IsOpen()) { cerr << "Could not open '" << inputFilename << "' for reading." << endl; } else { TH2F* histogram = dynamic_cast<TH2F*>( inputFile.Get(histogramName) ); if (!histogram) { cerr << "No histogram named '" << histogramName << "' in file '" << inputFilename << "'" << endl; } else { if (debug) cerr << inputFilename << " " << histogramName << " entries=" << histogram->GetEntries() << " integral=" << histogram->Integral() << " scale*integral=" << scale*histogram->Integral() << endl; histogram->Scale(scale); if (!returnedHistogram) { returnedHistogram = new TH2F(*histogram); returnedHistogram->SetDirectory(0); // otherwise "TFile inputFile" owns this returnedHistogram and deletes it when "TFile inputFile" goes out of scope } else { returnedHistogram->Add(histogram); } } inputFile.Close(); } // }}} };
void DoWalkStuff(TTree*tree,Projection myProjection){ vector <Corrections> WalkCorrections; stringstream name; stringstream arg; stringstream conditions; TH2F * temp; for (int j=0;j<numComparisons;j++){ for (int i=0;i<numChannels;i++){ int chan=-1; name.str(""); arg.str(""); conditions.str(""); name<<"WalkChannel_"<<i<<ListOfWalkNames[j]; if (i % 2 == 0){//if even channel conditions<<"channels["<<0<<"]=="<<i<<"&&abs(CorGOE)<0.5&&channels[2]==8&&abs("<<ListOfWalkComparisons[j]<<")<200"; arg<<"energiesCor["<<0<<"]:"<<ListOfWalkComparisons[j]; chan=i; }else{ // odd chanel conditions<<"channels["<<1<<"]=="<<i<<"&&abs(CorGOE)<0.5&&channels[2]==8&&abs("<<ListOfWalkComparisons[j]<<")<200"; arg<<"energiesCor["<<1<<"]:"<<ListOfWalkComparisons[j]; chan=i; } cout<<arg.str()<<" "<<conditions.str()<<endl; temp = new TH2F(name.str().c_str(),"title",1000,x_start,x_end,1000,0,1500); tree->Project(name.str().c_str(),arg.str().c_str(),conditions.str().c_str()); Corrections c; c.histo=temp; c.channel=chan; if (temp->GetEntries()!=0){ c.bit=1; c.name=ListOfWalkNames[j]; }else c.bit=0; WalkCorrections.push_back(c); } } cout<<"Size "<<WalkCorrections.size()<<endl; // delete temp; TFile * out =new TFile("WalkOut.root","recreate"); int count=0; for (int i=0;i<WalkCorrections.size();i++){ cout<<"*******************************************"<<endl; if (WalkCorrections[i].bit==1){ myProjection.SetData(WalkCorrections[i].histo); myProjection.SetRange("auto"); myProjection.MakeProjections(); vector<double> coef=myProjection.GetGraphCoef(); cout<<"This is "<<WalkCorrections[i].name<<" the channel is "<<WalkCorrections[i].channel<<endl; for(int k=0;k<coef.size();k++) cout<<"walk"<<WalkCorrections[i].channel<<"cor walk"<<WalkCorrections[i].channel<<"_"<<k+1<<" "<<coef[k]<<endl; vector <TH1D*>v =myProjection.getProjections(); for (int i=0;i<v.size();i++) v[i]->Write(); TGraphErrors *gr = myProjection.getGraph(); gr->Write(); count++; myProjection.Reset(); } } out->Close(); }
void DoPosStuff(TTree*tree,Projection myProjection){ vector <Corrections> PosCorrections; stringstream name; stringstream arg; stringstream conditions; TH2F * temp; for (int j=0;j<numComparisons-1;j++){ for (int i=0;i<numChannels;i++){ name.str(""); arg.str(""); conditions.str(""); name<<"PosChannel_"<<i<<ListOfPosNames[j]; conditions<<"channels["<<0<<"]=="<<i<<"&&abs(CorGOE)<0.5&&channels[2]==8"; arg<<"CorGOE:"<<ListOfPosComparisons[j]; cout<<arg.str()<<" "<<conditions.str()<<endl; temp = new TH2F(name.str().c_str(),"title",1000,x_start,x_end,1000,-1,1); tree->Project(name.str().c_str(),arg.str().c_str(),conditions.str().c_str()); Corrections c; c.histo=temp; c.channel=i; if (temp->GetEntries()!=0){ c.bit=1; c.name =ListOfPosNames[j]; }else{ c.bit=0; } PosCorrections.push_back(c); } } // delete temp; TFile * out =new TFile("PosOut.root","recreate"); int count=0;//counter for the corrections that have bit=1 for (int i=0;i<PosCorrections.size();i++){ cout<<"*******************************************"<<endl; if (PosCorrections[i].bit==1){ myProjection.SetData(PosCorrections[i].histo); myProjection.SetRange("auto"); myProjection.MakeProjections(); vector<double> coef=myProjection.GetGraphCoef(); cout<<"This is "<<PosCorrections[i].name<<" the channel is "<<PosCorrections[i].channel<<endl; for(int k=0;k<coef.size();k++) cout<<"pos"<<PosCorrections[i].channel<<"cor goe"<<PosCorrections[i].channel<<"_"<<k+1<<" "<<coef[k]<<endl; vector <TH1D*>v =myProjection.getProjections(); for (int i=0;i<v.size();i++) v[i]->Write(); TGraphErrors *gr = myProjection.getGraph(); gr->Write(); count++; myProjection.Reset(); }else{ cout<<"Filler line for "<<i<<endl; } } out->Close(); }
void make_up(){ gROOT->Reset(); // gStyle->SetOptStat(1111); gStyle->SetOptStat(0); gStyle->SetPalette(1); gStyle->SetPaintTextFormat("2.2f"); //TFile * theFile = new TFile("/afs/cern.ch/user/c/carrillo/higgs/yy/hlt/CMSSW_5_3_2_patch4/src/genAnalyzer/GenAnalyzer/genAnalyzer.root"); TFile * theFile = new TFile("genAnalyzer.root"); //TFile * theFile = new TFile("HiggsGenHltRecoAnalyzer/test/genAnalyzer.root"); system("mkdir gen"); system("mkdir hlt"); cout<<"creating canvas"<<endl; TCanvas * Ca0 = new TCanvas("Ca0","bit0",1200,800); Ca0->cd(); Draw1D("ptLead","p_{T} (GeV)","gen/",theFile); Draw1D("ptTrail","p_{T} (GeV)","gen/",theFile); Draw1D("massDiphoton","mass_{#gamma #gamma} (GeV)","gen/",theFile); Draw1D("massHiggs","mass_{H} (GeV)","gen/",theFile); Draw1D("higgsEta","#eta_{H} (GeV)","gen/",theFile); Draw1D("higgsPhi","#phi_{H} (GeV)","gen/",theFile); Draw1D("higgsPt","#p (GeV)","gen/",theFile); Draw1D("higgsP","#p (GeV)","gen/",theFile); //turnon curve //Interesting bits // string interesting_bits[]={"418","6","416","8","5","412","233","7","234","10","187","9","22","198","430","404","188","199","21","190","197","208","201","207","195","196","206","193","424","192","204","194","203","205","209","189","200","191"}; //string in_bits[]={"418","6"} //for(int k=0;k<2;k++){ //Definition for the interesting bits //0 gen //1 acc //2 194*acc //3 195*acc //4 205*acc //5 OR*acc //6 OR*acc TH2F * numerator; TH2F * denominator; cout<<"going for 2D"<<endl; numerator = (TH2F*) (theFile->Get("wide_pt1pt2_5")); denominator= (TH2F*) (theFile->Get("wide_pt1pt2_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator->GetEntries()/denominator->GetEntries()<<endl; binomialEfficiency2D(numerator,denominator,true); Ca0->SaveAs(("hlt/or_over_acc_efficiency.png")); Ca0->Clear(); binomialEfficiency2D(numerator,denominator,false); Ca0->SaveAs(("hlt/eff_wide_pt1pt2.png")); Ca0->Clear(); numerator = (TH2F*) (theFile->Get("wide_pt1pt2_4")); denominator= (TH2F*) (theFile->Get("wide_pt1pt2_1")); cout<<"calling binomial efficiency 4/1 ="<<numerator->GetEntries()/denominator->GetEntries()<<endl; binomialEfficiency2D(numerator,denominator,true); Ca0->SaveAs(("hlt/205_over_acc_efficiency.png")); Ca0->Clear(); numerator = (TH2F*) (theFile->Get("wide_pt1pt2_3")); denominator= (TH2F*) (theFile->Get("wide_pt1pt2_1")); cout<<"calling binomial efficiency 3/1 ="<<numerator->GetEntries()/denominator->GetEntries()<<endl; binomialEfficiency2D(numerator,denominator,true); Ca0->SaveAs(("hlt/195_over_acc_efficiency.png")); Ca0->Clear(); numerator = (TH2F*) (theFile->Get("wide_pt1pt2_2")); denominator= (TH2F*) (theFile->Get("wide_pt1pt2_1")); cout<<"calling binomial efficiency 2/1 ="<<numerator->GetEntries()/denominator->GetEntries()<<endl; binomialEfficiency2D(numerator,denominator,true); Ca0->SaveAs(("hlt/194_over_acc_efficiency.png")); Ca0->Clear(); numerator = (TH2F*) (theFile->Get("pt1pt2_5")); denominator= (TH2F*) (theFile->Get("pt1pt2_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator->GetEntries()/denominator->GetEntries()<<endl; binomialEfficiency2D(numerator,denominator,false); Ca0->SaveAs(("hlt/eff_pt1pt2.png")); Ca0->Clear(); numerator = (TH2F*) (theFile->Get("eta1eta2_5")); denominator= (TH2F*) (theFile->Get("eta1eta2_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator->GetEntries()/denominator->GetEntries()<<endl; binomialEfficiency2D(numerator,denominator,false); Ca0->SaveAs(("hlt/eff_eta1eta2.png")); Ca0->Clear(); numerator = (TH2F*) (theFile->Get("phi1phi2_5")); denominator= (TH2F*) (theFile->Get("phi1phi2_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator->GetEntries()/denominator->GetEntries()<<endl; binomialEfficiency2D(numerator,denominator,false); Ca0->SaveAs(("hlt/eff_phi1phi2.png")); Ca0->Clear(); Draw2D("wide_pt1pt2","p_{T} Lead (GeV)","p_{T} Trail (GeV)","gen/",theFile); Draw2D("phi1phi2","#phi_{Lead}","#phi_{Trail}","gen/",theFile); Draw2D("eta1eta2","#eta_{Lead}","#eta_{Trail}","gen/",theFile); Draw2D("pt1pt2","p_{T} Lead (GeV)","p_{T} Trail (GeV)","gen/",theFile); //Binomial Efficiency 1D TH1F * numerator1D; TH1F * denominator1D; numerator1D = (TH1F*) (theFile->Get("higgsEta_5")); denominator1D = (TH1F*) (theFile->Get("higgsEta_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_higgsEta.png")); Ca0->Clear(); numerator1D = (TH1F*) (theFile->Get("higgsPhi_5")); denominator1D = (TH1F*) (theFile->Get("higgsPhi_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_higgsPhi.png")); Ca0->Clear(); numerator1D = (TH1F*) (theFile->Get("higgsP_5")); denominator1D = (TH1F*) (theFile->Get("higgsP_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_higgsP.png")); Ca0->Clear(); numerator1D = (TH1F*) (theFile->Get("higgsPt_5")); denominator1D = (TH1F*) (theFile->Get("higgsPt_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_higgsPt.png")); Ca0->Clear(); numerator1D = (TH1F*) (theFile->Get("massDiphoton_5")); denominator1D = (TH1F*) (theFile->Get("massDiphoton_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_massDiphoton.png")); Ca0->Clear(); numerator1D = (TH1F*) (theFile->Get("massHiggs_5")); denominator1D = (TH1F*) (theFile->Get("massHiggs_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_massHiggs.png")); Ca0->Clear(); numerator1D = (TH1F*) (theFile->Get("ptLead_5")); denominator1D = (TH1F*) (theFile->Get("ptLead_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_ptLead.png")); Ca0->Clear(); numerator1D = (TH1F*) (theFile->Get("ptTrail_5")); denominator1D = (TH1F*) (theFile->Get("ptTrail_1")); cout<<"calling binomial efficiency 5/1 ="<<numerator1D->GetEntries()/denominator1D->GetEntries()<<endl; binomialEfficiency1D(numerator1D,denominator1D); Ca0->SaveAs(("gen/eff_ptTrail.png")); Ca0->Clear(); exit(0); }