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