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 32 of file DataMixingEMDigiWorker.cc.

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

standard constructor

Definition at line 35 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.

35  :
36  label_(ps.getParameter<std::string>("Label"))
37 
38  {
39 
40  // get the subdetector names
41  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
42 
43  // declare the products to produce, retrieve
44 
45  EBProducerSig_ = ps.getParameter<edm::InputTag>("EBdigiProducerSig");
46  EEProducerSig_ = ps.getParameter<edm::InputTag>("EEdigiProducerSig");
47  ESProducerSig_ = ps.getParameter<edm::InputTag>("ESdigiProducerSig");
48 
52 
53  EBPileInputTag_ = ps.getParameter<edm::InputTag>("EBPileInputTag");
54  EEPileInputTag_ = ps.getParameter<edm::InputTag>("EEPileInputTag");
55  ESPileInputTag_ = ps.getParameter<edm::InputTag>("ESPileInputTag");
56 
60 
61  EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
62  EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
63  ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
64 
65 
66 
67  }
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 71 of file DataMixingEMDigiWorker.cc.

71  {
72  }

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 173 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().

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

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

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

Referenced by putEM().

618  {
619 
620  std::vector<float> gainRatios(3);
621  // get gain ratios
623  ES.get<EcalGainRatiosRcd>().get(grHandle);
624  EcalMGPAGainRatio theRatio= (*grHandle)[detid];
625 
626 
627  gainRatios[0] = 1.;
628  gainRatios[1] = theRatio.gain12Over6();
629  gainRatios[2] = theRatio.gain6Over1() * theRatio.gain12Over6();
630 
631  return gainRatios;
632  }
float gain6Over1() const
float gain12Over6() const
T get() const
Definition: EventSetup.h:68
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 587 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().

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

Definition at line 259 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, SiStripPI::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().

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

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