CMS 3D CMS Logo

EcalRecHitRecalib.cc
Go to the documentation of this file.
1 
4 
8 
14 
16  ecalHitsProducer_ = iConfig.getParameter<std::string>("ecalRecHitsProducer");
17  barrelHits_ = iConfig.getParameter<std::string>("barrelHitCollection");
18  endcapHits_ = iConfig.getParameter<std::string>("endcapHitCollection");
19  RecalibBarrelHits_ = iConfig.getParameter<std::string>("RecalibBarrelHitCollection");
20  RecalibEndcapHits_ = iConfig.getParameter<std::string>("RecalibEndcapHitCollection");
21  refactor_ = iConfig.getUntrackedParameter<double>("Refactor", (double)1);
22  refactor_mean_ = iConfig.getUntrackedParameter<double>("Refactor_mean", (double)1);
23 
24  //register your products
25  produces<EBRecHitCollection>(RecalibBarrelHits_);
26  produces<EERecHitCollection>(RecalibEndcapHits_);
27 }
28 
30 
31 // ------------ method called to produce the data ------------
33  using namespace edm;
34  using namespace std;
35 
36  Handle<EBRecHitCollection> barrelRecHitsHandle;
37  Handle<EERecHitCollection> endcapRecHitsHandle;
38 
39  const EBRecHitCollection* EBRecHits = nullptr;
40  const EERecHitCollection* EERecHits = nullptr;
41 
42  iEvent.getByLabel(ecalHitsProducer_, barrelHits_, barrelRecHitsHandle);
43  if (!barrelRecHitsHandle.isValid()) {
44  LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
45  } else {
46  EBRecHits = barrelRecHitsHandle.product(); // get a ptr to the product
47  }
48 
49  iEvent.getByLabel(ecalHitsProducer_, endcapHits_, endcapRecHitsHandle);
50  if (!endcapRecHitsHandle.isValid()) {
51  LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
52  } else {
53  EERecHits = endcapRecHitsHandle.product(); // get a ptr to the product
54  }
55 
56  //Create empty output collections
57  auto RecalibEBRecHitCollection = std::make_unique<EBRecHitCollection>();
58  auto RecalibEERecHitCollection = std::make_unique<EERecHitCollection>();
59 
60  // Intercalib constants
62  iSetup.get<EcalIntercalibConstantsRcd>().get(pIcal);
63  const EcalIntercalibConstants* ical = pIcal.product();
64 
65  if (EBRecHits) {
66  //loop on all EcalRecHits (barrel)
68  for (itb = EBRecHits->begin(); itb != EBRecHits->end(); ++itb) {
69  // find intercalib constant for this xtal
70  EcalIntercalibConstantMap::const_iterator icalit = ical->getMap().find(itb->id().rawId());
71  EcalIntercalibConstant icalconst = -1;
72 
73  if (icalit != ical->getMap().end()) {
74  icalconst = (*icalit);
75  // edm::LogDebug("EcalRecHitRecalib") << "Found intercalib for xtal " << EBDetId(itb->id()) << " " << icalconst ;
76 
77  } else {
78  edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EBDetId(itb->id())
79  << "! something wrong with EcalIntercalibConstants in your DB? ";
80  }
81 
82  // make the rechit with rescaled energy and put in the output collection
83  icalconst = refactor_mean_ +
84  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
85  EcalRecHit aHit(itb->id(), itb->energy() * icalconst, itb->time());
86 
87  RecalibEBRecHitCollection->push_back(aHit);
88  }
89  }
90 
91  if (EERecHits) {
92  //loop on all EcalRecHits (barrel)
94  for (ite = EERecHits->begin(); ite != EERecHits->end(); ++ite) {
95  // find intercalib constant for this xtal
96  EcalIntercalibConstantMap::const_iterator icalit = ical->getMap().find(ite->id().rawId());
97  EcalIntercalibConstant icalconst = -1;
98 
99  if (icalit != ical->getMap().end()) {
100  icalconst = (*icalit);
101  // edm:: LogDebug("EcalRecHitRecalib") << "Found intercalib for xtal " << EEDetId(ite->id()) << " " << icalconst ;
102  } else {
103  edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EEDetId(ite->id())
104  << "! something wrong with EcalIntercalibConstants in your DB? ";
105  }
106 
107  // make the rechit with rescaled energy and put in the output collection
108 
109  icalconst = refactor_mean_ +
110  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
111  EcalRecHit aHit(ite->id(), ite->energy() * icalconst, ite->time());
112 
113  RecalibEERecHitCollection->push_back(aHit);
114  }
115  }
116 
117  //Put Recalibrated rechit in the event
118  iEvent.put(std::move(RecalibEBRecHitCollection), RecalibBarrelHits_);
119  iEvent.put(std::move(RecalibEERecHitCollection), RecalibEndcapHits_);
120 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
~EcalRecHitRecalib() override
const self & getMap() const
std::vector< EcalRecHit >::const_iterator const_iterator
EcalRecHitRecalib(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:224
std::string RecalibEndcapHits_
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
const_iterator end() const
T const * product() const
Definition: Handle.h:74
std::vector< Item >::const_iterator const_iterator
std::string endcapHits_
HLT enums.
std::string RecalibBarrelHits_
void produce(edm::Event &, const edm::EventSetup &) override
std::string barrelHits_
T get() const
Definition: EventSetup.h:71
const_iterator find(uint32_t rawId) const
const_iterator end() const
std::string ecalHitsProducer_
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const
float EcalIntercalibConstant