Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-23 03:25:26

0001 
0002 #include "FWCore/Framework/interface/Frameworkfwd.h"
0003 #include "FWCore/Framework/interface/global/EDFilter.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0009 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
0010 #include <DataFormats/EcalDetId/interface/EBDetId.h>
0011 #include <DataFormats/EcalDetId/interface/EEDetId.h>
0012 #include "DataFormats/DetId/interface/DetId.h"
0013 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbRecord.h"
0014 #include "CalibCalorimetry/EcalLaserCorrection/interface/EcalLaserDbService.h"
0015 
0016 #include "Geometry/EcalAlgo/interface/EcalEndcapGeometry.h"
0017 #include "Geometry/EcalAlgo/interface/EcalPreshowerGeometry.h"
0018 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0019 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0020 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0021 #include "RecoCaloTools/Navigation/interface/CaloTowerNavigator.h"
0022 
0023 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0024 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0025 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0026 #include "Geometry/CaloTopology/interface/CaloSubdetectorTopology.h"
0027 #include "FWCore/Utilities/interface/typelookup.h"  ///// added as a try for CaloTopology
0028 
0029 class EcalLaserCorrFilter : public edm::global::EDFilter<> {
0030 public:
0031   explicit EcalLaserCorrFilter(const edm::ParameterSet& iConfig);
0032   ~EcalLaserCorrFilter() override {}
0033 
0034 private:
0035   bool filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
0036 
0037   const edm::EDGetTokenT<EcalRecHitCollection> ebRHSrcToken_;
0038   const edm::EDGetTokenT<EcalRecHitCollection> eeRHSrcToken_;
0039   const edm::ESGetToken<EcalLaserDbService, EcalLaserDbRecord> laserToken_;
0040 
0041   // thresholds to laser corr to set kPoorCalib
0042   const double EBLaserMIN_, EELaserMIN_, EBLaserMAX_, EELaserMAX_, EBEnegyMIN_, EEEnegyMIN_;
0043   const bool taggingMode_, debug_;
0044 };
0045 
0046 EcalLaserCorrFilter::EcalLaserCorrFilter(const edm::ParameterSet& iConfig)
0047     : ebRHSrcToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EBRecHitSource"))),
0048       eeRHSrcToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EERecHitSource"))),
0049       laserToken_(esConsumes()),
0050       EBLaserMIN_(iConfig.getParameter<double>("EBLaserMIN")),
0051       EELaserMIN_(iConfig.getParameter<double>("EELaserMIN")),
0052       EBLaserMAX_(iConfig.getParameter<double>("EBLaserMAX")),
0053       EELaserMAX_(iConfig.getParameter<double>("EELaserMAX")),
0054       EBEnegyMIN_(iConfig.getParameter<double>("EBEnegyMIN")),
0055       EEEnegyMIN_(iConfig.getParameter<double>("EEEnegyMIN")),
0056       taggingMode_(iConfig.getParameter<bool>("taggingMode")),
0057       debug_(iConfig.getParameter<bool>("Debug")) {
0058   produces<bool>();
0059 }
0060 
0061 bool EcalLaserCorrFilter::filter(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0062   using namespace edm;
0063   using namespace reco;
0064   using namespace std;
0065 
0066   edm::Handle<EcalRecHitCollection> ebRHs;
0067   iEvent.getByToken(ebRHSrcToken_, ebRHs);
0068 
0069   edm::Handle<EcalRecHitCollection> eeRHs;
0070   iEvent.getByToken(eeRHSrcToken_, eeRHs);
0071 
0072   // Laser corrections
0073   auto const& laser = iSetup.getData(laserToken_);
0074 
0075   bool goodCalib = true;
0076 
0077   // check EE RecHits
0078   for (EcalRecHitCollection::const_iterator eerh = eeRHs->begin(); eerh != eeRHs->end(); ++eerh) {
0079     EcalRecHit hit = (*eerh);
0080     EEDetId eeDet = hit.id();
0081     double energy = eerh->energy();
0082     double time = eerh->time();
0083     int jx = EEDetId((*eerh).id()).ix();
0084     int jy = EEDetId((*eerh).id()).iy();
0085     int jz = EEDetId((*eerh).id()).zside();
0086 
0087     // get laser coefficient
0088     float lasercalib = laser.getLaserCorrection(EEDetId(eeDet), iEvent.time());
0089 
0090     if (energy > EEEnegyMIN_ && (lasercalib < EELaserMIN_ || lasercalib > EELaserMAX_)) {
0091       goodCalib = false;
0092       if (debug_) {
0093         edm::LogInfo("EcalLaserCorrFilter")
0094             << "RecHit EE " << iEvent.id().run() << ":" << iEvent.luminosityBlock() << ":" << iEvent.id().event()
0095             << " lasercalib " << lasercalib << " rechit ene " << energy << " time " << time << " ix, iy, z = " << jx
0096             << " " << jy << " " << jz;
0097       }
0098     }
0099 
0100     //if (!goodCalib) break;
0101   }
0102 
0103   // check EB RecHits
0104   for (EcalRecHitCollection::const_iterator ebrh = ebRHs->begin(); ebrh != ebRHs->end(); ++ebrh) {
0105     EcalRecHit hit = (*ebrh);
0106     EBDetId ebDet = hit.id();
0107     double energy = ebrh->energy();
0108     double time = ebrh->time();
0109     int etarec = EBDetId((*ebrh).id()).ieta();
0110     int phirec = EBDetId((*ebrh).id()).iphi();
0111     int zrec = EBDetId((*ebrh).id()).zside();
0112 
0113     // get laser coefficient
0114     float lasercalib = laser.getLaserCorrection(EBDetId(ebDet), iEvent.time());
0115 
0116     if (energy > EBEnegyMIN_ && (lasercalib < EBLaserMIN_ || lasercalib > EBLaserMAX_)) {
0117       goodCalib = false;
0118       if (debug_) {
0119         edm::LogInfo("EcalLaserCorrFilter")
0120             << "RecHit EB " << iEvent.id().run() << ":" << iEvent.luminosityBlock() << ":" << iEvent.id().event()
0121             << " lasercalib " << lasercalib << " rechit ene " << energy << " time " << time
0122             << " eta, phi, z = " << etarec << " " << phirec << " " << zrec;
0123       }
0124     }
0125     //if (!goodCalib) break;
0126   }
0127 
0128   bool result = goodCalib;
0129 
0130   iEvent.put(std::make_unique<bool>(result));
0131 
0132   return taggingMode_ || result;
0133 }
0134 
0135 #include "FWCore/Framework/interface/MakerMacros.h"
0136 
0137 DEFINE_FWK_MODULE(EcalLaserCorrFilter);