Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:24:25

0001 #include "SimG4CMS/Forward/interface/BHMNumberingScheme.h"
0002 #include "SimG4CMS/Forward/interface/ForwardName.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0005 #include "globals.hh"
0006 
0007 BHMNumberingScheme::BHMNumberingScheme() { LogDebug("BHMSim") << " Creating BHMNumberingScheme"; }
0008 
0009 int BHMNumberingScheme::detectorLevel(const G4Step* aStep) const {
0010   //Find number of levels
0011   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0012   return (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
0013 }
0014 
0015 void BHMNumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* copyno, G4String* name) const {
0016   //Get name and copy numbers
0017   if (level > 0) {
0018     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0019     for (int ii = 0; ii < level; ++ii) {
0020       int i = level - ii - 1;
0021       name[ii] = ForwardName::getName(touch->GetVolume(i)->GetName());
0022       copyno[ii] = touch->GetReplicaNumber(i);
0023     }
0024   }
0025 }
0026 
0027 unsigned int BHMNumberingScheme::getUnitID(const G4Step* aStep) const {
0028   unsigned intindex = 0;
0029   int level = detectorLevel(aStep);
0030 
0031   LogDebug("BHMSim") << "BHMNumberingScheme number of levels= " << level;
0032   if (level > 0) {
0033     int* copyno = new int[level];
0034     G4String* name = new G4String[level];
0035     detectorLevel(aStep, level, copyno, name);
0036 
0037     if (level > 3) {
0038       int subdet = copyno[0];
0039       int zside = copyno[3];
0040       int station = copyno[1];
0041       intindex = packIndex(subdet, zside, station);
0042       LogDebug("BHMSim") << "BHMNumberingScheme : subdet " << subdet << " zside " << zside << " station " << station;
0043     }
0044     delete[] copyno;
0045     delete[] name;
0046   }
0047   LogDebug("BHMSim") << "BHMNumberingScheme : UnitID 0x" << std::hex << intindex << std::dec;
0048 
0049   return intindex;
0050 }
0051 
0052 unsigned int BHMNumberingScheme::packIndex(int subdet, int zside, int station) {
0053   unsigned int idx = ((6 << 28) | (subdet & 0x7) << 25);  // Use 6 as the detector name
0054   idx |= ((zside & 0x3) << 5) | (station & 0x1F);         // bits 0-4:station 5-6:side
0055   LogDebug("BHMSim") << "BHM packing: subdet " << subdet << " zside  " << zside << " station " << station << "-> 0x"
0056                      << std::hex << idx << std::dec;
0057   return idx;
0058 }
0059 
0060 void BHMNumberingScheme::unpackIndex(const unsigned int& idx, int& subdet, int& zside, int& station) {
0061   subdet = (idx >> 25) >> 0x7;
0062   zside = (idx >> 5) & 0x3;
0063   station = idx & 0x1F;
0064   LogDebug("BHMSim") << " Bsc unpacking: 0x " << std::hex << idx << std::dec << " -> subdet " << subdet << " zside  "
0065                      << zside << " station " << station;
0066 }