CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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] == "FP420Ex1") {
00089         stationgen   = 1;
00090         //    } else if(name[ich] == "FP420Ex2") {
00091         //      stationgen   = 2;
00092       } else if(name[ich] == "FP420Ex3") {
00093         stationgen   = 2;// was =3
00094       } else if(name[ich] == "SISTATION") {
00095         station   = stationgen;
00096       } else if(name[ich] == "SIPLANE") {
00097         plane   = copyno[ich];
00098       // SIDETL (or R) can be ether X or Y type in next schemes of readout
00099         //        !!! (=...) zside
00100         //
00101         //      1                  2     <---copyno
00102         //   Front(=2) Empty(=4) Back(=6)     <--SIDETR OR SENSOR2
00103         //      1         2              <---copyno
00104         //   Front(=1) Back(=3) Empty(=5)     <--SIDETL OR SENSOR1
00105         //
00106       } else if(name[ich] == "SENSOR2") {
00107         //    } else if(name[ich] == "SIDETR") {
00108         //      zside   = 4 * copyno[ich] - 2 ;//= 2   6 (copyno=1,2)
00109         zside   = 3 * copyno[ich];//= 3   6 (copyno=1,2)
00110       } else if(name[ich] == "SENSOR1") {
00111         //     } else if(name[ich] == "SIDETL") {
00112         //      zside   = 2 * copyno[ich] - 1 ;//= 1   3 (copyno=1,2)
00113         zside   = copyno[ich];//= 1   2 (copyno=1,2)
00114       }
00115       //
00116       //  std::cout << "FP420NumberingScheme  " << "ich=" << ich  << "copyno" << copyno[ich] << "name="  << name[ich] << std::endl;
00117       //
00118     }
00119     // det = 1 for +FP420 , = 2 for -FP420  / (det-1) = 0,1
00120     // 0 is as default for every below:
00121     // Z index 
00122     // station number 1 - 5   (in reality just 2 ones)
00123     // superplane(superlayer) number  1 - 10 (in reality just 5 ones)
00124 
00125    // intindex = myPacker.packEcalIndex (det, zside, station, plane);
00126    // intindex = myPacker.packCastorIndex (det, zside, station, plane);
00127     intindex = packFP420Index (det, zside, station, plane);
00128     /*
00129     //
00130     std::cout << "FP420NumberingScheme det=" << det << " zside=" << zside << " station=" <<station  << " plane=" << plane << std::endl;
00131 
00132     for (int ich = 0; ich < level; ich++) {
00133       std::cout <<" name = " << name[ich] <<" copy = " << copyno[ich] << std::endl;
00134       std::cout << " packed index = intindex" << intindex << std::endl;
00135     }
00136     //    
00137  */   
00138 
00139     
00140     delete[] copyno;
00141     delete[] name;
00142   }
00143 
00144   return intindex;
00145   
00146 }
00147 
00148 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station,int plane){
00149   unsigned int idx = ((det-1)&1)<<20;     //bit 20     (det-1): 0 ,1= 2-->2**1=2 -> 2-1 -> ((det-1)&1)  1 bit: 0
00150   idx += (zside&7)<<7;                  //bits 7-9    zside: 0- 7= 8-->2**3 =8 -> 8-1 -> (zside&7)   3 bits:0-2
00151   //  idx += (zside&3)<<7;                         //bits 7-8    zside: 0- 2= 3-->2**2 =4 -> 4-1 -> (zside&3)   2 bits:0-1
00152   idx += (station&7)<<4;                //bits 4-6   station:0- 7= 8-->2**3 =8  -> 8-1 ->(station&7)  3 bits:0-2
00153   idx += (plane&15);                    //bits 0-3    plane: 0-15=16-->2**4 =16 -> 16-1 ->(plane&15)  4 bits:0-3
00154                                                                                 
00155   //  
00156 
00157   //  std::cout << "FP420 packing: det " << det  << " zside  " << zside << " station " << station  << " plane " <<  plane << " idx " << idx <<  std::endl;
00158   //  int newdet, newzside, newstation,newplane;
00159   //  unpackFP420Index(idx, newdet, newzside, newstation,newplane);
00160 
00161   //
00162                                                                                 
00163   return idx;
00164 }
00165 
00166 
00167 
00168 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det,
00169                                         int& zside, int& station,
00170                                         int& plane) {
00171   det  = (idx>>20)&1;
00172   det += 1;
00173   zside   = (idx>>7)&7;
00174   //  zside   = (idx>>7)&3;
00175   station = (idx>>4)&7;
00176   plane   =  idx&15;
00177   //                                                                                
00178   
00179   //  std::cout  << " FP420unpacking: idx=" << idx << " zside  " << zside << " station " << station  << " plane " <<  plane << std::endl;
00180 
00181   //
00182 }
00183 
00184