CMS 3D CMS Logo

EcalRecHitRecalib.cc
Go to the documentation of this file.
1 
4 
8 
14 
16 {
17  ecalHitsProducer_ = iConfig.getParameter< std::string > ("ecalRecHitsProducer");
18  barrelHits_ = iConfig.getParameter< std::string > ("barrelHitCollection");
19  endcapHits_ = iConfig.getParameter< std::string > ("endcapHitCollection");
20  RecalibBarrelHits_ = iConfig.getParameter< std::string > ("RecalibBarrelHitCollection");
21  RecalibEndcapHits_ = iConfig.getParameter< std::string > ("RecalibEndcapHitCollection");
22  refactor_ = iConfig.getUntrackedParameter<double> ("Refactor",(double)1);
23  refactor_mean_ = iConfig.getUntrackedParameter<double> ("Refactor_mean",(double)1);
24 
25  //register your products
26  produces< EBRecHitCollection >(RecalibBarrelHits_);
27  produces< EERecHitCollection >(RecalibEndcapHits_);
28 }
29 
30 
32 {
33 
34 
35 }
36 
37 
38 // ------------ method called to produce the data ------------
39 void
41 {
42  using namespace edm;
43  using namespace std;
44 
45  Handle<EBRecHitCollection> barrelRecHitsHandle;
46  Handle<EERecHitCollection> endcapRecHitsHandle;
47 
48  const EBRecHitCollection* EBRecHits = nullptr;
49  const EERecHitCollection* EERecHits = nullptr;
50 
51  iEvent.getByLabel(ecalHitsProducer_,barrelHits_,barrelRecHitsHandle);
52  if (!barrelRecHitsHandle.isValid()) {
53  LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
54  } else {
55  EBRecHits = barrelRecHitsHandle.product(); // get a ptr to the product
56  }
57 
58  iEvent.getByLabel(ecalHitsProducer_,endcapHits_,endcapRecHitsHandle);
59  if (!endcapRecHitsHandle.isValid()) {
60  LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
61  } else {
62  EERecHits = endcapRecHitsHandle.product(); // get a ptr to the product
63  }
64 
65  //Create empty output collections
66  auto RecalibEBRecHitCollection = std::make_unique<EBRecHitCollection>();
67  auto RecalibEERecHitCollection = std::make_unique<EERecHitCollection>();
68 
69 
70  // Intercalib constants
72  iSetup.get<EcalIntercalibConstantsRcd>().get(pIcal);
73  const EcalIntercalibConstants* ical = pIcal.product();
74 
75  if(EBRecHits)
76  {
77 
78  //loop on all EcalRecHits (barrel)
80  for (itb=EBRecHits->begin(); itb!=EBRecHits->end(); ++itb) {
81 
82  // find intercalib constant for this xtal
83  EcalIntercalibConstantMap::const_iterator icalit=ical->getMap().find(itb->id().rawId());
84  EcalIntercalibConstant icalconst = -1;
85 
86  if( icalit!=ical->getMap().end() ){
87  icalconst = (*icalit);
88  // edm::LogDebug("EcalRecHitRecalib") << "Found intercalib for xtal " << EBDetId(itb->id()) << " " << icalconst ;
89 
90  } else {
91  edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EBDetId(itb->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
92  ;
93  }
94 
95  // make the rechit with rescaled energy and put in the output collection
96  icalconst=refactor_mean_+(icalconst-refactor_mean_)*refactor_; //apply additional scaling factor (works if gaussian)
97  EcalRecHit aHit(itb->id(),itb->energy()*icalconst,itb->time());
98 
99  RecalibEBRecHitCollection->push_back( aHit);
100  }
101  }
102 
103  if(EERecHits)
104  {
105 
106  //loop on all EcalRecHits (barrel)
108  for (ite=EERecHits->begin(); ite!=EERecHits->end(); ++ite) {
109 
110  // find intercalib constant for this xtal
111  EcalIntercalibConstantMap::const_iterator icalit=ical->getMap().find(ite->id().rawId());
112  EcalIntercalibConstant icalconst = -1;
113 
114  if( icalit!=ical->getMap().end() ){
115  icalconst = (*icalit);
116  // edm:: LogDebug("EcalRecHitRecalib") << "Found intercalib for xtal " << EEDetId(ite->id()) << " " << icalconst ;
117  } else {
118  edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EEDetId(ite->id()) << "! something wrong with EcalIntercalibConstants in your DB? "
119  ;
120  }
121 
122  // make the rechit with rescaled energy and put in the output collection
123 
124  icalconst=refactor_mean_+(icalconst-refactor_mean_)*refactor_; //apply additional scaling factor (works if gaussian)
125  EcalRecHit aHit(ite->id(),ite->energy()*icalconst,ite->time());
126 
127  RecalibEERecHitCollection->push_back( aHit);
128  }
129  }
130 
131 
132  //Put Recalibrated rechit in the event
133  iEvent.put(std::move(RecalibEBRecHitCollection), RecalibBarrelHits_);
134  iEvent.put(std::move(RecalibEERecHitCollection), RecalibEndcapHits_);
135 
136 }
137 
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
~EcalRecHitRecalib() override
const self & getMap() const
std::vector< EcalRecHit >::const_iterator const_iterator
EcalRecHitRecalib(const edm::ParameterSet &)
int iEvent
Definition: GenABIO.cc:230
std::string RecalibEndcapHits_
bool isValid() const
Definition: HandleBase.h:74
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
const_iterator end() const
T const * product() const
Definition: Handle.h:81
std::vector< Item >::const_iterator const_iterator
std::string endcapHits_
HLT enums.
std::string RecalibBarrelHits_
void produce(edm::Event &, const edm::EventSetup &) override
std::string barrelHits_
T get() const
Definition: EventSetup.h:63
const_iterator find(uint32_t rawId) const
const_iterator end() const
std::string ecalHitsProducer_
def move(src, dest)
Definition: eostools.py:510
const_iterator begin() const
float EcalIntercalibConstant