Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-20 22:46:48

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 #include "G4SystemOfUnits.hh"
0018 
0019 //#define EDM_ML_DEBUG
0020 
0021 HFChamberSD::HFChamberSD(const std::string& name,
0022                                const SensitiveDetectorCatalog& clg,
0023                                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 << ":" << theHC;
0037 }
0038 
0039 G4bool HFChamberSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
0040   //do not process hits other than primary particle hits:
0041   double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
0042   int trackID = aStep->GetTrack()->GetTrackID();
0043   if (charge == 0. || trackID != 1 || aStep->GetTrack()->GetParentID() != 0 ||
0044       aStep->GetTrack()->GetCreatorProcess() != nullptr)
0045     return false;
0046   ++theNSteps;
0047   //if(theNSteps>1)return false;
0048 
0049   G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
0050   const G4VTouchable* touch = preStepPoint->GetTouchable();
0051   int detID = setDetUnitId(aStep);
0052 
0053   double edep = aStep->GetTotalEnergyDeposit();
0054   double time = (preStepPoint->GetGlobalTime()) / ns;
0055 
0056   const G4ThreeVector& globalPos = preStepPoint->GetPosition();
0057   G4ThreeVector localPos = touch->GetHistory()->GetTopTransform().TransformPoint(globalPos);
0058   const G4DynamicParticle* particle = aStep->GetTrack()->GetDynamicParticle();
0059   const G4ThreeVector& momDir = particle->GetMomentumDirection();
0060 
0061   HFShowerG4Hit* aHit = new HFShowerG4Hit(detID, trackID, edep, time);
0062   aHit->setLocalPos(localPos);
0063   aHit->setGlobalPos(globalPos);
0064   aHit->setPrimMomDir(momDir);
0065 
0066 #ifdef EDM_ML_DEBUG
0067   edm::LogVerbatim("FiberSim") << "HFChamberSD: Hit created in (" << touch->GetVolume(0)->GetLogicalVolume()->GetName() << ")  ID " << detID << " Track " << trackID << " Edep: " << edep / CLHEP::MeV << " MeV; Time: " << time << " ns; Position (local) " << localPos << " (global ) " << globalPos << " direction " << momDir;
0068 #endif
0069   theHC->insert(aHit);
0070   return true;
0071 }
0072 
0073 void HFChamberSD::EndOfEvent(G4HCofThisEvent* HCE) {
0074   edm::LogVerbatim("FiberSim") << "HFChamberSD: Finds " << theHC->entries() << " hits";
0075   clear();
0076 }
0077 
0078 void HFChamberSD::clear() { theNSteps = 0; }
0079 
0080 void HFChamberSD::DrawAll() {}
0081 
0082 void HFChamberSD::PrintAll() {}
0083 
0084 void HFChamberSD::clearHits() {}
0085 
0086 uint32_t HFChamberSD::setDetUnitId(const G4Step* aStep) {
0087   const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
0088   return (touch->GetReplicaNumber(0));
0089 }
0090 
0091 void HFChamberSD::fillHits(edm::PCaloHitContainer&, const std::string&) {}