CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CommonTools/TrackerMap/interface/TrackerMap.h

Go to the documentation of this file.
00001 #ifndef _TrackerMap_h_
00002 #define _TrackerMap_h_
00003 #include <string>
00004 #include <iostream>
00005 #include <fstream>
00006 #include <sstream>
00007 #include <cmath>
00008 #include <map>
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00012 #include "TColor.h"
00013 
00014 class TmModule;
00015 class TmApvPair;
00016 class EventSetup;
00017 class TmCcu;
00018 class TmPsu;
00019 
00020 class TrackerMap {
00021  public:
00022   //TrackerMap(){TrackerMap(" ");};   //!< default constructor
00023   TrackerMap(std::string s=" ",int xsize1=340,int ysize1=200);
00024   TrackerMap(const edm::ParameterSet & iConfig);
00025   TrackerMap(const edm::ParameterSet & iConfig,const edm::ESHandle<SiStripFedCabling> tkFed);
00026   ~TrackerMap();  
00027   
00028   void build();
00029   void init();
00030   void drawModule(TmModule * mod, int key, int layer, bool total, std::ofstream * file);
00031   void print(bool print_total=true,float minval=0., float maxval=0.,std::string s="svgmap");
00032   void printall(bool print_total=true,float minval=0., float maxval=0.,std::string s="svgmap");
00033   void printonline();
00034   void printlayers(bool print_total=true,float minval=0., float maxval=0.,std::string s="layer");
00035   void save(bool print_total=true,float minval=0., float maxval=0.,std::string s="svgmap.svg",int width=1500, int height=800);
00036   void save_as_fedtrackermap(bool print_total=true,float minval=0., float maxval=0.,std::string s="fed_svgmap.svg",int width=1500, int height=800);
00037   void save_as_fectrackermap(bool print_total=true,float minval=0., float maxval=0.,std::string s="fec_svgmap.svg",int width=1500, int height=800);
00038   void save_as_psutrackermap(bool print_total=true,float minval=0., float maxval=0.,std::string s="psu_svgmap.svg",int width=1500, int height=800);
00039   void save_as_HVtrackermap(bool print_total=true,float minval=0., float maxval=0.,std::string s="psu_svgmap.svg",int width=1500, int height=800);
00040   void drawApvPair( int crate, int numfed_incrate, bool total, TmApvPair* apvPair,std::ofstream * file,bool useApvPairValue);
00041   void drawCcu( int crate, int numfed_incrate, bool total, TmCcu* ccu,std::ofstream * file,bool useCcuValue);
00042   void drawPsu(int rack,int numcrate_inrack, bool print_total, TmPsu* psu,ofstream * svgfile,bool usePsuValue);
00043   void drawHV2(int rack,int numcrate_inrack, bool print_total, TmPsu* psu,ofstream * svgfile,bool usePsuValue);
00044   void drawHV3(int rack,int numcrate_inrack, bool print_total, TmPsu* psu,ofstream * svgfile,bool usePsuValue);
00045   void fill_current_val(int idmod, float current_val );
00046   void fill(int layer , int ring, int nmod, float x );
00047   void fill(int idmod, float qty );
00048   void fillc(int idmod, int RGBcode) {fillc(idmod,(RGBcode>>16) & 0xFF , (RGBcode>>8) & 0xFF, RGBcode & 0xFF);}
00049   void fillc(int idmod, int red, int green, int blue);
00050   void fillc(int layer,int ring, int nmod, int red, int green, int blue);
00051   void fillc_all_blank();
00052   void fill_all_blank();
00053   void fill_current_val_fed_channel(int fedId,int fedCh, float current_val );
00054   void fill_fed_channel(int fedId,int fedCh, float qty );
00055   void fill_fed_channel(int modId, float qty );
00056   void fillc_fed_channel(int fedId,int fedCh, int red, int green, int blue);
00057   void fillc_fec_channel(int crate,int slot, int ring, int addr, int red, int green, int blue  );
00058   void fill_fec_channel(int crate,int slot, int ring, int addr, float qty  );
00059   void fill_lv_channel(int rack,int crate, int board, float qty  );
00060   void fillc_lv_channel(int rack,int crate, int board, int red, int green, int blue);
00061   void fill_hv_channel2(int rack,int crate, int board, float qty  );
00062   void fillc_hv_channel2(int rack,int crate, int board, int red, int green, int blue);
00063   void fill_hv_channel3(int rack,int crate, int board, float qty  );
00064   void fillc_hv_channel3(int rack,int crate, int board, int red, int green, int blue);
00065   int module(int fedId,int fedCh);
00066   void setText(int idmod , std::string s );
00067   void setText(int layer, int ring, int nmod , std::string s );
00068   void setPalette(int numpalette){palette=numpalette;} 
00069   void drawPalette(std::ofstream * file); 
00070   void showPalette(bool printflag1){printflag=printflag1;}; 
00071   void setTitle(std::string s){title=s;};
00072   void setRange(float min,float max){gminvalue=min;gmaxvalue=max;};
00073   void addPixel(bool addPixelfl){addPixelFlag=addPixelfl;};
00074   void reset();
00075   void load(std::string s="tmap.svg"); 
00076   int getxsize(){return xsize;};
00077   int getysize(){return ysize;};
00078   int getcolor(float value, int palette);
00079   std::ifstream * findfile(std::string filename);
00080   int getNumMod(){return number_modules;};
00081   std::vector<TColor*> vc; 
00082   typedef std::map<const int  , TmModule *> SmoduleMap;
00083   SmoduleMap smoduleMap;
00084   typedef std::map<const int  , TmModule *> ImoduleMap;
00085   ImoduleMap imoduleMap;
00086   typedef std::map<const int  , TmApvPair*> SvgApvPair;
00087   SvgApvPair apvMap;
00088   typedef std::multimap<const int  , TmApvPair*> ModApvPair;
00089    ModApvPair apvModuleMap;
00090   typedef std::map<const int  , int>  SvgFed;
00091   SvgFed fedMap;
00092   typedef std::map<const int  , TmCcu*> MapCcu;
00093   MapCcu  ccuMap;
00094   typedef std::multimap<TmCcu*  , TmModule*> FecModule;
00095   FecModule fecModuleMap;
00096   typedef std::map<const int  , TmPsu*> MapPsu;
00097   MapPsu  psuMap;
00098   typedef std::multimap<TmPsu*  , TmModule*> PsuModule;
00099   PsuModule psuModuleMap;
00100   int palette;
00101   bool printflag;
00102   bool enableFedProcessing;
00103   bool enableFecProcessing;
00104   bool enableLVProcessing;
00105   bool enableHVProcessing;
00106   int ndet; //number of detectors 
00107   int npart; //number of detectors parts 
00108   std::string title;
00109    std::string jsfilename,infilename;
00110   std::string jsPath;
00111    bool psetAvailable;
00112   double phival(double x, double y){
00113     double phi;
00114     double phi1=atan(y/x);
00115     phi = phi1;
00116     if(y<0. && x>0) phi = phi1+2.*M_PI;
00117     if(x<0.)phi=phi1+M_PI;
00118     if(fabs(y)<0.000001 && x>0)phi=0;
00119     if(fabs(y)<0.000001&&x<0)phi=M_PI;
00120     if(fabs(x)<0.000001&&y>0)phi=M_PI/2.;
00121     if(fabs(x)<0.000001&&y<0)phi=3.*M_PI/2.;
00122       
00123     return phi;
00124   }
00125   
00126   int find_layer(int ix, int iy)
00127     {
00128       int add;
00129       int layer=0;
00130       if(iy <= xsize){//endcap+z
00131         add = 15;
00132         layer = ix/ysize;
00133         layer = layer+add+1;
00134       }
00135       if(iy > xsize && iy< 3*xsize){//barrel
00136         add=30;
00137         if(ix < 2*ysize){
00138           layer=1;
00139         }else {
00140           layer = ix/(2*ysize);
00141           if(iy < 2*xsize)layer=layer*2+1; else layer=layer*2;
00142         }
00143         layer = layer+add;
00144       }
00145       if(iy >= 3*xsize){        //endcap-z
00146         layer = ix/ysize;
00147         layer = 15-layer;
00148       }
00149       return layer;  
00150     }
00151 
00152   int getlayerCount(int subdet, int partdet){
00153     int ncomponent=0;
00154     if(subdet == 1){ //1=pixel
00155       if(partdet == 1 || partdet == 3){ //1-3=encap
00156         ncomponent = 3;
00157       }
00158       else { ncomponent = 3; } //barrel
00159     }
00160     if(subdet== 2){ //2=inner silicon
00161       if(partdet == 1 || partdet == 3){ //1-3=encap
00162         ncomponent = 3;
00163       }
00164       else { ncomponent = 4; } //barrel
00165     }
00166     if(subdet== 3){ //3=outer silicon
00167       if(partdet == 1 || partdet == 3){ //1-3=encap
00168         ncomponent = 9;
00169       }
00170       else { ncomponent = 6; } //barrel
00171     }
00172     return(ncomponent);
00173   }   
00174   double  xdpixel(double x){
00175     double res;
00176     if(saveAsSingleLayer)res= ((x-xmin)/(xmax-xmin)*xsize);
00177     else res= ((x-xmin)/(xmax-xmin)*xsize)+ix;
00178     return res;
00179   }
00180   double  ydpixel(double y){
00181     double res=0;
00182     double y1;
00183     y1 = (y-ymin)/(ymax-ymin);
00184     if(nlay>30)
00185        {
00186         if(nlay <34) res= 2*ysize - (y1*2*ysize);
00187         if(nlay==34) res= 2.4*ysize - (y1*2.4*ysize);
00188         if(nlay>34) res= 2.5*ysize - (y1*2.5*ysize);  
00189         }
00190     else res= xsize - (y1*xsize);
00191     if(!saveAsSingleLayer) res=res+iy;
00192     return res;
00193   }
00194   double  xdpixelc(double x){
00195     double res;
00196     if(saveAsSingleLayer)res= ((x-xmin)/(xmax-xmin)*xsize);
00197     else res= ((x-xmin)/(xmax-xmin)*xsize)+ix;
00198     return res;
00199   }
00200   double  ydpixelc(double y){
00201     double res;
00202     double y1;
00203     y1 = (y-ymin)/(ymax-ymin);
00204      if(saveAsSingleLayer)res= 2*ysize - (y1*2*ysize);
00205      else res= 2*ysize - (y1*2*ysize)+iy;
00206     return res;
00207   }
00208   double  xdpixelfec(double x){
00209     double res;
00210     if(saveAsSingleLayer)res= ((x-xmin)/(xmax-xmin)*xsize);
00211     else res= ((x-xmin)/(xmax-xmin)*xsize)+ix;
00212     return res;
00213   }
00214   double  ydpixelfec(double y){
00215     double res;
00216     double y1;
00217     y1 = (y-ymin)/(ymax-ymin);
00218      if(saveAsSingleLayer)res= 2*ysize - (y1*2*ysize);
00219      else res= 2*ysize - (y1*2*ysize)+iy;
00220     return res;
00221   }
00222   double  xdpixelpsu(double x){
00223     double res;
00224     if(saveAsSingleLayer)res= ((x-xmin)/(xmax-xmin)*xsize);
00225     else res= ((x-xmin)/(xmax-xmin)*xsize)+ix;
00226     return res;
00227   }
00228    double  ydpixelpsu(double y){
00229     double res;
00230     double y1;
00231     y1 = (y-ymin)/(ymax-ymin);
00232      if(saveAsSingleLayer)res= 2*ysize - (y1*2*ysize);
00233      else res= 2*ysize - (y1*2*ysize)+iy;
00234     return res;
00235   }
00236 
00237    void defcwindow(int num_crate){
00238     ncrate = num_crate;
00239     int xoffset=xsize/3;
00240     int yoffset=ysize;
00241     xmin=-1.;xmax=63.;  ymin = -1.; ymax=37.;
00242     if((ncrate%3)==2)ix = xoffset+xsize*4/3;
00243     if((ncrate%3)==1)ix = xoffset+2*xsize*4/3;
00244     if((ncrate%3)==0)ix = xoffset;
00245     iy = yoffset+((ncrate-1)/3)*ysize*2;
00246   } 
00247    void deffecwindow(int num_crate){
00248     ncrate = num_crate;
00249     int xoffset=xsize/3;
00250     int yoffset=2*ysize;
00251     xmin=-1.;xmax=37.;  ymin = -10.; ymax=40.;
00252     if(ncrate==1||ncrate==3)ix = xoffset+xsize*2;
00253     if(ncrate==2||ncrate==4)ix = xoffset;
00254     iy = yoffset+((ncrate-1)/2)*ysize*4;
00255   }
00256    void defpsuwindow(int num_rack){
00257     nrack = num_rack;
00258     int xoffset=xsize/5;
00259     int yoffset=ysize;
00260     xmin=-1.;xmax=63.;  ymin = -1.; ymax=37.;
00261 
00262     if((nrack%5)==1)ix = xoffset+4*int(xsize/1.5);
00263     if((nrack%5)==2)ix = xoffset+3*int(xsize/1.5);
00264     if((nrack%5)==3)ix = xoffset+2*int(xsize/1.5);
00265     if((nrack%5)==4)ix = xoffset+int(xsize/1.5);
00266     if((nrack%5)==0)ix = xoffset;
00267 
00268     iy = yoffset+((nrack-1)/5)*ysize*2;
00269 
00270     }
00271 
00272 
00273 void defwindow(int num_lay){
00274   nlay = num_lay;
00275   if(posrel){ // separated modules
00276     xmin=-2.;ymin=-2.;xmax=2.;ymax=2.;
00277     if(nlay >12 && nlay < 19){
00278       xmin=-.40;xmax=.40;ymin=-.40;ymax=.40;
00279     }
00280     if(nlay>30){
00281       xmin=-0.1;xmax=3.;ymin=-0.1;ymax=8.5;
00282       if(nlay<34){xmin=-0.3;xmax=1.0;}
00283       if(nlay>33&&nlay<38){xmax=2.0;}
00284       if(nlay>37){ymax=8.;}//inner
00285     }
00286   }else{ //overlayed modules
00287     xmin=-1.3;ymin=-1.3;xmax=1.3;ymax=1.3;
00288     if(nlay >12 && nlay < 19){
00289       xmin=-.20;xmax=.20;ymin=-.20;ymax=.20;
00290     }
00291     if(nlay>30){
00292       xmin=-1.5;xmax=1.5;ymin=-1.;ymax=28.;
00293       if(nlay<34){xmin=-0.5;xmax=0.5;}
00294       if(nlay>33&&nlay<38){xmin=-1.;xmax=1.;}
00295     }
00296     
00297   }
00298   if(nlay<16){
00299       ix=0;
00300       if(nlay==15||nlay==14)iy=(15-nlay)*2*ysize; else 
00301           {if(nlay>9&&nlay<13)iy=4*ysize-(int)(ysize/2.)+(12-nlay)*(int)(ysize/1.50);else iy=6*ysize+(9-nlay)*(int)(ysize*1.3);}}
00302   if(nlay>15&&nlay<31){
00303     ix=3*xsize;
00304      if(nlay==16||nlay==17)iy=(nlay-16)*2*ysize; else 
00305           {if(nlay>18&&nlay<22)iy=4*ysize-(int)(ysize/2.)+(nlay-19)*(int)(ysize/1.50);else iy=6*ysize+(nlay-22)*(int)(ysize*1.3);}}
00306   if(nlay>30){
00307     if(nlay==31){ix=(int)(1.5*xsize);iy=0;}
00308     if(nlay==32){int il=(nlay-30)/2;ix=xsize;iy=il*2*ysize;}
00309     if(nlay==33){int il=(nlay-30)/2;ix=2*xsize;iy=il*2*ysize;}
00310     if(nlay==34){int il=(nlay-30)/2;ix=xsize;iy=il*(int)(2.57*ysize);}
00311     if(nlay>34 && nlay%2==0){int il=(nlay-30)/2;ix=xsize;iy=il*(int)(2.5*ysize);}
00312     if(nlay>34 && nlay%2!=0){int il=(nlay-30)/2;ix=2*xsize;iy=il*(int)(2.5*ysize);}
00313   }
00314  }
00315   
00316   int getringCount(int subdet, int partdet, int layer){
00317     int ncomponent=0;
00318     if(subdet== 1){ //1=pixel
00319       if(partdet== 1 || partdet== 3){ //end-cap
00320         ncomponent = 7;
00321       }
00322       else{ncomponent = 8;} //barrel
00323     }   
00324     if(subdet== 2){ //inner-silicon
00325       if(partdet== 1 || partdet== 3){ //end-cap
00326         ncomponent = 3;
00327       }
00328       else{ncomponent = 12;} //barrel
00329     }
00330     if(subdet== 3){ //outer-silicon
00331       if(partdet== 1){ //end-cap-z
00332         if (layer== 1) ncomponent = 4;
00333         if (layer== 2 || layer== 3) ncomponent = 5;
00334         if (layer== 4 || layer== 5 || layer== 6) ncomponent = 6;
00335         if (layer== 7 || layer== 8 || layer== 9) ncomponent = 7;
00336       }
00337       if(partdet== 3){ //endcap+z
00338         if (layer== 9) ncomponent = 4;
00339         if (layer== 8 || layer== 7) ncomponent = 5;
00340         if (layer== 6 || layer== 5 || layer== 4) ncomponent = 6;
00341         if (layer== 3 || layer== 2 || layer== 1) ncomponent = 7;
00342       }
00343       if(partdet== 2){ //barrel
00344         ncomponent = 12;
00345       }
00346     }
00347     return(ncomponent);
00348   }
00349   int getmoduleCount(int subdet, int partdet, int layer, int ring){
00350     int ncomponent=0;
00351     int spicchif[] ={24,24,40,56,40,56,80};
00352     int spicchib[] ={20,32,44,30,38,46,56,42,48,54,60,66,74};
00353     int numero_layer = 0;
00354     
00355     if(partdet == 2){ //barrel
00356       numero_layer = layer-1;
00357       if(subdet== 2){ //inner
00358         numero_layer = numero_layer+3;
00359       }
00360       if(subdet == 3){ //outer
00361         numero_layer = numero_layer+7;
00362       }
00363       ncomponent = spicchib[numero_layer];
00364     }
00365     if(partdet!= 2){ //endcap
00366       if(subdet== 1)ncomponent=24;//pixel
00367       else
00368         ncomponent = spicchif[ring-1];
00369     }
00370     return(ncomponent);
00371   }
00372   static int layerno(int subdet,int leftright,int layer){
00373     if(subdet==6&&leftright==1)return(10-layer);
00374     if(subdet==6&&leftright==2)return(layer+21);
00375     if(subdet==4&&leftright==1)return(4-layer+9);
00376     if(subdet==4&&leftright==2)return(layer+18);
00377     if(subdet==2&&leftright==1)return(4-layer+12);
00378     if(subdet==2&&leftright==2)return(layer+15);
00379     if(subdet==1)return(layer+30);
00380     if(subdet==3)return(layer+33);
00381     if(subdet==5)return(layer+37);
00382   }
00383   
00384   static bool isRingStereo(int key){
00385     int layer=key/100000;
00386     int ring = key - layer*100000;
00387     ring = ring/1000;
00388     if(layer==34 || layer==35 || layer==38 || layer==39) return true;
00389     if(layer<13 || (layer>18&&layer<31))
00390       if(ring==1 || ring==2 || ring==5)return true;
00391     return false;
00392   }
00393   int nlayer(int det,int part,int lay){
00394     if(det==3 && part==1) return lay;
00395     if(det==2 && part==1) return lay+9;
00396     if(det==1 && part==1) return lay+12;
00397     if(det==1 && part==3) return lay+15;
00398     if(det==2 && part==3) return lay+18;
00399     if(det==3 && part==3) return lay+21;
00400     if(det==1 && part==2) return lay+30;
00401     if(det==2 && part==2) return lay+33;
00402     if(det==3 && part==2) return lay+37;
00403     return -1; 
00404   }
00405   
00406   std::string layername(int layer){
00407     std::string s= " ";
00408     std::ostringstream ons;
00409     
00410     if(layer < 10) ons << "TEC -z Layer " << layer;
00411     if(layer < 13 && layer > 9) ons << "TID -z Layer " << layer-9;
00412     if(layer < 16 && layer > 12) ons << "FPIX -z Layer " << layer-12;
00413     if(layer < 19 && layer > 15) ons << "FPIX +z Layer " << layer-15;
00414     if(layer < 22 && layer > 18) ons << "TID +z Layer " << layer-18;
00415     if(layer < 31 && layer > 21) ons << "TEC +z Layer " << layer-21;
00416     if(layer < 34 && layer > 30) ons << "TPB Layer " << layer-30;
00417     if(layer < 38 && layer > 33) ons << "TIB Layer " << layer-33;
00418     if(layer > 37) ons << "TOB Layer " << layer-37;
00419     s = ons.str(); 
00420     return s;  
00421   }
00422   int ntotRing[43];
00423   int firstRing[43];
00424   
00425  protected:
00426   int nlay;
00427   int ncrate;
00428   int nrack;
00429   int ncrates;
00430   int nfeccrates;
00431   int npsuracks;
00432   double xmin,xmax,ymin,ymax;
00433   int xsize,ysize,ix,iy;
00434   bool posrel;
00435   bool firstcall;
00436   std::ofstream * svgfile;
00437   std::ofstream * savefile;
00438   std::ifstream * jsfile;
00439   std::ifstream * inputfile;
00440   std::ifstream * ccufile;
00441   float gminvalue,gmaxvalue;
00442   float minvalue,maxvalue;
00443   int number_modules;
00444   bool temporary_file; 
00445   
00446  private:
00447   
00448   float oldz;
00449   bool saveAsSingleLayer;
00450   bool addPixelFlag;
00451 };
00452 #endif
00453