ATLAS Offline Software
Loading...
Searching...
No Matches
CryostatCalibrationMixedCalculator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5// LArG4::BarrelCryostat::CalibrationMixedCalculator
6// Prepared 24-Aug-2004 William Seligman
7// from code prepared by Mikhail Leltchouk
8
9// This class calculates the values needed for calibration hits in the
10// simulation.
11
12#undef DEBUG_HITS
13#define DEBUG_VOLUMES
14
17
19
20#include "G4Step.hh"
21#include "G4StepPoint.hh"
22#include "G4VPhysicalVolume.hh"
23#include "G4ThreeVector.hh"
24#include "globals.hh"
25
26#include <map>
27#include <algorithm>
28#include <cmath>
29#include <climits>
30
31namespace LArG4 {
32
33 namespace BarrelCryostat {
34
36 // Methods
38
39 CalibrationMixedCalculator::CalibrationMixedCalculator(const std::string& name, ISvcLocator *pSvcLocator)
40 : LArCalibCalculatorSvcImp(name, pSvcLocator)
41 {
42 }
43
45 // Get a "backup" calculator.
46 ATH_CHECK(m_backupCalculator.retrieve());
47 return StatusCode::SUCCESS;
48 }
49
50 // This calculator is intended to apply to the following volumes that have "mixed" identifiers:
51 // volumeName "LAr::Barrel::Cryostat::Cylinder::Mixed"
52 // copy number 2, 47, 49,
53 //
54 // volumeName "LAr::Barrel::Cryostat::Cone::Mixed"
55 // copy number 8, 9,
56 //
57 // volumeName "LAr::Barrel::Cryostat::Half::Cylinder::Mixed"
58 // copy number 21
59 //
60 // G. Pospelov (8-Fev-2006)
61 // Actually, this calculator is intended to apply to the following volumes
62 // LArMgr::LAr::Barrel::Cryostat::Mixed::Cylinder::*
63 // LArMgr::LAr::Barrel::Cryostat::OuterWall
64 // LArMgr::LAr::Barrel::Cryostat::InnerEndWall
65 // See also Simulation/G4Atlas/G4AtlasApps/python/atlas_calo.py and
66 // LArG4/LArG4Barrel/src/CryostatCalibrationCalculator.cxx
67
68 G4bool CalibrationMixedCalculator::Process(const G4Step* step, LArG4Identifier & identifier,
69 std::vector<G4double> & energies,
71 {
72 // Use the calculators to determine the energies and the
73 // identifier associated with this G4Step. Note that the
74 // default is to process both the energy and the ID.
75
76 if ( process == kEnergyAndID || process == kOnlyEnergy ) {
77 m_energyCalculator.Energies( step, energies );
78 }
79 else {
80 for (unsigned int i=0; i != 4; i++) energies.push_back( 0. );
81 }
82
83 identifier.clear();
84 if ( process == kEnergyAndID || process == kOnlyID )
85 {
86 // Calculate the identifier.
87
88 // Note:
89 // LArG4::BarrelCryostat::CryostatCalibrationCalculator uses
90 // a table-based approach to determine the identifier. The
91 // following code uses an "if-statement" approach.
92
93 // The fixed parameters (only a couple of which are readily
94 // accessible from the database):
95
96 constexpr double oneOverDeta = 10.; // 1/Deta = 1./0.1 = 10.
97 constexpr double oneOverDphi = 32./M_PI; // 1/Dphi
98
99 // Calculate the mid-point of the step, and the simple geometry variables.
100 G4VPhysicalVolume* physical = step->GetPreStepPoint()->GetPhysicalVolume();
101 //G4int copyNumber = physical->GetCopyNo();
102 G4String volumeName = physical->GetLogicalVolume()->GetName();
103
104 G4StepPoint* pre_step_point = step->GetPreStepPoint();
105 G4StepPoint* post_step_point = step->GetPostStepPoint();
106
107 G4ThreeVector startPoint = pre_step_point->GetPosition();
108 G4ThreeVector endPoint = post_step_point->GetPosition();
109 G4ThreeVector p = (startPoint + endPoint) * 0.5;
110
111 G4double rho = p.perp();
112 G4double eta = fabs( p.pseudoRapidity() );
113 G4double phi = p.phi();
114 if ( phi < 0. ) phi += 2.*M_PI; // Normalize for phiBin calculation
115
116 // Initialize identifier variables with (invalid) default
117 // values (INT_MIN is defined in <climits>).
118 G4int sampling = INT_MIN;
119 G4int region = INT_MIN;
120 G4int etaBin = INT_MIN;
121 // subdet = +/-4 "+" or " -" according to sign of Z in World coorinate
122 G4int subdet = ( p.z() > 0.) ? 4 : -4;
123 G4int type = 1;
124 G4int phiBin = (int) ( phi * oneOverDphi );
125 if (phiBin>63) phiBin=0;
126
127 constexpr double rho12 = 1386.+10.; // use old hardcoded 1386 for Sampling 1-2 transition
128 // and add 10mm for safety (misalignment)
129
130 if ( eta < 1.0 )
131 {
132 if ( rho < rho12) // LAr::Barrel::Cryostat::OuterWall
133 {
134 sampling = 1;
135 region = 1;
136 etaBin = (int) ( eta * oneOverDeta );
137 }
138 else
139 {
140 sampling = 2;
141 region = 0;
142 etaBin = (int) ( eta * oneOverDeta );
143 }
144 }
145 else if ( eta < 1.5 )
146 {
147 if ( rho < rho12) // LAr::Barrel::Cryostat::OuterWall
148 {
149 sampling = 1;
150 region = 1;
151 etaBin = (int) ( eta * oneOverDeta );
152 }
153 else
154 {
155 sampling = 2;
156 region = 2;
157 etaBin = (int) ( (eta-1.) * oneOverDeta );
158 }
159 }
160 else if ( eta < 1.6 )
161 {
162 sampling = 1;
163 region = 4;
164 etaBin = (int) ( (eta-1.5) * oneOverDeta );
165 }
166 else if ( eta < 1.8 )
167 {
168 sampling = 1;
169 region = 5;
170 etaBin = (int) ( (eta-1.5) * oneOverDeta );
171 }
172 else
173 {
174 sampling = 1;
175 region = 6;
176 etaBin = (int) ( (eta-1.3) * oneOverDeta );
177 }
178
179 // What if we have a G4Step that isn't handled by the above
180 // code? Answer: Use a "backup" calculator to try to
181 // process the step.
182
183 if ( type == INT_MIN ||
184 region == INT_MIN ||
185 sampling == INT_MIN ||
186 etaBin == INT_MIN ||
187 phiBin < 0 )
188 {
189#if defined (DEBUG_VOLUMES) || defined (DEBUG_HITS)
190 constexpr G4int messageMax = 10;
191 static std::atomic<G4int> messageCount = 0;
192 if ( messageCount++ < messageMax )
193 {
194 std::cout << "LArG4::BarrelCryostat::CalibrationMixedCalculator::Process"
195 << " (error " << messageCount << " of " << messageMax << " max displayed)"
196 << std::endl
197 << " G4Step in '"
198 << step->GetPreStepPoint()->GetPhysicalVolume()->GetName()
199 << "', using backup calculator"
200 << std::endl;
201 }
202#endif
203 m_backupCalculator->Process(step, identifier, energies, process);
204 }
205 else
206 {
207 // Append the cell ID to the (empty) identifier.
208 identifier << 10 // Calorimeter
209 << subdet // LAr +/-4 where "+" or " -" according to
210 // the sign of Z in World coorinate
211 << type
212 << sampling
213 << region
214 << etaBin
215 << phiBin;
216 }
217 }
218
219#ifdef DEBUG_HITS
220 G4double energy = accumulate(energies.begin(),energies.end(),0.);
221 std::cout << "LArG4::BarrelCryostat::CalibrationMixedCalculator::Process"
222 << " ID=" << std::string(identifier)
223 << " energy=" << energy
224 << " energies=(" << energies[0]
225 << "," << energies[1]
226 << "," << energies[2]
227 << "," << energies[3] << ")"
228 << std::endl;
229#endif
230
231 // Check for bad result.
232 return ( identifier != LArG4Identifier() );
233 }
234
235 } // namespace BarrelCryostat
236
237} // namespace LArG4
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_CHECK
Evaluate an expression and check for errors.
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
LArCalibCalculatorSvcImp(const std::string &name, ISvcLocator *pSvcLocator)
CalibrationMixedCalculator(const std::string &name, ISvcLocator *pSvcLocator)
virtual G4bool Process(const G4Step *step, LArG4Identifier &identifier, std::vector< G4double > &energies, const eCalculatorProcessing process=kEnergyAndID) const override final
const std::string process
eCalculatorProcessing
@ kOnlyEnergy
@ kEnergyAndID