CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTPGStripStatusPyWrapper.cc
Go to the documentation of this file.
7 #include "TROOT.h"
8 #include "TH2F.h"
9 #include "TCanvas.h"
10 #include "TStyle.h"
11 #include "TColor.h"
12 #include "TLine.h"
18 
21 
22 #include <string>
23 #include <sstream>
24 #include <algorithm>
25 #include <numeric>
26 #include <iterator>
27 #include <boost/ref.hpp>
28 #include <boost/bind.hpp>
29 #include <boost/function.hpp>
30 #include <boost/iterator/transform_iterator.hpp>
31 
32 #include <fstream>
33 
34 namespace cond {
35 
36  template<>
38  std::stringstream ss;
41  return ss.str();
42  }
43 
44  template<>
46  std::stringstream ss;
47  const EcalTPGStripStatusMap &stripMap = object().getMap();
48  std::cout << " tower map size " << stripMap.size() << std::endl;
49  ss <<" Endcap : Number of masked Trigger Strips " << stripMap.size() << std::endl;
50  return ss.str();
51  }
52 
53  template<>
54  std::string PayLoadInspector<EcalTPGStripStatus>::plot(std::string const & filename,
55  std::string const &,
56  std::vector<int> const&,
57  std::vector<float> const& ) const {
58  gStyle->SetPalette(1);
59 
60  const Int_t NRGBs = 5;
61  const Int_t NCont = 255;
62 
63  Double_t stops[NRGBs] = { 0.00, 0.34, 0.61, 0.84, 1.00 };
64  Double_t red[NRGBs] = { 0.00, 0.00, 0.87, 1.00, 0.51 };
65  Double_t green[NRGBs] = { 0.00, 0.81, 1.00, 0.20, 0.00 };
66  Double_t blue[NRGBs] = { 0.51, 1.00, 0.12, 0.00, 0.00 };
67  TColor::CreateGradientColorTable(NRGBs, stops, red, green, blue, NCont);
68  gStyle->SetNumberContours(NCont);
69 
70  TCanvas canvas("CC map","CC map",1200, 600);
71  TPad** pad = new TPad*[2];
72  float xmi[2] = {0.0, 0.5};
73  float xma[2] = {0.5, 1.0};
74  for (int obj = 0; obj < 2; obj++) {
75  pad[obj] = new TPad(Form("p_%i", obj),Form("p_%i", obj),
76  xmi[obj], 0.0, xma[obj], 1.0);
77  pad[obj]->Draw();
78  }
79 
80  TH2F** hEEStrip = new TH2F*[2];
81  for (int iz = 0; iz < 2; iz++) {
82  int izz = iz;
83  if(iz == 0) izz = -1;
84  hEEStrip[iz] = new TH2F(Form("EEStrip_%i", iz),
85  Form("EE masked strips side %i", izz),101,1.,101.,101,1.,101.);
86  hEEStrip[iz]->SetStats(0);
87  }
88 
89  // EcalMappingElectronics *mapping = new EcalMappingElectronics ;
90  std::string mappingFile = "Geometry/EcalMapping/data/EEMap.txt";
91 
92  std::ifstream f(edm::FileInPath(mappingFile).fullPath().c_str());
93  if (!f.good()) {
94  std::cout << "EcalTPGStripStatusPyWrapper File not found" << std::endl;
95  throw cms::Exception("FileNotFound");
96  }
97 
98  int ix, iy, iz, CL;
99  int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
100  int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
101  uint32_t rawEE[108][28][5][5];
102  int NbrawEE[108][28][5];
103  for(int TCC = 0; TCC < 108; TCC++)
104  for(int TT = 0; TT < 28; TT++)
105  for(int ST = 0; ST < 5; ST++)
106  NbrawEE[TCC][TT][ST] = 0;
107  while ( ! f.eof()) {
108  f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip
109  >> tccid >> tower >> pseudostrip_in_TCC >> pseudostrip_in_TT ;
110 
111  EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
112  uint32_t rawId = detid.denseIndex();
113  if(tccid > 108 || tower > 28 || pseudostrip_in_TT > 5 || xtal_in_pseudostrip > 5)
114  std::cout << " tccid " << tccid << " tower " << tower << " pseudostrip_in_TT "<< pseudostrip_in_TT
115  <<" xtal_in_pseudostrip " << xtal_in_pseudostrip << std::endl;
116  else {
117  rawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1][xtal_in_pseudostrip - 1] = rawId;
118  NbrawEE[tccid - 1][tower - 1][pseudostrip_in_TT - 1]++;
119  }
120  /*
121  // if(ix%10 == 0 && iy%10 == 0) std::cout << " dcc tower ps_in_SC xtal_in_ps " << dccid << " " << towerid << " " << pseudostrip_in_SC << " " << xtal_in_pseudostrip << std::endl;
122  EcalElectronicsId elecid(dccid,towerid, pseudostrip_in_SC, xtal_in_pseudostrip);
123  // if(ix%10 == 0 && iy%10 == 0) std::cout << " tcc tt ps_in_TT xtal_in_ps " << tccid << " " << tower << " " << pseudostrip_in_TT << " " << xtal_in_pseudostrip << std::endl;
124  EcalTriggerElectronicsId triggerid(tccid, tower, pseudostrip_in_TT, xtal_in_pseudostrip);
125  EcalMappingElement aElement;
126  aElement.electronicsid = elecid.rawId();
127  aElement.triggerid = triggerid.rawId();
128  (*mapping).setValue(detid, aElement);
129  */
130  }
131 
132  f.close();
133 
135  const EcalTPGStripStatusMap &stripMap = object().getMap();
136  std::cout << " tower map size " << stripMap.size() << std::endl;
137  double wei[2] = {0., 0.};
139  for(itSt = stripMap.begin(); itSt != stripMap.end(); ++itSt) {
140  if(itSt->second > 0) {
141  // let's decode the ID
142  int strip = itSt->first/8;
143  int pseudostrip = strip & 0x7;
144  strip /= 8;
145  int tt = strip & 0x7F;
146  strip /= 128;
147  int tccid = strip & 0x7F;
148  int NbXtalInStrip = NbrawEE[tccid - 1][tt - 1][pseudostrip - 1];
149  if(NbXtalInStrip != 5) std::cout << " Strip TCC " << tccid << " TT " << tt << " ST " << pseudostrip
150  << " Nx Xtals " << NbXtalInStrip << std::endl;
151  for(int Xtal = 0; Xtal < NbXtalInStrip; Xtal++) {
152  uint32_t rawId = rawEE[tccid - 1][tt - 1][pseudostrip - 1][Xtal];
153  // std::cout << " rawid " << rawId << std::endl;
155  float x = (float)detid.ix();
156  float y = (float)detid.iy();
157  int iz = detid.zside();
158  if(iz == -1) iz++;
159  if(Xtal == 0) wei[iz] += 1.;
160  hEEStrip[iz]->Fill(x + 0.5, y + 0.5, wei[iz]);
161  // std::cout << " x " << ix << " y " << iy << " z " << iz << std::endl;
162  }
163  }
164  }
165 
166  TLine* l = new TLine(0., 0., 0., 0.);
167  l->SetLineWidth(1);
168  int ixSectorsEE[202] = {
169  62, 62, 61, 61, 60, 60, 59, 59, 58, 58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42,
170  41, 41, 40, 40, 41, 41, 42, 42, 43, 43, 44, 44, 46, 46, 56, 56, 58, 58, 59, 59,
171  60, 60, 61, 61, 62, 62, 0,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81,
172  81, 76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9,
173  9, 6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26,
174  26, 36, 36, 41, 41, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88, 93, 93, 96,
175  96, 98, 98,101,101, 0, 62, 66, 66, 71, 71, 81, 81, 91, 91, 93, 0, 62, 66, 66,
176  91, 91, 98, 0, 58, 61, 61, 66, 66, 71, 71, 76, 76, 81, 81, 0, 51, 51, 0, 44,
177  41, 41, 36, 36, 31, 31, 26, 26, 21, 21, 0, 40, 36, 36, 11, 11, 4, 0, 40, 36,
178  36, 31, 31, 21, 21, 11, 11, 9, 0, 46, 46, 41, 41, 36, 36, 0, 56, 56, 61, 61, 66, 66};
179 
180  int iySectorsEE[202] = {
181  51, 56, 56, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 61, 61, 60, 60, 59, 59, 58,
182  58, 56, 56, 46, 46, 44, 44, 43, 43, 42, 42, 41, 41, 40, 40, 41, 41, 42, 42, 43,
183  43, 44, 44, 46, 46, 51, 0, 51, 61, 61, 66, 66, 76, 76, 81, 81, 86, 86, 88, 88,
184  93, 93, 96, 96, 98, 98,101,101, 98, 98, 96, 96, 93, 93, 88, 88, 86, 86, 81, 81,
185  76, 76, 66, 66, 61, 61, 41, 41, 36, 36, 26, 26, 21, 21, 16, 16, 14, 14, 9, 9,
186  6, 6, 4, 4, 1, 1, 4, 4, 6, 6, 9, 9, 14, 14, 16, 16, 21, 21, 26, 26,
187  36, 36, 41, 41, 51, 0, 46, 46, 41, 41, 36, 36, 31, 31, 26, 26, 0, 51, 51, 56,
188  56, 61, 61, 0, 61, 61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 62,101, 0, 61,
189  61, 66, 66, 71, 71, 76, 76, 86, 86, 88, 0, 51, 51, 56, 56, 61, 61, 0, 46, 46,
190  41, 41, 36, 36, 31, 31, 26, 26, 0, 40, 31, 31, 16, 16, 6, 0, 40, 31, 31, 16, 16, 6};
191 
192  pad[0]->cd();
193  hEEStrip[0]->Draw("col");
194  for ( int i=0; i<201; i=i+1) {
195  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
196  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
197  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
198  ixSectorsEE[i+1], iySectorsEE[i+1]);
199  l->SetLineWidth(0.2);
200  }
201  }
202 
203  pad[1]->cd();
204  hEEStrip[1]->Draw("col");
205  for ( int i=0; i<201; i=i+1) {
206  if ( (ixSectorsEE[i]!=0 || iySectorsEE[i]!=0) &&
207  (ixSectorsEE[i+1]!=0 || iySectorsEE[i+1]!=0) ) {
208  l->DrawLine(ixSectorsEE[i], iySectorsEE[i],
209  ixSectorsEE[i+1], iySectorsEE[i+1]);
210  l->SetLineWidth(0.2);
211  }
212  }
213 
214  canvas.SaveAs(filename.c_str());
215  return filename;
216  } // plot
217 }
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:215
int i
Definition: DBlmapReader.cc:9
int ix() const
Definition: EEDetId.h:71
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
static const int XYMODE
Definition: EEDetId.h:316
#define PYTHON_WRAPPER(_class, _name)
def canvas
Definition: svgfig.py:481
std::string summary() const
int zside() const
Definition: EEDetId.h:65
double f[11][100]
int iy() const
Definition: EEDetId.h:77
static std::string dumpXML(const EcalCondHeader &header, const EcalTPGStripStatus &record)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
list object
Definition: dbtoconf.py:77
uint32_t denseIndex() const
Definition: EEDetId.h:187
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
std::map< uint32_t, uint16_t > EcalTPGStripStatusMap
std::string dump() const
std::map< uint32_t, uint16_t >::const_iterator EcalTPGStripStatusMapIterator