CMS 3D CMS Logo

HcalRecHitRecalib.cc
Go to the documentation of this file.
2 
6 
9 
11  : tok_hbhe_(consumes<HBHERecHitCollection>(iConfig.getParameter<edm::InputTag>("hbheInput"))),
12  tok_ho_(consumes<HORecHitCollection>(iConfig.getParameter<edm::InputTag>("hoInput"))),
13  tok_hf_(consumes<HFRecHitCollection>(iConfig.getParameter<edm::InputTag>("hfInput"))),
14  topologyToken_(esConsumes<edm::Transition::BeginRun>()),
15  recalibHBHEHits_(iConfig.getParameter<std::string>("RecalibHBHEHitCollection")),
16  recalibHFHits_(iConfig.getParameter<std::string>("RecalibHFHitCollection")),
17  recalibHOHits_(iConfig.getParameter<std::string>("RecalibHOHitCollection")),
18  hcalfileinpath_(iConfig.getUntrackedParameter<std::string>("fileNameHcal", "")),
19  refactor_(iConfig.getUntrackedParameter<double>("Refactor", (double)1)),
20  refactor_mean_(iConfig.getUntrackedParameter<double>("Refactor_mean", (double)1)) {
21  //register your products
22  produces<HBHERecHitCollection>(recalibHBHEHits_);
23  produces<HFRecHitCollection>(recalibHFHits_);
24  produces<HORecHitCollection>(recalibHOHits_);
25 
26  // here read them from xml (particular to HCAL)
27  edm::FileInPath hcalfiletmp("CalibCalorimetry/CaloMiscalibTools/data/" + hcalfileinpath_);
28  hcalfile_ = hcalfiletmp.fullPath();
29 }
30 
32 
35 
37 
39  if (!hcalfile_.empty())
40  hcalreader_.parseXMLMiscalibFile(hcalfile_);
41  mapHcal_.print();
42 }
43 
44 // ------------ method called to produce the data ------------
46  using namespace edm;
47  using namespace std;
48 
49  Handle<HBHERecHitCollection> HBHERecHitsHandle;
50  Handle<HFRecHitCollection> HFRecHitsHandle;
51  Handle<HORecHitCollection> HORecHitsHandle;
52 
53  const HBHERecHitCollection* HBHERecHits = nullptr;
54  const HFRecHitCollection* HFRecHits = nullptr;
55  const HORecHitCollection* HORecHits = nullptr;
56 
57  iEvent.getByToken(tok_hbhe_, HBHERecHitsHandle);
58  if (!HBHERecHitsHandle.isValid()) {
59  LogDebug("") << "HcalREcHitRecalib: Error! can't get product!" << std::endl;
60  } else {
61  HBHERecHits = HBHERecHitsHandle.product(); // get a ptr to the product
62  }
63 
64  iEvent.getByToken(tok_ho_, HORecHitsHandle);
65  if (!HORecHitsHandle.isValid()) {
66  LogDebug("") << "HcalREcHitRecalib: Error! can't get product!" << std::endl;
67  } else {
68  HORecHits = HORecHitsHandle.product(); // get a ptr to the product
69  }
70 
71  iEvent.getByToken(tok_hf_, HFRecHitsHandle);
72  if (!HFRecHitsHandle.isValid()) {
73  LogDebug("") << "HcalREcHitRecalib: Error! can't get product!" << std::endl;
74  } else {
75  HFRecHits = HFRecHitsHandle.product(); // get a ptr to the product
76  }
77 
78  //Create empty output collections
79  auto RecalibHBHERecHitCollection = std::make_unique<HBHERecHitCollection>();
80  auto RecalibHFRecHitCollection = std::make_unique<HFRecHitCollection>();
81  auto RecalibHORecHitCollection = std::make_unique<HORecHitCollection>();
82 
83  if (HBHERecHits) {
85  for (itHBHE = HBHERecHits->begin(); itHBHE != HBHERecHits->end(); ++itHBHE) {
86  // make the rechit with rescaled energy and put in the output collection
87  float icalconst = (mapHcal_.get().find(itHBHE->id().rawId()))->second;
88  icalconst = refactor_mean_ +
89  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
90  HBHERecHit aHit(itHBHE->id(), itHBHE->energy() * icalconst, itHBHE->time());
91 
92  RecalibHBHERecHitCollection->push_back(aHit);
93  }
94  }
95 
96  if (HFRecHits) {
98  for (itHF = HFRecHits->begin(); itHF != HFRecHits->end(); ++itHF) {
99  // make the rechit with rescaled energy and put in the output collection
100  float icalconst = (mapHcal_.get().find(itHF->id().rawId()))->second;
101  icalconst = refactor_mean_ +
102  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
103  HFRecHit aHit(itHF->id(), itHF->energy() * icalconst, itHF->time());
104 
105  RecalibHFRecHitCollection->push_back(aHit);
106  }
107  }
108 
109  if (HORecHits) {
111  for (itHO = HORecHits->begin(); itHO != HORecHits->end(); ++itHO) {
112  // make the rechit with rescaled energy and put in the output collection
113  float icalconst = (mapHcal_.get().find(itHO->id().rawId()))->second;
114  icalconst = refactor_mean_ +
115  (icalconst - refactor_mean_) * refactor_; //apply additional scaling factor (works if gaussian)
116  HORecHit aHit(itHO->id(), itHO->energy() * icalconst, itHO->time());
117 
118  RecalibHORecHitCollection->push_back(aHit);
119  }
120  }
121 
122  //Put Recalibrated rechit in the event
123  iEvent.put(std::move(RecalibHBHERecHitCollection), recalibHBHEHits_);
124  iEvent.put(std::move(RecalibHFRecHitCollection), recalibHFHits_);
125  iEvent.put(std::move(RecalibHORecHitCollection), recalibHOHits_);
126 }
const std::map< uint32_t, float > & get()
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
~HcalRecHitRecalib() override
T const * product() const
Definition: Handle.h:70
std::vector< T >::const_iterator const_iterator
bool parseXMLMiscalibFile(std::string configFile)
HcalRecHitRecalib(const edm::ParameterSet &)
const std::string recalibHOHits_
const edm::EDGetTokenT< HFRecHitCollection > tok_hf_
const std::string hcalfileinpath_
const edm::ESGetToken< HcalTopology, HcalRecNumberingRecord > topologyToken_
void beginRun(const edm::Run &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:224
const std::string recalibHFHits_
const edm::EDGetTokenT< HBHERecHitCollection > tok_hbhe_
Transition
Definition: Transition.h:12
const_iterator begin() const
const_iterator end() const
void produce(edm::Event &, const edm::EventSetup &) override
const std::string recalibHBHEHits_
const double refactor_
CaloMiscalibMapHcal mapHcal_
bool isValid() const
Definition: HandleBase.h:70
void prefillMap(const HcalTopology &topology)
HLT enums.
const edm::EDGetTokenT< HORecHitCollection > tok_ho_
const double refactor_mean_
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45
#define LogDebug(id)