CMS 3D CMS Logo

FP420NumberingScheme.cc

Go to the documentation of this file.
00001 
00002 // File: FP420NumberingScheme.cc
00003 // Date: 02.2006
00004 // Description: Numbering scheme for FP420
00005 // Modifications:
00007 #include "SimG4CMS/FP420/interface/FP420NumberingScheme.h"
00008 //
00009 #include "CLHEP/Units/SystemOfUnits.h"
00010 #include "globals.hh"
00011 #include <iostream>
00012 
00013 //#define debug
00014 
00015 //UserVerbosity FP420NumberingScheme::cout("FP420NumberingScheme","silent","FP420NumberingScheme");
00016 
00017 FP420NumberingScheme::FP420NumberingScheme() {
00018 //  cout.infoOut << " Creating FP420NumberingScheme" << endl;
00019 }
00020 
00021 FP420NumberingScheme::~FP420NumberingScheme() {
00022 //  cout.infoOut << " Deleting FP420NumberingScheme" << endl;
00023 }
00024 
00025                                                                                 
00026 int FP420NumberingScheme::detectorLevel(const G4Step* aStep) const {
00027                                                                                 
00028   //Find number of levels
00029   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00030   int level = 0;
00031   if (touch) level = ((touch->GetHistoryDepth())+1);
00032   return level;
00033 }
00034                                                                                 
00035 void FP420NumberingScheme::detectorLevel(const G4Step* aStep, int& level,
00036                                         int* copyno, G4String* name) const {
00037                                                                                 
00038   //Get name and copy numbers
00039   if (level > 0) {
00040     const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
00041     for (int ii = 0; ii < level; ii++) {
00042       int i      = level - ii - 1;
00043       name[ii]   = touch->GetVolume(i)->GetName();
00044       copyno[ii] = touch->GetReplicaNumber(i);
00045     }
00046   }
00047 }
00048                                                                                 
00049 
00050 
00051 
00052 unsigned int FP420NumberingScheme::getUnitID(const G4Step* aStep) const {
00053 
00054   unsigned intindex=0;
00055   int level = detectorLevel(aStep);
00056 
00057 #ifdef debug
00058 //  cout.testOut << "FP420NumberingScheme number of levels= " << level << endl;
00059 #endif
00060 
00061  //  unsigned int intIndex = 0;
00062   if (level > 0) {
00063     int*      copyno = new int[level];
00064     G4String* name   = new G4String[level];
00065     detectorLevel(aStep, level, copyno, name);
00066 
00067   //    int det   = static_cast<int>(FP420);;
00068 
00069     int det = 1; 
00070     int stationgen  = 0;
00071     int zside   = 0;
00072     int station  = 0;
00073     int plane = 0;
00074     for (int ich=0; ich  <  level; ich++) {
00075       /*
00076       // old set up configuration with equidistant stations 
00077       if(name[ich] == "FP420Ex") {
00078         stationgen   = copyno[ich];
00079       } else if(name[ich] == "SISTATION") {
00080         station   = stationgen;
00081       } else if(name[ich] == "SIPLANE") {
00082         plane   = copyno[ich];
00083       } else if(name[ich] == "SIDETL") {
00084         zside   = 1;
00085       } else if(name[ich] == "SIDETR") {
00086         zside   = 2;
00087       }
00088 */
00089       // new and old set up configurations are possible:
00090       if(name[ich] == "FP420E") {
00091         det   = copyno[ich];
00092       } else if(name[ich] == "FP420Ex1") {
00093         stationgen   = 1;
00094         //    } else if(name[ich] == "FP420Ex2") {
00095         //      stationgen   = 2;
00096       } else if(name[ich] == "FP420Ex3") {
00097         stationgen   = 2;// was =3
00098       } else if(name[ich] == "SISTATION") {
00099         station   = stationgen;
00100       } else if(name[ich] == "SIPLANE") {
00101         plane   = copyno[ich];
00102       } else if(name[ich] == "SIDETL") {
00103         zside   = 1;
00104       } else if(name[ich] == "SIDETR") {
00105         zside   = 2;
00106       }
00107 #ifdef debug
00108 //      cout.testOut << "FP420NumberingScheme  " << "ich=" << ich  << "copyno" 
00109 //                 << copyno[ich] << "name="  << name[ich] << endl;
00110 #endif
00111     }
00112     // use for FP420 number 1 
00113     // 0 is as defauld for every below:
00114     // Z index X = 1; Y = 2 
00115     // station number 1 - 5
00116     // plane number  1 - 10
00117 
00118    // intindex = myPacker.packEcalIndex (det, zside, station, plane);
00119    // intindex = myPacker.packCastorIndex (det, zside, station, plane);
00120     intindex = packFP420Index (det, zside, station, plane);
00121 
00122 
00123 #ifdef debug
00124     /*
00125     cout.debugOut << "FP420NumberingScheme : det " << det << " zside " 
00126                   << zside << " station " << station << " plane " << plane
00127                   << " UnitID 0x" << hex << intindex << dec << endl;
00128 
00129     for (int ich = 0; ich < level; ich++)
00130       cout.debugOut <<" name = " << name[ich] <<" copy = " << copyno[ich] 
00131                     << endl;
00132     cout.testOut << " packed index = 0x" << hex << intindex << dec << endl;
00133 */
00134 #endif
00135 
00136     delete[] copyno;
00137     delete[] name;
00138   }
00139 
00140   return intindex;
00141   
00142 }
00143 
00144 unsigned FP420NumberingScheme::packFP420Index(int det, int zside, int station,int plane){
00145   unsigned int idx = ((det-1)&1)<<20;     //bit 20      det:0,1=2-->2**1=2        1 bit: 0
00146   idx += (zside&3)<<7;                  //bits 7-8    zside:0-2=3-->2**2 =4     2 bits:0-1
00147   idx += (station&7)<<4;                //bits 4-6   station:0-7=8-->2**3 =8     3 bits:0-2
00148   idx += (plane&15);                    //bits 0-3    plane:  0-15=16-->2**4 =16    4 bits:0-3
00149                                                                                 
00150 #ifdef debug
00151   /*
00152   cout.testOut << "FP420 packing: det " << det 
00153  << " zside  " << zside << " station " << station  << " plane " <<  plane << "-> 0x" << hex << idx << dec <<  endl;
00154   int newdet, newzside, newstation,newplane;
00155   unpackFP420Index(idx, newdet, newzside, newstation,newplane);
00156 */
00157 #endif
00158                                                                                 
00159   return idx;
00160 }
00161 void FP420NumberingScheme::unpackFP420Index(const unsigned int& idx, int& det,
00162                                         int& zside, int& station,
00163                                         int& plane) {
00164   det  = (idx>>20)&1;
00165   det += 1;
00166   zside   = (idx>>7)&3;
00167   station = (idx>>4)&7;
00168   plane   =  idx&15;
00169                                                                                 
00170 #ifdef debug
00171   /*
00172   cout.testOut  << " FP420 unpacking: 0x " << hex << idx << dec << " -> det " <<   det
00173           << " zside  " << zside << " station " << station  << " plane " <<  plane << endl;
00174 */
00175 #endif
00176 }
00177                                                                                 

Generated on Tue Jun 9 17:46:57 2009 for CMSSW by  doxygen 1.5.4