Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:    EcalBadScFilter
0004 // Class:      EcalBadScFilter
0005 //
0006 /**\class EcalBadSCFilter EcalBadScFilter.cc
0007 
0008  Description: <one line class summary>
0009  Event filtering to remove events with anomalous energy in EE supercrystals
0010 */
0011 //
0012 // Original Authors:  K. Theofilatos and D. Petyt
0013 //
0014 
0015 // include files
0016 #include "FWCore/Framework/interface/Frameworkfwd.h"
0017 #include "FWCore/Framework/interface/global/EDFilter.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0021 
0022 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0023 #include "DataFormats/DetId/interface/DetId.h"
0024 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0025 
0026 #include "Geometry/CaloTopology/interface/CaloTopology.h"
0027 #include "Geometry/Records/interface/CaloTopologyRecord.h"
0028 
0029 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0030 #include "RecoCaloTools/Navigation/interface/CaloNavigator.h"
0031 
0032 #include "TVector3.h"
0033 
0034 class EEBadScFilter : public edm::global::EDFilter<> {
0035 public:
0036   explicit EEBadScFilter(const edm::ParameterSet &iConfig);
0037   ~EEBadScFilter() override {}
0038 
0039 private:
0040   // main filter function
0041 
0042   bool filter(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override;
0043 
0044   // function to calculate 5x5 energy and check rechit flags
0045 
0046   void scan5x5(const DetId &det,
0047                const EcalRecHitCollection &hits,
0048                const CaloTopology &caloTopo,
0049                const CaloGeometry &geometry,
0050                int &nHits,
0051                float &totEt) const;
0052 
0053   // input parameters
0054 
0055   // ee rechit collection (from AOD)
0056   const edm::EDGetTokenT<EcalRecHitCollection> eeRHSrcToken_;
0057   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0058   const edm::ESGetToken<CaloTopology, CaloTopologyRecord> caloTopoToken_;
0059 
0060   //config parameters (defining the cuts on the bad SCs)
0061   const double Emin_;             // rechit energy threshold (check for !kGood rechit flags)
0062   const double EtminSC_;          // et threshold for the supercrystal
0063   const int side_;                // supercrystal size  (default = 5x5 crystals)
0064   const int nBadHitsSC_;          // number of bad hits in the SC to reject the event
0065   const std::vector<int> badsc_;  // crystal coordinates of the bad SCs (central xtal in the 5x5)
0066 
0067   const bool taggingMode_;
0068   const bool debug_;  // prints out debug info if set to true
0069 };
0070 
0071 // read the parameters from the config file
0072 EEBadScFilter::EEBadScFilter(const edm::ParameterSet &iConfig)
0073     : eeRHSrcToken_(consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EERecHitSource"))),
0074       geometryToken_(esConsumes()),
0075       caloTopoToken_(esConsumes()),
0076       Emin_(iConfig.getParameter<double>("EminHit")),
0077       EtminSC_(iConfig.getParameter<double>("EtminSC")),
0078       side_(iConfig.getParameter<int>("SCsize")),
0079       nBadHitsSC_(iConfig.getParameter<int>("nBadHitsSC")),
0080       badsc_(iConfig.getParameter<std::vector<int> >("badscEE")),
0081       taggingMode_(iConfig.getParameter<bool>("taggingMode")),
0082       debug_(iConfig.getParameter<bool>("debug")) {
0083   produces<bool>();
0084 }
0085 
0086 void EEBadScFilter::scan5x5(const DetId &det,
0087                             const EcalRecHitCollection &hits,
0088                             const CaloTopology &caloTopo,
0089                             const CaloGeometry &geometry,
0090                             int &nHits,
0091                             float &totEt) const {
0092   // function to compute:  total transverse energy in a given supercrystal (totEt)
0093   //                       number of hits with E>Emin_ and rechit flag != kGood (nHits)
0094   // bad events have large totEt and many high energy hits with rechit flags !kGood
0095 
0096   nHits = 0;
0097   totEt = 0;
0098 
0099   // navigator to define a 5x5 region around the input DetId
0100 
0101   CaloNavigator<DetId> cursor = CaloNavigator<DetId>(det, caloTopo.getSubdetectorTopology(det));
0102 
0103   // loop over a 5x5 array centered on the input DetId
0104 
0105   for (int j = side_ / 2; j >= -side_ / 2; --j) {
0106     for (int i = -side_ / 2; i <= side_ / 2; ++i) {
0107       cursor.home();
0108       cursor.offsetBy(i, j);
0109       if (hits.find(*cursor) != hits.end())  // if hit exists in the rechit collection
0110       {
0111         EcalRecHit tmpHit = *hits.find(*cursor);  // get rechit with detID at cursor
0112 
0113         const GlobalPoint p(geometry.getPosition(*cursor));  // calculate Et of the rechit
0114         TVector3 hitPos(p.x(), p.y(), p.z());
0115         hitPos *= 1.0 / hitPos.Mag();
0116         hitPos *= tmpHit.energy();
0117         float rechitEt = hitPos.Pt();
0118 
0119         //--- add rechit E_t to the total for this supercrystal
0120         totEt += rechitEt;
0121 
0122         // increment nHits if E>Emin and rechit flag is not kGood
0123         if (tmpHit.energy() > Emin_ && !tmpHit.checkFlag(EcalRecHit::kGood))
0124           nHits++;
0125       }
0126     }
0127   }
0128 }
0129 
0130 bool EEBadScFilter::filter(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const {
0131   // load required collections
0132 
0133   // EE rechit collection
0134   auto const &eeRHs = iEvent.get(eeRHSrcToken_);
0135 
0136   // Calo Geometry - needed for computing E_t
0137   auto const &geometry = iSetup.getData(geometryToken_);
0138 
0139   // Calo Toplology - needed for navigating the 5x5 xtal array around the centre of a SC
0140   auto const &caloTopo = iSetup.getData(caloTopoToken_);
0141 
0142   // by default the event is OK
0143   bool pass = true;
0144 
0145   // set discriminating variables to zero
0146   int nhits = 0;
0147   float totEt = 0.0;
0148 
0149   // define detid variables and ix,iy,iz coordinates
0150 
0151   EEDetId scdet;
0152   DetId det;
0153 
0154   int ix, iy, iz;
0155 
0156   // loop over the list of bad SCs (defined in the python file)
0157 
0158   for (std::vector<int>::const_iterator scit = badsc_.begin(); scit != badsc_.end(); ++scit) {
0159     // unpack the SC coordinates from the python file into ix,iy,iz
0160 
0161     iz = int(*scit / 1000000);
0162     iy = *scit % 100 * iz;
0163     ix = int((*scit - iy - 1000000 * iz) / 1000) * iz;
0164 
0165     // make the DetId from these coordinates
0166     scdet = EEDetId(ix, iy, iz);
0167     det = scdet;
0168 
0169     // loop over the 5x5 SC centered on this DetId and fill discriminating variables
0170 
0171     scan5x5(det, eeRHs, caloTopo, geometry, nhits, totEt);
0172 
0173     // print some debug info
0174 
0175     if (debug_) {
0176       edm::LogInfo("EEBadScFilter") << "SCID=" << *scit;
0177       edm::LogInfo("EEBadScFilter") << "ix=" << ix << " iy=" << iy << " iz=" << iz;
0178       edm::LogInfo("EEBadScFilter") << "Et(5x5)=" << totEt << " nbadhits=" << nhits;
0179     }
0180 
0181     // if 5x5 transverse energy is above threshold and number of bad hits above threshold
0182     // event is bad
0183 
0184     if (totEt > EtminSC_ && nhits >= nBadHitsSC_)
0185       pass = false;
0186   }
0187 
0188   // print the decision if event is bad
0189   if (pass == false && debug_)
0190     edm::LogInfo("EEBadScFilter") << "REJECT EVENT!!!";
0191 
0192   iEvent.put(std::make_unique<bool>(pass));
0193 
0194   // return the decision
0195 
0196   return taggingMode_ || pass;
0197 }
0198 
0199 #include "FWCore/Framework/interface/MakerMacros.h"
0200 
0201 DEFINE_FWK_MODULE(EEBadScFilter);