From e92defeb21f745a260d5ff7499956c8e8c0227fe Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:39:03 +0200 Subject: [PATCH 01/19] Update jet_correction_analyzer_x.cc Veto regions for UL 2017 and UL 2018 added and commented out. --- JetAnalyzers/bin/jet_correction_analyzer_x.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/JetAnalyzers/bin/jet_correction_analyzer_x.cc b/JetAnalyzers/bin/jet_correction_analyzer_x.cc index 69453955..6e855588 100644 --- a/JetAnalyzers/bin/jet_correction_analyzer_x.cc +++ b/JetAnalyzers/bin/jet_correction_analyzer_x.cc @@ -18,7 +18,8 @@ #include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h" #include "PhysicsTools/Utilities/interface/LumiReWeighting.h" #if __has_include("xrootd/XrdCl/XrdClFileSystem.hh") -#include "xrootd/XrdCl/XrdClFileSystem.hh" +//#include "xrootd/XrdCl/XrdClFileSystem.hh" +#include "condor/XrdClFileSystem_v2.hh" #define has_xrdcl 1 #else #define has_xrdcl 0 @@ -215,7 +216,7 @@ int main(int argc,char**argv) edm::LumiReWeighting LumiWeights_; if(!MCPUReWeighting.IsNull() && !DataPUReWeighting.IsNull()) { - LumiWeights_ = edm::LumiReWeighting(string(MCPUReWeighting),string(DataPUReWeighting),"pileup","pileup"); + LumiWeights_ = edm::LumiReWeighting(string(MCPUReWeighting),string(DataPUReWeighting),"h_pileup","pileup"); } if(!outputDir.IsNull() && !outputDir.EndsWith("/")) outputDir += "/"; @@ -603,6 +604,13 @@ int main(int argc,char**argv) if(nrefmax>0 && JRAEvt->nref>nrefmax) JRAEvt->nref = nrefmax; for (unsigned char iref=0;irefnref;iref++) { + /* + //=== veto region for UL2017 ======= + //if((JRAEvt->jtphi->at(iref)<-0.5236 && JRAEvt->jtphi->at(iref)>-0.8727 && JRAEvt->jteta->at(iref) >1.31 && JRAEvt->jteta->at(iref)<2.96) || (JRAEvt->jtphi->at(iref)>2.705 && JRAEvt->jtphi->at(iref)<3.1416 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.4835) )continue; + //=== veto region for UL2018 ======= + //if((JRAEvt->jtphi->at(iref)<-0.8727 && JRAEvt->jtphi->at(iref)>-1.5708 && JRAEvt->jteta->at(iref) < -1.31 && JRAEvt->jteta->at(iref)> -2.96) || (JRAEvt->jtphi->at(iref)>0.4363 && JRAEvt->jtphi->at(iref)<0.7854 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.31) )continue; +*/ +// if(JRAEvt->npv>0 && JRAEvt->npv<10){ //nVtx cut starts here float rho = JRAEvt->rho; float rho_hlt = (0!=chain->GetBranch("rho_hlt")) ? JRAEvt->rho_hlt : 0; float ptgen = JRAEvt->refpt->at(iref); @@ -858,6 +866,7 @@ int main(int argc,char**argv) ThetaDistribution ->Fill(theta); SolidAngleDist ->Fill(2*TMath::Pi()*cos(theta)); } +// }//nVtx ends here }//for (unsigned char iref=0;iref Date: Wed, 28 Oct 2020 18:41:07 +0200 Subject: [PATCH 02/19] Update jet_response_analyzer_x.cc Veto regions for UL2017 and UL2018 added and commented out. --- JetAnalyzers/bin/jet_response_analyzer_x.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/JetAnalyzers/bin/jet_response_analyzer_x.cc b/JetAnalyzers/bin/jet_response_analyzer_x.cc index 6f7de9a6..18ee9a63 100644 --- a/JetAnalyzers/bin/jet_response_analyzer_x.cc +++ b/JetAnalyzers/bin/jet_response_analyzer_x.cc @@ -190,7 +190,7 @@ int main(int argc,char**argv) int totaloothigh = cl.getValue ("totaloothigh", 100000); TString weightfile = cl.getValue("weightfile", ""); TString MCPUReWeighting = cl.getValue("MCPUReWeighting", ""); - TString MCPUHistoName = cl.getValue("MCPUHistoName", "pileup"); + TString MCPUHistoName = cl.getValue("MCPUHistoName", "h_pileup"); TString DataPUReWeighting = cl.getValue("DataPUReWeighting", ""); TString DataPUHistoName = cl.getValue("DataPUHistoName","pileup_jt400"); bool verbose = cl.getValue ("verbose", false); @@ -1478,6 +1478,12 @@ int main(int argc,char**argv) if (nrefmax>0) JRAEvt->nref = std::min((int)JRAEvt->nref,nrefmax); for (unsigned char iref=0;irefnref;iref++) { + /* + //=== veto region for UL2017 ======= + //if((JRAEvt->jtphi->at(iref)<-0.5236 && JRAEvt->jtphi->at(iref)>-0.8727 && JRAEvt->jteta->at(iref) >1.31 && JRAEvt->jteta->at(iref)<2.96) || (JRAEvt->jtphi->at(iref)>2.705 && JRAEvt->jtphi->at(iref)<3.1416 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.4835) )continue; + //=== veto region for UL2018 ======= + //if((JRAEvt->jtphi->at(iref)<-0.8727 && JRAEvt->jtphi->at(iref)>-1.5708 && JRAEvt->jteta->at(iref) < -1.31 && JRAEvt->jteta->at(iref)> -2.96) || (JRAEvt->jtphi->at(iref)>0.4363 && JRAEvt->jtphi->at(iref)<0.7854 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.31) )continue; +*/ if(ievt%10000==0 && irefnref-1) cout << "."; else if(ievt%10000==0 && iref==JRAEvt->nref-1) From 697eaa15fd59373d1de394399cfa01688301c1bb Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:44:30 +0200 Subject: [PATCH 03/19] Create jet_match_x.cc This script is necessary for matching jets between the NoPU (or EpsilonPU) and PU files. --- JetAnalyzers/bin/jet_match_x.cc | 1695 +++++++++++++++++++++++++++++++ 1 file changed, 1695 insertions(+) create mode 100644 JetAnalyzers/bin/jet_match_x.cc diff --git a/JetAnalyzers/bin/jet_match_x.cc b/JetAnalyzers/bin/jet_match_x.cc new file mode 100644 index 00000000..051187a9 --- /dev/null +++ b/JetAnalyzers/bin/jet_match_x.cc @@ -0,0 +1,1695 @@ +// ROOT Libraries +#include "TROOT.h" +#include "TSystem.h" +#include "TEnv.h" +#include "TChain.h" +#include "TFile.h" +#include "TChain.h" +#include "TString.h" +#include "TH1D.h" +#include "TH2D.h" +#include "TProfile.h" +#include "TProfile2D.h" +#include "TProfile3D.h" +#include "THnSparse.h" +#include "TBenchmark.h" + +// C++ Libraries +#include +#include +#include +#include + +// JetMETAnalysis Libraries +#include "JetMETAnalysis/JetUtilities/interface/CommandLine.h" +#include "JetMETAnalysis/JetUtilities/interface/JRAEvent.h" +#include "JetMETAnalysis/JetUtilities/interface/JetInfo.hh" +#include "JetMETAnalysis/JetUtilities/interface/EvtID.hh" +#include "JetMETAnalysis/JetUtilities/interface/ProgressBar.hh" + +// CMSSW Libraries +#include "DataFormats/Provenance/interface/RunLumiEventNumber.h" +#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h" +#include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h" +#include "PhysicsTools/Utilities/interface/LumiReWeighting.h" + +using namespace std; + +typedef map > ITJ; + +//////////////////////////////////////////////////////////////////////////////// +// declare class +//////////////////////////////////////////////////////////////////////////////// + +class MatchEventsAndJets { +public: + + MatchEventsAndJets(); + MatchEventsAndJets(string algo1_, string algo2_, bool iftest_); + ~MatchEventsAndJets() {;} + + void getMaxDeltaR(); + double getMaxDeltaR(string algName); + void SetMaxEvts(unsigned me) {maxEvts = me;} + void SetNRefMax(int nrm) {nrefmax = nrm;} + void SetDoNotSaveFlag(bool dns) {doNotSaveFlag = dns;} + void SetPhiRange(double minPhi_, double maxPhi_) {minPhi=minPhi_; maxPhi=maxPhi_;} + void SetWeightParameters(bool useweight_, bool pThatReweight_, double bias2SelectionRef_, double bias2SelectionPow_); + void SetupLumiWeights(string dataFile, string mcFile, string dataHist, string mcHist); + void OpenInputFiles(string filenamePU, string filenameNoPU); + void MakeMatchedEventsMaps(string treeName, string outputPath); + void ConvertEvtMapToVector(const ITS& mapTree, vector& vevtid, vector >& vll); + void ConvertEvtMapToTTree(const ITS& mapTree, TTree* treeMap); + void WriteMatchedEventsMap(string outputPath); + void CreateMatchedEventsMap(ITS& mapTreePU, ITS& mapTreeNoPU); + void ConvertTTreeToMap(ITS& mapTree, TTree* treeMap); + void ReadMatchedEventsMaps(string pathToMaps); + ITS fillMap(bool noPU, string treeName, string outputPath); + void GetNtuples(string treeName = "t"); + void OpenOutputFile(string outputPath = "./"); + void SetJEC(string JECPar = "ParallelMCL1_L1FastJet_AK4PFchs.txt"); + void SetNpvRhoNpuValues(int NBins, int Width) {NBinsNpvRhoNpu=NBins; npvRhoNpuBinWidth=Width;} + void SetVptBins(vector vptb) {vptBins = vptb;} + void DeclareHistograms(bool reduceHistograms); + void LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap, string outputPath); + void FillJetMap(); + void FillRecToRecThroughGenMap(); + bool GetJetMap(string readJetMap); + bool JetMapTreeFound() {return jetMapTreeFound;} + void ReadJetMap(int ientry, string readJetMap); + bool FillHistograms(bool reduceHistograms, IT::const_iterator it); + void RemoveHistograms(bool verbose); + void WriteOutput(string outputPath, bool writeJetMap); + +private: + + //Files + TFile * fpu; + TFile * fnopu; + TFile * fout; + + ofstream eventlist; + + //Algorithms + string algo1; + string algo2; + JetInfo algo1JetInfo; + JetInfo algo2JetInfo; + double maxDeltaR; + + //Ntuples + JRAEvent* tpu; + JRAEvent* tnopu; + + //JEC + bool ApplyJEC; + JetCorrectorParameters* L1JetPar; + vector vPar; + FactorizedJetCorrector* JetCorrector; + + //Maps and items used for looping through jets + // ITS mapTreePU; + // ITS mapTreeNoPU; + ITS mapEventMatch; + + //A map holding the equivalance of jets in two given events + map jetMap; + map histograms; + map hsparse; + //Used for filling the THnSparse + Double_t* fValue; + TTree* jetMapTree; + vector* recoJetIndexPU; + vector* recoJetIndexNoPU; + + + //Loop + vector vptBins; + int nrefmax; + int nevs; + int NBinsNpvRhoNpu; + int npvRhoNpuBinWidth; + int iIT; + int inpv; + int inpv_low; + int inpv_high; + int irho; + int irho_low; + int irho_high; + int itnpu; + int itnpu_low; + int itnpu_high; + int inpu; + int inpu_low; + int inpu_high; + double weight; + bool useweight; + bool pThatReweight; + double bias2SelectionRef; + double bias2SelectionPow; + edm::LumiReWeighting LumiWeights_; + bool LumiWeightsSet_; + bool jetMapTreeFound; + bool doNotSaveFlag; + double minPhi; + double maxPhi; + + //Debug + bool iftest; + int noPUNpvGTOneEventCounter; + unsigned maxEvts; + + double avg_debug; + int entries_debug; + Int_t *bins_debug; +}; + +//////////////////////////////////////////////////////////////////////////////// +// define class +//////////////////////////////////////////////////////////////////////////////// +//______________________________________________________________________________ +MatchEventsAndJets::MatchEventsAndJets() : algo1("ak4pf"), algo2("ak4pf"), iftest(false) { + JetCorrector = 0; + nevs = 0; + NBinsNpvRhoNpu = 6; + npvRhoNpuBinWidth = 5; + noPUNpvGTOneEventCounter = 0; + maxEvts = 0; + algo1JetInfo = JetInfo(algo1); + algo2JetInfo = JetInfo(algo2); + getMaxDeltaR(); + LumiWeightsSet_ = false; + recoJetIndexPU = NULL; + recoJetIndexNoPU = NULL; + jetMapTree = NULL; + fValue = NULL; +} + +//______________________________________________________________________________ +MatchEventsAndJets::MatchEventsAndJets(string algo1_, string algo2_, bool iftest_) + : algo1(algo1_), algo2(algo2_), iftest(iftest_){ + JetCorrector = 0; + nevs = 0; + NBinsNpvRhoNpu = 6; + npvRhoNpuBinWidth = 5; + noPUNpvGTOneEventCounter = 0; + maxEvts = 0; + algo1JetInfo = JetInfo(algo1); + algo2JetInfo = JetInfo(algo2); + getMaxDeltaR(); + LumiWeightsSet_ = false; + recoJetIndexPU = NULL; + recoJetIndexNoPU = NULL; + jetMapTree = NULL; + fValue = NULL; +} + +//______________________________________________________________________________ +void MatchEventsAndJets::SetWeightParameters(bool useweight_, bool pThatReweight_, double bias2SelectionRef_, double bias2SelectionPow_) { + useweight = useweight_; + pThatReweight = pThatReweight_; + bias2SelectionRef = bias2SelectionRef_; + bias2SelectionPow = bias2SelectionPow_; +} + + +//______________________________________________________________________________ +void MatchEventsAndJets::SetupLumiWeights(string dataFile, string mcFile, string dataHist, string mcHist) { + if(!dataFile.empty() && !mcFile.empty()) { + LumiWeights_ = edm::LumiReWeighting(mcFile,dataFile,mcHist,dataHist); + LumiWeightsSet_ = true; + cout << endl; + } + else { + cout << "WARNING::MatchEventsAndJets::SetupLumiWeights LumiWeights not set." << std::endl + << "\tOne or both of the input files was not set." << endl << endl; + } +} + +//______________________________________________________________________________ +void MatchEventsAndJets::getMaxDeltaR() { + double minConeSize = min(algo1JetInfo.coneSize,algo2JetInfo.coneSize)/20.0; + //maxDeltaR = min(0.25,0.05); + maxDeltaR = min(0.25,minConeSize); + + cout << setw(10) << " " << setw(13) << "Algo1" << setw(13) << "Algo2" << endl; + cout << std::setfill ('=') << setw(34) << " " << std::setfill (' ') << endl; + cout << setw(10) << "Cone Size:" << setw(13) << algo1JetInfo.coneSize + << setw(13) << algo2JetInfo.coneSize << endl; + cout << setw(10) << "Jet Type:" << setw(13) << algo1JetInfo.jetType + << setw(13) << algo2JetInfo.jetType << endl; + cout << setw(10) << "Alias:" << setw(13) << algo1JetInfo.alias + << setw(13) << algo2JetInfo.alias << endl; + cout << std::setfill ('-') << setw(34) << " " << std::setfill (' ') << endl; + cout << setw(18) << "0.5 * minConeSize:" << setw(4) << minConeSize << endl; + cout << setw(18) << "maxDeltaR:" << setw(4) << maxDeltaR << endl << endl; +} + +//______________________________________________________________________________ +double MatchEventsAndJets::getMaxDeltaR(string algName) { + return min(0.25,JetInfo(algName).coneSize/20.0); +} + +//______________________________________________________________________________ +void MatchEventsAndJets::OpenInputFiles(string filenamePU, string filenameNoPU) { + fpu = TFile::Open(filenamePU.c_str(),"READ"); + fnopu = TFile::Open(filenameNoPU.c_str(),"READ"); +} + +//______________________________________________________________________________ +void MatchEventsAndJets::MakeMatchedEventsMaps(string treeName, string outputPath) { + ITS mapTreePU = fillMap(false, treeName, outputPath); + ITS mapTreeNoPU = fillMap(true, treeName, outputPath); + + //create map of matched events + CreateMatchedEventsMap(mapTreePU,mapTreeNoPU); + + cout << "Event-matching report" << endl + << "\t Total number of unique events in first sample: " << mapTreePU.size() << endl + << "\t Total number of unique events in second sample: " << mapTreeNoPU.size() << endl + << "\t Number of matched events in both samples: " << mapEventMatch.size() << endl << endl; + + //if required, saving map of matched entries + if (!doNotSaveFlag) WriteMatchedEventsMap(outputPath); +} + +//______________________________________________________________________________ +ITS MatchEventsAndJets::fillMap(bool noPU, string treeName, string outputPath) { + TFile* f; + JRAEvent* t; + string algo; + ITS mapTree; + if(noPU == false) { + f = fpu; + algo = algo1; + t = tpu; + } + else if(noPU == true) { + f = fnopu; + algo = algo2; + t = tnopu; + } + + // Load only what's needed this WAY FASTER. + t->fChain->SetBranchStatus("*",0); + t->fChain->SetBranchStatus("run",1); + t->fChain->SetBranchStatus("evt",1); + t->fChain->SetBranchStatus("refpt",1); + Int_t lumi = 0; + + cout << "Filling map with event signatures from: "<GetName()<< endl; + cout << "\talgo: "<fChain->GetEntriesFast(); + + for (ull jentry=0; jentryLoadTree(jentry); + if (ientry < 0) break; + t->GetEntry(ientry); + + if(t->refpt->size()==0) { + no_ref_events++; + continue; + } + + if(mapTree.find(evtid(t->run, lumi, t->evt, t->refpt->at(0)))!=mapTree.end()) { + cout << "\tWARNING::This evtid already exists in the map." << endl; + } + + mapTree[evtid(t->run, lumi, t->evt, t->refpt->at(0))] = std::make_pair(jentry, (ull)ientry); + loadbar2(jentry+1,nentries,50,"\t\t"); + } + + cout << endl << "\tRead " << mapTree.size() << " unique signatures" << endl; + if(no_ref_events>0) { + cout << "\tWARNING::There were " << no_ref_events << " events which don't contain any ref jets" << endl // + << "\t\tThese events will be skipped" << endl << endl; + } + t->fChain->SetBranchStatus("*",1); + + return mapTree; +} + +//______________________________________________________________________________ +void MatchEventsAndJets::ConvertEvtMapToVector(const ITS& mapTree, vector& vevtid, vector >& vll) { + vevtid.clear(); + vll.clear(); + for(IT::const_iterator it=mapTree.begin(); it!=mapTree.end(); it++) { + vevtid.push_back(it->first); + vll.push_back(it->second); + } +} + +//______________________________________________________________________________ +void MatchEventsAndJets::ConvertEvtMapToTTree(const ITS& mapTree, TTree* treeMap) { + evtid tmpid; + pair tmpIndex; + treeMap->Branch("evtid","evtid",&tmpid); + treeMap->Branch("indices","pair",&tmpIndex); + for(IT::const_iterator it=mapTree.begin(); it!=mapTree.end(); it++) { + tmpid = it->first; + tmpIndex = it->second; + treeMap->Fill(); + } +} + +//______________________________________________________________________________ +void MatchEventsAndJets::WriteMatchedEventsMap(string outputPath) { + TDirectory* curDir = gDirectory; + string outputFilename = "matchedEventsMaps_"+algo1+"_"+algo2+".root"; + if (algo1 == algo2) + outputFilename = "matchedEventsMaps_"+algo1+".root"; + outputFilename = outputPath+outputFilename; + cout << "Writing mapTree to " << outputFilename << " ... " << endl << "\tprogress:"< entry; + ull PUentry; + ull NoPUentry; + tree->Branch("evtID",&evtID); + tree->Branch("PUentry",&PUentry); + tree->Branch("NoPUentry",&NoPUentry); + + if (!mapEventMatch.size()) { + cout<<"WARNING::No matched events"<first; + PUentry = it->second.first; + NoPUentry = it->second.second; + tree->Fill(); + + counter++; + }//for + + mapFile->Write(); + mapFile->Close(); + cout << endl; + curDir->cd(); +}//WriteMatchedEventsMap + +//______________________________________________________________________________ +void MatchEventsAndJets::CreateMatchedEventsMap(ITS& mapTreePU, ITS& mapTreeNoPU) { + + cout << "Creating matched events map"<first) == mapTreeNoPU.end()) { + counter++; + continue; + } + + mapEventMatch[it->first] = std::make_pair(mapTreePU[it->first].second,mapTreeNoPU[it->first].second); + + counter++; + + }//for + + if (!mapEventMatch.size()) { + cout<* tmpIndex; + treeMap->SetBranchAddress("evtid",&tmpid); + treeMap->SetBranchAddress("indices",&tmpIndex); + int nentries = treeMap->GetEntries(); + for(int ientry=0; ientryGetEntry(ientry); + mapTree[*tmpid] = *tmpIndex; + } +} + +//______________________________________________________________________________ +void MatchEventsAndJets::ReadMatchedEventsMaps(string pathToMaps) { + cout << "Reading matched event maps:" << endl + << "\tfile: " << pathToMaps << endl + << "\tprogress:" << endl; + + TDirectory* curDir = gDirectory; + TFile* mapFile = TFile::Open(pathToMaps.c_str(),"READ"); + + if(!mapFile || !mapFile->IsOpen()) { + cout<<"ERROR::ReadMatchedEventsMaps File "<Get("eventMapTree"); + + if(!tree) { + cout<<"ERROR::ReadMatchedEventsMaps cannot retrieve tree successfully. ABORTING"<SetBranchAddress("evtID",&evtID); + tree->SetBranchAddress("PUentry",&PUentry); + tree->SetBranchAddress("NoPUentry",&NoPUentry); + + Long64_t nentries = tree->GetEntries(); + + for (int e = 0; eGetEntry(e); + mapEventMatch[*evtID]=std::make_pair(PUentry,NoPUentry); + } + + mapFile->Close(); + curDir->cd(); + + cout << endl; + +} + +//______________________________________________________________________________ +void MatchEventsAndJets::GetNtuples(string treeName) { + int algo1_bit_number = (algo1JetInfo.jetType.Contains("calo",TString::kIgnoreCase)) ? 53 : 85; + int algo2_bit_number = (algo2JetInfo.jetType.Contains("calo",TString::kIgnoreCase)) ? 53 : 85; + + fpu->cd(algo1.c_str()); + tpu = new JRAEvent((TTree*) fpu->Get((algo1+"/"+treeName).c_str()),algo1_bit_number); + + fnopu->cd(algo2.c_str()); + tnopu = new JRAEvent((TTree*) fnopu->Get((algo2+"/"+treeName).c_str()),algo2_bit_number); +} + +//______________________________________________________________________________ +void MatchEventsAndJets::OpenOutputFile(string outputPath) { + string outputFilename = "output_"+algo1+"_"+algo2+".root"; + if (algo1 == algo2) + outputFilename = "output_"+algo1+".root"; + outputFilename = outputPath+outputFilename; + fout = new TFile(outputFilename.c_str(),"RECREATE"); +} + +//______________________________________________________________________________ +void MatchEventsAndJets::SetJEC(string JECPar) { + L1JetPar = new JetCorrectorParameters(JECPar); + vPar.push_back(*L1JetPar); + JetCorrector = new FactorizedJetCorrector(vPar); +} + +//______________________________________________________________________________ +void MatchEventsAndJets::DeclareHistograms(bool reduceHistograms) { + + //========================================================= + // DECLARATION OF HISTOS START HERE + //========================================================= + + // + // HISTOS OF GENERAL QUANTITIES.General, hence the g_ prefix + // + + histograms["h_ooavsweight"] = new TH2D("h_ooavsweight","h_ooavsweight;offsetOA;weight",1000,-1000,1000,200,-100,100); + histograms["h_onebin"] = new TH1D("h_onebin","h_onebin;offsetOA",2000,-100,100); + + histograms["h_chf"] = new TH2D("h_chf","h_chf;chf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nhf"] = new TH2D("h_nhf","h_nhf;nhf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nef"] = new TH2D("h_nef","h_nef;nef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_cef"] = new TH2D("h_cef","h_cef;cef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_muf"] = new TH2D("h_muf","h_muf;muf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + + histograms["h_chfw"] = new TH2D("h_chfw","h_chfw;chf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nhfw"] = new TH2D("h_nhfw","h_nhfw;nhf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nefw"] = new TH2D("h_nefw","h_nefw;nef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_cefw"] = new TH2D("h_cefw","h_cefw;cef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_mufw"] = new TH2D("h_mufw","h_mufw;muf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + + histograms["g_LumiWeight"] = new TH1D("g_LumiWeight", "g_LumiWeight;LumiWeight;Events", 1000,0,10); + histograms["g_GenWeight"] = new TH1D("g_GenWeight", "g_GenWeight;log_{10}(GenWeight);Events", 1000,-48,2); + histograms["g_pThatWeight"] = new TH1D("g_pThatWeight;log_{10}(pThatWeight);Events","g_pThatWeight", 1000,-48,2); + histograms["g_weight"] = new TH1D("g_weight","g_weight;log_{10}(EvtWeight);Events", 1000,-48,2); + histograms["g_pthat"] = new TH1D("g_pthat","g_pthat;#hat{p}_{T}^{PU};Events",(int)vpt[NPtBins]/10.0,vpt[0],vpt[NPtBins]); + if(!reduceHistograms) { + histograms["g_nj"] = new TH2D("g_nj","g_nj",30,0,30,30,0,30); + histograms["g_npv"] = new TH2D("g_npv","g_npv",50,0,50,50,0,50); + histograms["g_rho"] = new TH2D("g_rho","g_rho",50,0,50,50,0,50); + histograms["g_deltaNpv"] = new TProfile("g_deltaNpv","g_deltaNpv",50,0,50); + } + + // + // HISTOS OF EVENT or JET MATCHING performance, hence the m_ prefix + // + if(!reduceHistograms) { + histograms["m_refpt_diff"] = new TH1D("m_refpt_diff","refpt_diff;p_{T, j1}- p_{T, j2}; Number of events",300,-150,150); + histograms["m_refpdgid_diff"] = new TH1D("m_refpdgid_diff","m_refpdgid_diff;pdgid_{j1}- pdgid_{j2}; Number of events",100,-50,50); + histograms["m_deltaPthat"] = new TProfile("m_deltaPthat","m_deltaPthat;pthat_{pu}(GeV);pthat_{pu}-pthat_{nopu}(GeV)",300,0,3000); + + // To show the excees of jets at low-pt for the sample with pu. + histograms["m_njet_pt_pu"] = new TH1D("m_njet_pt_pu","m_njet_pt_pu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets + histograms["m_njet_pt_nopu"] = new TH1D("m_njet_pt_nopu","m_njet_pt-nopu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets + histograms["m_njet_pthigh_pu"] = new TH1D("m_njet_pthigh_pu","m_njet_pthigh_pu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets + histograms["m_njet_pthigh_nopu"] = new TH1D("m_njet_pthigh_nopu","m_njet_pthigh_nopu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets + + // Fraction of matched jets in all, barrel, endcap and forward regions + histograms["m_frac_nj_pt_b_match_pu"] = new TProfile("m_frac_nj_pt_b_match_pu","m_frac_nj_pt_b_match_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_nopu"] = new TProfile("m_frac_nj_pt_b_match_nopu","m_frac_nj_pt_b_match_nopu;pt_{jet};fraction of matched jets;", NPtBins,vpt); + histograms["m_frac_nj_pt_e_match_pu"] = new TProfile("m_frac_nj_pt_e_match_pu","m_frac_nj_pt_e_match_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_e_match_nopu"] = new TProfile("m_frac_nj_pt_e_match_nopu","m_frac_nj_pt_e_match_nopu;pt_{jet};fraction of matched jets;", NPtBins,vpt); + histograms["m_frac_nj_pt_f_match_pu"] = new TProfile("m_frac_nj_pt_f_match_pu","m_frac_nj_pt_f_match_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_f_match_nopu"] = new TProfile("m_frac_nj_pt_f_match_nopu","m_frac_nj_pt_f_match_nopu;pt_{jet};fraction of matched jets;", NPtBins,vpt); + + // Fraction of matched jets in barrel regions, with different NPV + histograms["m_frac_nj_pt_b_match_pu_npv10"] = new TProfile("m_frac_nj_pt_b_match_pu_npv10","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_nopu_npv1"] = new TProfile("m_frac_nj_pt_b_match_nopu_npv1","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); + histograms["m_frac_nj_pt_b_match_pu_npv20"] = new TProfile("m_frac_nj_pt_b_match_pu_npv20","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_nopu_npv2"] = new TProfile("m_frac_nj_pt_b_match_nopu_npv2","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); + histograms["m_frac_nj_pt_b_match_pu_npv30"] = new TProfile("m_frac_nj_pt_b_match_pu_npv30","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_nopu_npv3"] = new TProfile("m_frac_nj_pt_b_match_nopu_npv3","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); + histograms["m_frac_nj_pt_b_match_pu_npvO"] = new TProfile("m_frac_nj_pt_b_match_pu_npvO","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_nopu_npvO"] = new TProfile("m_frac_nj_pt_b_match_nopu_npvO","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); + + // Fraction of matched jets (reconstructed--->generated) in barrel regions, with different NPV + histograms["m_frac_nj_pt_b_match_RG_pu"] = new TProfile("m_frac_nj_pt_b_match_RG_pu","m_frac_nj_pt_b_match_RG_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_e_match_RG_pu"] = new TProfile("m_frac_nj_pt_e_match_RG_pu","m_frac_nj_pt_e_match_RG_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_f_match_RG_pu"] = new TProfile("m_frac_nj_pt_f_match_RG_pu","m_frac_nj_pt_f_match_RG_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_RG_nopu"] = new TProfile("m_frac_nj_pt_b_match_RG_nopu","m_frac_nj_pt_b_match_RG_nopu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_e_match_RG_nopu"] = new TProfile("m_frac_nj_pt_e_match_RG_nopu","m_frac_nj_pt_e_match_RG_nopu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_f_match_RG_nopu"] = new TProfile("m_frac_nj_pt_f_match_RG_nopu","m_frac_nj_pt_f_match_RG_nopu;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_RG_pu_npv10"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npv10","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_RG_pu_npv20"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npv20","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_RG_pu_npv30"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npv30","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + histograms["m_frac_nj_pt_b_match_RG_pu_npvO"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npvO","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); + + // Number of all jets vs. NPV in PU sample + histograms["m_all_nj_npv"] = new TProfile("m_all_nj_npv","m_all_nj_npv;NPV;# of jets/event",30,0.5,30.5); + + // Number of matched jets vs. NPV in PU sample + histograms["m_matched_nj_npv"] = new TProfile("m_matched_nj_npv","m_matched_nj_npv;NPV;# of jets/event",30,0.5,30.5); + + // Number of unmatched jets vs. NPV in PU sample + histograms["m_unmatched_nj_npv"] = new TProfile("m_unmatched_nj_npv","m_unmatched_nj_npv;NPV;# of jets/event",30,0.5,30.5); + + // Average jet pt vs. NPV in PU sample + histograms["m_all_jtpt_npv"] = new TProfile("m_all_jtpt_npv","m_all_jtpt_npv;NPV; (GeV)", 30, 0.5, 30.5); + + // Average matched jet pt vs. NPV in PU sample + histograms["m_matched_jtpt_npv"] = new TProfile("m_matched_jtpt_npv","m_matched_jtpt_npv;NPV; (GeV)", 30, 0.5, 30.5); + + // Average unmatched jet pt vs. NPV in PU sample + histograms["m_unmatched_jtpt_npv"] = new TProfile("m_unmatched_jtpt_npv","m_unmatched_jtpt_npv;NPV; (GeV)", 30, 0.5, 30.5); + + // Number of unmatched jets per event in different NPV bins. + // 6 old NPV bins 0-4, 5-9, 10-14, 15-19, 20-24, 25-29 + for (int n = 0 ; n < NBinsNpvRhoNpu ; n++) { + TString titles = ";p_{T,J};# PU Jets /event;"; + TString name = Form("m_njet_pt_npv%i_%i_unmatch",n*npvRhoNpuBinWidth,n*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); + histograms[name] = new TProfile(name, name+titles, NPtBins, vpt); // number of jets + + titles = ";#eta_{J}; p_{T,J};# PU Jets /event;"; + name = Form("m_njet_etaVspt_npv%i_%i_unmatch",n*npvRhoNpuBinWidth,n*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); + histograms[name] = new TProfile2D(name, name+titles, NETA, veta, NPtBins, vpt); // number of jets + } + } + + // + // HISTOS OF PU!!!, hence the p_suffix + // + if(!reduceHistograms) { + histograms["p_rhoVsRho"] = new TProfile ("p_rhoVsRho","p_rhoVsRho;",80,0,80); + histograms["p_npvVsNpv"] = new TProfile ("p_npvVsNpv","p_npvVsNpv;",80,0,80); + histograms["p_tnpuVsTnpu"] = new TProfile ("p_tnpuVsTnpu","p_tnpuVsTnpu;",80,0,80); + histograms["p_npuVsNpu"] = new TProfile ("p_npuVsNpu","p_npuVsNpu;",80,0,80); + histograms["p_matchedjet_off"] = new TProfile("p_matchedjet_off","p_matchedjet_off;_{jets} (GeV);# of matched jets",80,0,80); + histograms["p_drVsrefpt"] = new TProfile("p_drVsrefpt","p_drVsrefpt;p_{T}^{GEN};d_{R}",NPtBins, vpt); + + histograms["p_off_etaVsNpv"] = new TProfile2D("p_off_etaVsNpv","p_off_etaVsNpv;#eta_{j};N_{PV};Offset (p_{T}, GeV)",NETA, veta, 50,0,50); + histograms["p_off_etaVsRho"] = new TProfile2D("p_off_etaVsRho","p_off_etaVsRho;#eta_{j};Rho;Offset (p_{T}, GeV)",NETA, veta, 50,0,50); + histograms["p_off_etaVspueff"] = new TProfile2D("p_off_etaVsPUEff","p_off_etaVsPUEff;#eta_{j};PU_{Eff};Offset (p_{T}, GeV)",NETA, veta, 75,0,75); + histograms["p_off_etaVsGenSumPtOA"] = new TProfile2D("p_off_etaVsGenSumPtOA","p_off_etaVsGenSumPtOA;#eta_{j};GenSumPtOA;Offset (p_{T}, GeV)",NETA, veta, 100,0,2000); + histograms["p_off_etaVsJetPt"] = new TProfile2D("p_off_etaVsJetPt","p_off_etaVsJetPt;#eta_{j};p_{T}^{pu};Offset (p_{T}, GeV)",NETA, veta,NPtBins, vpt); + histograms["p_offOverA_etaVsJetPt"] = new TProfile2D("p_offOverA_etaVsJetPt","p_offOverA_etaVsJetPt;#eta_{j};p_{T}^{pu};OffsetOverArea",NETA, veta,NPtBins, vpt); + + histograms["p_off_EOOTVsITVsLOOT"] = new TProfile3D("p_off_EOOTVsITVsLOOT","p_off_EOOTVsITVsLOOT;EOOT;IT;LOOT",NRHO,vrho,NRHO,vrho,NRHO,vrho); + + //Rho + histograms["p_offOverA_etaVsRhoVsJetPt"] = new TProfile3D("p_offOverA_etaVsRhoVsJetPt","p_offOverA_etaVsRhoVsJetPt;#eta_{j};Rho;p_{T}^{gen};OffsetOverAre",NETA,veta,NRHO,vrho,NPtBins,vpt); + histograms["p_PtAve_etaVsRhoVsJetPt"] = new TProfile3D("p_PtAve_etaVsRhoVsJetPt","p_PtAve_etaVsRhoVsJetPt;#eta_{j};Rho;p_{T}^{gen};PtAve",NETA,veta,NRHO,vrho,NPtBins,vpt); + histograms["p_RhoAve_etaVsRhoVsJetPt"] = new TProfile3D("p_RhoAve_etaVsRhoVsJetPt","p_RhoAve_etaVsRhoVsJetPt;#eta_{j};Rho;p_{T}^{gen};RhoAve",NETA,veta,NRHO,vrho,NPtBins,vpt); + + //NPV + histograms["p_offOverA_etaVsNPVVsJetPt"] = new TProfile3D("p_offOverA_etaVsNPVVsJetPt","p_offOverA_etaVsNPVVsJetPt;#eta_{j};NPV;p_{T}^{gen};OffsetOverAre",NETA,veta,NRHO,vrho,NPtBins,vpt); + histograms["p_PtAve_etaVsNPVVsJetPt"] = new TProfile3D("p_PtAve_etaVsNPVVsJetPt","p_PtAve_etaVsNPVVsJetPt;#eta_{j};NPV;p_{T}^{gen};PtAve",NETA,veta,NRHO,vrho,NPtBins,vpt); + histograms["p_RhoAve_etaVsNPVVsJetPt"] = new TProfile3D("p_RhoAve_etaVsNPVVsJetPt","p_RhoAve_etaVsNPVVsJetPt;#eta_{j};NPV;p_{T}^{gen};RhoAve",NETA,veta,NRHO,vrho,NPtBins,vpt); + } + + //TNPU + histograms["p_offOverA_etaVsTnpusVsJetPt"] = new TProfile3D("p_offOverA_etaVsTnpusVsJetPt","p_offOverA_etaVsTnpusVsJetPt;#eta_{j};tnpu;p_{T}^{gen};OffsetOverArea",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); + histograms["p_PtAve_etaVsTnpusVsJetPt"] = new TProfile3D("p_PtAve_etaVsTnpusVsJetPt","p_PtAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); + histograms["p_RhoAve_etaVsTnpusVsJetPt"] = new TProfile3D("p_RhoAve_etaVsTnpusVsJetPt","p_RhoAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); + histograms["p_Events_etaVsTnpusVsJetPt"] = new TH3I("p_Events_etaVsTnpusVsJetPt","p_RhoAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); + //THnSparse with 4 dimensions + Int_t bins[4] = {NETA, NRHO, NTNPU, NPtBins}; + Double_t min[4] = {veta[0], vrho[0], vtnpu[0], vpt[0]}; + Double_t max[4] = {veta[NETA-1], vrho[NRHO-1], vtnpu[NTNPU-1], vpt[NPtBins-1]}; + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"] = new THnSparseF("p_offOverA_etaRhoVsTnpusVsJetPt", "p_offOverA_etaVsRhoVsTnpusVsJetPt", 4, bins, min, max); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(0,veta); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(1,vrho); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(2,vtnpu); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(3,vpt); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(0)->SetTitle("#eta_{j}"); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(1)->SetTitle("Rho"); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(2)->SetTitle("tnpu"); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(3)->SetTitle("p_{T}^{gen}"); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->Sumw2(); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"] = new THnSparseF("p_PtAve_etaRhoVsTnpusVsJetPt", "p_PtAve_etaVsRhoVsTnpusVsJetPt", 4, bins, min, max); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(0,veta); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(1,vrho); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(2,vtnpu); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(3,vpt); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(0)->SetTitle("#eta_{j}"); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(1)->SetTitle("Rho"); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(2)->SetTitle("tnpu"); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(3)->SetTitle("p_{T}^{gen}"); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->Sumw2(); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"] = new THnSparseF("p_entries_etaRhoVsTnpusVsJetPt", "p_entries_etaRhoVsTnpusVsJetPt", 4, bins, min, max); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(0,veta); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(1,vrho); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(2,vtnpu); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(3,vpt); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(0)->SetTitle("#eta_{j}"); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(1)->SetTitle("Rho"); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(2)->SetTitle("tnpu"); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(3)->SetTitle("p_{T}^{gen}"); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->Sumw2(); + if (!fValue) fValue = new Double_t[4]; + + //NPU + histograms["p_offOverA_etaVsNpusVsJetPt"] = new TProfile3D("p_offOverA_etaVsNpusVsJetPt","p_offOverA_etaVsNpusVsJetPt;#eta_{j};npu;p_{T}^{gen};OffsetOverAre",NETA,veta,NNPU,vnpu,NPtBins,vpt); + histograms["p_PtAve_etaVsNpusVsJetPt"] = new TProfile3D("p_PtAve_etaVsNpusVsJetPt","p_PtAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NNPU,vnpu,NPtBins,vpt); + histograms["p_RhoAve_etaVsNpusVsJetPt"] = new TProfile3D("p_RhoAve_etaVsNpusVsJetPt","p_RhoAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NNPU,vnpu,NPtBins,vpt); + histograms["p_Events_etaVsNpusVsJetPt"] = new TH3I("p_Events_etaVsNpusVsJetPt","p_RhoAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); + + if(!reduceHistograms) { + //NPV+Rho + histograms["p_offOverA_etaVsN_RVsJetPt"] = new TProfile3D("p_offOverA_etaVsN_RVsJetPt","p_offOverA_etaVsN_RVsJetPt;#eta_{j};(NPV+Rho)/2;p_{T}^{gen};OffsetOverAre",NETA,veta,NRHO,vrho,NPtBins,vpt); + histograms["p_PtAve_etaVsN_RVsJetPt"] = new TProfile3D("p_PtAve_etaVsN_RVsJetPt","p_PtAve_etaVsN_RVsJetPt;#eta_{j};(NPV+Rho)/2;p_{T}^{gen};PtAve",NETA,veta,NRHO,vrho,NPtBins,vpt); + + histograms["p_offsetOA_rho_npv_refpt_BB"] = new TProfile3D("p_offsetOA_rho_npv_refpt_BB","p_offsetOA_rho_npv_refpt_BB;Rho;N_{PV};p_{T}^{GEN};offsetOA",NRHO,vrho,NRHO,vrho,NPtBins,vpt); + histograms["p_npvVsoff"] = new TH2F("p_npvVsOff","p_npvVsOff;_{jets} (GeV);N_{PV}",80,0,80,80,0,80); + histograms["p_rhoVsoff"] = new TH2F("p_rhoVsOff","p_rhoVsOff;_{jets} (GeV);Rho",80,0,80,80,0,80); + histograms["p_areaVsrefpt"] = new TH2F("p_areaVsrefpt","p_areaVsrefpt;p_{T}^{GEN};jtarea^{pu}-jtarea^{nopu}",NPtBins, vpt,100,-1,1); + histograms["p_areaVsoffset_1000"] = new TH2F("p_areaVsoffset_1000","p_areaVsoffset_1000;offset;jtarea^{pu}-jtarea^{nopu}",100,-500,500,100,-1,1); + histograms["p_areaVsoffset_30_50"] = new TH2F("p_areaVsoffset_30_50","p_areaVsoffset_30_50;offset;jtarea^{pu}-jtarea^{nopu}",100,-100,100,100,-1,1); + + histograms["p_rho_npv_refpt_BB"] = new TH3F("p_rho_npv_refpt_BB","p_rho_npv_refpt_BB;Rho;N_{PV};p_{T}^{GEN}",NRHO,vrho,NRHO,vrho,NPtBins,vpt); + } + + // Break into 4 different detector region + TString hname = ""; + for (int det=0;det_{jets} (GeV);N_{PV}", + 80,0,80,80,0,80); + hname = Form("p_rhoVsOff_%s",detectorAbbreviation.Data()); + histograms[hname] = new TH2D(hname,hname+";_{jets} (GeV);Rho", + 80,0,80,80,0,80); + + //Offset Vs. p_{T} in bins of PF category + for (int iPF=0;iPF::iterator it=histograms.begin(); it!=histograms.end(); ++it) { + it->second->Sumw2(); + } +} + +//______________________________________________________________________________ +void MatchEventsAndJets::LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap, string outputPath) { + //First just figure out if the jetMapTree exists, assuming readJetMap is set. + //It might be that the program failed after the event mapping, so the event maps exist, but not the jet maps + //In this case the event maps should be read, but the jet maps should be recreated. + jetMapTreeFound = false;// (readJetMap.empty()) ? false : GetJetMap(readJetMap); + + if (!mapEventMatch.size()) { + cout< maxEvts && iftest) ? maxEvts : mapEventMatch.size(); + for (IT::const_iterator it = mapEventMatch.begin(); it != mapEventMatch.end() && nevs < nentries; ++it) { + + loadbar2(nevs+1,nentries,50,"\t\t"); + + // Load the entries at the proper place. + tpu->GetEntry(it->second.first); + tnopu->GetEntry(it->second.second); + + //Skip events without any primary vertex as these make no sense + if (tpu->npv == 0 || tnopu->npv == 0) { + nevs++; + continue; + } + // Set the in-time pileup index after the first event only + if(nevs==0) iIT = tpu->itIndex(); + + // Create the mapping of matched jets. + // key is PU, value is for NoPU + //if(!readJetMap) FillJetMap(); + if(readJetMap.empty() || !jetMapTreeFound) { + FillRecToRecThroughGenMap(); + } + else { + jetMapIndex++; + ReadJetMap(jetMapIndex,readJetMap); + } + + FillHistograms(reduceHistograms,it); + + nevs++; + + }//for + cout< > auxMap; + + // Order j1 according to reco-jet pT + vector j1o; + j1o.push_back(0); + for (int j1=1; j1 < tpu->nref; j1++){ + for (unsigned ito = 0; ito < j1o.size(); ++ito){ + if (tpu->jtpt->at(j1) > tpu->jtpt->at(j1o[ito])){ + j1o.insert(j1o.begin()+ito,j1); + break; + } + } + } + if (nrefmax > 0 && nrefmax < (int)j1o.size()) j1o.resize(nrefmax); + + for (int j1=0; j1 < tpu->nref; j1++){ + for (int j2=0; j2 < tnopu->nref; j2++){ + double dR = pow(tpu->jteta->at(j1o[j1]) - tnopu->jteta->at(j2),2); + dR += pow(tpu->jtphi->at(j1o[j1]) - tnopu->jtphi->at(j2),2); + dR = sqrt(dR); + auxMap[dR] = std::make_pair(j1o[j1], j2); + } + } + + // First clear the map for this new set of events + jetMap.clear(); + + // 1-Find the pair of jets with the smallest dr. Add them to resulting map + // 2-Remove the pair from the map, rinse and repeat. + while (auxMap.size() > 0){ + // 1- The first element which is the one with the smallest dR. Get the jet indexes + int j1 = auxMap.begin()->second.first; + int j2 = auxMap.begin()->second.second; + + // Add to the results + if (auxMap.begin()->first < maxDeltaR && fabs(tpu->refpt->at(j1) - tnopu->refpt->at(j2))<1 && tnopu->refdrjt->at(j2) < maxDeltaR) + jetMap[j1] = j2; + + // 2- Now remove all elements from the auxMap that contain either the first or second jet + ITJ::iterator itr = auxMap.begin(); + while(itr != auxMap.end()){ + if (itr->second.first == j1 || itr->second.second == j2) + auxMap.erase(itr++); + else + ++itr; + }//while removing + }//while +}//FillJetMap + +//______________________________________________________________________________ +void MatchEventsAndJets::FillRecToRecThroughGenMap() { + jetMap.clear(); + if(!recoJetIndexPU) recoJetIndexPU = new vector; + if(!recoJetIndexNoPU) recoJetIndexNoPU = new vector; + recoJetIndexPU->clear(); + recoJetIndexNoPU->clear(); + if (nrefmax>=0) tpu->nref = std::min((int)tpu->nref,nrefmax); + for (int iRefPU=0; iRefPU < tpu->nref; iRefPU++) { + int j1 = iRefPU; + int j2 = -1; + for (int iRefNoPU=0; iRefNoPU < tnopu->nref; iRefNoPU++) { + if(tnopu->refpt->at(iRefNoPU)==tpu->refpt->at(iRefPU)) { + j2 = iRefNoPU; + break; + } + } + if(j1 >= 0 && j2 >= 0 && j1 < tpu->nref && j2 < tnopu->nref && + tpu->refdrjt->at(j1) < maxDeltaR && tnopu->refdrjt->at(j2) < maxDeltaR && + fabs(tpu->refpt->at(j1) - tnopu->refpt->at(j2))<0.0001 + ) { + jetMap[j1] = j2; + } + recoJetIndexPU->push_back(j1); + recoJetIndexNoPU->push_back(j2); + } + + //Initialize the jetMapTree if it has not already been initialized + if(!jetMapTree) { + jetMapTree = new TTree("jetMapTree","jetMapTree"); + jetMapTree->Branch("recoJetIndexPU", "vector",&recoJetIndexPU); + jetMapTree->Branch("recoJetIndexNoPU","vector",&recoJetIndexNoPU); + jetMapTree->SetDirectory(0); + } + //Always fill the jet map tree + jetMapTree->Fill(); + +}//FillRecToRecThroughGenMap + +//______________________________________________________________________________ +bool MatchEventsAndJets::GetJetMap(string readJetMap) { + //Retrieve the tree from a file + cout << endl << "Reading matched jets tree:" << endl + << "\tfile: " << readJetMap << endl; + + TDirectory* curDir = gDirectory; + TFile* mapFile = TFile::Open(readJetMap.c_str(),"READ"); + + auto inTreePointer = (TTree*)mapFile->Get("jetMapTree"); + if(inTreePointer) { + jetMapTree = (TTree*)inTreePointer->Clone(); + cout << "\tjetMapTree:" << endl + << "\t\tnevts: " << jetMapTree->GetEntries() << endl; + } + else { + cout << "\tWARNING::MatchEventsAndJets::GetJetMap Could not retrieve the jetMapTree pointer from " << readJetMap << endl; + return false; + } + jetMapTree->SetDirectory(0); + jetMapTree->SetBranchAddress("recoJetIndexPU", &recoJetIndexPU); + jetMapTree->SetBranchAddress("recoJetIndexNoPU",&recoJetIndexNoPU); + + mapFile->Close(); + curDir->cd(); + return true; +} + +//______________________________________________________________________________ +void MatchEventsAndJets::ReadJetMap(int ientry, string readJetMap) { + //Just a small sanity check + if(!jetMapTree) { + cout << "ERROR::MatchEventsAndJets::ReadJetMap At this point the jetMapTree should have been retrieved from " << readJetMap << endl; + std::terminate(); + } + + //Create the map based on the vectors from the jetMapTree + jetMapTree->GetEntry(ientry); + jetMap.clear(); + for(unsigned int i = 0; isize() && ((nrefmax>=0)?i<(unsigned)nrefmax:true); i++) { + if(recoJetIndexPU->at(i) >= 0 && recoJetIndexNoPU->at(i) >= 0 && + recoJetIndexPU->at(i) < tpu->nref && recoJetIndexNoPU->at(i) < tnopu->nref && + tpu->refdrjt->at(recoJetIndexPU->at(i)) < maxDeltaR && + tnopu->refdrjt->at(recoJetIndexNoPU->at(i)) < maxDeltaR && + fabs(tpu->refpt->at(recoJetIndexPU->at(i)) - tnopu->refpt->at(recoJetIndexNoPU->at(i)))<0.0001) { + jetMap[recoJetIndexPU->at(i)] = recoJetIndexNoPU->at(i); + } + } +} + + +//______________________________________________________________________________ +bool MatchEventsAndJets::FillHistograms(bool reduceHistograms, IT::const_iterator it) { + //========================================================= + // FILLING OF HISTOS START HERE + //========================================================= + + // + // retrieve the correct weight and fill some histograms to keep track of them + // + weight = 1.0; + if(useweight) { + weight *= tpu->weight; + dynamic_cast(histograms["g_GenWeight"]) ->Fill(log(tpu->weight)); // The GenWeight + } + if(LumiWeightsSet_) { + weight *= LumiWeights_.weight(tpu->tnpus->at(iIT)); + dynamic_cast(histograms["g_LumiWeight"]) ->Fill(LumiWeights_.weight(tpu->tnpus->at(iIT))); // The LumiWeight + } + if(pThatReweight) { + weight *= pow(tpu->pthat/bias2SelectionRef,bias2SelectionPow); + dynamic_cast(histograms["g_pThatWeight"]) ->Fill(log(pow(tpu->pthat/bias2SelectionRef,bias2SelectionPow))); // The pThat weight + } + dynamic_cast(histograms["g_weight"]) ->Fill(log(weight)); // The overall weight + + // GENERAL HISTOS, no cuts. + dynamic_cast(histograms["g_pthat"]) ->Fill(tpu->pthat,weight); // pthat distributions + if(!reduceHistograms) { + dynamic_cast(histograms["g_nj"]) ->Fill(tpu->nref,tnopu->nref,weight); // njet distributions + dynamic_cast(histograms["g_npv"]) ->Fill(tpu->npv,tnopu->npv,weight); // npv dist. + dynamic_cast(histograms["g_rho"]) ->Fill(tpu->rho,tnopu->rho,weight); // rho dist + dynamic_cast(histograms["g_deltaNpv"]) ->Fill(tpu->npv,tpu->npv - tnopu->npv,weight); // Does the number of NPV change? + dynamic_cast(histograms["m_deltaPthat"])->Fill(tpu->pthat,tpu->pthat-tnopu->pthat,weight); // pthat sanity check + } + + //Skip events where the noPU sample has more than one vertex + if (tnopu->npv!=1) { + noPUNpvGTOneEventCounter++; + if(noPUNpvGTOneEventCounter==0) { + cout << "\tWARNING::The NoPU sample has more than 1 PV." << endl + << "\tSome events will be skipped (including this one)." << endl; + } + return false; + } + + inpv = JetInfo::getBinIndex(tpu->npv,NBinsNpvRhoNpu,npvRhoNpuBinWidth); + inpv_low = inpv*npvRhoNpuBinWidth; + inpv_high = inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; + irho = JetInfo::getBinIndex(tpu->rho,NBinsNpvRhoNpu,npvRhoNpuBinWidth); + irho_low = irho*npvRhoNpuBinWidth; + irho_high = irho*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; + itnpu = JetInfo::getBinIndex(tpu->tnpus->at(iIT),NBinsNpvRhoNpu,npvRhoNpuBinWidth); + itnpu_low = itnpu*npvRhoNpuBinWidth; + itnpu_high = itnpu*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; + inpu = JetInfo::getBinIndex(tpu->npus->at(iIT),NBinsNpvRhoNpu,npvRhoNpuBinWidth); + inpu_low = inpu*npvRhoNpuBinWidth; + inpu_high = inpu*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; + TString hname = ""; + + // + // Applying JEC from textfile + // + vector tpu_jtpt_raw; + if (JetCorrector) { + double correction = 1.0; + //for (int j1 = 0; j1 < tpu->nref; j1++) { + for (map::const_iterator j1it = jetMap.begin(); j1it != jetMap.end(); j1it++) { + int j1 = j1it->first; + JetCorrector->setJetEta(tpu->jteta->at(j1)); + JetCorrector->setJetPt(tpu->jtpt->at(j1)); + JetCorrector->setJetA(tpu->jtarea->at(j1)); + JetCorrector->setRho(tpu->rho); + correction = JetCorrector->getCorrection(); + //cout <jtpt->at(j1); + tpu_jtpt_raw.push_back(tpu->jtpt->at(j1)); + tpu->jtpt->at(j1) *= correction; + //cout <<" "<jtpt->at(j1)<::const_iterator j1it = jetMap.begin(); j1it != jetMap.end(); j1it++) { + int j1 = j1it->first; + if(j1 == -1) continue; + + // matching reco-jet with gen-jet + bool ismatchRG = tpu->refdrjt->at(j1)Fill(tpu->jtpt->at(j1)); + if(tpu->refpt->at(j1)>10){ + histograms["m_njet_pthigh_pu"]->Fill(tpu->jtpt->at(j1)); + } + + avg_jtpt_all += tpu->jtpt->at(j1); + + // if j1 is matched in this sample + bool ismatch = jetMap.find(j1) != jetMap.end(); + + if (ismatch) avg_jtpt_matched += tpu->jtpt->at(j1); + else avg_jtpt_unmatched += tpu->jtpt->at(j1); + + if (fabs(tpu->jteta->at(j1))<1.3) { + histograms["m_frac_nj_pt_b_match_pu"] ->Fill(tpu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_b_match_RG_pu"]->Fill(tpu->jtpt->at(j1),ismatchRG); + if (tpu->npv<=10) { + histograms["m_frac_nj_pt_b_match_pu_npv10"] ->Fill(tpu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_b_match_RG_pu_npv10"]->Fill(tpu->jtpt->at(j1),ismatchRG); + } + else if (tpu->npv<=20) { + histograms["m_frac_nj_pt_b_match_pu_npv20"] ->Fill(tpu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_b_match_RG_pu_npv20"]->Fill(tpu->jtpt->at(j1),ismatchRG); + } + else if (tpu->npv<=30) { + histograms["m_frac_nj_pt_b_match_pu_npv30"] ->Fill(tpu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_b_match_RG_pu_npv30"]->Fill(tpu->jtpt->at(j1),ismatchRG); + } + else { + histograms["m_frac_nj_pt_b_match_pu_npvO"] ->Fill(tpu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_b_match_RG_pu_npvO"]->Fill(tpu->jtpt->at(j1),ismatchRG); + } + } + else if (fabs(tpu->jteta->at(j1))<3) { + histograms["m_frac_nj_pt_e_match_pu"] ->Fill(tpu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_e_match_RG_pu"]->Fill(tpu->jtpt->at(j1),ismatchRG); + } + else { + histograms["m_frac_nj_pt_f_match_pu"] ->Fill(tpu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_f_match_RG_pu"]->Fill(tpu->jtpt->at(j1),ismatchRG); + } + if (!ismatch) { + hname = Form("m_njet_pt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); + histograms[hname]->Fill(tpu->jtpt->at(j1),+1); + hname = Form("m_njet_etaVspt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); + dynamic_cast(histograms[hname])->Fill(tpu->jteta->at(j1), tpu->jtpt->at(j1),+1); + } + } + + if (tpu->nref>0) avg_jtpt_all /= (double) tpu->nref; else avg_jtpt_all = 0; + if (jetMap.size()>0) avg_jtpt_matched /= (double) jetMap.size(); else avg_jtpt_matched = 0; + if (tpu->nref-jetMap.size()>0) avg_jtpt_unmatched /= (double) (tpu->nref - jetMap.size()); else avg_jtpt_unmatched = 0; + + histograms["m_all_nj_npv"] ->Fill(tpu->npv,tpu->nref); + histograms["m_matched_nj_npv"] ->Fill(tpu->npv, jetMap.size()); + histograms["m_unmatched_nj_npv"]->Fill(tpu->npv, tpu->nref-jetMap.size()); + + histograms["m_all_jtpt_npv"] ->Fill(tpu->npv, avg_jtpt_all); + histograms["m_matched_jtpt_npv"] ->Fill(tpu->npv, avg_jtpt_matched); + histograms["m_unmatched_jtpt_npv"]->Fill(tpu->npv, avg_jtpt_unmatched); + + // fill unmatch jets for NOPU sample + for (map::const_iterator j1it = jetMap.begin(); j1it != jetMap.end(); j1it++) { + int j1 = j1it->second; + if(j1 == -1) continue; + + histograms["m_njet_pt_nopu"]->Fill(tnopu->jtpt->at(j1)); + if(tnopu->refpt->at(j1)>10){ + histograms["m_njet_pthigh_nopu"]->Fill(tnopu->jtpt->at(j1)); + } + + bool ismatchRG = tnopu->refdrjt->at(j1)::const_iterator itj = jetMap.begin(); itj != jetMap.end(); itj++) { + if (itj->second == j1){ + ismatch = true; + break; + } + } + + if (fabs(tnopu->jteta->at(j1))<1.3) { + histograms["m_frac_nj_pt_b_match_nopu"] ->Fill(tnopu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_b_match_RG_nopu"]->Fill(tnopu->jtpt->at(j1),ismatchRG); + if (tpu->npv<=10) + histograms["m_frac_nj_pt_b_match_nopu_npv1"]->Fill(tnopu->jtpt->at(j1),ismatch); + else if (tpu->npv<=20) + histograms["m_frac_nj_pt_b_match_nopu_npv2"]->Fill(tnopu->jtpt->at(j1),ismatch); + else if (tpu->npv<=30) + histograms["m_frac_nj_pt_b_match_nopu_npv3"]->Fill(tnopu->jtpt->at(j1),ismatch); + else + histograms["m_frac_nj_pt_b_match_nopu_npvO"]->Fill(tnopu->jtpt->at(j1),ismatch); + } + else if (fabs(tnopu->jteta->at(j1))<3) { + histograms["m_frac_nj_pt_e_match_nopu"] ->Fill(tnopu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_e_match_RG_nopu"]->Fill(tnopu->jtpt->at(j1),ismatchRG); + } + else { + histograms["m_frac_nj_pt_f_match_nopu"] ->Fill(tnopu->jtpt->at(j1),ismatch); + histograms["m_frac_nj_pt_f_match_RG_nopu"]->Fill(tnopu->jtpt->at(j1),ismatchRG); + } + if (!ismatch) { + hname = Form("m_njet_pt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); + histograms[hname]->Fill(tnopu->jtpt->at(j1),-1); + hname = Form("m_njet_etaVspt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); + dynamic_cast(histograms[hname])->Fill(tnopu->jteta->at(j1), tnopu->jtpt->at(j1),-1); + } + } + } + + double avg_offset = 0; + double avg_offset_det[NDetectorNames] = {0,0,0,0}; + double njet_det[NDetectorNames] = {0,0,0,0}; + + // MATCHING HISTOS. + // Loop over matched jets + int jpu = -1; + int jnopu = -1; + int idet = -1; + TString detectorAbbreviation; + double offset = 0, offset_raw = 0, offsetOA = 0, offsetOrefpt = 0, areaDiff = 0, resp = 0, + respTonopu = 0, respNopu = 0, PUEff = 0, GenSumPtOA = 0; + int diff_pdgid = 0; + vector offset_PFcat; + for (map::const_iterator itj = jetMap.begin(); itj != jetMap.end(); itj++) { + + jpu = itj->first; + jnopu = itj->second; + if(jpu == -1 || jnopu == -1) continue; + + + + if (!tpu->jtarea->at(jpu) || TMath::IsNaN(tpu->jtarea->at(jpu)) || fabs(tpu->jtarea->at(jpu))==TMath::Infinity() || ((minPhi || maxPhi) && (tpu->jtphi->at(jpu)jtphi->at(jpu)>maxPhi))) continue; + + +//======Veto regions for UL2017 --> HEP17 (1.31, -0.5236, 2.96, -0.8727) , HBPw89 (0, 2.705, 1.4835, 3.1416 ) =========== +//if (!tpu->jtarea->at(jpu) || TMath::IsNaN(tpu->jtarea->at(jpu)) || fabs(tpu->jtarea->at(jpu))==TMath::Infinity() || ( (tpu->jtphi->at(jpu)<-0.5236 && tpu->jtphi->at(jpu)>-0.8727 && tpu->jteta->at(jpu)<2.96 && tpu->jteta->at(jpu)>1.31)|| ( tpu->jtphi->at(jpu)>2.705 && tpu->jtphi->at(jpu)<3.1416 && tpu->jteta->at(jpu)>0. && tpu->jteta->at(jpu)<1.4835) )) continue; + +//=== veto region for UL2018 ======= +//if (!tpu->jtarea->at(jpu) || TMath::IsNaN(tpu->jtarea->at(jpu)) || fabs(tpu->jtarea->at(jpu))==TMath::Infinity() || (tpu->jtphi->at(jpu)<-0.8727 && tpu->jtphi->at(jpu)>-1.5708 && tpu->jteta->at(jpu) < -1.31 && tpu->jteta->at(jpu)> -2.96) || (tpu->jtphi->at(jpu)>0.4363 && tpu->jtphi->at(jpu)<0.7854 && tpu->jteta->at(jpu) >0 && tpu->jteta->at(jpu)<1.31) continue; + +//cout << "JetPhi" << tpu->jtphi->at(jpu) << endl; + + + idet = JetInfo::getDetIndex(tpu->jteta->at(jpu)); + detectorAbbreviation = JetInfo::get_detector_abbreviation(detector_names[idet]); + detectorAbbreviation.ToLower(); + vector pdgid_indecies = JetInfo::getPDGIDIndecies(tpu->refpdgid->at(jpu)); + + diff_pdgid = tpu->refpdgid->at(jpu) - tnopu->refpdgid->at(jnopu); + offset = tpu->jtpt->at(jpu) - tnopu->jtpt->at(jnopu); + offset_raw = (tpu_jtpt_raw.size()>0) ? tpu_jtpt_raw[jpu] - tnopu->jtpt->at(jnopu) : -1.0; + offsetOA = offset / tpu->jtarea->at(jpu); + offsetOrefpt = offset / tpu->refpt->at(jpu); + areaDiff = tpu->jtarea->at(jpu) - tnopu->jtarea->at(jnopu); + resp = tpu->jtpt->at(jpu) / tpu->refpt->at(jpu); // response relative to reference jet + respTonopu = tpu->jtpt->at(jpu) / tnopu->jtpt->at(jnopu);// response relative to no pu jet + respNopu = tnopu->jtpt->at(jnopu) / tnopu->refpt->at(jnopu); // response no pu jet to reference jet + PUEff = 0.020*(tpu->sumEOOT())+0.975*(tpu->npus->at(iIT))+0.005*(tpu->sumLOOT()); // effective pu + GenSumPtOA = (0.020*(tpu->sumpt_lowpt->at(0))+0.975*(tpu->sumpt_lowpt->at(1))+0.005*(tpu->sumpt_lowpt->at(2)))/tpu->jtarea->at(jpu); + + if (fabs(offsetOA)>300) eventlist<second.first<second.second<evt<run<jtarea->at(jpu)<jtpt->at(jpu)<jtpt->at(jnopu)<(histograms["p_off_etaVsNpv"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,offset,weight); + dynamic_cast(histograms["p_off_etaVsRho"]) ->Fill(tpu->jteta->at(jpu),tpu->rho,offset,weight); + dynamic_cast(histograms["p_off_etaVspueff"]) ->Fill(tpu->jteta->at(jpu),PUEff,offset,weight); + dynamic_cast(histograms["p_off_etaVsGenSumPtOA"])->Fill(tpu->jteta->at(jpu),GenSumPtOA,offset,weight); + dynamic_cast(histograms["p_off_etaVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->jtpt->at(jpu),offset,weight); + dynamic_cast(histograms["p_offOverA_etaVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->jtpt->at(jpu),offsetOA,weight); + dynamic_cast(histograms["p_off_EOOTVsITVsLOOT"]) ->Fill(tpu->sumEOOT(),tpu->npus->at(iIT),tpu->sumLOOT(),offset,weight); + + //Rho + dynamic_cast(histograms["p_offOverA_etaVsRhoVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->rho,tpu->refpt->at(jpu),offsetOA,weight); + dynamic_cast(histograms["p_RhoAve_etaVsRhoVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->rho,tpu->refpt->at(jpu),tpu->rho,weight); + dynamic_cast(histograms["p_PtAve_etaVsRhoVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->rho,tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); + + //NPV + dynamic_cast(histograms["p_offOverA_etaVsNPVVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->npv,tpu->refpt->at(jpu),offsetOA,weight); + dynamic_cast(histograms["p_RhoAve_etaVsNPVVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,tpu->refpt->at(jpu),tpu->rho,weight); + dynamic_cast(histograms["p_PtAve_etaVsNPVVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); + } + + int etabin = 60; + int tnpubin = 6; + int ptbin = 26; + + bool cond = true; + cond &= tpu->jteta->at(jpu)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetXaxis()->GetBinLowEdge(etabin); + cond &= tpu->jteta->at(jpu)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetXaxis()->GetBinUpEdge(etabin); + cond &= tpu->tnpus->at(iIT)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetYaxis()->GetBinLowEdge(tnpubin); + cond &= tpu->tnpus->at(iIT)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetYaxis()->GetBinUpEdge(tnpubin); + cond &= tpu->refpt->at(jpu)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetZaxis()->GetBinLowEdge(ptbin); + cond &= tpu->refpt->at(jpu)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetZaxis()->GetBinUpEdge(ptbin); + + if (cond) dynamic_cast(histograms["h_onebin"])->Fill(offsetOA,weight); + //TNPU + + dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),offsetOA,weight); + dynamic_cast(histograms["p_PtAve_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); + dynamic_cast(histograms["p_RhoAve_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),tpu->rho,weight); + dynamic_cast(histograms["p_Events_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu)); + + fValue[0] = tpu->jteta->at(jpu); + fValue[1] = tpu->rho; + fValue[2] = tpu->tnpus->at(iIT); + fValue[3] = tpu->refpt->at(jpu); + hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->Fill(fValue,offsetOA*weight); + hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->Fill(fValue,tpu->jtpt->at(jpu)*weight); + hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->Fill(fValue,weight); + //if(hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetBin(fValue)==8500) { + // avg_debug +=offsetOA; + // entries_debug++; + //} + + //NPU (weight of NPU if tnpu is single valued at 20 = 1.0/TMath::Gaus(tpu->npus->at(iIT),20,sqrt(20)) + dynamic_cast(histograms["p_offOverA_etaVsNpusVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),offsetOA,weight); + dynamic_cast(histograms["p_PtAve_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); + dynamic_cast(histograms["p_RhoAve_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),tpu->rho,weight); + dynamic_cast(histograms["p_Events_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu)); + + if(!reduceHistograms) { + //NPV+Rho + dynamic_cast(histograms["p_offOverA_etaVsN_RVsJetPt"]) ->Fill(tpu->jteta->at(jpu),(tpu->rho+tpu->npv)/2.,tpu->refpt->at(jpu),offsetOA,weight); + dynamic_cast(histograms["p_PtAve_etaVsN_RVsJetPt"]) ->Fill(tpu->jteta->at(jpu),(tpu->rho+tpu->npv)/2,tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); + dynamic_cast(histograms["p_areaVsrefpt"]) ->Fill(tpu->refpt->at(jpu),areaDiff,weight); + if (tpu->refpt->at(jpu)>1000) + dynamic_cast(histograms["p_areaVsoffset_1000"]) ->Fill(offset,areaDiff,weight); + if (tpu->refpt->at(jpu)>30 && tpu->refpt->at(jpu)<50) + dynamic_cast(histograms["p_areaVsoffset_30_50"]) ->Fill(offset,areaDiff,weight); + + dynamic_cast(histograms["p_drVsrefpt"])->Fill(tpu->refpt->at(jpu),tpu->refdrjt->at(jpu),weight); + dynamic_cast(histograms["m_refpt_diff"]) ->Fill(tpu->refpt->at(jpu) - tnopu->refpt->at(jnopu),weight); + dynamic_cast(histograms["m_refpdgid_diff"])->Fill(diff_pdgid,weight); + + if (idet == 0) { + dynamic_cast(histograms["p_rho_npv_refpt_BB"]) ->Fill(tpu->rho,tpu->npv,tpu->refpt->at(jpu),weight); + dynamic_cast(histograms["p_offsetOA_rho_npv_refpt_BB"])->Fill(tpu->rho,tpu->npv,tpu->refpt->at(jpu),offsetOA,weight); + } + + //Break into detector regions and PF candidate types + //nef,cef,muf,nhf,hfhf,hfef,chf + if(!algo1JetInfo.jetType.Contains("calo",TString::kIgnoreCase) && !algo2JetInfo.jetType.Contains("calo",TString::kIgnoreCase)) { + offset_PFcat = vector{tpu->jtpt->at(jpu)*tpu->jtnef->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtnef->at(jnopu), + tpu->jtpt->at(jpu)*tpu->jtcef->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtcef->at(jnopu), + tpu->jtpt->at(jpu)*tpu->jtmuf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtmuf->at(jnopu), + tpu->jtpt->at(jpu)*tpu->jtnhf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtnhf->at(jnopu), + tpu->jtpt->at(jpu)*tpu->jthfhf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jthfhf->at(jnopu), + tpu->jtpt->at(jpu)*tpu->jthfef->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jthfef->at(jnopu), + tpu->jtpt->at(jpu)*tpu->jtchf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtchf->at(jnopu)}; + } + else { + offset_PFcat = vector{0,0,0,0,0,0,0}; + } + for (int iPF=0;iPF(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF],weight); + hname = Form("p_offResOtnpuVsrefpt_%s_%s",detectorAbbreviation.Data(),PFstr[iPF].Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF]/tpu->tnpus->at(iIT),weight); + hname = Form("prof_offResVsrefpt_%s_%s",detectorAbbreviation.Data(),PFstr[iPF].Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF],weight); + hname = Form("prof_offResOtnpuVsrefpt_%s_%s",detectorAbbreviation.Data(),PFstr[iPF].Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF]/tpu->tnpus->at(iIT),weight); + } + hname = Form("p_offResVsrefpt_%s_all",detectorAbbreviation.Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_offResOtnpuVsrefpt_%s_all",detectorAbbreviation.Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/tpu->tnpus->at(iIT),weight); + hname = Form("prof_offResVsrefpt_%s_all",detectorAbbreviation.Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("prof_offResOtnpuVsrefpt_%s_all",detectorAbbreviation.Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/tpu->tnpus->at(iIT),weight); + } + + //Break into detector regions + hname = Form("p_resVsrefpt_%s",detectorAbbreviation.Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); + hname = Form("np_resVsrefpt_%s",detectorAbbreviation.Data()); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); + + //TNPU + hname = Form("p_resVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),itnpu_low,itnpu_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); + hname = Form("p_offresVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),itnpu_low,itnpu_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_offresVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_nopuresVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),itnpu_low,itnpu_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); + + //NPU + hname = Form("p_resVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),inpu_low,inpu_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); + hname = Form("p_offresVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),inpu_low,inpu_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_offresVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_nopuresVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),inpu_low,inpu_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); + + if(!reduceHistograms) { + //NPV + hname = Form("p_resVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); + hname = Form("p_offresVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_offresOrefptVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offsetOrefpt,weight); + hname = Form("p_offresVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_resnopuVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respTonopu,weight); + hname = Form("p_nopuresVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); + hname = Form("p_offAfterOoffBeforeVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/offset_raw,weight); + + //RHO + hname = Form("p_resVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); + hname = Form("p_offresVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_offresOrefptVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offsetOrefpt,weight); + hname = Form("p_offresVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + hname = Form("p_resnopuVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respTonopu,weight); + hname = Form("p_nopuresVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); + hname = Form("p_offAfterOoffBeforeVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); + dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/offset_raw,weight); + + //OTHER + hname = Form("p_resVsnpu_%s_pt%.1f_%.1f",detectorAbbreviation.Data(), + vpt[JetInfo::getBinIndex(tpu->refpt->at(jpu),vpt,NPtBins)],vpt[JetInfo::getBinIndex(tpu->refpt->at(jpu),vpt,NPtBins)+1]); + if(tpu->refpt->at(jpu)>10.0) { + dynamic_cast(histograms[hname])->Fill(tpu->npus->at(iIT),resp,weight); + } + for (unsigned int ipdgid=0; ipdgid(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); + } + } + + avg_offset += offset; + avg_offset_det[idet]+=offset; + njet_det[idet]+=1.; + + } // for matched jets + + avg_offset /= jetMap.size(); + for (int det=0;det(histograms[hname])->Fill(avg_offset_det[det],tpu->npv,weight); + hname = Form("p_rhoVsOff_%s",detectorAbbreviation.Data()); + dynamic_cast(histograms[hname])->Fill(avg_offset_det[det],tpu->rho,weight); + } + } + if(!reduceHistograms) { + dynamic_cast(histograms["p_npvVsoff"]) ->Fill(avg_offset,tpu->npv,weight); + dynamic_cast(histograms["p_rhoVsoff"]) ->Fill(avg_offset,tpu->rho,weight); + dynamic_cast(histograms["p_rhoVsRho"]) ->Fill(tpu->rho,tpu->rho,weight); + dynamic_cast(histograms["p_npvVsNpv"]) ->Fill(tpu->npv,tpu->npv,weight); + dynamic_cast(histograms["p_tnpuVsTnpu"]) ->Fill(tpu->tnpus->at(iIT),tpu->tnpus->at(iIT),weight); + dynamic_cast(histograms["p_npuVsNpu"]) ->Fill(tpu->npus->at(iIT),tpu->npus->at(iIT),weight); + dynamic_cast(histograms["p_matchedjet_off"])->Fill(avg_offset,jetMap.size(),weight); + } + + //========================================================= + // FILLING OF HISTOS ENDS HERE + //========================================================= + + return true; +} + +//______________________________________________________________________________ +void MatchEventsAndJets::RemoveHistograms(bool verbose) { + cout<::iterator it=histograms.begin(); it!=histograms.end(); ++it) { + if (!it->second->GetEntries()) { + if (verbose) cout<<"\tRemoving histogram "<first<second->SetDirectory(0); + } + } +} + +//______________________________________________________________________________ +void MatchEventsAndJets::WriteOutput(string outputPath, bool writeJetMap){ + cout << endl << "Writing file " << fout->GetName() << " ... " << flush; + fout->cd(); + for(map::const_iterator it=hsparse.begin(); it!=hsparse.end();it++) { + it->second->Write(); + } + fout->Write(); + fout->Close(); + cout << "DONE" << endl; + + if(writeJetMap && !doNotSaveFlag) { + cout << endl << "Saving the jetMapTree to a file for later use ... " << flush; + string outputFilename = "matchedEventsMaps_"+algo1+"_"+algo2+".root"; + if (algo1 == algo2) + outputFilename = "matchedEventsMaps_"+algo1+".root"; + outputFilename = outputPath+outputFilename; + TFile* mapFile = TFile::Open(outputFilename.c_str(),"UPDATE"); + jetMapTree->Write(); + mapFile->Close(); + cout << "DONE" << endl << endl; + } +} + +//////////////////////////////////////////////////////////////////////////////// +// main +//////////////////////////////////////////////////////////////////////////////// + +// ------------------------------------------------------------------ +int main(int argc,char**argv) +{ + CommandLine cl; + if (!cl.parse(argc,argv)) return 0; + string samplePU = cl.getValue ("samplePU"); + string sampleNoPU = cl.getValue ("sampleNoPU"); + string basepath = cl.getValue ("basepath", "/fdata/hepx/store/user/aperloff/"); + string algo1 = cl.getValue ("algo1", "ak4pf"); + string algo2 = cl.getValue ("algo2", "ak4pf"); + bool iftest = cl.getValue ("iftest", false); + unsigned maxEvts = cl.getValue ("maxEvts", 40000); + double minPhi = cl.getValue ("minPhi", 0.0); + double maxPhi = cl.getValue ("maxPhi", 0.0); + int nrefmax = cl.getValue ("nrefmax", -1); + bool useweight = cl.getValue ("useweight", false); + bool pThatReweight = cl.getValue ("pThatReweight", false); + double bias2SelectionRef = cl.getValue ("bias2SelectionRef", 15); + double bias2SelectionPow = cl.getValue ("bias2SelectionPow", 6.0); + string MCPUReWeighting = cl.getValue ("MCPUReWeighting", ""); + string MCPUHistoName = cl.getValue ("MCPUHistoName", "h_pileup"); + string DataPUReWeighting = cl.getValue ("DataPUReWeighting", ""); + string DataPUHistoName = cl.getValue ("DataPUHistoName", "pileup"); + bool ApplyJEC = cl.getValue ("ApplyJEC", true); + string JECpar = cl.getValue ("JECpar", "ParallelMCL1_L1FastJet_AK4PFchs.txt"); + string outputPath = cl.getValue ("outputPath", "./"); + string readEvtMaps = cl.getValue ("readEvtMaps", ""); + bool doNotSave = cl.getValue ("doNotSave", false); + string treeName = cl.getValue ("treeName", "t"); + int npvRhoNpuBinWidth = cl.getValue ("npvRhoNpuBinWidth", 10); + int NBinsNpvRhoNpu = cl.getValue ("NBinsNpvRhoNpu", 6); + vector vptBins = cl.getVector ("vptBins", "14:::18:::20:::24:::28:::30"); + bool reduceHistograms = cl.getValue ("reduceHistograms", true); + bool verbose = cl.getValue ("verbose", false); + bool help = cl.getValue ("help", false); + + if (help) {cl.print(); return 0;} + if (!cl.check()) return 0; + cl.print(); + + TBenchmark* m_benchmark = new TBenchmark(); + m_benchmark->Reset(); + m_benchmark->Start("event"); + + // + // Do some additional sanity checks + // + + // Check that if pThatReweight is set then useweight is also set + if(pThatReweight && !useweight) { + cout << "ERROR::jet_match_x Can't reweight the pThat spectrum without first using the existing" + << " weights to return to an unmodified spectrum. Set the \"useweight\" option to true." << endl; + return -1; + } + + gEnv->SetValue("TFile.AsyncPrefetching", 1); + + if(outputPath.empty()) outputPath = string(gSystem->pwd())+"/"; + if(outputPath.back() != '/') outputPath+='/'; + if(basepath.back() != '/') basepath+='/'; + + MatchEventsAndJets* mej = new MatchEventsAndJets(algo1,algo2,iftest); + mej->SetDoNotSaveFlag(doNotSave); + mej->SetMaxEvts(maxEvts); + mej->SetPhiRange(minPhi,maxPhi); + mej->SetNRefMax(nrefmax); + mej->SetWeightParameters(useweight,pThatReweight,bias2SelectionRef,bias2SelectionPow); + mej->SetupLumiWeights((DataPUReWeighting.empty())? "" : basepath+DataPUReWeighting, + (MCPUReWeighting.empty()) ? "" : basepath+MCPUReWeighting, + DataPUHistoName,MCPUHistoName); + mej->OpenInputFiles(basepath+samplePU,basepath+sampleNoPU); + mej->GetNtuples(treeName); + if(readEvtMaps.empty()) + mej->MakeMatchedEventsMaps(treeName,outputPath); + else + mej->ReadMatchedEventsMaps(readEvtMaps); + mej->OpenOutputFile(outputPath); + if (ApplyJEC) { + cout << "jet_match_x::Setting the JEC parameter file to " << JECpar << " ... "; + mej->SetJEC(JECpar); + cout << "DONE" << endl; + } + mej->SetNpvRhoNpuValues(NBinsNpvRhoNpu,npvRhoNpuBinWidth); + mej->SetVptBins(vptBins); + mej->DeclareHistograms(reduceHistograms); + mej->LoopOverEvents(verbose,reduceHistograms,readEvtMaps,outputPath); + // mej->RemoveHistograms(verbose); + mej->WriteOutput(outputPath, false && (readEvtMaps.empty()||!mej->JetMapTreeFound())); + + m_benchmark->Stop("event"); + cout << "jet_match_x" << endl + << "\tCPU time = " << m_benchmark->GetCpuTime("event") << " s" << endl + << "\tReal time = " << m_benchmark->GetRealTime("event") << " s" << endl; + delete m_benchmark; + + return 0; +} From f80e85a9adb3ebea696b966850c5298e33cb7949 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:47:19 +0200 Subject: [PATCH 04/19] Update jet_synchfit_x.cc --- JetAnalyzers/bin/jet_synchfit_x.cc | 1284 ++++++++++++++++++---------- 1 file changed, 833 insertions(+), 451 deletions(-) diff --git a/JetAnalyzers/bin/jet_synchfit_x.cc b/JetAnalyzers/bin/jet_synchfit_x.cc index b773609c..ab5e3c3c 100644 --- a/JetAnalyzers/bin/jet_synchfit_x.cc +++ b/JetAnalyzers/bin/jet_synchfit_x.cc @@ -11,6 +11,7 @@ #include "TProfile.h" #include "TProfile2D.h" #include "TProfile3D.h" +#include "TGraphErrors.h" #include "TGraph2DErrors.h" #include "TSystem.h" #include "TF2.h" @@ -25,194 +26,512 @@ #include "JetMETAnalysis/JetUtilities/interface/JetInfo.hh" #include "JetMETAnalysis/JetAnalyzers/interface/REStyle.h" - using namespace std; struct FitRes { - double etalowedge; - double etaupedge; - TF2 * fit; + double etalowedge; + double etaupedge; + TF2 * fit; }; - //=========================================================================== // This method returns the graph from all the TProfile3D's -TGraph2DErrors * getGraph2D(int iEta, const TProfile3D * prof, - const TProfile3D * profPt, - const TProfile3D * profRho){ - - // The returning graph, with its name and title - TGraph2DErrors *graph = new TGraph2DErrors(); - graph->SetName(Form("p_offOverA_RhoVsJetPt_%d",iEta)); - graph->SetTitle(Form("p_offOverA_RhoVsJetPt_%d;Rho;p_{T}^{pu};OffsetOverArea",iEta)); - int nEvt = 0; - cout << "\tNBins (rho,pT): (" << prof->GetYaxis()->GetNbins() << "," << prof->GetZaxis()->GetNbins() << ")" << endl; - //cout << "NBins rho: " << prof->GetYaxis()->GetNbins() << endl; - //cout << "NBins pT: " << prof->GetZaxis()->GetNbins() << endl; - - for (int irho = 1 ; irho <= prof->GetYaxis()->GetNbins() ; irho ++){ - for (int irefpt = 1; irefpt <= prof->GetZaxis()->GetNbins() ; irefpt++){ - - int Gbin = prof->GetBin(iEta, irho, irefpt); - nEvt += prof->GetBinEntries(Gbin); - // avoid points with empty content or too small error - if (prof ->GetBinError (iEta,irho,irefpt) > 0.000001 && - (fabs(prof->GetBinError(iEta,irho,irefpt)/prof->GetBinContent(iEta,irho,irefpt)))<0.5 &&// 0.3 ==> 0.5 - (fabs(prof->GetBinError(iEta,irho,irefpt)/prof->GetBinContent(iEta,irho,irefpt)))>0.01 &&// 0.05 ==> 0.01 - profPt ->GetBinContent(iEta,irho,irefpt) > 0 && - profPt ->GetBinError (iEta,irho,irefpt) > 0.1 && - profRho->GetBinContent(iEta,irho,irefpt) > 0 && - profRho->GetBinError (iEta,irho,irefpt) > 0.1 ) { - - // get the relevant values - double rho = profRho->GetBinContent(iEta, irho, irefpt); - double rhoe = profRho->GetBinError (iEta, irho, irefpt); - double pt = profPt ->GetBinContent(iEta, irho, irefpt); - double pte = profPt ->GetBinError (iEta, irho, irefpt); - double ooa = prof ->GetBinContent(iEta, irho, irefpt); - double ooae = prof ->GetBinError (iEta, irho, irefpt); - - // Store the values - double n = graph->GetN(); - graph->SetPoint(n, rho, pt, ooa); - graph->SetPointError(n, rhoe, pte, ooae); - - }//if - +TGraph2DErrors * getGraph2D(int iEta, TProfile3D * prof, + const TProfile3D * profPt, + const TProfile3D * profRho, + TH3I * hist){ + + // The returning graph, with its name and title + TGraph2DErrors *graph = new TGraph2DErrors(); + graph->SetName(Form("p_offOverA_RhoVsJetPt_%d",iEta)); + graph->SetTitle(Form("p_offOverA_RhoVsJetPt_%d Eta=%f-%f;Rho;p_{T}^{pu};OffsetOverArea",iEta,prof->GetXaxis()->GetBinLowEdge(iEta),prof->GetXaxis()->GetBinUpEdge(iEta))); + int nEvt = 0; + cout << "\tNBins (rho,pT): (" << prof->GetYaxis()->GetNbins() << "," << prof->GetZaxis()->GetNbins() << ")" << endl; + + double nJets = prof->GetEntries(); + + for (int itnpu = 1 ; itnpu <= prof->GetYaxis()->GetNbins() ; itnpu++){ + for (int irefpt = 1 ; irefpt <= prof->GetZaxis()->GetNbins() ; irefpt++){ + + int Gbin = prof->GetBin(iEta, itnpu, irefpt); + nEvt += prof->GetBinEntries(Gbin); + // avoid points with empty content or too small error + if (prof ->GetBinError (iEta,itnpu,irefpt) > 0.000001 && + // hist ->GetBinContent(iEta,itnpu,irefpt) >=20 && + fabs(prof ->GetBinContent (iEta,itnpu,irefpt)) != TMath::Infinity() && + prof ->GetBinError (iEta,itnpu,irefpt) < 5.0 && + prof ->GetBinEffectiveEntries(Gbin) > sqrt(nJets/(5.0E+06)) && + // (fabs(prof->GetBinError(iEta,itnpu,irefpt)/prof->GetBinContent(iEta,itnpu,irefpt)))<0.5 &&// 0.3 ==> 0.5 + // (fabs(prof->GetBinError(iEta,itnpu,irefpt)/prof->GetBinContent(iEta,itnpu,irefpt)))>0.01 &&// 0.05 ==> 0.01 + profPt ->GetBinContent(iEta,itnpu,irefpt) > 0 && + profPt ->GetBinError (iEta,itnpu,irefpt) > 0.1 && + // profPt ->GetBinError (iEta,itnpu,irefpt) < 10*log10(profPt ->GetBinContent(iEta,itnpu,irefpt)) && + profRho->GetBinContent(iEta,itnpu,irefpt) > 0 && + profRho->GetBinError (iEta,itnpu,irefpt) > 0.1){ + + // get the relevant values + double rho = profRho->GetBinContent(iEta, itnpu, irefpt); + double rhoe = profRho->GetBinError (iEta, itnpu, irefpt); + double pt = profPt ->GetBinContent(iEta, itnpu, irefpt); + double pte = profPt ->GetBinError (iEta, itnpu, irefpt); + double ooa = prof ->GetBinContent(iEta, itnpu, irefpt); + double ooae = prof ->GetBinError (iEta, itnpu, irefpt); + + // Store the values + int n = graph->GetN(); + graph->SetPoint(n, rho, pt, ooa); + graph->SetPointError(n, rhoe, pte, ooae); + + }//if + } // irefpt - - }// irho - - cout << "\tgraph has (Entries,Evts): (" << graph->GetN() << "," << nEvt << ")" << endl; - //cout<<"\tgraph has "<GetN()<<" entries"<<"& # of Evts: " << nEvt<< endl; - - // return it - return graph; - + + }// itnpu + + cout << "\tgraph has (Entries,Evts): (" << graph->GetN() << "," << nEvt << ")" << endl; + + return graph; + } // getGraph2D +//=========================================================================== +// +void fitClosurePlots(TProfile3D * prof, + const TProfile3D * profPt, + const TProfile3D * profRho, + vector fitResults, + TH3I * hist, + TFile* fout){ + + cout<<"Creating clousure plots"<mkdir("graphs"); + fout->mkdir("graphs/p_offOverA_EtaVsRho"); + fout->mkdir("graphs/p_offOverA_EtaVsJetPt"); + + fout->mkdir("residualgraphs"); + fout->mkdir("residualgraphs/p_offOverA_EtaVsRho"); + fout->mkdir("residualgraphs/p_offOverA_EtaVsJetPt"); + + fout->mkdir("histograms"); + fout->mkdir("histograms/eta"); + fout->mkdir("histograms/tnpu"); + fout->mkdir("histograms/refpt"); + + fout->mkdir("residual"); + fout->mkdir("residual/eta"); + fout->mkdir("residual/tnpu"); + fout->mkdir("residual/refpt"); + + fout->mkdir("rel_residual"); + fout->mkdir("rel_residual/eta"); + fout->mkdir("rel_residual/tnpu"); + fout->mkdir("rel_residual/refpt"); + + fout->mkdir("rmsplots"); + + vector refpt_hists, tnpu_hists, refpt_residual_hists, tnpu_residual_hists, refpt_relative_residual_hists, tnpu_relative_residual_hists; + + TH2D * h_rms = new TH2D("rms","rms",prof->GetNbinsX(),prof->GetXaxis()->GetXbins()->GetArray(),prof->GetNbinsZ(),prof->GetZaxis()->GetXbins()->GetArray()); + TH2D * h_mean = new TH2D("mean","mean",prof->GetNbinsX(),prof->GetXaxis()->GetXbins()->GetArray(),prof->GetNbinsZ(),prof->GetZaxis()->GetXbins()->GetArray()); + TH1D * h_eff_entries = new TH1D("eff_entries","eff_entries",1000,0,1000); + vector > v_rms; + + for (int itnpu = 1 ; itnpu <= prof->GetYaxis()->GetNbins() ; itnpu++) { + tnpu_hists.push_back((TH2D*)new TH2D(Form("itnpu_%d",itnpu),Form("itnpu_%d;#eta;refpt;ooa",itnpu),prof->GetXaxis()->GetNbins(),prof->GetXaxis()->GetXmin(),prof->GetXaxis()->GetXmax(),prof->GetZaxis()->GetNbins(),prof->GetZaxis()->GetXmin(),prof->GetZaxis()->GetXmax())); + tnpu_residual_hists.push_back((TH2D*)new TH2D(Form("itnpu_%d_residual",itnpu),Form("itnpu_%d_residual;#eta;refpt;ooa residual",itnpu),prof->GetNbinsX(),prof->GetXaxis()->GetXbins()->GetArray(),prof->GetNbinsZ(),prof->GetZaxis()->GetXbins()->GetArray())); + tnpu_residual_hists.back()->GetZaxis()->SetRangeUser(-10,10); + tnpu_relative_residual_hists.push_back((TH2D*)new TH2D(Form("itnpu_%d_relative_residual",itnpu),Form("itnpu_%d_relative_residual;#eta;refpt;ooa relative residual",itnpu),prof->GetNbinsX(),prof->GetXaxis()->GetXbins()->GetArray(),prof->GetNbinsZ(),prof->GetZaxis()->GetXbins()->GetArray())); + tnpu_relative_residual_hists.back()->GetZaxis()->SetRangeUser(-20,20); + } + for (int irefpt = 1 ; irefpt <= prof->GetZaxis()->GetNbins() ; irefpt++) { + refpt_hists.push_back((TH2D*)new TH2D(Form("irefpt_%d",irefpt),Form("irefpt_%d;#eta;tnpu;ooa",irefpt),prof->GetXaxis()->GetNbins(),prof->GetXaxis()->GetXmin(),prof->GetXaxis()->GetXmax(),prof->GetYaxis()->GetNbins(),prof->GetYaxis()->GetXmin(),prof->GetYaxis()->GetXmax())); + refpt_residual_hists.push_back((TH2D*)new TH2D(Form("irefpt_%d_residual",irefpt),Form("irefpt_%d_residual;#eta;tnpu;ooa residual",irefpt),prof->GetXaxis()->GetNbins(),prof->GetXaxis()->GetXmin(),prof->GetXaxis()->GetXmax(),prof->GetYaxis()->GetNbins(),prof->GetYaxis()->GetXmin(),prof->GetYaxis()->GetXmax())); + refpt_residual_hists.back()->GetZaxis()->SetRangeUser(-10,10); + refpt_relative_residual_hists.push_back((TH2D*)new TH2D(Form("irefpt_%d_relative_residual",irefpt),Form("irefpt_%d_relative_residual;#eta;tnpu;ooa relative residual",irefpt),prof->GetXaxis()->GetNbins(),prof->GetXaxis()->GetXmin(),prof->GetXaxis()->GetXmax(),prof->GetYaxis()->GetNbins(),prof->GetYaxis()->GetXmin(),prof->GetYaxis()->GetXmax())); + refpt_relative_residual_hists.back()->GetZaxis()->SetRangeUser(-20,20); + } + + //loop over eta bins + for (int iEta = 1 ; iEta <= prof->GetXaxis()->GetNbins() ; iEta++){ + cout<<"\r\tiEta: "<GetXaxis()->GetNbins()< pt_dummy; + v_rms.push_back(pt_dummy); + + TH2D* eta_hist = new TH2D(Form("iEta_%d",iEta),Form("iEta_%d;tnpu;refpt;ooa",iEta),prof->GetYaxis()->GetNbins(),prof->GetYaxis()->GetXmin(),prof->GetYaxis()->GetXmax(),prof->GetZaxis()->GetNbins(),prof->GetZaxis()->GetXmin(),prof->GetZaxis()->GetXmax()); + TH2D* eta_residual_hist = new TH2D(Form("iEta_%d_residual",iEta),Form("iEta_%d_residual;tnpu;refpt;ooa residual",iEta),prof->GetYaxis()->GetNbins(),prof->GetYaxis()->GetXmin(),prof->GetYaxis()->GetXmax(),prof->GetZaxis()->GetNbins(),prof->GetZaxis()->GetXmin(),prof->GetZaxis()->GetXmax()); + TH2D* eta_relative_residual_hist = new TH2D(Form("iEta_%d_relative_residual",iEta),Form("iEta_%d_relative_residual;tnpu;refpt;ooa relative residual",iEta),prof->GetYaxis()->GetNbins(),prof->GetYaxis()->GetXmin(),prof->GetYaxis()->GetXmax(),prof->GetZaxis()->GetNbins(),prof->GetZaxis()->GetXmin(),prof->GetZaxis()->GetXmax()); + eta_residual_hist->GetZaxis()->SetRangeUser(-10,10); + eta_relative_residual_hist->GetZaxis()->SetRangeUser(-20,20); + + vector rhographs, ptpugraphs; + vector rho_residual_graphs, ptpu_residual_graphs; + + for (int itnpu = 1 ; itnpu <= prof->GetYaxis()->GetNbins() ; itnpu++) { + ptpugraphs.push_back((TGraphErrors*)new TGraphErrors()); + ptpu_residual_graphs.push_back((TGraph*)new TGraphErrors()); + } + + for (int irefpt = 1 ; irefpt <= prof->GetZaxis()->GetNbins() ; irefpt++) { + rhographs.push_back((TGraphErrors*)new TGraphErrors()); + rho_residual_graphs.push_back((TGraph*)new TGraphErrors()); + v_rms[iEta-1].push_back(new TH1D(Form("rms_Eta_%d_refpt_%d",iEta,irefpt),Form("rms_%d_%d",iEta,irefpt),200,-100,100)); + } + + //loop over tnpu and refpt bins + for (int itnpu = 1 ; itnpu <= prof->GetYaxis()->GetNbins() ; itnpu++){ + for (int irefpt = 1 ; irefpt <= prof->GetZaxis()->GetNbins() ; irefpt++){ + + int Gbin = prof->GetBin(iEta, itnpu, irefpt); + // avoid points with empty content or too small error + if (prof ->GetBinError (iEta,itnpu,irefpt) > 0.000001 && + prof ->GetBinError (iEta,itnpu,irefpt) < 5.0 && + prof ->GetBinEffectiveEntries(Gbin) > 3 && //Add back for Flat2017 + // (fabs(prof->GetBinError(iEta,itnpu,irefpt)/prof->GetBinContent(iEta,itnpu,irefpt)))<0.5 &&// 0.3 ==> 0.5 + // (fabs(prof->GetBinError(iEta,itnpu,irefpt)/prof->GetBinContent(iEta,itnpu,irefpt)))>0.01 &&// 0.05 ==> 0.01 + profPt ->GetBinContent(iEta,itnpu,irefpt) > 0 && + profPt ->GetBinError (iEta,itnpu,irefpt) > 0.1 && + // profPt ->GetBinError (iEta,itnpu,irefpt) < 10*log10(profPt ->GetBinContent(iEta,itnpu,irefpt)) && + profRho->GetBinContent(iEta,itnpu,irefpt) > 0 && + profRho->GetBinError (iEta,itnpu,irefpt) > 0.1){ + + h_eff_entries->Fill(prof->GetBinEffectiveEntries(Gbin)); + + // get the relevant values + double rho = profRho->GetBinContent(iEta, itnpu, irefpt); + double rhoe = profRho->GetBinError (iEta, itnpu, irefpt); + double pt = profPt ->GetBinContent(iEta, itnpu, irefpt); + double pte = profPt ->GetBinError (iEta, itnpu, irefpt); + double ooa = prof ->GetBinContent(iEta, itnpu, irefpt); + double ooae = prof ->GetBinError (iEta, itnpu, irefpt); + + double fitooa = fitResults[iEta-1].fit->Eval(rho,pt); + + // Store the values + int nrho = rhographs[irefpt-1]->GetN(); + rhographs[irefpt-1]->SetPoint(nrho, rho, ooa); + rho_residual_graphs[irefpt-1]->SetPoint(nrho, rho, fitooa); + rhographs[irefpt-1]->SetPointError(nrho, rhoe, ooae); + int ntnpu = ptpugraphs[itnpu-1]->GetN(); + ptpugraphs[itnpu-1]->SetPoint(ntnpu, pt, ooa); + ptpu_residual_graphs[itnpu-1]->SetPoint(ntnpu, pt, fitooa); + ptpugraphs[itnpu-1]->SetPointError(ntnpu, pte, ooae); + + eta_hist->SetBinContent(itnpu,irefpt,ooa); + refpt_hists[irefpt-1]->SetBinContent(iEta,itnpu,ooa); + tnpu_hists[itnpu-1]->SetBinContent(iEta,irefpt,ooa); + + eta_residual_hist->SetBinContent(itnpu,irefpt,(ooa-fitooa)/ooae); + refpt_residual_hists[irefpt-1]->SetBinContent(iEta,itnpu,(ooa-fitooa)/ooae); + tnpu_residual_hists[itnpu-1]->SetBinContent(iEta,irefpt,(ooa-fitooa)/ooae); + + eta_relative_residual_hist->SetBinContent(itnpu,irefpt,100.0*(ooa-fitooa)/pt); + refpt_relative_residual_hists[irefpt-1]->SetBinContent(iEta,itnpu,100.0*(ooa-fitooa)/pt); + tnpu_relative_residual_hists[itnpu-1]->SetBinContent(iEta,irefpt,100.0*(ooa-fitooa)/pt); + + v_rms[iEta-1][irefpt-1]->Fill(ooa-fitooa); + + }//if + + }//irefpt + + } //itnpu + + fout->cd("rmsplots"); + + for (unsigned irefpt = 0; irefptWrite(); + h_rms->SetBinContent(iEta,irefpt,100*(v_rms[iEta-1][irefpt]->GetRMS())/(h_rms->GetYaxis()->GetBinCenter(irefpt))); + h_mean->SetBinContent(iEta,irefpt,100*(v_rms[iEta-1][irefpt]->GetMean())/(h_rms->GetYaxis()->GetBinCenter(irefpt))); + } + + if (eta_hist->GetEntries()){ + fout->cd("histograms/eta"); + eta_hist->SetStats(0); + eta_hist->Write(); + } + + if (eta_residual_hist->GetEntries()){ + fout->cd("residual/eta"); + eta_residual_hist->SetStats(0); + eta_residual_hist->Write(); + } + + if (eta_residual_hist->GetEntries()){ + fout->cd("rel_residual/eta"); + eta_relative_residual_hist->SetStats(0); + eta_relative_residual_hist->Write(); + } + + fout->mkdir(Form("graphs/p_offOverA_EtaVsRho/Eta%d",iEta)); + fout->cd(Form("graphs/p_offOverA_EtaVsRho/Eta%d",iEta)); + + + for (unsigned irefpt = 0; irefptGetN()) continue; + rhographs[irefpt]->SetNameTitle(Form("ieta_%d_irefpt_%d",iEta,irefpt+1),Form("ieta_%d_irefpt_%d;#rho;ooa",iEta,irefpt+1)); + rhographs[irefpt]->Write(); + } + + fout->mkdir(Form("graphs/p_offOverA_EtaVsJetPt/Eta%d",iEta)); + fout->cd(Form("graphs/p_offOverA_EtaVsJetPt/Eta%d",iEta)); + + for (unsigned itnpu = 0; itnpuGetN()) continue; + ptpugraphs[itnpu]->SetNameTitle(Form("ieta_%d_itnpu_%d",iEta,itnpu+1),Form("ieta_%d_itnpu_%d;p_{T}^{pu};ooa",iEta,itnpu+1)); + ptpugraphs[itnpu]->Write(); + } + + fout->mkdir(Form("residualgraphs/p_offOverA_EtaVsRho/Eta%d",iEta)); + fout->cd(Form("residualgraphs/p_offOverA_EtaVsRho/Eta%d",iEta)); + + for (unsigned irefpt = 0; irefptGetN()) continue; + rho_residual_graphs[irefpt]->SetNameTitle(Form("ieta_%d_irefpt_%d_residual",iEta,irefpt+1),Form("ieta_%d_irefpt_%d_residual;#rho;ooa",iEta+1,irefpt+1)); + rho_residual_graphs[irefpt]->Write(); + } + + fout->mkdir(Form("residualgraphs/p_offOverA_EtaVsJetPt/Eta%d",iEta)); + fout->cd(Form("residualgraphs/p_offOverA_EtaVsJetPt/Eta%d",iEta)); + + for (unsigned itnpu = 0; itnpuGetN()) continue; + ptpu_residual_graphs[itnpu]->SetNameTitle(Form("ieta_%d_itnpu_%d_residual",iEta,itnpu+1),Form("ieta_%d_itnpu_%d_residual;p_{T}^{pu};ooa",iEta,itnpu+1)); + ptpu_residual_graphs[itnpu]->Write(); + } + + }// iEta + + + fout->cd("histograms/refpt"); + + for (unsigned irefpt = 0; irefptGetEntries()){ + refpt_hists[irefpt]->SetStats(0); + refpt_hists[irefpt]->Write(); + } + + fout->cd("histograms/tnpu"); + + for (unsigned itnpu = 0; itnpuGetEntries()){ + tnpu_hists[itnpu]->SetStats(0); + tnpu_hists[itnpu]->Write(); + } + + fout->cd("residual/refpt"); + + for (unsigned irefpt = 0; irefptGetEntries()){ + refpt_residual_hists[irefpt]->SetStats(0); + refpt_residual_hists[irefpt]->Write(); + } + + fout->cd("residual/tnpu"); + + for (unsigned itnpu = 0; itnpuGetEntries()){ + tnpu_residual_hists[itnpu]->SetStats(0); + tnpu_residual_hists[itnpu]->Write(); + } + + fout->cd("rel_residual/refpt"); + + for (unsigned irefpt = 0; irefptGetEntries()){ + refpt_residual_hists[irefpt]->SetStats(0); + refpt_residual_hists[irefpt]->Write(); + } + + fout->cd("rel_residual/tnpu"); + + for (unsigned itnpu = 0; itnpuGetEntries()){ + tnpu_relative_residual_hists[itnpu]->SetStats(0); + tnpu_relative_residual_hists[itnpu]->Write(); + } + fout->cd("/"); + + h_rms->Write(); + h_mean->Write(); + h_eff_entries->Write(); + + cout<IsOpen()) { - cout << "ERROR jet_synchfit_xx::getInputProfiles() could not open file " - <IsOpen()) { + cout << "ERROR jet_synchfit_xx::getInputProfiles() could not open file " + <Get("p_offOverA_etaVsNpusVsJetPt"); //offOverA(eta, rho, refpt) - profPt = (TProfile3D*) fin->Get("p_PtAve_etaVsNpusVsJetPt"); // pt(eta, rho, refpt) - profRho = (TProfile3D*) fin->Get("p_RhoAve_etaVsNpusVsJetPt");// rho(eta, rho, refpt) - - if (!prof || !profPt || !profRho) { - cout<<"ERROR jet_synchfit_xx::getInputProfiles() could not retrieve TProfile3D named " - <<"either of p_offOverA_etaVsNpusVsJetPt, p_PtAve_etaVsNpusVsJetPt, " - <<" or p_RhoAve_etaVsNpusVsJetPt"<Get("p_offOverA_etaVsNpusVsJetPt"); //offOverA(eta, rho, refpt) + profPt = (TProfile3D*) fin->Get("p_PtAve_etaVsNpusVsJetPt"); // pt(eta, rho, refpt) + profRho = (TProfile3D*) fin->Get("p_RhoAve_etaVsNpusVsJetPt");// rho(eta, rho, refpt) + hist = (TH3I*) fin->Get("p_Events_etaVsNpusVsJetPt"); + + if (!prof || !profPt || !profRho || !hist) { + cout<<"ERROR jet_synchfit_xx::getInputProfiles() could not retrieve TProfile3D named " + <<"either of p_offOverA_etaVsNpusVsJetPt, p_PtAve_etaVsNpusVsJetPt, " + <<" or p_RhoAve_etaVsNpusVsJetPt"<Get("p_offOverA_etaVsTnpusVsJetPt"); //offOverA(eta, rho, refpt) - profPt = (TProfile3D*) fin->Get("p_PtAve_etaVsTnpusVsJetPt"); // pt(eta, rho, refpt) - profRho = (TProfile3D*) fin->Get("p_RhoAve_etaVsTnpusVsJetPt");// rho(eta, rho, refpt) - - if (!prof || !profPt || !profRho) { - cout<<"ERROR jet_synchfit_xx::getInputProfiles() could not retrieve TProfile3D named " - <<"either of p_offOverA_etaVsTnpusVsJetPt, p_PtAve_etaVsTnpusVsJetPt, " - <<" or p_RhoAve_etaVsTnpusVsJetPt"<Get("p_offOverA_etaVsTnpusVsJetPt"); //offOverA(eta, rho, refpt) + profPt = (TProfile3D*) fin->Get("p_PtAve_etaVsTnpusVsJetPt"); // pt(eta, rho, refpt) + profRho = (TProfile3D*) fin->Get("p_RhoAve_etaVsTnpusVsJetPt");// rho(eta, rho, refpt) + hist = (TH3I*) fin->Get("p_Events_etaVsTnpusVsJetPt"); + + if (!prof || !profPt || !profRho || !hist) { + cout<<"ERROR jet_synchfit_xx::getInputProfiles() could not retrieve TProfile3D named " + <<"either of p_offOverA_etaVsTnpusVsJetPt, p_PtAve_etaVsTnpusVsJetPt, " + <<" or p_RhoAve_etaVsTnpusVsJetPt"< pari; - static bool pari_set = false; - static vector > pari_lim; - TF2* f4 = 0; - TString function; - - if(functionType=="standard") { - if(!pari_set) { - pari = {-0.5,0.5,0.1}; - pari_set = true; - } - function = "[0]+([1]*x)*(1+[2]*log(y))"; - } - //simplistic - //static vector pari = {1.0,1.0,1.0,1.0,1.0,1.0}; - else if(functionType=="modifiedHandkerchief") { - //Handkerchief Function (modified) - pari = {-10.0,-1.0,-50.0,-40.0,0.0,0.0}; - //if(iEta>=13) pari = {-3.18926, -4.76974, -47.0724, -96.8174, 0.00414141, 0.00421783}; - //for(int iEta=1; iEta<=82; iEta++) {cout << iEta << ", " << 41-abs(iEta-41)+(iEta>41) << endl;} - if(41-abs(iEta-41)+(iEta>41)==41) pari = {-76.8447, 2.43371, -529.969, -120.342, -0.003042, -0.0101412}; - if(41-abs(iEta-41)+(iEta>41)==40) pari = {-51.3274, 1.56577, -791.884, -63.0554, -0.00656194, -0.022223}; - if(41-abs(iEta-41)+(iEta>41)==39) pari = {-44.4371, 1.29876, -408.899, -96.5217, -0.00222077, -0.0080116}; - if(41-abs(iEta-41)+(iEta>41)==38) pari = {-60.3835, 1.64388, -371.99, -141.497, -0.00144365, -0.00529115}; - if(41-abs(iEta-41)+(iEta>41)==37) pari = {5.27442, -4.63182, -229.582, -252.359, 0.00117086, 0.00190071}; - if(41-abs(iEta-41)+(iEta>41)==36) pari = {-186.495, 5.34063, -1188.95, -133.991, -0.00698784, -0.0231839}; - if(41-abs(iEta-41)+(iEta>41)==35) pari = {-89.5476, 2.66965, -516.026, -152.121, -0.00230586, -0.00778348}; - if(41-abs(iEta-41)+(iEta>41)==34) pari = {-115.907, 3.41263, -733.659, -150.294, -0.0034369, -0.0113916}; - if(41-abs(iEta-41)+(iEta>41)==33) pari = {-69.606, 2.13182, -622.055, -100.156, -0.00443436, -0.0146278}; - if(41-abs(iEta-41)+(iEta>41)==32) pari = {214.451, -7.86659, -1373.74, -128.697, 0.0100042, 0.0297094}; - if(41-abs(iEta-41)+(iEta>41)==31) pari = {-117.381, 3.31343, -733.61, -166.283, -0.00283487, -0.00952053}; - if(41-abs(iEta-41)+(iEta>41)==30) pari = {-137.85, 4.13062, -767.227, -164.92, -0.00362462, -0.0118522}; - if(41-abs(iEta-41)+(iEta>41)==29) pari = {41.4364, -2.90509, -1031.35, -170.149, 0.00154982, 0.00337273}; - if(41-abs(iEta-41)+(iEta>41)==28) pari = {-160.515, 4.55097, -937.38, -176.282, -0.00414836, -0.0136325}; - if(41-abs(iEta-41)+(iEta>41)==27) pari = {-124.973, 3.64175, -765.608, -166.264, -0.00348996, -0.0114105}; - if(41-abs(iEta-41)+(iEta>41)==26) pari = {-115.341, 3.38935, -710.485, -164.869, -0.00379213, -0.012158}; - if(41-abs(iEta-41)+(iEta>41)==25) pari = {-52.841, 1.74631, -220.896, -138.787, -0.00200547, -0.00626572}; - if(41-abs(iEta-41)+(iEta>41)==24) pari = {-109.378, 3.67646, -582.373, -155.86, -0.00462153, -0.0140837}; - if(41-abs(iEta-41)+(iEta>41)==23) pari = {-102.919, 3.88843, -487.29, -146.096, -0.00515363, -0.0151392}; - if(41-abs(iEta-41)+(iEta>41)==22) pari = {-129.424, 5.50359, -475.85, -139.099, -0.00747056, -0.021239}; - if(41-abs(iEta-41)+(iEta>41)==21) pari = {84.0723, -3.92998, -670.284, -45.9705, 0.00259347, 0.00480303}; - if(41-abs(iEta-41)+(iEta>41)==20) pari = {1.29218, -0.339506, 5.34299, -0.0245294, -0.00667469, -0.0138323}; - if(41-abs(iEta-41)+(iEta>41)==19) pari = {0.640088, 0.140856, -1.46036, -1.58256, -0.0167095, -0.0259715}; - if(41-abs(iEta-41)+(iEta>41)==18) pari = {22.3054, -1.83057, -181.977, -3.36615, -0.00531555, -0.0194336}; - if(41-abs(iEta-41)+(iEta>41)==17) pari = {59.6557, -2.6691, -630.216, -2.06518, 0.00313721, 0.00144351}; - if(41-abs(iEta-41)+(iEta>41)==16) pari = {1.02797, 0.00323455, 4.87806, 3.25137, -0.00244485, -0.0143917}; - if(41-abs(iEta-41)+(iEta>41)==15) pari = {-20.3957, 0.901549, -656.728, -7.57845, 0.00633164, 0.00913796}; - if(41-abs(iEta-41)+(iEta>41)==14) pari = {-3.2931, -4.7954, -35.0192, -96.693, 0.00409229, 0.00423637}; - if(41-abs(iEta-41)+(iEta>41)==13) pari = {3.0007, -4.9422, -58.2853, -91.3892, 0.00509591, 0.00612996}; - if(41-abs(iEta-41)+(iEta>41)==12) pari = {-2.76875, -2.13562, -370.079, -97.4652, 0.00404468, 0.00636189}; - if(41-abs(iEta-41)+(iEta>41)==11) pari = {-12.975, -1.0913, -1823.74, -104.751, 0.00369794, 0.007533}; - if(41-abs(iEta-41)+(iEta>41)==10) pari = {-48.4921, -2.92375, -385.236, -185.967, 0.00209605, 0.0025999}; - if(41-abs(iEta-41)+(iEta>41)==9) pari = {-36.7745, -4.33193, -172.6, -164.971, 0.00270432, 0.00296645}; - if(41-abs(iEta-41)+(iEta>41)==8) pari = {-53.8115, -0.0177498, -1133.33, -106.878, 0.00487379, 0.0102605}; - if(41-abs(iEta-41)+(iEta>41)==7) pari = {-37.0815, -5.62769, -103.859, -174.628, 0.00250659, 0.00236942}; - if(41-abs(iEta-41)+(iEta>41)==6) pari = {-14.5656, -1.79994, -440.529, -104.604, 0.0050598, 0.00911403}; - if(41-abs(iEta-41)+(iEta>41)==5) pari = {-3.06766, -4.74059, -81.701, -96.9543, 0.0055314, 0.00677566}; - if(41-abs(iEta-41)+(iEta>41)==4) pari = {-39.1683, -5.23999, -118.088, -226.798, 0.00148175, 0.00142602}; - if(41-abs(iEta-41)+(iEta>41)==3) pari = {-3.18926, -4.76974, -47.0724, -96.8174, 0.00414141, 0.00421783}; - if(41-abs(iEta-41)+(iEta>41)==2) pari = {-10.9249, -2.33964, -119.69, -115.437, 0.00285224, 0.00359828}; - if(41-abs(iEta-41)+(iEta>41)==1) pari = {-3.18926, -4.76974, -47.0724, -96.8174, 0.00414141, 0.00421783}; - - pari_lim = {make_pair(-100,100),make_pair(-100,100),make_pair(-10000,10000), - make_pair(-1000,1000),make_pair(-1,1),make_pair(-1,1)}; + static vector pari; + static bool pari_set = false; + static vector > pari_lim; + TF2* f4 = 0; + TString function; + + if(functionType=="standard") { + if(!pari_set) { + pari = {16,0.9,0.04}; + pari_set = true; + } + function = "[0]+([1]*(x))*(1+[2]*log(y))"; + } + + else if(functionType=="ak4") { + if(!pari_set) { +// pari = {15,1,-1,5,0,0}; //for complex +// pari = {15,1}; //for simple + pari = {15,1,-1}; //for semi simple + pari_set = true; + } +// function = "[0]+[1]*(x-20.0)+[2]*log(y/30.0)+[3]*pow(log(y/30.0),2)+[4]*(x-20.0)*log(y/30.0)+[5]*(x-20.0)*pow(log(y/30.0),2)"; //complex parametrization +// function = "[1]*(x-[0])*pow(y,0)"; //simple parametrization + function = "[1]*(x-[0])*(1.+[2]*log(y/15.))"; //semi simple parametrization + } + + else if(functionType=="ak8") { + if(!pari_set) { +// pari = {15,1,-1,5,0,0}; + pari = {15,1,-1}; + pari_set = true; + } +// function = "[0]+[1]*(x-20.0)+[2]*log(y/90.0)+[3]*pow(log(y/90.0),2)+[4]*(x-20.0)*log(y/90.0)+[5]*(x-20.0)*pow(log(y/90.0),2)"; + function = "[1]*(x-[0])*(1.+[2]*log(y/15.))"; //semi simple parametrization + } + + else if(functionType=="ak4_test") { + if(!pari_set) { + pari = {15,1,-1,5,0,0,0,0,0}; + pari_set = true; + } + function = "[0]+[1]*(x-20.0)+[2]*log(y/30.0)+[3]*pow(log(y/30.0),2)+[4]*(x-20.0)*log(y/30.0)+[5]*(x-20.0)*pow(log(y/30.0),2)+[6]*pow(x-20.0,2)+[7]*pow(x-20.0,2)*log(y/30.0)+[8]*pow(x-20.0,2)*pow(log(y/30.0),2)"; + } + + else if(functionType=="ak8_test") { + if(!pari_set) { + pari = {15,1,-1,5,0,0,0,0,0}; + pari_set = true; + } + function = "[0]+[1]*(x-20.0)+[2]*log(y/90.0)+[3]*pow(log(y/90.0),2)+[4]*(x-20.0)*log(y/90.0)+[5]*(x-20.0)*pow(log(y/90.0),2)+[6]*pow(x-20.0,2)+[7]*pow(x-20.0,2)*log(y/90.0)+[8]*pow(x-20.0,2)*pow(log(y/90.0),2)"; + } + + else if(functionType=="ak4_test2") { + if(!pari_set) { + pari = {15,1,-1,5,0}; + pari_set = true; + } + function = "[0]*(x-2)*(1+[1]*(x-20.0))*(1+[2]*log(y/30.0))+([3]+[4]*log(y))"; + } + + else if(functionType=="ak8_test2") { + if(!pari_set) { + pari = {15,1,-1,5,0}; + pari_set = true; + } + function = "[0]*(x-2)*(1+[1]*(x-20.0))*(1+[2]*log(y/90.0))+([3]+[4]*log(y))"; + } + + //simplistic + //static vector pari = {1.0,1.0,1.0,1.0,1.0,1.0}; + else if(functionType=="modifiedHandkerchief") { + //Handkerchief Function (modified) + pari = {-10.0,-1.0,-50.0,-40.0,0.0,0.0}; + //if(iEta>=13) pari = {-3.18926, -4.76974, -47.0724, -96.8174, 0.00414141, 0.00421783}; + //for(int iEta=1; iEta<=82; iEta++) {cout << iEta << ", " << 41-abs(iEta-41)+(iEta>41) << endl;} + if(41-abs(iEta-41)+(iEta>41)==41) pari = {-76.8447, 2.43371, -529.969, -120.342, -0.003042, -0.0101412}; + if(41-abs(iEta-41)+(iEta>41)==40) pari = {-51.3274, 1.56577, -791.884, -63.0554, -0.00656194, -0.022223}; + if(41-abs(iEta-41)+(iEta>41)==39) pari = {-44.4371, 1.29876, -408.899, -96.5217, -0.00222077, -0.0080116}; + if(41-abs(iEta-41)+(iEta>41)==38) pari = {-60.3835, 1.64388, -371.99, -141.497, -0.00144365, -0.00529115}; + if(41-abs(iEta-41)+(iEta>41)==37) pari = {5.27442, -4.63182, -229.582, -252.359, 0.00117086, 0.00190071}; + if(41-abs(iEta-41)+(iEta>41)==36) pari = {-186.495, 5.34063, -1188.95, -133.991, -0.00698784, -0.0231839}; + if(41-abs(iEta-41)+(iEta>41)==35) pari = {-89.5476, 2.66965, -516.026, -152.121, -0.00230586, -0.00778348}; + if(41-abs(iEta-41)+(iEta>41)==34) pari = {-115.907, 3.41263, -733.659, -150.294, -0.0034369, -0.0113916}; + if(41-abs(iEta-41)+(iEta>41)==33) pari = {-69.606, 2.13182, -622.055, -100.156, -0.00443436, -0.0146278}; + if(41-abs(iEta-41)+(iEta>41)==32) pari = {214.451, -7.86659, -1373.74, -128.697, 0.0100042, 0.0297094}; + if(41-abs(iEta-41)+(iEta>41)==31) pari = {-117.381, 3.31343, -733.61, -166.283, -0.00283487, -0.00952053}; + if(41-abs(iEta-41)+(iEta>41)==30) pari = {-137.85, 4.13062, -767.227, -164.92, -0.00362462, -0.0118522}; + if(41-abs(iEta-41)+(iEta>41)==29) pari = {41.4364, -2.90509, -1031.35, -170.149, 0.00154982, 0.00337273}; + if(41-abs(iEta-41)+(iEta>41)==28) pari = {-160.515, 4.55097, -937.38, -176.282, -0.00414836, -0.0136325}; + if(41-abs(iEta-41)+(iEta>41)==27) pari = {-124.973, 3.64175, -765.608, -166.264, -0.00348996, -0.0114105}; + if(41-abs(iEta-41)+(iEta>41)==26) pari = {-115.341, 3.38935, -710.485, -164.869, -0.00379213, -0.012158}; + if(41-abs(iEta-41)+(iEta>41)==25) pari = {-52.841, 1.74631, -220.896, -138.787, -0.00200547, -0.00626572}; + if(41-abs(iEta-41)+(iEta>41)==24) pari = {-109.378, 3.67646, -582.373, -155.86, -0.00462153, -0.0140837}; + if(41-abs(iEta-41)+(iEta>41)==23) pari = {-102.919, 3.88843, -487.29, -146.096, -0.00515363, -0.0151392}; + if(41-abs(iEta-41)+(iEta>41)==22) pari = {-129.424, 5.50359, -475.85, -139.099, -0.00747056, -0.021239}; + if(41-abs(iEta-41)+(iEta>41)==21) pari = {84.0723, -3.92998, -670.284, -45.9705, 0.00259347, 0.00480303}; + if(41-abs(iEta-41)+(iEta>41)==20) pari = {1.29218, -0.339506, 5.34299, -0.0245294, -0.00667469, -0.0138323}; + if(41-abs(iEta-41)+(iEta>41)==19) pari = {0.640088, 0.140856, -1.46036, -1.58256, -0.0167095, -0.0259715}; + if(41-abs(iEta-41)+(iEta>41)==18) pari = {22.3054, -1.83057, -181.977, -3.36615, -0.00531555, -0.0194336}; + if(41-abs(iEta-41)+(iEta>41)==17) pari = {59.6557, -2.6691, -630.216, -2.06518, 0.00313721, 0.00144351}; + if(41-abs(iEta-41)+(iEta>41)==16) pari = {1.02797, 0.00323455, 4.87806, 3.25137, -0.00244485, -0.0143917}; + if(41-abs(iEta-41)+(iEta>41)==15) pari = {-20.3957, 0.901549, -656.728, -7.57845, 0.00633164, 0.00913796}; + if(41-abs(iEta-41)+(iEta>41)==14) pari = {-3.2931, -4.7954, -35.0192, -96.693, 0.00409229, 0.00423637}; + if(41-abs(iEta-41)+(iEta>41)==13) pari = {3.0007, -4.9422, -58.2853, -91.3892, 0.00509591, 0.00612996}; + if(41-abs(iEta-41)+(iEta>41)==12) pari = {-2.76875, -2.13562, -370.079, -97.4652, 0.00404468, 0.00636189}; + if(41-abs(iEta-41)+(iEta>41)==11) pari = {-12.975, -1.0913, -1823.74, -104.751, 0.00369794, 0.007533}; + if(41-abs(iEta-41)+(iEta>41)==10) pari = {-48.4921, -2.92375, -385.236, -185.967, 0.00209605, 0.0025999}; + if(41-abs(iEta-41)+(iEta>41)==9) pari = {-36.7745, -4.33193, -172.6, -164.971, 0.00270432, 0.00296645}; + if(41-abs(iEta-41)+(iEta>41)==8) pari = {-53.8115, -0.0177498, -1133.33, -106.878, 0.00487379, 0.0102605}; + if(41-abs(iEta-41)+(iEta>41)==7) pari = {-37.0815, -5.62769, -103.859, -174.628, 0.00250659, 0.00236942}; + if(41-abs(iEta-41)+(iEta>41)==6) pari = {-14.5656, -1.79994, -440.529, -104.604, 0.0050598, 0.00911403}; + if(41-abs(iEta-41)+(iEta>41)==5) pari = {-3.06766, -4.74059, -81.701, -96.9543, 0.0055314, 0.00677566}; + if(41-abs(iEta-41)+(iEta>41)==4) pari = {-39.1683, -5.23999, -118.088, -226.798, 0.00148175, 0.00142602}; + if(41-abs(iEta-41)+(iEta>41)==3) pari = {-3.18926, -4.76974, -47.0724, -96.8174, 0.00414141, 0.00421783}; + if(41-abs(iEta-41)+(iEta>41)==2) pari = {-10.9249, -2.33964, -119.69, -115.437, 0.00285224, 0.00359828}; + if(41-abs(iEta-41)+(iEta>41)==1) pari = {-3.18926, -4.76974, -47.0724, -96.8174, 0.00414141, 0.00421783}; + + pari_lim = {make_pair(-100,100),make_pair(-100,100),make_pair(-10000,10000), + make_pair(-1000,1000),make_pair(-1,1),make_pair(-1,1)}; function = "[0]+([1]*pow(log10(y-[2]),3))+([4]*log10(y-[2])*pow(x-[3],2))+([5]*(pow(log10(y-[2]),2)-pow(x-[3],2)))"; //x(u,v)=u y(u,v)=v z(u,v)=1/3u^3+uv^2+2(u^2-v^2)// Handkerchief Surface http://mathworld.wolfram.com/HandkerchiefSurface.html - } - else if(functionType=="modifiedHandkerchief+rho") { + } + else if(functionType=="modifiedHandkerchief+rho") { if(41-abs(iEta-41)+(iEta>41)==41) pari = {-76.8447, 2.43371, -529.969, -120.342, -0.003042, -0.0101412, 0.5}; if(41-abs(iEta-41)+(iEta>41)==40) pari = {-51.3274, 1.56577, -791.884, -63.0554, -0.00656194, -0.022223, 0.5}; if(41-abs(iEta-41)+(iEta>41)==39) pari = {-44.4371, 1.29876, -408.899, -96.5217, -0.00222077, -0.0080116, 0.5}; @@ -256,332 +575,395 @@ TF2 * doGraphFitting(TGraph2DErrors * graph, bool highPU, string functionType, i if(41-abs(iEta-41)+(iEta>41)==1) pari = {-3.18926, -4.76974, -47.0724, -96.8174, 0.00414141, 0.00421783, 0.5}; pari_lim = {make_pair(-1000,1000),make_pair(-100,100),make_pair(-10000,10000), - make_pair(-1000,1000),make_pair(-1,1),make_pair(-1,1),make_pair(-10,10)}; - - function = "[0]+([6]*x)+([1]*pow(log10(y-[2]),3))+([4]*log10(y-[2])*pow(x-[3],2))+([5]*(pow(log10(y-[2]),2)-pow(x-[3],2)))"; - } - else if(functionType=="modifiedMonkeySaddle") { - //modified Monkey Saddle - //static vector pari = {5.0,-0.05,-10.0,3.0,3.0,-10.0,2.0}; - //static vector pari = {5.0,-10.0,-0.35,0.0,50.0,-4.0,150.0}; - if(!pari_set) { - pari = {0.0,0.33,1500.0,35.0,1.0,2.0,}; - pari_set = true; + make_pair(-1000,1000),make_pair(-1,1),make_pair(-1,1),make_pair(-10,10)}; + + function = "[0]+([6]*x)+([1]*pow(log10(y-[2]),3))+([4]*log10(y-[2])*pow(x-[3],2))+([5]*(pow(log10(y-[2]),2)-pow(x-[3],2)))"; } - } - else if(functionType=="puppi") { - if(!pari_set) { - pari = {18,-1.5,-0.35,0.0,1.0}; - //pari = {-0.5,0.5,0.1,0.0,1.0}; - pari_set = true; + else if(functionType=="modifiedMonkeySaddle") { + //modified Monkey Saddle + //static vector pari = {5.0,-0.05,-10.0,3.0,3.0,-10.0,2.0}; + //static vector pari = {5.0,-10.0,-0.35,0.0,50.0,-4.0,150.0}; + if(!pari_set) { + pari = {0.0,0.33,1500.0,35.0,1.0,2.0,}; + pari_set = true; + } } - function = "[0]+([1]*x)*(1+[2]*log(y))+(1/([3]*log(y)+[4]))"; - } - else if(functionType=="other") { - //Modified Monkey Saddle Function - //function = "[0]+([1]*pow(x,3))-[2]*x*pow(log(y-[3]),2)"; - //function = "[0]+([1]*pow(-x-[2],[3]))+([4]*x*pow(y-[5],[6]))"; - //KPedro - //function = "[0]+([1]*pow(-x-[2],3)*(y-[3]))-([4]*pow(y-[5],3)*(-x-[6]))"; - //KPedro2 - //function = "[0]+([1]*x*y)*TMath::Exp(-([2]*pow(x-[3],2)+[4]*pow(y-[5],2)))"; - //z=x(x^2-3y^2) // monkey saddle http://mathworld.wolfram.com/MonkeySaddle.html - //x^3*y-y^3*x //Pedro - //x*y*exp(-x^3*y-x*y^3) my creation - //x*exp(-x^2-y^2) //matlab example - //-(x*y)*Exp[-(x^2 + y^2)] //pedro - } - else if(functionType=="standard+taylorExpansion") { - if(!pari_set) { - pari = {-0.5,0.5,0.1}; - pari_set = true; + else if(functionType=="puppi") { + if(!pari_set) { + pari = {18,-1.5,-0.35,0.0,1.0}; + //pari = {-0.5,0.5,0.1,0.0,1.0}; + pari_set = true; + } + function = "[0]+([1]*x)*(1+[2]*log(y))+(1/([3]*log(y)+[4]))"; + } + else if(functionType=="other") { + //Modified Monkey Saddle Function + //function = "[0]+([1]*pow(x,3))-[2]*x*pow(log(y-[3]),2)"; + //function = "[0]+([1]*pow(-x-[2],[3]))+([4]*x*pow(y-[5],[6]))"; + //KPedro + //function = "[0]+([1]*pow(-x-[2],3)*(y-[3]))-([4]*pow(y-[5],3)*(-x-[6]))"; + //KPedro2 + //function = "[0]+([1]*x*y)*TMath::Exp(-([2]*pow(x-[3],2)+[4]*pow(y-[5],2)))"; + //z=x(x^2-3y^2) // monkey saddle http://mathworld.wolfram.com/MonkeySaddle.html + //x^3*y-y^3*x //Pedro + //x*y*exp(-x^3*y-x*y^3) my creation + //x*exp(-x^2-y^2) //matlab example + //-(x*y)*Exp[-(x^2 + y^2)] //pedro + } + else if(functionType=="standard+taylorExpansion") { + if(!pari_set) { + pari = {-0.5,0.5,0.1}; + pari_set = true; + } + //Taylor expanded version + function = "[0]+([1]*(x-11))*(1+[2]*(log(y)-1.47))"; } - //Taylor expanded version - function = "[0]+([1]*(x-11))*(1+[2]*(log(y)-1.47))"; - } - cout << "\tInitial Parameters: (" << flush; - for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); + if (functionType=="ak4") { +// f4->SetRange(0,30,70,100); //for simple parametrization, fits for pT:30-100GeV + f4->SetRange(0,8,70,6500); //for complex and semi simple parametrization, fits for pT:8-6500GeV } - f4->SetParLimits(0,-50,50); - f4->SetParLimits(1,0,10); - f4->SetParLimits(2,-2,5); - } - else if(functionType=="modifiedHandkerchief" || functionType=="modifiedHandkerchief+rho") { - for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); - f4->SetParLimits(ipar,pari_lim[ipar].first,pari_lim[ipar].second); + + if (functionType=="ak8") { + f4->SetRange(0,8,70,6500); } - } - else { - f4->SetParLimits(0,-10,25); - f4->SetParLimits(1,0,10); - f4->SetParLimits(2,-2,5); - } - //if (graph->GetN()<500) - //f4->FixParameter(2,0.05); - -/* if(fabs((prof->GetXaxis()->GetBinLowEdge(iEta)+ prof->GetXaxis()->GetBinLowEdge(iEta + 1))/2)>4.2){ - f4->FixParameter(2,0); - }*/ - - int nfits = 10; - int counter=0; - double rchi2; - do{ - graph->Fit(f4,"0QMER"); + if(functionType=="puppi") { + for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); + } + f4->SetParLimits(0,-50,50); + f4->SetParLimits(1,0,10); + f4->SetParLimits(2,-2,5); + } + else if(functionType=="modifiedHandkerchief" || functionType=="modifiedHandkerchief+rho") { + for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); + f4->SetParLimits(ipar,pari_lim[ipar].first,pari_lim[ipar].second); + } + } + + else { + for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); + } + } + + int nfits = 10; + int counter=0; + double rchi2; + do{ +// graph->Fit(f4,"0QMER"); + graph->Fit(f4,"MER"); rchi2 = f4->GetChisquare()/ f4->GetNDF(); counter++; if ((rchi2>9 || rchi2==0) && counter==nfits-2) { - //Reset initial parameters - cout << "\tResetting initial parameters" << endl; - for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); - } + //Reset initial parameters + cout << "\tResetting initial parameters" << endl; + for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); + } } - } while ((rchi2>9 || rchi2==0.0) && counter < nfits); - cout <<"N. of fits: " << counter << endl; - - cout << "\tFinal Parameters: ("; - for(unsigned int ipar=0; ipar9 || rchi2==0.0) && counter < nfits); + cout <<"N. of fits: " << counter << endl; + + cout << "\tFinal Parameters: ("; + for(unsigned int ipar=0; iparGetParameter(ipar) << "\u00b1" << f4->GetParError(ipar); if(ipar!=pari.size()-1) cout << ", "; else cout << ")" << endl; - } - cout << "\tchi2/NDF=" << rchi2 << endl; - - for(unsigned int ipar=0; iparGetTitle()); + outF << fname <<" Correction L1FastJet}"< & fitResults){ - - if(fitResults.size() == 0) // safety protection - return; - - // Create the stream - ofstream outF(txtFilename.Data()); - - // Produce the first line - //TString fname = Form("{1 JetEta 3 JetPt JetA Rho max(0.0001,1-y*(%s)/x)",fitResults[0].fit->GetTitle()); - TString fname = Form("{1 JetEta 3 Rho JetPt JetA max(0.0001,1-z*(%s)/y)",fitResults[0].fit->GetTitle()); - //outF <<"{1 JetEta 3 JetPt JetA Rho max(0.0001,1-y*([0]+([1]*z)*(1+[2]*log(x)))/x)" - outF << fname <<" Correction L1FastJet}"<GetNpar()+6) - <GetXmin()<GetXmax() - <GetYmin()<GetYmax() - <GetNpar()+6) + <GetXmin()<GetXmax() + <GetYmin()<GetYmax() + <GetNpar(); p++) { - outF<GetParameter(p); + outF<GetParameter(p); } outF< & fitResults){ - - if(fitResults.size() == 0) // safety protection - return; - - // The number of parameters in the fit. - // Assume all fitResults element have the same number - unsigned int nfitpars = fitResults[0].fit->GetNpar(); - - // Create the vectors veta from the histo, no hardcoding here - double veta[fitResults.size()+1]; - for (unsigned int l=0;l histos; - TString cname = "OffsetOverAreaVsRhoVsPt_"; - for (unsigned int h = 0 ; h < nfitpars ; h++){ - TString hname = cname + Form("_Par%i",h); - histos.push_back(new TH1D(hname,hname+ Form(";#eta;Par%i;",h), - fitResults.size() ,veta)); - } - // add the chi2/ndf line - histos.push_back(new TH1D(cname+"_CHI2NDF",cname+"_CHI2NDF"+ - ";#eta;#chi^{2}/ndf;", fitResults.size() ,veta)); - - // loop over the fits - for (unsigned int l=0; lSetBinContent(l+1, fitResults[l].fit->GetParameter(p)); - histos[p]->SetBinError (l+1, fitResults[l].fit->GetParError(p)); - } - - // add the red chi2 info - double redchi2 = fitResults[l].fit->GetChisquare()/ fitResults[l].fit->GetNDF(); - histos[nfitpars]->SetBinContent(l+1, redchi2); - histos[nfitpars]->SetBinError(l+1,2/sqrt(fitResults[l].fit->GetNDF())); - // for large NDF's the error on the mean of the redchi2 is 2/sqrt(n) ??, not sure... - - }// loop over fits - - // Make a directory to save the histograms - fout->mkdir("parameters"); - fout->cd("parameters"); - - // Create the canvas - TCanvas *cPar = new TCanvas("Par_","Par_",1000,1000); - cPar->cd(); - int nx=(int)std::sqrt((float)nfitpars+1); - int ny=nx; - if (nx*ny<(int)nfitpars+1) nx++; - if (nx*ny<(int)nfitpars+1) ny++; - cPar->Divide(nx,ny,1e-04,1e-04); - - // fill the pads - for (int unsigned h = 0 ; h < histos.size() ; h++){ - cPar->cd(h+1); - histos[h]->Draw("E"); - histos[h]->Write(); - } - - // Save the Canvas as pdf - cPar->SaveAs(pdfFilename); - - fout->cd(); - cPar->Write(); -}// createPDFFile(pdfFilename, fitResults); + if(fitResults.size() == 0) // safety protection + return; + + // The number of parameters in the fit. + // Assume all fitResults element have the same number + unsigned int nfitpars = fitResults[0].fit->GetNpar(); + + // Create the vectors veta from the histo, no hardcoding here + double veta[fitResults.size()+1]; + for (unsigned int l=0;l histos; + TString cname = "OffsetOverAreaVsRhoVsPt_"; + for (unsigned int h = 0 ; h < nfitpars ; h++){ + TString hname = cname + Form("_Par%i",h); + histos.push_back(new TH1D(hname,hname+ Form(";#eta;Par%i;",h), + fitResults.size() ,veta)); + } + // add the chi2/ndf line + histos.push_back(new TH1D(cname+"_CHI2NDF",cname+"_CHI2NDF"+ + ";#eta;#chi^{2}/ndf;", fitResults.size() ,veta)); + + // loop over the fits + for (unsigned int l=0; lSetBinContent(l+1, fitResults[l].fit->GetParameter(p)); + histos[p]->SetBinError (l+1, fitResults[l].fit->GetParError(p)); + } + + // add the red chi2 info + double redchi2 = fitResults[l].fit->GetChisquare()/ fitResults[l].fit->GetNDF(); + histos[nfitpars]->SetBinContent(l+1, redchi2); + histos[nfitpars]->SetBinError(l+1,2/sqrt(fitResults[l].fit->GetNDF())); + // for large NDF's the error on the mean of the redchi2 is 2/sqrt(n) ??, not sure... + + }// loop over fits + + // Make a directory to save the histograms + fout->mkdir("parameters"); + fout->cd("parameters"); + + // Create the canvas + TCanvas *cPar = new TCanvas("Par_","Par_",1000,1000); + cPar->cd(); + int nx=(int)std::sqrt((float)nfitpars+1); + int ny=nx; + if (nx*ny<(int)nfitpars+1) nx++; + if (nx*ny<(int)nfitpars+1) ny++; + cPar->Divide(nx,ny,1e-04,1e-04); + + // fill the pads + for (int unsigned h = 0 ; h < histos.size() ; h++){ + cPar->cd(h+1); + histos[h]->Draw("E"); + histos[h]->Write(); + } + + // Save the Canvas as pdf + cPar->SaveAs(pdfFilename); + + fout->cd(); + cPar->Write(); +}// createPDFFile(pdfFilename, fitResults); //=========================================================================== int main(int argc,char**argv){ - - CommandLine cl; - if (!cl.parse(argc,argv)) return 0; - string inputDir = cl.getValue ("inputDir", "./"); - string outputDir = cl.getValue ("outputDir", "./"); - string aalgo1 = cl.getValue ("algo1", "ak5pf"); - string aalgo2 = cl.getValue ("algo2", "ak5pf"); - bool highPU = cl.getValue ("highPU", false); - bool useNPU = cl.getValue ("useNPU", false); - string functionType = cl.getValue ("functionType", "standard"); - string era = cl.getValue ("era", ""); - - if (!cl.check()) return 0; - cl.print(); - - if(inputDir.empty()) inputDir = string(gSystem->pwd())+"/"; - if(outputDir.empty()) outputDir = string(gSystem->pwd())+"/"; - if(inputDir.back()!='/') inputDir +="/"; - if(outputDir.back()!='/') outputDir+="/"; - - TString algo1(aalgo1); - TString algo2(aalgo2); - - setREStyle(); - - TString algo12 = algo1+"_"+algo2; - if (algo1.EqualTo(algo2)) - algo12 = algo1; - -// Open the input file and retrieve all relevant TProfile3D's - TString inputFilename = inputDir+"output_"+algo12+".root"; - TProfile3D *prof=0, *profPt=0, *profRho=0; - if (!getInputProfiles(inputFilename, prof, profPt, profRho, useNPU)) - return 1; - -// Create the output file to store the graphs - TString rootFilename = outputDir+"Parameter_"+algo12+".root"; - TFile *fout = new TFile (rootFilename,"RECREATE"); - TString oDir = "p_offOverA_EtaVsRhoVsJetPt"; - fout->mkdir(oDir); - fout->cd(oDir); - -// The vector to save the results of all fits - vector fitResults; - -// Loop over all etas - for (int iEta = 1; iEta <= prof->GetXaxis()->GetNbins(); iEta++){ - //for (int iEta = 13; iEta <= 44; iEta++){ - - // Report to Screen - cout<< "Analyzing ieta="<GetN()<4){ - cout<<"\t WARNING: Graph has only " << graph->GetN() << " entries. Skipping eta" << endl; - continue; - } - - // Do the fitting - TF2 * fitfunc = doGraphFitting(graph, highPU, functionType, iEta, prof); - cout << "Fitted function" << endl << endl; - - // Put this fit result in the vector fitResults - FitRes fitres; - fitres.etalowedge = prof->GetXaxis()->GetBinLowEdge(iEta); - fitres.etaupedge = prof->GetXaxis()->GetBinUpEdge(iEta); - fitres.fit = fitfunc; - fitResults.push_back(fitres); - - // Save the graph to file - graph->Write(); - fitfunc->Write(); - }// eta bins - - // Create the txt file from the fitResults vector - TString txtFilename = outputDir+era+"_L1FastJet_"+((algo1.EqualTo(algo2)) ? JetInfo(algo12).alias : algo12)+".txt"; - createTxtFile(txtFilename, fitResults); - - // Create the canvas with all parameters vs eta. - TString pdfFilename = outputDir+"Parameter_"+algo12+".pdf"; - createPDFFile(fout, pdfFilename, fitResults); - - // close the file and clean up - fout->Close(); - delete fout; - - return 0; - -} // jet_synchfit_x + CommandLine cl; + if (!cl.parse(argc,argv)) return 0; + string inputDir = cl.getValue ("inputDir", "./"); + string outputDir = cl.getValue ("outputDir", "./"); + string aalgo1 = cl.getValue ("algo1", "ak5pf"); + string aalgo2 = cl.getValue ("algo2", "ak5pf"); + bool highPU = cl.getValue ("highPU", false); + bool useNPU = cl.getValue ("useNPU", false); + string functionType = cl.getValue ("functionType", "standard"); + string era = cl.getValue ("era", ""); + + if (!cl.check()) return 0; + cl.print(); + + if(inputDir.empty()) inputDir = string(gSystem->pwd())+"/"; + if(outputDir.empty()) outputDir = string(gSystem->pwd())+"/"; + if(inputDir.back()!='/') inputDir +="/"; + if(outputDir.back()!='/') outputDir+="/"; + + TString algo1(aalgo1); + TString algo2(aalgo2); + + setREStyle(); + + TString algo12 = algo1+"_"+algo2; + if (algo1.EqualTo(algo2)) + algo12 = algo1; + + // Open the input file and retrieve all relevant TProfile3D's + TString inputFilename = inputDir+"output_"+algo12+".root"; + TProfile3D *prof=0, *profPt=0, *profRho=0; + TH3I *hist=0; + if (!getInputProfiles(inputFilename, prof, profPt, profRho, hist, useNPU)) + return 1; + + // Create the output file to store the graphs + TString rootFilename = outputDir+"Parameter_"+algo12+".root"; + TFile *fout = new TFile (rootFilename,"RECREATE"); + fout->mkdir("p_offOverA_EtaVsRhoVsJetPt"); + fout->cd("p_offOverA_EtaVsRhoVsJetPt"); + + // The vector to save the results of all fits + vector fitResults; + + double etabin[82], Chi2NDF[82], Prob[82], Chi2[82], NDF[82]; + + + // Loop over all etas + for (int iEta = 1; iEta <= prof->GetXaxis()->GetNbins(); iEta++){ + //for (int iEta = 13; iEta <= 44; iEta++){ + + // Report to Screen + cout<< "Analyzing ieta="<GetN()<4){ + cout<<"\t WARNING: Graph has only " << graph->GetN() << " entries. Skipping eta" << endl; + continue; + } + + // Do the fitting + TF2 * fitfunc = doGraphFitting(graph, highPU, functionType, iEta, prof); + cout << "Fitted function" << endl << endl; + + // Put this fit result in the vector fitResults + FitRes fitres; + fitres.etalowedge = prof->GetXaxis()->GetBinLowEdge(iEta); + fitres.etaupedge = prof->GetXaxis()->GetBinUpEdge(iEta); + fitres.fit = fitfunc; + fitResults.push_back(fitres); + + // Save the graph to file + graph->Write(); + fitfunc->Write(); + + //===== for drawing graph Chi2/NDF vs Eta ===== + etabin[iEta-1] = (fitres.etalowedge+fitres.etaupedge)/2; +// cout<<"eta="<<(fitres.etalowedge+fitres.etaupedge)/2<GetYaxis()->SetTitle("Chi2/ndf"); + g_chi2ndf_vs_eta->GetXaxis()->SetTitle("eta"); + g_chi2ndf_vs_eta->SetMarkerStyle(20); + g_chi2ndf_vs_eta->Draw("AP"); + pad1->SaveAs(Form("%s/Chi2NDF_vs_eta.png",outputDir.data())); + + TGraph *g_prob_vs_eta = new TGraph(82, etabin, Prob); + TCanvas *pad2 = new TCanvas("pad2", "",1); + g_prob_vs_eta->GetYaxis()->SetTitle("Prob."); + g_prob_vs_eta->GetXaxis()->SetTitle("eta"); + g_prob_vs_eta->SetMarkerStyle(20); +// g_prob_vs_eta->GetYaxis()->SetRangeUser(0.,0.01); + g_prob_vs_eta->Draw("AP"); + pad2->SaveAs(Form("%s/Prob_vs_eta.png",outputDir.data())); + + TGraph *g_chi2_vs_eta = new TGraph(82, etabin, Chi2); + TCanvas *pad3 = new TCanvas("pad3", "",1); + g_chi2_vs_eta->GetYaxis()->SetTitle("Chi2"); + g_chi2_vs_eta->GetXaxis()->SetTitle("eta"); + g_chi2_vs_eta->SetMarkerStyle(20); + g_chi2_vs_eta->Draw("AP"); + pad3->SaveAs(Form("%s/Chi2_vs_eta.png",outputDir.data())); + + TGraph *g_ndf_vs_eta = new TGraph(82, etabin, NDF); + TCanvas *pad4 = new TCanvas("pad4", "",1); + g_ndf_vs_eta->GetYaxis()->SetTitle("NDF"); + g_ndf_vs_eta->GetXaxis()->SetTitle("eta"); + g_ndf_vs_eta->SetMarkerStyle(20); + g_ndf_vs_eta->Draw("AP"); + pad4->SaveAs(Form("%s/NDF_vs_eta.png",outputDir.data())); + + + fitClosurePlots(prof, profPt, profRho, fitResults, hist, fout); + + // Create the txt file from the fitResults vector + TString txtFilename = outputDir+era+"_L1FastJet_"+((algo1.EqualTo(algo2)) ? JetInfo(algo12).alias : algo12)+".txt"; + createTxtFile(txtFilename, fitResults); + + // Create the canvas with all parameters vs eta. + TString pdfFilename = outputDir+"Parameter_"+algo12+".pdf"; + createPDFFile(fout, pdfFilename, fitResults); + + // close the file and clean up + fout->Close(); + delete fout; + + return 0; + +} // jet_synchfit_x From a6ad4ec1874d1a84da856560763d260bf601cf13 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Wed, 28 Oct 2020 18:56:41 +0200 Subject: [PATCH 05/19] Update L2Creator.cc Implemented fitting approach with standard+gaussian function, along with a pt-clipping technique and sanity checks for the fits in all eta bins. --- JetUtilities/src/L2Creator.cc | 168 +++++++++++++++++++++++++++++++--- 1 file changed, 157 insertions(+), 11 deletions(-) diff --git a/JetUtilities/src/L2Creator.cc b/JetUtilities/src/L2Creator.cc index de67892a..83fc9a86 100644 --- a/JetUtilities/src/L2Creator.cc +++ b/JetUtilities/src/L2Creator.cc @@ -24,6 +24,7 @@ L2Creator::L2Creator() { histogramMetric = HistUtil::getHistogramMetricType(histMet); delphes = false; maxFitIter = 30; + ptclipfit=false; } //______________________________________________________________________________ @@ -46,6 +47,10 @@ L2Creator::L2Creator(CommandLine& cl) { histMet = cl.getValue ("histMet", "mu_h"); histogramMetric = HistUtil::getHistogramMetricType(histMet); + ptclip = cl.getValue ("ptclip", 0.); + statTh = cl.getValue ("statTh", 4); + ptclipfit = cl.getValue ("ptclipfit", false); + if (!cl.partialCheck()) return; cl.print(); } @@ -211,6 +216,14 @@ void L2Creator::loopOverEtaBins() { TH1F* hrsp(0); hl_rsp.begin_loop(); + //print fit results for all eta bins in a txt file + TString txtFitResultsFilename = outputDir + "Fit_Results.txt"; + ofstream FitResults(txtFitResultsFilename); + FitResults.setf(ios::right); + + //edw gia draw prob,chi2 vs eta + double etabin[82], Chi2NDF[82], Prob[82], Prob_0p009[82]; + while ((hrsp=hl_rsp.next_object(indices))) { unsigned int ieta=indices[0]; @@ -232,7 +245,7 @@ void L2Creator::loopOverEtaBins() { // only add points to the graphs if the current histo is not empty // the current setting might be a little high // - if (hrsp->GetEntries() > 4) {//hrsp->Integral()!=0) { + if (hrsp->GetEntries() > 30) {//hrsp->Integral()!=0) {//EDW 4 //TF1* frsp = (TF1*)hrsp->GetListOfFunctions()->Last(); //std::cout << "hrspName = " << hrsp->GetName() << ": frsp = " << frsp << std::endl; @@ -277,19 +290,23 @@ void L2Creator::loopOverEtaBins() { double eabsrsp = epeak; double abscor = 0.0; double eabscor = 0.0; - - if (absrsp > 0) { +//cout << "EDW 1 " << "eta" << vabscor_eta.back()->GetName() << "absrsp " << absrsp << " and eabsrsp " << eabsrsp << " and abscor " << abscor << " and eabscor " << eabscor << endl; + if (absrsp > 0 ) {//edw test abscor =1.0/absrsp; eabscor = abscor*abscor*epeak; + + +//cout << "EDW 2 " << "eta" << vabscor_eta.back()->GetName() << endl; } - if ((abscor>0) && (absrsp>0) && (eabscor>1e-5) && (eabscor/abscor<0.5) && (eabsrsp>1e-4) && (eabsrsp/absrsp<0.5)) { + if ((abscor>0) && (absrsp>0) && (eabscor>1e-5) && (eabscor/abscor<0.5) && (eabsrsp>1e-4) && (eabsrsp/absrsp<0.5)) { int n = vabsrsp_eta.back()->GetN(); vabsrsp_eta.back()->SetPoint (n,refpt, absrsp); vabsrsp_eta.back()->SetPointError(n,erefpt,eabsrsp); vabscor_eta.back()->SetPoint (n,jetpt, abscor); vabscor_eta.back()->SetPointError(n,ejetpt,eabscor); + // cout << "EDW 3" << "eta" << vabscor_eta.back()->GetName() << "refpt" << refpt << "jetpt" << jetpt << "absrsp " << absrsp << " and eabsrsp " << eabsrsp << " and abscor " << abscor << " and eabscor " << eabscor << endl; } - else cout << "absrsp " << absrsp << " and eabsrsp " << eabsrsp << " and abscor " << abscor << " and eabscor " << eabscor << endl; + //else cout << "EDW 4" << "absrsp " << absrsp << " and eabsrsp " << eabsrsp << " and abscor " << abscor << " and eabscor " << eabscor << endl; } // @@ -376,6 +393,25 @@ void L2Creator::loopOverEtaBins() { fabscor=new TF1("fit",fcn.Data(),xmin,xmax); setOfflinePFParameters(gabscor, fabscor,xmin,xmax); + std::cout<<"ieta = "<77){ //for PUPPI + fabscor->FixParameter(3,0.); + fabscor->FixParameter(6,0.); + } + } + if(l2pffit.Contains("spline",TString::kIgnoreCase)) { vabscor_eta_spline.back()->setPartialFunction(fabscor); } @@ -537,6 +573,54 @@ void L2Creator::loopOverEtaBins() { } } + + //edw ptclipfit + if (ptclipfit) + { + if (xmin > 0.0001) + { + int nPar = fabscor->GetNpar(); + int clipPar = nPar; + + TString clip = TString::Format("((x<10)*([%d]))+((x>=10)*("+(TString)fabscor->GetTitle()+"))", clipPar); + TF1 * fabscornew = new TF1(fabscor->GetName(), clip, 0.001, 6500); + for (int ip=0; ipSetParameter(ip, fabscor->GetParameter(ip)); + } + + fabscornew->SetParameter(clipPar, fabscor->Eval(xmin)); + + fabscornew->SetChisquare(fabscor->GetChisquare()); + fabscornew->SetNDF(fabscor->GetNDF()); + + fabscor = fabscornew; + gabscor->GetListOfFunctions()->Clear(); + gabscor->GetListOfFunctions()->AddLast(fabscor); + } + } + + //EDW print chi2 and prob for each fit in every eta bin + std::cout<<"Chi2/NDF = "<GetChisquare()/fabscor->GetNDF()<GetName()<<"\n"; + FitResults<<"Chi2/NDF = "<GetChisquare()<<"/"<GetNDF()<<" = "<GetChisquare()/fabscor->GetNDF()<<"\n"; + FitResults<<"Prob = "<GetProb()<<"\n\n\n"; + FitResults<<"Number of points = "<GetChisquare()/fabscor->GetNDF()>1000) {Chi2NDF[ieta] =0; cout<GetChisquare()/fabscor->GetNDF(); + + Prob[ieta] = fabscor->GetProb(); + if(fabscor->GetProb()<0.009) Prob_0p009[ieta] = fabscor->GetProb(); + else Prob_0p009[ieta] = 0.01; + + // // format the graphs // @@ -553,6 +637,36 @@ void L2Creator::loopOverEtaBins() { vabscor_eta_spline.push_back(nullptr); } } + + FitResults.close(); + + + //===== Draw graph Chi2/NDF vs Eta ===== + TGraph *g_chi2ndf_vs_eta = new TGraph(82, etabin, Chi2NDF); + TCanvas *pad1 = new TCanvas("pad1", "",1); + g_chi2ndf_vs_eta->GetYaxis()->SetTitle("Chi2/ndf"); + g_chi2ndf_vs_eta->GetXaxis()->SetTitle("eta"); + g_chi2ndf_vs_eta->SetMarkerStyle(20); + g_chi2ndf_vs_eta->Draw("AP"); + pad1->SaveAs(Form("%s/Chi2NDF_vs_eta.png",outputDir.Data())); + + TGraph *g_prob_vs_eta = new TGraph(82, etabin, Prob); + TCanvas *pad2 = new TCanvas("pad2", "",1); + g_prob_vs_eta->GetYaxis()->SetTitle("Prob."); + g_prob_vs_eta->GetXaxis()->SetTitle("eta"); + g_prob_vs_eta->SetMarkerStyle(20); + g_prob_vs_eta->Draw("AP"); + pad2->SaveAs(Form("%s/Prob_vs_eta.png",outputDir.Data())); + + TGraph *g_prob_0p009_vs_eta = new TGraph(82, etabin, Prob_0p009); + TCanvas *pad3 = new TCanvas("pad3", "",1); + g_prob_0p009_vs_eta->GetYaxis()->SetTitle("Prob"); + g_prob_0p009_vs_eta->GetXaxis()->SetTitle("eta"); + g_prob_0p009_vs_eta->SetMarkerStyle(20); + g_prob_0p009_vs_eta->Draw("AP"); + pad3->SaveAs(Form("%s/prob_0p009_vs_eta.png",outputDir.Data())); + + } //______________________________________________________________________________ @@ -804,7 +918,7 @@ void L2Creator::makeCanvas(string makeCanvasVariable) { spline_func->SetRange(bounds.first,bounds.second); spline_func->SetLineColor(igraph%nperpad+1); spline_func->SetLineStyle(kDotted); - spline_func->Draw("same"); +// spline_func->Draw("same"); } } @@ -874,7 +988,8 @@ TString L2Creator::getOfflinePFFunction() { return "[0]+([1]/(pow(log10(x),2)+[2]))+([3]*exp(-[4]*(log10(x)-[5])*(log10(x)-[5])))"; } else if(l2pffit.EqualTo("standard+Gaussian",TString::kIgnoreCase)) { - return "[0]+([1]/(pow(log10(x),2)+[2]))+([3]*exp(-([4]*((log10(x)-[5])*(log10(x)-[5])))))+([6]*exp(-([7]*((log10(x)-[8])*(log10(x)-[8])))))"; + return "[0]+([1]/(pow(log10(x),2)+[2]))+([3]*exp(-([4]*((log10(x)-[5])*(log10(x)-[5])))))+([6]*exp(-([7]*((log10(x)-[8])*(log10(x)-[8])))))"; +// return "[0]+[1]*pow(x,[2])+[3]*exp(-[4]*max(0.,(log10(x)-[5]))*(log10(x)-[5]))"; //Modification of 0,1,2 with powerlaw first term + single-sided log-gaus by Mikko } else if(l2pffit.EqualTo("LogNormal+Gaussian+fixed",TString::kIgnoreCase)) { return "([0]+TMath::LogNormal(TMath::Log10(x),[1],[2],[3]))+([4]+[5]/(pow(log10(x),2)+[6])+[7]*exp(-[8]*(log10(x)-[9])*(log10(x)-[9])))"; @@ -939,7 +1054,7 @@ void L2Creator::setOfflinePFParameters(TGraphErrors* gabscor, TF1* fabscor, doub fabscor->SetParLimits(4,0,100); } else if(l2pffit.EqualTo("standard+Gaussian",TString::kIgnoreCase)) { - fabscor->SetParameter(0,-0.0221278); +/* fabscor->SetParameter(0,-0.0221278); fabscor->SetParameter(1,119.265); fabscor->SetParameter(2,100); fabscor->SetParameter(3,-0.0679365); @@ -954,6 +1069,34 @@ void L2Creator::setOfflinePFParameters(TGraphErrors* gabscor, TF1* fabscor, doub fabscor->SetParLimits(4,0,500); fabscor->SetParLimits(0,-2,25); fabscor->SetParLimits(1,0,250); +*/ + fabscor->SetParameter(0,0.0221278); //v2 + fabscor->SetParameter(1,14.265); + fabscor->SetParameter(2,10); + fabscor->SetParameter(3,-0.0679365); + fabscor->SetParameter(4,2.82597); + fabscor->SetParameter(5,1.8277); + fabscor->SetParameter(6,-0.0679365); + fabscor->SetParameter(7,3.82597); + fabscor->SetParameter(8,1.8277); + fabscor->SetParLimits(6,-20,10); + fabscor->SetParLimits(7,0,100); + fabscor->SetParLimits(3,-15,15); + fabscor->SetParLimits(4,0,5); + fabscor->SetParLimits(5,0,50); + fabscor->SetParLimits(0,-2,50); + fabscor->SetParLimits(2,0,200); + fabscor->SetParLimits(1,0,250); + + +/* fabscor->SetRange(8.,3500.); + fabscor->SetParameter(0,1.09892); //Modification of 0,1,2 with powerlaw first term + single-sided log-gaus by Mikko + fabscor->SetParameter(1,-0.46266); + fabscor->SetParameter(2,-0.152203); + fabscor->SetParameter(3,0.0951505); + fabscor->SetParameter(4,1.16479); + fabscor->SetParameter(5,1.53048); +*/ } else if(l2pffit.EqualTo("LogNormal+Gaussian+fixed",TString::kIgnoreCase)) { fabscor->SetRange(3,2000); @@ -1313,6 +1456,7 @@ void L2Creator::writeTextFileForCurrentAlgorithm_spline() { //For eta-dependent spline clipping int pt_limit = 70; + float pt_clip = ptclip; unsigned int vector_size = 0; vector_size = vabscor_eta.size(); @@ -1345,6 +1489,7 @@ void L2Creator::writeTextFileForCurrentAlgorithm_spline() { bool abovePtLimit = false; bool lastLine = false; + bool firstline = true; for(int isection=0; isectiongetNSections(); isection++) { if(lastLine) continue; @@ -1364,7 +1509,7 @@ void L2Creator::writeTextFileForCurrentAlgorithm_spline() { //if(isection==spline->getNSections()-1) { // bounds.second = 6500; //} - + if(bounds.second < pt_clip) continue; if(isection==spline->getNSections()-1) lastLine = true; if(bounds.second >= pt_limit) { abovePtLimit = true; @@ -1373,16 +1518,17 @@ void L2Creator::writeTextFileForCurrentAlgorithm_spline() { //For expediency of Summer16_25nsV5_MC do eta-dependent clipping fout<getNpar()+2) //Number of parameters + 2 - <setParameters(isection); for(int p=0; pgetNpar(); p++) { fout<GetParameter(p); } fout< Date: Wed, 28 Oct 2020 19:00:40 +0200 Subject: [PATCH 06/19] Update jet_synchfit_x.cc Implemented 2D fitting approach with semi-simple parametrization (also complex and simple parametrizations, which were previously used are commented out), along with sanity checks for the fits in all eta bins. --- JetAnalyzers/bin/jet_synchfit_x.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JetAnalyzers/bin/jet_synchfit_x.cc b/JetAnalyzers/bin/jet_synchfit_x.cc index ab5e3c3c..cae70175 100644 --- a/JetAnalyzers/bin/jet_synchfit_x.cc +++ b/JetAnalyzers/bin/jet_synchfit_x.cc @@ -440,7 +440,7 @@ TF2 * doGraphFitting(TGraph2DErrors * graph, bool highPU, string functionType, i pari = {15,1,-1}; pari_set = true; } -// function = "[0]+[1]*(x-20.0)+[2]*log(y/90.0)+[3]*pow(log(y/90.0),2)+[4]*(x-20.0)*log(y/90.0)+[5]*(x-20.0)*pow(log(y/90.0),2)"; +// function = "[0]+[1]*(x-20.0)+[2]*log(y/90.0)+[3]*pow(log(y/90.0),2)+[4]*(x-20.0)*log(y/90.0)+[5]*(x-20.0)*pow(log(y/90.0),2)"; //complex parametrization function = "[1]*(x-[0])*(1.+[2]*log(y/15.))"; //semi simple parametrization } From 62c6b1c07972d7da248a8a11da8167a1acc25f81 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Wed, 28 Oct 2020 19:05:21 +0200 Subject: [PATCH 07/19] Update L2Creator.hh Added pt-clip for the fitting approach ---> ptclipfit (and for splines --->ptclip). --- JetUtilities/interface/L2Creator.hh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/JetUtilities/interface/L2Creator.hh b/JetUtilities/interface/L2Creator.hh index 35785efc..73f1a453 100644 --- a/JetUtilities/interface/L2Creator.hh +++ b/JetUtilities/interface/L2Creator.hh @@ -98,8 +98,8 @@ private: string input, era, l3input, histMet; TString output, outputDir, l2calofit, l2pffit; vector formats, algs; - bool l2l3, delphes; - int maxFitIter; + bool l2l3, delphes, ptclipfit; + int maxFitIter, statTh; HistUtil::HistogramMetric histogramMetric; TFile* ofile; TFile* ifile; @@ -116,6 +116,7 @@ private: vector vabscor_eta; vector vrelcor_eta; vector vabscor_eta_spline; + float ptclip; }; #endif From d7c2f592e90268a9b776a96ff6dd5bc45f95583c Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Tue, 3 Nov 2020 18:55:35 +0200 Subject: [PATCH 08/19] Create XrdClFileSystem_v2.hh A slightly modified script of the xrootd/XrdCl/XrdClFileSystem.hh one, in order to avoid compilation errors. --- JetAnalyzers/XrdClFileSystem_v2.hh | 759 +++++++++++++++++++++++++++++ 1 file changed, 759 insertions(+) create mode 100644 JetAnalyzers/XrdClFileSystem_v2.hh diff --git a/JetAnalyzers/XrdClFileSystem_v2.hh b/JetAnalyzers/XrdClFileSystem_v2.hh new file mode 100644 index 00000000..34acff93 --- /dev/null +++ b/JetAnalyzers/XrdClFileSystem_v2.hh @@ -0,0 +1,759 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) +// Author: Lukasz Janyst +//------------------------------------------------------------------------------ +// This file is part of the XRootD software suite. +// +// XRootD is free software: you can redistribute it and/or modify +// it under the terms of the GNU Lesser General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// XRootD is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with XRootD. If not, see . +// +// In applying this licence, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. +//------------------------------------------------------------------------------ + +#ifndef __XRD_CL_FILE_SYSTEM_HH__ +#define __XRD_CL_FILE_SYSTEM_HH__ + +#include "XrdCl/XrdClURL.hh" +#include "XrdCl/XrdClStatus.hh" +#include "XrdOuc/XrdOucEnum.hh" +#include "XrdOuc/XrdOucCompiler.hh" +#include "XrdCl/XrdClXRootDResponses.hh" +#include "XrdSys/XrdSysPthread.hh" +#include "XProtocol/XProtocol.hh" +#include +#include + +namespace XrdCl +{ + class PostMaster; + class Message; + class FileSystemPlugIn; + struct MessageSendParams; + + //---------------------------------------------------------------------------- + //! XRootD query request codes + //---------------------------------------------------------------------------- + struct QueryCode + { + //-------------------------------------------------------------------------- + //! XRootD query request codes + //-------------------------------------------------------------------------- + enum Code + { + Config = kXR_Qconfig, //!< Query server configuration + ChecksumCancel = kXR_Qckscan, //!< Query file checksum cancellation + Checksum = kXR_Qcksum, //!< Query file checksum + Opaque = kXR_Qopaque, //!< Implementation dependent + OpaqueFile = kXR_Qopaquf, //!< Implementation dependent + Prepare = kXR_QPrep, //!< Query prepare status + Space = kXR_Qspace, //!< Query logical space stats + Stats = kXR_QStats, //!< Query server stats + Visa = kXR_Qvisa, //!< Query file visa attributes + XAttr = kXR_Qxattr //!< Query file extended attributes + }; + }; + + //---------------------------------------------------------------------------- + //! Open flags, may be or'd when appropriate + //---------------------------------------------------------------------------- + struct OpenFlags + { + //-------------------------------------------------------------------------- + //! Open flags, may be or'd when appropriate + //-------------------------------------------------------------------------- + enum Flags + { + None = 0, //!< Nothing + Compress = kXR_compress, //!< Read compressed data for open (ignored), + //!< for kXR_locate return unique hosts + Delete = kXR_delete, //!< Open a new file, deleting any existing + //!< file + Force = kXR_force, //!< Ignore file usage rules, for kXR_locate + //!< it means ignoreing network dependencies + MakePath = kXR_mkpath, //!< Create directory path if it does not + //!< already exist + New = kXR_new, //!< Open the file only if it does not already + //!< exist + NoWait = kXR_nowait, //!< Open the file only if it does not cause + //!< a wait. For locate: provide a location as + //!< soon as one becomes known. This means + //!< that not all locations are necessarily + //!< returned. If the file does not exist a + //!< wait is still imposed. + Append = kXR_open_apnd, //!< Open only for appending + Read = kXR_open_read, //!< Open only for reading + Update = kXR_open_updt, //!< Open for reading and writing + Write = kXR_open_wrto, //!< Open only for writing + POSC = kXR_posc, //!< Enable Persist On Successful Close + //!< processing + Refresh = kXR_refresh, //!< Refresh the cached information on file's + //!< location. Voids NoWait. + Replica = kXR_replica, //!< The file is being opened for replica + //!< creation + SeqIO = kXR_seqio, //!< File will be read or written sequentially + PrefName = kXR_prefname //!< Hostname response is prefered, applies + //!< only to FileSystem::Locate + }; + }; + XRDOUC_ENUM_OPERATORS( OpenFlags::Flags ) + + //---------------------------------------------------------------------------- + //! Access mode + //---------------------------------------------------------------------------- + struct Access + { + //-------------------------------------------------------------------------- + //! Access mode + //-------------------------------------------------------------------------- + enum Mode + { + None = 0, + UR = kXR_ur, //!< owner readable + UW = kXR_uw, //!< owner writable + UX = kXR_ux, //!< owner executable/browsable + GR = kXR_gr, //!< group readable + GW = kXR_gw, //!< group writable + GX = kXR_gx, //!< group executable/browsable + OR = kXR_or, //!< world readable + OW = kXR_ow, //!< world writeable + OX = kXR_ox //!< world executable/browsable + }; + }; + XRDOUC_ENUM_OPERATORS( Access::Mode ) + + //---------------------------------------------------------------------------- + //! MkDir flags + //---------------------------------------------------------------------------- + struct MkDirFlags + { + enum Flags + { + None = 0, //!< Nothing special + MakePath = 1 //!< create the entire directory tree if it doesn't exist + }; + }; + XRDOUC_ENUM_OPERATORS( MkDirFlags::Flags ) + + //---------------------------------------------------------------------------- + //! DirList flags + //---------------------------------------------------------------------------- + struct DirListFlags + { + enum Flags + { + None = 0, //!< Nothing special + Stat = 1, //!< Stat each entry + Locate = 2, //!< Locate all servers hosting the directory and send + //!< the dirlist request to all of them + Recursive = 4, //!< Do a recursive listing + Merge = 8, //!< Merge duplicates + Chunked = 16, //!< Serve chunked results for better performance + Zip = 32 //!< List content of ZIP files + }; + }; + XRDOUC_ENUM_OPERATORS( DirListFlags::Flags ) + + //---------------------------------------------------------------------------- + //! Prepare flags + //---------------------------------------------------------------------------- + struct PrepareFlags + { + enum Flags + { + None = 0, //!< no flags + Colocate = kXR_coloc, //!< co-locate staged files, if possible + Fresh = kXR_fresh, //!< refresh file access time even if + //!< the location is known + Stage = kXR_stage, //!< stage the file to disk if it is not + //!< online + WriteMode = kXR_wmode, //!< the file will be accessed for + //!< modification + Cancel = kXR_cancel, //!< cancel staging request + Evict = kXR_wait << 8 //!< evict the file from disk cache + //!< we have to shift kXR_evict as its value + //!< is the same as cancel's because this + //!< flag goes to options extension + }; + }; + XRDOUC_ENUM_OPERATORS( PrepareFlags::Flags ) + + //---------------------------------------------------------------------------- + //! Send file/filesystem queries to an XRootD cluster + //---------------------------------------------------------------------------- + class FileSystem + { + friend class AssignLBHandler; + friend class ForkHandler; + + public: + typedef std::vector LocationList; //!< Location list + + //------------------------------------------------------------------------ + //! Constructor + //! + //! @param url URL of the entry-point server to be contacted + //! @param enablePlugIns enable the plug-in mechanism for this object + //------------------------------------------------------------------------ + FileSystem( const URL &url, bool enablePlugIns = true ); + + //------------------------------------------------------------------------ + //! Destructor + //------------------------------------------------------------------------ + ~FileSystem(); + + //------------------------------------------------------------------------ + //! Locate a file - async + //! + //! @param path path to the file to be located + //! @param flags some of the OpenFlags::Flags + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a Buffer object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Locate( const std::string &path, + OpenFlags::Flags flags, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Locate a file - sync + //! + //! @param path path to the file to be located + //! @param flags some of the OpenFlags::Flags + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Locate( const std::string &path, + OpenFlags::Flags flags, + LocationInfo *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Locate a file, recursively locate all disk servers - async + //! + //! @param path path to the file to be located + //! @param flags some of the OpenFlags::Flags + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a Buffer object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus DeepLocate( const std::string &path, + OpenFlags::Flags flags, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Locate a file, recursively locate all disk servers - sync + //! + //! @param path path to the file to be located + //! @param flags some of the OpenFlags::Flags + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus DeepLocate( const std::string &path, + OpenFlags::Flags flags, + LocationInfo *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Move a directory or a file - async + //! + //! @param source the file or directory to be moved + //! @param dest the new name + //! @param handler handler to be notified when the response arrives, + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Mv( const std::string &source, + const std::string &dest, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Move a directory or a file - sync + //! + //! @param source the file or directory to be moved + //! @param dest the new name + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Mv( const std::string &source, + const std::string &dest, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain server information - async + //! + //! @param queryCode the query code as specified in the QueryCode struct + //! @param arg query argument + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a Buffer object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Query( QueryCode::Code queryCode, + const Buffer &arg, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain server information - sync + //! + //! @param queryCode the query code as specified in the QueryCode struct + //! @param arg query argument + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Query( QueryCode::Code queryCode, + const Buffer &arg, + Buffer *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Truncate a file - async + //! + //! @param path path to the file to be truncated + //! @param size file size + //! @param handler handler to be notified when the response arrives + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Truncate( const std::string &path, + uint64_t size, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Truncate a file - sync + //! + //! @param path path to the file to be truncated + //! @param size file size + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Truncate( const std::string &path, + uint64_t size, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Remove a file - async + //! + //! @param path path to the file to be removed + //! @param handler handler to be notified when the response arrives + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Rm( const std::string &path, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Remove a file - sync + //! + //! @param path path to the file to be removed + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Rm( const std::string &path, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Create a directory - async + //! + //! @param path path to the directory + //! @param flags or'd MkDirFlags + //! @param mode access mode, or'd Access::Mode + //! @param handler handler to be notified when the response arrives + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus MkDir( const std::string &path, + MkDirFlags::Flags flags, + Access::Mode mode, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Create a directory - sync + //! + //! @param path path to the directory + //! @param flags or'd MkDirFlags + //! @param mode access mode, or'd Access::Mode + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus MkDir( const std::string &path, + MkDirFlags::Flags flags, + Access::Mode mode, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Remove a directory - async + //! + //! @param path path to the directory to be removed + //! @param handler handler to be notified when the response arrives + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus RmDir( const std::string &path, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Remove a directory - sync + //! + //! @param path path to the directory to be removed + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus RmDir( const std::string &path, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Change access mode on a directory or a file - async + //! + //! @param path file/directory path + //! @param mode access mode, or'd Access::Mode + //! @param handler handler to be notified when the response arrives + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus ChMod( const std::string &path, + Access::Mode mode, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Change access mode on a directory or a file - sync + //! + //! @param path file/directory path + //! @param mode access mode, or'd Access::Mode + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus ChMod( const std::string &path, + Access::Mode mode, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Check if the server is alive - async + //! + //! @param handler handler to be notified when the response arrives + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Ping( ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Check if the server is alive - sync + //! + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Ping( uint16_t timeout = 0 ) XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain status information for a path - async + //! + //! @param path file/directory path + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a StatInfo object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Stat( const std::string &path, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain status information for a path - sync + //! + //! @param path file/directory path + //! @param response the response (to be deleted by the user only if the + //! procedure is successful) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Stat( const std::string &path, + StatInfo *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain status information for a Virtual File System - async + //! + //! @param path file/directory path + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a StatInfoVFS object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus StatVFS( const std::string &path, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain status information for a Virtual File System - sync + //! + //! @param path file/directory path + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus StatVFS( const std::string &path, + StatInfoVFS *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain server protocol information - async + //! + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a ProtocolInfo object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Protocol( ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Obtain server protocol information - sync + //! + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Protocol( ProtocolInfo *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! List entries of a directory - async + //! + //! @param path directory path + //! @param flags currently unused + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a DirectoryList + //! object if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus DirList( const std::string &path, + DirListFlags::Flags flags, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! List entries of a directory - sync + //! + //! @param path directory path + //! @param flags DirListFlags + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus DirList( const std::string &path, + DirListFlags::Flags flags, + DirectoryList *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Send info to the server (up to 1024 characters)- async + //! + //! @param info the info string to be sent + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a Buffer object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus SendInfo( const std::string &info, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Send info to the server (up to 1024 characters) - sync + //! + //! @param info the info string to be sent + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus SendInfo( const std::string &info, + Buffer *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Prepare one or more files for access - async + //! + //! @param fileList list of files to be prepared + //! @param flags PrepareFlags::Flags + //! @param priority priority of the request 0 (lowest) - 3 (highest) + //! @param handler handler to be notified when the response arrives, + //! the response parameter will hold a Buffer object + //! if the procedure is successful + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Prepare( const std::vector &fileList, + PrepareFlags::Flags flags, + uint8_t priority, + ResponseHandler *handler, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Prepare one or more files for access - sync + //! + //! @param fileList list of files to be prepared + //! @param flags PrepareFlags::Flags + //! @param priority priority of the request 0 (lowest) - 3 (highest) + //! @param response the response (to be deleted by the user) + //! @param timeout timeout value, if 0 the environment default will + //! be used + //! @return status of the operation + //------------------------------------------------------------------------ + XRootDStatus Prepare( const std::vector &fileList, + PrepareFlags::Flags flags, + uint8_t priority, + Buffer *&response, + uint16_t timeout = 0 ) + XRD_WARN_UNUSED_RESULT; + + //------------------------------------------------------------------------ + //! Set filesystem property + //! + //! Filesystem properties: + //! FollowRedirects [true/false] - enable/disable following redirections + //------------------------------------------------------------------------ + bool SetProperty( const std::string &name, const std::string &value ); + + //------------------------------------------------------------------------ + //! Get filesystem property + //! + //! @see FileSystem::SetProperty for property list + //------------------------------------------------------------------------ + bool GetProperty( const std::string &name, std::string &value ) const; + + private: + FileSystem(const FileSystem &other); + FileSystem &operator = (const FileSystem &other); + + //------------------------------------------------------------------------ + // Send a message in a locked environment + //------------------------------------------------------------------------ + Status Send( Message *msg, + ResponseHandler *handler, + MessageSendParams ¶ms ); + + //------------------------------------------------------------------------ + // Assign a load balancer if it has not already been assigned + //------------------------------------------------------------------------ + void AssignLoadBalancer( const URL &url ); + + //------------------------------------------------------------------------ + // Lock the internal lock + //------------------------------------------------------------------------ + void Lock() + { + pMutex.Lock(); + } + + //------------------------------------------------------------------------ + // Unlock the internal lock + //------------------------------------------------------------------------ + void UnLock() + { + pMutex.UnLock(); + } + + XrdSysMutex pMutex; + bool pLoadBalancerLookupDone; + bool pFollowRedirects; + URL *pUrl; + FileSystemPlugIn *pPlugIn; + }; +} + +#endif // __XRD_CL_FILE_SYSTEM_HH__ From f024f83c3f8d5a2f2d5da7513ba0629e29cfea07 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Tue, 3 Nov 2020 18:57:38 +0200 Subject: [PATCH 09/19] Update jet_correction_analyzer_x.cc This change includes the XrdClFileSystem_v2.hh script instead of the XrdClFileSystem.hh so as to avoid compilation errors. --- JetAnalyzers/bin/jet_correction_analyzer_x.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JetAnalyzers/bin/jet_correction_analyzer_x.cc b/JetAnalyzers/bin/jet_correction_analyzer_x.cc index 6e855588..6636e690 100644 --- a/JetAnalyzers/bin/jet_correction_analyzer_x.cc +++ b/JetAnalyzers/bin/jet_correction_analyzer_x.cc @@ -19,7 +19,7 @@ #include "PhysicsTools/Utilities/interface/LumiReWeighting.h" #if __has_include("xrootd/XrdCl/XrdClFileSystem.hh") //#include "xrootd/XrdCl/XrdClFileSystem.hh" -#include "condor/XrdClFileSystem_v2.hh" +#include "JetMETAnalysis/JetAnalyzers/XrdClFileSystem_v2.hh" #define has_xrdcl 1 #else #define has_xrdcl 0 From 8c368709d591eec5eaeadb63a98ae02e541b2744 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Thu, 5 Nov 2020 18:27:26 +0200 Subject: [PATCH 10/19] Update jet_correction_analyzer_x.cc --- JetAnalyzers/bin/jet_correction_analyzer_x.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/JetAnalyzers/bin/jet_correction_analyzer_x.cc b/JetAnalyzers/bin/jet_correction_analyzer_x.cc index 6636e690..e96288c0 100644 --- a/JetAnalyzers/bin/jet_correction_analyzer_x.cc +++ b/JetAnalyzers/bin/jet_correction_analyzer_x.cc @@ -604,13 +604,6 @@ int main(int argc,char**argv) if(nrefmax>0 && JRAEvt->nref>nrefmax) JRAEvt->nref = nrefmax; for (unsigned char iref=0;irefnref;iref++) { - /* - //=== veto region for UL2017 ======= - //if((JRAEvt->jtphi->at(iref)<-0.5236 && JRAEvt->jtphi->at(iref)>-0.8727 && JRAEvt->jteta->at(iref) >1.31 && JRAEvt->jteta->at(iref)<2.96) || (JRAEvt->jtphi->at(iref)>2.705 && JRAEvt->jtphi->at(iref)<3.1416 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.4835) )continue; - //=== veto region for UL2018 ======= - //if((JRAEvt->jtphi->at(iref)<-0.8727 && JRAEvt->jtphi->at(iref)>-1.5708 && JRAEvt->jteta->at(iref) < -1.31 && JRAEvt->jteta->at(iref)> -2.96) || (JRAEvt->jtphi->at(iref)>0.4363 && JRAEvt->jtphi->at(iref)<0.7854 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.31) )continue; -*/ -// if(JRAEvt->npv>0 && JRAEvt->npv<10){ //nVtx cut starts here float rho = JRAEvt->rho; float rho_hlt = (0!=chain->GetBranch("rho_hlt")) ? JRAEvt->rho_hlt : 0; float ptgen = JRAEvt->refpt->at(iref); @@ -866,7 +859,6 @@ int main(int argc,char**argv) ThetaDistribution ->Fill(theta); SolidAngleDist ->Fill(2*TMath::Pi()*cos(theta)); } -// }//nVtx ends here }//for (unsigned char iref=0;iref Date: Thu, 5 Nov 2020 18:32:50 +0200 Subject: [PATCH 11/19] Update jet_response_analyzer_x.cc --- JetAnalyzers/bin/jet_response_analyzer_x.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/JetAnalyzers/bin/jet_response_analyzer_x.cc b/JetAnalyzers/bin/jet_response_analyzer_x.cc index 18ee9a63..8482ca68 100644 --- a/JetAnalyzers/bin/jet_response_analyzer_x.cc +++ b/JetAnalyzers/bin/jet_response_analyzer_x.cc @@ -1478,12 +1478,6 @@ int main(int argc,char**argv) if (nrefmax>0) JRAEvt->nref = std::min((int)JRAEvt->nref,nrefmax); for (unsigned char iref=0;irefnref;iref++) { - /* - //=== veto region for UL2017 ======= - //if((JRAEvt->jtphi->at(iref)<-0.5236 && JRAEvt->jtphi->at(iref)>-0.8727 && JRAEvt->jteta->at(iref) >1.31 && JRAEvt->jteta->at(iref)<2.96) || (JRAEvt->jtphi->at(iref)>2.705 && JRAEvt->jtphi->at(iref)<3.1416 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.4835) )continue; - //=== veto region for UL2018 ======= - //if((JRAEvt->jtphi->at(iref)<-0.8727 && JRAEvt->jtphi->at(iref)>-1.5708 && JRAEvt->jteta->at(iref) < -1.31 && JRAEvt->jteta->at(iref)> -2.96) || (JRAEvt->jtphi->at(iref)>0.4363 && JRAEvt->jtphi->at(iref)<0.7854 && JRAEvt->jteta->at(iref) >0 && JRAEvt->jteta->at(iref)<1.31) )continue; -*/ if(ievt%10000==0 && irefnref-1) cout << "."; else if(ievt%10000==0 && iref==JRAEvt->nref-1) From 063a375740a57d5e5404391da45dd69c280f72d3 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Thu, 5 Nov 2020 18:53:20 +0200 Subject: [PATCH 12/19] Update jet_synchfit_x.cc --- JetAnalyzers/bin/jet_synchfit_x.cc | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/JetAnalyzers/bin/jet_synchfit_x.cc b/JetAnalyzers/bin/jet_synchfit_x.cc index cae70175..2f79bf60 100644 --- a/JetAnalyzers/bin/jet_synchfit_x.cc +++ b/JetAnalyzers/bin/jet_synchfit_x.cc @@ -36,11 +36,7 @@ struct FitRes { //=========================================================================== // This method returns the graph from all the TProfile3D's -TGraph2DErrors * getGraph2D(int iEta, TProfile3D * prof, - const TProfile3D * profPt, - const TProfile3D * profRho, - TH3I * hist){ - +TGraph2DErrors * getGraph2D(int iEta, TProfile3D * prof, const TProfile3D * profPt, const TProfile3D * profRho, TH3I * hist){ // The returning graph, with its name and title TGraph2DErrors *graph = new TGraph2DErrors(); graph->SetName(Form("p_offOverA_RhoVsJetPt_%d",iEta)); @@ -358,12 +354,7 @@ void fitClosurePlots(TProfile3D * prof, //=========================================================================== // This method tries to obtain all the relevant TProfiles from the inputFilename // It returns true if successfull -bool getInputProfiles(TString inputFilename, TProfile3D *& prof, - TProfile3D *& profPt, - TProfile3D *& profRho, - TH3I *& hist, - bool useNPU){ - +bool getInputProfiles(TString inputFilename, TProfile3D *& prof, TProfile3D *& profPt, TProfile3D *& profRho, TH3I *& hist, bool useNPU){ // Open the input file TFile *fin= new TFile(inputFilename); if(!fin->IsOpen()) { From ce54c0d275e8ea6706c4e228d3b9585a6375c167 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Thu, 5 Nov 2020 19:03:20 +0200 Subject: [PATCH 13/19] Update L2Creator.cc --- JetUtilities/src/L2Creator.cc | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/JetUtilities/src/L2Creator.cc b/JetUtilities/src/L2Creator.cc index 83fc9a86..4e0283f3 100644 --- a/JetUtilities/src/L2Creator.cc +++ b/JetUtilities/src/L2Creator.cc @@ -49,7 +49,7 @@ L2Creator::L2Creator(CommandLine& cl) { ptclip = cl.getValue ("ptclip", 0.); statTh = cl.getValue ("statTh", 4); - ptclipfit = cl.getValue ("ptclipfit", false); + ptclipfit = cl.getValue ("ptclipfit", false); if (!cl.partialCheck()) return; cl.print(); @@ -221,7 +221,7 @@ void L2Creator::loopOverEtaBins() { ofstream FitResults(txtFitResultsFilename); FitResults.setf(ios::right); - //edw gia draw prob,chi2 vs eta + //Draw prob,chi2 vs eta double etabin[82], Chi2NDF[82], Prob[82], Prob_0p009[82]; while ((hrsp=hl_rsp.next_object(indices))) { @@ -245,7 +245,7 @@ void L2Creator::loopOverEtaBins() { // only add points to the graphs if the current histo is not empty // the current setting might be a little high // - if (hrsp->GetEntries() > 30) {//hrsp->Integral()!=0) {//EDW 4 + if (hrsp->GetEntries() > 30) {//hrsp->Integral()!=0) //TF1* frsp = (TF1*)hrsp->GetListOfFunctions()->Last(); //std::cout << "hrspName = " << hrsp->GetName() << ": frsp = " << frsp << std::endl; @@ -290,13 +290,11 @@ void L2Creator::loopOverEtaBins() { double eabsrsp = epeak; double abscor = 0.0; double eabscor = 0.0; -//cout << "EDW 1 " << "eta" << vabscor_eta.back()->GetName() << "absrsp " << absrsp << " and eabsrsp " << eabsrsp << " and abscor " << abscor << " and eabscor " << eabscor << endl; - if (absrsp > 0 ) {//edw test + if (absrsp > 0 ) { abscor =1.0/absrsp; eabscor = abscor*abscor*epeak; -//cout << "EDW 2 " << "eta" << vabscor_eta.back()->GetName() << endl; } if ((abscor>0) && (absrsp>0) && (eabscor>1e-5) && (eabscor/abscor<0.5) && (eabsrsp>1e-4) && (eabsrsp/absrsp<0.5)) { int n = vabsrsp_eta.back()->GetN(); @@ -304,9 +302,7 @@ void L2Creator::loopOverEtaBins() { vabsrsp_eta.back()->SetPointError(n,erefpt,eabsrsp); vabscor_eta.back()->SetPoint (n,jetpt, abscor); vabscor_eta.back()->SetPointError(n,ejetpt,eabscor); - // cout << "EDW 3" << "eta" << vabscor_eta.back()->GetName() << "refpt" << refpt << "jetpt" << jetpt << "absrsp " << absrsp << " and eabsrsp " << eabsrsp << " and abscor " << abscor << " and eabscor " << eabscor << endl; - } - //else cout << "EDW 4" << "absrsp " << absrsp << " and eabsrsp " << eabsrsp << " and abscor " << abscor << " and eabscor " << eabscor << endl; + } } // @@ -396,7 +392,7 @@ void L2Creator::loopOverEtaBins() { std::cout<<"ieta = "<Draw("same"); } } From a206aa40d2b232ce6233ff0130fc4e972cede5c2 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Thu, 5 Nov 2020 19:22:59 +0200 Subject: [PATCH 14/19] Update jet_match_x.cc The jet_match_x.cc code is actually a modification of the jet_synchtest_x.cc one, which we do not use anymore. It implements an option to remove a phi slice (for the HEM issue studies). --- JetAnalyzers/bin/jet_match_x.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JetAnalyzers/bin/jet_match_x.cc b/JetAnalyzers/bin/jet_match_x.cc index 051187a9..8ca6b871 100644 --- a/JetAnalyzers/bin/jet_match_x.cc +++ b/JetAnalyzers/bin/jet_match_x.cc @@ -1,4 +1,4 @@ -// ROOT Libraries +// ROOT Libraries #include "TROOT.h" #include "TSystem.h" #include "TEnv.h" From b8a9cd63c0bcd35bf0d4530a5fdf6c78708a2da1 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Thu, 5 Nov 2020 19:32:26 +0200 Subject: [PATCH 15/19] Update jet_correction_analyzer_x.cc --- JetAnalyzers/bin/jet_correction_analyzer_x.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JetAnalyzers/bin/jet_correction_analyzer_x.cc b/JetAnalyzers/bin/jet_correction_analyzer_x.cc index e96288c0..f81e6033 100644 --- a/JetAnalyzers/bin/jet_correction_analyzer_x.cc +++ b/JetAnalyzers/bin/jet_correction_analyzer_x.cc @@ -18,8 +18,8 @@ #include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h" #include "PhysicsTools/Utilities/interface/LumiReWeighting.h" #if __has_include("xrootd/XrdCl/XrdClFileSystem.hh") -//#include "xrootd/XrdCl/XrdClFileSystem.hh" -#include "JetMETAnalysis/JetAnalyzers/XrdClFileSystem_v2.hh" +#include "xrootd/XProtocol/XProtocol.hh" +#include "xrootd/XrdCl/XrdClFileSystem.hh" #define has_xrdcl 1 #else #define has_xrdcl 0 From 478c8bd56d2476cb5211c74627e15fcef612e89b Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Thu, 5 Nov 2020 19:39:35 +0200 Subject: [PATCH 16/19] Delete XrdClFileSystem_v2.hh --- JetAnalyzers/XrdClFileSystem_v2.hh | 759 ----------------------------- 1 file changed, 759 deletions(-) delete mode 100644 JetAnalyzers/XrdClFileSystem_v2.hh diff --git a/JetAnalyzers/XrdClFileSystem_v2.hh b/JetAnalyzers/XrdClFileSystem_v2.hh deleted file mode 100644 index 34acff93..00000000 --- a/JetAnalyzers/XrdClFileSystem_v2.hh +++ /dev/null @@ -1,759 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) -// Author: Lukasz Janyst -//------------------------------------------------------------------------------ -// This file is part of the XRootD software suite. -// -// XRootD is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// XRootD is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with XRootD. If not, see . -// -// In applying this licence, CERN does not waive the privileges and immunities -// granted to it by virtue of its status as an Intergovernmental Organization -// or submit itself to any jurisdiction. -//------------------------------------------------------------------------------ - -#ifndef __XRD_CL_FILE_SYSTEM_HH__ -#define __XRD_CL_FILE_SYSTEM_HH__ - -#include "XrdCl/XrdClURL.hh" -#include "XrdCl/XrdClStatus.hh" -#include "XrdOuc/XrdOucEnum.hh" -#include "XrdOuc/XrdOucCompiler.hh" -#include "XrdCl/XrdClXRootDResponses.hh" -#include "XrdSys/XrdSysPthread.hh" -#include "XProtocol/XProtocol.hh" -#include -#include - -namespace XrdCl -{ - class PostMaster; - class Message; - class FileSystemPlugIn; - struct MessageSendParams; - - //---------------------------------------------------------------------------- - //! XRootD query request codes - //---------------------------------------------------------------------------- - struct QueryCode - { - //-------------------------------------------------------------------------- - //! XRootD query request codes - //-------------------------------------------------------------------------- - enum Code - { - Config = kXR_Qconfig, //!< Query server configuration - ChecksumCancel = kXR_Qckscan, //!< Query file checksum cancellation - Checksum = kXR_Qcksum, //!< Query file checksum - Opaque = kXR_Qopaque, //!< Implementation dependent - OpaqueFile = kXR_Qopaquf, //!< Implementation dependent - Prepare = kXR_QPrep, //!< Query prepare status - Space = kXR_Qspace, //!< Query logical space stats - Stats = kXR_QStats, //!< Query server stats - Visa = kXR_Qvisa, //!< Query file visa attributes - XAttr = kXR_Qxattr //!< Query file extended attributes - }; - }; - - //---------------------------------------------------------------------------- - //! Open flags, may be or'd when appropriate - //---------------------------------------------------------------------------- - struct OpenFlags - { - //-------------------------------------------------------------------------- - //! Open flags, may be or'd when appropriate - //-------------------------------------------------------------------------- - enum Flags - { - None = 0, //!< Nothing - Compress = kXR_compress, //!< Read compressed data for open (ignored), - //!< for kXR_locate return unique hosts - Delete = kXR_delete, //!< Open a new file, deleting any existing - //!< file - Force = kXR_force, //!< Ignore file usage rules, for kXR_locate - //!< it means ignoreing network dependencies - MakePath = kXR_mkpath, //!< Create directory path if it does not - //!< already exist - New = kXR_new, //!< Open the file only if it does not already - //!< exist - NoWait = kXR_nowait, //!< Open the file only if it does not cause - //!< a wait. For locate: provide a location as - //!< soon as one becomes known. This means - //!< that not all locations are necessarily - //!< returned. If the file does not exist a - //!< wait is still imposed. - Append = kXR_open_apnd, //!< Open only for appending - Read = kXR_open_read, //!< Open only for reading - Update = kXR_open_updt, //!< Open for reading and writing - Write = kXR_open_wrto, //!< Open only for writing - POSC = kXR_posc, //!< Enable Persist On Successful Close - //!< processing - Refresh = kXR_refresh, //!< Refresh the cached information on file's - //!< location. Voids NoWait. - Replica = kXR_replica, //!< The file is being opened for replica - //!< creation - SeqIO = kXR_seqio, //!< File will be read or written sequentially - PrefName = kXR_prefname //!< Hostname response is prefered, applies - //!< only to FileSystem::Locate - }; - }; - XRDOUC_ENUM_OPERATORS( OpenFlags::Flags ) - - //---------------------------------------------------------------------------- - //! Access mode - //---------------------------------------------------------------------------- - struct Access - { - //-------------------------------------------------------------------------- - //! Access mode - //-------------------------------------------------------------------------- - enum Mode - { - None = 0, - UR = kXR_ur, //!< owner readable - UW = kXR_uw, //!< owner writable - UX = kXR_ux, //!< owner executable/browsable - GR = kXR_gr, //!< group readable - GW = kXR_gw, //!< group writable - GX = kXR_gx, //!< group executable/browsable - OR = kXR_or, //!< world readable - OW = kXR_ow, //!< world writeable - OX = kXR_ox //!< world executable/browsable - }; - }; - XRDOUC_ENUM_OPERATORS( Access::Mode ) - - //---------------------------------------------------------------------------- - //! MkDir flags - //---------------------------------------------------------------------------- - struct MkDirFlags - { - enum Flags - { - None = 0, //!< Nothing special - MakePath = 1 //!< create the entire directory tree if it doesn't exist - }; - }; - XRDOUC_ENUM_OPERATORS( MkDirFlags::Flags ) - - //---------------------------------------------------------------------------- - //! DirList flags - //---------------------------------------------------------------------------- - struct DirListFlags - { - enum Flags - { - None = 0, //!< Nothing special - Stat = 1, //!< Stat each entry - Locate = 2, //!< Locate all servers hosting the directory and send - //!< the dirlist request to all of them - Recursive = 4, //!< Do a recursive listing - Merge = 8, //!< Merge duplicates - Chunked = 16, //!< Serve chunked results for better performance - Zip = 32 //!< List content of ZIP files - }; - }; - XRDOUC_ENUM_OPERATORS( DirListFlags::Flags ) - - //---------------------------------------------------------------------------- - //! Prepare flags - //---------------------------------------------------------------------------- - struct PrepareFlags - { - enum Flags - { - None = 0, //!< no flags - Colocate = kXR_coloc, //!< co-locate staged files, if possible - Fresh = kXR_fresh, //!< refresh file access time even if - //!< the location is known - Stage = kXR_stage, //!< stage the file to disk if it is not - //!< online - WriteMode = kXR_wmode, //!< the file will be accessed for - //!< modification - Cancel = kXR_cancel, //!< cancel staging request - Evict = kXR_wait << 8 //!< evict the file from disk cache - //!< we have to shift kXR_evict as its value - //!< is the same as cancel's because this - //!< flag goes to options extension - }; - }; - XRDOUC_ENUM_OPERATORS( PrepareFlags::Flags ) - - //---------------------------------------------------------------------------- - //! Send file/filesystem queries to an XRootD cluster - //---------------------------------------------------------------------------- - class FileSystem - { - friend class AssignLBHandler; - friend class ForkHandler; - - public: - typedef std::vector LocationList; //!< Location list - - //------------------------------------------------------------------------ - //! Constructor - //! - //! @param url URL of the entry-point server to be contacted - //! @param enablePlugIns enable the plug-in mechanism for this object - //------------------------------------------------------------------------ - FileSystem( const URL &url, bool enablePlugIns = true ); - - //------------------------------------------------------------------------ - //! Destructor - //------------------------------------------------------------------------ - ~FileSystem(); - - //------------------------------------------------------------------------ - //! Locate a file - async - //! - //! @param path path to the file to be located - //! @param flags some of the OpenFlags::Flags - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a Buffer object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Locate( const std::string &path, - OpenFlags::Flags flags, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Locate a file - sync - //! - //! @param path path to the file to be located - //! @param flags some of the OpenFlags::Flags - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Locate( const std::string &path, - OpenFlags::Flags flags, - LocationInfo *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Locate a file, recursively locate all disk servers - async - //! - //! @param path path to the file to be located - //! @param flags some of the OpenFlags::Flags - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a Buffer object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus DeepLocate( const std::string &path, - OpenFlags::Flags flags, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Locate a file, recursively locate all disk servers - sync - //! - //! @param path path to the file to be located - //! @param flags some of the OpenFlags::Flags - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus DeepLocate( const std::string &path, - OpenFlags::Flags flags, - LocationInfo *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Move a directory or a file - async - //! - //! @param source the file or directory to be moved - //! @param dest the new name - //! @param handler handler to be notified when the response arrives, - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Mv( const std::string &source, - const std::string &dest, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Move a directory or a file - sync - //! - //! @param source the file or directory to be moved - //! @param dest the new name - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Mv( const std::string &source, - const std::string &dest, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain server information - async - //! - //! @param queryCode the query code as specified in the QueryCode struct - //! @param arg query argument - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a Buffer object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Query( QueryCode::Code queryCode, - const Buffer &arg, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain server information - sync - //! - //! @param queryCode the query code as specified in the QueryCode struct - //! @param arg query argument - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Query( QueryCode::Code queryCode, - const Buffer &arg, - Buffer *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Truncate a file - async - //! - //! @param path path to the file to be truncated - //! @param size file size - //! @param handler handler to be notified when the response arrives - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Truncate( const std::string &path, - uint64_t size, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Truncate a file - sync - //! - //! @param path path to the file to be truncated - //! @param size file size - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Truncate( const std::string &path, - uint64_t size, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Remove a file - async - //! - //! @param path path to the file to be removed - //! @param handler handler to be notified when the response arrives - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Rm( const std::string &path, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Remove a file - sync - //! - //! @param path path to the file to be removed - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Rm( const std::string &path, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Create a directory - async - //! - //! @param path path to the directory - //! @param flags or'd MkDirFlags - //! @param mode access mode, or'd Access::Mode - //! @param handler handler to be notified when the response arrives - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus MkDir( const std::string &path, - MkDirFlags::Flags flags, - Access::Mode mode, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Create a directory - sync - //! - //! @param path path to the directory - //! @param flags or'd MkDirFlags - //! @param mode access mode, or'd Access::Mode - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus MkDir( const std::string &path, - MkDirFlags::Flags flags, - Access::Mode mode, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Remove a directory - async - //! - //! @param path path to the directory to be removed - //! @param handler handler to be notified when the response arrives - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus RmDir( const std::string &path, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Remove a directory - sync - //! - //! @param path path to the directory to be removed - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus RmDir( const std::string &path, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Change access mode on a directory or a file - async - //! - //! @param path file/directory path - //! @param mode access mode, or'd Access::Mode - //! @param handler handler to be notified when the response arrives - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus ChMod( const std::string &path, - Access::Mode mode, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Change access mode on a directory or a file - sync - //! - //! @param path file/directory path - //! @param mode access mode, or'd Access::Mode - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus ChMod( const std::string &path, - Access::Mode mode, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Check if the server is alive - async - //! - //! @param handler handler to be notified when the response arrives - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Ping( ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Check if the server is alive - sync - //! - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Ping( uint16_t timeout = 0 ) XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain status information for a path - async - //! - //! @param path file/directory path - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a StatInfo object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Stat( const std::string &path, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain status information for a path - sync - //! - //! @param path file/directory path - //! @param response the response (to be deleted by the user only if the - //! procedure is successful) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Stat( const std::string &path, - StatInfo *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain status information for a Virtual File System - async - //! - //! @param path file/directory path - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a StatInfoVFS object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus StatVFS( const std::string &path, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain status information for a Virtual File System - sync - //! - //! @param path file/directory path - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus StatVFS( const std::string &path, - StatInfoVFS *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain server protocol information - async - //! - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a ProtocolInfo object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Protocol( ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Obtain server protocol information - sync - //! - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Protocol( ProtocolInfo *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! List entries of a directory - async - //! - //! @param path directory path - //! @param flags currently unused - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a DirectoryList - //! object if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus DirList( const std::string &path, - DirListFlags::Flags flags, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! List entries of a directory - sync - //! - //! @param path directory path - //! @param flags DirListFlags - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus DirList( const std::string &path, - DirListFlags::Flags flags, - DirectoryList *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Send info to the server (up to 1024 characters)- async - //! - //! @param info the info string to be sent - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a Buffer object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus SendInfo( const std::string &info, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Send info to the server (up to 1024 characters) - sync - //! - //! @param info the info string to be sent - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus SendInfo( const std::string &info, - Buffer *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Prepare one or more files for access - async - //! - //! @param fileList list of files to be prepared - //! @param flags PrepareFlags::Flags - //! @param priority priority of the request 0 (lowest) - 3 (highest) - //! @param handler handler to be notified when the response arrives, - //! the response parameter will hold a Buffer object - //! if the procedure is successful - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Prepare( const std::vector &fileList, - PrepareFlags::Flags flags, - uint8_t priority, - ResponseHandler *handler, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Prepare one or more files for access - sync - //! - //! @param fileList list of files to be prepared - //! @param flags PrepareFlags::Flags - //! @param priority priority of the request 0 (lowest) - 3 (highest) - //! @param response the response (to be deleted by the user) - //! @param timeout timeout value, if 0 the environment default will - //! be used - //! @return status of the operation - //------------------------------------------------------------------------ - XRootDStatus Prepare( const std::vector &fileList, - PrepareFlags::Flags flags, - uint8_t priority, - Buffer *&response, - uint16_t timeout = 0 ) - XRD_WARN_UNUSED_RESULT; - - //------------------------------------------------------------------------ - //! Set filesystem property - //! - //! Filesystem properties: - //! FollowRedirects [true/false] - enable/disable following redirections - //------------------------------------------------------------------------ - bool SetProperty( const std::string &name, const std::string &value ); - - //------------------------------------------------------------------------ - //! Get filesystem property - //! - //! @see FileSystem::SetProperty for property list - //------------------------------------------------------------------------ - bool GetProperty( const std::string &name, std::string &value ) const; - - private: - FileSystem(const FileSystem &other); - FileSystem &operator = (const FileSystem &other); - - //------------------------------------------------------------------------ - // Send a message in a locked environment - //------------------------------------------------------------------------ - Status Send( Message *msg, - ResponseHandler *handler, - MessageSendParams ¶ms ); - - //------------------------------------------------------------------------ - // Assign a load balancer if it has not already been assigned - //------------------------------------------------------------------------ - void AssignLoadBalancer( const URL &url ); - - //------------------------------------------------------------------------ - // Lock the internal lock - //------------------------------------------------------------------------ - void Lock() - { - pMutex.Lock(); - } - - //------------------------------------------------------------------------ - // Unlock the internal lock - //------------------------------------------------------------------------ - void UnLock() - { - pMutex.UnLock(); - } - - XrdSysMutex pMutex; - bool pLoadBalancerLookupDone; - bool pFollowRedirects; - URL *pUrl; - FileSystemPlugIn *pPlugIn; - }; -} - -#endif // __XRD_CL_FILE_SYSTEM_HH__ From 83930e5d57aa62eaafacbcc7ffec02a1065cee27 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Mon, 9 Nov 2020 12:26:50 +0200 Subject: [PATCH 17/19] Update jet_synchtest_x.cc The main focus of the changes are: 1) an option to remove a phi slice (for the HEM issue studies) 2) the implementation of energy fractions --- JetAnalyzers/bin/jet_synchtest_x.cc | 291 +++++++++++++++++++--------- 1 file changed, 196 insertions(+), 95 deletions(-) diff --git a/JetAnalyzers/bin/jet_synchtest_x.cc b/JetAnalyzers/bin/jet_synchtest_x.cc index 268a15ad..76561bcf 100644 --- a/JetAnalyzers/bin/jet_synchtest_x.cc +++ b/JetAnalyzers/bin/jet_synchtest_x.cc @@ -50,34 +50,36 @@ class MatchEventsAndJets { void getMaxDeltaR(); double getMaxDeltaR(string algName); - void SetMaxEvts(int me) {maxEvts = me;} + void SetMaxEvts(unsigned me) {maxEvts = me;} void SetNRefMax(int nrm) {nrefmax = nrm;} void SetDoNotSaveFlag(bool dns) {doNotSaveFlag = dns;} + void SetPhiRange(double minPhi_, double maxPhi_) {minPhi=minPhi_; maxPhi=maxPhi_;} void SetWeightParameters(bool useweight_, bool pThatReweight_, double bias2SelectionRef_, double bias2SelectionPow_); void SetupLumiWeights(string dataFile, string mcFile, string dataHist, string mcHist); void OpenInputFiles(string filenamePU, string filenameNoPU); void MakeMatchedEventsMaps(string treeName, string outputPath); void ConvertEvtMapToVector(const ITS& mapTree, vector& vevtid, vector >& vll); void ConvertEvtMapToTTree(const ITS& mapTree, TTree* treeMap); - void WriteMatchedEventsMaps(ITS mapTree, bool noPU, string outputPath); + void WriteMatchedEventsMap(string outputPath); + void CreateMatchedEventsMap(ITS& mapTreePU, ITS& mapTreeNoPU); void ConvertTTreeToMap(ITS& mapTree, TTree* treeMap); void ReadMatchedEventsMaps(string pathToMaps); ITS fillMap(bool noPU, string treeName, string outputPath); void GetNtuples(string treeName = "t"); void OpenOutputFile(string outputPath = "./"); - void SetJEC(string JECPar = "parameters_ak5pf.txt"); + void SetJEC(string JECPar = "ParallelMCL1_L1FastJet_AK4PFchs.txt"); void SetNpvRhoNpuValues(int NBins, int Width) {NBinsNpvRhoNpu=NBins; npvRhoNpuBinWidth=Width;} void SetVptBins(vector vptb) {vptBins = vptb;} void DeclareHistograms(bool reduceHistograms); - void LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap); + void LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap, string outputPath); void FillJetMap(); void FillRecToRecThroughGenMap(); bool GetJetMap(string readJetMap); bool JetMapTreeFound() {return jetMapTreeFound;} void ReadJetMap(int ientry, string readJetMap); - bool FillHistograms(bool reduceHistograms); + bool FillHistograms(bool reduceHistograms, IT::const_iterator it); + void RemoveHistograms(bool verbose); void WriteOutput(string outputPath, bool writeJetMap); - void Report(); private: @@ -86,6 +88,7 @@ class MatchEventsAndJets { TFile * fnopu; TFile * fout; + ofstream eventlist; //Algorithms string algo1; string algo2; @@ -104,8 +107,7 @@ class MatchEventsAndJets { FactorizedJetCorrector* JetCorrector; //Maps and items used for looping through jets - ITS mapTreePU; - ITS mapTreeNoPU; + ITS mapEventMatch; //A map holding the equivalance of jets in two given events map jetMap; map histograms; @@ -145,11 +147,13 @@ class MatchEventsAndJets { bool LumiWeightsSet_; bool jetMapTreeFound; bool doNotSaveFlag; + double minPhi; + double maxPhi; //Debug bool iftest; int noPUNpvGTOneEventCounter; - int maxEvts; + unsigned maxEvts; double avg_debug; int entries_debug; @@ -160,7 +164,7 @@ class MatchEventsAndJets { // define class //////////////////////////////////////////////////////////////////////////////// //______________________________________________________________________________ -MatchEventsAndJets::MatchEventsAndJets() : algo1("ak5pf"), algo2("ak5pf"), iftest(false) { +MatchEventsAndJets::MatchEventsAndJets() : algo1("ak4pf"), algo2("ak4pf"), iftest(false) { JetCorrector = 0; nevs = 0; NBinsNpvRhoNpu = 6; @@ -249,8 +253,19 @@ void MatchEventsAndJets::OpenInputFiles(string filenamePU, string filenameNoPU) //______________________________________________________________________________ void MatchEventsAndJets::MakeMatchedEventsMaps(string treeName, string outputPath) { - mapTreePU = fillMap(false, treeName, outputPath); - mapTreeNoPU = fillMap(true, treeName, outputPath); + ITS mapTreePU = fillMap(false, treeName, outputPath); + ITS mapTreeNoPU = fillMap(true, treeName, outputPath); + + //create map of matched events + CreateMatchedEventsMap(mapTreePU,mapTreeNoPU); + + cout << "Event-matching report" << endl + << "\t Total number of unique events in first sample: " << mapTreePU.size() << endl + << "\t Total number of unique events in second sample: " << mapTreeNoPU.size() << endl + << "\t Number of matched events in both samples: " << mapEventMatch.size() << endl << endl; + + //if required, saving map of matched entries + if (!doNotSaveFlag) WriteMatchedEventsMap(outputPath); } //______________________________________________________________________________ @@ -310,9 +325,6 @@ ITS MatchEventsAndJets::fillMap(bool noPU, string treeName, string outputPath) { } t->fChain->SetBranchStatus("*",1); - if(!doNotSaveFlag) - WriteMatchedEventsMaps(mapTree,noPU,outputPath); - return mapTree; } @@ -340,21 +352,79 @@ void MatchEventsAndJets::ConvertEvtMapToTTree(const ITS& mapTree, TTree* treeMap } //______________________________________________________________________________ -void MatchEventsAndJets::WriteMatchedEventsMaps(map, evtid> mapTree, bool noPU, string outputPath) { +void MatchEventsAndJets::WriteMatchedEventsMap(string outputPath) { TDirectory* curDir = gDirectory; string outputFilename = "matchedEventsMaps_"+algo1+"_"+algo2+".root"; if (algo1 == algo2) outputFilename = "matchedEventsMaps_"+algo1+".root"; outputFilename = outputPath+outputFilename; - string name = "mapTree"; - cout << "\tWriting " << name+(noPU ? "NoPU" : "PU") << " to " << outputFilename << " ... " << flush; - string option = (noPU ? "UPDATE" : "RECREATE"); - TFile* mapFile = TFile::Open(outputFilename.c_str(),option.c_str()); - mapFile->WriteObject(&mapTree,(name+(noPU ? "NoPU" : "PU")).c_str()); + cout << "Writing mapTree to " << outputFilename << " ... " << endl << "\tprogress:"< entry; + ull PUentry; + ull NoPUentry; + tree->Branch("evtID",&evtID); + tree->Branch("PUentry",&PUentry); + tree->Branch("NoPUentry",&NoPUentry); + + if (!mapEventMatch.size()) { + cout<<"WARNING::No matched events"<first; + PUentry = it->second.first; + NoPUentry = it->second.second; + tree->Fill(); + + counter++; + }//for + mapFile->Write(); mapFile->Close(); - cout << "DONE" << endl; + cout << endl; curDir->cd(); +}//WriteMatchedEventsMap + +//______________________________________________________________________________ +void MatchEventsAndJets::CreateMatchedEventsMap(ITS& mapTreePU, ITS& mapTreeNoPU) { + + cout << "Creating matched events map"<first) == mapTreeNoPU.end()) { + counter++; + continue; + } + + mapEventMatch[it->first] = std::make_pair(mapTreePU[it->first].second,mapTreeNoPU[it->first].second); + + counter++; + + }//for + + if (!mapEventMatch.size()) { + cout<Get("mapTreePU"); - if(inMapPointer) { - mapTreePU = *inMapPointer; - cout << "\tmapTreePU:" << endl - << "\t\tunique signatures: " << mapTreePU.size() << endl; - } - else { - cout << "ERROR::MatchEventsAndJets::ReadMatchedEventsMaps Could not retrieve the mapTreePU pointer from " << pathToMaps << endl; - std::terminate(); + if(!mapFile || !mapFile->IsOpen()) { + cout<<"ERROR::ReadMatchedEventsMaps File "<Get("mapTreeNoPU"); - if(inMapPointer) { - mapTreeNoPU = *inMapPointer; - cout << "\tmapTreeNoPU:" << endl - << "\t\tunique signatures: " << mapTreeNoPU.size() << endl; + TTree* tree = (TTree*) mapFile->Get("eventMapTree"); + + if(!tree) { + cout<<"ERROR::ReadMatchedEventsMaps cannot retrieve tree successfully. ABORTING"<SetBranchAddress("evtID",&evtID); + tree->SetBranchAddress("PUentry",&PUentry); + tree->SetBranchAddress("NoPUentry",&NoPUentry); + + Long64_t nentries = tree->GetEntries(); + + for (int e = 0; eGetEntry(e); + mapEventMatch[*evtID]=std::make_pair(PUentry,NoPUentry); } mapFile->Close(); curDir->cd(); + cout << endl; } //______________________________________________________________________________ @@ -444,6 +521,20 @@ void MatchEventsAndJets::DeclareHistograms(bool reduceHistograms) { // // HISTOS OF GENERAL QUANTITIES.General, hence the g_ prefix // + histograms["h_ooavsweight"] = new TH2D("h_ooavsweight","h_ooavsweight;offsetOA;weight",1000,-1000,1000,200,-100,100); + histograms["h_onebin"] = new TH1D("h_onebin","h_onebin;offsetOA",2000,-100,100); + + histograms["h_chf"] = new TH2D("h_chf","h_chf;chf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nhf"] = new TH2D("h_nhf","h_nhf;nhf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nef"] = new TH2D("h_nef","h_nef;nef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_cef"] = new TH2D("h_cef","h_cef;cef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_muf"] = new TH2D("h_muf","h_muf;muf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + + histograms["h_chfw"] = new TH2D("h_chfw","h_chfw;chf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nhfw"] = new TH2D("h_nhfw","h_nhfw;nhf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_nefw"] = new TH2D("h_nefw","h_nefw;nef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_cefw"] = new TH2D("h_cefw","h_cefw;cef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); + histograms["h_mufw"] = new TH2D("h_mufw","h_mufw;muf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); histograms["g_LumiWeight"] = new TH1D("g_LumiWeight", "g_LumiWeight;LumiWeight;Events", 1000,0,10); histograms["g_GenWeight"] = new TH1D("g_GenWeight", "g_GenWeight;log_{10}(GenWeight);Events", 1000,-48,2); histograms["g_pThatWeight"] = new TH1D("g_pThatWeight;log_{10}(pThatWeight);Events","g_pThatWeight", 1000,-48,2); @@ -563,9 +654,10 @@ void MatchEventsAndJets::DeclareHistograms(bool reduceHistograms) { } //TNPU - histograms["p_offOverA_etaVsTnpusVsJetPt"] = new TProfile3D("p_offOverA_etaVsTnpusVsJetPt","p_offOverA_etaVsTnpusVsJetPt;#eta_{j};tnpu;p_{T}^{gen};OffsetOverAre",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); + histograms["p_offOverA_etaVsTnpusVsJetPt"] = new TProfile3D("p_offOverA_etaVsTnpusVsJetPt","p_offOverA_etaVsTnpusVsJetPt;#eta_{j};tnpu;p_{T}^{gen};OffsetOverArea",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); histograms["p_PtAve_etaVsTnpusVsJetPt"] = new TProfile3D("p_PtAve_etaVsTnpusVsJetPt","p_PtAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); histograms["p_RhoAve_etaVsTnpusVsJetPt"] = new TProfile3D("p_RhoAve_etaVsTnpusVsJetPt","p_RhoAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); + histograms["p_Events_etaVsTnpusVsJetPt"] = new TH3I("p_Events_etaVsTnpusVsJetPt","p_RhoAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); //THnSparse with 4 dimensions Int_t bins[4] = {NETA, NRHO, NTNPU, NPtBins}; Double_t min[4] = {veta[0], vrho[0], vtnpu[0], vpt[0]}; @@ -601,18 +693,12 @@ void MatchEventsAndJets::DeclareHistograms(bool reduceHistograms) { hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(3)->SetTitle("p_{T}^{gen}"); hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->Sumw2(); if (!fValue) fValue = new Double_t[4]; - //if (!bins_debug) { - // bins_debug = new Int_t[4]; - // bins_debug[0] = 11; - // bins_debug[1] = 3; - // bins_debug[2] = 6; - // bins_debug[3] = 4; - //} //NPU histograms["p_offOverA_etaVsNpusVsJetPt"] = new TProfile3D("p_offOverA_etaVsNpusVsJetPt","p_offOverA_etaVsNpusVsJetPt;#eta_{j};npu;p_{T}^{gen};OffsetOverAre",NETA,veta,NNPU,vnpu,NPtBins,vpt); histograms["p_PtAve_etaVsNpusVsJetPt"] = new TProfile3D("p_PtAve_etaVsNpusVsJetPt","p_PtAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NNPU,vnpu,NPtBins,vpt); histograms["p_RhoAve_etaVsNpusVsJetPt"] = new TProfile3D("p_RhoAve_etaVsNpusVsJetPt","p_RhoAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NNPU,vnpu,NPtBins,vpt); + histograms["p_Events_etaVsNpusVsJetPt"] = new TH3I("p_Events_etaVsNpusVsJetPt","p_RhoAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); if(!reduceHistograms) { //NPV+Rho @@ -791,41 +877,36 @@ void MatchEventsAndJets::DeclareHistograms(bool reduceHistograms) { } //______________________________________________________________________________ -void MatchEventsAndJets::LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap) { +void MatchEventsAndJets::LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap, string outputPath) { //First just figure out if the jetMapTree exists, assuming readJetMap is set. //It might be that the program failed after the event mapping, so the event maps exist, but not the jet maps //In this case the event maps should be read, but the jet maps should be recreated. - jetMapTreeFound = (readJetMap.empty()) ? false : GetJetMap(readJetMap); + jetMapTreeFound = false; + if (!mapEventMatch.size()) { + cout<= maxEvts) return; + eventlist.open(outputPath + "eventlist.txt"); - //if (nevs%10000==0) cout << "\t"< maxEvts && iftest) ? maxEvts : mapEventMatch.size(); + for (IT::const_iterator it = mapEventMatch.begin(); it != mapEventMatch.end() && nevs < nentries; ++it) { - // if this entry does not exist on the second ntuple just skip this event - if (mapTreeNoPU.find(it->first) == mapTreeNoPU.end()) { - if(verbose) { - cout << "\tWARNING::mapTreeNoPU.find(it->first) == mapTreeNoPU.end() failed" << endl - << "\tit->first.run_ == " << it->first.run() << endl - << "\tit->first.ls_ == " << it->first.luminosityBlock() << endl - << "\tit->first.evt_ == " << it->first.event() << endl - << "\tit->first.refpt0_ == " << it->first.pt() << endl; - } - continue; - } + loadbar2(nevs+1,nentries,50,"\t\t"); // Load the entries at the proper place. - tpu->GetEntry(mapTreePU[it->first].second); - tnopu->GetEntry(mapTreeNoPU[it->first].second); + tpu->GetEntry(it->second.first); + tnopu->GetEntry(it->second.second); //Skip events without any primary vertex as these make no sense - if (tpu->npv == 0 || tnopu->npv == 0) continue; - + if (tpu->npv == 0 || tnopu->npv == 0) { + nevs++; + continue; + } // Set the in-time pileup index after the first event only if(nevs==0) iIT = tpu->itIndex(); @@ -838,11 +919,13 @@ void MatchEventsAndJets::LoopOverEvents(bool verbose, bool reduceHistograms, str else { jetMapIndex++; ReadJetMap(jetMapIndex,readJetMap); - } + } + FillHistograms(reduceHistograms,it); - if(FillHistograms(reduceHistograms)) nevs++; + nevs++; }//for + cout<second; if(jpu == -1 || jnopu == -1) continue; + if (!tpu->jtarea->at(jpu) || TMath::IsNaN(tpu->jtarea->at(jpu)) || fabs(tpu->jtarea->at(jpu))==TMath::Infinity() || ((minPhi || maxPhi) && (tpu->jtphi->at(jpu)jtphi->at(jpu)>maxPhi))) continue; idet = JetInfo::getDetIndex(tpu->jteta->at(jpu)); detectorAbbreviation = JetInfo::get_detector_abbreviation(detector_names[idet]); detectorAbbreviation.ToLower(); @@ -1228,6 +1312,7 @@ bool MatchEventsAndJets::FillHistograms(bool reduceHistograms) { PUEff = 0.020*(tpu->sumEOOT())+0.975*(tpu->npus->at(iIT))+0.005*(tpu->sumLOOT()); // effective pu GenSumPtOA = (0.020*(tpu->sumpt_lowpt->at(0))+0.975*(tpu->sumpt_lowpt->at(1))+0.005*(tpu->sumpt_lowpt->at(2)))/tpu->jtarea->at(jpu); + if (fabs(offsetOA)>300) eventlist<second.first<second.second<evt<run<jtarea->at(jpu)<jtpt->at(jpu)<jtpt->at(jnopu)<(histograms["p_off_etaVsNpv"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,offset,weight); dynamic_cast(histograms["p_off_etaVsRho"]) ->Fill(tpu->jteta->at(jpu),tpu->rho,offset,weight); @@ -1248,10 +1333,24 @@ bool MatchEventsAndJets::FillHistograms(bool reduceHistograms) { dynamic_cast(histograms["p_PtAve_etaVsNPVVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); } + int etabin = 60; + int tnpubin = 6; + int ptbin = 26; + + bool cond = true; + cond &= tpu->jteta->at(jpu)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetXaxis()->GetBinLowEdge(etabin); + cond &= tpu->jteta->at(jpu)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetXaxis()->GetBinUpEdge(etabin); + cond &= tpu->tnpus->at(iIT)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetYaxis()->GetBinLowEdge(tnpubin); + cond &= tpu->tnpus->at(iIT)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetYaxis()->GetBinUpEdge(tnpubin); + cond &= tpu->refpt->at(jpu)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetZaxis()->GetBinLowEdge(ptbin); + cond &= tpu->refpt->at(jpu)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetZaxis()->GetBinUpEdge(ptbin); + + if (cond) dynamic_cast(histograms["h_onebin"])->Fill(offsetOA,weight); //TNPU dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),offsetOA,weight); dynamic_cast(histograms["p_PtAve_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); dynamic_cast(histograms["p_RhoAve_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),tpu->rho,weight); + dynamic_cast(histograms["p_Events_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu)); fValue[0] = tpu->jteta->at(jpu); fValue[1] = tpu->rho; fValue[2] = tpu->tnpus->at(iIT); @@ -1268,6 +1367,7 @@ bool MatchEventsAndJets::FillHistograms(bool reduceHistograms) { dynamic_cast(histograms["p_offOverA_etaVsNpusVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),offsetOA,weight); dynamic_cast(histograms["p_PtAve_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); dynamic_cast(histograms["p_RhoAve_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),tpu->rho,weight); + dynamic_cast(histograms["p_Events_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu)); if(!reduceHistograms) { //NPV+Rho @@ -1428,6 +1528,16 @@ bool MatchEventsAndJets::FillHistograms(bool reduceHistograms) { return true; } +void MatchEventsAndJets::RemoveHistograms(bool verbose) { + cout<::iterator it=histograms.begin(); it!=histograms.end(); ++it) { + if (!it->second->GetEntries()) { + if (verbose) cout<<"\tRemoving histogram "<first<second->SetDirectory(0); + } + } +} + //______________________________________________________________________________ void MatchEventsAndJets::WriteOutput(string outputPath, bool writeJetMap){ cout << "Writing file " << fout->GetName() << " ... " << flush; @@ -1452,17 +1562,6 @@ void MatchEventsAndJets::WriteOutput(string outputPath, bool writeJetMap){ } } -//______________________________________________________________________________ -void MatchEventsAndJets::Report() { - cout << "Event-matching report" << endl - << "\t Number of events skipped because the NoPU sample had more than 1 NPV: " << noPUNpvGTOneEventCounter << endl - << "\t Total number of unique events in first sample: " << mapTreePU.size() << endl - << "\t Total number of unique events in second sample: " << mapTreeNoPU.size() << endl - << "\t Number of matched events we ran over " << nevs << endl; - - //cout << "THnSparse::Debug::Avg OffsetOverA of bin 8500: " << avg_debug/entries_debug << endl; -} - //////////////////////////////////////////////////////////////////////////////// // main //////////////////////////////////////////////////////////////////////////////// @@ -1475,26 +1574,28 @@ int main(int argc,char**argv) string samplePU = cl.getValue ("samplePU"); string sampleNoPU = cl.getValue ("sampleNoPU"); string basepath = cl.getValue ("basepath", "/fdata/hepx/store/user/aperloff/"); - string algo1 = cl.getValue ("algo1", "ak5pf"); - string algo2 = cl.getValue ("algo2", "ak5pf"); + string algo1 = cl.getValue ("algo1", "ak4pf"); + string algo2 = cl.getValue ("algo2", "ak4pf"); bool iftest = cl.getValue ("iftest", false); - int maxEvts = cl.getValue ("maxEvts", 40000); + unsigned maxEvts = cl.getValue ("maxEvts", 40000); + double minPhi = cl.getValue ("minPhi", 0.0); + double maxPhi = cl.getValue ("maxPhi", 0.0); int nrefmax = cl.getValue ("nrefmax", -1); bool useweight = cl.getValue ("useweight", false); bool pThatReweight = cl.getValue ("pThatReweight", false); double bias2SelectionRef = cl.getValue ("bias2SelectionRef", 15); double bias2SelectionPow = cl.getValue ("bias2SelectionPow", 6.0); string MCPUReWeighting = cl.getValue ("MCPUReWeighting", ""); - string MCPUHistoName = cl.getValue ("MCPUHistoName", "pileup"); + string MCPUHistoName = cl.getValue ("MCPUHistoName", "h_pileup"); string DataPUReWeighting = cl.getValue ("DataPUReWeighting", ""); string DataPUHistoName = cl.getValue ("DataPUHistoName", "pileup"); - bool ApplyJEC = cl.getValue ("ApplyJEC", false); - string JECpar = cl.getValue ("JECpar", "parameters_ak5pf.txt"); + bool ApplyJEC = cl.getValue ("ApplyJEC", true); + string JECpar = cl.getValue ("JECpar", "ParallelMCL1_L1FastJet_AK4PFchs.txt"); string outputPath = cl.getValue ("outputPath", "./"); string readEvtMaps = cl.getValue ("readEvtMaps", ""); bool doNotSave = cl.getValue ("doNotSave", false); string treeName = cl.getValue ("treeName", "t"); - int npvRhoNpuBinWidth = cl.getValue ("npvRhoNpuBinWidth", 5); + int npvRhoNpuBinWidth = cl.getValue ("npvRhoNpuBinWidth", 10); int NBinsNpvRhoNpu = cl.getValue ("NBinsNpvRhoNpu", 6); vector vptBins = cl.getVector ("vptBins", "14:::18:::20:::24:::28:::30"); bool reduceHistograms = cl.getValue ("reduceHistograms", true); @@ -1529,6 +1630,7 @@ int main(int argc,char**argv) MatchEventsAndJets* mej = new MatchEventsAndJets(algo1,algo2,iftest); mej->SetDoNotSaveFlag(doNotSave); mej->SetMaxEvts(maxEvts); + mej->SetPhiRange(minPhi,maxPhi); mej->SetNRefMax(nrefmax); mej->SetWeightParameters(useweight,pThatReweight,bias2SelectionRef,bias2SelectionPow); mej->SetupLumiWeights((DataPUReWeighting.empty())? "" : basepath+DataPUReWeighting, @@ -1549,9 +1651,8 @@ int main(int argc,char**argv) mej->SetNpvRhoNpuValues(NBinsNpvRhoNpu,npvRhoNpuBinWidth); mej->SetVptBins(vptBins); mej->DeclareHistograms(reduceHistograms); - mej->LoopOverEvents(verbose,reduceHistograms,readEvtMaps); - mej->WriteOutput(outputPath,readEvtMaps.empty()||!mej->JetMapTreeFound()); - mej->Report(); + mej->LoopOverEvents(verbose,reduceHistograms,readEvtMaps,outputPath); + mej->WriteOutput(outputPath, false && (readEvtMaps.empty()||!mej->JetMapTreeFound())); m_benchmark->Stop("event"); cout << "jet_synchtest_x" << endl From 2809db1d6261a2319c523392700ef5b9abf09ab6 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Mon, 9 Nov 2020 12:27:47 +0200 Subject: [PATCH 18/19] Delete jet_match_x.cc --- JetAnalyzers/bin/jet_match_x.cc | 1695 ------------------------------- 1 file changed, 1695 deletions(-) delete mode 100644 JetAnalyzers/bin/jet_match_x.cc diff --git a/JetAnalyzers/bin/jet_match_x.cc b/JetAnalyzers/bin/jet_match_x.cc deleted file mode 100644 index 8ca6b871..00000000 --- a/JetAnalyzers/bin/jet_match_x.cc +++ /dev/null @@ -1,1695 +0,0 @@ -// ROOT Libraries -#include "TROOT.h" -#include "TSystem.h" -#include "TEnv.h" -#include "TChain.h" -#include "TFile.h" -#include "TChain.h" -#include "TString.h" -#include "TH1D.h" -#include "TH2D.h" -#include "TProfile.h" -#include "TProfile2D.h" -#include "TProfile3D.h" -#include "THnSparse.h" -#include "TBenchmark.h" - -// C++ Libraries -#include -#include -#include -#include - -// JetMETAnalysis Libraries -#include "JetMETAnalysis/JetUtilities/interface/CommandLine.h" -#include "JetMETAnalysis/JetUtilities/interface/JRAEvent.h" -#include "JetMETAnalysis/JetUtilities/interface/JetInfo.hh" -#include "JetMETAnalysis/JetUtilities/interface/EvtID.hh" -#include "JetMETAnalysis/JetUtilities/interface/ProgressBar.hh" - -// CMSSW Libraries -#include "DataFormats/Provenance/interface/RunLumiEventNumber.h" -#include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h" -#include "CondFormats/JetMETObjects/interface/FactorizedJetCorrector.h" -#include "PhysicsTools/Utilities/interface/LumiReWeighting.h" - -using namespace std; - -typedef map > ITJ; - -//////////////////////////////////////////////////////////////////////////////// -// declare class -//////////////////////////////////////////////////////////////////////////////// - -class MatchEventsAndJets { -public: - - MatchEventsAndJets(); - MatchEventsAndJets(string algo1_, string algo2_, bool iftest_); - ~MatchEventsAndJets() {;} - - void getMaxDeltaR(); - double getMaxDeltaR(string algName); - void SetMaxEvts(unsigned me) {maxEvts = me;} - void SetNRefMax(int nrm) {nrefmax = nrm;} - void SetDoNotSaveFlag(bool dns) {doNotSaveFlag = dns;} - void SetPhiRange(double minPhi_, double maxPhi_) {minPhi=minPhi_; maxPhi=maxPhi_;} - void SetWeightParameters(bool useweight_, bool pThatReweight_, double bias2SelectionRef_, double bias2SelectionPow_); - void SetupLumiWeights(string dataFile, string mcFile, string dataHist, string mcHist); - void OpenInputFiles(string filenamePU, string filenameNoPU); - void MakeMatchedEventsMaps(string treeName, string outputPath); - void ConvertEvtMapToVector(const ITS& mapTree, vector& vevtid, vector >& vll); - void ConvertEvtMapToTTree(const ITS& mapTree, TTree* treeMap); - void WriteMatchedEventsMap(string outputPath); - void CreateMatchedEventsMap(ITS& mapTreePU, ITS& mapTreeNoPU); - void ConvertTTreeToMap(ITS& mapTree, TTree* treeMap); - void ReadMatchedEventsMaps(string pathToMaps); - ITS fillMap(bool noPU, string treeName, string outputPath); - void GetNtuples(string treeName = "t"); - void OpenOutputFile(string outputPath = "./"); - void SetJEC(string JECPar = "ParallelMCL1_L1FastJet_AK4PFchs.txt"); - void SetNpvRhoNpuValues(int NBins, int Width) {NBinsNpvRhoNpu=NBins; npvRhoNpuBinWidth=Width;} - void SetVptBins(vector vptb) {vptBins = vptb;} - void DeclareHistograms(bool reduceHistograms); - void LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap, string outputPath); - void FillJetMap(); - void FillRecToRecThroughGenMap(); - bool GetJetMap(string readJetMap); - bool JetMapTreeFound() {return jetMapTreeFound;} - void ReadJetMap(int ientry, string readJetMap); - bool FillHistograms(bool reduceHistograms, IT::const_iterator it); - void RemoveHistograms(bool verbose); - void WriteOutput(string outputPath, bool writeJetMap); - -private: - - //Files - TFile * fpu; - TFile * fnopu; - TFile * fout; - - ofstream eventlist; - - //Algorithms - string algo1; - string algo2; - JetInfo algo1JetInfo; - JetInfo algo2JetInfo; - double maxDeltaR; - - //Ntuples - JRAEvent* tpu; - JRAEvent* tnopu; - - //JEC - bool ApplyJEC; - JetCorrectorParameters* L1JetPar; - vector vPar; - FactorizedJetCorrector* JetCorrector; - - //Maps and items used for looping through jets - // ITS mapTreePU; - // ITS mapTreeNoPU; - ITS mapEventMatch; - - //A map holding the equivalance of jets in two given events - map jetMap; - map histograms; - map hsparse; - //Used for filling the THnSparse - Double_t* fValue; - TTree* jetMapTree; - vector* recoJetIndexPU; - vector* recoJetIndexNoPU; - - - //Loop - vector vptBins; - int nrefmax; - int nevs; - int NBinsNpvRhoNpu; - int npvRhoNpuBinWidth; - int iIT; - int inpv; - int inpv_low; - int inpv_high; - int irho; - int irho_low; - int irho_high; - int itnpu; - int itnpu_low; - int itnpu_high; - int inpu; - int inpu_low; - int inpu_high; - double weight; - bool useweight; - bool pThatReweight; - double bias2SelectionRef; - double bias2SelectionPow; - edm::LumiReWeighting LumiWeights_; - bool LumiWeightsSet_; - bool jetMapTreeFound; - bool doNotSaveFlag; - double minPhi; - double maxPhi; - - //Debug - bool iftest; - int noPUNpvGTOneEventCounter; - unsigned maxEvts; - - double avg_debug; - int entries_debug; - Int_t *bins_debug; -}; - -//////////////////////////////////////////////////////////////////////////////// -// define class -//////////////////////////////////////////////////////////////////////////////// -//______________________________________________________________________________ -MatchEventsAndJets::MatchEventsAndJets() : algo1("ak4pf"), algo2("ak4pf"), iftest(false) { - JetCorrector = 0; - nevs = 0; - NBinsNpvRhoNpu = 6; - npvRhoNpuBinWidth = 5; - noPUNpvGTOneEventCounter = 0; - maxEvts = 0; - algo1JetInfo = JetInfo(algo1); - algo2JetInfo = JetInfo(algo2); - getMaxDeltaR(); - LumiWeightsSet_ = false; - recoJetIndexPU = NULL; - recoJetIndexNoPU = NULL; - jetMapTree = NULL; - fValue = NULL; -} - -//______________________________________________________________________________ -MatchEventsAndJets::MatchEventsAndJets(string algo1_, string algo2_, bool iftest_) - : algo1(algo1_), algo2(algo2_), iftest(iftest_){ - JetCorrector = 0; - nevs = 0; - NBinsNpvRhoNpu = 6; - npvRhoNpuBinWidth = 5; - noPUNpvGTOneEventCounter = 0; - maxEvts = 0; - algo1JetInfo = JetInfo(algo1); - algo2JetInfo = JetInfo(algo2); - getMaxDeltaR(); - LumiWeightsSet_ = false; - recoJetIndexPU = NULL; - recoJetIndexNoPU = NULL; - jetMapTree = NULL; - fValue = NULL; -} - -//______________________________________________________________________________ -void MatchEventsAndJets::SetWeightParameters(bool useweight_, bool pThatReweight_, double bias2SelectionRef_, double bias2SelectionPow_) { - useweight = useweight_; - pThatReweight = pThatReweight_; - bias2SelectionRef = bias2SelectionRef_; - bias2SelectionPow = bias2SelectionPow_; -} - - -//______________________________________________________________________________ -void MatchEventsAndJets::SetupLumiWeights(string dataFile, string mcFile, string dataHist, string mcHist) { - if(!dataFile.empty() && !mcFile.empty()) { - LumiWeights_ = edm::LumiReWeighting(mcFile,dataFile,mcHist,dataHist); - LumiWeightsSet_ = true; - cout << endl; - } - else { - cout << "WARNING::MatchEventsAndJets::SetupLumiWeights LumiWeights not set." << std::endl - << "\tOne or both of the input files was not set." << endl << endl; - } -} - -//______________________________________________________________________________ -void MatchEventsAndJets::getMaxDeltaR() { - double minConeSize = min(algo1JetInfo.coneSize,algo2JetInfo.coneSize)/20.0; - //maxDeltaR = min(0.25,0.05); - maxDeltaR = min(0.25,minConeSize); - - cout << setw(10) << " " << setw(13) << "Algo1" << setw(13) << "Algo2" << endl; - cout << std::setfill ('=') << setw(34) << " " << std::setfill (' ') << endl; - cout << setw(10) << "Cone Size:" << setw(13) << algo1JetInfo.coneSize - << setw(13) << algo2JetInfo.coneSize << endl; - cout << setw(10) << "Jet Type:" << setw(13) << algo1JetInfo.jetType - << setw(13) << algo2JetInfo.jetType << endl; - cout << setw(10) << "Alias:" << setw(13) << algo1JetInfo.alias - << setw(13) << algo2JetInfo.alias << endl; - cout << std::setfill ('-') << setw(34) << " " << std::setfill (' ') << endl; - cout << setw(18) << "0.5 * minConeSize:" << setw(4) << minConeSize << endl; - cout << setw(18) << "maxDeltaR:" << setw(4) << maxDeltaR << endl << endl; -} - -//______________________________________________________________________________ -double MatchEventsAndJets::getMaxDeltaR(string algName) { - return min(0.25,JetInfo(algName).coneSize/20.0); -} - -//______________________________________________________________________________ -void MatchEventsAndJets::OpenInputFiles(string filenamePU, string filenameNoPU) { - fpu = TFile::Open(filenamePU.c_str(),"READ"); - fnopu = TFile::Open(filenameNoPU.c_str(),"READ"); -} - -//______________________________________________________________________________ -void MatchEventsAndJets::MakeMatchedEventsMaps(string treeName, string outputPath) { - ITS mapTreePU = fillMap(false, treeName, outputPath); - ITS mapTreeNoPU = fillMap(true, treeName, outputPath); - - //create map of matched events - CreateMatchedEventsMap(mapTreePU,mapTreeNoPU); - - cout << "Event-matching report" << endl - << "\t Total number of unique events in first sample: " << mapTreePU.size() << endl - << "\t Total number of unique events in second sample: " << mapTreeNoPU.size() << endl - << "\t Number of matched events in both samples: " << mapEventMatch.size() << endl << endl; - - //if required, saving map of matched entries - if (!doNotSaveFlag) WriteMatchedEventsMap(outputPath); -} - -//______________________________________________________________________________ -ITS MatchEventsAndJets::fillMap(bool noPU, string treeName, string outputPath) { - TFile* f; - JRAEvent* t; - string algo; - ITS mapTree; - if(noPU == false) { - f = fpu; - algo = algo1; - t = tpu; - } - else if(noPU == true) { - f = fnopu; - algo = algo2; - t = tnopu; - } - - // Load only what's needed this WAY FASTER. - t->fChain->SetBranchStatus("*",0); - t->fChain->SetBranchStatus("run",1); - t->fChain->SetBranchStatus("evt",1); - t->fChain->SetBranchStatus("refpt",1); - Int_t lumi = 0; - - cout << "Filling map with event signatures from: "<GetName()<< endl; - cout << "\talgo: "<fChain->GetEntriesFast(); - - for (ull jentry=0; jentryLoadTree(jentry); - if (ientry < 0) break; - t->GetEntry(ientry); - - if(t->refpt->size()==0) { - no_ref_events++; - continue; - } - - if(mapTree.find(evtid(t->run, lumi, t->evt, t->refpt->at(0)))!=mapTree.end()) { - cout << "\tWARNING::This evtid already exists in the map." << endl; - } - - mapTree[evtid(t->run, lumi, t->evt, t->refpt->at(0))] = std::make_pair(jentry, (ull)ientry); - loadbar2(jentry+1,nentries,50,"\t\t"); - } - - cout << endl << "\tRead " << mapTree.size() << " unique signatures" << endl; - if(no_ref_events>0) { - cout << "\tWARNING::There were " << no_ref_events << " events which don't contain any ref jets" << endl // - << "\t\tThese events will be skipped" << endl << endl; - } - t->fChain->SetBranchStatus("*",1); - - return mapTree; -} - -//______________________________________________________________________________ -void MatchEventsAndJets::ConvertEvtMapToVector(const ITS& mapTree, vector& vevtid, vector >& vll) { - vevtid.clear(); - vll.clear(); - for(IT::const_iterator it=mapTree.begin(); it!=mapTree.end(); it++) { - vevtid.push_back(it->first); - vll.push_back(it->second); - } -} - -//______________________________________________________________________________ -void MatchEventsAndJets::ConvertEvtMapToTTree(const ITS& mapTree, TTree* treeMap) { - evtid tmpid; - pair tmpIndex; - treeMap->Branch("evtid","evtid",&tmpid); - treeMap->Branch("indices","pair",&tmpIndex); - for(IT::const_iterator it=mapTree.begin(); it!=mapTree.end(); it++) { - tmpid = it->first; - tmpIndex = it->second; - treeMap->Fill(); - } -} - -//______________________________________________________________________________ -void MatchEventsAndJets::WriteMatchedEventsMap(string outputPath) { - TDirectory* curDir = gDirectory; - string outputFilename = "matchedEventsMaps_"+algo1+"_"+algo2+".root"; - if (algo1 == algo2) - outputFilename = "matchedEventsMaps_"+algo1+".root"; - outputFilename = outputPath+outputFilename; - cout << "Writing mapTree to " << outputFilename << " ... " << endl << "\tprogress:"< entry; - ull PUentry; - ull NoPUentry; - tree->Branch("evtID",&evtID); - tree->Branch("PUentry",&PUentry); - tree->Branch("NoPUentry",&NoPUentry); - - if (!mapEventMatch.size()) { - cout<<"WARNING::No matched events"<first; - PUentry = it->second.first; - NoPUentry = it->second.second; - tree->Fill(); - - counter++; - }//for - - mapFile->Write(); - mapFile->Close(); - cout << endl; - curDir->cd(); -}//WriteMatchedEventsMap - -//______________________________________________________________________________ -void MatchEventsAndJets::CreateMatchedEventsMap(ITS& mapTreePU, ITS& mapTreeNoPU) { - - cout << "Creating matched events map"<first) == mapTreeNoPU.end()) { - counter++; - continue; - } - - mapEventMatch[it->first] = std::make_pair(mapTreePU[it->first].second,mapTreeNoPU[it->first].second); - - counter++; - - }//for - - if (!mapEventMatch.size()) { - cout<* tmpIndex; - treeMap->SetBranchAddress("evtid",&tmpid); - treeMap->SetBranchAddress("indices",&tmpIndex); - int nentries = treeMap->GetEntries(); - for(int ientry=0; ientryGetEntry(ientry); - mapTree[*tmpid] = *tmpIndex; - } -} - -//______________________________________________________________________________ -void MatchEventsAndJets::ReadMatchedEventsMaps(string pathToMaps) { - cout << "Reading matched event maps:" << endl - << "\tfile: " << pathToMaps << endl - << "\tprogress:" << endl; - - TDirectory* curDir = gDirectory; - TFile* mapFile = TFile::Open(pathToMaps.c_str(),"READ"); - - if(!mapFile || !mapFile->IsOpen()) { - cout<<"ERROR::ReadMatchedEventsMaps File "<Get("eventMapTree"); - - if(!tree) { - cout<<"ERROR::ReadMatchedEventsMaps cannot retrieve tree successfully. ABORTING"<SetBranchAddress("evtID",&evtID); - tree->SetBranchAddress("PUentry",&PUentry); - tree->SetBranchAddress("NoPUentry",&NoPUentry); - - Long64_t nentries = tree->GetEntries(); - - for (int e = 0; eGetEntry(e); - mapEventMatch[*evtID]=std::make_pair(PUentry,NoPUentry); - } - - mapFile->Close(); - curDir->cd(); - - cout << endl; - -} - -//______________________________________________________________________________ -void MatchEventsAndJets::GetNtuples(string treeName) { - int algo1_bit_number = (algo1JetInfo.jetType.Contains("calo",TString::kIgnoreCase)) ? 53 : 85; - int algo2_bit_number = (algo2JetInfo.jetType.Contains("calo",TString::kIgnoreCase)) ? 53 : 85; - - fpu->cd(algo1.c_str()); - tpu = new JRAEvent((TTree*) fpu->Get((algo1+"/"+treeName).c_str()),algo1_bit_number); - - fnopu->cd(algo2.c_str()); - tnopu = new JRAEvent((TTree*) fnopu->Get((algo2+"/"+treeName).c_str()),algo2_bit_number); -} - -//______________________________________________________________________________ -void MatchEventsAndJets::OpenOutputFile(string outputPath) { - string outputFilename = "output_"+algo1+"_"+algo2+".root"; - if (algo1 == algo2) - outputFilename = "output_"+algo1+".root"; - outputFilename = outputPath+outputFilename; - fout = new TFile(outputFilename.c_str(),"RECREATE"); -} - -//______________________________________________________________________________ -void MatchEventsAndJets::SetJEC(string JECPar) { - L1JetPar = new JetCorrectorParameters(JECPar); - vPar.push_back(*L1JetPar); - JetCorrector = new FactorizedJetCorrector(vPar); -} - -//______________________________________________________________________________ -void MatchEventsAndJets::DeclareHistograms(bool reduceHistograms) { - - //========================================================= - // DECLARATION OF HISTOS START HERE - //========================================================= - - // - // HISTOS OF GENERAL QUANTITIES.General, hence the g_ prefix - // - - histograms["h_ooavsweight"] = new TH2D("h_ooavsweight","h_ooavsweight;offsetOA;weight",1000,-1000,1000,200,-100,100); - histograms["h_onebin"] = new TH1D("h_onebin","h_onebin;offsetOA",2000,-100,100); - - histograms["h_chf"] = new TH2D("h_chf","h_chf;chf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_nhf"] = new TH2D("h_nhf","h_nhf;nhf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_nef"] = new TH2D("h_nef","h_nef;nef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_cef"] = new TH2D("h_cef","h_cef;cef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_muf"] = new TH2D("h_muf","h_muf;muf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - - histograms["h_chfw"] = new TH2D("h_chfw","h_chfw;chf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_nhfw"] = new TH2D("h_nhfw","h_nhfw;nhf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_nefw"] = new TH2D("h_nefw","h_nefw;nef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_cefw"] = new TH2D("h_cefw","h_cefw;cef*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - histograms["h_mufw"] = new TH2D("h_mufw","h_mufw;muf*refpt (PU-NoPU) [GeV];refpt [GeV]",500,-500,500,700,0,7000); - - histograms["g_LumiWeight"] = new TH1D("g_LumiWeight", "g_LumiWeight;LumiWeight;Events", 1000,0,10); - histograms["g_GenWeight"] = new TH1D("g_GenWeight", "g_GenWeight;log_{10}(GenWeight);Events", 1000,-48,2); - histograms["g_pThatWeight"] = new TH1D("g_pThatWeight;log_{10}(pThatWeight);Events","g_pThatWeight", 1000,-48,2); - histograms["g_weight"] = new TH1D("g_weight","g_weight;log_{10}(EvtWeight);Events", 1000,-48,2); - histograms["g_pthat"] = new TH1D("g_pthat","g_pthat;#hat{p}_{T}^{PU};Events",(int)vpt[NPtBins]/10.0,vpt[0],vpt[NPtBins]); - if(!reduceHistograms) { - histograms["g_nj"] = new TH2D("g_nj","g_nj",30,0,30,30,0,30); - histograms["g_npv"] = new TH2D("g_npv","g_npv",50,0,50,50,0,50); - histograms["g_rho"] = new TH2D("g_rho","g_rho",50,0,50,50,0,50); - histograms["g_deltaNpv"] = new TProfile("g_deltaNpv","g_deltaNpv",50,0,50); - } - - // - // HISTOS OF EVENT or JET MATCHING performance, hence the m_ prefix - // - if(!reduceHistograms) { - histograms["m_refpt_diff"] = new TH1D("m_refpt_diff","refpt_diff;p_{T, j1}- p_{T, j2}; Number of events",300,-150,150); - histograms["m_refpdgid_diff"] = new TH1D("m_refpdgid_diff","m_refpdgid_diff;pdgid_{j1}- pdgid_{j2}; Number of events",100,-50,50); - histograms["m_deltaPthat"] = new TProfile("m_deltaPthat","m_deltaPthat;pthat_{pu}(GeV);pthat_{pu}-pthat_{nopu}(GeV)",300,0,3000); - - // To show the excees of jets at low-pt for the sample with pu. - histograms["m_njet_pt_pu"] = new TH1D("m_njet_pt_pu","m_njet_pt_pu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets - histograms["m_njet_pt_nopu"] = new TH1D("m_njet_pt_nopu","m_njet_pt-nopu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets - histograms["m_njet_pthigh_pu"] = new TH1D("m_njet_pthigh_pu","m_njet_pthigh_pu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets - histograms["m_njet_pthigh_nopu"] = new TH1D("m_njet_pthigh_nopu","m_njet_pthigh_nopu;p_{T}^{RECO};#jets;",NPtBins, vpt); // number of jets - - // Fraction of matched jets in all, barrel, endcap and forward regions - histograms["m_frac_nj_pt_b_match_pu"] = new TProfile("m_frac_nj_pt_b_match_pu","m_frac_nj_pt_b_match_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_nopu"] = new TProfile("m_frac_nj_pt_b_match_nopu","m_frac_nj_pt_b_match_nopu;pt_{jet};fraction of matched jets;", NPtBins,vpt); - histograms["m_frac_nj_pt_e_match_pu"] = new TProfile("m_frac_nj_pt_e_match_pu","m_frac_nj_pt_e_match_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_e_match_nopu"] = new TProfile("m_frac_nj_pt_e_match_nopu","m_frac_nj_pt_e_match_nopu;pt_{jet};fraction of matched jets;", NPtBins,vpt); - histograms["m_frac_nj_pt_f_match_pu"] = new TProfile("m_frac_nj_pt_f_match_pu","m_frac_nj_pt_f_match_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_f_match_nopu"] = new TProfile("m_frac_nj_pt_f_match_nopu","m_frac_nj_pt_f_match_nopu;pt_{jet};fraction of matched jets;", NPtBins,vpt); - - // Fraction of matched jets in barrel regions, with different NPV - histograms["m_frac_nj_pt_b_match_pu_npv10"] = new TProfile("m_frac_nj_pt_b_match_pu_npv10","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_nopu_npv1"] = new TProfile("m_frac_nj_pt_b_match_nopu_npv1","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); - histograms["m_frac_nj_pt_b_match_pu_npv20"] = new TProfile("m_frac_nj_pt_b_match_pu_npv20","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_nopu_npv2"] = new TProfile("m_frac_nj_pt_b_match_nopu_npv2","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); - histograms["m_frac_nj_pt_b_match_pu_npv30"] = new TProfile("m_frac_nj_pt_b_match_pu_npv30","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_nopu_npv3"] = new TProfile("m_frac_nj_pt_b_match_nopu_npv3","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); - histograms["m_frac_nj_pt_b_match_pu_npvO"] = new TProfile("m_frac_nj_pt_b_match_pu_npvO","m_frac_nj_pt_b_match_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_nopu_npvO"] = new TProfile("m_frac_nj_pt_b_match_nopu_npvO","m_frac_nj_pt_b_match_nopu_npv;pt_{jet};fraction of matched jets;", NPtBins,vpt); - - // Fraction of matched jets (reconstructed--->generated) in barrel regions, with different NPV - histograms["m_frac_nj_pt_b_match_RG_pu"] = new TProfile("m_frac_nj_pt_b_match_RG_pu","m_frac_nj_pt_b_match_RG_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_e_match_RG_pu"] = new TProfile("m_frac_nj_pt_e_match_RG_pu","m_frac_nj_pt_e_match_RG_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_f_match_RG_pu"] = new TProfile("m_frac_nj_pt_f_match_RG_pu","m_frac_nj_pt_f_match_RG_pu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_RG_nopu"] = new TProfile("m_frac_nj_pt_b_match_RG_nopu","m_frac_nj_pt_b_match_RG_nopu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_e_match_RG_nopu"] = new TProfile("m_frac_nj_pt_e_match_RG_nopu","m_frac_nj_pt_e_match_RG_nopu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_f_match_RG_nopu"] = new TProfile("m_frac_nj_pt_f_match_RG_nopu","m_frac_nj_pt_f_match_RG_nopu;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_RG_pu_npv10"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npv10","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_RG_pu_npv20"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npv20","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_RG_pu_npv30"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npv30","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - histograms["m_frac_nj_pt_b_match_RG_pu_npvO"] = new TProfile("m_frac_nj_pt_b_match_RG_pu_npvO","m_frac_nj_pt_b_match_RG_pu_npv;pt_{jet};fraction of matched jets;", NPtBins, vpt); - - // Number of all jets vs. NPV in PU sample - histograms["m_all_nj_npv"] = new TProfile("m_all_nj_npv","m_all_nj_npv;NPV;# of jets/event",30,0.5,30.5); - - // Number of matched jets vs. NPV in PU sample - histograms["m_matched_nj_npv"] = new TProfile("m_matched_nj_npv","m_matched_nj_npv;NPV;# of jets/event",30,0.5,30.5); - - // Number of unmatched jets vs. NPV in PU sample - histograms["m_unmatched_nj_npv"] = new TProfile("m_unmatched_nj_npv","m_unmatched_nj_npv;NPV;# of jets/event",30,0.5,30.5); - - // Average jet pt vs. NPV in PU sample - histograms["m_all_jtpt_npv"] = new TProfile("m_all_jtpt_npv","m_all_jtpt_npv;NPV; (GeV)", 30, 0.5, 30.5); - - // Average matched jet pt vs. NPV in PU sample - histograms["m_matched_jtpt_npv"] = new TProfile("m_matched_jtpt_npv","m_matched_jtpt_npv;NPV; (GeV)", 30, 0.5, 30.5); - - // Average unmatched jet pt vs. NPV in PU sample - histograms["m_unmatched_jtpt_npv"] = new TProfile("m_unmatched_jtpt_npv","m_unmatched_jtpt_npv;NPV; (GeV)", 30, 0.5, 30.5); - - // Number of unmatched jets per event in different NPV bins. - // 6 old NPV bins 0-4, 5-9, 10-14, 15-19, 20-24, 25-29 - for (int n = 0 ; n < NBinsNpvRhoNpu ; n++) { - TString titles = ";p_{T,J};# PU Jets /event;"; - TString name = Form("m_njet_pt_npv%i_%i_unmatch",n*npvRhoNpuBinWidth,n*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); - histograms[name] = new TProfile(name, name+titles, NPtBins, vpt); // number of jets - - titles = ";#eta_{J}; p_{T,J};# PU Jets /event;"; - name = Form("m_njet_etaVspt_npv%i_%i_unmatch",n*npvRhoNpuBinWidth,n*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); - histograms[name] = new TProfile2D(name, name+titles, NETA, veta, NPtBins, vpt); // number of jets - } - } - - // - // HISTOS OF PU!!!, hence the p_suffix - // - if(!reduceHistograms) { - histograms["p_rhoVsRho"] = new TProfile ("p_rhoVsRho","p_rhoVsRho;",80,0,80); - histograms["p_npvVsNpv"] = new TProfile ("p_npvVsNpv","p_npvVsNpv;",80,0,80); - histograms["p_tnpuVsTnpu"] = new TProfile ("p_tnpuVsTnpu","p_tnpuVsTnpu;",80,0,80); - histograms["p_npuVsNpu"] = new TProfile ("p_npuVsNpu","p_npuVsNpu;",80,0,80); - histograms["p_matchedjet_off"] = new TProfile("p_matchedjet_off","p_matchedjet_off;_{jets} (GeV);# of matched jets",80,0,80); - histograms["p_drVsrefpt"] = new TProfile("p_drVsrefpt","p_drVsrefpt;p_{T}^{GEN};d_{R}",NPtBins, vpt); - - histograms["p_off_etaVsNpv"] = new TProfile2D("p_off_etaVsNpv","p_off_etaVsNpv;#eta_{j};N_{PV};Offset (p_{T}, GeV)",NETA, veta, 50,0,50); - histograms["p_off_etaVsRho"] = new TProfile2D("p_off_etaVsRho","p_off_etaVsRho;#eta_{j};Rho;Offset (p_{T}, GeV)",NETA, veta, 50,0,50); - histograms["p_off_etaVspueff"] = new TProfile2D("p_off_etaVsPUEff","p_off_etaVsPUEff;#eta_{j};PU_{Eff};Offset (p_{T}, GeV)",NETA, veta, 75,0,75); - histograms["p_off_etaVsGenSumPtOA"] = new TProfile2D("p_off_etaVsGenSumPtOA","p_off_etaVsGenSumPtOA;#eta_{j};GenSumPtOA;Offset (p_{T}, GeV)",NETA, veta, 100,0,2000); - histograms["p_off_etaVsJetPt"] = new TProfile2D("p_off_etaVsJetPt","p_off_etaVsJetPt;#eta_{j};p_{T}^{pu};Offset (p_{T}, GeV)",NETA, veta,NPtBins, vpt); - histograms["p_offOverA_etaVsJetPt"] = new TProfile2D("p_offOverA_etaVsJetPt","p_offOverA_etaVsJetPt;#eta_{j};p_{T}^{pu};OffsetOverArea",NETA, veta,NPtBins, vpt); - - histograms["p_off_EOOTVsITVsLOOT"] = new TProfile3D("p_off_EOOTVsITVsLOOT","p_off_EOOTVsITVsLOOT;EOOT;IT;LOOT",NRHO,vrho,NRHO,vrho,NRHO,vrho); - - //Rho - histograms["p_offOverA_etaVsRhoVsJetPt"] = new TProfile3D("p_offOverA_etaVsRhoVsJetPt","p_offOverA_etaVsRhoVsJetPt;#eta_{j};Rho;p_{T}^{gen};OffsetOverAre",NETA,veta,NRHO,vrho,NPtBins,vpt); - histograms["p_PtAve_etaVsRhoVsJetPt"] = new TProfile3D("p_PtAve_etaVsRhoVsJetPt","p_PtAve_etaVsRhoVsJetPt;#eta_{j};Rho;p_{T}^{gen};PtAve",NETA,veta,NRHO,vrho,NPtBins,vpt); - histograms["p_RhoAve_etaVsRhoVsJetPt"] = new TProfile3D("p_RhoAve_etaVsRhoVsJetPt","p_RhoAve_etaVsRhoVsJetPt;#eta_{j};Rho;p_{T}^{gen};RhoAve",NETA,veta,NRHO,vrho,NPtBins,vpt); - - //NPV - histograms["p_offOverA_etaVsNPVVsJetPt"] = new TProfile3D("p_offOverA_etaVsNPVVsJetPt","p_offOverA_etaVsNPVVsJetPt;#eta_{j};NPV;p_{T}^{gen};OffsetOverAre",NETA,veta,NRHO,vrho,NPtBins,vpt); - histograms["p_PtAve_etaVsNPVVsJetPt"] = new TProfile3D("p_PtAve_etaVsNPVVsJetPt","p_PtAve_etaVsNPVVsJetPt;#eta_{j};NPV;p_{T}^{gen};PtAve",NETA,veta,NRHO,vrho,NPtBins,vpt); - histograms["p_RhoAve_etaVsNPVVsJetPt"] = new TProfile3D("p_RhoAve_etaVsNPVVsJetPt","p_RhoAve_etaVsNPVVsJetPt;#eta_{j};NPV;p_{T}^{gen};RhoAve",NETA,veta,NRHO,vrho,NPtBins,vpt); - } - - //TNPU - histograms["p_offOverA_etaVsTnpusVsJetPt"] = new TProfile3D("p_offOverA_etaVsTnpusVsJetPt","p_offOverA_etaVsTnpusVsJetPt;#eta_{j};tnpu;p_{T}^{gen};OffsetOverArea",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); - histograms["p_PtAve_etaVsTnpusVsJetPt"] = new TProfile3D("p_PtAve_etaVsTnpusVsJetPt","p_PtAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); - histograms["p_RhoAve_etaVsTnpusVsJetPt"] = new TProfile3D("p_RhoAve_etaVsTnpusVsJetPt","p_RhoAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); - histograms["p_Events_etaVsTnpusVsJetPt"] = new TH3I("p_Events_etaVsTnpusVsJetPt","p_RhoAve_etaVsTnpusVsJetPt;#eta_{j};Tnpus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); - //THnSparse with 4 dimensions - Int_t bins[4] = {NETA, NRHO, NTNPU, NPtBins}; - Double_t min[4] = {veta[0], vrho[0], vtnpu[0], vpt[0]}; - Double_t max[4] = {veta[NETA-1], vrho[NRHO-1], vtnpu[NTNPU-1], vpt[NPtBins-1]}; - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"] = new THnSparseF("p_offOverA_etaRhoVsTnpusVsJetPt", "p_offOverA_etaVsRhoVsTnpusVsJetPt", 4, bins, min, max); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(0,veta); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(1,vrho); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(2,vtnpu); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->SetBinEdges(3,vpt); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(0)->SetTitle("#eta_{j}"); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(1)->SetTitle("Rho"); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(2)->SetTitle("tnpu"); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetAxis(3)->SetTitle("p_{T}^{gen}"); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->Sumw2(); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"] = new THnSparseF("p_PtAve_etaRhoVsTnpusVsJetPt", "p_PtAve_etaVsRhoVsTnpusVsJetPt", 4, bins, min, max); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(0,veta); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(1,vrho); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(2,vtnpu); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->SetBinEdges(3,vpt); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(0)->SetTitle("#eta_{j}"); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(1)->SetTitle("Rho"); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(2)->SetTitle("tnpu"); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->GetAxis(3)->SetTitle("p_{T}^{gen}"); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->Sumw2(); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"] = new THnSparseF("p_entries_etaRhoVsTnpusVsJetPt", "p_entries_etaRhoVsTnpusVsJetPt", 4, bins, min, max); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(0,veta); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(1,vrho); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(2,vtnpu); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->SetBinEdges(3,vpt); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(0)->SetTitle("#eta_{j}"); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(1)->SetTitle("Rho"); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(2)->SetTitle("tnpu"); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->GetAxis(3)->SetTitle("p_{T}^{gen}"); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->Sumw2(); - if (!fValue) fValue = new Double_t[4]; - - //NPU - histograms["p_offOverA_etaVsNpusVsJetPt"] = new TProfile3D("p_offOverA_etaVsNpusVsJetPt","p_offOverA_etaVsNpusVsJetPt;#eta_{j};npu;p_{T}^{gen};OffsetOverAre",NETA,veta,NNPU,vnpu,NPtBins,vpt); - histograms["p_PtAve_etaVsNpusVsJetPt"] = new TProfile3D("p_PtAve_etaVsNpusVsJetPt","p_PtAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NNPU,vnpu,NPtBins,vpt); - histograms["p_RhoAve_etaVsNpusVsJetPt"] = new TProfile3D("p_RhoAve_etaVsNpusVsJetPt","p_RhoAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NNPU,vnpu,NPtBins,vpt); - histograms["p_Events_etaVsNpusVsJetPt"] = new TH3I("p_Events_etaVsNpusVsJetPt","p_RhoAve_etaVsNpusVsJetPt;#eta_{j};Npus;p_{T}^{gen};PtAve",NETA,veta,NTNPU,vtnpu,NPtBins,vpt); - - if(!reduceHistograms) { - //NPV+Rho - histograms["p_offOverA_etaVsN_RVsJetPt"] = new TProfile3D("p_offOverA_etaVsN_RVsJetPt","p_offOverA_etaVsN_RVsJetPt;#eta_{j};(NPV+Rho)/2;p_{T}^{gen};OffsetOverAre",NETA,veta,NRHO,vrho,NPtBins,vpt); - histograms["p_PtAve_etaVsN_RVsJetPt"] = new TProfile3D("p_PtAve_etaVsN_RVsJetPt","p_PtAve_etaVsN_RVsJetPt;#eta_{j};(NPV+Rho)/2;p_{T}^{gen};PtAve",NETA,veta,NRHO,vrho,NPtBins,vpt); - - histograms["p_offsetOA_rho_npv_refpt_BB"] = new TProfile3D("p_offsetOA_rho_npv_refpt_BB","p_offsetOA_rho_npv_refpt_BB;Rho;N_{PV};p_{T}^{GEN};offsetOA",NRHO,vrho,NRHO,vrho,NPtBins,vpt); - histograms["p_npvVsoff"] = new TH2F("p_npvVsOff","p_npvVsOff;_{jets} (GeV);N_{PV}",80,0,80,80,0,80); - histograms["p_rhoVsoff"] = new TH2F("p_rhoVsOff","p_rhoVsOff;_{jets} (GeV);Rho",80,0,80,80,0,80); - histograms["p_areaVsrefpt"] = new TH2F("p_areaVsrefpt","p_areaVsrefpt;p_{T}^{GEN};jtarea^{pu}-jtarea^{nopu}",NPtBins, vpt,100,-1,1); - histograms["p_areaVsoffset_1000"] = new TH2F("p_areaVsoffset_1000","p_areaVsoffset_1000;offset;jtarea^{pu}-jtarea^{nopu}",100,-500,500,100,-1,1); - histograms["p_areaVsoffset_30_50"] = new TH2F("p_areaVsoffset_30_50","p_areaVsoffset_30_50;offset;jtarea^{pu}-jtarea^{nopu}",100,-100,100,100,-1,1); - - histograms["p_rho_npv_refpt_BB"] = new TH3F("p_rho_npv_refpt_BB","p_rho_npv_refpt_BB;Rho;N_{PV};p_{T}^{GEN}",NRHO,vrho,NRHO,vrho,NPtBins,vpt); - } - - // Break into 4 different detector region - TString hname = ""; - for (int det=0;det_{jets} (GeV);N_{PV}", - 80,0,80,80,0,80); - hname = Form("p_rhoVsOff_%s",detectorAbbreviation.Data()); - histograms[hname] = new TH2D(hname,hname+";_{jets} (GeV);Rho", - 80,0,80,80,0,80); - - //Offset Vs. p_{T} in bins of PF category - for (int iPF=0;iPF::iterator it=histograms.begin(); it!=histograms.end(); ++it) { - it->second->Sumw2(); - } -} - -//______________________________________________________________________________ -void MatchEventsAndJets::LoopOverEvents(bool verbose, bool reduceHistograms, string readJetMap, string outputPath) { - //First just figure out if the jetMapTree exists, assuming readJetMap is set. - //It might be that the program failed after the event mapping, so the event maps exist, but not the jet maps - //In this case the event maps should be read, but the jet maps should be recreated. - jetMapTreeFound = false;// (readJetMap.empty()) ? false : GetJetMap(readJetMap); - - if (!mapEventMatch.size()) { - cout< maxEvts && iftest) ? maxEvts : mapEventMatch.size(); - for (IT::const_iterator it = mapEventMatch.begin(); it != mapEventMatch.end() && nevs < nentries; ++it) { - - loadbar2(nevs+1,nentries,50,"\t\t"); - - // Load the entries at the proper place. - tpu->GetEntry(it->second.first); - tnopu->GetEntry(it->second.second); - - //Skip events without any primary vertex as these make no sense - if (tpu->npv == 0 || tnopu->npv == 0) { - nevs++; - continue; - } - // Set the in-time pileup index after the first event only - if(nevs==0) iIT = tpu->itIndex(); - - // Create the mapping of matched jets. - // key is PU, value is for NoPU - //if(!readJetMap) FillJetMap(); - if(readJetMap.empty() || !jetMapTreeFound) { - FillRecToRecThroughGenMap(); - } - else { - jetMapIndex++; - ReadJetMap(jetMapIndex,readJetMap); - } - - FillHistograms(reduceHistograms,it); - - nevs++; - - }//for - cout< > auxMap; - - // Order j1 according to reco-jet pT - vector j1o; - j1o.push_back(0); - for (int j1=1; j1 < tpu->nref; j1++){ - for (unsigned ito = 0; ito < j1o.size(); ++ito){ - if (tpu->jtpt->at(j1) > tpu->jtpt->at(j1o[ito])){ - j1o.insert(j1o.begin()+ito,j1); - break; - } - } - } - if (nrefmax > 0 && nrefmax < (int)j1o.size()) j1o.resize(nrefmax); - - for (int j1=0; j1 < tpu->nref; j1++){ - for (int j2=0; j2 < tnopu->nref; j2++){ - double dR = pow(tpu->jteta->at(j1o[j1]) - tnopu->jteta->at(j2),2); - dR += pow(tpu->jtphi->at(j1o[j1]) - tnopu->jtphi->at(j2),2); - dR = sqrt(dR); - auxMap[dR] = std::make_pair(j1o[j1], j2); - } - } - - // First clear the map for this new set of events - jetMap.clear(); - - // 1-Find the pair of jets with the smallest dr. Add them to resulting map - // 2-Remove the pair from the map, rinse and repeat. - while (auxMap.size() > 0){ - // 1- The first element which is the one with the smallest dR. Get the jet indexes - int j1 = auxMap.begin()->second.first; - int j2 = auxMap.begin()->second.second; - - // Add to the results - if (auxMap.begin()->first < maxDeltaR && fabs(tpu->refpt->at(j1) - tnopu->refpt->at(j2))<1 && tnopu->refdrjt->at(j2) < maxDeltaR) - jetMap[j1] = j2; - - // 2- Now remove all elements from the auxMap that contain either the first or second jet - ITJ::iterator itr = auxMap.begin(); - while(itr != auxMap.end()){ - if (itr->second.first == j1 || itr->second.second == j2) - auxMap.erase(itr++); - else - ++itr; - }//while removing - }//while -}//FillJetMap - -//______________________________________________________________________________ -void MatchEventsAndJets::FillRecToRecThroughGenMap() { - jetMap.clear(); - if(!recoJetIndexPU) recoJetIndexPU = new vector; - if(!recoJetIndexNoPU) recoJetIndexNoPU = new vector; - recoJetIndexPU->clear(); - recoJetIndexNoPU->clear(); - if (nrefmax>=0) tpu->nref = std::min((int)tpu->nref,nrefmax); - for (int iRefPU=0; iRefPU < tpu->nref; iRefPU++) { - int j1 = iRefPU; - int j2 = -1; - for (int iRefNoPU=0; iRefNoPU < tnopu->nref; iRefNoPU++) { - if(tnopu->refpt->at(iRefNoPU)==tpu->refpt->at(iRefPU)) { - j2 = iRefNoPU; - break; - } - } - if(j1 >= 0 && j2 >= 0 && j1 < tpu->nref && j2 < tnopu->nref && - tpu->refdrjt->at(j1) < maxDeltaR && tnopu->refdrjt->at(j2) < maxDeltaR && - fabs(tpu->refpt->at(j1) - tnopu->refpt->at(j2))<0.0001 - ) { - jetMap[j1] = j2; - } - recoJetIndexPU->push_back(j1); - recoJetIndexNoPU->push_back(j2); - } - - //Initialize the jetMapTree if it has not already been initialized - if(!jetMapTree) { - jetMapTree = new TTree("jetMapTree","jetMapTree"); - jetMapTree->Branch("recoJetIndexPU", "vector",&recoJetIndexPU); - jetMapTree->Branch("recoJetIndexNoPU","vector",&recoJetIndexNoPU); - jetMapTree->SetDirectory(0); - } - //Always fill the jet map tree - jetMapTree->Fill(); - -}//FillRecToRecThroughGenMap - -//______________________________________________________________________________ -bool MatchEventsAndJets::GetJetMap(string readJetMap) { - //Retrieve the tree from a file - cout << endl << "Reading matched jets tree:" << endl - << "\tfile: " << readJetMap << endl; - - TDirectory* curDir = gDirectory; - TFile* mapFile = TFile::Open(readJetMap.c_str(),"READ"); - - auto inTreePointer = (TTree*)mapFile->Get("jetMapTree"); - if(inTreePointer) { - jetMapTree = (TTree*)inTreePointer->Clone(); - cout << "\tjetMapTree:" << endl - << "\t\tnevts: " << jetMapTree->GetEntries() << endl; - } - else { - cout << "\tWARNING::MatchEventsAndJets::GetJetMap Could not retrieve the jetMapTree pointer from " << readJetMap << endl; - return false; - } - jetMapTree->SetDirectory(0); - jetMapTree->SetBranchAddress("recoJetIndexPU", &recoJetIndexPU); - jetMapTree->SetBranchAddress("recoJetIndexNoPU",&recoJetIndexNoPU); - - mapFile->Close(); - curDir->cd(); - return true; -} - -//______________________________________________________________________________ -void MatchEventsAndJets::ReadJetMap(int ientry, string readJetMap) { - //Just a small sanity check - if(!jetMapTree) { - cout << "ERROR::MatchEventsAndJets::ReadJetMap At this point the jetMapTree should have been retrieved from " << readJetMap << endl; - std::terminate(); - } - - //Create the map based on the vectors from the jetMapTree - jetMapTree->GetEntry(ientry); - jetMap.clear(); - for(unsigned int i = 0; isize() && ((nrefmax>=0)?i<(unsigned)nrefmax:true); i++) { - if(recoJetIndexPU->at(i) >= 0 && recoJetIndexNoPU->at(i) >= 0 && - recoJetIndexPU->at(i) < tpu->nref && recoJetIndexNoPU->at(i) < tnopu->nref && - tpu->refdrjt->at(recoJetIndexPU->at(i)) < maxDeltaR && - tnopu->refdrjt->at(recoJetIndexNoPU->at(i)) < maxDeltaR && - fabs(tpu->refpt->at(recoJetIndexPU->at(i)) - tnopu->refpt->at(recoJetIndexNoPU->at(i)))<0.0001) { - jetMap[recoJetIndexPU->at(i)] = recoJetIndexNoPU->at(i); - } - } -} - - -//______________________________________________________________________________ -bool MatchEventsAndJets::FillHistograms(bool reduceHistograms, IT::const_iterator it) { - //========================================================= - // FILLING OF HISTOS START HERE - //========================================================= - - // - // retrieve the correct weight and fill some histograms to keep track of them - // - weight = 1.0; - if(useweight) { - weight *= tpu->weight; - dynamic_cast(histograms["g_GenWeight"]) ->Fill(log(tpu->weight)); // The GenWeight - } - if(LumiWeightsSet_) { - weight *= LumiWeights_.weight(tpu->tnpus->at(iIT)); - dynamic_cast(histograms["g_LumiWeight"]) ->Fill(LumiWeights_.weight(tpu->tnpus->at(iIT))); // The LumiWeight - } - if(pThatReweight) { - weight *= pow(tpu->pthat/bias2SelectionRef,bias2SelectionPow); - dynamic_cast(histograms["g_pThatWeight"]) ->Fill(log(pow(tpu->pthat/bias2SelectionRef,bias2SelectionPow))); // The pThat weight - } - dynamic_cast(histograms["g_weight"]) ->Fill(log(weight)); // The overall weight - - // GENERAL HISTOS, no cuts. - dynamic_cast(histograms["g_pthat"]) ->Fill(tpu->pthat,weight); // pthat distributions - if(!reduceHistograms) { - dynamic_cast(histograms["g_nj"]) ->Fill(tpu->nref,tnopu->nref,weight); // njet distributions - dynamic_cast(histograms["g_npv"]) ->Fill(tpu->npv,tnopu->npv,weight); // npv dist. - dynamic_cast(histograms["g_rho"]) ->Fill(tpu->rho,tnopu->rho,weight); // rho dist - dynamic_cast(histograms["g_deltaNpv"]) ->Fill(tpu->npv,tpu->npv - tnopu->npv,weight); // Does the number of NPV change? - dynamic_cast(histograms["m_deltaPthat"])->Fill(tpu->pthat,tpu->pthat-tnopu->pthat,weight); // pthat sanity check - } - - //Skip events where the noPU sample has more than one vertex - if (tnopu->npv!=1) { - noPUNpvGTOneEventCounter++; - if(noPUNpvGTOneEventCounter==0) { - cout << "\tWARNING::The NoPU sample has more than 1 PV." << endl - << "\tSome events will be skipped (including this one)." << endl; - } - return false; - } - - inpv = JetInfo::getBinIndex(tpu->npv,NBinsNpvRhoNpu,npvRhoNpuBinWidth); - inpv_low = inpv*npvRhoNpuBinWidth; - inpv_high = inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; - irho = JetInfo::getBinIndex(tpu->rho,NBinsNpvRhoNpu,npvRhoNpuBinWidth); - irho_low = irho*npvRhoNpuBinWidth; - irho_high = irho*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; - itnpu = JetInfo::getBinIndex(tpu->tnpus->at(iIT),NBinsNpvRhoNpu,npvRhoNpuBinWidth); - itnpu_low = itnpu*npvRhoNpuBinWidth; - itnpu_high = itnpu*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; - inpu = JetInfo::getBinIndex(tpu->npus->at(iIT),NBinsNpvRhoNpu,npvRhoNpuBinWidth); - inpu_low = inpu*npvRhoNpuBinWidth; - inpu_high = inpu*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1; - TString hname = ""; - - // - // Applying JEC from textfile - // - vector tpu_jtpt_raw; - if (JetCorrector) { - double correction = 1.0; - //for (int j1 = 0; j1 < tpu->nref; j1++) { - for (map::const_iterator j1it = jetMap.begin(); j1it != jetMap.end(); j1it++) { - int j1 = j1it->first; - JetCorrector->setJetEta(tpu->jteta->at(j1)); - JetCorrector->setJetPt(tpu->jtpt->at(j1)); - JetCorrector->setJetA(tpu->jtarea->at(j1)); - JetCorrector->setRho(tpu->rho); - correction = JetCorrector->getCorrection(); - //cout <jtpt->at(j1); - tpu_jtpt_raw.push_back(tpu->jtpt->at(j1)); - tpu->jtpt->at(j1) *= correction; - //cout <<" "<jtpt->at(j1)<::const_iterator j1it = jetMap.begin(); j1it != jetMap.end(); j1it++) { - int j1 = j1it->first; - if(j1 == -1) continue; - - // matching reco-jet with gen-jet - bool ismatchRG = tpu->refdrjt->at(j1)Fill(tpu->jtpt->at(j1)); - if(tpu->refpt->at(j1)>10){ - histograms["m_njet_pthigh_pu"]->Fill(tpu->jtpt->at(j1)); - } - - avg_jtpt_all += tpu->jtpt->at(j1); - - // if j1 is matched in this sample - bool ismatch = jetMap.find(j1) != jetMap.end(); - - if (ismatch) avg_jtpt_matched += tpu->jtpt->at(j1); - else avg_jtpt_unmatched += tpu->jtpt->at(j1); - - if (fabs(tpu->jteta->at(j1))<1.3) { - histograms["m_frac_nj_pt_b_match_pu"] ->Fill(tpu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_b_match_RG_pu"]->Fill(tpu->jtpt->at(j1),ismatchRG); - if (tpu->npv<=10) { - histograms["m_frac_nj_pt_b_match_pu_npv10"] ->Fill(tpu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_b_match_RG_pu_npv10"]->Fill(tpu->jtpt->at(j1),ismatchRG); - } - else if (tpu->npv<=20) { - histograms["m_frac_nj_pt_b_match_pu_npv20"] ->Fill(tpu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_b_match_RG_pu_npv20"]->Fill(tpu->jtpt->at(j1),ismatchRG); - } - else if (tpu->npv<=30) { - histograms["m_frac_nj_pt_b_match_pu_npv30"] ->Fill(tpu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_b_match_RG_pu_npv30"]->Fill(tpu->jtpt->at(j1),ismatchRG); - } - else { - histograms["m_frac_nj_pt_b_match_pu_npvO"] ->Fill(tpu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_b_match_RG_pu_npvO"]->Fill(tpu->jtpt->at(j1),ismatchRG); - } - } - else if (fabs(tpu->jteta->at(j1))<3) { - histograms["m_frac_nj_pt_e_match_pu"] ->Fill(tpu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_e_match_RG_pu"]->Fill(tpu->jtpt->at(j1),ismatchRG); - } - else { - histograms["m_frac_nj_pt_f_match_pu"] ->Fill(tpu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_f_match_RG_pu"]->Fill(tpu->jtpt->at(j1),ismatchRG); - } - if (!ismatch) { - hname = Form("m_njet_pt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); - histograms[hname]->Fill(tpu->jtpt->at(j1),+1); - hname = Form("m_njet_etaVspt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); - dynamic_cast(histograms[hname])->Fill(tpu->jteta->at(j1), tpu->jtpt->at(j1),+1); - } - } - - if (tpu->nref>0) avg_jtpt_all /= (double) tpu->nref; else avg_jtpt_all = 0; - if (jetMap.size()>0) avg_jtpt_matched /= (double) jetMap.size(); else avg_jtpt_matched = 0; - if (tpu->nref-jetMap.size()>0) avg_jtpt_unmatched /= (double) (tpu->nref - jetMap.size()); else avg_jtpt_unmatched = 0; - - histograms["m_all_nj_npv"] ->Fill(tpu->npv,tpu->nref); - histograms["m_matched_nj_npv"] ->Fill(tpu->npv, jetMap.size()); - histograms["m_unmatched_nj_npv"]->Fill(tpu->npv, tpu->nref-jetMap.size()); - - histograms["m_all_jtpt_npv"] ->Fill(tpu->npv, avg_jtpt_all); - histograms["m_matched_jtpt_npv"] ->Fill(tpu->npv, avg_jtpt_matched); - histograms["m_unmatched_jtpt_npv"]->Fill(tpu->npv, avg_jtpt_unmatched); - - // fill unmatch jets for NOPU sample - for (map::const_iterator j1it = jetMap.begin(); j1it != jetMap.end(); j1it++) { - int j1 = j1it->second; - if(j1 == -1) continue; - - histograms["m_njet_pt_nopu"]->Fill(tnopu->jtpt->at(j1)); - if(tnopu->refpt->at(j1)>10){ - histograms["m_njet_pthigh_nopu"]->Fill(tnopu->jtpt->at(j1)); - } - - bool ismatchRG = tnopu->refdrjt->at(j1)::const_iterator itj = jetMap.begin(); itj != jetMap.end(); itj++) { - if (itj->second == j1){ - ismatch = true; - break; - } - } - - if (fabs(tnopu->jteta->at(j1))<1.3) { - histograms["m_frac_nj_pt_b_match_nopu"] ->Fill(tnopu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_b_match_RG_nopu"]->Fill(tnopu->jtpt->at(j1),ismatchRG); - if (tpu->npv<=10) - histograms["m_frac_nj_pt_b_match_nopu_npv1"]->Fill(tnopu->jtpt->at(j1),ismatch); - else if (tpu->npv<=20) - histograms["m_frac_nj_pt_b_match_nopu_npv2"]->Fill(tnopu->jtpt->at(j1),ismatch); - else if (tpu->npv<=30) - histograms["m_frac_nj_pt_b_match_nopu_npv3"]->Fill(tnopu->jtpt->at(j1),ismatch); - else - histograms["m_frac_nj_pt_b_match_nopu_npvO"]->Fill(tnopu->jtpt->at(j1),ismatch); - } - else if (fabs(tnopu->jteta->at(j1))<3) { - histograms["m_frac_nj_pt_e_match_nopu"] ->Fill(tnopu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_e_match_RG_nopu"]->Fill(tnopu->jtpt->at(j1),ismatchRG); - } - else { - histograms["m_frac_nj_pt_f_match_nopu"] ->Fill(tnopu->jtpt->at(j1),ismatch); - histograms["m_frac_nj_pt_f_match_RG_nopu"]->Fill(tnopu->jtpt->at(j1),ismatchRG); - } - if (!ismatch) { - hname = Form("m_njet_pt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); - histograms[hname]->Fill(tnopu->jtpt->at(j1),-1); - hname = Form("m_njet_etaVspt_npv%i_%i_unmatch",inpv*npvRhoNpuBinWidth,inpv*npvRhoNpuBinWidth+npvRhoNpuBinWidth-1); - dynamic_cast(histograms[hname])->Fill(tnopu->jteta->at(j1), tnopu->jtpt->at(j1),-1); - } - } - } - - double avg_offset = 0; - double avg_offset_det[NDetectorNames] = {0,0,0,0}; - double njet_det[NDetectorNames] = {0,0,0,0}; - - // MATCHING HISTOS. - // Loop over matched jets - int jpu = -1; - int jnopu = -1; - int idet = -1; - TString detectorAbbreviation; - double offset = 0, offset_raw = 0, offsetOA = 0, offsetOrefpt = 0, areaDiff = 0, resp = 0, - respTonopu = 0, respNopu = 0, PUEff = 0, GenSumPtOA = 0; - int diff_pdgid = 0; - vector offset_PFcat; - for (map::const_iterator itj = jetMap.begin(); itj != jetMap.end(); itj++) { - - jpu = itj->first; - jnopu = itj->second; - if(jpu == -1 || jnopu == -1) continue; - - - - if (!tpu->jtarea->at(jpu) || TMath::IsNaN(tpu->jtarea->at(jpu)) || fabs(tpu->jtarea->at(jpu))==TMath::Infinity() || ((minPhi || maxPhi) && (tpu->jtphi->at(jpu)jtphi->at(jpu)>maxPhi))) continue; - - -//======Veto regions for UL2017 --> HEP17 (1.31, -0.5236, 2.96, -0.8727) , HBPw89 (0, 2.705, 1.4835, 3.1416 ) =========== -//if (!tpu->jtarea->at(jpu) || TMath::IsNaN(tpu->jtarea->at(jpu)) || fabs(tpu->jtarea->at(jpu))==TMath::Infinity() || ( (tpu->jtphi->at(jpu)<-0.5236 && tpu->jtphi->at(jpu)>-0.8727 && tpu->jteta->at(jpu)<2.96 && tpu->jteta->at(jpu)>1.31)|| ( tpu->jtphi->at(jpu)>2.705 && tpu->jtphi->at(jpu)<3.1416 && tpu->jteta->at(jpu)>0. && tpu->jteta->at(jpu)<1.4835) )) continue; - -//=== veto region for UL2018 ======= -//if (!tpu->jtarea->at(jpu) || TMath::IsNaN(tpu->jtarea->at(jpu)) || fabs(tpu->jtarea->at(jpu))==TMath::Infinity() || (tpu->jtphi->at(jpu)<-0.8727 && tpu->jtphi->at(jpu)>-1.5708 && tpu->jteta->at(jpu) < -1.31 && tpu->jteta->at(jpu)> -2.96) || (tpu->jtphi->at(jpu)>0.4363 && tpu->jtphi->at(jpu)<0.7854 && tpu->jteta->at(jpu) >0 && tpu->jteta->at(jpu)<1.31) continue; - -//cout << "JetPhi" << tpu->jtphi->at(jpu) << endl; - - - idet = JetInfo::getDetIndex(tpu->jteta->at(jpu)); - detectorAbbreviation = JetInfo::get_detector_abbreviation(detector_names[idet]); - detectorAbbreviation.ToLower(); - vector pdgid_indecies = JetInfo::getPDGIDIndecies(tpu->refpdgid->at(jpu)); - - diff_pdgid = tpu->refpdgid->at(jpu) - tnopu->refpdgid->at(jnopu); - offset = tpu->jtpt->at(jpu) - tnopu->jtpt->at(jnopu); - offset_raw = (tpu_jtpt_raw.size()>0) ? tpu_jtpt_raw[jpu] - tnopu->jtpt->at(jnopu) : -1.0; - offsetOA = offset / tpu->jtarea->at(jpu); - offsetOrefpt = offset / tpu->refpt->at(jpu); - areaDiff = tpu->jtarea->at(jpu) - tnopu->jtarea->at(jnopu); - resp = tpu->jtpt->at(jpu) / tpu->refpt->at(jpu); // response relative to reference jet - respTonopu = tpu->jtpt->at(jpu) / tnopu->jtpt->at(jnopu);// response relative to no pu jet - respNopu = tnopu->jtpt->at(jnopu) / tnopu->refpt->at(jnopu); // response no pu jet to reference jet - PUEff = 0.020*(tpu->sumEOOT())+0.975*(tpu->npus->at(iIT))+0.005*(tpu->sumLOOT()); // effective pu - GenSumPtOA = (0.020*(tpu->sumpt_lowpt->at(0))+0.975*(tpu->sumpt_lowpt->at(1))+0.005*(tpu->sumpt_lowpt->at(2)))/tpu->jtarea->at(jpu); - - if (fabs(offsetOA)>300) eventlist<second.first<second.second<evt<run<jtarea->at(jpu)<jtpt->at(jpu)<jtpt->at(jnopu)<(histograms["p_off_etaVsNpv"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,offset,weight); - dynamic_cast(histograms["p_off_etaVsRho"]) ->Fill(tpu->jteta->at(jpu),tpu->rho,offset,weight); - dynamic_cast(histograms["p_off_etaVspueff"]) ->Fill(tpu->jteta->at(jpu),PUEff,offset,weight); - dynamic_cast(histograms["p_off_etaVsGenSumPtOA"])->Fill(tpu->jteta->at(jpu),GenSumPtOA,offset,weight); - dynamic_cast(histograms["p_off_etaVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->jtpt->at(jpu),offset,weight); - dynamic_cast(histograms["p_offOverA_etaVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->jtpt->at(jpu),offsetOA,weight); - dynamic_cast(histograms["p_off_EOOTVsITVsLOOT"]) ->Fill(tpu->sumEOOT(),tpu->npus->at(iIT),tpu->sumLOOT(),offset,weight); - - //Rho - dynamic_cast(histograms["p_offOverA_etaVsRhoVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->rho,tpu->refpt->at(jpu),offsetOA,weight); - dynamic_cast(histograms["p_RhoAve_etaVsRhoVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->rho,tpu->refpt->at(jpu),tpu->rho,weight); - dynamic_cast(histograms["p_PtAve_etaVsRhoVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->rho,tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); - - //NPV - dynamic_cast(histograms["p_offOverA_etaVsNPVVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->npv,tpu->refpt->at(jpu),offsetOA,weight); - dynamic_cast(histograms["p_RhoAve_etaVsNPVVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,tpu->refpt->at(jpu),tpu->rho,weight); - dynamic_cast(histograms["p_PtAve_etaVsNPVVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npv,tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); - } - - int etabin = 60; - int tnpubin = 6; - int ptbin = 26; - - bool cond = true; - cond &= tpu->jteta->at(jpu)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetXaxis()->GetBinLowEdge(etabin); - cond &= tpu->jteta->at(jpu)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetXaxis()->GetBinUpEdge(etabin); - cond &= tpu->tnpus->at(iIT)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetYaxis()->GetBinLowEdge(tnpubin); - cond &= tpu->tnpus->at(iIT)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetYaxis()->GetBinUpEdge(tnpubin); - cond &= tpu->refpt->at(jpu)>dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetZaxis()->GetBinLowEdge(ptbin); - cond &= tpu->refpt->at(jpu)(histograms["p_offOverA_etaVsTnpusVsJetPt"])->GetZaxis()->GetBinUpEdge(ptbin); - - if (cond) dynamic_cast(histograms["h_onebin"])->Fill(offsetOA,weight); - //TNPU - - dynamic_cast(histograms["p_offOverA_etaVsTnpusVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),offsetOA,weight); - dynamic_cast(histograms["p_PtAve_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); - dynamic_cast(histograms["p_RhoAve_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu),tpu->rho,weight); - dynamic_cast(histograms["p_Events_etaVsTnpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->tnpus->at(iIT),tpu->refpt->at(jpu)); - - fValue[0] = tpu->jteta->at(jpu); - fValue[1] = tpu->rho; - fValue[2] = tpu->tnpus->at(iIT); - fValue[3] = tpu->refpt->at(jpu); - hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->Fill(fValue,offsetOA*weight); - hsparse["p_PtAve_etaRhoVsTnpusVsJetPt"]->Fill(fValue,tpu->jtpt->at(jpu)*weight); - hsparse["p_entries_etaRhoVsTnpusVsJetPt"]->Fill(fValue,weight); - //if(hsparse["p_offOverA_etaRhoVsTnpusVsJetPt"]->GetBin(fValue)==8500) { - // avg_debug +=offsetOA; - // entries_debug++; - //} - - //NPU (weight of NPU if tnpu is single valued at 20 = 1.0/TMath::Gaus(tpu->npus->at(iIT),20,sqrt(20)) - dynamic_cast(histograms["p_offOverA_etaVsNpusVsJetPt"])->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),offsetOA,weight); - dynamic_cast(histograms["p_PtAve_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); - dynamic_cast(histograms["p_RhoAve_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu),tpu->rho,weight); - dynamic_cast(histograms["p_Events_etaVsNpusVsJetPt"]) ->Fill(tpu->jteta->at(jpu),tpu->npus->at(iIT),tpu->refpt->at(jpu)); - - if(!reduceHistograms) { - //NPV+Rho - dynamic_cast(histograms["p_offOverA_etaVsN_RVsJetPt"]) ->Fill(tpu->jteta->at(jpu),(tpu->rho+tpu->npv)/2.,tpu->refpt->at(jpu),offsetOA,weight); - dynamic_cast(histograms["p_PtAve_etaVsN_RVsJetPt"]) ->Fill(tpu->jteta->at(jpu),(tpu->rho+tpu->npv)/2,tpu->refpt->at(jpu),tpu->jtpt->at(jpu),weight); - dynamic_cast(histograms["p_areaVsrefpt"]) ->Fill(tpu->refpt->at(jpu),areaDiff,weight); - if (tpu->refpt->at(jpu)>1000) - dynamic_cast(histograms["p_areaVsoffset_1000"]) ->Fill(offset,areaDiff,weight); - if (tpu->refpt->at(jpu)>30 && tpu->refpt->at(jpu)<50) - dynamic_cast(histograms["p_areaVsoffset_30_50"]) ->Fill(offset,areaDiff,weight); - - dynamic_cast(histograms["p_drVsrefpt"])->Fill(tpu->refpt->at(jpu),tpu->refdrjt->at(jpu),weight); - dynamic_cast(histograms["m_refpt_diff"]) ->Fill(tpu->refpt->at(jpu) - tnopu->refpt->at(jnopu),weight); - dynamic_cast(histograms["m_refpdgid_diff"])->Fill(diff_pdgid,weight); - - if (idet == 0) { - dynamic_cast(histograms["p_rho_npv_refpt_BB"]) ->Fill(tpu->rho,tpu->npv,tpu->refpt->at(jpu),weight); - dynamic_cast(histograms["p_offsetOA_rho_npv_refpt_BB"])->Fill(tpu->rho,tpu->npv,tpu->refpt->at(jpu),offsetOA,weight); - } - - //Break into detector regions and PF candidate types - //nef,cef,muf,nhf,hfhf,hfef,chf - if(!algo1JetInfo.jetType.Contains("calo",TString::kIgnoreCase) && !algo2JetInfo.jetType.Contains("calo",TString::kIgnoreCase)) { - offset_PFcat = vector{tpu->jtpt->at(jpu)*tpu->jtnef->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtnef->at(jnopu), - tpu->jtpt->at(jpu)*tpu->jtcef->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtcef->at(jnopu), - tpu->jtpt->at(jpu)*tpu->jtmuf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtmuf->at(jnopu), - tpu->jtpt->at(jpu)*tpu->jtnhf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtnhf->at(jnopu), - tpu->jtpt->at(jpu)*tpu->jthfhf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jthfhf->at(jnopu), - tpu->jtpt->at(jpu)*tpu->jthfef->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jthfef->at(jnopu), - tpu->jtpt->at(jpu)*tpu->jtchf->at(jpu) - tnopu->jtpt->at(jnopu)*tnopu->jtchf->at(jnopu)}; - } - else { - offset_PFcat = vector{0,0,0,0,0,0,0}; - } - for (int iPF=0;iPF(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF],weight); - hname = Form("p_offResOtnpuVsrefpt_%s_%s",detectorAbbreviation.Data(),PFstr[iPF].Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF]/tpu->tnpus->at(iIT),weight); - hname = Form("prof_offResVsrefpt_%s_%s",detectorAbbreviation.Data(),PFstr[iPF].Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF],weight); - hname = Form("prof_offResOtnpuVsrefpt_%s_%s",detectorAbbreviation.Data(),PFstr[iPF].Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset_PFcat[iPF]/tpu->tnpus->at(iIT),weight); - } - hname = Form("p_offResVsrefpt_%s_all",detectorAbbreviation.Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_offResOtnpuVsrefpt_%s_all",detectorAbbreviation.Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/tpu->tnpus->at(iIT),weight); - hname = Form("prof_offResVsrefpt_%s_all",detectorAbbreviation.Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("prof_offResOtnpuVsrefpt_%s_all",detectorAbbreviation.Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/tpu->tnpus->at(iIT),weight); - } - - //Break into detector regions - hname = Form("p_resVsrefpt_%s",detectorAbbreviation.Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); - hname = Form("np_resVsrefpt_%s",detectorAbbreviation.Data()); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); - - //TNPU - hname = Form("p_resVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),itnpu_low,itnpu_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); - hname = Form("p_offresVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),itnpu_low,itnpu_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_offresVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_nopuresVsrefpt_%s_tnpu%i_%i",detectorAbbreviation.Data(),itnpu_low,itnpu_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); - - //NPU - hname = Form("p_resVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),inpu_low,inpu_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); - hname = Form("p_offresVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),inpu_low,inpu_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_offresVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_nopuresVsrefpt_%s_npu%i_%i",detectorAbbreviation.Data(),inpu_low,inpu_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); - - if(!reduceHistograms) { - //NPV - hname = Form("p_resVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); - hname = Form("p_offresVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_offresOrefptVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offsetOrefpt,weight); - hname = Form("p_offresVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_resnopuVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respTonopu,weight); - hname = Form("p_nopuresVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); - hname = Form("p_offAfterOoffBeforeVsrefpt_%s_npv%i_%i",detectorAbbreviation.Data(),inpv_low,inpv_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/offset_raw,weight); - - //RHO - hname = Form("p_resVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),resp,weight); - hname = Form("p_offresVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_offresOrefptVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offsetOrefpt,weight); - hname = Form("p_offresVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),0,((NBinsNpvRhoNpu-1)*npvRhoNpuBinWidth)+npvRhoNpuBinWidth-1); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - hname = Form("p_resnopuVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respTonopu,weight); - hname = Form("p_nopuresVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),respNopu,weight); - hname = Form("p_offAfterOoffBeforeVsrefpt_%s_rho%i_%i",detectorAbbreviation.Data(),irho_low,irho_high); - dynamic_cast(histograms[hname])->Fill(tpu->refpt->at(jpu),offset/offset_raw,weight); - - //OTHER - hname = Form("p_resVsnpu_%s_pt%.1f_%.1f",detectorAbbreviation.Data(), - vpt[JetInfo::getBinIndex(tpu->refpt->at(jpu),vpt,NPtBins)],vpt[JetInfo::getBinIndex(tpu->refpt->at(jpu),vpt,NPtBins)+1]); - if(tpu->refpt->at(jpu)>10.0) { - dynamic_cast(histograms[hname])->Fill(tpu->npus->at(iIT),resp,weight); - } - for (unsigned int ipdgid=0; ipdgid(histograms[hname])->Fill(tpu->refpt->at(jpu),offset,weight); - } - } - - avg_offset += offset; - avg_offset_det[idet]+=offset; - njet_det[idet]+=1.; - - } // for matched jets - - avg_offset /= jetMap.size(); - for (int det=0;det(histograms[hname])->Fill(avg_offset_det[det],tpu->npv,weight); - hname = Form("p_rhoVsOff_%s",detectorAbbreviation.Data()); - dynamic_cast(histograms[hname])->Fill(avg_offset_det[det],tpu->rho,weight); - } - } - if(!reduceHistograms) { - dynamic_cast(histograms["p_npvVsoff"]) ->Fill(avg_offset,tpu->npv,weight); - dynamic_cast(histograms["p_rhoVsoff"]) ->Fill(avg_offset,tpu->rho,weight); - dynamic_cast(histograms["p_rhoVsRho"]) ->Fill(tpu->rho,tpu->rho,weight); - dynamic_cast(histograms["p_npvVsNpv"]) ->Fill(tpu->npv,tpu->npv,weight); - dynamic_cast(histograms["p_tnpuVsTnpu"]) ->Fill(tpu->tnpus->at(iIT),tpu->tnpus->at(iIT),weight); - dynamic_cast(histograms["p_npuVsNpu"]) ->Fill(tpu->npus->at(iIT),tpu->npus->at(iIT),weight); - dynamic_cast(histograms["p_matchedjet_off"])->Fill(avg_offset,jetMap.size(),weight); - } - - //========================================================= - // FILLING OF HISTOS ENDS HERE - //========================================================= - - return true; -} - -//______________________________________________________________________________ -void MatchEventsAndJets::RemoveHistograms(bool verbose) { - cout<::iterator it=histograms.begin(); it!=histograms.end(); ++it) { - if (!it->second->GetEntries()) { - if (verbose) cout<<"\tRemoving histogram "<first<second->SetDirectory(0); - } - } -} - -//______________________________________________________________________________ -void MatchEventsAndJets::WriteOutput(string outputPath, bool writeJetMap){ - cout << endl << "Writing file " << fout->GetName() << " ... " << flush; - fout->cd(); - for(map::const_iterator it=hsparse.begin(); it!=hsparse.end();it++) { - it->second->Write(); - } - fout->Write(); - fout->Close(); - cout << "DONE" << endl; - - if(writeJetMap && !doNotSaveFlag) { - cout << endl << "Saving the jetMapTree to a file for later use ... " << flush; - string outputFilename = "matchedEventsMaps_"+algo1+"_"+algo2+".root"; - if (algo1 == algo2) - outputFilename = "matchedEventsMaps_"+algo1+".root"; - outputFilename = outputPath+outputFilename; - TFile* mapFile = TFile::Open(outputFilename.c_str(),"UPDATE"); - jetMapTree->Write(); - mapFile->Close(); - cout << "DONE" << endl << endl; - } -} - -//////////////////////////////////////////////////////////////////////////////// -// main -//////////////////////////////////////////////////////////////////////////////// - -// ------------------------------------------------------------------ -int main(int argc,char**argv) -{ - CommandLine cl; - if (!cl.parse(argc,argv)) return 0; - string samplePU = cl.getValue ("samplePU"); - string sampleNoPU = cl.getValue ("sampleNoPU"); - string basepath = cl.getValue ("basepath", "/fdata/hepx/store/user/aperloff/"); - string algo1 = cl.getValue ("algo1", "ak4pf"); - string algo2 = cl.getValue ("algo2", "ak4pf"); - bool iftest = cl.getValue ("iftest", false); - unsigned maxEvts = cl.getValue ("maxEvts", 40000); - double minPhi = cl.getValue ("minPhi", 0.0); - double maxPhi = cl.getValue ("maxPhi", 0.0); - int nrefmax = cl.getValue ("nrefmax", -1); - bool useweight = cl.getValue ("useweight", false); - bool pThatReweight = cl.getValue ("pThatReweight", false); - double bias2SelectionRef = cl.getValue ("bias2SelectionRef", 15); - double bias2SelectionPow = cl.getValue ("bias2SelectionPow", 6.0); - string MCPUReWeighting = cl.getValue ("MCPUReWeighting", ""); - string MCPUHistoName = cl.getValue ("MCPUHistoName", "h_pileup"); - string DataPUReWeighting = cl.getValue ("DataPUReWeighting", ""); - string DataPUHistoName = cl.getValue ("DataPUHistoName", "pileup"); - bool ApplyJEC = cl.getValue ("ApplyJEC", true); - string JECpar = cl.getValue ("JECpar", "ParallelMCL1_L1FastJet_AK4PFchs.txt"); - string outputPath = cl.getValue ("outputPath", "./"); - string readEvtMaps = cl.getValue ("readEvtMaps", ""); - bool doNotSave = cl.getValue ("doNotSave", false); - string treeName = cl.getValue ("treeName", "t"); - int npvRhoNpuBinWidth = cl.getValue ("npvRhoNpuBinWidth", 10); - int NBinsNpvRhoNpu = cl.getValue ("NBinsNpvRhoNpu", 6); - vector vptBins = cl.getVector ("vptBins", "14:::18:::20:::24:::28:::30"); - bool reduceHistograms = cl.getValue ("reduceHistograms", true); - bool verbose = cl.getValue ("verbose", false); - bool help = cl.getValue ("help", false); - - if (help) {cl.print(); return 0;} - if (!cl.check()) return 0; - cl.print(); - - TBenchmark* m_benchmark = new TBenchmark(); - m_benchmark->Reset(); - m_benchmark->Start("event"); - - // - // Do some additional sanity checks - // - - // Check that if pThatReweight is set then useweight is also set - if(pThatReweight && !useweight) { - cout << "ERROR::jet_match_x Can't reweight the pThat spectrum without first using the existing" - << " weights to return to an unmodified spectrum. Set the \"useweight\" option to true." << endl; - return -1; - } - - gEnv->SetValue("TFile.AsyncPrefetching", 1); - - if(outputPath.empty()) outputPath = string(gSystem->pwd())+"/"; - if(outputPath.back() != '/') outputPath+='/'; - if(basepath.back() != '/') basepath+='/'; - - MatchEventsAndJets* mej = new MatchEventsAndJets(algo1,algo2,iftest); - mej->SetDoNotSaveFlag(doNotSave); - mej->SetMaxEvts(maxEvts); - mej->SetPhiRange(minPhi,maxPhi); - mej->SetNRefMax(nrefmax); - mej->SetWeightParameters(useweight,pThatReweight,bias2SelectionRef,bias2SelectionPow); - mej->SetupLumiWeights((DataPUReWeighting.empty())? "" : basepath+DataPUReWeighting, - (MCPUReWeighting.empty()) ? "" : basepath+MCPUReWeighting, - DataPUHistoName,MCPUHistoName); - mej->OpenInputFiles(basepath+samplePU,basepath+sampleNoPU); - mej->GetNtuples(treeName); - if(readEvtMaps.empty()) - mej->MakeMatchedEventsMaps(treeName,outputPath); - else - mej->ReadMatchedEventsMaps(readEvtMaps); - mej->OpenOutputFile(outputPath); - if (ApplyJEC) { - cout << "jet_match_x::Setting the JEC parameter file to " << JECpar << " ... "; - mej->SetJEC(JECpar); - cout << "DONE" << endl; - } - mej->SetNpvRhoNpuValues(NBinsNpvRhoNpu,npvRhoNpuBinWidth); - mej->SetVptBins(vptBins); - mej->DeclareHistograms(reduceHistograms); - mej->LoopOverEvents(verbose,reduceHistograms,readEvtMaps,outputPath); - // mej->RemoveHistograms(verbose); - mej->WriteOutput(outputPath, false && (readEvtMaps.empty()||!mej->JetMapTreeFound())); - - m_benchmark->Stop("event"); - cout << "jet_match_x" << endl - << "\tCPU time = " << m_benchmark->GetCpuTime("event") << " s" << endl - << "\tReal time = " << m_benchmark->GetRealTime("event") << " s" << endl; - delete m_benchmark; - - return 0; -} From ff9ce76e5eb9cc242d9d3342e2adb1475819c8f4 Mon Sep 17 00:00:00 2001 From: izisopou <54803536+izisopou@users.noreply.github.com> Date: Mon, 9 Nov 2020 12:58:14 +0200 Subject: [PATCH 19/19] Update jet_synchfit_x.cc --- JetAnalyzers/bin/jet_synchfit_x.cc | 46 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/JetAnalyzers/bin/jet_synchfit_x.cc b/JetAnalyzers/bin/jet_synchfit_x.cc index 2f79bf60..d2d07b24 100644 --- a/JetAnalyzers/bin/jet_synchfit_x.cc +++ b/JetAnalyzers/bin/jet_synchfit_x.cc @@ -26,12 +26,13 @@ #include "JetMETAnalysis/JetUtilities/interface/JetInfo.hh" #include "JetMETAnalysis/JetAnalyzers/interface/REStyle.h" + using namespace std; struct FitRes { - double etalowedge; - double etaupedge; - TF2 * fit; + double etalowedge; + double etaupedge; + TF2 * fit; }; //=========================================================================== @@ -91,7 +92,6 @@ TGraph2DErrors * getGraph2D(int iEta, TProfile3D * prof, const TProfile3D * prof } // getGraph2D //=========================================================================== -// void fitClosurePlots(TProfile3D * prof, const TProfile3D * profPt, const TProfile3D * profRho, @@ -521,8 +521,8 @@ TF2 * doGraphFitting(TGraph2DErrors * graph, bool highPU, string functionType, i function = "[0]+([1]*pow(log10(y-[2]),3))+([4]*log10(y-[2])*pow(x-[3],2))+([5]*(pow(log10(y-[2]),2)-pow(x-[3],2)))"; //x(u,v)=u y(u,v)=v z(u,v)=1/3u^3+uv^2+2(u^2-v^2)// Handkerchief Surface http://mathworld.wolfram.com/HandkerchiefSurface.html - } - else if(functionType=="modifiedHandkerchief+rho") { + } + else if(functionType=="modifiedHandkerchief+rho") { if(41-abs(iEta-41)+(iEta>41)==41) pari = {-76.8447, 2.43371, -529.969, -120.342, -0.003042, -0.0101412, 0.5}; if(41-abs(iEta-41)+(iEta>41)==40) pari = {-51.3274, 1.56577, -791.884, -63.0554, -0.00656194, -0.022223, 0.5}; if(41-abs(iEta-41)+(iEta>41)==39) pari = {-44.4371, 1.29876, -408.899, -96.5217, -0.00222077, -0.0080116, 0.5}; @@ -610,17 +610,17 @@ TF2 * doGraphFitting(TGraph2DErrors * graph, bool highPU, string functionType, i function = "[0]+([1]*(x-11))*(1+[2]*(log(y)-1.47))"; } - cout << "\tInitial Parameters: (" << flush; - for(unsigned int ipar=0; iparGetChisquare()/ f4->GetNDF(); counter++; if ((rchi2>9 || rchi2==0) && counter==nfits-2) { - //Reset initial parameters - cout << "\tResetting initial parameters" << endl; - for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); + //Reset initial parameters + cout << "\tResetting initial parameters" << endl; + for(unsigned int ipar=0; iparSetParameter(ipar,pari[ipar]); } } - } while ((rchi2>9 || rchi2==0.0) && counter < nfits); - cout <<"N. of fits: " << counter << endl; - - cout << "\tFinal Parameters: ("; - for(unsigned int ipar=0; ipar9 || rchi2==0.0) && counter < nfits); + cout <<"N. of fits: " << counter << endl; + + cout << "\tFinal Parameters: ("; + for(unsigned int ipar=0; iparGetParameter(ipar) << "\u00b1" << f4->GetParError(ipar); if(ipar!=pari.size()-1) cout << ", "; else cout << ")" << endl;