1 |
bendavid |
1.4 |
// $Id: RunLumiSelectionMod.cc,v 1.3 2010/05/29 18:10:15 bendavid Exp $
|
2 |
bendavid |
1.1 |
|
3 |
|
|
#include "MitAna/PhysicsMod/interface/RunLumiSelectionMod.h"
|
4 |
|
|
#include <TTree.h>
|
5 |
|
|
#include "MitAna/DataTree/interface/Names.h"
|
6 |
|
|
|
7 |
|
|
using namespace mithep;
|
8 |
|
|
|
9 |
|
|
ClassImp(mithep::RunLumiSelectionMod)
|
10 |
|
|
|
11 |
|
|
//--------------------------------------------------------------------------------------------------
|
12 |
|
|
RunLumiSelectionMod::RunLumiSelectionMod(const char *name, const char *title) :
|
13 |
|
|
BaseMod(name,title),
|
14 |
|
|
fAbort(kTRUE),
|
15 |
bendavid |
1.2 |
fAcceptMC(kFALSE),
|
16 |
bendavid |
1.1 |
fNEvents(0),
|
17 |
|
|
fNAcceped(0),
|
18 |
|
|
fNFailed(0),
|
19 |
bendavid |
1.4 |
fAcceptCurrentRunLumi(kFALSE),
|
20 |
|
|
fRunLumiGraph(0)
|
21 |
bendavid |
1.1 |
{
|
22 |
|
|
// Constructor.
|
23 |
|
|
}
|
24 |
|
|
|
25 |
|
|
//--------------------------------------------------------------------------------------------------
|
26 |
|
|
RunLumiSelectionMod::~RunLumiSelectionMod()
|
27 |
|
|
{
|
28 |
|
|
// Destructor.
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
//--------------------------------------------------------------------------------------------------
|
33 |
|
|
void RunLumiSelectionMod::BeginRun()
|
34 |
|
|
{
|
35 |
|
|
|
36 |
|
|
}
|
37 |
|
|
|
38 |
|
|
//--------------------------------------------------------------------------------------------------
|
39 |
|
|
void RunLumiSelectionMod::Process()
|
40 |
|
|
{
|
41 |
|
|
// Increment counters and stop further processing of an event if current run is excluded
|
42 |
|
|
|
43 |
|
|
++fNEvents;
|
44 |
|
|
|
45 |
bendavid |
1.2 |
RunLumiPairType runLumi(GetEventHeader()->RunNum(),GetEventHeader()->LumiSec());
|
46 |
|
|
|
47 |
|
|
//check decision only if lumi section has changed
|
48 |
|
|
if (runLumi != fCurrentRunLumi) {
|
49 |
|
|
fAcceptCurrentRunLumi = kFALSE;
|
50 |
|
|
//check for MC default accept
|
51 |
|
|
if (fAcceptMC && GetEventHeader()->IsMC()) {
|
52 |
|
|
fAcceptCurrentRunLumi = kTRUE;
|
53 |
|
|
}
|
54 |
|
|
else {
|
55 |
bendavid |
1.3 |
fAcceptCurrentRunLumi = fAcceptedRunsLumis.HasRunLumi(runLumi);
|
56 |
bendavid |
1.2 |
}
|
57 |
|
|
fCurrentRunLumi = runLumi;
|
58 |
bendavid |
1.4 |
if (fAcceptCurrentRunLumi) {
|
59 |
|
|
fRunLumiSet.Add(runLumi);
|
60 |
|
|
}
|
61 |
bendavid |
1.2 |
if (0) {
|
62 |
|
|
printf("Run %u, Lumi %u, accepted = %i\n",runLumi.first,runLumi.second,fAcceptCurrentRunLumi);
|
63 |
|
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
bendavid |
1.1 |
// take action if failed
|
67 |
bendavid |
1.2 |
if (!fAcceptCurrentRunLumi) {
|
68 |
bendavid |
1.1 |
++fNFailed;
|
69 |
|
|
OnFailed();
|
70 |
|
|
if (fAbort) {
|
71 |
|
|
SkipEvent(); // abort processing of this event by sub-modules
|
72 |
|
|
}
|
73 |
|
|
return;
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
// take action if accepted
|
77 |
|
|
++fNAcceped;
|
78 |
|
|
IncNEventsProcessed();
|
79 |
|
|
OnAccepted();
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
//--------------------------------------------------------------------------------------------------
|
83 |
|
|
void RunLumiSelectionMod::SlaveBegin()
|
84 |
|
|
{
|
85 |
|
|
|
86 |
bendavid |
1.4 |
// fRunLumiVector = new RunLumiVector;
|
87 |
|
|
// fRunLumiVector->SetName("ProcessedRunsLumis");
|
88 |
|
|
// AddOutput(fRunLumiVector);
|
89 |
|
|
|
90 |
bendavid |
1.1 |
}
|
91 |
|
|
|
92 |
|
|
//--------------------------------------------------------------------------------------------------
|
93 |
|
|
void RunLumiSelectionMod::SlaveTerminate()
|
94 |
|
|
{
|
95 |
|
|
// Save number of accepted events.
|
96 |
|
|
|
97 |
bendavid |
1.4 |
const RunLumiSet::SetType &theset = fRunLumiSet.runLumiSet();
|
98 |
|
|
|
99 |
|
|
UInt_t setSize = theset.size();
|
100 |
|
|
Double_t *runArray = new Double_t[setSize];
|
101 |
|
|
Double_t *lumiArray = new Double_t[setSize];
|
102 |
|
|
|
103 |
|
|
UInt_t arrayPos = 0;
|
104 |
|
|
for (RunLumiSet::SetType::const_iterator it = theset.begin(); it!=theset.end(); ++it) {
|
105 |
|
|
printf("first = %u, second = %u\n",it->first,it->second);
|
106 |
|
|
runArray[arrayPos] = it->first;
|
107 |
|
|
lumiArray[arrayPos] = it->second;
|
108 |
|
|
++arrayPos;
|
109 |
|
|
}
|
110 |
|
|
|
111 |
|
|
fRunLumiGraph = new TGraph(setSize,runArray,lumiArray);
|
112 |
|
|
fRunLumiGraph->SetName("ProcessedRunsLumis");
|
113 |
|
|
AddOutput(fRunLumiGraph);
|
114 |
|
|
|
115 |
|
|
delete runArray;
|
116 |
|
|
delete lumiArray;
|
117 |
|
|
|
118 |
bendavid |
1.1 |
SaveNEventsProcessed();
|
119 |
|
|
}
|
120 |
bendavid |
1.2 |
|
121 |
|
|
//--------------------------------------------------------------------------------------------------
|
122 |
|
|
void RunLumiSelectionMod::AddJSONFile(const std::string &filepath)
|
123 |
|
|
{
|
124 |
bendavid |
1.3 |
//pass JSON file to map object
|
125 |
|
|
fAcceptedRunsLumis.AddJSONFile(filepath);
|
126 |
bendavid |
1.2 |
}
|