CMS 3D CMS Logo

HcalRecHitRecalib.cc
Go to the documentation of this file.
2 
8 
11 
13  tok_hbhe_ = consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"));
14  tok_ho_ = consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"));
15  tok_hf_ = consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInput"));
16 
17  // HBHEHitsProducer_ = iConfig.getParameter< std::string > ("HBHERecHitsProducer");
18  // HOHitsProducer_ = iConfig.getParameter< std::string > ("HERecHitsProducer");
19  // HFHitsProducer_ = iConfig.getParameter< std::string > ("HERecHitsProducer");
20  // HBHEHits_ = iConfig.getParameter< std::string > ("HBHEHitCollection");
21  // HFHits_ = iConfig.getParameter< std::string > ("HFHitCollection");
22  // HOHits_ = iConfig.getParameter< std::string > ("HOHitCollection");
23 
24  RecalibHBHEHits_ = iConfig.getParameter<std::string>("RecalibHBHEHitCollection");
25  RecalibHFHits_ = iConfig.getParameter<std::string>("RecalibHFHitCollection");
26  RecalibHOHits_ = iConfig.getParameter<std::string>("RecalibHOHitCollection");
27 
28  refactor_ = iConfig.getUntrackedParameter<double>("Refactor", (double)1);
29  refactor_mean_ = iConfig.getUntrackedParameter<double>("Refactor_mean", (double)1);
30 
31  //register your products
32  produces<HBHERecHitCollection>(RecalibHBHEHits_);
33  produces<HFRecHitCollection>(RecalibHFHits_);
34  produces<HORecHitCollection>(RecalibHOHits_);
35 
36  // here read them from xml (particular to HCAL)
37 
38  hcalfileinpath_ = iConfig.getUntrackedParameter<std::string>("fileNameHcal", "");
39  edm::FileInPath hcalfiletmp("CalibCalorimetry/CaloMiscalibTools/data/" + hcalfileinpath_);
40 
41  hcalfile_ = hcalfiletmp.fullPath();
42 }
43 
45 
48  iSetup.get<HcalRecNumberingRecord>().get(topology);
49 
50  mapHcal_.prefillMap(*topology);
51 
53  if (!hcalfile_.empty())
54  hcalreader_.parseXMLMiscalibFile(hcalfile_);
55  mapHcal_.print();
56 }
57 
58 // ------------ method called to produce the data ------------
60  using namespace edm;
61  using namespace std;
62 
63  Handle<HBHERecHitCollection> HBHERecHitsHandle;
64  Handle<HFRecHitCollection> HFRecHitsHandle;
65  Handle<HORecHitCollection> HORecHitsHandle;
66 
67  const HBHERecHitCollection* HBHERecHits = nullptr;
68  const HFRecHitCollection* HFRecHits = nullptr;
69  const HORecHitCollection* HORecHits = nullptr;
70 
71  iEvent.getByToken(tok_hbhe_, HBHERecHitsHandle);
72  if (!HBHERecHitsHandle.isValid()) {
73  LogDebug("") << "HcalREcHitRecalib: Error! can't get product!" << std::endl;
74  } else {
75  HBHERecHits = HBHERecHitsHandle.product(); // get a ptr to the product
76  }
77 
78  iEvent.getByToken(tok_ho_, HORecHitsHandle);
79  if (!HORecHitsHandle.isValid()) {
80  LogDebug("") << "HcalREcHitRecalib: Error! can't get product!" << std::endl;
81  } else {
82  HORecHits = HORecHitsHandle.product(); // get a ptr to the product
83  }
84 
85  iEvent.getByToken(tok_hf_, HFRecHitsHandle);
86  if (!HFRecHitsHandle.isValid()) {
87  LogDebug("") << "HcalREcHitRecalib: Error! can't get product!" << std::endl;
88  } else {
89  HFRecHits = HFRecHitsHandle.product(); // get a ptr to the product
90  }
91 
92  // iEvent.getByLabel(HBHEHitsProducer_,HBHEHits_,HBHERecHitsHandle);
93  // HBHERecHits = HBHERecHitsHandle.product(); // get a ptr to the product
94 
95  // iEvent.getByLabel(HFHitsProducer_,HFHits_,HFRecHitsHandle);
96  // HFRecHits = HFRecHitsHandle.product(); // get a ptr to the product
97 
98  // iEvent.getByLabel(HOHitsProducer_,HOHits_,HORecHitsHandle);
99  // HORecHits = HORecHitsHandle.product(); // get a ptr to the product
100 
101  //Create empty output collections
102  auto RecalibHBHERecHitCollection = std::make_unique<HBHERecHitCollection>();
103  auto RecalibHFRecHitCollection = std::make_unique<HFRecHitCollection>();
104  auto RecalibHORecHitCollection = std::make_unique<HORecHitCollection>();
105 
106  // Intercalib constants
107  // edm::ESHandle<EcalIntercalibConstants> pIcal;
108  // iSetup.get<EcalIntercalibConstantsRcd>().get(pIcal);
109  // const EcalIntercalibConstants* ical = pIcal.product();
110 
111  if (HBHERecHits) {
112  //loop on all EcalRecHits (barrel)
114  for (itHBHE = HBHERecHits->begin(); itHBHE != HBHERecHits->end(); ++itHBHE) {
115  // find intercalib constant for this cell
116 
117  // EcalIntercalibConstants::EcalIntercalibConstantMap::const_iterator icalit=ical->getMap().find(itb->id().rawId());
118  // EcalIntercalibConstants::EcalIntercalibConstant icalconst;
119 
120  // if( icalit!=ical->getMap().end() ){
121  // icalconst = icalit->second;
122  // edm::LogDebug("EcalRecHitMiscalib") << "Found intercalib for xtal " << EBDetId(itb->id()) << " " << icalconst ;
123 
124  // } else {
125  // edm::LogError("EcalRecHitMiscalib") << "No intercalib const found for xtal " << EBDetId(itb->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
126  // ;
127  // }
128 
129  float icalconst = (mapHcal_.get().find(itHBHE->id().rawId()))->second;
130  // make the rechit with rescaled energy and put in the output collection
131 
132  icalconst = refactor_mean_ +
133  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
134  HBHERecHit aHit(itHBHE->id(), itHBHE->energy() * icalconst, itHBHE->time());
135 
136  RecalibHBHERecHitCollection->push_back(aHit);
137  }
138  }
139 
140  if (HFRecHits) {
141  //loop on all EcalRecHits (barrel)
143  for (itHF = HFRecHits->begin(); itHF != HFRecHits->end(); ++itHF) {
144  // find intercalib constant for this cell
145 
146  // EcalIntercalibConstants::EcalIntercalibConstantMap::const_iterator icalit=ical->getMap().find(itb->id().rawId());
147  // EcalIntercalibConstants::EcalIntercalibConstant icalconst;
148 
149  // if( icalit!=ical->getMap().end() ){
150  // icalconst = icalit->second;
151  // edm::LogDebug("EcalRecHitMiscalib") << "Found intercalib for xtal " << EBDetId(itb->id()) << " " << icalconst ;
152 
153  // } else {
154  // edm::LogError("EcalRecHitMiscalib") << "No intercalib const found for xtal " << EBDetId(itb->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
155  // ;
156  // }
157 
158  // make the rechit with rescaled energy and put in the output collection
159 
160  float icalconst = (mapHcal_.get().find(itHF->id().rawId()))->second;
161  icalconst = refactor_mean_ +
162  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
163  HFRecHit aHit(itHF->id(), itHF->energy() * icalconst, itHF->time());
164 
165  RecalibHFRecHitCollection->push_back(aHit);
166  }
167  }
168 
169  if (HORecHits) {
170  //loop on all EcalRecHits (barrel)
172  for (itHO = HORecHits->begin(); itHO != HORecHits->end(); ++itHO) {
173  // find intercalib constant for this cell
174 
175  // EcalIntercalibConstants::EcalIntercalibConstantMap::const_iterator icalit=ical->getMap().find(itb->id().rawId());
176  // EcalIntercalibConstants::EcalIntercalibConstant icalconst;
177 
178  // if( icalit!=ical->getMap().end() ){
179  // icalconst = icalit->second;
180  // edm::LogDebug("EcalRecHitMiscalib") << "Found intercalib for xtal " << EBDetId(itb->id()) << " " << icalconst ;
181 
182  // } else {
183  // edm::LogError("EcalRecHitMiscalib") << "No intercalib const found for xtal " << EBDetId(itb->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
184  // ;
185  // }
186 
187  // make the rechit with rescaled energy and put in the output collection
188 
189  float icalconst = (mapHcal_.get().find(itHO->id().rawId()))->second;
190  icalconst = refactor_mean_ +
191  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
192  HORecHit aHit(itHO->id(), itHO->energy() * icalconst, itHO->time());
193 
194  RecalibHORecHitCollection->push_back(aHit);
195  }
196  }
197 
198  //Put Recalibrated rechit in the event
199  iEvent.put(std::move(RecalibHBHERecHitCollection), RecalibHBHEHits_);
200  iEvent.put(std::move(RecalibHFRecHitCollection), RecalibHFHits_);
201  iEvent.put(std::move(RecalibHORecHitCollection), RecalibHOHits_);
202 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
const std::map< uint32_t, float > & get()
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
~HcalRecHitRecalib() override
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< T >::const_iterator const_iterator
bool parseXMLMiscalibFile(std::string configFile)
HcalRecHitRecalib(const edm::ParameterSet &)
std::string RecalibHFHits_
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::string hcalfileinpath_
int iEvent
Definition: GenABIO.cc:224
std::string RecalibHOHits_
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< HFRecHitCollection > tok_hf_
std::string RecalibHBHEHits_
const_iterator end() const
void produce(edm::Event &, const edm::EventSetup &) override
T const * product() const
Definition: Handle.h:74
CaloMiscalibMapHcal mapHcal_
void prefillMap(const HcalTopology &topology)
HLT enums.
T get() const
Definition: EventSetup.h:71
edm::EDGetTokenT< HORecHitCollection > tok_ho_
def move(src, dest)
Definition: eostools.py:511
const_iterator begin() const
Definition: Run.h:45