CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 
void addEMSignals (const edm::Event &e, const edm::EventSetup &ES)
 
 DataMixingEMDigiWorker ()
 
 DataMixingEMDigiWorker (const edm::ParameterSet &ps)
 
void putEM (edm::Event &e, const edm::EventSetup &ES)
 
virtual ~DataMixingEMDigiWorker ()
 

Private Types

typedef std::multimap< DetId,
EBDataFrame
EBDigiMap
 
typedef std::multimap< DetId,
EEDataFrame
EEDigiMap
 
typedef std::multimap< DetId,
ESDataFrame
ESDigiMap
 

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_
 
EBDigiMap EBDigiStorage_
 
edm::InputTag EBPileInputTag_
 
edm::InputTag EBProducerSig_
 
std::string EEDigiCollectionDM_
 
edm::InputTag EEdigiCollectionSig_
 
EEDigiMap EEDigiStorage_
 
edm::InputTag EEPileInputTag_
 
edm::InputTag EEProducerSig_
 
std::string ESDigiCollectionDM_
 
edm::InputTag ESdigiCollectionSig_
 
ESDigiMap ESDigiStorage_
 
edm::InputTag ESPileInputTag_
 
edm::InputTag ESProducerSig_
 
std::string label_
 

Detailed Description

Definition at line 40 of file DataMixingEMDigiWorker.h.

Member Typedef Documentation

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

Definition at line 84 of file DataMixingEMDigiWorker.h.

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

Definition at line 85 of file DataMixingEMDigiWorker.h.

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

Definition at line 86 of file DataMixingEMDigiWorker.h.

Constructor & Destructor Documentation

DataMixingEMDigiWorker::DataMixingEMDigiWorker ( )

Definition at line 36 of file DataMixingEMDigiWorker.cc.

36 { }
DataMixingEMDigiWorker::DataMixingEMDigiWorker ( const edm::ParameterSet ps)
explicit

standard constructor

Definition at line 39 of file DataMixingEMDigiWorker.cc.

References EBDigiCollectionDM_, EBPileInputTag_, EBProducerSig_, EEDigiCollectionDM_, EEPileInputTag_, EEProducerSig_, ESDigiCollectionDM_, ESPileInputTag_, ESProducerSig_, edm::ParameterSet::getParameter(), and AlCaHLTBitMon_QueryRunRegistry::string.

39  :
40  label_(ps.getParameter<std::string>("Label"))
41 
42  {
43 
44  // get the subdetector names
45  // this->getSubdetectorNames(); //something like this may be useful to check what we are supposed to do...
46 
47  // declare the products to produce, retrieve
48 
49  EBProducerSig_ = ps.getParameter<edm::InputTag>("EBdigiProducerSig");
50  EEProducerSig_ = ps.getParameter<edm::InputTag>("EEdigiProducerSig");
51  ESProducerSig_ = ps.getParameter<edm::InputTag>("ESdigiProducerSig");
52 
53  EBPileInputTag_ = ps.getParameter<edm::InputTag>("EBPileInputTag");
54  EEPileInputTag_ = ps.getParameter<edm::InputTag>("EEPileInputTag");
55  ESPileInputTag_ = ps.getParameter<edm::InputTag>("ESPileInputTag");
56 
57  EBDigiCollectionDM_ = ps.getParameter<std::string>("EBDigiCollectionDM");
58  EEDigiCollectionDM_ = ps.getParameter<std::string>("EEDigiCollectionDM");
59  ESDigiCollectionDM_ = ps.getParameter<std::string>("ESDigiCollectionDM");
60  // nMaxPrintout_ = ps.getUntrackedParameter<int>("nMaxPrintout",10);
61 
62  //EBalgo_ = new EcalDigiSimpleAlgo();
63  //EEalgo_ = new EcalDigiSimpleAlgo();
64 
65  // don't think I can "produce" in a sub-class...
66 
67  //produces< EBDigiCollection >(EBDigiCollectionDM_);
68  //produces< EEDigiCollection >(EEDigiCollectionDM_);
69 
70  }
T getParameter(std::string const &) const
DataMixingEMDigiWorker::~DataMixingEMDigiWorker ( )
virtual

Default destructor

Definition at line 74 of file DataMixingEMDigiWorker.cc.

74  {
75  }

Member Function Documentation

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

Definition at line 174 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  boost::shared_ptr<Wrapper<EBDigiCollection> const> EBDigisPTR =
183  getProductByTag<EBDigiCollection>(*ep, EBPileInputTag_ );
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  LogDebug("DataMixingEMDigiWorker") << "processed EBDigi with rawId: "
199  << it->id().rawId() << "\n"
200  << " digi energy: " << it->energy();
201 #endif
202  }
203  }
204 
205  // EE Next
206 
207  boost::shared_ptr<Wrapper<EEDigiCollection> const> EEDigisPTR =
208  getProductByTag<EEDigiCollection>(*ep, EEPileInputTag_ );
209 
210  if(EEDigisPTR ) {
211 
212  const EEDigiCollection* EEDigis = const_cast< EEDigiCollection * >(EEDigisPTR->product());
213 
214  LogDebug("DataMixingEMDigiWorker") << "total # EE digis: " << EEDigis->size();
215 
216  for(EEDigiCollection::const_iterator it = EEDigis->begin();
217  it != EEDigis->end(); ++it) {
218 
219  EEDigiStorage_.insert(EEDigiMap::value_type( (it->id()), *it ));
220 
221 #ifdef DEBUG
222  LogDebug("DataMixingEMDigiWorker") << "processed EEDigi with rawId: "
223  << it->id().rawId() << "\n"
224  << " digi energy: " << it->energy();
225 #endif
226  }
227  }
228  // ES Next
229 
230  boost::shared_ptr<Wrapper<ESDigiCollection> const> ESDigisPTR =
231  getProductByTag<ESDigiCollection>(*ep, ESPileInputTag_ );
232 
233  if(ESDigisPTR ) {
234 
235  const ESDigiCollection* ESDigis = const_cast< ESDigiCollection * >(ESDigisPTR->product());
236 
237  LogDebug("DataMixingEMDigiWorker") << "total # ES digis: " << ESDigis->size();
238 
239  for(ESDigiCollection::const_iterator it = ESDigis->begin();
240  it != ESDigis->end(); ++it) {
241 
242  ESDigiStorage_.insert(ESDigiMap::value_type( (it->id()), *it ));
243 
244 #ifdef DEBUG
245  LogDebug("DataMixingEMDigiWorker") << "processed ESDigi with rawId: "
246  << it->id().rawId() << "\n"
247  << " digi energy: " << it->energy();
248 #endif
249  }
250  }
251 
252 
253 
254  }
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
EventID const & id() const
const_iterator begin() const
Container::value_type value_type
const_iterator end() const
void DataMixingEMDigiWorker::addEMSignals ( const edm::Event e,
const edm::EventSetup ES 
)

Definition at line 77 of file DataMixingEMDigiWorker.cc.

References edm::DataFrameContainer::begin(), gather_cfg::cout, EBdigiCollectionSig_, EBDigiStorage_, EBProducerSig_, EEDigiStorage_, EEProducerSig_, edm::DataFrameContainer::end(), ESDigiStorage_, ESProducerSig_, edm::Event::getByLabel(), edm::EventBase::id(), edm::InputTag::label(), LogDebug, edm::Handle< T >::product(), and edm::DataFrameContainer::size().

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

77  {
78  // fill in maps of hits
79 
80  LogInfo("DataMixingEMDigiWorker")<<"===============> adding MC signals for "<<e.id();
81 
82  // EB first
83 
85 
86  const EBDigiCollection* EBDigis = 0;
87 
88  if(e.getByLabel(EBProducerSig_, pEBDigis) ){
89  EBDigis = pEBDigis.product(); // get a ptr to the product
90  LogDebug("DataMixingEMDigiWorker") << "total # EB digis: " << EBDigis->size();
91  }
92  else { std::cout << "NO EBDigis! " << EBProducerSig_.label() << " " << EBdigiCollectionSig_.label() << std::endl;}
93 
94  if (EBDigis)
95  {
96  // loop over digis, storing them in a map so we can add pileup later
97 
98 
99  for(EBDigiCollection::const_iterator it = EBDigis->begin();
100  it != EBDigis->end(); ++it) {
101 
102  EBDigiStorage_.insert(EBDigiMap::value_type( ( it->id() ), *it ));
103 #ifdef DEBUG
104  LogDebug("DataMixingEMDigiWorker") << "processed EBDigi with rawId: "
105  << it->id().rawId() << "\n"
106  << " digi energy: " << it->energy();
107 #endif
108  }
109  }
110 
111  // EE next
112 
114 
115  const EEDigiCollection* EEDigis = 0;
116 
117 
118  if(e.getByLabel(EEProducerSig_, pEEDigis) ){
119  EEDigis = pEEDigis.product(); // get a ptr to the product
120  LogDebug("DataMixingEMDigiWorker") << "total # EE digis: " << EEDigis->size();
121  }
122 
123 
124  if (EEDigis)
125  {
126  // loop over digis, storing them in a map so we can add pileup later
127  for(EEDigiCollection::const_iterator it = EEDigis->begin();
128  it != EEDigis->end(); ++it) {
129 
130  EEDigiStorage_.insert(EEDigiMap::value_type( ( it->id() ), *it ));
131 #ifdef DEBUG
132  LogDebug("DataMixingEMDigiWorker") << "processed EEDigi with rawId: "
133  << it->id().rawId() << "\n"
134  << " digi energy: " << it->energy();
135 #endif
136 
137  }
138  }
139  // ES next
140 
141  Handle< ESDigiCollection > pESDigis;
142 
143  const ESDigiCollection* ESDigis = 0;
144 
145 
146  if(e.getByLabel( ESProducerSig_, pESDigis) ){
147  ESDigis = pESDigis.product(); // get a ptr to the product
148 #ifdef DEBUG
149  LogDebug("DataMixingEMDigiWorker") << "total # ES digis: " << ESDigis->size();
150 #endif
151  }
152 
153 
154  if (ESDigis)
155  {
156 
157  // loop over digis, storing them in a map so we can add pileup later
158  for(ESDigiCollection::const_iterator it = ESDigis->begin();
159  it != ESDigis->end(); ++it) {
160 
161  ESDigiStorage_.insert(ESDigiMap::value_type( ( it->id() ), *it ));
162 
163 #ifdef DEBUG
164  LogDebug("DataMixingEMDigiWorker") << "processed ESDigi with rawId: "
165  << it->id().rawId() << "\n"
166  << " digi energy: " << it->energy();
167 #endif
168 
169  }
170  }
171 
172  } // end of addEMSignals
#define LogDebug(id)
boost::transform_iterator< IterHelp, boost::counting_iterator< int > > const_iterator
const_iterator begin() const
Container::value_type value_type
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
T const * product() const
Definition: Handle.h:74
std::string const & label() const
Definition: InputTag.h:42
const_iterator end() const
edm::EventID id() const
Definition: EventBase.h:56
tuple cout
Definition: gather_cfg.py:121
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 615 of file DataMixingEMDigiWorker.cc.

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

Referenced by putEM().

615  {
616 
617  std::vector<float> gainRatios(3);
618  // get gain ratios
620  ES.get<EcalGainRatiosRcd>().get(grHandle);
621  EcalMGPAGainRatio theRatio= (*grHandle)[detid];
622 
623 
624  gainRatios[0] = 1.;
625  gainRatios[1] = theRatio.gain12Over6();
626  gainRatios[2] = theRatio.gain6Over1() * theRatio.gain12Over6();
627 
628  return gainRatios;
629  }
float gain6Over1() const
const T & get() const
Definition: EventSetup.h:55
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 584 of file DataMixingEMDigiWorker.cc.

References EcalCondObjectContainer< T >::end(), EcalCondObjectContainer< T >::find(), edm::EventSetup::get(), and edm::ESHandle< class >::product().

Referenced by putEM().

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

Definition at line 256 of file DataMixingEMDigiWorker.cc.

References ecalMGPA::adc(), edm::DataFrame::begin(), data, EBDigiCollectionDM_, EBDigiStorage_, EEDigiCollectionDM_, EEDigiStorage_, ESDigiCollectionDM_, ESDigiStorage_, EcalDataFrame::frame(), ecalMGPA::gainId(), GetGainRatios(), GetPedestals(), max(), min, edm::Event::put(), compare_using_db::sample, ESDataFrame::setSample(), EcalDataFrame::setSample(), ESDataFrame::size(), EcalDataFrame::size(), and findQualityFiles::size.

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

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

Member Data Documentation

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

Definition at line 80 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

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

Definition at line 72 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals().

EBDigiMap edm::DataMixingEMDigiWorker::EBDigiStorage_
private

Definition at line 88 of file DataMixingEMDigiWorker.h.

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

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

Definition at line 76 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

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

Definition at line 68 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

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

Definition at line 81 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

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

Definition at line 73 of file DataMixingEMDigiWorker.h.

EEDigiMap edm::DataMixingEMDigiWorker::EEDigiStorage_
private

Definition at line 89 of file DataMixingEMDigiWorker.h.

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

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

Definition at line 77 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

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

Definition at line 69 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

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

Definition at line 82 of file DataMixingEMDigiWorker.h.

Referenced by DataMixingEMDigiWorker(), and putEM().

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

Definition at line 74 of file DataMixingEMDigiWorker.h.

ESDigiMap edm::DataMixingEMDigiWorker::ESDigiStorage_
private

Definition at line 90 of file DataMixingEMDigiWorker.h.

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

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

Definition at line 78 of file DataMixingEMDigiWorker.h.

Referenced by addEMPileups(), and DataMixingEMDigiWorker().

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

Definition at line 70 of file DataMixingEMDigiWorker.h.

Referenced by addEMSignals(), and DataMixingEMDigiWorker().

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