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 
49 
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 }
Handle.h
edm::SortedCollection::const_iterator
std::vector< T >::const_iterator const_iterator
Definition: SortedCollection.h:80
MessageLogger.h
HcalRecHitRecalib::tok_hbhe_
edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
Definition: HcalRecHitRecalib.h:45
edm::Handle::product
T const * product() const
Definition: Handle.h:70
ESHandle.h
HcalRecHitRecalib::hcalfile_
std::string hcalfile_
Definition: HcalRecHitRecalib.h:52
CaloMiscalibMapHcal::print
void print()
Definition: CaloMiscalibMapHcal.h:46
edm::Run
Definition: Run.h:45
HORecHit
Definition: HORecHit.h:11
egHLT::errCodes::HFRecHits
Definition: EgHLTErrCodes.h:21
egHLT::errCodes::HBHERecHits
Definition: EgHLTErrCodes.h:20
edm
HLT enums.
Definition: AlignableModifier.h:19
HBHERecHit
Definition: HBHERecHit.h:13
HcalRecHitRecalib::refactor_mean_
double refactor_mean_
Definition: HcalRecHitRecalib.h:57
edm::SortedCollection
Definition: SortedCollection.h:49
HcalRecNumberingRecord.h
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
HcalRecHitRecalib::hcalfileinpath_
std::string hcalfileinpath_
Definition: HcalRecHitRecalib.h:53
edm::Handle
Definition: AssociativeIterator.h:50
FileInPath.h
edm::FileInPath
Definition: FileInPath.h:64
HFRecHit
Definition: HFRecHit.h:11
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
HcalRecHitRecalib::HcalRecHitRecalib
HcalRecHitRecalib(const edm::ParameterSet &)
Definition: HcalRecHitRecalib.cc:12
ecaldqm::topology
const CaloTopology * topology(nullptr)
edm::SortedCollection::begin
const_iterator begin() const
Definition: SortedCollection.h:262
HcalRecHitRecalib::RecalibHFHits_
std::string RecalibHFHits_
Definition: HcalRecHitRecalib.h:49
edm::ESHandle< HcalTopology >
HcalRecHitRecalib::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: HcalRecHitRecalib.cc:46
CaloMiscalibMapHcal::prefillMap
void prefillMap(const HcalTopology &topology)
Definition: CaloMiscalibMapHcal.h:21
HcalRecNumberingRecord
Definition: HcalRecNumberingRecord.h:23
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalRecHitRecalib::tok_hf_
edm::EDGetTokenT< HFRecHitCollection > tok_hf_
Definition: HcalRecHitRecalib.h:47
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
edm::ParameterSet
Definition: ParameterSet.h:47
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
HcalDetId.h
HcalRecHitRecalib::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: HcalRecHitRecalib.cc:59
HcalRecHitRecalib::mapHcal_
CaloMiscalibMapHcal mapHcal_
Definition: HcalRecHitRecalib.h:55
iEvent
int iEvent
Definition: GenABIO.cc:224
HcalRecHitRecalib::RecalibHOHits_
std::string RecalibHOHits_
Definition: HcalRecHitRecalib.h:50
MiscalibReaderFromXMLHcal.h
edm::EventSetup
Definition: EventSetup.h:57
get
#define get
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
HcalRecHitRecalib::RecalibHBHEHits_
std::string RecalibHBHEHits_
Definition: HcalRecHitRecalib.h:48
CaloMiscalibMapHcal::get
const std::map< uint32_t, float > & get()
Definition: CaloMiscalibMapHcal.h:55
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HcalRecHitRecalib::refactor_
double refactor_
Definition: HcalRecHitRecalib.h:56
MiscalibReaderFromXML::parseXMLMiscalibFile
bool parseXMLMiscalibFile(std::string configFile)
Definition: MiscalibReaderXML.cc:69
HcalRecHitRecalib::tok_ho_
edm::EDGetTokenT< HORecHitCollection > tok_ho_
Definition: HcalRecHitRecalib.h:46
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
MiscalibReaderFromXMLHcal
Definition: MiscalibReaderFromXMLHcal.h:8
HcalRecHitRecalib.h
edm::InputTag
Definition: InputTag.h:15
HcalRecHitRecalib::~HcalRecHitRecalib
~HcalRecHitRecalib() override
Definition: HcalRecHitRecalib.cc:44