Go to the documentation of this file.00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <memory>
00022
00023
00024
00025 #include <vector>
00026 #include <map>
00027
00028
00029 #include "TH1F.h"
00030
00031 #include "FWCore/Framework/interface/Frameworkfwd.h"
00032 #include "FWCore/Framework/interface/EDAnalyzer.h"
00033
00034 #include "FWCore/Framework/interface/Event.h"
00035 #include "FWCore/Framework/interface/MakerMacros.h"
00036 #include "FWCore/Framework/interface/Run.h"
00037
00038 #include "FWCore/Framework/interface/ESHandle.h"
00039
00040 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00041
00042 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00043
00044 #include "FWCore/ServiceRegistry/interface/Service.h"
00045 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00046
00047 #include "FWCore/Utilities/interface/InputTag.h"
00048
00049 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00050 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
00051
00052 #include "DPGAnalysis/SiStripTools/interface/RunHistogramManager.h"
00053
00054
00055
00056
00057 class SiStripQualityHistory : public edm::EDAnalyzer {
00058 public:
00059 explicit SiStripQualityHistory(const edm::ParameterSet&);
00060 ~SiStripQualityHistory();
00061
00062 enum {Module,Fiber,APV,Strip};
00063
00064 private:
00065 virtual void beginJob() ;
00066 virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
00067 virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
00068 virtual void endJob() ;
00069
00070
00071
00072 RunHistogramManager m_rhm;
00073 const std::vector<edm::ParameterSet> _monitoredssq;
00074 const unsigned int _mode;
00075 const bool m_run;
00076 const unsigned int m_maxLS;
00077 const unsigned int m_LSfrac;
00078
00079 std::map<std::string,TH1F*> _history;
00080 std::map<std::string,TProfile**> m_badmodrun;
00081
00082 };
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 SiStripQualityHistory::SiStripQualityHistory(const edm::ParameterSet& iConfig):
00096 m_rhm(),
00097 _monitoredssq(iConfig.getParameter<std::vector<edm::ParameterSet> >("monitoredSiStripQuality")),
00098 _mode(iConfig.getUntrackedParameter<unsigned int>("granularityMode",Module)),
00099 m_run(iConfig.getParameter<bool>("runProcess")),
00100 m_maxLS(iConfig.getUntrackedParameter<unsigned int>("maxLSBeforeRebin",100)),
00101 m_LSfrac(iConfig.getUntrackedParameter<unsigned int>("startingLSFraction",4)),
00102 _history(),m_badmodrun()
00103 {
00104
00105
00106 edm::Service<TFileService> tfserv;
00107
00108 for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
00109
00110 std::string name = ps->getParameter<std::string>("name");
00111
00112
00113
00114 if(m_run) _history[name] = tfserv->make<TH1F>(name.c_str(),name.c_str(),10,0,10);
00115
00116 char hrunname[400];
00117 sprintf(hrunname,"badmodrun_%s",name.c_str());
00118 char hruntitle[400];
00119 sprintf(hruntitle,"Number of bad modules %s",name.c_str());
00120 m_badmodrun[name] = m_rhm.makeTProfile(hrunname,hruntitle,m_LSfrac*m_maxLS,0,m_maxLS*262144);
00121 }
00122
00123 }
00124
00125
00126 SiStripQualityHistory::~SiStripQualityHistory()
00127 {
00128
00129
00130
00131
00132 }
00133
00134
00135
00136
00137
00138
00139
00140 void
00141 SiStripQualityHistory::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00142 {
00143
00144
00145 for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
00146
00147 std::string name = ps->getParameter<std::string>("name");
00148 std::string label = ps->getParameter<std::string>("ssqLabel");
00149
00150
00151
00152 edm::ESHandle<SiStripQuality> ssq;
00153 iSetup.get<SiStripQualityRcd>().get(label,ssq);
00154
00155 std::vector<SiStripQuality::BadComponent> bads = ssq->getBadComponentList();
00156
00157 LogDebug("BadComponents") << bads.size() << " bad components found";
00158
00159 int nbad=0;
00160
00161 if(_mode==Module || _mode==Fiber || _mode==APV) {
00162 for(std::vector<SiStripQuality::BadComponent>::const_iterator bc=bads.begin();bc!=bads.end();++bc) {
00163
00164 if(_mode==Module) {
00165 if(bc->BadModule) ++nbad;
00166 }
00167 else if(_mode == Fiber) {
00168 for(int fiber=1;fiber<5;fiber*=2) {
00169 if((bc->BadFibers & fiber)>0) ++nbad;
00170 }
00171 }
00172 else if(_mode ==APV) {
00173 for(int apv=1;apv<33;apv*=2) {
00174 if((bc->BadApvs & apv)>0) ++nbad;
00175 }
00176 }
00177 }
00178 }
00179 else if(_mode==Strip) {
00180 SiStripBadStrip::ContainerIterator dbegin = ssq->getDataVectorBegin();
00181 SiStripBadStrip::ContainerIterator dend = ssq->getDataVectorEnd();
00182 for(SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
00183 nbad += ssq->decode(*data).range;
00184 }
00185
00186 }
00187
00188 if(m_badmodrun.find(name)!=m_badmodrun.end() && m_badmodrun[name] && *m_badmodrun[name]) {
00189 (*m_badmodrun[name])->Fill(iEvent.orbitNumber(),nbad);
00190 }
00191
00192 }
00193 }
00194
00195 void
00196 SiStripQualityHistory::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup)
00197 {
00198
00199 m_rhm.beginRun(iRun);
00200
00201
00202
00203 for(std::vector<edm::ParameterSet>::const_iterator ps=_monitoredssq.begin();ps!=_monitoredssq.end();++ps) {
00204
00205 std::string name = ps->getParameter<std::string>("name");
00206 std::string label = ps->getParameter<std::string>("ssqLabel");
00207
00208 if(m_badmodrun.find(name)!=m_badmodrun.end()) {
00209 if(m_badmodrun[name] && *m_badmodrun[name]) {
00210 (*m_badmodrun[name])->SetBit(TH1::kCanRebin);
00211 (*m_badmodrun[name])->GetXaxis()->SetTitle("time [Orb#]"); (*m_badmodrun[name])->GetYaxis()->SetTitle("bad components");
00212 }
00213 }
00214
00215 if(m_run) {
00216
00217 edm::ESHandle<SiStripQuality> ssq;
00218 iSetup.get<SiStripQualityRcd>().get(label,ssq);
00219
00220 std::vector<SiStripQuality::BadComponent> bads = ssq->getBadComponentList();
00221
00222 LogDebug("BadComponents") << bads.size() << " bad components found";
00223
00224 int nbad=0;
00225
00226 if(_mode==Module || _mode==Fiber || _mode==APV) {
00227 for(std::vector<SiStripQuality::BadComponent>::const_iterator bc=bads.begin();bc!=bads.end();++bc) {
00228
00229 if(_mode==Module) {
00230 if(bc->BadModule) ++nbad;
00231 }
00232 else if(_mode == Fiber) {
00233 for(int fiber=1;fiber<5;fiber*=2) {
00234 if((bc->BadFibers & fiber)>0) ++nbad;
00235 }
00236 }
00237 else if(_mode ==APV) {
00238 for(int apv=1;apv<33;apv*=2) {
00239 if((bc->BadApvs & apv)>0) ++nbad;
00240 }
00241 }
00242 }
00243 }
00244 else if(_mode==Strip) {
00245 SiStripBadStrip::ContainerIterator dbegin = ssq->getDataVectorBegin();
00246 SiStripBadStrip::ContainerIterator dend = ssq->getDataVectorEnd();
00247 for(SiStripBadStrip::ContainerIterator data = dbegin; data < dend; ++data) {
00248 nbad += ssq->decode(*data).range;
00249 }
00250 }
00251
00252
00253 char runname[100];
00254 sprintf(runname,"%d",iRun.run());
00255 LogDebug("AnalyzedRun") << name << " " << runname << " " << nbad;
00256 _history[name]->Fill(runname,nbad);
00257 }
00258 }
00259
00260 }
00261
00262
00263 void
00264 SiStripQualityHistory::beginJob()
00265 {}
00266
00267
00268 void
00269 SiStripQualityHistory::endJob()
00270 {
00271
00272
00273
00274
00275
00276
00277
00278
00279 }
00280
00281
00282
00283 DEFINE_FWK_MODULE(SiStripQualityHistory);