CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 analyze(const edm::Event&, const edm::EventSetup&) override;
67  void endJob() override;
68 
69  // ----------member data ---------------------------
70 
72  const std::vector<edm::ParameterSet> _monitoredssq;
73  std::vector<edm::ESGetToken<SiStripQuality, SiStripQualityRcd>> _ssqTokens;
74  const unsigned int _mode;
75  const bool m_run;
76  const unsigned int m_maxLS;
77  const unsigned int m_LSfrac;
78  // std::map<std::string,TGraph*> _history;
79  std::map<std::string, TH1F*> _history;
80  std::map<std::string, TProfile**> m_badmodrun;
81 };
82 
83 //
84 // constants, enums and typedefs
85 //
86 
87 //
88 // static data member definitions
89 //
90 
91 //
92 // constructors and destructor
93 //
95  : m_rhm(consumesCollector()),
96  _monitoredssq(iConfig.getParameter<std::vector<edm::ParameterSet>>("monitoredSiStripQuality")),
97  _mode(iConfig.getUntrackedParameter<unsigned int>("granularityMode", Module)),
98  m_run(iConfig.getParameter<bool>("runProcess")),
99  m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin", 100)),
100  m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction", 4)),
101  _history(),
102  m_badmodrun() {
103  //now do what ever initialization is needed
104 
106 
107  for (const auto& ps : _monitoredssq) {
108  _ssqTokens.emplace_back(
109  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag{"", ps.getParameter<std::string>("ssqLabel")}));
110  std::string name = ps.getParameter<std::string>("name");
111  // _history[name] = tfserv->make<TGraph>();
112  // _history[name]->SetName(name.c_str()); _history[name]->SetTitle(name.c_str());
113 
114  if (m_run)
115  _history[name] = tfserv->make<TH1F>(name.c_str(), name.c_str(), 10, 0, 10);
116 
117  char hrunname[400];
118  sprintf(hrunname, "badmodrun_%s", name.c_str());
119  char hruntitle[400];
120  sprintf(hruntitle, "Number of bad modules %s", name.c_str());
121  m_badmodrun[name] = m_rhm.makeTProfile(hrunname, hruntitle, m_LSfrac * m_maxLS, 0, m_maxLS * 262144);
122  }
123 }
124 
126  // do anything here that needs to be done at desctruction time
127  // (e.g. close files, deallocate resources etc.)
128 }
129 
130 //
131 // member functions
132 //
133 
134 // ------------ method called to for each event ------------
136  // edm::LogInfo("EventProcessing") << "event being processed";
137 
138  for (std::size_t iMon = 0; iMon != _monitoredssq.size(); ++iMon) {
139  std::string name = _monitoredssq[iMon].getParameter<std::string>("name");
140  const auto& ssq = iSetup.getData(_ssqTokens[iMon]);
141 
142  std::vector<SiStripQuality::BadComponent> bads = ssq.getBadComponentList();
143 
144  LogDebug("BadComponents") << bads.size() << " bad components found";
145 
146  int nbad = 0;
147 
148  if (_mode == Module || _mode == Fiber || _mode == APV) {
149  for (const auto& bc : bads) {
150  if (_mode == Module) {
151  if (bc.BadModule)
152  ++nbad;
153  } else if (_mode == Fiber) {
154  for (int fiber = 1; fiber < 5; fiber *= 2) {
155  if ((bc.BadFibers & fiber) > 0)
156  ++nbad;
157  }
158  } else if (_mode == APV) {
159  for (int apv = 1; apv < 33; apv *= 2) {
160  if ((bc.BadApvs & apv) > 0)
161  ++nbad;
162  }
163  }
164  }
165  } else if (_mode == Strip) {
166  SiStripBadStrip::ContainerIterator dbegin = ssq.getDataVectorBegin();
167  SiStripBadStrip::ContainerIterator dend = ssq.getDataVectorEnd();
168  for (SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
169  nbad += ssq.decode(*data).range;
170  }
171  }
172 
173  if (m_badmodrun.find(name) != m_badmodrun.end() && m_badmodrun[name] && *m_badmodrun[name]) {
174  (*m_badmodrun[name])->Fill(iEvent.orbitNumber(), nbad);
175  }
176  }
177 }
178 
179 void SiStripQualityHistory::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
180  m_rhm.beginRun(iRun);
181 
182  // loop on all the SiStripQuality objects to be monitored
183  for (std::size_t iMon = 0; iMon != _monitoredssq.size(); ++iMon) {
184  std::string name = _monitoredssq[iMon].getParameter<std::string>("name");
185 
186  if (m_badmodrun.find(name) != m_badmodrun.end()) {
187  if (m_badmodrun[name] && *m_badmodrun[name]) {
188  (*m_badmodrun[name])->SetCanExtend(TH1::kXaxis);
189  (*m_badmodrun[name])->GetXaxis()->SetTitle("time [Orb#]");
190  (*m_badmodrun[name])->GetYaxis()->SetTitle("bad components");
191  }
192  }
193 
194  if (m_run) {
195  const auto& ssq = iSetup.getData(_ssqTokens[iMon]);
196 
197  std::vector<SiStripQuality::BadComponent> bads = ssq.getBadComponentList();
198 
199  LogDebug("BadComponents") << bads.size() << " bad components found";
200 
201  int nbad = 0;
202 
203  if (_mode == Module || _mode == Fiber || _mode == APV) {
204  for (const auto& bc : bads) {
205  if (_mode == Module) {
206  if (bc.BadModule)
207  ++nbad;
208  } else if (_mode == Fiber) {
209  for (int fiber = 1; fiber < 5; fiber *= 2) {
210  if ((bc.BadFibers & fiber) > 0)
211  ++nbad;
212  }
213  } else if (_mode == APV) {
214  for (int apv = 1; apv < 33; apv *= 2) {
215  if ((bc.BadApvs & apv) > 0)
216  ++nbad;
217  }
218  }
219  }
220  } else if (_mode == Strip) {
221  SiStripBadStrip::ContainerIterator dbegin = ssq.getDataVectorBegin();
222  SiStripBadStrip::ContainerIterator dend = ssq.getDataVectorEnd();
223  for (SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
224  nbad += ssq.decode(*data).range;
225  }
226  }
227 
228  // _history[name]->SetPoint(_history[name]->GetN(),iRun.run(),nbad);
229  char runname[100];
230  sprintf(runname, "%d", iRun.run());
231  LogDebug("AnalyzedRun") << name << " " << runname << " " << nbad;
232  _history[name]->Fill(runname, nbad);
233  }
234  }
235 }
236 
237 // ------------ method called once each job just before starting event loop ------------
239 
240 // ------------ method called once each job just after ending the event loop ------------
242  /*
243  for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
244 
245  std::string name = ps->getParameter<std::string>("name");
246  _history[name]->Write();
247 
248  }
249  */
250 }
251 
252 //define this as a plug-in
void analyze(const edm::Event &, const edm::EventSetup &) override
RunNumber_t run() const
Definition: RunBase.h:40
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
std::vector< unsigned int >::const_iterator ContainerIterator
SiStripQualityHistory(const edm::ParameterSet &)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
std::map< std::string, TProfile ** > m_badmodrun
bool getData(T &iHolder) const
Definition: EventSetup.h:128
const std::vector< edm::ParameterSet > _monitoredssq
int iEvent
Definition: GenABIO.cc:224
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
m_rhm(consumesCollector())
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
int orbitNumber() const
Definition: EventBase.h:65
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
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
RunHistogramManager m_rhm
std::map< std::string, TH1F * > _history
Definition: Run.h:45
#define LogDebug(id)