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 LArG4Identifier& identifier_sr,
70 std::vector<double>& energies,
72 {
73 // Use the calculators to determine the energies and the
74 // identifier associated with this G4Step. Note that the
75 // default is to process both the energy and the ID.
76
77 if ( process == kEnergyAndID || process == kOnlyEnergy ) {
78 m_energyCalculator.Energies( step, energies );
79 }
80 else {
81 for (unsigned int i=0; i != 4; i++) energies.push_back( 0. );
82 }
83
84 identifier.clear();
85 if ( process == kEnergyAndID || process == kOnlyID )
86 {
87 // Calculate the identifier.
88
89 // Note:
90 // LArG4::BarrelCryostat::CryostatCalibrationCalculator uses
91 // a table-based approach to determine the identifier. The
92 // following code uses an "if-statement" approach.
93
94 // The fixed parameters (only a couple of which are readily
95 // accessible from the database):
96
97 constexpr double oneOverDeta = 10.; // 1/Deta = 1./0.1 = 10.
98 constexpr double oneOverDphi = 32./M_PI; // 1/Dphi
99
100 // Calculate the mid-point of the step, and the simple geometry variables.
101 G4VPhysicalVolume* physical = step->GetPreStepPoint()->GetPhysicalVolume();
102 //G4int copyNumber = physical->GetCopyNo();
103 G4String volumeName = physical->GetLogicalVolume()->GetName();
104
105 G4StepPoint* pre_step_point = step->GetPreStepPoint();
106 G4StepPoint* post_step_point = step->GetPostStepPoint();
107
108 G4ThreeVector startPoint = pre_step_point->GetPosition();
109 G4ThreeVector endPoint = post_step_point->GetPosition();
110 G4ThreeVector p = (startPoint + endPoint) * 0.5;
111
112 G4double rho = p.perp();
113 G4double eta = fabs( p.pseudoRapidity() );
114 G4double phi = p.phi();
115 if ( phi < 0. ) phi += 2.*M_PI; // Normalize for phiBin calculation
116
117 // Initialize identifier variables with (invalid) default
118 // values (INT_MIN is defined in <climits>).
119 G4int sampling = INT_MIN;
120 G4int region = INT_MIN;
121 G4int etaBin = INT_MIN;
122 // subdet = +/-4 "+" or " -" according to sign of Z in World coorinate
123 G4int subdet = ( p.z() > 0.) ? 4 : -4;
124 G4int type = 1;
125 G4int phiBin = (int) ( phi * oneOverDphi );
126 if (phiBin>63) phiBin=0;
127
128 constexpr double rho12 = 1386.+10.; // use old hardcoded 1386 for Sampling 1-2 transition
129 // and add 10mm for safety (misalignment)
130
131 if ( eta < 1.0 )
132 {
133 if ( rho < rho12) // LAr::Barrel::Cryostat::OuterWall
134 {
135 sampling = 1;
136 region = 1;
137 etaBin = (int) ( eta * oneOverDeta );
138 }
139 else
140 {
141 sampling = 2;
142 region = 0;
143 etaBin = (int) ( eta * oneOverDeta );
144 }
145 }
146 else if ( eta < 1.5 )
147 {
148 if ( rho < rho12) // LAr::Barrel::Cryostat::OuterWall
149 {
150 sampling = 1;
151 region = 1;
152 etaBin = (int) ( eta * oneOverDeta );
153 }
154 else
155 {
156 sampling = 2;
157 region = 2;
158 etaBin = (int) ( (eta-1.) * oneOverDeta );
159 }
160 }
161 else if ( eta < 1.6 )
162 {
163 sampling = 1;
164 region = 4;
165 etaBin = (int) ( (eta-1.5) * oneOverDeta );
166 }
167 else if ( eta < 1.8 )
168 {
169 sampling = 1;
170 region = 5;
171 etaBin = (int) ( (eta-1.5) * oneOverDeta );
172 }
173 else
174 {
175 sampling = 1;
176 region = 6;
177 etaBin = (int) ( (eta-1.3) * oneOverDeta );
178 }
179
180 // What if we have a G4Step that isn't handled by the above
181 // code? Answer: Use a "backup" calculator to try to
182 // process the step.
183
184 if ( type == INT_MIN ||
185 region == INT_MIN ||
186 sampling == INT_MIN ||
187 etaBin == INT_MIN ||
188 phiBin < 0 )
189 {
190#if defined (DEBUG_VOLUMES) || defined (DEBUG_HITS)
191 constexpr G4int messageMax = 10;
192 static std::atomic<G4int> messageCount = 0;
193 if ( messageCount++ < messageMax )
194 {
195 std::cout << "LArG4::BarrelCryostat::CalibrationMixedCalculator::Process"
196 << " (error " << messageCount << " of " << messageMax << " max displayed)"
197 << std::endl
198 << " G4Step in '"
199 << step->GetPreStepPoint()->GetPhysicalVolume()->GetName()
200 << "', using backup calculator"
201 << std::endl;
202 }
203#endif
204 m_backupCalculator->Process(step, identifier, identifier_sr, energies, process);
205 }
206 else
207 {
208 // Append the cell ID to the (empty) identifier.
209 identifier << 10 // Calorimeter
210 << subdet // LAr +/-4 where "+" or " -" according to
211 // the sign of Z in World coorinate
212 << type
213 << sampling
214 << region
215 << etaBin
216 << phiBin;
217 }
218 }
219
220#ifdef DEBUG_HITS
221 G4double energy = accumulate(energies.begin(),energies.end(),0.);
222 std::cout << "LArG4::BarrelCryostat::CalibrationMixedCalculator::Process"
223 << " ID=" << std::string(identifier)
224 << " energy=" << energy
225 << " energies=(" << energies[0]
226 << "," << energies[1]
227 << "," << energies[2]
228 << "," << energies[3] << ")"
229 << std::endl;
230#endif
231
232 // Check for bad result.
233 return ( identifier != LArG4Identifier() );
234 }
235
236 } // namespace BarrelCryostat
237
238} // 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, LArG4Identifier &identifier_sr, std::vector< double > &energies, const LArG4::eCalculatorProcessing process) const override final
const std::string process
eCalculatorProcessing
@ kOnlyEnergy
@ kEnergyAndID