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 
16 
19 
21 
22 #include <iostream>
23 #include <cmath>
24 #include <vector>
25 
26 
31 
32 
33 
35 
36  EBRecHitCollection_ = ps.getParameter<edm::InputTag>("EBRecHitCollection");
37  EERecHitCollection_ = ps.getParameter<edm::InputTag>("EERecHitCollection");
38  EBRecHitToken_ = consumes<EBRecHitCollection>(EBRecHitCollection_);
39  EERecHitToken_ = consumes<EBRecHitCollection>(EERecHitCollection_);
40  EBRecalibRecHitCollection_ = ps.getParameter<std::string>("EBRecalibRecHitCollection");
41  EERecalibRecHitCollection_ = ps.getParameter<std::string>("EERecalibRecHitCollection");
42  doEnergyScale_ = ps.getParameter<bool>("doEnergyScale");
43  doIntercalib_ = ps.getParameter<bool>("doIntercalib");
44  doLaserCorrections_ = ps.getParameter<bool>("doLaserCorrections");
45 
46  doEnergyScaleInverse_ = ps.getParameter<bool>("doEnergyScaleInverse");
47  doIntercalibInverse_ = ps.getParameter<bool>("doIntercalibInverse");
48  doLaserCorrectionsInverse_ = ps.getParameter<bool>("doLaserCorrectionsInverse");
49 
52 
53  produces< EBRecHitCollection >(EBRecalibRecHitCollection_);
54  produces< EERecHitCollection >(EERecalibRecHitCollection_);
55 }
56 
58 
59  if (EBalgo_) delete EBalgo_;
60  if (EEalgo_) delete EEalgo_;
61 
62 }
63 
65 {
66  using namespace edm;
69 
70  const EBRecHitCollection* EBRecHits = 0;
71  const EERecHitCollection* EERecHits = 0;
72 
73  if ( EBRecHitCollection_.label() != "" ) {
74  evt.getByToken( EBRecHitToken_, pEBRecHits);
75  EBRecHits = pEBRecHits.product(); // get a ptr to the product
76  }
77  if ( EERecHitCollection_.label() != "" ) {
78  evt.getByToken( EERecHitToken_, pEERecHits);
79  EERecHits = pEERecHits.product(); // get a ptr to the product
80  }
81 
82  // collection of rechits to put in the event
83  std::auto_ptr< EBRecHitCollection > EBRecalibRecHits( new EBRecHitCollection );
84  std::auto_ptr< EERecHitCollection > EERecalibRecHits( new EERecHitCollection );
85 
86  // now fetch all conditions we need to make rechits
87  // ADC to GeV constant
89  const EcalADCToGeVConstant *agc = 0;
90  float agc_eb = 1.;
91  float agc_ee = 1.;
92  if (doEnergyScale_) {
93  es.get<EcalADCToGeVConstantRcd>().get(pAgc);
94  agc = pAgc.product();
95  // use this value in the algorithm
96  agc_eb = float(agc->getEBValue());
97  agc_ee = float(agc->getEEValue());
98  }
99  // Intercalib constants
101  const EcalIntercalibConstants *ical = 0;
102  if (doIntercalib_) {
103  es.get<EcalIntercalibConstantsRcd>().get(pIcal);
104  ical = pIcal.product();
105  }
106  // Laser corrections
108  es.get<EcalLaserDbRecord>().get( pLaser );
109 
110 
112  agc_eb = 1.0/agc_eb;
113  agc_ee = 1.0/agc_ee;
114  }
115 
116 
117  if (EBRecHits) {
118  // loop over uncalibrated rechits to make calibrated ones
119  for(EBRecHitCollection::const_iterator it = EBRecHits->begin(); it != EBRecHits->end(); ++it) {
120 
121  EcalIntercalibConstant icalconst = 1.;
122  if (doIntercalib_) {
123  // find intercalib constant for this xtal
124  const EcalIntercalibConstantMap &icalMap = ical->getMap();
125  EcalIntercalibConstantMap::const_iterator icalit = icalMap.find(it->id());
126  if( icalit!=icalMap.end() ){
127  icalconst = (*icalit);
128  } else {
129  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EBDetId(it->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
130  ;
131  }
132  }
133  // get laser coefficient
134  float lasercalib = 1;
135  if (doLaserCorrections_) {
136  lasercalib = pLaser->getLaserCorrection( EBDetId(it->id()), evt.time() );
137  }
138 
139  // make the rechit and put in the output collection
140  // must implement op= for EcalRecHit
141 
143  icalconst = 1.0/icalconst;
144  }
146  lasercalib = 1.0/lasercalib;
147  }
148 
149  EcalRecHit aHit( (*it).id(), (*it).energy() * agc_eb * icalconst * lasercalib, (*it).time() );
150  EBRecalibRecHits->push_back( aHit );
151  }
152  }
153 
154  if (EERecHits)
155  {
156  // loop over uncalibrated rechits to make calibrated ones
158  it != EERecHits->end(); ++it) {
159 
160  // find intercalib constant for this xtal
161  EcalIntercalibConstant icalconst = 1.;
162  if (doIntercalib_) {
163  const EcalIntercalibConstantMap &icalMap = ical->getMap();
164  EcalIntercalibConstantMap::const_iterator icalit=icalMap.find(it->id());
165  if( icalit!=icalMap.end() ) {
166  icalconst = (*icalit);
167  } else {
168  edm::LogError("EcalRecHitError") << "No intercalib const found for xtal " << EEDetId(it->id()) << "! something wrong with EcalIntercalibConstants in your DB? ";
169  }
170  }
171  // get laser coefficient
172  float lasercalib = 1;
173  if (doLaserCorrections_) {
174  lasercalib = pLaser->getLaserCorrection( EEDetId(it->id()), evt.time() );
175  }
176 
177  // make the rechit and put in the output collection
178  // must implement op= for EcalRecHit
179  //EcalRecHit aHit( EEalgo_->makeRecHit(*it, icalconst * lasercalib) );
180 
182  icalconst = 1.0/icalconst;
183  }
185  lasercalib = 1.0/lasercalib;
186  }
187 
188  EcalRecHit aHit( (*it).id(), (*it).energy() * agc_ee * icalconst * lasercalib, (*it).time() );
189  EERecalibRecHits->push_back( aHit );
190  }
191  }
192  // put the collection of recunstructed hits in the event
193  LogInfo("EcalRecalibRecHitInfo") << "total # EB re-calibrated rechits: " << EBRecalibRecHits->size();
194  LogInfo("EcalRecalibRecHitInfo") << "total # EE re-calibrated rechits: " << EERecalibRecHits->size();
195 
196  evt.put( EBRecalibRecHits, EBRecalibRecHitCollection_ );
197  evt.put( EERecalibRecHits, EERecalibRecHitCollection_ );
198 }
199 
edm::EDGetTokenT< EERecHitCollection > EERecHitToken_
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
const self & getMap() const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< EcalRecHit >::const_iterator const_iterator
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
edm::EDGetTokenT< EBRecHitCollection > EBRecHitToken_
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:42
const_iterator find(uint32_t rawId) const
const_iterator end() const
edm::Timestamp time() const
Definition: EventBase.h:57
float EcalIntercalibConstant