/*! * ### Example usage: \code .L $AliRoot_SRC/STAT/Macros/aliExternalInfo.C+ drawLogbook("LHC15o","pass1","QA.TPC.meanTPCncl>0","runDuration:totalEventsPhysics:totalNumberOfFilesMigrated:MonALISA.RCT.tpc_value"); drawLogbook("LHC10h","pass2","totalEventsPhysics>1000&&totalNumberOfFilesMigrated>20","runDuration:totalEventsPhysics:totalNumberOfFilesMigrated:MonALISA.RCT.tpc_value"); drawLogbook("LHC11h","pass2","totalEventsPhysics>1000&&totalNumberOfFilesMigrated>20","runDuration:totalEventsPhysics:totalNumberOfFilesMigrated:MonALISA.RCT.tpc_value"); \endcode */ void drawLogbook(TString period, TString pass,TString runSelection="", TString varSelection="runDuration:totalEventsPhysics:totalNumberOfFilesMigrated"){ TTree * treeLogbook = info.GetTree("Logbook",period,pass,"QA.TPC;QA.TRD;QA.ITS;MonALISA.RCT"); TObjArray *varList=0; if (varSelection[0]=='['){ //variable list using class selection // Use class selection to select variables varList=AliTreePlayer::selectMetadata(treeLogbook,varSelection,0); Int_t nvars=varList->GetEntries(); for (Int_t i=0; i<nvars;i++){ TString vname=varList->At(i)->GetName(); vname.ReplaceAll(".class",""); } // varList=AliTreePlayer::selectMetadata(treeLogbook, "[class==\"Logbook&&Time\"]",0); }else{ varList=varSelection.Tokenize(":"); } Int_t nvars=varList->GetEntries(); TCanvas * canvas = new TCanvas("drawLogbook","drawLogbook",1200,1000); canvas->Divide(1,nvars); for (Int_t i=0; i<nvars; i++){ canvas->cd(i+1); TString var=TString::Format("%s:run",varList->At(i)->GetName()); TStatToolkit::MakeGraphSparse(treeLogbook,var,runSelection,25,1,1)->Draw("ap"); Double_t mean = TMath::Mean(treeLogbook->GetSelectedRows(),treeLogbook->GetV1()); Double_t sum = treeLogbook->GetSelectedRows()*mean; latex.DrawLatexNDC(0.15,0.8,TString::Format("Mean=%0.0f",mean)); latex.DrawLatexNDC(0.15,0.7,TString::Format("Sum=%0.0f",sum)); } canvas->SaveAs(TString::Format("%s_%s.png",pass.Data(),period.Data()).Data()); }
void PlotPoints(){ GetAllMasses(); TCanvas *c1 = new TCanvas("c1","MassPlot",200,10,700,500); c1 -> DrawFrame(0, 0, 850, 600); TGraph *MassPlot = new TGraph(StopMass.size(), (float*) &StopMass[0], (float*) &NeutralinoMass[0]); MassPlot->SetMarkerStyle(20); MassPlot->SetMarkerSize(1.1); MassPlot->SetMarkerColor(2); MassPlot->Draw("P"); TLatex Title = TLatex(); Title.DrawLatexNDC(.40, .94, "Mass Points"); TLatex Xaxis = TLatex(); Xaxis.DrawLatexNDC(0.65, 0.03, "Stop Mass [GeV]"); TLatex Yaxis = TLatex(); Yaxis.SetTextAngle(90); Yaxis.DrawLatexNDC(0.03, 0.31, "Neutralino Mass [GeV]"); c1 -> Print(outputdir + "MassPoints.pdf", "pdf"); c1 -> Print(outputdir + "MassPoints.png", "png"); }
void plotMttResolution() { setTDRStyle(); TCanvas *c = new TCanvas("c", "c", 800, 800); TH1F *mtt = (TH1F*) _file0->Get("mtt_resolution_mva"); mtt->SetTitle(""); mtt->SetName("m_{t#bar{t}}"); mtt->GetXaxis()->SetTitle("m_{t#bar{t}} - m_{t#bar{t}}^{gen} (GeV)"); mtt->SetLineColor(TColor::GetColor("#542437")); mtt->SetLineColor(TColor::GetColor("#8A9B0F")); mtt->SetLineColor(TColor::GetColor("#C02942")); mtt->SetFillColor(mtt->GetLineColor()); mtt->SetFillStyle(3004); mtt->GetXaxis()->SetTitleOffset(1.2); TF1 *voigt = new TF1("voigt", "gaus", -100, 100); voigt->SetParName(0, "amp"); voigt->SetParName(2, "mean"); voigt->SetParName(1, "sigma"); voigt->SetParameter(0, mtt->GetMaximum()); voigt->SetParameter(2, 0); voigt->SetParameter(1, 100); mtt->Fit(voigt, "RVN"); voigt->SetLineColor(TColor::GetColor("#8A9B0F")); voigt->SetLineWidth(2); mtt->Draw(); voigt->Draw("same"); TLatex* latex = new TLatex(); latex->SetTextFont(42); latex->SetTextSize(0.033); latex->DrawLatexNDC(0.25, 0.84, TString::Format("mean = %.2f", voigt->GetParameter(1))); latex->DrawLatexNDC(0.25, 0.8, TString::Format("#sigma = %.2f", voigt->GetParameter(2))); gPad->Modified(); gPad->Update(); c->Print("mtt_resolution.pdf"); }
void derivefromprofile() { auto file = config.getfile_djt("mcPbqcd"); auto nt = (TTree *)file->Get("nt"); for (unsigned i=1;i<binbounds.size();i++) { int b1 = binbounds[i-1]; int b2 = binbounds[i]; auto p = new TProfile(Form("p%d%d",b1,b2),Form("prof"),100,0,200); nt->Project(p->GetName(),"(subid2 == 0 && refpt2 > 20):jtptSignal2",Form("weight*(jtpt1>100&&bin>=%d && bin<%d)",b1,b2)); profs.push_back(p); auto f = new TF1(Form("f%d%d",b1,b2),"exp(-[0]*exp(-[1]*x))"); f->SetParameters(100,0.1); p->Fit(f); fs.push_back(f); float median = -1/f->GetParameter(1)*log(-1/f->GetParameter(0)*log(0.5)); auto c = getc(); TLatex *Tl = new TLatex(); p->SetMinimum(0);p->SetMaximum(1); p->Draw(); f->Draw("same"); Tl->DrawLatexNDC(0.6,0.4,Form("PbPb bin %d-%d",b1,b2)); Tl->DrawLatexNDC(0.6,0.35,Form("median = %.2f",median)); TLine *l1 = new TLine(median,0,median, f->Eval(median)); l1->Draw(); TLine *l2 = new TLine(0,0.5,median, f->Eval(median)); l2->Draw(); SavePlot(c,Form("fit%d%d",b1,b2)); } }
void countZs(const char* filename, int run1=1, int run2=0, float lumi=0, bool add=false) { TFile *file = new TFile(filename); if (!file) return; TCanvas *c1 = new TCanvas(); c1->cd(); TH1F *h = (TH1F*) file->Get("Run summary/DiMuonHistograms/GlbGlbMuon_HM"); h->GetYaxis()->SetRangeUser(0,200); h->Draw(); TF1 *f = new TF1("f","gaus(0)+pol2(3)",70,110); f->SetParName(0,"norm"); f->SetParName(1,"mass"); f->SetParName(2,"width"); f->SetParameters(1.16028e+02,9.07785e+01,2.11556e+00,-2.17600e+01,9.67443e-01,-6.98382e-03); f->SetParLimits(0,0,1e6); f->SetParLimits(1,85,95); f->SetParLimits(2,1.5,5); h->Fit(f,"","",70,110); h->GetYaxis()->SetRangeUser(0,200); c1->Update(); TF1 *f2 = new TF1("f2","gaus(0)",70,110); f2->SetParameters(f->GetParameter(0),f->GetParameter(1),f->GetParameter(2)); int integral = (int) (f2->Integral(70,110) / h->GetBinWidth(2)); TLatex *tl = new TLatex(); tl->DrawLatexNDC(0.1,0.95,Form("pPb 8TeV [%i-%i, %.1f nb^{-1}]",run1,run2,lumi)); tl->DrawLatexNDC(0.18,0.75,Form("%i Z bosons",integral)); tl->DrawLatexNDC(0.18,0.7,Form("(#sigma = %.1f nb)",integral/lumi)); if (!add) c1->SaveAs(Form("plotZ_%i_%i.pdf",run1,run2)); else c1->SaveAs("plotZ.gif+100"); file->Close(); }
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 drawSpectra2D(const TString configFile, const TString inputFile, const TString outputFile, const TString outputFigureName) { std::cout<<"running drawSpectra2D()"<<std::endl; std::cout<<"configFile = "<< configFile.Data() <<std::endl; std::cout<<"inputFile = "<< inputFile.Data() <<std::endl; std::cout<<"outputFile = "<< outputFile.Data() <<std::endl; InputConfiguration configInput = InputConfigurationParser::Parse(configFile.Data()); CutConfiguration configCuts = CutConfigurationParser::Parse(configFile.Data()); if (!configInput.isValid) { std::cout << "Input configuration is invalid." << std::endl; std::cout << "exiting" << std::endl; return; } if (!configCuts.isValid) { std::cout << "Cut configuration is invalid." << std::endl; std::cout << "exiting" << std::endl; return; } /* * drawing behavior : * 1. If N = # formulas and N = # selections, then N histograms will be drawn, * 2. If 1 = # formulas and N = # selections, then N histograms will be drawn with the same formula. * 3. If N = # formulas and 1 = # selections, then N histograms will be drawn with the same selection. * 4. else, exit. */ // input for mode int mode = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_mode]; // input for TTree std::vector<std::string> treePaths = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_treePath]); std::vector<std::string> treeFriendsPath = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_treeFriendPath]); std::vector<std::string> treeFriendsPathIndividual = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_treeFriendPathIndividual]); std::vector<std::string> formulas = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_treeFormula]); std::string selectionBase = configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_treeSelectionBase]; std::vector<std::string> selections = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_treeSelection]); std::vector<std::string> selectionSplitter = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_treeSelectionSplitter]); std::vector<std::string> weights = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_TH1_weight]); // input for TH1 std::vector<std::string> titles = ConfigurationParser::ParseList(ConfigurationParser::ParseLatex(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_TH1_title])); std::vector<std::string> titlesX = ConfigurationParser::ParseList(ConfigurationParser::ParseLatex(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_TH1_titleX])); std::vector<std::string> titlesY = ConfigurationParser::ParseList(ConfigurationParser::ParseLatex(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_TH1_titleY])); // nBinsx, xLow, xUp, nBinsy, yLow, yUp for a TH2D histogram std::vector<std::vector<float>> TH2D_Bins_List = ConfigurationParser::ParseListTH2D_Bins(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_TH2D_Bins_List]); float titleOffsetX = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_titleOffsetX]; float titleOffsetY = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_titleOffsetY]; float markerSize = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_markerSize]; int drawNormalized = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_drawNormalized]; std::vector<std::string> drawOptions = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_drawOption]); std::vector<std::string> markerStyles = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_markerStyle]); std::vector<std::string> lineStyles = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_lineStyle]); std::vector<std::string> fillStyles = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_fillStyle]); std::vector<std::string> colors = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_color]); std::vector<std::string> fillColors = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_fillColor]); std::vector<std::string> lineColors = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_lineColor]); int lineWidth = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_lineWidth]; // input for TLegend std::vector<std::string> legendEntryLabels = ConfigurationParser::ParseList(ConfigurationParser::ParseLatex(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_legendEntryLabel])); std::string legendPosition = configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_legendPosition]; float legendOffsetX = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_legendOffsetX]; float legendOffsetY = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_legendOffsetY]; int legendBorderSize = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_legendBorderSize]; float legendWidth = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_legendWidth]; float legendHeight = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_legendHeight]; float legendTextSize = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_legendTextSize]; // input for text objects std::string tmpText = ConfigurationParser::ParseLatex(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_text]); std::vector<std::string> textLines = ConfigurationParser::ParseList(tmpText); int textFont = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_textFont]; float textSize = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_textSize]; std::string textPosition = configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_textPosition]; float textOffsetX = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_textOffsetX]; float textOffsetY = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_textOffsetY]; std::string tmpTextOverPad = ConfigurationParser::ParseLatex(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_textAbovePad]); std::vector<std::string> textsOverPad = ConfigurationParser::ParseList(tmpTextOverPad); std::vector<std::string> textsOverPadAlignments = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_textAbovePadAlign]); int textAbovePadFont = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_textAbovePadFont]; float textAbovePadSize = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_textAbovePadSize]; float textAbovePadOffsetX = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_textAbovePadOffsetX]; float textAbovePadOffsetY = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_textAbovePadOffsetY]; // input for TLine // y-axis positions of the horizontal lines to be drawn std::vector<float> TLines_horizontal = ConfigurationParser::ParseListFloat(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_TLine_horizontal]); std::vector<std::string> lineStyles_horizontal = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_LineStyle_horizontal]); // x-axis positions of the vertical lines to be drawn std::vector<float> TLines_vertical = ConfigurationParser::ParseListFloat(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_TLine_vertical]); std::vector<std::string> lineStyles_vertical = ConfigurationParser::ParseList(configInput.proc[INPUT::kPERFORMANCE].s[INPUT::k_LineStyle_vertical]); // input for TCanvas int windowWidth = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_windowWidth]; int windowHeight = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_windowHeight]; float leftMargin = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_leftMargin]; float rightMargin = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_rightMargin]; float bottomMargin = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_bottomMargin]; float topMargin = configInput.proc[INPUT::kPERFORMANCE].f[INPUT::k_topMargin]; int setLogx = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_setLogx]; int setLogy = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_setLogy]; int setLogz = configInput.proc[INPUT::kPERFORMANCE].i[INPUT::k_setLogz]; // set default values if (selections.size() == 0) selections.push_back("1"); if (weights.size() == 0) weights.push_back(INPUT_DEFAULT::TH1_weight.c_str()); // default weight = 1. if (titleOffsetX == 0) titleOffsetX = INPUT_DEFAULT::titleOffsetX; if (titleOffsetY == 0) titleOffsetY = INPUT_DEFAULT::titleOffsetY; if (drawNormalized >= INPUT_TH1::kN_TYPE_NORM) drawNormalized = INPUT_DEFAULT::drawNormalized; if (lineWidth == 0) lineWidth = INPUT_DEFAULT::lineWidth; if (markerSize == 0) markerSize = INPUT_DEFAULT::markerSize; if (textFont == 0) textFont = INPUT_DEFAULT::textFont; if (textSize == 0) textSize = INPUT_DEFAULT::textSize; if (windowWidth == 0) windowWidth = INPUT_DEFAULT::windowWidth; if (windowHeight == 0) windowHeight = INPUT_DEFAULT::windowHeight; if (leftMargin == 0) leftMargin = INPUT_DEFAULT::leftMargin; if (rightMargin == 0) rightMargin = INPUT_DEFAULT::rightMargin; if (bottomMargin == 0) bottomMargin = INPUT_DEFAULT::bottomMargin; if (topMargin == 0) topMargin = INPUT_DEFAULT::topMargin; int nTrees = treePaths.size(); int nFriends = treeFriendsPath.size(); int nFriendsIndividual = treeFriendsPathIndividual.size(); int nFormulas = formulas.size(); int nSelections = selections.size(); int nSelectionSplitter = selectionSplitter.size(); int nWeights = weights.size(); int nTitles = titles.size(); int nTitlesX = titlesX.size(); int nTitlesY = titlesY.size(); int nTH2D_Bins_List = TH2D_Bins_List[0].size(); int nDrawOptions = drawOptions.size(); int nMarkerStyles = markerStyles.size(); int nLineStyles = lineStyles.size(); int nFillStyles = fillStyles.size(); int nColors = colors.size(); int nFillColors = fillColors.size(); int nLineColors = lineColors.size(); int nLegendEntryLabels = legendEntryLabels.size(); int nTextLines = textLines.size(); int nTextsOverPad = textsOverPad.size(); int nTextsOverPadAlignments = textsOverPadAlignments.size(); int nTLines_horizontal = TLines_horizontal.size(); int nLineStyles_horizontal = lineStyles_horizontal.size(); int nTLines_vertical = TLines_vertical.size(); int nLineStyles_vertical = lineStyles_vertical.size(); // verbose about input configuration std::cout<<"Input Configuration :"<<std::endl; std::cout << "mode = " << mode << std::endl; if (mode == INPUT_MODE::k_comparison) { // in comparison mode "inputFile" should have the following format // inputFile = <inputFile1>,<inputFile2>,... // there should be no single space between <inputFile1> and <inputFile2>. // the idea is to feed the input samples as a single argument and split them in the macro. std::cout << "comparison mode : Spectra from two input samples are going to be compared." << std::endl; } std::cout << "nTrees = " << nTrees << std::endl; for (int i=0; i<nTrees; ++i) { std::cout << Form("treePaths[%d] = %s", i, treePaths.at(i).c_str()) << std::endl; } std::cout << "nFriends = " << nFriends << std::endl; for (int i=0; i<nFriends; ++i) { std::cout << Form("treeFriendsPath[%d] = %s", i, treeFriendsPath.at(i).c_str()) << std::endl; } std::cout << "nFriendsIndividual = " << nFriendsIndividual << std::endl; for (int i=0; i<nFriendsIndividual; ++i) { std::cout << Form("treeFriendsPathIndividual[%d] = %s", i, treeFriendsPathIndividual.at(i).c_str()) << std::endl; } std::cout << "nFormulas = " << nFormulas << std::endl; for (int i=0; i<nFormulas; ++i) { std::cout << Form("formulas[%d] = %s", i, formulas.at(i).c_str()) << std::endl; } std::cout << "selectionBase = " << selectionBase.c_str() << std::endl; std::cout << "nSelections = " << nSelections << std::endl; for (int i=0; i<nSelections; ++i) { std::cout << Form("selections[%d] = %s", i, selections.at(i).c_str()) << std::endl; } std::cout << "nSelectionSplitter = " << nSelectionSplitter << std::endl; for (int i=0; i<nSelectionSplitter; ++i) { std::cout << Form("selectionSplitter[%d] = %s", i, selectionSplitter.at(i).c_str()) << std::endl; } std::cout << "nWeights = " << nWeights << std::endl; for (int i=0; i<nWeights; ++i) { std::cout << Form("weights[%d] = %s", i, weights.at(i).c_str()) << std::endl; } std::cout << "nTitles = " << nTitles << std::endl; for (int i=0; i<nTitles; ++i) { std::cout << Form("titles[%d] = %s", i, titles.at(i).c_str()) << std::endl; } std::cout << "nTitlesX = " << nTitlesX << std::endl; for (int i=0; i<nTitlesX; ++i) { std::cout << Form("titlesX[%d] = %s", i, titlesX.at(i).c_str()) << std::endl; } std::cout << "nTitlesY = " << nTitlesY << std::endl; for (int i=0; i<nTitlesY; ++i) { std::cout << Form("titlesY[%d] = %s", i, titlesY.at(i).c_str()) << std::endl; } std::cout << "nTH2D_Bins_List = " << nTH2D_Bins_List << std::endl; for (int i=0; i<nTH2D_Bins_List; ++i) { std::cout << Form("TH2D_Bins_List[%d] = { ", i); std::cout << Form("%.0f, ", TH2D_Bins_List[0].at(i)); std::cout << Form("%f, ", TH2D_Bins_List[1].at(i)); std::cout << Form("%f }", TH2D_Bins_List[2].at(i)); std::cout << " { "; std::cout << Form("%.0f, ", TH2D_Bins_List[3].at(i)); std::cout << Form("%f, ", TH2D_Bins_List[4].at(i)); std::cout << Form("%f }", TH2D_Bins_List[5].at(i)) << std::endl;; } std::cout << "titleOffsetX = " << titleOffsetX << std::endl; std::cout << "titleOffsetY = " << titleOffsetY << std::endl; std::cout << "markerSize = " << markerSize << std::endl; std::cout << "drawNormalized = " << drawNormalized << std::endl; std::cout << "nDrawOptions = " << nDrawOptions << std::endl; for (int i = 0; i<nDrawOptions; ++i) { std::cout << Form("drawOptions[%d] = %s", i, drawOptions.at(i).c_str()) << std::endl; } std::cout << "nMarkerStyles = " << nMarkerStyles << std::endl; for (int i = 0; i<nMarkerStyles; ++i) { std::cout << Form("markerStyles[%d] = %s", i, markerStyles.at(i).c_str()) << std::endl; } std::cout << "nLineStyles = " << nLineStyles << std::endl; for (int i = 0; i<nLineStyles; ++i) { std::cout << Form("lineStyles[%d] = %s", i, lineStyles.at(i).c_str()) << std::endl; } std::cout << "nFillStyles = " << nFillStyles << std::endl; for (int i = 0; i<nFillStyles; ++i) { std::cout << Form("fillStyles[%d] = %s", i, fillStyles.at(i).c_str()) << std::endl; } std::cout << "nColors = " << nColors << std::endl; for (int i = 0; i<nColors; ++i) { std::cout << Form("colors[%d] = %s", i, colors.at(i).c_str()) << std::endl; } std::cout << "nFillColors = " << nFillColors << std::endl; for (int i = 0; i<nFillColors; ++i) { std::cout << Form("fillColors[%d] = %s", i, fillColors.at(i).c_str()) << std::endl; } std::cout << "nLineColors = " << nLineColors << std::endl; for (int i = 0; i<nLineColors; ++i) { std::cout << Form("lineColors[%d] = %s", i, lineColors.at(i).c_str()) << std::endl; } std::cout << "lineWidth = " << lineWidth << std::endl; std::cout << "nLegendEntryLabels = " << nLegendEntryLabels << std::endl; for (int i = 0; i<nLegendEntryLabels; ++i) { std::cout << Form("legendEntryLabels[%d] = %s", i, legendEntryLabels.at(i).c_str()) << std::endl; } if (nLegendEntryLabels > 0) { std::cout << "legendPosition = " << legendPosition.c_str() << std::endl; if (legendPosition.size() == 0) std::cout<< "No position is provided, legend will not be drawn." <<std::endl; std::cout << "legendOffsetX = " << legendOffsetX << std::endl; std::cout << "legendOffsetY = " << legendOffsetY << std::endl; std::cout << "legendBorderSize = " << legendBorderSize << std::endl; std::cout << "legendWidth = " << legendWidth << std::endl; std::cout << "legendHeight = " << legendHeight << std::endl; std::cout << "legendTextSize = " << legendTextSize << std::endl; } std::cout << "nTextLines = " << nTextLines << std::endl; for (int i = 0; i<nTextLines; ++i) { std::cout << Form("textLines[%d] = %s", i, textLines.at(i).c_str()) << std::endl; } if (nTextLines > 0) { std::cout << "textFont = " << textFont << std::endl; std::cout << "textSize = " << textSize << std::endl; std::cout << "textPosition = " << textPosition << std::endl; std::cout << "textOffsetX = " << textOffsetX << std::endl; std::cout << "textOffsetY = " << textOffsetY << std::endl; } std::cout << "nTextsOverPad = " << nTextsOverPad << std::endl; for (int i = 0; i<nTextsOverPad; ++i) { std::cout << Form("textsOverPad[%d] = %s", i, textsOverPad.at(i).c_str()) << std::endl; } if (nTextsOverPad > 0) { std::cout << "nTextsOverPadAlignments = " << nTextsOverPadAlignments << std::endl; for (int i = 0; i<nTextsOverPadAlignments; ++i) { std::cout << Form("textsOverPadAlignments[%d] = %s", i, textsOverPadAlignments.at(i).c_str()) << std::endl; } std::cout << "textAbovePadFont = " << textAbovePadFont << std::endl; std::cout << "textAbovePadSize = " << textAbovePadSize << std::endl; std::cout << "textAbovePadOffsetX = " << textAbovePadOffsetX << std::endl; std::cout << "textAbovePadOffsetY = " << textAbovePadOffsetY << std::endl; } std::cout << "nTLines_horizontal = " << nTLines_horizontal << std::endl; for (int i = 0; i<nTLines_horizontal; ++i) { std::cout << Form("TLines_horizontal[%d] = %f", i, TLines_horizontal.at(i)) << std::endl; } if (nTLines_horizontal > 0) { std::cout << "nLineStyles_horizontal = " << nLineStyles_horizontal << std::endl; for (int i = 0; i<nLineStyles_horizontal; ++i) { std::cout << Form("lineStyles_horizontal[%d] = %s", i, lineStyles_horizontal.at(i).c_str()) << std::endl; } } std::cout << "nTLines_vertical = " << nTLines_vertical << std::endl; for (int i = 0; i<nTLines_vertical; ++i) { std::cout << Form("TLines_vertical[%d] = %f", i, TLines_vertical.at(i)) << std::endl; } if (nTLines_vertical > 0) { std::cout << "nLineStyles_vertical = " << nLineStyles_vertical << std::endl; for (int i = 0; i<nLineStyles_vertical; ++i) { std::cout << Form("lineStyles_vertical[%d] = %s", i, lineStyles_vertical.at(i).c_str()) << std::endl; } } std::cout << "windowWidth = " << windowWidth << std::endl; std::cout << "windowHeight = " << windowHeight << std::endl; std::cout << "leftMargin = " << leftMargin << std::endl; std::cout << "rightMargin = " << rightMargin << std::endl; std::cout << "bottomMargin = " << bottomMargin << std::endl; std::cout << "topMargin = " << topMargin << std::endl; std::cout << "setLogx = " << setLogx << std::endl; std::cout << "setLogy = " << setLogy << std::endl; std::cout << "setLogz = " << setLogz << std::endl; // cut configuration // verbose about cut configuration std::cout<<"Cut Configuration :"<<std::endl; std::cout<<"Input handling :"<< std::endl; std::vector<std::string> inputFileArguments = InputConfigurationParser::ParseFileArgument(inputFile.Data()); int nInputFileArguments = inputFileArguments.size(); // if no mode is specified (which is what happens most of the time), then it is expected that nInputFileArguments = 1. std::cout<<"nInputFileArguments (number of input file arguments) = "<< nInputFileArguments << std::endl; for (int i = 0; i < nInputFileArguments; ++i) { std::cout << Form("inputFileArguments[%d] = %s", i, inputFileArguments.at(i).c_str()) << std::endl; } std::vector<std::vector<std::string>> inputFiles(nInputFileArguments); std::cout<<"#####"<< std::endl; for (int i = 0; i < nInputFileArguments; ++i) { if (nInputFileArguments > 1) { std::cout<<"###"<< std::endl; std::cout<<"inputFileArgument = " << inputFileArguments.at(i).c_str() << std::endl; } inputFiles[i] = InputConfigurationParser::ParseFiles(inputFileArguments.at(i)); std::cout<<"input ROOT files : num = " << inputFiles[i].size() << std::endl; for (std::vector<std::string>::iterator it = inputFiles[i].begin() ; it != inputFiles[i].end(); ++it) { std::cout<<(*it).c_str()<< std::endl; } } std::cout<<"##### END #####"<< std::endl; // check consistency of the input file arguments with the mode if (mode == INPUT_MODE::k_noMode && nInputFileArguments > 1) { std::cout<<"no specific mode is chosen. more than one input samples are provided."<< std::endl; std::cout<<"exiting"<< std::endl; return; } if (mode == INPUT_MODE::k_comparison && nInputFileArguments == 1) { std::cout<<"comparison mode is chosen. But only one input sample is provided."<< std::endl; std::cout<<"exiting"<< std::endl; return; } if (nTrees == 1 && nFriendsIndividual > 0) { std::cout<<"nTrees = "<< nTrees <<", nFriendsIndividual = " << nFriendsIndividual << std::endl; std::cout<<"There is only one tree to be plotted, it does not make sense to use individual friend trees."<< std::endl; std::cout<<"exiting"<< std::endl; return; } else if (nTrees > 1 && nFriendsIndividual > 0 && nTrees != nFriendsIndividual) { std::cout<<"nTrees = "<< nTrees <<", nFriendsIndividual = " << nFriendsIndividual << std::endl; std::cout<<"exiting"<< std::endl; return; } if (nSelectionSplitter == 1) { std::cout << "nSelectionSplitter = "<< nSelectionSplitter << std::endl; std::cout << "selectionSplitter has been set to have exactly one selection"<< std::endl; std::cout << "selectionSplitter is allowed to be either empty or to have more than one selections"<< std::endl; std::cout << "exiting"<< std::endl; return; } int nSplits = 1; if (nSelectionSplitter > 1) nSplits = nSelectionSplitter; int nSelectionsTot = nSelections * nSplits; int nFormulasTot = nFormulas * nSplits; TH1::SetDefaultSumw2(); int nHistos = nFormulasTot; if (nFormulas == 1 && nSelections > nFormulas) nHistos = nSelectionsTot; else if (nFormulas == 1 && nSelections == 1 && nTrees > nFormulas) nHistos = nTrees * nSplits; else if (nFormulas > 1 && nSelections > 1 && nFormulas != nSelections) { std::cout << "mismatch of number of formulas and number of selections"<< std::endl; std::cout << "nHistos = "<< nHistos << std::endl; std::cout << "nSelections = "<< nSelections << std::endl; std::cout << "exiting " << std::endl; return; } else if (nFormulas > 1 && nTrees > 1 && nFormulas != nTrees) { std::cout << "mismatch of number of formulas and number of trees"<< std::endl; std::cout << "nHistos = "<< nHistos << std::endl; std::cout << "nTrees = "<< nTrees << std::endl; std::cout << "exiting " << std::endl; return; } else if (nSelections > 1 && nTrees > 1 && nSelections != nTrees) { std::cout << "mismatch of number of selections and number of trees"<< std::endl; std::cout << "nHistos = "<< nHistos << std::endl; std::cout << "nSelections = "<< nSelections << std::endl; std::cout << "nTrees = "<< nTrees << std::endl; std::cout << "exiting " << std::endl; return; } TFile* output = TFile::Open(outputFile.Data(),"RECREATE"); output->cd(); int nHistosInput = nHistos/nSplits; // number of histograms without considering selectionSplitter std::cout << "nHistos = " << nHistos << std::endl; TH2D* h[nHistos]; for (int i=0; i<nHistos; ++i) { int nBinsx = (int)TH2D_Bins_List[0].at(0); float xLow = TH2D_Bins_List[1].at(0); float xUp = TH2D_Bins_List[2].at(0); int nBinsy = (int)TH2D_Bins_List[3].at(0); float yLow = TH2D_Bins_List[4].at(0); float yUp = TH2D_Bins_List[5].at(0); if (nTH2D_Bins_List == nHistosInput) { nBinsx = (int)TH2D_Bins_List[0].at(i%nTH2D_Bins_List); xLow = TH2D_Bins_List[1].at(i%nTH2D_Bins_List); xUp = TH2D_Bins_List[2].at(i%nTH2D_Bins_List); nBinsy = (int)TH2D_Bins_List[3].at(i%nTH2D_Bins_List); yLow = TH2D_Bins_List[4].at(i%nTH2D_Bins_List); yUp = TH2D_Bins_List[5].at(i%nTH2D_Bins_List); } std::string title = ""; if (nTitles == 1) { if (titles.at(0).compare(CONFIGPARSER::nullInput) != 0) title = titles.at(0).c_str(); } else if (nTitles == nHistosInput) { if (titles.at(i%nTitles).compare(CONFIGPARSER::nullInput) != 0) title = titles.at(i%nTitles).c_str(); } else if (nTitles == nHistos) { if (titles.at(i).compare(CONFIGPARSER::nullInput) != 0) title = titles.at(i).c_str(); } std::string titleX = ""; if (nTitlesX == 1) titleX = titlesX.at(0).c_str(); else if (nTitlesX == nHistosInput) titleX = titlesX.at(i%nTitlesX).c_str(); else if (nTitlesX == nHistos) titleX = titlesX.at(i).c_str(); std::string titleY = ""; if (nTitlesY == 1) titleY = titlesY.at(0).c_str(); else if (nTitlesY == nHistosInput) titleY = titlesY.at(i%nTitlesY).c_str(); else if (nTitlesY == nHistos) titleY = titlesY.at(i).c_str(); h[i] = new TH2D(Form("h2D_%d", i),Form("%s;%s;%s", title.c_str(), titleX.c_str(), titleY.c_str()), nBinsx, xLow, xUp, nBinsy, yLow, yUp); } // if no mode is specified (which is what happens most of the time), then it is expected that nInputFileArguments = 1. // so in that case : 1.) the "TTree*" objects below are effectively 1D, not 2D. 2.) the loops below have effective depth 1, not 2. TTree* trees[nTrees][nInputFileArguments]; TTree* treeFriends[nFriends][nInputFileArguments]; TTree* treeFriendsIndividual[nFriendsIndividual][nInputFileArguments]; TTree* treeHiForestInfo[nInputFileArguments]; Long64_t entries[nInputFileArguments]; Long64_t entriesSelected[nHistos]; std::fill_n(entriesSelected, nHistos, 0); int nFiles[nInputFileArguments]; TFile* fileTmp = 0; std::cout << "initial reading to get the number of entries (if there is only one input file) and HiForest info" << std::endl; for (int iInFileArg = 0; iInFileArg < nInputFileArguments; ++iInFileArg) { nFiles[iInFileArg] = inputFiles[iInFileArg].size(); if (nInputFileArguments > 1) { std::cout <<"iInFileArg = " << iInFileArg << " , "<< std::endl; } // read the first file only to get the HiForest info std::string inputPath = inputFiles[iInFileArg].at(0).c_str(); fileTmp = new TFile(inputPath.c_str(), "READ"); bool treeExists = true; if (nFiles[iInFileArg] == 1) { // read one tree only to get the number of entries trees[0][iInFileArg] = (TTree*)fileTmp->Get(treePaths.at(0).c_str()); if (!trees[0][iInFileArg]) { std::cout << "tree is not found in the path : "<< treePaths.at(0).c_str() <<". skipping file." << std::endl; treeExists = false; } if (treeExists) { entries[iInFileArg] = trees[0][iInFileArg]->GetEntries(); std::cout << "entries = " << entries[iInFileArg] << std::endl; } } if (treeExists) { treeHiForestInfo[0] = (TTree*)fileTmp->Get("HiForest/HiForestInfo"); if (!treeHiForestInfo[0]) { std::cout << "HiForest/HiForestInfo tree is not found." << std::endl; treeExists = false; } if (treeExists) { HiForestInfoController hfic(treeHiForestInfo[0]); if (iInFileArg == 0) std::cout<<"### HiForestInfo Tree ###"<< std::endl; else std::cout<<"### HiForestInfo Tree, input "<< iInFileArg+1 << " ###" << std::endl; hfic.printHiForestInfo(); std::cout<<"###"<< std::endl; } } fileTmp->Close(); } std::cout << "TTree::Draw()" <<std::endl; for (int iInFileArg = 0; iInFileArg < nInputFileArguments; ++iInFileArg) { if (nInputFileArguments > 1) { std::cout <<"iInFileArg = " << iInFileArg << std::endl; } entries[iInFileArg] = 0; for (int iFile = 0; iFile < nFiles[iInFileArg]; ++iFile) { std::string inputPath = inputFiles[iInFileArg].at(iFile).c_str(); std::cout <<"iFile = " << iFile << " , " ; std::cout <<"reading input file : " << inputPath.c_str() << std::endl; fileTmp = new TFile(inputPath.c_str(), "READ"); // check if the file is usable, if not skip the file. if (isGoodFile(fileTmp) != 0) { std::cout << "File is not good. skipping file." << std::endl; continue; } bool treeExists = true; for (int i=0; i<nTrees; ++i) { trees[i][iInFileArg] = (TTree*)fileTmp->Get(treePaths.at(i).c_str()); if (!trees[i][iInFileArg]) { std::cout << "tree is not found in the path : "<< treePaths.at(i).c_str() <<". skipping file." << std::endl; treeExists = false; } } for (int i=0; i<nFriends; ++i) { treeFriends[i][iInFileArg] = (TTree*)fileTmp->Get(treeFriendsPath.at(i).c_str()); if (!treeFriends[i][iInFileArg]) { std::cout << "tree is not found in the path : "<< treeFriendsPath.at(i).c_str() <<". skipping file." << std::endl; treeExists = false; } } if (!treeExists) continue; // add friends for (int i=0; i<nTrees; ++i) { for (int j=0; j<nFriends; ++j) { trees[i][iInFileArg]->AddFriend(treeFriends[j][iInFileArg], Form("t%d", j)); } } for (int i=0; i < nFriendsIndividual; ++i) { if (treeFriendsPathIndividual.at(i).compare(CONFIGPARSER::nullInput) != 0) { treeFriendsIndividual[i][iInFileArg] = (TTree*)fileTmp->Get(treeFriendsPathIndividual.at(i).c_str()); } } if (nFriendsIndividual > 0) { for (int i=0; i<nTrees; ++i) { if (treeFriendsPathIndividual.at(i).compare(CONFIGPARSER::nullInput) != 0) { trees[i][0]->AddFriend(treeFriendsIndividual[i][0], Form("tSelf%d", i)); } } } Long64_t entriesTmp = trees[0][iInFileArg]->GetEntries(); // assume all the trees have same number of entries entries[iInFileArg] += entriesTmp; if (nInputFileArguments == 1) { std::cout << "entries in File = " << entriesTmp << std::endl; } else { std::cout << Form("entries[%d] = ", iInFileArg) << entriesTmp << std::endl; } output->cd(); for (int i=0; i<nHistos; ++i) { int treeIndex = 0; if (nHistosInput == nTrees) treeIndex = i%nTrees; // std::cout << "treePath = " << treePaths.at(treeIndex).c_str() << ", "; int iInFileArg = 0; if (mode == INPUT_MODE::k_comparison) { iInFileArg = i%nInputFileArguments; std::cout << "iInFileArg = " << iInFileArg << ", "; } std::string formula = formulas.at(0).c_str(); std::string selection = selections.at(0).c_str(); std::string weight = weights.at(0).c_str(); if (nHistosInput == nFormulas) formula = formulas.at(i%nFormulas).c_str(); if (nHistosInput == nSelections) selection = selections.at(i%nSelections).c_str(); if (nHistosInput == nWeights) weight = weights.at(i%nWeights).c_str(); std::string selectionSplit = ""; if (nSelectionSplitter > 1) selectionSplit = selectionSplitter.at(i/ (nHistos/nSelectionSplitter)).c_str(); // std::cout << "drawing histogram i = " << i << ", "; TCut selectionFinal = selectionBase.c_str(); selectionFinal = selectionFinal && selection.c_str(); if (selectionSplit.size() > 0) selectionFinal = selectionFinal && selectionSplit.c_str(); Long64_t entriesSelectedTmp = trees[treeIndex][iInFileArg]->GetEntries(selectionFinal.GetTitle()); // std::cout << "entriesSelected in file = " << entriesSelectedTmp << std::endl; entriesSelected[i] += entriesSelectedTmp; TCut weight_AND_selection = Form("(%s)*(%s)", weight.c_str(), selectionFinal.GetTitle()); trees[treeIndex][iInFileArg]->Draw(Form("%s >>+ %s", formula.c_str(), h[i]->GetName()), weight_AND_selection.GetTitle(), "goff"); } fileTmp->Close(); } } std::cout << "TTree::Draw() ENDED" <<std::endl; for (int i = 0; i < nInputFileArguments; ++i) { if (nInputFileArguments == 1) { std::cout << "entries = " << entries[0] << std::endl; } else { std::cout << Form("entries[%d] = ", i) << entries[i] << std::endl; } } std::cout << "### selected entries" << std::endl; for (int i = 0; i < nHistos; ++i) { std::cout << "TH1D i = " << i << ", "; int treeIndex = 0; if (nHistosInput == nTrees) treeIndex = i%nTrees; std::cout << "treePath = " << treePaths.at(treeIndex).c_str() << ", "; std::cout << "entriesSelected = " << entriesSelected[i] << std::endl; } std::cout << "###" << std::endl; // print info about histograms for (int i=0; i<nHistos; ++i) { std::cout << "#####" << std::endl; std::cout << Form("h[%d]", i) << std::endl; std::string summary = summaryTH1(h[i]); std::cout << summary.c_str() << std::endl; } output->cd(); TH2D* h_normInt[nHistos]; TH2D* h_normEvents[nHistos]; for (int i=0; i<nHistos; ++i) { h[i]->Write(); h_normInt[i] = (TH2D*)h[i]->Clone(Form("%s_normInt", h[i]->GetName())); h_normInt[i]->Scale(1./h[i]->Integral()); h_normInt[i]->Write(); h_normEvents[i] = (TH2D*)h[i]->Clone(Form("%s_normEvents", h[i]->GetName())); h_normEvents[i]->Scale(1./entriesSelected[i]); h_normEvents[i]->Write(); } // histograms are written. After this point changes to the histograms will not be reflected in the output ROOT file. // set the style of the histograms for canvases to be written for (int i=0; i<nHistos; ++i) { h[i]->SetTitleOffset(titleOffsetX,"X"); h[i]->SetTitleOffset(titleOffsetY,"Y"); h_normInt[i]->SetTitleOffset(titleOffsetX,"X"); h_normInt[i]->SetTitleOffset(titleOffsetY,"Y"); h_normEvents[i]->SetTitleOffset(titleOffsetX,"X"); h_normEvents[i]->SetTitleOffset(titleOffsetY,"Y"); // default marker style and color h[i]->SetMarkerStyle(kFullCircle); h[i]->SetMarkerColor(kBlack); h_normInt[i]->SetMarkerStyle(kFullCircle); h_normInt[i]->SetMarkerColor(kBlack); h_normEvents[i]->SetMarkerStyle(kFullCircle); h_normEvents[i]->SetMarkerColor(kBlack); // no stats box in the final plots h[i]->SetStats(false); h_normInt[i]->SetStats(false); h_normEvents[i]->SetStats(false); } // write canvases TCanvas* c; for (int i=0; i<nHistos; ++i) { c = new TCanvas(Form("cnv_%d",i),"",windowWidth,windowHeight); c->SetTitle(h[i]->GetTitle()); setCanvasMargin(c, leftMargin, rightMargin, bottomMargin, topMargin); setCanvasFinal(c, setLogx, setLogy, setLogz); c->cd(); h[i]->SetTitleOffset(titleOffsetX,"X"); h[i]->SetTitleOffset(titleOffsetY,"Y"); h[i]->SetStats(false); h[i]->Draw("colz"); c->Write(); c->Close(); // do not use Delete() for TCanvas. // normalized to 1. c = new TCanvas(Form("cnv_%d_normInt",i),"",windowWidth,windowHeight); c->SetTitle(h_normInt[i]->GetTitle()); setCanvasMargin(c, leftMargin, rightMargin, bottomMargin, topMargin); setCanvasFinal(c, setLogx, setLogy, setLogz); c->cd(); h_normInt[i]->SetTitleOffset(titleOffsetX,"X"); h_normInt[i]->SetTitleOffset(titleOffsetY,"Y"); h_normInt[i]->SetStats(false); h_normInt[i]->Draw("colz"); c->Write(); c->Close(); // do not use Delete() for TCanvas. // normalized by number of events c = new TCanvas(Form("cnv_%d_normEvents",i),"",windowWidth,windowHeight); c->SetTitle(h_normEvents[i]->GetTitle()); setCanvasMargin(c, leftMargin, rightMargin, bottomMargin, topMargin); setCanvasFinal(c, setLogx, setLogy, setLogz); c->cd(); h_normEvents[i]->SetTitleOffset(titleOffsetX,"X"); h_normEvents[i]->SetTitleOffset(titleOffsetY,"Y"); h_normEvents[i]->SetStats(false); h_normEvents[i]->Draw("colz"); c->Write(); c->Close(); // do not use Delete() for TCanvas. } // canvases are written. // set style of the histograms for the canvases to be saved as picture for(int i=0; i<nHistos; ++i) { std::string drawOption = "colz"; if (nDrawOptions == 1) { if (drawOptions.at(0).compare(CONFIGPARSER::nullInput) != 0) drawOption = drawOptions.at(0).c_str(); } else if (nDrawOptions == nHistosInput) { if (drawOptions.at(i).compare(CONFIGPARSER::nullInput) != 0) drawOption = drawOptions.at(i%nDrawOptions).c_str(); } // https://root.cern.ch/doc/master/classTObject.html#abe2a97d15738d5de00cd228e0dc21e56 // TObject::SetDrawOption() is not suitable for the approach here. int markerStyle = GRAPHICS::markerStyle; if (nMarkerStyles == 1) markerStyle = GraphicsConfigurationParser::ParseMarkerStyle(markerStyles.at(0)); else if (nMarkerStyles == nHistosInput) markerStyle = GraphicsConfigurationParser::ParseMarkerStyle(markerStyles.at(i%nMarkerStyles)); h[i]->SetMarkerStyle(markerStyle); h_normInt[i]->SetMarkerStyle(markerStyle); h_normEvents[i]->SetMarkerStyle(markerStyle); int lineStyle = GRAPHICS::lineStyle; if (nLineStyles == 1) lineStyle = GraphicsConfigurationParser::ParseLineStyle(lineStyles.at(0)); else if (nLineStyles == nHistosInput) lineStyle = GraphicsConfigurationParser::ParseLineStyle(lineStyles.at(i%nLineStyles)); h[i]->SetLineStyle(lineStyle); h_normInt[i]->SetLineStyle(lineStyle); h_normEvents[i]->SetLineStyle(lineStyle); int fillStyle = GRAPHICS::fillStyle; if (nFillStyles == 1) fillStyle = GraphicsConfigurationParser::ParseLineStyle(fillStyles.at(0)); else if (nFillStyles == nHistosInput) fillStyle = GraphicsConfigurationParser::ParseLineStyle(fillStyles.at(i%nFillStyles)); h[i]->SetFillStyle(fillStyle); h_normInt[i]->SetFillStyle(fillStyle); h_normEvents[i]->SetFillStyle(fillStyle); int color = GRAPHICS::colors[i]; if (nColors == 1) color = GraphicsConfigurationParser::ParseColor(colors.at(0)); else if (nColors == nHistosInput) color = GraphicsConfigurationParser::ParseColor(colors.at(i%nColors)); h[i]->SetMarkerColor(color); h[i]->SetLineColor(color); h_normInt[i]->SetMarkerColor(color); h_normInt[i]->SetLineColor(color); h_normEvents[i]->SetMarkerColor(color); h_normEvents[i]->SetLineColor(color); int fillColor = -1; if (nFillColors == 1) fillColor = GraphicsConfigurationParser::ParseColor(fillColors.at(0)); else if (nFillColors == nHistosInput) fillColor = GraphicsConfigurationParser::ParseColor(fillColors.at(i%nFillColors)); if (fillColor != -1) { h[i]->SetFillColor(fillColor); h_normInt[i]->SetFillColor(fillColor); h_normEvents[i]->SetFillColor(fillColor); } int lineColor = -1; if (nLineColors == 1) lineColor = GraphicsConfigurationParser::ParseColor(lineColors.at(0)); else if (nLineColors == nHistosInput) lineColor = GraphicsConfigurationParser::ParseColor(lineColors.at(i%nLineColors)); if (nLineColors != -1) { h[i]->SetLineColor(lineColor); h_normInt[i]->SetLineColor(lineColor); h_normEvents[i]->SetLineColor(lineColor); } if(lineWidth != INPUT_DEFAULT::lineWidth) { if (drawOption.find("hist") != std::string::npos) { h[i]->SetLineWidth(lineWidth); h_normInt[i]->SetLineWidth(lineWidth); h_normEvents[i]->SetLineWidth(lineWidth); } } h[i]->SetMarkerSize(markerSize); h_normInt[i]->SetMarkerSize(markerSize); h_normEvents[i]->SetMarkerSize(markerSize); } TH1D* h_draw[nHistos]; for (int i=0; i<nHistos; ++i) { if (drawNormalized == INPUT_TH1::k_normInt) { h_draw[i] = (TH1D*)h_normInt[i]->Clone(Form("h_%d_draw", i)); } else if (drawNormalized == INPUT_TH1::k_normEvents) { h_draw[i] = (TH1D*)h_normEvents[i]->Clone(Form("h_%d_draw", i)); } else { // no normalization h_draw[i] = (TH1D*)h[i]->Clone(Form("h_%d_draw", i)); } } for (int i = 0; i<nHistos; ++i) { c = new TCanvas(Form("cnv_drawSpectra2D_%d", i),"",windowWidth,windowHeight); setCanvasMargin(c, leftMargin, rightMargin, bottomMargin, topMargin); setCanvasFinal(c, setLogx, setLogy, setLogz); c->cd(); TLegend* leg = new TLegend(); std::string drawOption = ""; if (nDrawOptions == 1) drawOption = drawOptions.at(0).c_str(); else if (nDrawOptions == nHistosInput) drawOption = drawOptions.at(i%nDrawOptions).c_str(); h_draw[i]->Draw(drawOption.c_str()); if (nLegendEntryLabels == nHistosInput) { std::string label = legendEntryLabels.at(i%nLegendEntryLabels).c_str(); std::string legendOption = "lpf"; if (drawOption.find("hist") != std::string::npos) legendOption = "lf"; if (label.compare(CONFIGPARSER::nullInput) != 0) leg->AddEntry(h_draw[i], label.c_str(), legendOption.c_str()); } if (legendTextSize != 0) leg->SetTextSize(legendTextSize); leg->SetBorderSize(legendBorderSize); double height = calcTLegendHeight(leg); double width = calcTLegendWidth(leg); if (legendHeight != 0) height = legendHeight; if (legendWidth != 0) width = legendWidth; if (legendPosition.size() > 0) { // draw the legend if really a position is provided. setLegendPosition(leg, legendPosition, c, height, width, legendOffsetX, legendOffsetY); leg->Draw(); } // add Text TLatex* latex = 0; if (nTextLines > 0) { latex = new TLatex(); latex->SetTextFont(textFont); latex->SetTextSize(textSize); setTextAlignment(latex, textPosition); std::vector<std::pair<float,float>> textCoordinates = calcTextCoordinates(textLines, textPosition, c, textOffsetX, textOffsetY); for (int i = 0; i<nTextLines; ++i) { float x = textCoordinates.at(i).first; float y = textCoordinates.at(i).second; latex->DrawLatexNDC(x, y, textLines.at(i).c_str()); } } // add Text above the pad TLatex* latexOverPad = 0; if (nTextsOverPad > 0) { latexOverPad = new TLatex(); latexOverPad->SetTextFont(textAbovePadFont); latexOverPad->SetTextSize(textAbovePadSize); for (int i = 0; i < nTextsOverPad; ++i) { int textOverPadAlignment = GRAPHICS::textAlign; if (nTextsOverPadAlignments == 1) textOverPadAlignment = GraphicsConfigurationParser::ParseTextAlign(textsOverPadAlignments.at(0)); else if (nTextsOverPadAlignments == nTextsOverPad) textOverPadAlignment = GraphicsConfigurationParser::ParseTextAlign(textsOverPadAlignments.at(i)); latexOverPad->SetTextAlign(textOverPadAlignment); setTextAbovePad(latexOverPad, c, textAbovePadOffsetX, textAbovePadOffsetY); latexOverPad->DrawLatexNDC(latexOverPad->GetX(), latexOverPad->GetY(), textsOverPad.at(i).c_str()); } } // add TLine TLine* line_horizontal[nTLines_horizontal]; for (int iLine = 0; iLine<nTLines_horizontal; ++iLine) { // draw horizontal line double xmin = h[i]->GetXaxis()->GetBinLowEdge(h[i]->GetXaxis()->GetFirst()); double xmax = h[i]->GetXaxis()->GetBinLowEdge(h[i]->GetXaxis()->GetLast()+1); int lineStyle_horizontal = GRAPHICS::lineStyle_horizontal; if (nLineStyles_horizontal == 1) lineStyle_horizontal = GraphicsConfigurationParser::ParseLineStyle(lineStyles_horizontal.at(0)); else if (nLineStyles_horizontal == nTLines_horizontal) lineStyle_horizontal = GraphicsConfigurationParser::ParseLineStyle(lineStyles_horizontal.at(iLine)); line_horizontal[iLine] = new TLine(xmin, TLines_horizontal.at(iLine), xmax, TLines_horizontal.at(iLine)); line_horizontal[iLine]->SetLineStyle(lineStyle_horizontal); // https://root.cern.ch/doc/master/TAttLine_8h.html#a7092c0c4616367016b70d54e5c680a69 line_horizontal[iLine]->Draw(); } // add TLine TLine* line_vertical[nTLines_vertical]; for (int iLine = 0; iLine<nTLines_vertical; ++iLine) { // draw vertical line double ymin = h[i]->GetYaxis()->GetBinLowEdge(h[i]->GetYaxis()->GetFirst()); double ymax = h[i]->GetYaxis()->GetBinLowEdge(h[i]->GetYaxis()->GetLast()+1); int lineStyle_vertical = GRAPHICS::lineStyle_vertical; if (nLineStyles_vertical == 1) lineStyle_vertical = GraphicsConfigurationParser::ParseLineStyle(lineStyles_vertical.at(0)); else if (nLineStyles_vertical == nTLines_vertical) lineStyle_vertical = GraphicsConfigurationParser::ParseLineStyle(lineStyles_vertical.at(iLine)); line_vertical[iLine] = new TLine(TLines_vertical.at(iLine), ymin, TLines_vertical.at(iLine), ymax); line_vertical[iLine]->SetLineStyle(lineStyle_vertical); // https://root.cern.ch/doc/master/TAttLine_8h.html#a7092c0c4616367016b70d54e5c680a69 line_vertical[iLine]->Draw(); } c->Write(); // save histograms as picture if a figure name is provided. // for now 2D canvases are not drawn on top, they are drawn separately. if (!outputFigureName.EqualTo("")) { std::string tmpOutputFigureName = outputFigureName.Data(); if (tmpOutputFigureName.find(".") != std::string::npos) { // file extension is specified if (nHistos > 1) { // modify outputFile name // if i=1, then "output.ext" becomes "output_2.ext" size_t pos = tmpOutputFigureName.find_last_of("."); tmpOutputFigureName.replace(pos,1, Form("_%d.", i+1)); } c->SaveAs(tmpOutputFigureName.c_str()); } else { // file extension is NOT specified if (nHistos > 1) { // modify outputFile name // if i=1, then "output" becomes "output_2" tmpOutputFigureName = Form("%s_%d", tmpOutputFigureName.c_str(), i+1); } c->SaveAs(Form("%s.C", tmpOutputFigureName.c_str())); c->SaveAs(Form("%s.png", tmpOutputFigureName.c_str())); c->SaveAs(Form("%s.pdf", tmpOutputFigureName.c_str())); } } leg->Delete(); c->Close(); } output->Close(); }
int plotResoVsIC(){ SetTdrStyle(); const unsigned nIC = 10; const unsigned ICval[nIC] = {0,1,2,3,4,5,10,15,20,50}; std::ostringstream label; TFile *fcalib[nIC]; TGraphErrors *constant = new TGraphErrors(); constant->SetName("constant"); constant->SetTitle(";intercalib. smearing"); constant->SetMarkerStyle(20); constant->SetMarkerColor(1); constant->SetLineColor(1); TGraphErrors *constantSR7 = new TGraphErrors(); constantSR7->SetName("constantSR7"); constantSR7->SetTitle(";intercalib. smearing"); constantSR7->SetMarkerStyle(23); constantSR7->SetMarkerColor(2); constantSR7->SetLineColor(2); TGraphErrors *noise = (TGraphErrors *) constant->Clone("noise"); TGraphErrors *sampling = (TGraphErrors *) constant->Clone("sampling"); TGraphErrors *samplingSR7 = (TGraphErrors *) constantSR7->Clone("samplingSR7"); TCanvas *mycReso = new TCanvas("mycReso","mycReso",1500,1000); mycReso->Divide(2,5); TCanvas *mycR = new TCanvas("mycR","Sampling",1500,1000); TCanvas *mycC = new TCanvas("mycC","Constant",1500,1000); TCanvas *mycN = new TCanvas("mycN","Noise",1500,1000); gStyle->SetOptFit(1111); gStyle->SetOptStat(0); gStyle->SetStatW(0.2); gStyle->SetStatH(0.5); TLatex lat; char buf[500]; TGraphErrors *gr[nIC][2]; double x0,y0; double x0_7,y0_7; for (unsigned ic(0);ic<nIC;++ic){//loop on intercalib label.str(""); label << "PLOTS/CalibReso"; label << "_vsE"; label << "_IC" << ICval[ic]; label << ".root"; fcalib[ic] = TFile::Open(label.str().c_str()); if (!fcalib[ic]) { std::cout << " -- failed to open file: " << label.str() << std::endl; continue; } else { std::cout << " -- file " << label.str() << " successfully opened." << std::endl; } fcalib[ic]->cd("SR2"); gr[ic][0] = (TGraphErrors *)gDirectory->Get("resoRecoFit2eta21pu1"); fcalib[ic]->cd("SR7"); gr[ic][1] = (TGraphErrors *)gDirectory->Get("resoRecoFit7eta21pu1"); TF1 *fit = gr[ic][0]->GetFunction("reso"); TF1 *fit7 = gr[ic][1]->GetFunction("reso"); mycReso->cd(ic+1); gr[ic][0]->Draw("APE"); fit->SetLineColor(6); fit->Draw("same"); lat.SetTextSize(0.1); sprintf(buf,"Single #gamma, #eta=2.1, 3#times3 cm^{2}"); lat.DrawLatexNDC(0.2,0.8,buf); sprintf(buf,"ICsmear = %d %%",ICval[ic]); lat.DrawLatexNDC(0.2,0.7,buf); double cval = sqrt(pow(fit->GetParameter(1),2)-pow(y0,2)); constant->SetPoint(ic,ICval[ic]/100.,cval); constant->SetPointError(ic,0,fit->GetParameter(1)*fit->GetParError(1)/cval); noise->SetPoint(ic,ICval[ic]/100.,fit->GetParameter(2)); noise->SetPointError(ic,0,fit->GetParError(2)); sampling->SetPoint(ic,ICval[ic]/100.,fit->GetParameter(0)); sampling->SetPointError(ic,0,fit->GetParError(0)); cval = sqrt(pow(fit7->GetParameter(1),2)-pow(y0_7,2)); constantSR7->SetPoint(ic,ICval[ic]/100.,cval); constantSR7->SetPointError(ic,0,fit7->GetParameter(1)*fit7->GetParError(1)/cval); //constantSR7->SetPoint(ic,ICval[ic]/100.,fit7->GetParameter(1)); //constantSR7->SetPointError(ic,0,fit7->GetParError(1)); samplingSR7->SetPoint(ic,ICval[ic]/100.,fit7->GetParameter(0)); samplingSR7->SetPointError(ic,0,fit7->GetParError(0)); if (ic==0) { constant->GetPoint(0,x0,y0); constantSR7->GetPoint(0,x0_7,y0_7); cval = sqrt(pow(fit->GetParameter(1),2)-pow(y0,2)); constant->SetPoint(ic,ICval[ic]/100.,cval); constant->SetPointError(ic,0,fit->GetParameter(1)*fit->GetParError(1)/cval); cval = sqrt(pow(fit7->GetParameter(1),2)-pow(y0_7,2)); constantSR7->SetPoint(ic,ICval[ic]/100.,cval); constantSR7->SetPointError(ic,0,fit7->GetParameter(1)*fit7->GetParError(1)/cval); } } mycReso->Update(); mycReso->Print("PLOTS/ResolutionFitvsIC.pdf"); TLegend *leg = new TLegend(0.6,0.6,0.8,0.8); leg->SetFillColor(10); leg->AddEntry(sampling,"3#times3 cm^{2}","P"); leg->AddEntry(samplingSR7,"All detector","P"); mycR->cd(); gPad->SetGridy(1); sampling->GetYaxis()->SetTitle("Sampling term (GeV^{1/2})"); sampling->SetMinimum(0.2); sampling->SetMaximum(0.3); sampling->Draw("APE"); samplingSR7->Draw("PEsame"); lat.SetTextSize(0.04); sprintf(buf,"Single #gamma, #eta=2.1"); lat.DrawLatexNDC(0.2,0.87,buf); lat.DrawLatexNDC(0.01,0.01,"HGCAL G4 standalone"); leg->Draw("same"); mycR->Update(); mycR->Print("PLOTS/SamplingvsIC.pdf"); mycC->cd(); gPad->SetLogx(1); gPad->SetGridy(1); gStyle->SetOptFit(0); //gStyle->SetStatH(0.1); //gStyle->SetStatW(0.2); constant->GetYaxis()->SetTitle("Constant from intercalib."); constant->SetMinimum(0); constant->SetMaximum(0.08); constant->Draw("APE"); //constantSR7->Draw("PEsame"); sprintf(buf,"Single #gamma, #eta=2.1"); lat.DrawLatexNDC(0.2,0.87,buf); lat.DrawLatexNDC(0.01,0.01,"HGCAL G4 standalone"); TF1 *BE = new TF1("BE","sqrt([0]*[0] + pow(x*1/sqrt([1]),2))",0,1); BE->SetParameters(0,30); // BE->SetParLimits(0,1,1); BE->FixParameter(0,0); BE->SetLineColor(1); constant->Fit("BE","BI"); lat.SetTextColor(1); //sprintf(buf,"c #propto c_{0} #oplus #frac{x}{#sqrt{n}}, n=%3.1f #pm %3.1f",BE->GetParameter(1),BE->GetParError(1)); sprintf(buf,"c_{ic}=#frac{x}{#sqrt{n}}, n=%3.1f #pm %3.1f",BE->GetParameter(1),BE->GetParError(1)); lat.DrawLatexNDC(0.2,0.77,"c=c_{0} #oplus c_{ic}"); lat.DrawLatexNDC(0.2,0.67,buf); //BE->SetParameter(0,y0_7); //constantSR7->Fit("BE","BI","same"); //BE->SetLineColor(2); //BE->Draw("same"); //lat.SetTextColor(2); //sprintf(buf,"c #propto c_{0} #oplus #frac{x}{#sqrt{n}}, n=%3.1f #pm %3.1f",BE->GetParameter(1),BE->GetParError(1)); //lat.DrawLatexNDC(0.2,0.6,buf); //lat.SetTextColor(1); //leg->Draw("same"); mycC->Update(); mycC->Print("PLOTS/ConstantvsIC.pdf"); mycN->cd(); noise->GetYaxis()->SetTitle("Noise term (GeV)"); noise->Draw("APE"); sprintf(buf,"Single #gamma, #eta=2.1, 3#times3 cm^{2}"); lat.DrawLatexNDC(0.2,0.87,buf); lat.DrawLatexNDC(0.01,0.01,"HGCAL G4 standalone"); mycN->Print("PLOTS/NoisevsIC.pdf"); return 0; }//main
void fitTime(float deltaT1,float deltaT2, float MIPcalib, float MIPcut, TString tag, TString title) { gStyle->SetOptTitle(0); gStyle->SetOptStat(0); gStyle->SetOptFit(1111111); TCanvas* c1=new TCanvas("c1","c1",900,700); TChain *c=new TChain("H4treeReco"); // c->Add("root://eoscms///eos/cms/store/caf/user/meridian/test/RECO_3353.root"); // c->Add("root://eoscms///eos/cms/store/caf/user/meridian/test/RECO_3354.root"); // c->Add("root://eoscms///eos/cms/store/caf/user/meridian/test/RECO_3355.root"); // c->Add("root://eoscms///eos/cms/store/caf/user/meridian/test/RECO_3356.root"); c->Add("root://eoscms///eos/cms/store/caf/user/meridian/test/RECO_3367.root"); c->Draw(Form("(t_max_frac50[2]-t_max_frac50[1]+%4.3f)>>h1(100,-0.2,0.2)",deltaT1),Form("wave_max[1]>200 && wave_fit_smallw_ampl[2]>%3.1f*%3.1f",MIPcalib,MIPcut)); c->Draw(Form("(t_max_frac50[3]-t_max_frac50[1]+%4.3f)>>h2(100,-0.2,0.2)",deltaT2),Form("wave_max[1]>200 && wave_fit_smallw_ampl[3]>%3.1f*%3.1f",MIPcalib,MIPcut)); // c->Draw("(t_max_frac50[3]-t_max_frac50[1]+5.41)>>h2(100,-0.2,0.2)","wave_max[1]>200 && wave_fit_smallw_ampl[3]>41*20"); // c->Draw("(t_max_frac50[2]-t_max_frac50[3]+0.155)>>h3(100,-0.2,0.2)","wave_fit_smallw_ampl[2]>41*20 && wave_fit_smallw_ampl[3]>41*20"); c->Draw(Form("(t_max_frac50[2]-t_max_frac50[3]+%4.3f)>>h3(100,-0.2,0.2)",deltaT1-deltaT2),Form("wave_max[1]>200 && wave_fit_smallw_ampl[3]>%3.1f*%3.1f && wave_fit_smallw_ampl[2]>%3.1f*%3.1f",MIPcalib,MIPcut,MIPcalib,MIPcut)); TLatex t; t.SetTextSize(0.04); TH1F* h1=(TH1F*)gROOT->FindObject("h1"); h1->Sumw2(); h1->SetMarkerStyle(20); h1->SetMarkerSize(0.3); h1->SetMarkerColor(kMagenta); h1->SetLineColor(kBlack); h1->Fit("gaus"); h1->GetXaxis()->SetTitle("#Delta_{t} Si_{1} - MCP (ns)"); t.DrawLatexNDC(0.07,0.92,title); t.DrawLatexNDC(0.16,0.8,Form("Amplitude > %2.0f MIP",MIPcut)); c1->SaveAs(Form("DeltaT_ch%d_MCP_%s.png",2,tag.Data())); TH1F* h2=(TH1F*)gROOT->FindObject("h2"); h2->Sumw2(); h2->SetMarkerStyle(20); h2->SetMarkerSize(0.3); h2->SetMarkerColor(kMagenta); h2->GetXaxis()->SetTitle("#Delta_{t} Si_{2} - MCP (ns)"); h2->SetLineColor(kBlack); h2->Fit("gaus"); t.DrawLatexNDC(0.07,0.92,title); t.DrawLatexNDC(0.16,0.8,Form("Amplitude > %2.0f MIP",MIPcut)); c1->SaveAs(Form("DeltaT_ch%d_MCP_%s.png",3,tag.Data())); TH1F* h3=(TH1F*)gROOT->FindObject("h3"); h3->Sumw2(); h3->SetMarkerStyle(20); h3->SetMarkerSize(0.3); h3->SetMarkerColor(kMagenta); h3->GetXaxis()->SetTitle("#Delta_{t} Si_{1} - Si_{2} (ns)"); h3->SetLineColor(kBlack); h3->Fit("gaus"); t.DrawLatexNDC(0.07,0.92,"e- 50 GeV Si 320#mum p-type. 4 X_{0} lead"); t.DrawLatexNDC(0.16,0.8,"Amplitude > 20 MIP"); t.DrawLatexNDC(0.07,0.92,title); t.DrawLatexNDC(0.16,0.8,Form("Amplitude > %2.0f MIP",MIPcut)); c1->SaveAs(Form("DeltaT_ch%d_ch%d_%s.png",2,3,tag.Data())); TF1* fRes=new TF1("fRes","TMath::Sqrt(([0]*[0])/(x*x)+([1]*[1]))",1,100); fRes->SetLineWidth(2); // c->Draw("(t_max_frac50[2]-t_max_frac50[1]+5.57):wave_fit_smallw_ampl[2]/41.>>h1_2(30,1,41,50,-0.2,0.2)","wave_max[1]>200 && wave_fit_smallw_ampl[2]>20"); c->Draw(Form("(t_max_frac50[2]-t_max_frac50[1]+%4.3f):wave_fit_smallw_ampl[2]/%3.1f>>h1_2(30,1,41,50,-0.2,0.2)",deltaT1,MIPcalib),"wave_max[1]>200 && wave_fit_smallw_ampl[2]>20"); TH2F* h1_2=(TH2F*)gROOT->FindObject("h1_2"); h1_2->FitSlicesY(); TH1F* h1_2_2=(TH1F*)gROOT->FindObject("h1_2_2"); TH1F* h1_2_2_corr=(TH1F*)h1_2_2->Clone(h1_2_2->GetName()+TString("_corr")); for (int i=1;i<=h1_2_2_corr->GetNbinsX();++i) { if (h1_2_2->GetBinContent(i)>0.0221) { h1_2_2_corr->SetBinContent(i,TMath::Sqrt(h1_2_2->GetBinContent(i)*h1_2_2->GetBinContent(i)-0.0221*0.0221)); h1_2_2_corr->SetBinError(i,TMath::Sqrt(h1_2_2->GetBinError(i)*h1_2_2->GetBinError(i)+0.003*0.003)); } else { h1_2_2_corr->SetBinContent(i,0.); h1_2_2_corr->SetBinError(i,0.008); } // std::cout << i << "," << h1_2_2_corr->GetBinContent(i) << "," << h1_2_2_corr->GetBinError(i) << std::endl; } h1_2_2_corr->Draw(); h1_2_2_corr->Fit("fRes","R"); h1_2_2_corr->SetMinimum(0.); h1_2_2_corr->SetMaximum(0.3); h1_2_2_corr->GetXaxis()->SetTitle("Signal amplitude (# MIP)"); h1_2_2_corr->GetYaxis()->SetTitle("#sigma_{t} (ns)"); h1_2_2_corr->SetMarkerStyle(20); h1_2_2_corr->SetMarkerSize(1.2); h1_2_2_corr->SetMarkerColor(kBlue); h1_2_2_corr->SetLineColor(kBlack); t.DrawLatexNDC(0.12,0.92,title); t.DrawLatexNDC(0.12,0.82,"#sigma_{MCP}=22.1ps subtracted"); c1->SaveAs(Form("DeltaT_vs_Ampl_ch%d_MCP_%s.png",2,tag.Data())); c->Draw(Form("(t_max_frac50[3]-t_max_frac50[1]+%4.3f):wave_fit_smallw_ampl[3]/%3.1f>>h2_2(30,1,41,50,-0.2,0.2)",deltaT2,MIPcalib),"wave_max[1]>200 && wave_fit_smallw_ampl[3]>20"); TH2F* h2_2=(TH2F*)gROOT->FindObject("h2_2"); h2_2->FitSlicesY(); TH1F* h2_2_2=(TH1F*)gROOT->FindObject("h2_2_2"); TH1F* h2_2_2_corr=(TH1F*)h2_2_2->Clone(h2_2_2->GetName()+TString("_corr")); for (int i=1;i<=h2_2_2_corr->GetNbinsX();++i) { if (h2_2_2->GetBinContent(i)>0.0221) { h2_2_2_corr->SetBinContent(i,TMath::Sqrt(h2_2_2->GetBinContent(i)*h2_2_2->GetBinContent(i)-0.0221*0.0221)); h2_2_2_corr->SetBinError(i,TMath::Sqrt(h2_2_2->GetBinError(i)*h2_2_2->GetBinError(i)+0.003*0.003)); } else { h2_2_2_corr->SetBinContent(i,0.); h2_2_2_corr->SetBinError(i,0.008); } // std::cout << i << "," << h2_2_2_corr->GetBinContent(i) << "," << h2_2_2_corr->GetBinError(i) << std::endl; } h2_2_2_corr->Draw(); h2_2_2_corr->Fit("fRes","R"); h2_2_2_corr->SetMinimum(0.); h2_2_2_corr->SetMaximum(0.3); h2_2_2_corr->GetXaxis()->SetTitle("Signal amplitude (# MIP)"); h2_2_2_corr->GetYaxis()->SetTitle("#sigma_{t} (ns)"); h2_2_2_corr->SetMarkerStyle(20); h2_2_2_corr->SetMarkerSize(1.2); h2_2_2_corr->SetMarkerColor(kBlue); h2_2_2_corr->SetLineColor(kBlack); t.DrawLatexNDC(0.12,0.92,title); t.DrawLatexNDC(0.12,0.82,"#sigma_{MCP}=22.1ps subtracted"); c1->SaveAs(Form("DeltaT_vs_Ampl_ch%d_MCP_%s.png",3,tag.Data())); }
int logWeightingScanAll(){//main SetTdrStyle(); //TString plotDir = "../PLOTS/gitV00-02-12/version12/gamma/200um/"; TString plotDir = "/afs/cern.ch/work/a/amagnan/PFCalEEAna/PLOTS/gitV00-02-12/version12/gamma/200um/"; bool useFit = true; //const unsigned nPu = 2; //unsigned pu[nPu] = {0,140}; const unsigned nPu = 1;//2; unsigned pu[nPu] = {0};//,140}; const unsigned nScans = 50; const double wStart = 1.; const double wStep = (6.-wStart)/nScans; const unsigned neta = 4;//7; const unsigned npt = 3;//13; const unsigned nLayers = 30; unsigned eta[neta] = {17,21,25,29}; //unsigned pt[npt] = {20,30,40,50,60,70,80,90,100,125,150,175,200}; unsigned pt[npt] = {20,50,100}; //TF1 *cauchy = new TF1("cauchy","1/(TMath::Pi()*[2]*(1+pow((x-[0])/[2],2)))",-15,15); //cauchy->SetParameters(0,0,2.5); double wxminall[nPu][nLayers][neta]; double wyminall[nPu][nLayers][neta]; double etaval[neta]; const unsigned nCanvas = 5; TCanvas *mycx[nCanvas]; TCanvas *mycy[nCanvas]; for (unsigned iC(0);iC<nCanvas;++iC){ std::ostringstream lName; lName << "mycx" << iC; mycx[iC] = new TCanvas(lName.str().c_str(),lName.str().c_str(),1500,1000); mycx[iC]->Divide(3,2); lName.str(""); lName << "mycy" << iC; mycy[iC] = new TCanvas(lName.str().c_str(),lName.str().c_str(),1500,1000); mycy[iC]->Divide(3,2); } TCanvas *mycW = new TCanvas("mycW","mycW",1500,1000); TCanvas *mycFit = new TCanvas("mycFit","mycFit",1); for (unsigned ieta(0); ieta<neta;++ieta){ etaval[ieta] = eta[ieta]/10.; bool savePoint = (eta[ieta] == 17);// && pt[ipt]==50); std::ostringstream pteta; pteta << "eta" << eta[ieta];// << "_et" << pt[ipt]; TFile *fin[nPu]; TFile *fout = 0; if (savePoint) { fout = TFile::Open(("PLOTS/LogWeightingStudy_"+pteta.str()+".root").c_str(),"RECREATE"); fout->mkdir("scan"); fout->mkdir("scan/xpos"); fout->mkdir("scan/ypos"); for (unsigned iS(0); iS<nScans;++iS){ std::ostringstream lName; lName << "scan/xpos/scan_" << wStart+iS*wStep; fout->mkdir(lName.str().c_str()); lName.str(""); lName << "scan/ypos/scan_" << wStart+iS*wStep; fout->mkdir(lName.str().c_str()); } fout->cd(); } TH1F *p_xt; TH1F *p_yt; TH1F *p_intercalibSigmaSquare[nPu]; TH1F *p_chi2ndf; if (savePoint) { p_xt = new TH1F("p_xt",";x truth (mm)",100,-5,5); p_yt = new TH1F("p_yt",";y truth (mm)",100,-5,5);//200,1170,1370); p_intercalibSigmaSquare[0] = new TH1F("p_intercalibSigmaSquare_0",";#sigma_{E}^{2} (2% intercalib) (GeV^2)",3000,0,30000); p_intercalibSigmaSquare[1] = new TH1F("p_intercalibSigmaSquare_140",";#sigma_{E}^{2} (2% intercalib) (GeV^2)",3000,0,30000); p_chi2ndf = new TH1F("p_chi2ndf",";#chi^{2}/N",100,0,20); } TH1F *p_posx[nPu][nLayers][nScans]; TH1F *p_posy[nPu][nLayers][nScans]; TH1F *p_wx[nPu][nLayers][3]; TH1F *p_wy[nPu][nLayers][3]; TH2F *p_Exy[nPu][nLayers]; TH2F *p_deltavsreco_x[nPu][nLayers]; TH2F *p_deltavsreco_y[nPu][nLayers]; TH2F *p_recovstruth_x[nPu][nLayers]; TH2F *p_recovstruth_y[nPu][nLayers]; if (savePoint){ mycFit->Print("PLOTS/fits_x.pdf["); mycFit->Print("PLOTS/fits_y.pdf["); } gStyle->SetOptStat("eMRuo"); TGraphErrors *grX[nPu][nLayers]; TGraphErrors *grY[nPu][nLayers]; TGraphErrors *grXrms[nPu][nLayers]; TGraphErrors *grYrms[nPu][nLayers]; double resxmin[nPu][nLayers]; double resymin[nPu][nLayers]; double lay[nLayers]; double wxmin[nPu][nLayers]; double wymin[nPu][nLayers]; for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu std::vector<std::vector<double> > Exy; std::vector<double> init; init.resize(25,0); Exy.resize(nLayers,init); std::vector<double> truthPosX; truthPosX.resize(nLayers,0); std::vector<double> truthPosY; truthPosY.resize(nLayers,0); std::ostringstream label; label << "pu" << pu[ipu]; if (savePoint){ fout->mkdir(label.str().c_str()); fout->cd(label.str().c_str()); } for (unsigned iL(0);iL<nLayers;++iL){ lay[iL] = iL; resxmin[ipu][iL] = 100; wxmin[ipu][iL] = 10; resymin[ipu][iL] = 100; wymin[ipu][iL] = 10; label.str(""); label << "pu" << pu[ipu]; if (savePoint) fout->cd(label.str().c_str()); label.str(""); label << "grX_pu" << pu[ipu] << "_" << iL; grX[ipu][iL] = new TGraphErrors(); grX[ipu][iL]->SetName(label.str().c_str()); label.str(""); label << "grY_pu" << pu[ipu] << "_" << iL; grY[ipu][iL] = new TGraphErrors(); grY[ipu][iL]->SetName(label.str().c_str()); label.str(""); label << "grXrms_pu" << pu[ipu] << "_" << iL; grXrms[ipu][iL] = new TGraphErrors(); grXrms[ipu][iL]->SetName(label.str().c_str()); label.str(""); label << "grYrms_pu" << pu[ipu] << "_" << iL; grYrms[ipu][iL] = new TGraphErrors(); grYrms[ipu][iL]->SetName(label.str().c_str()); if (savePoint) { label.str(""); label << "Exy_pu"<< pu[ipu] << "_" << iL; p_Exy[ipu][iL] = new TH2F(label.str().c_str(),";x idx;y idx; E (mips)", 5,0,5,5,0,5); } label.str(""); label << "deltavsreco_x_pu"<< pu[ipu] << "_" << iL; p_deltavsreco_x[ipu][iL] = new TH2F(label.str().c_str(),";x reco (mm);x_{reco}-x_{truth} (mm);", 30,-15,15,100,-10,10); label.str(""); label << "deltavsreco_y_pu"<< pu[ipu] << "_" << iL; p_deltavsreco_y[ipu][iL] = new TH2F(label.str().c_str(),";y reco (mm);y_{reco}-y_{truth} (mm);", 30,-15,15,100,-10,10); if (savePoint) { label.str(""); label << "recovstruth_x_pu"<< pu[ipu] << "_" << iL; p_recovstruth_x[ipu][iL] = new TH2F(label.str().c_str(),";x_{truth} (mm);x reco (mm)", 30,-15,15,30,-15,15); label.str(""); label << "recovstruth_y_pu"<< pu[ipu] << "_" << iL; p_recovstruth_y[ipu][iL] = new TH2F(label.str().c_str(),";y_{truth} (mm);y reco (mm)", 30,-15,15,//200,1170,1370, 30,-15,15 ); } if (savePoint) { if (savePoint) { label.str(""); label << "pu" << pu[ipu]; fout->cd(label.str().c_str()); } for (unsigned i(0);i<5;++i){ label.str(""); label << "wx_pu" << pu[ipu] << "_" << iL << "_" << i; p_wx[ipu][iL][i] = new TH1F(label.str().c_str(), ";wx;events", 100,-10,0); label.str(""); label << "wy_pu" << pu[ipu] << "_" << iL << "_" << i; p_wy[ipu][iL][i] = new TH1F(label.str().c_str(), ";wy;events", 100,-10,0); } } for (unsigned iS(0); iS<nScans;++iS){ label.str(""); label << "scan/xpos/scan_" << wStart+iS*wStep; if (savePoint) fout->cd(label.str().c_str()); label.str(""); label << "posx_pu" << pu[ipu] << "_" << iL << "_" << iS; p_posx[ipu][iL][iS] = new TH1F(label.str().c_str(), ";x-x_{truth} (mm);events", 100,-10,10); label.str(""); label << "scan/ypos/scan_" << wStart+iS*wStep; if (savePoint) fout->cd(label.str().c_str()); label.str(""); label << "posy_pu" << pu[ipu] << "_" << iL << "_" << iS; p_posy[ipu][iL][iS] = new TH1F(label.str().c_str(), ";y-y_{truth} (mm);events", 100,-10,10); } }//loop on layers for (unsigned ipt(0); ipt<npt;++ipt){ std::ostringstream linputStr; linputStr << plotDir << "/" << "eta" << eta[ieta] << "_et" << pt[ipt] << "_pu" << pu[ipu] ; //linputStr << "_logweight"; linputStr << ".root"; fin[ipu] = TFile::Open(linputStr.str().c_str()); if (!fin[ipu]) { std::cout << " -- Error, input file " << linputStr.str() << " cannot be opened. Skipping..." << std::endl; continue; } else std::cout << " -- File " << linputStr.str() << " successfully opened." << std::endl; TTree *tree = (TTree*)gDirectory->Get("EcellsSR2"); if (!tree) { std::cout << " Tree not found! " << std::endl; continue; //return 1; } for (unsigned iL(0);iL<nLayers;++iL){ label.str(""); label << "TruthPosX_" << iL; tree->SetBranchAddress(label.str().c_str(),&truthPosX[iL]); label.str(""); label << "TruthPosY_" << iL; tree->SetBranchAddress(label.str().c_str(),&truthPosY[iL]); for (unsigned iy(0);iy<5;++iy){ for (unsigned ix(0);ix<5;++ix){ unsigned idx = 5*iy+ix; label.str(""); label << "E_" << iL << "_" << idx; tree->SetBranchAddress(label.str().c_str(),&Exy[iL][idx]); } } }//loop on layers unsigned nEvts = tree->GetEntries(); for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on entries if (ievt%50 == 0) std::cout << "... Processing entry: " << ievt << std::endl; tree->GetEntry(ievt); double Etotsq = 0; for (unsigned iL(0);iL<nLayers;++iL){ double Etot = 0; double Ex[5] = {0,0,0,0,0}; double Ey[5] = {0,0,0,0,0}; for (unsigned idx(0);idx<25;++idx){ if (iL>22) Etot += Exy[iL][idx]; else if ((idx>5 && idx<9)|| (idx>10 && idx<14)|| (idx>15 && idx<19)) Etot += Exy[iL][idx]; } Etotsq += pow(calibratedE(Etot*absWeight(iL,eta[ieta]/10.),eta[ieta]/10.),2); if (iL>22){ Ex[0] = Exy[iL][0]+Exy[iL][5]+Exy[iL][10]+Exy[iL][15]+Exy[iL][20]; Ex[1] = Exy[iL][1]+Exy[iL][6]+Exy[iL][11]+Exy[iL][16]+Exy[iL][21]; Ex[2] = Exy[iL][2]+Exy[iL][7]+Exy[iL][12]+Exy[iL][17]+Exy[iL][22]; Ex[3] = Exy[iL][3]+Exy[iL][8]+Exy[iL][13]+Exy[iL][18]+Exy[iL][23]; Ex[4] = Exy[iL][4]+Exy[iL][9]+Exy[iL][14]+Exy[iL][19]+Exy[iL][24]; Ey[0] = Exy[iL][0]+Exy[iL][1]+Exy[iL][2]+Exy[iL][3]+Exy[iL][4]; Ey[1] = Exy[iL][5]+Exy[iL][6]+Exy[iL][7]+Exy[iL][8]+Exy[iL][9]; Ey[2] = Exy[iL][10]+Exy[iL][11]+Exy[iL][12]+Exy[iL][13]+Exy[iL][14]; Ey[3] = Exy[iL][15]+Exy[iL][16]+Exy[iL][17]+Exy[iL][18]+Exy[iL][19]; Ey[4] = Exy[iL][20]+Exy[iL][21]+Exy[iL][22]+Exy[iL][23]+Exy[iL][24]; } else { Ex[0] = Exy[iL][6]+Exy[iL][11]+Exy[iL][16]; Ex[1] = Exy[iL][7]+Exy[iL][12]+Exy[iL][17]; Ex[2] = Exy[iL][8]+Exy[iL][13]+Exy[iL][18]; Ey[0] = Exy[iL][6]+Exy[iL][7]+Exy[iL][8]; Ey[1] = Exy[iL][11]+Exy[iL][12]+Exy[iL][13]; Ey[2] = Exy[iL][16]+Exy[iL][17]+Exy[iL][18]; } double simplex = 0; double simpley = 0; if (Etot!=0) { if (iL>22) { simplex = 10*(2*Ex[4]+Ex[3]-Ex[1]-2*Ex[0])/Etot; simpley = 10*(2*Ey[4]+Ey[3]-Ey[1]-2*Ey[0])/Etot; } else { simplex = 10*(Ex[2]-Ex[0])/Etot; simpley = 10*(Ey[2]-Ey[0])/Etot; } } double xt = truthPosX[iL]; unsigned cellCenter = static_cast<unsigned>((truthPosY[iL]+5)/10.)*10; double yt = 0; //if (cellCenter>truthPosY[iL]) yt = cellCenter-truthPosY[iL]; yt=truthPosY[iL]-cellCenter; p_deltavsreco_x[ipu][iL]->Fill(simplex,simplex-xt); p_deltavsreco_y[ipu][iL]->Fill(simpley,simpley-yt); if (savePoint) { p_xt->Fill(xt); p_yt->Fill(yt); p_recovstruth_x[ipu][iL]->Fill(xt,simplex); p_recovstruth_y[ipu][iL]->Fill(yt,simpley); for (unsigned idx(0);idx<9;++idx){ p_Exy[ipu][iL]->Fill(idx%5,idx/5,Exy[iL][idx]/Etot); } } double wx[6][nScans]; double wy[6][nScans]; for (unsigned i(0);i<6;++i){ for (unsigned iS(0); iS<nScans;++iS){ wx[i][iS] = 0; wy[i][iS] = 0; } } for (unsigned i(0);i<5;++i){ if (savePoint) p_wx[ipu][iL][i]->Fill(log(Ex[i]/Etot)); if (savePoint) p_wy[ipu][iL][i]->Fill(log(Ey[i]/Etot)); for (unsigned iS(0); iS<nScans;++iS){ double w0 = wStart+iS*wStep; wx[i][iS] = std::max(0.,log(Ex[i]/Etot)+w0); wy[i][iS] = std::max(0.,log(Ey[i]/Etot)+w0); // if (log(Ex[i]/Etot)+w0<0) // std::cout << " - iL= " << iL << " i=" << i << " w0=" << w0 // << " logEx=" << log(Ex[i]/Etot) // << " wx " << wx[i][iS] // << std::endl; // if (log(Ey[i]/Etot)+w0<0) // std::cout << " - iL= " << iL << " i=" << i << " w0=" << w0 // << " logEy=" << log(Ey[i]/Etot) // << " wy " << wy[i][iS] // << std::endl; wx[5][iS] += wx[i][iS]; wy[5][iS] += wy[i][iS]; } } for (unsigned iS(0); iS<nScans;++iS){ double x = 0;//10*(wx[2][iS]-wx[0][iS])/wx[3][iS]; if (wx[5][iS]!=0) { if (iL>22) x = 10*(2*wx[4][iS]+wx[3][iS]-wx[1][iS]-2*wx[0][iS])/wx[5][iS]; else x = 10*(wx[2][iS]-wx[0][iS])/wx[5][iS]; } double y = 0;//10*(wy[2][iS]-wy[0][iS])/wy[3][iS]; if (wy[5][iS]!=0) { if (iL>22) y = 10*(2*wy[4][iS]+wy[3][iS]-wy[1][iS]-2*wy[0][iS])/wy[5][iS]; else y = 10*(wy[2][iS]-wy[0][iS])/wy[5][iS]; } //if (fabs(y-yt)>5) std::cout << " --- iL=" << iL << " iS=" << iS //<< " x=" << x << " xt=" << xt //<< " y=" << y << " yt=" << yt //<< std::endl; p_posx[ipu][iL][iS]->Fill(x-xt); p_posy[ipu][iL][iS]->Fill(y-yt); } }//loop on layers if (savePoint) p_intercalibSigmaSquare[ipu]->Fill(Etotsq); }//loop on entries }//loop on pt //fill first point with linear weighting TLatex lat; char buf[500]; for (unsigned iL(0);iL<nLayers;++iL){ mycFit->cd(); TH1D *projy = p_deltavsreco_x[ipu][iL]->ProjectionY(); projy->Draw(); projy->Fit("gaus","0+Q"); TF1 *fitx = projy->GetFunction("gaus"); fitx->SetLineColor(6); fitx->Draw("same"); sprintf(buf,"Layer %d, linear weighting, pu=%d",iL,pu[ipu]); lat.DrawLatexNDC(0.1,0.96,buf); grX[ipu][iL]->SetPoint(0,0.5,fitx->GetParameter(2)); grX[ipu][iL]->SetPointError(0,0,fitx->GetParError(2)); grXrms[ipu][iL]->SetPoint(0,0.5,projy->GetRMS()); grXrms[ipu][iL]->SetPointError(0,0,projy->GetRMSError()); mycFit->Update(); if (savePoint) mycFit->Print("PLOTS/fits_x.pdf"); mycFit->cd(); projy = p_deltavsreco_y[ipu][iL]->ProjectionY(); projy->Draw(); projy->Fit("gaus","0+Q"); TF1 *fity = projy->GetFunction("gaus"); fitx->SetLineColor(6); fitx->Draw("same"); sprintf(buf,"Layer %d, linear weighting, pu=%d",iL,pu[ipu]); lat.DrawLatexNDC(0.1,0.96,buf); grY[ipu][iL]->SetPoint(0,0.5,fity->GetParameter(2)); grY[ipu][iL]->SetPointError(0,0,fity->GetParError(2)); grYrms[ipu][iL]->SetPoint(0,0.5,projy->GetRMS()); grYrms[ipu][iL]->SetPointError(0,0,projy->GetRMSError()); mycFit->Update(); if (savePoint) mycFit->Print("PLOTS/fits_y.pdf"); } //fit vs w0, get w0min for (unsigned iL(0);iL<nLayers;++iL){ for (unsigned iS(0); iS<nScans;++iS){ mycFit->cd(); p_posx[ipu][iL][iS]->Draw(); double w0 = wStart+iS*wStep; //myGaus->SetParameters(); p_posx[ipu][iL][iS]->Fit("gaus","0+Q","",-2.,2.); TF1 *fitx = p_posx[ipu][iL][iS]->GetFunction("gaus"); fitx->SetLineColor(6); fitx->Draw("same"); sprintf(buf,"Layer %d, w0=%3.1f, pu=%d",iL,w0,pu[ipu]); lat.DrawLatexNDC(0.1,0.96,buf); mycFit->Update(); if (savePoint) mycFit->Print("PLOTS/fits_x.pdf"); mycFit->cd(); p_posy[ipu][iL][iS]->Draw(); p_posy[ipu][iL][iS]->Fit("gaus","0+Q","",-2.,2.); TF1 *fity = p_posy[ipu][iL][iS]->GetFunction("gaus"); fity->SetLineColor(6); fity->Draw("same"); sprintf(buf,"Layer %d, w0=%3.1f, pu=%d",iL,w0,pu[ipu]); lat.DrawLatexNDC(0.1,0.96,buf); mycFit->Update(); if (savePoint) mycFit->Print("PLOTS/fits_y.pdf"); //grX[ipu][iL]->SetPoint(iS,w0,p_posx[ipu][iL][iS]->GetRMS()); //grX[ipu][iL]->SetPointError(iS,0,p_posx[ipu][iL][iS]->GetRMSError()); //grY[ipu][iL]->SetPoint(iS,w0,p_posy[ipu][iL][iS]->GetRMS()); //grY[ipu][iL]->SetPointError(iS,0,p_posy[ipu][iL][iS]->GetRMSError()); double xval = useFit? fitx->GetParameter(2) : p_posx[ipu][iL][iS]->GetRMS(); if (savePoint) p_chi2ndf->Fill(fitx->GetChisquare()/fitx->GetNDF()); grX[ipu][iL]->SetPoint(iS+1,w0,fitx->GetParameter(2)); grX[ipu][iL]->SetPointError(iS+1,0,fitx->GetParError(2)); grXrms[ipu][iL]->SetPoint(iS+1,w0,p_posx[ipu][iL][iS]->GetRMS()); grXrms[ipu][iL]->SetPointError(iS+1,0,p_posx[ipu][iL][iS]->GetRMSError()); if (xval < resxmin[ipu][iL]){ resxmin[ipu][iL] = xval; wxminall[ipu][iL][ieta] = w0; wxmin[ipu][iL] = w0; } double yval = useFit? fity->GetParameter(2) : p_posy[ipu][iL][iS]->GetRMS(); if (savePoint) p_chi2ndf->Fill(fity->GetChisquare()/fity->GetNDF()); grY[ipu][iL]->SetPoint(iS+1,w0,fity->GetParameter(2)); grY[ipu][iL]->SetPointError(iS+1,0,fity->GetParError(2)); grYrms[ipu][iL]->SetPoint(iS+1,w0,p_posy[ipu][iL][iS]->GetRMS()); grYrms[ipu][iL]->SetPointError(iS+1,0,p_posy[ipu][iL][iS]->GetRMSError()); if (yval < resymin[ipu][iL]){ resymin[ipu][iL] = yval; wyminall[ipu][iL][ieta] = w0; wymin[ipu][iL] = w0; } } grX[ipu][iL]->SetTitle(";W0; #sigma(x-xt) (mm)"); grY[ipu][iL]->SetTitle(";W0; #sigma(y-yt) (mm)"); grX[ipu][iL]->SetLineColor(ipu+1); grX[ipu][iL]->SetMarkerColor(ipu+1); grX[ipu][iL]->SetMarkerStyle(ipu+21); grY[ipu][iL]->SetLineColor(ipu+1); grY[ipu][iL]->SetMarkerColor(ipu+1); grY[ipu][iL]->SetMarkerStyle(ipu+21); grXrms[ipu][iL]->SetLineColor(ipu+3); grXrms[ipu][iL]->SetMarkerColor(ipu+3); grXrms[ipu][iL]->SetMarkerStyle(ipu+23); grYrms[ipu][iL]->SetLineColor(ipu+3); grYrms[ipu][iL]->SetMarkerColor(ipu+3); grYrms[ipu][iL]->SetMarkerStyle(ipu+23); mycx[iL/6]->cd(iL%6+1); grX[ipu][iL]->Draw(ipu==0?"APL":"PLsame"); grXrms[ipu][iL]->Draw("PLsame"); //gStyle->SetStatX(0.4); //gStyle->SetStatY(1.0); //p_Exy[ipu][iL]->Draw("colztext"); sprintf(buf,"Layer %d",iL); lat.DrawLatexNDC(0.4,0.85,buf); mycy[iL/6]->cd(iL%6+1); grY[ipu][iL]->Draw(ipu==0?"APL":"PLsame"); grYrms[ipu][iL]->Draw("PLsame"); lat.DrawLatexNDC(0.4,0.85,buf); }//loop on layers //return 1; }//loop on pu if (savePoint) { mycFit->Print("PLOTS/fits_x.pdf]"); mycFit->Print("PLOTS/fits_y.pdf]"); } return 1; TLegend *leg = new TLegend(0.6,0.6,0.94,0.94); leg->SetFillColor(0); if (grX[0][10]) leg->AddEntry(grX[0][10],"fit pu=0","P"); if (grXrms[0][10]) leg->AddEntry(grXrms[0][10],"RMS pu=0","P"); if (grX[1][10]) leg->AddEntry(grX[1][10],"fit pu=140","P"); if (grXrms[1][10]) leg->AddEntry(grXrms[1][10],"RMS pu=140","P"); for (unsigned iC(0);iC<nCanvas;++iC){ mycx[iC]->cd(1); leg->Draw("same"); mycx[iC]->Update(); std::ostringstream lsave; lsave << "PLOTS/logWeighted_x_" << 6*iC << "_" << 6*iC+5 << "_" << pteta.str() ; lsave << ".pdf"; mycx[iC]->Print(lsave.str().c_str()); mycx[iC]->Update(); mycy[iC]->cd(1); leg->Draw("same"); lsave.str(""); lsave << "PLOTS/logWeighted_y_" << 6*iC << "_" << 6*iC+5 << "_" << pteta.str(); lsave << ".pdf"; mycy[iC]->Print(lsave.str().c_str()); } //plot w0min vs layer TGraph *grW[4] = {0,0,0,0}; for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu std::cout << " --Processing pu " << pu[ipu] << std::endl; grW[2*ipu] = new TGraph(nLayers,lay,wxmin[ipu]); grW[2*ipu+1] = new TGraph(nLayers,lay,wymin[ipu]); for (unsigned iL(0);iL<nLayers;++iL){ std::cout << " if (layer==" << iL << ") return " << (wxmin[ipu][iL]+wymin[ipu][iL])/2. <<";" // << " minimum x= " << grX[ipu][iL]->GetYaxis()->GetXmin() // << " minimum y= " << grY[ipu][iL]->GetYaxis()->GetXmin() << std::endl; } mycW->cd(); grW[2*ipu]->SetTitle(";layer;W0"); grW[2*ipu]->SetMaximum(6); grW[2*ipu]->SetMinimum(0); grW[2*ipu]->SetLineColor(2*ipu+1); grW[2*ipu]->SetMarkerColor(2*ipu+1); grW[2*ipu]->SetMarkerStyle(20+2*ipu+1); grW[2*ipu+1]->SetLineColor(2*ipu+2); grW[2*ipu+1]->SetMarkerColor(2*ipu+2); grW[2*ipu+1]->SetMarkerStyle(20+2*ipu+2); if (ipu==0) { grW[2*ipu]->Draw("APL"); grW[2*ipu+1]->Draw("PLsame"); } else { grW[2*ipu]->Draw("PLsame"); grW[2*ipu+1]->Draw("PLsame"); } } std::ostringstream lsave; lsave << "PLOTS/w0minvsLayers_" << pteta.str(); if (useFit) lsave << "_fit"; else lsave << "_rms"; lsave << ".pdf"; mycW->Update(); mycW->Print(lsave.str().c_str()); if (savePoint) fout->Write(); else { for (unsigned i(0);i<4;++i){ if (grW[i]) grW[i]->Delete(); } for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu for (unsigned iL(0); iL<nLayers;++iL){//loop on layers grX[ipu][iL]->Delete(); grXrms[ipu][iL]->Delete(); grY[ipu][iL]->Delete(); grYrms[ipu][iL]->Delete(); p_deltavsreco_x[ipu][iL]->Delete(); p_deltavsreco_y[ipu][iL]->Delete(); for (unsigned iS(0); iS<nScans;++iS){ p_posx[ipu][iL][iS]->Delete(); p_posy[ipu][iL][iS]->Delete(); } } } } std::cout << " -- eta point finished successfully" << std::endl; }//loop on eta //plot w0min vs pt for all eta TGraph *grW[4] = {0,0,0,0}; mycW->Clear(); for (unsigned iL(0); iL<nLayers;++iL){//loop on layers for (unsigned ipu(0); ipu<nPu; ++ipu){//loop on pu std::cout << " --Processing pu " << pu[ipu] << std::endl; grW[2*ipu] = new TGraph(neta,etaval,wxminall[ipu][iL]); grW[2*ipu+1] = new TGraph(neta,etaval,wyminall[ipu][iL]); mycW->cd();//ieta+1); grW[2*ipu]->SetTitle(";#eta;W0"); grW[2*ipu]->SetMaximum(6); grW[2*ipu]->SetMinimum(0); grW[2*ipu]->SetLineColor(2*ipu+1); grW[2*ipu]->SetMarkerColor(2*ipu+1); grW[2*ipu]->SetMarkerStyle(20+2*ipu+1); grW[2*ipu+1]->SetLineColor(2*ipu+2); grW[2*ipu+1]->SetMarkerColor(2*ipu+2); grW[2*ipu+1]->SetMarkerStyle(20+2*ipu+2); if (ipu==0) { grW[2*ipu]->Draw("APL"); grW[2*ipu+1]->Draw("PLsame"); } else { grW[2*ipu]->Draw("PLsame"); grW[2*ipu+1]->Draw("PLsame"); } }//loop on pu std::ostringstream lsave; lsave << "PLOTS/w0minvseta_layer" << iL; if (useFit) lsave << "_fit"; else lsave << "_rms"; lsave << ".pdf"; char buf[500]; TLatex lat; sprintf(buf,"Layer %d",iL); lat.DrawLatexNDC(0.1,0.96,buf); mycW->Update(); mycW->Print(lsave.str().c_str()); }//loop on layers return 0; }//main
int EvtDisplay(){//main //const unsigned nS = 7; //TString scenario[nS] = {"0","1","2","3","4","5","6"}; //TString scenario = "VBFH/concept/"; //TString scenario = "ZHtautau/concept/"; //TString scenario = "ZH125/concept/"; TString scenario = "GluGlu/concept/"; bool doAll = false; TString version = "20"; unsigned mipThresh = 1; double minRadius = 316;//mm ////double minX=-150,maxX=150; //double minX=-700,maxX=700; ////double minY=420,maxY=720; ////double minY=1150,maxY=1450; //double minY=-1100,maxY=500; std::ostringstream ltitleBase; //ltitle << "#gamma 200 GeV" //ltitleBase << "VBF H,H#rightarrow#gamma#gamma"; //ltitleBase << "ZH,H#rightarrow#tau#tau"; ltitleBase << "pp #rightarrow gg"; //<< " Event #" << event[ievt] // << ", E_{1#times1 cm^{2}} > " // << mipThresh << " Mips"; const unsigned nLayers = 64; const unsigned nEcalLayers = 31; //VBFH //const unsigned nEvts = 7;//1000; //unsigned event[nEvts]={4,5,6,7,9,11,12};//,6,12};//103,659,875}; //Htautau 1000 //const unsigned nEvts = 7;//1000; //unsigned event[nEvts]={1,2,5,8,10,11,12};//,6,12};//103,659,875}; //Htautau 125 //const unsigned nEvts = 5;//1000; //unsigned event[nEvts]={0,1,2,10,14};//,6,12};//103,659,875}; //gluons const unsigned nEvts = 3;//1000; unsigned event[nEvts]={7,16,22};//,2,3,4};//,6,12};//103,659,875}; // const unsigned nEvts = 13;//1000; //unsigned event[nEvts];//={1,6,12};//103,659,875}; //for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on events //event[ievt] = ievt; //} double minZ=3170,maxZ=5000; //VBFH //double minX[nEvts] = {-700,-600,-400,-400,0,0,0}; //double maxX[nEvts] = {-100,0,200,100,700,700,500}; //double minY[nEvts] = {100,-600,-1100,-800,-100,-200,-700}; //double maxY[nEvts] = {480,0,0,0,400,300,0}; //Htautau 1000 /*double minX[nEvts] = {0,-500,0,-400,0,-500,-700}; double maxX[nEvts] = {600,0,700,500,700,0,600}; double minY[nEvts] = {0,-700,-100,-700,-400,0,-400}; double maxY[nEvts] = {500,0,400,900,200,700,700};*/ //Htautau 125 /*double minX[nEvts] = {-300,-850,-200,-450,-550}; double maxX[nEvts] = {100,-450,300,0,-150}; double minY[nEvts] = {-900,-280,200,-950,-800}; double maxY[nEvts] = {-500,150,650,-550,-400};*/ //pp to gg double minX[nEvts] = {100,100,-200}; double maxX[nEvts] = {700,700,500}; double minY[nEvts] = {100,100,200}; double maxY[nEvts] = {700,700,900}; if (doAll){ for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on events minX[ievt]=-1700;maxX[ievt]=1700; minY[ievt]=-1700;maxY[ievt]=1700; } } //if (doAll){ //minX=-1700,maxX=1700; //minY=-1700,maxY=1700; //} std::ostringstream lName; const unsigned nCanvas = nEvts; TCanvas *myc[nCanvas]; //TPad *pad1 = 0; for (unsigned iC(0);iC<nCanvas;++iC){ lName.str(""); lName << "myc" << iC; myc[iC] = new TCanvas(lName.str().c_str(),lName.str().c_str(),1400,1000); //myc[iC]->Divide(2,1); } std::ostringstream saveName; TString inputDir = "../PLOTS/version_"+version+"/"+scenario+"/"; if (doAll) inputDir += "Overview/"; for (unsigned ievt(0); ievt<nEvts; ++ievt){//loop on events lName.str(""); lName << inputDir ; lName << "CalibHistos_E200_evt" << event[ievt] << ".root"; TFile *inputFile = TFile::Open(lName.str().c_str()); if (!inputFile) { std::cout << " -- Error, input file " << lName.str() << " cannot be opened. Going to next..." << std::endl; continue; //return 1; } TString plotDir = inputDir; //if (doAll) plotDir += "Overview/"; inputFile->cd(); TH3F *p_xyz = 0; p_xyz = (TH3F*)gDirectory->Get("p_xyz")->Clone(); if (!p_xyz) { std::cout << " -- ERROR, pointer for XYZ histogram is null. Exiting..." << std::endl; return 1; } p_xyz->Sumw2(); p_xyz->RebinY(2); p_xyz->RebinZ(2); std::cout << " --bins, min and max of hist = " << p_xyz->GetNbinsY() << " " << p_xyz->GetMinimum() << " " << p_xyz->GetMaximum() << std::endl; set_plot_style(); std::ostringstream ltitle; ltitle << ltitleBase.str(); const unsigned nSlices = 6; int lColor[nSlices] = {1,4,7,3,5,2}; TH3F *p_slice[nSlices]; double val[nSlices+1] = {1,5,20,100,300,500,10000}; for (unsigned iS(0); iS<nSlices; ++iS){ lName.str(""); lName << "slice_" << iS ; p_slice[iS] = new TH3F(lName.str().c_str(),";z(mm);x(mm);y(mm)", p_xyz->GetNbinsX(),p_xyz->GetXaxis()->GetBinLowEdge(1),p_xyz->GetXaxis()->GetBinLowEdge(p_xyz->GetNbinsX()+1), p_xyz->GetNbinsY(),p_xyz->GetYaxis()->GetBinLowEdge(1),p_xyz->GetYaxis()->GetBinLowEdge(p_xyz->GetNbinsY()+1), p_xyz->GetNbinsZ(),p_xyz->GetZaxis()->GetBinLowEdge(1),p_xyz->GetZaxis()->GetBinLowEdge(p_xyz->GetNbinsZ()+1) ); p_slice[iS]->SetMarkerColor(lColor[iS]); //p_slice[iS]->SetLineColor(iS+1); //p_slice[iS]->SetFillColor(iS+1); //p_slice[iS]->SetMarkerStyle(7); p_slice[iS]->GetXaxis()->SetRangeUser(minZ,maxZ); p_slice[iS]->GetYaxis()->SetRangeUser(minX[ievt],maxX[ievt]); p_slice[iS]->GetZaxis()->SetRangeUser(minY[ievt],maxY[ievt]); p_slice[iS]->GetXaxis()->SetLabelSize(0.05); p_slice[iS]->GetYaxis()->SetLabelSize(0.05); p_slice[iS]->GetZaxis()->SetLabelSize(0.05); p_slice[iS]->GetXaxis()->SetTitleSize(0.05); p_slice[iS]->GetYaxis()->SetTitleSize(0.05); p_slice[iS]->GetZaxis()->SetTitleSize(0.05); p_slice[iS]->SetTitle(ltitle.str().c_str()); //val[iS]= exp(iS*log(p_xyz->GetMaximum())/nSlices); } //val[nSlices] = p_xyz->GetMaximum(); double lmin = 10; double lmax = p_xyz->GetBinContent(1,1,1); for (int xb(1); xb<p_xyz->GetNbinsX()+1;++xb){ //std::cout << "--- xb=" << xb << "" << std::endl; for (int yb(1); yb<p_xyz->GetNbinsY()+1;++yb){ double xTmp = p_xyz->GetYaxis()->GetBinCenter(yb); for (int zb(1); zb<p_xyz->GetNbinsZ()+1;++zb){ double yTmp = p_xyz->GetZaxis()->GetBinCenter(zb); double radius = sqrt(yTmp*yTmp+xTmp*xTmp); if (radius < minRadius){ p_xyz->SetBinContent(xb,yb,zb,0); continue; } double ltmp = p_xyz->GetBinContent(xb,yb,zb); if (ltmp<lmin && ltmp>0) lmin=ltmp; if (ltmp>lmax) lmax=ltmp; if (ltmp<1) continue; //std::cout << xb << " " << yb << " " << zb << " " << p_xyz->GetBinContent(xb,yb,zb) << std::endl; if (ltmp < mipThresh) { p_xyz->SetBinContent(xb,yb,zb,0); } else { p_xyz->SetBinContent(xb,yb,zb,ltmp); for (unsigned iS(0); iS<nSlices; ++iS){ if (ltmp<=val[iS+1] && ltmp>val[iS]) p_slice[iS]->SetBinContent(xb,yb,zb,ltmp); } } } } } std::cout << " --min and max by hand = " << lmin << " " << lmax << std::endl; gStyle->SetOptStat(0); myc[ievt]->cd(); //TPad *pad1 = new TPad("pad1","This is pad1",0.01,0.01,0.83,0.99); //pad1->Draw(); //pad1->cd(); //myc[ievt]->cd(1); for (unsigned iS(0); iS<nSlices; ++iS){ std::cout << " -- slice " << iS << std::endl; //set artificially the boundaries: min and max in dummy bins //p_slice[iS]->SetBinContent(1,1,1,1); //p_slice[iS]->SetBinContent(2,1,1,lmax); p_slice[iS]->Draw(iS==0? "" : "same"); } //myc[ievt]->cd(2); //TPad *pad2 = new TPad("pad2","This is pad2",0.85,0.01,0.99,0.99); //pad2->Draw(); //pad2->cd(); TLatex lat; lat.SetTextAlign(31); //lat.SetTextSize(0.2); for (unsigned iS(0); iS<nSlices; iS++){ //std::cout << iS << std::endl; char buf[500]; sprintf(buf,"%3.1f < Mips < %3.1f",val[iS],val[iS+1]); lat.SetTextColor(lColor[iS]); lat.DrawLatexNDC(1.,(iS*1.0/nSlices)/2.+0.5,buf); } myc[ievt]->Update(); saveName.str(""); saveName << plotDir << "/evtDisplay_evt" << event[ievt] << "_mipThresh" << mipThresh; myc[ievt]->Print((saveName.str()+".png").c_str()); myc[ievt]->Print((saveName.str()+".pdf").c_str()); }//loop on events return 0; }//main
int plotEmissed() { //std::string basename = "p_nAboveMax_"; std::string basename = "p_fracEmissed_"; std::string pSuffix = "300"; std::string pPrefix = "Thresh3000/"; bool integrate = true; const unsigned nS = 1; std::string scenario[nS] = { "e-/" }; const unsigned nV = 1; TString version[nV] = {"12"};//,"0"}; const unsigned nHists = 3; std::string label[nHists] = {"5x5mm2","10x10mm2","15x15mm2"}; const unsigned nLayers = 30; //unsigned genEn[]={1000}; //unsigned genEn[]={5,10,15,20,25,30,40,50,60,100,150,200,300,400,500,1000,2000}; unsigned genEn[]={400,500,1000,2000}; const unsigned nGenEn=sizeof(genEn)/sizeof(unsigned); double genEnErr[nGenEn]; double genEnD[nGenEn]; TCanvas *mycL = new TCanvas("mycL","mycL",1500,1000); mycL->Divide(2,2); TCanvas *myc = new TCanvas("myc","myc",1); char buf[500]; TLatex lat; for (unsigned iV(0); iV<nV;++iV){//loop on versions for (unsigned iS(0); iS<nS;++iS){//loop on scenarios TString plotDir = "../PLOTS/gitV00-02-02/version"+version[iV]+"/"+scenario[iS]+"/"+pPrefix; TH1F *maxNhit[nHists]; for (unsigned iE(0); iE<nGenEn; ++iE){ std::cout << "- Processing energy : " << genEn[iE] << std::endl; genEnErr[iE] = 0; genEnD[iE] = genEn[iE]; TFile *inputFile = 0; std::ostringstream linputStr; linputStr << plotDir << "validation_" << pSuffix << "um_e" << genEn[iE] << ".root"; inputFile = TFile::Open(linputStr.str().c_str()); if (!inputFile) { std::cout << " -- Error, input file " << linputStr.str() << " cannot be opened. Exiting..." << std::endl; return 1; } else std::cout << " -- File " << inputFile->GetName() << " sucessfully opened." << std::endl; //maxNhit[0] = (TH1F*)gDirectory->Get(basename+"2d5"); //if (iE==0) maxNhit[0] = (TH1F*)gDirectory->Get((basename+"5").c_str()); //else maxNhit[0]->Add((TH1F*)gDirectory->Get((basename+"5").c_str())); //if (iE==0) maxNhit[1] = (TH1F*)gDirectory->Get((basename+"10").c_str()); //else maxNhit[1]->Add((TH1F*)gDirectory->Get((basename+"10").c_str())); //if (iE==0) maxNhit[2] = (TH1F*)gDirectory->Get((basename+"15").c_str()); //else maxNhit[2]->Add((TH1F*)gDirectory->Get((basename+"15").c_str())); // }//loop on energies if (integrate){ for (unsigned iH(0); iH<nHists;++iH){ double inttot = maxNhit[iH]->Integral(0,maxNhit[iH]->GetNbinsX()+1); if (inttot==0) { std::cout << "Integral is 0 ! " << "Setting to 1 so it doesn't crash..." << std::endl; inttot = 1; } for (int bin(0); bin<maxNhit[0]->GetNbinsX()+2;++bin){ double err = 0; double integral = maxNhit[iH]->IntegralAndError(bin,maxNhit[iH]->GetNbinsX()+1,err); /*for (int bin2(bin); bin2<maxNhit[0]->GetNbinsX()+2;++bin2){ integral += maxNhit[iH]->GetBinContent(bin2); err += pow(maxNhit[iH]->GetBinError(bin2),2); } err = sqrt(err);*/ maxNhit[iH]->SetBinContent(bin,integral/inttot); maxNhit[iH]->SetBinError(bin,err/inttot); } } } mycL->cd(); TLegend *leg = new TLegend(0.66,0.66,0.89,0.89); leg->SetFillColor(10); for (unsigned iH(0); iH<nHists;++iH){ gStyle->SetOptStat(0); myc->cd(); gPad->SetLogy(1); gStyle->SetStatX(0.89); gStyle->SetStatY(0.89); gStyle->SetStatH(0.5); gStyle->SetStatW(0.3); //maxNhit[iH]->Rebin(genEn[iE]>500? 20*iE : (iE>0?2*iE:1)); maxNhit[iH]->GetXaxis()->SetRange(maxNhit[iH]->FindFirstBinAbove(0),maxNhit[iH]->FindLastBinAbove(0)); //maxNhit[iH]->SetTitle(";#hits with E_{hit} > E^{avg}_{max};Events"); //maxNhit[iH]->SetTitle(";#hits with E_{hit} > E^{avg}_{max};Events"); maxNhit[iH]->SetLineColor(iH+1); maxNhit[iH]->SetMarkerColor(iH+1); maxNhit[iH]->SetMarkerStyle(iH+21); //maxNhit[iH]->Rebin(2); maxNhit[iH]->Draw(); //sprintf(buf,"Maximum = %3.0f MIPs",maxNhit[iH]->GetXaxis()->GetBinCenter(maxNhit[iH]->FindLastBinAbove(0))); lat.SetTextSize(0.05); //lat.DrawLatexNDC(0.12,0.85,buf); sprintf(buf,"%s #mu m Si",pSuffix.c_str()); lat.DrawLatexNDC(0.12,0.75,buf); //sprintf(buf,"Geant4 Standalone, e-, pad size = %s",label[iH].c_str()); //if (nGenEn==1) sprintf(buf,"Geant4 Standalone, e- %d GeV, pad size = %s",genEn[iE], label[iH].c_str()); lat.DrawLatexNDC(0.1,0.92,buf); std::ostringstream lsave; lsave << plotDir << pSuffix << "um/" << basename << label[iH]; //if (nGenEn==1) lsave << "e" << genEn[iE]; if (integrate) lsave << "_int"; lsave << ".pdf"; myc->Print(lsave.str().c_str()); mycL->cd(iE+1); gPad->SetLogy(1); gPad->SetGridx(); gPad->SetGridy(); maxNhit[iH]->GetYaxis()->SetTitle("Event fraction"); maxNhit[iH]->GetXaxis()->SetTitle("#frac{E_{missed}}{E_{tot}}"); //maxNhit[iH]->DrawNormalized(iH==0?"PE":"PEsame"); maxNhit[iH]->Sumw2(); if (!integrate && maxNhit[iH]->GetEntries()>0) maxNhit[iH]->Scale(1./maxNhit[iH]->GetEntries()); maxNhit[iH]->SetMaximum(1); maxNhit[iH]->SetMinimum(0.0001); maxNhit[iH]->GetXaxis()->SetRangeUser(0,0.6); maxNhit[iH]->Draw(iH==0?"PE":"PEsame"); leg->AddEntry(maxNhit[iH],label[iH].c_str(),"P"); lat.SetTextSize(0.05); //sprintf(buf,"Maximum = %3.0f MIPs",maxNhit[iH]->GetXaxis()->GetBinCenter(maxNhit[iH]->FindLastBinAbove(0))); //lat.DrawLatexNDC(0.2,0.8,buf); if (iH==0){ //sprintf(buf,"%s #mu m Si",pSuffix.c_str()); //lat.DrawLatexNDC(0.15,0.3,buf); //sprintf(buf,"Geant4 Standalone, e-, %s #mu m Si",pSuffix.c_str()); //if (nGenEn==1) sprintf(buf,"Geant4 Standalone, e- %d GeV, %s #mu m Si",genEn[iE],pSuffix.c_str()); lat.DrawLatexNDC(0.1,0.92,buf); } }//loop on hists mycL->cd(iE+1); lat.DrawLatexNDC(0.5,0.2,"Saturation: 3000 MIPs"); leg->Draw("same"); }//loop on energies std::ostringstream lsave; lsave << plotDir << pSuffix<< "um/" << basename ; //if (nGenEn==1) lsave << "e" << genEn[iE]; if (integrate) lsave << "int_"; lsave << "all.pdf"; mycL->Print(lsave.str().c_str()); /* TGraphErrors *gr[nHists][1]; TLegend *leg[1]; for (unsigned i(0); i<1;++i){ leg[i] = new TLegend(0.6,0.2,0.88,0.48); leg[i]->SetFillColor(10); myc->cd(); gPad->SetLogx(1); gPad->SetLogy(1); gPad->SetGridx(1); gPad->SetGridy(1); TF1 *fitfunc[nHists]; for (unsigned iH(0);iH<nHists;++iH){ if (i==0) gr[iH][i] = new TGraphErrors(nGenEn,genEnD,mean[iH],genEnErr,rms[iH]); //else gr[iH][i] = new TGraphErrors(nGenEn,genEnD,mean3rms[iH],genEnErr,mean3rmserr[iH]); gr[iH][i]->GetXaxis()->SetTitle("Beam energy (GeV)"); if (i==0) gr[iH][i]->GetYaxis()->SetTitle("N(E>maxE)"); //else gr[iH][i]->GetYaxis()->SetTitle("<maxN>+3#times RMS (MIPs)"); gr[iH][i]->SetTitle(""); gr[iH][i]->SetMarkerColor(iH+1); gr[iH][i]->SetLineColor(iH+1); gr[iH][i]->SetMarkerStyle(20+iH); gr[iH][i]->SetMaximum(20000); gr[iH][i]->Draw(iH>0?"P":"AP"); leg[i]->AddEntry(gr[iH][i],label[iH].c_str(),"P"); /* if (i==0){ gr[iH][i]->Fit("pol2","","same"); fitfunc[iH] = gr[iH][i]->GetFunction("pol2"); } else { gr[iH][i]->Fit("pol1","","same",20,2000); fitfunc[iH] = gr[iH][i]->GetFunction("pol1"); } fitfunc[iH]->SetLineColor(iH+1); if (i==0) sprintf(buf,"<maxN> = (%3.0f #pm %3.0f) + (%3.1f #pm %3.1f)#times E + (%1.0e#pm%1.0e) #times E^{2}",fitfunc[iH]->GetParameter(0),fitfunc[iH]->GetParError(0),fitfunc[iH]->GetParameter(1),fitfunc[iH]->GetParError(1),fitfunc[iH]->GetParameter(2),fitfunc[iH]->GetParError(2)); else sprintf(buf,"<maxN> = (%3.1f #pm %3.1f) + (%3.2f #pm %3.2f)#times E",fitfunc[iH]->GetParameter(0),fitfunc[iH]->GetParError(0),fitfunc[iH]->GetParameter(1),fitfunc[iH]->GetParError(1)); lat.SetTextColor(iH+1); lat.SetTextSize(0.04); //lat.DrawLatexNDC(0.05,0.95-0.05*iH,buf); } sprintf(buf,"HGCAL Geant4 Standalone Simulation, e-"); lat.SetTextColor(1); lat.SetTextSize(0.04); lat.DrawLatexNDC(0.01,0.01,buf); leg[i]->Draw("same"); lsave.str(""); lsave << plotDir << pSuffix << "um/NhitsAboveMax"; //if (i==1) lsave << "_meanplus3rms"; lsave << ".pdf"; myc->Update(); myc->Print(lsave.str().c_str()); //return 1; } */ }//loop on scenarios }//loop on versions return 0; }
void plotHist() { gROOT->ProcessLine(".L tdrstyle.C"); setTDRStyle(); // names and such string inDir, inFile01, inFile02, inFile03, inFile04, outFile, numHist, denHist, proc; inDir = "/home/ieeya/Downloads/HLT_Val/Part2_OpenHLT/OpenHLT/logs/run02/ttbar_skim/e_740/turnOn_phys14/drawVar_v1/"; // specify input and output files, 01 is numerator, 02 is denominator // same for 03, 04 etc proc = "dye"; inFile01 = inDir + "dye_tID.root"; inFile02 = inDir + "dye_eID.root"; inFile03 = inDir + "wev_tID.root"; inFile04 = inDir + "wev_eID.root"; numHist = "drawHist/ptElectron_match"; denHist = "drawHist/ptElectron_gsf"; TFile *inPut01 = new TFile(inFile01.c_str()); TFile *inPut02 = new TFile(inFile02.c_str()); TFile *inPut03 = new TFile(inFile03.c_str()); TFile *inPut04 = new TFile(inFile04.c_str()); const Int_t nBin = 25; //25 //Double_t ptBins[nBin + 1] = {0., 5., 10., 15., 20., 25., 30., 32., 34., 36., 38., 40., 42., 44., 46., 48., 50., 55., 60., 70., 80., 90., 110., 130., 150., 200.}; Double_t ptBins[nBin + 1] = {0., 5., 10., 15., 20., 25., 30., 32., 34., 36., 38., 40., 42., 44., 46., 48., 50., 55., 60., 70., 80., 90., 110., 130., 150., 200.}; //Double_t ptBins[nBin + 1] = {20., 25., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 52., 54., 56., 58., 60., 62., 64., 66., 68., 70., 75., 80., 85., 90., 95., 100., 110., 120., 130., 140., 150., 175., 200.}; // create the histograms TH1::SetDefaultSumw2(true); TH1D *inNum01 = dynamic_cast<TH1D *>(inPut01->Get(numHist.c_str())); //TH1D *reNum01 = (TH1D*) inNum01->Rebin(nBin, "reNum01", ptBins); TH1D *inDen01 = dynamic_cast<TH1D *>(inPut02->Get(denHist.c_str())); //TH1D *reDen01 = (TH1D*) inDen01->Rebin(nBin, "reDen01", ptBins); TH1D *inNum02 = dynamic_cast<TH1D *>(inPut03->Get(numHist.c_str())); //TH1D *reNum02 = (TH1D*) inNum02->Rebin(nBin, "reNum02", ptBins); TH1D *inDen02 = dynamic_cast<TH1D *>(inPut04->Get(denHist.c_str())); //TH1D *reDen02 = (TH1D*) inDen01->Rebin(nBin, "reDen02", ptBins); Double_t yMin = 0., yMax = 1.13; // bins etc is still manual TH1D *outEff01 = new TH1D("effElectron01", "Single Electron Turn On for 32 GeV Online Cut", nBin, ptBins); outEff01->SetXTitle("Electron p_{T} (GeV/c)"); outEff01->SetYTitle("Efficiency"); outEff01->SetLineColor(kAzure - 1); outEff01->SetLineWidth(3); outEff01->Divide(inNum01, inDen01, 1., 1., "B"); outEff01->SetMinimum(yMin); outEff01->SetMaximum(yMax); TH1D *outEff02 = new TH1D("effElectron02", "720p8 WP75 Electron eff vs p_{T}", nBin, ptBins); outEff02->SetXTitle("Electron p_{T} (GeV/c)"); outEff02->SetYTitle("Efficiency"); outEff02->SetLineColor(kRed + 1); outEff02->SetLineWidth(3); //outEff02->Divide(reNum02, reDen02, 1., 1., "B"); outEff02->SetMinimum(yMin); outEff02->SetMaximum(yMax); TCanvas *c01 = new TCanvas("c01", "c01", 200, 10, 1000, 1000); c01->cd(); c01->SetGrid(); outEff01->Draw("CL"); //outEff02->Draw("same"); TLatex txt; txt.SetTextSize(0.03); txt.SetTextAlign(13); txt.DrawLatexNDC(0.1, 0.87, "#bf{CMS}"); txt.DrawLatexNDC(0.1, 0.84, "#it{Simulation Preliminary}"); txt.DrawLatexNDC(0.808, 0.927, "2015, 13 TeV"); TLegend *leg01 = new TLegend(.76, .75, .94, .93); leg01->SetHeader("L1 Seed"); leg01->AddEntry(outEff01, "L1_SingleIsoEG30er"); leg01->AddEntry(outEff02, "L1_SingleEG30"); //leg01->Draw(); c01->SaveAs((inDir + proc + "_turnOn.pdf").c_str()); c01->Close(); }
void derivefromNS(bool data = false) { // float shift = mode == 2 ? -2 : mode*2; //mode = 0,1,2 shift = 0,2,-2 // cout<<"shift = "<<shift<<endl; auto file = config.getfile_djt(data ? "dtPbjcl" : "mcPbqcd"); auto nt = (TTree *)file->Get("nt"); for (unsigned i=1;i<binbounds.size();i++) { int b1 = binbounds[i-1]; int b2 = binbounds[i]; seth(71,38,180); //71,38 auto h = geth(Form("h%d%d",b1,b2)); //allowing one more bin for overflow seth(b2-b1,b1,b2); auto hb = geth(Form("hb%d%d",b1,b2)); TString mcappendix = data ? "" : "&& pthat>50";//"&& subid2!=0 && pthat>50"; //"&& pthat>50";//"&& !(subid2==0 && refpt2>20) && pthat>50"; //"&& pthat>80";// //Form("jtpt2+%f",shift) nt->Project(h->GetName(),"jtpt2", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data())); nt->Project(hb->GetName(),"bin", Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphi21<1.05 %s)",b1,b2,mcappendix.Data())); ScaleVisibleBins(h,NSfrac[i-1]); h->SetBinContent(1,h->GetBinContent(0)+h->GetBinContent(1)); // auto p = new TProfile(Form("p%d%d",b1,b2),Form("prof"),71,38,180); // nt->Project(p->GetName(),"(subid2 == 0 && refpt2 > 20):jtptSignal2",Form("weight*(jtpt1>100&&bin>=%d && bin<%d && dphiSignal21<1.05 && !(subid2==0 && refpt2>20) && pthat>80)",b1,b2)); auto g = getCDFgraph(h); g->GetXaxis()->SetTitle("p_{T,2} threshold [GeV]"); g->GetYaxis()->SetTitle("found fraction"); auto gtemp = getCDFgraph(h); meanb.push_back(hb->GetMean()); prob.push_back(gtemp->Eval(pt)); float c0=g->Eval(50); cout<<"prob at 50: "<<c0<<endl; auto gf = new TFile("graph.root","recreate"); gtemp->Write(); gf->Close(); // auto f = new TF1(Form("f%d%d",b1,b2),"1-[0]*exp(-[1]*(x-40))",40,180); // f->SetParameters(0.1,0.1); // // f->FixParameter(1,0.08); // auto f = new TF1(Form("f%d%d",b1,b2),"TMath::Erf((x-[0])/[1])",40,180); // f->SetParameters(40,10); // f->FixParameter(1,25); auto f = new TF1(Form("f%d%d",b1,b2),"exp(-[0]*exp(-[1]*x))",40,180); f->SetParameters(100,0.1); // f->FixParameter(1,0.11); //!!!!!!!!!! f->SetLineColor(kRed); f->SetLineWidth(2); g->Fit(f,"RM"); fs.push_back(f); binmean.push_back(hb->GetMean()); float median = -1/f->GetParameter(1)*log(-1/f->GetParameter(0)*log(0.5)); Draw({h}); // h->Rebin(2); auto gcoarse = getCDFgraph(h); auto c = getc(); TLatex *Tl = new TLatex(); gcoarse->SetMinimum(0);g->SetMaximum(1); gcoarse->Draw("AP"); f->Draw("same"); Tl->DrawLatexNDC(0.6,0.55,"y=e^{-a e^{-b x} }"); Tl->DrawLatexNDC(0.6,0.50,Form("a = %.1f",f->GetParameter(0))); Tl->DrawLatexNDC(0.6,0.45,Form("b = %.2f",f->GetParameter(1))); Tl->DrawLatexNDC(0.6,0.4,Form("PbPb bin %d-%d",b1,b2)); Tl->DrawLatexNDC(0.6,0.35,Form("median = %.2f",median)); TLine *l1 = new TLine(median,0,median, f->Eval(median)); l1->Draw(); TLine *l2 = new TLine(0,0.5,median, f->Eval(median)); l2->Draw(); // p->SetMarkerColor(kRed); // p->SetMarkerSize(1); // p->Draw("same"); SavePlot(c,Form("fit%d%d",b1,b2));//return; } }
void findtruthpp() { seth(10,0,1); auto hmcppxJTrue = geth("hmcppxJTrue","true;x_{J};Event fractions"); auto hmcppxJTrueTag = geth("hmcppxJTrueTag","true tagged;x_{J};Event fractions"); auto hmcppxJTrueTagCorr = geth("hmcppxJTrueTagCorr","true tagged corrected;x_{J};Event fractions"); TFile *fmcpp = new TFile(config.getFileName_djt("mcppbfa")); Fill(fmcpp,[&] (dict &m) { if (m["pthat"]<pthatcut) return; if (m[pairCodeSB1]!=0) return; // if (m["pthat"]<80) return; // if (m["bProdCode"]!=1) return; float w = m["weight"]*processweight((int)m["bProdCode"]); // float w = m["weight"]; // if (m["bProdCode"]==2) return; float corr = tageffcorrectionpp(m["jtpt1"],m["jteta1"],m[jtptSB],m[jtetaSB]); float wb = w*corr; if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[dphiSB1]>PI23) hmcppxJTrue->Fill(m[jtptSB]/m["jtpt1"],w); if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[dphiSB1]>PI23 && m["discr_csvV1_1"]>0.9 && m[discr_csvV1_SB]>0.9) { hmcppxJTrueTag->Fill(m[jtptSB]/m["jtpt1"],w); hmcppxJTrueTagCorr->Fill(m[jtptSB]/m["jtpt1"],wb); } }); NormalizeAllHists(); plotputmean = true; plotytitle = "Event fractions"; plotdivide = false; // aktstring += "R=0.4 |#eta|<2.0"; // plotsecondline = Form("p_{T,1}>%d GeV, p_{T,2}>%d GeV", (int)pt1cut, (int)pt2cut); // plotthirdline = "#Delta#phi>2/3#pi"; plottextposy = 0.8; plottextposx = 0.2; plotmeanposy = 0.43; plotymax = 0.2; plotymin = 0; plotlegendpos = BottomRight;//TopLeft; aktstring = "pp"; SetMC({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); SetData({hmcppxJTrue}); Draw({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); hmcppxJTrue->SetMinimum(0); hmcppxJTrue->SetMaximum(0.3); hmcppxJTrue->SetLineWidth(2); hmcppxJTrue->SetMarkerStyle(kNone); hmcppxJTrue->SetFillStyle(0); hmcppxJTrueTag->SetMarkerStyle(kOpenCircle); hmcppxJTrueTagCorr->SetMarkerStyle(kOpenSquare); plotymax = 0.3; SetB({hmcppxJTrue,hmcppxJTrueTag,hmcppxJTrueTagCorr}); float xjtrue = hmcppxJTrue->GetMean(); float xjtruetag = hmcppxJTrueTag->GetMean(); float xjtruetagcorr = hmcppxJTrueTagCorr->GetMean(); float exjtrue = hmcppxJTrue->GetMeanError(); float exjtruetag = hmcppxJTrueTag->GetMeanError(); float exjtruetagcorr = hmcppxJTrueTagCorr->GetMeanError(); auto c = getc(); hmcppxJTrue->Draw("hist"); hmcppxJTrueTag->Draw("E1,same"); hmcppxJTrueTagCorr->Draw("E1,same"); plotlegendpos = TopLeft; auto l = getLegend(); l->AddEntry(hmcppxJTrue,Form("b-dijets, #LTx_{J}#GT=%.3f#pm%.3f",xjtrue,exjtrue),"L"); l->AddEntry(hmcppxJTrueTag,Form("uncorrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetag,exjtruetag),"P"); l->AddEntry(hmcppxJTrueTagCorr,Form("corrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetagcorr,exjtruetagcorr),"P"); l->Draw(); TLatex *Tl = new TLatex(); Tl->DrawLatexNDC(0.2, 0.8, aktstring); SavePlot(c,"closurepp"); }
void findtruthPbPb(int binMin, int binMax) { TFile *fmc = new TFile(config.getFileName_djt("mcPbbfa")); buildNamesuffix = TString::Format("_bin_%d_%d",binMin, binMax); // buildTitlesuffix = TString::Format("%d-%d %%",binMin/2, binMax/2); seth(10,0,1); auto hmcPbPbxJTrue = geth("hmcPbPbxJTrue","PbPb true;x_{J};Event fractions"); auto hmcPbPbxJTrueTag = geth("hmcPbPbxJTrueTag","PbPb true tagged;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorr = geth("hmcPbPbxJTrueTagCorr","PbPb true tagged corrected;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrPt = geth("hmcPbPbxJTrueTagCorrPt","PbPb true tagged corrected pt;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrEta = geth("hmcPbPbxJTrueTagCorrEta","PbPb true tagged corrected eta;x_{J};Event fractions"); auto hmcPbPbxJTrueTagCorrBin = geth("hmcPbPbxJTrueTagCorrBin","PbPb true tagged corrected bin;x_{J};Event fractions"); seth(12,20,140);//10,40,100); auto hpt2true = geth("hpt2true","true;p_{T,2} GeV"); auto hpt2truetag = geth("hpt2truetag","true tagged;p_{T,2} GeV"); auto hpt2truetagovertrue = geth("hpt2truetagovertrue","true tagged/true;p_{T,2} GeV"); auto hpt2truetagcorr = geth("hpt2truetagcorr","true tagged corrected;p_{T,2} GeV"); auto hpt2truetagcorrovertrue = geth("hpt2truetagcorrovertrue","true tagged corrected/true;p_{T,2} GeV"); seth(10,100,200); auto hpt1true = geth("hpt1true","true;p_{T,1} GeV"); auto hpt1truetag = geth("hpt1truetag","true tagged;p_{T,1} GeV"); auto hpt1truetagovertrue = geth("hpt1truetagovertrue","true tagged/true;p_{T,1} GeV"); auto hpt1truetagcorr = geth("hpt1truetagcorr","true tagged corrected;p_{T,1} GeV"); auto hpt1truetagcorrovertrue = geth("hpt1truetagcorrovertrue","true tagged corrected/true;p_{T,1} GeV"); seth(10,0,200); auto hbintrue = geth("hbintrue","true;bin"); auto hbintruetag = geth("hbintruetag","true tagged;bin"); auto hbintruetagovertrue = geth("hbintruetagovertrue","true tagged/true;bin"); auto hbintruetagcorr = geth("hbintruetagcorr","true tagged corrected;bin"); auto hbintruetagcorrovertrue = geth("hbintruetagcorrovertrue","true tagged corrected/true;bin"); seth(20,-2,2); auto heta2true = geth("heta2true","true;#eta_{2}"); auto heta2truetag = geth("heta2truetag","true tagged;#eta_{2}"); auto heta2truetagovertrue = geth("heta2truetagovertrue","true tagged/true;#eta_{2}"); auto heta2truetagcorr = geth("heta2truetagcorr","true tagged corrected;#eta_{2}"); auto heta2truetagcorrovertrue = geth("heta2truetagcorrovertrue","true tagged corrected/true;#eta_{2}"); auto heta1true = geth("heta1true","true;#eta_{1}"); auto heta1truetag = geth("heta1truetag","true tagged;#eta_{1}"); auto heta1truetagovertrue = geth("heta1truetagovertrue","true tagged/true;#eta_{1}"); auto heta1truetagcorr = geth("heta1truetagcorr","true tagged corrected;#eta_{1}"); auto heta1truetagcorrovertrue = geth("heta1truetagcorrovertrue","true tagged corrected/true;#eta_{1}"); unordered_set<int> eventstodiscard = {1805770,1116573,1084397};//, // 5755734,1599758,395810, // 1363321,211625,3195128}; // Fill(fmc,[&] (dict &m) { if (m["bin"]<binMin || m["bin"]>=binMax) return; if (m["pthat"]<pthatcut) return; if (m[pairCodeSB1]!=0) return; // if (m["bProdCode"]>1) return; if (eventstodiscard.find(m["event"])!=eventstodiscard.end()) return; //kill large-weight GSP event float w = m["weight"]*processweight((int)m["bProdCode"]); //because we have only b-dijets float corr = tageffcorrectionPbPb(m["jtpt1"],m["jteta1"],m[jtptSB],m[jtetaSB],m["bin"]); // float corrpt = getPbPbcorrectionPt(m["jtpt1"],m[jtptSB]); // float correta = getPbPbcorrectionEta(m["jteta1"],m[jtetaSB]); // float corrbin = getPbPbcorrectionBin(m["bin"]); float wb = w*corr; if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[refptSB]>20 && m[dphiSB1]>PI23) { hmcPbPbxJTrue->Fill(m[jtptSB]/m["jtpt1"],w); hpt2true->Fill(m[jtptSB],w); hpt1true->Fill(m["jtpt1"],w); heta2true->Fill(m[jtetaSB],w); heta1true->Fill(m["jteta1"],w); hbintrue->Fill(m["bin"],w); } if (m["jtpt1"]>pt1cut && m["refpt1"]>50 && abs(m["refparton_flavorForB1"])==5 && m[jtptSB]>pt2cut && m[refptSB]>20 && m[dphiSB1]>PI23 && m["discr_csvV1_1"]>0.9 && m[discr_csvV1_SB]>0.9) { // //corrpt *= m[jtptSB] < 60 ? 1./0.7 : 1; //wb *= m[jtptSB] < 60 ? 1./0.7 : 1; hmcPbPbxJTrueTag->Fill(m[jtptSB]/m["jtpt1"],w); hmcPbPbxJTrueTagCorr->Fill(m[jtptSB]/m["jtpt1"],wb); // hmcPbPbxJTrueTagCorrPt->Fill(m[jtptSB]/m["jtpt1"],w*corrpt); // hmcPbPbxJTrueTagCorrEta->Fill(m[jtptSB]/m["jtpt1"],w*corrpt*correta); // hmcPbPbxJTrueTagCorrBin->Fill(m[jtptSB]/m["jtpt1"],w*corrpt*correta*corrbin); hpt2truetag->Fill(m[jtptSB],w); hpt1truetag->Fill(m["jtpt1"],w); heta2truetag->Fill(m[jtetaSB],w); heta1truetag->Fill(m["jteta1"],w); hbintruetag->Fill(m["bin"],w); hpt2truetagcorr->Fill(m[jtptSB],wb); hpt1truetagcorr->Fill(m["jtpt1"],wb); heta2truetagcorr->Fill(m[jtetaSB],wb); heta1truetagcorr->Fill(m["jteta1"],wb); hbintruetagcorr->Fill(m["bin"],wb); } }); NormalizeAllHists(); //plotymax = 9999; aktstring = TString::Format("PbPb %d-%d %%",binMin/2, binMax/2);//TString::Format("PbPb#Delta#phi>2/3#pi %d-%d %%",binMin/2, binMax/2); SetMC({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); SetData({hmcPbPbxJTrue}); hmcPbPbxJTrue->SetMinimum(0); hmcPbPbxJTrue->SetMaximum(0.3); hmcPbPbxJTrue->SetLineWidth(2); hmcPbPbxJTrue->SetMarkerStyle(kNone); hmcPbPbxJTrue->SetFillStyle(0); hmcPbPbxJTrueTag->SetMarkerStyle(kOpenCircle); hmcPbPbxJTrueTagCorr->SetMarkerStyle(kOpenSquare); plotymax = 0.3; Draw({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); SetB({hmcPbPbxJTrue,hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorr}); float xjtrue = hmcPbPbxJTrue->GetMean(); float xjtruetag = hmcPbPbxJTrueTag->GetMean(); float xjtruetagcorr = hmcPbPbxJTrueTagCorr->GetMean(); float exjtrue = hmcPbPbxJTrue->GetMeanError(); float exjtruetag = hmcPbPbxJTrueTag->GetMeanError(); float exjtruetagcorr = hmcPbPbxJTrueTagCorr->GetMeanError(); auto c = getc(); hmcPbPbxJTrue->Draw("hist"); hmcPbPbxJTrueTag->Draw("E1,same"); hmcPbPbxJTrueTagCorr->Draw("E1,same"); plotlegendpos = TopLeft; auto l = getLegend(); l->AddEntry(hmcPbPbxJTrue,Form("b-dijets, #LTx_{J}#GT=%.3f#pm%.3f",xjtrue,exjtrue),"L"); l->AddEntry(hmcPbPbxJTrueTag,Form("uncorrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetag,exjtruetag),"P"); l->AddEntry(hmcPbPbxJTrueTagCorr,Form("corrected, #LTx_{J}#GT=%.3f#pm%.3f",xjtruetagcorr,exjtruetagcorr),"P"); l->Draw(); TLatex *Tl = new TLatex(); Tl->DrawLatexNDC(0.2, 0.8, aktstring); SavePlot(c,Form("closure%d%d",binMin,binMax)); // //if (binMin==0 && binMax==200) { // Draw({hmcPbPbxJTrueTag,hmcPbPbxJTrueTagCorrPt,hmcPbPbxJTrueTagCorrEta,hmcPbPbxJTrueTagCorrBin}); // SetMC({hpt2truetag,hpt1truetag,heta2truetag,heta1truetag,hbintruetag}); // plotputmean = false; // plotymax = 0.2; // Draw({hpt2true,hpt2truetag,hpt2truetagcorr}); // plotymax = 0.3; // Draw({hpt1true,hpt1truetag,hpt1truetagcorr}); // plotymax = 0.2; // Draw({heta2true,heta2truetag,heta2truetagcorr}); // Draw({heta1true,heta1truetag,heta1truetagcorr}); // plotymax = 1; // Draw({hbintrue,hbintruetag,hbintruetagcorr}); plotymin = 0; plotymax = 0.2; Draw({hpt2truetag,hpt2true}); Draw({hpt2truetagcorr,hpt2true}); hpt2truetagovertrue->Divide(hpt2truetag,hpt2true,1,1); //"B" hpt1truetagovertrue->Divide(hpt1truetag,hpt1true,1,1); //"B" heta2truetagovertrue->Divide(heta2truetag,heta2true,1,1); //"B" heta1truetagovertrue->Divide(heta1truetag,heta1true,1,1); //"B" hbintruetagovertrue->Divide(hbintruetag,hbintrue,1,1); //"B" hpt2truetagcorrovertrue->Divide(hpt2truetagcorr,hpt2true,1,1); //"B" hpt1truetagcorrovertrue->Divide(hpt1truetagcorr,hpt1true,1,1); //"B" heta2truetagcorrovertrue->Divide(heta2truetagcorr,heta2true,1,1); //"B" heta1truetagcorrovertrue->Divide(heta1truetagcorr,heta1true,1,1); //"B" hbintruetagcorrovertrue->Divide(hbintruetagcorr,hbintrue,1,1); //"B" NormalizeAllHists(); Draw({hpt2truetagovertrue,hpt2truetagcorrovertrue}); Draw({hpt1truetagovertrue,hpt1truetagcorrovertrue}); Draw({heta2truetagovertrue,heta2truetagcorrovertrue}); Draw({heta1truetagovertrue,heta1truetagcorrovertrue}); Draw({hbintruetagovertrue,hbintruetagcorrovertrue}); // } }