CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalRecalibRecHitProducer.cc
Go to the documentation of this file.
1 
19 
22 
24 
25 #include <iostream>
26 #include <cmath>
27 #include <vector>
28 
29 //#include "CondFormats/EcalObjects/interface/EcalPedestals.h"
30 //#include "CondFormats/DataRecord/interface/EcalPedestalsRcd.h"
36 
37 
38 
40 
41  EBRecHitCollection_ = ps.getParameter<edm::InputTag>("EBRecHitCollection");
42  EERecHitCollection_ = ps.getParameter<edm::InputTag>("EERecHitCollection");
43  EBRecalibRecHitCollection_ = ps.getParameter<std::string>("EBRecalibRecHitCollection");
44  EERecalibRecHitCollection_ = ps.getParameter<std::string>("EERecalibRecHitCollection");
45  doEnergyScale_ = ps.getParameter<bool>("doEnergyScale");
46  doIntercalib_ = ps.getParameter<bool>("doIntercalib");
47  doLaserCorrections_ = ps.getParameter<bool>("doLaserCorrections");
48 
51 
52  produces< EBRecHitCollection >(EBRecalibRecHitCollection_);
53  produces< EERecHitCollection >(EERecalibRecHitCollection_);
54 }
55 
57 
58  if (EBalgo_) delete EBalgo_;
59  if (EEalgo_) delete EEalgo_;
60 
61 }
62 
64 {
65  using namespace edm;
68 
69  const EBRecHitCollection* EBRecHits = 0;
70  const EERecHitCollection* EERecHits = 0;
71 
72  if ( EBRecHitCollection_.label() != "" && EBRecHitCollection_.instance() != "" ) {
73  evt.getByLabel( EBRecHitCollection_, pEBRecHits);
74  if ( pEBRecHits.isValid() ) {
75  EBRecHits = pEBRecHits.product(); // get a ptr to the product
76 #ifdef DEBUG
77  LogDebug("EcalRecHitDebug") << "total # EB rechits to be re-calibrated: " << EBRecHits->size();
78 #endif
79  } else {
80  edm::LogError("EcalRecHitError") << "Error! can't get the product " << EBRecHitCollection_.label() ;
81  }
82  }
83 
84  if ( EERecHitCollection_.label() != "" && EERecHitCollection_.instance() != "" ) {
85  evt.getByLabel( EERecHitCollection_, pEERecHits);
86  if ( pEERecHits.isValid() ) {
87  EERecHits = pEERecHits.product(); // get a ptr to the product
88 #ifdef DEBUG
89  LogDebug("EcalRecHitDebug") << "total # EE uncalibrated rechits to be re-calibrated: " << EERecHits->size();
90 #endif
91  } else {
92  edm::LogError("EcalRecHitError") << "Error! can't get the product " << EERecHitCollection_.label() ;
93  }
94  }
95 
96  // collection of rechits to put in the event
97  std::auto_ptr< EBRecHitCollection > EBRecalibRecHits( new EBRecHitCollection );
98  std::auto_ptr< EERecHitCollection > EERecalibRecHits( new EERecHitCollection );
99 
100  // now fetch all conditions we need to make rechits
101  // ADC to GeV constant
103  const EcalADCToGeVConstant *agc = 0;
104  float agc_eb = 1.;
105  float agc_ee = 1.;
106  if (doEnergyScale_) {
107  es.get<EcalADCToGeVConstantRcd>().get(pAgc);
108  agc = pAgc.product();
109  // use this value in the algorithm
110  agc_eb = float(agc->getEBValue());
111  agc_ee = float(agc->getEEValue());
112  }
113  // Intercalib constants
115  const EcalIntercalibConstants *ical = 0;
116  if (doIntercalib_) {
117  es.get<EcalIntercalibConstantsRcd>().get(pIcal);
118  ical = pIcal.product();
119  }
120  // Laser corrections
122  es.get<EcalLaserDbRecord>().get( pLaser );
123 
124  if (EBRecHits) {
125  // loop over uncalibrated rechits to make calibrated ones
126  for(EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
127 
128  EcalIntercalibConstant icalconst = 1.;
129  if (doIntercalib_) {
130  // find intercalib constant for this xtal
131  const EcalIntercalibConstantMap &icalMap = ical->getMap();
132  EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(it->id());
133  if( icalit!=icalMap.end() ){
134  icalconst = (*icalit);
135  } else {
136  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(it->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
137  ;
138  }
139  }
140  // get laser coefficient
141  float lasercalib = 1;
142  if (doLaserCorrections_) {
143  lasercalib = pLaser->getLaserCorrection( EBDetId(it->id()), evt.time() );
144  }
145 
146  // make the rechit and put in the output collection
147  // must implement op= for EcalRecHit
148  EcalRecHit aHit( (*it).id(), (*it).energy() * agc_eb * icalconst * lasercalib, (*it).time() );
149  EBRecalibRecHits->push_back( aHit );
150  }
151  }
152 
153  if (EERecHits)
154  {
155  // loop over uncalibrated rechits to make calibrated ones
157  it != EERecHits->end(); ++it) {
158 
159  // find intercalib constant for this xtal
160  EcalIntercalibConstant icalconst = 1.;
161  if (doIntercalib_) {
162  const EcalIntercalibConstantMap &icalMap = ical->getMap();
163  EcalIntercalibConstantMap::const_iterator icalit=icalMap.find(it->id());
164  if( icalit!=icalMap.end() ) {
165  icalconst = (*icalit);
166  } else {
167  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EEDetId(it->id()) << "! something wrong with EcalIntercalibConstants in your DB? ";
168  }
169  }
170  // get laser coefficient
171  float lasercalib = 1;
172  if (doLaserCorrections_) {
173  lasercalib = pLaser->getLaserCorrection( EEDetId(it->id()), evt.time() );
174  }
175 
176  // make the rechit and put in the output collection
177  // must implement op= for EcalRecHit
178  //EcalRecHit aHit( EEalgo_->makeRecHit(*it, icalconst * lasercalib) );
179  EcalRecHit aHit( (*it).id(), (*it).energy() * agc_ee * icalconst * lasercalib, (*it).time() );
180  EERecalibRecHits->push_back( aHit );
181  }
182  }
183  // put the collection of recunstructed hits in the event
184  LogInfo("EcalRecalibRecHitInfo") << "total # EB re-calibrated rechits: " << EBRecalibRecHits->size();
185  LogInfo("EcalRecalibRecHitInfo") << "total # EE re-calibrated rechits: " << EERecalibRecHits->size();
186 
187  evt.put( EBRecalibRecHits, EBRecalibRecHitCollection_ );
188  evt.put( EERecalibRecHits, EERecalibRecHitCollection_ );
189 }
190 
#define LogDebug(id)
T getParameter(std::string const &) const
const self & getMap() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< T >::const_iterator const_iterator
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
EcalRecalibRecHitProducer(const edm::ParameterSet &ps)
const T & get() const
Definition: EventSetup.h:55
std::vector< Item >::const_iterator const_iterator
virtual void produce(edm::Event &evt, const edm::EventSetup &es)
std::string const & label() const
Definition: InputTag.h:25
const_iterator find(uint32_t rawId) const
const_iterator end() const
std::string const & instance() const
Definition: InputTag.h:26
edm::Timestamp time() const
Definition: EventBase.h:57
float EcalIntercalibConstant