ATLAS Offline Software
CryostatCalibrationMixedCalculator.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::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 
31 namespace LArG4 {
32 
33  namespace BarrelCryostat {
34 
36  // Methods
38 
39  CalibrationMixedCalculator::CalibrationMixedCalculator(const std::string& name, ISvcLocator *pSvcLocator)
40  : LArCalibCalculatorSvcImp(name, pSvcLocator)
41  , m_backupCalculator("BarrelCryostatCalibrationLArCalculator",name)
42  {
43  declareProperty("BackupCalculator", m_backupCalculator);
44  }
45 
47  // Get a "backup" calculator.
48  ATH_CHECK(m_backupCalculator.retrieve());
49 
50  return StatusCode::SUCCESS;
51  }
52 
53 
55  {
56  // Cleanup pointers.
57  //delete m_backupCalculator;
58  //m_backupCalculator = 0;
59  }
60 
61  // This calculator is intended to apply to the following volumes that have "mixed" identifiers:
62  // volumeName "LAr::Barrel::Cryostat::Cylinder::Mixed"
63  // copy number 2, 47, 49,
64  //
65  // volumeName "LAr::Barrel::Cryostat::Cone::Mixed"
66  // copy number 8, 9,
67  //
68  // volumeName "LAr::Barrel::Cryostat::Half::Cylinder::Mixed"
69  // copy number 21
70  //
71  // G. Pospelov (8-Fev-2006)
72  // Actually, this calculator is intended to apply to the following volumes
73  // LArMgr::LAr::Barrel::Cryostat::Mixed::Cylinder::*
74  // LArMgr::LAr::Barrel::Cryostat::OuterWall
75  // LArMgr::LAr::Barrel::Cryostat::InnerEndWall
76  // See also Simulation/G4Atlas/G4AtlasApps/python/atlas_calo.py and
77  // LArG4/LArG4Barrel/src/CryostatCalibrationCalculator.cxx
78 
80  std::vector<G4double> & energies,
81  const eCalculatorProcessing process) const
82  {
83  // Use the calculators to determine the energies and the
84  // identifier associated with this G4Step. Note that the
85  // default is to process both the energy and the ID.
86 
87  if ( process == kEnergyAndID || process == kOnlyEnergy )
88  {
89  m_energyCalculator.Energies( step, energies );
90  }
91  else
92  for (unsigned int i=0; i != 4; i++) energies.push_back( 0. );
93 
94 
95  identifier.clear();
96  if ( process == kEnergyAndID || process == kOnlyID )
97  {
98  // Calculate the identifier.
99 
100  // Note:
101  // LArG4::BarrelCryostat::CryostatCalibrationCalculator uses
102  // a table-based approach to determine the identifier. The
103  // following code uses an "if-statement" approach.
104 
105  // The fixed parameters (only a couple of which are readily
106  // accessible from the database):
107 
108  constexpr double oneOverDeta = 10.; // 1/Deta = 1./0.1 = 10.
109  constexpr double oneOverDphi = 32./M_PI; // 1/Dphi
110 
111  // Calculate the mid-point of the step, and the simple geometry variables.
112  G4VPhysicalVolume* physical = step->GetPreStepPoint()->GetPhysicalVolume();
113  //G4int copyNumber = physical->GetCopyNo();
114  G4String volumeName = physical->GetLogicalVolume()->GetName();
115 
116  G4StepPoint* pre_step_point = step->GetPreStepPoint();
117  G4StepPoint* post_step_point = step->GetPostStepPoint();
118 
119  G4ThreeVector startPoint = pre_step_point->GetPosition();
120  G4ThreeVector endPoint = post_step_point->GetPosition();
121  G4ThreeVector p = (startPoint + endPoint) * 0.5;
122 
123  G4double rho = p.perp();
124  G4double eta = fabs( p.pseudoRapidity() );
125  G4double phi = p.phi();
126  if ( phi < 0. ) phi += 2.*M_PI; // Normalize for phiBin calculation
127 
128  // Initialize identifier variables with (invalid) default
129  // values (INT_MIN is defined in <climits>).
130  G4int sampling = INT_MIN;
131  G4int region = INT_MIN;
132  G4int etaBin = INT_MIN;
133  // subdet = +/-4 "+" or " -" according to sign of Z in World coorinate
134  G4int subdet = ( p.z() > 0.) ? 4 : -4;
135  G4int type = 1;
136  G4int phiBin = (int) ( phi * oneOverDphi );
137  if (phiBin>63) phiBin=0;
138 
139  constexpr double rho12 = 1386.+10.; // use old hardcoded 1386 for Sampling 1-2 transition
140  // and add 10mm for safety (misalignment)
141 
142  if ( eta < 1.0 )
143  {
144  if ( rho < rho12) // LAr::Barrel::Cryostat::OuterWall
145  {
146  sampling = 1;
147  region = 1;
148  etaBin = (int) ( eta * oneOverDeta );
149  }
150  else
151  {
152  sampling = 2;
153  region = 0;
154  etaBin = (int) ( eta * oneOverDeta );
155  }
156  }
157  else if ( eta < 1.5 )
158  {
159  if ( rho < rho12) // LAr::Barrel::Cryostat::OuterWall
160  {
161  sampling = 1;
162  region = 1;
163  etaBin = (int) ( eta * oneOverDeta );
164  }
165  else
166  {
167  sampling = 2;
168  region = 2;
169  etaBin = (int) ( (eta-1.) * oneOverDeta );
170  }
171  }
172  else if ( eta < 1.6 )
173  {
174  sampling = 1;
175  region = 4;
176  etaBin = (int) ( (eta-1.5) * oneOverDeta );
177  }
178  else if ( eta < 1.8 )
179  {
180  sampling = 1;
181  region = 5;
182  etaBin = (int) ( (eta-1.5) * oneOverDeta );
183  }
184  else
185  {
186  sampling = 1;
187  region = 6;
188  etaBin = (int) ( (eta-1.3) * oneOverDeta );
189  }
190 
191  // What if we have a G4Step that isn't handled by the above
192  // code? Answer: Use a "backup" calculator to try to
193  // process the step.
194 
195  if ( type == INT_MIN ||
196  region == INT_MIN ||
197  sampling == INT_MIN ||
198  etaBin == INT_MIN ||
199  phiBin < 0 )
200  {
201 #if defined (DEBUG_VOLUMES) || defined (DEBUG_HITS)
202  constexpr G4int messageMax = 10;
203  static std::atomic<G4int> messageCount = 0;
204  if ( messageCount++ < messageMax )
205  {
206  std::cout << "LArG4::BarrelCryostat::CalibrationMixedCalculator::Process"
207  << " (error " << messageCount << " of " << messageMax << " max displayed)"
208  << std::endl
209  << " G4Step in '"
210  << step->GetPreStepPoint()->GetPhysicalVolume()->GetName()
211  << "', using backup calculator"
212  << std::endl;
213  }
214 #endif
215  m_backupCalculator->Process(step, identifier, energies, process);
216  }
217  else
218  {
219  // Append the cell ID to the (empty) identifier.
220  identifier << 10 // Calorimeter
221  << subdet // LAr +/-4 where "+" or " -" according to
222  // the sign of Z in World coorinate
223  << type
224  << sampling
225  << region
226  << etaBin
227  << phiBin;
228  }
229  }
230 
231 #ifdef DEBUG_HITS
232  G4double energy = accumulate(energies.begin(),energies.end(),0.);
233  std::cout << "LArG4::BarrelCryostat::CalibrationMixedCalculator::Process"
234  << " ID=" << std::string(identifier)
235  << " energy=" << energy
236  << " energies=(" << energies[0]
237  << "," << energies[1]
238  << "," << energies[2]
239  << "," << energies[3] << ")"
240  << std::endl;
241 #endif
242 
243  // Check for bad result.
244  if ( identifier == LArG4Identifier() )
245  return false;
246 
247  return true;
248  }
249 
250  } // namespace BarrelCryostat
251 
252 } // 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
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
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::CalibrationMixedCalculator::CalibrationMixedCalculator
CalibrationMixedCalculator(const std::string &name, ISvcLocator *pSvcLocator)
Definition: CryostatCalibrationMixedCalculator.cxx:39
xAOD::identifier
identifier
Definition: UncalibratedMeasurement_v1.cxx:15
LArG4
Definition: LArWheelCalculatorEnums.h:8
LArG4::BarrelCryostat::CalibrationMixedCalculator::~CalibrationMixedCalculator
virtual ~CalibrationMixedCalculator()
Definition: CryostatCalibrationMixedCalculator.cxx:54
SUSY_SimplifiedModel_PostInclude.process
string process
Definition: SUSY_SimplifiedModel_PostInclude.py:42
LArG4::BarrelCryostat::CalibrationMixedCalculator::m_backupCalculator
ServiceHandle< ILArCalibCalculatorSvc > m_backupCalculator
Definition: LArG4Barrel/src/CryostatCalibrationMixedCalculator.h:69
xAOD::etaBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap etaBin
Definition: L2StandAloneMuon_v1.cxx:148
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
LArG4Identifier.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
xAOD::phiBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setPhiMap phiBin
Definition: L2StandAloneMuon_v2.cxx:144
LArG4::BarrelCryostat::CalibrationMixedCalculator::Process
virtual G4bool Process(const G4Step *step, LArG4Identifier &identifier, std::vector< G4double > &energies, const eCalculatorProcessing process=kEnergyAndID) const override final
Definition: CryostatCalibrationMixedCalculator.cxx:79
LArG4::BarrelCryostat::CalibrationMixedCalculator::m_energyCalculator
CaloG4::SimulationEnergies m_energyCalculator
Definition: LArG4Barrel/src/CryostatCalibrationMixedCalculator.h:67
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
LArCellBinning.step
step
Definition: LArCellBinning.py:158
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
LArG4::kEnergyAndID
@ kEnergyAndID
Definition: LArG4EnumDefs.h:10
LArG4::BarrelCryostat::CalibrationMixedCalculator::initialize
StatusCode initialize() override final
Definition: CryostatCalibrationMixedCalculator.cxx:46
CryostatCalibrationMixedCalculator.h
LArG4::eCalculatorProcessing
eCalculatorProcessing
Definition: LArG4EnumDefs.h:10
fitman.rho
rho
Definition: fitman.py:532