CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/SimG4CMS/FP420/src/FP420NumberingScheme.cc

Go to the documentation of this file.
00001 
00002 // File: FP420NumberingScheme.cc
00003 // Date: 02.2006
00004 // Description: Numbering scheme for FP420
00005 // Modifications: 08.2008  mside and fside added
00007 #include "SimG4CMS/FP420/interface/FP420NumberingScheme.h"
00008 //
00009 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00010 #include "globals.hh"
00011 #include <iostream>
00012 
00013 //UserVerbosity FP420NumberingScheme::cout("FP420NumberingScheme","silent","FP420NumberingScheme");
00014 
00015 FP420NumberingScheme::FP420NumberingScheme() {
00016 //  sn0=3, pn0=6, rn0=7;   
00017 }
00018 
00019 FP420NumberingScheme::~FP420NumberingScheme() {
00020   //  std::cout << " Deleting FP420NumberingScheme" << std::endl;
00021 }
00022 
00023                                                                                 
00024 int FP420NumberingScheme::detectorLevel(const G4Step* aStep) const {
00025                                                                                 
00026   //Find number of levels
00027   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00028   int level = 0;
00029   if (touch) level = ((touch->GetHistoryDepth())+1);
00030   return level;
00031 }
00032                                                                                 
00033 void FP420NumberingScheme::detectorLevel(const G4Step* aStep, int& level,
00034                                         int* copyno, G4String* name) const {
00035                                                                                 
00036   //Get name and copy numbers
00037   if (level > 0) {
00038     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00039     for (int ii = 0; ii < level; ii++) {
00040       int i      = level - ii - 1;
00041       name[ii]   = touch->GetVolume(i)->GetName();
00042       copyno[ii] = touch->GetReplicaNumber(i);
00043     }
00044   }
00045 }
00046                                                                                 
00047 
00048 
00049 
00050 unsigned int FP420NumberingScheme::getUnitID(const G4Step* aStep) const {
00051   
00052   unsigned intindex=0;
00053   int level = detectorLevel(aStep);
00054   
00055   // std::cout << "FP420NumberingScheme number of levels= " << level << std::endl;
00056   
00057   //  unsigned int intIndex = 0;
00058   if (level > 0) {
00059     int*      copyno = new int[level];
00060     G4String* name   = new G4String[level];
00061     detectorLevel(aStep, level, copyno, name);
00062     
00063     //    int det   = static_cast<int>(FP420);;
00064     
00065     int det = 1; 
00066     int stationgen  = 0;
00067     int zside   = 0;
00068     int station  = 0;
00069     int plane = 0;
00070     for (int ich=0; ich  <  level; ich++) {
00071       /*
00072       // old set up configuration with equidistant stations 
00073       if(name[ich] == "FP420Ex") {
00074       stationgen   = copyno[ich];
00075       } else if(name[ich] == "SISTATION") {
00076       station   = stationgen;
00077       } else if(name[ich] == "SIPLANE") {
00078       plane   = copyno[ich];
00079       } else if(name[ich] == "SIDETL") {
00080       zside   = 1;
00081       } else if(name[ich] == "SIDETR") {
00082       zside   = 2;
00083       }
00084       */
00085       // new and old set up configurations are possible:
00086       if(name[ich] == "FP420E") {
00087         det   = copyno[ich];
00088       } else if(name[ich] == "HPS240E") {
00089         det   = copyno[ich] + 2 ;
00090       } else if(name[ich] == "FP420Ex1" || name[ich] == "HPS240Ex1") {
00091         stationgen   = 1;
00092         //    } else if(name[ich] == "FP420Ex2") {
00093         //      stationgen   = 2;
00094       } else if(name[ich] == "FP420Ex3" || name[ich] == "HPS240Ex3") {
00095         stationgen   = 2;// was =3
00096       } else if(name[ich] == "SISTATION" || name[ich] == "HPS240SISTATION") {
00097         station   = stationgen;
00098       } else if(name[ich] == "SIPLANE" || name[ich] == "HPS240SIPLANE") {
00099         plane   = copyno[ich];
00100         // SIDETL (or R) can be ether X or Y type in next schemes of readout
00101         //        !!! (=...) zside
00102         //
00103         //      1                  2     <---copyno
00104         //   Front(=2) Empty(=4) Back(=6)     <--SIDETR OR SENSOR2
00105         //      1         2              <---copyno
00106         //   Front(=1) Back(=3) Empty(=5)     <--SIDETL OR SENSOR1
00107         //
00108       } else if(name[ich] == "SENSOR2" || name[ich] == "HPS240SENSOR2") {
00109         //    } else if(name[ich] == "SIDETR") {
00110         //      zside   = 4 * copyno[ich] - 2 ;//= 2   6 (copyno=1,2)
00111         zside   = 3 * copyno[ich];//= 3   6 (copyno=1,2)
00112       } else if(name[ich] == "SENSOR1" || name[ich] == "HPS240SENSOR1") {
00113         //     } else if(name[ich] == "SIDETL") {
00114         //      zside   = 2 * copyno[ich] - 1 ;//= 1   3 (copyno=1,2)
00115         zside   = copyno[ich];//= 1   2 (copyno=1,2)
00116       }
00117       //
00118       //  std::cout << "FP420NumberingScheme  " << "ich=" << ich  << "copyno" << copyno[ich] << "name="  << name[ich] << std::endl;
00119       //
00120     }
00121     // det = 1 for +FP420 ,  = 2 for -FP420  / (det-1) = 0,1
00122     // det = 3 for +HPS240 , = 4 for -HPS240 / (det-1) = 2,3
00123     // 0 is as default for every below:
00124     // Z index 
00125     // station number 1 - 8   (in reality just 2 ones)
00126     // superplane(superlayer) number  1 - 16 (in reality just 5 ones)
00127     
00128     // intindex = myPacker.packEcalIndex (det, zside, station, plane);// see examples
00129     // intindex = myPacker.packCastorIndex (det, zside, station, plane);// see examples
00130     intindex = packFP420Index (det, zside, station, plane);
00131     /*
00132     //
00133     std::cout << "FP420NumberingScheme det=" << det << " zside=" << zside << " station=" <<station  << " plane=" << plane << std::endl;
00134     
00135     for (int ich = 0; ich < level; ich++) {
00136     std::cout <<" name = " << name[ich] <<" copy = " << copyno[ich] << std::endl;
00137     std::cout << " packed index = intindex" << intindex << std::endl;
00138     }
00139     //    
00140     */   
00141     
00142     
00143     delete[] copyno;
00144     delete[] name;
00145   }
00146   
00147   return intindex;
00148   
00149 }
00150 
00151 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station,int plane){
00152   //  
00153   unsigned int idx = ((det-1)&3)<<19;   //bit 19-20 (det-1):0- 3 = 4-->2**2 = 4  -> 4-1  ->((det-1)&3)  2 bit: 0-1
00154   // unsigned int idx = ((det-1)&1)<<20;//bit 20-20 (det-1):0- 1 = 2-->2**1 = 2  -> 2-1  ->((det-1)&1)  1 bit: 0
00155   idx += (zside&7)<<7;                 //bits  7- 9   zside:0- 7 = 8-->2**3 = 8  -> 8-1  ->  (zside&7)  3 bits:0-2
00156   //  idx += (zside&3)<<7;             //bits  7- 8   zside:0- 3 = 4-->2**2 = 4  -> 4-1  ->  (zside&3)  2 bits:0-1
00157   idx += (station&7)<<4;               //bits  4- 6 station:0- 7 = 8-->2**3 = 8  -> 8-1  ->(station&7)  3 bits:0-2
00158   idx += (plane&15);                   //bits  0- 3   plane:0-15 =16-->2**4 =16  ->16-1  -> (plane&15)  4 bits:0-3
00159   
00160   //  
00161   
00162   //  std::cout << "FP420 packing: det " << det  << " zside  " << zside << " station " << station  << " plane " <<  plane << " idx " << idx <<  std::endl;
00163   //  int newdet, newzside, newstation,newplane;
00164   //  unpackFP420Index(idx, newdet, newzside, newstation,newplane);
00165   
00166   //
00167   
00168   return idx;
00169 }
00170 
00171 
00172 
00173 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det,
00174                                         int& zside, int& station,
00175                                         int& plane) {
00176   det  = (idx>>19)&3;
00177   //det  = (idx>>20)&1;
00178   det += 1;
00179   zside   = (idx>>7)&7;
00180   //  zside   = (idx>>7)&3;
00181   station = (idx>>4)&7;
00182   plane   =  idx&15;
00183   //                                                                                
00184   
00185   //  std::cout  << " FP420unpacking: idx=" << idx << " zside  " << zside << " station " << station  << " plane " <<  plane << std::endl;
00186 
00187   //
00188 }
00189 
00190