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