36 #include "G4OpticalPhoton.hh"
37 #include "G4VProcess.hh"
40 #include "G4Threading.hh"
42 #ifdef G4MULTITHREADED
43 #include "G4AutoLock.hh"
44 namespace { G4Mutex buildMutex = G4MUTEX_INITIALIZER; }
60 G4int nb_hits_tot = 0, nb_hits_trac = 0, nb_hits_calo = 0;
63 if( colltrackerID < 0 && collcaloID < 0 )
66 fPrimaryEvent.Clear(
"");
69 G4HCofThisEvent *HCE = evt->GetHCofThisEvent();
73 if ( colltrackerID > -1 ) {
74 nb_hits_trac += THC->entries();
77 if ( collcaloID > -1 ) {
78 nb_hits_calo += CHC->entries();
80 nb_hits_tot = nb_hits_trac + nb_hits_calo;
84 G4int istart = 0, iend = evt->GetNumberOfPrimaryVertex();
85 G4int K = 0; G4double H = 0.0;
86 for( G4int i = istart; i < iend ; i++ ){
88 G4int jstart = 0, jend = evt->GetPrimaryVertex(i)->GetNumberOfParticle();
89 for( G4int j = jstart; j < jend; j++ ) {
91 SBRPHit *hit = fPrimaryEvent.AddHit();
94 G4PrimaryParticle *prim = evt->GetPrimaryVertex(i)->GetPrimary(j);
96 hit->
fPDG = prim->GetPDGcode();
99 hit->
fE = prim->GetKineticEnergy()/CLHEP::MeV;
101 hit->
fX = evt->GetPrimaryVertex(i)->GetX0()/CLHEP::cm;
102 hit->
fY = evt->GetPrimaryVertex(i)->GetY0()/CLHEP::cm;
103 hit->
fZ = evt->GetPrimaryVertex(i)->GetZ0()/CLHEP::cm;
105 hit->
fT = evt->GetPrimaryVertex(i)->GetT0();
108 hit->
fPX = prim->GetMomentumDirection().x();
109 hit->
fPY = prim->GetMomentumDirection().y();
110 hit->
fPZ = prim->GetMomentumDirection().z();
112 hit->
fFlag = prim->GetTrackID()-1;
114 H += (std::sqrt( prim->GetMomentum().mag2() + prim->GetMass() * prim->GetMass()) - prim->GetMass())/CLHEP::MeV;
118 fPrimaryEvent.SetEMult(H,K);
120 if ( nb_hits_trac ) {
121 int n_hit = nb_hits_trac;
124 for (
int i = 0 ; i < n_hit; i++) {
126 SBRHit *hit = fEvent.AddHit();
129 G4cout <<
" Cannot add more that " << i <<
" hits in the collection " << G4endl;
133 hit->
fPDG = (*THC)[i]->GetPDGcode();
135 hit->
fE = (*THC)[i]->GetEdep()/CLHEP::MeV;
137 hit->
fX = (*THC)[i]->GetPos().x()/CLHEP::cm;
138 hit->
fY = (*THC)[i]->GetPos().y()/CLHEP::cm;
139 hit->
fZ = (*THC)[i]->GetPos().z()/CLHEP::cm;
140 hit->
fT = (*THC)[i]->GetToF();
142 hit->
fFlag = (*THC)[i]->GetPrimaryID()-1 ;
143 hit->
fUID = (*THC)[i]->GetDetID();
145 H += (*THC)[i]->GetEdep()/CLHEP::MeV;
148 fEvent.SetEMult(H,K);
152 int n_hit = nb_hits_calo;
155 for (
int i = 0 ; i < n_hit; i++) {
157 SBRHit *hit = fEvent.AddHit();
159 G4cout <<
" Cannot add more that " << i <<
" hits in the collection " << G4endl;
164 hit->
fE = (*CHC)[i]->GetEdep()/CLHEP::MeV;
166 hit->
fX = (*CHC)[i]->GetPos().x()/CLHEP::cm;
167 hit->
fY = (*CHC)[i]->GetPos().y()/CLHEP::cm;
168 hit->
fZ = (*CHC)[i]->GetPos().z()/CLHEP::cm;
169 hit->
fT = (*CHC)[i]->GetToF();
171 hit->
fFlag = (*CHC)[i]->GetNbHits() ;
172 hit->
fUID = (*CHC)[i]->GetDetID();
174 H += (*CHC)[i]->GetEdep()/CLHEP::MeV;
177 fEvent.SetEMult(H,K);
179 if ( fRecordOption == 1 ) {
180 if ( fEvent.GetMultTot() > 0 ) fTree->Fill();
188 fOpticalEventBeg(0x0),
189 fOpticalEventEnd(0x0)
192 std::ifstream file(conffile.data());
193 if ( file.is_open() == false ) {
194 G4cout <<
" ** SToGS::BaseROOTEventsUserAction WARNING ** Cannot open file " << conffile <<
", default parameters to be used "<< G4endl;
197 std::string aline; getline(file,aline);
198 while ( file.good() && !file.eof() ) {
200 if ( aline[0] ==
'#' ){
205 std::string key, what, option; std::istringstream decode(aline); decode.clear();
208 if ( key ==
"scintillation:" ) {
219 #ifdef G4MULTITHREADED
220 G4AutoLock lock(&buildMutex);
223 G4Run* therun = 0x0; G4cout <<
" In SToGS::BaseROOTEventsUserAction, Generate a new Run " << G4endl;
225 if ( fTree == 0x0 ) {
226 fTree =
new TTree(fTreeName.data(),fTreeTitle.data());
227 fTree->SetDirectory(0x0);
230 if (fisOptical > 0) {
233 fTree->Branch(
"OpticalEvBegin.", fOpticalEventBeg);
234 fTree->Branch(
"OpticalEvEnd.", fOpticalEventEnd);
240 if ( G4Threading::IsWorkerThread() ) {
245 else therun = G4UserRunAction::GenerateRun();
255 if (fisOptical > 0) {
256 delete fOpticalEventBeg;
delete fOpticalEventEnd;
265 if ( fisOptical > 0 ) {
266 fOpticalEventBeg->Clear(
"");
267 fOpticalEventEnd->Clear(
"");
273 if ( fisOptical < 1 ) {
277 if(atrack->GetDefinition()==G4OpticalPhoton::OpticalPhotonDefinition()){
279 if(atrack->GetParentID()>0){
281 if(atrack->GetCreatorProcess()->GetProcessName()==
"Scintillation") {
285 G4int pid = atrack->GetTrackID();
292 hit->
fX = atrack->GetPosition().x();
293 hit->
fY = atrack->GetPosition().y();
294 hit->
fZ = atrack->GetPosition().z();
296 hit->
fTA = atrack->GetGlobalTime();
297 hit->
fTL = atrack->GetLocalTime();
299 hit->
fLength = atrack->GetTrackLength();
300 hit->
fNbSteps = atrack->GetCurrentStepNumber();
311 if ( fisOptical < 1 ) {
315 if(atrack->GetDefinition()==G4OpticalPhoton::OpticalPhotonDefinition()){
317 if(atrack->GetParentID()>0){
319 if(atrack->GetCreatorProcess()->GetProcessName()==
"Scintillation") {
323 G4int pid = atrack->GetTrackID();
330 hit->
fX = atrack->GetPosition().x();
331 hit->
fY = atrack->GetPosition().y();
332 hit->
fZ = atrack->GetPosition().z();
334 hit->
fTA = atrack->GetGlobalTime();
335 hit->
fTL = atrack->GetLocalTime();
337 hit->
fLength = atrack->GetTrackLength();
338 hit->
fNbSteps = atrack->GetCurrentStepNumber();
G4THitsCollection< TrackerHit > TrackerHitsCollection
SToGS Base Root Polarized Hit.
virtual void PreUserTrackingAction(const G4Track *)
G4THitsCollection< CopClusterHit > CopClusterHitsCollection
virtual void EndOfRunAction(const G4Run *)
virtual G4Run * GenerateRun()
virtual void RecordEvent(const G4Event *evt)
BaseROOTEventsRun(TTree *tree)
BaseROOTEventsUserAction(G4String conffile="setup/SToGS_Tree_actions.conf")
virtual void EndOfRunAction(const G4Run *)
virtual void BeginOfEventAction(const G4Event *)
G4int fisOptical
true if one has also photons from scintillations
virtual void BeginOfEventAction(const G4Event *)
virtual void PostUserTrackingAction(const G4Track *)