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 }
EcalCondObjectContainer::getMap
const self & getMap() const
Definition: EcalCondObjectContainer.h:80
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
EcalCondObjectContainer::end
const_iterator end() const
Definition: EcalCondObjectContainer.h:76
EcalRecHit
Definition: EcalRecHit.h:15
Handle.h
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
EcalRecHitRecalib.h
EcalIntercalibConstants.h
EBDetId
Definition: EBDetId.h:17
edm
HLT enums.
Definition: AlignableModifier.h:19
EcalRecHitRecalib::refactor_
double refactor_
Definition: EcalRecHitRecalib.h:52
EBDetId.h
EEDetId.h
edm::SortedCollection< EcalRecHit >
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EcalRecHitRecalib::refactor_mean_
double refactor_mean_
Definition: EcalRecHitRecalib.h:53
EcalCondObjectContainer< float >
edm::Handle
Definition: AssociativeIterator.h:50
filterRecHits_cfi.EERecHits
EERecHits
Definition: filterRecHits_cfi.py:9
EcalRecHitCollections.h
EcalIntercalibConstant
float EcalIntercalibConstant
Definition: EcalIntercalibConstants.h:10
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
EcalRecHitRecalib::RecalibEndcapHits_
std::string RecalibEndcapHits_
Definition: EcalRecHitRecalib.h:51
EcalRecHitRecalib::EcalRecHitRecalib
EcalRecHitRecalib(const edm::ParameterSet &)
Definition: EcalRecHitRecalib.cc:15
edm::ESHandle
Definition: DTSurvey.h:22
EcalCondObjectContainer::find
const_iterator find(uint32_t rawId) const
Definition: EcalCondObjectContainer.h:53
EEDetId
Definition: EEDetId.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
edm::LogError
Definition: MessageLogger.h:183
EcalRecHitRecalib::endcapHits_
std::string endcapHits_
Definition: EcalRecHitRecalib.h:49
iEvent
int iEvent
Definition: GenABIO.cc:224
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
eostools.move
def move(src, dest)
Definition: eostools.py:511
EcalRecHitRecalib::RecalibBarrelHits_
std::string RecalibBarrelHits_
Definition: EcalRecHitRecalib.h:50
std
Definition: JetResolutionObject.h:76
EventSetup.h
EcalRecHitRecalib::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: EcalRecHitRecalib.cc:32
EcalCondObjectContainer< float >::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalCondObjectContainer.h:19
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
EcalIntercalibConstantsRcd
Definition: EcalIntercalibConstantsRcd.h:5
EcalIntercalibConstantsRcd.h
EcalRecHitRecalib::ecalHitsProducer_
std::string ecalHitsProducer_
Definition: EcalRecHitRecalib.h:47
EcalRecHitRecalib::barrelHits_
std::string barrelHits_
Definition: EcalRecHitRecalib.h:48
EcalRecHitRecalib::~EcalRecHitRecalib
~EcalRecHitRecalib() override
Definition: EcalRecHitRecalib.cc:29
filterRecHits_cfi.EBRecHits
EBRecHits
Definition: filterRecHits_cfi.py:8