CMS 3D CMS Logo

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 
00013 
00014 class TmModule;
00015 class TmApvPair;
00016 class EventSetup;
00017 
00018 using namespace std;
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 drawApvPair( int crate, int numfed_incrate, bool total, TmApvPair* apvPair,std::ofstream * file,bool useApvPairValue);
00038   void fill_current_val(int idmod, float current_val );
00039   void fill(int layer , int ring, int nmod, float x );
00040   void fill(int idmod, float qty );
00041   void fillc(int idmod, int RGBcode) {fillc(idmod,(RGBcode>>16) & 0xFF , (RGBcode>>8) & 0xFF, RGBcode & 0xFF);}
00042   void fillc(int idmod, int red, int green, int blue);
00043   void fillc(int layer,int ring, int nmod, int red, int green, int blue);
00044   void fill_current_val_fed_channel(int fedId,int fedCh, float current_val );
00045   void fill_fed_channel(int fedId,int fedCh, float qty );
00046   void fill_fed_channel(int modId, float qty );
00047   void fillc_fed_channel(int fedId,int fedCh, int red, int green, int blue);
00048   int module(int fedId,int fedCh);
00049   void setText(int idmod , std::string s );
00050   void setText(int layer, int ring, int nmod , string s );
00051   void setPalette(int numpalette){palette=numpalette;} 
00052   void drawPalette(std::ofstream * file); 
00053   void showPalette(bool printflag1){printflag=printflag1;}; 
00054   int getxsize(){return xsize;};
00055   int getysize(){return ysize;};
00056   int getcolor(float value, int palette);
00057   std::ifstream * findfile(std::string filename);
00058   int getNumMod(){return number_modules;};
00059   typedef std::map<const int  , TmModule *> SmoduleMap;
00060   SmoduleMap smoduleMap;
00061   typedef std::map<const int  , TmModule *> ImoduleMap;
00062   ImoduleMap imoduleMap;
00063  typedef std::map<const int  , TmApvPair*> SvgApvPair;
00064   SvgApvPair apvMap;
00065   typedef std::multimap<const int  , TmApvPair*> ModApvPair;
00066    ModApvPair apvModuleMap;
00067   typedef std::map<const int  , int>  SvgFed;
00068   SvgFed fedMap;
00069   int palette;
00070   bool printflag;
00071   bool enableFedProcessing;
00072   int ndet; //number of detectors 
00073   int npart; //number of detectors parts 
00074   string title;
00075    std::string jsfilename,infilename;
00076   std::string jsPath;
00077    bool psetAvailable;
00078   double phival(double x, double y){
00079     double phi;
00080     double phi1=atan(y/x);
00081     phi = phi1;
00082     if(y<0. && x>0) phi = phi1+2.*M_PI;
00083     if(x<0.)phi=phi1+M_PI;
00084     if(fabs(y)<0.000001 && x>0)phi=0;
00085     if(fabs(y)<0.000001&&x<0)phi=M_PI;
00086     if(fabs(x)<0.000001&&y>0)phi=M_PI/2.;
00087     if(fabs(x)<0.000001&&y<0)phi=3.*M_PI/2.;
00088       
00089     return phi;
00090   }
00091   
00092   int find_layer(int ix, int iy)
00093     {
00094       int add;
00095       int layer=0;
00096       if(iy <= xsize){//endcap+z
00097         add = 15;
00098         layer = ix/ysize;
00099         layer = layer+add+1;
00100       }
00101       if(iy > xsize && iy< 3*xsize){//barrel
00102         add=30;
00103         if(ix < 2*ysize){
00104           layer=1;
00105         }else {
00106           layer = ix/(2*ysize);
00107           if(iy < 2*xsize)layer=layer*2+1; else layer=layer*2;
00108         }
00109         layer = layer+add;
00110       }
00111       if(iy >= 3*xsize){        //endcap-z
00112         layer = ix/ysize;
00113         layer = 15-layer;
00114       }
00115       return layer;  
00116     }
00117 
00118   int getlayerCount(int subdet, int partdet){
00119     int ncomponent=0;
00120     if(subdet == 1){ //1=pixel
00121       if(partdet == 1 || partdet == 3){ //1-3=encap
00122         ncomponent = 3;
00123       }
00124       else { ncomponent = 3; } //barrel
00125     }
00126     if(subdet== 2){ //2=inner silicon
00127       if(partdet == 1 || partdet == 3){ //1-3=encap
00128         ncomponent = 3;
00129       }
00130       else { ncomponent = 4; } //barrel
00131     }
00132     if(subdet== 3){ //3=outer silicon
00133       if(partdet == 1 || partdet == 3){ //1-3=encap
00134         ncomponent = 9;
00135       }
00136       else { ncomponent = 6; } //barrel
00137     }
00138     return(ncomponent);
00139   }   
00140   double  xdpixel(double x){
00141     double res;
00142     if(saveAsSingleLayer)res= ((x-xmin)/(xmax-xmin)*xsize);
00143     else res= ((x-xmin)/(xmax-xmin)*xsize)+ix;
00144     return res;
00145   }
00146   double  ydpixel(double y){
00147     double res;
00148     double y1;
00149     y1 = (y-ymin)/(ymax-ymin);
00150     if(nlay>30)   res= 2*ysize - (y1*2*ysize);
00151     else res= ysize - (y1*ysize);
00152     if(!saveAsSingleLayer) res=res+iy;
00153     return res;
00154   }
00155   double  xdpixelc(double x){
00156     double res;
00157     if(saveAsSingleLayer)res= ((x-xmin)/(xmax-xmin)*xsize);
00158     else res= ((x-xmin)/(xmax-xmin)*xsize)+ix;
00159     return res;
00160   }
00161   double  ydpixelc(double y){
00162     double res;
00163     double y1;
00164     y1 = (y-ymin)/(ymax-ymin);
00165      if(saveAsSingleLayer)res= 2*ysize - (y1*2*ysize);
00166      else res= 2*ysize - (y1*2*ysize)+iy;
00167     return res;
00168   }
00169    void defcwindow(int num_crate){
00170     ncrate = num_crate;
00171     int xoffset=xsize/3;
00172     int yoffset=ysize;
00173     xmin=-1.;xmax=63.;  ymin = -1.; ymax=37.;
00174     if((ncrate%3)==2)ix = xoffset+xsize*4/3;
00175     if((ncrate%3)==1)ix = xoffset+2*xsize*4/3;
00176     if((ncrate%3)==0)ix = xoffset;
00177     iy = yoffset+((ncrate-1)/3)*ysize*2;
00178   } 
00179 void defwindow(int num_lay){
00180   nlay = num_lay;
00181   if(posrel){ // separated modules
00182     xmin=-2.;ymin=-2.;xmax=2.;ymax=2.;
00183     if(nlay >12 && nlay < 19){
00184       xmin=-.40;xmax=.40;ymin=-.40;ymax=.40;
00185     }
00186     if(nlay>30){
00187       xmin=-0.1;xmax=3.;ymin=-0.1;ymax=8.5;
00188       if(nlay<34){xmin=-0.3;xmax=1.0;}
00189       if(nlay>33&&nlay<38){xmax=2.0;}
00190       if(nlay>37){ymax=8.;}//inner
00191     }
00192   }else{ //overlayed modules
00193     xmin=-1.3;ymin=-1.3;xmax=1.3;ymax=1.3;
00194     if(nlay >12 && nlay < 19){
00195       xmin=-.20;xmax=.20;ymin=-.20;ymax=.20;
00196     }
00197     if(nlay>30){
00198       xmin=-1.5;xmax=1.5;ymin=-1.;ymax=28.;
00199       if(nlay<34){xmin=-0.5;xmax=0.5;}
00200       if(nlay>33&&nlay<38){xmin=-1.;xmax=1.;}
00201     }
00202     
00203   }
00204   if(nlay<16){
00205       ix=0;iy=(15-nlay)*ysize;}
00206   if(nlay>15&&nlay<31){
00207     ix=3*xsize;iy=(nlay-16)*ysize;}
00208   if(nlay>30){
00209     if(nlay==31){ix=(int)(1.5*xsize);iy=0;}
00210     if(nlay>31 && nlay%2==0){int il=(nlay-30)/2;ix=xsize;iy=il*2*ysize;}
00211     if(nlay>31 && nlay%2!=0){int il=(nlay-30)/2;ix=2*xsize;iy=il*2*ysize;}
00212   }
00213  }
00214   
00215   int getringCount(int subdet, int partdet, int layer){
00216     int ncomponent=0;
00217     if(subdet== 1){ //1=pixel
00218       if(partdet== 1 || partdet== 3){ //end-cap
00219         ncomponent = 7;
00220       }
00221       else{ncomponent = 8;} //barrel
00222     }   
00223     if(subdet== 2){ //inner-silicon
00224       if(partdet== 1 || partdet== 3){ //end-cap
00225         ncomponent = 3;
00226       }
00227       else{ncomponent = 12;} //barrel
00228     }
00229     if(subdet== 3){ //outer-silicon
00230       if(partdet== 1){ //end-cap-z
00231         if (layer== 1) ncomponent = 4;
00232         if (layer== 2 || layer== 3) ncomponent = 5;
00233         if (layer== 4 || layer== 5 || layer== 6) ncomponent = 6;
00234         if (layer== 7 || layer== 8 || layer== 9) ncomponent = 7;
00235       }
00236       if(partdet== 3){ //endcap+z
00237         if (layer== 9) ncomponent = 4;
00238         if (layer== 8 || layer== 7) ncomponent = 5;
00239         if (layer== 6 || layer== 5 || layer== 4) ncomponent = 6;
00240         if (layer== 3 || layer== 2 || layer== 1) ncomponent = 7;
00241       }
00242       if(partdet== 2){ //barrel
00243         ncomponent = 12;
00244       }
00245     }
00246     return(ncomponent);
00247   }
00248   int getmoduleCount(int subdet, int partdet, int layer, int ring){
00249     int ncomponent=0;
00250     int spicchif[] ={24,24,40,56,40,56,80};
00251     int spicchib[] ={20,32,44,30,38,46,56,42,48,54,60,66,74};
00252     int numero_layer = 0;
00253     
00254     if(partdet == 2){ //barrel
00255       numero_layer = layer-1;
00256       if(subdet== 2){ //inner
00257         numero_layer = numero_layer+3;
00258       }
00259       if(subdet == 3){ //outer
00260         numero_layer = numero_layer+7;
00261       }
00262       ncomponent = spicchib[numero_layer];
00263     }
00264     if(partdet!= 2){ //endcap
00265       if(subdet== 1)ncomponent=24;//pixel
00266       else
00267         ncomponent = spicchif[ring-1];
00268     }
00269     return(ncomponent);
00270   }
00271   static int layerno(int subdet,int leftright,int layer){
00272     if(subdet==6&&leftright==1)return(10-layer);
00273     if(subdet==6&&leftright==2)return(layer+21);
00274     if(subdet==4&&leftright==1)return(4-layer+9);
00275     if(subdet==4&&leftright==2)return(layer+18);
00276     if(subdet==2&&leftright==1)return(4-layer+12);
00277     if(subdet==2&&leftright==2)return(layer+15);
00278     if(subdet==1)return(layer+30);
00279     if(subdet==3)return(layer+33);
00280     if(subdet==5)return(layer+37);
00281   }
00282   
00283   static bool isRingStereo(int key){
00284     int layer=key/100000;
00285     int ring = key - layer*100000;
00286     ring = ring/1000;
00287     if(layer==34 || layer==35 || layer==38 || layer==39) return true;
00288     if(layer<13 || (layer>18&&layer<31))
00289       if(ring==1 || ring==2 || ring==5)return true;
00290     return false;
00291   }
00292   int nlayer(int det,int part,int lay){
00293     if(det==3 && part==1) return lay;
00294     if(det==2 && part==1) return lay+9;
00295     if(det==1 && part==1) return lay+12;
00296     if(det==1 && part==3) return lay+15;
00297     if(det==2 && part==3) return lay+18;
00298     if(det==3 && part==3) return lay+21;
00299     if(det==1 && part==2) return lay+30;
00300     if(det==2 && part==2) return lay+33;
00301     if(det==3 && part==2) return lay+37;
00302     return -1; 
00303   }
00304   
00305   string layername(int layer){
00306     string s= " ";
00307     ostringstream ons;
00308     
00309     if(layer < 10) ons << "TEC -z Layer " << layer;
00310     if(layer < 13 && layer > 9) ons << "TID -z Layer " << layer-9;
00311     if(layer < 16 && layer > 12) ons << "FPIX -z Layer " << layer-12;
00312     if(layer < 19 && layer > 15) ons << "FPIX +z Layer " << layer-15;
00313     if(layer < 22 && layer > 18) ons << "TID +z Layer " << layer-18;
00314     if(layer < 31 && layer > 21) ons << "TEC +z Layer " << layer-21;
00315     if(layer < 34 && layer > 30) ons << "TPB Layer " << layer-30;
00316     if(layer < 38 && layer > 33) ons << "TIB Layer " << layer-33;
00317     if(layer > 37) ons << "TOB Layer " << layer-37;
00318     s = ons.str(); 
00319     return s;  
00320   }
00321   int ntotRing[43];
00322   int firstRing[43];
00323   
00324  protected:
00325   int nlay;
00326   int ncrate;
00327   int ncrates;
00328   double xmin,xmax,ymin,ymax;
00329   int xsize,ysize,ix,iy;
00330   bool posrel;
00331   bool firstcall;
00332   std::ofstream * svgfile;
00333   std::ofstream * savefile;
00334   std::ifstream * jsfile;
00335   float minvalue,maxvalue;
00336   int number_modules;
00337   bool temporary_file; 
00338   
00339  private:
00340   
00341   float oldz;
00342   bool saveAsSingleLayer;
00343 };
00344 #endif
00345 

Generated on Tue Jun 9 17:26:03 2009 for CMSSW by  doxygen 1.5.4