CMS 3D CMS Logo

HFChamberSD.cc
Go to the documentation of this file.
3 
4 #include "G4VPhysicalVolume.hh"
5 #include "G4PVPlacement.hh"
6 #include "G4HCofThisEvent.hh"
7 #include "G4TouchableHistory.hh"
8 #include "G4Track.hh"
9 #include "G4Step.hh"
10 #include "G4VSolid.hh"
11 #include "G4DynamicParticle.hh"
12 #include "G4ParticleDefinition.hh"
13 #include "G4SDManager.hh"
14 #include "G4ios.hh"
15 
16 #include "G4PhysicalConstants.hh"
17 #include "G4SystemOfUnits.hh"
18 
19 //#define EDM_ML_DEBUG
20 
22  : SensitiveCaloDetector(name, clg), theHCID(-1), theHC(nullptr), theNSteps(0) {
23  edm::LogVerbatim("FiberSim") << "HFChamberSD : Instantiated for " << name;
24 }
25 
27 
28 void HFChamberSD::Initialize(G4HCofThisEvent* HCE) {
29  edm::LogVerbatim("FiberSim") << "HFChamberSD : Initialize called for " << GetName() << " in collection " << HCE;
30  theHC = new HFShowerG4HitsCollection(GetName(), collectionName[0]);
31  if (theHCID < 0)
32  theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
33  HCE->AddHitsCollection(theHCID, theHC);
34  edm::LogVerbatim("FiberSim") << "HFChamberSD : Add hit collectrion for " << collectionName[0] << ":" << theHCID << ":"
35  << theHC;
36 }
37 
38 G4bool HFChamberSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
39  //do not process hits other than primary particle hits:
40  double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
41  int trackID = aStep->GetTrack()->GetTrackID();
42  if (charge == 0. || trackID != 1 || aStep->GetTrack()->GetParentID() != 0 ||
43  aStep->GetTrack()->GetCreatorProcess() != nullptr)
44  return false;
45  ++theNSteps;
46  //if(theNSteps>1)return false;
47 
48  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
49  const G4VTouchable* touch = preStepPoint->GetTouchable();
50  int detID = setDetUnitId(aStep);
51 
52  double edep = aStep->GetTotalEnergyDeposit();
53  double time = (preStepPoint->GetGlobalTime()) / ns;
54 
55  const G4ThreeVector& globalPos = preStepPoint->GetPosition();
56  G4ThreeVector localPos = touch->GetHistory()->GetTopTransform().TransformPoint(globalPos);
57  const G4DynamicParticle* particle = aStep->GetTrack()->GetDynamicParticle();
58  const G4ThreeVector& momDir = particle->GetMomentumDirection();
59 
60  HFShowerG4Hit* aHit = new HFShowerG4Hit(detID, trackID, edep, time);
61  aHit->setLocalPos(localPos);
62  aHit->setGlobalPos(globalPos);
63  aHit->setPrimMomDir(momDir);
64 
65 #ifdef EDM_ML_DEBUG
66  edm::LogVerbatim("FiberSim") << "HFChamberSD: Hit created in (" << touch->GetVolume(0)->GetLogicalVolume()->GetName()
67  << ") ID " << detID << " Track " << trackID << " Edep: " << edep / CLHEP::MeV
68  << " MeV; Time: " << time << " ns; Position (local) " << localPos << " (global ) "
69  << globalPos << " direction " << momDir;
70 #endif
71  theHC->insert(aHit);
72  return true;
73 }
74 
75 void HFChamberSD::EndOfEvent(G4HCofThisEvent* HCE) {
76  edm::LogVerbatim("FiberSim") << "HFChamberSD: Finds " << theHC->entries() << " hits";
77  clear();
78 }
79 
81 
83 
85 
87 
88 uint32_t HFChamberSD::setDetUnitId(const G4Step* aStep) {
89  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
90  return (touch->GetReplicaNumber(0));
91 }
92 
Log< level::Info, true > LogVerbatim
void clear() override
Definition: HFChamberSD.cc:80
std::vector< PCaloHit > PCaloHitContainer
void clearHits() override
Definition: HFChamberSD.cc:86
void setLocalPos(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:42
HFChamberSD(const std::string &, const SensitiveDetectorCatalog &, const SimTrackManager *)
Definition: HFChamberSD.cc:21
~HFChamberSD() override
Definition: HFChamberSD.cc:26
uint32_t setDetUnitId(const G4Step *) override
Definition: HFChamberSD.cc:88
HFShowerG4HitsCollection * theHC
Definition: HFChamberSD.h:39
void Initialize(G4HCofThisEvent *HCE) override
Definition: HFChamberSD.cc:28
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: HFChamberSD.cc:93
void setPrimMomDir(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:44
void PrintAll() override
Definition: HFChamberSD.cc:84
G4int theHCID
Definition: HFChamberSD.h:38
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override
Definition: HFChamberSD.cc:38
void EndOfEvent(G4HCofThisEvent *HCE) override
Definition: HFChamberSD.cc:75
void setGlobalPos(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:43
void DrawAll() override
Definition: HFChamberSD.cc:82
G4THitsCollection< HFShowerG4Hit > HFShowerG4HitsCollection
Definition: HFShowerG4Hit.h:55