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