ATLAS Offline Software
EndcapFastSimDedicatedSD.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 
12 
15 
16 #include "GaudiKernel/Bootstrap.h"
17 #include "GaudiKernel/ISvcLocator.h"
18 
19 
21 #include "LArSimEvent/LArHit.h"
25 #include "LArG4Code/EnergySpot.h"
27 #include "StoreGate/StoreGateSvc.h"
28 #include "CLHEP/Geometry/Point3D.h"
29 #include "CLHEP/Geometry/Transform3D.h"
31 
32 using HepGeom::Point3D;
34 
35 // Constructor:
37  : IFastSimDedicatedSD("EndcapFastSimDedicatedSD", detStore)
38  , m_emecManager(nullptr)
39  , m_innerWheelCalculatorPos(nullptr)
40  , m_innerWheelCalculatorNeg(nullptr)
41  , m_outerWheelCalculatorPos(nullptr)
42  , m_outerWheelCalculatorNeg(nullptr)
43 {
44  G4cout << GetName() << "::initialize()" << G4endl;
45  if ( detStore->retrieve( m_emecManager ).isFailure() ){
46  throw std::runtime_error("Could not retrieve EMEC manager");
47  }
48 
49 
50 
51  ISvcLocator* svcLocator = Gaudi::svcLocator();
52 
53  // Access the GeoModelSvc:
54  IGeoModelSvc *geoModel=nullptr;
55  if (svcLocator->service ("GeoModelSvc",geoModel) !=StatusCode::SUCCESS) {
56  G4Exception(
57  "LArWheelSliceSolid", "AccessGeoModel", FatalException,
58  "createSolid cannot access GeoModelSvc");
59  }
60 
61  IGeoDbTagSvc *geoDbTagSvc(nullptr);
62  if ( svcLocator->service ("GeoDbTagSvc",geoDbTagSvc)!=StatusCode::SUCCESS ) {
63  G4Exception(
64  "LArWheelSliceSolid", "AccessDbTagSvc", FatalException,
65  "createSolid cannot access DbTagSvc");
66  }
67 
68  // Access the geometry database:
69  IRDBAccessSvc *pAccessSvc=nullptr;
70  if ( svcLocator->service(geoDbTagSvc->getParamSvcName(),pAccessSvc)!=StatusCode::SUCCESS) {
71  G4Exception(
72  "LArWheelSliceSolid", "AccessAccessSvc", FatalException,
73  "createSolid cannot access AccessSvc");
74  }
75 
76  DecodeVersionKey larVersionKey(geoModel, "LAr");
77  EMECData emecData=toEMECData(pAccessSvc,larVersionKey);
78 
79 
80 
85 }
86 
87 // ProcessHitsMethod
89 
90  // Fill the identifier.
91  Point3D<double> globalPosition=spot.GetPosition();
92 
95 
96 
97  Point3D<double> localPosition = globalPosition.z()<0 ? xfNeg*globalPosition : xfPos*globalPosition;
98  Point3D<double> shiftedLocalPosition = localPosition + Point3D<double>(0.0,0.0,m_emecManager->getFocalToRef()+m_emecManager->getRefToActive());
99  int zIndex = globalPosition.z()<0 ? 0:1;
100  double eta = shiftedLocalPosition.getEta();
101  double phi = localPosition.getPhi();
102  double z = localPosition.z();
103 
106  const EMECDetectorRegion *region = *e;
107  if (region->getEndcapIndex()!=zIndex) continue;
108  const EMECDetDescr *regionDescriptor=region->getDescriptor();
109  const CellBinning & etaBinning=regionDescriptor->getEtaBinning();
110  if (eta>etaBinning.getStart() && eta<etaBinning.getEnd()) {
111 
112  unsigned int etaIndex = int((eta - etaBinning.getStart())/etaBinning.getDelta()) + etaBinning.getFirstDivisionNumber();
113  unsigned int phiIndex = 0;
114  EMECCellConstLink cellPtr = region->getEMECCell(etaIndex,phiIndex);
115  double zmax = cellPtr->getZLocal(EMECCell::BACK);
116  double zmin = cellPtr->getZLocal(EMECCell::FRONT);
117  if (z>zmin && z<zmax) {
118  const CellBinning & phiBinning=regionDescriptor->getPhiBinning();
119  double minPhi=std::min(phiBinning.getStart(), phiBinning.getEnd());
120  double maxPhi=std::max(phiBinning.getStart(), phiBinning.getEnd());
121  while (phi<minPhi) phi += 2*M_PI;
122  while (phi>maxPhi) phi -= 2*M_PI;
123 
124  unsigned int regionIndex = region->getRegionIndex();
125  unsigned int samplingIndex = region->getSamplingIndex();
126  //unsigned int phiIndex = int((phi - phiBinning.getStart())/phiBinning.getDelta()) + phiBinning.getFirstDivisionNumber();
127  int wheel = region->getRadialIndex()==0 ? 2:3;
128  int sWheel = zIndex==0 ? -wheel: wheel;
129 
130  // But now we are more sophisticated...:
131 
132  LArWheelCalculator *wheelCalc=nullptr;
133  int nGaps= region->getRadialIndex()==0 ? 768:256;
134  int nBins= phiBinning.getNumDivisions();
135  int gapsPerBin = nGaps/nBins;
136 
137 
138  if (zIndex==0 && region->getRadialIndex()==0) {
139  wheelCalc=const_cast<LArWheelCalculator *> (m_outerWheelCalculatorNeg);
140  }
141  else if (zIndex==0 && region->getRadialIndex()==1){
142  wheelCalc=const_cast<LArWheelCalculator *> (m_innerWheelCalculatorPos);
143  }
144  else if (zIndex==1 && region->getRadialIndex()==0){
145  wheelCalc=const_cast<LArWheelCalculator *>(m_outerWheelCalculatorNeg);
146  }
147  else if (zIndex==1 && region->getRadialIndex()==1){
148  wheelCalc=const_cast<LArWheelCalculator *> (m_innerWheelCalculatorPos);
149  }
150  else {
151  throw std::runtime_error("Error, unknown wheel in EndcapFastSimDedicatedSD");
152  }
153 
154  int phiBin = wheelCalc->GetPhiGap(localPosition)/gapsPerBin;
155 
156  if (zIndex==0) {
157  phiBin = (nBins-2)/2 - phiBin;
158  if(phiBin < 0) {
159  phiBin += nBins;
160  }
161  }
162 
163  //std::cout << didIt << "Compare phi gap: " << nGaps << ' ' << nBins << ' ' << gapsPerBin << ':' << phiBin << '/' << phiIndex << std::endl;
164 
165  //static LArG4Identifier id;
166  m_larID.clear();
167  m_larID << 4 // LArCalorimeter
168  << 1 // LArEM
169  << sWheel
170  << samplingIndex
171  << regionIndex
172  << etaIndex
173  << phiBin;
174  // call process to add this to the collection
175  SimpleHit(m_larID, spot.GetTime(), spot.GetEnergy());
176  return;
177  }
178  }
179  }
180 
181 
182 }
EndcapFastSimDedicatedSD::EndcapFastSimDedicatedSD
EndcapFastSimDedicatedSD(StoreGateSvc *)
Definition: EndcapFastSimDedicatedSD.cxx:36
EndcapFastSimDedicatedSD.h
EMECDetectorRegion::getEndcapIndex
EMECDetectorRegion::DetectorSide getEndcapIndex() const
The endcap index.
Definition: EMECDetectorRegion.h:214
EndcapFastSimDedicatedSD::m_outerWheelCalculatorPos
LArWheelCalculator * m_outerWheelCalculatorPos
Definition: EndcapFastSimDedicatedSD.h:45
max
#define max(a, b)
Definition: cfImp.cxx:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:64
IGeoModelSvc
Definition: IGeoModelSvc.h:17
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
EMECData.h
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:79
LArG4::InnerAbsorberWheel
@ InnerAbsorberWheel
Definition: LArWheelCalculatorEnums.h:11
PixelAthClusterMonAlgCfg.zmin
zmin
Definition: PixelAthClusterMonAlgCfg.py:176
EnergySpot
Definition: EnergySpot.h:18
EMECDetectorManager.h
EMECDetDescr::getPhiBinning
const CellBinning & getPhiBinning() const
The Binning in Phi.
Definition: EMECDetDescr.h:170
EndcapFastSimDedicatedSD::ProcessSpot
void ProcessSpot(const EnergySpot &spot) override final
ProcessHitsMethod.
Definition: EndcapFastSimDedicatedSD.cxx:88
EMECData
Definition: EMECData.h:131
LArG4Identifier::clear
void clear()
M_PI
#define M_PI
Definition: ActiveFraction.h:11
EndcapFastSimDedicatedSD::m_outerWheelCalculatorNeg
LArWheelCalculator * m_outerWheelCalculatorNeg
Definition: EndcapFastSimDedicatedSD.h:46
EMECDetectorRegion
Definition: EMECDetectorRegion.h:30
IFastSimDedicatedSD
This is the interface for the fast simulation dedicated sensitive detector.
Definition: IFastSimDedicatedSD.h:13
EndcapFastSimDedicatedSD::m_innerWheelCalculatorNeg
LArWheelCalculator * m_innerWheelCalculatorNeg
Definition: EndcapFastSimDedicatedSD.h:44
LArWheelCalculator::GetPhiGap
int GetPhiGap(const CLHEP::Hep3Vector &p) const
Definition: LArWheelCalculator.h:134
EMECDetectorRegion::getAbsoluteTransform
const Amg::Transform3D & getAbsoluteTransform(const GeoAlignmentStore *alignStore=nullptr) const
Returns the absolute transform of this element.
Definition: EMECDetectorRegion.cxx:52
EMECDetDescr
Descriptor for regions of the electromagnetic endcap calorimeter.
Definition: EMECDetDescr.h:27
EMECCell::FRONT
@ FRONT
Definition: EMECCell.h:36
EMECDetectorRegion::getRadialIndex
unsigned int getRadialIndex() const
Returns the Radial (Outer Wheel=0,InnerWheel=1) Index.
Definition: EMECDetectorRegion.h:178
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
IRDBAccessSvc.h
Definition of the abstract IRDBAccessSvc interface.
EMECDetectorManager::beginDetectorRegion
EMECDetectorManager::DetectorRegionConstIterator beginDetectorRegion() const
Iterate over detector regions.
Definition: EMECDetectorManager.cxx:98
z
#define z
EnergySpot::GetEnergy
G4double GetEnergy() const
Definition: EnergySpot.h:37
IRDBAccessSvc
IRDBAccessSvc is an abstract interface to the athena service that provides the following functionalit...
Definition: IRDBAccessSvc.h:45
EMECCell::BACK
@ BACK
Definition: EMECCell.h:36
DecodeVersionKey
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
Definition: DecodeVersionKey.h:18
Amg::Transform3D
Eigen::Affine3d Transform3D
Definition: GeoPrimitives.h:46
EndcapFastSimDedicatedSD::m_emecManager
EMECDetectorManager * m_emecManager
Definition: EndcapFastSimDedicatedSD.h:42
EMECDetectorRegion::getDescriptor
const EMECDetDescr * getDescriptor() const
Returns the Descriptor for this region.
Definition: EMECDetectorRegion.h:157
PixelAthClusterMonAlgCfg.zmax
zmax
Definition: PixelAthClusterMonAlgCfg.py:176
LArWheelCalculator
Definition: LArWheelCalculator.h:58
IGeoDbTagSvc
Definition: IGeoDbTagSvc.h:26
EMECDetectorManager::getRefToActive
double getRefToActive() const
This provides the distance in CLHEP::mm from the Active EMEC volume to the reference plane.
Definition: EMECDetectorManager.h:292
EnergySpot::GetTime
G4double GetTime() const
Definition: EnergySpot.h:43
EndcapFastSimDedicatedSD::m_innerWheelCalculatorPos
LArWheelCalculator * m_innerWheelCalculatorPos
Definition: EndcapFastSimDedicatedSD.h:43
EMECDetDescr::getEtaBinning
const CellBinning & getEtaBinning() const
The Binning in Eta.
Definition: EMECDetDescr.h:177
min
#define min(a, b)
Definition: cfImp.cxx:40
CLHEPtoEigenConverter.h
LArG4SimpleSD::SimpleHit
G4bool SimpleHit(const LArG4Identifier &lar_id, G4double time, G4double energy)
First method translates to this - also for fast sims.
fillTRTHists.zIndex
int zIndex
Definition: fillTRTHists.py:15
python.PyKernel.detStore
detStore
Definition: PyKernel.py:41
dumpTgcDigiJitter.nBins
list nBins
Definition: dumpTgcDigiJitter.py:29
IGeoDbTagSvc::getParamSvcName
virtual const std::string & getParamSvcName() const =0
xAOD::phiBin
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setPhiMap phiBin
Definition: L2StandAloneMuon_v2.cxx:144
toEMECData.h
EMECDetectorManager::getDetectorRegion
const EMECDetectorRegion * getDetectorRegion(unsigned int endcap, unsigned int sampling, unsigned int region, bool inner) const
Random Access to detector regions.
Definition: EMECDetectorManager.cxx:108
EMECDetectorRegion::getSamplingIndex
unsigned int getSamplingIndex() const
Returns the Sampling Layer Index.
Definition: EMECDetectorRegion.h:164
EndcapFastSimDedicatedSD::m_larID
LArG4Identifier m_larID
My LAr identifier.
Definition: EndcapFastSimDedicatedSD.h:49
DecodeVersionKey.h
eflowRec::phiIndex
unsigned int phiIndex(float phi, float binsize)
calculate phi index for a given phi
Definition: EtaPhiLUT.cxx:23
EnergySpot.h
LArHit.h
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
IRDBRecord.h
Definition of the abstract IRDBRecord interface.
EMECDetectorRegion::getEMECCell
EMECCellConstLink getEMECCell(unsigned int ieta, unsigned int iphi) const
Access to Cells.
Definition: EMECDetectorRegion.cxx:26
LArHitContainer.h
toEMECData
EMECData toEMECData(IRDBAccessSvc *rdbAccess, const DecodeVersionKey &larVersionKey)
Definition: toEMECData.h:14
Amg::EigenTransformToCLHEP
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
Definition: CLHEPtoEigenConverter.h:120
EnergySpot::GetPosition
G4ThreeVector GetPosition() const
Definition: EnergySpot.h:40
EMECDetectorManager::getFocalToRef
double getFocalToRef() const
This provides the distance in CLHEP::mm from the Focal Plane to the reference plane.
Definition: EMECDetectorManager.h:285
EMECDetectorRegion::getRegionIndex
unsigned int getRegionIndex() const
Returns the Region Index.
Definition: EMECDetectorRegion.h:171
IRDBRecordset.h
Definition of the abstract IRDBRecordset interface.
LArG4::OuterAbsorberWheel
@ OuterAbsorberWheel
Definition: LArWheelCalculatorEnums.h:11
IGeoModelSvc.h
StoreGateSvc.h
EMECDetectorRegion.h
EMECDetectorManager::DetectorRegionConstIterator
std::vector< const EMECDetectorRegion * >::const_iterator DetectorRegionConstIterator
Definition: EMECDetectorManager.h:34
IGeoDbTagSvc.h
LArWheelCalculator.h
EMECDetectorManager::endDetectorRegion
EMECDetectorManager::DetectorRegionConstIterator endDetectorRegion() const
Iterate over detector regions.
Definition: EMECDetectorManager.cxx:103