Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-13 09:27:17

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // File: FP420NumberingScheme.cc
0003 // Date: 02.2006
0004 // Description: Numbering scheme for FP420
0005 // Modifications: 08.2008  mside and fside added
0006 ///////////////////////////////////////////////////////////////////////////////
0007 #include "SimG4CMS/FP420/interface/FP420NumberingScheme.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 //
0010 #include "CLHEP/Units/GlobalSystemOfUnits.h"
0011 #include "globals.hh"
0012 #include "G4Step.hh"
0013 #include <iostream>
0014 
0015 //#define EDM_ML_DEBUG
0016 
0017 FP420NumberingScheme::FP420NumberingScheme() {
0018   //  sn0=3, pn0=6, rn0=7;
0019 }
0020 
0021 FP420NumberingScheme::~FP420NumberingScheme() {
0022 #ifdef EDM_ML_DEBUG
0023   edm::LogVerbatim("FP420") << " Deleting FP420NumberingScheme";
0024 #endif
0025 }
0026 
0027 int FP420NumberingScheme::detectorLevel(const G4Step* aStep) const {
0028   //Find number of levels
0029   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0030   int level = 0;
0031   if (touch)
0032     level = ((touch->GetHistoryDepth()) + 1);
0033   return level;
0034 }
0035 
0036 void FP420NumberingScheme::detectorLevel(const G4Step* aStep, int& level, int* copyno, G4String* name) const {
0037   //Get name and copy numbers
0038   if (level > 0) {
0039     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0040     for (int ii = 0; ii < level; ii++) {
0041       int i = level - ii - 1;
0042       name[ii] = touch->GetVolume(i)->GetName();
0043       copyno[ii] = touch->GetReplicaNumber(i);
0044     }
0045   }
0046 }
0047 
0048 unsigned int FP420NumberingScheme::getUnitID(const G4Step* aStep) const {
0049   unsigned intindex = 0;
0050   int level = detectorLevel(aStep);
0051 
0052 #ifdef EDM_ML_DEBUG
0053   edm::LogVerbatim("FP420") << "FP420NumberingScheme number of levels= " << level;
0054 #endif
0055   //  unsigned int intIndex = 0;
0056   if (level > 0) {
0057     int* copyno = new int[level];
0058     G4String* name = new G4String[level];
0059     detectorLevel(aStep, level, copyno, name);
0060 
0061     //    int det   = static_cast<int>(FP420);;
0062 
0063     int det = 1;
0064     int stationgen = 0;
0065     int zside = 0;
0066     int station = 0;
0067     int plane = 0;
0068     for (int ich = 0; ich < level; ich++) {
0069       /*
0070       // old set up configuration with equidistant stations 
0071       if(name[ich] == "FP420Ex") {
0072       stationgen   = copyno[ich];
0073       } else if(name[ich] == "SISTATION") {
0074       station   = stationgen;
0075       } else if(name[ich] == "SIPLANE") {
0076       plane   = copyno[ich];
0077       } else if(name[ich] == "SIDETL") {
0078       zside   = 1;
0079       } else if(name[ich] == "SIDETR") {
0080       zside   = 2;
0081       }
0082       */
0083       // new and old set up configurations are possible:
0084       if (name[ich] == "FP420E") {
0085         det = copyno[ich];
0086       } else if (name[ich] == "HPS240E") {
0087         det = copyno[ich] + 2;
0088       } else if (name[ich] == "FP420Ex1" || name[ich] == "HPS240Ex1") {
0089         stationgen = 1;
0090         //    } else if(name[ich] == "FP420Ex2") {
0091         //  stationgen   = 2;
0092       } else if (name[ich] == "FP420Ex3" || name[ich] == "HPS240Ex3") {
0093         stationgen = 2;  // was =3
0094       } else if (name[ich] == "SISTATION" || name[ich] == "HPS240SISTATION") {
0095         station = stationgen;
0096       } else if (name[ich] == "SIPLANE" || name[ich] == "HPS240SIPLANE") {
0097         plane = copyno[ich];
0098         // SIDETL (or R) can be ether X or Y type in next schemes of readout
0099         //        !!! (=...) zside
0100         //
0101         //      1                  2     <---copyno
0102         //   Front(=2) Empty(=4) Back(=6)     <--SIDETR OR SENSOR2
0103         //      1         2              <---copyno
0104         //   Front(=1) Back(=3) Empty(=5)     <--SIDETL OR SENSOR1
0105         //
0106       } else if (name[ich] == "SENSOR2" || name[ich] == "HPS240SENSOR2") {
0107         //    } else if(name[ich] == "SIDETR") {
0108         //  zside   = 4 * copyno[ich] - 2 ;//= 2   6 (copyno=1,2)
0109         zside = 3 * copyno[ich];  //= 3   6 (copyno=1,2)
0110       } else if (name[ich] == "SENSOR1" || name[ich] == "HPS240SENSOR1") {
0111         //     } else if(name[ich] == "SIDETL") {
0112         //  zside   = 2 * copyno[ich] - 1 ;//= 1   3 (copyno=1,2)
0113         zside = copyno[ich];  //= 1   2 (copyno=1,2)
0114       }
0115       //
0116 #ifdef EDM_ML_DEBUG
0117       edm::LogVerbatim("FP420") << "FP420NumberingScheme  "
0118                                 << "ich=" << ich << "copyno" << copyno[ich] << "name=" << name[ich];
0119 #endif
0120     }
0121     // det = 1 for +FP420 ,  = 2 for -FP420  / (det-1) = 0,1
0122     // det = 3 for +HPS240 , = 4 for -HPS240 / (det-1) = 2,3
0123     // 0 is as default for every below:
0124     // Z index
0125     // station number 1 - 8   (in reality just 2 ones)
0126     // superplane(superlayer) number  1 - 16 (in reality just 5 ones)
0127 
0128     // intindex = myPacker.packEcalIndex (det, zside, station, plane);// see examples
0129     // intindex = myPacker.packCastorIndex (det, zside, station, plane);// see examples
0130     intindex = packFP420Index(det, zside, station, plane);
0131     //
0132 #ifdef EDM_ML_DEBUG
0133     edm::LogVerbatim("FP420") << "FP420NumberingScheme det=" << det << " zside=" << zside << " station=" << station
0134                               << " plane=" << plane;
0135     for (int ich = 0; ich < level; ich++) {
0136       edm::LogVerbatim("FP420") << " name = " << name[ich] << " copy = " << copyno[ich];
0137       edm::LogVerbatim("FP420") << " packed index = intindex" << intindex;
0138     }
0139 #endif
0140 
0141     delete[] copyno;
0142     delete[] name;
0143   }
0144 
0145   return intindex;
0146 }
0147 
0148 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station, int plane) {
0149   //
0150   unsigned int idx = ((det - 1) & 3) << 19;  //bit 19-20 (det-1):0- 3 = 4-->2**2 = 4  -> 4-1  ->((det-1)&3)  2 bit: 0-1
0151   // unsigned int idx = ((det-1)&1)<<20;//bit 20-20 (det-1):0- 1 = 2-->2**1 = 2  -> 2-1  ->((det-1)&1)  1 bit: 0
0152   idx += (zside & 7) << 7;  //bits  7- 9   zside:0- 7 = 8-->2**3 = 8  -> 8-1  ->  (zside&7)  3 bits:0-2
0153   //  idx += (zside&3)<<7;             //bits  7- 8   zside:0- 3 = 4-->2**2 = 4  -> 4-1  ->  (zside&3)  2 bits:0-1
0154   idx += (station & 7) << 4;  //bits  4- 6 station:0- 7 = 8-->2**3 = 8  -> 8-1  ->(station&7)  3 bits:0-2
0155   idx += (plane & 15);        //bits  0- 3   plane:0-15 =16-->2**4 =16  ->16-1  -> (plane&15)  4 bits:0-3
0156 
0157   //
0158 
0159 #ifdef EDM_ML_DEBUG
0160   edm::LogVerbatim("FP420") << "FP420 packing: det " << det << " zside  " << zside << " station " << station
0161                             << " plane " << plane << " idx " << idx;
0162 #endif
0163   //  int newdet, newzside, newstation,newplane;
0164   //  unpackFP420Index(idx, newdet, newzside, newstation,newplane);
0165 
0166   //
0167 
0168   return idx;
0169 }
0170 
0171 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det, int& zside, int& station, int& plane) {
0172   det = (idx >> 19) & 3;
0173   //det  = (idx>>20)&1;
0174   det += 1;
0175   zside = (idx >> 7) & 7;
0176   //  zside   = (idx>>7)&3;
0177   station = (idx >> 4) & 7;
0178   plane = idx & 15;
0179   //
0180 
0181 #ifdef EDM_ML_DEBUG
0182   edm::LogVerbatim("FP420") << " FP420unpacking: idx=" << idx << " zside  " << zside << " station " << station
0183                             << " plane " << plane;
0184 #endif
0185   //
0186 }