CMS 3D CMS Logo

SiPixelQualityHistory.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: SiPixelQualityHistory
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Tue Sep 18 17:52:00 CEST 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
23 
24 #include <vector>
25 #include <map>
26 
27 //#include "TGraph.h"
28 #include "TH1F.h"
29 
32 
36 
39 
41 
43 
46 
48 
51 
53 //
54 // class decleration
55 //
56 
57 class SiPixelQualityHistory : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
58 public:
60  ~SiPixelQualityHistory() override;
61 
62  enum { Summary, Module, ROC };
63 
64 private:
65  void beginJob() override;
66  void beginRun(const edm::Run&, const edm::EventSetup&) override;
67  void endRun(const edm::Run&, const edm::EventSetup&) override {}
68  void analyze(const edm::Event&, const edm::EventSetup&) override;
69  void endJob() override;
70 
71  // ----------member data ---------------------------
72 
74  const std::vector<edm::ParameterSet> m_monitoredspq;
75  std::vector<edm::ESGetToken<SiPixelQuality, SiPixelQualityRcd>> m_spqTokens;
76  const unsigned int m_mode;
77  const bool m_run;
78  const unsigned int m_maxLS;
79  const unsigned int m_LSfrac;
80  // std::map<std::string,TGraph*> m_history;
81  std::map<std::string, TH1F*> m_history;
82  std::map<std::string, TProfile**> m_badmodrun;
83 };
84 
85 //
86 // constants, enums and typedefs
87 //
88 
89 //
90 // static data member definitions
91 //
92 
93 //
94 // constructors and destructor
95 //
97  : m_rhm(consumesCollector()),
98  m_monitoredspq(iConfig.getParameter<std::vector<edm::ParameterSet>>("monitoredSiPixelQuality")),
99  m_mode(iConfig.getUntrackedParameter<unsigned int>("granularityMode", Module)),
100  m_run(iConfig.getParameter<bool>("runProcess")),
101  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin", 100)),
102  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction", 4)),
103  m_history(),
104  m_badmodrun() {
105  //now do what ever initialization is needed
106  usesResource(TFileService::kSharedResource);
107 
109 
110  for (const auto& ps : m_monitoredspq) {
111  m_spqTokens.emplace_back(
112  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{"", ps.getParameter<std::string>("spqLabel")}));
113 
114  std::string name = ps.getParameter<std::string>("name");
115 
116  if (m_run)
117  m_history[name] = tfserv->make<TH1F>(name.c_str(), name.c_str(), 10, 0, 10);
118 
119  char hrunname[400];
120  sprintf(hrunname, "badmodrun_%s", name.c_str());
121  char hruntitle[400];
122  sprintf(hruntitle, "Number of bad modules %s", name.c_str());
123  m_badmodrun[name] = m_rhm.makeTProfile(hrunname, hruntitle, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
124  }
125 }
126 
128  // do anything here that needs to be done at desctruction time
129  // (e.g. close files, deallocate resources etc.)
130 }
131 
132 //
133 // member functions
134 //
135 
136 // ------------ method called to for each event ------------
138  // edm::LogInfo("EventProcessing") << "event being processed";
139 
140  for (std::size_t iMon = 0; iMon != m_monitoredspq.size(); ++iMon) {
141  std::string name = m_monitoredspq[iMon].getParameter<std::string>("name");
142  const auto& spq = iSetup.getData(m_spqTokens[iMon]);
143 
144  int nbad = 0;
145 
146  if (m_mode == Summary) {
147  // nbad = spq.BadModuleNumber();
148 
149  } else {
150  std::vector<SiPixelQuality::disabledModuleType> bads = spq.getBadComponentList();
151 
152  LogDebug("BadComponents") << bads.size() << " bad components found";
153 
154  for (const auto& bc : bads) {
155  if (m_mode == Module) {
156  if (spq.IsModuleBad(bc.DetID))
157  ++nbad;
158  // if(bc.errorType==0) ++nbad;
159  } else if (m_mode == ROC) {
160  for (int roc = 1; roc < 2 * 2 * 2 * 2 * 2 * 2 * 2 + 1; roc *= 2) {
161  if ((bc.BadRocs & roc) > 0)
162  ++nbad;
163  }
164  }
165  }
166  }
167  if (m_badmodrun.find(name) != m_badmodrun.end() && m_badmodrun[name] && *m_badmodrun[name]) {
168  (*m_badmodrun[name])->Fill(iEvent.orbitNumber(), nbad);
169  }
170  }
171 }
172 
173 void SiPixelQualityHistory::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
174  m_rhm.beginRun(iRun);
175 
176  // loop on all the SiPixelQuality objects to be monitored
177  for (std::size_t iMon = 0; iMon != m_monitoredspq.size(); ++iMon) {
178  const auto& ps = m_monitoredspq[iMon];
179  std::string name = ps.getParameter<std::string>("name");
180 
181  if (m_badmodrun.find(name) != m_badmodrun.end()) {
182  if (m_badmodrun[name] && *m_badmodrun[name]) {
183  (*m_badmodrun[name])->SetCanExtend(TH1::kXaxis);
184  (*m_badmodrun[name])->GetXaxis()->SetTitle("time [Orb#]");
185  (*m_badmodrun[name])->GetYaxis()->SetTitle("bad components");
186  }
187  }
188 
189  if (m_run) {
190  const auto& spq = iSetup.getData(m_spqTokens[iMon]);
191 
192  int nbad = 0;
193 
194  if (m_mode == Summary) {
195  // nbad = spq.BadModuleNumber();
196 
197  } else {
198  std::vector<SiPixelQuality::disabledModuleType> bads = spq.getBadComponentList();
199 
200  LogDebug("BadComponents") << bads.size() << " bad components found";
201 
202  for (const auto& bc : bads) {
203  if (m_mode == Module) {
204  if (spq.IsModuleBad(bc.DetID))
205  ++nbad;
206  // if(bc.errorType==0) ++nbad;
207  } else if (m_mode == ROC) {
208  for (int roc = 1; roc < 2 * 2 * 2 * 2 * 2 * 2 * 2 + 1; roc *= 2) {
209  if ((bc.BadRocs & roc) > 0)
210  ++nbad;
211  }
212  }
213  }
214  }
215  char runname[100];
216  sprintf(runname, "%d", iRun.run());
217  LogDebug("AnalyzedRun") << name << " " << runname << " " << nbad;
218  m_history[name]->Fill(runname, nbad);
219  }
220  }
221 }
222 
223 // ------------ method called once each job just before starting event loop ------------
225 
226 // ------------ method called once each job just after ending the event loop ------------
228  /*
229  for(std::vector<edm::ParameterSet>::const_iterator ps=m_monitoredspq.begin();ps!=m_monitoredspq.end();++ps) {
230 
231  std::string name = ps->getParameter<std::string>("name");
232  m_history[name]->Write();
233 
234  }
235  */
236 }
237 
238 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
void beginRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::string, TH1F * > m_history
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
RunHistogramManager m_rhm
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
const std::vector< edm::ParameterSet > m_monitoredspq
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::vector< edm::ESGetToken< SiPixelQuality, SiPixelQualityRcd > > m_spqTokens
void beginRun(const edm::Run &iRun)
const unsigned int m_LSfrac
HLT enums.
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::map< std::string, TProfile ** > m_badmodrun
SiPixelQualityHistory(const edm::ParameterSet &)
Definition: Run.h:45
const unsigned int m_maxLS
#define LogDebug(id)