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_
 
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcdgrToken_
 
std::string label_
 
edm::ESGetToken< EcalPedestals, EcalPedestalsRcdpedToken_
 

Detailed Description

Definition at line 45 of file DataMixingEMDigiWorker.h.

Member Typedef Documentation

◆ EBDigiMap

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

Definition at line 102 of file DataMixingEMDigiWorker.h.

◆ EEDigiMap

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

Definition at line 103 of file DataMixingEMDigiWorker.h.

◆ ESDigiMap

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

Definition at line 104 of file DataMixingEMDigiWorker.h.

Constructor & Destructor Documentation

◆ DataMixingEMDigiWorker() [1/2]

DataMixingEMDigiWorker::DataMixingEMDigiWorker ( )

Definition at line 26 of file DataMixingEMDigiWorker.cc.

26 {}

◆ DataMixingEMDigiWorker() [2/2]

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

standard constructor

Definition at line 29 of file DataMixingEMDigiWorker.cc.

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

30  : label_(ps.getParameter<std::string>("Label"))
31 
32  {
33  // get the subdetector names
34  // this->getSubdetectorNames(); //something like this may be useful to
35  // check what we are supposed to do...
36 
37  // declare the products to produce, retrieve
38 
39  EBProducerSig_ = ps.getParameter<edm::InputTag>("EBdigiProducerSig");
40  EEProducerSig_ = ps.getParameter<edm::InputTag>("EEdigiProducerSig");
41  ESProducerSig_ = ps.getParameter<edm::InputTag>("ESdigiProducerSig");
42 
46 
47  EBPileInputTag_ = ps.getParameter<edm::InputTag>("EBPileInputTag");
48  EEPileInputTag_ = ps.getParameter<edm::InputTag>("EEPileInputTag");
49  ESPileInputTag_ = ps.getParameter<edm::InputTag>("ESPileInputTag");
50 
54 
55  EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
56  EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
57  ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
58 
61  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< EEDigiCollection > EEDigiPileToken_
edm::EDGetTokenT< ESDigiCollection > ESDigiPileToken_
EcalGainRatioMap EcalGainRatios
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:50
edm::ESGetToken< EcalPedestals, EcalPedestalsRcd > pedToken_
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > grToken_
edm::EDGetTokenT< EBDigiCollection > EBDigiToken_
edm::EDGetTokenT< ESDigiCollection > ESDigiToken_
edm::EDGetTokenT< EEDigiCollection > EEDigiToken_
edm::EDGetTokenT< EBDigiCollection > EBDigiPileToken_

◆ ~DataMixingEMDigiWorker()

DataMixingEMDigiWorker::~DataMixingEMDigiWorker ( )
virtual

Default destructor

Definition at line 64 of file DataMixingEMDigiWorker.cc.

64 {}

Member Function Documentation

◆ addEMPileups()

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

Definition at line 148 of file DataMixingEMDigiWorker.cc.

References edm::DataFrameContainer::begin(), EBDigiStorage_, EBPileInputTag_, EEDigiStorage_, EEPileInputTag_, edm::DataFrameContainer::end(), SiStripBadComponentsDQMServiceTemplate_cfg::ep, ESDigiStorage_, ESPileInputTag_, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, LogDebug, and edm::DataFrameContainer::size().

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

152  {
153  LogInfo("DataMixingEMDigiWorker") << "\n===============> adding pileups from event " << ep->id()
154  << " for bunchcrossing " << bcr;
155 
156  // fill in maps of hits; same code as addSignals, except now applied to the
157  // pileup events
158 
159  // EB first
160 
161  std::shared_ptr<Wrapper<EBDigiCollection> const> EBDigisPTR =
162  getProductByTag<EBDigiCollection>(*ep, EBPileInputTag_, mcc);
163 
164  if (EBDigisPTR) {
165  const EBDigiCollection *EBDigis = const_cast<EBDigiCollection *>(EBDigisPTR->product());
166 
167  LogDebug("DataMixingEMDigiWorker") << "total # EB digis: " << EBDigis->size();
168 
169  // loop over digis, adding these to the existing maps
170  for (EBDigiCollection::const_iterator it = EBDigis->begin(); it != EBDigis->end(); ++it) {
171  EBDigiStorage_.insert(EBDigiMap::value_type((it->id()), *it));
172 
173 #ifdef DEBUG
174  // Commented out because this does not compile anymore
175  // LogDebug("DataMixingEMDigiWorker") << "processed EBDigi with rawId: "
176  // << it->id().rawId() << "\n"
177  // << " digi energy: " << it->energy();
178 #endif
179  }
180  }
181 
182  // EE Next
183 
184  std::shared_ptr<Wrapper<EEDigiCollection> const> EEDigisPTR =
185  getProductByTag<EEDigiCollection>(*ep, EEPileInputTag_, mcc);
186 
187  if (EEDigisPTR) {
188  const EEDigiCollection *EEDigis = const_cast<EEDigiCollection *>(EEDigisPTR->product());
189 
190  LogDebug("DataMixingEMDigiWorker") << "total # EE digis: " << EEDigis->size();
191 
192  for (EEDigiCollection::const_iterator it = EEDigis->begin(); it != EEDigis->end(); ++it) {
193  EEDigiStorage_.insert(EEDigiMap::value_type((it->id()), *it));
194 
195 #ifdef DEBUG
196  // Commented out because this does not compile anymore
197  // LogDebug("DataMixingEMDigiWorker") << "processed EEDigi with rawId: "
198  // << it->id().rawId() << "\n"
199  // << " digi energy: " << it->energy();
200 #endif
201  }
202  }
203  // ES Next
204 
205  std::shared_ptr<Wrapper<ESDigiCollection> const> ESDigisPTR =
206  getProductByTag<ESDigiCollection>(*ep, ESPileInputTag_, mcc);
207 
208  if (ESDigisPTR) {
209  const ESDigiCollection *ESDigis = const_cast<ESDigiCollection *>(ESDigisPTR->product());
210 
211  LogDebug("DataMixingEMDigiWorker") << "total # ES digis: " << ESDigis->size();
212 
213  for (ESDigiCollection::const_iterator it = ESDigis->begin(); it != ESDigis->end(); ++it) {
214  ESDigiStorage_.insert(ESDigiMap::value_type((it->id()), *it));
215 
216 #ifdef DEBUG
217  // Commented out because this does not compile anymore
218  // LogDebug("DataMixingEMDigiWorker") << "processed ESDigi with rawId: "
219  // << it->id().rawId() << "\n"
220  // << " digi energy: " << it->energy();
221 #endif
222  }
223  }
224  }
const_iterator end() const
Log< level::Info, false > LogInfo
const_iterator begin() const
The iterator returned can not safely be used across threads.
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
#define LogDebug(id)

◆ addEMSignals()

void DataMixingEMDigiWorker::addEMSignals ( const edm::Event e,
const edm::EventSetup ES 
)

Definition at line 66 of file DataMixingEMDigiWorker.cc.

References edm::DataFrameContainer::begin(), MillePedeFileConverter_cfg::e, EBDigiStorage_, EBDigiToken_, EEDigiStorage_, EEDigiToken_, edm::DataFrameContainer::end(), ESDigiStorage_, ESDigiToken_, ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, LogDebug, edm::Handle< T >::product(), and edm::DataFrameContainer::size().

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

66  {
67  // fill in maps of hits
68 
69  LogInfo("DataMixingEMDigiWorker") << "===============> adding MC signals for " << e.id();
70 
71  // EB first
72 
73  Handle<EBDigiCollection> pEBDigis;
74 
75  const EBDigiCollection *EBDigis = nullptr;
76 
77  if (e.getByToken(EBDigiToken_, pEBDigis)) {
78  EBDigis = pEBDigis.product(); // get a ptr to the product
79  LogDebug("DataMixingEMDigiWorker") << "total # EB digis: " << EBDigis->size();
80  }
81 
82  if (EBDigis) {
83  // loop over digis, storing them in a map so we can add pileup later
84 
85  for (EBDigiCollection::const_iterator it = EBDigis->begin(); it != EBDigis->end(); ++it) {
86  EBDigiStorage_.insert(EBDigiMap::value_type((it->id()), *it));
87 #ifdef DEBUG
88  // Commented out because this does not compile anymore
89  // LogDebug("DataMixingEMDigiWorker") << "processed EBDigi with rawId: "
90  // << it->id().rawId() << "\n"
91  // << " digi energy: " << it->energy();
92 #endif
93  }
94  }
95 
96  // EE next
97 
98  Handle<EEDigiCollection> pEEDigis;
99 
100  const EEDigiCollection *EEDigis = nullptr;
101 
102  if (e.getByToken(EEDigiToken_, pEEDigis)) {
103  EEDigis = pEEDigis.product(); // get a ptr to the product
104  LogDebug("DataMixingEMDigiWorker") << "total # EE digis: " << EEDigis->size();
105  }
106 
107  if (EEDigis) {
108  // loop over digis, storing them in a map so we can add pileup later
109  for (EEDigiCollection::const_iterator it = EEDigis->begin(); it != EEDigis->end(); ++it) {
110  EEDigiStorage_.insert(EEDigiMap::value_type((it->id()), *it));
111 #ifdef DEBUG
112  // Commented out because this does not compile anymore
113  // LogDebug("DataMixingEMDigiWorker") << "processed EEDigi with rawId: "
114  // << it->id().rawId() << "\n"
115  // << " digi energy: " << it->energy();
116 #endif
117  }
118  }
119  // ES next
120 
121  Handle<ESDigiCollection> pESDigis;
122 
123  const ESDigiCollection *ESDigis = nullptr;
124 
125  if (e.getByToken(ESDigiToken_, pESDigis)) {
126  ESDigis = pESDigis.product(); // get a ptr to the product
127 #ifdef DEBUG
128  LogDebug("DataMixingEMDigiWorker") << "total # ES digis: " << ESDigis->size();
129 #endif
130  }
131 
132  if (ESDigis) {
133  // loop over digis, storing them in a map so we can add pileup later
134  for (ESDigiCollection::const_iterator it = ESDigis->begin(); it != ESDigis->end(); ++it) {
135  ESDigiStorage_.insert(ESDigiMap::value_type((it->id()), *it));
136 
137 #ifdef DEBUG
138  // Commented out because this does not compile anymore
139  // LogDebug("DataMixingEMDigiWorker") << "processed ESDigi with rawId: "
140  // << it->id().rawId() << "\n"
141  // << " digi energy: " << it->energy();
142 #endif
143  }
144  }
145 
146  } // end of addEMSignals
const_iterator end() const
Log< level::Info, false > LogInfo
const_iterator begin() const
The iterator returned can not safely be used across threads.
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
edm::EDGetTokenT< EBDigiCollection > EBDigiToken_
edm::EDGetTokenT< ESDigiCollection > ESDigiToken_
edm::EDGetTokenT< EEDigiCollection > EEDigiToken_
#define LogDebug(id)

◆ GetGainRatios()

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

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

Referenced by putEM().

554  {
555  std::vector<float> gainRatios(3);
556  // get gain ratios
557  const auto &grHandle = ES.getHandle(grToken_);
558  EcalMGPAGainRatio theRatio = (*grHandle)[detid];
559 
560  gainRatios[0] = 1.;
561  gainRatios[1] = theRatio.gain12Over6();
562  gainRatios[2] = theRatio.gain6Over1() * theRatio.gain12Over6();
563 
564  return gainRatios;
565  }
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
float gain12Over6() const
float gain6Over1() const
edm::ESGetToken< EcalGainRatios, EcalGainRatiosRcd > grToken_

◆ GetPedestals()

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

References EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::find(), edm::EventSetup::getHandle(), EcalCondObjectContainer< T >::getMap(), and pedToken_.

Referenced by putEM().

528  {
529  std::vector<float> pedeStals(3);
530 
531  // get pedestals
532  const auto &pedHandle = ES.getHandle(pedToken_);
533 
534  const EcalPedestalsMap &pedMap = pedHandle.product()->getMap(); // map of pedestals
535  EcalPedestalsMapIterator pedIter; // pedestal iterator
536  EcalPedestals::Item aped; // pedestal object for a single xtal
537 
538  pedIter = pedMap.find(detid);
539  if (pedIter != pedMap.end()) {
540  aped = (*pedIter);
541  pedeStals[0] = aped.mean_x12;
542  pedeStals[1] = aped.mean_x6;
543  pedeStals[2] = aped.mean_x1;
544  } else {
545  edm::LogError("DataMixingMissingInput") << "Cannot find pedestals";
546  pedeStals[0] = 0;
547  pedeStals[1] = 0;
548  pedeStals[2] = 0;
549  }
550 
551  return pedeStals;
552  }
Log< level::Error, false > LogError
EcalPedestalsMap::const_iterator EcalPedestalsMapIterator
Definition: EcalPedestals.h:49
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const_iterator find(uint32_t rawId) const
edm::ESGetToken< EcalPedestals, EcalPedestalsRcd > pedToken_
const_iterator end() const

◆ putEM()

void DataMixingEMDigiWorker::putEM ( edm::Event e,
const edm::EventSetup ES 
)

Definition at line 226 of file DataMixingEMDigiWorker.cc.

References gpuClustering::adc, edm::DataFrame::begin(), data, MillePedeFileConverter_cfg::e, EBDigiCollectionDM_, EBDigiStorage_, EEDigiCollectionDM_, EEDigiStorage_, ESDigiCollectionDM_, ESDigiStorage_, EcalDataFrame::frame(), ecalLiteDTU::gainId(), GetGainRatios(), GetPedestals(), createfilelist::int, SiStripPI::max, SiStripPI::min, eostools::move(), particleFlowDisplacedVertex_cfi::ratio, ecalGpuTask_cfi::sample, ESDataFrame::setSample(), EcalDataFrame::setSample(), ESDataFrame::size(), and EcalDataFrame::size().

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

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

Member Data Documentation

◆ EBDigiCollectionDM_

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

Definition at line 95 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

◆ EBdigiCollectionSig_

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

Definition at line 76 of file DataMixingEMDigiWorker.h.

◆ EBDigiPileToken_

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

Definition at line 91 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

◆ EBDigiStorage_

EBDigiMap edm::DataMixingEMDigiWorker::EBDigiStorage_
private

Definition at line 106 of file DataMixingEMDigiWorker.h.

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

◆ EBDigiToken_

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

Definition at line 87 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

◆ EBPileInputTag_

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

Definition at line 83 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

◆ EBProducerSig_

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

Definition at line 72 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

◆ EEDigiCollectionDM_

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

Definition at line 97 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

◆ EEdigiCollectionSig_

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

Definition at line 78 of file DataMixingEMDigiWorker.h.

◆ EEDigiPileToken_

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

Definition at line 92 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

◆ EEDigiStorage_

EEDigiMap edm::DataMixingEMDigiWorker::EEDigiStorage_
private

Definition at line 107 of file DataMixingEMDigiWorker.h.

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

◆ EEDigiToken_

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

Definition at line 88 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

◆ EEPileInputTag_

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

Definition at line 84 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

◆ EEProducerSig_

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

Definition at line 73 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

◆ ESDigiCollectionDM_

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

Definition at line 99 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

◆ ESdigiCollectionSig_

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

Definition at line 80 of file DataMixingEMDigiWorker.h.

◆ ESDigiPileToken_

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

Definition at line 93 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

◆ ESDigiStorage_

ESDigiMap edm::DataMixingEMDigiWorker::ESDigiStorage_
private

Definition at line 108 of file DataMixingEMDigiWorker.h.

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

◆ ESDigiToken_

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

Definition at line 89 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

◆ ESPileInputTag_

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

Definition at line 85 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

◆ ESProducerSig_

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

Definition at line 74 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker().

◆ grToken_

edm::ESGetToken<EcalGainRatios, EcalGainRatiosRcd> edm::DataMixingEMDigiWorker::grToken_
private

Definition at line 115 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and GetGainRatios().

◆ label_

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

◆ pedToken_

edm::ESGetToken<EcalPedestals, EcalPedestalsRcd> edm::DataMixingEMDigiWorker::pedToken_
private

Definition at line 114 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and GetPedestals().