CMS 3D CMS Logo

SiPixelTrackerMap.cc

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

Generated on Tue Jun 9 17:33:21 2009 for CMSSW by  doxygen 1.5.4