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  // fill in maps of hits
83 
84  LogInfo("DataMixingHcalDigiWorker")<<"===============> adding MC signals for "<<e.id();
85 
86  // HBHE first
87 
89 
90  const HBHEDigiCollection* HBHEDigis = 0;
91 
92  if( e.getByLabel( HBHEdigiCollectionSig_, pHBHEDigis) ) {
93  HBHEDigis = pHBHEDigis.product(); // get a ptr to the product
94  LogDebug("DataMixingHcalDigiWorker") << "total # HBHE digis: " << HBHEDigis->size();
95  }
96  // else { std::cout << "NO HBHE Digis " << HBHEdigiCollectionSig_.label() << std::endl;}
97 
98 
99  if (HBHEDigis)
100  {
101  // loop over digis, storing them in a map so we can add pileup later
102  for(HBHEDigiCollection::const_iterator it = HBHEDigis->begin();
103  it != HBHEDigis->end(); ++it) {
104 
105  // calibration, for future reference: (same block for all Hcal types)
106 
107  HcalDetId cell = it->id();
108  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
109  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
110  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
111  HcalCoderDb coder (*channelCoder, *shape);
112 
113  CaloSamples tool;
114  coder.adc2fC((*it),tool);
115 
116  // put sample values back into digi?
117 
118 
119  // RecHit MyHit = reco_.reconstruct(*it,coder,calibrations));
120  //... can now fish calibrated information from RecHit
121 
122 
123  HBHEDigiStorage_.insert(HBHEDigiMap::value_type( ( it->id() ), tool ));
124 
125 #ifdef DEBUG
126  // Commented out because this does not compile anymore
127  // LogDebug("DataMixingHcalDigiWorker") << "processed HBHEDigi with rawId: "
128  // << it->id() << "\n"
129  // << " digi energy: " << it->energy();
130 #endif
131 
132  }
133  }
134 
135  // HO next
136 
138 
139  const HODigiCollection* HODigis = 0;
140 
141  if( e.getByLabel( HOdigiCollectionSig_, pHODigis) ){
142  HODigis = pHODigis.product(); // get a ptr to the product
143 #ifdef DEBUG
144  LogDebug("DataMixingHcalDigiWorker") << "total # HO digis: " << HODigis->size();
145 #endif
146  }
147 
148 
149  if (HODigis)
150  {
151  // loop over digis, storing them in a map so we can add pileup later
152  for(HODigiCollection::const_iterator it = HODigis->begin();
153  it != HODigis->end(); ++it) {
154 
155  // calibration, for future reference: (same block for all Hcal types)
156  HcalDetId cell = it->id();
157  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
158  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
159  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
160  HcalCoderDb coder (*channelCoder, *shape);
161 
162  CaloSamples tool;
163  coder.adc2fC((*it),tool);
164 
165  HODigiStorage_.insert(HODigiMap::value_type( ( it->id() ), tool ));
166 
167 #ifdef DEBUG
168  // Commented out because this does not compile anymore
169  // LogDebug("DataMixingHcalDigiWorker") << "processed HODigi with rawId: "
170  // << it->id() << "\n"
171  // << " digi energy: " << it->energy();
172 #endif
173 
174  }
175  }
176 
177  // HF next
178 
180 
181  const HFDigiCollection* HFDigis = 0;
182 
183  if( e.getByLabel( HFdigiCollectionSig_, pHFDigis) ) {
184  HFDigis = pHFDigis.product(); // get a ptr to the product
185 #ifdef DEBUG
186  LogDebug("DataMixingHcalDigiWorker") << "total # HF digis: " << HFDigis->size();
187 #endif
188  }
189 
190 
191  if (HFDigis)
192  {
193  // loop over digis, storing them in a map so we can add pileup later
194  for(HFDigiCollection::const_iterator it = HFDigis->begin();
195  it != HFDigis->end(); ++it) {
196 
197  // calibration, for future reference: (same block for all Hcal types)
198  HcalDetId cell = it->id();
199  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
200  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
201  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
202  HcalCoderDb coder (*channelCoder, *shape);
203 
204  CaloSamples tool;
205  coder.adc2fC((*it),tool);
206 
207  HFDigiStorage_.insert(HFDigiMap::value_type( ( it->id() ), tool ));
208 
209 #ifdef DEBUG
210  // Commented out because this does not compile anymore
211  // LogDebug("DataMixingHcalDigiWorker") << "processed HFDigi with rawId: "
212  // << it->id() << "\n"
213  // << " digi energy: " << it->energy();
214 #endif
215 
216  }
217  }
218 
219  // ZDC next
220 
221  if(DoZDC_){
222 
223  Handle< ZDCDigiCollection > pZDCDigis;
224 
225  const ZDCDigiCollection* ZDCDigis = 0;
226 
227  if( e.getByLabel( ZDCdigiCollectionSig_, pZDCDigis) ) {
228  ZDCDigis = pZDCDigis.product(); // get a ptr to the product
229 #ifdef DEBUG
230  LogDebug("DataMixingHcalDigiWorker") << "total # ZDC digis: " << ZDCDigis->size();
231 #endif
232  }
233 
234 
235  if (ZDCDigis)
236  {
237  // loop over digis, storing them in a map so we can add pileup later
238  for(ZDCDigiCollection::const_iterator it = ZDCDigis->begin();
239  it != ZDCDigis->end(); ++it) {
240 
241  // calibration, for future reference: (same block for all Hcal types)
242  HcalDetId cell = it->id();
243  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
244  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
245  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
246  HcalCoderDb coder (*channelCoder, *shape);
247 
248  CaloSamples tool;
249  coder.adc2fC((*it),tool);
250 
251  ZDCDigiStorage_.insert(ZDCDigiMap::value_type( ( it->id() ), tool ));
252 
253 #ifdef DEBUG
254  // Commented out because this does not compile anymore
255  // LogDebug("DataMixingHcalDigiWorker") << "processed ZDCDigi with rawId: "
256  // << it->id() << "\n"
257  // << " digi energy: " << it->energy();
258 #endif
259 
260  }
261  }
262  }
263 
264  } // end of addHCalSignals
265 
266  void DataMixingHcalDigiWorker::addHcalPileups(const int bcr, const EventPrincipal *ep, unsigned int eventNr,const edm::EventSetup& ES,
267  ModuleCallingContext const* mcc) {
268 
269  LogDebug("DataMixingHcalDigiWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
270 
271  // get conditions
272  edm::ESHandle<HcalDbService> conditions;
273  ES.get<HcalDbRecord>().get(conditions);
274 
275  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
276 
277  // HBHE first
278 
279 
280  boost::shared_ptr<Wrapper<HBHEDigiCollection> const> HBHEDigisPTR =
281  getProductByTag<HBHEDigiCollection>(*ep, HBHEPileInputTag_, mcc);
282 
283  if(HBHEDigisPTR ) {
284 
285  const HBHEDigiCollection* HBHEDigis = const_cast< HBHEDigiCollection * >(HBHEDigisPTR->product());
286 
287  LogInfo("DataMixingHcalDigiWorker") << "total # HBHE digis: " << HBHEDigis->size();
288 
289  // loop over digis, adding these to the existing maps
290  for(HBHEDigiCollection::const_iterator it = HBHEDigis->begin();
291  it != HBHEDigis->end(); ++it) {
292 
293  // calibration, for future reference: (same block for all Hcal types)
294  HcalDetId cell = it->id();
295  // const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
296  const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
297  const HcalQIEShape* shape = conditions->getHcalShape (channelCoder); // this one is generic
298  HcalCoderDb coder (*channelCoder, *shape);
299 
300  CaloSamples tool;
301  coder.adc2fC((*it),tool);
302 
303  HBHEDigiStorage_.insert(HBHEDigiMap::value_type( (it->id()), tool ));
304 
305 #ifdef DEBUG
306  // Commented out because this does not compile anymore
307  // LogDebug("DataMixingHcalDigiWorker") << "processed HBHEDigi with rawId: "
308  // << it->id() << "\n"
309  // << " digi energy: " << it->energy();
310 #endif
311  }
312  }
313  else {std::cout << "NO HBHE Digis!!!!" << std::endl;}
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
tuple cout
Definition: gather_cfg.py:121
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