Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-13 01:44:05

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: BscNumberingScheme.cc
0003 // Date: 02.2006
0004 // Description: Numbering scheme for Bsc
0005 // Modifications:
0006 ///////////////////////////////////////////////////////////////////////////////
0007 #include "SimG4CMS/Forward/interface/BscNumberingScheme.h"
0008 #include "SimG4CMS/Forward/interface/ForwardName.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 //
0011 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0012 #include "globals.hh"
0013 
0014 BscNumberingScheme::BscNumberingScheme() { LogDebug("BscSim") << " Creating BscNumberingScheme"; }
0015 
0016 int BscNumberingScheme::detectorLevel(const G4Step* aStep) const {
0017   //Find number of levels
0018   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0019   return (touch) ? ((touch->GetHistoryDepth()) + 1) : 0;
0020 }
0021 
0022 void BscNumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* copyno, G4String* name) const {
0023   //Get name and copy numbers
0024   if (level > 0) {
0025     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0026     for (int ii = 0; ii < level; ++ii) {
0027       int i = level - ii - 1;
0028       name[ii] = ForwardName::getName(touch->GetVolume(i)->GetName());
0029       copyno[ii] = touch->GetReplicaNumber(i);
0030     }
0031   }
0032 }
0033 
0034 unsigned int BscNumberingScheme::getUnitID(const G4Step* aStep) const {
0035   unsigned int intindex = 0;
0036   int level = detectorLevel(aStep);
0037 
0038   LogDebug("BscSim") << "BscNumberingScheme number of levels= " << level;
0039 
0040   if (level > 0) {
0041     int* copyno = new int[level];
0042     G4String* name = new G4String[level];
0043     detectorLevel(aStep, level, copyno, name);
0044 
0045     int det = 0;
0046     int zside = 0;
0047     int station = 0;
0048     for (int ich = 0; ich < level; ich++) {
0049       // new and old set up configurations are possible:
0050       if (name[ich] == "BSC1" || name[ich] == "BSC2") {
0051         zside = copyno[ich] - 1;
0052       } else if (name[ich] == "BSCTrap") {
0053         det = 0;
0054         station = 2 * (copyno[ich] - 1);
0055       } else if (name[ich] == "BSCTubs") {
0056         det = 1;
0057         station = copyno[ich] - 1;
0058       } else if (name[ich] == "BSCTTop") {
0059         ++station;
0060       } else if (name[ich] == "BSC2Pad") {
0061         det = 2;
0062         station = copyno[ich] - 1;
0063       }
0064 
0065       LogDebug("BscSim") << "BscNumberingScheme  "
0066                          << "ich=" << ich << "copyno" << copyno[ich] << "name=" << name[ich];
0067     }
0068     intindex = packBscIndex(zside, det, station);
0069     LogDebug("BscSim") << "BscNumberingScheme : det " << det << " zside " << zside << " station " << station
0070                        << " UnitID 0x" << std::hex << intindex << std::dec;
0071 
0072     for (int ich = 0; ich < level; ich++)
0073       LogDebug("BscSim") << " name = " << name[ich] << " copy = " << copyno[ich];
0074 
0075     LogDebug("BscSim") << " packed index = 0x" << std::hex << intindex << std::dec;
0076 
0077     delete[] copyno;
0078     delete[] name;
0079   }
0080 
0081   return intindex;
0082 }
0083 
0084 unsigned int BscNumberingScheme::packBscIndex(int zside, int det, int station) {
0085   unsigned int idx = 6 << 28;  // autre numero que les detecteurs existants
0086   idx += (zside << 5) & 32;    // vaut 0 ou 1 bit 5
0087   idx += (det << 3) & 24;      //bit 3-4    det:0-1-2    2 bits:0-1
0088   idx += (station & 7);        //bits 0-2   station:0-7=8-->2**3 =8   3 bits:0-2
0089   LogDebug("BscSim") << "Bsc packing: det " << det << " zside  " << zside << " station " << station << "-> 0x"
0090                      << std::hex << idx << std::dec;
0091 
0092   //  unpackBscIndex(idx);
0093   return idx;
0094 }
0095 
0096 void BscNumberingScheme::unpackBscIndex(const unsigned int& idx) {
0097   int zside, det, station;
0098   zside = (idx & 32) >> 5;
0099   det = (idx & 24) >> 3;
0100   station = idx & 7;
0101   LogDebug("BscSim") << " Bsc unpacking: 0x " << std::hex << idx << std::dec << " -> det " << det << " zside  " << zside
0102                      << " station " << station;
0103 }