CMS 3D CMS Logo

EcalBadCalibFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EcalBadCalibFilter
4 // Class: EcalBadCalibFilter
5 //
11 //
12 // Original Authors: D. Petyt
13 //
14 
15 
16 // include files
17 
18 #include <iostream>
19 
26 
32 
33 
36 
38 
39 
40 
41 using namespace std;
42 
43 
45 
46 public:
47 
48  explicit EcalBadCalibFilter(const edm::ParameterSet & iConfig);
49  ~EcalBadCalibFilter() override {}
50 
51 private:
52 
53  // main filter function
54 
55  bool filter(edm::StreamID, edm::Event & iEvent, const edm::EventSetup & iSetup) const override;
56 
57  // input parameters
58  // ecal rechit collection (from AOD)
60 
61  //config parameters (defining the cuts on the bad SCs)
62  const double ecalMin_; // ecal rechit et threshold
63 
64  const std::vector<unsigned int> baddetEcal_; // DetIds of bad Ecal channels
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  : ecalRHSrcToken_ (consumes<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>("EcalRecHitSource")))
74  , ecalMin_ (iConfig.getParameter<double>("ecalMinEt"))
75  , baddetEcal_ (iConfig.getParameter<std::vector<unsigned int> >("baddetEcal"))
76  , taggingMode_ (iConfig.getParameter<bool>("taggingMode"))
77  , debug_ (iConfig.getParameter<bool>("debug"))
78 {
79  produces<bool>();
80 }
81 
82 
84 
85 
86  // load required collections
87 
88  // Ecal rechit collection
90  iEvent.getByToken(ecalRHSrcToken_, ecalRHs);
91 
92  // Calo Geometry - needed for computing E_t
94  iSetup.get<CaloGeometryRecord>().get(pG);
95  const CaloGeometry* geo = pG.product();
96 
97  // by default the event is OK
98  bool pass = true;
99 
100  for (const auto ecalit : baddetEcal_) {
101 
102  DetId ecaldet(ecalit);
103 
104  if (ecaldet.rawId()==0) continue;
105 
106  // find rechit corresponding to this DetId
107  EcalRecHitCollection::const_iterator ecalhit=ecalRHs->find(ecaldet);
108 
109  if (ecalhit==ecalRHs->end()) continue;
110 
111  // if rechit not found, move to next DetId
112  if (ecalhit->id().rawId()==0 || ecalhit->id().rawId()!= ecaldet.rawId()) { continue; }
113 
114 
115  // define energy variables
116  float ene=0;
117  float et=0;
118 
119  // rechit has been found: obtain crystal energy
120  ene=ecalhit->energy();
121 
122  // compute transverse energy
123  const GlobalPoint & posecal=geo->getPosition(ecaldet);
124  float pf = posecal.perp()/posecal.mag();
125  et=ene*pf;
126 
127 
128  // print some debug info
129  if (debug_) {
130 
131  // ref: DataFormats/EcalDetId/interface/EcalSubdetector.h
132  // EcalBarrel
133  if (ecaldet.subdetId()==1) {
134  EBDetId ebdet(ecalit);
135  int ix=ebdet.ieta();
136  int iy=ebdet.iphi();
137  int iz=ebdet.zside();
138 
139  edm::LogInfo("EcalBadCalibFilter") << "DetId=" << ecaldet.rawId();
140  edm::LogInfo("EcalBadCalibFilter") << "ieta=" << ix << " iphi=" << iy << " iz=" << iz;
141  edm::LogInfo("EcalBadCalibFilter") << "Et=" << et << " thresh=" << ecalMin_;
142  }
143 
144  // EcalEndcap
145  else if (ecaldet.subdetId()==2) {
146  EEDetId eedet(ecalit);
147  int ix=eedet.ix();
148  int iy=eedet.iy();
149  int iz=eedet.zside();
150 
151  edm::LogInfo("EcalBadCalibFilter") << "DetId=" << ecaldet.rawId();
152  edm::LogInfo("EcalBadCalibFilter") << "ix=" << ix << " iy=" << iy << " iz=" << iz;
153  edm::LogInfo("EcalBadCalibFilter") << "Et=" << et << " thresh=" << ecalMin_;
154  }
155 
156  }
157 
158 
159  // if transverse energy is above threshold and channel has bad IC
160  if (et>ecalMin_) {
161  pass=false;
162  if (debug_) {
163  edm::LogInfo("EcalBadCalibFilter") << "DUMP EVENT" << std::endl;
164  }
165  }
166 
167  }
168 
169 
170  // print the decision if event is bad
171  if (pass==false && debug_) edm::LogInfo("EcalBadCalibFilter") << "REJECT EVENT!!!";
172 
173  iEvent.put(std::make_unique<bool>(pass));
174 
175  return taggingMode_ || pass;
176 }
177 
178 
180 
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
int ix() const
Definition: EEDetId.h:77
T perp() const
Definition: PV3DBase.h:72
const std::vector< unsigned int > baddetEcal_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< EcalRecHit >::const_iterator const_iterator
EcalBadCalibFilter(const edm::ParameterSet &iConfig)
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
T mag() const
Definition: PV3DBase.h:67
const edm::EDGetTokenT< EcalRecHitCollection > ecalRHSrcToken_
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
int zside() const
Definition: EEDetId.h:71
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:74
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
const_iterator end() const
Definition: DetId.h:18
et
define resolution functions of each parameter
iterator find(key_type k)
HLT enums.
T get() const
Definition: EventSetup.h:71
~EcalBadCalibFilter() override
T const * product() const
Definition: ESHandle.h:86
bool filter(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45