CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalLaserHFFilter2012.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalLaserHFFilter2012
4 // Class: HcalLaserHFFilter2012
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 //
49 // class declaration
50 //
51 
53 public:
56 
57  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
58 
59 private:
60  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
61  virtual void endJob() override;
62 
63  // ----------member data ---------------------------
64  bool verbose_; // if set to true, then the run:LS:event for any event failing the cut will be printed out
65  std::string prefix_; // prefix will be printed before any event if verbose mode is true, in order to make searching for events easier
66  int minCalibChannelsHFLaser_; // set minimum number of HF Calib events that causes an event to be considered a bad (i.e., HF laser) event
69 
72  std::ofstream outfile_;
73 };
74 
75 //
76 // constants, enums and typedefs
77 //
78 
79 //
80 // static data member definitions
81 //
82 
83 //
84 // constructors and destructor
85 //
87 {
88  //now do what ever initialization is needed
89  verbose_ = ps.getUntrackedParameter<bool>("verbose",false);
90  prefix_ = ps.getUntrackedParameter<std::string>("prefix","");
91  minCalibChannelsHFLaser_=ps.getUntrackedParameter<int>("minCalibChannelsHFLaser",10);
92  edm::InputTag digi_default("hcalDigis");
93  digiLabel_ = ps.getUntrackedParameter<edm::InputTag>("digiLabel",digi_default);
94  tok_calib_ = consumes<HcalCalibDigiCollection>(digiLabel_);
95  WriteBadToFile_=ps.getUntrackedParameter<bool>("WriteBadToFile",false);
96  if (WriteBadToFile_)
97  outfile_.open("badHcalLaserList_hffilter.txt");
98  forceFilterTrue_=ps.getUntrackedParameter<bool>("forceFilterTrue",false);
99 
100 } // HcalLaserHFFilter2012::HcalLaserHFFilter2012 constructor
101 
102 
104 {
105 
106  // do anything here that needs to be done at destruction time
107  // (e.g. close files, deallocate resources etc.)
108 
109 }
110 
111 
112 //
113 // member functions
114 //
115 
116 // ------------ method called on each new Event ------------
117 bool
119 {
120  // Step 1:: try to get calib digi collection.
121  // Return true if collection not found? Or false? What should default behavior be?
123  if (!(iEvent.getByToken(tok_calib_,calib_digi)))
124  {
125  edm::LogWarning("HcalLaserHFFilter2012")<< digiLabel_<<" calib_digi not available";
126  return true;
127  }
128 
129  if (!(calib_digi.isValid()))
130  {
131  edm::LogWarning("HcalLaserHFFilter2012")<< digiLabel_<<" calib_digi is not valid";
132  return true;
133  }
134 
135  // Step 2: Count HF digi calib channels
136  int ncalibHF=0; // this will track number of HF digi channels
137 
138 
139  for (HcalCalibDigiCollection::const_iterator Calibiter = calib_digi->begin();
140  Calibiter != calib_digi->end(); ++ Calibiter)
141  {
142  const HcalCalibDataFrame digi = (const HcalCalibDataFrame)(*Calibiter);
143  if (digi.zsMarkAndPass()) continue; // skip digis labeled as "mark and pass" in NZS events
144  HcalCalibDetId myid=(HcalCalibDetId)digi.id();
145  if (myid.hcalSubdet()!=HcalForward) continue;
146  ++ncalibHF;
147  if (ncalibHF>=minCalibChannelsHFLaser_)
148  {
149  if (verbose_) std::cout <<prefix_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
150  if (WriteBadToFile_)
151  outfile_<<iEvent.id().run()<<":"<<iEvent.luminosityBlock()<<":"<<iEvent.id().event()<<std::endl;
152  if (forceFilterTrue_) return true; // if special input boolean set, always return true, regardless of filter decision
153  else return false;
154  }
155  }
156 
157  return true;
158 } // HcalLaserHFFilter2012::filter
159 
160 // ------------ method called once each job just after ending the event loop ------------
161 void
163  if (WriteBadToFile_) outfile_.close();
164 }
165 
166 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
167 void
169  //The following says we do not know what parameters are allowed so do no validation
170  // Please change this to state exactly what you do use, even if it is no parameters
172  desc.setUnknown();
173  descriptions.addDefault(desc);
174 }
175 //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
virtual bool filter(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HcalLaserHFFilter2012(const edm::ParameterSet &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< HcalCalibDigiCollection > tok_calib_
std::vector< HcalCalibDataFrame >::const_iterator const_iterator
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
const HcalCalibDetId & id() const
bool isValid() const
Definition: HandleBase.h:75
virtual void endJob() override
edm::EventID id() const
Definition: EventBase.h:60
tuple cout
Definition: gather_cfg.py:121
bool zsMarkAndPass() const
was ZS MarkAndPass?
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)