test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
20 // system include files
21 #include <memory>
22 
23 // user include files
24 
25 #include <vector>
26 #include <map>
27 
28 //#include "TGraph.h"
29 #include "TH1F.h"
30 
33 
37 
39 
41 
43 
46 
48 
51 
53 //
54 // class decleration
55 //
56 
58  public:
61 
63 
64  private:
65  virtual void beginJob() override ;
66  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
67  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
68  virtual void endJob() override ;
69 
70  // ----------member data ---------------------------
71 
73  const std::vector<edm::ParameterSet> _monitoredssq;
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 //
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(),m_badmodrun()
103 {
104  //now do what ever initialization is needed
105 
107 
108  for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
109 
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) _history[name] = tfserv->make<TH1F>(name.c_str(),name.c_str(),10,0,10);
115 
116  char hrunname[400];
117  sprintf(hrunname,"badmodrun_%s",name.c_str());
118  char hruntitle[400];
119  sprintf(hruntitle,"Number of bad modules %s",name.c_str());
120  m_badmodrun[name] = m_rhm.makeTProfile(hrunname,hruntitle,m_LSfrac*m_maxLS,0,m_maxLS*262144);
121  }
122 
123 }
124 
125 
127 {
128 
129  // do anything here that needs to be done at desctruction time
130  // (e.g. close files, deallocate resources etc.)
131 
132 }
133 
134 
135 //
136 // member functions
137 //
138 
139 // ------------ method called to for each event ------------
140 void
142 {
143  // edm::LogInfo("EventProcessing") << "event being processed";
144 
145  for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
146 
147  std::string name = ps->getParameter<std::string>("name");
148  std::string label = ps->getParameter<std::string>("ssqLabel");
149 
150 
151 
153  iSetup.get<SiStripQualityRcd>().get(label,ssq);
154 
155  std::vector<SiStripQuality::BadComponent> bads = ssq->getBadComponentList();
156 
157  LogDebug("BadComponents") << bads.size() << " bad components found";
158 
159  int nbad=0;
160 
161  if(_mode==Module || _mode==Fiber || _mode==APV) {
162  for(std::vector<SiStripQuality::BadComponent>::const_iterator bc=bads.begin();bc!=bads.end();++bc) {
163 
164  if(_mode==Module) {
165  if(bc->BadModule) ++nbad;
166  }
167  else if(_mode == Fiber) {
168  for(int fiber=1;fiber<5;fiber*=2) {
169  if((bc->BadFibers & fiber)>0) ++nbad;
170  }
171  }
172  else if(_mode ==APV) {
173  for(int apv=1;apv<33;apv*=2) {
174  if((bc->BadApvs & apv)>0) ++nbad;
175  }
176  }
177  }
178  }
179  else if(_mode==Strip) {
180  SiStripBadStrip::ContainerIterator dbegin = ssq->getDataVectorBegin();
181  SiStripBadStrip::ContainerIterator dend = ssq->getDataVectorEnd();
182  for(SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
183  nbad += ssq->decode(*data).range;
184  }
185 
186  }
187 
188  if(m_badmodrun.find(name)!=m_badmodrun.end() && m_badmodrun[name] && *m_badmodrun[name]) {
189  (*m_badmodrun[name])->Fill(iEvent.orbitNumber(),nbad);
190  }
191 
192  }
193 }
194 
195 void
197 {
198 
199  m_rhm.beginRun(iRun);
200 
201  // loop on all the SiStripQuality objects to be monitored
202 
203  for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
204 
205  std::string name = ps->getParameter<std::string>("name");
206  std::string label = ps->getParameter<std::string>("ssqLabel");
207 
208  if(m_badmodrun.find(name)!=m_badmodrun.end()) {
209  if(m_badmodrun[name] && *m_badmodrun[name]) {
210  (*m_badmodrun[name])->SetCanExtend(TH1::kXaxis);
211  (*m_badmodrun[name])->GetXaxis()->SetTitle("time [Orb#]"); (*m_badmodrun[name])->GetYaxis()->SetTitle("bad components");
212  }
213  }
214 
215  if(m_run) {
216 
218  iSetup.get<SiStripQualityRcd>().get(label,ssq);
219 
220  std::vector<SiStripQuality::BadComponent> bads = ssq->getBadComponentList();
221 
222  LogDebug("BadComponents") << bads.size() << " bad components found";
223 
224  int nbad=0;
225 
226  if(_mode==Module || _mode==Fiber || _mode==APV) {
227  for(std::vector<SiStripQuality::BadComponent>::const_iterator bc=bads.begin();bc!=bads.end();++bc) {
228 
229  if(_mode==Module) {
230  if(bc->BadModule) ++nbad;
231  }
232  else if(_mode == Fiber) {
233  for(int fiber=1;fiber<5;fiber*=2) {
234  if((bc->BadFibers & fiber)>0) ++nbad;
235  }
236  }
237  else if(_mode ==APV) {
238  for(int apv=1;apv<33;apv*=2) {
239  if((bc->BadApvs & apv)>0) ++nbad;
240  }
241  }
242  }
243  }
244  else if(_mode==Strip) {
245  SiStripBadStrip::ContainerIterator dbegin = ssq->getDataVectorBegin();
246  SiStripBadStrip::ContainerIterator dend = ssq->getDataVectorEnd();
247  for(SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
248  nbad += ssq->decode(*data).range;
249  }
250  }
251 
252  // _history[name]->SetPoint(_history[name]->GetN(),iRun.run(),nbad);
253  char runname[100];
254  sprintf(runname,"%d",iRun.run());
255  LogDebug("AnalyzedRun") << name << " " << runname << " " << nbad;
256  _history[name]->Fill(runname,nbad);
257  }
258  }
259 
260 }
261 
262 // ------------ method called once each job just before starting event loop ------------
263 void
265 {}
266 
267 // ------------ method called once each job just after ending the event loop ------------
268 void
270 {
271  /*
272  for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
273 
274  std::string name = ps->getParameter<std::string>("name");
275  _history[name]->Write();
276 
277  }
278  */
279 }
280 
281 
282 //define this as a plug-in
#define LogDebug(id)
virtual 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:17
virtual void endJob() override
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, TH1F * > _history
#define Module(md)
Definition: vmac.h:201
const std::vector< edm::ParameterSet > _monitoredssq
int iEvent
Definition: GenABIO.cc:230
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)
virtual void beginJob() override
int orbitNumber() const
Definition: EventBase.h:66
const unsigned int m_LSfrac
const T & get() const
Definition: EventSetup.h:56
void beginRun(const edm::Run &iRun)
const unsigned int m_maxLS
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
std::map< std::string, TProfile ** > m_badmodrun
RunHistogramManager m_rhm
Definition: Run.h:43