1 |
|
// $Id$ |
2 |
|
|
3 |
+ |
#include "MitProd/TreeFiller/interface/FillMitTree.h" |
4 |
|
#include "FWCore/MessageLogger/interface/MessageLogger.h" |
5 |
< |
#include "FWCore/Framework/interface/ESHandle.h" |
5 |
< |
#include "DataFormats/Common/interface/Handle.h" |
5 |
> |
#include "FWCore/ParameterSet/interface/ParameterSet.h" |
6 |
|
#include "FWCore/ServiceRegistry/interface/Service.h" |
7 |
< |
|
8 |
< |
#include "MitProd/TreeFiller/interface/FillerGlobalMuons.h" |
9 |
< |
#include "MitProd/TreeFiller/interface/FillMitTree.h" |
7 |
> |
#include "MitProd/TreeService/interface/TreeService.h" |
8 |
> |
#include "MitProd/ObjectService/interface/ObjectService.h" |
9 |
> |
#include "MitProd/TreeFiller/interface/AssociationMaps.h" |
10 |
> |
#include "MitProd/TreeFiller/interface/FillerBasicClusters.h" |
11 |
> |
#include "MitProd/TreeFiller/interface/FillerBeamSpot.h" |
12 |
> |
#include "MitProd/TreeFiller/interface/FillerCaloJets.h" |
13 |
> |
#include "MitProd/TreeFiller/interface/FillerCaloMet.h" |
14 |
> |
#include "MitProd/TreeFiller/interface/FillerCaloTaus.h" |
15 |
> |
#include "MitProd/TreeFiller/interface/FillerCaloTowers.h" |
16 |
> |
#include "MitProd/TreeFiller/interface/FillerConversionElectrons.h" |
17 |
> |
#include "MitProd/TreeFiller/interface/FillerConversions.h" |
18 |
> |
#include "MitProd/TreeFiller/interface/FillerDecayParts.h" |
19 |
> |
#include "MitProd/TreeFiller/interface/FillerElectrons.h" |
20 |
> |
#include "MitProd/TreeFiller/interface/FillerGenJets.h" |
21 |
> |
#include "MitProd/TreeFiller/interface/FillerMetaInfos.h" |
22 |
> |
#include "MitProd/TreeFiller/interface/FillerMCEventInfo.h" |
23 |
> |
#include "MitProd/TreeFiller/interface/FillerMCParticles.h" |
24 |
> |
#include "MitProd/TreeFiller/interface/FillerMet.h" |
25 |
> |
#include "MitProd/TreeFiller/interface/FillerMetaInfos.h" |
26 |
> |
#include "MitProd/TreeFiller/interface/FillerMuons.h" |
27 |
> |
#include "MitProd/TreeFiller/interface/FillerPFCandidates.h" |
28 |
> |
#include "MitProd/TreeFiller/interface/FillerPFJets.h" |
29 |
> |
#include "MitProd/TreeFiller/interface/FillerPFMet.h" |
30 |
> |
#include "MitProd/TreeFiller/interface/FillerPFTaus.h" |
31 |
> |
#include "MitProd/TreeFiller/interface/FillerPhotons.h" |
32 |
> |
#include "MitProd/TreeFiller/interface/FillerStableParts.h" |
33 |
> |
#include "MitProd/TreeFiller/interface/FillerSuperClusters.h" |
34 |
> |
#include "MitProd/TreeFiller/interface/FillerTracks.h" |
35 |
> |
#include "MitProd/TreeFiller/interface/FillerVertexes.h" |
36 |
> |
#include "MitAna/DataTree/interface/Names.h" |
37 |
> |
#include "MitAna/DataTree/interface/BranchTable.h" |
38 |
|
|
39 |
|
using namespace std; |
40 |
|
using namespace edm; |
41 |
|
using namespace mithep; |
42 |
|
|
43 |
< |
//------------------------------------------------------------------------------------------------- |
43 |
> |
mithep::ObjectService *mithep::FillMitTree::os_ = 0; |
44 |
> |
|
45 |
> |
//-------------------------------------------------------------------------------------------------- |
46 |
|
FillMitTree::FillMitTree(const edm::ParameterSet &cfg) : |
47 |
< |
fillerGlobalMuons_(0) |
47 |
> |
defactive_(cfg.getUntrackedParameter<bool>("defactive",1)), |
48 |
> |
brtable_(0), |
49 |
> |
acfnumber_(-1) |
50 |
|
{ |
51 |
< |
// initialize fillers |
52 |
< |
fillerGlobalMuons_ = new FillerGlobalMuons(cfg); |
53 |
< |
if (fillerGlobalMuons_->Active()) |
54 |
< |
fillers_.push_back(fillerGlobalMuons_); |
51 |
> |
// Constructor. |
52 |
> |
|
53 |
> |
if (!configure(cfg)) { |
54 |
> |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::FillMitTree()\n") |
55 |
> |
<< "Could not configure fillers." << "\n"; |
56 |
> |
} |
57 |
|
} |
58 |
|
|
59 |
< |
//------------------------------------------------------------------------------------------------- |
59 |
> |
//-------------------------------------------------------------------------------------------------- |
60 |
|
FillMitTree::~FillMitTree() |
61 |
|
{ |
62 |
< |
// We own the fillers so we have to delete them |
63 |
< |
delete fillerGlobalMuons_; |
62 |
> |
// Destructor. |
63 |
> |
|
64 |
> |
delete brtable_; |
65 |
|
} |
66 |
|
|
67 |
< |
//------------------------------------------------------------------------------------------------- |
68 |
< |
void FillMitTree::beginJob(edm::EventSetup const &event) |
67 |
> |
//-------------------------------------------------------------------------------------------------- |
68 |
> |
bool FillMitTree::addActiveFiller(BaseFiller *bf) |
69 |
|
{ |
70 |
< |
Service<TreeService> ts; |
36 |
< |
TreeWriter *tws = ts->get(); |
37 |
< |
if (! tws) { |
38 |
< |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n") |
39 |
< |
<< "Could not get pointer to Tree with name " << tws->GetName() << "\n"; |
40 |
< |
return; |
41 |
< |
} |
70 |
> |
// Check if filler is active and add it to list of fillers. Otherwise delete it. |
71 |
|
|
72 |
< |
// Loop over the various components and book the branches |
73 |
< |
for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) { |
74 |
< |
(*iF)->BookDataBlock(tws); |
72 |
> |
if (!bf) |
73 |
> |
return 0; |
74 |
> |
|
75 |
> |
if (bf->Active()) { |
76 |
> |
fillers_.push_back(bf); |
77 |
> |
return 1; |
78 |
|
} |
79 |
< |
return; |
79 |
> |
|
80 |
> |
delete bf; |
81 |
> |
bf = 0; |
82 |
> |
return 0; |
83 |
|
} |
84 |
|
|
85 |
< |
//------------------------------------------------------------------------------------------------- |
85 |
> |
//-------------------------------------------------------------------------------------------------- |
86 |
|
void FillMitTree::analyze(const edm::Event &event, |
87 |
|
const edm::EventSetup &setup) |
88 |
|
{ |
89 |
< |
// First step: Loop over the data fillers of the various components |
89 |
> |
// Access and copy event content. |
90 |
> |
|
91 |
> |
// first step: Loop over the data fillers of the various components |
92 |
|
for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) { |
93 |
|
(*iF)->FillDataBlock(event,setup); |
94 |
|
} |
95 |
|
|
96 |
< |
// Second step: Loop over the link resolution of the various components |
96 |
> |
// second step: Loop over the link resolution of the various components |
97 |
|
for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) { |
98 |
|
(*iF)->ResolveLinks(event,setup); |
99 |
|
} |
100 |
+ |
|
101 |
+ |
if (brtable_) { // only the first FillMitTree object has to deal with the branch table |
102 |
+ |
if (acfnumber_==-1) { |
103 |
+ |
brtable_->Rehash(brtable_->GetSize()); |
104 |
+ |
if (0) |
105 |
+ |
brtable_->Print(); |
106 |
+ |
} |
107 |
+ |
if (acfnumber_ != tws_->GetFileNumber()) { |
108 |
+ |
tws_->StoreObject(brtable_); |
109 |
+ |
acfnumber_ = tws_->GetFileNumber(); |
110 |
+ |
} |
111 |
+ |
} |
112 |
+ |
} |
113 |
+ |
|
114 |
+ |
//-------------------------------------------------------------------------------------------------- |
115 |
+ |
void FillMitTree::beginJob(const edm::EventSetup &event) |
116 |
+ |
{ |
117 |
+ |
// Access the tree and book branches. |
118 |
+ |
|
119 |
+ |
Service<TreeService> ts; |
120 |
+ |
tws_ = ts->get(); |
121 |
+ |
if (!tws_) { |
122 |
+ |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n") |
123 |
+ |
<< "Could not get pointer to tree. " |
124 |
+ |
<< "Do you have the TreeServie define in your config?" << "\n"; |
125 |
+ |
return; |
126 |
+ |
} |
127 |
+ |
|
128 |
+ |
if (os_==0) { // only the first FillMitTree object has to deal with this |
129 |
+ |
Service<ObjectService> os; |
130 |
+ |
if (!os.isAvailable()) { |
131 |
+ |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n") |
132 |
+ |
<< "Could not get object service. " |
133 |
+ |
<< "Do you have the ObjectService defined in your config?" << "\n"; |
134 |
+ |
return; |
135 |
+ |
} |
136 |
+ |
os_ = &(*os); |
137 |
+ |
brtable_ = new BranchTable; |
138 |
+ |
brtable_->SetName(Names::gkBranchTable); |
139 |
+ |
brtable_->SetOwner(); |
140 |
+ |
os->add(brtable_, brtable_->GetName()); |
141 |
+ |
} |
142 |
+ |
|
143 |
+ |
// loop over the various components and book the branches |
144 |
+ |
for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) { |
145 |
+ |
edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl; |
146 |
+ |
(*iF)->BookDataBlock(*tws_); |
147 |
+ |
} |
148 |
+ |
} |
149 |
+ |
|
150 |
+ |
//-------------------------------------------------------------------------------------------------- |
151 |
+ |
bool FillMitTree::configure(const edm::ParameterSet &cfg) |
152 |
+ |
{ |
153 |
+ |
// Configure our fillers according to given parameter ("fillers"). |
154 |
+ |
|
155 |
+ |
std::vector<std::string> pars; |
156 |
+ |
if (cfg.exists("fillers")) |
157 |
+ |
pars=cfg.getUntrackedParameter<vector<string> >("fillers"); |
158 |
+ |
else |
159 |
+ |
cfg.getParameterSetNames(pars, false); |
160 |
+ |
|
161 |
+ |
// loop over psets |
162 |
+ |
for (unsigned int i = 0; i<pars.size(); ++i) { |
163 |
+ |
|
164 |
+ |
const string name(pars.at(i)); |
165 |
+ |
|
166 |
+ |
string ftype("Filler" + name); |
167 |
+ |
if (cfg.existsAs<ParameterSet>(name,0)) { |
168 |
+ |
ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name)); |
169 |
+ |
if (!next.exists("fillerType")) { |
170 |
+ |
edm::LogError("FillMitTree") << "Can not determine fillerType for pset named " |
171 |
+ |
<< name << std::endl; |
172 |
+ |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n") |
173 |
+ |
<< "Can not determine fillerType for pset named " |
174 |
+ |
<< name << std::endl; |
175 |
+ |
} |
176 |
+ |
ftype = next.getUntrackedParameter<string>("fillerType"); |
177 |
+ |
} |
178 |
+ |
|
179 |
+ |
edm::LogInfo("FillMitTree") << "Attempting to configure '" << ftype |
180 |
+ |
<< "' for '" << name << "'" << std::endl; |
181 |
+ |
|
182 |
+ |
if (ftype.compare("FillerMetaInfos")==0) { |
183 |
+ |
FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg, name.c_str(), defactive_); |
184 |
+ |
addActiveFiller(fillerMetaInfos); |
185 |
+ |
continue; |
186 |
+ |
} |
187 |
+ |
|
188 |
+ |
if (ftype.compare("FillerMCParticles")==0) { |
189 |
+ |
FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_); |
190 |
+ |
addActiveFiller(fillerMCParticles); |
191 |
+ |
continue; |
192 |
+ |
} |
193 |
+ |
|
194 |
+ |
if (ftype.compare("FillerMCEventInfo")==0) { |
195 |
+ |
FillerMCEventInfo *fillerMCEventInfo = new FillerMCEventInfo(cfg, name.c_str(), defactive_); |
196 |
+ |
addActiveFiller(fillerMCEventInfo); |
197 |
+ |
continue; |
198 |
+ |
} |
199 |
+ |
|
200 |
+ |
if (ftype.compare("FillerBeamSpot")==0) { |
201 |
+ |
FillerBeamSpot *fillerBeamSpot = new FillerBeamSpot(cfg, name.c_str(), defactive_); |
202 |
+ |
addActiveFiller(fillerBeamSpot); |
203 |
+ |
continue; |
204 |
+ |
} |
205 |
+ |
|
206 |
+ |
if (ftype.compare("FillerVertexes")==0) { |
207 |
+ |
FillerVertexes *fillerVertexes = new FillerVertexes(cfg, name.c_str(), defactive_); |
208 |
+ |
addActiveFiller(fillerVertexes); |
209 |
+ |
continue; |
210 |
+ |
} |
211 |
+ |
|
212 |
+ |
if (ftype.compare("FillerCaloTowers")==0) { |
213 |
+ |
FillerCaloTowers *fillerCaloTowers = new FillerCaloTowers(cfg, name.c_str(), defactive_); |
214 |
+ |
addActiveFiller(fillerCaloTowers); |
215 |
+ |
continue; |
216 |
+ |
} |
217 |
+ |
|
218 |
+ |
if (ftype.compare("FillerGenJets")==0) { |
219 |
+ |
FillerGenJets *fillerGenJets = new FillerGenJets(cfg, name.c_str(), defactive_); |
220 |
+ |
addActiveFiller(fillerGenJets); |
221 |
+ |
continue; |
222 |
+ |
} |
223 |
+ |
|
224 |
+ |
if (ftype.compare("FillerCaloJets")==0) { |
225 |
+ |
FillerCaloJets *fillerCaloJets = new FillerCaloJets(cfg, name.c_str(), defactive_); |
226 |
+ |
addActiveFiller(fillerCaloJets); |
227 |
+ |
continue; |
228 |
+ |
} |
229 |
+ |
|
230 |
+ |
if (ftype.compare("FillerMet")==0) { |
231 |
+ |
FillerMet *fillerMet = new FillerMet(cfg, name.c_str(), defactive_); |
232 |
+ |
addActiveFiller(fillerMet); |
233 |
+ |
continue; |
234 |
+ |
} |
235 |
+ |
|
236 |
+ |
if (ftype.compare("FillerCaloMet")==0) { |
237 |
+ |
FillerCaloMet *fillerCaloMet = new FillerCaloMet(cfg, name.c_str(), defactive_); |
238 |
+ |
addActiveFiller(fillerCaloMet); |
239 |
+ |
continue; |
240 |
+ |
} |
241 |
+ |
|
242 |
+ |
if (ftype.compare("FillerPFMet")==0) { |
243 |
+ |
FillerPFMet *fillerPFMet = new FillerPFMet(cfg, name.c_str(), defactive_); |
244 |
+ |
addActiveFiller(fillerPFMet); |
245 |
+ |
continue; |
246 |
+ |
} |
247 |
+ |
|
248 |
+ |
if (ftype.compare("FillerBasicClusters")==0) { |
249 |
+ |
FillerBasicClusters *fillerBasicClusters = |
250 |
+ |
new FillerBasicClusters(cfg, name.c_str(), defactive_); |
251 |
+ |
addActiveFiller(fillerBasicClusters); |
252 |
+ |
continue; |
253 |
+ |
} |
254 |
+ |
|
255 |
+ |
if (ftype.compare("FillerSuperClusters")==0) { |
256 |
+ |
FillerSuperClusters *fillerSuperClusters = |
257 |
+ |
new FillerSuperClusters(cfg, name.c_str(), defactive_); |
258 |
+ |
addActiveFiller(fillerSuperClusters); |
259 |
+ |
continue; |
260 |
+ |
} |
261 |
+ |
|
262 |
+ |
if (ftype.compare("FillerTracks")==0) { |
263 |
+ |
FillerTracks *fillerTracks = new FillerTracks(cfg, name.c_str(), defactive_); |
264 |
+ |
addActiveFiller(fillerTracks); |
265 |
+ |
continue; |
266 |
+ |
} |
267 |
+ |
|
268 |
+ |
if (ftype.compare("FillerMuons")==0) { |
269 |
+ |
FillerMuons *fillerMuons = new FillerMuons(cfg, name.c_str(), defactive_); |
270 |
+ |
addActiveFiller(fillerMuons); |
271 |
+ |
continue; |
272 |
+ |
} |
273 |
+ |
|
274 |
+ |
if (ftype.compare("FillerElectrons")==0) { |
275 |
+ |
FillerElectrons *fillerElectrons = new FillerElectrons(cfg, name.c_str(), defactive_); |
276 |
+ |
addActiveFiller(fillerElectrons); |
277 |
+ |
continue; |
278 |
+ |
} |
279 |
+ |
|
280 |
+ |
if (ftype.compare("FillerConversionElectrons")==0) { |
281 |
+ |
FillerConversionElectrons *fillerConversionElectrons = |
282 |
+ |
new FillerConversionElectrons(cfg, name.c_str(), defactive_); |
283 |
+ |
addActiveFiller(fillerConversionElectrons); |
284 |
+ |
continue; |
285 |
+ |
} |
286 |
+ |
|
287 |
+ |
if (ftype.compare("FillerConversions")==0) { |
288 |
+ |
FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_); |
289 |
+ |
addActiveFiller(fillerConversions); |
290 |
+ |
continue; |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
if (ftype.compare("FillerPhotons")==0) { |
294 |
+ |
FillerPhotons *fillerPhotons = new FillerPhotons(cfg, name.c_str(), defactive_); |
295 |
+ |
addActiveFiller(fillerPhotons); |
296 |
+ |
continue; |
297 |
+ |
} |
298 |
+ |
|
299 |
+ |
if (ftype.compare("FillerStableParts")==0) { |
300 |
+ |
FillerStableParts *fillerStableParts = new FillerStableParts(cfg, name.c_str(), defactive_); |
301 |
+ |
addActiveFiller(fillerStableParts); |
302 |
+ |
continue; |
303 |
+ |
} |
304 |
+ |
|
305 |
+ |
if (ftype.compare("FillerDecayParts")==0) { |
306 |
+ |
FillerDecayParts *fillerDecayParts = new FillerDecayParts(cfg, name.c_str(), defactive_); |
307 |
+ |
addActiveFiller(fillerDecayParts); |
308 |
+ |
continue; |
309 |
+ |
} |
310 |
+ |
|
311 |
+ |
if (ftype.compare("FillerPFCandidates")==0) { |
312 |
+ |
FillerPFCandidates *fillerPFCands = new FillerPFCandidates(cfg, name.c_str(), defactive_); |
313 |
+ |
addActiveFiller(fillerPFCands); |
314 |
+ |
continue; |
315 |
+ |
} |
316 |
+ |
|
317 |
+ |
if (ftype.compare("FillerPFJets")==0) { |
318 |
+ |
FillerPFJets *fillerPFJets = new FillerPFJets(cfg, name.c_str(), defactive_); |
319 |
+ |
addActiveFiller(fillerPFJets); |
320 |
+ |
continue; |
321 |
+ |
} |
322 |
+ |
|
323 |
+ |
if (ftype.compare("FillerCaloTaus")==0) { |
324 |
+ |
FillerCaloTaus *fillerCaloTaus = new FillerCaloTaus(cfg, name.c_str(), defactive_); |
325 |
+ |
addActiveFiller(fillerCaloTaus); |
326 |
+ |
continue; |
327 |
+ |
} |
328 |
+ |
|
329 |
+ |
if (ftype.compare("FillerPFTaus")==0) { |
330 |
+ |
FillerPFTaus *fillerPFTaus = new FillerPFTaus(cfg, name.c_str(), defactive_); |
331 |
+ |
addActiveFiller(fillerPFTaus); |
332 |
+ |
continue; |
333 |
+ |
} |
334 |
+ |
|
335 |
+ |
edm::LogError("FillMitTree") |
336 |
+ |
<< "Unknown fillerType " << ftype << " for pset named " << name << std::endl; |
337 |
+ |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n") |
338 |
+ |
<< "Unknown fillerType " << ftype << " for pset named " << name << std::endl; |
339 |
+ |
} |
340 |
+ |
|
341 |
+ |
return 1; |
342 |
|
} |
343 |
|
|
344 |
< |
//------------------------------------------------------------------------------------------------- |
344 |
> |
//-------------------------------------------------------------------------------------------------- |
345 |
|
void FillMitTree::endJob() |
346 |
|
{ |
347 |
+ |
// Delete fillers. |
348 |
+ |
|
349 |
+ |
for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) { |
350 |
+ |
delete *iF; |
351 |
+ |
} |
352 |
+ |
|
353 |
|
edm::LogInfo("FillMitTree::endJob") << "Ending Job" << endl; |
354 |
|
} |