CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PltSD.cc
Go to the documentation of this file.
3 
6 
7 #include "G4Step.hh"
8 #include "G4StepPoint.hh"
9 #include "G4Track.hh"
10 #include "G4ThreeVector.hh"
11 
12 #include "CLHEP/Units/GlobalSystemOfUnits.h"
13 #include "CLHEP/Units/GlobalPhysicalConstants.h"
14 
15 #include <iostream>
16 
17 //#define EDM_ML_DEBUG
18 
20  const SensitiveDetectorCatalog& clg,
21  edm::ParameterSet const& p,
22  const SimTrackManager* manager)
23  : TimingSD(name, clg, manager) {
24  edm::ParameterSet m_TrackerSD = p.getParameter<edm::ParameterSet>("PltSD");
25  energyCut =
26  m_TrackerSD.getParameter<double>("EnergyThresholdForPersistencyInGeV") * CLHEP::GeV; //default must be 0.5
28  m_TrackerSD.getParameter<double>("EnergyThresholdForHistoryInGeV") * CLHEP::GeV; //default must be 0.05
29 
30  setCuts(energyCut, energyHistoryCut);
31 }
32 
34 
35 uint32_t PltSD::setDetUnitId(const G4Step* aStep) {
36  unsigned int detId = 0;
37 
38 #ifdef EDM_ML_DEBUG
39  edm::LogVerbatim("PltSD") << " DetID = " << detId;
40 #endif
41  //Find number of levels
42  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
43  int level = 0;
44  if (touch)
45  level = ((touch->GetHistoryDepth()) + 1);
46 
47  //Get name and copy numbers
48  if (level > 1) {
49  //some debugging with the names
50  std::string sensorName = ForwardName::getName(touch->GetVolume(2)->GetName());
51  std::string telName = ForwardName::getName(touch->GetVolume(3)->GetName());
52  std::string volumeName = ForwardName::getName(touch->GetVolume(4)->GetName());
53  if (sensorName != "PLTSensorPlane")
54  edm::LogVerbatim("PltSD") << " PltSD::setDetUnitId -w- Sensor name not PLTSensorPlane ";
55  if (telName != "Telescope")
56  edm::LogVerbatim("PltSD") << " PltSD::setDetUnitId -w- Telescope name not Telescope ";
57  if (volumeName != "PLT")
58  edm::LogVerbatim("PltSD") << " PltSD::setDetUnitId -w- Volume name not PLT ";
59 
60  //Get the information about which telescope, plane, row/column was hit
61  int columnNum = touch->GetReplicaNumber(0);
62  int rowNum = touch->GetReplicaNumber(1);
63  int sensorNum = touch->GetReplicaNumber(2);
64  int telNum = touch->GetReplicaNumber(3);
65  //temp stores the PLTBCM volume the hit occured in (i.e. was the hit on the + or -z side?)
66  int temp = touch->GetReplicaNumber(5);
67  //convert to the PLT hit id standard
68  int pltNum;
69  if (temp == 2)
70  pltNum = 0;
71  else
72  pltNum = 1;
73 
74  //correct the telescope numbers on the -z side to have the same naming convention in phi as the +z side
75  if (pltNum == 0) {
76  if (telNum == 0) {
77  telNum = 7;
78  } else if (telNum == 1) {
79  telNum = 6;
80  } else if (telNum == 2) {
81  telNum = 5;
82  } else if (telNum == 3) {
83  telNum = 4;
84  } else if (telNum == 4) {
85  telNum = 3;
86  } else if (telNum == 5) {
87  telNum = 2;
88  } else if (telNum == 6) {
89  telNum = 1;
90  } else if (telNum == 7) {
91  telNum = 0;
92  }
93  }
94  //the PLT is divided into sets of telescopes on the + and -x sides
95  int halfCarriageNum = -1;
96 
97  //If the telescope is on the -x side of the carriage, halfCarriageNum=0. If on the +x side, it is = 1.
98  if (telNum == 0 || telNum == 1 || telNum == 2 || telNum == 3)
99  halfCarriageNum = 0;
100  else
101  halfCarriageNum = 1;
102  //correct the telescope numbers of the +x half-carriage to range from 0 to 3
103  if (halfCarriageNum == 1) {
104  if (telNum == 4) {
105  telNum = 0;
106  } else if (telNum == 5) {
107  telNum = 1;
108  } else if (telNum == 6) {
109  telNum = 2;
110  } else if (telNum == 7) {
111  telNum = 3;
112  }
113  }
114  //Define unique detId for each pixel. See https://twiki.cern.ch/twiki/bin/viewauth/CMS/PLTSimulationGuide for more information
115  detId =
116  10000000 * pltNum + 1000000 * halfCarriageNum + 100000 * telNum + 10000 * sensorNum + 100 * rowNum + columnNum;
117 #ifdef EDM_ML_DEBUG
118  edm::LogVerbatim("PltSD") << "Hit Recorded at "
119  << "plt:" << pltNum << " hc:" << halfCarriageNum << " tel:" << telNum
120  << " plane:" << sensorNum;
121 #endif
122  }
123  return detId;
124 }
125 
126 bool PltSD::checkHit(const G4Step*, BscG4Hit* hit) {
127  // 50 micron are allowed between the exit
128  // point of the current hit and the entry point of the new hit
129  static const float tolerance2 = (float)(0.0025 * CLHEP::mm * CLHEP::mm);
130  return ((hit->getExitLocalP() - getLocalEntryPoint()).mag2() < tolerance2);
131 }
Log< level::Info, true > LogVerbatim
const G4ThreeVector & getLocalEntryPoint() const
Definition: TimingSD.h:62
void setCuts(double eCut, double historyCut)
Definition: TimingSD.cc:89
bool checkHit(const G4Step *, BscG4Hit *) override
Definition: PltSD.cc:126
T mag2() const
The vector magnitude squared. Equivalent to vec.dot(vec)
const G4ThreeVector & getExitLocalP() const
Definition: BscG4Hit.h:35
double energyHistoryCut
Definition: PltSD.h:25
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
~PltSD() override
Definition: PltSD.cc:33
PltSD(const std::string &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: PltSD.cc:19
std::string getName(const G4String &)
Definition: ForwardName.cc:3
tuple level
Definition: testEve_cfg.py:47
double energyCut
Definition: PltSD.h:24
uint32_t setDetUnitId(const G4Step *) override
Definition: PltSD.cc:35