ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillMitTree.cc
Revision: 1.58
Committed: Mon Nov 22 16:53:31 2010 UTC (14 years, 5 months ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1
Changes since 1.57: +9 -2 lines
Log Message:
New filler for conversions

File Contents

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