CMS 3D CMS Logo

SiStripFedCabling_PayloadInspector.cc
Go to the documentation of this file.
1 
12 
16 
21 
22 #include <memory>
23 #include <sstream>
24 #include <TCanvas.h>
25 #include <TH2D.h>
26 #include <TLatex.h>
27 
28 namespace {
29 
30  /************************************************
31  TrackerMap of SiStrip FED Cabling
32  *************************************************/
33  class SiStripFedCabling_TrackerMap : public cond::payloadInspector::PlotImage<SiStripFedCabling> {
34  public:
35  SiStripFedCabling_TrackerMap() : cond::payloadInspector::PlotImage<SiStripFedCabling>( "Tracker Map SiStrip Fed Cabling" ){
36  setSingleIov( true );
37  }
38 
39  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
40  auto iov = iovs.front();
41  std::shared_ptr<SiStripFedCabling> payload = fetchPayload( std::get<1>(iov) );
42 
43  std::unique_ptr<TrackerMap> tmap = std::unique_ptr<TrackerMap>(new TrackerMap("SiStripFedCabling"));
44  tmap->setPalette(1);
45  std::string titleMap = "TrackerMap of SiStrip Fed Cabling per module, IOV : "+std::to_string(std::get<0>(iov));
46  tmap->setTitle(titleMap);
47 
48  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
49  std::unique_ptr<SiStripDetCabling> detCabling_ =std::unique_ptr<SiStripDetCabling>(new SiStripDetCabling(*(payload.get()),&tTopo));
50 
51  std::vector<uint32_t> activeDetIds;
52  detCabling_->addActiveDetectorsRawIds(activeDetIds);
53 
54  for(const auto &detId : activeDetIds){
55  int32_t n_conn = 0;
56  for(uint32_t connDet_i=0; connDet_i<detCabling_->getConnections(detId).size(); connDet_i++){
57  if(detCabling_->getConnections(detId)[connDet_i]!=nullptr && detCabling_->getConnections(detId)[connDet_i]->isConnected()!=0) n_conn++;
58  }
59  if(n_conn!=0){
60  tmap->fill(detId,n_conn*2);
61  }
62  }
63 
64  std::string fileName(m_imageFileName);
65  tmap->save(true,0.,6.,fileName);
66 
67  return true;
68  }
69  };
70 
71  /************************************************
72  Summary Plot of SiStrip FED Cabling
73  *************************************************/
74  class SiStripFedCabling_Summary : public cond::payloadInspector::PlotImage<SiStripFedCabling> {
75  public:
76  SiStripFedCabling_Summary() : cond::payloadInspector::PlotImage<SiStripFedCabling>( "SiStrip Fed Cabling Summary" ){
77  setSingleIov( true );
78  }
79 
80  bool fill( const std::vector<std::tuple<cond::Time_t,cond::Hash> >& iovs ) override{
81  auto iov = iovs.front();
82  std::shared_ptr<SiStripFedCabling> payload = fetchPayload( std::get<1>(iov) );
83  int IOV = std::get<0>(iov);
84  std::vector<uint32_t> activeDetIds;
85 
86  TrackerTopology tTopo = StandaloneTrackerTopology::fromTrackerParametersXMLFile(edm::FileInPath("Geometry/TrackerCommonData/data/trackerParameters.xml").fullPath());
87  std::unique_ptr<SiStripDetCabling> detCabling_ =std::unique_ptr<SiStripDetCabling>(new SiStripDetCabling(*(payload.get()),&tTopo));
88 
89  detCabling_->addActiveDetectorsRawIds(activeDetIds);
90 
91  containers myCont;
92  containers allCounts;
93 
94  edm::FileInPath fp_ = edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
96  auto DetInfos = reader->getAllData();
97  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){
98  // check if det id is correct and if it is actually cabled in the detector
99  if( it->first==0 || it->first==0xFFFFFFFF ) {
100  edm::LogError("DetIdNotGood") << "@SUB=analyze" << "Wrong det id: " << it->first
101  << " ... neglecting!" << std::endl;
102  continue;
103  }
104  updateCounters(it->first,allCounts,tTopo);
105  }
106 
107  for(const auto &detId : activeDetIds){
108  updateCounters(detId,myCont,tTopo);
109  }
110 
111  TH2D* ME = new TH2D("SummaryOfCabling","SummaryOfCabling",6,0.5,6.5,9,0.5,9.5);
112  ME->GetXaxis()->SetTitle("Sub Det");
113  ME->GetYaxis()->SetTitle("Layer");
114 
115  ME->SetTitle("");
116 
117  ME->GetXaxis()->SetBinLabel(1,"TIB");
118  ME->GetXaxis()->SetBinLabel(2,"TID F");
119  ME->GetXaxis()->SetBinLabel(3,"TID B");
120  ME->GetXaxis()->SetBinLabel(4,"TOB");
121  ME->GetXaxis()->SetBinLabel(5,"TEC F");
122  ME->GetXaxis()->SetBinLabel(6,"TEC B");
123 
124  for(int i=0;i<4;i++){
125  ME->Fill(1,i+1,float(myCont.counterTIB[i])/allCounts.counterTIB[i]);
126  }
127 
128  for(int i=0;i<2;i++){
129  for(int j=0;j<3;j++){
130  ME->Fill(i+2,j+1,float(myCont.counterTID[i][j])/allCounts.counterTID[i][j]);
131  }
132  }
133 
134  for(int i=0;i<6;i++){
135  ME->Fill(4,i+1,float(myCont.counterTOB[i])/allCounts.counterTOB[i]);
136  }
137 
138  for(int i=0;i<2;i++){
139  for(int j=0;j<9;j++){
140  ME->Fill(i+5,j+1,float(myCont.counterTEC[i][j])/allCounts.counterTEC[i][j]);
141  }
142  }
143 
144  TCanvas c1("SiStrip FED cabling summary","SiStrip FED cabling summary",800,600);
145  c1.SetTopMargin(0.07);
146  c1.SetBottomMargin(0.10);
147  c1.SetLeftMargin(0.07);
148  c1.SetRightMargin(0.10);
149 
150  ME->Draw("colz");
151  ME->Draw("TEXTsame");
152  ME->SetStats(kFALSE);
153 
154  TLatex t1;
155  t1.SetNDC();
156  t1.SetTextAlign(26);
157  t1.SetTextSize(0.05);
158  t1.DrawLatex(0.5, 0.96, Form("SiStrip FedCabling, IOV %i", IOV));
159 
160  std::string fileName(m_imageFileName);
161  c1.SaveAs(fileName.c_str());
162 
163  return true;
164  }
165 
166  private:
167  struct containers{
168  public:
169  int counterTIB[4]={0};
170  int counterTID[2][3]={{0}};
171  int counterTOB[6]={0};
172  int counterTEC[2][9]={{0}};
173  };
174 
175  void updateCounters(int detId,containers &cont,const TrackerTopology& tTopo){
176 
177  StripSubdetector subdet(detId);
178 
179  switch (subdet.subdetId()) {
181  {
182  int i = tTopo.tibLayer(detId) - 1;
183  cont.counterTIB[i]++;
184  break;
185  }
187  {
188  int j = tTopo.tidWheel(detId) - 1;
189  int side = tTopo.tidSide(detId);
190  if (side == 2) {
191  cont.counterTID[0][j]++;
192  } else if (side == 1) {
193  cont.counterTID[1][j]++;
194  }
195  break;
196  }
198  {
199  int i = tTopo.tobLayer(detId) - 1;
200  cont.counterTOB[i]++;
201  break;
202  }
204  {
205  int j = tTopo.tecWheel(detId) - 1;
206  int side = tTopo.tecSide(detId);
207  if (side == 2) {
208  cont.counterTEC[0][j]++;
209  } else if (side == 1) {
210  cont.counterTEC[1][j]++;
211  }
212  break;
213  }
214  }
215  }
216  };
217 
218 }
219 
221  PAYLOAD_INSPECTOR_CLASS( SiStripFedCabling_TrackerMap );
222  PAYLOAD_INSPECTOR_CLASS( SiStripFedCabling_Summary );
223 }
unsigned int tibLayer(const DetId &id) const
std::shared_ptr< PayloadType > fetchPayload(const cond::Hash &payloadHash)
unsigned int tidWheel(const DetId &id) const
Definition: ME.h:11
#define PAYLOAD_INSPECTOR_CLASS(CLASS_NAME)
const std::map< uint32_t, DetInfo > & getAllData() const
unsigned int tidSide(const DetId &id) const
virtual bool fill(const std::vector< std::tuple< cond::Time_t, cond::Hash > > &iovs)=0
#define PAYLOAD_INSPECTOR_MODULE(PAYLOAD_TYPENAME)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
Definition: plugin.cc:24
TrackerTopology fromTrackerParametersXMLFile(const std::string &xmlFileName)
std::string fullPath() const
Definition: FileInPath.cc:163
unsigned int tecWheel(const DetId &id) const
unsigned int tobLayer(const DetId &id) const
unsigned int tecSide(const DetId &id) const