forked from UCATLAS/xAODAnaHelpers
/
MuonHistsAlgo.cxx
172 lines (132 loc) · 5.56 KB
/
MuonHistsAlgo.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include <EventLoop/Job.h>
#include <EventLoop/StatusCode.h>
#include <EventLoop/Worker.h>
#include <xAODMuon/MuonContainer.h>
#include <xAODEventInfo/EventInfo.h>
#include <AthContainers/ConstDataVector.h>
#include <xAODAnaHelpers/MuonHistsAlgo.h>
#include <xAODAnaHelpers/HelperFunctions.h>
#include <xAODAnaHelpers/HelperClasses.h>
#include <xAODAnaHelpers/tools/ReturnCheck.h>
#include "TEnv.h"
#include "TSystem.h"
// this is needed to distribute the algorithm to the workers
ClassImp(MuonHistsAlgo)
MuonHistsAlgo :: MuonHistsAlgo () {
m_inContainerName = "";
// which plots will be turned on
m_detailStr = "";
// name of algo input container comes from - only if
m_inputAlgo = "";
m_debug = false;
}
EL::StatusCode MuonHistsAlgo :: setupJob (EL::Job& job)
{
job.useXAOD();
xAOD::Init("MuonHistsAlgo").ignore();
return EL::StatusCode::SUCCESS;
}
EL::StatusCode MuonHistsAlgo :: histInitialize ()
{
Info("histInitialize()", "%s", m_name.c_str() );
return EL::StatusCode::SUCCESS;
}
EL::StatusCode MuonHistsAlgo::AddHists( std::string name ) {
std::string fullname(m_name);
fullname += name; // add systematic
MuonHists* muonHists = new MuonHists( fullname, m_detailStr ); // add systematic
RETURN_CHECK("MuonHistsAlgo::AddHists", muonHists->initialize(), "");
muonHists->record( wk() );
m_plots[name] = muonHists;
return EL::StatusCode::SUCCESS;
}
EL::StatusCode MuonHistsAlgo :: configure ()
{
if(!getConfig().empty()){
// the file exists, use TEnv to read it off
TEnv* config = new TEnv(getConfig(true).c_str());
// input container to be read from TEvent or TStore
m_inContainerName = config->GetValue("InputContainer", m_inContainerName.c_str());
// which plots will be turned on
m_detailStr = config->GetValue("DetailStr", m_detailStr.c_str());
// name of algo input container comes from - only if
m_inputAlgo = config->GetValue("InputAlgo", m_inputAlgo.c_str());
m_debug = config->GetValue("Debug" , m_debug);
Info("configure()", "Loaded in configuration values");
// everything seems preliminarily ok, let's print config and say we were successful
config->Print();
delete config;
}
// in case anything was missing or blank...
if( m_inContainerName.empty() || m_detailStr.empty() ){
Error("configure()", "One or more required configuration values are empty");
return EL::StatusCode::FAILURE;
}
return EL::StatusCode::SUCCESS;
}
EL::StatusCode MuonHistsAlgo :: fileExecute () { return EL::StatusCode::SUCCESS; }
EL::StatusCode MuonHistsAlgo :: changeInput (bool /*firstFile*/) { return EL::StatusCode::SUCCESS; }
EL::StatusCode MuonHistsAlgo :: initialize ()
{
Info("initialize()", m_name.c_str());
// needed here and not in initalize since this is called first
Info("histInitialize()", "Attempting to configure using: %s", m_configName.c_str());
if ( this->configure() == EL::StatusCode::FAILURE ) {
Error("histInitialize()", "%s failed to properly configure. Exiting.", m_name.c_str() );
return EL::StatusCode::FAILURE;
} else {
Info("histInitialize()", "Succesfully configured! ");
}
// only running 1 collection
if(m_inputAlgo.empty()) { AddHists( "" ); }
m_event = wk()->xaodEvent();
m_store = wk()->xaodStore();
return EL::StatusCode::SUCCESS;
}
EL::StatusCode MuonHistsAlgo :: execute ()
{
const xAOD::EventInfo* eventInfo(nullptr);
RETURN_CHECK("MuonHistsAlgo::execute()", HelperFunctions::retrieve(eventInfo, m_eventInfoContainerName, m_event, m_store, m_verbose) ,"");
float eventWeight(1);
if( eventInfo->isAvailable< float >( "mcEventWeight" ) ) {
eventWeight = eventInfo->auxdecor< float >( "mcEventWeight" );
}
// this will hold the collection processed
const xAOD::MuonContainer* inMuons = 0;
// if input comes from xAOD, or just running one collection,
// then get the one collection and be done with it
if( m_inputAlgo.empty() ) {
RETURN_CHECK("MuonHistsAlgo::execute()", HelperFunctions::retrieve(inMuons, m_inContainerName, m_event, m_store, m_verbose) ,("Failed to get "+m_inContainerName).c_str());
/* two ways to fill */
// 1. pass the muon collection
RETURN_CHECK("MuonHistsAlgo::execute()", m_plots[""]->execute( inMuons, eventWeight ), "");
/* 2. loop over the muons
for( auto muon_itr : *inMuons ) {
m_plots[""]->execute( muon_itr, eventWeight );
}
*/
}
else { // get the list of systematics to run over
// get vector of string giving the names
std::vector<std::string>* systNames(nullptr);
RETURN_CHECK("MuonHistsAlgo::execute()", HelperFunctions::retrieve(systNames, m_inputAlgo, 0, m_store, m_verbose) ,"");
// loop over systematics
for( auto systName : *systNames ) {
RETURN_CHECK("MuonHistsAlgo::execute()", HelperFunctions::retrieve(inMuons, m_inContainerName+systName, m_event, m_store, m_verbose) ,"");
if( m_plots.find( systName ) == m_plots.end() ) { this->AddHists( systName ); }
RETURN_CHECK("MuonHistsAlgo::execute()", m_plots[systName]->execute( inMuons, eventWeight ), "");
}
}
return EL::StatusCode::SUCCESS;
}
EL::StatusCode MuonHistsAlgo :: postExecute () { return EL::StatusCode::SUCCESS; }
EL::StatusCode MuonHistsAlgo :: finalize () {
Info("finalize()", m_name.c_str());
if(!m_plots.empty()){
for( auto plots : m_plots ) {
if(plots.second) delete plots.second;
}
}
return EL::StatusCode::SUCCESS;
}
EL::StatusCode MuonHistsAlgo :: histFinalize () { return EL::StatusCode::SUCCESS; }