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