CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalLaserHBHEFilter2012.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalLaserHBHEFilter2012
4 // Class: HcalLaserHBHEFilter2012
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 verbose_; // if set to true, then the run:LS:event for any event failing the cut will be printed out
64  std::string prefix_; // prefix will be printed before any event if verbose mode is true, in order to make searching for events easier
65  int minCalibChannelsHBHELaser_; // set minimum number of HBHE Calib events that causes an event to be considered a bad (i.e., HBHE laser) event
66  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
70 
71  double HBHEcalibThreshold_; // minimum integrated charge needed for a hit to count as an occupied calib channel
72  std::vector <int> CalibTS_; // time slices used when integrating calib charges
75  std::ofstream outfile_;
76 };
77 
78 //
79 // constants, enums and typedefs
80 //
81 
82 //
83 // static data member definitions
84 //
85 
86 //
87 // constructors and destructor
88 //
90 {
91  //now do what ever initialization is needed
92  verbose_ = ps.getUntrackedParameter<bool>("verbose",false);
93  prefix_ = ps.getUntrackedParameter<std::string>("prefix","");
94  minCalibChannelsHBHELaser_ = ps.getUntrackedParameter<int>("minCalibChannelsHBHELaser",20);
95  minFracDiffHBHELaser_ = ps.getUntrackedParameter<double>("minFracDiffHBHELaser",0.3);
96  edm::InputTag digi_default("hcalDigis");
97  digiLabel_ = ps.getUntrackedParameter<edm::InputTag>("digiLabel",digi_default);
98 
99  tok_calib_ = consumes<HcalCalibDigiCollection>(digiLabel_);
100  tok_hbhe_ = consumes<HBHEDigiCollection>(digiLabel_);
101 
102  HBHEcalibThreshold_ = ps.getUntrackedParameter<double>("HBHEcalibThreshold",15);
103  std::vector <int> dummyTS;
104  for (int i=3;i<=6;++i)
105  dummyTS.push_back(i);
106  CalibTS_ = ps.getUntrackedParameter<std::vector<int> >("CalibTS",dummyTS);
107  WriteBadToFile_=ps.getUntrackedParameter<bool>("WriteBadToFile",false);
108  if (WriteBadToFile_)
109  outfile_.open("badHcalLaserList_hbhefilter.txt");
110  forceFilterTrue_=ps.getUntrackedParameter<bool>("forceFilterTrue",false);
111 } // HcalLaserHBHEFilter2012::HcalLaserHBHEFilter2012 constructor
112 
113 
115 {
116 
117  // do anything here that needs to be done at destruction time
118  // (e.g. close files, deallocate resources etc.)
119 
120 }
121 
122 
123 //
124 // member functions
125 //
126 
127 // ------------ method called on each new Event ------------
128 bool
130 {
131  // Step 1:: try to get calib digi and HBHE collections.
132  // Return true if collection not found? Or false? What should default behavior be?
134  if (!(iEvent.getByToken(tok_calib_,calib_digi)))
135  {
136  edm::LogWarning("HcalLaserHBHEFilter2012")<< digiLabel_<<" calib_digi not available";
137  return true;
138  }
139 
140  if (!(calib_digi.isValid()))
141  {
142  edm::LogWarning("HcalLaserHBHEFilter2012")<< digiLabel_<<" calib_digi is not valid";
143  return true;
144  }
145 
147  if (!(iEvent.getByToken(tok_hbhe_,hbhe_digi)))
148  {
149  edm::LogWarning("HcalLaserHBHEFilter2012")<< digiLabel_<<" hbhe_digi not available";
150  return true;
151  }
152 
153  if (!(hbhe_digi.isValid()))
154  {
155  edm::LogWarning("HcalLaserHBHEFilter2012")<< digiLabel_<<" hbhe_digi is not valid";
156  return true;
157  }
158 
159  // Step 2: Count HBHE digi calib channels
160  int ncalibHBHE=0; // this will track number of HBHE digi channels
161 
162 
163  for (HcalCalibDigiCollection::const_iterator Calibiter = calib_digi->begin();
164  Calibiter != calib_digi->end(); ++ Calibiter)
165  {
166  const HcalCalibDataFrame digi = (const HcalCalibDataFrame)(*Calibiter);
167  if (digi.zsMarkAndPass()) continue; // skip digis labeled as "mark and pass" in NZS events
168  HcalCalibDetId myid=(HcalCalibDetId)digi.id();
169  if (myid.hcalSubdet()!=HcalBarrel && myid.hcalSubdet()!=HcalEndcap) continue;
170  if ( myid.calibFlavor()==HcalCalibDetId::HOCrosstalk) continue;
171  // Compute charge in current channel (for relevant TS only)
172  // If total charge in channel exceeds threshold, increment count of calib channels
173  double thischarge=0;
174  for (unsigned int i=0;i<CalibTS_.size();++i)
175  {
176  thischarge+=digi[CalibTS_[i]].nominal_fC();
177  if (thischarge> HBHEcalibThreshold_ )
178  {
179  ++ncalibHBHE;
180  break;
181  }
182  }
183 
184  if (ncalibHBHE>=minCalibChannelsHBHELaser_)
185  {
186  if (verbose_)
187  std::cout <<prefix_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
188  if (WriteBadToFile_)
189  outfile_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
190  if (forceFilterTrue_) return true; // if special input boolean set, always return true, regardless of filter decision
191  else return false;
192  }
193  }
194 
195  // Step 3: Look at distribution of HBHE hits
196 
197  // Count digis in good, bad RBXes. ('bad' RBXes see no laser signal)
198  double badrbxfrac=0.;
199  double goodrbxfrac=0.;
200  int Nbad=72*3; // 3 bad RBXes, 72 channels each
201  int Ngood=2592*2-Nbad; // remaining HBHE channels are 'good'
202  for (HBHEDigiCollection::const_iterator hbhe = hbhe_digi->begin();
203  hbhe != hbhe_digi->end(); ++ hbhe)
204  {
205  const HBHEDataFrame digi = (const HBHEDataFrame)(*hbhe);
206  HcalDetId myid=(HcalDetId)digi.id();
207  bool isbad=false; // assume channel is not bad
208  if ( myid.subdet()==HcalBarrel && myid.ieta()<0 )
209  {
210  if (myid.iphi()>=15 && myid.iphi()<=18) isbad=true;
211  else if (myid.iphi()>=27 && myid.iphi()<=34) isbad=true;
212  }
213  if (isbad==true) badrbxfrac+=1.;
214  else goodrbxfrac+=1.;
215  }
216  goodrbxfrac/=Ngood;
217  badrbxfrac/=Nbad;
218  if (goodrbxfrac-badrbxfrac>minFracDiffHBHELaser_)
219  {
220  if (verbose_)
221  std::cout <<prefix_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
222  if (WriteBadToFile_)
223  outfile_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
224 
225  if (forceFilterTrue_) return true; // if special input boolean set, always return true, regardless of filter decision
226  else return false;
227  }
228  // Step 4: HBHE laser tests passed. return true
229  return true;
230 
231 } // HcalLaserHBHEFilter2012::filter
232 
233 // ------------ method called once each job just after ending the event loop ------------
234 void
236  if (WriteBadToFile_) outfile_.close();
237 
238 }
239 
240 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
241 void
243  //The following says we do not know what parameters are allowed so do no validation
244  // Please change this to state exactly what you do use, even if it is no parameters
246  desc.setUnknown();
247  descriptions.addDefault(desc);
248 }
249 //define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
HcalLaserHBHEFilter2012(const edm::ParameterSet &)
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
virtual bool filter(edm::Event &, const edm::EventSetup &) override
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< HBHEDigiCollection > tok_hbhe_
int ieta() const
get the cell ieta
Definition: HcalDetId.h:51
const HcalCalibDetId & id() const
bool isValid() const
Definition: HandleBase.h:75
int iphi() const
get the cell iphi
Definition: HcalDetId.h:53
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)
edm::EDGetTokenT< HcalCalibDigiCollection > tok_calib_
virtual void endJob() override