CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/SimG4CMS/Forward/src/CastorNumberingScheme.cc

Go to the documentation of this file.
00001 
00002 // File: CastorNumberingScheme.cc
00003 // Description: Numbering scheme for Castor
00005 #include "SimG4CMS/Forward/interface/CastorNumberingScheme.h"
00006 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 
00009 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00010 #include "G4LogicalVolumeStore.hh"
00011 #include <iostream>
00012 
00013 #define debug
00014 
00015 CastorNumberingScheme::CastorNumberingScheme(): lvCAST(0),lvCAES(0),lvCEDS(0),
00016                                                 lvCAHS(0),lvCHDS(0),lvCAER(0),
00017                                                 lvCEDR(0),lvCAHR(0),lvCHDR(0),
00018                                                 lvC3EF(0),lvC3HF(0),lvC4EF(0),
00019                                                 lvC4HF(0) {
00020   edm::LogInfo("ForwardSim") << "Creating CastorNumberingScheme";
00021   const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
00022   std::vector<lvp>::const_iterator lvcite;
00023   for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
00024     if (strcmp(((*lvcite)->GetName()).c_str(),"CAST") == 0) lvCAST = (*lvcite);
00025     if (strcmp(((*lvcite)->GetName()).c_str(),"CAES") == 0) lvCAES = (*lvcite);
00026     if (strcmp(((*lvcite)->GetName()).c_str(),"CEDS") == 0) lvCEDS = (*lvcite);
00027     if (strcmp(((*lvcite)->GetName()).c_str(),"CAHS") == 0) lvCAHS = (*lvcite);
00028     if (strcmp(((*lvcite)->GetName()).c_str(),"CHDS") == 0) lvCHDS = (*lvcite);
00029     if (strcmp(((*lvcite)->GetName()).c_str(),"CAER") == 0) lvCAER = (*lvcite);
00030     if (strcmp(((*lvcite)->GetName()).c_str(),"CEDR") == 0) lvCEDR = (*lvcite);
00031     if (strcmp(((*lvcite)->GetName()).c_str(),"CAHR") == 0) lvCAHR = (*lvcite);
00032     if (strcmp(((*lvcite)->GetName()).c_str(),"CHDR") == 0) lvCHDR = (*lvcite);
00033     if (strcmp(((*lvcite)->GetName()).c_str(),"C3EF") == 0) lvC3EF = (*lvcite);
00034     if (strcmp(((*lvcite)->GetName()).c_str(),"C3HF") == 0) lvC3HF = (*lvcite);
00035     if (strcmp(((*lvcite)->GetName()).c_str(),"C4EF") == 0) lvC4EF = (*lvcite);
00036     if (strcmp(((*lvcite)->GetName()).c_str(),"C4HF") == 0) lvC4HF = (*lvcite);
00037   }
00038 #ifdef debug
00039   LogDebug("ForwardSim") << "CastorNumberingScheme:: LogicalVolume pointers\n"
00040                          << lvCAST << " for CAST; " << lvCAES << " for CAES; "
00041                          << lvCEDS << " for CEDS; " << lvCAHS << " for CAHS; "
00042                          << lvCHDS << " for CHDS; " << lvCAER << " for CAER; "
00043                          << lvCEDR << " for CEDR; " << lvCAHR << " for CAHR; "
00044                          << lvCHDR << " for CHDR; " << lvC3EF << " for C3EF; "
00045                          << lvC3HF << " for C3HF; " << lvC4EF << " for C4EF; "
00046                          << lvC4HF << " for C4HF.";
00047 #endif
00048 }
00049 
00050 CastorNumberingScheme::~CastorNumberingScheme() {
00051   edm::LogInfo("ForwardSim") << "Deleting CastorNumberingScheme";
00052 }
00053 
00054 uint32_t CastorNumberingScheme::getUnitID(const G4Step* aStep) const {
00055 
00056   uint32_t intindex = 0;
00057 
00058   uint32_t index=0;
00059   int      level, copyno[20];
00060   lvp      lvs[20];
00061   detectorLevel(aStep, level, copyno, lvs);
00062 
00063 #ifdef debug
00064   LogDebug("ForwardSim") << "CastorNumberingScheme number of levels= " <<level;
00065 #endif
00066 
00067   if (level > 0) {
00068 
00069     int zside   = 0;
00070     int sector  = 0;
00071     int module = 0;
00072 
00073     //    HcalCastorDetId::Section section;
00074      for (int ich=0; ich  <  level; ich++) {
00075        if(lvs[ich] == lvCAST) {
00076      // Z index +Z = 1 ; -Z = 2
00077      zside   = copyno[ich];
00078        } else if(lvs[ich] == lvCAES || lvs[ich] == lvCEDS) {
00079      // sector number for dead material 1 - 8
00080      //section = HcalCastorDetId::EM;
00081      if (copyno[ich]<5) {sector = 5-copyno[ich] ;
00082           }else{sector = 13-copyno[ich] ;}  
00083        } else if(lvs[ich] == lvCAHS || lvs[ich] == lvCHDS) {
00084      // sector number for dead material 1 - 8
00085      if (copyno[ich]<5) {sector = 5-copyno[ich] ;
00086           }else{sector = 13-copyno[ich] ;}
00087       //section = HcalCastorDetId::HAD;
00088        } else if(lvs[ich] == lvCAER || lvs[ich] == lvCEDR) {
00089      // zmodule number 1-2 for EM section (2 copies)
00090      module = copyno[ich];
00091        } else if(lvs[ich] == lvCAHR || lvs[ich] == lvCHDR) {
00092      //zmodule number 3-14 for HAD section (12 copies)
00093      module = copyno[ich] + 2;
00094        } else if(lvs[ich] == lvC3EF || lvs[ich] == lvC3HF) {
00095      // sector number for sensitive material 1 - 16
00096      sector = sector*2  ;
00097        } else if(lvs[ich] == lvC4EF || lvs[ich] == lvC4HF) {
00098      // sector number for sensitive material 1 - 16
00099      sector = sector*2 -1;
00100        }
00101    
00102     
00103     
00104 #ifdef debug
00105       LogDebug("ForwardSim") << "CastorNumberingScheme  " << "ich = " << ich  
00106                              << "copyno" << copyno[ich] << "name = " 
00107                              << lvs[ich]->GetName();
00108 #endif
00109     }
00110     // use for Castor number 9 
00111     // 
00112     // Z index +Z = 1 ; -Z = 2
00113     // sector number 1 - 16
00114     // zmodule number  1 - 18
00115 
00116 
00117     //    int det = 9; 
00118     //    intindex = packIndex (det, zside, sector, zmodule);
00119 
00120     //intindex = packIndex (section, zside, sector, module);
00121 
00122     intindex = packIndex(zside, sector, module);
00123 
00124     bool true_for_positive_eta = false;
00125     if(zside == 1)true_for_positive_eta = true;
00126     if(zside == -1)true_for_positive_eta = false;
00127 
00128     HcalCastorDetId castorId = HcalCastorDetId(true_for_positive_eta, sector, module);
00129     index = castorId.rawId();
00130 
00131 #ifdef debug
00132     LogDebug("ForwardSim") << "CastorNumberingScheme :" <<" zside "
00133                            << zside << " sector " << sector << " module " 
00134                            << module << " UnitID 0x" << std::hex << intindex 
00135                            << std::dec;
00136 #endif
00137   }
00138   return index;
00139   
00140 }
00141 
00142 //uint32_t CastorNumberingScheme::packIndex(int section, int z, int sector,  int module ) {
00143 
00144 uint32_t CastorNumberingScheme::packIndex(int z, int sector, int module) {
00145   /*
00146   uint32_t idx=(section&31)<<28;     //bits 28-31   (21-27 are free for now)
00147   idx+=((z-1)&1)<<20;                //bits  20  (1...2)
00148   idx+=(sector&15)<<6;               //bits  6-9 (1...16)
00149   idx+=(module&63);                 //bits  0-5 (1...18)
00150   return idx;
00151   */
00152 
00153   uint32_t idx=((z-1)&1)<<8;       //bit 8
00154   idx+=(sector&15)<<4;             //bits  4-7 (1...16)
00155   idx+=(module&15);                 //bits  0-3 (1...14)
00156   return idx;
00157 
00158 }
00159 
00160 //void CastorNumberingScheme::unpackIndex(const uint32_t& idx, int& section, int& z, int& sector, int& module) {
00161 
00162 void CastorNumberingScheme::unpackIndex(const uint32_t& idx, int& z, int& sector, int& module) {
00163   /*
00164   section = (idx>>28)&31;
00165   z   = (idx>>20)&1;
00166   z  += 1;
00167   sector = (idx>>6)&15;
00168   module= (idx&63);
00169   */
00170   z   = (idx>>8)&1;
00171   z  += 1;
00172   sector = (idx>>4)&15;
00173   module= (idx&15);
00174 }
00175   
00176 void CastorNumberingScheme::detectorLevel(const G4Step* aStep, int& level,
00177                                           int* copyno, lvp* lvs) const {
00178  
00179   //Get name and copy numbers
00180   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00181   level = 0;
00182   if (touch) level = ((touch->GetHistoryDepth())+1);
00183   if (level > 0) {
00184     for (int ii = 0; ii < level; ii++) {
00185       int i      = level - ii - 1;
00186       lvs[ii]    = touch->GetVolume(i)->GetLogicalVolume();
00187       copyno[ii] = touch->GetReplicaNumber(i);
00188     }
00189   }
00190 }