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
32#include <utility>
33
34using HepGeom::Point3D;
35using HepGeom::Transform3D;
36
37// Constructor:
39 std::string hitCollectionName,
40 bool verbose)
41 : IFastSimDedicatedSD("EndcapFastSimDedicatedSD", detStore,
42 std::move(hitCollectionName))
43 , m_emecManager(nullptr)
48{
49 if (verbose) { G4cout << GetName() << "::initialize()" << G4endl; }
50 if ( detStore->retrieve( m_emecManager ).isFailure() ){
51 throw std::runtime_error("Could not retrieve EMEC manager");
52 }
53
54
55
56 ISvcLocator* svcLocator = Gaudi::svcLocator();
57
58 // Access the GeoModelSvc:
59 SmartIF<IGeoModelSvc> geoModel{svcLocator->service ("GeoModelSvc")};
60 if ( !geoModel ) {
61 G4Exception(
62 "LArWheelSliceSolid", "AccessGeoModel", FatalException,
63 "createSolid cannot access GeoModelSvc");
64 }
65
66 SmartIF<IGeoDbTagSvc> geoDbTagSvc{svcLocator->service ("GeoDbTagSvc")};
67 if ( !geoDbTagSvc ) {
68 G4Exception(
69 "LArWheelSliceSolid", "AccessDbTagSvc", FatalException,
70 "createSolid cannot access DbTagSvc");
71 }
72
73 // Access the geometry database:
74 SmartIF<IRDBAccessSvc> pAccessSvc{svcLocator->service(geoDbTagSvc->getParamSvcName())};
75 if ( !pAccessSvc ) {
76 G4Exception(
77 "LArWheelSliceSolid", "AccessAccessSvc", FatalException,
78 "createSolid cannot access AccessSvc");
79 }
80
81 DecodeVersionKey larVersionKey(geoModel, "LAr");
82 EMECData emecData=toEMECData(pAccessSvc,larVersionKey);
83
84
85
90}
91
92// ProcessHitsMethod
93void EndcapFastSimDedicatedSD::ProcessSpot(const EnergySpot & spot, double weight){
94
95 // Fill the identifier.
96 Point3D<double> globalPosition=spot.GetPosition();
97
98 static const Transform3D xfPos = Amg::EigenTransformToCLHEP(m_emecManager->getDetectorRegion(1,1,0,0)->getAbsoluteTransform().inverse());
99 static const Transform3D xfNeg = Amg::EigenTransformToCLHEP(m_emecManager->getDetectorRegion(0,1,0,0)->getAbsoluteTransform().inverse());
100
101
102 Point3D<double> localPosition = globalPosition.z()<0 ? xfNeg*globalPosition : xfPos*globalPosition;
103 Point3D<double> shiftedLocalPosition = localPosition + Point3D<double>(0.0,0.0,m_emecManager->getFocalToRef()+m_emecManager->getRefToActive());
104 int zIndex = globalPosition.z()<0 ? 0:1;
105 double eta = shiftedLocalPosition.getEta();
106 double phi = localPosition.getPhi();
107 double z = localPosition.z();
108
110 for (e=m_emecManager->beginDetectorRegion();e!=m_emecManager->endDetectorRegion(); ++e) {
111 const EMECDetectorRegion *region = *e;
112 if (region->getEndcapIndex()!=zIndex) continue;
113 const EMECDetDescr *regionDescriptor=region->getDescriptor();
114 const CellBinning & etaBinning=regionDescriptor->getEtaBinning();
115 if (eta>etaBinning.getStart() && eta<etaBinning.getEnd()) {
116
117 unsigned int etaIndex = int((eta - etaBinning.getStart())/etaBinning.getDelta()) + etaBinning.getFirstDivisionNumber();
118 unsigned int phiIndex = 0;
119 EMECCellConstLink cellPtr = region->getEMECCell(etaIndex,phiIndex);
120 double zmax = cellPtr->getZLocal(EMECCell::BACK);
121 double zmin = cellPtr->getZLocal(EMECCell::FRONT);
122 if (z>zmin && z<zmax) {
123 const CellBinning & phiBinning=regionDescriptor->getPhiBinning();
124 double minPhi=std::min(phiBinning.getStart(), phiBinning.getEnd());
125 double maxPhi=std::max(phiBinning.getStart(), phiBinning.getEnd());
126 while (phi<minPhi) phi += 2*M_PI;
127 while (phi>maxPhi) phi -= 2*M_PI;
128
129 unsigned int regionIndex = region->getRegionIndex();
130 unsigned int samplingIndex = region->getSamplingIndex();
131 //unsigned int phiIndex = int((phi - phiBinning.getStart())/phiBinning.getDelta()) + phiBinning.getFirstDivisionNumber();
132 int wheel = region->getRadialIndex()==0 ? 2:3;
133 int sWheel = zIndex==0 ? -wheel: wheel;
134
135 // But now we are more sophisticated...:
136
137 LArWheelCalculator *wheelCalc=nullptr;
138 int nGaps= region->getRadialIndex()==0 ? 768:256;
139 int nBins= phiBinning.getNumDivisions();
140 int gapsPerBin = nGaps/nBins;
141
142
143 if (zIndex==0 && region->getRadialIndex()==0) {
144 wheelCalc=const_cast<LArWheelCalculator *> (m_outerWheelCalculatorNeg);
145 }
146 else if (zIndex==0 && region->getRadialIndex()==1){
147 wheelCalc=const_cast<LArWheelCalculator *> (m_innerWheelCalculatorPos);
148 }
149 else if (zIndex==1 && region->getRadialIndex()==0){
150 wheelCalc=const_cast<LArWheelCalculator *>(m_outerWheelCalculatorNeg);
151 }
152 else if (zIndex==1 && region->getRadialIndex()==1){
153 wheelCalc=const_cast<LArWheelCalculator *> (m_innerWheelCalculatorPos);
154 }
155 else {
156 throw std::runtime_error("Error, unknown wheel in EndcapFastSimDedicatedSD");
157 }
158
159 int phiBin = wheelCalc->GetPhiGap(localPosition)/gapsPerBin;
160
161 if (zIndex==0) {
162 phiBin = (nBins-2)/2 - phiBin;
163 if(phiBin < 0) {
164 phiBin += nBins;
165 }
166 }
167
168 //std::cout << didIt << "Compare phi gap: " << nGaps << ' ' << nBins << ' ' << gapsPerBin << ':' << phiBin << '/' << phiIndex << std::endl;
169
170 //static LArG4Identifier id;
171 m_larID.clear();
172 m_larID << 4 // LArCalorimeter
173 << 1 // LArEM
174 << sWheel
175 << samplingIndex
176 << regionIndex
177 << etaIndex
178 << phiBin;
179 // call process to add this to the collection
180 SimpleHit(m_larID, spot.GetTime(), spot.GetEnergy()*weight);
181 return;
182 }
183 }
184 }
185
186
187}
#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(pathvar)
#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 *, std::string hitCollectionName, 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, std::string hitCollectionName)
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.
StatusCode retrieve(const T *&ptr) const
Retrieve the default object into a const T*.
bool verbose
Definition hcg.cxx:75
HepGeom::Transform3D EigenTransformToCLHEP(const Amg::Transform3D &eigenTransf)
Converts an Eigen-based Amg::Transform3D into a CLHEP-based HepGeom::Transform3D.
STL namespace.
EMECData toEMECData(IRDBAccessSvc *rdbAccess, const DecodeVersionKey &larVersionKey)
Definition toEMECData.h:13