1 |
// $Id: FillMitTree.cc,v 1.56 2010/03/18 20:21:00 bendavid Exp $
|
2 |
|
3 |
#include "MitProd/TreeFiller/interface/FillMitTree.h"
|
4 |
#include "FWCore/MessageLogger/interface/MessageLogger.h"
|
5 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
6 |
#include "FWCore/ServiceRegistry/interface/Service.h"
|
7 |
#include "MitProd/ObjectService/interface/ObjectService.h"
|
8 |
#include "MitProd/TreeFiller/interface/AssociationMaps.h"
|
9 |
#include "MitProd/TreeFiller/interface/FillerBasicClusters.h"
|
10 |
#include "MitProd/TreeFiller/interface/FillerBeamSpot.h"
|
11 |
#include "MitProd/TreeFiller/interface/FillerCaloJets.h"
|
12 |
#include "MitProd/TreeFiller/interface/FillerCaloMet.h"
|
13 |
#include "MitProd/TreeFiller/interface/FillerCaloTaus.h"
|
14 |
#include "MitProd/TreeFiller/interface/FillerCaloTowers.h"
|
15 |
#include "MitProd/TreeFiller/interface/FillerConversions.h"
|
16 |
#include "MitProd/TreeFiller/interface/FillerDecayParts.h"
|
17 |
#include "MitProd/TreeFiller/interface/FillerElectrons.h"
|
18 |
#include "MitProd/TreeFiller/interface/FillerEvtSelData.h"
|
19 |
#include "MitProd/TreeFiller/interface/FillerGenJets.h"
|
20 |
#include "MitProd/TreeFiller/interface/FillerGenMet.h"
|
21 |
#include "MitProd/TreeFiller/interface/FillerJPTJets.h"
|
22 |
#include "MitProd/TreeFiller/interface/FillerMCEventInfo.h"
|
23 |
#include "MitProd/TreeFiller/interface/FillerMCParticles.h"
|
24 |
#include "MitProd/TreeFiller/interface/FillerMCVertexes.h"
|
25 |
#include "MitProd/TreeFiller/interface/FillerMet.h"
|
26 |
#include "MitProd/TreeFiller/interface/FillerMetaInfos.h"
|
27 |
#include "MitProd/TreeFiller/interface/FillerMetaInfos.h"
|
28 |
#include "MitProd/TreeFiller/interface/FillerMuons.h"
|
29 |
#include "MitProd/TreeFiller/interface/FillerPFCandidates.h"
|
30 |
#include "MitProd/TreeFiller/interface/FillerPFJets.h"
|
31 |
#include "MitProd/TreeFiller/interface/FillerPFMet.h"
|
32 |
#include "MitProd/TreeFiller/interface/FillerPFTaus.h"
|
33 |
#include "MitProd/TreeFiller/interface/FillerPhotons.h"
|
34 |
#include "MitProd/TreeFiller/interface/FillerPixelHits.h"
|
35 |
#include "MitProd/TreeFiller/interface/FillerStableParts.h"
|
36 |
#include "MitProd/TreeFiller/interface/FillerStripHits.h"
|
37 |
#include "MitProd/TreeFiller/interface/FillerSuperClusters.h"
|
38 |
#include "MitProd/TreeFiller/interface/FillerTracks.h"
|
39 |
#include "MitProd/TreeFiller/interface/FillerTrackJets.h"
|
40 |
#include "MitProd/TreeFiller/interface/FillerVertexes.h"
|
41 |
#include "MitAna/DataTree/interface/Names.h"
|
42 |
#include "MitAna/DataTree/interface/BranchTable.h"
|
43 |
#include "MitCommon/OptIO/interface/OptInt.h"
|
44 |
|
45 |
using namespace std;
|
46 |
using namespace edm;
|
47 |
using namespace mithep;
|
48 |
|
49 |
mithep::ObjectService *mithep::FillMitTree::os_ = 0;
|
50 |
|
51 |
//--------------------------------------------------------------------------------------------------
|
52 |
FillMitTree::FillMitTree(const edm::ParameterSet &cfg) :
|
53 |
defactive_(cfg.getUntrackedParameter<bool>("defactive",1)),
|
54 |
brtable_(0),
|
55 |
acfnumber_(-1),
|
56 |
tws_(new TreeWriter(Names::gkEvtTreeName,0))
|
57 |
{
|
58 |
// Constructor.
|
59 |
|
60 |
if (!configure(cfg)) {
|
61 |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::FillMitTree()\n")
|
62 |
<< "Could not configure fillers." << "\n";
|
63 |
}
|
64 |
}
|
65 |
|
66 |
//--------------------------------------------------------------------------------------------------
|
67 |
FillMitTree::~FillMitTree()
|
68 |
{
|
69 |
// Destructor.
|
70 |
|
71 |
delete brtable_;
|
72 |
delete tws_;
|
73 |
}
|
74 |
|
75 |
//--------------------------------------------------------------------------------------------------
|
76 |
bool FillMitTree::addActiveFiller(BaseFiller *bf)
|
77 |
{
|
78 |
// Check if filler is active and add it to list of fillers. Otherwise delete it.
|
79 |
|
80 |
if (!bf)
|
81 |
return 0;
|
82 |
|
83 |
if (bf->Active()) {
|
84 |
fillers_.push_back(bf);
|
85 |
return 1;
|
86 |
}
|
87 |
|
88 |
delete bf;
|
89 |
bf = 0;
|
90 |
return 0;
|
91 |
}
|
92 |
|
93 |
//--------------------------------------------------------------------------------------------------
|
94 |
void FillMitTree::beginRun(edm::Run const &run, edm::EventSetup const &setup)
|
95 |
{
|
96 |
// Access and copy event content.
|
97 |
|
98 |
// first step: Loop over the data fillers of the various components
|
99 |
for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
|
100 |
(*iF)->FillRunBlock(run,setup);
|
101 |
}
|
102 |
|
103 |
}
|
104 |
|
105 |
//--------------------------------------------------------------------------------------------------
|
106 |
void FillMitTree::analyze(const edm::Event &event,
|
107 |
const edm::EventSetup &setup)
|
108 |
{
|
109 |
// Access and copy event content.
|
110 |
|
111 |
//tree writer begin event actions
|
112 |
tws_->BeginEvent(kTRUE);
|
113 |
|
114 |
// first step: Loop over the data fillers of the various components
|
115 |
for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
|
116 |
(*iF)->FillDataBlock(event,setup);
|
117 |
}
|
118 |
|
119 |
// second step: Loop over the link resolution of the various components
|
120 |
for (std::vector<BaseFiller*>::const_iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
|
121 |
(*iF)->ResolveLinks(event,setup);
|
122 |
}
|
123 |
|
124 |
if (brtable_) { // only the first FillMitTree object has to deal with the branch table
|
125 |
if (acfnumber_==-1) {
|
126 |
brtable_->Rehash(brtable_->GetSize());
|
127 |
if (0)
|
128 |
brtable_->Print();
|
129 |
}
|
130 |
if (acfnumber_ != tws_->GetFileNumber()) {
|
131 |
tws_->StoreObject(brtable_);
|
132 |
acfnumber_ = tws_->GetFileNumber();
|
133 |
}
|
134 |
}
|
135 |
|
136 |
//tree writer end of event actions
|
137 |
tws_->EndEvent(kTRUE);
|
138 |
|
139 |
}
|
140 |
|
141 |
//--------------------------------------------------------------------------------------------------
|
142 |
void FillMitTree::beginJob()
|
143 |
{
|
144 |
// Access the tree and book branches.
|
145 |
|
146 |
if (os_==0) { // only the first FillMitTree object has to deal with this
|
147 |
Service<ObjectService> os;
|
148 |
if (!os.isAvailable()) {
|
149 |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n")
|
150 |
<< "Could not get object service. "
|
151 |
<< "Do you have the ObjectService defined in your config?" << "\n";
|
152 |
return;
|
153 |
}
|
154 |
os_ = &(*os);
|
155 |
brtable_ = new BranchTable;
|
156 |
brtable_->SetName(Names::gkBranchTable);
|
157 |
brtable_->SetOwner();
|
158 |
os->add(brtable_, brtable_->GetName());
|
159 |
}
|
160 |
|
161 |
// loop over the various components and book the branches
|
162 |
for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
|
163 |
edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl;
|
164 |
(*iF)->BookDataBlock(*tws_);
|
165 |
}
|
166 |
|
167 |
// call branch ref for the event tree
|
168 |
if (brtable_ && tws_->GetTree())
|
169 |
tws_->GetTree()->BranchRef();
|
170 |
|
171 |
}
|
172 |
|
173 |
//--------------------------------------------------------------------------------------------------
|
174 |
bool FillMitTree::configure(const edm::ParameterSet &cfg)
|
175 |
{
|
176 |
|
177 |
// Configure TreeWriter
|
178 |
const std::string twsConfigName("TreeWriter");
|
179 |
ParameterSet twsConfig;
|
180 |
if (cfg.existsAs<ParameterSet>(twsConfigName,0))
|
181 |
twsConfig = cfg.getUntrackedParameter<ParameterSet>(twsConfigName);
|
182 |
|
183 |
configureTreeWriter(twsConfig);
|
184 |
|
185 |
// Configure our fillers according to given parameter ("fillers").
|
186 |
|
187 |
std::vector<std::string> pars;
|
188 |
if (cfg.exists("fillers"))
|
189 |
pars=cfg.getUntrackedParameter<vector<string> >("fillers");
|
190 |
else
|
191 |
cfg.getParameterSetNames(pars, false);
|
192 |
|
193 |
// loop over psets
|
194 |
for (unsigned int i = 0; i<pars.size(); ++i) {
|
195 |
|
196 |
const string name(pars.at(i));
|
197 |
|
198 |
string ftype("Filler" + name);
|
199 |
if (cfg.existsAs<ParameterSet>(name,0)) {
|
200 |
ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name));
|
201 |
if (!next.exists("fillerType")) {
|
202 |
edm::LogError("FillMitTree") << "Cannot determine fillerType for pset named "
|
203 |
<< name << std::endl;
|
204 |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
|
205 |
<< "Cannot determine fillerType for pset named "
|
206 |
<< name << std::endl;
|
207 |
}
|
208 |
ftype = next.getUntrackedParameter<string>("fillerType");
|
209 |
}
|
210 |
|
211 |
edm::LogInfo("FillMitTree") << "Attempting to configure '" << ftype
|
212 |
<< "' for '" << name << "'" << std::endl;
|
213 |
|
214 |
if (ftype.compare("FillerMetaInfos")==0) {
|
215 |
FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg, name.c_str(), defactive_);
|
216 |
addActiveFiller(fillerMetaInfos);
|
217 |
continue;
|
218 |
}
|
219 |
|
220 |
if (ftype.compare("FillerMCParticles")==0) {
|
221 |
FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_);
|
222 |
addActiveFiller(fillerMCParticles);
|
223 |
continue;
|
224 |
}
|
225 |
|
226 |
if (ftype.compare("FillerMCEventInfo")==0) {
|
227 |
FillerMCEventInfo *fillerMCEventInfo = new FillerMCEventInfo(cfg, name.c_str(), defactive_);
|
228 |
addActiveFiller(fillerMCEventInfo);
|
229 |
continue;
|
230 |
}
|
231 |
|
232 |
if (ftype.compare("FillerMCVertexes")==0) {
|
233 |
FillerMCVertexes *fillerMCVertexes = new FillerMCVertexes(cfg, name.c_str(), defactive_);
|
234 |
addActiveFiller(fillerMCVertexes);
|
235 |
continue;
|
236 |
}
|
237 |
|
238 |
if (ftype.compare("FillerEvtSelData")==0) {
|
239 |
FillerEvtSelData *fillerEvtSelData = new FillerEvtSelData(cfg, name.c_str(), defactive_);
|
240 |
addActiveFiller(fillerEvtSelData);
|
241 |
continue;
|
242 |
}
|
243 |
|
244 |
if (ftype.compare("FillerBeamSpot")==0) {
|
245 |
FillerBeamSpot *fillerBeamSpot = new FillerBeamSpot(cfg, name.c_str(), defactive_);
|
246 |
addActiveFiller(fillerBeamSpot);
|
247 |
continue;
|
248 |
}
|
249 |
|
250 |
if (ftype.compare("FillerVertexes")==0) {
|
251 |
FillerVertexes *fillerVertexes = new FillerVertexes(cfg, name.c_str(), defactive_);
|
252 |
addActiveFiller(fillerVertexes);
|
253 |
continue;
|
254 |
}
|
255 |
|
256 |
if (ftype.compare("FillerCaloTowers")==0) {
|
257 |
FillerCaloTowers *fillerCaloTowers = new FillerCaloTowers(cfg, name.c_str(), defactive_);
|
258 |
addActiveFiller(fillerCaloTowers);
|
259 |
continue;
|
260 |
}
|
261 |
|
262 |
if (ftype.compare("FillerGenJets")==0) {
|
263 |
FillerGenJets *fillerGenJets = new FillerGenJets(cfg, name.c_str(), defactive_);
|
264 |
addActiveFiller(fillerGenJets);
|
265 |
continue;
|
266 |
}
|
267 |
|
268 |
if (ftype.compare("FillerCaloJets")==0) {
|
269 |
FillerCaloJets *fillerCaloJets = new FillerCaloJets(cfg, name.c_str(), defactive_);
|
270 |
addActiveFiller(fillerCaloJets);
|
271 |
continue;
|
272 |
}
|
273 |
|
274 |
if (ftype.compare("FillerMet")==0) {
|
275 |
FillerMet *fillerMet = new FillerMet(cfg, name.c_str(), defactive_);
|
276 |
addActiveFiller(fillerMet);
|
277 |
continue;
|
278 |
}
|
279 |
|
280 |
if (ftype.compare("FillerGenMet")==0) {
|
281 |
FillerGenMet *fillerGenMet = new FillerGenMet(cfg, name.c_str(), defactive_);
|
282 |
addActiveFiller(fillerGenMet);
|
283 |
continue;
|
284 |
}
|
285 |
|
286 |
if (ftype.compare("FillerCaloMet")==0) {
|
287 |
FillerCaloMet *fillerCaloMet = new FillerCaloMet(cfg, name.c_str(), defactive_);
|
288 |
addActiveFiller(fillerCaloMet);
|
289 |
continue;
|
290 |
}
|
291 |
|
292 |
if (ftype.compare("FillerPFMet")==0) {
|
293 |
FillerPFMet *fillerPFMet = new FillerPFMet(cfg, name.c_str(), defactive_);
|
294 |
addActiveFiller(fillerPFMet);
|
295 |
continue;
|
296 |
}
|
297 |
|
298 |
if (ftype.compare("FillerBasicClusters")==0) {
|
299 |
FillerBasicClusters *fillerBasicClusters =
|
300 |
new FillerBasicClusters(cfg, name.c_str(), defactive_);
|
301 |
addActiveFiller(fillerBasicClusters);
|
302 |
continue;
|
303 |
}
|
304 |
|
305 |
if (ftype.compare("FillerSuperClusters")==0) {
|
306 |
FillerSuperClusters *fillerSuperClusters =
|
307 |
new FillerSuperClusters(cfg, name.c_str(), defactive_);
|
308 |
addActiveFiller(fillerSuperClusters);
|
309 |
continue;
|
310 |
}
|
311 |
|
312 |
if (ftype.compare("FillerPixelHits")==0) {
|
313 |
FillerPixelHits *fillerPixelHits =
|
314 |
new FillerPixelHits(cfg, name.c_str(), defactive_);
|
315 |
addActiveFiller(fillerPixelHits);
|
316 |
continue;
|
317 |
}
|
318 |
|
319 |
if (ftype.compare("FillerStripHits")==0) {
|
320 |
FillerStripHits *fillerStripHits =
|
321 |
new FillerStripHits(cfg, name.c_str(), defactive_);
|
322 |
addActiveFiller(fillerStripHits);
|
323 |
continue;
|
324 |
}
|
325 |
|
326 |
if (ftype.compare("FillerTracks")==0) {
|
327 |
FillerTracks *fillerTracks = new FillerTracks(cfg, name.c_str(), defactive_);
|
328 |
addActiveFiller(fillerTracks);
|
329 |
continue;
|
330 |
}
|
331 |
|
332 |
if (ftype.compare("FillerMuons")==0) {
|
333 |
FillerMuons *fillerMuons = new FillerMuons(cfg, name.c_str(), defactive_);
|
334 |
addActiveFiller(fillerMuons);
|
335 |
continue;
|
336 |
}
|
337 |
|
338 |
if (ftype.compare("FillerElectrons")==0) {
|
339 |
FillerElectrons *fillerElectrons = new FillerElectrons(cfg, name.c_str(), defactive_);
|
340 |
addActiveFiller(fillerElectrons);
|
341 |
continue;
|
342 |
}
|
343 |
|
344 |
if (ftype.compare("FillerConversions")==0) {
|
345 |
FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_);
|
346 |
addActiveFiller(fillerConversions);
|
347 |
continue;
|
348 |
}
|
349 |
|
350 |
if (ftype.compare("FillerPhotons")==0) {
|
351 |
FillerPhotons *fillerPhotons = new FillerPhotons(cfg, name.c_str(), defactive_);
|
352 |
addActiveFiller(fillerPhotons);
|
353 |
continue;
|
354 |
}
|
355 |
|
356 |
if (ftype.compare("FillerStableParts")==0) {
|
357 |
FillerStableParts *fillerStableParts = new FillerStableParts(cfg, name.c_str(), defactive_);
|
358 |
addActiveFiller(fillerStableParts);
|
359 |
continue;
|
360 |
}
|
361 |
|
362 |
if (ftype.compare("FillerDecayParts")==0) {
|
363 |
FillerDecayParts *fillerDecayParts = new FillerDecayParts(cfg, name.c_str(), defactive_);
|
364 |
addActiveFiller(fillerDecayParts);
|
365 |
continue;
|
366 |
}
|
367 |
|
368 |
if (ftype.compare("FillerPFCandidates")==0) {
|
369 |
FillerPFCandidates *fillerPFCands = new FillerPFCandidates(cfg, name.c_str(), defactive_);
|
370 |
addActiveFiller(fillerPFCands);
|
371 |
continue;
|
372 |
}
|
373 |
|
374 |
if (ftype.compare("FillerPFJets")==0) {
|
375 |
FillerPFJets *fillerPFJets = new FillerPFJets(cfg, name.c_str(), defactive_);
|
376 |
addActiveFiller(fillerPFJets);
|
377 |
continue;
|
378 |
}
|
379 |
|
380 |
if (ftype.compare("FillerJPTJets")==0) {
|
381 |
FillerJPTJets *fillerJPTJets = new FillerJPTJets(cfg, name.c_str(), defactive_);
|
382 |
addActiveFiller(fillerJPTJets);
|
383 |
continue;
|
384 |
}
|
385 |
|
386 |
if (ftype.compare("FillerCaloTaus")==0) {
|
387 |
FillerCaloTaus *fillerCaloTaus = new FillerCaloTaus(cfg, name.c_str(), defactive_);
|
388 |
addActiveFiller(fillerCaloTaus);
|
389 |
continue;
|
390 |
}
|
391 |
|
392 |
if (ftype.compare("FillerPFTaus")==0) {
|
393 |
FillerPFTaus *fillerPFTaus = new FillerPFTaus(cfg, name.c_str(), defactive_);
|
394 |
addActiveFiller(fillerPFTaus);
|
395 |
continue;
|
396 |
}
|
397 |
|
398 |
if (ftype.compare("FillerTrackJets")==0) {
|
399 |
FillerTrackJets *fillerTrackJets = new FillerTrackJets(cfg, name.c_str(), defactive_);
|
400 |
addActiveFiller(fillerTrackJets);
|
401 |
continue;
|
402 |
}
|
403 |
|
404 |
edm::LogError("FillMitTree")
|
405 |
<< "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
|
406 |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n")
|
407 |
<< "Unknown fillerType " << ftype << " for pset named " << name << std::endl;
|
408 |
}
|
409 |
|
410 |
return 1;
|
411 |
}
|
412 |
|
413 |
//--------------------------------------------------------------------------------------------------
|
414 |
bool FillMitTree::configureTreeWriter(const edm::ParameterSet &cfg)
|
415 |
{
|
416 |
// Configure tree writer with options from config file.
|
417 |
|
418 |
tws_->SetPrefix(cfg.getUntrackedParameter<string>("fileName","mit-test"));
|
419 |
tws_->SetBaseURL(cfg.getUntrackedParameter<string>("pathName","."));
|
420 |
tws_->SetMaxSize((Long64_t)cfg.getUntrackedParameter<unsigned>("maxSize",1024)*1024*1024);
|
421 |
tws_->SetCompressLevel(cfg.getUntrackedParameter<unsigned>("compLevel",9));
|
422 |
tws_->SetDefaultSL(cfg.getUntrackedParameter<unsigned>("splitLevel",99));
|
423 |
tws_->SetDefaultBrSize(cfg.getUntrackedParameter<unsigned>("brSize",16*1024));
|
424 |
|
425 |
if (OptInt::IsActivated()) {
|
426 |
OptInt::SetZipMode(cfg.getUntrackedParameter<unsigned>("zipMode",99));
|
427 |
OptInt::SetGzipFraction(cfg.getUntrackedParameter<double>("gZipThres",1.0));
|
428 |
OptInt::SetBzipFraction(cfg.getUntrackedParameter<double>("bZipThres",-1.0));
|
429 |
OptInt::SetLzoFraction(cfg.getUntrackedParameter<double>("lzoThres",-1.0));
|
430 |
OptInt::SetLzmaFraction(cfg.getUntrackedParameter<double>("lzmaThres",0.95));
|
431 |
OptInt::SetVerbose(cfg.getUntrackedParameter<unsigned>("optIOVerbose",0));
|
432 |
|
433 |
} else {
|
434 |
|
435 |
if (cfg.exists("zipMode") || cfg.exists("bZipThres") ||
|
436 |
cfg.exists("gZipThres") || cfg.exists("lzoThres") ||
|
437 |
cfg.exists("lzmaThres")) {
|
438 |
edm::LogError("FillMitTree") <<
|
439 |
"OptIO interface not properly pre-loaded, ignoring given settings." << std::endl;
|
440 |
}
|
441 |
}
|
442 |
|
443 |
return 1;
|
444 |
}
|
445 |
|
446 |
//--------------------------------------------------------------------------------------------------
|
447 |
void FillMitTree::endJob()
|
448 |
{
|
449 |
// Delete fillers.
|
450 |
|
451 |
for (std::vector<BaseFiller*>::iterator iF = fillers_.begin(); iF != fillers_.end(); ++iF) {
|
452 |
delete *iF;
|
453 |
}
|
454 |
|
455 |
tws_->Clear();
|
456 |
|
457 |
edm::LogInfo("FillMitTree::endJob") << "Ending Job" << endl;
|
458 |
}
|