00001
00002
00003
00004
00005
00016
00017
00018
00019
00020
00021
00022 #include "DQM/SiPixelMonitorClient/interface/SiPixelTrackerMap.h"
00023 #include "DQM/SiPixelMonitorClient/interface/SiPixelContinuousPalette.h"
00024 #include "DQM/SiPixelMonitorClient/interface/ANSIColors.h"
00025 #include "CommonTools/TrackerMap/interface/TmModule.h"
00026
00027 #include "TText.h"
00028
00029 #include <fstream>
00030 #include <iostream>
00031 using namespace std;
00032
00033
00034 SiPixelTrackerMap::SiPixelTrackerMap(string s,int xsize1, int ysize1) : TrackerMap(s,xsize1,ysize1)
00035 {
00036
00037
00038
00039 title = s ;
00040
00041 }
00042
00043
00044 void SiPixelTrackerMap::drawModule(TmModule * mod, int key,int nlay, bool print_total)
00045 {
00046
00047 double phi,r,dx,dy, dy1;
00048 double xp[4],yp[4],xp1,yp1;
00049 double vhbot,vhtop,vhapo;
00050 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};
00051 double xt1,yt1,xs1=0.,ys1=0.,xt2,yt2,xs2,ys2,pv1,pv2;
00052
00053 double xd[4],yd[4];
00054 int np = 4;
00055
00056 int numod=0;
00057 phi = phival(mod->posx,mod->posy);
00058 r = sqrt(mod->posx*mod->posx+mod->posy*mod->posy);
00059 vhbot = mod->width;
00060 vhtop=mod->width;
00061 vhapo=mod->length;
00062 if(nlay < 31){
00063 vhbot = mod->widthAtHalfLength/2.-(mod->width/2.-mod->widthAtHalfLength/2.);
00064 vhtop=mod->width/2.;
00065 vhapo=mod->length/2.;
00066 if(nlay >12 && nlay <19){
00067 if(posrel)r = r+r;
00068 xp[0]=r-vhtop;yp[0]=-vhapo;
00069 xp[1]=r+vhtop;yp[1]=-vhapo;
00070 xp[2]=r+vhtop;yp[2]=vhapo;
00071 xp[3]=r-vhtop;yp[3]=vhapo;
00072 }else{
00073 if(posrel)r = r + r/3.;
00074 xp[0]=r-vhapo;yp[0]=-vhbot;
00075 xp[1]=r+vhapo;yp[1]=-vhtop;
00076 xp[2]=r+vhapo;yp[2]=vhtop;
00077 xp[3]=r-vhapo;yp[3]=vhbot;
00078 }
00079 for(int j=0;j<4;j++){
00080 xp1 = xp[j]*cos(phi)-yp[j]*sin(phi);
00081 yp1 = xp[j]*sin(phi)+yp[j]*cos(phi);
00082 xp[j] = xp1;yp[j]=yp1;
00083 }
00084 } else {
00085 numod=mod->idModule;if(numod>100)numod=numod-100;
00086 int vane = mod->ring;
00087 if(posrel){
00088 dx = vhapo;
00089 phi=M_PI;
00090 xt1=rmedio[nlay-31]; yt1=-vhtop/2.;
00091 xs1 = xt1*cos(phi)-yt1*sin(phi);
00092 ys1 = xt1*sin(phi)+yt1*cos(phi);
00093 xt2=rmedio[nlay-31]; yt2=vhtop/2.;
00094 xs2 = xt2*cos(phi)-yt2*sin(phi);
00095 ys2 = xt2*sin(phi)+yt2*cos(phi);
00096 dy=phival(xs2,ys2)-phival(xs1,ys1);
00097 dy1 = dy;
00098 if(nlay==31)dy1=0.39;
00099 if(nlay==32)dy1=0.23;
00100 if(nlay==33)dy1=0.16;
00101 xp[0]=vane*(dx+dx/8.);yp[0]=numod*(dy1);
00102 xp[1]=vane*(dx+dx/8.)+dx;yp[1]=numod*(dy1);
00103 xp[2]=vane*(dx+dx/8.)+dx;yp[2]=numod*(dy1)+dy;
00104 xp[3]=vane*(dx+dx/8.);yp[3]=numod*(dy1)+dy;
00105 }else{
00106 xt1=r; yt1=-vhtop/2.;
00107 xs1 = xt1*cos(phi)-yt1*sin(phi);
00108 ys1 = xt1*sin(phi)+yt1*cos(phi);
00109 xt2=r; yt2=vhtop/2.;
00110 xs2 = xt2*cos(phi)-yt2*sin(phi);
00111 ys2 = xt2*sin(phi)+yt2*cos(phi);
00112 pv1=phival(xs1,ys1);
00113 pv2=phival(xs2,ys2);
00114 if(fabs(pv1-pv2)>M_PI && numod==1)pv1=pv1-2.*M_PI;
00115 if(fabs(pv1-pv2)>M_PI && numod!=1)pv2=pv2+2.*M_PI;
00116 xp[0]=mod->posz-vhapo/2.;yp[0]=4.2*pv1;
00117 xp[1]=mod->posz+vhapo/2.;yp[1]=4.2*pv1;
00118 xp[2]=mod->posz+vhapo/2. ;yp[2]=4.2*pv2;
00119 xp[3]=mod->posz-vhapo/2.;yp[3]=4.2*pv2;
00120 }
00121 }
00122 if(isRingStereo(key))
00123 {
00124 np = 3;
00125 if(mod->idModule>100 ){for(int j=0;j<3;j++){
00126 xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
00127 }
00128 }else {
00129 xd[0]=xdpixel(xp[2]);yd[0]=ydpixel(yp[2]);
00130 xd[1]=xdpixel(xp[3]);yd[1]=ydpixel(yp[3]);
00131 xd[2]=xdpixel(xp[0]);yd[2]=ydpixel(yp[0]);
00132 }
00133 } else {
00134 for(int j=0;j<4;j++){
00135 xd[j]=xdpixel(xp[j]);yd[j]=ydpixel(yp[j]);
00136 }
00137 }
00138 char buffer [20];
00139 sprintf(buffer,"%X",mod->idex);
00140
00141
00142 bool FPIX_M_1 = false ;
00143 bool FPIX_M_2 = false ;
00144 bool FPIX_P_1 = false ;
00145 bool FPIX_P_2 = false ;
00146 bool BPIX_L_1 = false ;
00147 bool BPIX_L_2 = false ;
00148 bool BPIX_L_3 = false ;
00149 string moduleName = mod->name;
00150 if(moduleName.find("PixelEndcap")!=string::npos || moduleName.find("PixelBarrel")!=string::npos) {
00151 FPIX_M_1 = false ;
00152 FPIX_M_2 = false ;
00153 FPIX_P_1 = false ;
00154 FPIX_P_2 = false ;
00155 BPIX_L_1 = false ;
00156 BPIX_L_2 = false ;
00157 BPIX_L_3 = false ;
00158 if( moduleName.find("PixelEndcap 3")!=string::npos ) {FPIX_M_1 = true;}
00159 if( moduleName.find("PixelEndcap 4")!=string::npos ) {FPIX_M_2 = true;}
00160 if( moduleName.find("PixelEndcap 1")!=string::npos ) {FPIX_P_1 = true;}
00161 if( moduleName.find("PixelEndcap 2")!=string::npos ) {FPIX_P_2 = true;}
00162 if( moduleName.find("PixelBarrel 1")!=string::npos ) {BPIX_L_1 = true;}
00163 if( moduleName.find("PixelBarrel 2")!=string::npos ) {BPIX_L_2 = true;}
00164 if( moduleName.find("PixelBarrel 3")!=string::npos ) {BPIX_L_3 = true;}
00165
00166 *svgfile << " <svg:polygon detid=\""
00167 << mod->idex
00168 << "\" id=\""
00169 << mod->idex
00170 << "\" onclick=\"SvgMap.showData(evt);\" onmouseover=\"SvgMap.showData(evt);\" onmouseout=\"SvgMap.showData(evt);\" entries=\""
00171 << mod->text
00172 << "\" POS=\""
00173 << mod->name
00174 << " Id "
00175 << mod->idex
00176 << " \" fill=\"rgb("
00177 << 146
00178 << ","
00179 << 0
00180 << ","
00181 << 255
00182 << ")\" points=\"";
00183 for(int k=0;k<np;k++)
00184 {
00185 if( FPIX_M_1 )
00186 {
00187 xd[k] = xd[k] * 1.8 - 60 ;
00188 yd[k] = yd[k] * 2.0 - 30 ;
00189 }
00190 if( FPIX_M_2 )
00191 {
00192 xd[k] = xd[k] * 1.8 - 60 ;
00193 yd[k] = yd[k] * 2.0 - 60 ;
00194 }
00195 if( FPIX_P_1 )
00196 {
00197 xd[k] = xd[k] * 1.8 - 1020 ;
00198 yd[k] = yd[k] * 2.0 - 30 ;
00199 }
00200 if( FPIX_P_2 )
00201 {
00202 xd[k] = xd[k] * 1.8 - 1020 ;
00203 yd[k] = yd[k] * 2.0 - 60 ;
00204 }
00205 if( BPIX_L_1 )
00206 {
00207 xd[k] = xd[k] * 1.2 - 130 ;
00208 }
00209 if( BPIX_L_2 )
00210 {
00211 xd[k] = xd[k] * 1.2 - 30 ;
00212 }
00213 if( BPIX_L_3 )
00214 {
00215 xd[k] = xd[k] * 1.2 - 240 ;
00216 yd[k] = yd[k] - 5 ;
00217 }
00218 *svgfile << xd[k] << "," << yd[k] << " " ;
00219 }
00220 *svgfile <<"\" />" <<endl;
00221 return ;
00222 }
00223
00224 }
00225
00226
00227
00228
00229
00230 void SiPixelTrackerMap::print(bool print_total, string TKType, float minval, float maxval)
00231 {
00232
00233
00234 minvalue=minval; maxvalue=maxval;
00235 svgfile = new ofstream("svgmap.xml",ios::out);
00236 jsfile = new ifstream("TrackerMapHeader.txt",ios::in);
00237
00238
00239 string line;
00240 while (getline( *jsfile, line ))
00241 {
00242 *svgfile << line << endl;
00243 }
00244
00245
00246 if(!print_total)
00247 {
00248 for (int layer=1; layer < 44; layer++)
00249 {
00250 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++)
00251 {
00252 for (int module=1;module<200;module++)
00253 {
00254 int key=layer*100000+ring*1000+module;
00255 TmModule * mod = smoduleMap[key];
00256 if(mod !=0 && !mod->notInUse())
00257 {
00258 mod->value = mod->value / mod->count;
00259 }
00260 }
00261 }
00262 }
00263 }
00264
00265 if(minvalue>=maxvalue)
00266 {
00267 minvalue=9999999.;
00268 maxvalue=-9999999.;
00269 for (int layer=1; layer < 44; layer++)
00270 {
00271 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++)
00272 {
00273 for (int module=1;module<200;module++)
00274 {
00275 int key=layer*100000+ring*1000+module;
00276 TmModule * mod = smoduleMap[key];
00277 if(mod !=0 && !mod->notInUse())
00278 {
00279 if (minvalue > mod->value)minvalue=mod->value;
00280 if (maxvalue < mod->value)maxvalue=mod->value;
00281 }
00282 }
00283 }
00284 }
00285 }
00286
00287 for (int layer=1; layer < 44; layer++)
00288 {
00289 nlay=layer;
00290 defwindow(nlay);
00291 for (int ring=firstRing[layer-1]; ring < ntotRing[layer-1]+firstRing[layer-1];ring++)
00292 {
00293 for (int module=1;module<200;module++)
00294 {
00295 int key=layer*100000+ring*1000+module;
00296 TmModule * mod = smoduleMap[key];
00297 if(mod !=0 && !mod->notInUse())
00298 {
00299 drawModule(mod,key,layer,print_total);
00300 }
00301 }
00302 }
00303 }
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 *svgfile << " " << endl ;
00314
00315 if( TKType == "Averages" || TKType == "Entries")
00316 {
00317 *svgfile << " <svg:g id=\"theColorMap\" transform=\"translate(0, 0)\" style=\"visibility: visible;\">" << endl ;
00318 } else {
00319 *svgfile << " <svg:g id=\"theColorMap\" transform=\"translate(0, 0)\" style=\"visibility: hidden;\">" << endl ;
00320 }
00321
00322
00323 int px = 1370 ;
00324 int dx = 25 ;
00325 int py = 50 ;
00326 int dy = 6 ;
00327 int j = 5 ;
00328 for( int i=99; i>=0; i--)
00329 {
00330 *svgfile << " <svg:polygon id=\"map\" fill=\"rgb("
00331 << SiPixelContinuousPalette::r[i]
00332 << ","
00333 << SiPixelContinuousPalette::g[i]
00334 << ","
00335 << SiPixelContinuousPalette::b[i]
00336 << ")\" points=\""
00337 << px
00338 << ","
00339 << py
00340 << " "
00341 << px+dx
00342 << ","
00343 << py
00344 << " "
00345 << px+dx
00346 << ","
00347 << py+dy
00348 << " "
00349 << px
00350 << ","
00351 << py+dy
00352 << "\" />"
00353 << endl ;
00354 if( i == 0 || i==20 || i==40 || i==60 || i==80 || i==99)
00355 {
00356 *svgfile << " " << endl ;
00357 *svgfile << " <svg:text id=\"colorCodeMark"
00358 << j--
00359 << "\" class=\"normalText\" x=\""
00360 << px+dx+5
00361 << "\" y=\""
00362 << py + 3
00363 << "\" font-size=\"20\">"
00364 << i
00365 << "%</svg:text>"
00366 << endl;
00367 *svgfile << " " << endl ;
00368 }
00369 py += dy + 1;
00370
00371
00372 }
00373 *svgfile << " </svg:g>" << endl ;
00374
00375 if( TKType == "Alarms" )
00376 {
00377 *svgfile << " <svg:g id=\"theAlarmMap\" transform=\"translate(0, 0)\" style=\"visibility: visible;\">" << endl ;
00378 } else {
00379 *svgfile << " <svg:g id=\"theAlarmMap\" transform=\"translate(0, 0)\" style=\"visibility: hidden;\">" << endl ;
00380 }
00381 *svgfile << " " << endl ;
00382 *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(255,0,0)\" points=\"1300,300 1325,300 1325,320 1300,320\" />" << endl ;
00383 *svgfile << " <svg:text id=\"ERROR\" class=\"normalText\" x=\"1334\" y=\"317\" font-size=\"20\">ERROR </svg:text>" << endl ;
00384 *svgfile << " " << endl ;
00385 *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(0,255,0)\" points=\"1300,330 1325,330 1325,350 1300,350\" />" << endl ;
00386 *svgfile << " <svg:text id=\"OK\" class=\"normalText\" x=\"1334\" y=\"347\" font-size=\"20\">OK </svg:text>" << endl ;
00387 *svgfile << " " << endl ;
00388 *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(255,255,0)\" points=\"1300,360 1325,360 1325,380 1300,380\" />" << endl ;
00389 *svgfile << " <svg:text id=\"WARNING\" class=\"normalText\" x=\"1334\" y=\"377\" font-size=\"20\">WARNING </svg:text>" << endl ;
00390 *svgfile << " " << endl ;
00391 *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(0,0,255)\" points=\"1300,390 1325,390 1325,410 1300,410\" />" << endl ;
00392 *svgfile << " <svg:text id=\"OTHER\" class=\"normalText\" x=\"1334\" y=\"407\" font-size=\"20\">OTHER </svg:text>" << endl ;
00393 *svgfile << " " << endl ;
00394 *svgfile << " <svg:polygon id=\"map\" fill =\"rgb(255,255,255)\" points=\"1300,420 1325,420 1325,440 1300,440\" />" << endl ;
00395 *svgfile << " <svg:text id=\"UNDEFINED\" class=\"normalText\" x=\"1334\" y=\"437\" font-size=\"20\">UNDEFINED</svg:text>" << endl ;
00396 *svgfile << " " << endl ;
00397 *svgfile << " </svg:g>" << endl ;
00398
00399 *svgfile << " " << endl ;
00400
00401 *svgfile << " <svg:text id=\"colorCodeME\" class=\"normalText\" x=\"1000\" y=\"4000\">"
00402 << title
00403 << "</svg:text>"
00404 << endl;
00405 delete jsfile ;
00406 jsfile = new ifstream("TrackerMapTrailer.txt",ios::in);
00407 while (getline( *jsfile, line ))
00408 {
00409 *svgfile << line << endl;
00410 }
00411 delete jsfile ;
00412
00413 svgfile->close() ;
00414
00415
00416
00417
00418
00419
00420 delete svgfile ;
00421 }