ATLAS Offline Software
CryostatCalibrationLArCalculator.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // LArG4::BarrelCryostat::CalibrationLArCalculator
6 // Prepared 06-Jul-2004 Bill Seligman
7 // 16-Jul-2004 M.Leltchouk - extended for LAr::Barrel::MotherVolume
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 
16 
18 //#include "LArG4Code/CalibrationDefaultCalculator.h"
19 
20 #include "G4Step.hh"
21 #include "G4StepPoint.hh"
22 #include "G4VPhysicalVolume.hh"
23 #include "G4ThreeVector.hh"
24 #include "globals.hh"
25 
26 #include <atomic>
27 #include <map>
28 #include <algorithm>
29 #include <cmath>
30 #include <climits>
31 
32 namespace LArG4 {
33 
34  namespace BarrelCryostat {
35 
37  // Methods
39 
40  CalibrationLArCalculator::CalibrationLArCalculator(const std::string& name, ISvcLocator *pSvcLocator)
41  : LArCalibCalculatorSvcImp(name, pSvcLocator)
42  , m_parameters(nullptr)
43  , m_defaultCalculator("CalibrationDefaultCalculator",name)
44  {
45  declareProperty("DefaultCalculator",m_defaultCalculator);
46  }
47 
49  // Get the default calculator (hopefully a temporary piece of code):
50  ATH_CHECK(m_defaultCalculator.retrieve());
51 
52  // Access source of detector parameters.
54  return StatusCode::SUCCESS;
55  }
56 
57 
59  {
60  // Cleanup pointers.
61  //delete m_defaultCalculator;
62  //m_defaultCalculator = 0;
63  }
64 
66  std::vector<G4double> & energies,
67  const eCalculatorProcessing process) const
68  {
69  // Use the calculators to determine the energies and the
70  // identifier associated with this G4Step. Note that the
71  // default is to process both the energy and the ID.
72 
73  if ( process == kEnergyAndID || process == kOnlyEnergy )
74  {
75  m_energyCalculator.Energies( step, energies );
76  }
77  else
78  for (unsigned int i=0; i != 4; i++) energies.push_back( 0. );
79 
80 
81  identifier.clear();
82  if ( process == kEnergyAndID || process == kOnlyID )
83  {
84  // Calculate the identifier.
85 
86  // Note:
87  // LArG4::BarrelCryostat::CryostatCalibrationCalculator uses
88  // a table-based approach to determine the identifier. The
89  // following code uses an "if-statement" approach.
90 
91  // The fixed parameters (only a couple of which are readily
92  // accessible from the database):
93 
94  constexpr double oneOverDeta = 10.; // 1/Deta = 1./0.1 = 10.
95  constexpr double oneOverDphi = 32./M_PI; // 1/Dphi
96 
97  constexpr double rhoMinPresamplerMother = 1385.*CLHEP::mm;
98  constexpr double rhoMiddlePresampler = (1385.*CLHEP::mm + 1447.*CLHEP::mm)/2.;
99  // from PresParameterDef.icc
100  // rMinPresamplerMother = 1385*CLHEP::mm;
101  // rMaxPresamplerMother = 1447*CLHEP::mm - 0.001*CLHEP::mm;
102 
103  constexpr double rhoAlignmentSafety = 10.*CLHEP::mm;
104  constexpr double rhoInFrontOfColdWall = rhoMinPresamplerMother - rhoAlignmentSafety;
105  static const double RIN_AC = m_parameters->GetValue("LArEMBRadiusInnerAccordion"); // 1500.024*CLHEP::mm; from ACCG
106  constexpr double RCUT12 = 1593.9*CLHEP::mm;
107  constexpr double RCUT23 = 1866.1*CLHEP::mm;
108  static const double ROUT_AC = m_parameters->GetValue("LArEMBRadiusOuterAccordion"); // 1960.*CLHEP::mm;
109  static const double rhoOuterAccordionWithSafety = ROUT_AC - rhoAlignmentSafety;
110  static const double LArEMBZmax = m_parameters->GetValue("LArEMBZmax"); // 3165.*CLHEP::mm
111 
112  static const double zMaxAccordionWithSafety = LArEMBZmax - 10.*CLHEP::mm;
113 
114 
115  // Calculate the mid-point of the step, and the simple geometry variables.
116 
117  G4StepPoint* pre_step_point = step->GetPreStepPoint();
118  G4StepPoint* post_step_point = step->GetPostStepPoint();
119 
120  G4ThreeVector startPoint = pre_step_point->GetPosition();
121  G4ThreeVector endPoint = post_step_point->GetPosition();
122  G4ThreeVector p = (startPoint + endPoint) * 0.5;
123 
124  G4double rho = p.perp();
125  G4double eta = fabs( p.pseudoRapidity() );
126  G4double phi = p.phi();
127  if ( phi < 0. ) phi += 2.*M_PI; // Normalize for phiBin calculation
128 
129  // subdet = +/-4 "+" or " -" according to sign of Z in World coorinate
130  G4int subdet = ( p.z() > 0.) ? 4 : -4;
131  G4int phiBin = (int) ( phi * oneOverDphi );
132  if (phiBin>63) phiBin=0;
133 
134  // Initialize identifier variables with (invalid) default
135  // values (INT_MIN is defined in <climits>).
136  G4int type = INT_MIN;
137  G4int sampling = INT_MIN;
138  G4int region = INT_MIN;
139  G4int etaBin = INT_MIN;
140 
141 
142  if(std::fabs(p.z())< 10 && eta < 0.1 && rho > rhoMinPresamplerMother && rho < ROUT_AC )
143  {
144  // type = 2 dead materials in "internal" cracks:
145  // real crack for nominal geometry at this level is +-3mm
146  // add some margin to allow for misalignement
147 
148  type = 2;
149 
150  // sampling = 0,1,2,3 (follow the corresponding calorimeter structure)
151  if ( rho < RIN_AC ) { sampling = 0; }
152  else if ( rho < RCUT12 ) { sampling = 1; }
153  else if ( rho < RCUT23 ) { sampling = 2; }
154  else { sampling = 3; }
155 
156  // region = 0 - between two halves of EMB,
157  region = 0;
158  etaBin = 0;
159  }
160  else
161  {
162  // type = 1 dead materials outside accordion and active presampler layers
163  type = 1;
164 
165  if( eta < 1.5 )
166  {
167  if ( rho < rhoInFrontOfColdWall ) // and in LAr::Barrel::MotherVolume
168 
169  // The region is defined correctly for a radial mis-alignments
170  // up to 10mm because ColdWallThickness >= 20mm and
171  // rhoAlignmentSafety = 10.*mm;
172  // The E-deposit in the Cold Wall itself is handled by
173  // another calculator.
174  {
175  sampling = 1;
176  region = 0;
177  etaBin = (int) ( eta * oneOverDeta );
178  }
179  else if ( rho < rhoMiddlePresampler )
180  // The region is defined correctly for a radial mis-alignments
181  // up to (1447.*mm - 1385.*mm)/2
182  // The E-deposit in the Presampler itself is handled by
183  // other calculator.
184  {
185  sampling = 1;
186  region = 2;
187  etaBin = (int) ( eta * oneOverDeta );
188  }
189  else if ( rho < rhoOuterAccordionWithSafety &&
190  fabs( p.z()) < zMaxAccordionWithSafety )
191  // The region is defined correctly for a radial mis-alignments
192  // up to 10mm because rhoAlignmentSafety = 10.*mm;
193  // The E-deposit in the Barrel Accordion itself is handled by
194  // other calculator.
195  {
196  sampling = 1;
197  region = 3;
198  etaBin = (int) ( eta * oneOverDeta );
199  }
200  else // rho > ROUT_AC or |z| >= zMaxAccordionWithSafety
201  {
202  sampling = 2;
203 
204  if( eta < 1.0 )
205  {
206  region = 0;
207  etaBin = (int) ( eta * oneOverDeta );
208  }
209  else // 1.0 <= eta < 1.5
210  {
211  region = 2;
212  etaBin = (int) ( (eta-1.) * oneOverDeta );
213  }
214  }
215  }
216  else if ( eta < 1.6 )
217  {
218  sampling = 1;
219  region = 4;
220  etaBin = (int) ( (eta-1.5) * oneOverDeta );
221  }
222  else if ( eta < 1.8 )
223  {
224  sampling = 1;
225  region = 5;
226  etaBin = (int) ( (eta-1.6) * oneOverDeta );
227  }
228  else if ( eta < 3.2 )
229  {
230  sampling = 1;
231  region = 6;
232  etaBin = (int) ( (eta-1.8) * oneOverDeta );
233  }
234  }
235 
236  // This is a "quick fix" for a complex issue: We're still
237  // developing code for the cryostat. What if, somehow, we have
238  // a G4Step in a LAr volume that isn't handled by the above
239  // code? Answer: Use the default calibration calculator (the
240  // same one used for volumes without sensitive detectors) to get
241  // the identifier.
242 
243  if ( type == INT_MIN ||
244  region == INT_MIN ||
245  sampling == INT_MIN ||
246  etaBin == INT_MIN ||
247  phiBin < 0 )
248  {
249 #if defined (DEBUG_VOLUMES) || defined (DEBUG_HITS)
250  constexpr G4int messageMax = 10;
251  static std::atomic<G4int> messageCount = 0;
252  if ( messageCount++ < messageMax )
253  {
254  std::cout << "LArG4::BarrelCryostat::CalibrationLArCalculator::Process"
255  << " (error " << messageCount << " of " << messageMax << " max displayed)"
256  << std::endl
257  << " G4Step in LAr at unexpected place: (x,y,z) [mm] = ("
258  << p.x()/CLHEP::mm << ","
259  << p.y()/CLHEP::mm << ","
260  << p.z()/CLHEP::mm
261  << "); eta=" << eta
262  << ", phi=" << phi << std::endl
263  << " using default calculator"
264  << std::endl;
265  }
266 #endif
267  m_defaultCalculator->Process(step, identifier, energies, process);
268  }
269  else
270  {
271  // Append the cell ID to the (empty) identifier.
272  identifier << 10 // Calorimeter
273  << subdet // LAr +/-4 where "+" or " -" according to
274  // the sign of Z in World coorinate
275  << type
276  << sampling
277  << region
278  << etaBin
279  << phiBin;
280  }
281  }
282 
283 #ifdef DEBUG_HITS
284  G4double energy = accumulate(energies.begin(),energies.end(),0.);
285  std::cout << "LArG4::BarrelCryostat::CalibrationLArCalculator::Process"
286  << " ID=" << std::string(identifier)
287  << " energy=" << energy
288  << " energies=(" << energies[0]
289  << "," << energies[1]
290  << "," << energies[2]
291  << "," << energies[3] << ")"
292  << std::endl;
293 #endif
294 
295  // Check for bad result.
296  if ( identifier == LArG4Identifier() )
297  return false;
298 
299  return true;
300  }
301 
302  } // namespace BarrelCryostat
303 
304 } // namespace LArG4
CaloG4::SimulationEnergies::Energies
void Energies(const G4Step *, std::vector< G4double > &) const
The simple method to call from a calibration calculator: Examine the G4Step and return the energies r...
LArG4Identifier
Definition: LArG4Identifier.h:121
LArCalibCalculatorSvcImp
Definition: LArCalibCalculatorSvcImp.h:12
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
accumulate
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
Definition: FPGATrackSimMatrixAccumulator.cxx:22
LArG4::kOnlyEnergy
@ kOnlyEnergy
Definition: LArG4EnumDefs.h:10
M_PI
#define M_PI
Definition: ActiveFraction.h:11
CryostatCalibrationLArCalculator.h
LArG4::BarrelCryostat::CalibrationLArCalculator::Process
virtual G4bool Process(const G4Step *step, LArG4Identifier &identifier, std::vector< G4double > &energies, const eCalculatorProcessing process=kEnergyAndID) const override final
Definition: CryostatCalibrationLArCalculator.cxx:65
xAOD::identifier
identifier
Definition: UncalibratedMeasurement_v1.cxx:15
LArG4
Definition: LArWheelCalculatorEnums.h:8
SUSY_SimplifiedModel_PostInclude.process
string process
Definition: SUSY_SimplifiedModel_PostInclude.py:42
LArG4::BarrelCryostat::CalibrationLArCalculator::~CalibrationLArCalculator
virtual ~CalibrationLArCalculator()
Definition: CryostatCalibrationLArCalculator.cxx:58
xAOD::etaBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
Definition: L2StandAloneMuon_v1.cxx:148
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
lumiFormat.i
int i
Definition: lumiFormat.py:85
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArG4::kOnlyID
@ kOnlyID
Definition: LArG4EnumDefs.h:10
LArG4::BarrelCryostat::CalibrationLArCalculator::initialize
StatusCode initialize() override final
Definition: CryostatCalibrationLArCalculator.cxx:48
LArG4Identifier.h
LArG4::BarrelCryostat::CalibrationLArCalculator::m_energyCalculator
CaloG4::SimulationEnergies m_energyCalculator
Definition: LArG4Barrel/src/CryostatCalibrationLArCalculator.h:69
LArGeo::VDetectorParameters::GetValue
virtual double GetValue(const std::string &, const int i0=INT_MIN, const int i1=INT_MIN, const int i2=INT_MIN, const int i3=INT_MIN, const int i4=INT_MIN) const =0
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
xAOD::phiBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setPhiMap phiBin
Definition: L2StandAloneMuon_v2.cxx:144
LArG4::BarrelCryostat::CalibrationLArCalculator::m_parameters
const LArVG4DetectorParameters * m_parameters
Definition: LArG4Barrel/src/CryostatCalibrationLArCalculator.h:72
LArG4::BarrelCryostat::CalibrationLArCalculator::m_defaultCalculator
ServiceHandle< ILArCalibCalculatorSvc > m_defaultCalculator
Definition: LArG4Barrel/src/CryostatCalibrationLArCalculator.h:74
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
LArG4::BarrelCryostat::CalibrationLArCalculator::CalibrationLArCalculator
CalibrationLArCalculator(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CryostatCalibrationLArCalculator.cxx:40
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArCellBinning.step
step
Definition: LArCellBinning.py:158
LArG4::kEnergyAndID
@ kEnergyAndID
Definition: LArG4EnumDefs.h:10
LArGeo::VDetectorParameters::GetInstance
static const VDetectorParameters * GetInstance()
Definition: VDetectorParameters.cxx:29
LArG4::eCalculatorProcessing
eCalculatorProcessing
Definition: LArG4EnumDefs.h:10
fitman.rho
rho
Definition: fitman.py:532