CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/src/TEcnaNumbering.cc

Go to the documentation of this file.
00001 //----------Author's Name: B.Fabbro, F.X.Gentit + EB table from P.Jarry  DSM/IRFU/SPP CEA-Saclay
00002 //----------Copyright:Those valid for CEA software
00003 //----------Modified:30/06/2011
00004 
00005 #include "CalibCalorimetry/EcalCorrelatedNoiseAnalysisAlgos/interface/TEcnaNumbering.h"
00006 
00007 //--------------------------------------
00008 //  TEcnaNumbering.cc
00009 //  Class creation: 30 September 2005
00010 //  Documentation: see TEcnaNumbering.h
00011 //--------------------------------------
00012 
00013 ClassImp(TEcnaNumbering)
00014 //-------------------------------------------------------------------------------------------------------
00015 //
00016 //  Building of the numbering for the Ecal channels (EB and EE)
00017 //
00018 //  Convention for the names used here and in the other "TEcna" classes:
00019 //
00020 //  Name     Number                      Reference set   Range      Comment
00021 //
00022 //  SMTow  : Tower number                in SuperModule  [1,68]     (phi,eta) progression
00023 //  SMCrys : Crystal number              in SuperModule  [1,1700]   (phi,eta) progression
00024 //  SMEcha : Electronic channel number   in SuperModule  [0,1699]   S shape data reading order    
00025 //  TowEcha: Electronic channel number   in Tower        [0,24]     S shape data reading order  
00026 //
00027 //  DeeSC  : super-crystal(SC) number    in Dee          [1,200]    (IY,IX) progression
00028 //  DeeCrys: Crystal number              in Dee matrix   [1,5000]   (IY,IX) progression
00029 //  DeeEcha: Electronic channel number   in Dee matrix   [0,4999]   (IY,IX) progression (starting from 0)
00030 //  SCEcha : Electronic channel number   in SC           [1,25]     Crystal numbering for construction 
00031 //-------------------------------------------------------------------------------------------------------
00032 
00033 //====================================== constructors =========================================
00034 TEcnaNumbering::TEcnaNumbering() {
00035 // Constructor without argument: call to method Init()
00036 
00037 //  cout << "[Info Management] CLASS: TEcnaNumbering.    CREATE OBJECT: this = " << this << endl;
00038 
00039   Init();
00040 }
00041 
00042 TEcnaNumbering::TEcnaNumbering(TEcnaObject* pObjectManager, const TString& SubDet) {
00043 // Constructor with argument: call to methods Init() and SetEcalSubDetector(const TString&)
00044 
00045  // cout << "[Info Management] CLASS: TEcnaNumbering.    CREATE OBJECT: this = " << this << endl;
00046 
00047   Init();
00048   Long_t i_this = (Long_t)this;
00049   pObjectManager->RegisterPointer("TEcnaNumbering", i_this);
00050 
00051   //............................ fEcal  => to be changed in fParEcal
00052   fEcal = 0;
00053   Long_t iParEcal = pObjectManager->GetPointerValue("TEcnaParEcal");
00054   if( iParEcal == 0 )
00055     {fEcal = new TEcnaParEcal(pObjectManager, SubDet.Data()); /*fCnew++*/}
00056   else
00057     {fEcal = (TEcnaParEcal*)iParEcal;}
00058 
00059   SetEcalSubDetector(SubDet.Data());
00060 }
00061 
00062 
00063 TEcnaNumbering::TEcnaNumbering(const TString& SubDet, const TEcnaParEcal* pEcal) {
00064 // Constructor with argument: call to methods Init() and SetEcalSubDetector(const TString&)
00065 
00066  // cout << "[Info Management] CLASS: TEcnaNumbering.    CREATE OBJECT: this = " << this << endl;
00067 
00068   Init();
00069   SetEcalSubDetector(SubDet.Data(), pEcal);
00070 }
00071 
00072 //====================================== destructor =========================================
00073 TEcnaNumbering::~TEcnaNumbering() {
00074 //destructor
00075 
00076   //if (fEcal   != 0){delete fEcal;   fCdelete++;}
00077 
00078   //....................... Barrel
00079   if (fT2dSMCrys  != 0){delete [] fT2dSMCrys;  fCdelete++;}
00080   if (fT1dSMCrys  != 0){delete [] fT1dSMCrys;  fCdelete++;}
00081   if (fT1dSMTow   != 0){delete [] fT1dSMTow;   fCdelete++;}
00082   if (fT1dTowEcha != 0){delete [] fT1dTowEcha; fCdelete++;}
00083 
00084   //....................... Endcap
00085   if (fT3dDeeCrys     != 0){delete [] fT3dDeeCrys;     fCdelete++;}
00086   if (fT2dDeeCrys     != 0){delete [] fT2dDeeCrys;     fCdelete++;}
00087   if (fT1dDeeCrys     != 0){delete [] fT1dDeeCrys;     fCdelete++;}
00088   if (fT2dDeeSC       != 0){delete [] fT2dDeeSC;       fCdelete++;}
00089   if (fT1dDeeSC       != 0){delete [] fT1dDeeSC;       fCdelete++;}
00090   if (fT2dSCEcha      != 0){delete [] fT2dSCEcha;      fCdelete++;}
00091   if (fT1dSCEcha      != 0){delete [] fT1dSCEcha;      fCdelete++;}
00092   if (fT2d_jch_JY     != 0){delete [] fT2d_jch_JY;     fCdelete++;}
00093   if (fT1d_jch_JY     != 0){delete [] fT1d_jch_JY;     fCdelete++;}
00094   if (fT2d_ich_IX     != 0){delete [] fT2d_ich_IX;     fCdelete++;}
00095   if (fT1d_ich_IX     != 0){delete [] fT1d_ich_IX;     fCdelete++;}
00096   if (fT2d_DS         != 0){delete [] fT2d_DS;         fCdelete++;}
00097   if (fT1d_DS         != 0){delete [] fT1d_DS;         fCdelete++;}
00098   if (fT2d_DSSC       != 0){delete [] fT2d_DSSC;       fCdelete++;}
00099   if (fT1d_DSSC       != 0){delete [] fT1d_DSSC;       fCdelete++;}
00100   if (fT2d_DeeSCCons  != 0){delete [] fT2d_DeeSCCons;  fCdelete++;}
00101   if (fT1d_DeeSCCons  != 0){delete [] fT1d_DeeSCCons;  fCdelete++;}
00102   if (fT2d_RecovDeeSC != 0){delete [] fT2d_RecovDeeSC; fCdelete++;}
00103   if (fT1d_RecovDeeSC != 0){delete [] fT1d_RecovDeeSC; fCdelete++;}
00104 
00105  // cout << "[Info Management] CLASS: TEcnaNumbering.    DESTROY OBJECT: this = " << this << endl;
00106 
00107 }
00108 //------------------------------------------------------------- Init()
00109 void TEcnaNumbering::Init()
00110 {
00111 //Set default values and build crystal numbering table
00112 
00113   //.............................. Initialisations
00114   fTTBELL  = '\007';
00115   fgMaxCar = 512;
00116 
00117   //....................... Barrel
00118   fT2dSMCrys  = 0;
00119   fT1dSMCrys  = 0;
00120   fT1dSMTow   = 0;
00121   fT1dTowEcha = 0;
00122 
00123   fCodeChNumberingLvrbBot = "bottom";
00124   fCodeChNumberingLvrbTop = "top";
00125 
00126   //....................... Endcap
00127   fT3dDeeCrys     = 0;
00128   fT2dDeeCrys     = 0;
00129   fT1dDeeCrys     = 0;
00130   fT2dDeeSC       = 0;
00131   fT1dDeeSC       = 0;
00132   fT2dSCEcha      = 0;
00133   fT1dSCEcha      = 0;
00134   fT2d_jch_JY     = 0;
00135   fT1d_jch_JY     = 0;
00136   fT2d_ich_IX     = 0;
00137   fT1d_ich_IX     = 0;
00138   fT2d_DS         = 0;
00139   fT1d_DS         = 0;
00140   fT2d_DSSC       = 0;
00141   fT1d_DSSC       = 0;
00142   fT2d_DeeSCCons  = 0;
00143   fT1d_DeeSCCons  = 0;
00144   fT2d_RecovDeeSC = 0;
00145   fT1d_RecovDeeSC = 0;
00146 
00147   fCodeChNumberingITP1Bot = "bottom";   // ==> Type 1 Interface plate  IPT1 (a faire)
00148   fCodeChNumberingITP2Top = "top";      // ==> Type 2 Interface plate  IPT2 (a faire)
00149 
00150   //------------------ Init pointers on the CNA objects
00151   fEcal = 0;
00152 }
00153 // end of Init()
00154 //------------------------------------------------------------- SetEcalSubDetector(...)
00155 void TEcnaNumbering::SetEcalSubDetector(const TString& SubDet, const TEcnaParEcal* pEcal){
00156 //Set the current subdetector flag and the current subdetector parameters
00157 
00158   fEcal = 0;
00159   if( pEcal == 0 )
00160     {fEcal = new TEcnaParEcal(SubDet.Data());  /*fCnew++*/ ;}
00161   else
00162     {fEcal = (TEcnaParEcal*)pEcal;}
00163 
00164   Int_t MaxCar = fgMaxCar;
00165   fFlagSubDet.Resize(MaxCar);
00166   fFlagSubDet = fEcal->GetEcalSubDetector();      // fFlagSubDet = "EB" or "EE"
00167 
00168   if( fFlagSubDet == "EB" ){BuildBarrelCrysTable();}
00169   if( fFlagSubDet == "EE" ){BuildEndcapCrysTable(); BuildEndcapSCTable();}
00170 }
00171 
00172 void TEcnaNumbering::SetEcalSubDetector(const TString& SubDet){
00173 //Set the current subdetector flag and the current subdetector parameters
00174 
00175   Int_t MaxCar = fgMaxCar;
00176   fFlagSubDet.Resize(MaxCar);
00177   fFlagSubDet = fEcal->GetEcalSubDetector();      // fFlagSubDet = "EB" or "EE"
00178 
00179   if( fFlagSubDet == "EB" ){BuildBarrelCrysTable();}
00180   if( fFlagSubDet == "EE" ){BuildEndcapCrysTable(); BuildEndcapSCTable();}
00181 }
00182 
00183 //====================================================================================================
00184 //
00185 //
00186 //                                  B   A   R   R   E   L 
00187 //
00188 //
00189 //====================================================================================================
00190 //
00191 //               SMCrys <-> (SMTow, TowEcha) correspondance table (from Patrick Jarry)
00192 //
00193 //====================================================================================================
00194 void TEcnaNumbering::BuildBarrelCrysTable()
00195 {
00196 // Build the correspondance table: SMCrys <-> (SMTow, TowEcha) for the ECAL BARREL
00197 //
00198 //  From CMS Internal Note  "CMS ECAL Barrel channel numbering"
00199 //
00200 //       Name      Number                     Reference set   Range        Comment
00201 //
00202 //       SMTow  : Tower number               in SuperModule  [1,68]      (phi,eta) progression
00203 //       SMCrys : Crystal number             in SuperModule  [1,1700]    (phi,eta) progression
00204 //       SMEcha : Electronic channel number  in SuperModule  [0,1699]    S shape data reading order 
00205 //   
00206 //       TowEcha: Electronic channel number  in Tower        [0,24]      S shape data reading order  
00207 //
00208 //
00209 //   fill the 2D array:  fT2dSMCrys[n_SMTow][n_TowEcha]
00210 //
00211 //   and the 1d arrays:  fT1dSMTow[i_SMCrys] and fT1dTowEcha[i_SMCrys]
00212 //
00213 //-----------------------------------------------------------------------------------------------------
00214 
00215   if ( fT2dSMCrys == 0 )
00216     {
00217       Int_t MaxSMTow   = fEcal->MaxTowInSM();
00218       Int_t MaxTowEcha = fEcal->MaxCrysInTow();
00219       Int_t MaxSMCrys  = fEcal->MaxCrysInSM();
00220       
00221       //................... Allocation and Init CrysNumbersTable
00222       
00223       fT2dSMCrys = new Int_t*[MaxSMTow];                         fCnew++;  
00224       fT1dSMCrys = new  Int_t[MaxSMTow*MaxTowEcha];              fCnew++;   
00225       for(Int_t i_SMTow = 0 ; i_SMTow < MaxSMTow ; i_SMTow++){
00226         fT2dSMCrys[i_SMTow] = &fT1dSMCrys[0] + i_SMTow*MaxTowEcha;}
00227       for(Int_t i=0; i<MaxSMTow; i++)
00228         {for(Int_t j=0; j<MaxTowEcha; j++){fT2dSMCrys[i][j]=0;}}      
00229 
00230       fT1dSMTow   = new Int_t[MaxSMCrys];                        fCnew++;
00231       for(Int_t i=0; i<MaxSMCrys; i++){fT1dSMTow[i]=0;}
00232 
00233       fT1dTowEcha = new Int_t[MaxSMCrys];                        fCnew++;
00234       for(Int_t i=0; i<MaxSMCrys; i++){fT1dTowEcha[i]=0;}
00235 
00236       //........................ Build table      
00237       Int_t m2  = (Int_t)2;
00238       Int_t m26 = (Int_t)26;
00239 
00240       //      Int_t jch_type[2][26];
00241       Int_t** jch_type    = new Int_t*[m2];                      fCnew++;  
00242       Int_t*  jch_type_d1 = new Int_t[m2*m26];                   fCnew++;
00243       for(Int_t i_m2 = 0 ; i_m2 < m2 ; i_m2++){
00244         jch_type[i_m2] = &jch_type_d1[0] + i_m2*m26;}
00245 
00246       for(Int_t k=25;k>=21;k--){jch_type[0][k] = 25-k;}  //  k = 25,24,23,22,21 -> jch_type[0][k] = 0,1,2,3,4
00247       for(Int_t k=16;k<=20;k++){jch_type[0][k] = k-16;}  //  k = 16,17,18,19,20 -> jch_type[0][k] = 0,1,2,3,4
00248       for(Int_t k=15;k>=11;k--){jch_type[0][k] = 15-k;}  //  k = 15,14,12,13,11 -> jch_type[0][k] = 0,1,2,3,4
00249       for(Int_t k=6; k<=10;k++){jch_type[0][k] = k-6;}   //  k =  6, 7, 8, 9,10 -> jch_type[0][k] = 0,1,2,3,4
00250       for(Int_t k=5; k>=1; k--){jch_type[0][k] = 5-k;}   //  k =  5, 4, 3, 2, 1 -> jch_type[0][k] = 0,1,2,3,4
00251       
00252       for(Int_t k=1; k<=5; k++){jch_type[1][k] = k-1;}   //  k =  1, 2, 3, 4, 5 -> jch_type[1][k] = 0,1,2,3,4
00253       for(Int_t k=10;k>=6; k--){jch_type[1][k] = 10-k;}  //  k = 10, 9, 8, 7, 6 -> jch_type[1][k] = 0,1,2,3,4
00254       for(Int_t k=11;k<=15;k++){jch_type[1][k] = k-11;}  //  k = 11,12,13,14,15 -> jch_type[1][k] = 0,1,2,3,4
00255       for(Int_t k=20;k>=16;k--){jch_type[1][k] = 20-k;}  //  k = 20,19,18,17,16 -> jch_type[1][k] = 0,1,2,3,4
00256       for(Int_t k=21;k<=25;k++){jch_type[1][k] = k-21;}  //  k = 21,22,23,24,25 -> jch_type[1][k] = 0,1,2,3,4
00257 
00258       //      Int_t ich_type[2][26]; 
00259       Int_t** ich_type    = new Int_t*[m2];                      fCnew++;  
00260       Int_t*  ich_type_d1 = new Int_t[m2*m26];                   fCnew++;
00261       for(Int_t i_m2 = 0 ; i_m2 < m2 ; i_m2++){
00262         ich_type[i_m2] = &ich_type_d1[0] + i_m2*m26;}
00263      
00264       for(Int_t k=25;k>=21;k--){ich_type[0][k] = 0;}     //  k = 25,24,23,22,21 -> ich_type[0][k] = 0
00265       for(Int_t k=16;k<=20;k++){ich_type[0][k] = 1;}     //  k = 16,17,18,19,20 -> ich_type[0][k] = 1
00266       for(Int_t k=15;k>=11;k--){ich_type[0][k] = 2;}     //  k = 15,14,12,13,11 -> ich_type[0][k] = 2
00267       for(Int_t k=6; k<=10;k++){ich_type[0][k] = 3;}     //  k =  6, 7, 8, 9,10 -> ich_type[0][k] = 3
00268       for(Int_t k=5; k>=1; k--){ich_type[0][k] = 4;}     //  k =  5, 4, 3, 2, 1 -> ich_type[0][k] = 4
00269       
00270       for(Int_t k=1; k<=5; k++){ich_type[1][k] = 0;}     //  k =  1, 2, 3, 4, 5 -> ich_type[1][k] = 0
00271       for(Int_t k=10;k>=6; k--){ich_type[1][k] = 1;}     //  k = 10, 9, 8, 7, 6 -> ich_type[1][k] = 1
00272       for(Int_t k=11;k<=15;k++){ich_type[1][k] = 2;}     //  k = 11,12,13,14,15 -> ich_type[1][k] = 2
00273       for(Int_t k=20;k>=16;k--){ich_type[1][k] = 3;}     //  k = 20,19,18,17,16 -> ich_type[1][k] = 3
00274       for(Int_t k=21;k<=25;k++){ich_type[1][k] = 4;}     //  k = 21,22,23,24,25 -> ich_type[1][k] = 4
00275       
00276       //     Int_t type[17]={0,0,0,1,1, 0,0,1,1, 0,0,1,1, 0,0,1,1};
00277       Int_t m17 =17;
00278       Int_t* type = new Int_t[m17];                             fCnew++; 
00279 
00280       //  0 -> LVRB at the bottom, 1 -> LVRB at the top
00281       type[0] = 0;                   // M1
00282       type[1] = 0;
00283       type[2] = 0;
00284       type[3] = 1;
00285       type[4] = 1;
00286 
00287       type[5] = 0;                   // M2
00288       type[6] = 0;
00289       type[7] = 1;
00290       type[8] = 1;
00291 
00292       type[9]  = 0;                  // M3
00293       type[10] = 0;
00294       type[11] = 1;
00295       type[12] = 1;
00296 
00297       type[13] = 0;                  // M4
00298       type[14] = 0;
00299       type[15] = 1;
00300       type[16] = 1;
00301 
00302       for(Int_t tow=0; tow<MaxSMTow; tow++)                    //  tow  = 0 to 67   (MaxSMTow = 68)
00303         {
00304           for(Int_t ic=1; ic<=MaxTowEcha; ic++)                //  ic   = 1 to 25   (MaxTowEcha = 25) 
00305             {
00306               Int_t jtow = tow % 4;                            //  jtow = 0,1,2,3 
00307               Int_t itow = tow / 4;                            //  itow = 0 to 16
00308 
00309               Int_t icrys = itow*5 + ich_type[type[itow]][ic]; //  type[0->16] = 0,1 ,
00310                                                                //  ich_type[0->1][1->25] = 0,1,2,3,4
00311                                                                //  icrys = 0 to 84  (=> eta)
00312 
00313               Int_t jcrys = jtow*5 + jch_type[type[itow]][ic]; //  type[0->16] = 0,1 ,
00314                                                                //  jch_type[0->1][1->25] = 0,1,2,3,4
00315                                                                //  jcrys = 0 to 19  (=> phi)
00316 
00317               Int_t n1SMCrys = icrys*20+jcrys+1;               //  n1SMCrys = 1 to 1700
00318 
00319               fT2dSMCrys[tow][ic-1]   = n1SMCrys;      // fT2dSMCrys[]  : range = [1,1700]
00320               fT1dSMTow[n1SMCrys-1]   = tow+1;         // fT1dSMTow[]   : range = [1,68]
00321               fT1dTowEcha[n1SMCrys-1] = ic-1;          // fT1dTowEcha[] : range = [0,24]
00322             }
00323         }
00324       // cout << "#TEcnaNumbering::TBuildBarrelCrysTable()> Crys Table Building done" << endl;
00325 
00326       delete [] jch_type;                       fCdelete++;
00327       delete [] jch_type_d1;                    fCdelete++;
00328       delete [] ich_type;                       fCdelete++;
00329       delete [] ich_type_d1;                    fCdelete++;
00330       delete [] type;                           fCdelete++;
00331     }
00332   else
00333     {
00334       // cout << "#TEcnaNumbering::TBuildBarrelCrysTable()> No Building of Crys Table since it is already done." << endl;
00335     }
00336 }
00337 
00338 //===============================================================================
00339 //
00340 //        GetSMCrysFrom1SMTowAnd0TowEcha
00341 //        GetSMCrysFromSMEcha
00342 //
00343 //===============================================================================
00344 Int_t TEcnaNumbering::Get1SMCrysFrom1SMTowAnd0TowEcha(const Int_t& n1SMTow,
00345                                                       const Int_t& i0TowEcha)
00346 {
00347 //get crystal number in SM from tower number in SM
00348 // and from Electronic Channel number in tower
00349 
00350   Int_t n1SMCrys = 0;
00351 
00352   if( fT2dSMCrys == 0 ){BuildBarrelCrysTable();}
00353   
00354   if (n1SMTow >= 1 && n1SMTow <= fEcal->MaxTowInSM())
00355     {
00356       if (i0TowEcha >=0 && i0TowEcha < fEcal->MaxCrysInTow())
00357         {
00358           n1SMCrys = fT2dSMCrys[n1SMTow-1][i0TowEcha];
00359         }
00360       else
00361         {
00362           n1SMCrys = -2;   // Electronic Cnannel in Tower out of range 
00363           cout << "!TEcnaNumbering::Get1SMCrysFrom1SMTowAnd0TowEcha(...)> Electronic Channel in Tower out of range."
00364                << " i0TowEcha = " << i0TowEcha << "(n1SMTow = " << n1SMTow << ")" << fTTBELL << endl;
00365         }
00366     }
00367   else
00368     {
00369       n1SMCrys = -3;   // Tower number in SM out of range
00370       cout << "!TEcnaNumbering::Get1SMCrysFrom1SMTowAnd0TowEcha(...)> Tower number in SM out of range."
00371            << " n1SMTow = " << n1SMTow << "(i0TowEcha = " << i0TowEcha << ")" << fTTBELL << endl;
00372     }
00373 
00374   return n1SMCrys;   // Range = [1,1700]
00375 }
00376 
00377 //===============================================================================
00378 //
00379 //                Get0TowEchaFrom1SMCrys, Get1SMTowFrom1SMCrys
00380 //
00381 //===============================================================================
00382 
00383 Int_t TEcnaNumbering::Get0TowEchaFrom1SMCrys(const Int_t& n1SMCrys)
00384 {
00385 // get Electronic Channel number in Tower from Crystal number in SuperModule
00386 
00387   Int_t i0TowEcha = -1;
00388 
00389   if( n1SMCrys >= 1 && n1SMCrys <= fEcal->MaxCrysInSM() )
00390     {
00391       i0TowEcha = fT1dTowEcha[n1SMCrys-1];
00392     }
00393   else
00394     {
00395       i0TowEcha = -2;
00396       cout << "!TEcnaNumbering::Get0TowEchaFrom1SMCrys(...)> Crystal number in SM out of range."
00397            << " n1SMCrys = " << n1SMCrys << fTTBELL << endl;
00398     }
00399   return i0TowEcha;   // range = [0,24]
00400 }
00401 
00402 Int_t TEcnaNumbering::Get1SMTowFrom1SMCrys(const Int_t& n1SMCrys)
00403 {
00404 // get Tower number in SM (range [1,68]) from Crystal number in SuperModule (range [1,1700])
00405 
00406   Int_t n1SMtox = 0;
00407   
00408   if( n1SMCrys >= 1 && n1SMCrys <= fEcal->MaxCrysInSM() )
00409     {
00410       n1SMtox = fT1dSMTow[n1SMCrys-1];
00411     }
00412   else
00413     {
00414       n1SMtox = -1;
00415       cout << "!TEcnaNumbering::Get1SMTowFrom1SMCrys(...)> Crystal number in SM out of range."
00416            << " n1SMCrys = " << n1SMCrys << fTTBELL << endl;
00417     }
00418   return n1SMtox;   // range = [1,68]
00419 }
00420 
00421 //===============================================================================
00422 //
00423 //          Get0TowEchaFrom0SMEcha
00424 //          Get1SMTowFrom0SMEcha
00425 //
00426 //===============================================================================
00427 
00428 Int_t TEcnaNumbering::Get0TowEchaFrom0SMEcha(const Int_t& i0SMEcha)
00429 {
00430 //get electronic channel number in tower from electronic channel number in SM
00431 
00432   Int_t n1SMTow = i0SMEcha/fEcal->MaxCrysInTow()+1;
00433   Int_t i0TowEcha = i0SMEcha - fEcal->MaxCrysInTow()*(n1SMTow-1);
00434 
00435   return i0TowEcha;   // range = [0,24]
00436 }
00437 
00438 Int_t TEcnaNumbering::Get1SMTowFrom0SMEcha(const Int_t& i0SMEcha)
00439 {
00440 //get tower number from electronic channel number in SM
00441 
00442   Int_t n1SMTow = i0SMEcha/fEcal->MaxCrysInTow()+1;
00443 
00444   return n1SMTow;  // range = [1,68]
00445 }
00446 
00447 Int_t TEcnaNumbering::Get0SMEchaFrom1SMTowAnd0TowEcha(const Int_t& n1SMTow, const Int_t& i0TowEcha)
00448 {
00449 //get tower number from electronic channel number in SM
00450 
00451   Int_t i0SMEcha = (n1SMTow-1)*fEcal->MaxCrysInTow()+i0TowEcha;
00452 
00453   return i0SMEcha;
00454 }
00455 //===========================================================================
00456 //
00457 //                        GetHashedNumberFromIEtaAndIPhi
00458 //
00459 //===========================================================================
00460 Int_t TEcnaNumbering::GetHashedNumberFromIEtaAndIPhi(const Int_t& IEta, const Int_t& IPhi)
00461 {
00462   Int_t Hashed = 0;
00463 
00464   if( IEta > 0 ){Hashed = (85 + IEta - 1)*360 + IPhi - 1;}
00465   if( IEta < 0 ){Hashed = (85 + IEta)*360     + IPhi - 1;}
00466 
00467   return Hashed;
00468 }
00469 
00470 Int_t TEcnaNumbering::GetIEtaFromHashed(const Int_t& Hashed,  const Int_t& SMNumber)
00471 {
00472   Int_t IEta = 0;
00473 
00474   if( GetSMHalfBarrel(SMNumber) == "EB+" ){IEta = Hashed/360 - 85 + 1;}
00475   if( GetSMHalfBarrel(SMNumber) == "EB-" ){IEta = 85 + Hashed/360;}
00476 
00477   return IEta;
00478 }
00479 
00480 Int_t TEcnaNumbering::GetIPhiFromHashed(const Int_t& Hashed)
00481 {
00482   Int_t IPhi = Hashed%360 + 1;
00483 
00484   return IPhi;
00485 }
00486 //===========================================================================
00487 //
00488 //                        GetTowerLvrbType
00489 //
00490 //===========================================================================
00491 TString  TEcnaNumbering::GetStinLvrbType(const Int_t& n1SMTow)
00492 {
00493   TString lvrb_type = GetTowerLvrbType(n1SMTow);
00494   return lvrb_type;
00495 }
00496 TString  TEcnaNumbering::GetTowerLvrbType(const Int_t& n1SMTow)
00497 {
00498 //gives the LVRB type of the crystal numbering of tower
00499 
00500   TString type = fCodeChNumberingLvrbTop;   // => default value
00501 
00502   if (n1SMTow >=  1 && n1SMTow <= 12){type = fCodeChNumberingLvrbBot;}
00503   if (n1SMTow >= 21 && n1SMTow <= 28){type = fCodeChNumberingLvrbBot;}
00504   if (n1SMTow >= 37 && n1SMTow <= 44){type = fCodeChNumberingLvrbBot;}
00505   if (n1SMTow >= 53 && n1SMTow <= 60){type = fCodeChNumberingLvrbBot;}
00506 
00507   return type;
00508 }
00509 
00510 //==============================================================================
00511 //
00512 //       GetEta, GetEtaMin, GetEtaMax,  GetIEtaMin, GetIEtaMax
00513 //
00514 //==============================================================================
00515 Double_t TEcnaNumbering::GetEta(const Int_t& n1EBSM, const Int_t& n1SMTow,
00516                                 const Int_t& i0TowEcha)
00517 {
00518 //Gives Eta for a given (n1EBSM, n1SMTow, i0TowEcha)
00519   
00520   Double_t eta = (Double_t)0.;
00521 
00522   Int_t max_crys_eta_in_tower = fEcal->MaxCrysEtaInTow();
00523   Int_t max_tow_eta_in_sm     = fEcal->MaxTowEtaInSM();
00524   Int_t max_sm_in_barrel      = fEcal->MaxSMInEB();
00525 
00526   if ( n1EBSM >= 1 && n1EBSM <= max_sm_in_barrel )
00527     {
00528       for (Int_t i_sm_tow_eta = 0; i_sm_tow_eta < max_tow_eta_in_sm; i_sm_tow_eta++)
00529         {
00530           Int_t i_crys_eta_min = (Int_t)(1 + i_sm_tow_eta*(max_crys_eta_in_tower-1));
00531           Int_t i_crys_eta_max = (Int_t)((i_sm_tow_eta+1)*(max_crys_eta_in_tower-1));
00532           Int_t i_crys_eta     = (Int_t)(i_sm_tow_eta*max_crys_eta_in_tower);
00533           // = 0,..,16 -> last xtal in eta for the previous tower
00534           Double_t d_echa_eta  = (Double_t)(i0TowEcha/max_crys_eta_in_tower);    // = 0,1,2,3,4
00535 
00536             if ( n1SMTow >= i_crys_eta_min && n1SMTow <= i_crys_eta_max )
00537               {
00538                 if (GetTowerLvrbType(n1SMTow) == fCodeChNumberingLvrbTop)
00539                 {eta = (Double_t)(i_crys_eta) + d_echa_eta + 1;}
00540                 if (GetTowerLvrbType(n1SMTow) == fCodeChNumberingLvrbBot)
00541                 {eta = (Double_t)(i_crys_eta+max_crys_eta_in_tower)-d_echa_eta;}
00542               }
00543         }      
00544       if ( GetSMHalfBarrel(n1EBSM) == "EB-" ){eta = - eta;}      
00545     }
00546   else
00547     {
00548       cout << "TEcnaNumbering::GetEta(...)> SM = " << n1EBSM
00549            << ". Out of range (range = [1," << fEcal->MaxSMInEB() << "])" 
00550            << fTTBELL << endl; 
00551     }
00552   return eta;
00553 }
00554 //-------------------------------------------------------------------------------------
00555 Double_t TEcnaNumbering::GetEtaMin(const Int_t& n1EBSM, const Int_t& n1SMTow)
00556 {
00557 //Gives EtaMin for a given Tower
00558 
00559   Int_t max_tow_eta_in_sm     = fEcal->MaxTowEtaInSM();
00560   Int_t max_crys_eta_in_tower = fEcal->MaxCrysEtaInTow();
00561 
00562   Double_t eta_min = (Double_t)0.;
00563 
00564   for (Int_t i_sm_tow_eta = 0; i_sm_tow_eta < max_tow_eta_in_sm; i_sm_tow_eta++)
00565     {
00566       Int_t i_crys_eta_min =    (Int_t)(1 + i_sm_tow_eta*(max_crys_eta_in_tower-1));
00567       Int_t i_crys_eta_max =    (Int_t)((i_sm_tow_eta+1)*(max_crys_eta_in_tower-1));
00568       Int_t i_crys_eta     =    (Int_t)(i_sm_tow_eta*max_crys_eta_in_tower);
00569 
00570       if ( n1SMTow >= i_crys_eta_min && n1SMTow <= i_crys_eta_max )
00571         {
00572           if (GetSMHalfBarrel(n1EBSM) == "EB+")
00573             {eta_min = (Double_t)i_crys_eta;}
00574           if (GetSMHalfBarrel(n1EBSM) == "EB-")
00575             {eta_min = -(Double_t)(i_crys_eta + max_crys_eta_in_tower);}
00576         }
00577     }
00578   return eta_min;
00579 }
00580 //------------------------------------------------------------------------------------
00581 Double_t TEcnaNumbering::GetEtaMax(const Int_t& n1EBSM, const Int_t& n1SMTow)
00582 {
00583 //Gives EtaMax for a given Tower
00584 
00585   Int_t max_tow_eta_in_sm     = fEcal->MaxTowEtaInSM();
00586   Int_t max_crys_eta_in_tower = fEcal->MaxCrysEtaInTow();
00587 
00588   Double_t eta_max = (max_crys_eta_in_tower-1);
00589 
00590   for (Int_t i_sm_tow_eta = 0; i_sm_tow_eta < max_tow_eta_in_sm; i_sm_tow_eta++)
00591     {
00592       Int_t i_crys_eta_min = (Int_t)(1 + i_sm_tow_eta*(max_crys_eta_in_tower-1));
00593       Int_t i_crys_eta_max = (Int_t)((i_sm_tow_eta+1)*(max_crys_eta_in_tower-1));
00594       Int_t i_crys_eta     = (Int_t)(i_sm_tow_eta*max_crys_eta_in_tower);
00595 
00596       if ( n1SMTow >= i_crys_eta_min && n1SMTow <= i_crys_eta_max )
00597         {
00598           if (GetSMHalfBarrel(n1EBSM) == "EB+")
00599             {eta_max = (Double_t)(i_crys_eta + max_crys_eta_in_tower);}
00600           if (GetSMHalfBarrel(n1EBSM) == "EB-")
00601             {eta_max = -(Double_t)i_crys_eta;}
00602         }
00603     }
00604 
00605   return eta_max;
00606 }
00607 
00608 Double_t TEcnaNumbering::GetIEtaMin(const Int_t& n1EBSM, const Int_t& n1SMTow)
00609 {
00610 //Gives IEtaMin for a given (n1EBSM, n1SMTow)
00611 
00612   Double_t i_eta_min = (Int_t)0.; 
00613    
00614   if(GetSMHalfBarrel(n1EBSM) == "EB+")
00615     {i_eta_min = (Double_t)GetEtaMin(n1EBSM, n1SMTow)+(Double_t)0.5;}
00616   if(GetSMHalfBarrel(n1EBSM) == "EB-")
00617     {i_eta_min = (Double_t)GetEtaMin(n1EBSM, n1SMTow)-(Double_t)0.5;}
00618 
00619   return i_eta_min;
00620 }
00621 
00622 Double_t TEcnaNumbering::GetIEtaMax(const Int_t& n1EBSM, const Int_t& n1SMTow)
00623 {
00624 //Gives IEtaMax for a given (n1EBSM, n1SMTow)
00625 
00626   Double_t i_eta_max = (Int_t)0.; 
00627    
00628   if(GetSMHalfBarrel(n1EBSM) == "EB+")
00629     {i_eta_max = (Double_t)GetEtaMax(n1EBSM, n1SMTow)+(Double_t)0.5;}
00630   if(GetSMHalfBarrel(n1EBSM) == "EB-")
00631     {i_eta_max = (Double_t)GetEtaMax(n1EBSM, n1SMTow)-(Double_t)0.5;}
00632 
00633   return i_eta_max;
00634 }
00635 
00636 Double_t TEcnaNumbering::GetIEtaMin(const Int_t& n1EBSM)
00637 {
00638 //Gives IEtaMin for a given (n1EBSM)
00639 
00640   Double_t i_eta_min = (Int_t)0.;
00641 
00642   Int_t n1SMTowPlus  = (Int_t)1;   
00643   Int_t n1SMTowMinus = (Int_t)fEcal->MaxTowInSM();
00644 
00645   if( GetSMHalfBarrel(n1EBSM) == "EB+" )
00646     {i_eta_min = (Double_t)GetIEtaMin(n1EBSM, n1SMTowPlus );}
00647   if( GetSMHalfBarrel(n1EBSM) == "EB-" )
00648     {i_eta_min = (Double_t)GetIEtaMin(n1EBSM, n1SMTowMinus);}
00649 
00650   return i_eta_min;
00651 }
00652 
00653 Double_t TEcnaNumbering::GetIEtaMax(const Int_t& n1EBSM)
00654 {
00655 //Gives IEtaMax for a given (n1EBSM)
00656 
00657   Double_t i_eta_max = (Int_t)0.; 
00658 
00659   Int_t n1SMTowPlus  = (Int_t)fEcal->MaxTowInSM();   
00660   Int_t n1SMTowMinus = (Int_t)1;   
00661    
00662   if( GetSMHalfBarrel(n1EBSM) == "EB+")
00663     {i_eta_max = (Double_t)GetIEtaMax(n1EBSM, n1SMTowPlus );}
00664   if( GetSMHalfBarrel(n1EBSM) == "EB-")
00665     {i_eta_max = (Double_t)GetIEtaMax(n1EBSM, n1SMTowMinus);}
00666 
00667   return i_eta_max;
00668 }
00669 
00670 //==============================================================================
00671 //
00672 //    GetSMCentralPhi, GetPhiInSM, GetPhi,
00673 //    GetPhiMin, GetPhiMax, GetIPhiMin, GetIPhiMax
00674 //
00675 //==============================================================================
00676 Double_t TEcnaNumbering::GetSMCentralPhi(const Int_t& n1EBSM)
00677 {
00678 //Gives the central phi value of the SuperModule
00679 
00680   Double_t central_phi = (Double_t)10.;    //  DEFAULT = SM1
00681   
00682   if (GetSMHalfBarrel(n1EBSM) == "EB+"){central_phi = 10. + (Double_t)20.*(n1EBSM-1);}
00683   if (GetSMHalfBarrel(n1EBSM) == "EB-"){central_phi = 10. + (Double_t)20.*(n1EBSM-19);}
00684 
00685   return central_phi;
00686 }
00687 //------------------------------------------------------------------------------------
00688 Double_t TEcnaNumbering::GetPhiInSM(const Int_t& n1EBSM,
00689                                     const Int_t& n1SMTow, const Int_t& i0TowEcha)
00690 {
00691 //Gives Phi for a given (n1EBSM, n1SMTow, i0TowEcha)
00692 
00693   Double_t phi_in_SM = (Double_t)0.;
00694 
00695   Int_t rest_temp =(Int_t)(n1SMTow%(fEcal->MaxCrysPhiInTow()-1));  // "Phi" of the tower = 1,2,3,0 
00696 
00697   if ( n1EBSM >= 1 && n1EBSM <= fEcal->MaxSMInEB() )
00698     {
00699       if( rest_temp == 1 ){phi_in_SM = (Double_t)15.;}
00700       if( rest_temp == 2 ){phi_in_SM = (Double_t)10.;}
00701       if( rest_temp == 3 ){phi_in_SM = (Double_t)5.;}
00702       if( rest_temp == 0 ){phi_in_SM = (Double_t)0.;}
00703       
00704       if (GetTowerLvrbType(n1SMTow) == fCodeChNumberingLvrbTop)
00705         { 
00706           if( i0TowEcha ==  4 || i0TowEcha ==  5 || i0TowEcha == 14 || i0TowEcha == 15 || i0TowEcha == 24 )
00707             {phi_in_SM = phi_in_SM + 0;}
00708           
00709           if( i0TowEcha ==  3 || i0TowEcha ==  6 || i0TowEcha == 13 || i0TowEcha == 16 || i0TowEcha == 23 )
00710             {phi_in_SM = phi_in_SM + 1;} 
00711           
00712           if( i0TowEcha ==  2 || i0TowEcha ==  7 || i0TowEcha == 12 || i0TowEcha == 17 || i0TowEcha == 22 )
00713             {phi_in_SM = phi_in_SM + 2;}
00714           
00715           if( i0TowEcha ==  1 || i0TowEcha ==  8 || i0TowEcha == 11 || i0TowEcha == 18 || i0TowEcha == 21 )
00716             {phi_in_SM = phi_in_SM + 3;}
00717           
00718           if( i0TowEcha ==  0 || i0TowEcha ==  9 || i0TowEcha == 10 || i0TowEcha == 19 || i0TowEcha == 20 )
00719             {phi_in_SM = phi_in_SM + 4;} 
00720         }
00721       if (GetTowerLvrbType(n1SMTow) == fCodeChNumberingLvrbBot)
00722         {
00723           if( i0TowEcha == 20 || i0TowEcha == 19 || i0TowEcha == 10 || i0TowEcha ==  9 || i0TowEcha ==  0 )
00724             {phi_in_SM = phi_in_SM + 0;}
00725           
00726           if( i0TowEcha == 21 || i0TowEcha == 18 || i0TowEcha == 11 || i0TowEcha ==  8 || i0TowEcha ==  1 )
00727             {phi_in_SM = phi_in_SM + 1;}
00728  
00729           if( i0TowEcha == 22 || i0TowEcha == 17 || i0TowEcha == 12 || i0TowEcha ==  7 || i0TowEcha ==  2 )
00730             {phi_in_SM = phi_in_SM + 2;}
00731 
00732           if( i0TowEcha == 23 || i0TowEcha == 16 || i0TowEcha == 13 || i0TowEcha ==  6 || i0TowEcha ==  3 )
00733             {phi_in_SM = phi_in_SM + 3;}
00734 
00735           if( i0TowEcha == 24 || i0TowEcha == 15 || i0TowEcha == 14 || i0TowEcha ==  5 || i0TowEcha ==  4 )
00736             {phi_in_SM = phi_in_SM + 4;} 
00737           }
00738     }
00739   else
00740     {
00741       cout << "TEcnaNumbering::GetPhiInSM(...)> SM = " << n1EBSM
00742            << ". Out of range (range = [1," << fEcal->MaxSMInEB() << "])" 
00743            << fTTBELL << endl; 
00744     }
00745   phi_in_SM = 20 - phi_in_SM;
00746   return phi_in_SM;
00747 }
00748 //---------------------------------------------------------------------------------------
00749 Double_t TEcnaNumbering::GetPhi(const Int_t& n1EBSM,
00750                                 const Int_t& n1SMTow, const Int_t& i0TowEcha)
00751 {
00752 //Gives Phi for a given (n1EBSM, n1SMTow, i0TowEcha)
00753   
00754   Double_t phi = (Double_t)0.;
00755 
00756   if ( n1EBSM >= 1 && n1EBSM <= fEcal->MaxSMInEB() )
00757     {
00758       Double_t phiInSM   = GetPhiInSM(n1EBSM, n1SMTow, i0TowEcha);
00759       Double_t phi_start = GetSMCentralPhi(n1EBSM);
00760  
00761       phi = 20 - phiInSM + phi_start -(Double_t)10.;
00762     }
00763   else
00764     {
00765       cout << "TEcnaNumbering::GetPhi(...)> SM = " << n1EBSM
00766            << ". Out of range (range = [1," << fEcal->MaxSMInEB() << "])" 
00767            << fTTBELL << endl; 
00768     }
00769   return phi;
00770 }
00771 
00772 //-----------------------------------------------------------------------------------------
00773 Double_t TEcnaNumbering::GetPhiMin(const Int_t& n1EBSM, const Int_t& n1SMTow)
00774 {
00775 //Gives PhiMin for a given Tower
00776 
00777   Int_t max_crys_phi_in_tower = fEcal->MaxCrysPhiInTow();
00778 
00779   Double_t phi_min = (Double_t)0.;     // DEFAULT
00780   Double_t phi_start = GetSMCentralPhi(n1EBSM);
00781 
00782   Int_t rest_temp =(Int_t)(n1SMTow%(max_crys_phi_in_tower-1));
00783 
00784   if(GetSMHalfBarrel(n1EBSM) == "EB+")
00785     {
00786       if ( rest_temp == 1 ) {phi_min = phi_start + (Double_t)5.;}
00787       if ( rest_temp == 2 ) {phi_min = phi_start + (Double_t)0.;}
00788       if ( rest_temp == 3 ) {phi_min = phi_start - (Double_t)5.;}
00789       if ( rest_temp == 0 ) {phi_min = phi_start - (Double_t)10.;}
00790     }
00791   if(GetSMHalfBarrel(n1EBSM) == "EB-")
00792     {
00793       if ( rest_temp == 0 ) {phi_min = phi_start + (Double_t)5.;}
00794       if ( rest_temp == 3 ) {phi_min = phi_start + (Double_t)0.;}
00795       if ( rest_temp == 2 ) {phi_min = phi_start - (Double_t)5.;}
00796       if ( rest_temp == 1 ) {phi_min = phi_start - (Double_t)10.;}
00797     }
00798   return phi_min;
00799 }
00800 //-----------------------------------------------------------------------------------------
00801 Double_t TEcnaNumbering::GetPhiMax(const Int_t& n1EBSM, const Int_t& n1SMTow)
00802 {
00803 //Gives PhiMax for a given Tower
00804 
00805   Int_t max_crys_phi_in_tower = fEcal->MaxCrysPhiInTow();
00806 
00807   Double_t phi_max = (Double_t)20.;     // DEFAULT
00808   Double_t phi_start = GetSMCentralPhi(n1EBSM);
00809 
00810   Int_t rest_temp =(Int_t)(n1SMTow%(max_crys_phi_in_tower-1));
00811 
00812   if(GetSMHalfBarrel(n1EBSM) == "EB+")
00813     {
00814       if ( rest_temp == 1 ) {phi_max = phi_start + (Double_t)10.;}
00815       if ( rest_temp == 2 ) {phi_max = phi_start + (Double_t)5.;}
00816       if ( rest_temp == 3 ) {phi_max = phi_start - (Double_t)0.;}
00817       if ( rest_temp == 0 ) {phi_max = phi_start - (Double_t)5.;}
00818     }
00819 
00820   if(GetSMHalfBarrel(n1EBSM) == "EB-")
00821     {
00822       if ( rest_temp == 0 ) {phi_max = phi_start + (Double_t)10.;}
00823       if ( rest_temp == 3 ) {phi_max = phi_start + (Double_t)5.;}
00824       if ( rest_temp == 2 ) {phi_max = phi_start - (Double_t)0.;}
00825       if ( rest_temp == 1 ) {phi_max = phi_start - (Double_t)5.;}
00826     }
00827 
00828   return phi_max;
00829 }
00830 //-----------------------------------------------------------------------------------------
00831 Double_t TEcnaNumbering::GetPhiMin(const Int_t& n1EBSM)
00832 {
00833 //Gives PhiMin for a given SuperModule
00834 
00835   Double_t phi_min = GetSMCentralPhi(n1EBSM) - (Double_t)10.;
00836 
00837   return phi_min;
00838 }
00839 //-----------------------------------------------------------------------------------------
00840 Double_t TEcnaNumbering::GetPhiMax(const Int_t& n1EBSM)
00841 {
00842 //Gives PhiMax for a given SuperModule
00843 
00844   Double_t phi_max = GetSMCentralPhi(n1EBSM) + (Double_t)10.;
00845 
00846   return phi_max;
00847 }
00848 //-----------------------------------------------------------------------------------------
00849 Double_t TEcnaNumbering::GetJPhiMin(const Int_t& n1EBSM, const Int_t& n1SMTow)
00850 {
00851 //Gives JPhiMin for a given Tower
00852 
00853   Double_t j_phi_min = (Double_t)1.;
00854   Int_t max_crys_phi_in_tower = fEcal->MaxCrysPhiInTow();
00855   Int_t rest_temp =(Int_t)(n1SMTow%(max_crys_phi_in_tower-1));
00856   
00857   if ( rest_temp == 1 ){j_phi_min = (Double_t) 1. - (Double_t)0.5;}
00858   if ( rest_temp == 2 ){j_phi_min = (Double_t) 6. - (Double_t)0.5;}
00859   if ( rest_temp == 3 ){j_phi_min = (Double_t)11. - (Double_t)0.5;}
00860   if ( rest_temp == 0 ){j_phi_min = (Double_t)16. - (Double_t)0.5;}
00861 
00862   return j_phi_min;
00863 }
00864 //-----------------------------------------------------------------------------------------
00865 Double_t TEcnaNumbering::GetJPhiMax(const Int_t& n1EBSM, const Int_t& n1SMTow)
00866 {
00867 //Gives JPhiMax for a given Tower
00868 
00869   Double_t j_phi_max = (Double_t)20.;
00870   Int_t max_crys_phi_in_tower = fEcal->MaxCrysPhiInTow();
00871   Int_t rest_temp =(Int_t)(n1SMTow%(max_crys_phi_in_tower-1));
00872   
00873   if ( rest_temp == 1 ){j_phi_max = (Double_t) 5. + (Double_t)0.5;}
00874   if ( rest_temp == 2 ){j_phi_max = (Double_t)10. + (Double_t)0.5;}
00875   if ( rest_temp == 3 ){j_phi_max = (Double_t)15. + (Double_t)0.5;}
00876   if ( rest_temp == 0 ){j_phi_max = (Double_t)20. + (Double_t)0.5;}
00877 
00878   return j_phi_max;
00879 }
00880 
00881 //-----------------------------------------------------------------------------------------
00882 Double_t TEcnaNumbering::GetJPhiMin(const Int_t& n1EBSM)
00883 {
00884 //Gives JPhiMin for a given SuperModule
00885 
00886   Double_t j_phi_min = (Double_t)1. - (Double_t)0.5;
00887 
00888   return j_phi_min;
00889 }
00890 //-----------------------------------------------------------------------------------------
00891 Double_t TEcnaNumbering::GetJPhiMax(const Int_t& n1EBSM)
00892 {
00893 //Gives JPhiMax for a given SuperModule
00894 
00895   Double_t j_phi_max = (Double_t)20. + (Double_t)0.5;
00896 
00897   return j_phi_max;
00898 }
00899 
00900 //==============================================================================
00901 //
00902 //   GetXDirectionEB, GetYDirectionEB, GetJYDirectionEB
00903 //
00904 //==============================================================================
00905 
00906 //------------------------------------------------------------------
00907 TString TEcnaNumbering::GetXDirectionEB(const Int_t& SMNumber)
00908 {
00909   TString xdirection = "x";      // DEFAULT
00910 
00911   if( GetSMHalfBarrel(SMNumber) == "EB+" ){xdirection = "x";}
00912   if( GetSMHalfBarrel(SMNumber) == "EB-" ){xdirection = "x";}
00913 
00914   return xdirection;
00915 }
00916 //---------------------------------------------------------
00917 TString TEcnaNumbering::GetYDirectionEB(const Int_t& SMNumber)
00918 {
00919   TString ydirection = "-x";      // DEFAULT
00920 
00921   if( GetSMHalfBarrel(SMNumber) == "EB+" ){ydirection = "-x";}
00922   if( GetSMHalfBarrel(SMNumber) == "EB-" ){ydirection = "-x";}
00923 
00924   return ydirection;
00925 }
00926 
00927 //---------------------------------------------------------
00928 TString TEcnaNumbering::GetJYDirectionEB(const Int_t& SMNumber)
00929 {
00930   TString jydirection = "-x";      // DEFAULT
00931 
00932   if( GetSMHalfBarrel(SMNumber) == "EB+" ){jydirection = "x";}
00933   if( GetSMHalfBarrel(SMNumber) == "EB-" ){jydirection = "-x";}
00934 
00935   return jydirection;
00936 }
00937 
00938 //============================================================================
00939 TString  TEcnaNumbering::GetSMHalfBarrel(const Int_t& SMNumber)
00940 {
00941 //gives the half-barrel of the SM ("EB+" or "EB-")
00942 
00943   TString type = "EB-";   // => default value
00944 
00945   if ( SMNumber >=  1                      && SMNumber <= fEcal->MaxSMInEBPlus() ){type = "EB+";}
00946   if ( SMNumber >   fEcal->MaxSMInEBPlus() && SMNumber <= fEcal->MaxSMInEB()     ){type = "EB-";}
00947 
00948   return type;
00949 }
00950 
00951 Int_t TEcnaNumbering::PlusMinusSMNumber(const Int_t& PlusSMNumber)
00952 {
00953   Int_t PMSMNumber = PlusSMNumber;
00954   if( PlusSMNumber > fEcal->MaxSMPhiInEB() ){PMSMNumber = - PlusSMNumber + fEcal->MaxSMPhiInEB();}
00955   return PMSMNumber;
00956 }
00957 //====================================================================================================
00958 //
00959 //
00960 //                                  E   N   D   C   A   P 
00961 //
00962 //
00963 //====================================================================================================
00964 //
00965 //               DeeCrys <-> (DeeSC, SCEcha) correspondance table
00966 //               (from the barrel table given by Patrick Jarry)
00967 //
00968 //====================================================================================================
00969 void TEcnaNumbering::BuildEndcapCrysTable()
00970 {
00971 // Build the correspondance table: DeeCrys <-> (DeeSC, SCEcha) for the ECAL ENDCAP
00972 //
00973 //  From CMS Internal Note  "CMS ECAL Endcap channel numbering"
00974 //
00975 //       Name      Number                     Reference set  Range          Comment
00976 //
00977 //       DeeSC   : Super-Crystal (SC) number    in Dee      [1,200]   (IY,IX) progression
00978 //       DeeCrys : Crystal number               in Dee      [1,5000]  (IY,IX) progression
00979 //       DeeEcha : Electronic channel number    in Dee      [0,4999]  Crystal numbering for construction 
00980 //   
00981 //       SCEcha  : Electronic channel number    in SC       [1,25]    Crystal numbering for construction  
00982 //
00983 //
00984 //   fill the 3D array:  fT3dDeeCrys[n_DeeSC][n_SCEcha][2]
00985 //
00986 //   and the 2d arrays:  fT2dDeeSC[n_DeeCrys][2] and fT2dSCEcha[n_DeeCrys][2]
00987 //
00988 //------------------------------------------------------------------------------------------------------
00989 
00990   if ( fT3dDeeCrys == 0 )
00991     {
00992       Int_t MaxDeeSC   = fEcal->MaxSCEcnaInDee();    // fEcal->MaxSCEcnaInDee() = 200
00993       Int_t MaxSCEcha  = fEcal->MaxCrysInSC();
00994       Int_t MaxDeeCrys = fEcal->MaxCrysEcnaInDee();
00995 
00996       Int_t MaxDirections = 2;    //  (2 directions: left and right)
00997 
00998       //................... Allocation and Init CrysNumbersTable
00999       fT3dDeeCrys = new Int_t**[MaxDeeSC];                         fCnew++;       
01000       fT2dDeeCrys = new  Int_t*[MaxDeeSC*MaxSCEcha];               fCnew++;  
01001       fT1dDeeCrys = new   Int_t[MaxDeeSC*MaxSCEcha*MaxDirections]; fCnew++;
01002       
01003       for(Int_t i_DeeSC = 0; i_DeeSC < MaxDeeSC; i_DeeSC++){
01004         fT3dDeeCrys[i_DeeSC] = &fT2dDeeCrys[0] + i_DeeSC*MaxSCEcha;
01005         for(Int_t i_SCEcha = 0; i_SCEcha < MaxSCEcha; i_SCEcha++){
01006           fT2dDeeCrys[i_DeeSC*MaxSCEcha + i_SCEcha] = &fT1dDeeCrys[0]
01007             + (i_DeeSC*MaxSCEcha + i_SCEcha)*MaxDirections;}}
01008       for(Int_t i=0; i<MaxDeeSC; i++)
01009         {for(Int_t j=0; j<MaxSCEcha; j++)
01010           {for(Int_t k=0; k<MaxDirections; k++){fT3dDeeCrys[i][j][k]=0;}}}      
01011 
01012       fT2dDeeSC  = new Int_t*[MaxDeeCrys];                         fCnew++;
01013       fT1dDeeSC  = new  Int_t[MaxDeeCrys*MaxDirections];           fCnew++;
01014       for(Int_t i_DeeCrys = 0 ; i_DeeCrys < MaxDeeCrys ; i_DeeCrys++){
01015         fT2dDeeSC[i_DeeCrys] = &fT1dDeeSC[0] + i_DeeCrys*MaxDirections;}
01016       for(Int_t i=0; i<MaxDeeCrys; i++)
01017         {for(Int_t j=0; j<MaxDirections; j++){fT2dDeeSC[i][j]=0;}}
01018 
01019       fT2dSCEcha = new Int_t*[MaxDeeCrys];                       fCnew++;
01020       fT1dSCEcha = new  Int_t[MaxDeeCrys*MaxDirections];                    fCnew++;   
01021       for(Int_t i_DeeCrys = 0 ; i_DeeCrys < MaxDeeCrys ; i_DeeCrys++){
01022         fT2dSCEcha[i_DeeCrys] = &fT1dSCEcha[0] + i_DeeCrys*MaxDirections;}
01023       for(Int_t i=0; i<MaxDeeCrys; i++)
01024         {for(Int_t j=0; j<MaxDirections; j++){fT2dSCEcha[i][j]=0;}}      
01025 
01026       //................................ Build table
01027       Int_t MaxTyp    = (Int_t)4;
01028       Int_t MaxCrysP1 = (Int_t)(fEcal->MaxCrysInSC()+1);
01029 
01030       //      Int_t fT2d_jch_JY[type][Echa+1]:  JY in the SC as a function of type and Echa+1
01031       fT2d_jch_JY    = new Int_t*[MaxTyp];                      fCnew++;  
01032       fT1d_jch_JY = new Int_t[MaxTyp*MaxCrysP1];             fCnew++;
01033       for(Int_t i_MaxTyp = 0 ; i_MaxTyp < MaxTyp ; i_MaxTyp++){
01034         fT2d_jch_JY[i_MaxTyp] = &fT1d_jch_JY[0] + i_MaxTyp*MaxCrysP1;}
01035 
01036       // type: 0=(top/right), 1=(top/left), 2=(bottom/left), 3=(bottom/right),  
01037 
01038       //................. top/right
01039       for(Int_t k= 5;k>= 1;k--){fT2d_jch_JY[0][k] = 4;}     //  k =  5, 4, 3, 2, 1 -> fT2d_jch_JY[0][k] = 4
01040       for(Int_t k=10;k>= 6;k--){fT2d_jch_JY[0][k] = 3;}     //  k = 10, 9, 8, 7, 6 -> fT2d_jch_JY[0][k] = 3
01041       for(Int_t k=15;k>=11;k--){fT2d_jch_JY[0][k] = 2;}     //  k = 15,14,13,12,11 -> fT2d_jch_JY[0][k] = 2
01042       for(Int_t k=20;k>=16;k--){fT2d_jch_JY[0][k] = 1;}     //  k = 20,19,18,17,16 -> fT2d_jch_JY[0][k] = 1
01043       for(Int_t k=25;k>=21;k--){fT2d_jch_JY[0][k] = 0;}     //  k = 25,24,23,22,21 -> fT2d_jch_JY[0][k] = 0
01044       //................. top/left
01045       for(Int_t k= 5;k>= 1;k--){fT2d_jch_JY[1][k] =  5-k;}  //  k =  5, 4, 3, 2, 1 -> fT2d_jch_JY[1][k] = 0,1,2,3,4
01046       for(Int_t k=10;k>= 6;k--){fT2d_jch_JY[1][k] = 10-k;}  //  k = 10, 9, 8, 7, 6 -> fT2d_jch_JY[1][k] = 0,1,2,3,4
01047       for(Int_t k=15;k>=11;k--){fT2d_jch_JY[1][k] = 15-k;}  //  k = 15,14,13,12,11 -> fT2d_jch_JY[1][k] = 0,1,2,3,4
01048       for(Int_t k=20;k>=16;k--){fT2d_jch_JY[1][k] = 20-k;}  //  k = 20,19,18,17,16 -> fT2d_jch_JY[1][k] = 0,1,2,3,4
01049       for(Int_t k=25;k>=21;k--){fT2d_jch_JY[1][k] = 25-k;}  //  k = 25,24,23,22,21 -> fT2d_jch_JY[1][k] = 0,1,2,3,4
01050       //................. bottom/left
01051       for(Int_t k= 1;k<=5; k++){fT2d_jch_JY[2][k] = 0;}     //  k =  1, 2, 3, 4, 5 -> fT2d_jch_JY[2][k] = 0
01052       for(Int_t k= 6;k<=10;k++){fT2d_jch_JY[2][k] = 1;}     //  k =  6, 7, 8, 9,10 -> fT2d_jch_JY[2][k] = 1
01053       for(Int_t k=11;k<=15;k++){fT2d_jch_JY[2][k] = 2;}     //  k = 11,12,13,14,15 -> fT2d_jch_JY[2][k] = 2
01054       for(Int_t k=16;k<=20;k++){fT2d_jch_JY[2][k] = 3;}     //  k = 16,17,18,19,20 -> fT2d_jch_JY[2][k] = 3
01055       for(Int_t k=21;k<=25;k++){fT2d_jch_JY[2][k] = 4;}     //  k = 21,22,23,24,25 -> fT2d_jch_JY[2][k] = 4
01056       //................. bottom/right
01057       for(Int_t k= 1;k<=5; k++){fT2d_jch_JY[3][k] = k-1;}   //  k =  1, 2, 3, 4, 5 -> fT2d_jch_JY[3][k] = 0,1,2,3,4
01058       for(Int_t k= 6;k<=10;k++){fT2d_jch_JY[3][k] = k-6;}   //  k =  6, 7, 8, 9,10 -> fT2d_jch_JY[3][k] = 0,1,2,3,4
01059       for(Int_t k=11;k<=15;k++){fT2d_jch_JY[3][k] = k-11;}  //  k = 11,12,13,14,15 -> fT2d_jch_JY[3][k] = 0,1,2,3,4
01060       for(Int_t k=16;k<=20;k++){fT2d_jch_JY[3][k] = k-16;}  //  k = 16,17,18,19,20 -> fT2d_jch_JY[3][k] = 0,1,2,3,4
01061       for(Int_t k=21;k<=25;k++){fT2d_jch_JY[3][k] = k-21;}  //  k = 21,22,23,24,25 -> fT2d_jch_JY[3][k] = 0,1,2,3,4
01062 
01063       //      Int_t fT2d_ich_IX[type][Echa+1]:  IX in the SC as a function of type and Echa+1
01064       fT2d_ich_IX = new Int_t*[MaxTyp];                      fCnew++;  
01065       fT1d_ich_IX = new Int_t[MaxTyp*MaxCrysP1];             fCnew++;
01066       for(Int_t i_MaxTyp = 0 ; i_MaxTyp < MaxTyp ; i_MaxTyp++){
01067         fT2d_ich_IX[i_MaxTyp] = &fT1d_ich_IX[0] + i_MaxTyp*MaxCrysP1;}
01068 
01069       //................. top/right
01070       for(Int_t k= 5;k>= 1;k--){fT2d_ich_IX[0][k] =  5-k;}  //  k =  5, 4, 3, 2, 1 -> fT2d_ich_IX[0][k] = 0,1,2,3,4
01071       for(Int_t k=10;k>= 6;k--){fT2d_ich_IX[0][k] = 10-k;}  //  k = 10, 9, 8, 7, 6 -> fT2d_ich_IX[0][k] = 0,1,2,3,4
01072       for(Int_t k=15;k>=11;k--){fT2d_ich_IX[0][k] = 15-k;}  //  k = 15,14,13,12,11 -> fT2d_ich_IX[0][k] = 0,1,2,3,4
01073       for(Int_t k=20;k>=16;k--){fT2d_ich_IX[0][k] = 20-k;}  //  k = 20,19,18,17,16 -> fT2d_ich_IX[0][k] = 0,1,2,3,4
01074       for(Int_t k=25;k>=21;k--){fT2d_ich_IX[0][k] = 25-k;}  //  k = 25,24,23,22,21 -> fT2d_ich_IX[0][k] = 0,1,2,3,4
01075       //................. top/left      
01076       for(Int_t k= 5;k>= 1;k--){fT2d_ich_IX[1][k] = 4;}     //  k =  5, 4, 3, 2, 1 -> fT2d_ich_IX[1][k] = 4
01077       for(Int_t k=10;k>= 6;k--){fT2d_ich_IX[1][k] = 3;}     //  k = 10, 9, 8, 7, 6 -> fT2d_ich_IX[1][k] = 3
01078       for(Int_t k=15;k>=11;k--){fT2d_ich_IX[1][k] = 2;}     //  k = 15,14,13,12,11 -> fT2d_ich_IX[1][k] = 2
01079       for(Int_t k=20;k>=16;k--){fT2d_ich_IX[1][k] = 1;}     //  k = 20,19,18,17,16 -> fT2d_ich_IX[1][k] = 1
01080       for(Int_t k=25;k>=21;k--){fT2d_ich_IX[1][k] = 0;}     //  k = 25,24,23,22,21 -> fT2d_ich_IX[1][k] = 0
01081       //................. bottom/left
01082       for(Int_t k=1; k<=5; k++){fT2d_ich_IX[2][k] =  5-k;}  //  k =  1, 2, 3, 4, 5 -> fT2d_ich_IX[2][k] = 0,1,2,3,4
01083       for(Int_t k=6; k<=10;k++){fT2d_ich_IX[2][k] = 10-k;}  //  k =  6, 7, 8, 9,10 -> fT2d_ich_IX[2][k] = 0,1,2,3,4
01084       for(Int_t k=11;k<=15;k++){fT2d_ich_IX[2][k] = 15-k;}  //  k = 11,12,13,14,15 -> fT2d_ich_IX[2][k] = 0,1,2,3,4
01085       for(Int_t k=16;k<=20;k++){fT2d_ich_IX[2][k] = 20-k;}  //  k = 16,17,18,19,20 -> fT2d_ich_IX[2][k] = 0,1,2,3,4
01086       for(Int_t k=21;k<=25;k++){fT2d_ich_IX[2][k] = 25-k;}  //  k = 21,22,23,24,25 -> fT2d_ich_IX[2][k] = 0,1,2,3,4
01087       //................. bottom/right      
01088       for(Int_t k= 1;k<= 5;k++){fT2d_ich_IX[3][k] = 4;}     //  k =  1, 2, 3, 4, 5 -> fT2d_ich_IX[3][k] = 4
01089       for(Int_t k= 6;k<=10;k++){fT2d_ich_IX[3][k] = 3;}     //  k =  6, 7, 8, 9,10 -> fT2d_ich_IX[3][k] = 3
01090       for(Int_t k=11;k<=15;k++){fT2d_ich_IX[3][k] = 2;}     //  k = 11,12,13,14,15 -> fT2d_ich_IX[3][k] = 2
01091       for(Int_t k=16;k<=20;k++){fT2d_ich_IX[3][k] = 1;}     //  k = 16,17,18,19,20 -> fT2d_ich_IX[3][k] = 1
01092       for(Int_t k=21;k<=25;k++){fT2d_ich_IX[3][k] = 0;}     //  k = 21,22,23,24,25 -> fT2d_ich_IX[3][k] = 0
01093 
01094       //............................................ type
01095       Int_t  Nb_DeeSC_JY  = fEcal->MaxSCIYInDee();      
01096       Int_t** type    = new Int_t*[Nb_DeeSC_JY];                   fCnew++; 
01097       Int_t*  type_d1 = new Int_t[Nb_DeeSC_JY*MaxDirections];      fCnew++;  
01098       for(Int_t i_DeeSC_JY = 0 ; i_DeeSC_JY < Nb_DeeSC_JY ; i_DeeSC_JY++){
01099         type[i_DeeSC_JY] = &type_d1[0] + i_DeeSC_JY*MaxDirections;}
01100 
01101       //  bottom = (0,9), top  = (10,19)
01102       //  right  = 0    , left = 1
01103       //  type = Quadrant number - 1
01104 
01105       type[10][0] = 0;                   // Q1 top right
01106       type[11][0] = 0;
01107       type[12][0] = 0;
01108       type[13][0] = 0;
01109       type[14][0] = 0;
01110       type[15][0] = 0;
01111       type[16][0] = 0;
01112       type[17][0] = 0;
01113       type[18][0] = 0;
01114       type[19][0] = 0;
01115  
01116       type[10][1] = 1;                   // Q2 top left    
01117       type[11][1] = 1;
01118       type[12][1] = 1;
01119       type[13][1] = 1;
01120       type[14][1] = 1;
01121       type[15][1] = 1;
01122       type[16][1] = 1;
01123       type[17][1] = 1;
01124       type[18][1] = 1;
01125       type[19][1] = 1;
01126 
01127       type[ 0][1] = 2;                   // Q3 : bottom left 
01128       type[ 1][1] = 2;
01129       type[ 2][1] = 2;
01130       type[ 3][1] = 2;
01131       type[ 4][1] = 2;
01132       type[ 5][1] = 2;
01133       type[ 6][1] = 2;
01134       type[ 7][1] = 2;
01135       type[ 8][1] = 2;
01136       type[ 9][1] = 2;
01137  
01138       type[ 0][0] = 3;                   // Q4 : bottom right 
01139       type[ 1][0] = 3;
01140       type[ 2][0] = 3;
01141       type[ 3][0] = 3;
01142       type[ 4][0] = 3;
01143       type[ 5][0] = 3;
01144       type[ 6][0] = 3;
01145       type[ 7][0] = 3;
01146       type[ 8][0] = 3;
01147       type[ 9][0] = 3;
01148 
01149       Int_t Nb_SCCrys_IX = fEcal->MaxCrysIXInSC();
01150       Int_t Nb_SCCrys_JY = fEcal->MaxCrysIYInSC();
01151 
01152       for(Int_t kSC=0; kSC<MaxDeeSC; kSC++)                   //  kSC  = 0 to 199   (MaxDeeSC = 200)
01153         {
01154           for(Int_t n_Echa=1; n_Echa<=MaxSCEcha; n_Echa++)       //  n_Echa   = 1 to 25    (MaxSCEcha = 25) 
01155             {
01156               for(Int_t idir=0; idir<2; idir++)
01157                 {
01158                   Int_t ikSC = kSC / Nb_DeeSC_JY;                 //  ikSC = 0 to 9
01159                   Int_t jkSC = kSC % Nb_DeeSC_JY;                 //  jkSC = 0,1,2,..,19 
01160                   
01161                   Int_t icrys = ikSC*Nb_SCCrys_IX + fT2d_ich_IX[type[jkSC][idir]][n_Echa];
01162                   //  type[0->9][1->2] = 0,1,2,3
01163                   //  fT2d_ich_IX[0->3][1->25] = 0,1,2,3,4
01164                   //  icrys = 0 to 49  (=> IX)
01165                   
01166                   Int_t jcrys = jkSC*Nb_SCCrys_JY + fT2d_jch_JY[type[jkSC][idir]][n_Echa];
01167                   //  type[0->9][1->2] = 0,1,2,3
01168                   //  fT2d_jch_JY[0->3][1->25] = 0,1,2,3,4
01169                   //  jcrys = 0 to 99  (=> IY)
01170                   
01171                   Int_t n_DeeCrys = icrys*Nb_DeeSC_JY*Nb_SCCrys_JY+jcrys+1;    //  n_DeeCrys = 1 to 5000
01172                   
01173                   fT3dDeeCrys[kSC][n_Echa-1][idir] = n_DeeCrys;   // fT3dDeeCrys[][][] : range = [1,5000]
01174                   fT2dDeeSC[n_DeeCrys-1][idir]     = kSC+1;       // fT2dDeeSC[][]     : range = [1,200]
01175                   fT2dSCEcha[n_DeeCrys-1][idir]    = n_Echa;      // fT2dSCEcha[][]    : range = [1,25]
01176                 }
01177             }
01178         }
01179       // cout << "#TEcnaNumbering::TBuildEndcapCrysTable()> Crys Table Building done" << endl;
01180 
01181       delete [] type;                           fCdelete++;
01182       delete [] type_d1;                        fCdelete++;
01183     }
01184   else
01185     {
01186       // cout << "#TEcnaNumbering::TBuildEndcapCrysTable()> No Building of Crys Table since it is already done " << endl;
01187     }
01188 }
01189 
01190 void TEcnaNumbering::BuildEndcapSCTable()
01191 {
01192 // Build the correspondance table: (Dee, DeeSC) <-> (DS , DSSC) for the ECAL ENDCAP
01193 //
01194 //  From CMS Internal Note  "CMS ECAL Endcap channel numbering"
01195 //
01196 //       Name       Number                     Reference set    Range     Comment
01197 //
01198 //       Dee      : Dee number                                  [1,4]
01199 //       DeeSC    : Super-Crystal (SC) number  in Dee           [1,200]   (IY,IX) progression
01200 //       DS       : Data Sector number         in EE + or -     [1,9]     (IY,IX) progression
01201 //       DSSC     : Super-Crystal (SC) number  in Data Sector   [1,32]    Crystal numbering in data sector
01202 //       DeeSCCons: Super-Crystal (SC) number  for construction [1,297]                      
01203 // 
01204 //   fill the 2d arrays:  fT2d_DS[4][200], fT2d_DSSC[4][200] and fT2d_DeeSCCons[4][200]
01205 //
01206 //------------------------------------------------------------------------------------------------------
01207 
01208 //.................. Allocations and Init
01209   Int_t MaxEEDee       = fEcal->MaxDeeInEE();
01210   Int_t MaxDeeSC       = fEcal->MaxSCEcnaInDee();
01211   Int_t MaxEESCForCons = 2*fEcal->MaxSCForConsInDee();
01212 
01213   fT2d_DS = new Int_t*[MaxEEDee];                       fCnew++;    // = DS[Dee - 1, CNA_SCInDee - 1]
01214   fT1d_DS = new  Int_t[MaxEEDee*MaxDeeSC];              fCnew++;
01215   for(Int_t i_DeeCrys = 0 ; i_DeeCrys < MaxEEDee ; i_DeeCrys++){
01216     fT2d_DS[i_DeeCrys] = &fT1d_DS[0] + i_DeeCrys*MaxDeeSC;}
01217   for(Int_t i=0; i<MaxEEDee; i++)
01218     {for(Int_t j=0; j<MaxDeeSC; j++){fT2d_DS[i][j]=0;}}
01219 
01220   fT2d_DSSC = new Int_t*[MaxEEDee];                     fCnew++;    // = SCInDS[Dee - 1, CNA_SCInDee - 1]  
01221   fT1d_DSSC = new  Int_t[MaxEEDee*MaxDeeSC];            fCnew++;
01222   for(Int_t i_DeeCrys = 0 ; i_DeeCrys < MaxEEDee ; i_DeeCrys++){
01223     fT2d_DSSC[i_DeeCrys] = &fT1d_DSSC[0] + i_DeeCrys*MaxDeeSC;}
01224   for(Int_t i=0; i<MaxEEDee; i++)
01225     {for(Int_t j=0; j<MaxDeeSC; j++){fT2d_DSSC[i][j]=0;}}
01226 
01227   fT2d_DeeSCCons = new Int_t*[MaxEEDee];                fCnew++;    // = SCConsInDee[Dee - 1, CNA_SCInDee - 1]
01228   fT1d_DeeSCCons = new  Int_t[MaxEEDee*MaxDeeSC];       fCnew++;
01229   for(Int_t i_DeeCrys = 0 ; i_DeeCrys < MaxEEDee ; i_DeeCrys++){
01230     fT2d_DeeSCCons[i_DeeCrys] = &fT1d_DeeSCCons[0] + i_DeeCrys*MaxDeeSC;}
01231   for(Int_t i=0; i<MaxEEDee; i++)
01232     {for(Int_t j=0; j<MaxDeeSC; j++){fT2d_DeeSCCons[i][j]=0;}}
01233 
01234   fT2d_RecovDeeSC = new Int_t*[MaxEEDee];               fCnew++;    // = CNA_SCInDee[Dee - 1, SCConsInDee - 1]
01235   fT1d_RecovDeeSC = new  Int_t[MaxEEDee*MaxEESCForCons];  fCnew++;
01236   for(Int_t i_DeeCrys = 0 ; i_DeeCrys < MaxEEDee ; i_DeeCrys++){
01237     fT2d_RecovDeeSC[i_DeeCrys] = &fT1d_RecovDeeSC[0] + i_DeeCrys*MaxEESCForCons;}
01238   for(Int_t i=0; i<MaxEEDee; i++)
01239     {for(Int_t j=0; j<MaxEESCForCons; j++){fT2d_RecovDeeSC[i][j]=0;}}
01240 
01241   //.............................. Data sector (DS) numbers: fT2d_DS[][]
01242   //                               isc = ECNA numbers
01243 
01244   Int_t ids = 0;
01245 
01246   //........... (D1,S1)=(D2,S9)=(D3,S9)=(D4,S1)
01247   for(Int_t dee = 1; dee<=4; dee++)
01248     {
01249       if( dee == 1 || dee == 4 ){ids = 1;}
01250       if( dee == 2 || dee == 3 ){ids = 9;}
01251       for(Int_t isc= 13; isc<= 20; isc++)fT2d_DS[dee-1][isc-1] = ids;
01252       for(Int_t isc= 33; isc<= 40; isc++)fT2d_DS[dee-1][isc-1] = ids;
01253       for(Int_t isc= 54; isc<= 60; isc++)fT2d_DS[dee-1][isc-1] = ids;
01254       for(Int_t isc= 75; isc<= 79; isc++)fT2d_DS[dee-1][isc-1] = ids;
01255       for(Int_t isc= 96; isc<= 99; isc++)fT2d_DS[dee-1][isc-1] = ids;
01256       for(Int_t isc=118; isc<=119; isc++)fT2d_DS[dee-1][isc-1] = ids;
01257     }
01258   //........... (D1,S2)=(D2,S8)=(D3,S8)=(D4,S2)
01259   for(Int_t dee = 1; dee<=4; dee++)
01260     {
01261       if( dee == 1 || dee == 4 ){ids = 2;}
01262       if( dee == 2 || dee == 3 ){ids = 8;}
01263       for(Int_t isc= 32; isc<= 32; isc++)fT2d_DS[dee-1][isc-1] = ids;
01264       for(Int_t isc= 51; isc<= 53; isc++)fT2d_DS[dee-1][isc-1] = ids;
01265       for(Int_t isc= 72; isc<= 74; isc++)fT2d_DS[dee-1][isc-1] = ids;
01266       for(Int_t isc= 92; isc<= 95; isc++)fT2d_DS[dee-1][isc-1] = ids;
01267       for(Int_t isc=112; isc<=117; isc++)fT2d_DS[dee-1][isc-1] = ids;
01268       for(Int_t isc=132; isc<=138; isc++)fT2d_DS[dee-1][isc-1] = ids;
01269       for(Int_t isc=152; isc<=157; isc++)fT2d_DS[dee-1][isc-1] = ids;
01270       for(Int_t isc=173; isc<=176; isc++)fT2d_DS[dee-1][isc-1] = ids;
01271       for(Int_t isc=193; isc<=193; isc++)fT2d_DS[dee-1][isc-1] = ids;
01272     }
01273   //........... (D1,S3)=(D2,S7)=(D3,S7)=(D4,S3)
01274   for(Int_t dee = 1; dee<=4; dee++)
01275     {
01276       if( dee == 1 || dee == 4 ){ids = 3;}
01277       if( dee == 2 || dee == 3 ){ids = 7;}
01278       for(Int_t isc= 50; isc<= 50; isc++)fT2d_DS[dee-1][isc-1] = ids;
01279       for(Int_t isc= 69; isc<= 71; isc++)fT2d_DS[dee-1][isc-1] = ids;
01280       for(Int_t isc= 88; isc<= 91; isc++)fT2d_DS[dee-1][isc-1] = ids;
01281       for(Int_t isc=108; isc<=111; isc++)fT2d_DS[dee-1][isc-1] = ids;
01282       for(Int_t isc=127; isc<=131; isc++)fT2d_DS[dee-1][isc-1] = ids;
01283       for(Int_t isc=147; isc<=151; isc++)fT2d_DS[dee-1][isc-1] = ids;
01284       for(Int_t isc=166; isc<=172; isc++)fT2d_DS[dee-1][isc-1] = ids;
01285       for(Int_t isc=188; isc<=192; isc++)fT2d_DS[dee-1][isc-1] = ids;
01286     }
01287   //........... (D1,S4)=(D2,S6)=(D3,S6)=(D4,S4)
01288   for(Int_t dee = 1; dee<=4; dee++)
01289     {
01290       if( dee == 1 || dee == 4 ){ids = 4;}
01291       if( dee == 2 || dee == 3 ){ids = 6;}
01292       for(Int_t isc= 27; isc<= 29; isc++)fT2d_DS[dee-1][isc-1] = ids;
01293       for(Int_t isc= 44; isc<= 49; isc++)fT2d_DS[dee-1][isc-1] = ids;
01294       for(Int_t isc= 62; isc<= 68; isc++)fT2d_DS[dee-1][isc-1] = ids;
01295       for(Int_t isc= 82; isc<= 87; isc++)fT2d_DS[dee-1][isc-1] = ids;
01296       for(Int_t isc=102; isc<=107; isc++)fT2d_DS[dee-1][isc-1] = ids;
01297       for(Int_t isc=123; isc<=126; isc++)fT2d_DS[dee-1][isc-1] = ids;
01298       for(Int_t isc=144; isc<=146; isc++)fT2d_DS[dee-1][isc-1] = ids;
01299       for(Int_t isc=165; isc<=165; isc++)fT2d_DS[dee-1][isc-1] = ids;
01300     }
01301   //........... (D1,S5)=(D2,S5)=(D3,S5)=(D4,S5)
01302   for(Int_t dee = 1; dee<=4; dee++)
01303     {
01304       for(Int_t isc=  1; isc<=  8; isc++)fT2d_DS[dee-1][isc-1] = 5;
01305       for(Int_t isc= 21; isc<= 26; isc++)fT2d_DS[dee-1][isc-1] = 5;
01306       for(Int_t isc= 41; isc<= 43; isc++)fT2d_DS[dee-1][isc-1] = 5;
01307     }
01308   
01309   //............................................ SC numbers in Data Sectors: fT2d_DSSC[][]
01310   //                                             fT2d_DSSC[dee-1][SC ECNA number - 1] = SC number in DS;
01311   for(Int_t dee=1; dee<=4; dee++)
01312     {
01313       for(Int_t isc=1; isc<=MaxDeeSC; isc++)
01314         {fT2d_DSSC[dee-1][isc-1] = -1;}
01315       //.......................................... S1 (D1,D4), S9 (D2,D3) ; 33 SC's
01316       fT2d_DSSC[dee-1][13-1] = 12;
01317       fT2d_DSSC[dee-1][14-1] = 11;
01318       fT2d_DSSC[dee-1][15-1] = 10;
01319       fT2d_DSSC[dee-1][16-1] =  9;
01320       fT2d_DSSC[dee-1][17-1] =  4;
01321       fT2d_DSSC[dee-1][18-1] =  3;
01322       fT2d_DSSC[dee-1][19-1] =  2;
01323       fT2d_DSSC[dee-1][20-1] =  1;
01324 
01325       fT2d_DSSC[dee-1][33-1] = 16;
01326       fT2d_DSSC[dee-1][34-1] = 15;
01327       fT2d_DSSC[dee-1][35-1] = 14;
01328       fT2d_DSSC[dee-1][36-1] = 13;
01329       fT2d_DSSC[dee-1][37-1] =  8;
01330       fT2d_DSSC[dee-1][38-1] =  7;
01331       fT2d_DSSC[dee-1][39-1] =  6;
01332       fT2d_DSSC[dee-1][40-1] =  5;
01333 
01334       fT2d_DSSC[dee-1][54-1] = 33;
01335       fT2d_DSSC[dee-1][55-1] = 31;
01336       fT2d_DSSC[dee-1][56-1] = 27;
01337       fT2d_DSSC[dee-1][57-1] = 24;
01338       fT2d_DSSC[dee-1][58-1] = 20;
01339       fT2d_DSSC[dee-1][59-1] = 17;
01340       fT2d_DSSC[dee-1][60-1] = 30;  //  (182a, 33a for construction)
01341       
01342       fT2d_DSSC[dee-1][75-1] = 32;
01343       fT2d_DSSC[dee-1][76-1] = 28;
01344       fT2d_DSSC[dee-1][77-1] = 25;
01345       fT2d_DSSC[dee-1][78-1] = 21;
01346       fT2d_DSSC[dee-1][79-1] = 18;
01347       
01348       fT2d_DSSC[dee-1][96-1] = 29;
01349       fT2d_DSSC[dee-1][97-1] = 26;
01350       fT2d_DSSC[dee-1][98-1] = 22;
01351       fT2d_DSSC[dee-1][99-1] = 19;
01352 
01353       fT2d_DSSC[dee-1][118-1] = 23;
01354       fT2d_DSSC[dee-1][119-1] = 30;  //  (182b, 33b for construction)
01355 
01356       //.......................................... S2 (D1,D4), S8(D2,D3) ; 32 SC's
01357       fT2d_DSSC[dee-1][32-1] = 25;  // also 3;  // ( (207c, 58c) also (178c, 29c) for construction)
01358 
01359       fT2d_DSSC[dee-1][51-1] = 32;
01360       fT2d_DSSC[dee-1][52-1] = 26;
01361       fT2d_DSSC[dee-1][53-1] = 18;
01362 
01363       fT2d_DSSC[dee-1][72-1] = 27;
01364       fT2d_DSSC[dee-1][73-1] = 19;
01365       fT2d_DSSC[dee-1][74-1] = 12;
01366       
01367       fT2d_DSSC[dee-1][92-1] = 28;
01368       fT2d_DSSC[dee-1][93-1] = 20;
01369       fT2d_DSSC[dee-1][94-1] = 13;
01370       fT2d_DSSC[dee-1][95-1] =  7;
01371 
01372       fT2d_DSSC[dee-1][112-1] = 29;
01373       fT2d_DSSC[dee-1][113-1] = 21;
01374       fT2d_DSSC[dee-1][114-1] = 14;
01375       fT2d_DSSC[dee-1][115-1] =  8;
01376       fT2d_DSSC[dee-1][116-1] =  4;
01377       fT2d_DSSC[dee-1][117-1] =  1;
01378 
01379       fT2d_DSSC[dee-1][132-1] = 30;
01380       fT2d_DSSC[dee-1][133-1] = 22;
01381       fT2d_DSSC[dee-1][134-1] = 15;
01382       fT2d_DSSC[dee-1][135-1] =  9;
01383       fT2d_DSSC[dee-1][136-1] =  5;
01384       fT2d_DSSC[dee-1][137-1] =  2;
01385       fT2d_DSSC[dee-1][138-1] =  3;  // (178a, 29a for construction)
01386 
01387       fT2d_DSSC[dee-1][152-1] = 31;
01388       fT2d_DSSC[dee-1][153-1] = 23;
01389       fT2d_DSSC[dee-1][154-1] = 16;
01390       fT2d_DSSC[dee-1][155-1] = 10;
01391       fT2d_DSSC[dee-1][156-1] =  6;
01392       fT2d_DSSC[dee-1][157-1] =  3;  // (178b, 29b for construction)
01393 
01394       fT2d_DSSC[dee-1][173-1] = 24;
01395       fT2d_DSSC[dee-1][174-1] = 17;
01396       fT2d_DSSC[dee-1][175-1] = 11;
01397       fT2d_DSSC[dee-1][176-1] = 25;  // (207a, 58a for construction)
01398 
01399       fT2d_DSSC[dee-1][193-1] = 25;  // (207b, 58b for construction)
01400 
01401       //.......................................... S3 (D1,D4), S7 (D2,D3)  ; 34 SC's
01402       fT2d_DSSC[dee-1][50-1] = 10;
01403 
01404       fT2d_DSSC[dee-1][69-1] = 18;
01405       fT2d_DSSC[dee-1][70-1] = 11;
01406       fT2d_DSSC[dee-1][71-1] =  3;
01407 
01408       fT2d_DSSC[dee-1][88-1] = 25;
01409       fT2d_DSSC[dee-1][89-1] = 19;
01410       fT2d_DSSC[dee-1][90-1] = 12;
01411       fT2d_DSSC[dee-1][91-1] =  4;
01412 
01413       fT2d_DSSC[dee-1][108-1] = 26;
01414       fT2d_DSSC[dee-1][109-1] = 20;
01415       fT2d_DSSC[dee-1][110-1] = 13;
01416       fT2d_DSSC[dee-1][111-1] =  5;
01417 
01418       fT2d_DSSC[dee-1][127-1] = 31;
01419       fT2d_DSSC[dee-1][128-1] = 27;
01420       fT2d_DSSC[dee-1][129-1] = 21;
01421       fT2d_DSSC[dee-1][130-1] = 14;
01422       fT2d_DSSC[dee-1][131-1] =  6;
01423 
01424       fT2d_DSSC[dee-1][147-1] = 32;
01425       fT2d_DSSC[dee-1][148-1] = 28;
01426       fT2d_DSSC[dee-1][149-1] = 22;
01427       fT2d_DSSC[dee-1][150-1] = 15;
01428       fT2d_DSSC[dee-1][151-1] =  7;
01429 
01430       fT2d_DSSC[dee-1][166-1] = 33;
01431       fT2d_DSSC[dee-1][167-1] = 30;
01432       fT2d_DSSC[dee-1][168-1] = 29;
01433       fT2d_DSSC[dee-1][169-1] = 23;
01434       fT2d_DSSC[dee-1][170-1] = 16;
01435       fT2d_DSSC[dee-1][171-1] =  8;
01436       fT2d_DSSC[dee-1][172-1] =  1;
01437 
01438       fT2d_DSSC[dee-1][188-1] = 34; // (298a, 149a for construction)
01439       fT2d_DSSC[dee-1][189-1] = 24;
01440       fT2d_DSSC[dee-1][190-1] = 17;
01441       fT2d_DSSC[dee-1][191-1] =  9;
01442       fT2d_DSSC[dee-1][192-1] =  2;
01443 
01444       //.......................................... S4 (D1,D4), S6 (D2,D3) ; 33 SC's
01445       fT2d_DSSC[dee-1][27-1] = 33;
01446       fT2d_DSSC[dee-1][28-1] = 32;
01447       fT2d_DSSC[dee-1][29-1] = 14; // also 21;  //  ( (261a, 112a) also (268a, 119a) for construction)
01448 
01449       fT2d_DSSC[dee-1][44-1] = 22;
01450       fT2d_DSSC[dee-1][45-1] = 15;
01451       fT2d_DSSC[dee-1][46-1] =  8;
01452       fT2d_DSSC[dee-1][47-1] =  4;
01453       fT2d_DSSC[dee-1][48-1] =  2;
01454       fT2d_DSSC[dee-1][49-1] =  1;
01455 
01456       fT2d_DSSC[dee-1][62-1] = 29;
01457       fT2d_DSSC[dee-1][63-1] = 28;
01458       fT2d_DSSC[dee-1][64-1] = 23;
01459       fT2d_DSSC[dee-1][65-1] = 16;
01460       fT2d_DSSC[dee-1][66-1] =  9;
01461       fT2d_DSSC[dee-1][67-1] =  5;
01462       fT2d_DSSC[dee-1][68-1] =  3;
01463 
01464       fT2d_DSSC[dee-1][82-1] = 31;
01465       fT2d_DSSC[dee-1][83-1] = 30;
01466       fT2d_DSSC[dee-1][84-1] = 24;
01467       fT2d_DSSC[dee-1][85-1] = 17;
01468       fT2d_DSSC[dee-1][86-1] = 10;
01469       fT2d_DSSC[dee-1][87-1] =  6;
01470 
01471       fT2d_DSSC[dee-1][102-1] = 21;  //   (268c, 119c for construction)
01472       fT2d_DSSC[dee-1][103-1] = 27;
01473       fT2d_DSSC[dee-1][104-1] = 25;
01474       fT2d_DSSC[dee-1][105-1] = 18;
01475       fT2d_DSSC[dee-1][106-1] = 11;
01476       fT2d_DSSC[dee-1][107-1] =  7;
01477 
01478       fT2d_DSSC[dee-1][123-1] = 21;  //   (268b, 119b for construction)
01479       fT2d_DSSC[dee-1][124-1] = 26;
01480       fT2d_DSSC[dee-1][125-1] = 19;
01481       fT2d_DSSC[dee-1][126-1] = 12;
01482 
01483       fT2d_DSSC[dee-1][144-1] = 14;  //   (261c, 112c for construction)
01484       fT2d_DSSC[dee-1][145-1] = 20;
01485       fT2d_DSSC[dee-1][146-1] = 13;
01486 
01487       fT2d_DSSC[dee-1][165-1] = 14;  //   (261b, 112b for construction)
01488 
01489       //.......................................... S5   (2*17 = 34 SC's)
01490       if(dee == 1 || dee == 3)
01491         {
01492           fT2d_DSSC[dee-1][1-1] = 34;
01493           fT2d_DSSC[dee-1][2-1] = 33;
01494           fT2d_DSSC[dee-1][3-1] = 32;
01495           fT2d_DSSC[dee-1][4-1] = 31;
01496           fT2d_DSSC[dee-1][5-1] = 26;
01497           fT2d_DSSC[dee-1][6-1] = 25;
01498           fT2d_DSSC[dee-1][7-1] = 24;
01499           fT2d_DSSC[dee-1][8-1] = 23;
01500 
01501           fT2d_DSSC[dee-1][21-1] = 30;
01502           fT2d_DSSC[dee-1][22-1] = 29;
01503           fT2d_DSSC[dee-1][23-1] = 28;
01504           fT2d_DSSC[dee-1][24-1] = 27;
01505           fT2d_DSSC[dee-1][25-1] = 22;
01506           fT2d_DSSC[dee-1][26-1] = 21;
01507 
01508           fT2d_DSSC[dee-1][41-1] = 20;  //   (281a for construction)
01509           fT2d_DSSC[dee-1][42-1] = 19;
01510           fT2d_DSSC[dee-1][43-1] = 18;
01511         }
01512 
01513       if(dee == 2 || dee == 4)
01514         {
01515           fT2d_DSSC[dee-1][1-1] = 17;
01516           fT2d_DSSC[dee-1][2-1] = 16;
01517           fT2d_DSSC[dee-1][3-1] = 15;
01518           fT2d_DSSC[dee-1][4-1] = 14;
01519           fT2d_DSSC[dee-1][5-1] =  9;
01520           fT2d_DSSC[dee-1][6-1] =  8;
01521           fT2d_DSSC[dee-1][7-1] =  7;
01522           fT2d_DSSC[dee-1][8-1] =  6;
01523 
01524           fT2d_DSSC[dee-1][21-1] = 13;
01525           fT2d_DSSC[dee-1][22-1] = 12;
01526           fT2d_DSSC[dee-1][23-1] = 11;
01527           fT2d_DSSC[dee-1][24-1] = 10;
01528           fT2d_DSSC[dee-1][25-1] =  5;
01529           fT2d_DSSC[dee-1][26-1] =  4;
01530 
01531           fT2d_DSSC[dee-1][41-1] = 3;  //   (132a for construction)
01532           fT2d_DSSC[dee-1][42-1] = 2;
01533           fT2d_DSSC[dee-1][43-1] = 1;
01534         }
01535     }
01536   //............................... Numbers for construction: fT2d_DeeSCCons[][]
01537   //                                fT2d_DeeSCCons[dee-1][SC ECNA number - 1] = SC number for construction;
01538 
01539   //............................... init to -1
01540   for(Int_t dee=1; dee<=4; dee++)
01541     {for(Int_t isc=1; isc<=MaxDeeSC; isc++)
01542         {fT2d_DeeSCCons[dee-1][isc-1] = -1;}}
01543 
01544   for(Int_t i_dee_type=1; i_dee_type<=2; i_dee_type++)
01545     {
01546       Int_t dee = -1;
01547       if( i_dee_type == 1 ){dee = 1;}
01548       if( i_dee_type == 2 ){dee = 3;}
01549       
01550       //.......................................... (D1,S1 or D3,S9) AND (D2,S9 or D4,S1)
01551       //  number in comment = fT2d_DSSC[dee-1][SC ECNA nb - 1] (= SC number in DS)
01552       fT2d_DeeSCCons[dee-1][13-1] = 161; fT2d_DeeSCCons[dee][13-1] = 12; // 12;
01553       fT2d_DeeSCCons[dee-1][14-1] = 160; fT2d_DeeSCCons[dee][14-1] = 11; // 11;
01554       fT2d_DeeSCCons[dee-1][15-1] = 159; fT2d_DeeSCCons[dee][15-1] = 10; // 10;
01555       fT2d_DeeSCCons[dee-1][16-1] = 158; fT2d_DeeSCCons[dee][16-1] =  9; //  9;
01556       fT2d_DeeSCCons[dee-1][17-1] = 153; fT2d_DeeSCCons[dee][17-1] =  4; //  4;
01557       fT2d_DeeSCCons[dee-1][18-1] = 152; fT2d_DeeSCCons[dee][18-1] =  3; //  3;
01558       fT2d_DeeSCCons[dee-1][19-1] = 151; fT2d_DeeSCCons[dee][19-1] =  2; //  2;
01559       fT2d_DeeSCCons[dee-1][20-1] = 150; fT2d_DeeSCCons[dee][20-1] =  1; //  1;
01560       
01561       fT2d_DeeSCCons[dee-1][33-1] = 165; fT2d_DeeSCCons[dee][33-1] = 16; // 16;
01562       fT2d_DeeSCCons[dee-1][34-1] = 164; fT2d_DeeSCCons[dee][34-1] = 15; // 15;
01563       fT2d_DeeSCCons[dee-1][35-1] = 163; fT2d_DeeSCCons[dee][35-1] = 14; // 14;
01564       fT2d_DeeSCCons[dee-1][36-1] = 162; fT2d_DeeSCCons[dee][36-1] = 13; // 13;
01565       fT2d_DeeSCCons[dee-1][37-1] = 157; fT2d_DeeSCCons[dee][37-1] =  8; //  8;
01566       fT2d_DeeSCCons[dee-1][38-1] = 156; fT2d_DeeSCCons[dee][38-1] =  7; //  7;
01567       fT2d_DeeSCCons[dee-1][39-1] = 155; fT2d_DeeSCCons[dee][39-1] =  6; //  6;
01568       fT2d_DeeSCCons[dee-1][40-1] = 154; fT2d_DeeSCCons[dee][40-1] =  5; //  5;
01569       
01570       fT2d_DeeSCCons[dee-1][54-1] = 193; fT2d_DeeSCCons[dee][54-1] = 44; // 33; 
01571       fT2d_DeeSCCons[dee-1][55-1] = 186; fT2d_DeeSCCons[dee][55-1] = 37; // 31;
01572       fT2d_DeeSCCons[dee-1][56-1] = 179; fT2d_DeeSCCons[dee][56-1] = 30; // 27;
01573       fT2d_DeeSCCons[dee-1][57-1] = 173; fT2d_DeeSCCons[dee][57-1] = 24; // 24;
01574       fT2d_DeeSCCons[dee-1][58-1] = 169; fT2d_DeeSCCons[dee][58-1] = 20; // 20;
01575       fT2d_DeeSCCons[dee-1][59-1] = 166; fT2d_DeeSCCons[dee][59-1] = 17; // 17;
01576       fT2d_DeeSCCons[dee-1][60-1] = 182; fT2d_DeeSCCons[dee][60-1] = 33; // 30;    // 182a ;  33a;
01577 
01578       fT2d_DeeSCCons[dee-1][75-1] = 187; fT2d_DeeSCCons[dee][75-1] = 38; // 32;
01579       fT2d_DeeSCCons[dee-1][76-1] = 180; fT2d_DeeSCCons[dee][76-1] = 31; // 28;
01580       fT2d_DeeSCCons[dee-1][77-1] = 174; fT2d_DeeSCCons[dee][77-1] = 25; // 25;
01581       fT2d_DeeSCCons[dee-1][78-1] = 170; fT2d_DeeSCCons[dee][78-1] = 21; // 21;
01582       fT2d_DeeSCCons[dee-1][79-1] = 167; fT2d_DeeSCCons[dee][79-1] = 18; // 18;
01583       
01584       fT2d_DeeSCCons[dee-1][96-1] = 181; fT2d_DeeSCCons[dee][96-1] = 32; // 29;
01585       fT2d_DeeSCCons[dee-1][97-1] = 175; fT2d_DeeSCCons[dee][97-1] = 26; // 26;
01586       fT2d_DeeSCCons[dee-1][98-1] = 171; fT2d_DeeSCCons[dee][98-1] = 22; // 22;
01587       fT2d_DeeSCCons[dee-1][99-1] = 168; fT2d_DeeSCCons[dee][99-1] = 19; // 19;
01588       
01589       fT2d_DeeSCCons[dee-1][118-1] = 172; fT2d_DeeSCCons[dee][118-1] = 23; // 23;
01590       fT2d_DeeSCCons[dee-1][119-1] = 182; fT2d_DeeSCCons[dee][119-1] = 33; // 30;    // 182b ;  33b;
01591      
01592       //.......................................... (D1,S2 or D3,S8) AND (D2,S8 or D4,S2)
01593       fT2d_DeeSCCons[dee-1][32-1] = 178; fT2d_DeeSCCons[dee][32-1] = 29; // 25-3;   // 178c-207c ; 29c-58c;
01594 
01595       fT2d_DeeSCCons[dee-1][51-1] = 216; fT2d_DeeSCCons[dee][51-1] = 67; // 32;
01596       fT2d_DeeSCCons[dee-1][52-1] = 208; fT2d_DeeSCCons[dee][52-1] = 59; // 26;
01597       fT2d_DeeSCCons[dee-1][53-1] = 200; fT2d_DeeSCCons[dee][53-1] = 51; // 18;
01598       
01599       fT2d_DeeSCCons[dee-1][72-1] = 209; fT2d_DeeSCCons[dee][72-1] = 60; // 27;
01600       fT2d_DeeSCCons[dee-1][73-1] = 201; fT2d_DeeSCCons[dee][73-1] = 52; // 19;
01601       fT2d_DeeSCCons[dee-1][74-1] = 194; fT2d_DeeSCCons[dee][74-1] = 45; // 12;
01602       
01603       fT2d_DeeSCCons[dee-1][92-1] = 210; fT2d_DeeSCCons[dee][92-1] = 61; // 28;
01604       fT2d_DeeSCCons[dee-1][93-1] = 202; fT2d_DeeSCCons[dee][93-1] = 53; // 20;
01605       fT2d_DeeSCCons[dee-1][94-1] = 195; fT2d_DeeSCCons[dee][94-1] = 46; // 13;
01606       fT2d_DeeSCCons[dee-1][95-1] = 188; fT2d_DeeSCCons[dee][95-1] = 39; //  7;
01607       
01608       fT2d_DeeSCCons[dee-1][112-1] = 211; fT2d_DeeSCCons[dee][112-1] = 62; // 29;
01609       fT2d_DeeSCCons[dee-1][113-1] = 203; fT2d_DeeSCCons[dee][113-1] = 54; // 21;
01610       fT2d_DeeSCCons[dee-1][114-1] = 196; fT2d_DeeSCCons[dee][114-1] = 47; // 14;
01611       fT2d_DeeSCCons[dee-1][115-1] = 189; fT2d_DeeSCCons[dee][115-1] = 40; //  8;
01612       fT2d_DeeSCCons[dee-1][116-1] = 183; fT2d_DeeSCCons[dee][116-1] = 34; //  4;
01613       fT2d_DeeSCCons[dee-1][117-1] = 176; fT2d_DeeSCCons[dee][117-1] = 27; //  1;
01614       
01615       fT2d_DeeSCCons[dee-1][132-1] = 212; fT2d_DeeSCCons[dee][132-1] = 63; // 30;
01616       fT2d_DeeSCCons[dee-1][133-1] = 204; fT2d_DeeSCCons[dee][133-1] = 55; // 22;
01617       fT2d_DeeSCCons[dee-1][134-1] = 197; fT2d_DeeSCCons[dee][134-1] = 48; // 15;
01618       fT2d_DeeSCCons[dee-1][135-1] = 190; fT2d_DeeSCCons[dee][135-1] = 41; //  9;
01619       fT2d_DeeSCCons[dee-1][136-1] = 184; fT2d_DeeSCCons[dee][136-1] = 35; //  5;
01620       fT2d_DeeSCCons[dee-1][137-1] = 177; fT2d_DeeSCCons[dee][137-1] = 28; //  2;
01621       fT2d_DeeSCCons[dee-1][138-1] = 178; fT2d_DeeSCCons[dee][138-1] = 29; //  3; //  178a ;  29a;
01622       
01623       fT2d_DeeSCCons[dee-1][152-1] = 213; fT2d_DeeSCCons[dee][152-1] = 64; // 31;
01624       fT2d_DeeSCCons[dee-1][153-1] = 205; fT2d_DeeSCCons[dee][153-1] = 56; // 23;
01625       fT2d_DeeSCCons[dee-1][154-1] = 198; fT2d_DeeSCCons[dee][154-1] = 49; // 16;
01626       fT2d_DeeSCCons[dee-1][155-1] = 191; fT2d_DeeSCCons[dee][155-1] = 42; // 10;
01627       fT2d_DeeSCCons[dee-1][156-1] = 185; fT2d_DeeSCCons[dee][156-1] = 36; //  6;
01628       fT2d_DeeSCCons[dee-1][157-1] = 178; fT2d_DeeSCCons[dee][157-1] = 29; //  3; //  178b ;  29b;
01629       
01630       fT2d_DeeSCCons[dee-1][173-1] = 206; fT2d_DeeSCCons[dee][173-1] = 57; // 24;
01631       fT2d_DeeSCCons[dee-1][174-1] = 199; fT2d_DeeSCCons[dee][174-1] = 50; // 17;
01632       fT2d_DeeSCCons[dee-1][175-1] = 192; fT2d_DeeSCCons[dee][175-1] = 43; // 11;
01633       fT2d_DeeSCCons[dee-1][176-1] = 207; fT2d_DeeSCCons[dee][176-1] = 58; // 25; //  58a ;  207a;
01634  
01635       fT2d_DeeSCCons[dee-1][193-1] = 207; fT2d_DeeSCCons[dee][193-1] = 58; // 25; //  58b ;  207b;
01636     
01637       //.......................................... (D1,S3 or D3,S7) AND  (D2,S7 or D4,S3) 
01638       fT2d_DeeSCCons[dee-1][50-1] = 224; fT2d_DeeSCCons[dee][50-1] = 75; // 10;
01639       
01640       fT2d_DeeSCCons[dee-1][69-1] = 233; fT2d_DeeSCCons[dee][69-1] = 84; // 18;
01641       fT2d_DeeSCCons[dee-1][70-1] = 225; fT2d_DeeSCCons[dee][70-1] = 76; // 11;
01642       fT2d_DeeSCCons[dee-1][71-1] = 217; fT2d_DeeSCCons[dee][71-1] = 68; //  3;
01643       
01644       fT2d_DeeSCCons[dee-1][88-1] = 242; fT2d_DeeSCCons[dee][88-1] = 93; // 25;
01645       fT2d_DeeSCCons[dee-1][89-1] = 234; fT2d_DeeSCCons[dee][89-1] = 85; // 19;
01646       fT2d_DeeSCCons[dee-1][90-1] = 226; fT2d_DeeSCCons[dee][90-1] = 77; // 12;
01647       fT2d_DeeSCCons[dee-1][91-1] = 218; fT2d_DeeSCCons[dee][91-1] = 69; //  4;
01648       
01649       fT2d_DeeSCCons[dee-1][108-1] = 243; fT2d_DeeSCCons[dee][108-1] = 94; // 26;
01650       fT2d_DeeSCCons[dee-1][109-1] = 235; fT2d_DeeSCCons[dee][109-1] = 86; // 20;
01651       fT2d_DeeSCCons[dee-1][110-1] = 227; fT2d_DeeSCCons[dee][110-1] = 78; // 13;
01652       fT2d_DeeSCCons[dee-1][111-1] = 219; fT2d_DeeSCCons[dee][111-1] = 70; //  5;
01653       
01654       fT2d_DeeSCCons[dee-1][127-1] = 252; fT2d_DeeSCCons[dee][127-1] = 103; // 31;
01655       fT2d_DeeSCCons[dee-1][128-1] = 244; fT2d_DeeSCCons[dee][128-1] =  95; // 27;
01656       fT2d_DeeSCCons[dee-1][129-1] = 236; fT2d_DeeSCCons[dee][129-1] =  87; // 21;
01657       fT2d_DeeSCCons[dee-1][130-1] = 228; fT2d_DeeSCCons[dee][130-1] =  79; // 14;
01658       fT2d_DeeSCCons[dee-1][131-1] = 220; fT2d_DeeSCCons[dee][131-1] =  71; //  6;
01659       
01660       fT2d_DeeSCCons[dee-1][147-1] = 253; fT2d_DeeSCCons[dee][147-1] = 104; // 32;
01661       fT2d_DeeSCCons[dee-1][148-1] = 245; fT2d_DeeSCCons[dee][148-1] =  96; // 28;
01662       fT2d_DeeSCCons[dee-1][149-1] = 237; fT2d_DeeSCCons[dee][149-1] =  88; // 22;
01663       fT2d_DeeSCCons[dee-1][150-1] = 229; fT2d_DeeSCCons[dee][150-1] =  80; // 15;
01664       fT2d_DeeSCCons[dee-1][151-1] = 221; fT2d_DeeSCCons[dee][151-1] =  72; //  7;
01665       
01666       fT2d_DeeSCCons[dee-1][166-1] = 254; fT2d_DeeSCCons[dee][166-1] = 105; // 33;
01667       fT2d_DeeSCCons[dee-1][167-1] = 247; fT2d_DeeSCCons[dee][167-1] =  98; // 30;
01668       fT2d_DeeSCCons[dee-1][168-1] = 246; fT2d_DeeSCCons[dee][168-1] =  97; // 29;
01669       fT2d_DeeSCCons[dee-1][169-1] = 238; fT2d_DeeSCCons[dee][169-1] =  89; // 23;
01670       fT2d_DeeSCCons[dee-1][170-1] = 230; fT2d_DeeSCCons[dee][170-1] =  81; // 16;
01671       fT2d_DeeSCCons[dee-1][171-1] = 222; fT2d_DeeSCCons[dee][171-1] =  73; //  8;
01672       fT2d_DeeSCCons[dee-1][172-1] = 214; fT2d_DeeSCCons[dee][172-1] =  65; //  1;
01673       
01674       fT2d_DeeSCCons[dee-1][188-1] = 298; fT2d_DeeSCCons[dee][188-1] = 149; // 24; //  298a ;  149a;
01675       fT2d_DeeSCCons[dee-1][189-1] = 239; fT2d_DeeSCCons[dee][189-1] =  90; // 24;
01676       fT2d_DeeSCCons[dee-1][190-1] = 231; fT2d_DeeSCCons[dee][190-1] =  82; // 17;
01677       fT2d_DeeSCCons[dee-1][191-1] = 223; fT2d_DeeSCCons[dee][191-1] =  74; //  9;
01678       fT2d_DeeSCCons[dee-1][192-1] = 215; fT2d_DeeSCCons[dee][192-1] =  66; //  2;
01679   
01680       //.......................................... (D1,S4 or D3,S6) AND  (D2,S6 or D4,S4)
01681       fT2d_DeeSCCons[dee-1][29-1] = 261; fT2d_DeeSCCons[dee][29-1] = 112; // 14-21;   // 261a-268a ; 112a-119a;
01682       fT2d_DeeSCCons[dee-1][27-1] = 283; fT2d_DeeSCCons[dee][27-1] = 134; // 33;
01683       fT2d_DeeSCCons[dee-1][28-1] = 282; fT2d_DeeSCCons[dee][28-1] = 133; // 32;
01684       
01685       fT2d_DeeSCCons[dee-1][44-1] = 269; fT2d_DeeSCCons[dee][44-1] = 120; // 22;
01686       fT2d_DeeSCCons[dee-1][45-1] = 262; fT2d_DeeSCCons[dee][45-1] = 113; // 15;
01687       fT2d_DeeSCCons[dee-1][46-1] = 255; fT2d_DeeSCCons[dee][46-1] = 106; //  8;
01688       fT2d_DeeSCCons[dee-1][47-1] = 248; fT2d_DeeSCCons[dee][47-1] =  99; //  4;
01689       fT2d_DeeSCCons[dee-1][48-1] = 240; fT2d_DeeSCCons[dee][48-1] =  91; //  2;
01690       fT2d_DeeSCCons[dee-1][49-1] = 232; fT2d_DeeSCCons[dee][49-1] =  83; //  1;
01691       
01692       fT2d_DeeSCCons[dee-1][62-1] = 276; fT2d_DeeSCCons[dee][62-1] = 127; // 29;
01693       fT2d_DeeSCCons[dee-1][63-1] = 275; fT2d_DeeSCCons[dee][63-1] = 126; // 28;
01694       fT2d_DeeSCCons[dee-1][64-1] = 270; fT2d_DeeSCCons[dee][64-1] = 121; // 23;
01695       fT2d_DeeSCCons[dee-1][65-1] = 263; fT2d_DeeSCCons[dee][65-1] = 114; // 16;
01696       fT2d_DeeSCCons[dee-1][66-1] = 256; fT2d_DeeSCCons[dee][66-1] = 107; //  9;
01697       fT2d_DeeSCCons[dee-1][67-1] = 249; fT2d_DeeSCCons[dee][67-1] = 100; //  5;
01698       fT2d_DeeSCCons[dee-1][68-1] = 241; fT2d_DeeSCCons[dee][68-1] =  92; //  3;
01699       
01700       fT2d_DeeSCCons[dee-1][82-1] = 278; fT2d_DeeSCCons[dee][82-1] = 129; // 31;
01701       fT2d_DeeSCCons[dee-1][83-1] = 277; fT2d_DeeSCCons[dee][83-1] = 128; // 30;
01702       fT2d_DeeSCCons[dee-1][84-1] = 271; fT2d_DeeSCCons[dee][84-1] = 122; // 24;
01703       fT2d_DeeSCCons[dee-1][85-1] = 264; fT2d_DeeSCCons[dee][85-1] = 115; // 17;
01704       fT2d_DeeSCCons[dee-1][86-1] = 257; fT2d_DeeSCCons[dee][86-1] = 108; // 10;
01705       fT2d_DeeSCCons[dee-1][87-1] = 250; fT2d_DeeSCCons[dee][87-1] = 101; //  6;
01706       
01707       fT2d_DeeSCCons[dee-1][102-1] = 268; fT2d_DeeSCCons[dee][102-1] = 119; // 21; //  268c ;  119c;
01708       fT2d_DeeSCCons[dee-1][103-1] = 274; fT2d_DeeSCCons[dee][103-1] = 125; // 27;
01709       fT2d_DeeSCCons[dee-1][104-1] = 272; fT2d_DeeSCCons[dee][104-1] = 123; // 25;
01710       fT2d_DeeSCCons[dee-1][105-1] = 265; fT2d_DeeSCCons[dee][105-1] = 116; // 18;
01711       fT2d_DeeSCCons[dee-1][106-1] = 258; fT2d_DeeSCCons[dee][106-1] = 109; // 11;
01712       fT2d_DeeSCCons[dee-1][107-1] = 251; fT2d_DeeSCCons[dee][107-1] = 102; //  7;
01713       
01714       fT2d_DeeSCCons[dee-1][123-1] = 268; fT2d_DeeSCCons[dee][123-1] = 119; // 27; //  268b ;  119b;
01715       fT2d_DeeSCCons[dee-1][124-1] = 273; fT2d_DeeSCCons[dee][124-1] = 124; // 26;
01716       fT2d_DeeSCCons[dee-1][125-1] = 266; fT2d_DeeSCCons[dee][125-1] = 117; // 19;
01717       fT2d_DeeSCCons[dee-1][126-1] = 259; fT2d_DeeSCCons[dee][126-1] = 110; // 12;
01718 
01719       fT2d_DeeSCCons[dee-1][144-1] = 261; fT2d_DeeSCCons[dee][144-1] = 112; // 27; //  261c ;  112c;      
01720       fT2d_DeeSCCons[dee-1][145-1] = 267; fT2d_DeeSCCons[dee][145-1] = 118; // 20;
01721       fT2d_DeeSCCons[dee-1][146-1] = 260; fT2d_DeeSCCons[dee][146-1] = 111; // 13;
01722 
01723       fT2d_DeeSCCons[dee-1][165-1] = 261; fT2d_DeeSCCons[dee][165-1] = 112; // 27; //  261b ;  112b;
01724       
01725       //.......................................... D1 or D3, right half of S5 
01726       fT2d_DeeSCCons[dee-1][1-1] = 297; // 34;
01727       fT2d_DeeSCCons[dee-1][2-1] = 296; // 33;
01728       fT2d_DeeSCCons[dee-1][3-1] = 295; // 32;
01729       fT2d_DeeSCCons[dee-1][4-1] = 294; // 31;
01730       fT2d_DeeSCCons[dee-1][5-1] = 289; // 26;
01731       fT2d_DeeSCCons[dee-1][6-1] = 288; // 25;
01732       fT2d_DeeSCCons[dee-1][7-1] = 287; // 24;
01733       fT2d_DeeSCCons[dee-1][8-1] = 286; // 23;
01734       
01735       fT2d_DeeSCCons[dee-1][21-1] = 293; // 30;
01736       fT2d_DeeSCCons[dee-1][22-1] = 292; // 29;
01737       fT2d_DeeSCCons[dee-1][23-1] = 291; // 28;
01738       fT2d_DeeSCCons[dee-1][24-1] = 290; // 27;
01739       fT2d_DeeSCCons[dee-1][25-1] = 285; // 22;
01740       fT2d_DeeSCCons[dee-1][26-1] = 284; // 21;
01741       
01742       fT2d_DeeSCCons[dee-1][41-1] = 281; // 20; //  281a
01743       fT2d_DeeSCCons[dee-1][42-1] = 280; // 19;
01744       fT2d_DeeSCCons[dee-1][43-1] = 279; // 18;
01745       
01746       //.......................................... D2 or D4, left half of S5
01747       fT2d_DeeSCCons[dee][1-1] = 148; // 17;
01748       fT2d_DeeSCCons[dee][2-1] = 147; // 16;
01749       fT2d_DeeSCCons[dee][3-1] = 146; // 15;
01750       fT2d_DeeSCCons[dee][4-1] = 145; // 14;
01751       fT2d_DeeSCCons[dee][5-1] = 140; //  9;
01752       fT2d_DeeSCCons[dee][6-1] = 139; //  8;
01753       fT2d_DeeSCCons[dee][7-1] = 138; //  7;
01754       fT2d_DeeSCCons[dee][8-1] = 137; //  6;
01755       
01756       fT2d_DeeSCCons[dee][21-1] = 144; // 13;
01757       fT2d_DeeSCCons[dee][22-1] = 143; // 12;
01758       fT2d_DeeSCCons[dee][23-1] = 142; // 11;
01759       fT2d_DeeSCCons[dee][24-1] = 141; // 10;
01760       fT2d_DeeSCCons[dee][25-1] = 136; //  5;
01761       fT2d_DeeSCCons[dee][26-1] = 135; //  4;
01762      
01763       fT2d_DeeSCCons[dee][41-1] = 132; // 3; //  132a
01764       fT2d_DeeSCCons[dee][42-1] = 131; // 2;
01765       fT2d_DeeSCCons[dee][43-1] = 130; // 1;
01766     }
01767 
01768   //........................ ECNA numbers from numbers for constructions: fT2d_RecovDeeSC[][]
01769 
01770   for(Int_t i0EEDee=0; i0EEDee<MaxEEDee; i0EEDee++)
01771     {
01772       for(Int_t i_ecna=0; i_ecna<MaxDeeSC; i_ecna++)
01773         {
01774           //....... test to avoid the -1 init value in 2nd index of array fT2d_RecovDeeSC[][]
01775           //        (part of the matrix without real SC counterpart)
01776           if( fT2d_DeeSCCons[i0EEDee][i_ecna] >= 0 && fT2d_DeeSCCons[i0EEDee][i_ecna] <= MaxEESCForCons )
01777             {
01778               fT2d_RecovDeeSC[i0EEDee][fT2d_DeeSCCons[i0EEDee][i_ecna]-1] = i_ecna+1;
01779             }
01780         }
01781     }
01782 }
01783 //------------ (end of BuildEndcapSCTable) -------------------------
01784 
01785 //===============================================================================
01786 //
01787 //        Get1DeeCrysFrom1DeeSCEcnaAnd0SCEcha
01788 //        GetDeeCrysFromDeeEcha
01789 //
01790 //===============================================================================
01791 Int_t TEcnaNumbering::Get1DeeCrysFrom1DeeSCEcnaAnd0SCEcha(const Int_t&  n1DeeSCEcna,
01792                                                           const Int_t&  i0SCEcha,
01793                                                           const TString& sDeeDir)
01794 {
01795 //get crystal number in Dee from SC number in Dee
01796 // and from Electronic Channel number in super-crystal
01797 
01798   Int_t n1DeeCrys = 0;
01799   Int_t i0DeeDir = GetDeeDirIndex(sDeeDir);
01800 
01801   if( fT3dDeeCrys == 0 ){BuildEndcapCrysTable();}
01802 
01803   if( (n1DeeSCEcna >= 1) && (n1DeeSCEcna <= fEcal->MaxSCEcnaInDee()) )
01804     {
01805       if (i0SCEcha >=0 && i0SCEcha < fEcal->MaxCrysInSC())
01806         {
01807           n1DeeCrys = fT3dDeeCrys[n1DeeSCEcna-1][i0SCEcha][i0DeeDir];
01808         }
01809       else
01810         {
01811           n1DeeCrys = -2;   // Electronic Cnannel in Super-Crystal out of range
01812           cout << "!TEcnaNumbering::Get1DeeCrysFrom1DeeSCEcnaAnd0SCEcha(...)> Electronic Channel in SuperCrystal = "
01813                << i0SCEcha+1 << ". Out of range (range = [1," << fEcal->MaxCrysInSC() << "])" << fTTBELL << endl;
01814         }
01815     }
01816   else
01817     {
01818       n1DeeCrys = -3;   // Super-Crystal number in Dee out of range
01819       cout << "!TEcnaNumbering::Get1DeeCrysFrom1DeeSCEcnaAnd0SCEcha(...)> Super-Crystal number in Dee out of range."
01820            << " n1DeeSCEcna = " << n1DeeSCEcna << fTTBELL << endl;
01821     }
01822 
01823   return n1DeeCrys;  // Range = [1,5000]
01824 }
01825 
01826 //===============================================================================
01827 //
01828 //                Get1SCEchaFrom1DeeCrys, Get1DeeSCEcnaFrom1DeeCrys
01829 //
01830 //===============================================================================
01831 
01832 Int_t TEcnaNumbering::Get1SCEchaFrom1DeeCrys(const Int_t& n1DeeCrys, const TString& sDeeDir)
01833 {
01834 // get Electronic Channel number in Super-Crystal from Crystal ECNA number in Dee
01835 
01836   Int_t n1SCEcha = -1;
01837   Int_t iDeeDir  = GetDeeDirIndex(sDeeDir);
01838 
01839   if( n1DeeCrys >= 1 && n1DeeCrys <= fEcal->MaxCrysEcnaInDee() )
01840     {
01841       n1SCEcha = fT2dSCEcha[n1DeeCrys-1][iDeeDir];
01842     }
01843   else
01844     {
01845       n1SCEcha = -2;
01846       cout << "!TEcnaNumbering::Get1SCEchaFrom1DeeCrys(...)> Crystal number in Dee out of range."
01847            << " n1DeeCrys = " << n1DeeCrys << "(max = " << fEcal->MaxCrysEcnaInDee() << ")" << fTTBELL << endl;
01848     }
01849   return n1SCEcha;   // range = [1,25]
01850 }
01851 
01852 Int_t TEcnaNumbering::Get1DeeSCEcnaFrom1DeeCrys(const Int_t& n1DeeCrys, const TString& sDeeDir)
01853 {
01854 // get Super-Crystal number in Dee from Crystal number in Dee
01855 
01856   Int_t n1DeeSCEcna = 0;
01857   Int_t iDeeDir    = GetDeeDirIndex(sDeeDir);
01858   
01859   if( n1DeeCrys >= 1 && n1DeeCrys <= fEcal->MaxCrysEcnaInDee() )
01860     {
01861       n1DeeSCEcna = fT2dDeeSC[n1DeeCrys-1][iDeeDir];
01862     }
01863   else
01864     {
01865       n1DeeSCEcna = -1;
01866       cout << "!TEcnaNumbering::Get1DeeSCEcnaFrom1DeeCrys(...)> Crystal number in Dee out of range."
01867            << " n1DeeCrys = " << n1DeeCrys << "(max = " << fEcal->MaxCrysEcnaInDee() << ")" << fTTBELL << endl;
01868     }
01869   return n1DeeSCEcna;  // range = [1,200]
01870 }
01871 
01872 //===============================================================================
01873 //
01874 //          GetSCEchaFromDeeEcha
01875 //          Get1DeeSCEcnaFromDeeEcha
01876 //
01877 //===============================================================================
01878 
01879 Int_t TEcnaNumbering::Get1SCEchaFrom0DeeEcha(const Int_t& i0DeeEcha)
01880 {
01881 //get electronic channel number in super-crystal from electronic channel number in Dee
01882 
01883   Int_t i0DeeSC = i0DeeEcha/fEcal->MaxCrysInSC();
01884   Int_t n1SCEcha = i0DeeEcha - fEcal->MaxCrysInSC()*i0DeeSC + 1;
01885 
01886   return n1SCEcha;  //  range = [1,25]
01887 }
01888 
01889 Int_t TEcnaNumbering::Get1DeeSCEcnaFrom0DeeEcha(const Int_t& i0DeeEcha)
01890 {
01891 //get super-crystal number from electronic channel number in Dee
01892 
01893   Int_t n1DeeSC = i0DeeEcha/fEcal->MaxCrysInSC()+1;
01894 
01895   return n1DeeSC;  //  range = [1,200]
01896 }
01897 
01898 //--------------------------------------------------------------------------------
01899 //
01900 //       Correspondance (n1DeeNumber, DeeSC)  <->  (DS, DSSC, DeeSCCons)
01901 //
01902 //       GetDSFrom1DeeSCEcna,        GetDSSCFrom1DeeSCEcna,
01903 //       GetDeeSCConsFrom1DeeSCEcna, Get1DeeSCEcnaFromDeeSCCons
01904 //      
01905 //       Get the values from the relevant arrays
01906 //       with cross-check of the index values in argument
01907 //--------------------------------------------------------------------------------
01908 
01909 Int_t TEcnaNumbering::GetDSFrom1DeeSCEcna(const Int_t& n1DeeNumber, const Int_t& n1DeeSCEcna)
01910 {
01911 // Get Data Sector number from SC ECNA number in Dee 
01912 
01913   Int_t data_sector = -1;
01914 
01915   if( n1DeeNumber > 0 && n1DeeNumber <= fEcal->MaxDeeInEE() )
01916     {
01917       if( n1DeeSCEcna > 0  &&  n1DeeSCEcna <= fEcal->MaxSCEcnaInDee() )
01918         {
01919           data_sector = fT2d_DS[n1DeeNumber-1][n1DeeSCEcna-1];
01920         }
01921       else
01922         {
01923           cout << "!TEcnaNumbering::GetDSFrom1DeeSCEcna(...)> n1DeeSCEcna = " << n1DeeSCEcna
01924                << ". Out of range ( range = [1," << fEcal->MaxSCEcnaInDee() << "] )"
01925                << fTTBELL << endl;
01926         }
01927     }
01928   else
01929     {
01930       if( n1DeeNumber != 0 )
01931         {
01932           cout << "!TEcnaNumbering::GetDSFrom1DeeSCEcna(...)> n1DeeNumber = " << n1DeeNumber 
01933                << ". Out of range ( range = [1," << fEcal->MaxDeeInEE() << "] )"
01934                << fTTBELL << endl;
01935         }
01936       else
01937         {
01938           cout << "TEcnaNumbering::GetDSFrom1DeeSCEcna(...)> Dee = " << n1DeeNumber
01939                << ". Out of range (range = [1," << fEcal->MaxDeeInEE() << "])" 
01940                << fTTBELL << endl; 
01941         }
01942     }
01943   return data_sector;
01944 }
01945 //..........................................................................................
01946 Int_t TEcnaNumbering::GetDSSCFrom1DeeSCEcna(const Int_t& n1DeeNumber, const Int_t& n1DeeSCEcna,
01947                                             const Int_t& n1SCEcha)
01948 {
01949   //.......... Get the correct SC number for the unconnected SC's (inner border)
01950   Int_t ds_sc = GetDSSCFrom1DeeSCEcna(n1DeeNumber, n1DeeSCEcna);
01951 
01952   if( n1DeeSCEcna == 29 || n1DeeSCEcna == 32 )
01953     {
01954       if( n1SCEcha == 11 )
01955         {
01956           if( ds_sc == 14 ){ds_sc= 21;}  // 14 <=> 261/BR OR 112/BL
01957         }
01958       if( n1SCEcha == 1 || n1SCEcha == 2 || n1SCEcha == 3 ||
01959           n1SCEcha == 6 || n1SCEcha == 7 )
01960         {
01961           if( ds_sc ==  3 ){ds_sc = 25;}  // 3 <=> 178/TR OR 29/TL
01962         }
01963     }
01964   return ds_sc;
01965 }
01966 //..........................................................................................
01967 Int_t TEcnaNumbering::GetDSSCFrom1DeeSCEcna(const Int_t& n1DeeNumber, const Int_t& n1DeeSCEcna)
01968 {
01969 // Get SC number in Data Sector from SC Ecna number in Dee 
01970 
01971   Int_t ds_sc = -1;
01972 
01973   if( n1DeeNumber > 0 && n1DeeNumber <= fEcal->MaxDeeInEE() )
01974     {
01975       if( n1DeeSCEcna > 0  &&  n1DeeSCEcna <= fEcal->MaxSCEcnaInDee() )
01976         {
01977           ds_sc = fT2d_DSSC[n1DeeNumber-1][n1DeeSCEcna-1]; // 25 (not 3) or 14 (not 21) if n1DeeSCEcna = 32 or 29
01978                                                            // 25 and 14 => 5 Xtals,  3 and 21 => 1 Xtal
01979         }
01980       else
01981         {
01982           cout << "!TEcnaNumbering::GetDSSCFrom1DeeSCEcna(...)> n1DeeSCEcna = " << n1DeeSCEcna
01983                << ". Out of range ( range = [1," << fEcal->MaxSCEcnaInDee() << "] )"
01984                << fTTBELL << endl;
01985         }
01986     }
01987   else
01988     {
01989       if( n1DeeNumber != 0 )
01990         {
01991           cout << "!TEcnaNumbering::GetDSSCFrom1DeeSCEcna(...)> n1DeeNumber = " << n1DeeNumber 
01992                << ". Out of range ( range = [1," << fEcal->MaxDeeInEE() << "] )"
01993                << fTTBELL << endl;
01994         }
01995       else
01996         {
01997           cout << "TEcnaNumbering::GetDSSCFrom1DeeSCEcna(...)> Dee = " << n1DeeNumber
01998                << ". Out of range (range = [1," << fEcal->MaxDeeInEE() << "])" 
01999                << fTTBELL << endl;
02000         }
02001     }
02002   return ds_sc;
02003 }
02004 //..........................................................................................
02005 Int_t TEcnaNumbering::GetDeeSCConsFrom1DeeSCEcna(const Int_t& n1DeeNumber, const Int_t& n1DeeSCEcna)
02006 {
02007 // Get SC number for Construction in Dee from SC ECNA number in Dee
02008 
02009   Int_t dee_sc_cons = -1;
02010 
02011   if( n1DeeNumber > 0 && n1DeeNumber <= fEcal->MaxDeeInEE() )
02012     {
02013       if( n1DeeSCEcna > 0  &&  n1DeeSCEcna <= fEcal->MaxSCEcnaInDee() )
02014         {
02015           dee_sc_cons = fT2d_DeeSCCons[n1DeeNumber-1][n1DeeSCEcna-1];
02016         }
02017       else
02018         {
02019           cout << "!TEcnaNumbering::GetDeeSCConsFrom1DeeSCEcna(...)> *** WARNING *** n1DeeSCEcna = " << n1DeeSCEcna
02020                << ". Out of range ( range = [1," << fEcal->MaxSCEcnaInDee()
02021                << "] ). Nb for const. forced to " << fT2d_DeeSCCons[n1DeeNumber-1][19] << "." << endl;
02022           dee_sc_cons = fT2d_DeeSCCons[n1DeeNumber-1][19];
02023         }
02024     }
02025   else
02026     {
02027       if( n1DeeNumber != 0 )
02028         {
02029           cout << "!TEcnaNumbering::GetDeeSCConsFrom1DeeSCEcna(...)> n1DeeNumber = " << n1DeeNumber 
02030                << ". Out of range ( range = [1," << fEcal->MaxDeeInEE() << "] )"
02031                << fTTBELL << endl;
02032         }
02033       else
02034         {
02035           cout << "TEcnaNumbering::GetDeeSCConsFrom1DeeSCEcna(...)> Dee = " << n1DeeNumber
02036                << ". Out of range (range = [1," << fEcal->MaxDeeInEE() << "])" 
02037                << fTTBELL << endl;
02038         }
02039     }
02040   return dee_sc_cons;
02041 }
02042 //..........................................................................................
02043 Int_t TEcnaNumbering::GetDeeSCConsFrom1DeeSCEcna(const Int_t& n1DeeNumber, const Int_t& n1DeeSCEcna,
02044                                                  const Int_t& n1SCEcha)
02045 {
02046   //.......... Get the correct SC number (for cons) for the unconnected SC's (inner border)
02047   Int_t dee_sc_cons = GetDeeSCConsFrom1DeeSCEcna(n1DeeNumber, n1DeeSCEcna);
02048 
02049   if( n1DeeSCEcna == 29 || n1DeeSCEcna == 32 )
02050     {
02051       if( n1SCEcha == 11 )
02052         {
02053           if( dee_sc_cons == 261 ){dee_sc_cons = 268;}  // 261<=>14/BR
02054           if( dee_sc_cons == 112 ){dee_sc_cons = 119;}  // 112<=>14/BL
02055         }
02056       if( n1SCEcha == 1 ||  n1SCEcha == 2 || n1SCEcha == 3 ||
02057           n1SCEcha == 6 ||  n1SCEcha == 7 )
02058         {
02059           if( dee_sc_cons == 178 ){dee_sc_cons = 207;}  // 178<=>3/TR
02060           if( dee_sc_cons ==  29 ){dee_sc_cons =  58;}  //  29<=>3/TL
02061         }
02062     }
02063   return dee_sc_cons;
02064 }
02065 //..........................................................................................
02066 Int_t TEcnaNumbering::Get1DeeSCEcnaFromDeeSCCons(const Int_t& n1DeeNumber, const Int_t& DeeSCCons)
02067 {
02068 // Get SC Ecna number in Dee from SC number for Construction in Dee
02069  
02070   Int_t dee_sc_ecna = -1;
02071 
02072   if( n1DeeNumber > 0 && n1DeeNumber <= fEcal->MaxDeeInEE() )
02073     {
02074       Int_t off_set_cons = 0;
02075       if( n1DeeNumber == 1 || n1DeeNumber == 3 ){off_set_cons = fEcal->MaxSCForConsInDee();}
02076       
02077       if( DeeSCCons > off_set_cons  &&  DeeSCCons <= fEcal->MaxSCForConsInDee()+off_set_cons )
02078         {
02079           dee_sc_ecna = fT2d_RecovDeeSC[n1DeeNumber-1][DeeSCCons-1];
02080         }
02081       else
02082         {
02083           cout << "!TEcnaNumbering::Get1DeeSCEcnaFromDeeSCCons(...)> DeeSCCons = " << DeeSCCons
02084                << ". Out of range ( range = [ " << off_set_cons+1
02085                << "," << fEcal->MaxSCForConsInDee()+off_set_cons << "] )"
02086                << fTTBELL << endl;
02087         }
02088     }
02089   else
02090     {
02091       if( n1DeeNumber != 0 )
02092         {
02093           cout << "!TEcnaNumbering::Get1DeeSCEcnaFromDeeSCCons(...)> n1DeeNumber = " << n1DeeNumber 
02094                << ". Out of range ( range = [1," << fEcal->MaxDeeInEE() << "] )"
02095                << fTTBELL << endl;
02096         }
02097       else
02098         {
02099           cout << "TEcnaNumbering::Get1DeeSCEcnaFromDeeSCCons(...)> Dee = " << n1DeeNumber
02100                << ". Out of range (range = [1," << fEcal->MaxDeeInEE() << "])" 
02101                << fTTBELL << endl;
02102         }
02103     }
02104   return dee_sc_ecna;
02105 }
02106 
02107 TString TEcnaNumbering::GetSCType(const Int_t& nb_for_cons)
02108 {
02109 // gives the special not connected SC's
02110 
02111   TString SCType = "Connected";   // => default type
02112 
02113   if( nb_for_cons == 182 || nb_for_cons ==  33 ){SCType = "NotConnected";}  // (D1,S1) (D3,S9) || (D2,S9) (D4,S1)
02114 
02115   if( nb_for_cons == 178 || nb_for_cons ==  29 ){SCType = "NotConnected";}  // (D1,S2) (D3,S8) || (D2,S8) (D4,S2)
02116   if( nb_for_cons == 207 || nb_for_cons ==  58 ){SCType = "NotConnected";}
02117 
02118   if( nb_for_cons == 298 || nb_for_cons == 149 ){SCType = "NotConnected";}  // (D1,S3) (D3,S7) || (D2,S7) (D4,S3)
02119 
02120   if( nb_for_cons == 261 || nb_for_cons == 112 ){SCType = "NotConnected";}  // (D1,S4) (D3,S6) || (D2,S6) (D4,S4)
02121   if( nb_for_cons == 268 || nb_for_cons == 119 ){SCType = "NotConnected";}
02122 
02123   if( nb_for_cons == 281 || nb_for_cons == 132 ){SCType = "NotConnected";}  // (D1,S5) (D3,S5) || (D2,S5) (D4,S5)
02124 
02125   if( nb_for_cons == 161 || nb_for_cons ==  12 ){SCType = "NotComplete";}   // (D1,S1) (D3,S9) || (D2,S9) (D4,S1)
02126   if( nb_for_cons == 216 || nb_for_cons ==  67 ){SCType = "NotComplete";}   // (D1,S2) (D3,S8) || (D2,S8) (D4,S2)
02127   if( nb_for_cons == 224 || nb_for_cons ==  75 ){SCType = "NotComplete";}   // (D1,S3) (D3,S7) || (D2,S7) (D4,S3)
02128   if( nb_for_cons == 286 || nb_for_cons == 137 ){SCType = "NotComplete";}   // (D1,S5) (D3,S5) || (D2,S5) (D4,S5)
02129 
02130   return SCType;
02131 }
02132 
02133 Int_t TEcnaNumbering::StexEchaForCons(const Int_t& n1DeeNumber, const Int_t& i0StexEcha)
02134 {
02135   Int_t n1StexStin = Get1StexStinFrom0StexEcha(i0StexEcha);
02136   return fT2d_DeeSCCons[n1DeeNumber-1][n1StexStin-1];
02137 }
02138   // return -1 if the SC does not correspond to a real SC; return the number for construction otherwise
02139 
02140 //===========================================================================
02141 //
02142 //                        GetSCQuadFrom1DeeSCEcna
02143 //
02144 //===========================================================================  
02145 
02146 TString  TEcnaNumbering::GetSCQuadFrom1DeeSCEcna(const Int_t& n1DeeSCEcna)
02147 {
02148 //gives the quadrant type ("top" or "bottom") from the SC number in Dee
02149 
02150   TString SCQuad = "top";   // => default value
02151 
02152   if (n1DeeSCEcna >=   1 && n1DeeSCEcna <=  10){SCQuad = "bottom";}
02153   if (n1DeeSCEcna >=  21 && n1DeeSCEcna <=  30){SCQuad = "bottom";}
02154   if (n1DeeSCEcna >=  41 && n1DeeSCEcna <=  50){SCQuad = "bottom";}
02155   if (n1DeeSCEcna >=  61 && n1DeeSCEcna <=  70){SCQuad = "bottom";}
02156   if (n1DeeSCEcna >=  81 && n1DeeSCEcna <=  90){SCQuad = "bottom";}
02157   if (n1DeeSCEcna >= 101 && n1DeeSCEcna <= 110){SCQuad = "bottom";}
02158   if (n1DeeSCEcna >= 121 && n1DeeSCEcna <= 130){SCQuad = "bottom";}
02159   if (n1DeeSCEcna >= 141 && n1DeeSCEcna <= 150){SCQuad = "bottom";}
02160   if (n1DeeSCEcna >= 161 && n1DeeSCEcna <= 170){SCQuad = "bottom";}
02161   if (n1DeeSCEcna >= 181 && n1DeeSCEcna <= 190){SCQuad = "bottom";}
02162 
02163   return SCQuad;
02164 }
02165 Int_t TEcnaNumbering::GetSCQuadTypeIndex(const TString& SCQuadType, const TString& sDeeDir)
02166 {
02167 //gives the index of the SC quadrant type (top/right, top/left, bottom/left, bottom/right)
02168 // = quadrant number - 1
02169 
02170   Int_t itype = 0;   // => default
02171   if ( SCQuadType == "top"    && sDeeDir == "right" ){itype = 0;}
02172   if ( SCQuadType == "top"    && sDeeDir == "left"  ){itype = 1;}
02173   if ( SCQuadType == "bottom" && sDeeDir == "left"  ){itype = 2;}
02174   if ( SCQuadType == "bottom" && sDeeDir == "right" ){itype = 3;}
02175   return itype;
02176 }
02177 //===========================================================================
02178 //
02179 //                    GetEEDeeType, GetDeeDirViewedFromIP
02180 //
02181 //===========================================================================  
02182 TString TEcnaNumbering::GetEEDeeEndcap(const Int_t& n1DeeNumber)
02183 {
02184 //gives the Endcap (EE+ or EE-) of the Dee (H. Heath, CMS NOTE 2006/027)
02185 
02186   TString eetype = "EE+";   // => default
02187   if ( n1DeeNumber == 1 || n1DeeNumber == 2 ){eetype = "EE+";}
02188   if ( n1DeeNumber == 3 || n1DeeNumber == 4 ){eetype = "EE-";}
02189   return eetype;
02190 }
02191 TString TEcnaNumbering::GetEEDeeType(const Int_t& n1DeeNumber)
02192 {
02193 //gives the EE +/- and Forward/Near of the Dee (H. Heath, CMS NOTE 2006/027)
02194 
02195   TString type = "EE+F";   // => default
02196   if ( n1DeeNumber == 1 ){type = "EE+F";}
02197   if ( n1DeeNumber == 2 ){type = "EE+N";}
02198   if ( n1DeeNumber == 3 ){type = "EE-N";}
02199   if ( n1DeeNumber == 4 ){type = "EE-F";}
02200   return type;
02201 }
02202 
02203 TString TEcnaNumbering::GetDeeDirViewedFromIP(const Int_t& n1DeeNumber)
02204 {
02205 //gives the direction (left/right) of the IX axis of the Dee
02206 // looking from the interaction point
02207 
02208   TString sDeeDir = "right";   // => default
02209   if ( (n1DeeNumber == 1) || (n1DeeNumber == 3) ){sDeeDir = "right";}
02210   if ( (n1DeeNumber == 2) || (n1DeeNumber == 4) ){sDeeDir = "left" ;}
02211   return sDeeDir;
02212 }
02213 Int_t TEcnaNumbering::GetDeeDirIndex(const TString& sDeeDir)
02214 {
02215 //gives the index of the direction (left,right) of the IX axis of the Dee
02216 // looking from the interaction point (right = 0, left = 1)
02217 
02218   Int_t iDeeDir = 0;   // => default
02219   if ( sDeeDir == "right" ){iDeeDir = 0;}
02220   if ( sDeeDir == "left"  ){iDeeDir = 1;}
02221   return iDeeDir;
02222 }
02223 
02224 //==============================================================================
02225 //
02226 //    GetIXCrysInSC,  GetJYCrysInSC
02227 //    GetIXSCInDee,   GetJYSCInDee
02228 //    GetIXCrysInDee, GetJYCrysInDConsFrom1DeeSCEcna(fStexNumber, StexStinEcna);
02229 //
02230 //==============================================================================
02231 Int_t TEcnaNumbering::GetIXCrysInSC(const Int_t& n1DeeNumber, const Int_t& DeeSC,
02232                                     const Int_t& i0SCEcha)
02233 {
02234 //Gives Crys IX in SC for a given (n1DeeNumber, DeeSC, i0SCEcha)
02235   
02236   TString SCQuadType = GetSCQuadFrom1DeeSCEcna(DeeSC);
02237   TString sDeeDir    = GetDeeDirViewedFromIP(n1DeeNumber);
02238   Int_t type_index   = GetSCQuadTypeIndex(SCQuadType, sDeeDir);
02239   Int_t IXCrysInSC   = fT2d_ich_IX[type_index][i0SCEcha+1] + 1;
02240   return IXCrysInSC;   // possible values: 1,2,3,4,5
02241 }
02242 
02243 Int_t TEcnaNumbering::GetIXSCInDee(const Int_t& DeeSC)
02244 {
02245 //Gives SC IX in Dee for a given (DeeSC)
02246   
02247   Int_t IXSCInDee = (DeeSC-1)/fEcal->MaxSCIYInDee() + 1;
02248   return IXSCInDee;  //  possible values: 1,2,...,9,10
02249 }
02250 
02251 Int_t TEcnaNumbering::GetIXCrysInDee(const Int_t& n1DeeNumber, const Int_t& DeeSC,
02252                                      const Int_t& i0SCEcha)
02253 {
02254 //Gives Crys IX in Dee for a given (n1DeeNumber, DeeSC, i0SCEcha)
02255 
02256   Int_t IXCrysInDee =
02257     (GetIXSCInDee(DeeSC)-1)*fEcal->MaxCrysIXInSC() +
02258     GetIXCrysInSC(n1DeeNumber, DeeSC, i0SCEcha);
02259   return IXCrysInDee;  // possible values: 1,2,...,49,50
02260 }
02261 //---------------------------------------------------------------------------------
02262 Int_t TEcnaNumbering::GetJYCrysInSC(const Int_t& n1DeeNumber, const Int_t& DeeSC,
02263                                     const Int_t& i0SCEcha)
02264 {
02265 //Gives Crys JY in SC  for a given (n1DeeNumber, DeeSC, i0SCEcha)
02266 
02267   TString SCQuadType = GetSCQuadFrom1DeeSCEcna(DeeSC);
02268   TString sDeeDir    = GetDeeDirViewedFromIP(n1DeeNumber);
02269   Int_t type_index   = GetSCQuadTypeIndex(SCQuadType, sDeeDir);
02270   Int_t JYCrysInSC   = fT2d_jch_JY[type_index][i0SCEcha+1] + 1;
02271   return JYCrysInSC;   // possible values: 1,2,3,4,5
02272 }
02273 
02274 Int_t TEcnaNumbering::GetJYSCInDee(const Int_t& DeeSC)
02275 {
02276 //Gives SC JY in Dee for a given (n1DeeNumber, DeeSC, i0SCEcha)
02277   
02278   Int_t JYSCInDee = (DeeSC-1)%fEcal->MaxSCIYInDee() + 1;
02279   return JYSCInDee;  //  possible values: 1,2,...,19,20
02280 }
02281 
02282 Int_t TEcnaNumbering::GetJYCrysInDee(const Int_t& n1DeeNumber, const Int_t& DeeSC,
02283                                      const Int_t& i0SCEcha)
02284 {
02285 //Gives Crys JY in Dee for a given (n1DeeNumber, DeeSC, i0SCEcha)
02286 
02287   Int_t JYCrysInDee =
02288     (GetJYSCInDee(DeeSC)-1)*fEcal->MaxCrysIYInSC() +
02289     GetJYCrysInSC(n1DeeNumber, DeeSC, i0SCEcha);
02290   return JYCrysInDee;  // possible values: 1,2,...,99,100 
02291 }
02292 //---------------------------------------------------------------------------------
02293 Int_t TEcnaNumbering::GetMaxSCInDS(const Int_t& DeeDS)
02294 {
02295 // Gives the number of SC's in Data Sector DeeDS
02296 
02297   Int_t nb_of_sc = -1;
02298   if( DeeDS == 1 || DeeDS == 9 ){nb_of_sc = 33;}
02299   if( DeeDS == 2 || DeeDS == 8 ){nb_of_sc = 32;}
02300   if( DeeDS == 3 || DeeDS == 7 ){nb_of_sc = 34;}
02301   if( DeeDS == 4 || DeeDS == 6 ){nb_of_sc = 33;}
02302   if( DeeDS == 5){nb_of_sc = 34;}
02303   return nb_of_sc;
02304 }
02305 
02306 
02307 //==============================================================================
02308 //
02309 //       GetIXMin, GetIXMax,  GetIIXMin, GetIIXMax
02310 //
02311 //==============================================================================
02312 Double_t TEcnaNumbering::GetIIXMin(const Int_t& DeeSC)
02313 {
02314 //Gives IIXMin for a given DeeSC , unit = crystal
02315 
02316   Double_t IX_min   = (Double_t)((DeeSC-1)/fEcal->MaxSCIYInDee())*fEcal->MaxCrysIXInSC() + 1.;
02317   return IX_min;
02318 }
02319 
02320 Double_t TEcnaNumbering::GetIIXMax(const Int_t& DeeSC)
02321 {
02322 //Gives IIXMax for a given DeeSC , unit = crystal
02323 
02324   Double_t IX_max  = ((Double_t)((DeeSC-1)/fEcal->MaxSCIYInDee())+1.)*fEcal->MaxCrysIXInSC();
02325   return IX_max;
02326 }
02327 
02328 Double_t TEcnaNumbering::GetIIXMin()
02329 {
02330 //Gives IIXMin for Dee , unit = Super-crystal
02331 
02332   Double_t i_IX_min = (Int_t)1.;
02333   return i_IX_min;
02334 }
02335 
02336 Double_t TEcnaNumbering::GetIIXMax()
02337 {
02338 //Gives IIXMax for Dee , unit = Super-crystal
02339 
02340   Double_t i_IX_max = (Int_t)fEcal->MaxSCIXInDee(); 
02341   return i_IX_max;
02342 }
02343 
02344 //==============================================================================
02345 //
02346 //     GetIIYMin, GetIIYMax
02347 //
02348 //==============================================================================
02349 Double_t TEcnaNumbering::GetJIYMin(const Int_t& n1DeeNumber, const Int_t& DeeSC)
02350 {
02351 //Gives JIYMin for a given Super-Crystal
02352 
02353   Double_t IY_DeeSC = DeeSC%fEcal->MaxSCIYInDee();
02354   if( IY_DeeSC == 0. ){IY_DeeSC = fEcal->MaxSCIYInDee();}
02355 
02356   Double_t j_IY_min = (IY_DeeSC-1)*fEcal->MaxCrysIYInSC() + 1.;
02357  
02358   return j_IY_min;
02359 }
02360 //-----------------------------------------------------------------------------------------
02361 Double_t TEcnaNumbering::GetJIYMax(const Int_t& n1DeeNumber, const Int_t& DeeSC)
02362 {
02363 //Gives JIYMax for a given Super-Crystal
02364 
02365   Double_t IY_DeeSC = DeeSC%fEcal->MaxSCIYInDee();
02366   if( IY_DeeSC == 0  ){IY_DeeSC = fEcal->MaxSCIYInDee();}
02367 
02368   Double_t j_IY_max = IY_DeeSC*fEcal->MaxCrysIYInSC();
02369 
02370   return j_IY_max;
02371 }
02372 
02373 //-----------------------------------------------------------------------------------------
02374 Double_t TEcnaNumbering::GetJIYMin(const Int_t& n1DeeNumber)
02375 {
02376 //Gives JIYMin for a given Dee
02377 
02378   Double_t j_IY_min = (Double_t)1.;
02379 
02380   return j_IY_min;
02381 }
02382 //-----------------------------------------------------------------------------------------
02383 Double_t TEcnaNumbering::GetJIYMax(const Int_t& n1DeeNumber)
02384 {
02385 //Gives JIYMax for a given Dee
02386 
02387   Double_t j_IY_max = (Double_t)fEcal->MaxSCIYInDee();
02388 
02389   return j_IY_max;
02390 }
02391 //=====================================================================
02392 TString  TEcnaNumbering::GetDeeHalfEndcap(const Int_t& n1DeeNumber)
02393 {
02394 //gives the half-endcap of the Dee ("EE+" or "EE-")
02395 
02396   TString type = "EE-";   // => default value
02397 
02398   if ( n1DeeNumber == 1 || n1DeeNumber == 2 ){type = "EE+";}
02399   if ( n1DeeNumber == 3 || n1DeeNumber == 4 ){type = "EE-";}
02400 
02401   return type;
02402 }
02403 //==============================================================================
02404 //
02405 //   GetXDirectionEE, GetYDirectionEE, GetJYDirectionEE
02406 //
02407 //==============================================================================
02408 TString TEcnaNumbering::GetXDirectionEE(const Int_t& n1DeeNumber)
02409 {
02410   TString xdirection = "x";      // DEFAULT
02411 
02412   if( GetEEDeeType(n1DeeNumber) == "EE+F" ){xdirection = "-x";}   //  Dee 1
02413   if( GetEEDeeType(n1DeeNumber) == "EE+N" ){xdirection = "-x";}   //  Dee 2
02414   if( GetEEDeeType(n1DeeNumber) == "EE-N" ){xdirection = "x";}    //  Dee 3
02415   if( GetEEDeeType(n1DeeNumber) == "EE-F" ){xdirection = "x";}    //  Dee 4
02416 
02417   return xdirection;
02418 }
02419 //---------------------------------------------------------
02420 TString TEcnaNumbering::GetYDirectionEE(const Int_t& n1DeeNumber)
02421 {
02422   TString ydirection = "-x";      // DEFAULT
02423 
02424   if( GetEEDeeType(n1DeeNumber) == "endcap+" ){ydirection = "-x";}
02425   if( GetEEDeeType(n1DeeNumber) == "endcap-" ){ydirection = "-x";}
02426 
02427   return ydirection;
02428 }
02429 
02430 //---------------------------------------------------------
02431 TString TEcnaNumbering::GetJYDirectionEE(const Int_t& n1DeeNumber)
02432 {
02433   TString jydirection = "x";      // ALWAYS IN THIS CASE
02434   return jydirection;
02435 }
02436 
02437 //==========================================================================================================
02438 //
02439 //
02440 //                               B A R R E L    A N D    E N D C A P 
02441 //
02442 //
02443 //
02444 //==========================================================================================================
02445 //===============================================================================
02446 //
02447 //        Get1StexStinFrom0StexEcha
02448 //     // GetStinEchaFromStexEcha
02449 //        Get0StexEchaFrom1StexStinAnd0StinEcha
02450 //        Get1StexCrysFrom1StexStinAnd0StinEcha
02451 //
02452 //===============================================================================
02453 Int_t TEcnaNumbering::Get1StexStinFrom0StexEcha(const Int_t& i0StexEcha)
02454 {
02455   Int_t n1StexStin = 0;
02456 
02457   if( fFlagSubDet == "EB" ){n1StexStin = Get1SMTowFrom0SMEcha(i0StexEcha);}
02458   if( fFlagSubDet == "EE" ){n1StexStin = Get1DeeSCEcnaFrom0DeeEcha(i0StexEcha);}
02459 
02460   return n1StexStin;
02461 }
02462 
02463 Int_t TEcnaNumbering::Get0StexEchaFrom1StexStinAnd0StinEcha(const Int_t& n1StexStin,
02464                                                             const Int_t& i0StinEcha)
02465 {
02466 // Electronic Channel number in Stex from Stin number in Stex
02467 // and from Electronic Channel number in Stin
02468 
02469   Int_t StexEcha = (Int_t)(-1.);
02470                     
02471   if ( n1StexStin >  0 && n1StexStin <= fEcal->MaxStinEcnaInStex() &&
02472        i0StinEcha >= 0 && i0StinEcha < fEcal->MaxCrysInStin()  )
02473     {StexEcha = (n1StexStin-1)*fEcal->MaxCrysInStin() + i0StinEcha;}
02474   else
02475     {
02476       cout << "!TEcnaNumbering::Get0StexEchaFrom1StexStinAnd0StinEcha *** ERROR ***> VALUE"
02477            << " OUT OF RANGE. Forced to -1. Argument values: n1StexStin = " << n1StexStin
02478            << ", channel = " << i0StinEcha
02479            << fTTBELL << endl;
02480     }
02481   return StexEcha;
02482 }
02483 Int_t TEcnaNumbering::Get1StexCrysFrom1StexStinAnd0StinEcha(const Int_t& n1StexStin,
02484                                                             const Int_t& i0StinEcha, const Int_t& StexNumber)
02485 {
02486 // Crystal number in Stex from Stin number in Stex
02487 // and from Electronic Channel number in Stin (for the StexNumber_th Stex)
02488 // argument StexNumber used only in "EE" case
02489 
02490   Int_t n1StexCrys = (Int_t)0;
02491   if( fFlagSubDet ==  "EB" ){n1StexCrys = Get1SMCrysFrom1SMTowAnd0TowEcha(n1StexStin, i0StinEcha);}
02492   if( fFlagSubDet ==  "EE" ){TString sDeeDir = GetDeeDirViewedFromIP(StexNumber);
02493   n1StexCrys = Get1DeeCrysFrom1DeeSCEcnaAnd0SCEcha(n1StexStin, i0StinEcha, sDeeDir);}
02494   
02495   return n1StexCrys;
02496 }
02497 //===============================================================================
02498 //
02499 //        GetIHocoMin, GetIHocoMax, GetVecoMin, GetVecoMax
02500 //        GetJVecoMin, GetJVecoMax
02501 //
02502 //===============================================================================
02503 Double_t TEcnaNumbering::GetIHocoMin(const Int_t& Stex, const Int_t& StexStin)
02504 {
02505   Double_t IHocoMin = (Double_t)0.;
02506   if(fFlagSubDet == "EB" ){IHocoMin = GetIEtaMin(Stex, StexStin);}
02507   if(fFlagSubDet == "EE" ){IHocoMin = GetIIXMin(StexStin);}
02508   return IHocoMin;
02509 }
02510 
02511 Double_t TEcnaNumbering::GetIHocoMax(const Int_t& Stex, const Int_t& StexStin)
02512 {
02513   Double_t IHocoMax = (Double_t)0.;
02514   if(fFlagSubDet == "EB" ){IHocoMax = GetIEtaMax(Stex, StexStin);}
02515   if(fFlagSubDet == "EE" ){IHocoMax = GetIIXMax(StexStin);}
02516   return IHocoMax;
02517 }
02518 
02519 Double_t TEcnaNumbering::GetVecoMin(const Int_t& Stex, const Int_t& StexStin)
02520 {
02521   Double_t IVecoMin = (Double_t)0.;
02522   if(fFlagSubDet == "EB" ){IVecoMin = GetPhiMin(Stex, StexStin);}
02523   if(fFlagSubDet == "EE" ){IVecoMin = GetJIYMin(Stex, StexStin);}
02524   return IVecoMin;
02525 }
02526 
02527 Double_t TEcnaNumbering::GetVecoMax(const Int_t& Stex, const Int_t& StexStin)
02528 {
02529   Double_t IVecoMax = (Double_t)0.;
02530   if(fFlagSubDet == "EB" ){IVecoMax = GetPhiMax(Stex, StexStin);}
02531   if(fFlagSubDet == "EE" ){IVecoMax = GetJIYMax(Stex, StexStin);}
02532   return IVecoMax;
02533 }
02534 
02535 Double_t TEcnaNumbering::GetJVecoMin(const Int_t& Stex, const Int_t& StexStin)
02536 {
02537   Double_t JVecoMin = (Double_t)0.;
02538   if(fFlagSubDet == "EB" ){JVecoMin = GetJPhiMin(Stex, StexStin);}
02539   if(fFlagSubDet == "EE" ){JVecoMin = GetJIYMin(Stex, StexStin);}   // not used
02540   return JVecoMin;
02541 }
02542 Double_t TEcnaNumbering::GetJVecoMax(const Int_t& Stex, const Int_t& StexStin)
02543 {
02544   Double_t JVecoMax = (Double_t)0.;
02545   if(fFlagSubDet == "EB" ){JVecoMax = GetJPhiMax(Stex, StexStin);}
02546   if(fFlagSubDet == "EE" ){JVecoMax = GetJIYMax(Stex, StexStin);}   // not used
02547   return JVecoMax;
02548 }
02549 //===========================================================================
02550 //
02551 //                        GetStexHalfBarrel   
02552 //
02553 //===========================================================================  
02554 TString  TEcnaNumbering::GetStexHalfStas(const Int_t& SMNumber)
02555 {
02556   TString half_stas = "EB? EE?";
02557 
02558   if( fFlagSubDet == "EB" ){half_stas = GetSMHalfBarrel(SMNumber);}
02559   if( fFlagSubDet == "EE" ){half_stas = GetDeeHalfEndcap(SMNumber);}
02560 
02561   return half_stas;
02562 }
02563 //===========================================================================
02564 //
02565 //                  GetSMFromFED, GetDSFromFED
02566 //
02567 //=========================================================================== 
02568 Int_t TEcnaNumbering::GetSMFromFED(const Int_t& FEDNumber)
02569 {
02570   Int_t EBSMNumber = 0;    // SM = Super Module
02571   if( FEDNumber >= 610 && FEDNumber <= 645 ){EBSMNumber = FEDNumber - 609;}
02572   return EBSMNumber;
02573 }
02574 
02575 Int_t TEcnaNumbering::GetDSFromFED(const Int_t& FEDNumber)
02576 {
02577   Int_t EEDSNumber = 0;    // DS = Data Sector
02578 
02579   if( FEDNumber >= 600 && FEDNumber <= 609 ){EEDSNumber = FEDNumber - 599;} 
02580   if( FEDNumber >= 646 && FEDNumber <= 655 ){EEDSNumber = FEDNumber - 645;} 
02581 
02582   return EEDSNumber;
02583 }
02584 
02585 //--------------------------------------------
02586 Int_t TEcnaNumbering::MaxCrysInStinEcna(const Int_t& n1DeeNumber, const Int_t& n1DeeSCEcna, const TString& s_option)
02587 {
02588 // Number of Xtals in "Ecna SC" for not complete and not connected SC's.
02589 // Also valid for all connected and complete SC's and for towers of EB
02590 
02591   Int_t max_crys = fEcal->MaxCrysInStin();   // valid for EB and for connected and complete SC's of EE
02592 
02593   // Number of Xtals in SC for not complete and not connected SC's
02594 
02595   if(fFlagSubDet == "EE")
02596     {
02597       Int_t n_for_cons = GetDeeSCConsFrom1DeeSCEcna(n1DeeNumber, n1DeeSCEcna);
02598 
02599       //............ not complete SC's (inner border)
02600       if( n_for_cons ==  12 || n_for_cons ==  67 || n_for_cons ==  75 || n_for_cons == 137 ||
02601           n_for_cons == 161 || n_for_cons == 216 || n_for_cons == 224 || n_for_cons == 286 ){max_crys = 20;}
02602 
02603       //............ not connected SC's
02604       if( (n_for_cons == 182 || n_for_cons ==  33) && (n1DeeSCEcna ==  60 || n1DeeSCEcna == 119) ){max_crys = 10;}
02605 
02606       if( (n_for_cons == 178 || n_for_cons ==  29) && (n1DeeSCEcna == 138 || n1DeeSCEcna == 157) ){max_crys = 10;}
02607       if( (n_for_cons == 207 || n_for_cons ==  58) && (n1DeeSCEcna == 176 || n1DeeSCEcna == 193) ){max_crys = 10;}
02608 
02609       if( (n_for_cons == 298 || n_for_cons == 149) && (n1DeeSCEcna == 188) ){max_crys = 10;}
02610 
02611       if( (n_for_cons == 261 || n_for_cons == 112) && (n1DeeSCEcna == 144 || n1DeeSCEcna == 165) ){max_crys = 10;}
02612       if( (n_for_cons == 268 || n_for_cons == 119) && (n1DeeSCEcna == 102 || n1DeeSCEcna == 123) ){max_crys = 10;}
02613 
02614       if( (n_for_cons == 281 || n_for_cons == 132) && (n1DeeSCEcna ==  41) ){max_crys = 10;}
02615 
02616       //............. not connected and mixed Ecna SC's
02617       if( s_option == "TEcnaRun" || s_option == "TEcnaRead" )
02618         {
02619           if( s_option == "TEcnaRun" )
02620             {
02621               // special translation of Xtal 11 of SCEcna 29 and 32 to respectively Xtal 11 of SCEcna 10 and 11
02622               if( n1DeeSCEcna == 29 || n1DeeSCEcna == 32 ){max_crys = 5;} 
02623               if( n1DeeSCEcna == 10 || n1DeeSCEcna == 11 ){max_crys = 1;}
02624             }
02625           if( s_option == "TEcnaRead" )
02626             {
02627               //if( n1DeeSCEcna == 29 || n1DeeSCEcna == 32 ){max_crys = 6;}
02628               if( n1DeeSCEcna == 29 || n1DeeSCEcna == 32 ){max_crys = 5;}
02629               if( n1DeeSCEcna == 10 || n1DeeSCEcna == 11 ){max_crys = 1;}
02630             }
02631         }
02632       else
02633         {
02634           cout << "!TEcnaNumbering::MaxCrysInStinEcna(...)> " << s_option
02635                << ": unknown option." << fTTBELL << endl;
02636         }
02637     }
02638   return max_crys;
02639 }