CMS 3D CMS Logo

SiStripDetVOff_PayloadInspector.cc
Go to the documentation of this file.
4 
7 
11 
12 #include <memory>
13 #include <sstream>
14 
15 // include ROOT
16 #include "TH2F.h"
17 #include "TLegend.h"
18 #include "TCanvas.h"
19 #include "TLine.h"
20 #include "TStyle.h"
21 #include "TLatex.h"
22 #include "TPave.h"
23 #include "TPaveStats.h"
24 #include "TGaxis.h"
25 
26 namespace {
27 
28  class SiStripDetVOff_LV : public cond::payloadInspector::TimeHistoryPlot<SiStripDetVOff,int>{
29  public:
30  SiStripDetVOff_LV(): cond::payloadInspector::TimeHistoryPlot<SiStripDetVOff,int >( "Nr of mod with LV OFF vs time", "nLVOff"){
31  }
32 
33  int getFromPayload( SiStripDetVOff& payload ) override{
34  return payload.getLVoffCounts();
35  }
36 
37  };
38 
39  class SiStripDetVOff_HV : public cond::payloadInspector::TimeHistoryPlot<SiStripDetVOff,int> {
40  public:
41  SiStripDetVOff_HV() : cond::payloadInspector::TimeHistoryPlot<SiStripDetVOff,int >( "Nr of mod with HV OFF vs time","nHVOff"){
42  }
43 
44  int getFromPayload( SiStripDetVOff& payload ) override{
45  return payload.getHVoffCounts();
46  }
47 
48  };
49 
50  /************************************************
51  TrackerMap of Module VOff
52  *************************************************/
53  class SiStripDetVOff_IsModuleVOff_TrackerMap : public cond::payloadInspector::PlotImage<SiStripDetVOff> {
54  public:
55  SiStripDetVOff_IsModuleVOff_TrackerMap() : cond::payloadInspector::PlotImage<SiStripDetVOff>( "Tracker Map IsModuleVOff" ){
56  setSingleIov( true );
57  }
58 
59  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
60  auto iov = iovs.front();
61  std::shared_ptr<SiStripDetVOff> payload = fetchPayload( std::get<1>(iov) );
62 
63  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripIsModuleVOff"));
64  tmap->setPalette(1);
65  std::string titleMap = "TrackerMap of VOff modules (HV or LV), payload : "+std::get<1>(iov);
66  tmap->setTitle(titleMap);
67 
68  std::vector<uint32_t> detid;
69  payload->getDetIds(detid);
70 
71  for (const auto & d : detid) {
72  if(payload->IsModuleVOff(d)){
73  tmap->fill(d,1.);
74  }
75  } // loop over detIds
76 
77  std::string fileName(m_imageFileName);
78  tmap->save(true,0.99,1.01,fileName);
79 
80  return true;
81  }
82  };
83 
84  /************************************************
85  TrackerMap of Module HVOff
86  *************************************************/
87  class SiStripDetVOff_IsModuleHVOff_TrackerMap : public cond::payloadInspector::PlotImage<SiStripDetVOff> {
88  public:
89  SiStripDetVOff_IsModuleHVOff_TrackerMap() : cond::payloadInspector::PlotImage<SiStripDetVOff>( "Tracker Map IsModuleHVOff" ){
90  setSingleIov( true );
91  }
92 
93  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
94  auto iov = iovs.front();
95  std::shared_ptr<SiStripDetVOff> payload = fetchPayload( std::get<1>(iov) );
96 
97  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripIsModuleHVOff"));
98  tmap->setPalette(1);
99  std::string titleMap = "TrackerMap of HV Off modules, payload : "+std::get<1>(iov);
100  tmap->setTitle(titleMap);
101 
102  std::vector<uint32_t> detid;
103  payload->getDetIds(detid);
104 
105  for (const auto & d : detid) {
106  if(payload->IsModuleHVOff(d)){
107  tmap->fill(d,1.);
108  }
109  } // loop over detIds
110 
111  std::string fileName(m_imageFileName);
112  tmap->save(true,0.99,1.01,fileName);
113 
114  return true;
115  }
116  };
117 
118  /************************************************
119  TrackerMap of Module LVOff
120  *************************************************/
121  class SiStripDetVOff_IsModuleLVOff_TrackerMap : public cond::payloadInspector::PlotImage<SiStripDetVOff> {
122  public:
123  SiStripDetVOff_IsModuleLVOff_TrackerMap() : cond::payloadInspector::PlotImage<SiStripDetVOff>( "Tracker Map IsModuleLVOff" ){
124  setSingleIov( true );
125  }
126 
127  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
128  auto iov = iovs.front();
129  std::shared_ptr<SiStripDetVOff> payload = fetchPayload( std::get<1>(iov) );
130 
131  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripIsModuleLVOff"));
132  tmap->setPalette(1);
133  std::string titleMap = "TrackerMap of LV Off modules, payload : "+std::get<1>(iov);
134  tmap->setTitle(titleMap);
135 
136  std::vector<uint32_t> detid;
137  payload->getDetIds(detid);
138 
139  for (const auto & d : detid) {
140  if(payload->IsModuleLVOff(d)){
141  tmap->fill(d,1.);
142  }
143  } // loop over detIds
144 
145  std::string fileName(m_imageFileName);
146  tmap->save(true,0.99,1.01,fileName);
147 
148  return true;
149  }
150  };
151 
152  /************************************************
153  test class
154  *************************************************/
155 
156  class SiStripDetVOffTest : public cond::payloadInspector::Histogram1D<SiStripDetVOff> {
157 
158  public:
159  SiStripDetVOffTest() : cond::payloadInspector::Histogram1D<SiStripDetVOff>("SiStrip DetVOff test",
160  "SiStrip DetVOff test", 10,0.0,10.0),
161  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
162  {
163  Base::setSingleIov( true );
164  }
165 
166  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
167  for ( auto const & iov: iovs) {
168  std::shared_ptr<SiStripDetVOff> payload = Base::fetchPayload( std::get<1>(iov) );
169  if( payload.get() ){
170 
171  std::vector<uint32_t> detid;
172  payload->getDetIds(detid);
173 
174  SiStripDetSummary summaryHV{&m_trackerTopo};
175  SiStripDetSummary summaryLV{&m_trackerTopo};
176 
177  for (const auto & d : detid) {
178  if(payload->IsModuleLVOff(d)) summaryLV.add(d);
179  if(payload->IsModuleHVOff(d)) summaryHV.add(d);
180  }
181  std::map<unsigned int, SiStripDetSummary::Values> mapHV = summaryHV.getCounts();
182  std::map<unsigned int, SiStripDetSummary::Values> mapLV = summaryLV.getCounts();
183 
184  // SiStripPI::printSummary(mapHV);
185  // SiStripPI::printSummary(mapLV);
186 
187  std::stringstream ss;
188  ss << "Summary of HV off detectors:" << std::endl;
189  summaryHV.print(ss, true);
190 
191  ss << "Summary of LV off detectors:" << std::endl;
192  summaryLV.print(ss, true);
193 
194  std::cout<<ss.str()<<std::endl;
195 
196 
197  }// payload
198  }// iovs
199  return true;
200  }// fill
201  private:
202  TrackerTopology m_trackerTopo;
203  };
204 
205  /************************************************
206  Plot DetVOff by region
207  *************************************************/
208 
209  class SiStripDetVOffByRegion : public cond::payloadInspector::PlotImage<SiStripDetVOff> {
210  public:
211  SiStripDetVOffByRegion() : cond::payloadInspector::PlotImage<SiStripDetVOff>( "SiStrip DetVOff By Region" ),
212  m_trackerTopo{StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath())}
213  {
214  setSingleIov( true );
215  }
216 
217  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
218  auto iov = iovs.front();
219  std::shared_ptr<SiStripDetVOff> payload = fetchPayload( std::get<1>(iov) );
220 
221  std::vector<uint32_t> detid;
222  payload->getDetIds(detid);
223 
224  SiStripDetSummary summaryHV{&m_trackerTopo};
225  SiStripDetSummary summaryLV{&m_trackerTopo};
226 
227  for (const auto & d : detid) {
228  if(payload->IsModuleLVOff(d)) summaryLV.add(d);
229  if(payload->IsModuleHVOff(d)) summaryHV.add(d);
230  }
231  std::map<unsigned int, SiStripDetSummary::Values> mapHV = summaryHV.getCounts();
232  std::map<unsigned int, SiStripDetSummary::Values> mapLV = summaryLV.getCounts();
233  std::vector<unsigned int> keys;
234  std::transform(mapHV.begin(),
235  mapHV.end(),
236  std::back_inserter(keys),
237  [](const std::map<unsigned int, SiStripDetSummary::Values>::value_type &pair){return pair.first;});
238 
239  //=========================
240 
241  TCanvas canvas("DetVOff Partion summary","SiStripDetVOff region summary",1200,1000);
242  canvas.cd();
243  auto h_HV = std::unique_ptr<TH1F>(new TH1F("HVbyRegion","SiStrip HV/LV summary by region;; modules with HV off",mapHV.size(),0.,mapHV.size()));
244  auto h_LV = std::unique_ptr<TH1F>(new TH1F("LVbyRegion","SiStrip HV/LV summary by region;; modules with LV off",mapLV.size(),0.,mapLV.size()));
245 
246  h_HV->SetStats(false);
247  h_LV->SetStats(false);
248 
249  canvas.SetBottomMargin(0.18);
250  canvas.SetLeftMargin(0.10);
251  canvas.SetRightMargin(0.10);
252  canvas.Modified();
253 
254  std::vector<int> boundaries;
255  unsigned int iBin=0;
256 
258  std::string currentDetector;
259 
260  for (const auto &index : keys){
261  iBin++;
262  int countHV = mapHV[index].count;
263  int countLV = mapLV[index].count;
264 
265  if(currentDetector.empty()) currentDetector="TIB";
266 
267  switch ((index)/1000)
268  {
269  case 1:
270  detector = "TIB";
271  break;
272  case 2:
273  detector = "TOB";
274  break;
275  case 3:
276  detector = "TEC";
277  break;
278  case 4:
279  detector = "TID";
280  break;
281  }
282 
283  h_HV->SetBinContent(iBin,countHV);
284  h_HV->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(index).second);
285  h_HV->GetXaxis()->LabelsOption("v");
286 
287  h_LV->SetBinContent(iBin,countLV);
288  h_LV->GetXaxis()->SetBinLabel(iBin,SiStripPI::regionType(index).second);
289  h_LV->GetXaxis()->LabelsOption("v");
290 
291  if(detector!=currentDetector) {
292  boundaries.push_back(iBin);
293  currentDetector=detector;
294  }
295  }
296 
297  auto extrema = SiStripPI::getExtrema(h_LV.get(),h_HV.get());
298  h_HV->GetYaxis()->SetRangeUser(extrema.first,extrema.second);
299  h_LV->GetYaxis()->SetRangeUser(extrema.first,extrema.second);
300 
301  h_HV->SetMarkerStyle(20);
302  h_HV->SetMarkerSize(1);
303  h_HV->SetLineColor(kRed);
304  h_HV->SetMarkerColor(kRed);
305  h_HV->Draw("HIST");
306  h_HV->Draw("TEXT45same");
307 
308  h_LV->SetMarkerStyle(21);
309  h_LV->SetMarkerSize(1);
310  h_LV->SetLineColor(kBlue);
311  h_LV->SetLineStyle(9);
312  h_LV->SetMarkerColor(kBlue);
313  h_LV->Draw("HISTsame");
314  h_LV->Draw("TEXT45same");
315 
316  canvas.Update();
317  canvas.cd();
318 
319  TLine l[boundaries.size()];
320  unsigned int i=0;
321  for (const auto & line : boundaries){
322  l[i] = TLine(h_HV->GetBinLowEdge(line),canvas.cd()->GetUymin(),h_HV->GetBinLowEdge(line),canvas.cd()->GetUymax());
323  l[i].SetLineWidth(1);
324  l[i].SetLineStyle(9);
325  l[i].SetLineColor(2);
326  l[i].Draw("same");
327  i++;
328  }
329 
330  TLegend legend = TLegend(0.45,0.80,0.90,0.9);
331  legend.SetHeader((std::get<1>(iov)).c_str(),"C"); // option "C" allows to center the header
332  legend.AddEntry(h_HV.get(),("HV channels: "+std::to_string(payload->getHVoffCounts())).c_str(),"PL");
333  legend.AddEntry(h_LV.get(),("LV channels: "+std::to_string(payload->getLVoffCounts())).c_str(),"PL");
334  legend.SetTextSize(0.025);
335  legend.Draw("same");
336 
337  // Remove the current axis
338  h_HV.get()->GetYaxis()->SetLabelOffset(999);
339  h_HV.get()->GetYaxis()->SetTickLength(0);
340  h_HV.get()->GetYaxis()->SetTitleOffset(999);
341 
342  h_LV.get()->GetYaxis()->SetLabelOffset(999);
343  h_LV.get()->GetYaxis()->SetTickLength(0);
344  h_LV.get()->GetYaxis()->SetTitleOffset(999);
345 
346  //draw an axis on the left side
347  auto l_axis = std::unique_ptr<TGaxis>(new TGaxis(gPad->GetUxmin(),gPad->GetUymin(),gPad->GetUxmin(),gPad->GetUymax(),0,extrema.second,510));
348  l_axis->SetLineColor(kRed);
349  l_axis->SetTextColor(kRed);
350  l_axis->SetLabelColor(kRed);
351  l_axis->SetTitleOffset(1.2);
352  l_axis->SetTitleColor(kRed);
353  l_axis->SetTitle(h_HV.get()->GetYaxis()->GetTitle());
354  l_axis->Draw();
355 
356  //draw an axis on the right side
357  auto r_axis = std::unique_ptr<TGaxis>(new TGaxis(gPad->GetUxmax(),gPad->GetUymin(),gPad->GetUxmax(),gPad->GetUymax(),0,extrema.second,510,"+L"));
358  r_axis->SetLineColor(kBlue);
359  r_axis->SetTextColor(kBlue);
360  r_axis->SetLabelColor(kBlue);
361  r_axis->SetTitleColor(kBlue);
362  r_axis->SetTitleOffset(1.2);
363  r_axis->SetTitle(h_LV.get()->GetYaxis()->GetTitle());
364  r_axis->Draw();
365 
366  std::string fileName(m_imageFileName);
367  canvas.SaveAs(fileName.c_str());
368 
369  return true;
370  }
371  private:
372  TrackerTopology m_trackerTopo;
373  };
374 
375 }
376 
378  PAYLOAD_INSPECTOR_CLASS( SiStripDetVOff_LV );
379  PAYLOAD_INSPECTOR_CLASS( SiStripDetVOff_HV );
380  PAYLOAD_INSPECTOR_CLASS( SiStripDetVOff_IsModuleVOff_TrackerMap );
381  PAYLOAD_INSPECTOR_CLASS( SiStripDetVOff_IsModuleLVOff_TrackerMap );
382  PAYLOAD_INSPECTOR_CLASS( SiStripDetVOff_IsModuleHVOff_TrackerMap );
383  PAYLOAD_INSPECTOR_CLASS( SiStripDetVOffTest );
384  PAYLOAD_INSPECTOR_CLASS( SiStripDetVOffByRegion );
385 }
int getLVoffCounts() const
Returns the total number of modules with LV off.
U second(std::pair< T, U > const &p)
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
virtual Y getFromPayload(PayloadType &payload)=0
std::pair< float, float > getExtrema(TH1 *h1, TH1 *h2)
void add(DetId detid, float value)
Used to compute the mean value of the value variable divided by subdetector, layer and mono/stereo...
int getHVoffCounts() const
Returns the total number of modules with HV off.
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
std::pair< int, const char * > regionType(int index)
Definition: plugin.cc:24
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
def canvas(sub, attr)
Definition: svgfig.py:481