CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalLaserHBHEHFFilter2012.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalLaserHBHEHFFilter2012
4 // Class: HcalLaserHBHEHFFilter2012
5 //
13 //
14 // Original Author:
15 // Created: Fri Oct 19 13:15:44 EDT 2012
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
33 
34 #include <cmath>
35 #include <iostream>
36 #include <sstream>
37 #include <fstream>
38 
41 
43 
46 
47 //
48 // class declaration
49 //
50 
52 public:
55 
56  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
57 
58 private:
59  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
60  virtual void endJob() override;
61 
62  // ----------member data ---------------------------
63  bool filterHBHE_; // Flag to activate laser filter for HBHE
64  int minCalibChannelsHBHELaser_; // set minimum number of HBHE Calib events that causes an event to be considered a bad (i.e., HBHE laser) event
65  double minFracDiffHBHELaser_; // minimum difference in fractional occupancies between 'good' and 'bad' HBHE regions (i.e., regions whose RBXes receive laser signals and those whose RBXes see no laser) necessary to declare an event as a laser event. In laser events, good fractional occupancy is generally near 1, while bad fractional occupancy is considerably less
66 
67  double HBHEcalibThreshold_; // minimum integrated charge needed for a hit to count as an occupied calib channel
68  std::vector <int> CalibTS_; // time slices used when integrating calib charges
69 
70  bool filterHF_; // Flag to activate laser filter for HF
71  int minCalibChannelsHFLaser_; // set minimum number of HF Calib events that causes an event to be considered a bad (i.e., HF laser) event
72 
76 
77  bool verbose_; // if set to true, then the run:LS:event for any event failing the cut will be printed out
78  std::string prefix_; // prefix will be printed before any event if verbose mode is true, in order to make searching for events easier
81  std::ofstream outfile_;
82 };
83 
84 //
85 // constants, enums and typedefs
86 //
87 
88 //
89 // static data member definitions
90 //
91 
92 //
93 // constructors and destructor
94 //
96 {
97  //now do what ever initialization is needed
98  filterHBHE_ = ps.getParameter<bool>("filterHBHE");
99  minCalibChannelsHBHELaser_ = ps.getParameter<int>("minCalibChannelsHBHELaser");
100  minFracDiffHBHELaser_ = ps.getParameter<double>("minFracDiffHBHELaser");
101  HBHEcalibThreshold_ = ps.getParameter<double>("HBHEcalibThreshold");
102  CalibTS_ = ps.getParameter<std::vector<int> >("CalibTS");
103 
104  filterHF_ = ps.getParameter<bool>("filterHF");
105  minCalibChannelsHFLaser_ = ps.getParameter<int>("minCalibChannelsHFLaser");
106 
107  digiLabel_ = ps.getParameter<edm::InputTag>("digiLabel");
108  tok_calib_ = consumes<HcalCalibDigiCollection>(digiLabel_);
109  tok_hbhe_ = consumes<HBHEDigiCollection>(digiLabel_);
110 
111  verbose_ = ps.getUntrackedParameter<bool>("verbose",false);
112  prefix_ = ps.getUntrackedParameter<std::string>("prefix","");
113  WriteBadToFile_ = ps.getUntrackedParameter<bool>("WriteBadToFile",false);
114  forceFilterTrue_ = ps.getUntrackedParameter<bool>("forceFilterTrue",false);
115  if (WriteBadToFile_)
116  outfile_.open("badHcalLaserList_hcalfilter.txt");
117 } // HcalLaserHBHEHFFilter2012::HcalLaserHBHEHFFilter2012 constructor
118 
119 
121 {
122 
123  // do anything here that needs to be done at destruction time
124  // (e.g. close files, deallocate resources etc.)
125 
126 }
127 
128 
129 //
130 // member functions
131 //
132 
133 // ------------ method called on each new Event ------------
134 bool
136 {
137  // Step 1:: try to get calib digi and HBHE collections.
138  // Return true if collection not found? Or false? What should default behavior be?
140  if (!(iEvent.getByToken(tok_calib_,calib_digi)))
141  {
142  edm::LogWarning("HcalLaserFilter2012")<< digiLabel_<<" calib_digi not available";
143  return true;
144  }
145 
146  if (!(calib_digi.isValid()))
147  {
148  edm::LogWarning("HcalLaserFilter2012")<< digiLabel_<<" calib_digi is not valid";
149  return true;
150  }
151 
153  if (!(iEvent.getByToken(tok_hbhe_,hbhe_digi)))
154  {
155  edm::LogWarning("HcalLaserFilter2012")<< digiLabel_<<" hbhe_digi not available";
156  return true;
157  }
158 
159  if (!(hbhe_digi.isValid()))
160  {
161  edm::LogWarning("HcalLaserHBHEHFFilter2012")<< digiLabel_<<" hbhe_digi is not valid";
162  return true;
163  }
164 
165  // Step 2: Count HBHE digi calib channels
166  int ncalibHBHE=0; // this will track number of HBHE digi channels
167  int ncalibHF=0; // this will track number of HF digi channels
168 
169 
170  for (HcalCalibDigiCollection::const_iterator Calibiter = calib_digi->begin();
171  Calibiter != calib_digi->end(); ++ Calibiter) {
172  const HcalCalibDataFrame digi = (const HcalCalibDataFrame)(*Calibiter);
173  if (digi.zsMarkAndPass()) continue; // skip digis labeled as "mark and pass" in NZS events
174  HcalCalibDetId myid=(HcalCalibDetId)digi.id();
175  if (filterHBHE_ && (myid.hcalSubdet()==HcalBarrel || myid.hcalSubdet()==HcalEndcap))
176  {
177  if ( myid.calibFlavor()==HcalCalibDetId::HOCrosstalk) continue;
178  // Compute charge in current channel (for relevant TS only)
179  // If total charge in channel exceeds threshold, increment count of calib channels
180  double thischarge=0;
181  for (unsigned int i=0;i<CalibTS_.size();++i) {
182  thischarge+=digi[CalibTS_[i]].nominal_fC();
183  if (thischarge> HBHEcalibThreshold_ ) {
184  ++ncalibHBHE;
185  break;
186  }
187  }
188 
189  if (ncalibHBHE>=minCalibChannelsHBHELaser_) {
190  if (verbose_)
191  std::cout <<prefix_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
192  if (WriteBadToFile_)
193  outfile_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
194  if (forceFilterTrue_) return true; // if special input boolean set, always return true, regardless of filter decision
195  else return false;
196  } // if (ncalibHBHE>=minCalibChannelsHBHELaser_)
197 
198  }
199  else if (filterHF_ && (myid.hcalSubdet()==HcalForward))
200  {
201  ++ncalibHF;
202  if (ncalibHF>=minCalibChannelsHFLaser_) {
203  if (verbose_) std::cout <<prefix_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
204  if (WriteBadToFile_)
205  outfile_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
206  if (forceFilterTrue_) return true; // if special input boolean set, always return true, regardless of filter decision
207  else return false;
208  }
209  }
210  }
211 
212  if (filterHBHE_) {
213  // Step 3: Look at distribution of HBHE hits
214  // Count digis in good, bad RBXes. ('bad' RBXes see no laser signal)
215  double badrbxfrac=0.;
216  double goodrbxfrac=0.;
217  int Nbad=72*3; // 3 bad RBXes, 72 channels each
218  int Ngood=2592*2-Nbad; // remaining HBHE channels are 'good'
219  for (HBHEDigiCollection::const_iterator hbhe = hbhe_digi->begin();
220  hbhe != hbhe_digi->end(); ++ hbhe)
221  {
222  const HBHEDataFrame digi = (const HBHEDataFrame)(*hbhe);
223  HcalDetId myid=(HcalDetId)digi.id();
224  bool isbad=false; // assume channel is not bad
225  if ( myid.subdet()==HcalBarrel && myid.ieta()<0 )
226  {
227  if (myid.iphi()>=15 && myid.iphi()<=18) isbad=true;
228  else if (myid.iphi()>=27 && myid.iphi()<=34) isbad=true;
229  }
230  if (isbad==true) badrbxfrac+=1.;
231  else goodrbxfrac+=1.;
232  }
233  goodrbxfrac/=Ngood;
234  badrbxfrac/=Nbad;
235  if (goodrbxfrac-badrbxfrac>minFracDiffHBHELaser_)
236  {
237  if (verbose_)
238  std::cout <<prefix_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
239  if (WriteBadToFile_)
240  outfile_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
241 
242  if (forceFilterTrue_) return true; // if special input boolean set, always return true, regardless of filter decision
243  else return false;
244  }
245  }
246  // Step 4: HBHEHF laser tests passed. return true
247  return true;
248 
249 } // HcalLaserHBHEHFFilter2012::filter
250 
251 // ------------ method called once each job just after ending the event loop ------------
252 void
254  if (WriteBadToFile_) outfile_.close();
255 
256 }
257 
258 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
259 void
261  //The following says we do not know what parameters are allowed so do no validation
262  // Please change this to state exactly what you do use, even if it is no parameters
264  desc.setUnknown();
265  descriptions.addDefault(desc);
266 }
267 //define this as a plug-in
269 
RunNumber_t run() const
Definition: EventID.h:39
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual bool filter(edm::Event &, const edm::EventSetup &) override
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:45
CalibDetType calibFlavor() const
get the flavor of this calibration detid
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< HcalCalibDataFrame >::const_iterator const_iterator
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
edm::EDGetTokenT< HcalCalibDigiCollection > tok_calib_
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
HcalLaserHBHEHFFilter2012(const edm::ParameterSet &)
int ieta() const
get the cell ieta
Definition: HcalDetId.h:51
const HcalCalibDetId & id() const
edm::EDGetTokenT< HBHEDigiCollection > tok_hbhe_
bool isValid() const
Definition: HandleBase.h:75
int iphi() const
get the cell iphi
Definition: HcalDetId.h:53
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EventID id() const
Definition: EventBase.h:60
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22
tuple cout
Definition: gather_cfg.py:121
bool zsMarkAndPass() const
was ZS MarkAndPass?
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)