ATLAS Offline Software
CSCSensitiveDetector.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 #include "CSCSensitiveDetector.h"
6 #include "G4Trd.hh"
7 #include <string>
8 #include <sstream>
10 #include "MCTruth/TrackHelper.h"
11 #include "G4Geantino.hh"
12 #include "G4ChargedGeantino.hh"
13 
15 
16 // construction/destruction
18  const std::string& hitCollectionName)
19  : G4VSensitiveDetector( name )
20  , m_myCSCHitColl( hitCollectionName )
21 {
23 }
24 
25 // Implemenation of memebr functions
26 void CSCSensitiveDetector::Initialize(G4HCofThisEvent*)
27 {
28  if (!m_myCSCHitColl.isValid()) m_myCSCHitColl = std::make_unique<CSCSimHitCollection>();
29 }
30 
31 G4bool CSCSensitiveDetector::ProcessHits(G4Step* aStep,G4TouchableHistory* /*ROHist*/) {
32 
33  G4Track* currentTrack = aStep->GetTrack();
34 
36  auto trackDef = currentTrack->GetDefinition();
37  if (trackDef->GetPDGCharge() == 0.0) {
38  if (trackDef != G4Geantino::GeantinoDefinition()) return true;
39  else if (trackDef == G4ChargedGeantino::ChargedGeantinoDefinition()) return true;
40  }
41 
42  const G4TouchableHistory* touchHist = static_cast<const G4TouchableHistory*>(aStep->GetPreStepPoint()->GetTouchable());
43  G4ThreeVector startPos=aStep->GetPreStepPoint()->GetPosition();
44  G4ThreeVector endPos=aStep->GetPostStepPoint()->GetPosition();
45  double kinEnergy = aStep->GetPreStepPoint()->GetKineticEnergy();
46 
49  std::string stationName="";
50  int stationEta=1;
51  int stationPhi=1;
52  int multiLayer=1;
53  int wireLayer=0;
54 
57  Amg::Vector3D HitStart = Amg::Vector3D(-1000,-1000,-1000);
58  Amg::Vector3D HitEnd = Amg::Vector3D(-1000,-1000,-1000);
59  double globalTime = -1;
60  double energyDeposit= -1;
61  G4int lundcode = -1;
62  // int trackid = -1;
63 
66  bool isAssembly = false;
67  for (int i = touchHist->GetHistoryDepth(); i>=0; --i) {
68  std::string::size_type npos;
69  std::string volName = touchHist->GetVolume(i)->GetName();
70 
71  //G4cout << "Csc SD: swimming through the tree: level "<<i-touchHist->GetHistoryDepth() << G4endl;
72  //G4cout << "Csc SD: name "<<volName << G4endl;
73 
75  if ((npos = volName.find("av_")) != std::string::npos &&
76  (npos = volName.find("impr_")) != std::string::npos) isAssembly = true;
77 
78  if ((npos = volName.find("station")) != std::string::npos && (!isAssembly)) {
79 
81  volName.resize(npos-2);
82  int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
83  stationName = volName;
84  //stationEta = volCopyNo/100;
85  // bug fix for 14.2.0 to cope with non-mirrored chambers as proposed by
86  // S.Spagnolo
87  stationEta = (volCopyNo%1000)/100;
88  stationPhi = abs(volCopyNo%100);
89 
90  } else if ((npos = volName.find("CSC")) != std::string::npos && isAssembly ) {
91  // vol name for Assembly components are
92  // av_WWW_impr_XXX_Muon::BMSxMDTxx_pv_ZZZ_NAME
93  // where WWW is ass. istance nr.
94  // XXX is comp. imprint nr.
95  // BMSxMDTxx is the name of the comp. log.Vol.
96  // x station sub-type; xx technology subtype
97  // ZZZ is No of order of this daugther
98  // NAME is the comp. tag (geoIdentifierTag)
99  // for CSCs it is cl[1] or cl[2]
100  // copy numbers for Ass.components are =
101  // CopyNoBase(= geoIdentifierTag of the assembly) + geoIdentifierTag of the component
102  // geoIdentifierTag of the component = Job
103  // geoIdentifierTag of the assembly = (sideC*10000 +
104  // mirsign*1000 + abs(zi)*100 + fi+1)*100000;
105  // mirsign*1000 + abs(zi)*100 + fi+1)*100000;
106 
108  std::string::size_type loc1,loc2;
109  if ((loc1 = volName.find("Muon::")) != std::string::npos) {
110  stationName = volName.substr(loc1+6,3); //type only
111  }
112 
114  int volCopyNo = touchHist->GetVolume(i)->GetCopyNo();
115  int copyNrBase = int(volCopyNo/100000);
116  int sideC = int(copyNrBase/10000);
117  int zi = int((copyNrBase%1000)/100);
118  // int mirfl = int((copyNrBase%10000)/1000);
119  int fi = int(copyNrBase%100);
120  if (sideC == 1) zi = -zi;
121  stationEta = zi;
122  stationPhi = fi;
123 
124  // now get the geoIdentifierTag of the rpc components
125  int gmID = 0;
126  if ((loc1 = volName.find('[')) != std::string::npos) {
127  if ((loc2 = volName.find(']', loc1+1)) != std::string::npos) {
128  std::istringstream istrvar(volName.substr(loc1+1,loc2-loc1-1));
129  istrvar>>gmID;
130  }
131  }
133  multiLayer = gmID;
134  } else if ((npos = volName.find("component")) != std::string::npos && (!isAssembly)) {
135 
137  multiLayer = touchHist->GetVolume(i)->GetCopyNo();
138  if(multiLayer==3) multiLayer=2; //multilayer index
139  } else if ((npos = volName.find("CscArCO2")) != std::string::npos) {
140 
142  wireLayer=touchHist->GetVolume(i)->GetCopyNo();
143  wireLayer+=1;
144  if(wireLayer==4) wireLayer=1;
145  else if(wireLayer==3) wireLayer=2;
146  else if(wireLayer==2) wireLayer=3;
147  else if(wireLayer==1) wireLayer=4;
148  // G4cout << "CSC:::::: wireLayer "<<wireLayer << G4endl;
149 
151  G4String particle=aStep->GetTrack()->GetDefinition()->GetParticleName();
152  // http://www.slac.stanford.edu/BFROOT/www/Computing/Environment/NewUser/htmlbug/node51.html #GEANT code
153  if (particle=="gamma") lundcode=1;
154  else if (particle=="e+") lundcode=2;
155  else if (particle=="e-") lundcode=3;
156  else if (particle=="mu+") lundcode=5;
157  else if (particle=="mu-") lundcode=6;
158  else if (particle=="pi+") lundcode=8;
159  else if (particle=="pi-") lundcode=9;
160  else if (particle=="kaon+") lundcode=11;
161  else if (particle=="kaon-") lundcode=12;
162  else if (particle=="proton") lundcode=14;
163  else if (particle=="anti_proton") lundcode=15;
164  else if (particle=="sigma+") lundcode=19;
165  else if (particle=="sigma-") lundcode=21;
166  else if (particle=="anti_sigma-") lundcode=27;
167  else if (particle=="anti_sigma+") lundcode=29;
168  else if (particle=="deuteron") lundcode=45;
169  //else if (particle=="geantino") lundcode=999;
170  //else lundcode=999;
171 
172  if (lundcode < 0)
173  G4cout << "WP CSCSensitiveDetector.cxx have exceptional particlue out of selection:: "
174  << particle<< G4endl;
175 
177  // trackid=aStep->GetTrack()->GetTrackID();
178 
180  globalTime = aStep->GetPreStepPoint()->GetGlobalTime();
181 
183  energyDeposit = aStep->GetTotalEnergyDeposit();
184 
186  const G4AffineTransform transform = touchHist->GetHistory()->GetTopTransform();
187 
189  HitStart = Amg::Hep3VectorToEigen( transform.TransformPoint(startPos) );
190 
193  HitEnd = Amg::Hep3VectorToEigen( transform.TransformPoint(endPos) );
194 
195  }
196  }
197 
198  TrackHelper trHelp(aStep->GetTrack());
199 
202  stationEta, multiLayer, wireLayer);
203 
205  m_myCSCHitColl->Emplace(CSCid, globalTime, energyDeposit,
206  HitStart, HitEnd, lundcode,
207  trHelp.GenerateParticleLink(), kinEnergy);
208 
209  return true;
210 }
Muon::nsw::STGTPSegments::moduleIDBits::stationPhi
constexpr uint8_t stationPhi
station Phi 1 to 8
Definition: NSWSTGTPDecodeBitmaps.h:129
Trk::ParticleSwitcher::particle
constexpr ParticleHypothesis particle[PARTICLEHYPOTHESES]
the array of masses
Definition: ParticleHypothesis.h:76
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
ZDC::sideC
BySideTypeMod sideC(-1)
dumpTgcDigiDeadChambers.stationName
dictionary stationName
Definition: dumpTgcDigiDeadChambers.py:30
TrackHelper.h
Trk::loc2
@ loc2
generic first and second local coordinate
Definition: ParamDefs.h:41
CSCSensitiveDetector::Initialize
void Initialize(G4HCofThisEvent *HCE) override final
member functions
Definition: CSCSensitiveDetector.cxx:26
Trk::energyDeposit
@ energyDeposit
Definition: MeasurementType.h:32
Amg::Hep3VectorToEigen
Amg::Vector3D Hep3VectorToEigen(const CLHEP::Hep3Vector &CLHEPvector)
Converts a CLHEP-based CLHEP::Hep3Vector into an Eigen-based Amg::Vector3D.
Definition: CLHEPtoEigenConverter.h:137
TrackHelper
Definition: TrackHelper.h:14
CscHitIdHelper::GetHelper
static const CscHitIdHelper * GetHelper()
Definition: CscHitIdHelper.cxx:23
CscHitIdHelper::BuildCscHitId
int BuildCscHitId(const std::string &, const int, const int, const int, const int) const
Definition: CscHitIdHelper.cxx:89
CSCSensitiveDetector.h
lumiFormat.i
int i
Definition: lumiFormat.py:92
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
CscHitIdHelper.h
CLHEPtoEigenConverter.h
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
CSCSensitiveDetector::m_muonHelper
const CscHitIdHelper * m_muonHelper
Definition: CSCSensitiveDetector.h:77
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
checkFileSG.fi
fi
Definition: checkFileSG.py:65
TrackHelper::GenerateParticleLink
HepMcParticleLink GenerateParticleLink()
Generates a creates new HepMcParticleLink object on the stack based on GetUniqueID(),...
Definition: TrackHelper.h:35
Muon::nsw::STGTPSegments::moduleIDBits::stationEta
constexpr uint8_t stationEta
1 to 3
Definition: NSWSTGTPDecodeBitmaps.h:127
HitID
int HitID
Definition: GenericMuonSimHit.h:13
Trk::loc1
@ loc1
Definition: ParamDefs.h:40
sTgcDigitEffiDump.multiLayer
int multiLayer
Definition: sTgcDigitEffiDump.py:36
CSCSensitiveDetector::ProcessHits
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override final
Definition: CSCSensitiveDetector.cxx:31
CSCSensitiveDetector::m_myCSCHitColl
SG::WriteHandle< CSCSimHitCollection > m_myCSCHitColl
member data
Definition: CSCSensitiveDetector.h:76
CSCSensitiveDetector::CSCSensitiveDetector
CSCSensitiveDetector(const std::string &name, const std::string &hitCollectionName)
construction/destruction
Definition: CSCSensitiveDetector.cxx:17