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 
19 #include "HcalTB06BeamSD.h"
20 
21 #include "G4Step.hh"
22 #include "G4Track.hh"
23 #include "G4Material.hh"
24 #include "CLHEP/Units/GlobalSystemOfUnits.h"
25 
26 //#define EDM_ML_DEBUG
27 
29  const edm::EventSetup& es,
30  const SensitiveDetectorCatalog& clg,
31  edm::ParameterSet const& p,
32  const SimTrackManager* manager)
33  : CaloSD(name, es, clg, p, manager) {
34  // Values from NIM 80 (1970) 239-244: as implemented in Geant3
35  edm::ParameterSet m_HC = p.getParameter<edm::ParameterSet>("HcalTB06BeamSD");
36  useBirk = m_HC.getParameter<bool>("UseBirkLaw");
37  birk1 = m_HC.getParameter<double>("BirkC1") * (g / (MeV * cm2));
38  birk2 = m_HC.getParameter<double>("BirkC2");
39  birk3 = m_HC.getParameter<double>("BirkC3");
40 
41  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD:: Use of Birks law is set "
42  << "to " << useBirk << " with three "
43  << "constants kB = " << birk1 << ", C1 = " << birk2 << ", C2 = " << birk3;
44 
45  std::string attribute, value;
46 
48  es.get<IdealGeometryRecord>().get(cpv);
49 
50  // Wire Chamber volume names
51  attribute = "Volume";
52  value = "WireChamber";
53  DDSpecificsMatchesValueFilter filter1{DDValue(attribute, value, 0)};
54  DDFilteredView fv1(*cpv, filter1);
55  wcNames = getNames(fv1);
56  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD:: Names to be tested for " << attribute << " = " << value << ": "
57  << wcNames.size() << " paths";
58  for (unsigned int i = 0; i < wcNames.size(); i++)
59  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD:: (" << i << ") " << wcNames[i];
60 
61  //Material list for scintillator detector
62  attribute = "ReadOutName";
63  DDSpecificsMatchesValueFilter filter2{DDValue(attribute, name, 0)};
64  DDFilteredView fv2(*cpv, filter2);
65  bool dodet = fv2.firstChild();
66 
67  std::vector<G4String> matNames;
68  std::vector<int> nocc;
69  while (dodet) {
70  const DDLogicalPart& log = fv2.logicalPart();
71  matName = log.material().name().name();
72  bool notIn = true;
73  for (unsigned int i = 0; i < matNames.size(); i++) {
74  if (matName == matNames[i]) {
75  notIn = false;
76  nocc[i]++;
77  }
78  }
79  if (notIn) {
80  matNames.push_back(matName);
81  nocc.push_back(0);
82  }
83  dodet = fv2.next();
84  }
85  if (!matNames.empty()) {
86  matName = matNames[0];
87  int occ = nocc[0];
88  for (unsigned int i = 0; i < matNames.size(); i++) {
89  if (nocc[i] > occ) {
90  occ = nocc[i];
91  matName = matNames[i];
92  }
93  }
94  } else {
95  matName = "Not Found";
96  }
97  edm::LogInfo("HcalTB06BeamSD") << "HcalTB06BeamSD: Material name for " << attribute << " = " << name << ":"
98  << matName;
99 }
100 
102 
103 double HcalTB06BeamSD::getEnergyDeposit(const G4Step* aStep) {
104  double destep = aStep->GetTotalEnergyDeposit();
105  double weight = 1;
106  if (useBirk && matName == aStep->GetPreStepPoint()->GetMaterial()->GetName())
107  weight *= getAttenuation(aStep, birk1, birk2, birk3);
108 #ifdef EDM_ML_DEBUG
109  edm::LogVerbatim("HcalTB06BeamSD") << "HcalTB06BeamSD: Detector "
110  << aStep->GetPreStepPoint()->GetTouchable()->GetVolume()->GetName() << " weight "
111  << weight;
112 #endif
113  return weight * destep;
114 }
115 
116 uint32_t HcalTB06BeamSD::setDetUnitId(const G4Step* aStep) {
117  const G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
118  const G4VTouchable* touch = preStepPoint->GetTouchable();
119  G4String name = preStepPoint->GetPhysicalVolume()->GetName();
120 
121  int det = 1;
122  int lay = 0, x = 0, y = 0;
123  if (!isItWireChamber(name)) {
124  lay = (touch->GetReplicaNumber(0));
125  } else {
126  det = 2;
127  lay = (touch->GetReplicaNumber(1));
128  G4ThreeVector localPoint = setToLocal(preStepPoint->GetPosition(), touch);
129  x = (int)(localPoint.x() / (0.2 * mm));
130  y = (int)(localPoint.y() / (0.2 * mm));
131  }
132 
133  return HcalTestBeamNumbering::packIndex(det, lay, x, y);
134 }
135 
136 std::vector<G4String> HcalTB06BeamSD::getNames(DDFilteredView& fv) {
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])
145  ok = false;
146  if (ok)
147  tmp.push_back(name);
148  dodet = fv.next();
149  }
150  return tmp;
151 }
152 
153 bool HcalTB06BeamSD::isItWireChamber(const G4String& name) {
154  std::vector<G4String>::const_iterator it = wcNames.begin();
155  for (; it != wcNames.end(); it++)
156  if (name == *it)
157  return true;
158  return false;
159 }
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:59
Definition: CaloSD.h:38
double getEnergyDeposit(const G4Step *) override
Definition: weight.py:1
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
HcalTB06BeamSD(const std::string &, const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
static uint32_t packIndex(int det, int lay, int x, int y)
const double MeV
bool isItWireChamber(const G4String &)
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:291
double getAttenuation(const G4Step *aStep, double birk1, double birk2, double birk3) const
Definition: CaloSD.cc:434
G4String matName
T get() const
Definition: EventSetup.h:73
bool firstChild()
set the current node to the first child ...
tmp
align.sh
Definition: createJobs.py:716
const std::string & name() const
Returns the name.
Definition: DDName.cc:40
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.