test
CMS 3D CMS Logo

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