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