1 |
peiffer |
1.29 |
// $Id: AnalysisCycle.cxx,v 1.28 2013/01/29 15:47:14 peiffer Exp $
|
2 |
rkogler |
1.1 |
|
3 |
|
|
#include <iostream>
|
4 |
|
|
|
5 |
|
|
using namespace std;
|
6 |
|
|
|
7 |
|
|
// Local include(s):
|
8 |
|
|
#include "include/AnalysisCycle.h"
|
9 |
|
|
#include "include/SelectionModules.h"
|
10 |
|
|
#include "include/ObjectHandler.h"
|
11 |
|
|
#include "include/EventCalc.h"
|
12 |
peiffer |
1.2 |
#include "STreeType.h"
|
13 |
rkogler |
1.1 |
|
14 |
|
|
ClassImp( AnalysisCycle );
|
15 |
|
|
|
16 |
|
|
AnalysisCycle::AnalysisCycle()
|
17 |
bazterra |
1.18 |
: SCycleBase()
|
18 |
|
|
{
|
19 |
|
|
|
20 |
|
|
// constructor, declare variables that should be obtained
|
21 |
|
|
// from the steering-xml file
|
22 |
|
|
|
23 |
|
|
SetLogName( GetName() );
|
24 |
rkogler |
1.1 |
|
25 |
peiffer |
1.10 |
m_puwp = NULL;
|
26 |
bazterra |
1.18 |
m_newrun = false;
|
27 |
|
|
m_lsf = NULL;
|
28 |
|
|
|
29 |
|
|
// set some default values
|
30 |
|
|
m_readTTbarReco = false;
|
31 |
|
|
m_writeTTbarReco = false;
|
32 |
|
|
|
33 |
|
|
// declare variables for lumi file
|
34 |
|
|
DeclareProperty( "LumiFilePath" , m_lumifile_path);
|
35 |
|
|
DeclareProperty( "LumiFileName" , m_lumifile_name);
|
36 |
|
|
DeclareProperty( "LumiTrigger" , m_lumi_trigger);
|
37 |
|
|
|
38 |
|
|
// steerable properties of the Ntuple files
|
39 |
|
|
DeclareProperty( "JetCollection", m_JetCollection );
|
40 |
|
|
DeclareProperty( "ElectronCollection", m_ElectronCollection );
|
41 |
|
|
DeclareProperty( "MuonCollection", m_MuonCollection );
|
42 |
|
|
DeclareProperty( "TauCollection", m_TauCollection );
|
43 |
|
|
DeclareProperty( "PhotonCollection", m_PhotonCollection );
|
44 |
|
|
DeclareProperty( "PrimaryVertexCollection", m_PrimaryVertexCollection );
|
45 |
|
|
DeclareProperty( "METName", m_METName );
|
46 |
|
|
DeclareProperty( "TopJetCollection", m_TopJetCollection );
|
47 |
|
|
DeclareProperty( "TopJetCollectionGen", m_TopJetCollectionGen );
|
48 |
|
|
DeclareProperty( "PrunedJetCollection", m_PrunedJetCollection );
|
49 |
|
|
//DeclareProperty( "addGenInfo", m_addGenInfo);
|
50 |
|
|
DeclareProperty( "GenParticleCollection", m_GenParticleCollection);
|
51 |
|
|
DeclareProperty( "readTTbarReco", m_readTTbarReco);
|
52 |
|
|
DeclareProperty( "writeTTbarReco", m_writeTTbarReco);
|
53 |
|
|
|
54 |
|
|
// steerable properties for the jec
|
55 |
|
|
DeclareProperty( "JECFileLocation" , m_JECFileLocation);
|
56 |
|
|
DeclareProperty( "JECDataGlobalTag" , m_JECDataGlobalTag);
|
57 |
|
|
DeclareProperty( "JECMCGlobalTag" , m_JECMCGlobalTag);
|
58 |
|
|
DeclareProperty( "JECJetCollection" , m_JECJetCollection);
|
59 |
|
|
|
60 |
|
|
// steerable properties for the Pile-up reweighting
|
61 |
|
|
DeclareProperty( "PU_Filename_MC" , m_PUFilenameMC);
|
62 |
|
|
DeclareProperty( "PU_Filename_Data" , m_PUFilenameData);
|
63 |
|
|
DeclareProperty( "PU_Histname_MC" , m_PUHistnameMC);
|
64 |
|
|
DeclareProperty( "PU_Histname_Data" , m_PUHistnameData);
|
65 |
|
|
|
66 |
rkogler |
1.23 |
// lepton weights
|
67 |
bazterra |
1.18 |
DeclareProperty( "LeptonScaleFactors", m_leptonweights);
|
68 |
bazterra |
1.22 |
|
69 |
rkogler |
1.23 |
// uncertainties
|
70 |
|
|
DeclareProperty("SystematicUncertainty", m_sys_unc_name);
|
71 |
|
|
DeclareProperty("SystematicVariation", m_sys_var_name);
|
72 |
|
|
|
73 |
bazterra |
1.22 |
// steering property for data-driven qcd in electron channel
|
74 |
|
|
m_reversed_electron_selection = false;
|
75 |
|
|
DeclareProperty( "ReversedElectronSelection", m_reversed_electron_selection);
|
76 |
bazterra |
1.18 |
}
|
77 |
peiffer |
1.15 |
|
78 |
bazterra |
1.18 |
AnalysisCycle::~AnalysisCycle()
|
79 |
|
|
{
|
80 |
|
|
// destructor
|
81 |
peiffer |
1.15 |
|
82 |
bazterra |
1.18 |
if (m_puwp) {
|
83 |
|
|
delete m_puwp;
|
84 |
|
|
}
|
85 |
|
|
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
void AnalysisCycle::BeginCycle() throw( SError )
|
89 |
|
|
{
|
90 |
|
|
// Start of the job, general set-up and definition of
|
91 |
|
|
// objects are done here
|
92 |
|
|
|
93 |
|
|
// Set-Up LumiHandler
|
94 |
|
|
LuminosityHandler *lumiHandler = new LuminosityHandler();
|
95 |
|
|
|
96 |
|
|
lumiHandler->SetGRLPath( m_lumifile_path );
|
97 |
|
|
lumiHandler->SetLumiFileName( m_lumifile_name );
|
98 |
|
|
lumiHandler->SetTrigger( m_lumi_trigger );
|
99 |
|
|
lumiHandler->SetIntLumiPerBin( m_int_lumi_per_bin );
|
100 |
|
|
|
101 |
|
|
// Initialise, checks also if LumiFile is specified and readable
|
102 |
|
|
lumiHandler->Initialise();
|
103 |
|
|
// dump lumi information in text file
|
104 |
|
|
//lumiHandler->DumpLumiInfoIntoTxtFile();
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
// adding luminosity handler to gloabl config
|
108 |
|
|
AddConfigObject( lumiHandler );
|
109 |
|
|
|
110 |
|
|
return;
|
111 |
|
|
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
void AnalysisCycle::EndCycle() throw( SError )
|
115 |
|
|
{
|
116 |
|
|
|
117 |
|
|
return;
|
118 |
|
|
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
void AnalysisCycle::BeginInputData( const SInputData& inputData) throw( SError )
|
122 |
|
|
{
|
123 |
|
|
// declaration of variables and histograms
|
124 |
|
|
|
125 |
|
|
// check if LumiHandler is set up correctly
|
126 |
|
|
if( LumiHandler() == NULL ) {
|
127 |
|
|
m_logger << FATAL << "Luminosity Handler not properly added to Configuration!" << SLogger::endmsg;
|
128 |
|
|
exit(-1);
|
129 |
|
|
}
|
130 |
|
|
|
131 |
|
|
//determine whether running on MC or data
|
132 |
|
|
m_addGenInfo=true;
|
133 |
|
|
if(inputData.GetType()=="DATA" || inputData.GetType()=="Data" || inputData.GetType()=="data") m_addGenInfo=false;
|
134 |
|
|
|
135 |
|
|
// Overwrite target Luminosity
|
136 |
|
|
// has to be done for every input data
|
137 |
|
|
if( LumiHandler()->IsLumiCalc() ) {
|
138 |
|
|
m_logger << WARNING << "--- Not a WARNING! --- Overwrite Target Lumi with Lumi from LumiFile: "
|
139 |
|
|
<< LumiHandler()->GetTargetLumi() << " (pb^-1)!" << SLogger::endmsg;
|
140 |
|
|
GetConfig().SetTargetLumi( LumiHandler()->GetTargetLumi() );
|
141 |
|
|
}
|
142 |
|
|
|
143 |
|
|
if(m_JECFileLocation.size()>0) {
|
144 |
|
|
m_logger << INFO << "Using JEC files from " << m_JECFileLocation << SLogger::endmsg;
|
145 |
|
|
m_logger << INFO << "Using JEC global tags for data " << m_JECDataGlobalTag << " and for MC " << m_JECMCGlobalTag << SLogger::endmsg;
|
146 |
|
|
m_logger << INFO << "Using JEC for jet collection " << m_JECJetCollection << SLogger::endmsg;
|
147 |
|
|
} else
|
148 |
|
|
m_logger << WARNING << "No location for JEC files is provided" << SLogger::endmsg;
|
149 |
|
|
|
150 |
|
|
// pile-up reweighting
|
151 |
|
|
if(m_PUFilenameMC.size()>0 && m_PUFilenameData.size()>0 && m_PUHistnameMC.size()>0 && m_PUHistnameData.size()>0 && m_addGenInfo) {
|
152 |
|
|
m_PUFilenameMC += ".";
|
153 |
|
|
m_PUFilenameMC += inputData.GetType();
|
154 |
|
|
m_PUFilenameMC += ".";
|
155 |
|
|
m_PUFilenameMC += inputData.GetVersion();
|
156 |
|
|
m_PUFilenameMC += ".root";
|
157 |
|
|
m_logger << INFO << "PU Reweighting will be performed. File(data) = " << m_PUFilenameData
|
158 |
|
|
<< " File(MC) = " << m_PUFilenameMC << SLogger::endmsg;
|
159 |
|
|
m_logger << INFO << "PU, histograms: Hist(data) = " << m_PUHistnameData
|
160 |
|
|
<< " Hist(MC) = " << m_PUHistnameMC << SLogger::endmsg;
|
161 |
|
|
m_puwp = new PUWeightProducer(m_PUFilenameMC, m_PUFilenameData, m_PUHistnameMC, m_PUHistnameData);
|
162 |
|
|
} else {
|
163 |
|
|
m_puwp = NULL;
|
164 |
|
|
}
|
165 |
|
|
|
166 |
bazterra |
1.22 |
if(m_reversed_electron_selection)
|
167 |
|
|
m_logger << INFO << "Applying reversed electron selection (data-driven qcd) !!!!" << SLogger::endmsg;
|
168 |
|
|
|
169 |
rkogler |
1.23 |
// check if the settings for the systematic uncertainty make sense
|
170 |
|
|
if(m_sys_unc_name.size()>0){
|
171 |
|
|
bool isok = false;
|
172 |
|
|
if (m_sys_unc_name=="NONE" || m_sys_unc_name=="none" || m_sys_unc_name=="None") isok = true;
|
173 |
|
|
if (m_sys_unc_name=="JEC" || m_sys_unc_name=="jec") isok = true;
|
174 |
|
|
if (m_sys_unc_name=="JER" || m_sys_unc_name=="jer") isok = true;
|
175 |
peiffer |
1.24 |
if (m_sys_unc_name=="LeptonScale") isok = true;
|
176 |
rkogler |
1.23 |
|
177 |
|
|
if (isok){
|
178 |
|
|
|
179 |
|
|
if (m_sys_unc_name=="NONE" || m_sys_unc_name=="none" || m_sys_unc_name=="None"){
|
180 |
|
|
m_logger << INFO << "Running without systematic uncertainty" << SLogger::endmsg;
|
181 |
|
|
|
182 |
|
|
} else {
|
183 |
|
|
m_logger << WARNING << "Running with systematic uncertainty: " << m_sys_unc_name << " (this is more an info than a warning)" << SLogger::endmsg;
|
184 |
|
|
|
185 |
|
|
if (m_sys_var_name=="UP" || m_sys_var_name=="up" || m_sys_var_name=="Up"
|
186 |
|
|
|| m_sys_var_name=="DOWN" || m_sys_var_name=="down" || m_sys_var_name=="Down"){
|
187 |
|
|
m_logger << WARNING << "Applying shift: " << m_sys_var_name << SLogger::endmsg;
|
188 |
|
|
|
189 |
|
|
} else {
|
190 |
|
|
m_logger << FATAL << "Requested shift: " << m_sys_var_name
|
191 |
|
|
<< " is not supported. Please choose \"up\" or \"down\" for SystematicVariation" << SLogger::endmsg;
|
192 |
|
|
exit(EXIT_FAILURE);
|
193 |
|
|
}
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
} else {
|
197 |
|
|
m_logger << FATAL << "Systematic uncertainty: " << m_sys_unc_name << " is not known." << SLogger::endmsg;
|
198 |
|
|
exit(EXIT_FAILURE);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
}
|
202 |
|
|
|
203 |
bazterra |
1.18 |
// output Ntuple
|
204 |
|
|
if (inputData.GetTrees(STreeType::OutputSimpleTree)) {
|
205 |
|
|
m_logger << INFO << "adding output tree" << SLogger::endmsg;
|
206 |
|
|
DeclareVariable( m_bcc.run, "run" );
|
207 |
|
|
DeclareVariable( m_bcc.rho, "rho" );
|
208 |
|
|
DeclareVariable( m_bcc.luminosityBlock, "luminosityBlock" );
|
209 |
|
|
DeclareVariable( m_bcc.event, "event" );
|
210 |
|
|
DeclareVariable( m_bcc.isRealData, "isRealData" );
|
211 |
|
|
//DeclareVariable( m_bcc.HBHENoiseFilterResult, "HBHENoiseFilterResult" );
|
212 |
|
|
DeclareVariable( m_bcc.beamspot_x0, "beamspot_x0");
|
213 |
|
|
DeclareVariable( m_bcc.beamspot_y0, "beamspot_y0");
|
214 |
|
|
DeclareVariable( m_bcc.beamspot_z0, "beamspot_z0");
|
215 |
|
|
if(m_ElectronCollection.size()>0) DeclareVariable(m_output_electrons, m_ElectronCollection.c_str() );
|
216 |
|
|
if(m_MuonCollection.size()>0) DeclareVariable(m_output_muons, m_MuonCollection.c_str() );
|
217 |
|
|
if(m_TauCollection.size()>0) DeclareVariable(m_output_taus, m_TauCollection.c_str() );
|
218 |
|
|
if(m_JetCollection.size()>0) DeclareVariable(m_output_jets, m_JetCollection.c_str() );
|
219 |
|
|
if(m_PhotonCollection.size()>0) DeclareVariable(m_output_photons, m_PhotonCollection.c_str() );
|
220 |
|
|
if(m_METName.size()>0) DeclareVariable(m_output_met, m_METName.c_str() );
|
221 |
|
|
if(m_PrimaryVertexCollection.size()>0) DeclareVariable(m_output_pvs, m_PrimaryVertexCollection.c_str());
|
222 |
|
|
if(m_TopJetCollection.size()>0) DeclareVariable(m_output_topjets, m_TopJetCollection.c_str());
|
223 |
|
|
if(m_addGenInfo && m_TopJetCollectionGen.size()>0) DeclareVariable(m_output_topjetsgen, m_TopJetCollectionGen.c_str());
|
224 |
|
|
if(m_PrunedJetCollection.size()>0) DeclareVariable(m_output_prunedjets, m_PrunedJetCollection.c_str());
|
225 |
|
|
if(m_addGenInfo && m_GenParticleCollection.size()>0) DeclareVariable(m_output_genparticles, m_GenParticleCollection.c_str());
|
226 |
|
|
if(m_addGenInfo) DeclareVariable(m_output_genInfo, "genInfo" );
|
227 |
|
|
if(m_writeTTbarReco) DeclareVariable(m_output_recoHyps, "recoHyps");
|
228 |
|
|
DeclareVariable(m_output_triggerNames, "triggerNames");
|
229 |
|
|
DeclareVariable(m_output_triggerResults, "triggerResults");
|
230 |
|
|
}
|
231 |
|
|
|
232 |
peiffer |
1.24 |
|
233 |
rkogler |
1.27 |
if (m_sys_unc_name == "LeptonScale"){
|
234 |
|
|
if(m_sys_var_name == "UP" || m_sys_var_name == "Up" || m_sys_var_name == "up"){
|
235 |
|
|
m_lsf = new LeptonScaleFactors(m_leptonweights, e_Up);
|
236 |
|
|
} else {
|
237 |
|
|
m_lsf = new LeptonScaleFactors(m_leptonweights, e_Down);
|
238 |
|
|
}
|
239 |
|
|
} else {
|
240 |
|
|
m_lsf = new LeptonScaleFactors(m_leptonweights);
|
241 |
peiffer |
1.24 |
}
|
242 |
rkogler |
1.27 |
|
243 |
bazterra |
1.18 |
return;
|
244 |
rkogler |
1.1 |
}
|
245 |
|
|
|
246 |
|
|
|
247 |
|
|
void AnalysisCycle::RegisterSelection(Selection* sel)
|
248 |
|
|
{
|
249 |
bazterra |
1.18 |
// register a selection in the list of selections
|
250 |
|
|
|
251 |
|
|
if (!sel) {
|
252 |
|
|
m_logger << WARNING << "Got NULL pointer, can not register selection." << SLogger::endmsg;
|
253 |
|
|
return;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
// check if selection already exists, only register it if not
|
257 |
|
|
TString InName(sel->GetName());
|
258 |
|
|
bool exists = false;
|
259 |
|
|
for (unsigned int i=0; i<m_selections.size(); ++i) {
|
260 |
|
|
TString SelName = m_selections[i]->GetName();
|
261 |
|
|
if (InName == SelName) {
|
262 |
|
|
exists = true;
|
263 |
|
|
}
|
264 |
|
|
}
|
265 |
|
|
if (!exists) {
|
266 |
|
|
m_selections.push_back(sel);
|
267 |
|
|
}
|
268 |
rkogler |
1.1 |
|
269 |
rkogler |
1.4 |
return;
|
270 |
rkogler |
1.1 |
}
|
271 |
|
|
|
272 |
|
|
|
273 |
|
|
void AnalysisCycle::RegisterHistCollection(BaseHists* hists)
|
274 |
|
|
{
|
275 |
bazterra |
1.18 |
// register a collection of histograms in the list
|
276 |
rkogler |
1.1 |
|
277 |
bazterra |
1.18 |
if (!hists) {
|
278 |
|
|
m_logger << WARNING << "Got NULL pointer, can not register histogram collection." << SLogger::endmsg;
|
279 |
|
|
return;
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
|
283 |
|
|
m_histcollections.push_back(hists);
|
284 |
peiffer |
1.5 |
|
285 |
|
|
|
286 |
bazterra |
1.18 |
return;
|
287 |
rkogler |
1.1 |
}
|
288 |
|
|
|
289 |
|
|
|
290 |
|
|
Selection* AnalysisCycle::GetSelection(const std::string name)
|
291 |
|
|
{
|
292 |
bazterra |
1.18 |
// get a selection from the list of selections
|
293 |
rkogler |
1.1 |
|
294 |
bazterra |
1.18 |
TString InName(name.c_str());
|
295 |
|
|
for (unsigned int i=0; i<m_selections.size(); ++i) {
|
296 |
|
|
TString SelName = m_selections[i]->GetName();
|
297 |
|
|
if (InName == SelName) {
|
298 |
|
|
return m_selections[i];
|
299 |
|
|
}
|
300 |
|
|
}
|
301 |
|
|
m_logger << DEBUG << "Could not find selection with name " << InName << "." << SLogger::endmsg;
|
302 |
|
|
return NULL;
|
303 |
rkogler |
1.1 |
}
|
304 |
|
|
|
305 |
|
|
|
306 |
|
|
BaseHists* AnalysisCycle::GetHistCollection(const std::string name)
|
307 |
|
|
{
|
308 |
bazterra |
1.18 |
// get a histogram collection from the list
|
309 |
|
|
|
310 |
|
|
TString InName(name.c_str());
|
311 |
|
|
for (unsigned int i=0; i<m_histcollections.size(); ++i) {
|
312 |
|
|
TString HistName = m_histcollections[i]->GetName();
|
313 |
|
|
if (InName == HistName) {
|
314 |
|
|
return m_histcollections[i];
|
315 |
|
|
}
|
316 |
|
|
}
|
317 |
|
|
m_logger << WARNING << "Could not find hist collection with name " << InName << "." << SLogger::endmsg;
|
318 |
|
|
return NULL;
|
319 |
rkogler |
1.1 |
}
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
void AnalysisCycle::InitHistos()
|
324 |
|
|
{
|
325 |
bazterra |
1.18 |
// initialise all registered histograms and set the
|
326 |
|
|
// correct output path
|
327 |
rkogler |
1.1 |
|
328 |
bazterra |
1.18 |
for (unsigned int i=0; i<m_histcollections.size(); ++i) {
|
329 |
|
|
m_histcollections[i]->SetHistOutput(this->GetHistOutput());
|
330 |
|
|
m_histcollections[i]->Init();
|
331 |
|
|
}
|
332 |
rkogler |
1.1 |
|
333 |
bazterra |
1.18 |
return;
|
334 |
rkogler |
1.1 |
|
335 |
|
|
}
|
336 |
|
|
|
337 |
|
|
void AnalysisCycle::FinaliseHistos()
|
338 |
|
|
{
|
339 |
bazterra |
1.18 |
// finalise all registered histograms
|
340 |
rkogler |
1.1 |
|
341 |
bazterra |
1.18 |
for (unsigned int i=0; i<m_histcollections.size(); ++i) {
|
342 |
|
|
m_histcollections[i]->Finish();
|
343 |
|
|
}
|
344 |
rkogler |
1.1 |
|
345 |
bazterra |
1.18 |
m_histcollections.clear();
|
346 |
peiffer |
1.5 |
|
347 |
bazterra |
1.18 |
return;
|
348 |
rkogler |
1.1 |
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
void AnalysisCycle::PrintSelectionSummary()
|
352 |
|
|
{
|
353 |
bazterra |
1.18 |
// print a summary of all selections
|
354 |
rkogler |
1.1 |
|
355 |
bazterra |
1.18 |
for (unsigned int i=0; i<m_selections.size(); ++i) {
|
356 |
|
|
m_selections[i]->printCutFlow();
|
357 |
|
|
}
|
358 |
rkogler |
1.1 |
|
359 |
|
|
}
|
360 |
|
|
|
361 |
rkogler |
1.4 |
void AnalysisCycle::ResetSelectionStats()
|
362 |
|
|
{
|
363 |
bazterra |
1.18 |
// set all selection statistics to zero
|
364 |
rkogler |
1.4 |
|
365 |
bazterra |
1.18 |
for (unsigned int i=0; i<m_selections.size(); ++i) {
|
366 |
|
|
m_selections[i]->resetCutFlow();
|
367 |
|
|
}
|
368 |
rkogler |
1.4 |
|
369 |
|
|
}
|
370 |
|
|
|
371 |
rkogler |
1.1 |
|
372 |
bazterra |
1.18 |
void AnalysisCycle::EndInputData( const SInputData& ) throw( SError )
|
373 |
rkogler |
1.1 |
{
|
374 |
mmeyer |
1.8 |
|
375 |
bazterra |
1.18 |
// clean-up, info messages and final calculations after the analysis
|
376 |
rkogler |
1.1 |
|
377 |
bazterra |
1.18 |
PrintSelectionSummary();
|
378 |
peiffer |
1.3 |
|
379 |
bazterra |
1.18 |
FinaliseHistos();
|
380 |
peiffer |
1.3 |
|
381 |
bazterra |
1.18 |
ResetSelectionStats();
|
382 |
peiffer |
1.3 |
|
383 |
bazterra |
1.18 |
return;
|
384 |
rkogler |
1.1 |
|
385 |
mmeyer |
1.8 |
|
386 |
rkogler |
1.1 |
}
|
387 |
|
|
|
388 |
bazterra |
1.18 |
void AnalysisCycle::BeginInputFile( const SInputData& ) throw( SError )
|
389 |
rkogler |
1.1 |
{
|
390 |
bazterra |
1.18 |
// Connect all variables from the Ntuple file with the ones needed for the analysis.
|
391 |
|
|
// The different collections that should be loaded are steerable through the XML file.
|
392 |
|
|
// The variables are commonly stored in the BaseCycleContaincer and can be
|
393 |
|
|
// accessed afterwards through the ObjectHandler
|
394 |
|
|
|
395 |
|
|
ConnectVariable( "AnalysisTree", "triggerResults" , m_bcc.triggerResults);
|
396 |
|
|
ConnectVariable( "AnalysisTree", "triggerNames" , m_bcc.triggerNames);
|
397 |
|
|
if(m_ElectronCollection.size()>0) ConnectVariable( "AnalysisTree", m_ElectronCollection.c_str() ,m_bcc. electrons);
|
398 |
|
|
if(m_MuonCollection.size()>0) ConnectVariable( "AnalysisTree", m_MuonCollection.c_str() , m_bcc.muons);
|
399 |
|
|
if(m_TauCollection.size()>0) ConnectVariable( "AnalysisTree", m_TauCollection.c_str() , m_bcc.taus);
|
400 |
|
|
if(m_JetCollection.size()>0) ConnectVariable( "AnalysisTree", m_JetCollection.c_str() , m_bcc.jets);
|
401 |
|
|
if(m_PhotonCollection.size()>0) ConnectVariable( "AnalysisTree", m_PhotonCollection.c_str() , m_bcc.photons);
|
402 |
|
|
if(m_METName.size()>0) ConnectVariable( "AnalysisTree", m_METName.c_str() , m_bcc.met);
|
403 |
|
|
if(m_PrimaryVertexCollection.size()>0) ConnectVariable( "AnalysisTree", m_PrimaryVertexCollection.c_str() , m_bcc.pvs);
|
404 |
|
|
if(m_TopJetCollection.size()>0) ConnectVariable( "AnalysisTree", m_TopJetCollection.c_str() , m_bcc.topjets);
|
405 |
|
|
if(m_addGenInfo && m_TopJetCollectionGen.size()>0) ConnectVariable( "AnalysisTree", m_TopJetCollectionGen.c_str() , m_bcc.topjetsgen);
|
406 |
peiffer |
1.29 |
else m_bcc.topjetsgen=NULL;
|
407 |
bazterra |
1.18 |
if(m_PrunedJetCollection.size()>0) ConnectVariable( "AnalysisTree", m_PrunedJetCollection.c_str() , m_bcc.prunedjets);
|
408 |
|
|
if(m_addGenInfo && m_GenParticleCollection.size()>0) ConnectVariable( "AnalysisTree", m_GenParticleCollection.c_str() , m_bcc.genparticles);
|
409 |
peiffer |
1.29 |
else m_bcc.genparticles=NULL;
|
410 |
bazterra |
1.18 |
if(m_addGenInfo) ConnectVariable( "AnalysisTree", "genInfo" , m_bcc.genInfo);
|
411 |
peiffer |
1.29 |
else m_bcc.genInfo=NULL;
|
412 |
bazterra |
1.18 |
if(m_readTTbarReco) ConnectVariable( "AnalysisTree", "recoHyps", m_bcc.recoHyps);
|
413 |
|
|
ConnectVariable( "AnalysisTree", "run" , m_bcc.run);
|
414 |
|
|
ConnectVariable( "AnalysisTree", "rho" , m_bcc.rho);
|
415 |
|
|
ConnectVariable( "AnalysisTree", "luminosityBlock" , m_bcc.luminosityBlock);
|
416 |
|
|
ConnectVariable( "AnalysisTree" ,"event" ,m_bcc.event);
|
417 |
|
|
ConnectVariable( "AnalysisTree" ,"isRealData", m_bcc.isRealData);
|
418 |
|
|
//ConnectVariable( "AnalysisTree" ,"HBHENoiseFilterResult", m_bcc.HBHENoiseFilterResult);
|
419 |
|
|
ConnectVariable( "AnalysisTree" ,"beamspot_x0", m_bcc.beamspot_x0);
|
420 |
|
|
ConnectVariable( "AnalysisTree" ,"beamspot_y0", m_bcc.beamspot_y0);
|
421 |
|
|
ConnectVariable( "AnalysisTree" ,"beamspot_z0", m_bcc.beamspot_z0);
|
422 |
|
|
|
423 |
|
|
//if(m_caTopTagGen.size()>0) ConnectVariable("AnalysisTree", m_caTopTagGen.c_str(), m_bcc.topjets);
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
ObjectHandler* objs = ObjectHandler::Instance();
|
427 |
|
|
objs->SetBaseCycleContainer(&m_bcc);
|
428 |
|
|
objs->SetLumiHandler( LumiHandler() );
|
429 |
mmeyer |
1.8 |
|
430 |
bazterra |
1.18 |
return;
|
431 |
rkogler |
1.1 |
|
432 |
|
|
}
|
433 |
|
|
|
434 |
bazterra |
1.18 |
void AnalysisCycle::ExecuteEvent( const SInputData&, Double_t weight) throw( SError )
|
435 |
rkogler |
1.1 |
{
|
436 |
bazterra |
1.18 |
// This method performs basic consistency checks, resets the event calculator,
|
437 |
|
|
// calculates the pile-up weight and performs the good-run selection.
|
438 |
|
|
// It should always be the first thing to be called in each user analysis.
|
439 |
|
|
|
440 |
|
|
// first thing to do: call reset of event calc
|
441 |
|
|
EventCalc* calc = EventCalc::Instance();
|
442 |
|
|
calc->Reset();
|
443 |
rkogler |
1.1 |
|
444 |
bazterra |
1.18 |
if(m_bcc.isRealData && m_addGenInfo) {
|
445 |
|
|
m_logger << WARNING<< "Running over real data, but addGenInfo=True?!" << SLogger::endmsg;
|
446 |
|
|
}
|
447 |
rkogler |
1.1 |
|
448 |
bazterra |
1.18 |
//fill list of trigger names
|
449 |
peiffer |
1.25 |
|
450 |
bazterra |
1.18 |
if(m_bcc.triggerNames->size()!=0) {
|
451 |
|
|
m_bcc.triggerNames_actualrun = *m_bcc.triggerNames;
|
452 |
|
|
m_newrun=true;
|
453 |
|
|
}
|
454 |
peiffer |
1.25 |
|
455 |
|
|
if(m_bcc.triggerNames_actualrun.size()==0){
|
456 |
|
|
|
457 |
|
|
m_logger << WARNING<< "No trigger table found for this event -> start trigger search on following events" << SLogger::endmsg;
|
458 |
|
|
|
459 |
|
|
int tmp_run= m_bcc.run;
|
460 |
|
|
int tmp_event = m_bcc.event;
|
461 |
|
|
|
462 |
|
|
TTree* tmp_tree = GetInputTree("AnalysisTree");
|
463 |
|
|
|
464 |
|
|
int N_ent= tmp_tree->GetEntries();
|
465 |
|
|
for(int i=0; i<N_ent; ++i){
|
466 |
|
|
tmp_tree->GetEntry(i);
|
467 |
|
|
|
468 |
peiffer |
1.26 |
//search for next event in tree with trigger table filled, check for same run number in case of real data
|
469 |
|
|
if(m_bcc.triggerNames->size()!=0 && (!m_bcc.isRealData || m_bcc.run==tmp_run)){
|
470 |
peiffer |
1.25 |
m_bcc.triggerNames_actualrun = *m_bcc.triggerNames;
|
471 |
|
|
m_newrun=true;
|
472 |
|
|
m_logger << WARNING<< "Trigger search was succesful" << SLogger::endmsg;
|
473 |
|
|
break;
|
474 |
|
|
}
|
475 |
|
|
}
|
476 |
|
|
|
477 |
|
|
//go back to original event
|
478 |
|
|
for(int i=0; i<N_ent; ++i){
|
479 |
|
|
tmp_tree->GetEntry(i);
|
480 |
|
|
if(m_bcc.event==tmp_event && m_bcc.run==tmp_run) break;
|
481 |
|
|
}
|
482 |
|
|
|
483 |
|
|
if(m_bcc.event!=tmp_event || m_bcc.run!=tmp_run){
|
484 |
|
|
m_logger << ERROR<< "Trigger search error: can not find original event" << SLogger::endmsg;
|
485 |
|
|
}
|
486 |
|
|
|
487 |
|
|
}
|
488 |
|
|
if(m_bcc.triggerNames_actualrun.size()==0){
|
489 |
|
|
m_logger << ERROR << "Trigger search was NOT succesful!!!" << SLogger::endmsg;
|
490 |
|
|
}
|
491 |
rkogler |
1.1 |
|
492 |
bazterra |
1.18 |
// generate random run Nr for MC samples (consider luminosity of each run)
|
493 |
|
|
// e.g. for proper OTX cut in MC, and needs to be done only once per event
|
494 |
|
|
if( !m_bcc.isRealData && LumiHandler()->IsLumiCalc() ) {
|
495 |
peiffer |
1.25 |
m_bcc.run = LumiHandler()->GetRandomRunNr();
|
496 |
bazterra |
1.18 |
}
|
497 |
rkogler |
1.1 |
|
498 |
bazterra |
1.18 |
//set the lumiweight to 1 for data
|
499 |
|
|
if(m_bcc.isRealData) weight = 1;
|
500 |
rkogler |
1.1 |
|
501 |
bazterra |
1.18 |
// store the weight (lumiweight) in the eventcalc class and use it
|
502 |
|
|
calc -> ProduceWeight(weight);
|
503 |
peiffer |
1.12 |
|
504 |
peiffer |
1.29 |
if(!m_bcc.isRealData && m_bcc.genInfo) {
|
505 |
mmeyer |
1.8 |
|
506 |
bazterra |
1.18 |
std::vector<float> genweights = m_bcc.genInfo->weights();
|
507 |
|
|
for(unsigned int i=0; i< genweights.size(); ++i) {
|
508 |
|
|
calc -> ProduceWeight(genweights[i]);
|
509 |
|
|
}
|
510 |
|
|
|
511 |
|
|
if(m_puwp) {
|
512 |
|
|
double pu_weight = m_puwp->produceWeight(m_bcc.genInfo);
|
513 |
|
|
// set the weight in the eventcalc
|
514 |
|
|
calc -> ProduceWeight(pu_weight);
|
515 |
|
|
}
|
516 |
|
|
|
517 |
|
|
//lepton scale factor
|
518 |
|
|
if(m_lsf) {
|
519 |
rkogler |
1.27 |
calc->ProduceWeight(m_lsf->GetWeight());
|
520 |
bazterra |
1.18 |
}
|
521 |
mmeyer |
1.8 |
}
|
522 |
|
|
|
523 |
bazterra |
1.18 |
//select only good runs
|
524 |
|
|
if(m_bcc.isRealData && LumiHandler()->IsLumiCalc() ) {
|
525 |
|
|
if( !LumiHandler()->PassGoodRunsList( m_bcc.run, m_bcc.luminosityBlock )) throw SError( SError::SkipEvent );
|
526 |
rkogler |
1.1 |
}
|
527 |
peiffer |
1.14 |
|
528 |
bazterra |
1.18 |
//create new pointer to recoHyps if no recoHyps were read in
|
529 |
|
|
//note: list of recoHyps is still empty, has to be filled in the user cycle
|
530 |
peiffer |
1.13 |
|
531 |
peiffer |
1.28 |
if(!m_readTTbarReco && m_writeTTbarReco){
|
532 |
|
|
m_bcc.recoHyps = new std::vector<ReconstructionHypothesis>;
|
533 |
|
|
}
|
534 |
peiffer |
1.29 |
|
535 |
bazterra |
1.18 |
return;
|
536 |
rkogler |
1.1 |
|
537 |
|
|
}
|
538 |
|
|
|
539 |
peiffer |
1.2 |
void AnalysisCycle::WriteOutputTree() throw( SError)
|
540 |
|
|
{
|
541 |
bazterra |
1.18 |
//write out all objects
|
542 |
|
|
m_output_photons.clear();
|
543 |
|
|
m_output_jets.clear();
|
544 |
|
|
m_output_electrons.clear();
|
545 |
|
|
m_output_muons.clear();
|
546 |
|
|
m_output_taus.clear();
|
547 |
|
|
m_output_pvs.clear();
|
548 |
|
|
m_output_topjets.clear();
|
549 |
|
|
m_output_topjetsgen.clear();
|
550 |
|
|
m_output_prunedjets.clear();
|
551 |
|
|
m_output_genparticles.clear();
|
552 |
|
|
m_output_triggerNames.clear();
|
553 |
|
|
m_output_triggerResults.clear();
|
554 |
|
|
m_output_recoHyps.clear();
|
555 |
|
|
|
556 |
|
|
if(m_PhotonCollection.size()>0) m_output_photons=*m_bcc.photons;
|
557 |
|
|
if(m_JetCollection.size()>0) m_output_jets=*m_bcc.jets;
|
558 |
|
|
if(m_ElectronCollection.size()>0) m_output_electrons=*m_bcc.electrons;
|
559 |
|
|
if(m_MuonCollection.size()>0) m_output_muons=*m_bcc.muons;
|
560 |
|
|
if(m_TauCollection.size()>0) m_output_taus=*m_bcc.taus;
|
561 |
|
|
if(m_PrimaryVertexCollection.size()>0) m_output_pvs=*m_bcc.pvs;
|
562 |
|
|
if(m_METName.size()>0) m_output_met = *m_bcc.met;
|
563 |
|
|
if(m_addGenInfo) m_output_genInfo = *m_bcc.genInfo;
|
564 |
|
|
if(m_TopJetCollection.size()>0) m_output_topjets=*m_bcc.topjets;
|
565 |
|
|
if(m_addGenInfo && m_TopJetCollectionGen.size()>0) m_output_topjetsgen=*m_bcc.topjetsgen;
|
566 |
|
|
if(m_PrunedJetCollection.size()>0) m_output_prunedjets=*m_bcc.prunedjets;
|
567 |
|
|
if(m_addGenInfo && m_GenParticleCollection.size()>0) m_output_genparticles=*m_bcc.genparticles;
|
568 |
|
|
if(m_writeTTbarReco) m_output_recoHyps=*m_bcc.recoHyps;
|
569 |
|
|
|
570 |
|
|
if(m_newrun) m_output_triggerNames = m_bcc.triggerNames_actualrun;//store trigger names only for new runs
|
571 |
|
|
m_newrun=false;
|
572 |
peiffer |
1.2 |
|
573 |
bazterra |
1.18 |
m_output_triggerResults = *m_bcc.triggerResults;
|
574 |
peiffer |
1.2 |
|
575 |
peiffer |
1.28 |
|
576 |
|
|
//clear reco hyp pointers for next event
|
577 |
|
|
if( m_bcc.recoHyps && !m_readTTbarReco && m_writeTTbarReco){
|
578 |
|
|
//std::cout <<"recoHyps size = " << m_bcc.recoHyps->size() <<std::endl;
|
579 |
|
|
m_bcc.recoHyps->clear();
|
580 |
|
|
delete m_bcc.recoHyps;
|
581 |
|
|
}
|
582 |
|
|
|
583 |
peiffer |
1.2 |
}
|
584 |
|
|
|