CMS 3D CMS Logo

EEBadScFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalBadScFilter
4 // Class: EcalBadScFilter
5 //
11 //
12 // Original Authors: K. Theofilatos and D. Petyt
13 //
14 
15 
16 // include files
23 
27 
30 
33 
34 #include "TVector3.h"
35 
37 
38  public:
39 
40  explicit EEBadScFilter(const edm::ParameterSet & iConfig);
41  ~EEBadScFilter() override {}
42 
43  private:
44 
45  // main filter function
46 
47  bool filter(edm::StreamID, edm::Event & iEvent, const edm::EventSetup & iSetup) const override;
48 
49  // function to calculate 5x5 energy and check rechit flags
50 
51  virtual void scan5x5(const DetId & det, const edm::Handle<EcalRecHitCollection> &hits, const edm::ESHandle<CaloTopology> &caloTopo, const edm::ESHandle<CaloGeometry> &geometry, int &nHits, float & totEt) const;
52 
53  // input parameters
54 
55  // ee rechit collection (from AOD)
57 
58  //config parameters (defining the cuts on the bad SCs)
59  const double Emin_; // rechit energy threshold (check for !kGood rechit flags)
60  const double EtminSC_; // et threshold for the supercrystal
61  const int side_; // supercrystal size (default = 5x5 crystals)
62  const int nBadHitsSC_; // number of bad hits in the SC to reject the event
63  const std::vector<int> badsc_; // crystal coordinates of the bad SCs (central xtal in the 5x5)
64 
65  const bool taggingMode_;
66  const bool debug_; // prints out debug info if set to true
67 
68 };
69 
70 // read the parameters from the config file
72  : eeRHSrcToken_ (consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EERecHitSource")))
73  , Emin_ (iConfig.getParameter<double>("EminHit"))
74  , EtminSC_ (iConfig.getParameter<double>("EtminSC"))
75  , side_ (iConfig.getParameter<int>("SCsize"))
76  , nBadHitsSC_ (iConfig.getParameter<int>("nBadHitsSC"))
77  , badsc_ (iConfig.getParameter<std::vector<int> >("badscEE"))
78  , taggingMode_ (iConfig.getParameter<bool>("taggingMode"))
79  , debug_ (iConfig.getParameter<bool>("debug"))
80 {
81  produces<bool>();
82 }
83 
84 
85 void EEBadScFilter::scan5x5(const DetId & det, const edm::Handle<EcalRecHitCollection> &hits, const edm::ESHandle<CaloTopology> &caloTopo, const edm::ESHandle<CaloGeometry> &geometry, int &nHits, float & totEt) const
86 {
87 
88  // function to compute: total transverse energy in a given supercrystal (totEt)
89  // number of hits with E>Emin_ and rechit flag != kGood (nHits)
90  // bad events have large totEt and many high energy hits with rechit flags !kGood
91 
92  nHits = 0;
93  totEt = 0;
94 
95  // navigator to define a 5x5 region around the input DetId
96 
98  const CaloGeometry* geo = geometry.product();
99 
100  // loop over a 5x5 array centered on the input DetId
101 
102  for(int j=side_/2; j>=-side_/2; --j)
103  {
104  for(int i=-side_/2; i<=side_/2; ++i)
105  {
106  cursor.home();
107  cursor.offsetBy(i,j);
108  if(hits->find(*cursor)!=hits->end()) // if hit exists in the rechit collection
109  {
110  EcalRecHit tmpHit = *hits->find(*cursor); // get rechit with detID at cursor
111 
112 
113  const GlobalPoint p ( geo->getPosition(*cursor) ) ; // calculate Et of the rechit
114  TVector3 hitPos(p.x(),p.y(),p.z());
115  hitPos *= 1.0/hitPos.Mag();
116  hitPos *= tmpHit.energy();
117  float rechitEt = hitPos.Pt();
118 
119  //--- add rechit E_t to the total for this supercrystal
120  totEt += rechitEt;
121 
122  // increment nHits if E>Emin and rechit flag is not kGood
123  if(tmpHit.energy()>Emin_ && !tmpHit.checkFlag(EcalRecHit::kGood))nHits++;
124 
125  }
126  }
127  }
128 
129 
130 }
131 
132 
133 
134 
135 
137 
138 
139  // load required collections
140 
141 
142  // EE rechit collection
144  iEvent.getByToken(eeRHSrcToken_, eeRHs);
145 
146  // Calo Geometry - needed for computing E_t
148  iSetup.get<CaloGeometryRecord>().get(pG);
149 
150  // Calo Toplology - needed for navigating the 5x5 xtal array around the centre of a SC
151  edm::ESHandle<CaloTopology> pTopology;
152  iSetup.get<CaloTopologyRecord>().get(pTopology);
153 
154  // by default the event is OK
155  bool pass = true;
156 
157 
158  // set discriminating variables to zero
159  int nhits=0;
160  float totEt=0.0;
161 
162 
163  // define detid variables and ix,iy,iz coordinates
164 
165  EEDetId scdet;
166  DetId det;
167 
168  int ix,iy,iz;
169 
170  // loop over the list of bad SCs (defined in the python file)
171 
172  for (std::vector<int>::const_iterator scit = badsc_.begin(); scit != badsc_.end(); ++ scit) {
173 
174 
175 
176  // unpack the SC coordinates from the python file into ix,iy,iz
177 
178  iz=int(*scit/1000000);
179  iy=*scit%100*iz;
180  ix=int((*scit-iy-1000000*iz)/1000)*iz;
181 
182  // make the DetId from these coordinates
183  scdet=EEDetId(ix,iy,iz);
184  det=scdet;
185 
186  // loop over the 5x5 SC centered on this DetId and fill discriminating variables
187 
188  scan5x5(det,eeRHs,pTopology,pG,nhits,totEt);
189 
190  // print some debug info
191 
192  if (debug_) {
193  edm::LogInfo("EEBadScFilter") << "SCID=" << *scit;
194  edm::LogInfo("EEBadScFilter") << "ix=" << ix << " iy=" << iy << " iz=" << iz;
195  edm::LogInfo("EEBadScFilter") << "Et(5x5)=" << totEt << " nbadhits=" << nhits;
196  }
197 
198 
199  // if 5x5 transverse energy is above threshold and number of bad hits above threshold
200  // event is bad
201 
202  if (totEt>EtminSC_ && nhits>=nBadHitsSC_) pass=false;
203 
204 
205  }
206 
207  // print the decision if event is bad
208  if (pass==false && debug_) edm::LogInfo("EEBadScFilter") << "REJECT EVENT!!!";
209 
210 
211  iEvent.put(std::make_unique<bool>(pass));
212 
213  // return the decision
214 
215  return taggingMode_ || pass;
216 }
217 
218 
220 
const edm::EDGetTokenT< EcalRecHitCollection > eeRHSrcToken_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
virtual void scan5x5(const DetId &det, const edm::Handle< EcalRecHitCollection > &hits, const edm::ESHandle< CaloTopology > &caloTopo, const edm::ESHandle< CaloGeometry > &geometry, int &nHits, float &totEt) const
const double Emin_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const std::vector< int > badsc_
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const bool debug_
EEBadScFilter(const edm::ParameterSet &iConfig)
T offsetBy(int deltaX, int deltaY) const
Free movement of arbitray steps.
Definition: CaloNavigator.h:80
const int nBadHitsSC_
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool checkFlag(int flag) const
check if the flag is true
Definition: EcalRecHit.h:187
const bool taggingMode_
const int side_
float energy() const
Definition: EcalRecHit.h:68
const_iterator end() const
void home() const
move the navigator back to the starting point
Definition: DetId.h:18
bool filter(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:20
iterator find(key_type k)
HLT enums.
T get() const
Definition: EventSetup.h:71
const double EtminSC_
T const * product() const
Definition: ESHandle.h:86
~EEBadScFilter() override