Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:35:20

0001 #ifndef _CommonTools_TrackerMap_TrackerMap_h_
0002 #define _CommonTools_TrackerMap_TrackerMap_h_
0003 #include <utility>
0004 #include <string>
0005 #include <iostream>
0006 #include <fstream>
0007 #include <sstream>
0008 #include <cmath>
0009 #include <map>
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
0012 #include "TColor.h"
0013 #include <cassert>
0014 #include <vector>
0015 #include "TPolyLine.h"
0016 
0017 class TH1F;
0018 class TLegend;
0019 /*
0020 #define  NUMFEDCH_INCOLUMN 12
0021 #define  NUMFEDCH_INROW 8
0022 #define  NUMFED_INCOLUMN 6
0023 #define  NUMFED_INROW 4
0024 #define  NUMFEDCRATE_INCOLUMN 3
0025 #define  XFEDCSIZE  340
0026 #define  YFEDCSIZE  400
0027 */
0028 
0029 /*
0030 #define  NUMFEDCH_INCOLUMN 12
0031 #define  NUMFEDCH_INROW 8
0032 #define  NUMFED_INCOLUMN 1
0033 #define  NUMFED_INROW 21
0034 //#define  NUMFEDCRATE_INCOLUMN 11
0035 //#define  NUMFEDCRATE_INROW 3
0036 #define  NUMFEDCRATE_INCOLUMN 16
0037 #define  NUMFEDCRATE_INROW 2
0038 //#define  XFEDCSIZE  160  // 14 boxes
0039 //#define  YFEDCSIZE  2100 // 9*21 boxes
0040 #define  XFEDCSIZE  140  // 14 boxes
0041 #define  YFEDCSIZE  1890 // 9*21 boxes
0042 */
0043 
0044 #define NUMPSUCH_INROW 18
0045 #define NUMPSUCRATE_INCOLUMN 5
0046 #define NUMPSURACK_INCOLUMN 6
0047 #define NUMPSURACK_INROW 5
0048 #define XPSURSIZE 150  // (5)*1.5 boxes
0049 #define YPSURSIZE 360  // 18 boxes
0050 #define XPSUOFFSET 50
0051 #define YPSUOFFSET 100
0052 
0053 #define NUMFEDCH_INCOLUMN 12
0054 #define NUMFEDCH_INROW 8
0055 #define NUMFED_INCOLUMN 21
0056 #define NUMFED_INROW 1
0057 //#define  NUMFEDCRATE_INCOLUMN 11
0058 //#define  NUMFEDCRATE_INROW 3
0059 #define NUMFEDCRATE_INCOLUMN 1
0060 #define NUMFEDCRATE_INROW 31
0061 //#define  XFEDCSIZE  160  // 14 boxes
0062 //#define  YFEDCSIZE  2100 // 9*21 boxes
0063 #define XFEDCSIZE 2940  // 14*21 boxes
0064 #define YFEDCSIZE 90    // 9 boxes
0065 #define XFEDOFFSET 150
0066 #define YFEDOFFSET 100
0067 
0068 class TmModule;
0069 class TmApvPair;
0070 class EventSetup;
0071 class TmCcu;
0072 class TmPsu;
0073 class TrackerTopology;
0074 
0075 class TrackerMap {
0076 public:
0077   //TrackerMap(){TrackerMap(" ");};   //!< default constructor
0078   TrackerMap(std::string s = " ", int xsize1 = 340, int ysize1 = 200);
0079   TrackerMap(const edm::ParameterSet& iConfig);
0080   TrackerMap(const edm::ParameterSet& iConfig, const SiStripFedCabling* tkFed, const TrackerTopology* const topology);
0081   ~TrackerMap();  //!< default destructor
0082 
0083   void build();
0084   void init();
0085   void drawModule(TmModule* mod, int key, int layer, bool total, std::ofstream* file);
0086   void print(bool print_total = true, float minval = 0., float maxval = 0., std::string s = "svgmap");
0087   void printall(bool print_total = true,
0088                 float minval = 0.,
0089                 float maxval = 0.,
0090                 std::string s = "svgmap",
0091                 int width = 6000,
0092                 int height = 3200);
0093   void printonline();
0094   void printlayers(bool print_total = true, float minval = 0., float maxval = 0., std::string s = "layer");
0095   void save(bool print_total = true,
0096             float minval = 0.,
0097             float maxval = 0.,
0098             std::string s = "svgmap.svg",
0099             int width = 1500,
0100             int height = 800);
0101   void save_as_fedtrackermap(bool print_total = true,
0102                              float minval = 0.,
0103                              float maxval = 0.,
0104                              std::string s = "fed_svgmap.svg",
0105                              int width = YFEDOFFSET + (YFEDCSIZE + YFEDOFFSET) * NUMFEDCRATE_INROW + 300,
0106                              int height = XFEDOFFSET + (XFEDCSIZE + XFEDOFFSET) * NUMFEDCRATE_INCOLUMN + 300);
0107   void save_as_fectrackermap(bool print_total = true,
0108                              float minval = 0.,
0109                              float maxval = 0.,
0110                              std::string s = "fec_svgmap.svg",
0111                              int width = 1500,
0112                              int height = 800);
0113   void save_as_psutrackermap(bool print_total = true,
0114                              float minval = 0.,
0115                              float maxval = 0.,
0116                              std::string s = "psu_svgmap.svg",
0117                              int width = YPSUOFFSET + (YPSURSIZE + YPSUOFFSET) * NUMPSURACK_INROW + 300,
0118                              int height = XPSUOFFSET + (XPSURSIZE + XPSUOFFSET) * NUMPSURACK_INCOLUMN + 300);
0119   void save_as_HVtrackermap(bool print_total = true,
0120                             float minval = 0.,
0121                             float maxval = 0.,
0122                             std::string s = "psu_svgmap.svg",
0123                             int width = 1500,
0124                             int height = 800);
0125   void drawApvPair(
0126       int crate, int numfed_incrate, bool total, TmApvPair* apvPair, std::ofstream* file, bool useApvPairValue);
0127   void drawCcu(int crate, int numfed_incrate, bool total, TmCcu* ccu, std::ofstream* file, bool useCcuValue);
0128   void drawPsu(int rack, int numcrate_inrack, bool print_total, TmPsu* psu, std::ofstream* svgfile, bool usePsuValue);
0129   void drawHV2(int rack, int numcrate_inrack, bool print_total, TmPsu* psu, std::ofstream* svgfile, bool usePsuValue);
0130   void drawHV3(int rack, int numcrate_inrack, bool print_total, TmPsu* psu, std::ofstream* svgfile, bool usePsuValue);
0131   void fill_current_val(int idmod, float current_val);
0132   void fill(int layer, int ring, int nmod, float x);
0133   void fill(int idmod, float qty);
0134   void fillc(int idmod, int RGBcode) { fillc(idmod, (RGBcode >> 16) & 0xFF, (RGBcode >> 8) & 0xFF, RGBcode & 0xFF); }
0135   void fillc(int idmod, int red, int green, int blue);
0136   void fillc(int layer, int ring, int nmod, int red, int green, int blue);
0137   void fillc_all_blank();
0138   void fill_all_blank();
0139   void fill_current_val_fed_channel(int fedId, int fedCh, float current_val);
0140   void fill_fed_channel(int fedId, int fedCh, float qty);
0141   void fill_fed_channel(int modId, float qty);
0142   void fillc_fed_channel(int fedId, int fedCh, int red, int green, int blue);
0143   void fillc_fec_channel(int crate, int slot, int ring, int addr, int red, int green, int blue);
0144   void fill_fec_channel(int crate, int slot, int ring, int addr, float qty);
0145   void fill_lv_channel(int rack, int crate, int board, float qty);
0146   void fillc_lv_channel(int rack, int crate, int board, int red, int green, int blue);
0147   void fill_hv_channel2(int rack, int crate, int board, float qty);
0148   void fillc_hv_channel2(int rack, int crate, int board, int red, int green, int blue);
0149   void fill_hv_channel3(int rack, int crate, int board, float qty);
0150   void fillc_hv_channel3(int rack, int crate, int board, int red, int green, int blue);
0151   int module(int fedId, int fedCh);
0152   void setText(int idmod, std::string s);
0153   void setText(int layer, int ring, int nmod, std::string s);
0154   void setPalette(int numpalette) { palette = numpalette; }
0155   void drawPalette(std::ofstream* file, int xoffset = 3660, int yoffset = 1540);
0156   void showPalette(bool printflag1) { printflag = printflag1; };
0157   void setTitle(std::string s) { title = s; };
0158   void setRange(float min, float max);
0159   std::pair<float, float> getAutomaticRange();
0160   void addPixel(bool addPixelfl) { addPixelFlag = addPixelfl; };
0161   void onlyPixel(bool onlyPixelfl) { onlyPixelFlag = onlyPixelfl; };
0162   void reset();
0163   void load(std::string s = "tmap.svg");
0164   int getxsize() { return xsize; };
0165   int getysize() { return ysize; };
0166   int getcolor(float value, int palette);
0167   std::ifstream* findfile(std::string filename);
0168   int getNumMod() { return number_modules; };
0169   std::vector<TColor*> vc;
0170   typedef std::map<const int, TmModule*> SmoduleMap;
0171   SmoduleMap smoduleMap;
0172   typedef std::map<const int, TmModule*> ImoduleMap;
0173   ImoduleMap imoduleMap;
0174   typedef std::map<const int, TmApvPair*> SvgApvPair;
0175   SvgApvPair apvMap;
0176   typedef std::multimap<const int, TmApvPair*> ModApvPair;
0177   ModApvPair apvModuleMap;
0178   typedef std::map<const int, int> SvgFed;
0179   SvgFed fedMap;
0180   SvgFed slotMap;
0181   typedef std::map<const int, TmCcu*> MapCcu;
0182   MapCcu ccuMap;
0183   typedef std::multimap<TmCcu*, TmModule*> FecModule;
0184   FecModule fecModuleMap;
0185   typedef std::map<const int, TmPsu*> MapPsu;
0186   MapPsu psuMap;
0187   typedef std::multimap<TmPsu*, TmModule*> PsuModule;
0188   PsuModule psuModuleMap;
0189   int palette;
0190   bool printflag;
0191   bool saveWebInterface;
0192   bool saveGeoTrackerMap;
0193   bool enableFedProcessing;
0194   bool enableFecProcessing;
0195   bool enableLVProcessing;
0196   bool enableHVProcessing;
0197   bool tkMapLog;
0198   std::string title;
0199   std::string jsfilename, infilename;
0200   std::string jsPath;
0201   bool psetAvailable;
0202 
0203   double phival(double x, double y) {
0204     double phi;
0205     if (fabs(x) >= 0.000001 && fabs(y) >= 0.000001) {
0206       phi = atan(y / x);
0207       if (y < 0. && x > 0)
0208         phi += 2. * M_PI;
0209       else if (x < 0.)
0210         phi += M_PI;
0211     } else if (fabs(y) < 0.000001)
0212       phi = x > 0 ? 0 : M_PI;
0213     else  // if (fabs(x) < 0.000001)
0214       phi = y > 0 ? M_PI / 2. : 3. * M_PI / 2.;
0215     return phi;
0216   }
0217 
0218   int find_layer(int ix, int iy) {
0219     int layer = 0;
0220     if (iy <= xsize) {  //endcap+z
0221       const int add = 15;
0222       layer = ix / ysize;
0223       layer = layer + add + 1;
0224     } else if (iy < 3 * xsize) {  //barrel
0225       const int add = 30;
0226       if (ix < 2 * ysize) {
0227         layer = 1;
0228       } else {
0229         layer = ix / (2 * ysize);
0230         if (iy < 2 * xsize)
0231           layer = layer * 2 + 1;
0232         else
0233           layer = layer * 2;
0234       }
0235       layer = layer + add;
0236     } else if (iy >= 3 * xsize) {  //endcap-z
0237       layer = ix / ysize;
0238       layer = 15 - layer;
0239     }
0240     return layer;
0241   }
0242 
0243   int getlayerCount(int subdet, int partdet) {
0244     int ncomponent = 0;
0245     if (subdet == 1) {                     //1=pixel
0246       if (partdet == 1 || partdet == 3) {  //1-3=encap
0247         ncomponent = 3;
0248       } else {
0249         ncomponent = 3;
0250       }  //barrel
0251     }
0252     if (subdet == 2) {                     //2=inner silicon
0253       if (partdet == 1 || partdet == 3) {  //1-3=encap
0254         ncomponent = 3;
0255       } else {
0256         ncomponent = 4;
0257       }  //barrel
0258     }
0259     if (subdet == 3) {                     //3=outer silicon
0260       if (partdet == 1 || partdet == 3) {  //1-3=encap
0261         ncomponent = 9;
0262       } else {
0263         ncomponent = 6;
0264       }  //barrel
0265     }
0266     return (ncomponent);
0267   }
0268 
0269   double xdpixel(double x) {
0270     double res;
0271     if (saveAsSingleLayer)
0272       res = ((x - xmin) / (xmax - xmin) * xsize);
0273     else
0274       res = ((x - xmin) / (xmax - xmin) * xsize) + ix;
0275     return res;
0276   }
0277   double ydpixel(double y) {
0278     double res = 0;
0279     double y1;
0280     y1 = (y - ymin) / (ymax - ymin);
0281     if (nlay > 30) {
0282       if (nlay < 34)
0283         res = 2 * ysize - (y1 * 2 * ysize);
0284       if (nlay == 34)
0285         res = 2.4 * ysize - (y1 * 2.4 * ysize);
0286       if (nlay > 34)
0287         res = 2.5 * ysize - (y1 * 2.5 * ysize);
0288     } else
0289       res = xsize - (y1 * xsize);
0290     if (!saveAsSingleLayer)
0291       res = res + iy;
0292     return res;
0293   }
0294   double xdpixelc(double x) {
0295     double res;
0296     if (saveAsSingleLayer)
0297       res = ((x - xmin) / (xmax - xmin) * XFEDCSIZE);
0298     else
0299       res = ((x - xmin) / (xmax - xmin) * XFEDCSIZE) + ix;
0300     return res;
0301   }
0302   double ydpixelc(double y) {
0303     double res;
0304     double y1;
0305     y1 = (y - ymin) / (ymax - ymin);
0306     if (saveAsSingleLayer)
0307       res = YFEDCSIZE - (y1 * YFEDCSIZE);
0308     else
0309       res = YFEDCSIZE - (y1 * YFEDCSIZE) + iy;
0310     return res;
0311   }
0312   double xdpixelfec(double x) {
0313     double res;
0314     if (saveAsSingleLayer)
0315       res = ((x - xmin) / (xmax - xmin) * xsize);
0316     else
0317       res = ((x - xmin) / (xmax - xmin) * xsize) + ix;
0318     return res;
0319   }
0320   double ydpixelfec(double y) {
0321     double res;
0322     double y1;
0323     y1 = (y - ymin) / (ymax - ymin);
0324     if (saveAsSingleLayer)
0325       res = 2 * ysize - (y1 * 2 * ysize);
0326     else
0327       res = 2 * ysize - (y1 * 2 * ysize) + iy;
0328     return res;
0329   }
0330   double xdpixelpsu(double x) {
0331     double res;
0332     if (saveAsSingleLayer)
0333       res = ((x - xmin) / (xmax - xmin) * XPSURSIZE);
0334     else
0335       res = ((x - xmin) / (xmax - xmin) * XPSURSIZE) + ix;
0336     return res;
0337   }
0338   double ydpixelpsu(double y) {
0339     double res;
0340     double y1;
0341     y1 = (y - ymin) / (ymax - ymin);
0342     if (saveAsSingleLayer)
0343       res = YPSURSIZE - (y1 * YPSURSIZE);
0344     else
0345       res = YPSURSIZE - (y1 * YPSURSIZE) + iy;
0346     return res;
0347   }
0348 
0349   void defcwindow(int num_crate) {
0350     //    ncrate = num_crate;
0351     int xoffset = XFEDOFFSET;
0352     int yoffset = YFEDOFFSET;
0353     xmin = 0.;
0354     xmax = (NUMFEDCH_INCOLUMN + 2) * NUMFED_INCOLUMN;
0355     ymin = 0.;
0356     ymax = (NUMFEDCH_INROW + 1) * NUMFED_INROW;
0357 
0358     ix = xoffset + ((NUMFEDCRATE_INCOLUMN - 1) - ((num_crate - 1) % NUMFEDCRATE_INCOLUMN)) * (XFEDCSIZE + XFEDOFFSET);
0359     iy = yoffset + ((num_crate - 1) / NUMFEDCRATE_INCOLUMN) * (YFEDCSIZE + YFEDOFFSET);
0360   }
0361   void deffecwindow(int num_crate) {
0362     //    ncrate = num_crate;
0363     int xoffset = xsize / 3;
0364     int yoffset = 2 * ysize;
0365     xmin = -1.;
0366     xmax = 37.;
0367     ymin = -10.;
0368     ymax = 40.;
0369     if (num_crate == 1 || num_crate == 3)
0370       ix = xoffset + xsize * 2;
0371     if (num_crate == 2 || num_crate == 4)
0372       ix = xoffset;
0373     iy = yoffset + ((num_crate - 1) / 2) * ysize * 4;
0374   }
0375   void defpsuwindow(int num_rack) {
0376     //    nrack = num_rack;
0377     int xoffset = XPSUOFFSET;
0378     int yoffset = YPSUOFFSET;
0379     xmin = 0;
0380     xmax = (NUMPSUCRATE_INCOLUMN) * 1.5;
0381     ymin = 0;
0382     ymax = NUMPSUCH_INROW;
0383 
0384     ix = xoffset + ((NUMPSURACK_INCOLUMN - 1) - ((num_rack - 1) % NUMPSURACK_INCOLUMN)) * (XPSURSIZE + XPSUOFFSET);
0385     iy = yoffset + ((num_rack - 1) / NUMPSURACK_INCOLUMN) * (YPSURSIZE + YPSUOFFSET);
0386   }
0387 
0388   void defwindow(int num_lay) {
0389     // nlay = num_lay;
0390     if (posrel) {  // separated modules
0391       xmin = -2.;
0392       ymin = -2.;
0393       xmax = 2.;
0394       ymax = 2.;
0395       if (num_lay > 12 && num_lay < 19) {
0396         xmin = -.40;
0397         xmax = .40;
0398         ymin = -.40;
0399         ymax = .40;
0400       }
0401       if (num_lay > 30) {
0402         xmin = -0.1;
0403         xmax = 3.;
0404         ymin = -0.1;
0405         ymax = 8.5;
0406         if (num_lay < 34) {
0407           xmin = -0.3;
0408           xmax = 1.0;
0409         }
0410         if (num_lay > 33 && num_lay < 38) {
0411           xmax = 2.0;
0412         }
0413         if (num_lay > 37) {
0414           ymax = 8.;
0415         }  //inner
0416       }
0417     } else {  //overlayed modules
0418       xmin = -1.3;
0419       ymin = -1.3;
0420       xmax = 1.3;
0421       ymax = 1.3;
0422       if (num_lay > 12 && num_lay < 19) {
0423         xmin = -.20;
0424         xmax = .20;
0425         ymin = -.20;
0426         ymax = .20;
0427       }
0428       if (num_lay > 30) {
0429         xmin = -1.5;
0430         xmax = 1.5;
0431         ymin = -1.;
0432         ymax = 28.;
0433         if (num_lay < 34) {
0434           xmin = -0.5;
0435           xmax = 0.5;
0436         }
0437         if (num_lay > 33 && num_lay < 38) {
0438           xmin = -1.;
0439           xmax = 1.;
0440         }
0441       }
0442     }
0443     if (num_lay < 16) {
0444       ix = 0;
0445       if (num_lay == 15 || num_lay == 14)
0446         iy = (15 - num_lay) * 2 * ysize;
0447       else {
0448         if (num_lay > 9 && num_lay < 13)
0449           iy = 4 * ysize - (int)(ysize / 2.) + (12 - num_lay) * (int)(ysize / 1.50);
0450         else
0451           iy = 6 * ysize + (9 - num_lay) * (int)(ysize * 1.3);
0452       }
0453     }
0454     if (num_lay > 15 && num_lay < 31) {
0455       ix = 3 * xsize;
0456       if (num_lay == 16 || num_lay == 17)
0457         iy = (num_lay - 16) * 2 * ysize;
0458       else {
0459         if (num_lay > 18 && num_lay < 22)
0460           iy = 4 * ysize - (int)(ysize / 2.) + (num_lay - 19) * (int)(ysize / 1.50);
0461         else
0462           iy = 6 * ysize + (num_lay - 22) * (int)(ysize * 1.3);
0463       }
0464     }
0465     if (num_lay > 30) {
0466       if (num_lay == 31) {
0467         ix = (int)(1.5 * xsize);
0468         iy = 0;
0469       }
0470       if (num_lay == 32) {
0471         int il = (num_lay - 30) / 2;
0472         ix = xsize;
0473         iy = il * 2 * ysize;
0474       }
0475       if (num_lay == 33) {
0476         int il = (num_lay - 30) / 2;
0477         ix = 2 * xsize;
0478         iy = il * 2 * ysize;
0479       }
0480       if (num_lay == 34) {
0481         int il = (num_lay - 30) / 2;
0482         ix = xsize;
0483         iy = il * (int)(2.57 * ysize);
0484       }
0485       if (num_lay > 34 && num_lay % 2 == 0) {
0486         int il = (num_lay - 30) / 2;
0487         ix = xsize;
0488         iy = il * (int)(2.5 * ysize);
0489       }
0490       if (num_lay > 34 && num_lay % 2 != 0) {
0491         int il = (num_lay - 30) / 2;
0492         ix = 2 * xsize;
0493         iy = il * (int)(2.5 * ysize);
0494       }
0495     }
0496   }
0497 
0498   int getringCount(int subdet, int partdet, int layer) {
0499     int ncomponent = 0;
0500     if (subdet == 1) {                   //1=pixel
0501       if (partdet == 1 || partdet == 3)  //end-cap
0502         ncomponent = 7;
0503       else  //barrel
0504         ncomponent = 8;
0505     } else if (subdet == 2) {            //inner-silicon
0506       if (partdet == 1 || partdet == 3)  //end-cap
0507         ncomponent = 3;
0508       else  //barrel
0509         ncomponent = 12;
0510     } else if (subdet == 3) {  //outer-silicon
0511       if (partdet == 1) {      //end-cap-z
0512         if (layer == 1)
0513           ncomponent = 4;
0514         else if (layer == 2 || layer == 3)
0515           ncomponent = 5;
0516         else if (layer == 4 || layer == 5 || layer == 6)
0517           ncomponent = 6;
0518         else if (layer == 7 || layer == 8 || layer == 9)
0519           ncomponent = 7;
0520       } else if (partdet == 3) {  //endcap+z
0521         if (layer == 9)
0522           ncomponent = 4;
0523         else if (layer == 8 || layer == 7)
0524           ncomponent = 5;
0525         else if (layer == 6 || layer == 5 || layer == 4)
0526           ncomponent = 6;
0527         else if (layer == 3 || layer == 2 || layer == 1)
0528           ncomponent = 7;
0529       } else if (partdet == 2) {  //barrel
0530         ncomponent = 12;
0531       }
0532     }
0533     return (ncomponent);
0534   }
0535 
0536   int getmoduleCount(int subdet, int partdet, int layer, int ring) {
0537     int ncomponent = 0;
0538     int spicchif[] = {24, 24, 40, 56, 40, 56, 80};
0539     int spicchib[] = {20, 32, 44, 30, 38, 46, 56, 42, 48, 54, 60, 66, 74};
0540     int numero_layer = 0;
0541 
0542     if (partdet == 2) {  //barrel
0543       numero_layer = layer - 1;
0544       if (subdet == 2) {  //inner
0545         numero_layer = numero_layer + 3;
0546       }
0547       if (subdet == 3) {  //outer
0548         numero_layer = numero_layer + 7;
0549       }
0550       ncomponent = spicchib[numero_layer];
0551     }
0552     if (partdet != 2) {  //endcap
0553       if (subdet == 1)
0554         ncomponent = 24;  //pixel
0555       else
0556         ncomponent = spicchif[ring - 1];
0557     }
0558     return (ncomponent);
0559   }
0560 
0561   static int layerno(int subdet, int leftright, int layer) {
0562     if (subdet == 6 && leftright == 1)
0563       return (10 - layer);
0564     if (subdet == 6 && leftright == 2)
0565       return (layer + 21);
0566     if (subdet == 4 && leftright == 1)
0567       return (4 - layer + 9);
0568     if (subdet == 4 && leftright == 2)
0569       return (layer + 18);
0570     if (subdet == 2 && leftright == 1)
0571       return (4 - layer + 12);
0572     if (subdet == 2 && leftright == 2)
0573       return (layer + 15);
0574     if (subdet == 1)
0575       return (layer + 30);
0576     if (subdet == 3)
0577       return (layer + 33);
0578     if (subdet == 5)
0579       return (layer + 37);
0580     assert(false);
0581   }
0582 
0583   static bool isRingStereo(int key) {
0584     int layer = key / 100000;
0585     int ring = key - layer * 100000;
0586     ring = ring / 1000;
0587     if (layer == 34 || layer == 35 || layer == 38 || layer == 39)
0588       return true;
0589     if (layer < 13 || (layer > 18 && layer < 31))
0590       if (ring == 1 || ring == 2 || ring == 5)
0591         return true;
0592     return false;
0593   }
0594 
0595   int nlayer(int det, int part, int lay) {
0596     if (det == 3 && part == 1)
0597       return lay;
0598     if (det == 2 && part == 1)
0599       return lay + 9;
0600     if (det == 1 && part == 1)
0601       return lay + 12;
0602     if (det == 1 && part == 3)
0603       return lay + 15;
0604     if (det == 2 && part == 3)
0605       return lay + 18;
0606     if (det == 3 && part == 3)
0607       return lay + 21;
0608     if (det == 1 && part == 2)
0609       return lay + 30;
0610     if (det == 2 && part == 2)
0611       return lay + 33;
0612     if (det == 3 && part == 2)
0613       return lay + 37;
0614     std::cout
0615         << "Error in TrackerMap: this can never happen as det and part are comprised between 1 and 3, while they are "
0616         << det << " and " << part << " respectively" << std::endl;
0617     return lay;
0618   }
0619 
0620   std::string layername(int layer) {
0621     std::string s = " ";
0622     std::ostringstream ons;
0623 
0624     if (layer < 10)
0625       ons << "TEC -z Layer " << layer;
0626     if (layer < 13 && layer > 9)
0627       ons << "TID -z Layer " << layer - 9;
0628     if (layer < 16 && layer > 12)
0629       ons << "FPIX -z Layer " << layer - 12;
0630     if (layer < 19 && layer > 15)
0631       ons << "FPIX +z Layer " << layer - 15;
0632     if (layer < 22 && layer > 18)
0633       ons << "TID +z Layer " << layer - 18;
0634     if (layer < 31 && layer > 21)
0635       ons << "TEC +z Layer " << layer - 21;
0636     if (layer < 34 && layer > 30)
0637       ons << "TPB Layer " << layer - 30;
0638     if (layer < 38 && layer > 33)
0639       ons << "TIB Layer " << layer - 33;
0640     if (layer > 37)
0641       ons << "TOB Layer " << layer - 37;
0642     s = ons.str();
0643     return s;
0644   }
0645 
0646   int ntotRing[43];
0647   int firstRing[43];
0648 
0649 protected:
0650   int nlay;
0651   //  int ncrate;
0652   //  int nrack;
0653   int ncrates;
0654   int firstcrate;
0655   int nfeccrates;
0656   int npsuracks;
0657   double xmin, xmax, ymin, ymax;
0658   int xsize, ysize, ix, iy;
0659   bool posrel;
0660   bool firstcall;
0661   std::ofstream* svgfile;
0662   std::ofstream* savefile;
0663   std::ifstream* jsfile;
0664   std::ifstream* inputfile;
0665   std::ifstream* ccufile;
0666   float gminvalue, gmaxvalue;
0667   float minvalue, maxvalue;
0668   int number_modules;
0669   bool temporary_file;
0670 
0671 private:
0672   float oldz;
0673   bool saveAsSingleLayer;
0674   bool addPixelFlag;
0675   bool onlyPixelFlag;
0676   TLegend* buildLegend();
0677   std::vector<TPolyLine*> legInfos_;
0678   std::vector<std::string> legKeys_;
0679 };
0680 #endif