CMS 3D CMS Logo

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