CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingHcalWorker.cc
Go to the documentation of this file.
1 // File: DataMixingHcalWorker.cc
2 // Description: see DataMixingHcalWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
8 #include <memory>
16 //
17 //
18 #include "DataMixingHcalWorker.h"
19 
20 
21 using namespace std;
22 
23 namespace edm
24 {
25 
26  // Virtual constructor
27 
28  DataMixingHcalWorker::DataMixingHcalWorker() { }
29 
30  // Constructor
31  DataMixingHcalWorker::DataMixingHcalWorker(const edm::ParameterSet& ps, edm::ConsumesCollector && iC) :
32  label_(ps.getParameter<std::string>("Label"))
33 
34  {
35 
36  // get the subdetector names
37  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
38 
39  // declare the products to produce
40 
41  // Hcal
42 
43  HBHErechitCollectionSig_ = ps.getParameter<edm::InputTag>("HBHEProducerSig");
44  HOrechitCollectionSig_ = ps.getParameter<edm::InputTag>("HOProducerSig");
45  HFrechitCollectionSig_ = ps.getParameter<edm::InputTag>("HFProducerSig");
46  ZDCrechitCollectionSig_ = ps.getParameter<edm::InputTag>("ZDCrechitCollectionSig");
47 
48  HBHEPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("HBHEPileRecHitInputTag");
49  HOPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("HOPileRecHitInputTag");
50  HFPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("HFPileRecHitInputTag");
51  ZDCPileRecHitInputTag_ = ps.getParameter<edm::InputTag>("ZDCPileRecHitInputTag");
52 
53  HBHERecHitCollectionDM_ = ps.getParameter<std::string>("HBHERecHitCollectionDM");
54  HORecHitCollectionDM_ = ps.getParameter<std::string>("HORecHitCollectionDM");
55  HFRecHitCollectionDM_ = ps.getParameter<std::string>("HFRecHitCollectionDM");
56  ZDCRecHitCollectionDM_ = ps.getParameter<std::string>("ZDCRecHitCollectionDM");
57 
61 
65 
66 
69 
70  }
71 
72  // Virtual destructor needed.
74  }
75 
77  // fill in maps of hits
78 
79  LogInfo("DataMixingHcalWorker")<<"===============> adding MC signals for "<<e.id();
80 
81  // HBHE first
82 
83  Handle< HBHERecHitCollection > pHBHERecHits;
84 
86 
87  if( e.getByToken( HBHERecHitToken_, pHBHERecHits) ) {
88  HBHERecHits = pHBHERecHits.product(); // get a ptr to the product
89  LogDebug("DataMixingHcalWorker") << "total # HBHE rechits: " << HBHERecHits->size();
90  }
91 
92 
93  if (HBHERecHits)
94  {
95  // loop over rechits, storing them in a map so we can add pileup later
96  for(HBHERecHitCollection::const_iterator it = HBHERecHits->begin();
97  it != HBHERecHits->end(); ++it) {
98 
99  HBHERecHitStorage_.insert(HBHERecHitMap::value_type( ( it->id() ), *it ));
100 
101 #ifdef DEBUG
102  LogDebug("DataMixingHcalWorker") << "processed HBHERecHit with rawId: "
103  << it->id() << "\n"
104  << " rechit energy: " << it->energy();
105 #endif
106 
107  }
108  }
109 
110  // HO next
111 
112  Handle< HORecHitCollection > pHORecHits;
113 
114  const HORecHitCollection* HORecHits = 0;
115 
116  if( e.getByToken( HORecHitToken_, pHORecHits) ){
117  HORecHits = pHORecHits.product(); // get a ptr to the product
118 #ifdef DEBUG
119  LogDebug("DataMixingHcalWorker") << "total # HO rechits: " << HORecHits->size();
120 #endif
121  }
122 
123 
124  if (HORecHits)
125  {
126  // loop over rechits, storing them in a map so we can add pileup later
127  for(HORecHitCollection::const_iterator it = HORecHits->begin();
128  it != HORecHits->end(); ++it) {
129 
130  HORecHitStorage_.insert(HORecHitMap::value_type( ( it->id() ), *it ));
131 
132 #ifdef DEBUG
133  LogDebug("DataMixingHcalWorker") << "processed HORecHit with rawId: "
134  << it->id() << "\n"
135  << " rechit energy: " << it->energy();
136 #endif
137 
138  }
139  }
140 
141  // HF next
142 
143  Handle< HFRecHitCollection > pHFRecHits;
144 
145  const HFRecHitCollection* HFRecHits = 0;
146 
147  if( e.getByToken( HFRecHitToken_, pHFRecHits) ) {
148  HFRecHits = pHFRecHits.product(); // get a ptr to the product
149 #ifdef DEBUG
150  LogDebug("DataMixingHcalWorker") << "total # HF rechits: " << HFRecHits->size();
151 #endif
152  }
153 
154 
155  if (HFRecHits)
156  {
157  // loop over rechits, storing them in a map so we can add pileup later
158  for(HFRecHitCollection::const_iterator it = HFRecHits->begin();
159  it != HFRecHits->end(); ++it) {
160 
161  HFRecHitStorage_.insert(HFRecHitMap::value_type( ( it->id() ), *it ));
162 
163 #ifdef DEBUG
164  LogDebug("DataMixingHcalWorker") << "processed HFRecHit with rawId: "
165  << it->id() << "\n"
166  << " rechit energy: " << it->energy();
167 #endif
168 
169  }
170  }
171 
172  // ZDC next
173 
174  Handle< ZDCRecHitCollection > pZDCRecHits;
175 
176  const ZDCRecHitCollection* ZDCRecHits = 0;
177 
178  if( e.getByToken( ZDCRecHitToken_, pZDCRecHits) ) {
179  ZDCRecHits = pZDCRecHits.product(); // get a ptr to the product
180 #ifdef DEBUG
181  LogDebug("DataMixingHcalWorker") << "total # ZDC rechits: " << ZDCRecHits->size();
182 #endif
183  }
184 
185 
186  if (ZDCRecHits)
187  {
188  // loop over rechits, storing them in a map so we can add pileup later
189  for(ZDCRecHitCollection::const_iterator it = ZDCRecHits->begin();
190  it != ZDCRecHits->end(); ++it) {
191 
192  ZDCRecHitStorage_.insert(ZDCRecHitMap::value_type( ( it->id() ), *it ));
193 
194 #ifdef DEBUG
195  LogDebug("DataMixingHcalWorker") << "processed ZDCRecHit with rawId: "
196  << it->id() << "\n"
197  << " rechit energy: " << it->energy();
198 #endif
199 
200  }
201  }
202 
203  } // end of addEMSignals
204 
205  void DataMixingHcalWorker::addHcalPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,
206  ModuleCallingContext const* mcc) {
207 
208  LogDebug("DataMixingHcalWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
209 
210  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
211 
212  // HBHE first
213 
214  std::shared_ptr<Wrapper<HBHERecHitCollection> const> HBHERecHitsPTR =
215  getProductByTag<HBHERecHitCollection>(*ep, HBHEPileRecHitInputTag_, mcc);
216 
217  if(HBHERecHitsPTR ) {
218 
219  const HBHERecHitCollection* HBHERecHits = const_cast< HBHERecHitCollection * >(HBHERecHitsPTR->product());
220 
221  LogDebug("DataMixingEMWorker") << "total # HBHE rechits: " << HBHERecHits->size();
222 
223  // loop over rechits, adding these to the existing maps
224  for(HBHERecHitCollection::const_iterator it = HBHERecHits->begin();
225  it != HBHERecHits->end(); ++it) {
226 
227  HBHERecHitStorage_.insert(HBHERecHitMap::value_type( (it->id()), *it ));
228 
229 #ifdef DEBUG
230  LogDebug("DataMixingEMWorker") << "processed HBHERecHit with rawId: "
231  << it->id().rawId() << "\n"
232  << " rechit energy: " << it->energy();
233 #endif
234  }
235  }
236 
237  // HO Next
238 
239  std::shared_ptr<Wrapper<HORecHitCollection> const> HORecHitsPTR =
240  getProductByTag<HORecHitCollection>(*ep, HOPileRecHitInputTag_, mcc);
241 
242  if(HORecHitsPTR ) {
243 
244  const HORecHitCollection* HORecHits = const_cast< HORecHitCollection * >(HORecHitsPTR->product());
245 
246  LogDebug("DataMixingEMWorker") << "total # HO rechits: " << HORecHits->size();
247 
248  // loop over rechits, adding these to the existing maps
249  for(HORecHitCollection::const_iterator it = HORecHits->begin();
250  it != HORecHits->end(); ++it) {
251 
252  HORecHitStorage_.insert(HORecHitMap::value_type( (it->id()), *it ));
253 
254 #ifdef DEBUG
255  LogDebug("DataMixingEMWorker") << "processed HORecHit with rawId: "
256  << it->id().rawId() << "\n"
257  << " rechit energy: " << it->energy();
258 #endif
259  }
260  }
261 
262  // HF Next
263 
264  std::shared_ptr<Wrapper<HFRecHitCollection> const> HFRecHitsPTR =
265  getProductByTag<HFRecHitCollection>(*ep, HFPileRecHitInputTag_, mcc);
266 
267  if(HFRecHitsPTR ) {
268 
269  const HFRecHitCollection* HFRecHits = const_cast< HFRecHitCollection * >(HFRecHitsPTR->product());
270 
271  LogDebug("DataMixingEMWorker") << "total # HF rechits: " << HFRecHits->size();
272 
273  // loop over rechits, adding these to the existing maps
274  for(HFRecHitCollection::const_iterator it = HFRecHits->begin();
275  it != HFRecHits->end(); ++it) {
276 
277  HFRecHitStorage_.insert(HFRecHitMap::value_type( (it->id()), *it ));
278 
279 #ifdef DEBUG
280  LogDebug("DataMixingEMWorker") << "processed HFRecHit with rawId: "
281  << it->id().rawId() << "\n"
282  << " rechit energy: " << it->energy();
283 #endif
284  }
285  }
286 
287  // ZDC Next
288 
289  std::shared_ptr<Wrapper<ZDCRecHitCollection> const> ZDCRecHitsPTR =
290  getProductByTag<ZDCRecHitCollection>(*ep, ZDCPileRecHitInputTag_, mcc);
291 
292  if(ZDCRecHitsPTR ) {
293 
294  const ZDCRecHitCollection* ZDCRecHits = const_cast< ZDCRecHitCollection * >(ZDCRecHitsPTR->product());
295 
296  LogDebug("DataMixingEMWorker") << "total # ZDC rechits: " << ZDCRecHits->size();
297 
298  // loop over rechits, adding these to the existing maps
299  for(ZDCRecHitCollection::const_iterator it = ZDCRecHits->begin();
300  it != ZDCRecHits->end(); ++it) {
301 
302  ZDCRecHitStorage_.insert(ZDCRecHitMap::value_type( (it->id()), *it ));
303 
304 #ifdef DEBUG
305  LogDebug("DataMixingEMWorker") << "processed ZDCRecHit with rawId: "
306  << it->id().rawId() << "\n"
307  << " rechit energy: " << it->energy();
308 #endif
309  }
310  }
311 
312 
313  }
314 
316 
317  // collection of rechits to put in the event
318  std::auto_ptr< HBHERecHitCollection > HBHErechits( new HBHERecHitCollection );
319  std::auto_ptr< HORecHitCollection > HOrechits( new HORecHitCollection );
320  std::auto_ptr< HFRecHitCollection > HFrechits( new HFRecHitCollection );
321  std::auto_ptr< ZDCRecHitCollection > ZDCrechits( new ZDCRecHitCollection );
322 
323  // loop over the maps we have, re-making individual hits or rechits if necessary.
324  DetId formerID = 0;
325  DetId currentID;
326  float ESum = 0.;
327  float HBTime = 0.;
328 
329  // HB first...
330 
331  HBHERecHitMap::const_iterator iHBchk;
332 
333  for(HBHERecHitMap::const_iterator iHB = HBHERecHitStorage_.begin();
334  iHB != HBHERecHitStorage_.end(); ++iHB) {
335 
336  currentID = iHB->first;
337 
338  if (currentID == formerID) { // we have to add these rechits together
339 
340  ESum+=(iHB->second).energy();
341 
342  }
343  else {
344  if(formerID>0) {
345  // cutoff for ESum?
346  HBHERecHit aHit(formerID, ESum, HBTime);
347  HBHErechits->push_back( aHit );
348  }
349  //save pointers for next iteration
350  formerID = currentID;
351  ESum = (iHB->second).energy();
352  HBTime = (iHB->second).time(); // take time of first hit in sequence - is this ok?
353  }
354 
355  iHBchk = iHB;
356  if((++iHBchk) == HBHERecHitStorage_.end()) { //make sure not to lose the last one
357  HBHERecHit aHit(formerID, ESum, HBTime);
358  HBHErechits->push_back( aHit );
359  }
360  }
361 
362  // HO next...
363 
364  // loop over the maps we have, re-making individual hits or rechits if necessary.
365  formerID = 0;
366  ESum = 0.;
367  float HOTime = 0.;
368 
369  HORecHitMap::const_iterator iHOchk;
370 
371  for(HORecHitMap::const_iterator iHO = HORecHitStorage_.begin();
372  iHO != HORecHitStorage_.end(); ++iHO) {
373 
374  currentID = iHO->first;
375 
376  if (currentID == formerID) { // we have to add these rechits together
377 
378  ESum+=(iHO->second).energy();
379 
380  }
381  else {
382  if(formerID>0) {
383  // cutoff for ESum?
384  HORecHit aHit(formerID, ESum, HOTime);
385  HOrechits->push_back( aHit );
386  }
387  //save pointers for next iteration
388  formerID = currentID;
389  ESum = (iHO->second).energy();
390  HOTime = (iHO->second).time(); // take time of first hit in sequence - is this ok?
391  }
392 
393  iHOchk = iHO;
394  if((++iHOchk) == HORecHitStorage_.end()) { //make sure not to lose the last one
395  HORecHit aHit(formerID, ESum, HOTime);
396  HOrechits->push_back( aHit );
397  }
398  }
399 
400 
401  // HF next...
402 
403  // loop over the maps we have, re-making individual hits or rechits if necessary.
404  formerID = 0;
405  ESum = 0.;
406  float HFTime = 0.;
407  HFRecHit HFOldHit;
408 
409  HFRecHitMap::const_iterator iHFchk;
410 
411  for(HFRecHitMap::const_iterator iHF = HFRecHitStorage_.begin();
412  iHF != HFRecHitStorage_.end(); ++iHF) {
413 
414  currentID = iHF->first;
415 
416  if (currentID == formerID) { // we have to add these rechits together
417 
418  ESum+=(iHF->second).energy();
419 
420  }
421  else {
422  if(formerID>0) {
423  // cutoff for ESum?
424  HFRecHit aHit(formerID, ESum, HFTime);
425  HFrechits->push_back( aHit );
426  }
427  //save pointers for next iteration
428  formerID = currentID;
429  ESum = (iHF->second).energy();
430  HFTime = (iHF->second).time(); // take time of first hit in sequence - is this ok?
431  }
432 
433  iHFchk = iHF;
434  if((++iHFchk) == HFRecHitStorage_.end()) { //make sure not to lose the last one
435  HFRecHit aHit(formerID, ESum, HBTime);
436  HFrechits->push_back( aHit );
437  }
438  }
439 
440  // ZDC next...
441 
442  // loop over the maps we have, re-making individual hits or rechits if necessary.
443  formerID = 0;
444  ESum = 0.;
445  float ZDCTime = 0.;
446  float lowGainEnergy = 0;
447  ZDCRecHit ZOldHit;
448 
449  ZDCRecHitMap::const_iterator iZDCchk;
450 
451  for(ZDCRecHitMap::const_iterator iZDC = ZDCRecHitStorage_.begin();
452  iZDC != ZDCRecHitStorage_.end(); ++iZDC) {
453 
454  currentID = iZDC->first;
455 
456  if (currentID == formerID) { // we have to add these rechits together
457 
458  ESum+=(iZDC->second).energy();
459 
460  }
461  else {
462  if(formerID>0) {
463  // cutoff for ESum?
464  ZDCRecHit aHit(formerID, ESum, ZDCTime, lowGainEnergy);
465  ZDCrechits->push_back( aHit );
466  }
467  //save pointers for next iteration
468  formerID = currentID;
469  ESum = (iZDC->second).energy();
470  lowGainEnergy = (iZDC->second).lowGainEnergy();
471  ZDCTime = (iZDC->second).time(); // take time of first hit in sequence - is this ok?
472  }
473 
474  iZDCchk = iZDC;
475  if((++iZDCchk) == ZDCRecHitStorage_.end()) { //make sure not to lose the last one
476  ZDCRecHit aHit(formerID, ESum, HBTime, lowGainEnergy);
477  ZDCrechits->push_back( aHit );
478  }
479  }
480 
481  //done merging
482 
483  // put the collection of recunstructed hits in the event
484  LogInfo("DataMixingHcalWorker") << "total # HBHE Merged rechits: " << HBHErechits->size() ;
485  LogInfo("DataMixingHcalWorker") << "total # HO Merged rechits: " << HOrechits->size() ;
486  LogInfo("DataMixingHcalWorker") << "total # HF Merged rechits: " << HFrechits->size() ;
487  LogInfo("DataMixingHcalWorker") << "total # ZDC Merged rechits: " << ZDCrechits->size() ;
488 
489  e.put( HBHErechits, HBHERecHitCollectionDM_ );
490  e.put( HOrechits, HORecHitCollectionDM_ );
491  e.put( HFrechits, HFRecHitCollectionDM_ );
492  e.put( ZDCrechits, ZDCRecHitCollectionDM_ );
493 
494  // clear local storage after this event
495  HBHERecHitStorage_.clear();
496  HORecHitStorage_.clear();
497  HFRecHitStorage_.clear();
498  ZDCRecHitStorage_.clear();
499 
500  }
501 
502 } //edm
#define LogDebug(id)
T getParameter(std::string const &) const
void addHcalSignals(const edm::Event &e)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
void addHcalPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, ModuleCallingContext const *)
EventID const & id() const
std::vector< HBHERecHit >::const_iterator const_iterator
edm::EDGetTokenT< ZDCRecHitCollection > ZDCRecHitToken_
edm::EDGetTokenT< ZDCRecHitCollection > ZDCRecHitPToken_
edm::EDGetTokenT< HORecHitCollection > HORecHitToken_
edm::EDGetTokenT< HBHERecHitCollection > HBHERecHitPToken_
edm::EDGetTokenT< HFRecHitCollection > HFRecHitToken_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:115
Container::value_type value_type
const_iterator end() const
Definition: DetId.h:18
T const * product() const
Definition: Handle.h:81
edm::EDGetTokenT< HBHERecHitCollection > HBHERecHitToken_
edm::EDGetTokenT< HFRecHitCollection > HFRecHitPToken_
edm::EventID id() const
Definition: EventBase.h:60
size_type size() const
edm::EDGetTokenT< HORecHitCollection > HORecHitPToken_
const_iterator begin() const