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/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/FillerConversions.h" |
17 |
+ |
#include "MitProd/TreeFiller/interface/FillerDecayParts.h" |
18 |
+ |
#include "MitProd/TreeFiller/interface/FillerElectrons.h" |
19 |
+ |
#include "MitProd/TreeFiller/interface/FillerGenJets.h" |
20 |
+ |
#include "MitProd/TreeFiller/interface/FillerGenMet.h" |
21 |
+ |
#include "MitProd/TreeFiller/interface/FillerMCEventInfo.h" |
22 |
+ |
#include "MitProd/TreeFiller/interface/FillerMCParticles.h" |
23 |
+ |
#include "MitProd/TreeFiller/interface/FillerMet.h" |
24 |
|
#include "MitProd/TreeFiller/interface/FillerMetaInfos.h" |
25 |
< |
#include "MitProd/TreeFiller/interface/FillerGlobalMuons.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 |
< |
//------------------------------------------------------------------------------------------------- |
44 |
< |
FillMitTree::FillMitTree(const edm::ParameterSet &cfg) |
43 |
> |
mithep::ObjectService *mithep::FillMitTree::os_ = 0; |
44 |
> |
|
45 |
> |
//-------------------------------------------------------------------------------------------------- |
46 |
> |
FillMitTree::FillMitTree(const edm::ParameterSet &cfg) : |
47 |
> |
defactive_(cfg.getUntrackedParameter<bool>("defactive",1)), |
48 |
> |
brtable_(0), |
49 |
> |
acfnumber_(-1) |
50 |
|
{ |
51 |
< |
// Constructor: initialize fillers |
51 |
> |
// Constructor. |
52 |
|
|
53 |
|
if (!configure(cfg)) { |
54 |
|
throw edm::Exception(edm::errors::Configuration, "FillMitTree::FillMitTree()\n") |
56 |
|
} |
57 |
|
} |
58 |
|
|
59 |
< |
//------------------------------------------------------------------------------------------------- |
59 |
> |
//-------------------------------------------------------------------------------------------------- |
60 |
|
FillMitTree::~FillMitTree() |
61 |
|
{ |
62 |
< |
// Destructor: nothing to be done here. |
62 |
> |
// Destructor. |
63 |
> |
|
64 |
> |
delete brtable_; |
65 |
|
} |
66 |
|
|
67 |
< |
//------------------------------------------------------------------------------------------------- |
67 |
> |
//-------------------------------------------------------------------------------------------------- |
68 |
> |
bool FillMitTree::addActiveFiller(BaseFiller *bf) |
69 |
> |
{ |
70 |
> |
// Check if filler is active and add it to list of fillers. Otherwise delete it. |
71 |
> |
|
72 |
> |
if (!bf) |
73 |
> |
return 0; |
74 |
> |
|
75 |
> |
if (bf->Active()) { |
76 |
> |
fillers_.push_back(bf); |
77 |
> |
return 1; |
78 |
> |
} |
79 |
> |
|
80 |
> |
delete bf; |
81 |
> |
bf = 0; |
82 |
> |
return 0; |
83 |
> |
} |
84 |
> |
|
85 |
> |
//-------------------------------------------------------------------------------------------------- |
86 |
|
void FillMitTree::analyze(const edm::Event &event, |
87 |
|
const edm::EventSetup &setup) |
88 |
|
{ |
89 |
|
// Access and copy event content. |
90 |
|
|
91 |
< |
// First step: Loop over the data fillers of the various components |
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 |
< |
//------------------------------------------------------------------------------------------------- |
114 |
> |
//-------------------------------------------------------------------------------------------------- |
115 |
|
void FillMitTree::beginJob(const edm::EventSetup &event) |
116 |
|
{ |
117 |
|
// Access the tree and book branches. |
118 |
|
|
119 |
|
Service<TreeService> ts; |
120 |
< |
TreeWriter *tws = ts->get(); |
121 |
< |
if (! tws) { |
120 |
> |
tws_ = ts->get(); |
121 |
> |
if (!tws_) { |
122 |
|
throw edm::Exception(edm::errors::Configuration, "FillMitTree::beginJob()\n") |
123 |
< |
<< "Could not get pointer to tree." << "\n"; |
123 |
> |
<< "Could not get pointer to tree. " |
124 |
> |
<< "Do you have the TreeServie define in your config?" << "\n"; |
125 |
|
return; |
126 |
|
} |
127 |
|
|
128 |
< |
// Loop over the various components and book the branches |
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 |
< |
(*iF)->BookDataBlock(tws); |
145 |
> |
edm::LogInfo("FillMitTree::beginJob") << "Booking for " << (*iF)->Name() << endl; |
146 |
> |
(*iF)->BookDataBlock(*tws_); |
147 |
|
} |
148 |
< |
return; |
148 |
> |
|
149 |
> |
// call branch ref for the event tree |
150 |
> |
tws_->GetTree()->BranchRef(); |
151 |
|
} |
152 |
|
|
153 |
< |
//------------------------------------------------------------------------------------------------- |
153 |
> |
//-------------------------------------------------------------------------------------------------- |
154 |
|
bool FillMitTree::configure(const edm::ParameterSet &cfg) |
155 |
|
{ |
156 |
< |
// Configure our fillers. |
156 |
> |
// Configure our fillers according to given parameter ("fillers"). |
157 |
|
|
158 |
< |
|
159 |
< |
FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg); |
160 |
< |
if (fillerMetaInfos->Active()) |
161 |
< |
fillers_.push_back(fillerMetaInfos); |
162 |
< |
else |
163 |
< |
delete fillerMetaInfos; |
164 |
< |
|
165 |
< |
FillerGlobalMuons *fillerGlobalMuons = new FillerGlobalMuons(cfg); |
166 |
< |
if (fillerGlobalMuons->Active()) |
167 |
< |
fillers_.push_back(fillerGlobalMuons); |
168 |
< |
else |
169 |
< |
delete fillerGlobalMuons; |
158 |
> |
std::vector<std::string> pars; |
159 |
> |
if (cfg.exists("fillers")) |
160 |
> |
pars=cfg.getUntrackedParameter<vector<string> >("fillers"); |
161 |
> |
else |
162 |
> |
cfg.getParameterSetNames(pars, false); |
163 |
> |
|
164 |
> |
// loop over psets |
165 |
> |
for (unsigned int i = 0; i<pars.size(); ++i) { |
166 |
> |
|
167 |
> |
const string name(pars.at(i)); |
168 |
> |
|
169 |
> |
string ftype("Filler" + name); |
170 |
> |
if (cfg.existsAs<ParameterSet>(name,0)) { |
171 |
> |
ParameterSet next(cfg.getUntrackedParameter<ParameterSet>(name)); |
172 |
> |
if (!next.exists("fillerType")) { |
173 |
> |
edm::LogError("FillMitTree") << "Cannot determine fillerType for pset named " |
174 |
> |
<< name << std::endl; |
175 |
> |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n") |
176 |
> |
<< "Cannot determine fillerType for pset named " |
177 |
> |
<< name << std::endl; |
178 |
> |
} |
179 |
> |
ftype = next.getUntrackedParameter<string>("fillerType"); |
180 |
> |
} |
181 |
> |
|
182 |
> |
edm::LogInfo("FillMitTree") << "Attempting to configure '" << ftype |
183 |
> |
<< "' for '" << name << "'" << std::endl; |
184 |
> |
|
185 |
> |
if (ftype.compare("FillerMetaInfos")==0) { |
186 |
> |
FillerMetaInfos *fillerMetaInfos = new FillerMetaInfos(cfg, name.c_str(), defactive_); |
187 |
> |
addActiveFiller(fillerMetaInfos); |
188 |
> |
continue; |
189 |
> |
} |
190 |
> |
|
191 |
> |
if (ftype.compare("FillerMCParticles")==0) { |
192 |
> |
FillerMCParticles *fillerMCParticles = new FillerMCParticles(cfg, name.c_str(), defactive_); |
193 |
> |
addActiveFiller(fillerMCParticles); |
194 |
> |
continue; |
195 |
> |
} |
196 |
> |
|
197 |
> |
if (ftype.compare("FillerMCEventInfo")==0) { |
198 |
> |
FillerMCEventInfo *fillerMCEventInfo = new FillerMCEventInfo(cfg, name.c_str(), defactive_); |
199 |
> |
addActiveFiller(fillerMCEventInfo); |
200 |
> |
continue; |
201 |
> |
} |
202 |
> |
|
203 |
> |
if (ftype.compare("FillerBeamSpot")==0) { |
204 |
> |
FillerBeamSpot *fillerBeamSpot = new FillerBeamSpot(cfg, name.c_str(), defactive_); |
205 |
> |
addActiveFiller(fillerBeamSpot); |
206 |
> |
continue; |
207 |
> |
} |
208 |
> |
|
209 |
> |
if (ftype.compare("FillerVertexes")==0) { |
210 |
> |
FillerVertexes *fillerVertexes = new FillerVertexes(cfg, name.c_str(), defactive_); |
211 |
> |
addActiveFiller(fillerVertexes); |
212 |
> |
continue; |
213 |
> |
} |
214 |
> |
|
215 |
> |
if (ftype.compare("FillerCaloTowers")==0) { |
216 |
> |
FillerCaloTowers *fillerCaloTowers = new FillerCaloTowers(cfg, name.c_str(), defactive_); |
217 |
> |
addActiveFiller(fillerCaloTowers); |
218 |
> |
continue; |
219 |
> |
} |
220 |
> |
|
221 |
> |
if (ftype.compare("FillerGenJets")==0) { |
222 |
> |
FillerGenJets *fillerGenJets = new FillerGenJets(cfg, name.c_str(), defactive_); |
223 |
> |
addActiveFiller(fillerGenJets); |
224 |
> |
continue; |
225 |
> |
} |
226 |
> |
|
227 |
> |
if (ftype.compare("FillerCaloJets")==0) { |
228 |
> |
FillerCaloJets *fillerCaloJets = new FillerCaloJets(cfg, name.c_str(), defactive_); |
229 |
> |
addActiveFiller(fillerCaloJets); |
230 |
> |
continue; |
231 |
> |
} |
232 |
> |
|
233 |
> |
if (ftype.compare("FillerMet")==0) { |
234 |
> |
FillerMet *fillerMet = new FillerMet(cfg, name.c_str(), defactive_); |
235 |
> |
addActiveFiller(fillerMet); |
236 |
> |
continue; |
237 |
> |
} |
238 |
> |
|
239 |
> |
if (ftype.compare("FillerGenMet")==0) { |
240 |
> |
FillerGenMet *fillerGenMet = new FillerGenMet(cfg, name.c_str(), defactive_); |
241 |
> |
addActiveFiller(fillerGenMet); |
242 |
> |
continue; |
243 |
> |
} |
244 |
> |
|
245 |
> |
if (ftype.compare("FillerCaloMet")==0) { |
246 |
> |
FillerCaloMet *fillerCaloMet = new FillerCaloMet(cfg, name.c_str(), defactive_); |
247 |
> |
addActiveFiller(fillerCaloMet); |
248 |
> |
continue; |
249 |
> |
} |
250 |
> |
|
251 |
> |
if (ftype.compare("FillerPFMet")==0) { |
252 |
> |
FillerPFMet *fillerPFMet = new FillerPFMet(cfg, name.c_str(), defactive_); |
253 |
> |
addActiveFiller(fillerPFMet); |
254 |
> |
continue; |
255 |
> |
} |
256 |
> |
|
257 |
> |
if (ftype.compare("FillerBasicClusters")==0) { |
258 |
> |
FillerBasicClusters *fillerBasicClusters = |
259 |
> |
new FillerBasicClusters(cfg, name.c_str(), defactive_); |
260 |
> |
addActiveFiller(fillerBasicClusters); |
261 |
> |
continue; |
262 |
> |
} |
263 |
> |
|
264 |
> |
if (ftype.compare("FillerSuperClusters")==0) { |
265 |
> |
FillerSuperClusters *fillerSuperClusters = |
266 |
> |
new FillerSuperClusters(cfg, name.c_str(), defactive_); |
267 |
> |
addActiveFiller(fillerSuperClusters); |
268 |
> |
continue; |
269 |
> |
} |
270 |
> |
|
271 |
> |
if (ftype.compare("FillerTracks")==0) { |
272 |
> |
FillerTracks *fillerTracks = new FillerTracks(cfg, name.c_str(), defactive_); |
273 |
> |
addActiveFiller(fillerTracks); |
274 |
> |
continue; |
275 |
> |
} |
276 |
> |
|
277 |
> |
if (ftype.compare("FillerMuons")==0) { |
278 |
> |
FillerMuons *fillerMuons = new FillerMuons(cfg, name.c_str(), defactive_); |
279 |
> |
addActiveFiller(fillerMuons); |
280 |
> |
continue; |
281 |
> |
} |
282 |
> |
|
283 |
> |
if (ftype.compare("FillerElectrons")==0) { |
284 |
> |
FillerElectrons *fillerElectrons = new FillerElectrons(cfg, name.c_str(), defactive_); |
285 |
> |
addActiveFiller(fillerElectrons); |
286 |
> |
continue; |
287 |
> |
} |
288 |
> |
|
289 |
> |
if (ftype.compare("FillerConversions")==0) { |
290 |
> |
FillerConversions *fillerConversions = new FillerConversions(cfg, name.c_str(), defactive_); |
291 |
> |
addActiveFiller(fillerConversions); |
292 |
> |
continue; |
293 |
> |
} |
294 |
> |
|
295 |
> |
if (ftype.compare("FillerPhotons")==0) { |
296 |
> |
FillerPhotons *fillerPhotons = new FillerPhotons(cfg, name.c_str(), defactive_); |
297 |
> |
addActiveFiller(fillerPhotons); |
298 |
> |
continue; |
299 |
> |
} |
300 |
> |
|
301 |
> |
if (ftype.compare("FillerStableParts")==0) { |
302 |
> |
FillerStableParts *fillerStableParts = new FillerStableParts(cfg, name.c_str(), defactive_); |
303 |
> |
addActiveFiller(fillerStableParts); |
304 |
> |
continue; |
305 |
> |
} |
306 |
> |
|
307 |
> |
if (ftype.compare("FillerDecayParts")==0) { |
308 |
> |
FillerDecayParts *fillerDecayParts = new FillerDecayParts(cfg, name.c_str(), defactive_); |
309 |
> |
addActiveFiller(fillerDecayParts); |
310 |
> |
continue; |
311 |
> |
} |
312 |
> |
|
313 |
> |
if (ftype.compare("FillerPFCandidates")==0) { |
314 |
> |
FillerPFCandidates *fillerPFCands = new FillerPFCandidates(cfg, name.c_str(), defactive_); |
315 |
> |
addActiveFiller(fillerPFCands); |
316 |
> |
continue; |
317 |
> |
} |
318 |
> |
|
319 |
> |
if (ftype.compare("FillerPFJets")==0) { |
320 |
> |
FillerPFJets *fillerPFJets = new FillerPFJets(cfg, name.c_str(), defactive_); |
321 |
> |
addActiveFiller(fillerPFJets); |
322 |
> |
continue; |
323 |
> |
} |
324 |
> |
|
325 |
> |
if (ftype.compare("FillerCaloTaus")==0) { |
326 |
> |
FillerCaloTaus *fillerCaloTaus = new FillerCaloTaus(cfg, name.c_str(), defactive_); |
327 |
> |
addActiveFiller(fillerCaloTaus); |
328 |
> |
continue; |
329 |
> |
} |
330 |
> |
|
331 |
> |
if (ftype.compare("FillerPFTaus")==0) { |
332 |
> |
FillerPFTaus *fillerPFTaus = new FillerPFTaus(cfg, name.c_str(), defactive_); |
333 |
> |
addActiveFiller(fillerPFTaus); |
334 |
> |
continue; |
335 |
> |
} |
336 |
> |
|
337 |
> |
edm::LogError("FillMitTree") |
338 |
> |
<< "Unknown fillerType " << ftype << " for pset named " << name << std::endl; |
339 |
> |
throw edm::Exception(edm::errors::Configuration, "FillMitTree::configure\n") |
340 |
> |
<< "Unknown fillerType " << ftype << " for pset named " << name << std::endl; |
341 |
> |
} |
342 |
|
|
343 |
|
return 1; |
344 |
|
} |
345 |
|
|
346 |
< |
//------------------------------------------------------------------------------------------------- |
346 |
> |
//-------------------------------------------------------------------------------------------------- |
347 |
|
void FillMitTree::endJob() |
348 |
|
{ |
349 |
|
// Delete fillers. |