#include "StripSD.hh" #include "G4Step.hh" #include "Randomize.hh" #include "G4HCofThisEvent.hh" #include "G4HCtable.hh" #include "G4SDManager.hh" StripSD::StripSD(G4String SDname) : G4VSensitiveDetector(SDname) { // 'collectionName' is a protected data member of base class G4VSensitiveDetector. // Here we declare the name of the collection we will be using. collectionName.insert(SDname); //collectionName.insert("StripHitCollection"); // Note that we may add as many collection names we would wish: ie // a sensitive detector can have many collections. HCID = -1; } StripSD::~StripSD() {} G4bool StripSD::ProcessHits(G4Step *step, G4TouchableHistory *) { // step is guaranteed to be in Strip volume : no need to check for volume G4TouchableHandle touchable = step->GetPreStepPoint()->GetTouchableHandle(); // energy deposit in this step G4double edep = step->GetTotalEnergyDeposit(); //check if step is due to primary particle: it has track ID 1 and parent 0 // The primary is the track with ID 1 and with no parent G4bool isPrimary = ( step->GetTrack()->GetTrackID() == 1 && step->GetTrack()->GetParentID() == 0 ) ? true : false; //if (edep <= 0.) return false; //Gets rid of neutral particles // get step points in world coordinate system G4ThreeVector point1 = step->GetPreStepPoint()->GetPosition(); G4ThreeVector point2 = step->GetPostStepPoint()->GetPosition(); // randomize point of energy deposition to get hit pos for this step G4ThreeVector pointE = point1 + G4UniformRand()*(point2 - point1); //G4ThreeVector pointE = point2; //Sets kinetic energy of hit JT G4double kin_e = step->GetTrack()->GetKineticEnergy(); // get step points in world coordinate system //JT G4double t1 = step->GetPreStepPoint()->GetLocalTime(); //JT G4double t2 = step->GetPostStepPoint()->GetLocalTime(); //JT // randomize point of energy deposition to get hit time for this step //JT G4double htime = t1 + G4UniformRand()*(t2 - t1); //JT G4int stripCopyNo = touchable->GetReplicaNumber(); G4int planeCopyNo = -1; if(step->GetPreStepPoint()->GetPhysicalVolume()->GetName().contains("RT")) // this is due to replica in replica in RT but not in Strips planeCopyNo = touchable->GetReplicaNumber(2); else planeCopyNo = touchable->GetReplicaNumber(1); G4int track = step->GetTrack()->GetTrackID(); G4int Z = step->GetTrack()->GetDefinition()->GetPDGCharge(); StripHit* hit = new StripHit(stripCopyNo,planeCopyNo,isPrimary,track,Z); //hit->Print(); hitCollection->insert(hit); G4String particleName = step->GetTrack()->GetDefinition()->GetParticleName(); // set kinetic energy hit->SetKE(kin_e); // set energy deposition hit->AddEdep(edep); // set hit time hit->SetHitTime(htime); //JT // store position of energy deposition hit->SetPosition(pointE); hit->SetParticleName(particleName); G4cout << "StripSD::PlaneCopyNo=" << planeCopyNo << G4endl; G4cout << "StripSD::StripCopyNo=" << stripCopyNo << G4endl; G4cout << "StripSD::pointE="<< pointE << G4endl; return true; } void StripSD::Initialize(G4HCofThisEvent* HCE) { // ------------------------------ // -- Creation of the collection // ------------------------------ // -- collectionName[0] is "StripHitCollection", as declared in constructor //hitCollection = new StripHitCollection(GetName(), collectionName[0]); hitCollection = new StripHitCollection(SensitiveDetectorName, collectionName[0]); // ---------------------------------------------------------------------------- // -- and attachment of this collection to the "Hits Collection of this Event": // ---------------------------------------------------------------------------- // -- To insert the collection, we need to get an index for it. This index // -- is unique to the collection. It is provided by the GetCollectionID(...) // -- method (which calls what is needed in the kernel to get this index). //static G4int HCID = -1; if (HCID<0) HCID = GetCollectionID(0); // <<-- this is to get an ID for collectionName[0] HCE->AddHitsCollection(HCID, hitCollection); } void StripSD::EndOfEvent(G4HCofThisEvent*) { // test output of hits G4cout << "EndOfEvent method of SD `" << GetName() << "' called." << G4endl; // for (size_t i = 0; i < hitCollection->GetSize(); ++i ) { // G4cout<Print(); // } // -- we could have attached the collection to the G4HCofThisEvent in this // -- method as well (instead of Initialize). }