SToGS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
SToGS_UserActionInitialization.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 //----------------------------------------------------------------------------------
28 
29 
30 #include "SToGSConfig.hh"
33 
34 #include "G4ios.hh"
35 #include "G4SDManager.hh"
36 #include "G4TrackingManager.hh"
37 
38 #ifdef G4MULTITHREADED
39 #include "G4AutoLock.hh"
40 namespace { G4Mutex buildMutex = G4MUTEX_INITIALIZER; }
41 #endif
42 
43 #include <fstream>
44 
46 {
47  // if real primary, no parent, add user information
48  if ( atrack->GetParentID() == 0 ) {
49  if ( atrack->GetUserInformation() ) {
50  SToGS::PrimaryTrackInformation *pinfo = new SToGS::PrimaryTrackInformation(atrack->GetTrackID());
51  fpTrackingManager->SetUserTrackInformation(pinfo);
52  }
53  }
54  if (theRealAction) {
55  theRealAction->PreUserTrackingAction(atrack);
56  }
57 }
59 {
60  G4TrackVector *secondaries = fpTrackingManager->GimmeSecondaries();
61  if ( secondaries ) {
62  size_t nbSecondaries = secondaries->size();
63  if ( nbSecondaries > 0 ) {
64  SToGS::PrimaryTrackInformation *pinfo = (SToGS::PrimaryTrackInformation *)atrack->GetUserInformation();
65  G4int pid = atrack->GetTrackID();
66  if ( pinfo ) {
67  pid = pinfo->GetPrimaryID();
68  }
69  for (size_t i = 0; i < nbSecondaries; i++) {
71  (*secondaries)[i]->SetUserInformation(sinfo);
72  }
73  }
74  }
75  if (theRealAction) {
76  theRealAction->PostUserTrackingAction(atrack);
77  }
78 }
79 
80 SToGS::UserActionInitialization::UserActionInitialization(G4String user_action_opt, G4String which_gene, G4String which_gene_opt)
81 #if G4VERSION_NUMBER < 1000
82  :
83 #else
84  : G4VUserActionInitialization(),
85 #endif
86  fUserActionOption(user_action_opt),
87  fWhichGenerator(which_gene,which_gene_opt)
88 {
89 }
91 {
92  for (size_t i = 0; i < fAllUserAction.size(); i++) {
93  if ( fAllUserAction[i] ) {
94  delete fAllUserAction[i];
95  fAllUserAction[i] = 0x0;
96  }
97  };
98 }
99 std::pair < G4String, G4String > SToGS::UserActionInitialization::SetWhichGenerator(G4String which_gene, G4String option)
100 {
101  std::pair < G4String, G4String > current = fWhichGenerator, new_one(which_gene,option);
102 
103  fWhichGenerator = new_one;
104  return current;
105 }
106 
107 // Primary Generators
109 
110 /*
111 #ifdef HAS_MYPRI
112 // based on My plugins defined in SToGSConfig, it build the detector name in factory
113 if ( basename.contains(MYDET_) ) {
114  if ( conffile == "" ) {
115  theConstructor = new MYDET_CLASSTYPE();
116  }
117  else theConstructor = new MYDET_CLASSTYPE(conffile);
118  theDetector = theConstructor->Construct();
119  }
120 #endif
121  */
122 
123 G4VUserPrimaryGeneratorAction *SToGS::UserActionInitialization::GetGun(G4String which, G4String opt) const
124 {
125  G4VUserPrimaryGeneratorAction *gun = 0x0;
126  if ( which == "GPS" )
127  gun = new SToGS::GPSPrimaryGeneratorAction(opt);
128 
129 #ifdef HAS_MYPRI
130  if ( which == MYPRI_ )
131  gun = new MYPRI_CLASSTYPE(opt);
132 #endif
133 
134  return gun;
135 }
136 G4VUserPrimaryGeneratorAction *SToGS::UserActionInitialization::GetGun() const
137 {
138  return GetGun(fWhichGenerator.first,fWhichGenerator.second);
139 }
140 
141 #include "SToGS_G4_TrackerSD.hh"
142 #include "SToGS_G4_CopClusterSD.hh"
143 
144 G4VSensitiveDetector *SToGS::UserActionInitialization::GetTrackerSD( G4String name )
145 {
146  G4cout << "[+[SToGS::UserActionInitialization::GetTrackerSD()]] Creating a Tracker SD " << G4endl;
147  G4VSensitiveDetector *aSD = 0x0;
148 
149  G4SDManager *SDman =
150  G4SDManager::GetSDMpointer();
151 
152 #ifdef G4MULTITHREADED
153  // TO BE CHECKED IF SHOULD BE LIKE THAT !
154  aSD = new SToGS::TrackerSD(name);
155  if ( aSD )
156  SDman->AddNewDetector(aSD);
157 #else
158  aSD = SDman->FindSensitiveDetector(name,false);
159  if ( aSD == 0x0 ) {
160  aSD = new SToGS::TrackerSD(name);
161  if ( aSD )
162  SDman->AddNewDetector(aSD);
163  }
164 #endif
165  G4cout << "[_[SToGS::UserActionInitialization::GetTrackerSD()]] Creating a Tracker SD " << G4endl;
166  return aSD;
167 }
168 
169 G4VSensitiveDetector *SToGS::UserActionInitialization::GetCopClusterSD( G4String name )
170 {
171  G4cout << "[+[SToGS::UserActionInitialization::GetCopClusterSD()]] Creating a CopCluster SD " << G4endl;
172  G4VSensitiveDetector *aSD = 0x0;
173 
174  G4SDManager *SDman =
175  G4SDManager::GetSDMpointer();
176 
177 #ifdef G4MULTITHREADED
178  // TO BE CHECKED IF SHOULD BE LIKE THAT !
179  aSD = new SToGS::CopClusterSD(name);
180  if ( aSD )
181  SDman->AddNewDetector(aSD);
182 #else
183  aSD = SDman->FindSensitiveDetector(name,false);
184  if ( aSD == 0x0 ) {
185  aSD = new SToGS::CopClusterSD(name);
186  if ( aSD )
187  SDman->AddNewDetector(aSD);
188  }
189 #endif
190  G4cout << "[_[SToGS::UserActionInitialization::GetCopClusterSD()]] Creating a CopCluster SD " << G4endl;
191  return aSD;
192 }
193 
195 {
196 #ifdef G4MULTITHREADED
197  G4AutoLock lock(&buildMutex);
198 #endif
199  G4cout << " ------ INF ------ from SToGS::UserActionInitialization::BuildAndRegister() " << G4endl;
200 #if G4VERSION_NUMBER < 1000
201  G4cout << " *** ERROR *** SToGS::UserActionInitialization::BuildAndRegister() should never be called by this version of Geant4 " << G4endl;
202 #else
203  SetUserAction( GetGun(fWhichGenerator.first,fWhichGenerator.second) );
204  //
205  fAllUserAction.push_back(actions);
206  //
207  SetUserAction( new SToGS::RunAction(actions) ) ;
208  SetUserAction( new SToGS::EventAction(actions) ) ;
209  SetUserAction( new SToGS::TrackingAction(actions) ) ;
210  SetUserAction( new SToGS::SteppingAction(actions) ) ;
211 #endif
212  G4cout << " ------ END ------ from SToGS::UserActionInitialization::BuildAndRegister() " << G4endl;
213 }
214 
216 {
217 #ifdef G4MULTITHREADED
218  G4AutoLock lock(&buildMutex);
219 #endif
220  G4cout << " ------ INF ------ from SToGS::UserActionInitialization::Register() " << G4endl;
221 #if G4VERSION_NUMBER < 1000
222  G4cout << " *** ERROR *** SToGS::AllInOneUserActionInitialization::Build() should never be called by this version of Geant4 " << G4endl;
223 #else
224  fAllUserAction.push_back(actions);
225 #endif
226  G4cout << " ------ END ------ from SToGS::UserActionInitialization::Register() " << G4endl;
227 }
228 
229 
void BuildAndRegister(AllActions *) const
add the passed class to the list of allocated ones. It is required for a proper destruction ...
Informations to be kept at each step if a positive energy is deposited in a sensitive detector...
virtual void PreUserTrackingAction(const G4Track *atrack)
UserActionInitialization(G4String which_user_action_opt, G4String which_gene, G4String which_gene_opt)
Base class for a Run action that calls a concrete one.
Base class for a Tracking action that calls a concrete one.
Base class for a Steeping action that calls a concrete one.
static G4VSensitiveDetector * GetCopClusterSD(G4String name="/SToGS/SD/CopCluster")
to get a general SToGS Calorimeter. In Multi-threading mode, return a new instance otherwise a global...
Base class for a Event action that calls a concrete one.
G4int GetPrimaryID() const
Get the primary ID.
static G4VSensitiveDetector * GetTrackerSD(G4String name="/SToGS/SD/Tracker")
to get a general SToGS tracker. In Multi-threading mode, return a new instance otherwise a global one...
virtual G4VUserPrimaryGeneratorAction * GetGun() const
depending on one string, select a given gun
virtual void PostUserTrackingAction(const G4Track *atrack)
std::pair< G4String, G4String > SetWhichGenerator(G4String which_gene, G4String option)
once allocated the generator associated with a UserActionInititialization could be changed here befor...
Base class that regroups in the same space all user's hooks. Convenient for sharing similar data...
User Track Information that kept the origine of any track.
This class is just calling the GPS interface - Could be exported to any other G4 Applications.