SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_PrintOut.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 
27 #include "SToGS_PrintOut.hh"
28 #include "SToGS_G4_TrackerSD.hh"
29 #include "SToGS_G4_CopClusterSD.hh"
31 
32 #include "G4SDManager.hh"
33 #include "G4RunManager.hh"
34 #include "G4Event.hh"
35 #include "G4UnitsTable.hh"
36 
37 #ifdef G4MULTITHREADED
38 #include "G4AutoLock.hh"
39 namespace { G4Mutex buildMutex = G4MUTEX_INITIALIZER; }
40 #endif
41 
43  G4Run(),
44  colltrackerID(-1),
45  collcaloID(-1)
46 {
47  G4SDManager* SDman = G4SDManager::GetSDMpointer();
48  if ( SDman ) {
49  // keep the collection ID associated to this collection
50  colltrackerID = SDman->GetCollectionID("TrackerHits");
51 
52  // keep the collection ID associated to this collection
53  collcaloID = SDman->GetCollectionID("CopClusterHits");
54  }
55 }
57 {
58  ;
59 }
60 void SToGS::PrintOutRun::RecordEvent(const G4Event* evt)
61 {
63 
64  if( colltrackerID < 0 && collcaloID < 0 ) {
65  return;
66  }
67  G4cout << " Beginning Record of Event: " << evt->GetEventID() + 1 << G4endl;
68 
69 
70  G4HCofThisEvent *HCE = evt->GetHCofThisEvent();
71 
72  if(HCE)
73  {
74  THC = (SToGS::TrackerHitsCollection *)(HCE->GetHC(colltrackerID));
75  CHC = (SToGS::CopClusterHitsCollection*)(HCE->GetHC(collcaloID));
76  }
77 
78  if(THC && colltrackerID > -1)
79  {
80  int n_hit = THC->entries();
81  G4cout << " " << n_hit
82  << " hits are stored in tracker collection" << G4endl;
83 
84  for (int i = 0 ;i < n_hit; i++) {
85  G4cout << " hit # " << i << " " << G4BestUnit((*THC)[i]->GetEdep(), "Energy") << G4endl;
86 // (*THC)[i]->Print();
87  }
88  }
89 
90  if(CHC && collcaloID > -1)
91  {
92  int n_hit = CHC->entries();
93  G4cout << " " << n_hit
94  << " hits are stored in calo collection" << G4endl;
95 
96  for(int i = 0; i < n_hit; i++) {
97  G4cout << " hit # " << i << G4BestUnit((*CHC)[i]->GetEdep(), "Energy") << G4endl;
98 // (*CHC)[i]->Print();
99  }
100  }
101 
102  G4cout << " End Record of Event: " << evt->GetEventID() + 1 << G4endl;
103 }
104 
106 {
107  G4Run* therun = 0x0; G4cout << " In PrintOutAction, Generate a new Run " << G4endl;
108 
109  // creates a new run. As the file is open bu AsciiRun no need to open something for master ... maybe one day to keep some globals ?
110 #if G4MULTITHREADED
111  if ( G4Threading::IsWorkerThread() ) {
112  // if ( IsMaster() ) {
113  SToGS::PrintOutRun *loc_therun = new SToGS::PrintOutRun();
114  therun = loc_therun;
115  }
116  else therun = G4UserRunAction::GenerateRun();
117 #else
118  therun = new SToGS::PrintOutRun();
119 #endif
120  return therun;
121 }
122 
124 {
125  G4cout << "Begin of Run: " << aRun->GetRunID() << " " << aRun->GetNumberOfEventToBeProcessed() << G4endl ;
126 }
128 {
129  G4cout << "End of Run: " << aRun->GetRunID() << " " << aRun->GetNumberOfEvent() << G4endl ;
130 }
131 
133 {
134  G4int evtNb = evt->GetEventID();
135  G4cout << " Begin of Event: " << evtNb + 1 << G4endl;
136 }
138 {
139  G4int evtNb = evt->GetEventID();
140  G4cout << " End of Event: " << evtNb + 1 << G4endl;
141 }
142 
144 {
145  //
146  G4cout << " Begin of Track: (PreUserTrackingAction) " << G4endl;
147  G4cout << " PARTICLE: " << aTrack->GetDefinition()->GetParticleName() << G4endl;
148  G4cout << " TRACK ID: " << aTrack->GetTrackID() << G4endl;
149  G4cout << " PARENT ID: " << aTrack->GetParentID() << G4endl;
150  G4cout << " TOTAL ENERGY: " << G4BestUnit(aTrack->GetTotalEnergy(), "Energy") << G4endl;
151  G4cout << " KINETIC ENERGY: " << G4BestUnit(aTrack->GetKineticEnergy(), "Energy") << G4endl;
152  G4cout << " VELOCITY: " << aTrack->GetVelocity() << G4endl;
153 }
154 
156 {
157  // verify if next volume exist -> if it does not exist it means that the particle went out of the world volume
158  if(aTrack->GetNextVolume())
159  G4cout << " VOLUME WHERE THE PARTICLE WAS KILLED: " << aTrack->GetTouchable()->GetVolume()->GetName() << G4endl;
160  else
161  G4cout << " THE PARTICLE WAS KILLED BECAUSE IT WENT OUT OF THE WORLD VOLUME" << G4endl;
162 
163  G4cout << " End of Track: (PostUserTrackingAction) " << G4endl;
164 }
165 
167 {
168  G4Track* theTrack = aStep->GetTrack();
169 
170  G4int primaryID = theTrack->GetParentID(); SToGS::PrimaryTrackInformation *pinfo = (SToGS::PrimaryTrackInformation *)theTrack->GetUserInformation();
171  if ( pinfo )
172  primaryID = pinfo->GetPrimaryID();
173 
174  G4cout << " A Step: " << G4endl;
175  G4cout << " trackID: " << theTrack->GetTrackID()
176  << ", parentID: " << theTrack->GetParentID()
177  << ", primaryID: " << primaryID
178  << ", particleName: " << theTrack->GetDefinition()->GetParticleName()
179  << ", PDG: " << theTrack->GetDefinition()->GetPDGEncoding ()
180  << ", processName: " << aStep->GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName()
181  << G4endl
182  << " detID: " << theTrack->GetVolume()->GetCopyNo()
183  << ", detName: " << theTrack->GetVolume()->GetName()
184  << ", motherID: " << aStep->GetPreStepPoint()->GetTouchableHandle()->GetReplicaNumber(1)
185  << ", motherDetName: " /* << motherDetName */ << G4endl;
186  G4cout << " edep: " << aStep->GetTotalEnergyDeposit() / CLHEP::keV << " keV"
187  << ", pos: " << aStep->GetPostStepPoint()->GetPosition()
188  << ", ToF: " << aStep->GetPostStepPoint()->GetGlobalTime() / CLHEP::ns << " ns" << G4endl;
189 }
190 
191 G4UserRunAction *SToGS::PrintOut::GetRunAction() const
192 {
193  if ( fUserActionOption.contains("run") )
195  return 0x0;
196 }
197 G4UserEventAction *SToGS::PrintOut::GetEventAction() const
198 {
199  if ( fUserActionOption.contains("event") )
201  return 0x0;
202 }
203 G4UserTrackingAction *SToGS::PrintOut::GetTrackingAction() const
204 {
205  if ( fUserActionOption.contains("track") )
207  return 0x0;
208 }
209 G4UserSteppingAction *SToGS::PrintOut::GetSteppingAction() const
210 {
211  if ( fUserActionOption.contains("step") )
213  return 0x0;
214 }
215 
217 {
218 #ifdef G4MULTITHREADED
219  G4AutoLock lock(&buildMutex);
220 #endif
221 
222  G4cout << " ------ INF ------ from SToGS::PrintOut::Build() " << G4endl;
223 #if G4VERSION_NUMBER < 1000
224  G4cout << " *** ERROR *** SToGS::PrintOut::Build() should never be called by this version of Geant4 " << G4endl;
225 #else
226  SetUserAction( GetGun(fWhichGenerator.first,fWhichGenerator.second) );
227 
228  PrintOutAction *all_actions = new PrintOutAction(fUserActionOption); fAllUserAction.push_back(all_actions);
229  SetUserAction( new SToGS::RunAction(all_actions) ) ;
230  if ( fUserActionOption.contains("event") )
231  SetUserAction( new SToGS::EventAction(all_actions) ) ;
232  if ( fUserActionOption.contains("track") )
233  SetUserAction( new SToGS::TrackingAction(all_actions) ) ;
234  if ( fUserActionOption.contains("step") )
235  SetUserAction( new SToGS::SteppingAction(all_actions) ) ;
236 #endif
237  G4cout << " ------ END ------ from SToGS::PrintOut::Build() " << G4endl;
238 }
239 
240 
241 
242 
243 
244 
virtual void RecordEvent(const G4Event *evt)
G4THitsCollection< TrackerHit > TrackerHitsCollection
At any steps, it prints out some informations regarding run, event, step ...
virtual G4UserTrackingAction * GetTrackingAction() const
a G4 user's action manage by a single AllAction class
virtual G4UserEventAction * GetEventAction() const
virtual void BeginOfRunAction(const G4Run *)
virtual void EndOfRunAction(const G4Run *)
Base class for a Run action that calls a concrete one.
G4THitsCollection< CopClusterHit > CopClusterHitsCollection
Base class for a Tracking action that calls a concrete one.
virtual void Build() const
virtual void BeginOfEventAction(const G4Event *)
Base class for a Steeping action that calls a concrete one.
virtual void UserSteppingAction(const G4Step *)
Base class for a Event action that calls a concrete one.
G4int GetPrimaryID() const
Get the primary ID.
virtual void PostUserTrackingAction(const G4Track *)
virtual void PreUserTrackingAction(const G4Track *)
virtual G4UserRunAction * GetRunAction() const
depending on one string, select a given gun
virtual G4Run * GenerateRun()
virtual G4UserSteppingAction * GetSteppingAction() const
User Track Information that kept the origine of any track.
virtual void EndOfEventAction(const G4Event *)