Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:04

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 #include "AnalysisManager.hh"
0028 #include "eRositaTrackerSD.hh"
0029 #include "eRositaTrackerHit.hh"
0030 
0031 #include <fstream>
0032 #include <iostream>
0033 
0034 #include "G4HCofThisEvent.hh"
0035 #include "G4ios.hh"
0036 #include "G4ParticleTypes.hh"
0037 #include "G4SDManager.hh"
0038 #include "G4Step.hh"
0039 #include "G4ThreeVector.hh"
0040 
0041 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0042 
0043 eRositaTrackerSD::eRositaTrackerSD(G4String name) : G4VSensitiveDetector(name)
0044 {
0045     constexpr auto TRACKER_COLLECTION_NAME = "TrackerCollection";
0046     collectionName.insert(TRACKER_COLLECTION_NAME);
0047 }
0048 
0049 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0050 
0051 eRositaTrackerSD::~eRositaTrackerSD()
0052 {
0053 }
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0056 
0057 void eRositaTrackerSD::Initialize(G4HCofThisEvent* collection)
0058 {
0059     trackerCollection = new eRositaTrackerHitsCollection(SensitiveDetectorName, collectionName[0]);
0060     static G4int collectionIdentifier = -1;
0061 
0062     if (collectionIdentifier < 0) {
0063         collectionIdentifier = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
0064     }
0065     collection->AddHitsCollection(collectionIdentifier, trackerCollection);
0066 }
0067 
0068 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0069 
0070 auto eRositaTrackerSD::ProcessHits(G4Step* step, G4TouchableHistory*) -> G4bool
0071 {
0072     if (step->GetTrack()->GetDefinition() != G4Gamma::GammaDefinition()) {
0073         return false;
0074     }
0075 
0076     // auto depositedEnergy = step->GetTotalEnergyDeposit();
0077     auto depositedEnergy = step->GetPreStepPoint()->GetKineticEnergy();
0078     if (depositedEnergy == 0.) {
0079         return false;
0080     }
0081 
0082     auto *newHit = new eRositaTrackerHit();
0083     newHit->SetTrackIdentifier(step->GetTrack()->GetTrackID());
0084     // newHit->SetChamberNumber(step->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber());
0085     newHit->SetDepositedEnergy(depositedEnergy);
0086     newHit->SetPosition(step->GetPostStepPoint()->GetPosition());
0087     trackerCollection->insert(newHit);
0088 
0089     // newHit->Print();
0090     // newHit->Draw();
0091 
0092     // std::ofstream dataFile("ASCII");
0093     // newHit->PrintToFile(dataFile);
0094     // dataFile.close();
0095 
0096     return true;
0097 }
0098 
0099 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0100 
0101 void eRositaTrackerSD::EndOfEvent(G4HCofThisEvent*)
0102 {
0103     G4int numberOfHits = trackerCollection->entries();
0104 
0105     if (verboseLevel > 0) {
0106         G4cout << G4endl
0107             << "Hits collection: in this event there are " << numberOfHits
0108             << " hits in the tracker chambers: " << G4endl;
0109 
0110         for (G4int i = 0; i < numberOfHits; i++) {
0111             (*trackerCollection)[i]->Print();
0112         }
0113     }
0114 
0115     for (G4int i = 0; i < numberOfHits; i++) {
0116         (*trackerCollection)[i]->PrintToFile();
0117     };
0118 }