CMS 3D CMS Logo

SiStripQualityHistory.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: SiStripQualityHistory
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 
38 
40 
42 
45 
47 
50 
52 //
53 // class decleration
54 //
55 
56 class SiStripQualityHistory : public edm::one::EDAnalyzer<edm::one::WatchRuns, edm::one::SharedResources> {
57 public:
59  ~SiStripQualityHistory() override;
60 
61  enum { Module, Fiber, APV, Strip };
62 
63 private:
64  void beginJob() override;
65  void beginRun(const edm::Run&, const edm::EventSetup&) override;
66  void endRun(const edm::Run&, const edm::EventSetup&) override {}
67  void analyze(const edm::Event&, const edm::EventSetup&) override;
68  void endJob() override;
69 
70  // ----------member data ---------------------------
71 
73  const std::vector<edm::ParameterSet> _monitoredssq;
74  std::vector<edm::ESGetToken<SiStripQuality, SiStripQualityRcd>> _ssqTokens;
75  const unsigned int _mode;
76  const bool m_run;
77  const unsigned int m_maxLS;
78  const unsigned int m_LSfrac;
79  // std::map<std::string,TGraph*> _history;
80  std::map<std::string, TH1F*> _history;
81  std::map<std::string, TProfile**> m_badmodrun;
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  : m_rhm(consumesCollector()),
97  _monitoredssq(iConfig.getParameter<std::vector<edm::ParameterSet>>("monitoredSiStripQuality")),
98  _mode(iConfig.getUntrackedParameter<unsigned int>("granularityMode", Module)),
99  m_run(iConfig.getParameter<bool>("runProcess")),
100  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin", 100)),
101  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction", 4)),
102  _history(),
103  m_badmodrun() {
104  //now do what ever initialization is needed
105  usesResource(TFileService::kSharedResource);
106 
108 
109  for (const auto& ps : _monitoredssq) {
110  _ssqTokens.emplace_back(
111  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{"", ps.getParameter<std::string>("ssqLabel")}));
112  std::string name = ps.getParameter<std::string>("name");
113  // _history[name] = tfserv->make<TGraph>();
114  // _history[name]->SetName(name.c_str()); _history[name]->SetTitle(name.c_str());
115 
116  if (m_run)
117  _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 != _monitoredssq.size(); ++iMon) {
141  std::string name = _monitoredssq[iMon].getParameter<std::string>("name");
142  const auto& ssq = iSetup.getData(_ssqTokens[iMon]);
143 
144  std::vector<SiStripQuality::BadComponent> bads = ssq.getBadComponentList();
145 
146  LogDebug("BadComponents") << bads.size() << " bad components found";
147 
148  int nbad = 0;
149 
150  if (_mode == Module || _mode == Fiber || _mode == APV) {
151  for (const auto& bc : bads) {
152  if (_mode == Module) {
153  if (bc.BadModule)
154  ++nbad;
155  } else if (_mode == Fiber) {
156  for (int fiber = 1; fiber < 5; fiber *= 2) {
157  if ((bc.BadFibers & fiber) > 0)
158  ++nbad;
159  }
160  } else if (_mode == APV) {
161  for (int apv = 1; apv < 33; apv *= 2) {
162  if ((bc.BadApvs & apv) > 0)
163  ++nbad;
164  }
165  }
166  }
167  } else if (_mode == Strip) {
168  SiStripBadStrip::ContainerIterator dbegin = ssq.getDataVectorBegin();
169  SiStripBadStrip::ContainerIterator dend = ssq.getDataVectorEnd();
170  for (SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
171  nbad += ssq.decode(*data).range;
172  }
173  }
174 
175  if (m_badmodrun.find(name) != m_badmodrun.end() && m_badmodrun[name] && *m_badmodrun[name]) {
176  (*m_badmodrun[name])->Fill(iEvent.orbitNumber(), nbad);
177  }
178  }
179 }
180 
181 void SiStripQualityHistory::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
182  m_rhm.beginRun(iRun);
183 
184  // loop on all the SiStripQuality objects to be monitored
185  for (std::size_t iMon = 0; iMon != _monitoredssq.size(); ++iMon) {
186  std::string name = _monitoredssq[iMon].getParameter<std::string>("name");
187 
188  if (m_badmodrun.find(name) != m_badmodrun.end()) {
189  if (m_badmodrun[name] && *m_badmodrun[name]) {
190  (*m_badmodrun[name])->SetCanExtend(TH1::kXaxis);
191  (*m_badmodrun[name])->GetXaxis()->SetTitle("time [Orb#]");
192  (*m_badmodrun[name])->GetYaxis()->SetTitle("bad components");
193  }
194  }
195 
196  if (m_run) {
197  const auto& ssq = iSetup.getData(_ssqTokens[iMon]);
198 
199  std::vector<SiStripQuality::BadComponent> bads = ssq.getBadComponentList();
200 
201  LogDebug("BadComponents") << bads.size() << " bad components found";
202 
203  int nbad = 0;
204 
205  if (_mode == Module || _mode == Fiber || _mode == APV) {
206  for (const auto& bc : bads) {
207  if (_mode == Module) {
208  if (bc.BadModule)
209  ++nbad;
210  } else if (_mode == Fiber) {
211  for (int fiber = 1; fiber < 5; fiber *= 2) {
212  if ((bc.BadFibers & fiber) > 0)
213  ++nbad;
214  }
215  } else if (_mode == APV) {
216  for (int apv = 1; apv < 33; apv *= 2) {
217  if ((bc.BadApvs & apv) > 0)
218  ++nbad;
219  }
220  }
221  }
222  } else if (_mode == Strip) {
223  SiStripBadStrip::ContainerIterator dbegin = ssq.getDataVectorBegin();
224  SiStripBadStrip::ContainerIterator dend = ssq.getDataVectorEnd();
225  for (SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
226  nbad += ssq.decode(*data).range;
227  }
228  }
229 
230  // _history[name]->SetPoint(_history[name]->GetN(),iRun.run(),nbad);
231  char runname[100];
232  sprintf(runname, "%d", iRun.run());
233  LogDebug("AnalyzedRun") << name << " " << runname << " " << nbad;
234  _history[name]->Fill(runname, nbad);
235  }
236  }
237 }
238 
239 // ------------ method called once each job just before starting event loop ------------
241 
242 // ------------ method called once each job just after ending the event loop ------------
244  /*
245  for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
246 
247  std::string name = ps->getParameter<std::string>("name");
248  _history[name]->Write();
249 
250  }
251  */
252 }
253 
254 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< unsigned int >::const_iterator ContainerIterator
SiStripQualityHistory(const edm::ParameterSet &)
void endRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::string, TProfile ** > m_badmodrun
const std::vector< edm::ParameterSet > _monitoredssq
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)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
bool getData(T &iHolder) const
Definition: EventSetup.h:122
std::vector< edm::ESGetToken< SiStripQuality, SiStripQualityRcd > > _ssqTokens
const unsigned int m_LSfrac
void beginRun(const edm::Run &iRun)
const unsigned int m_maxLS
void beginRun(const edm::Run &, const edm::EventSetup &) override
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
RunHistogramManager m_rhm
std::map< std::string, TH1F * > _history
Definition: Run.h:45
#define LogDebug(id)