CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DataMixingHcalDigiWorker.cc
Go to the documentation of this file.
1 // File: DataMixingHcalDigiWorker.cc
2 // Description: see DataMixingHcalDigiWorker.h
3 // Author: Mike Hildreth, University of Notre Dame
4 //
5 //--------------------------------------------
6 
7 #include <map>
17 // calibration headers, for future reference
22 //
23 //
25 
26 
27 using namespace std;
28 
29 namespace edm
30 {
31 
32  // Virtual constructor
33 
34  DataMixingHcalDigiWorker::DataMixingHcalDigiWorker() { }
35 
36  // Constructor
37  DataMixingHcalDigiWorker::DataMixingHcalDigiWorker(const edm::ParameterSet& ps) :
38  label_(ps.getParameter<std::string>("Label"))
39 
40  {
41 
42  // get the subdetector names
43  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
44 
45  // declare the products to produce
46 
47  // Hcal
48 
49  HBHEdigiCollectionSig_ = ps.getParameter<edm::InputTag>("HBHEdigiCollectionSig");
50  HOdigiCollectionSig_ = ps.getParameter<edm::InputTag>("HOdigiCollectionSig");
51  HFdigiCollectionSig_ = ps.getParameter<edm::InputTag>("HFdigiCollectionSig");
52  ZDCdigiCollectionSig_ = ps.getParameter<edm::InputTag>("ZDCdigiCollectionSig");
53 
54  HBHEPileInputTag_ = ps.getParameter<edm::InputTag>("HBHEPileInputTag");
55  HOPileInputTag_ = ps.getParameter<edm::InputTag>("HOPileInputTag");
56  HFPileInputTag_ = ps.getParameter<edm::InputTag>("HFPileInputTag");
57  ZDCPileInputTag_ = ps.getParameter<edm::InputTag>("ZDCPileInputTag");
58 
59  DoZDC_ = false;
60  if(ZDCPileInputTag_.label() != "") DoZDC_ = true;
61 
62  HBHEDigiCollectionDM_ = ps.getParameter<std::string>("HBHEDigiCollectionDM");
63  HODigiCollectionDM_ = ps.getParameter<std::string>("HODigiCollectionDM");
64  HFDigiCollectionDM_ = ps.getParameter<std::string>("HFDigiCollectionDM");
65  ZDCDigiCollectionDM_ = ps.getParameter<std::string>("ZDCDigiCollectionDM");
66 
67 
68  }
69 
70  // Virtual destructor needed.
72  }
73 
75  // Calibration stuff will look like this:
76 
77  // get conditions
78  edm::ESHandle<HcalDbService> conditions;
79  ES.get<HcalDbRecord>().get(conditions);
80 
81 
82 
83  // fill in maps of hits
84 
85  LogInfo("DataMixingHcalDigiWorker")<<"===============> adding MC signals for "<<e.id();
86 
87  // HBHE first
88 
90 
91  const HBHEDigiCollection* HBHEDigis = 0;
92 
93  if( e.getByLabel( HBHEdigiCollectionSig_, pHBHEDigis) ) {
94  HBHEDigis = pHBHEDigis.product(); // get a ptr to the product
95  LogDebug("DataMixingHcalDigiWorker") << "total # HBHE digis: " << HBHEDigis->size();
96  }
97  // else { std::cout << "NO HBHE Digis " << HBHEdigiCollectionSig_.label() << std::endl;}
98 
99 
100  if (HBHEDigis)
101  {
102  // loop over digis, storing them in a map so we can add pileup later
103  for(HBHEDigiCollection::const_iterator it = HBHEDigis->begin();
104  it != HBHEDigis->end(); ++it) {
105 
106  // calibration, for future reference: (same block for all Hcal types)
107 
108  HcalDetId cell = it->id();
109  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
110  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
111  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
112  HcalCoderDb coder (*channelCoder, *shape);
113 
114  CaloSamples tool;
115  coder.adc2fC((*it),tool);
116 
117  // put sample values back into digi?
118 
119 
120  // RecHit MyHit = reco_.reconstruct(*it,coder,calibrations));
121  //... can now fish calibrated information from RecHit
122 
123 
124  HBHEDigiStorage_.insert(HBHEDigiMap::value_type( ( it->id() ), tool ));
125 
126 #ifdef DEBUG
127  // Commented out because this does not compile anymore
128  // LogDebug("DataMixingHcalDigiWorker") << "processed HBHEDigi with rawId: "
129  // << it->id() << "\n"
130  // << " digi energy: " << it->energy();
131 #endif
132 
133  }
134  }
135 
136  // HO next
137 
139 
140  const HODigiCollection* HODigis = 0;
141 
142  if( e.getByLabel( HOdigiCollectionSig_, pHODigis) ){
143  HODigis = pHODigis.product(); // get a ptr to the product
144 #ifdef DEBUG
145  LogDebug("DataMixingHcalDigiWorker") << "total # HO digis: " << HODigis->size();
146 #endif
147  }
148 
149 
150  if (HODigis)
151  {
152  // loop over digis, storing them in a map so we can add pileup later
153  for(HODigiCollection::const_iterator it = HODigis->begin();
154  it != HODigis->end(); ++it) {
155 
156  // calibration, for future reference: (same block for all Hcal types)
157  HcalDetId cell = it->id();
158  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
159  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
160  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
161  HcalCoderDb coder (*channelCoder, *shape);
162 
163  CaloSamples tool;
164  coder.adc2fC((*it),tool);
165 
166  HODigiStorage_.insert(HODigiMap::value_type( ( it->id() ), tool ));
167 
168 #ifdef DEBUG
169  // Commented out because this does not compile anymore
170  // LogDebug("DataMixingHcalDigiWorker") << "processed HODigi with rawId: "
171  // << it->id() << "\n"
172  // << " digi energy: " << it->energy();
173 #endif
174 
175  }
176  }
177 
178  // HF next
179 
181 
182  const HFDigiCollection* HFDigis = 0;
183 
184  if( e.getByLabel( HFdigiCollectionSig_, pHFDigis) ) {
185  HFDigis = pHFDigis.product(); // get a ptr to the product
186 #ifdef DEBUG
187  LogDebug("DataMixingHcalDigiWorker") << "total # HF digis: " << HFDigis->size();
188 #endif
189  }
190 
191 
192  if (HFDigis)
193  {
194  // loop over digis, storing them in a map so we can add pileup later
195  for(HFDigiCollection::const_iterator it = HFDigis->begin();
196  it != HFDigis->end(); ++it) {
197 
198  // calibration, for future reference: (same block for all Hcal types)
199  HcalDetId cell = it->id();
200  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
201  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
202  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
203  HcalCoderDb coder (*channelCoder, *shape);
204 
205  CaloSamples tool;
206  coder.adc2fC((*it),tool);
207 
208  HFDigiStorage_.insert(HFDigiMap::value_type( ( it->id() ), tool ));
209 
210 #ifdef DEBUG
211  // Commented out because this does not compile anymore
212  // LogDebug("DataMixingHcalDigiWorker") << "processed HFDigi with rawId: "
213  // << it->id() << "\n"
214  // << " digi energy: " << it->energy();
215 #endif
216 
217  }
218  }
219 
220  // ZDC next
221 
222  if(DoZDC_){
223 
224  Handle< ZDCDigiCollection > pZDCDigis;
225 
226  const ZDCDigiCollection* ZDCDigis = 0;
227 
228  if( e.getByLabel( ZDCdigiCollectionSig_, pZDCDigis) ) {
229  ZDCDigis = pZDCDigis.product(); // get a ptr to the product
230 #ifdef DEBUG
231  LogDebug("DataMixingHcalDigiWorker") << "total # ZDC digis: " << ZDCDigis->size();
232 #endif
233  }
234 
235 
236  if (ZDCDigis)
237  {
238  // loop over digis, storing them in a map so we can add pileup later
239  for(ZDCDigiCollection::const_iterator it = ZDCDigis->begin();
240  it != ZDCDigis->end(); ++it) {
241 
242  // calibration, for future reference: (same block for all Hcal types)
243  HcalDetId cell = it->id();
244  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
245  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
246  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
247  HcalCoderDb coder (*channelCoder, *shape);
248 
249  CaloSamples tool;
250  coder.adc2fC((*it),tool);
251 
252  ZDCDigiStorage_.insert(ZDCDigiMap::value_type( ( it->id() ), tool ));
253 
254 #ifdef DEBUG
255  // Commented out because this does not compile anymore
256  // LogDebug("DataMixingHcalDigiWorker") << "processed ZDCDigi with rawId: "
257  // << it->id() << "\n"
258  // << " digi energy: " << it->energy();
259 #endif
260 
261  }
262  }
263  }
264 
265  } // end of addHCalSignals
266 
267  void DataMixingHcalDigiWorker::addHcalPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,const edm::EventSetup& ES,
268  ModuleCallingContext const* mcc) {
269 
270  LogDebug("DataMixingHcalDigiWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
271 
272  // get conditions
273  edm::ESHandle<HcalDbService> conditions;
274  ES.get<HcalDbRecord>().get(conditions);
275 
276  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
277 
278  // HBHE first
279 
280 
281  boost::shared_ptr<Wrapper<HBHEDigiCollection> const> HBHEDigisPTR =
282  getProductByTag<HBHEDigiCollection>(*ep, HBHEPileInputTag_, mcc);
283 
284  if(HBHEDigisPTR ) {
285 
286  const HBHEDigiCollection* HBHEDigis = const_cast< HBHEDigiCollection * >(HBHEDigisPTR->product());
287 
288  LogInfo("DataMixingHcalDigiWorker") << "total # HBHE digis: " << HBHEDigis->size();
289 
290  // loop over digis, adding these to the existing maps
291  for(HBHEDigiCollection::const_iterator it = HBHEDigis->begin();
292  it != HBHEDigis->end(); ++it) {
293 
294  // calibration, for future reference: (same block for all Hcal types)
295  HcalDetId cell = it->id();
296  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
297  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
298  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
299  HcalCoderDb coder (*channelCoder, *shape);
300 
301  CaloSamples tool;
302  coder.adc2fC((*it),tool);
303 
304  HBHEDigiStorage_.insert(HBHEDigiMap::value_type( (it->id()), tool ));
305 
306 #ifdef DEBUG
307  // Commented out because this does not compile anymore
308  // LogDebug("DataMixingHcalDigiWorker") << "processed HBHEDigi with rawId: "
309  // << it->id() << "\n"
310  // << " digi energy: " << it->energy();
311 #endif
312  }
313  }
314  // HO Next
315 
316  boost::shared_ptr<Wrapper<HODigiCollection> const> HODigisPTR =
317  getProductByTag<HODigiCollection>(*ep, HOPileInputTag_, mcc);
318 
319  if(HODigisPTR ) {
320 
321  const HODigiCollection* HODigis = const_cast< HODigiCollection * >(HODigisPTR->product());
322 
323  LogDebug("DataMixingHcalDigiWorker") << "total # HO digis: " << HODigis->size();
324 
325  // loop over digis, adding these to the existing maps
326  for(HODigiCollection::const_iterator it = HODigis->begin();
327  it != HODigis->end(); ++it) {
328 
329  // calibration, for future reference: (same block for all Hcal types)
330  HcalDetId cell = it->id();
331  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
332  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
333  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
334  HcalCoderDb coder (*channelCoder, *shape);
335 
336  CaloSamples tool;
337  coder.adc2fC((*it),tool);
338 
339  HODigiStorage_.insert(HODigiMap::value_type( (it->id()), tool ));
340 
341 #ifdef DEBUG
342  // Commented out because this does not compile anymore
343  // LogDebug("DataMixingHcalDigiWorker") << "processed HODigi with rawId: "
344  // << it->id() << "\n"
345  // << " digi energy: " << it->energy();
346 #endif
347  }
348  }
349 
350 
351  // HF Next
352 
353  boost::shared_ptr<Wrapper<HFDigiCollection> const> HFDigisPTR =
354  getProductByTag<HFDigiCollection>(*ep, HFPileInputTag_, mcc);
355 
356  if(HFDigisPTR ) {
357 
358  const HFDigiCollection* HFDigis = const_cast< HFDigiCollection * >(HFDigisPTR->product());
359 
360  LogDebug("DataMixingHcalDigiWorker") << "total # HF digis: " << HFDigis->size();
361 
362  // loop over digis, adding these to the existing maps
363  for(HFDigiCollection::const_iterator it = HFDigis->begin();
364  it != HFDigis->end(); ++it) {
365 
366  // calibration, for future reference: (same block for all Hcal types)
367  HcalDetId cell = it->id();
368  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
369  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
370  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
371  HcalCoderDb coder (*channelCoder, *shape);
372 
373  CaloSamples tool;
374  coder.adc2fC((*it),tool);
375 
376  HFDigiStorage_.insert(HFDigiMap::value_type( (it->id()), tool ));
377 
378 #ifdef DEBUG
379  // Commented out because this does not compile anymore
380  // LogDebug("DataMixingHcalDigiWorker") << "processed HFDigi with rawId: "
381  // << it->id() << "\n"
382  // << " digi energy: " << it->energy();
383 #endif
384  }
385  }
386 
387 
388  // ZDC Next
389 
390  if(DoZDC_) {
391 
392 
393  boost::shared_ptr<Wrapper<ZDCDigiCollection> const> ZDCDigisPTR =
394  getProductByTag<ZDCDigiCollection>(*ep, ZDCPileInputTag_, mcc);
395 
396  if(ZDCDigisPTR ) {
397 
398  const ZDCDigiCollection* ZDCDigis = const_cast< ZDCDigiCollection * >(ZDCDigisPTR->product());
399 
400  LogDebug("DataMixingHcalDigiWorker") << "total # ZDC digis: " << ZDCDigis->size();
401 
402  // loop over digis, adding these to the existing maps
403  for(ZDCDigiCollection::const_iterator it = ZDCDigis->begin();
404  it != ZDCDigis->end(); ++it) {
405 
406  // calibration, for future reference: (same block for all Hcal types)
407  HcalDetId cell = it->id();
408  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
409  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
410  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
411  HcalCoderDb coder (*channelCoder, *shape);
412 
413  CaloSamples tool;
414  coder.adc2fC((*it),tool);
415 
416  ZDCDigiStorage_.insert(ZDCDigiMap::value_type( (it->id()), tool ));
417 
418 #ifdef DEBUG
419  // Commented out because this does not compile anymore
420  // LogDebug("DataMixingHcalDigiWorker") << "processed ZDCDigi with rawId: "
421  // << it->id() << "\n"
422  // << " digi energy: " << it->energy();
423 #endif
424  }
425  }
426  }
427 
428 
429  }
430 
432 
433  // collection of digis to put in the event
434  std::auto_ptr< HBHEDigiCollection > HBHEdigis( new HBHEDigiCollection );
435  std::auto_ptr< HODigiCollection > HOdigis( new HODigiCollection );
436  std::auto_ptr< HFDigiCollection > HFdigis( new HFDigiCollection );
437  std::auto_ptr< ZDCDigiCollection > ZDCdigis( new ZDCDigiCollection );
438 
439  // get conditions
440  edm::ESHandle<HcalDbService> conditions;
441  ES.get<HcalDbRecord>().get(conditions);
442 
443  // loop over the maps we have, re-making individual hits or digis if necessary.
444  DetId formerID = 0;
445  DetId currentID;
446 
447  CaloSamples HB_old;
448 
449  double fC_new;
450  double fC_old;
451  double fC_sum;
452 
453  // HB first...
454 
455  HBHEDigiMap::const_iterator iHBchk;
456 
457  for(HBHEDigiMap::const_iterator iHB = HBHEDigiStorage_.begin();
458  iHB != HBHEDigiStorage_.end(); ++iHB) {
459 
460  currentID = iHB->first;
461 
462  if (currentID == formerID) { // we have to add these digis together
463 
464  //loop over digi samples in each CaloSample
465 
466  unsigned int sizenew = (iHB->second).size();
467  unsigned int sizeold = HB_old.size();
468 
469  bool usenew = false;
470 
471  if(sizenew > sizeold) usenew = true;
472 
473  unsigned int max_samp = std::max(sizenew, sizeold);
474 
475  CaloSamples HB_bigger(currentID,max_samp);
476 
477  // HB_old.setSize(max_samp); --> can't do this...
478 
479  // samples from different events can be of different lengths - sum all
480  // that overlap.
481 
482  for(unsigned int isamp = 0; isamp<max_samp; isamp++) {
483  if(isamp < sizenew) {
484  fC_new = (iHB->second)[isamp]; // should return nominal_fC();
485  }
486  else { fC_new = 0;}
487 
488  if(isamp < sizeold) {
489  fC_old = HB_old[isamp];
490  }
491  else { fC_old = 0;}
492 
493  // add values
494  fC_sum = fC_new + fC_old;
495 
496  //uint fCS = int(fC_sum);
497  //const HcalQIESample fC(fCS);
498  //HB_old.setSample(isamp, fC);
499 
500  if(usenew) {HB_bigger[isamp] = fC_sum; }
501  else { HB_old[isamp] = fC_sum; } // overwrite old sample, adding new info
502 
503  }
504  if(usenew) HB_old = HB_bigger; // save new, larger sized sample in "old" slot
505 
506  }
507  else {
508  if(formerID>0) {
509  // make new digi
510  HBHEdigis->push_back(HBHEDataFrame(formerID));
511 
512  // set up information to convert back
513 
514  HcalDetId cell = HB_old.id();
515  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
516  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
517  HcalCoderDb coder (*channelCoder, *shape);
518 
519  unsigned int sizeold = HB_old.size();
520  for(unsigned int isamp = 0; isamp<sizeold; isamp++) {
521  coder.fC2adc(HB_old,(HBHEdigis->back()), 1 ); // as per simulation, capid=1
522  }
523  }
524  //save pointers for next iteration
525  formerID = currentID;
526  HB_old = iHB->second;
527  //OldUpAdd = HB_old.id();
528  }
529 
530  iHBchk = iHB;
531  if((++iHBchk) == HBHEDigiStorage_.end()) { //make sure not to lose the last one
532 
533  // make new digi
534  HBHEdigis->push_back(HBHEDataFrame(currentID));
535 
536  // set up information to convert back
537 
538  HcalDetId cell = (iHB->second).id();
539  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
540  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
541  HcalCoderDb coder (*channelCoder, *shape);
542 
543  unsigned int sizenew = (iHB->second).size();
544  for(unsigned int isamp = 0; isamp<sizenew; isamp++) {
545  coder.fC2adc(HB_old,(HBHEdigis->back()), 1 ); // as per simulation, capid=1
546  }
547  }
548  }
549 
550 
551  // HO next...
552 
553  // loop over the maps we have, re-making individual hits or digis if necessary.
554  formerID = 0;
555  CaloSamples HO_old;
556 
557  HODigiMap::const_iterator iHOchk;
558 
559  for(HODigiMap::const_iterator iHO = HODigiStorage_.begin();
560  iHO != HODigiStorage_.end(); ++iHO) {
561 
562  currentID = iHO->first;
563 
564  if (currentID == formerID) { // we have to add these digis together
565 
566  //loop over digi samples in each CaloSample
567  unsigned int sizenew = (iHO->second).size();
568  unsigned int sizeold = HO_old.size();
569 
570  unsigned int max_samp = std::max(sizenew, sizeold);
571 
572  CaloSamples HO_bigger(currentID,max_samp);
573 
574  bool usenew = false;
575 
576  if(sizenew > sizeold) usenew = true;
577 
578  // samples from different events can be of different lengths - sum all
579  // that overlap.
580 
581  for(unsigned int isamp = 0; isamp<max_samp; isamp++) {
582  if(isamp < sizenew) {
583  fC_new = (iHO->second)[isamp];
584  }
585  else { fC_new = 0;}
586 
587  if(isamp < sizeold) {
588  fC_old = HO_old[isamp];
589  }
590  else { fC_old = 0;}
591 
592  // add values
593  fC_sum = fC_new + fC_old;
594 
595  if(usenew) {HO_bigger[isamp] = fC_sum; }
596  else { HO_old[isamp] = fC_sum; } // overwrite old sample, adding new info
597 
598  }
599  if(usenew) HO_old = HO_bigger; // save new, larger sized sample in "old" slot
600 
601  }
602  else {
603  if(formerID>0) {
604  // make new digi
605  HOdigis->push_back(HODataFrame(formerID));
606 
607  // set up information to convert back
608 
609  HcalDetId cell = HO_old.id();
610  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
611  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
612  HcalCoderDb coder (*channelCoder, *shape);
613 
614  unsigned int sizeold = HO_old.size();
615  for(unsigned int isamp = 0; isamp<sizeold; isamp++) {
616  coder.fC2adc(HO_old,(HOdigis->back()), 1 ); // as per simulation, capid=1
617  }
618  }
619  //save pointers for next iteration
620  formerID = currentID;
621  HO_old = iHO->second;
622  }
623 
624  iHOchk = iHO;
625  if((++iHOchk) == HODigiStorage_.end()) { //make sure not to lose the last one
626  // make new digi
627  HOdigis->push_back(HODataFrame(currentID));
628 
629  // set up information to convert back
630 
631  HcalDetId cell = (iHO->second).id();
632  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
633  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
634  HcalCoderDb coder (*channelCoder, *shape);
635 
636  unsigned int sizeold = (iHO->second).size();
637  for(unsigned int isamp = 0; isamp<sizeold; isamp++) {
638  coder.fC2adc(HO_old,(HOdigis->back()), 1 ); // as per simulation, capid=1
639  }
640 
641  }
642  }
643 
644  // HF next...
645 
646  // loop over the maps we have, re-making individual hits or digis if necessary.
647  formerID = 0;
648  CaloSamples HF_old;
649 
650  HFDigiMap::const_iterator iHFchk;
651 
652  for(HFDigiMap::const_iterator iHF = HFDigiStorage_.begin();
653  iHF != HFDigiStorage_.end(); ++iHF) {
654 
655  currentID = iHF->first;
656 
657  if (currentID == formerID) { // we have to add these digis together
658 
659  //loop over digi samples in each CaloSample
660  unsigned int sizenew = (iHF->second).size();
661  unsigned int sizeold = HF_old.size();
662 
663  unsigned int max_samp = std::max(sizenew, sizeold);
664 
665  CaloSamples HF_bigger(currentID,max_samp);
666 
667  bool usenew = false;
668 
669  if(sizenew > sizeold) usenew = true;
670 
671  // samples from different events can be of different lengths - sum all
672  // that overlap.
673 
674  for(unsigned int isamp = 0; isamp<max_samp; isamp++) {
675  if(isamp < sizenew) {
676  fC_new = (iHF->second)[isamp];
677  }
678  else { fC_new = 0;}
679 
680  if(isamp < sizeold) {
681  fC_old = HF_old[isamp];
682  }
683  else { fC_old = 0;}
684 
685  // add values
686  fC_sum = fC_new + fC_old;
687 
688  if(usenew) {HF_bigger[isamp] = fC_sum; }
689  else { HF_old[isamp] = fC_sum; } // overwrite old sample, adding new info
690 
691  }
692  if(usenew) HF_old = HF_bigger; // save new, larger sized sample in "old" slot
693 
694  }
695  else {
696  if(formerID>0) {
697  // make new digi
698  HFdigis->push_back(HFDataFrame(formerID));
699 
700  // set up information to convert back
701 
702  HcalDetId cell = HF_old.id();
703  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
704  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
705  HcalCoderDb coder (*channelCoder, *shape);
706 
707  unsigned int sizeold = HF_old.size();
708  for(unsigned int isamp = 0; isamp<sizeold; isamp++) {
709  coder.fC2adc(HF_old,(HFdigis->back()), 1 ); // as per simulation, capid=1
710  }
711  }
712  //save pointers for next iteration
713  formerID = currentID;
714  HF_old = iHF->second;
715  }
716 
717  iHFchk = iHF;
718  if((++iHFchk) == HFDigiStorage_.end()) { //make sure not to lose the last one
719  // make new digi
720  HFdigis->push_back(HFDataFrame(currentID));
721 
722  // set up information to convert back
723 
724  HcalDetId cell = (iHF->second).id();
725  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
726  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
727  HcalCoderDb coder (*channelCoder, *shape);
728 
729  unsigned int sizeold = (iHF->second).size();
730  for(unsigned int isamp = 0; isamp<sizeold; isamp++) {
731  coder.fC2adc(HF_old,(HFdigis->back()), 1 ); // as per simulation, capid=1
732  }
733 
734  }
735  }
736 
737 
738  // ZDC next...
739 
740  // loop over the maps we have, re-making individual hits or digis if necessary.
741  formerID = 0;
742  CaloSamples ZDC_old;
743 
744  ZDCDigiMap::const_iterator iZDCchk;
745 
746  for(ZDCDigiMap::const_iterator iZDC = ZDCDigiStorage_.begin();
747  iZDC != ZDCDigiStorage_.end(); ++iZDC) {
748 
749  currentID = iZDC->first;
750 
751  if (currentID == formerID) { // we have to add these digis together
752 
753  //loop over digi samples in each CaloSample
754  unsigned int sizenew = (iZDC->second).size();
755  unsigned int sizeold = ZDC_old.size();
756 
757  unsigned int max_samp = std::max(sizenew, sizeold);
758 
759  CaloSamples ZDC_bigger(currentID,max_samp);
760 
761  bool usenew = false;
762 
763  if(sizenew > sizeold) usenew = true;
764 
765  // samples from different events can be of different lengths - sum all
766  // that overlap.
767 
768  for(unsigned int isamp = 0; isamp<max_samp; isamp++) {
769  if(isamp < sizenew) {
770  fC_new = (iZDC->second)[isamp];
771  }
772  else { fC_new = 0;}
773 
774  if(isamp < sizeold) {
775  fC_old = ZDC_old[isamp];
776  }
777  else { fC_old = 0;}
778 
779  // add values
780  fC_sum = fC_new + fC_old;
781 
782  if(usenew) {ZDC_bigger[isamp] = fC_sum; }
783  else { ZDC_old[isamp] = fC_sum; } // overwrite old sample, adding new info
784 
785  }
786  if(usenew) ZDC_old = ZDC_bigger; // save new, larger sized sample in "old" slot
787 
788  }
789  else {
790  if(formerID>0) {
791  // make new digi
792  ZDCdigis->push_back(ZDCDataFrame(formerID));
793 
794  // set up information to convert back
795 
796  HcalDetId cell = ZDC_old.id();
797  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
798  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
799  HcalCoderDb coder (*channelCoder, *shape);
800 
801  unsigned int sizeold = ZDC_old.size();
802  for(unsigned int isamp = 0; isamp<sizeold; isamp++) {
803  coder.fC2adc(ZDC_old,(ZDCdigis->back()), 1 ); // as per simulation, capid=1
804  }
805  }
806  //save pointers for next iteration
807  formerID = currentID;
808  ZDC_old = iZDC->second;
809  }
810 
811  iZDCchk = iZDC;
812  if((++iZDCchk) == ZDCDigiStorage_.end()) { //make sure not to lose the last one
813  // make new digi
814  ZDCdigis->push_back(ZDCDataFrame(currentID));
815 
816  // set up information to convert back
817 
818  HcalDetId cell = (iZDC->second).id();
819  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
820  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
821  HcalCoderDb coder (*channelCoder, *shape);
822 
823  unsigned int sizeold = (iZDC->second).size();
824  for(unsigned int isamp = 0; isamp<sizeold; isamp++) {
825  coder.fC2adc(ZDC_old,(ZDCdigis->back()), 1 ); // as per simulation, capid=1
826  }
827 
828  }
829  }
830 
831 
832 
833  //done merging
834 
835  // put the collection of recunstructed hits in the event
836  LogInfo("DataMixingHcalDigiWorker") << "total # HBHE Merged digis: " << HBHEdigis->size() ;
837  LogInfo("DataMixingHcalDigiWorker") << "total # HO Merged digis: " << HOdigis->size() ;
838  LogInfo("DataMixingHcalDigiWorker") << "total # HF Merged digis: " << HFdigis->size() ;
839  LogInfo("DataMixingHcalDigiWorker") << "total # ZDC Merged digis: " << ZDCdigis->size() ;
840 
841 
842  // make empty collections for now:
843  std::auto_ptr<HBHEUpgradeDigiCollection> hbheupgradeResult(new HBHEUpgradeDigiCollection());
844  std::auto_ptr<HFUpgradeDigiCollection> hfupgradeResult(new HFUpgradeDigiCollection());
845 
846 
847  e.put( HBHEdigis, HBHEDigiCollectionDM_ );
848  e.put( HOdigis, HODigiCollectionDM_ );
849  e.put( HFdigis, HFDigiCollectionDM_ );
850  e.put( ZDCdigis, ZDCDigiCollectionDM_ );
851  e.put( hbheupgradeResult, "HBHEUpgradeDigiCollection" );
852  e.put( hfupgradeResult, "HFUpgradeDigiCollection" );
853 
854  // clear local storage after this event
855  HBHEDigiStorage_.clear();
856  HODigiStorage_.clear();
857  HFDigiStorage_.clear();
858  ZDCDigiStorage_.clear();
859 
860  }
861 
862 } //edm
#define LogDebug(id)
T getParameter(std::string const &) const
EventID const & id() const
std::vector< HBHEDataFrame >::const_iterator const_iterator
void addHcalPileups(const int bcr, const edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES, ModuleCallingContext const *)
virtual void fC2adc(const CaloSamples &clf, HBHEDataFrame &df, int fCapIdOffset) const
Definition: HcalCoderDb.cc:51
const T & max(const T &a, const T &b)
void putHcal(edm::Event &e, const edm::EventSetup &ES)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const
Definition: HcalCoderDb.cc:44
edm::SortedCollection< HcalUpgradeDataFrame > HFUpgradeDigiCollection
Container::value_type value_type
edm::SortedCollection< HcalUpgradeDataFrame > HBHEUpgradeDigiCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:390
const_iterator end() const
Definition: DetId.h:18
int size() const
get the size
Definition: CaloSamples.h:24
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:81
std::string const & label() const
Definition: InputTag.h:42
edm::EventID id() const
Definition: EventBase.h:56
size_type size() const
DetId id() const
get the (generic) id
Definition: CaloSamples.h:21
void addHcalSignals(const edm::Event &e, const edm::EventSetup &ES)
tuple size
Write out results.
const_iterator begin() const