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