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