CMS 3D CMS Logo

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/SystemOfUnits.h"
00010 #include <iostream>
00011 
00012 #define debug
00013 
00014 CastorNumberingScheme::CastorNumberingScheme() {
00015   edm::LogInfo("ForwardSim") << "Creating CastorNumberingScheme";
00016 }
00017 
00018 CastorNumberingScheme::~CastorNumberingScheme() {
00019   edm::LogInfo("ForwardSim") << "Deleting CastorNumberingScheme";
00020 }
00021 
00022 uint32_t CastorNumberingScheme::getUnitID(const G4Step* aStep) const {
00023 
00024   uint32_t intindex = 0;
00025 
00026   uint32_t index=0;
00027   int      level = detectorLevel(aStep);
00028 
00029 #ifdef debug
00030   LogDebug("ForwardSim") << "CastorNumberingScheme number of levels= " <<level;
00031 #endif
00032 
00033   if (level > 0) {
00034     int*      copyno = new int[level];
00035     G4String* name   = new G4String[level];
00036 
00037     detectorLevel(aStep, level, copyno, name);
00038 
00039     int zside   = 0;
00040     int sector  = 0;
00041     int module = 0;
00042 
00043     //    HcalCastorDetId::Section section;
00044 
00045     for (int ich=0; ich  <  level; ich++) {
00046       if(name[ich] == "CAST") {
00047         // Z index +Z = 1 ; -Z = 2
00048         zside   = copyno[ich];
00049       } else if(name[ich] == "CAES" || name[ich] == "CEDS") {
00050         // sector number for dead material 1 - 8
00051         //section = HcalCastorDetId::EM;
00052         sector = copyno[ich];
00053       } else if(name[ich] == "CAHS" || name[ich] == "CHDS") {
00054         // sector number for dead material 1 - 8
00055         //section = HcalCastorDetId::HAD;
00056         sector = copyno[ich];
00057       } else if(name[ich] == "CAER" || name[ich] == "CEDR") {
00058         // zmodule number 1-2 for EM section (2 copies)
00059         module = copyno[ich];
00060       } else if(name[ich] == "CAHR" || name[ich] == "CHDR") {
00061         //zmodule number 3-14 for HAD section (12 copies)
00062         module = copyno[ich] + 2;  
00063       } else if(name[ich] == "C3EF" || name[ich] == "C3HF") {
00064         // sector number for sensitive material 1 - 16
00065         sector = sector*2 - 1 ;
00066       } else if(name[ich] == "C4EF" || name[ich] == "C4HF") {
00067         // sector number for sensitive material 1 - 16
00068         sector = sector*2 ;
00069       }
00070     
00071     
00072 #ifdef debug
00073       LogDebug("ForwardSim") << "CastorNumberingScheme  " << "ich = " << ich  
00074                              << "copyno" << copyno[ich] << "name = " 
00075                              << name[ich];
00076 #endif
00077     }
00078     // use for Castor number 9 
00079     // 
00080     // Z index +Z = 1 ; -Z = 2
00081     // sector number 1 - 16
00082     // zmodule number  1 - 18
00083 
00084 
00085     //    int det = 9; 
00086     //    intindex = packIndex (det, zside, sector, zmodule);
00087 
00088     //intindex = packIndex (section, zside, sector, module);
00089 
00090     intindex = packIndex(zside, sector, module);
00091 
00092     bool true_for_positive_eta;
00093     if(zside = 1)true_for_positive_eta = true;
00094     if(zside = -1)true_for_positive_eta = false;
00095 
00096     HcalCastorDetId castorId = HcalCastorDetId(true_for_positive_eta, sector, module);
00097     index = castorId.rawId();
00098 
00099 #ifdef debug
00100     LogDebug("ForwardSim") << "CastorNumberingScheme :" <<" zside "
00101                            << zside << " sector " << sector << " module " 
00102                            << module << " UnitID 0x" << std::hex << intindex 
00103                            << std::dec;
00104 #endif
00105 
00106     delete[] copyno;
00107     delete[] name;
00108   }
00109   return index;
00110   
00111 }
00112 
00113 //uint32_t CastorNumberingScheme::packIndex(int section, int z, int sector,  int module ) {
00114 
00115 uint32_t CastorNumberingScheme::packIndex(int z, int sector, int module) {
00116   /*
00117   uint32_t idx=(section&31)<<28;     //bits 28-31   (21-27 are free for now)
00118   idx+=((z-1)&1)<<20;                //bits  20  (1...2)
00119   idx+=(sector&15)<<6;               //bits  6-9 (1...16)
00120   idx+=(module&63);                 //bits  0-5 (1...18)
00121   return idx;
00122   */
00123 
00124   uint32_t idx=((z-1)&1)<<8;       //bit 8
00125   idx+=(sector&15)<<4;             //bits  4-7 (1...16)
00126   idx+=(module&15);                 //bits  0-3 (1...14)
00127   return idx;
00128 
00129 }
00130 
00131 //void CastorNumberingScheme::unpackIndex(const uint32_t& idx, int& section, int& z, int& sector, int& module) {
00132 
00133 void CastorNumberingScheme::unpackIndex(const uint32_t& idx, int& z, int& sector, int& module) {
00134   /*
00135   section = (idx>>28)&31;
00136   z   = (idx>>20)&1;
00137   z  += 1;
00138   sector = (idx>>6)&15;
00139   module= (idx&63);
00140   */
00141   z   = (idx>>8)&1;
00142   z  += 1;
00143   sector = (idx>>4)&15;
00144   module= (idx&15);
00145 }
00146 
00147 int CastorNumberingScheme::detectorLevel(const G4Step* aStep) const {
00148   
00149   //Find number of levels
00150   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00151   int level = 0;
00152   if (touch) level = ((touch->GetHistoryDepth())+1);
00153   return level;
00154 }
00155   
00156 void CastorNumberingScheme::detectorLevel(const G4Step* aStep, int& level,
00157                                           int* copyno, G4String* name) const {
00158  
00159   //Get name and copy numbers
00160   if (level > 0) {
00161     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00162     for (int ii = 0; ii < level; ii++) {
00163       int i      = level - ii - 1;
00164       name[ii]   = touch->GetVolume(i)->GetName();
00165       copyno[ii] = touch->GetReplicaNumber(i);
00166     }
00167   }
00168 }

Generated on Tue Jun 9 17:46:57 2009 for CMSSW by  doxygen 1.5.4