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 
93  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD: Material name for "
94  << attribute << " = " << name << ":"
95  << matName;
96 }
97 
99 
100 double HcalTB06BeamSD::getEnergyDeposit(const G4Step* aStep) {
101 
102  double destep = aStep->GetTotalEnergyDeposit();
103  double weight = 1;
104  if (useBirk && matName == aStep->GetPreStepPoint()->GetMaterial()->GetName())
105  weight *= getAttenuation(aStep, birk1, birk2, birk3);
106 #ifdef EDM_ML_DEBUG
107  edm::LogVerbatim("HcalTB06BeamSD") << "HcalTB06BeamSD: Detector "
108  << aStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName()
109  << " weight " << weight;
110 #endif
111  return weight*destep;
112 }
113 
114 uint32_t HcalTB06BeamSD::setDetUnitId(const G4Step * aStep) {
115 
116  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
117  const G4VTouchable* touch = preStepPoint->GetTouchable();
118  G4String name = preStepPoint->GetPhysicalVolume()->GetName();
119 
120  int det = 1;
121  int lay = 0, x = 0, y = 0;
122  if (!isItWireChamber(name)) {
123  lay = (touch->GetReplicaNumber(0));
124  } else {
125  det = 2;
126  lay = (touch->GetReplicaNumber(1));
127  G4ThreeVector localPoint = setToLocal(preStepPoint->GetPosition(), touch);
128  x = (int)(localPoint.x()/(0.2*mm));
129  y = (int)(localPoint.y()/(0.2*mm));
130  }
131 
132  return HcalTestBeamNumbering::packIndex (det, lay, x, y);
133 }
134 
135 std::vector<G4String> HcalTB06BeamSD::getNames(DDFilteredView& fv) {
136 
137  std::vector<G4String> tmp;
138  bool dodet = fv.firstChild();
139  while (dodet) {
140  const DDLogicalPart & log = fv.logicalPart();
141  G4String name = log.name().name();
142  bool ok = true;
143  for (unsigned int i=0; i<tmp.size(); i++)
144  if (name == tmp[i]) ok = false;
145  if (ok) tmp.push_back(name);
146  dodet = fv.next();
147  }
148  return tmp;
149 }
150 
151 bool HcalTB06BeamSD::isItWireChamber (const G4String& name) {
152 
153  std::vector<G4String>::const_iterator it = wcNames.begin();
154  for (; it != wcNames.end(); it++)
155  if (name == *it) return true;
156  return false;
157 }
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.