CMS 3D CMS Logo

FEDBadModuleFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: FEDBadModuleFilter
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Wed Oct 22 17:54:30 CEST 2008
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 #include "TProfile.h"
23 
24 // user include files
27 
30 
32 
33 #include <vector>
34 #include <set>
35 
37 
39 
42 
45 
46 //
47 // class declaration
48 //
49 
51  public:
52  explicit FEDBadModuleFilter(const edm::ParameterSet&);
53  ~FEDBadModuleFilter() override;
54 
55 private:
56  void beginJob() override ;
57  bool filter(edm::Event&, const edm::EventSetup&) override;
58  void beginRun(const edm::Run&, const edm::EventSetup&) override;
59  void endJob() override ;
60 
61  // ----------member data ---------------------------
62 
64  unsigned int m_modulethr;
65  std::set<unsigned int> m_modules;
69  const unsigned int m_maxLS;
70  const unsigned int m_LSfrac;
72  TH1F** m_nbadrun;
73  TProfile** m_nbadvsorbrun;
74 
75 };
76 
77 //
78 // constants, enums and typedefs
79 //
80 
81 //
82 // static data member definitions
83 //
84 
85 //
86 // constructors and destructor
87 //
89  m_digibadmodulecollectionToken(consumes<DetIdCollection>(iConfig.getParameter<edm::InputTag>("collectionName"))),
90  m_modulethr(iConfig.getParameter<unsigned int>("badModThr")),
91  m_modsel(),
92  m_wantedhist(iConfig.getUntrackedParameter<bool>("wantedHisto",false)),
93  m_printlist(iConfig.getUntrackedParameter<bool>("printList",false)),
94  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin",100)),
95  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction",4)),
97 
98 {
99  //now do what ever initialization is needed
100 
101  if(m_wantedhist) {
102  m_nbadrun = m_rhm.makeTH1F("nbadrun","Number of bad channels",500,-0.5,499.5);
103  m_nbadvsorbrun = m_rhm.makeTProfile("nbadvsorbrun","Number of bad channels vs time",m_LSfrac*m_maxLS,0,m_maxLS*262144);
104  }
105 
106  std::vector<unsigned int> modules = iConfig.getUntrackedParameter<std::vector<unsigned int> >("moduleList",std::vector<unsigned int>());
107  m_modules = std::set<unsigned int>(modules.begin(),modules.end());
108 
109  if(iConfig.exists("moduleSelection")) {
110  m_modsel = DetIdSelector(iConfig.getUntrackedParameter<edm::ParameterSet>("moduleSelection"));
111  }
112 }
113 
114 
116 {
117 
118  // do anything here that needs to be done at desctruction time
119  // (e.g. close files, deallocate resources etc.)
120 
121 }
122 
123 
124 //
125 // member functions
126 //
127 
128 // ------------ method called on each new Event ------------
129 bool
131 {
132  using namespace edm;
133 
134  Handle<DetIdCollection > badmodules;
135  iEvent.getByToken(m_digibadmodulecollectionToken,badmodules);
136 
137  unsigned int nbad = 0;
138  if(m_printlist || !m_modules.empty() || m_modsel.isValid() ) {
139  for(DetIdCollection::const_iterator mod = badmodules->begin(); mod!=badmodules->end(); ++mod) {
140  if((m_modules.empty() || m_modules.find(*mod) != m_modules.end() ) && (!m_modsel.isValid() || m_modsel.isSelected(*mod))) {
141  ++nbad;
142  if(m_printlist) edm::LogInfo("FEDBadModule") << *mod;
143  }
144  }
145  }
146  else {
147  nbad = badmodules->size();
148  }
149 
150  if(m_wantedhist) {
151  if(m_nbadvsorbrun && *m_nbadvsorbrun) (*m_nbadvsorbrun)->Fill(iEvent.orbitNumber(),nbad);
152  if(m_nbadrun && *m_nbadrun) (*m_nbadrun)->Fill(nbad);
153  }
154 
155  return (nbad >= m_modulethr);
156 
157 }
158 
159 // ------------ method called once each job just before starting event loop ------------
160 void
162 {
163 }
164 
165 // ------------ method called once each job just after ending the event loop ------------
166 void
168 }
169 
170 void
172 {
173 
174  if(m_wantedhist) {
175 
176  m_rhm.beginRun(iRun);
177  if(*m_nbadvsorbrun) {
178  (*m_nbadvsorbrun)->SetCanExtend(TH1::kXaxis);
179  (*m_nbadvsorbrun)->GetXaxis()->SetTitle("time [Orb#]");
180  (*m_nbadvsorbrun)->GetYaxis()->SetTitle("Bad Channels");
181  }
182 
183  }
184 }
185 
186 //define this as a plug-in
void beginJob() override
size_type size() const
Definition: EDCollection.h:97
T getUntrackedParameter(std::string const &, T const &) const
const unsigned int m_maxLS
edm::EDGetTokenT< DetIdCollection > m_digibadmodulecollectionToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
const_iterator end() const
Definition: EDCollection.h:153
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool filter(edm::Event &, const edm::EventSetup &) override
bool isSelected(const DetId &detid) const
std::set< unsigned int > m_modules
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void beginRun(const edm::Run &, const edm::EventSetup &) override
void endJob() override
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
RunHistogramManager m_rhm
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
FEDBadModuleFilter(const edm::ParameterSet &)
int orbitNumber() const
Definition: EventBase.h:65
bool isValid() const
Definition: DetIdSelector.h:23
const_iterator begin() const
Definition: EDCollection.h:146
void beginRun(const edm::Run &iRun)
HLT enums.
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
const unsigned int m_LSfrac
Definition: Run.h:45
std::vector< DetId >::const_iterator const_iterator
Definition: EDCollection.h:19