CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripMonitorQuality.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripMonitorQuality
4 // Class: SiStripMonitorQuality
5 //
13 //
14 // Original Author: Suchandra Dutta
15 // Created: Fri Dec 7 20:50 CET 2007
16 //
17 //
18 
20 
23 
30 
31 
34 
36 
37 // std
38 #include <cstdlib>
39 #include <cmath>
40 #include <numeric>
41 #include <algorithm>
42 
44  dqmStore_(edm::Service<DQMStore>().operator->()),
45  conf_(iConfig),
46  m_cacheID_(0)
47 
48 
49 {
50  edm::LogInfo("SiStripMonitorQuality") <<"SiStripMonitorQuality "
51  << " Constructing....... ";
52 }
53 
54 
56 {
57  edm::LogInfo("SiStripMonitorQuality") <<"SiStripMonitorQuality "
58  << " Destructing....... ";
59 }
60 //
61 // -- Begin Job
62 //
64 }
65 //
67 
68  unsigned long long cacheID = eSetup.get<SiStripQualityRcd>().cacheIdentifier();
69  if (m_cacheID_ == cacheID) return;
70 
71  //Retrieve tracker topology from geometry
73  eSetup.get<IdealGeometryRecord>().get(tTopoHandle);
74  const TrackerTopology* const tTopo = tTopoHandle.product();
75 
76  m_cacheID_ = cacheID;
77 
78  std::string quality_label = conf_.getParameter<std::string>("StripQualityLabel");
79  eSetup.get<SiStripQualityRcd>().get(quality_label,stripQuality_);
80  eSetup.get<SiStripDetCablingRcd>().get( detCabling_ );
81 
82  edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality::analyze: "<<
83  " Reading SiStripQuality "<< std::endl;
84 
85  SiStripBadStrip::RegistryIterator rbegin = stripQuality_->getRegistryVectorBegin();
86  SiStripBadStrip::RegistryIterator rend = stripQuality_->getRegistryVectorEnd();
87  uint32_t detid;
88 
89  if (rbegin==rend) return;
90 
91  for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
92 
93  detid = rp->detid;
94  // Check consistency in DetId
95  if (detid == 0 || detid == 0xFFFFFFFF){
96  edm::LogError("SiStripMonitorQuality") <<"SiStripMonitorQuality::bookHistograms : "
97  << "Wrong DetId !!!!!! " << detid << " Neglecting !!!!!! ";
98  continue;
99  }
100  // check if the detid is connected in cabling
101  if (!detCabling_->IsConnected(detid)) {
102  edm::LogError("SiStripMonitorQuality") <<"SiStripMonitorQuality::bookHistograms : "
103  << " DetId " << detid << " not connected, Neglecting !!!!!! ";
104  continue;
105  }
106 
107  MonitorElement* det_me;
108 
109  int nStrip = detCabling_->nApvPairs(detid) * 256;
110 
111  // use SistripHistoId for producing histogram id (and title)
112  SiStripHistoId hidmanager;
113  // create SiStripFolderOrganizer
114  SiStripFolderOrganizer folder_organizer;
115  // set appropriate folder using SiStripFolderOrganizer
116  folder_organizer.setDetectorFolder(detid, tTopo); // pass the detid to this method
117 
118  std::string hid;
119  hid = hidmanager.createHistoId("StripQualityFromCondDB","det", detid);
120 
121  det_me = ibooker.book1D(hid, hid, nStrip,0.5,nStrip+0.5);
122  ibooker.tag(det_me, detid);
123  det_me->setAxisTitle("Strip Number",1);
124  det_me->setAxisTitle("Quality Flag from CondDB ",2);
125  QualityMEs.insert( std::make_pair(detid, det_me));
126  }
127 
128 }
129 
130 
131 // ------------ method called to produce the data ------------
133 {
134  unsigned long long cacheID = eSetup.get<SiStripQualityRcd>().cacheIdentifier();
135  if (m_cacheID_ == cacheID) return;
136 
137  //Retrieve tracker topology from geometry
138  edm::ESHandle<TrackerTopology> tTopoHandle;
139  eSetup.get<IdealGeometryRecord>().get(tTopoHandle);
140  const TrackerTopology* const tTopo = tTopoHandle.product();
141 
142  m_cacheID_ = cacheID;
143 
144  std::string quality_label = conf_.getParameter<std::string>("StripQualityLabel");
145  eSetup.get<SiStripQualityRcd>().get(quality_label,stripQuality_);
146  eSetup.get<SiStripDetCablingRcd>().get( detCabling_ );
147 
148  edm::LogInfo("SiStripMonitorQuality") << "SiStripMonitorQuality::analyze: "<<
149  " Reading SiStripQuality "<< std::endl;
150 
151  SiStripBadStrip::RegistryIterator rbegin = stripQuality_->getRegistryVectorBegin();
152  SiStripBadStrip::RegistryIterator rend = stripQuality_->getRegistryVectorEnd();
153  uint32_t detid;
154 
155  if (rbegin==rend) return;
156 
157  for (SiStripBadStrip::RegistryIterator rp=rbegin; rp != rend; ++rp) {
158 
159  detid = rp->detid;
160  // Check consistency in DetId
161  if (detid == 0 || detid == 0xFFFFFFFF){
162  edm::LogError("SiStripMonitorQuality") <<"SiStripMonitorQuality::analyze : "
163  << "Wrong DetId !!!!!! " << detid << " Neglecting !!!!!! ";
164  continue;
165  }
166  // check if the detid is connected in cabling
167  if (!detCabling_->IsConnected(detid)) {
168  edm::LogError("SiStripMonitorQuality") <<"SiStripMonitorQuality::analyze : "
169  << " DetId " << detid << " not connected, Neglecting !!!!!! ";
170  continue;
171  }
172  MonitorElement* me = getQualityME(detid, tTopo);
173  SiStripBadStrip::Range range = SiStripBadStrip::Range( stripQuality_->getDataVectorBegin()+rp->ibegin ,
174  stripQuality_->getDataVectorBegin()+rp->iend );
175  SiStripBadStrip::ContainerIterator it=range.first;
176  for(;it!=range.second;++it){
177  unsigned int value=(*it);
178  short str_start = stripQuality_->decode(value).firstStrip;
179  short str_end = str_start + stripQuality_->decode(value).range;
180  for ( short isr = str_start; isr < str_end + 1; isr++) {
181  if (isr <= (me->getNbinsX()-1)) me->Fill(isr+1, 1.0);
182  }
183  }
184  }
185 }
186 //
187 // -- End Run
188 //
190  bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
192  if (outputMEsInRootFile) {
193  //dqmStore_->showDirStructure();
194  dqmStore_->save(outputFileName);
195  }
196 }
197 //
198 // -- End Job
199 //
201  edm::LogInfo("SiStripMonitorQuality") <<"SiStripMonitorQuality::EndJob: "
202  << " Finishing!! ";
203 }
204 //
205 // -- End Job
206 //
208 
209  std::map<uint32_t, MonitorElement* >::iterator pos = QualityMEs.find(idet);
210  MonitorElement* det_me = NULL;
211  if (pos != QualityMEs.end()) {
212  det_me = pos->second;
213  det_me->Reset();
214  } else {
215  //this should never happen because of bookHistograms()
216  edm::LogError("SiStripMonitorQuality") <<"SiStripMonitorQuality::getQualityME : "
217  << "Wrong DetId !!!!!! " << idet << " No ME found!";
218  }
219  return det_me;
220 }
222 
T getParameter(std::string const &) const
edm::ESHandle< SiStripDetCabling > detCabling_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< unsigned int >::const_iterator ContainerIterator
#define NULL
Definition: scimark2.h:8
Registry::const_iterator RegistryIterator
void Fill(long long x)
void setDetectorFolder(uint32_t rawdetid, const TrackerTopology *tTopo)
int iEvent
Definition: GenABIO.cc:230
MonitorElement * getQualityME(uint32_t idet, const TrackerTopology *tTopo)
edm::ESHandle< SiStripQuality > stripQuality_
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
void tag(MonitorElement *, unsigned int)
Definition: DQMStore.cc:286
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
virtual void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
std::string createHistoId(std::string description, std::string id_type, uint32_t component_id)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
SiStripMonitorQuality(const edm::ParameterSet &)
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, const uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE", const bool resetMEsAfterWriting=false)
Definition: DQMStore.cc:2566
virtual void analyze(const edm::Event &, const edm::EventSetup &)
std::pair< ContainerIterator, ContainerIterator > Range
unsigned long long m_cacheID_
int getNbinsX(void) const
get # of bins in X-axis
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
std::map< uint32_t, MonitorElement * > QualityMEs
Definition: Run.h:41