9 #include <boost/algorithm/string.hpp> 10 #include <boost/filesystem.hpp> 11 #include <boost/property_tree/ptree.hpp> 12 #include <boost/property_tree/json_parser.hpp> 28 fileCollection_ =
new TFileCollection(
"fileCollection",
"",inputFilelist.c_str());
32 t_event_ =
new TChain(evtinfo.c_str());
33 t_event_ -> AddFileInfoList(fileList_);
35 std::vector<std::string> branches;
36 TObjArray * treeBranches =
t_event_->GetListOfBranches();
37 for (
int i = 0 ; i < treeBranches->GetEntries() ; ++i )
38 branches.push_back(treeBranches->At(i)->GetName());
45 std::vector<std::string>::iterator it;
46 it = std::find(branches.begin(),branches.end(),
"nPileup");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
n_pu_);
47 it = std::find(branches.begin(),branches.end(),
"nTruePileup");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
n_true_pu_);
49 it = std::find(branches.begin(),branches.end(),
"lumiPileup");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
lumi_pu_);
50 it = std::find(branches.begin(),branches.end(),
"instantLumi");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
inst_lumi_);
52 it = std::find(branches.begin(),branches.end(),
"genWeight");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
genWeight_);
53 it = std::find(branches.begin(),branches.end(),
"genScale");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
genScale_);
54 it = std::find(branches.begin(),branches.end(),
"pdfid1");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
pdf_.
id.first);
55 it = std::find(branches.begin(),branches.end(),
"pdfid2");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
pdf_.
id.second);
56 it = std::find(branches.begin(),branches.end(),
"pdfx1");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
pdf_.
x.first);
57 it = std::find(branches.begin(),branches.end(),
"pdfx2");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
pdf_.
x.second);
59 it = std::find(branches.begin(),branches.end(),
"rho");
if ( it != branches.end() )
t_event_ -> SetBranchAddress( (*it).c_str(), &
rho_);
108 if ( !addCollections)
return;
114 if ( type ==
"Jet" ) this->addCollection<Jet>(
name);
115 if ( type ==
"Muon" ) this->addCollection<Muon>(
name);
116 if ( type ==
"GenJet" ) this->addCollection<GenJet>(
name);
117 if ( type ==
"MET" ) this->addCollection<MET>(
name);
118 if ( type ==
"Vertex" ) this->addCollection<Vertex>(
name);
119 if ( type ==
"TriggerObject" ) this->addCollection<TriggerObject>(
name);
120 if ( type ==
"GenParticle" ) this->addCollection<GenParticle>(
name);
121 if ( type ==
"Candidate" ) this->addCollection<Candidate>(
name);
122 if ( type ==
"JetTag" ) this->addCollection<JetTag>(
name);
123 if ( type ==
"L1TMuon" ) this->addCollection<L1TMuon>(
name);
124 if ( type ==
"L1TJet" ) this->addCollection<L1TJet>(
name);
125 if ( type ==
"RecoMuon" ) this->addCollection<RecoMuon>(
name);
126 if ( type ==
"RecoTrack" ) this->addCollection<RecoTrack>(
name);
138 std::string treeTitle = ((TTree*)
t_event_->GetFile()->Get(path.c_str())) -> GetTitle();
139 tree_[unique_name] =
new TChain(path.c_str(),treeTitle.c_str());
143 treeTitle.erase(std::remove(treeTitle.begin(),treeTitle.end(),
' '),treeTitle.end());
144 std::string classname = treeTitle.substr(0,treeTitle.find_first_of(
"|"));
145 std::string inputTag = treeTitle.substr(treeTitle.find_first_of(
"|")+1);
169 std::cout <<
"tree does not exist" << std::endl;
173 for (
int i = 0 ; i < triggerBranches->GetEntries() ; ++i )
175 std::string branch = triggerBranches->At(i)->GetName();
176 if ( TString(branch).BeginsWith(
"ps") )
192 if ( trig ==
"" )
return true;
205 std::map<std::string,int> ps;
206 for (
auto & trig : trigs )
221 if ( path ==
"" )
return -2;
226 std::cout <<
"tree does not exist" << std::endl;
229 TObjArray * xsecBranches =
t_xsection_->GetListOfBranches();
230 for (
int i = 0 ; i < xsecBranches->GetEntries() ; ++i )
232 std::string branch = xsecBranches->At(i)->GetName();
233 if ( branch ==
"run" )
continue;
264 float lumiScale = 1.;
266 if (
mylumi_ < 0 )
return lumiScale;
275 std::cout <<
"=======================================================" << std::endl;
276 std::cout <<
" CROSS SECTIONS" << std::endl;
277 std::cout <<
"=======================================================" << std::endl;
280 std::cout <<
"No cross section tree has been declared." << std::endl;
281 std::cout <<
"=======================================================" << std::endl;
282 std::cout << std::endl;
283 std::cout << std::endl;
289 std::cout << xs.first <<
" = " << xs.second <<
" pb " << std::endl;
291 std::cout <<
"=======================================================" << std::endl;
292 std::cout << std::endl;
293 std::cout << std::endl;
302 unsigned int nfiltered;
303 unsigned int sumtotal = 0;
304 unsigned int sumfiltered = 0;
306 t_genfilter_ -> SetBranchAddress(
"nEventsTotal", &ntotal);
307 t_genfilter_ -> SetBranchAddress(
"nEventsFiltered", &nfiltered);
313 sumfiltered += nfiltered;
326 std::cout <<
"=======================================================" << std::endl;
327 std::cout <<
" GENERATOR FILTER" << std::endl;
328 std::cout <<
"=======================================================" << std::endl;
331 std::cout <<
"No generator tree has been declared." << std::endl;
332 std::cout <<
"=======================================================" << std::endl;
333 std::cout << std::endl;
334 std::cout << std::endl;
337 std::cout <<
"Total generated events = " <<
genfilter_.
total << std::endl;
341 std::cout <<
"=======================================================" << std::endl;
342 std::cout << std::endl;
343 std::cout << std::endl;
354 unsigned int nfiltered;
355 unsigned int sumtotal = 0;
356 unsigned int sumfiltered = 0;
358 t_evtfilter_ -> SetBranchAddress(
"nEventsTotal", &ntotal);
359 t_evtfilter_ -> SetBranchAddress(
"nEventsFiltered", &nfiltered);
365 sumfiltered += nfiltered;
380 using boost::property_tree::ptree;
382 read_json(fileName , pt);
384 for (
auto & element: pt)
386 int run = std::stoi(element.first);
387 std::vector<int> lumiranges;
388 for (
auto & property_array : element.second )
390 for (
auto & property : property_array.second )
392 lumiranges.push_back(property.second.get_value<
int>());
395 if ( lumiranges.size()%2 != 0 )
return -1;
407 std::vector<int> lumiranges =
json_[
run_];
408 for (
size_t i = 0 ; i< lumiranges.size() ; i += 2 )
410 if (
lumi_ >= lumiranges.at(i) &&
lumi_ <= lumiranges.at(i+1) ) isGood =
true;
420 std::vector<std::string> field;
423 boost::split(field, ftitle, boost::is_any_of(
":"));
429 for (
int i = 0 ; i < mylist->GetSize() ; ++i )
431 std::string className = ((TKey*) mylist -> At(i)) -> GetClassName();
432 std::string objName = ((TKey*) mylist -> At(i)) -> GetName();
433 if ( className ==
"TH2F" )
446 if ( rank < 1 ) srank =
"";
447 else srank = Form(
"%i",rank);
451 if ( flav ==
"udsg" ) flav =
"l";
456 if ( abs(iflav) == 5 ) flav =
"b";
457 if ( abs(iflav) == 4 ) flav =
"c";
458 if ( abs(iflav) < 4 || iflav == 21 ) flav =
"l";
461 float eta = fabs(jet.
eta());
463 std::string hname = Form(
"h_%sjet%s_eff_pt_eta",flav.c_str(),srank.c_str());
512 const std::string & filename,
513 const std::string & wp,
514 const std::string & sysType,
515 const std::vector<std::string> & otherSysTypes)
517 std::string wps = wp;
518 std::transform(wps.begin(), wps.end(), wps.begin(), ::tolower);
555 std::string filename;
564 std::ifstream
f(name.c_str(),std::ios_base::in);
565 if ( !
f.good() )
return -1;
569 if ( seed < 1 )
return -1;