Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: ZdcNumberingScheme.cc
0003 // Date: 02.04
0004 // Description: Numbering scheme for Zdc
0005 // Modifications:
0006 ///////////////////////////////////////////////////////////////////////////////
0007 #include "SimG4CMS/Forward/interface/ZdcNumberingScheme.h"
0008 #include "SimG4CMS/Forward/interface/ForwardName.h"
0009 #include "DataFormats/HcalDetId/interface/HcalZDCDetId.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0012 #include <iostream>
0013 
0014 //#define EDM_ML_DEBUG
0015 
0016 ZdcNumberingScheme::ZdcNumberingScheme(int iv) {
0017   verbosity = iv;
0018   if (verbosity > 0)
0019     edm::LogVerbatim("ForwardSim") << "Creating ZDCNumberingScheme";
0020 }
0021 
0022 ZdcNumberingScheme::~ZdcNumberingScheme() {
0023   if (verbosity > 0)
0024     edm::LogVerbatim("ForwardSim") << " Deleting ZdcNumberingScheme";
0025 }
0026 
0027 void ZdcNumberingScheme::setVerbosity(const int iv) { verbosity = iv; }
0028 
0029 unsigned int ZdcNumberingScheme::getUnitID(const G4Step* aStep) const {
0030   uint32_t index = 0;
0031   int level = detectorLevel(aStep);
0032 
0033   if (level > 0) {
0034     int* copyno = new int[level];
0035     G4String* name = new G4String[level];
0036 
0037     detectorLevel(aStep, level, copyno, name);
0038 
0039     int zside = 0;
0040     int channel = 0;
0041     int fiber = 0;
0042     int layer = 0;
0043     HcalZDCDetId::Section section = HcalZDCDetId::Unknown;
0044 
0045     for (int ich = 0; ich < level; ich++) {
0046       if (name[ich] == "ZDC") {
0047         if (copyno[ich] == 1)
0048           zside = 1;
0049         if (copyno[ich] == 2)
0050           zside = -1;
0051       } else if (name[ich] == "ZDC_EMLayer") {
0052         section = HcalZDCDetId::EM;
0053 #ifdef EDM_ML_DEBUG
0054         layer = copyno[ich];
0055 #endif
0056       } else if (name[ich] == "ZDC_EMFiber") {
0057         fiber = copyno[ich];
0058         if (fiber < 20)
0059           channel = 1;
0060         else if (fiber < 39)
0061           channel = 2;
0062         else if (fiber < 58)
0063           channel = 3;
0064         else if (fiber < 77)
0065           channel = 4;
0066         else
0067           channel = 5;
0068       } else if (name[ich] == "ZDC_LumLayer") {
0069         section = HcalZDCDetId::LUM;
0070         layer = copyno[ich];
0071         channel = layer;
0072       } else if (name[ich] == "ZDC_HadLayer") {
0073         section = HcalZDCDetId::HAD;
0074         layer = copyno[ich];
0075         if (layer < 6)
0076           channel = 1;
0077         else if (layer < 12)
0078           channel = 2;
0079         else if (layer < 18)
0080           channel = 3;
0081         else
0082           channel = 4;
0083       }
0084 #ifdef EDM_ML_DEBUG
0085       else if (name[ich] == "ZDC_LumGas") {
0086         fiber = 1;
0087       } else if (name[ich] == "ZDC_HadFiber") {
0088         fiber = copyno[ich];
0089       }
0090 #endif
0091     }
0092 
0093 #ifdef EDM_ML_DEBUG
0094     unsigned intindex = 0;
0095     intindex = packZdcIndex(section, layer, fiber, channel, zside);
0096 #endif
0097 
0098     bool true_for_positive_eta = true;
0099     if (zside == -1)
0100       true_for_positive_eta = false;
0101 
0102     HcalZDCDetId zdcId(section, true_for_positive_eta, channel);
0103     index = zdcId.rawId();
0104 
0105 #ifdef EDM_ML_DEBUG
0106     edm::LogVerbatim("ForwardSim") << "DetectorId: " << zdcId;
0107 
0108     edm::LogVerbatim("ForwardSim") << "ZdcNumberingScheme:"
0109                                    << "  getUnitID - # of levels = " << level;
0110     for (int ich = 0; ich < level; ich++)
0111       edm::LogVerbatim("ForwardSim") << "  " << ich << ": copyno " << copyno[ich] << " name=" << name[ich]
0112                                      << "  section " << section << " zside " << zside << " layer " << layer << " fiber "
0113                                      << fiber << " channel " << channel << "packedIndex =" << intindex
0114                                      << " detId raw: " << std::hex << index << std::dec;
0115 
0116 #endif
0117 
0118     delete[] copyno;
0119     delete[] name;
0120   }
0121 
0122   return index;
0123 }
0124 
0125 unsigned ZdcNumberingScheme::packZdcIndex(int section, int layer, int fiber, int channel, int z) {
0126   unsigned int idx = ((z - 1) & 1) << 20;  //bit 20
0127   idx += (channel & 7) << 17;              //bits 17-19
0128   idx += (fiber & 255) << 9;               //bits 9-16
0129   idx += (layer & 127) << 2;               //bits 2-8
0130   idx += (section & 3);                    //bits 0-1
0131 
0132 #ifdef EDM_ML_DEBUG
0133   edm::LogVerbatim("ForwardSim") << "ZDC packing: section " << section << " layer  " << layer << " fiber " << fiber
0134                                  << " channel " << channel << " zside " << z << "idx: " << std::hex << idx << std::dec;
0135   int newsubdet, newlayer, newfiber, newchannel, newz;
0136   unpackZdcIndex(idx, newsubdet, newlayer, newfiber, newchannel, newz);
0137 #endif
0138 
0139   return idx;
0140 }
0141 
0142 void ZdcNumberingScheme::unpackZdcIndex(
0143     const unsigned int& idx, int& section, int& layer, int& fiber, int& channel, int& z) {
0144   z = 1 + ((idx >> 20) & 1);
0145   channel = (idx >> 17) & 7;
0146   fiber = (idx >> 9) & 255;
0147   layer = (idx >> 2) & 127;
0148   section = idx & 3;
0149 
0150 #ifdef EDM_ML_DEBUG
0151   edm::LogVerbatim("ForwardSim") << "ZDC unpacking: idx:" << idx << " -> section " << section << " layer " << layer
0152                                  << " fiber " << fiber << " channel " << channel << " zside " << z;
0153 #endif
0154 }
0155 
0156 int ZdcNumberingScheme::detectorLevel(const G4Step* aStep) const {
0157   //Find number of levels
0158   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0159   int level = 0;
0160   if (touch)
0161     level = ((touch->GetHistoryDepth()) + 1);
0162   return level;
0163 }
0164 
0165 void ZdcNumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* copyno, G4String* name) const {
0166   //Get name and copy numbers
0167   if (level > 0) {
0168     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0169     for (int ii = 0; ii < level; ii++) {
0170       int i = level - ii - 1;
0171       name[ii] = ForwardName::getName(touch->GetVolume(i)->GetName());
0172       copyno[ii] = touch->GetReplicaNumber(i);
0173     }
0174   }
0175 }