CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/SimG4CMS/Forward/src/BscNumberingScheme.cc

Go to the documentation of this file.
00001 
00002 // File: BscNumberingScheme.cc
00003 // Date: 02.2006
00004 // Description: Numbering scheme for Bsc
00005 // Modifications:
00007 #include "SimG4CMS/Forward/interface/BscNumberingScheme.h"
00008 //
00009 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00010 #include "globals.hh"
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 
00013 BscNumberingScheme::BscNumberingScheme() {
00014   LogDebug("BscSim") << " Creating BscNumberingScheme" ;
00015 }
00016 
00017 BscNumberingScheme::~BscNumberingScheme() {
00018   LogDebug("BscSim") << " Deleting BscNumberingScheme" ;
00019 }
00020 
00021 int BscNumberingScheme::detectorLevel(const G4Step* aStep) const {
00022 
00023   //Find number of levels
00024   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00025   int level = 0;
00026   if (touch) level = ((touch->GetHistoryDepth())+1);
00027   return level;
00028 }
00029 
00030 void BscNumberingScheme::detectorLevel(const G4Step* aStep, int& level,
00031                                         int* copyno, G4String* name) const {
00032 
00033   //Get name and copy numbers
00034   if (level > 0) {
00035     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00036     for (int ii = 0; ii < level; ii++) {
00037       int i      = level - ii - 1;
00038       name[ii]   = touch->GetVolume(i)->GetName();
00039       copyno[ii] = touch->GetReplicaNumber(i);
00040     }
00041   }
00042 }
00043 
00044 unsigned int BscNumberingScheme::getUnitID(const G4Step* aStep) const {
00045 
00046   unsigned intindex=0;
00047   int level = detectorLevel(aStep);
00048 
00049   LogDebug("BscSim") << "BscNumberingScheme number of levels= " << level;
00050 
00051  //  unsigned int intIndex = 0;
00052   if (level > 0) {
00053     int*      copyno = new int[level];
00054     G4String* name   = new G4String[level];
00055     detectorLevel(aStep, level, copyno, name);
00056 
00057     int det   = 0;
00058     int zside   = 0;
00059     int station  = 0;
00060     for (int ich=0; ich  <  level; ich++) {
00061       // new and old set up configurations are possible:
00062       if(name[ich] == "BSC1" ||name[ich] == "BSC2" ) {
00063         zside   = copyno[ich]-1;
00064       } else if(name[ich] == "BSCTrap") {
00065         det   = 0;
00066         station =  2*(copyno[ich]-1);
00067       } else if(name[ich] == "BSCTubs") {
00068         det   = 1;
00069         station =  copyno[ich]-1;
00070       } else if(name[ich] == "BSCTTop") {
00071         ++station;
00072       } else if(name[ich] == "BSC2Pad"){
00073         det   = 2;
00074         station =  copyno[ich]-1;
00075       }
00076 
00077       LogDebug("BscSim") << "BscNumberingScheme  " << "ich=" << ich  <<"copyno"
00078                          << copyno[ich] << "name="  << name[ich];
00079 
00080     }
00081     intindex = packBscIndex (zside,det,  station);
00082     LogDebug("BscSim") << "BscNumberingScheme : det " << det << " zside " 
00083                        << zside << " station " << station 
00084                        << " UnitID 0x" << std::hex << intindex << std::dec;
00085 
00086     for (int ich = 0; ich < level; ich++)
00087       LogDebug("BscSim") <<" name = " << name[ich] <<" copy = " << copyno[ich];
00088     LogDebug("BscSim") << " packed index = 0x" << std::hex << intindex 
00089                        << std::dec;
00090 
00091     delete[] copyno;
00092     delete[] name;
00093   }
00094 
00095   return intindex;
00096   
00097 }
00098 
00099 unsigned BscNumberingScheme::packBscIndex(int zside,int det,  int station){
00100   unsigned int idx = 6 << 28; // autre numero que les detecteurs existants 
00101   idx += (zside<<5)&32;       // vaut 0 ou 1 bit 5    
00102   idx += (det<<3)&24;         //bit 3-4    det:0-1-2    2 bits:0-1
00103   idx += (station&7);         //bits 0-2   station:0-7=8-->2**3 =8   3 bits:0-2
00104   LogDebug("BscSim") << "Bsc packing: det " << det 
00105                      << " zside  " << zside << " station " << station  
00106                      << "-> 0x" << std::hex << idx << std::dec;
00107 
00108   //  unpackBscIndex(idx);  
00109   return idx;
00110 }
00111 
00112 void BscNumberingScheme::unpackBscIndex(const unsigned int& idx) {
00113   int zside, det, station;
00114   zside  = (idx&32)>>5;
00115   det    = (idx&24)>>3;
00116   station = idx&7;                                           
00117   LogDebug("BscSim") << " Bsc unpacking: 0x " << std::hex << idx << std::dec 
00118                      << " -> det " <<   det  << " zside  " << zside 
00119                      << " station " << station  ;
00120 }