Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:07

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