Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-11-04 00:02:35

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