CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
edm::DataMixingEMDigiWorker Class Reference

#include <DataMixingEMDigiWorker.h>

Public Member Functions

void addEMPileups (const int bcr, const edm::EventPrincipal *, unsigned int EventId, const edm::EventSetup &ES, ModuleCallingContext const *)
 
void addEMSignals (const edm::Event &e, const edm::EventSetup &ES)
 
 DataMixingEMDigiWorker ()
 
 DataMixingEMDigiWorker (const edm::ParameterSet &ps, edm::ConsumesCollector &&iC)
 
void putEM (edm::Event &e, const edm::EventSetup &ES)
 
virtual ~DataMixingEMDigiWorker ()
 

Private Types

typedef std::multimap< DetId, EBDataFrameEBDigiMap
 
typedef std::multimap< DetId, EEDataFrameEEDigiMap
 
typedef std::multimap< DetId, ESDataFrameESDigiMap
 

Private Member Functions

const std::vector< float > GetGainRatios (const edm::EventSetup &ES, const DetId &detid)
 retrieve gain ratios for that detid [0]=g12, [1]=g6, [2]=g12 More...
 
const std::vector< float > GetPedestals (const edm::EventSetup &ES, const DetId &detid)
 retrieve pedestals for that detid [0]=g12, [1]=g6, [2]=g12 More...
 

Private Attributes

std::string EBDigiCollectionDM_
 
edm::InputTag EBdigiCollectionSig_
 
edm::EDGetTokenT< EBDigiCollectionEBDigiPileToken_
 
EBDigiMap EBDigiStorage_
 
edm::EDGetTokenT< EBDigiCollectionEBDigiToken_
 
edm::InputTag EBPileInputTag_
 
edm::InputTag EBProducerSig_
 
std::string EEDigiCollectionDM_
 
edm::InputTag EEdigiCollectionSig_
 
edm::EDGetTokenT< EEDigiCollectionEEDigiPileToken_
 
EEDigiMap EEDigiStorage_
 
edm::EDGetTokenT< EEDigiCollectionEEDigiToken_
 
edm::InputTag EEPileInputTag_
 
edm::InputTag EEProducerSig_
 
std::string ESDigiCollectionDM_
 
edm::InputTag ESdigiCollectionSig_
 
edm::EDGetTokenT< ESDigiCollectionESDigiPileToken_
 
ESDigiMap ESDigiStorage_
 
edm::EDGetTokenT< ESDigiCollectionESDigiToken_
 
edm::InputTag ESPileInputTag_
 
edm::InputTag ESProducerSig_
 
std::string label_
 

Detailed Description

Definition at line 43 of file DataMixingEMDigiWorker.h.

Member Typedef Documentation

typedef std::multimap<DetId, EBDataFrame> edm::DataMixingEMDigiWorker::EBDigiMap
private

Definition at line 97 of file DataMixingEMDigiWorker.h.

typedef std::multimap<DetId, EEDataFrame> edm::DataMixingEMDigiWorker::EEDigiMap
private

Definition at line 98 of file DataMixingEMDigiWorker.h.

typedef std::multimap<DetId, ESDataFrame> edm::DataMixingEMDigiWorker::ESDigiMap
private

Definition at line 99 of file DataMixingEMDigiWorker.h.

Constructor & Destructor Documentation

DataMixingEMDigiWorker::DataMixingEMDigiWorker ( )

Definition at line 37 of file DataMixingEMDigiWorker.cc.

37 { }
DataMixingEMDigiWorker::DataMixingEMDigiWorker ( const edm::ParameterSet ps,
edm::ConsumesCollector &&  iC 
)
explicit

standard constructor

Definition at line 40 of file DataMixingEMDigiWorker.cc.

References EBDigiCollectionDM_, EBDigiPileToken_, EBDigiToken_, EBPileInputTag_, EBProducerSig_, EEDigiCollectionDM_, EEDigiPileToken_, EEDigiToken_, EEPileInputTag_, EEProducerSig_, ESDigiCollectionDM_, ESDigiPileToken_, ESDigiToken_, ESPileInputTag_, ESProducerSig_, edm::ParameterSet::getParameter(), and AlCaHLTBitMon_QueryRunRegistry::string.

40  :
41  label_(ps.getParameter<std::string>("Label"))
42 
43  {
44 
45  // get the subdetector names
46  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
47 
48  // declare the products to produce, retrieve
49 
50  EBProducerSig_ = ps.getParameter<edm::InputTag>("EBdigiProducerSig");
51  EEProducerSig_ = ps.getParameter<edm::InputTag>("EEdigiProducerSig");
52  ESProducerSig_ = ps.getParameter<edm::InputTag>("ESdigiProducerSig");
53 
57 
58  EBPileInputTag_ = ps.getParameter<edm::InputTag>("EBPileInputTag");
59  EEPileInputTag_ = ps.getParameter<edm::InputTag>("EEPileInputTag");
60  ESPileInputTag_ = ps.getParameter<edm::InputTag>("ESPileInputTag");
61 
65 
66  EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
67  EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
68  ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
69 
70 
71 
72  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
edm::EDGetTokenT< EEDigiCollection > EEDigiPileToken_
edm::EDGetTokenT< ESDigiCollection > ESDigiPileToken_
edm::EDGetTokenT< EBDigiCollection > EBDigiToken_
edm::EDGetTokenT< ESDigiCollection > ESDigiToken_
edm::EDGetTokenT< EEDigiCollection > EEDigiToken_
edm::EDGetTokenT< EBDigiCollection > EBDigiPileToken_
DataMixingEMDigiWorker::~DataMixingEMDigiWorker ( )
virtual

Default destructor

Definition at line 76 of file DataMixingEMDigiWorker.cc.

76  {
77  }

Member Function Documentation

void DataMixingEMDigiWorker::addEMPileups ( const int  bcr,
const edm::EventPrincipal ep,
unsigned int  EventId,
const edm::EventSetup ES,
ModuleCallingContext const *  mcc 
)

Definition at line 178 of file DataMixingEMDigiWorker.cc.

References edm::DataFrameContainer::begin(), EBDigiStorage_, EBPileInputTag_, EEDigiStorage_, EEPileInputTag_, edm::DataFrameContainer::end(), ESDigiStorage_, ESPileInputTag_, edm::EventPrincipal::id(), LogDebug, and edm::DataFrameContainer::size().

Referenced by edm::DataMixingModule::pileWorker().

179  {
180 
181  LogInfo("DataMixingEMDigiWorker") <<"\n===============> adding pileups from event "<<ep->id()<<" for bunchcrossing "<<bcr;
182 
183  // fill in maps of hits; same code as addSignals, except now applied to the pileup events
184 
185  // EB first
186 
187  std::shared_ptr<Wrapper<EBDigiCollection> const> EBDigisPTR =
188  getProductByTag<EBDigiCollection>(*ep, EBPileInputTag_, mcc);
189 
190  if(EBDigisPTR ) {
191 
192  const EBDigiCollection* EBDigis = const_cast< EBDigiCollection * >(EBDigisPTR->product());
193 
194  LogDebug("DataMixingEMDigiWorker") << "total # EB digis: " << EBDigis->size();
195 
196  // loop over digis, adding these to the existing maps
197  for(EBDigiCollection::const_iterator it = EBDigis->begin();
198  it != EBDigis->end(); ++it) {
199 
200  EBDigiStorage_.insert(EBDigiMap::value_type( (it->id()), *it ));
201 
202 #ifdef DEBUG
203  // Commented out because this does not compile anymore
204  // LogDebug("DataMixingEMDigiWorker") << "processed EBDigi with rawId: "
205  // << it->id().rawId() << "\n"
206  // << " digi energy: " << it->energy();
207 #endif
208  }
209  }
210 
211  // EE Next
212 
213  std::shared_ptr<Wrapper<EEDigiCollection> const> EEDigisPTR =
214  getProductByTag<EEDigiCollection>(*ep, EEPileInputTag_, mcc);
215 
216  if(EEDigisPTR ) {
217 
218  const EEDigiCollection* EEDigis = const_cast< EEDigiCollection * >(EEDigisPTR->product());
219 
220  LogDebug("DataMixingEMDigiWorker") << "total # EE digis: " << EEDigis->size();
221 
222  for(EEDigiCollection::const_iterator it = EEDigis->begin();
223  it != EEDigis->end(); ++it) {
224 
225  EEDigiStorage_.insert(EEDigiMap::value_type( (it->id()), *it ));
226 
227 #ifdef DEBUG
228  // Commented out because this does not compile anymore
229  // LogDebug("DataMixingEMDigiWorker") << "processed EEDigi with rawId: "
230  // << it->id().rawId() << "\n"
231  // << " digi energy: " << it->energy();
232 #endif
233  }
234  }
235  // ES Next
236 
237  std::shared_ptr<Wrapper<ESDigiCollection> const> ESDigisPTR =
238  getProductByTag<ESDigiCollection>(*ep, ESPileInputTag_, mcc);
239 
240  if(ESDigisPTR ) {
241 
242  const ESDigiCollection* ESDigis = const_cast< ESDigiCollection * >(ESDigisPTR->product());
243 
244  LogDebug("DataMixingEMDigiWorker") << "total # ES digis: " << ESDigis->size();
245 
246  for(ESDigiCollection::const_iterator it = ESDigis->begin();
247  it != ESDigis->end(); ++it) {
248 
249  ESDigiStorage_.insert(ESDigiMap::value_type( (it->id()), *it ));
250 
251 #ifdef DEBUG
252  // Commented out because this does not compile anymore
253  // LogDebug("DataMixingEMDigiWorker") << "processed ESDigi with rawId: "
254  // << it->id().rawId() << "\n"
255  // << " digi energy: " << it->energy();
256 #endif
257  }
258  }
259 
260 
261 
262  }
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
EventID const & id() const
const_iterator begin() const
const_iterator end() const
void DataMixingEMDigiWorker::addEMSignals ( const edm::Event e,
const edm::EventSetup ES 
)

Definition at line 79 of file DataMixingEMDigiWorker.cc.

References edm::DataFrameContainer::begin(), EBDigiStorage_, EBDigiToken_, EEDigiStorage_, EEDigiToken_, edm::DataFrameContainer::end(), ESDigiStorage_, ESDigiToken_, edm::Event::getByToken(), edm::EventBase::id(), LogDebug, edm::Handle< T >::product(), and edm::DataFrameContainer::size().

Referenced by edm::DataMixingModule::addSignals().

79  {
80  // fill in maps of hits
81 
82  LogInfo("DataMixingEMDigiWorker")<<"===============> adding MC signals for "<<e.id();
83 
84  // EB first
85 
87 
88  const EBDigiCollection* EBDigis = 0;
89 
90  if(e.getByToken(EBDigiToken_, pEBDigis) ){
91  EBDigis = pEBDigis.product(); // get a ptr to the product
92  LogDebug("DataMixingEMDigiWorker") << "total # EB digis: " << EBDigis->size();
93  }
94 
95  if (EBDigis)
96  {
97  // loop over digis, storing them in a map so we can add pileup later
98 
99 
100  for(EBDigiCollection::const_iterator it = EBDigis->begin();
101  it != EBDigis->end(); ++it) {
102 
103  EBDigiStorage_.insert(EBDigiMap::value_type( ( it->id() ), *it ));
104 #ifdef DEBUG
105  // Commented out because this does not compile anymore
106  // LogDebug("DataMixingEMDigiWorker") << "processed EBDigi with rawId: "
107  // << it->id().rawId() << "\n"
108  // << " digi energy: " << it->energy();
109 #endif
110  }
111  }
112 
113  // EE next
114 
116 
117  const EEDigiCollection* EEDigis = 0;
118 
119 
120  if(e.getByToken(EEDigiToken_, pEEDigis) ){
121  EEDigis = pEEDigis.product(); // get a ptr to the product
122  LogDebug("DataMixingEMDigiWorker") << "total # EE digis: " << EEDigis->size();
123  }
124 
125 
126  if (EEDigis)
127  {
128  // loop over digis, storing them in a map so we can add pileup later
129  for(EEDigiCollection::const_iterator it = EEDigis->begin();
130  it != EEDigis->end(); ++it) {
131 
132  EEDigiStorage_.insert(EEDigiMap::value_type( ( it->id() ), *it ));
133 #ifdef DEBUG
134  // Commented out because this does not compile anymore
135  // LogDebug("DataMixingEMDigiWorker") << "processed EEDigi with rawId: "
136  // << it->id().rawId() << "\n"
137  // << " digi energy: " << it->energy();
138 #endif
139 
140  }
141  }
142  // ES next
143 
144  Handle< ESDigiCollection > pESDigis;
145 
146  const ESDigiCollection* ESDigis = 0;
147 
148 
149  if(e.getByToken( ESDigiToken_, pESDigis) ){
150  ESDigis = pESDigis.product(); // get a ptr to the product
151 #ifdef DEBUG
152  LogDebug("DataMixingEMDigiWorker") << "total # ES digis: " << ESDigis->size();
153 #endif
154  }
155 
156 
157  if (ESDigis)
158  {
159 
160  // loop over digis, storing them in a map so we can add pileup later
161  for(ESDigiCollection::const_iterator it = ESDigis->begin();
162  it != ESDigis->end(); ++it) {
163 
164  ESDigiStorage_.insert(ESDigiMap::value_type( ( it->id() ), *it ));
165 
166 #ifdef DEBUG
167  // Commented out because this does not compile anymore
168  // LogDebug("DataMixingEMDigiWorker") << "processed ESDigi with rawId: "
169  // << it->id().rawId() << "\n"
170  // << " digi energy: " << it->energy();
171 #endif
172 
173  }
174  }
175 
176  } // end of addEMSignals
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
const_iterator begin() const
T const * product() const
Definition: Handle.h:81
const_iterator end() const
edm::EventID id() const
Definition: EventBase.h:58
edm::EDGetTokenT< EBDigiCollection > EBDigiToken_
edm::EDGetTokenT< ESDigiCollection > ESDigiToken_
edm::EDGetTokenT< EEDigiCollection > EEDigiToken_
const std::vector< float > DataMixingEMDigiWorker::GetGainRatios ( const edm::EventSetup ES,
const DetId detid 
)
private

retrieve gain ratios for that detid [0]=g12, [1]=g6, [2]=g12

Definition at line 623 of file DataMixingEMDigiWorker.cc.

References EcalMGPAGainRatio::gain12Over6(), EcalMGPAGainRatio::gain6Over1(), and edm::EventSetup::get().

Referenced by putEM().

623  {
624 
625  std::vector<float> gainRatios(3);
626  // get gain ratios
628  ES.get<EcalGainRatiosRcd>().get(grHandle);
629  EcalMGPAGainRatio theRatio= (*grHandle)[detid];
630 
631 
632  gainRatios[0] = 1.;
633  gainRatios[1] = theRatio.gain12Over6();
634  gainRatios[2] = theRatio.gain6Over1() * theRatio.gain12Over6();
635 
636  return gainRatios;
637  }
float gain6Over1() const
const T & get() const
Definition: EventSetup.h:56
float gain12Over6() const
const std::vector< float > DataMixingEMDigiWorker::GetPedestals ( const edm::EventSetup ES,
const DetId detid 
)
private

retrieve pedestals for that detid [0]=g12, [1]=g6, [2]=g12

Definition at line 592 of file DataMixingEMDigiWorker.cc.

References EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::find(), edm::EventSetup::get(), EcalCondObjectContainer< T >::getMap(), EcalPedestal::mean_x1, EcalPedestal::mean_x12, EcalPedestal::mean_x6, and edm::ESHandle< T >::product().

Referenced by putEM().

592  {
593 
594  std::vector<float> pedeStals(3);
595 
596  // get pedestals
598  ES.get<EcalPedestalsRcd>().get( pedHandle );
599 
600 
601  const EcalPedestalsMap & pedMap = pedHandle.product()->getMap(); // map of pedestals
602  EcalPedestalsMapIterator pedIter; // pedestal iterator
603  EcalPedestals::Item aped; // pedestal object for a single xtal
604 
605 
606  pedIter = pedMap.find(detid);
607  if( pedIter != pedMap.end() ) {
608  aped = (*pedIter);
609  pedeStals[0] = aped.mean_x12;
610  pedeStals[1] = aped.mean_x6;
611  pedeStals[2] = aped.mean_x1;
612  } else {
613  edm::LogError("DataMixingMissingInput") << "Cannot find pedestals";
614  pedeStals[0] = 0;
615  pedeStals[1] = 0;
616  pedeStals[2] = 0;
617  }
618 
619 
620  return pedeStals;
621  }
const self & getMap() const
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:52
const T & get() const
Definition: EventSetup.h:56
const_iterator find(uint32_t rawId) const
const_iterator end() const
T const * product() const
Definition: ESHandle.h:86
void DataMixingEMDigiWorker::putEM ( edm::Event e,
const edm::EventSetup ES 
)

Definition at line 264 of file DataMixingEMDigiWorker.cc.

References ecalMGPA::adc(), edm::DataFrame::begin(), data, EBDigiCollectionDM_, EBDigiStorage_, EEDigiCollectionDM_, EEDigiStorage_, ESDigiCollectionDM_, ESDigiStorage_, EcalDataFrame::frame(), ecalMGPA::gainId(), GetGainRatios(), GetPedestals(), createfilelist::int, hpstanc_transforms::max, min(), eostools::move(), edm::Event::put(), particleFlowDisplacedVertex_cfi::ratio, simplePhotonAnalyzer_cfi::sample, ESDataFrame::setSample(), EcalDataFrame::setSample(), ESDataFrame::size(), EcalDataFrame::size(), and findQualityFiles::size.

Referenced by edm::DataMixingModule::put().

264  {
265 
266  // collection of digis to put in the event
267  std::unique_ptr< EBDigiCollection > EBdigis( new EBDigiCollection );
268  std::unique_ptr< EEDigiCollection > EEdigis( new EEDigiCollection );
269  std::unique_ptr< ESDigiCollection > ESdigis( new ESDigiCollection );
270 
271 
272  // loop over the maps we have, re-making individual hits or digis if necessary.
273  DetId formerID = 0;
274  DetId currentID;
275 
276  EBDataFrame EB_old;
277 
278  int gain_new = 0;
279  int gain_old = 0;
280  int gain_consensus = 0;
281  int adc_new;
282  int adc_old;
283  int adc_sum;
284  uint16_t data;
285 
286  // EB first...
287 
288  EBDigiMap::const_iterator iEBchk;
289 
290 
291 
292  for(EBDigiMap::const_iterator iEB = EBDigiStorage_.begin();
293  iEB != EBDigiStorage_.end(); iEB++) {
294 
295  currentID = iEB->first;
296 
297  if (currentID == formerID) { // we have to add these digis together
298  /*
299  cout<< " Adding signals " << EBDetId(currentID).ieta() << " "
300  << EBDetId(currentID).iphi() << std::endl;
301 
302  cout << 1 << " " ;
303  for (int i=0; i<10;++i) std::cout << EB_old[i].adc()<< "["<<EB_old[i].gainId()<< "] " ; std::cout << std::endl;
304 
305  cout << 2 << " " ;
306  for (int i=0; i<10;++i) std::cout << (iEB->second)[i].adc()<< "["<<(iEB->second)[i].gainId()<< "] " ; std::cout << std::endl;
307  */
308  //loop over digi samples in each DataFrame
309  unsigned int sizenew = (iEB->second).size();
310  unsigned int sizeold = EB_old.size();
311 
312  unsigned int max_samp = std::max(sizenew, sizeold);
313 
314  // samples from different events can be of different lengths - sum all
315  // that overlap.
316  // check to see if gains match - if not, scale smaller cell down.
317 
318  int sw_gain_consensus=0;
319 
320 
321  for(unsigned int isamp = 0; isamp<max_samp; isamp++) {
322  if(isamp < sizenew) {
323  gain_new = (iEB->second)[isamp].gainId();
324  adc_new = (iEB->second)[isamp].adc();
325  }
326  else { adc_new = 0;}
327 
328  if(isamp < sizeold) {
329  gain_old = EB_old[isamp].gainId();
330  adc_old = EB_old[isamp].adc();
331  }
332  else { adc_old = 0;}
333 
334  const std::vector<float> pedeStals = GetPedestals(ES,currentID);
335  const std::vector<float> gainRatios = GetGainRatios(ES,currentID);
336 
337  if(adc_new>0 && adc_old>0) {
338  if(gain_old == gain_new) { // we're happy - easy case
339  gain_consensus = gain_old;
340  }
341  else { // lower gain sample has more energy
342 
343 
344  if(gain_old < gain_new) { // old has higher gain than new, scale to lower gain
345 
346 
347  float ratio = gainRatios[gain_new-1]/gainRatios[gain_old-1];
348  adc_old = (int) round ((adc_old - pedeStals[gain_old-1]) / ratio + pedeStals[gain_new-1] );
349  gain_consensus = gain_new;
350  }
351  else { // scale to old (lower) gain
352  float ratio = gainRatios[gain_old-1]/gainRatios[gain_new-1];
353  adc_new = (int) round ( (adc_new - pedeStals[gain_new-1]) / ratio+ pedeStals[gain_old-1] );
354  gain_consensus = gain_old;
355  }
356  }
357  }
358 
359 
360  // add values, but don't count pedestals twice
361  adc_sum = adc_new + adc_old - (int) round (pedeStals[gain_consensus-1]);
362 
363 
364  // if we are now saturating that gain, switch to the next
365  if (adc_sum> 4096) {
366  if (gain_consensus<3){
367 
368  double ratio = gainRatios[gain_consensus]/gainRatios[gain_consensus-1];
369  adc_sum = (int) round ((adc_sum - pedeStals[gain_consensus-1])/ ratio + pedeStals[gain_consensus] ) ;
370  sw_gain_consensus=++gain_consensus;
371  }
372  else adc_sum = 4096;
373 
374  }
375 
376  // furthermore, make sure we don't decrease our gain once we've switched up
377  // in case go back
378  if (gain_consensus<sw_gain_consensus){
379 
380  double ratio = gainRatios[sw_gain_consensus-1]/gainRatios[gain_consensus-1];
381  adc_sum = (int) round((adc_sum - pedeStals[gain_consensus-1] )/ratio + pedeStals[sw_gain_consensus-1]);
382  gain_consensus = sw_gain_consensus;
383  }
384 
385  EcalMGPASample sample(adc_sum, gain_consensus);
386  EB_old.setSample(isamp,sample); // overwrite old sample, adding new info
387  } // for sample
388 
389 
390  } // if current = former
391  else {
392  if(formerID>0) {
393  EBdigis->push_back( formerID, EB_old.frame().begin() );
394  }
395  //save pointers for next iteration
396  formerID = currentID;
397  EB_old = iEB->second;
398 
399  }
400 
401 
402  iEBchk = iEB;
403  if((++iEBchk) == EBDigiStorage_.end()) { //make sure not to lose the last one
404  EBdigis->push_back( currentID, (iEB->second).frame().begin()) ;
405  }
406  }
407 
408  // EE next...
409 
410  formerID = 0;
411  EEDataFrame EE_old;
412 
413  EEDigiMap::const_iterator iEEchk;
414 
415  for(EEDigiMap::const_iterator iEE = EEDigiStorage_.begin();
416  iEE != EEDigiStorage_.end(); iEE++) {
417 
418  currentID = iEE->first;
419 
420  if (currentID == formerID) { // we have to add these digis together
421 
422  //loop over digi samples in each DataFrame
423  unsigned int sizenew = (iEE->second).size();
424  unsigned int sizeold = EE_old.size();
425 
426  unsigned int max_samp = std::max(sizenew, sizeold);
427 
428  // samples from different events can be of different lengths - sum all
429  // that overlap.
430  // check to see if gains match - if not, scale smaller cell down.
431 
432  for(unsigned int isamp = 0; isamp<max_samp; isamp++) {
433  if(isamp < sizenew) {
434  gain_new = (iEE->second)[isamp].gainId();
435  adc_new = (iEE->second)[isamp].adc();
436  }
437  else { adc_new = 0;}
438 
439  if(isamp < sizeold) {
440  gain_old = EE_old[isamp].gainId();
441  adc_old = EE_old[isamp].adc();
442  }
443  else { adc_old = 0;}
444 
445  const std::vector<float> pedeStals = GetPedestals(ES,currentID);
446  const std::vector<float> gainRatios = GetGainRatios(ES,currentID);
447 
448  if(adc_new>0 && adc_old>0) {
449  if(gain_old == gain_new) { // we're happy - easy case
450  gain_consensus = gain_old;
451  }
452  else { // lower gain sample has more energy
453 
454  if(gain_old < gain_new) { // old has higher gain than new, scale to lower gain
455 
456 
457  float ratio = gainRatios[gain_new-1]/gainRatios[gain_old-1];
458  adc_old = (int) round ((adc_old - pedeStals[gain_old-1]) / ratio + pedeStals[gain_new-1] );
459  gain_consensus = gain_new;
460  }
461  else { // scale to old (lower) gain
462  float ratio = gainRatios[gain_old-1]/gainRatios[gain_new-1];
463  adc_new = (int) round ( (adc_new - pedeStals[gain_new-1]) / ratio+ pedeStals[gain_old-1] );
464  gain_consensus = gain_old;
465  }
466  }
467 
468  }
469 
470 
471  // add values, but don't count pedestals twice
472  adc_sum = adc_new + adc_old - (int) round (pedeStals[gain_consensus-1]);
473 
474  // if the sum saturates this gain, switch
475  if (adc_sum> 4096) {
476  if (gain_consensus<3){
477 
478  double ratio = gainRatios[gain_consensus]/gainRatios[gain_consensus-1];
479  adc_sum = (int) round ((adc_sum - pedeStals[gain_consensus-1])/ ratio + pedeStals[gain_consensus] ) ;
480  ++gain_consensus;
481  }
482  else adc_sum = 4096;
483 
484  }
485 
486  EcalMGPASample sample(adc_sum, gain_consensus);
487  EE_old.setSample(isamp,sample);
488  }
489 
490  }
491  else {
492  if(formerID>0) {
493  EEdigis->push_back(formerID, EE_old.frame().begin() );
494 
495  }
496  //save pointers for next iteration
497  formerID = currentID;
498  EE_old = iEE->second;
499  }
500 
501  iEEchk = iEE;
502  if((++iEEchk) == EEDigiStorage_.end()) { //make sure not to lose the last one
503  EEdigis->push_back(currentID, (iEE->second).frame().begin());
504  }
505  }
506 
507 
508  // ES next...
509 
510  formerID = 0;
511  ESDataFrame ES_old;
512 
513  ESDigiMap::const_iterator iESchk;
514 
515  for(ESDigiMap::const_iterator iES = ESDigiStorage_.begin();
516  iES != ESDigiStorage_.end(); iES++) {
517 
518  currentID = iES->first;
519 
520  if (currentID == formerID) { // we have to add these digis together
521 
522  //loop over digi samples in each DataFrame
523  unsigned int sizenew = (iES->second).size();
524  unsigned int sizeold = ES_old.size();
525  uint16_t rawdat = 0;
526  unsigned int max_samp = std::max(sizenew, sizeold);
527 
528  // samples from different events can be of different lengths - sum all
529  // that overlap.
530  // check to see if gains match - if not, scale smaller cell down.
531 
532  for(unsigned int isamp = 0; isamp<max_samp; isamp++) {
533  if(isamp < sizenew) {
534  adc_new = (iES->second)[isamp].adc();
535  rawdat = (iES->second)[isamp].raw();
536  }
537  else { adc_new = 0;}
538 
539  if(isamp < sizeold) {
540  adc_old = ES_old[isamp].adc();
541  rawdat = ES_old[isamp].raw();
542  }
543  else { adc_old = 0;}
544 
545  // add values
546  adc_sum = adc_new + adc_old;
547  // make data word of gain, rawdata
548  adc_sum = std::min(adc_sum,4095); //first 12 bits of (uint)
549  data = adc_sum+(rawdat&0xF000); // data is 14 bit word with gain as MSBs
550  ES_old.setSample(isamp,data);
551  }
552 
553  }
554  else {
555  if(formerID>0) {
556  ESdigis->push_back(ES_old);
557  }
558  //save pointers for next iteration
559  formerID = currentID;
560  ES_old = iES->second;
561  }
562 
563  iESchk = iES;
564  if((++iESchk) == ESDigiStorage_.end()) { //make sure not to lose the last one
565  ESdigis->push_back(iES->second);
566  // ESDataFrame df( (*ESdigis)->back() );
567  //for(int isamp=0; isamp<(iES->second).size(); isamp++) {
568  // df.setSample(isamp,(iES->second).data[isamp]);
569  // }
570  }
571  }
572 
573 
574  // done merging
575 
576  // put the collection of reconstructed hits in the event
577  LogInfo("DataMixingEMDigiWorker") << "total # EB Merged digis: " << EBdigis->size() ;
578  LogInfo("DataMixingEMDigiWorker") << "total # EE Merged digis: " << EEdigis->size() ;
579  LogInfo("DataMixingEMDigiWorker") << "total # ES Merged digis: " << ESdigis->size() ;
580 
581  e.put(std::move(EBdigis), EBDigiCollectionDM_ );
582  e.put(std::move(EEdigis), EEDigiCollectionDM_ );
583  e.put(std::move(ESdigis), ESDigiCollectionDM_ );
584 
585  // clear local storage after this event
586 
587  EBDigiStorage_.clear();
588  EEDigiStorage_.clear();
589  ESDigiStorage_.clear();
590 
591  }
int adc(sample_type sample)
get the ADC sample (12 bits)
size
Write out results.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
const std::vector< float > GetGainRatios(const edm::EventSetup &ES, const DetId &detid)
retrieve gain ratios for that detid [0]=g12, [1]=g6, [2]=g12
int gainId(sample_type sample)
get the gainId (2 bits)
const std::vector< float > GetPedestals(const edm::EventSetup &ES, const DetId &detid)
retrieve pedestals for that detid [0]=g12, [1]=g6, [2]=g12
int size() const
Definition: ESDataFrame.h:23
int size() const
Definition: EcalDataFrame.h:26
iterator begin()
Definition: DataFrame.h:48
T min(T a, T b)
Definition: MathUtil.h:58
void setSample(int i, const ESSample &sam)
Definition: ESDataFrame.h:30
Definition: DetId.h:18
edm::DataFrame const & frame() const
Definition: EcalDataFrame.h:50
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void setSample(int i, EcalMGPASample sam)
Definition: EcalDataFrame.h:43
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

std::string edm::DataMixingEMDigiWorker::EBDigiCollectionDM_
private

Definition at line 93 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

edm::InputTag edm::DataMixingEMDigiWorker::EBdigiCollectionSig_
private

Definition at line 76 of file DataMixingEMDigiWorker.h.

edm::EDGetTokenT<EBDigiCollection> edm::DataMixingEMDigiWorker::EBDigiPileToken_
private

Definition at line 88 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

EBDigiMap edm::DataMixingEMDigiWorker::EBDigiStorage_
private

Definition at line 101 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), addEMSignals(), and putEM().

edm::EDGetTokenT<EBDigiCollection> edm::DataMixingEMDigiWorker::EBDigiToken_
private

Definition at line 84 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

edm::InputTag edm::DataMixingEMDigiWorker::EBPileInputTag_
private

Definition at line 80 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

edm::InputTag edm::DataMixingEMDigiWorker::EBProducerSig_
private

Definition at line 72 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

std::string edm::DataMixingEMDigiWorker::EEDigiCollectionDM_
private

Definition at line 94 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

edm::InputTag edm::DataMixingEMDigiWorker::EEdigiCollectionSig_
private

Definition at line 77 of file DataMixingEMDigiWorker.h.

edm::EDGetTokenT<EEDigiCollection> edm::DataMixingEMDigiWorker::EEDigiPileToken_
private

Definition at line 89 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

EEDigiMap edm::DataMixingEMDigiWorker::EEDigiStorage_
private

Definition at line 102 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), addEMSignals(), and putEM().

edm::EDGetTokenT<EEDigiCollection> edm::DataMixingEMDigiWorker::EEDigiToken_
private

Definition at line 85 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

edm::InputTag edm::DataMixingEMDigiWorker::EEPileInputTag_
private

Definition at line 81 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

edm::InputTag edm::DataMixingEMDigiWorker::EEProducerSig_
private

Definition at line 73 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

std::string edm::DataMixingEMDigiWorker::ESDigiCollectionDM_
private

Definition at line 95 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

edm::InputTag edm::DataMixingEMDigiWorker::ESdigiCollectionSig_
private

Definition at line 78 of file DataMixingEMDigiWorker.h.

edm::EDGetTokenT<ESDigiCollection> edm::DataMixingEMDigiWorker::ESDigiPileToken_
private

Definition at line 90 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

ESDigiMap edm::DataMixingEMDigiWorker::ESDigiStorage_
private

Definition at line 103 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), addEMSignals(), and putEM().

edm::EDGetTokenT<ESDigiCollection> edm::DataMixingEMDigiWorker::ESDigiToken_
private

Definition at line 86 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

edm::InputTag edm::DataMixingEMDigiWorker::ESPileInputTag_
private

Definition at line 82 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

edm::InputTag edm::DataMixingEMDigiWorker::ESProducerSig_
private

Definition at line 74 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

std::string edm::DataMixingEMDigiWorker::label_
private