Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-16 03:23:17

0001 #include "DataFormats/Common/interface/Handle.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 
0004 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0005 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0006 #include "CalibCalorimetry/CaloMiscalibTools/interface/EcalRecHitRecalib.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 EcalRecHitRecalib::EcalRecHitRecalib(const edm::ParameterSet& iConfig)
0010     : ecalHitsProducer_(iConfig.getParameter<std::string>("ecalRecHitsProducer")),
0011       barrelHits_(iConfig.getParameter<std::string>("barrelHitCollection")),
0012       endcapHits_(iConfig.getParameter<std::string>("endcapHitCollection")),
0013       recalibBarrelHits_(iConfig.getParameter<std::string>("RecalibBarrelHitCollection")),
0014       recalibEndcapHits_(iConfig.getParameter<std::string>("RecalibEndcapHitCollection")),
0015       refactor_(iConfig.getUntrackedParameter<double>("Refactor", (double)1)),
0016       refactor_mean_(iConfig.getUntrackedParameter<double>("Refactor_mean", (double)1)),
0017       ebRecHitToken_(consumes<EBRecHitCollection>(edm::InputTag(ecalHitsProducer_, barrelHits_))),
0018       eeRecHitToken_(consumes<EERecHitCollection>(edm::InputTag(ecalHitsProducer_, endcapHits_))),
0019       intercalibConstsToken_(esConsumes()),
0020       barrelHitsToken_(produces<EBRecHitCollection>(recalibBarrelHits_)),
0021       endcapHitsToken_(produces<EERecHitCollection>(recalibEndcapHits_)) {}
0022 
0023 EcalRecHitRecalib::~EcalRecHitRecalib() {}
0024 
0025 // ------------ method called to produce the data  ------------
0026 void EcalRecHitRecalib::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0027   using namespace edm;
0028   using namespace std;
0029 
0030   Handle<EBRecHitCollection> barrelRecHitsHandle;
0031   Handle<EERecHitCollection> endcapRecHitsHandle;
0032 
0033   const EBRecHitCollection* EBRecHits = nullptr;
0034   const EERecHitCollection* EERecHits = nullptr;
0035 
0036   iEvent.getByToken(ebRecHitToken_, barrelRecHitsHandle);
0037   if (!barrelRecHitsHandle.isValid()) {
0038     LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
0039   } else {
0040     EBRecHits = barrelRecHitsHandle.product();  // get a ptr to the product
0041   }
0042 
0043   iEvent.getByToken(eeRecHitToken_, endcapRecHitsHandle);
0044   if (!endcapRecHitsHandle.isValid()) {
0045     LogDebug("") << "EcalREcHitMiscalib: Error! can't get product!" << std::endl;
0046   } else {
0047     EERecHits = endcapRecHitsHandle.product();  // get a ptr to the product
0048   }
0049 
0050   //Create empty output collections
0051   auto RecalibEBRecHitCollection = std::make_unique<EBRecHitCollection>();
0052   auto RecalibEERecHitCollection = std::make_unique<EERecHitCollection>();
0053 
0054   // Intercalib constants
0055   const EcalIntercalibConstants& ical = iSetup.getData(intercalibConstsToken_);
0056 
0057   if (EBRecHits) {
0058     //loop on all EcalRecHits (barrel)
0059     EBRecHitCollection::const_iterator itb;
0060     for (itb = EBRecHits->begin(); itb != EBRecHits->end(); ++itb) {
0061       // find intercalib constant for this xtal
0062       EcalIntercalibConstantMap::const_iterator icalit = ical.getMap().find(itb->id().rawId());
0063       EcalIntercalibConstant icalconst = -1;
0064 
0065       if (icalit != ical.getMap().end()) {
0066         icalconst = (*icalit);
0067 
0068       } else {
0069         edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EBDetId(itb->id())
0070                                            << "! something wrong with EcalIntercalibConstants in your DB? ";
0071       }
0072 
0073       // make the rechit with rescaled energy and put in the output collection
0074       icalconst = refactor_mean_ +
0075                   (icalconst - refactor_mean_) * refactor_;  //apply additional scaling factor (works if gaussian)
0076       EcalRecHit aHit(itb->id(), itb->energy() * icalconst, itb->time());
0077 
0078       RecalibEBRecHitCollection->push_back(aHit);
0079     }
0080   }
0081 
0082   if (EERecHits) {
0083     //loop on all EcalRecHits (barrel)
0084     EERecHitCollection::const_iterator ite;
0085     for (ite = EERecHits->begin(); ite != EERecHits->end(); ++ite) {
0086       // find intercalib constant for this xtal
0087       EcalIntercalibConstantMap::const_iterator icalit = ical.getMap().find(ite->id().rawId());
0088       EcalIntercalibConstant icalconst = -1;
0089 
0090       if (icalit != ical.getMap().end()) {
0091         icalconst = (*icalit);
0092       } else {
0093         edm::LogError("EcalRecHitRecalib") << "No intercalib const found for xtal " << EEDetId(ite->id())
0094                                            << "! something wrong with EcalIntercalibConstants in your DB? ";
0095       }
0096 
0097       // make the rechit with rescaled energy and put in the output collection
0098 
0099       icalconst = refactor_mean_ +
0100                   (icalconst - refactor_mean_) * refactor_;  //apply additional scaling factor (works if gaussian)
0101       EcalRecHit aHit(ite->id(), ite->energy() * icalconst, ite->time());
0102 
0103       RecalibEERecHitCollection->push_back(aHit);
0104     }
0105   }
0106 
0107   //Put Recalibrated rechit in the event
0108   iEvent.put(barrelHitsToken_, std::move(RecalibEBRecHitCollection));
0109   iEvent.put(endcapHitsToken_, std::move(RecalibEERecHitCollection));
0110 }