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 
20  const SensitiveDetectorCatalog & clg, edm::ParameterSet const & p,
21  const SimTrackManager* manager) :
22  SensitiveCaloDetector(name, cpv, clg, p),
23  m_trackManager(manager), theHCID(-1), theHC(nullptr), theNSteps(0) {
24 
25 }
26 
28  delete theHC;
29 }
30 
31 void HFChamberSD::Initialize(G4HCofThisEvent * HCE) {
32 
33  LogDebug("FiberSim") << "HFChamberSD : Initialize called for " << GetName();
34  theHC = new HFShowerG4HitsCollection(GetName(), collectionName[0]);
35  if (theHCID<0)
36  theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
37  HCE->AddHitsCollection(theHCID, theHC);
38 
39 }
40 
41 G4bool HFChamberSD::ProcessHits(G4Step * aStep, G4TouchableHistory*) {
42 
43  //do not process hits other than primary particle hits:
44  double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
45  int trackID = aStep->GetTrack()->GetTrackID();
46  if(charge == 0. || trackID != 1 ||aStep->GetTrack()->GetParentID() != 0 || aStep->GetTrack()->GetCreatorProcess() != nullptr) return false;
47  ++theNSteps;
48  //if(theNSteps>1)return false;
49 
50  G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
51  const G4VTouchable* touch = preStepPoint->GetTouchable();
52  int detID = setDetUnitId(aStep);
53 
54  double edep = aStep->GetTotalEnergyDeposit();
55  double time = (preStepPoint->GetGlobalTime())/ns;
56 
57  const G4ThreeVector& globalPos = preStepPoint->GetPosition();
58  G4ThreeVector localPos = touch->GetHistory()->GetTopTransform().TransformPoint(globalPos);
59  const G4DynamicParticle* particle = aStep->GetTrack()->GetDynamicParticle();
60  const G4ThreeVector& momDir = particle->GetMomentumDirection();
61 
62  HFShowerG4Hit *aHit = new HFShowerG4Hit(detID, trackID, edep, time);
63  aHit->setLocalPos(localPos);
64  aHit->setGlobalPos(globalPos);
65  aHit->setPrimMomDir(momDir);
66 
67  LogDebug("FiberSim") << "HFChamberSD: Hit created in ("
68  << touch->GetVolume(0)->GetLogicalVolume()->GetName()
69  << ") " << " ID " << detID << " Track " << trackID
70  << " Edep: " << edep/MeV << " MeV; Time: " << time
71  << " ns; Position (local) " << localPos << " (global ) "
72  << globalPos << " direction " << momDir;
73 
74  theHC->insert(aHit);
75  return true;
76 }
77 
78 void HFChamberSD::EndOfEvent(G4HCofThisEvent * HCE) {
79 
80  LogDebug("FiberSim") << "HFChamberSD: Sees" << theHC->entries() << " hits";
81  clear();
82 }
83 
85  theNSteps = 0;
86 }
87 
89 
91 
93 
94 uint32_t HFChamberSD::setDetUnitId(const G4Step* aStep) {
95  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
96  return (touch->GetReplicaNumber(0));
97 }
98 
#define LogDebug(id)
void clear() override
Definition: HFChamberSD.cc:84
std::vector< PCaloHit > PCaloHitContainer
void clearHits() override
Definition: HFChamberSD.cc:92
void setLocalPos(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:46
#define nullptr
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
~HFChamberSD() override
Definition: HFChamberSD.cc:27
uint32_t setDetUnitId(const G4Step *) override
Definition: HFChamberSD.cc:94
const double MeV
HFShowerG4HitsCollection * theHC
Definition: HFChamberSD.h:44
std::string const collectionName[nCollections]
Definition: Collections.h:47
void Initialize(G4HCofThisEvent *HCE) override
Definition: HFChamberSD.cc:31
void fillHits(edm::PCaloHitContainer &, const std::string &) override
Definition: HFChamberSD.cc:99
void setPrimMomDir(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:48
void PrintAll() override
Definition: HFChamberSD.cc:90
G4int theHCID
Definition: HFChamberSD.h:43
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist) override
Definition: HFChamberSD.cc:41
void EndOfEvent(G4HCofThisEvent *HCE) override
Definition: HFChamberSD.cc:78
void setGlobalPos(const G4ThreeVector &xyz)
Definition: HFShowerG4Hit.h:47
HFChamberSD(const std::string &, const DDCompactView &, const SensitiveDetectorCatalog &, const edm::ParameterSet &, const SimTrackManager *)
Definition: HFChamberSD.cc:19
void DrawAll() override
Definition: HFChamberSD.cc:88
G4THitsCollection< HFShowerG4Hit > HFShowerG4HitsCollection
Definition: HFShowerG4Hit.h:59