1 |
bendavid |
1.2 |
// $Id: RunLumiSelectionMod.cc,v 1.1 2010/05/03 11:36:01 bendavid Exp $
|
2 |
bendavid |
1.1 |
|
3 |
bendavid |
1.2 |
#include <boost/property_tree/ptree.hpp>
|
4 |
|
|
#include <boost/property_tree/json_parser.hpp>
|
5 |
|
|
#include <boost/lexical_cast.hpp>
|
6 |
bendavid |
1.1 |
#include "MitAna/PhysicsMod/interface/RunLumiSelectionMod.h"
|
7 |
|
|
#include <TFile.h>
|
8 |
|
|
#include <TTree.h>
|
9 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
10 |
|
|
|
11 |
|
|
using namespace mithep;
|
12 |
|
|
|
13 |
|
|
ClassImp(mithep::RunLumiSelectionMod)
|
14 |
|
|
|
15 |
|
|
//--------------------------------------------------------------------------------------------------
|
16 |
|
|
RunLumiSelectionMod::RunLumiSelectionMod(const char *name, const char *title) :
|
17 |
|
|
BaseMod(name,title),
|
18 |
|
|
fAbort(kTRUE),
|
19 |
bendavid |
1.2 |
fAcceptMC(kFALSE),
|
20 |
bendavid |
1.1 |
fNEvents(0),
|
21 |
|
|
fNAcceped(0),
|
22 |
|
|
fNFailed(0),
|
23 |
bendavid |
1.2 |
fAcceptCurrentRunLumi(kFALSE)
|
24 |
bendavid |
1.1 |
{
|
25 |
|
|
// Constructor.
|
26 |
|
|
}
|
27 |
|
|
|
28 |
|
|
//--------------------------------------------------------------------------------------------------
|
29 |
|
|
RunLumiSelectionMod::~RunLumiSelectionMod()
|
30 |
|
|
{
|
31 |
|
|
// Destructor.
|
32 |
|
|
}
|
33 |
|
|
|
34 |
|
|
|
35 |
|
|
//--------------------------------------------------------------------------------------------------
|
36 |
|
|
void RunLumiSelectionMod::BeginRun()
|
37 |
|
|
{
|
38 |
|
|
|
39 |
|
|
}
|
40 |
|
|
|
41 |
|
|
//--------------------------------------------------------------------------------------------------
|
42 |
|
|
void RunLumiSelectionMod::Process()
|
43 |
|
|
{
|
44 |
|
|
// Increment counters and stop further processing of an event if current run is excluded
|
45 |
|
|
|
46 |
|
|
++fNEvents;
|
47 |
|
|
|
48 |
bendavid |
1.2 |
RunLumiPairType runLumi(GetEventHeader()->RunNum(),GetEventHeader()->LumiSec());
|
49 |
|
|
|
50 |
|
|
//check decision only if lumi section has changed
|
51 |
|
|
if (runLumi != fCurrentRunLumi) {
|
52 |
|
|
fAcceptCurrentRunLumi = kFALSE;
|
53 |
|
|
//check for MC default accept
|
54 |
|
|
if (fAcceptMC && GetEventHeader()->IsMC()) {
|
55 |
|
|
fAcceptCurrentRunLumi = kTRUE;
|
56 |
|
|
}
|
57 |
|
|
else {
|
58 |
|
|
//check if run is included
|
59 |
|
|
MapType::const_iterator it = fAcceptedRunsLumis.find(runLumi.first);
|
60 |
|
|
if (it!=fAcceptedRunsLumis.end()) {
|
61 |
|
|
//check lumis
|
62 |
|
|
const MapType::mapped_type &lumiPairList = it->second;
|
63 |
|
|
for (MapType::mapped_type::const_iterator jt = lumiPairList.begin(); jt<lumiPairList.end(); ++jt) {
|
64 |
|
|
if (runLumi.second >= jt->first && runLumi.second <= jt->second) {
|
65 |
|
|
//found lumi in accepted range
|
66 |
|
|
fAcceptCurrentRunLumi = kTRUE;
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
else {
|
71 |
|
|
//run not in JSON file, reject it
|
72 |
|
|
fAcceptCurrentRunLumi = kFALSE;
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
fCurrentRunLumi = runLumi;
|
76 |
|
|
if (0) {
|
77 |
|
|
printf("Run %u, Lumi %u, accepted = %i\n",runLumi.first,runLumi.second,fAcceptCurrentRunLumi);
|
78 |
|
|
}
|
79 |
|
|
}
|
80 |
|
|
|
81 |
bendavid |
1.1 |
// take action if failed
|
82 |
bendavid |
1.2 |
if (!fAcceptCurrentRunLumi) {
|
83 |
bendavid |
1.1 |
++fNFailed;
|
84 |
|
|
OnFailed();
|
85 |
|
|
if (fAbort) {
|
86 |
|
|
SkipEvent(); // abort processing of this event by sub-modules
|
87 |
|
|
}
|
88 |
|
|
return;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
// take action if accepted
|
92 |
|
|
++fNAcceped;
|
93 |
|
|
IncNEventsProcessed();
|
94 |
|
|
OnAccepted();
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
//--------------------------------------------------------------------------------------------------
|
98 |
|
|
void RunLumiSelectionMod::SlaveBegin()
|
99 |
|
|
{
|
100 |
|
|
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
//--------------------------------------------------------------------------------------------------
|
104 |
|
|
void RunLumiSelectionMod::SlaveTerminate()
|
105 |
|
|
{
|
106 |
|
|
// Save number of accepted events.
|
107 |
|
|
|
108 |
|
|
SaveNEventsProcessed();
|
109 |
|
|
}
|
110 |
bendavid |
1.2 |
|
111 |
|
|
//--------------------------------------------------------------------------------------------------
|
112 |
|
|
void RunLumiSelectionMod::AddJSONFile(const std::string &filepath)
|
113 |
|
|
{
|
114 |
|
|
|
115 |
|
|
//read json file into boost property tree
|
116 |
|
|
boost::property_tree::ptree jsonTree;
|
117 |
|
|
boost::property_tree::read_json(filepath,jsonTree);
|
118 |
|
|
|
119 |
|
|
//loop through boost property tree and fill the MapType structure with the list of good lumi
|
120 |
|
|
//ranges for each run
|
121 |
|
|
for (boost::property_tree::ptree::const_iterator it = jsonTree.begin(); it!=jsonTree.end(); ++it) {
|
122 |
|
|
UInt_t runNumber = boost::lexical_cast<UInt_t>(it->first);
|
123 |
|
|
MapType::mapped_type &lumiPairList = fAcceptedRunsLumis[runNumber];
|
124 |
|
|
boost::property_tree::ptree lumiPairListTree = it->second;
|
125 |
|
|
for (boost::property_tree::ptree::const_iterator jt = lumiPairListTree.begin(); jt!=lumiPairListTree.end(); ++jt) {
|
126 |
|
|
boost::property_tree::ptree lumiPairTree = jt->second;
|
127 |
|
|
if (lumiPairTree.size()==2) {
|
128 |
|
|
UInt_t firstLumi = boost::lexical_cast<UInt_t>(lumiPairTree.begin()->second.data());
|
129 |
|
|
UInt_t lastLumi = boost::lexical_cast<UInt_t>((++lumiPairTree.begin())->second.data());
|
130 |
|
|
lumiPairList.push_back(std::pair<UInt_t,UInt_t>(firstLumi,lastLumi));
|
131 |
|
|
}
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
|
135 |
|
|
//dump run and lumi ranges from MapType structure to verify correct json parsing
|
136 |
|
|
if (0) {
|
137 |
|
|
printf("Iterating over parsed JSON:\n");
|
138 |
|
|
for (MapType::const_iterator it = fAcceptedRunsLumis.begin(); it != fAcceptedRunsLumis.end(); ++it) {
|
139 |
|
|
printf(" Run %u:\n",it->first);
|
140 |
|
|
for (MapType::mapped_type::const_iterator jt = it->second.begin(); jt < it->second.end(); ++jt) {
|
141 |
|
|
printf(" Lumis %u - %u\n",jt->first,jt->second);
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
}
|