CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelTrackerMap.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelMonitorClient
4 // Class: SiPixelTrackerMap
5 //
16 //
17 // Original Author: Dario Menasce
18 // Created:
19 //
20 //
25 
26 #include "TText.h"
27 
28 #include <fstream>
29 #include <iostream>
30 using namespace std;
31 
32 //----------------------------------------------------------------------------------------------------
33 SiPixelTrackerMap::SiPixelTrackerMap(string s,int xsize1, int ysize1) : TrackerMap(s,xsize1,ysize1)
34 {
35 // cout << ACBlue << ACBold
36 // << "[SiPixelTrackerMap::SiPixelTrackerMap()]"
37 // << endl ;
38  title = s ;
39  // cout<<"created a new Tracker Map! the title is: "<<s<<endl;
40 }
41 
42 //----------------------------------------------------------------------------------------------------
43 void SiPixelTrackerMap::drawModule(TmModule * mod, int key,int nlay, bool print_total)
44 {
45  //int x,y;
46  double phi,r,dx,dy, dy1;
47  double xp[4],yp[4],xp1,yp1;
48  double vhbot,vhtop,vhapo;
49  double rmedio[]={0.041,0.0701,0.0988,0.255,0.340,0.430,0.520,0.610,0.696,0.782,0.868,0.965,1.080};
50  double xt1,yt1,xs1=0.,ys1=0.,xt2,yt2,xs2,ys2,pv1,pv2;
51 // int green = 0;
52  double xd[4],yd[4];
53  int np = 4;
54  //int numrec=0;
55  int numod=0;
56  phi = phival(mod->posx,mod->posy);
57  r = sqrt(mod->posx*mod->posx+mod->posy*mod->posy);
58  vhbot = mod->width;
59  vhtop=mod->width;
60  vhapo=mod->length;
61  if(nlay < 31){ //endcap
62  vhbot = mod->widthAtHalfLength/2.-(mod->width/2.-mod->widthAtHalfLength/2.);
63  vhtop=mod->width/2.;
64  vhapo=mod->length/2.;
65  if(nlay >12 && nlay <19){
66  if(posrel)r = r+r;
67  xp[0]=r-vhtop;yp[0]=-vhapo;
68  xp[1]=r+vhtop;yp[1]=-vhapo;
69  xp[2]=r+vhtop;yp[2]=vhapo;
70  xp[3]=r-vhtop;yp[3]=vhapo;
71  }else{
72  if(posrel)r = r + r/3.;
73  xp[0]=r-vhapo;yp[0]=-vhbot;
74  xp[1]=r+vhapo;yp[1]=-vhtop;
75  xp[2]=r+vhapo;yp[2]=vhtop;
76  xp[3]=r-vhapo;yp[3]=vhbot;
77  }
78  for(int j=0;j<4;j++){
79  xp1 = xp[j]*cos(phi)-yp[j]*sin(phi);
80  yp1 = xp[j]*sin(phi)+yp[j]*cos(phi);
81  xp[j] = xp1;yp[j]=yp1;
82  }
83  } else { //barrel
84  numod=mod->idModule;if(numod>100)numod=numod-100;
85  int vane = mod->ring;
86  if(posrel){
87  dx = vhapo;
88  phi=M_PI;
89  xt1=rmedio[nlay-31]; yt1=-vhtop/2.;
90  xs1 = xt1*cos(phi)-yt1*sin(phi);
91  ys1 = xt1*sin(phi)+yt1*cos(phi);
92  xt2=rmedio[nlay-31]; yt2=vhtop/2.;
93  xs2 = xt2*cos(phi)-yt2*sin(phi);
94  ys2 = xt2*sin(phi)+yt2*cos(phi);
95  dy=phival(xs2,ys2)-phival(xs1,ys1);
96  dy1 = dy;
97  if(nlay==31)dy1=0.39;
98  if(nlay==32)dy1=0.23;
99  if(nlay==33)dy1=0.16;
100  xp[0]=vane*(dx+dx/8.);yp[0]=numod*(dy1);
101  xp[1]=vane*(dx+dx/8.)+dx;yp[1]=numod*(dy1);
102  xp[2]=vane*(dx+dx/8.)+dx;yp[2]=numod*(dy1)+dy;
103  xp[3]=vane*(dx+dx/8.);yp[3]=numod*(dy1)+dy;
104  }else{
105  xt1=r; yt1=-vhtop/2.;
106  xs1 = xt1*cos(phi)-yt1*sin(phi);
107  ys1 = xt1*sin(phi)+yt1*cos(phi);
108  xt2=r; yt2=vhtop/2.;
109  xs2 = xt2*cos(phi)-yt2*sin(phi);
110  ys2 = xt2*sin(phi)+yt2*cos(phi);
111  pv1=phival(xs1,ys1);
112  pv2=phival(xs2,ys2);
113  if(fabs(pv1-pv2)>M_PI && numod==1)pv1=pv1-2.*M_PI;
114  if(fabs(pv1-pv2)>M_PI && numod!=1)pv2=pv2+2.*M_PI;
115  xp[0]=mod->posz-vhapo/2.;yp[0]=4.2*pv1;
116  xp[1]=mod->posz+vhapo/2.;yp[1]=4.2*pv1;
117  xp[2]=mod->posz+vhapo/2. ;yp[2]=4.2*pv2;
118  xp[3]=mod->posz-vhapo/2.;yp[3]=4.2*pv2;
119  }
120  }
121  if(isRingStereo(key))
122  {
123  np = 3;
124  if(mod->idModule>100 ){for(int j=0;j<3;j++){
125  xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
126  }
127  }else {
128  xd[0]=xdpixel(xp[2]);yd[0]=ydpixel(yp[2]);
129  xd[1]=xdpixel(xp[3]);yd[1]=ydpixel(yp[3]);
130  xd[2]=xdpixel(xp[0]);yd[2]=ydpixel(yp[0]);
131  }
132  } else {
133  for(int j=0;j<4;j++){
134  xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
135  }
136  }
137  char buffer [20];
138  sprintf(buffer,"%X",mod->idex);
139 
140 //cout<<"drawModule: xp= "<<xp<<" , yp= "<<yp<<endl;
141  bool FPIX_M_1 = false ;
142  bool FPIX_M_2 = false ;
143  bool FPIX_P_1 = false ;
144  bool FPIX_P_2 = false ;
145  bool BPIX_L_1 = false ;
146  bool BPIX_L_2 = false ;
147  bool BPIX_L_3 = false ;
148  string moduleName = mod->name;
149  if(moduleName.find("PixelEndcap")!=string::npos || moduleName.find("PixelBarrel")!=string::npos) {
150  FPIX_M_1 = false ;
151  FPIX_M_2 = false ;
152  FPIX_P_1 = false ;
153  FPIX_P_2 = false ;
154  BPIX_L_1 = false ;
155  BPIX_L_2 = false ;
156  BPIX_L_3 = false ;
157  if( moduleName.find("PixelEndcap 3")!=string::npos ) {FPIX_M_1 = true;}
158  if( moduleName.find("PixelEndcap 4")!=string::npos ) {FPIX_M_2 = true;}
159  if( moduleName.find("PixelEndcap 1")!=string::npos ) {FPIX_P_1 = true;}
160  if( moduleName.find("PixelEndcap 2")!=string::npos ) {FPIX_P_2 = true;}
161  if( moduleName.find("PixelBarrel 1")!=string::npos ) {BPIX_L_1 = true;}
162  if( moduleName.find("PixelBarrel 2")!=string::npos ) {BPIX_L_2 = true;}
163  if( moduleName.find("PixelBarrel 3")!=string::npos ) {BPIX_L_3 = true;}
164  //}
165  *svgfile << " <svg:polygon detid=\""
166  << mod->idex
167  << "\" id=\""
168  << mod->idex
169  << "\" onclick=\"SvgMap.showData(evt);\" onmouseover=\"SvgMap.showData(evt);\" onmouseout=\"SvgMap.showData(evt);\" entries=\""
170  << mod->text
171  << "\" POS=\""
172  << mod->name
173  << " Id "
174  << mod->idex
175  << " \" fill=\"rgb("
176  << 146
177  << ","
178  << 0
179  << ","
180  << 255
181  << ")\" points=\"";
182  for(int k=0;k<np;k++)
183  {
184  if( FPIX_M_1 )
185  {
186  xd[k] = xd[k] * 1.8 - 60 ;
187  yd[k] = yd[k] * 2.0 - 30 ;
188  }
189  if( FPIX_M_2 )
190  {
191  xd[k] = xd[k] * 1.8 - 60 ;
192  yd[k] = yd[k] * 2.0 - 60 ;
193  }
194  if( FPIX_P_1 )
195  {
196  xd[k] = xd[k] * 1.8 - 1020 ;
197  yd[k] = yd[k] * 2.0 - 30 ;
198  }
199  if( FPIX_P_2 )
200  {
201  xd[k] = xd[k] * 1.8 - 1020 ;
202  yd[k] = yd[k] * 2.0 - 60 ;
203  }
204  if( BPIX_L_1 )
205  {
206  xd[k] = xd[k] * 1.2 - 130 ;
207  }
208  if( BPIX_L_2 )
209  {
210  xd[k] = xd[k] * 1.2 - 30 ;
211  }
212  if( BPIX_L_3 )
213  {
214  xd[k] = xd[k] * 1.2 - 240 ;
215  yd[k] = yd[k] - 5 ;
216  }
217  *svgfile << xd[k] << "," << yd[k] << " " ;
218  }
219  *svgfile <<"\" />" <<endl;
220  return ;
221  }
222 
223 }
224 
225 //===================================================================================
226 //print in svg format tracker map
227 //print_total = true represent in color the total stored in the module
228 //print_total = false represent in color the average
229 void SiPixelTrackerMap::print(bool print_total, string TKType, float minval, float maxval)
230 {
231 //cout<<"Entering SiPixelTrackerMap::print: "<<endl;
232 
233  minvalue=minval; maxvalue=maxval;
234  svgfile = new std::ofstream("svgmap.xml",ios::out);
235  jsfile = new std::ifstream("TrackerMapHeader.txt",ios::in);
236 
237  //copy javascript interface from trackermap.txt file
238  string line;
239  while (getline( *jsfile, line ))
240  {
241  *svgfile << line << endl;
242  }
243  //
244 
245  if(!print_total)
246  {
247  for (int layer=1; layer < 44; layer++)
248  {
249  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++)
250  {
251  for (int module=1;module<200;module++)
252  {
253  int key=layer*100000+ring*1000+module;
254  TmModule * mod = smoduleMap[key];
255  if(mod !=0 && !mod->notInUse())
256  {
257  mod->value = mod->value / mod->count;
258  }
259  }
260  }
261  }
262  }
263 
264  if(minvalue>=maxvalue)
265  {
266  minvalue=9999999.;
267  maxvalue=-9999999.;
268  for (int layer=1; layer < 44; layer++)
269  {
270  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++)
271  {
272  for (int module=1;module<200;module++)
273  {
274  int key=layer*100000+ring*1000+module;
275  TmModule * mod = smoduleMap[key];
276  if(mod !=0 && !mod->notInUse())
277  {
278  if (minvalue > mod->value)minvalue=mod->value;
279  if (maxvalue < mod->value)maxvalue=mod->value;
280  }
281  }
282  }
283  }
284  }
285 
286  for (int layer=1; layer < 44; layer++)
287  {
288  nlay=layer;
289  defwindow(nlay);
290  for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++)
291  {
292  for (int module=1;module<200;module++)
293  {
294  int key=layer*100000+ring*1000+module;
295  TmModule * mod = smoduleMap[key];
296  if(mod !=0 && !mod->notInUse())
297  {
298  drawModule(mod,key,layer,print_total);
299  }
300  }
301  }
302  }
303 
304 /* cout << ACYellow << ACBold
305  << "[SiPixelTrackerMap::print()] "
306  << ACPlain
307  << "TKType: |"
308  << TKType
309  << "|"
310  << endl ;
311 */
312  *svgfile << " " << endl ;
313 
314  if( TKType == "Averages" || TKType == "Entries")
315  {
316  *svgfile << " <svg:g id=\"theColorMap\" transform=\"translate(0, 0)\" style=\"visibility: visible;\">" << endl ;
317  } else {
318  *svgfile << " <svg:g id=\"theColorMap\" transform=\"translate(0, 0)\" style=\"visibility: hidden;\">" << endl ;
319  }
320 
321  // this is the color scale on the right hand side of the tracker map:
322  int px = 1370 ;
323  int dx = 25 ;
324  int py = 50 ;
325  int dy = 6 ;
326  int j = 5 ;
327  for( int i=99; i>=0; i--)
328  {
329  *svgfile << " <svg:polygon id=\"map\" fill=\"rgb("
331  << ","
333  << ","
335  << ")\" points=\""
336  << px
337  << ","
338  << py
339  << " "
340  << px+dx
341  << ","
342  << py
343  << " "
344  << px+dx
345  << ","
346  << py+dy
347  << " "
348  << px
349  << ","
350  << py+dy
351  << "\" />"
352  << endl ;
353  if( i == 0 || i==20 || i==40 || i==60 || i==80 || i==99)
354  {
355  *svgfile << " " << endl ;
356  *svgfile << " <svg:text id=\"colorCodeMark"
357  << j--
358  << "\" class=\"normalText\" x=\""
359  << px+dx+5
360  << "\" y=\""
361  << py + 3
362  << "\" font-size=\"20\">"
363  << i
364  << "%</svg:text>"
365  << endl;
366  *svgfile << " " << endl ;
367  }
368  py += dy + 1;
369 
370  // cout<<"inside the polygon loop: i= "<<i<<" , r= "<<SiPixelContinuousPalette::r[i]<<" , g= "<<SiPixelContinuousPalette::g[i]<<" , b= "<<SiPixelContinuousPalette::b[i]<<" , px= "<<px<<" , py= "<<py<<endl;
371  }
372  *svgfile << " </svg:g>" << endl ;
373 
374  if( TKType == "Alarms" )
375  {
376  *svgfile << " <svg:g id=\"theAlarmMap\" transform=\"translate(0, 0)\" style=\"visibility: visible;\">" << endl ;
377  } else {
378  *svgfile << " <svg:g id=\"theAlarmMap\" transform=\"translate(0, 0)\" style=\"visibility: hidden;\">" << endl ;
379  }
380  *svgfile << " " << endl ;
381  *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(255,0,0)\" points=\"1300,300 1325,300 1325,320 1300,320\" />" << endl ;
382  *svgfile << " <svg:text id=\"ERROR\" class=\"normalText\" x=\"1334\" y=\"317\" font-size=\"20\">ERROR </svg:text>" << endl ;
383  *svgfile << " " << endl ;
384  *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(0,255,0)\" points=\"1300,330 1325,330 1325,350 1300,350\" />" << endl ;
385  *svgfile << " <svg:text id=\"OK\" class=\"normalText\" x=\"1334\" y=\"347\" font-size=\"20\">OK </svg:text>" << endl ;
386  *svgfile << " " << endl ;
387  *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(255,255,0)\" points=\"1300,360 1325,360 1325,380 1300,380\" />" << endl ;
388  *svgfile << " <svg:text id=\"WARNING\" class=\"normalText\" x=\"1334\" y=\"377\" font-size=\"20\">WARNING </svg:text>" << endl ;
389  *svgfile << " " << endl ;
390  *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(0,0,255)\" points=\"1300,390 1325,390 1325,410 1300,410\" />" << endl ;
391  *svgfile << " <svg:text id=\"OTHER\" class=\"normalText\" x=\"1334\" y=\"407\" font-size=\"20\">OTHER </svg:text>" << endl ;
392  *svgfile << " " << endl ;
393  *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(255,255,255)\" points=\"1300,420 1325,420 1325,440 1300,440\" />" << endl ;
394  *svgfile << " <svg:text id=\"UNDEFINED\" class=\"normalText\" x=\"1334\" y=\"437\" font-size=\"20\">UNDEFINED</svg:text>" << endl ;
395  *svgfile << " " << endl ;
396  *svgfile << " </svg:g>" << endl ;
397 
398  *svgfile << " " << endl ;
399 
400  *svgfile << " <svg:text id=\"colorCodeME\" class=\"normalText\" x=\"1000\" y=\"4000\">"
401  << title
402  << "</svg:text>"
403  << endl;
404  delete jsfile ;
405  jsfile = new std::ifstream("TrackerMapTrailer.txt",ios::in);
406  while (getline( *jsfile, line ))
407  {
408  *svgfile << line << endl;
409  }
410  delete jsfile ;
411 
412  svgfile->close() ;
413 /* cout << ACYellow << ACBold
414  << "[SiPixelTrackerMap::print( )] "
415  << ACPlain
416  << "svgmap.xml file just closed..."
417  << endl ;
418 */
419  delete svgfile ;
420 }
int i
Definition: DBlmapReader.cc:9
float minvalue
Definition: TrackerMap.h:499
float value
Definition: TmModule.h:12
SmoduleMap smoduleMap
Definition: TrackerMap.h:140
int module(int fedId, int fedCh)
Definition: TrackerMap.cc:2687
void defwindow(int num_lay)
Definition: TrackerMap.h:328
int idModule
Definition: TmModule.h:26
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
float posz
Definition: TmModule.h:9
void drawModule(TmModule *mod, int key, int nlay, bool print_total)
int firstRing[43]
Definition: TrackerMap.h:479
float posx
Definition: TmModule.h:9
bool posrel
Definition: TrackerMap.h:491
return((rh^lh)&mask)
double phival(double x, double y)
Definition: TrackerMap.h:173
std::string moduleName(Provenance const &provenance)
Definition: Provenance.cc:27
unsigned int idex
Definition: TmModule.h:29
int np
Definition: AMPTWrapper.h:33
std::string text
Definition: TmModule.h:14
float posy
Definition: TmModule.h:9
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int j
Definition: DBlmapReader.cc:9
std::ofstream * svgfile
Definition: TrackerMap.h:493
SiPixelTrackerMap(std::string s=" ", int xsize1=340, int ysize1=200)
double ydpixel(double y)
Definition: TrackerMap.h:241
#define M_PI
int count
Definition: TmModule.h:13
float width
Definition: TmModule.h:10
int k[5][pyjets_maxn]
tuple out
Definition: dbtoconf.py:99
float widthAtHalfLength
Definition: TmModule.h:10
bool notInUse()
Definition: TmModule.h:24
double xdpixel(double x)
Definition: TrackerMap.h:235
void print(bool print_total=true, std::string TKType="Averages", float minval=0., float maxval=0.)
list key
Definition: combine.py:13
float maxvalue
Definition: TrackerMap.h:499
volatile std::atomic< bool > shutdown_flag false
static bool isRingStereo(int key)
Definition: TrackerMap.h:440
std::ifstream * jsfile
Definition: TrackerMap.h:495
int ring
Definition: TmModule.h:27
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
float length
Definition: TmModule.h:10
Definition: vlib.h:208
std::string name
Definition: TmModule.h:15
int ntotRing[43]
Definition: TrackerMap.h:478
Definition: DDAxes.h:10