CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
17 #include <iostream>
18 
24 
28 
31 
34 
35 #include "TVector3.h"
36 
37 class EEBadScFilter : public edm::EDFilter {
38 
39  public:
40 
41  explicit EEBadScFilter(const edm::ParameterSet & iConfig);
43 
44  private:
45 
46  // main filter function
47 
48  virtual bool filter(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
49 
50  // function to calculate 5x5 energy and check rechit flags
51 
52  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);
53 
54  // input parameters
55 
56  // ee rechit collection (from AOD)
58 
59  //config parameters (defining the cuts on the bad SCs)
60  const double Emin_; // rechit energy threshold (check for !kGood rechit flags)
61  const double EtminSC_; // et threshold for the supercrystal
62  const int side_; // supercrystal size (default = 5x5 crystals)
63  const int nBadHitsSC_; // number of bad hits in the SC to reject the event
64  const std::vector<int> badsc_; // crystal coordinates of the bad SCs (central xtal in the 5x5)
65 
66  const bool taggingMode_;
67  const bool debug_; // prints out debug info if set to true
68 
69 };
70 
71 // read the parameters from the config file
73  : eeRHSrcToken_ (consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EERecHitSource")))
74  , Emin_ (iConfig.getParameter<double>("EminHit"))
75  , EtminSC_ (iConfig.getParameter<double>("EtminSC"))
76  , side_ (iConfig.getParameter<int>("SCsize"))
77  , nBadHitsSC_ (iConfig.getParameter<int>("nBadHitsSC"))
78  , badsc_ (iConfig.getParameter<std::vector<int> >("badscEE"))
79  , taggingMode_ (iConfig.getParameter<bool>("taggingMode"))
80  , debug_ (iConfig.getParameter<bool>("debug"))
81 {
82  produces<bool>();
83 }
84 
85 
86 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)
87 {
88 
89  // function to compute: total transverse energy in a given supercrystal (totEt)
90  // number of hits with E>Emin_ and rechit flag != kGood (nHits)
91  // bad events have large totEt and many high energy hits with rechit flags !kGood
92 
93  nHits = 0;
94  totEt = 0;
95 
96  // navigator to define a 5x5 region around the input DetId
97 
98  CaloNavigator<DetId> cursor = CaloNavigator<DetId>(det,caloTopo->getSubdetectorTopology(det));
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 ( geometry->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  ix=0,iy=0,iz=0;
171 
172 
173  // loop over the list of bad SCs (defined in the python file)
174 
175  for (std::vector<int>::const_iterator scit = badsc_.begin(); scit != badsc_.end(); ++ scit) {
176 
177 
178 
179  // unpack the SC coordinates from the python file into ix,iy,iz
180 
181  iz=int(*scit/1000000);
182  iy=*scit%100*iz;
183  ix=int((*scit-iy-1000000*iz)/1000)*iz;
184 
185  // make the DetId from these coordinates
186  scdet=EEDetId(ix,iy,iz);
187  det=scdet;
188 
189  // loop over the 5x5 SC centered on this DetId and fill discriminating variables
190 
191  scan5x5(det,eeRHs,pTopology,pG,nhits,totEt);
192 
193  // print some debug info
194 
195  if (debug_) {
196  std::cout << "EEBadScFilter.cc: SCID=" << *scit << std::endl;
197  std::cout << "EEBadScFilter.cc: ix=" << ix << " iy=" << iy << " iz=" << iz << std::endl;
198  std::cout << "EEBadScFilter.cc: Et(5x5)=" << totEt << " nbadhits=" << nhits << std::endl;
199  }
200 
201 
202  // if 5x5 transverse energy is above threshold and number of bad hits above threshold
203  // event is bad
204 
205  if (totEt>EtminSC_ && nhits>=nBadHitsSC_) pass=false;
206 
207 
208  }
209 
210  // print the decision if event is bad
211  if (pass==false && debug_) std::cout << "EEBadScFilter.cc: REJECT EVENT!!!" << std::endl;
212 
213 
214  iEvent.put( std::auto_ptr<bool>(new bool(pass)) );
215 
216  // return the decision
217 
218  return taggingMode_ || pass;
219 }
220 
221 
223 
const edm::EDGetTokenT< EcalRecHitCollection > eeRHSrcToken_
int i
Definition: DBlmapReader.cc:9
const double Emin_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
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 std::vector< int > badsc_
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:230
bool checkFlag(int flag) const
check if the flag is true
Definition: EcalRecHit.h:172
const bool taggingMode_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
const int side_
int j
Definition: DBlmapReader.cc:9
float energy() const
Definition: EcalRecHit.h:68
virtual bool filter(edm::Event &iEvent, const edm::EventSetup &iSetup) override
void home() const
move the navigator back to the starting point
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:56
ESHandle< TrackerGeometry > geometry
const double EtminSC_
tuple cout
Definition: gather_cfg.py:121