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