ATLAS Offline Software
Loading...
Searching...
No Matches
EndcapFastSimDedicatedSD.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 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"
28#include "CLHEP/Geometry/Point3D.h"
29#include "CLHEP/Geometry/Transform3D.h"
31
32using HepGeom::Point3D;
33using HepGeom::Transform3D;
34
35// Constructor:
37 : IFastSimDedicatedSD("EndcapFastSimDedicatedSD", detStore)
38 , m_emecManager(nullptr)
43{
44 if (verbose) { 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 SmartIF<IGeoModelSvc> geoModel{svcLocator->service ("GeoModelSvc")};
55 if ( !geoModel ) {
56 G4Exception(
57 "LArWheelSliceSolid", "AccessGeoModel", FatalException,
58 "createSolid cannot access GeoModelSvc");
59 }
60
61 SmartIF<IGeoDbTagSvc> geoDbTagSvc{svcLocator->service ("GeoDbTagSvc")};
62 if ( !geoDbTagSvc ) {
63 G4Exception(
64 "LArWheelSliceSolid", "AccessDbTagSvc", FatalException,
65 "createSolid cannot access DbTagSvc");
66 }
67
68 // Access the geometry database:
69 SmartIF<IRDBAccessSvc> pAccessSvc{svcLocator->service(geoDbTagSvc->getParamSvcName())};
70 if ( !pAccessSvc ) {
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
88void EndcapFastSimDedicatedSD::ProcessSpot(const EnergySpot & spot, double weight){
89
90 // Fill the identifier.
91 Point3D<double> globalPosition=spot.GetPosition();
92
93 static const Transform3D xfPos = Amg::EigenTransformToCLHEP(m_emecManager->getDetectorRegion(1,1,0,0)->getAbsoluteTransform().inverse());
94 static const Transform3D xfNeg = Amg::EigenTransformToCLHEP(m_emecManager->getDetectorRegion(0,1,0,0)->getAbsoluteTransform().inverse());
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
105 for (e=m_emecManager->beginDetectorRegion();e!=m_emecManager->endDetectorRegion(); ++e) {
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()*weight);
176 return;
177 }
178 }
179 }
180
181
182}
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Eigen::Affine3d Transform3D
Definition of the abstract IRDBAccessSvc interface.
Definition of the abstract IRDBRecord interface.
Definition of the abstract IRDBRecordset interface.
if(febId1==febId2)
#define z
This is a helper class to query the version tags from GeoModelSvc and determine the appropriate tag a...
Descriptor for regions of the electromagnetic endcap calorimeter.
const CellBinning & getEtaBinning() const
The Binning in Eta.
const CellBinning & getPhiBinning() const
The Binning in Phi.
std::vector< constEMECDetectorRegion * >::const_iterator DetectorRegionConstIterator
EMECCellConstLink getEMECCell(unsigned int ieta, unsigned int iphi) const
Access to Cells.
unsigned int getRadialIndex() const
Returns the Radial (Outer Wheel=0,InnerWheel=1) Index.
unsigned int getRegionIndex() const
Returns the Region Index.
EMECDetectorRegion::DetectorSide getEndcapIndex() const
The endcap index.
const EMECDetDescr * getDescriptor() const
Returns the Descriptor for this region.
unsigned int getSamplingIndex() const
Returns the Sampling Layer Index.
EMECDetectorManager * m_emecManager
void ProcessSpot(const EnergySpot &spot, double weight) override final
ProcessHitsMethod.
EndcapFastSimDedicatedSD(StoreGateSvc *, bool verbose)
LArWheelCalculator * m_innerWheelCalculatorNeg
LArWheelCalculator * m_outerWheelCalculatorNeg
LArG4Identifier m_larID
My LAr identifier.
LArWheelCalculator * m_outerWheelCalculatorPos
LArWheelCalculator * m_innerWheelCalculatorPos
G4ThreeVector GetPosition() const
Definition EnergySpot.h:40
G4double GetEnergy() const
Definition EnergySpot.h:37
G4double GetTime() const
Definition EnergySpot.h:43
IFastSimDedicatedSD(const std::string &name, StoreGateSvc *detStore)
Simple constructor and destructor.
G4bool SimpleHit(const LArG4Identifier &lar_id, G4double time, G4double energy)
First method translates to this - also for fast sims.
This class separates some of the geometry details of the LAr endcap.
int GetPhiGap(const CLHEP::Hep3Vector &p) const
The Athena Transient Store API.
bool verbose
Definition hcg.cxx:73
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
EMECData toEMECData(IRDBAccessSvc *rdbAccess, const DecodeVersionKey &larVersionKey)
Definition toEMECData.h:13