CMS 3D CMS Logo

HcalTB06BeamSD.cc
Go to the documentation of this file.
1 // File: HcalTB06BeamSD.cc
3 // Description: Sensitive Detector class for beam counters in TB06 setup
5 
17 
18 #include "G4Step.hh"
19 #include "G4Track.hh"
20 #include "G4Material.hh"
21 #include "CLHEP/Units/GlobalSystemOfUnits.h"
22 
23 //#define EDM_ML_DEBUG
24 
26  const DDCompactView & cpv,
27  const SensitiveDetectorCatalog & clg,
28  edm::ParameterSet const & p,
29  const SimTrackManager* manager) :
30  CaloSD(name, cpv, clg, p, manager) {
31 
32  // Values from NIM 80 (1970) 239-244: as implemented in Geant3
33  edm::ParameterSet m_HC = p.getParameter<edm::ParameterSet>("HcalTB06BeamSD");
34  useBirk = m_HC.getParameter<bool>("UseBirkLaw");
35  birk1 = m_HC.getParameter<double>("BirkC1")*(g/(MeV*cm2));
36  birk2 = m_HC.getParameter<double>("BirkC2");
37  birk3 = m_HC.getParameter<double>("BirkC3");
38 
39  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD:: Use of Birks law is set "
40  << "to " << useBirk << " with three "
41  << "constants kB = " << birk1 << ", C1 = "
42  << birk2 << ", C2 = " << birk3;
43 
44  std::string attribute, value;
45 
46  // Wire Chamber volume names
47  attribute = "Volume";
48  value = "WireChamber";
49  DDSpecificsMatchesValueFilter filter1{DDValue(attribute,value,0)};
50  DDFilteredView fv1(cpv,filter1);
51  wcNames = getNames(fv1);
52  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD:: Names to be tested for "
53  << attribute << " = " << value << ": "
54  << wcNames.size() << " paths";
55  for (unsigned int i=0; i<wcNames.size(); i++)
56  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD:: (" << i << ") "
57  << wcNames[i];
58 
59  //Material list for scintillator detector
60  attribute = "ReadOutName";
61  DDSpecificsMatchesValueFilter filter2{DDValue(attribute,name,0)};
62  DDFilteredView fv2(cpv,filter2);
63  bool dodet = fv2.firstChild();
64 
65  std::vector<G4String> matNames;
66  std::vector<int> nocc;
67  while (dodet) {
68  const DDLogicalPart & log = fv2.logicalPart();
69  matName = log.material().name().name();
70  bool notIn = true;
71  for (unsigned int i=0; i<matNames.size(); i++) {
72  if (matName == matNames[i]) {notIn = false; nocc[i]++;}
73  }
74  if (notIn) {
75  matNames.push_back(matName);
76  nocc.push_back(0);
77  }
78  dodet = fv2.next();
79  }
80  if (!matNames.empty()) {
81  matName = matNames[0];
82  int occ = nocc[0];
83  for (unsigned int i = 0; i < matNames.size(); i++) {
84  if (nocc[i] > occ) {
85  occ = nocc[i];
86  matName = matNames[i];
87  }
88  }
89  } else {
90  matName = "Not Found";
91  }
92  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD: Material name for "
93  << attribute << " = " << name << ":"
94  << matName;
95 }
96 
98 
99 double HcalTB06BeamSD::getEnergyDeposit(const G4Step* aStep) {
100 
101  double destep = aStep->GetTotalEnergyDeposit();
102  double weight = 1;
103  if (useBirk && matName == aStep->GetPreStepPoint()->GetMaterial()->GetName())
104  weight *= getAttenuation(aStep, birk1, birk2, birk3);
105 #ifdef EDM_ML_DEBUG
106  edm::LogVerbatim("HcalTB06BeamSD") << "HcalTB06BeamSD: Detector "
107  << aStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName()
108  << " weight " << weight;
109 #endif
110  return weight*destep;
111 }
112 
113 uint32_t HcalTB06BeamSD::setDetUnitId(const G4Step * aStep) {
114 
115  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
116  const G4VTouchable* touch = preStepPoint->GetTouchable();
117  G4String name = preStepPoint->GetPhysicalVolume()->GetName();
118 
119  int det = 1;
120  int lay = 0, x = 0, y = 0;
121  if (!isItWireChamber(name)) {
122  lay = (touch->GetReplicaNumber(0));
123  } else {
124  det = 2;
125  lay = (touch->GetReplicaNumber(1));
126  G4ThreeVector localPoint = setToLocal(preStepPoint->GetPosition(), touch);
127  x = (int)(localPoint.x()/(0.2*mm));
128  y = (int)(localPoint.y()/(0.2*mm));
129  }
130 
131  return HcalTestBeamNumbering::packIndex (det, lay, x, y);
132 }
133 
134 std::vector<G4String> HcalTB06BeamSD::getNames(DDFilteredView& fv) {
135 
136  std::vector<G4String> tmp;
137  bool dodet = fv.firstChild();
138  while (dodet) {
139  const DDLogicalPart & log = fv.logicalPart();
140  G4String name = log.name().name();
141  bool ok = true;
142  for (unsigned int i=0; i<tmp.size(); i++)
143  if (name == tmp[i]) ok = false;
144  if (ok) tmp.push_back(name);
145  dodet = fv.next();
146  }
147  return tmp;
148 }
149 
150 bool HcalTB06BeamSD::isItWireChamber (const G4String& name) {
151 
152  std::vector<G4String>::const_iterator it = wcNames.begin();
153  for (; it != wcNames.end(); it++)
154  if (name == *it) return true;
155  return false;
156 }
T getParameter(std::string const &) const
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
std::vector< G4String > wcNames
const N & name() const
Definition: DDBase.h:74
Definition: CaloSD.h:37
double getEnergyDeposit(const G4Step *) override
Definition: weight.py:1
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
static uint32_t packIndex(int det, int lay, int x, int y)
const double MeV
bool isItWireChamber(const G4String &)
HcalTB06BeamSD(const std::string &, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
bool next()
set current node to the next node in the filtered tree
const std::vector< std::string > & getNames() const
uint32_t setDetUnitId(const G4Step *step) override
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
~HcalTB06BeamSD() override
G4ThreeVector setToLocal(const G4ThreeVector &, const G4VTouchable *) const
Definition: CaloSD.cc:307
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:462
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
G4String matName
bool firstChild()
set the current node to the first child ...
const std::string & name() const
Returns the name.
Definition: DDName.cc:53
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.