Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-10 02:21:22

0001 #include "SimG4CMS/ShowerLibraryProducer/interface/HFChamberSD.h"
0002 #include "DataFormats/Math/interface/Point3D.h"
0003 
0004 #include "G4VPhysicalVolume.hh"
0005 #include "G4PVPlacement.hh"
0006 #include "G4HCofThisEvent.hh"
0007 #include "G4TouchableHistory.hh"
0008 #include "G4Track.hh"
0009 #include "G4Step.hh"
0010 #include "G4VSolid.hh"
0011 #include "G4DynamicParticle.hh"
0012 #include "G4ParticleDefinition.hh"
0013 #include "G4SDManager.hh"
0014 #include "G4ios.hh"
0015 
0016 #include "G4PhysicalConstants.hh"
0017 
0018 #include <CLHEP/Units/SystemOfUnits.h>
0019 using CLHEP::ns;
0020 
0021 //#define EDM_ML_DEBUG
0022 
0023 HFChamberSD::HFChamberSD(const std::string& name, const SensitiveDetectorCatalog& clg, const SimTrackManager* manager)
0024     : SensitiveCaloDetector(name, clg), theHCID(-1), theHC(nullptr), theNSteps(0) {
0025   edm::LogVerbatim("FiberSim") << "HFChamberSD : Instantiated for " << name;
0026 }
0027 
0028 HFChamberSD::~HFChamberSD() { delete theHC; }
0029 
0030 void HFChamberSD::Initialize(G4HCofThisEvent* HCE) {
0031   edm::LogVerbatim("FiberSim") << "HFChamberSD : Initialize called for " << GetName() << " in collection " << HCE;
0032   theHC = new HFShowerG4HitsCollection(GetName(), collectionName[0]);
0033   if (theHCID < 0)
0034     theHCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0035   HCE->AddHitsCollection(theHCID, theHC);
0036   edm::LogVerbatim("FiberSim") << "HFChamberSD : Add hit collectrion for " << collectionName[0] << ":" << theHCID << ":"
0037                                << theHC;
0038 }
0039 
0040 G4bool HFChamberSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
0041   //do not process hits other than primary particle hits:
0042   double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
0043   int trackID = aStep->GetTrack()->GetTrackID();
0044   if (charge == 0. || trackID != 1 || aStep->GetTrack()->GetParentID() != 0 ||
0045       aStep->GetTrack()->GetCreatorProcess() != nullptr)
0046     return false;
0047   ++theNSteps;
0048   //if(theNSteps>1)return false;
0049 
0050   G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
0051   const G4VTouchable* touch = preStepPoint->GetTouchable();
0052   int detID = setDetUnitId(aStep);
0053 
0054   double edep = aStep->GetTotalEnergyDeposit();
0055   double time = (preStepPoint->GetGlobalTime()) / ns;
0056 
0057   const G4ThreeVector& globalPos = preStepPoint->GetPosition();
0058   G4ThreeVector localPos = touch->GetHistory()->GetTopTransform().TransformPoint(globalPos);
0059   const G4DynamicParticle* particle = aStep->GetTrack()->GetDynamicParticle();
0060   const G4ThreeVector& momDir = particle->GetMomentumDirection();
0061 
0062   HFShowerG4Hit* aHit = new HFShowerG4Hit(detID, trackID, edep, time);
0063   aHit->setLocalPos(localPos);
0064   aHit->setGlobalPos(globalPos);
0065   aHit->setPrimMomDir(momDir);
0066 
0067 #ifdef EDM_ML_DEBUG
0068   edm::LogVerbatim("FiberSim") << "HFChamberSD: Hit created in (" << touch->GetVolume(0)->GetLogicalVolume()->GetName()
0069                                << ")  ID " << detID << " Track " << trackID << " Edep: " << edep / CLHEP::MeV
0070                                << " MeV; Time: " << time << " ns; Position (local) " << localPos << " (global ) "
0071                                << globalPos << " direction " << momDir;
0072 #endif
0073   theHC->insert(aHit);
0074   return true;
0075 }
0076 
0077 void HFChamberSD::EndOfEvent(G4HCofThisEvent* HCE) {
0078   edm::LogVerbatim("FiberSim") << "HFChamberSD: Finds " << theHC->entries() << " hits";
0079   clear();
0080 }
0081 
0082 void HFChamberSD::clear() { theNSteps = 0; }
0083 
0084 void HFChamberSD::DrawAll() {}
0085 
0086 void HFChamberSD::PrintAll() {}
0087 
0088 void HFChamberSD::clearHits() {}
0089 
0090 uint32_t HFChamberSD::setDetUnitId(const G4Step* aStep) {
0091   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0092   return (touch->GetReplicaNumber(0));
0093 }
0094 
0095 void HFChamberSD::fillHits(edm::PCaloHitContainer&, const std::string&) {}