diff --git a/Calibration/HcalCalibAlgos/macros/CalibCorr.C b/Calibration/HcalCalibAlgos/macros/CalibCorr.C index 005b2c8500884..98c60921e3cd8 100644 --- a/Calibration/HcalCalibAlgos/macros/CalibCorr.C +++ b/Calibration/HcalCalibAlgos/macros/CalibCorr.C @@ -215,7 +215,7 @@ double puFactor(int type, int ieta, double pmom, double eHcal, double ediff, boo << LINEAR_COR_COEF[icor] << ":" << SQUARE_COR_COEF[icor] << " Fac " << fac; } else if (type == 97) { // dlphin Try 3 const double CONST_COR_COEF[6] = {0.987617, 0.983421, 0.938622, 0.806662, 0.738354, 0.574195}; - const double LINEAR_COR_COEF[6] = {-0.07018610, -0.2494880, -0.1997290, -0.1769320,-0.2427950,-0.1230480}; + const double LINEAR_COR_COEF[6] = {-0.07018610, -0.2494880, -0.1997290, -0.1769320, -0.2427950, -0.1230480}; const double SQUARE_COR_COEF[6] = {0, 0, 0.0263541, 0.0257008, 0.0426584, 0.0200361}; const int PU_IETA_1 = 7; const int PU_IETA_2 = 16; @@ -232,7 +232,7 @@ double puFactor(int type, int ieta, double pmom, double eHcal, double ediff, boo << LINEAR_COR_COEF[icor] << ":" << SQUARE_COR_COEF[icor] << " Fac " << fac; } else if (type == 98) { // dlphin Try 2 const double CONST_COR_COEF[6] = {0.987665, 0.983468, 0.938628, 0.807241, 0.739132, 0.529059}; - const double LINEAR_COR_COEF[6] = {-0.0708906, -0.249995, -0.199683, -0.177692,-0.243436,-0.0668783}; + const double LINEAR_COR_COEF[6] = {-0.0708906, -0.249995, -0.199683, -0.177692, -0.243436, -0.0668783}; const double SQUARE_COR_COEF[6] = {0, 0, 0.0263163, 0.0260158, 0.0426864, 0.00398778}; const int PU_IETA_1 = 7; const int PU_IETA_2 = 16; diff --git a/Calibration/HcalCalibAlgos/macros/CalibFitPlots.C b/Calibration/HcalCalibAlgos/macros/CalibFitPlots.C index eb5b946cc61c1..978e23e765615 100644 --- a/Calibration/HcalCalibAlgos/macros/CalibFitPlots.C +++ b/Calibration/HcalCalibAlgos/macros/CalibFitPlots.C @@ -872,7 +872,7 @@ void FitHistExtended(const char* infile, fitLanGau(hist3, debug); hists.push_back(hist3); } - // results meaner0 = fitTwoGauss(hist, debug); + // results meaner0 = fitTwoGauss(hist, debug); results meaner0 = fitOneGauss(hist, true, debug); value = meaner0.mean; error = meaner0.errmean; diff --git a/Calibration/HcalCalibAlgos/macros/CalibMonitor.C b/Calibration/HcalCalibAlgos/macros/CalibMonitor.C index 46082e1f5e7ff..b0b195de9c0cb 100644 --- a/Calibration/HcalCalibAlgos/macros/CalibMonitor.C +++ b/Calibration/HcalCalibAlgos/macros/CalibMonitor.C @@ -1640,11 +1640,11 @@ void GetEntries::Init(TTree *tree, const char *dupFileName) { std::cout << "Cannot open " << dupFileName << std::endl; } else { while (1) { - Long64_t jentry; - infile >> jentry; - if (!infile.good()) - break; - entries_.push_back(jentry); + Long64_t jentry; + infile >> jentry; + if (!infile.good()) + break; + entries_.push_back(jentry); } infile.close(); std::cout << "Reads a list of " << entries_.size() << " events from " << dupFileName << std::endl; diff --git a/Calibration/HcalCalibAlgos/macros/CalibPlotProperties.C b/Calibration/HcalCalibAlgos/macros/CalibPlotProperties.C index 06334dbdf1181..7bd998ac64ecb 100644 --- a/Calibration/HcalCalibAlgos/macros/CalibPlotProperties.C +++ b/Calibration/HcalCalibAlgos/macros/CalibPlotProperties.C @@ -493,11 +493,11 @@ void CalibPlotProperties::Init(TChain *tree, const char *dupFileName) { std::cout << "Cannot open duplicate file " << dupFileName << std::endl; } else { while (1) { - Long64_t jentry; - infil1 >> jentry; - if (!infil1.good()) - break; - entries_.push_back(jentry); + Long64_t jentry; + infil1 >> jentry; + if (!infil1.good()) + break; + entries_.push_back(jentry); } infil1.close(); std::cout << "Reads a list of " << entries_.size() << " events from " << dupFileName << std::endl; diff --git a/Calibration/HcalCalibAlgos/macros/CalibRho.C b/Calibration/HcalCalibAlgos/macros/CalibRho.C index c670d7136f49b..dff047355ca98 100644 --- a/Calibration/HcalCalibAlgos/macros/CalibRho.C +++ b/Calibration/HcalCalibAlgos/macros/CalibRho.C @@ -3,7 +3,7 @@ // Usage: // .L CalibRho.C+g // -// EHcalVsRho c1(inpFilName, dupFileName); +// EHcalVsRho c1(inpFilName, dupFileName); // c1.LoopFill(maxEta, outFile1, logFile); Fills E vs rho plots // FitEvsRho(logFile, parameterFile, outFile2); Fits the area vs iEta // c1.LoopTest(maxEta, parameterFile, rootFile); Makes the corrected histos @@ -13,7 +13,7 @@ // inpFileName (const char*) File name of the input ROOT tree // or name of the file containing a list of // file names of input ROOT trees -// dupFileName (const char*) Name of the file containing list of entries +// dupFileName (const char*) Name of the file containing list of entries // of duplicate events // maxEta (int) Maximum value of |iEta| // outFile1 (const char*) Output ROOT file name which will contain the @@ -21,7 +21,7 @@ // will provide the estimate of "effective area" // logFile (const char*) Name of the text file which will contain the // effective area for each ieta value -// parameterFile (const char*) Name of the text file with values of the +// parameterFile (const char*) Name of the text file with values of the // fitted parameter set // outFile2 (const char*) Name of the ROOT file with the results of // the fit @@ -60,139 +60,140 @@ #include "CalibCorr.C" class EHcalVsRho { -public : - TChain *fChain; //!pointer to the analyzed TTree or TChain - Int_t fCurrent; //!current Tree number in a TChain - +public: + TChain *fChain; //!pointer to the analyzed TTree or TChain + Int_t fCurrent; //!current Tree number in a TChain + EHcalVsRho(const char *inFile, const char *dupFile); virtual ~EHcalVsRho(); - virtual Int_t Cut(Long64_t entry); - virtual Int_t GetEntry(Long64_t entry); + virtual Int_t Cut(Long64_t entry); + virtual Int_t GetEntry(Long64_t entry); virtual Long64_t LoadTree(Long64_t entry); - virtual void Init(TChain *tree, const char* dupFile); - virtual Bool_t Notify(); - virtual void Show(Long64_t entry = -1); - void LoopFill(int maxEta, const char *outFile, const char *logFile); - void LoopTest(int maxEta, const char *inFile, const char *outFile); - double EffCalc(TH1D*, double, double&, double&); - double getEA(const int ieta, const double* par); + virtual void Init(TChain *tree, const char *dupFile); + virtual Bool_t Notify(); + virtual void Show(Long64_t entry = -1); + void LoopFill(int maxEta, const char *outFile, const char *logFile); + void LoopTest(int maxEta, const char *inFile, const char *outFile); + double EffCalc(TH1D *, double, double &, double &); + double getEA(const int ieta, const double *par); private: - // Declaration of leaf types - Int_t t_Run; - Int_t t_Event; - Int_t t_DataType; - Int_t t_ieta; - Int_t t_iphi; - Double_t t_EventWeight; - Int_t t_nVtx; - Int_t t_nTrk; - Int_t t_goodPV; - Double_t t_l1pt; - Double_t t_l1eta; - Double_t t_l1phi; - Double_t t_l3pt; - Double_t t_l3eta; - Double_t t_l3phi; - Double_t t_p; - Double_t t_pt; - Double_t t_phi; - Double_t t_mindR1; - Double_t t_mindR2; - Double_t t_eMipDR; - Double_t t_eHcal; - Double_t t_eHcal10; - Double_t t_eHcal30; - Double_t t_hmaxNearP; - Double_t t_rhoh; - Bool_t t_selectTk; - Bool_t t_qltyFlag; - Bool_t t_qltyMissFlag; - Bool_t t_qltyPVFlag; - Double_t t_gentrackP; + Int_t t_Run; + Int_t t_Event; + Int_t t_DataType; + Int_t t_ieta; + Int_t t_iphi; + Double_t t_EventWeight; + Int_t t_nVtx; + Int_t t_nTrk; + Int_t t_goodPV; + Double_t t_l1pt; + Double_t t_l1eta; + Double_t t_l1phi; + Double_t t_l3pt; + Double_t t_l3eta; + Double_t t_l3phi; + Double_t t_p; + Double_t t_pt; + Double_t t_phi; + Double_t t_mindR1; + Double_t t_mindR2; + Double_t t_eMipDR; + Double_t t_eHcal; + Double_t t_eHcal10; + Double_t t_eHcal30; + Double_t t_hmaxNearP; + Double_t t_rhoh; + Bool_t t_selectTk; + Bool_t t_qltyFlag; + Bool_t t_qltyMissFlag; + Bool_t t_qltyPVFlag; + Double_t t_gentrackP; std::vector *t_DetIds; - std::vector *t_HitEnergies; - std::vector *t_trgbits; + std::vector *t_HitEnergies; + std::vector *t_trgbits; std::vector *t_DetIds1; std::vector *t_DetIds3; - std::vector *t_HitEnergies1; - std::vector *t_HitEnergies3; - + std::vector *t_HitEnergies1; + std::vector *t_HitEnergies3; + // List of branches - TBranch *b_t_Run; //! - TBranch *b_t_Event; //! - TBranch *b_t_DataType; //! - TBranch *b_t_ieta; //! - TBranch *b_t_iphi; //! - TBranch *b_t_EventWeight; //! - TBranch *b_t_nVtx; //! - TBranch *b_t_nTrk; //! - TBranch *b_t_goodPV; //! - TBranch *b_t_l1pt; //! - TBranch *b_t_l1eta; //! - TBranch *b_t_l1phi; //! - TBranch *b_t_l3pt; //! - TBranch *b_t_l3eta; //! - TBranch *b_t_l3phi; //! - TBranch *b_t_p; //! - TBranch *b_t_pt; //! - TBranch *b_t_phi; //! - TBranch *b_t_mindR1; //! - TBranch *b_t_mindR2; //! - TBranch *b_t_eMipDR; //! - TBranch *b_t_eHcal; //! - TBranch *b_t_eHcal10; //! - TBranch *b_t_eHcal30; //! - TBranch *b_t_hmaxNearP; //! - TBranch *b_t_rhoh; //! - TBranch *b_t_selectTk; //! - TBranch *b_t_qltyFlag; //! - TBranch *b_t_qltyMissFlag; //! - TBranch *b_t_qltyPVFlag; //! - TBranch *b_t_gentrackP; //! - TBranch *b_t_DetIds; //! - TBranch *b_t_HitEnergies; //! - TBranch *b_t_trgbits; //! - TBranch *b_t_DetIds1; //! - TBranch *b_t_DetIds3; //! - TBranch *b_t_HitEnergies1; //! - TBranch *b_t_HitEnergies3; //! - - std::vector entries_; + TBranch *b_t_Run; //! + TBranch *b_t_Event; //! + TBranch *b_t_DataType; //! + TBranch *b_t_ieta; //! + TBranch *b_t_iphi; //! + TBranch *b_t_EventWeight; //! + TBranch *b_t_nVtx; //! + TBranch *b_t_nTrk; //! + TBranch *b_t_goodPV; //! + TBranch *b_t_l1pt; //! + TBranch *b_t_l1eta; //! + TBranch *b_t_l1phi; //! + TBranch *b_t_l3pt; //! + TBranch *b_t_l3eta; //! + TBranch *b_t_l3phi; //! + TBranch *b_t_p; //! + TBranch *b_t_pt; //! + TBranch *b_t_phi; //! + TBranch *b_t_mindR1; //! + TBranch *b_t_mindR2; //! + TBranch *b_t_eMipDR; //! + TBranch *b_t_eHcal; //! + TBranch *b_t_eHcal10; //! + TBranch *b_t_eHcal30; //! + TBranch *b_t_hmaxNearP; //! + TBranch *b_t_rhoh; //! + TBranch *b_t_selectTk; //! + TBranch *b_t_qltyFlag; //! + TBranch *b_t_qltyMissFlag; //! + TBranch *b_t_qltyPVFlag; //! + TBranch *b_t_gentrackP; //! + TBranch *b_t_DetIds; //! + TBranch *b_t_HitEnergies; //! + TBranch *b_t_trgbits; //! + TBranch *b_t_DetIds1; //! + TBranch *b_t_DetIds3; //! + TBranch *b_t_HitEnergies1; //! + TBranch *b_t_HitEnergies3; //! + + std::vector entries_; }; EHcalVsRho::EHcalVsRho(const char *inFile, const char *dupFile) : fChain(0) { char treeName[400]; - sprintf (treeName, "HcalIsoTrkAnalyzer/CalibTree"); - TChain *chain = new TChain(treeName); - std::cout << "Create a chain for " << treeName << " from " << inFile - << std::endl; - if (!fillChain(chain,inFile)) { + sprintf(treeName, "HcalIsoTrkAnalyzer/CalibTree"); + TChain *chain = new TChain(treeName); + std::cout << "Create a chain for " << treeName << " from " << inFile << std::endl; + if (!fillChain(chain, inFile)) { std::cout << "*****No valid tree chain can be obtained*****" << std::endl; } else { - std::cout << "Proceed with a tree chain with " << chain->GetEntries() - << " entries" << std::endl; + std::cout << "Proceed with a tree chain with " << chain->GetEntries() << " entries" << std::endl; Init(chain, dupFile); } } EHcalVsRho::~EHcalVsRho() { - if (!fChain) return; + if (!fChain) + return; delete fChain->GetCurrentFile(); } Int_t EHcalVsRho::GetEntry(Long64_t entry) { // Read contents of entry. - if (!fChain) return 0; + if (!fChain) + return 0; return fChain->GetEntry(entry); } Long64_t EHcalVsRho::LoadTree(Long64_t entry) { // Set the environment to read one entry - if (!fChain) return -5; + if (!fChain) + return -5; Long64_t centry = fChain->LoadTree(entry); - if (centry < 0) return centry; + if (centry < 0) + return centry; if (fChain->GetTreeNumber() != fCurrent) { fCurrent = fChain->GetTreeNumber(); Notify(); @@ -200,7 +201,7 @@ Long64_t EHcalVsRho::LoadTree(Long64_t entry) { return centry; } -void EHcalVsRho::Init(TChain *tree, const char* dupFile) { +void EHcalVsRho::Init(TChain *tree, const char *dupFile) { // The Init() function is called when the selector needs to initialize // a new tree or chain. Typically here the branch addresses and branch // pointers of the tree will be set. @@ -208,7 +209,7 @@ void EHcalVsRho::Init(TChain *tree, const char* dupFile) { // code, but the routine can be extended by the user if needed. // Init() will be called many times when running on PROOF // (once per file to be processed). - + // Set object pointer t_DetIds = 0; t_HitEnergies = 0; @@ -218,7 +219,8 @@ void EHcalVsRho::Init(TChain *tree, const char* dupFile) { t_HitEnergies1 = 0; t_HitEnergies3 = 0; // Set branch addresses and branch pointers - if (!tree) return; + if (!tree) + return; fChain = tree; fCurrent = -1; fChain->SetMakeClass(1); @@ -269,14 +271,14 @@ void EHcalVsRho::Init(TChain *tree, const char* dupFile) { std::cout << "Cannot open " << dupFile << std::endl; } else { while (1) { - Long64_t jentry; - infile >> jentry; - if (!infile.good()) break; - entries_.push_back(jentry); + Long64_t jentry; + infile >> jentry; + if (!infile.good()) + break; + entries_.push_back(jentry); } infile.close(); - std::cout << "Reads a list of " << entries_.size() << " events from " - << dupFile << std::endl; + std::cout << "Reads a list of " << entries_.size() << " events from " << dupFile << std::endl; } } } @@ -294,7 +296,8 @@ Bool_t EHcalVsRho::Notify() { void EHcalVsRho::Show(Long64_t entry) { // Print contents of entry. // If entry is not specified, print current entry - if (!fChain) return; + if (!fChain) + return; fChain->Show(entry); } @@ -305,172 +308,183 @@ Int_t EHcalVsRho::Cut(Long64_t) { return 1; } -void EHcalVsRho::LoopFill(int maxEta, const char *outFile, const char *logFile){ - if (fChain == 0) return; - TFile *f1 = new TFile(outFile,"RECREATE"); +void EHcalVsRho::LoopFill(int maxEta, const char *outFile, const char *logFile) { + if (fChain == 0) + return; + TFile *f1 = new TFile(outFile, "RECREATE"); char name[100], Title[100], graph[100], proji[100]; - - std::vector VIsoRho; - std::vector Hcal_corr; - for (int ieta = 0; ieta VIsoRho; + std::vector Hcal_corr; + for (int ieta = 0; ieta < maxEta; ieta++) { + sprintf(name, "IsoRho2d%d", ieta + 1); + sprintf(Title, "Iso vs Rho %d", ieta + 1); + VIsoRho.push_back(new TH2D(name, Title, 30, 0, 30, 25000, 0, 250)); + sprintf(name, "IsoRhoProfile%d", ieta + 1); + Hcal_corr.push_back(new TProfile(name, Title, 30, 0, 30)); } Long64_t nentries = fChain->GetEntriesFast(); std::cout << "Total # of entries: " << nentries << std::endl; Long64_t nbytes = 0, nb = 0; Long64_t kount(0), duplicate(0), good(0); - for (Long64_t jentry=0; jentryGetEntry(jentry); nbytes += nb; + if (ientry < 0) + break; + nb = fChain->GetEntry(jentry); + nbytes += nb; ++kount; - if (kount%100000 == 0) std::cout << "Processing Entry " << kount<=40) && (t_p<=60)) { - VIsoRho[absIeta-1]->Fill(t_rhoh,t_eHcal); - Hcal_corr[absIeta-1]->Fill(t_rhoh,t_eHcal); + if ((absIeta <= maxEta) && (t_p >= 40) && (t_p <= 60)) { + VIsoRho[absIeta - 1]->Fill(t_rhoh, t_eHcal); + Hcal_corr[absIeta - 1]->Fill(t_rhoh, t_eHcal); ++good; } } - std::cout << "Uses " << good << " events out of " << kount << " excluding " - << duplicate << " duplicate events" << std::endl; - - gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite); - gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite); - gStyle->SetOptTitle(0); gStyle->SetOptFit(1); + std::cout << "Uses " << good << " events out of " << kount << " excluding " << duplicate << " duplicate events" + << std::endl; + + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(kWhite); + gStyle->SetPadColor(kWhite); + gStyle->SetFillColor(kWhite); + gStyle->SetOptTitle(0); + gStyle->SetOptFit(1); std::ofstream myfile; myfile.open(logFile); - for (int ieta=0; ietaWrite(); Hcal_corr[ieta]->Write(); - TH2D *his_i = dynamic_cast(VIsoRho[ieta]->Clone()); - his_i ->GetEntries(); + TH2D *his_i = dynamic_cast(VIsoRho[ieta]->Clone()); + his_i->GetEntries(); int dim = his_i->GetXaxis()->GetNbins(); double *xcut, *binc, *errXL, *errXH, *errYL, *errYH; double *errX, *errY; - double errX1, errX2, xmax(0); - - xcut = new double[dim]; - binc = new double[dim]; - errX = new double[dim]; - errY = new double[dim]; - errXL = new double[dim]; - errXH = new double[dim]; - errYL = new double[dim]; - errYH = new double[dim]; - - for (int j= 0; j < dim; j++) { - sprintf (proji,"proj%d-%d",ieta+1,j); - TH1D* h_proj = dynamic_cast(his_i->ProjectionY(proji,j,j+1," ")); - binc[j] = his_i->GetXaxis()->GetBinCenter(j+1); - xcut[j] = EffCalc(h_proj,0.90,errX1,errX2); - - errXL[j]=0.0; - errXH[j]=0.0; - errYL[j]=errX1; - errYH[j]=errX2; - - errX[j]=0.0; - errY[j]=0.0; + double errX1, errX2, xmax(0); + + xcut = new double[dim]; + binc = new double[dim]; + errX = new double[dim]; + errY = new double[dim]; + errXL = new double[dim]; + errXH = new double[dim]; + errYL = new double[dim]; + errYH = new double[dim]; + + for (int j = 0; j < dim; j++) { + sprintf(proji, "proj%d-%d", ieta + 1, j); + TH1D *h_proj = dynamic_cast(his_i->ProjectionY(proji, j, j + 1, " ")); + binc[j] = his_i->GetXaxis()->GetBinCenter(j + 1); + xcut[j] = EffCalc(h_proj, 0.90, errX1, errX2); + + errXL[j] = 0.0; + errXH[j] = 0.0; + errYL[j] = errX1; + errYH[j] = errX2; + + errX[j] = 0.0; + errY[j] = 0.0; h_proj->Write(); - if (xcut[j] > xmax) xmax = xcut[j]; + if (xcut[j] > xmax) + xmax = xcut[j]; } - TGraphAsymmErrors * Isovsrho = new TGraphAsymmErrors(dim,binc,xcut,errXL,errXH,errYL,errYH); - sprintf(graph,"IsovsRho%d",ieta+1); - sprintf(name,"EvsRho%d",ieta+1); + TGraphAsymmErrors *Isovsrho = new TGraphAsymmErrors(dim, binc, xcut, errXL, errXH, errYL, errYH); + sprintf(graph, "IsovsRho%d", ieta + 1); + sprintf(name, "EvsRho%d", ieta + 1); - TF1 *fnc = new TF1("fnc","[1]*x + [0]",4,13); - TFitResultPtr fitI = Isovsrho->Fit("fnc","+QSR"); + TF1 *fnc = new TF1("fnc", "[1]*x + [0]", 4, 13); + TFitResultPtr fitI = Isovsrho->Fit("fnc", "+QSR"); double ic = fnc->GetParameter(1); double err = fitI->FitResult::Error(1); - myfile << ieta+1 << " " << ic << " " << err << std::endl; - std::cout << "Fit " << ieta+1 << " " << fnc->GetParameter(0) << " " - << fitI->FitResult::Error(0) << " " << ic << " " << err << "\n"; + myfile << ieta + 1 << " " << ic << " " << err << std::endl; + std::cout << "Fit " << ieta + 1 << " " << fnc->GetParameter(0) << " " << fitI->FitResult::Error(0) << " " << ic + << " " << err << "\n"; gStyle->SetOptFit(1); - TCanvas *pad = new TCanvas(graph,name,0,10,1200,400); + TCanvas *pad = new TCanvas(graph, name, 0, 10, 1200, 400); pad->SetRightMargin(0.10); pad->SetTopMargin(0.10); Isovsrho->SetMarkerStyle(24); Isovsrho->SetMarkerSize(0.4); - Isovsrho->GetXaxis()->SetRangeUser(0,15); + Isovsrho->GetXaxis()->SetRangeUser(0, 15); Isovsrho->GetXaxis()->SetTitle("#rho"); Isovsrho->GetXaxis()->SetLabelSize(0.04); Isovsrho->GetXaxis()->SetTitleSize(0.06); Isovsrho->GetXaxis()->SetTitleOffset(0.8); - Isovsrho->GetYaxis()->SetRangeUser(0,1.25*xmax); + Isovsrho->GetYaxis()->SetRangeUser(0, 1.25 * xmax); Isovsrho->GetYaxis()->SetTitle("Energy (GeV)"); Isovsrho->GetYaxis()->SetLabelSize(0.04); Isovsrho->GetYaxis()->SetTitleSize(0.06); Isovsrho->GetYaxis()->SetTitleOffset(0.6); Isovsrho->Draw("AP"); pad->Update(); - TPaveStats* st1 = (TPaveStats*)Isovsrho->GetListOfFunctions()->FindObject("stats"); + TPaveStats *st1 = (TPaveStats *)Isovsrho->GetListOfFunctions()->FindObject("stats"); if (st1 != nullptr) { - st1->SetY1NDC(0.78); st1->SetY2NDC(0.90); - st1->SetX1NDC(0.65); st1->SetX2NDC(0.90); + st1->SetY1NDC(0.78); + st1->SetY2NDC(0.90); + st1->SetX1NDC(0.65); + st1->SetX2NDC(0.90); } pad->Write(); } myfile.close(); f1->Close(); -} - -double EHcalVsRho::EffCalc(TH1D* h, double perc, double & errXL, - double & errXH) { - double eff, eff_err=0.0, xCut=0.0; +} + +double EHcalVsRho::EffCalc(TH1D *h, double perc, double &errXL, double &errXH) { + double eff, eff_err = 0.0, xCut = 0.0; int tot = h->GetEntries(); int integ = 0; errXL = 0.0; errXH = 0.0; - for(int i = 0; i < (h->GetXaxis()->GetNbins()+1 ); i++) { + for (int i = 0; i < (h->GetXaxis()->GetNbins() + 1); i++) { xCut = h->GetXaxis()->GetBinLowEdge(i); integ += h->GetBinContent(i); - - if (integ != 0 && tot != 0 ) { - eff = (integ*1.0/tot); - eff_err = sqrt ( eff * ( 1 - eff ) / tot ) ; + + if (integ != 0 && tot != 0) { + eff = (integ * 1.0 / tot); + eff_err = sqrt(eff * (1 - eff) / tot); } else { eff = 0.0; } - if (eff > perc) break; + if (eff > perc) + break; } - if (eff == 0.0) xCut = 0.0; + if (eff == 0.0) + xCut = 0.0; errXL = eff_err; errXH = eff_err; return xCut; } void EHcalVsRho::LoopTest(int maxEta, const char *inFile, const char *outFile) { + if (fChain == 0) + return; - if (fChain == 0) return; - - TFile *f1 = new TFile(outFile,"RECREATE"); - std::map histo, histo_uncorr; + TFile *f1 = new TFile(outFile, "RECREATE"); + std::map histo, histo_uncorr; char name[100], title[100]; - for (int ieta =-maxEta; ieta<=maxEta; ieta++) { - sprintf(name, "MPV%d",ieta); - sprintf(title, "Corrected Response (i#eta = %d)", ieta-30); - histo[ieta] = new TH1D(name, title, 100, 0, 2); - sprintf(name, "MPVUn%d",ieta); - sprintf(title, "Uncorrected Response (i#eta = %d)", ieta-30); + for (int ieta = -maxEta; ieta <= maxEta; ieta++) { + sprintf(name, "MPV%d", ieta); + sprintf(title, "Corrected Response (i#eta = %d)", ieta - 30); + histo[ieta] = new TH1D(name, title, 100, 0, 2); + sprintf(name, "MPVUn%d", ieta); + sprintf(title, "Uncorrected Response (i#eta = %d)", ieta - 30); histo_uncorr[ieta] = new TH1D(name, title, 100, 0, 2); } - std::cout << "Initialized histograms from " << -maxEta << ":" << maxEta<<"\n"; - + std::cout << "Initialized histograms from " << -maxEta << ":" << maxEta << "\n"; + double par[10]; ifstream myReadFile; myReadFile.open(inFile); @@ -483,64 +497,66 @@ void EHcalVsRho::LoopTest(int maxEta, const char *inFile, const char *outFile) { } myReadFile.close(); std::cout << "Reads " << npar << " parameters:"; - for (int k=0; k 40) && (t_p < 60.0)); - if (select) { + + select = ((t_qltyFlag) && (t_selectTk) && (t_hmaxNearP < 10.0) && (t_eMipDR < 1.0) && (t_p > 40) && (t_p < 60.0)); + if (select) { double corr_eHcal = 0.0; int absIeta = abs(t_ieta); ++good; if (absIeta <= maxEta) { - corr_eHcal = t_eHcal - t_rhoh*getEA(absIeta,par); - double myEovP = corr_eHcal/(t_p-t_eMipDR); - double myEovP_uncorr = t_eHcal/(t_p-t_eMipDR); - histo[t_ieta]->Fill(myEovP); - histo_uncorr[t_ieta]->Fill(myEovP_uncorr); + corr_eHcal = t_eHcal - t_rhoh * getEA(absIeta, par); + double myEovP = corr_eHcal / (t_p - t_eMipDR); + double myEovP_uncorr = t_eHcal / (t_p - t_eMipDR); + histo[t_ieta]->Fill(myEovP); + histo_uncorr[t_ieta]->Fill(myEovP_uncorr); } } } - for (std::map::iterator itr=histo.begin(); - itr != histo.end(); ++itr) itr->second->Write(); - for (std::map::iterator itr=histo_uncorr.begin(); - itr != histo_uncorr.end(); ++itr) itr->second->Write(); + for (std::map::iterator itr = histo.begin(); itr != histo.end(); ++itr) + itr->second->Write(); + for (std::map::iterator itr = histo_uncorr.begin(); itr != histo_uncorr.end(); ++itr) + itr->second->Write(); f1->Close(); - std::cout << "Processes " << good << " out of " << kount << " events with " - << duplicate << " duplicate entries" << std::endl; + std::cout << "Processes " << good << " out of " << kount << " events with " << duplicate << " duplicate entries" + << std::endl; } -double EHcalVsRho::getEA(const int eta, const double* par) { +double EHcalVsRho::getEA(const int eta, const double *par) { double eA; - if (eta<20) + if (eta < 20) eA = par[0]; - else - eA = (((par[5]*eta+par[4])*eta+par[3])*eta+par[2])*eta+par[1]; + else + eA = (((par[5] * eta + par[4]) * eta + par[3]) * eta + par[2]) * eta + par[1]; return eA; } void FitEvsRho(const char *inFile, const char *outFile, const char *rootFile) { - - const int ndim=30; + const int ndim = 30; double EA[ndim] = {0.0}; - double errEA[ndim]={0.0}; - double ietaEA[ndim]={0.0}; + double errEA[ndim] = {0.0}; + double ietaEA[ndim] = {0.0}; ifstream myReadFile; myReadFile.open(inFile); @@ -548,20 +564,25 @@ void FitEvsRho(const char *inFile, const char *outFile, const char *rootFile) { if (myReadFile.is_open()) { while (!myReadFile.eof()) { myReadFile >> ietaEA[ii] >> EA[ii] >> errEA[ii]; - if (EA[ii] < 0) EA[ii] = 0; + if (EA[ii] < 0) + EA[ii] = 0; ii++; } } myReadFile.close(); std::cout << "Reads " << ii << " points from " << inFile << std::endl; - gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite); - gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite); - gStyle->SetOptTitle(0); gStyle->SetOptStat(0); + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(kWhite); + gStyle->SetPadColor(kWhite); + gStyle->SetFillColor(kWhite); + gStyle->SetOptTitle(0); + gStyle->SetOptStat(0); gStyle->SetOptFit(0); - TFile *f1 = new TFile(rootFile,"RECREATE"); - TGraphErrors * eA = new TGraphErrors(ii,ietaEA,EA,errEA,errEA); - eA->SetMarkerStyle(20); eA->SetMarkerColor(4); + TFile *f1 = new TFile(rootFile, "RECREATE"); + TGraphErrors *eA = new TGraphErrors(ii, ietaEA, EA, errEA, errEA); + eA->SetMarkerStyle(20); + eA->SetMarkerColor(4); eA->SetLineColor(2); eA->GetXaxis()->SetTitle("i#eta"); eA->GetXaxis()->SetTitleOffset(0.6); @@ -570,24 +591,24 @@ void FitEvsRho(const char *inFile, const char *outFile, const char *rootFile) { eA->GetYaxis()->SetTitleOffset(0.6); eA->GetYaxis()->SetTitleSize(0.06); - Double_t par[6]; - const int nmid=19; - TF1 *g1 = new TF1("g1","pol0",1,nmid); - TF1 *g2 = new TF1("g2","pol4",nmid,ii); + Double_t par[6]; + const int nmid = 19; + TF1 *g1 = new TF1("g1", "pol0", 1, nmid); + TF1 *g2 = new TF1("g2", "pol4", nmid, ii); - eA->Fit(g1,"R"); - eA->Fit(g2,"R+"); + eA->Fit(g1, "R"); + eA->Fit(g2, "R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[1]); - TCanvas *c2 = new TCanvas("EA vs #eta","EA vs ieta",0,10,1200,400); + TCanvas *c2 = new TCanvas("EA vs #eta", "EA vs ieta", 0, 10, 1200, 400); eA->Draw("AP"); c2->Write(); f1->Close(); - + ofstream params; params.open(outFile); - for (int i=0; i<6; i++) { + for (int i = 0; i < 6; i++) { params << par[i] << std::endl; std::cout << "Parameter[" << i << "] = " << par[i] << std::endl; } @@ -595,89 +616,96 @@ void FitEvsRho(const char *inFile, const char *outFile, const char *rootFile) { } void FitEovPwithRho(int maxEta, const char *inFile, const char *outFile) { - TFile *file = new TFile(inFile); - std::map histo, histo_uncorr; + std::map histo, histo_uncorr; char name[100]; - for (int ieta =-maxEta; ieta<=maxEta; ieta++) { - sprintf(name, "MPV%d",ieta); - TH1D* h0 = (TH1D*)file->FindObjectAny(name); - histo[ieta] = (h0 != 0) ? (TH1D*)(h0->Clone()) : 0; - sprintf(name, "MPVUn%d",ieta); - TH1D* h1 = (TH1D*)file->FindObjectAny(name); - histo_uncorr[ieta] = (h1 != 0) ? (TH1D*)(h1->Clone()) : 0; + for (int ieta = -maxEta; ieta <= maxEta; ieta++) { + sprintf(name, "MPV%d", ieta); + TH1D *h0 = (TH1D *)file->FindObjectAny(name); + histo[ieta] = (h0 != 0) ? (TH1D *)(h0->Clone()) : 0; + sprintf(name, "MPVUn%d", ieta); + TH1D *h1 = (TH1D *)file->FindObjectAny(name); + histo_uncorr[ieta] = (h1 != 0) ? (TH1D *)(h1->Clone()) : 0; } - -//TFile *f1 = - new TFile(outFile,"RECREATE"); + + //TFile *f1 = + new TFile(outFile, "RECREATE"); double xlim = maxEta + 0.5; - TH1D* EovPvsieta = new TH1D("Corrected","Corrected",2*maxEta+1,-xlim,xlim); - TH1D* EovPvsieta_uncorr = new TH1D("Uncorrect","Uncorrect",2*maxEta+1,-xlim,xlim); + TH1D *EovPvsieta = new TH1D("Corrected", "Corrected", 2 * maxEta + 1, -xlim, xlim); + TH1D *EovPvsieta_uncorr = new TH1D("Uncorrect", "Uncorrect", 2 * maxEta + 1, -xlim, xlim); - TF1* fnc = new TF1("fnc","gaus"); + TF1 *fnc = new TF1("fnc", "gaus"); unsigned int k1(0), k2(0); - for (int ieta=-maxEta; ieta<=maxEta; ieta++) { - if (ieta == 0) continue; + for (int ieta = -maxEta; ieta <= maxEta; ieta++) { + if (ieta == 0) + continue; if (histo[ieta] != 0) { double mean = histo[ieta]->GetMean(); - double rms = histo[ieta]->GetRMS(); - TFitResultPtr FitG = histo[ieta]->Fit("fnc","QRWLS","",mean-rms,mean+rms); - double a = fnc->GetParameter(1); + double rms = histo[ieta]->GetRMS(); + TFitResultPtr FitG = histo[ieta]->Fit("fnc", "QRWLS", "", mean - rms, mean + rms); + double a = fnc->GetParameter(1); double err = FitG->FitResult::Error(1); histo[ieta]->Write(); ++k1; - int ibin = ieta+maxEta+1; - EovPvsieta->SetBinContent(ibin,a); - EovPvsieta->SetBinError(ibin,err); - std::cout << "Correct[" << k1 << "] " << ieta << " a " << a << " +- " - << err << std::endl; + int ibin = ieta + maxEta + 1; + EovPvsieta->SetBinContent(ibin, a); + EovPvsieta->SetBinError(ibin, err); + std::cout << "Correct[" << k1 << "] " << ieta << " a " << a << " +- " << err << std::endl; } - + if (histo_uncorr[ieta] != 0) { double mean = histo_uncorr[ieta]->GetMean(); - double rms = histo_uncorr[ieta]->GetRMS(); - TFitResultPtr FitG = histo_uncorr[ieta]->Fit("fnc","QRWLS","",mean-rms,mean+rms); - double a = fnc->GetParameter(1); + double rms = histo_uncorr[ieta]->GetRMS(); + TFitResultPtr FitG = histo_uncorr[ieta]->Fit("fnc", "QRWLS", "", mean - rms, mean + rms); + double a = fnc->GetParameter(1); double err = FitG->FitResult::Error(1); histo_uncorr[ieta]->Write(); ++k2; - int ibin = ieta+maxEta+1; - EovPvsieta_uncorr->SetBinContent(ibin,a); - EovPvsieta_uncorr->SetBinError(ibin,err); - std::cout << "Correct[" << k2 << "] " << ieta << " a " << a << " +- " - << err << std::endl; + int ibin = ieta + maxEta + 1; + EovPvsieta_uncorr->SetBinContent(ibin, a); + EovPvsieta_uncorr->SetBinError(ibin, err); + std::cout << "Correct[" << k2 << "] " << ieta << " a " << a << " +- " << err << std::endl; } } - gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite); - gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite); + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(kWhite); + gStyle->SetPadColor(kWhite); + gStyle->SetFillColor(kWhite); gStyle->SetOptTitle(0); - gStyle->SetOptStat(10); gStyle->SetOptFit(1); - TCanvas *c3 = new TCanvas("E/P vs ieta","E/P vs ieta",0,10,1200,400); + gStyle->SetOptStat(10); + gStyle->SetOptFit(1); + TCanvas *c3 = new TCanvas("E/P vs ieta", "E/P vs ieta", 0, 10, 1200, 400); EovPvsieta->GetXaxis()->SetTitle("i#eta"); EovPvsieta->GetYaxis()->SetTitle("MPV[E_{Hcal}/(p_{Track}-E_{Ecal})]"); - EovPvsieta->SetMarkerStyle(20); EovPvsieta->SetMarkerColor(2); + EovPvsieta->SetMarkerStyle(20); + EovPvsieta->SetMarkerColor(2); EovPvsieta->SetMarkerSize(1.0); - EovPvsieta->Fit("pol0","+QRWLS","",-maxEta,maxEta); + EovPvsieta->Fit("pol0", "+QRWLS", "", -maxEta, maxEta); - EovPvsieta_uncorr->SetMarkerStyle(24); EovPvsieta_uncorr->SetMarkerColor(4); + EovPvsieta_uncorr->SetMarkerStyle(24); + EovPvsieta_uncorr->SetMarkerColor(4); EovPvsieta_uncorr->SetMarkerSize(1.0); - EovPvsieta->GetYaxis()->SetRangeUser(0.5,2.0); + EovPvsieta->GetYaxis()->SetRangeUser(0.5, 2.0); EovPvsieta->Draw(); c3->Update(); - TPaveStats* st1 = (TPaveStats*)EovPvsieta->GetListOfFunctions()->FindObject("stats"); + TPaveStats *st1 = (TPaveStats *)EovPvsieta->GetListOfFunctions()->FindObject("stats"); if (st1 != nullptr) { - st1->SetY1NDC(0.81); st1->SetY2NDC(0.90); - st1->SetX1NDC(0.65); st1->SetX2NDC(0.90); + st1->SetY1NDC(0.81); + st1->SetY2NDC(0.90); + st1->SetX1NDC(0.65); + st1->SetX2NDC(0.90); } EovPvsieta_uncorr->Draw("sames"); c3->Update(); - st1 = (TPaveStats*)EovPvsieta_uncorr->GetListOfFunctions()->FindObject("stats"); + st1 = (TPaveStats *)EovPvsieta_uncorr->GetListOfFunctions()->FindObject("stats"); std::cout << st1 << std::endl; if (st1 != nullptr) { - st1->SetY1NDC(0.78); st1->SetY2NDC(0.81); - st1->SetX1NDC(0.65); st1->SetX2NDC(0.90); + st1->SetY1NDC(0.78); + st1->SetY2NDC(0.81); + st1->SetX1NDC(0.65); + st1->SetX2NDC(0.90); } c3->Modified(); c3->Update(); @@ -685,67 +713,85 @@ void FitEovPwithRho(int maxEta, const char *inFile, const char *outFile) { EovPvsieta_uncorr->Write(); } -void PlotEvsRho(const char* inFile, int eta=0, int type=0, bool save=false) { - - gStyle->SetCanvasBorderMode(0); gStyle->SetCanvasColor(kWhite); - gStyle->SetPadColor(kWhite); gStyle->SetFillColor(kWhite); +void PlotEvsRho(const char *inFile, int eta = 0, int type = 0, bool save = false) { + gStyle->SetCanvasBorderMode(0); + gStyle->SetCanvasColor(kWhite); + gStyle->SetPadColor(kWhite); + gStyle->SetFillColor(kWhite); gStyle->SetOptTitle(0); - gStyle->SetOptStat(1110); gStyle->SetOptFit(10); - + gStyle->SetOptStat(1110); + gStyle->SetOptFit(10); + TFile *file = new TFile(inFile); int etamin = (eta == 0) ? ((type == 0) ? 1 : 25) : eta; int etamax = (eta == 0) ? 25 : eta; for (int it = etamin; it <= etamax; ++it) { char name[50]; - sprintf (name, "IsovsRho%d", it); - TCanvas* pad; + sprintf(name, "IsovsRho%d", it); + TCanvas *pad; if (type == 0) { - pad = (TCanvas*)(file->FindObjectAny(name)); + pad = (TCanvas *)(file->FindObjectAny(name)); pad->Draw(); } else { - sprintf (name, "MPV%d", it); - pad = new TCanvas(name,name,0,10,800,500); + sprintf(name, "MPV%d", it); + pad = new TCanvas(name, name, 0, 10, 800, 500); pad->SetRightMargin(0.10); pad->SetTopMargin(0.10); - TH1D* h1 = (TH1D*)(file->FindObjectAny(name)); - sprintf (name, "MPVUn%d", it); - TH1D* h2 = (TH1D*)(file->FindObjectAny(name)); + TH1D *h1 = (TH1D *)(file->FindObjectAny(name)); + sprintf(name, "MPVUn%d", it); + TH1D *h2 = (TH1D *)(file->FindObjectAny(name)); double ymx1 = h1->GetMaximum(); double ymx2 = h2->GetMaximum(); double ymax = (ymx1 > ymx2) ? ymx1 : ymx2; - h1->GetXaxis()->SetRangeUser(0.5,2.0); - h2->GetXaxis()->SetRangeUser(0.5,2.0); - h1->GetYaxis()->SetRangeUser(0,1.25*ymax); - h2->GetYaxis()->SetRangeUser(0,1.25*ymax); - h1->GetXaxis()->SetTitleSize(0.048); h1->GetXaxis()->SetTitleOffset(0.8); + h1->GetXaxis()->SetRangeUser(0.5, 2.0); + h2->GetXaxis()->SetRangeUser(0.5, 2.0); + h1->GetYaxis()->SetRangeUser(0, 1.25 * ymax); + h2->GetYaxis()->SetRangeUser(0, 1.25 * ymax); + h1->GetXaxis()->SetTitleSize(0.048); + h1->GetXaxis()->SetTitleOffset(0.8); h1->GetXaxis()->SetTitle("E_{Hcal}/(p-E_{Ecal})"); - h1->GetYaxis()->SetTitleSize(0.048); h1->GetYaxis()->SetTitleOffset(0.8); + h1->GetYaxis()->SetTitleSize(0.048); + h1->GetYaxis()->SetTitleOffset(0.8); h1->GetYaxis()->SetTitle("Tracks"); - h1->SetLineColor(2); h1->Draw(); - pad->Modified(); pad->Update(); - TPaveStats* st1 = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats"); + h1->SetLineColor(2); + h1->Draw(); + pad->Modified(); + pad->Update(); + TPaveStats *st1 = (TPaveStats *)h1->GetListOfFunctions()->FindObject("stats"); if (st1 != nullptr) { - st1->SetLineColor(2); st1->SetTextColor(2); - st1->SetY1NDC(0.75); st1->SetY2NDC(0.90); - st1->SetX1NDC(0.65); st1->SetX2NDC(0.90); + st1->SetLineColor(2); + st1->SetTextColor(2); + st1->SetY1NDC(0.75); + st1->SetY2NDC(0.90); + st1->SetX1NDC(0.65); + st1->SetX2NDC(0.90); } - h2->SetLineColor(4); h2->Draw("sames"); - pad->Modified(); pad->Update(); - TPaveStats* st2 = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats"); + h2->SetLineColor(4); + h2->Draw("sames"); + pad->Modified(); + pad->Update(); + TPaveStats *st2 = (TPaveStats *)h2->GetListOfFunctions()->FindObject("stats"); if (st2 != nullptr) { - st2->SetLineColor(4); st2->SetTextColor(4); - st2->SetY1NDC(0.60); st2->SetY2NDC(0.75); - st2->SetX1NDC(0.65); st2->SetX2NDC(0.90); + st2->SetLineColor(4); + st2->SetTextColor(4); + st2->SetY1NDC(0.60); + st2->SetY2NDC(0.75); + st2->SetX1NDC(0.65); + st2->SetX2NDC(0.90); } - pad->Modified(); pad->Update(); - TF1* f1 = (TF1*)h1->GetListOfFunctions()->FindObject("fnc"); - if (f1 != nullptr) f1->SetLineColor(2); - TF1* f2 = (TF1*)h2->GetListOfFunctions()->FindObject("fnc"); - if (f2 != nullptr) f2->SetLineColor(4); - pad->Modified(); pad->Update(); + pad->Modified(); + pad->Update(); + TF1 *f1 = (TF1 *)h1->GetListOfFunctions()->FindObject("fnc"); + if (f1 != nullptr) + f1->SetLineColor(2); + TF1 *f2 = (TF1 *)h2->GetListOfFunctions()->FindObject("fnc"); + if (f2 != nullptr) + f2->SetLineColor(4); + pad->Modified(); + pad->Update(); } if (save) { - sprintf (name, "%s.pdf", pad->GetName()); + sprintf(name, "%s.pdf", pad->GetName()); pad->Print(name); } }