ACTARSim
ACTAR TPC Simulation Reference Guide
ActarSimROOTAnalysis.cc
Go to the documentation of this file.
1 // - AUTHOR: Hector Alvarez-Pol 03/2005
2 /******************************************************************
3  * Copyright (C) 2005-2016, Hector Alvarez-Pol *
4  * All rights reserved. *
5  * *
6  * License according to GNU LESSER GPL (see lgpl-3.0.txt). *
7  * For the list of contributors see CREDITS. *
8  ******************************************************************/
9 //////////////////////////////////////////////////////////////////
10 /// \class ActarSimROOTAnalysis
11 /// ROOT-based analysis functionality
12 /////////////////////////////////////////////////////////////////
13 
14 #include "ActarSimROOTAnalysis.hh"
15 
16 #include "ActarSimROOTAnalGas.hh"
17 #include "ActarSimROOTAnalSci.hh"
18 #include "ActarSimROOTAnalSil.hh"
21 #include "ActarSimROOTAnalPla.hh"
22 
25 
27 #include "ActarSimPrimaryInfo.hh"
28 
29 #include "ActarSimData.hh"
30 #include "ActarSimTrack.hh"
31 #include "ActarSimSimpleTrack.hh"
32 
33 #include "ActarSimBeamInfo.hh"
34 
35 #include "G4ios.hh"
36 
37 #include "G4RunManager.hh"
38 #include "G4SDManager.hh"
39 #include "G4VPhysicalVolume.hh"
40 #include "G4Event.hh"
41 #include "G4Run.hh"
42 #include "G4Track.hh"
43 #include "G4ClassificationOfNewTrack.hh"
44 #include "G4TrackStatus.hh"
45 #include "G4Step.hh"
46 #include "G4Types.hh"
47 //#include "G4VVisManager.hh"
48 
49 #include "G4Trajectory.hh"
50 
51 //#include "G4PhysicalConstants.hh"
52 //#include "G4SystemOfUnits.hh"
53 
54 #include <time.h>
55 
56 #include "TROOT.h"
57 //#include "TApplication.h"
58 #include "TSystem.h"
59 #include "TH1.h"
60 #include "TH2.h"
61 //#include "TH3.h"
62 #include "TTree.h"
63 //#include "TPad.h"
64 //#include "TCanvas.h"
65 #include "TFile.h"
66 #include "TClonesArray.h"
67 
68 //global pointer to the ROOT analysis manager
70 
71 //////////////////////////////////////////////////////////////////
72 /// Constructor
74  storeTracksFlag("off"), storeTrackHistosFlag("off"),
75  storeEventsFlag("off"), storeSimpleTracksFlag("on"),
76  storeHistogramsFlag("off"), beamInteractionFlag("off") {
77 
78  LastDoItTime = (time_t)0;
79  if(gSystem) gSystem->ProcessEvents();
80 
81  if(gActarSimROOTAnalysis)
82  delete gActarSimROOTAnalysis;
83  gActarSimROOTAnalysis = this;
84 
85  //create a messenger for this class
87 
88  newDirName = new char[255];
89 
90  simFile = 0;
91  eventTree=0;
92  tracksTree=0;
93  primaryInfoCA = 0;
94  beamInfoCA = 0;
95  theDataCA = 0;
96 
97  //null initialization to check that is null before their instantiation
98  gasAnal = 0;
99  silAnal = 0;
100  silRingAnal = 0;
101  sciAnal = 0;
102  sciRingAnal = 0;
103  plaAnal = 0;
104 
111 
112  theData = new ActarSimData();
113  pBeamInfo = new ActarSimBeamInfo();
114 
115  //TODO -> Implement SimpleHit versions in Sil and Sci
116  //TODO -> containing only simulation data (no hardware info)
117 
118  OnceAWhileDoIt();
119 }
120 
121 //////////////////////////////////////////////////////////////////
122 /// Constructor. Save and close Files.
124  delete analMessenger;
125 
126  simFile->Write();
127  simFile->Close();
128 
129  if (gActarSimROOTAnalysis == this)
130  gActarSimROOTAnalysis = (ActarSimROOTAnalysis *)0;
131 
132  delete theData;
133 
134  if (gSystem) gSystem->ProcessEvents();
135 }
136 
137 //////////////////////////////////////////////////////////////////
138 /// Initialization of the detector analysis after the
139 /// class constructor, to allow the selection valid detectors
141  //TFile for storing the info
142  if(!simFile){
143  //simFile = new TFile("simFile.root","RECREATE");
144  //simFile = new TFile("root_files/simFile.root","RECREATE");
145  simFile = new TFile("root_files/sim_files/simFile.root","RECREATE");
146  simFile->cd();
147 
148  eventTree = new TTree("The_ACTAR_Event_Tree","Event_Tree");
149  tracksTree = new TTree("The_ACTAR_Tracks_Tree","Tracks_Tree");
150 
151  primaryInfoCA = new TClonesArray("ActarSimPrimaryInfo",2);
152  eventTree->Branch("primaryInfo",&primaryInfoCA);
153  beamInfoCA = new TClonesArray("ActarSimBeamInfo",1);
154  eventTree->Branch("beamInfo",&beamInfoCA);
155  theDataCA = new TClonesArray("ActarSimData",1);
156  eventTree->Branch("theData",&theDataCA);
157  }
158 
159  //Create the detector analysis only if the flag is set and is not already
160  //set before (then, should be null as they are defined in the constructor)
163 
166 
169 
172 
175 
178 
179  //OTHER DETECTORS ANALYSIS SHOULD BE INCLUDED HERE
180  OnceAWhileDoIt();
181 }
182 
183 //////////////////////////////////////////////////////////////////
184 /// Things to do while contructing...
185 void ActarSimROOTAnalysis::Construct(const G4VPhysicalVolume *theWorldVolume) {
186  if (theWorldVolume) {;} /* keep the compiler "quiet" */
187  if (gSystem) gSystem->ProcessEvents();
188 
189  OnceAWhileDoIt();
190 }
191 
192 //////////////////////////////////////////////////////////////////
193 /// Actions to perform in the analysis during the particle construction
195  if (gSystem) gSystem->ProcessEvents();
196 
197  OnceAWhileDoIt();
198 }
199 
200 //////////////////////////////////////////////////////////////////
201 /// Actions to perform in the analysis during the processes construction
203  if (gSystem) gSystem->ProcessEvents();
204 
205  OnceAWhileDoIt();
206 }
207 
208 //////////////////////////////////////////////////////////////////
209 /// Actions to perform in the analysis during the cut setting
211  if (gSystem) gSystem->ProcessEvents();
212 
213  OnceAWhileDoIt();
214 }
215 
216 //////////////////////////////////////////////////////////////////
217 /// Defining any beam related histogram or information in the output file
218 void ActarSimROOTAnalysis::GenerateBeam(const G4Event *anEvent){
219  SetTheEventID(anEvent->GetEventID());
220 
221  //Clear the ClonesArray before filling it
224  //There is only one clone of beamInfo..
225  new((*beamInfoCA)[0])ActarSimBeamInfo(*pBeamInfo);
226  //do not delete pBeamInfo, as the same pointer is used for all events
227 }
228 
229 //////////////////////////////////////////////////////////////////
230 /// DEPRECATED!!!!! DO NOT USE
231 /// TODO Change from this to a GeneratePrimaries(anEvent, beamInfo).
232 /// DEPRECATED!!!!! DO NOT USE
233 void ActarSimROOTAnalysis::GeneratePrimaries(const G4Event *anEvent,
234  G4double Theta1,
235  G4double Theta2,
236  G4double Energy1,
237  G4double Energy2) {
238  //DEPRECATED!!!!! DO NOT USE
239  if (gSystem) gSystem->ProcessEvents();
240  SetTheEventID(anEvent->GetEventID());
241 
242  //TODO->Remove this assymetry!!! There should be only one GeneratePrimaries
243  //and all information should come in objects, nor arguments!!!!
244  Double_t aTheta1 = (Theta1 / CLHEP::deg); // in [deg]
245  Double_t aTheta2 = (Theta2 / CLHEP::deg); // in [deg]
246  Double_t aEnergy1 = (Energy1 / CLHEP::MeV); // in [MeV]
247  Double_t aEnergy2 = (Energy2 / CLHEP::MeV); // in [MeV]
248 
249  G4int nbOfPrimaryVertex = anEvent->GetNumberOfPrimaryVertex();
250  G4int* nbOfPrimaries = new G4int[nbOfPrimaryVertex];
251  G4int totalPrimaries = 0;
252 
253  for(G4int nbVertexes = 0 ; nbVertexes < nbOfPrimaryVertex ; nbVertexes++){
254  nbOfPrimaries[nbVertexes] = anEvent->GetPrimaryVertex(nbVertexes)->GetNumberOfParticle();
255  totalPrimaries += nbOfPrimaries[nbVertexes];
256  }
257 
258  G4int countingPrimaries = 0;
259 
260  //Clear the ClonesArray before filling it
261  primaryInfoCA->Clear();
262 
263  //Let us create and fill as many ActarSimPrimaryInfo as primaries in the event
264  thePrimaryInfo = new ActarSimPrimaryInfo*[totalPrimaries];
265 
266  for(G4int i=0;i<nbOfPrimaryVertex;i++) {
267  for(G4int j=0;j<nbOfPrimaries[i];j++) {
268  thePrimaryInfo[countingPrimaries] =
269  new ActarSimPrimaryInfo(anEvent->GetPrimaryVertex(i)->GetPrimary(j));
270  thePrimaryInfo[countingPrimaries]->SetNbPrimariesInEvent(totalPrimaries);
271  //do really need this datamember
272  thePrimaryInfo[countingPrimaries]->SetRunID(GetTheRunID());
273  thePrimaryInfo[countingPrimaries]->SetEventID(GetTheEventID());
274  thePrimaryInfo[countingPrimaries]->SetVertexPosition(anEvent->GetPrimaryVertex(i)->GetX0() / CLHEP::mm,
275  anEvent->GetPrimaryVertex(i)->GetY0() / CLHEP::mm,
276  anEvent->GetPrimaryVertex(i)->GetZ0() / CLHEP::mm );
277  //thePrimaryInfo[i]->print();
278  countingPrimaries++;
279  }
280  }
281  //G4cout<<"ActarSimROOTAnalysis----> GeneratePrimaries() "<<totalPrimaries<<G4endl;
282 
283  //at the end, fill the ClonesArray
284  for (G4int i=0;i<totalPrimaries;i++)
286 
287  //G4cout<<" in LOOP ActarSimROOTAnalysis----> GeneratePrimaries() "<<G4endl;
288 
289  for (G4int i=0;i<totalPrimaries;i++) delete thePrimaryInfo[i];
290  delete thePrimaryInfo;
291 
292  delete [] nbOfPrimaries;
293 
294  if (hScatteredIonKinematic) hScatteredIonKinematic->Fill(aTheta1,aEnergy1);
295  if (hRecoilIonKinematic) hRecoilIonKinematic->Fill(aTheta2,aEnergy2);
296 
297  if(gasAnal) gasAnal->GeneratePrimaries(anEvent);
298  if(silAnal) silAnal->GeneratePrimaries(anEvent);
300  if(sciAnal) sciAnal->GeneratePrimaries(anEvent);
302  if(plaAnal) plaAnal->GeneratePrimaries(anEvent);
303 
304  OnceAWhileDoIt();
305 }
306 
307 //////////////////////////////////////////////////////////////////
308 /// Actions to perform in the analysis during the cut setting
309 void ActarSimROOTAnalysis::GeneratePrimaries(const G4Event *anEvent, ActarSimBeamInfo *beamInfo) {
310 
311  if (gSystem) gSystem->ProcessEvents();
312  SetTheEventID(anEvent->GetEventID());
313 
314  Double_t aTheta1 = beamInfo->GetThetaEntrance() / CLHEP::deg; // in [deg]
315  Double_t aTheta2 = beamInfo->GetThetaVertex() / CLHEP::deg; // in [deg]
316  Double_t aEnergy1 = beamInfo->GetEnergyEntrance() / CLHEP::MeV; // in [MeV]
317  Double_t aEnergy2 = beamInfo->GetEnergyVertex() / CLHEP::MeV; // in [MeV]
318 
319 
320  G4int nbOfPrimaryVertex = anEvent->GetNumberOfPrimaryVertex();
321  G4int* nbOfPrimaries = new G4int[nbOfPrimaryVertex];
322  G4int totalPrimaries = 0;
323 
324  for(G4int nbVertexes = 0 ; nbVertexes < nbOfPrimaryVertex ; nbVertexes++){
325  nbOfPrimaries[nbVertexes] = anEvent->GetPrimaryVertex(nbVertexes)->GetNumberOfParticle();
326  totalPrimaries += nbOfPrimaries[nbVertexes];
327  }
328 
329  G4int countingPrimaries = 0;
330 
331  //Clear the ClonesArray before filling it
332  primaryInfoCA->Clear();
333 
334  //Let us create and fill as many ActarSimPrimaryInfo as primaries in the event
335  thePrimaryInfo = new ActarSimPrimaryInfo*[totalPrimaries];
336 
337  for(G4int i=0;i<nbOfPrimaryVertex;i++) {
338  for(G4int j=0;j<nbOfPrimaries[i];j++) {
339  thePrimaryInfo[countingPrimaries] =
340  new ActarSimPrimaryInfo(anEvent->GetPrimaryVertex(i)->GetPrimary(j));
341  thePrimaryInfo[countingPrimaries]->SetNbPrimariesInEvent(totalPrimaries);
342  //do really need this datamember
343  thePrimaryInfo[countingPrimaries]->SetRunID(GetTheRunID());
344  thePrimaryInfo[countingPrimaries]->SetEventID(GetTheEventID());
345  thePrimaryInfo[countingPrimaries]->SetVertexPosition(anEvent->GetPrimaryVertex(i)->GetX0() / CLHEP::mm,
346  anEvent->GetPrimaryVertex(i)->GetY0() / CLHEP::mm,
347  anEvent->GetPrimaryVertex(i)->GetZ0() / CLHEP::mm );
348  //thePrimaryInfo[i]->print();
349  countingPrimaries++;
350  }
351  }
352 
353  //at the end, fill the ClonesArray
354  //G4cout<<"ActarSimROOTAnalysis----> GeneratePrimaries() "<<totalPrimaries<<G4endl;
355 
356  for (G4int i=0;i<totalPrimaries;i++){
357  //G4cout<<"PrimaryInfoCA[i]"<<primaryInfoCA<<G4endl;
358  new((*primaryInfoCA)[i])ActarSimPrimaryInfo(*thePrimaryInfo[i]);
359  //G4cout<<" in LOOP ActarSimROOTAnalysis----> GeneratePrimaries() "<<i<<G4endl;
360  }
361  for (G4int i=0;i<totalPrimaries;i++) delete thePrimaryInfo[i];
362  delete thePrimaryInfo;
363  delete [] nbOfPrimaries;
364 
365  if (hScatteredIonKinematic) hScatteredIonKinematic->Fill(aTheta1,aEnergy1);
366  if (hRecoilIonKinematic) hRecoilIonKinematic->Fill(aTheta2,aEnergy2);
367 
368  if(gasAnal) gasAnal->GeneratePrimaries(anEvent);
369  if(silAnal) silAnal->GeneratePrimaries(anEvent);
371  if(sciAnal) sciAnal->GeneratePrimaries(anEvent);
373  if(plaAnal) plaAnal->GeneratePrimaries(anEvent);
374 
375  OnceAWhileDoIt();
376 }
377 
378 //////////////////////////////////////////////////////////////////
379 /// Actions to perform in the analysis at the beginning of the run
380 void ActarSimROOTAnalysis::BeginOfRunAction(const G4Run *aRun) {
381  if (gSystem) gSystem->ProcessEvents();
382 
383  //Storing the runID
384  SetTheRunID(aRun->GetRunID());
385 
386  //going to the file!!!
387  G4cout << "##################################################################" << G4endl
388  << "######## ActarSimROOTAnalysis::BeginOfRunAction() ############" << G4endl;
389  G4cout << "######## New Run With Number " << aRun->GetRunID() << " Detected!! ######" << G4endl;
390  G4cout << "#### A new directory will be opened in the output ROOT file ####" << G4endl;
391  G4cout << "################################################################## " << G4endl;
392 
393  //static Char_t newDirName[255];
394  sprintf(newDirName,"%s%i","Histos",aRun->GetRunID());
395  simFile->mkdir(newDirName,newDirName);
396  simFile->cd(newDirName);
397 
398  if(storeHistogramsFlag=="on"){
399  // Step Sum Length
400  // histogram for the Cine Kinematic Results for the Scattered Ion
401  //if(reactionFromCineFlag == "on")
403  (TH2F *)gROOT->FindObject("hScatteredIonKinematic");
405  else {
406  hScatteredIonKinematic = new TH2F("hScatteredIonKinematic",
407  "Cine Kinematic for the Scattered Ion",
408  2, 0., 180, 2, 0., 100.);
409  if (hScatteredIonKinematic) hScatteredIonKinematic->SetXTitle("Angle (deg)");
410  if (hScatteredIonKinematic) hScatteredIonKinematic->SetYTitle("Energy (MeV)");
411  if (hScatteredIonKinematic) hScatteredIonKinematic->SetMarkerColor(1);
412  if (hScatteredIonKinematic) hScatteredIonKinematic->SetMarkerStyle(21);
413  if (hScatteredIonKinematic) hScatteredIonKinematic->SetMarkerSize(0.8);
414  }
415 
416  // histogram for the Cine Kinematic Results for the Recoil Ion
418  (TH2F *)gROOT->FindObject("hRecoilIonKinematic");
420  else {
421  hRecoilIonKinematic = new TH2F("hRecoilIonKinematic",
422  "Cine Kinematic for the Recoil Ion",
423  2, 0., 10, 2, 0., 1000.);
424  if (hRecoilIonKinematic) hRecoilIonKinematic->SetXTitle("Angle (deg)");
425  if (hRecoilIonKinematic) hRecoilIonKinematic->SetYTitle("Energy (MeV)");
426  if (hRecoilIonKinematic) hRecoilIonKinematic->SetMarkerColor(1);
427  if (hRecoilIonKinematic) hRecoilIonKinematic->SetMarkerStyle(21);
428  if (hRecoilIonKinematic) hRecoilIonKinematic->SetMarkerSize(0.8);
429  }
430  }
431 
432  if(storeHistogramsFlag=="on"){
433  // Primary
434  hPrimTheta = (TH1D *)gROOT->FindObject("hPrimTheta");
435  if(hPrimTheta) hPrimTheta->Reset();
436  else {
437  hPrimTheta = new TH1D("hPrimTheta",
438  "Primary Theta angle",
439  1000, -0.01, 3.15); //
440  hPrimTheta->SetXTitle("Theta [rad]");
441  }
442 
443  // Primary
444  hPrimPhi = (TH1D *)gROOT->FindObject("hPrimPhi");
445  if(hPrimPhi) hPrimPhi->Reset();
446  else {
447  hPrimPhi = new TH1D("hPrimPhi",
448  "Primary Phi angle",
449  1000, -0.01, 6.29); //
450  hPrimPhi->SetXTitle("Phi [rad]");
451  }
452 
453  // Primary
454  hPrimEnergy = (TH1D *)gROOT->FindObject("hPrimEnergy");
455  if(hPrimEnergy) hPrimEnergy->Reset();
456  else {
457  hPrimEnergy = new TH1D("hPrimEnergy",
458  "Primary Energy (first particle)",
459  10000, -0.01, 301); //
460  hPrimEnergy->SetXTitle("Energy [MeV]");
461  }
462 
463  // Primary Energy vs Theta angle
465  (TH2D *)gROOT->FindObject("hPrimEnergyVsTheta");
467  else {
468  hPrimEnergyVsTheta = new TH2D("hPrimEnergyVsTheta",
469  "Primary Energy vs Theta angle",
470  100, -0.01, 3.15, 100, 0, 301); //mover a 301
471  hPrimEnergyVsTheta->SetYTitle("E [MeV]");
472  hPrimEnergyVsTheta->SetXTitle("Theta [rad]");
473  }
474  }
475 
476  //calling the actions defined for each detector
477  if(gasAnal) gasAnal->BeginOfRunAction(aRun);
478  if(silAnal) silAnal->BeginOfRunAction(aRun);
480  if(sciAnal) sciAnal->BeginOfRunAction(aRun);
482  if(plaAnal) plaAnal->BeginOfRunAction(aRun);
483 
484  simFile->cd();
485 
486  OnceAWhileDoIt(true); // do it now
487 }
488 
489 //////////////////////////////////////////////////////////////////
490 /// Actions to perform in the analysis at the end of the run
491 void ActarSimROOTAnalysis::EndOfRunAction(const G4Run *aRun) {
492  if(gasAnal) gasAnal->EndOfRunAction(aRun);
493 
494  if (aRun) {;} /* keep the compiler "quiet" */
495  if (gSystem) gSystem->ProcessEvents();
496 
497  G4cout << "##################################################################" << G4endl
498  << "######## ActarSimROOTAnalysis::EndOfRunAction() ############" << G4endl;
499  G4cout << "######## Run With Number " << aRun->GetRunID() << " finished! ######" << G4endl;
500  G4cout << "################################################################## " << G4endl;
501 
502  OnceAWhileDoIt(true); // do it now
503 }
504 
505 //////////////////////////////////////////////////////////////////
506 /// Actions to perform in the analysis at the beginning of the event
507 void ActarSimROOTAnalysis::BeginOfEventAction(const G4Event *anEvent){
508  SetTheEventID(anEvent->GetEventID());
509 
510  if (gSystem) gSystem->ProcessEvents();
511 
512  //calling the actions defined for each detector
513  if(gasAnal) gasAnal->BeginOfEventAction(anEvent);
514  if(silAnal) silAnal->BeginOfEventAction(anEvent);
516  if(sciAnal) sciAnal->BeginOfEventAction(anEvent);
517  if(sciAnal) sciAnal->BeginOfEventAction(anEvent);
518  if(plaAnal) plaAnal->BeginOfEventAction(anEvent);
519 
520  OnceAWhileDoIt();
521 }
522 
523 //////////////////////////////////////////////////////////////////
524 /// Actions to perform in the analysis at the end of the event
525 void ActarSimROOTAnalysis::EndOfEventAction(const G4Event *anEvent) {
526  if (gSystem) gSystem->ProcessEvents();
527 
528  G4PrimaryVertex* myPVertex1 = anEvent->GetPrimaryVertex(0);
529  G4PrimaryVertex* myPVertex2 = 0;
530  if(anEvent->GetNumberOfPrimaryVertex()>1)
531  myPVertex2 = anEvent->GetPrimaryVertex(1);
532 
533  // G4cout << "The number of Primaries in the first vertex is "
534  // << myPVertex->GetNumberOfParticle() << G4endl;
535 
536  G4PrimaryParticle* myPrim1 = myPVertex1->GetPrimary();
537  G4PrimaryParticle* myPrim2 = 0;
538  if(myPVertex2) myPrim2 = myPVertex2->GetPrimary();
539  G4ThreeVector momentumPrim1 = myPrim1->GetMomentum();
540  G4ThreeVector momentumPrim2;
541  if(myPrim2) momentumPrim2 = myPrim2->GetMomentum();
542  G4double massPrim1 = myPrim1->GetMass();
543  G4double massPrim2=0.0;
544  if(myPrim2) massPrim2 = myPrim2->GetMass();
545 
546  //KRANE(A.5) T = E - mc2;
547  G4double energyPrim1 = sqrt(momentumPrim1.mag2()+massPrim1*massPrim1) - massPrim1;
548  G4double energyPrim2 = sqrt(momentumPrim2.mag2()+massPrim2*massPrim2) - massPrim2;
549 
550 
551  if(storeHistogramsFlag=="on"){ // added flag dypang 080301
552  //Primary histograms
553  if (hPrimTheta)
554  hPrimTheta->Fill(momentumPrim1.theta());
555  if (hPrimPhi)
556  hPrimPhi->Fill(momentumPrim1.phi());
557  if (hPrimEnergy)
558  hPrimEnergy->Fill(energyPrim1);
559  if (hPrimEnergyVsTheta)
560  hPrimEnergyVsTheta->Fill(momentumPrim1.theta(),energyPrim1);
561  }
562 
563  if(storeEventsFlag=="on"){
564  theData->SetThetaPrim1(momentumPrim1.theta());
565  theData->SetThetaPrim2(momentumPrim2.theta());
566  theData->SetPhiPrim1(momentumPrim1.phi());
567  theData->SetPhiPrim2(momentumPrim2.phi());
568  theData->SetEnergyPrim1(energyPrim1);
569  theData->SetEnergyPrim2(energyPrim2);
570  }
571 
572  //calling the actions defined for each detector
573  //DPL jun2012 only silicon hits stored in ROOT file
574  //G4int hitsCollectionID =G4SDManager::GetSDMpointer()->GetCollectionID("SilCollection");
575  //G4HCofThisEvent* HCofEvent = anEvent->GetHCofThisEvent();
576  //ActarSimSilGeantHitsCollection* hitsCollection =
577  // (ActarSimSilGeantHitsCollection*) HCofEvent->GetHC(hitsCollectionID);
578  //Number of ActarSimSilGeantHit (or steps) in the hitsCollection
579  //G4int NbHits = hitsCollection->entries();
580  //G4cout<<"Hits in the silicon "<< NbHits <<G4endl;
581  //if(NbHits){
582  //G4cout<<"ActarSimROOTAnalysis----> EndOfEventAction() "<<gasAnal<<G4endl;
583  if(gasAnal) gasAnal->EndOfEventAction(anEvent);
584  if(silAnal) silAnal->EndOfEventAction(anEvent);
586  if(sciAnal) sciAnal->EndOfEventAction(anEvent);
588  if(plaAnal) plaAnal->EndOfEventAction(anEvent);
589 
590  if(pBeamInfo->GetStatus()==0){ // pBeamInfo==0 at end of the event in the "fragments event" (pBeamInfo==2 in beam events )
591  //There is only one clone of theData..
592  new((*theDataCA)[0])ActarSimData(*theData);
593  //do not delete theData, as the same pointer is used for all events
594  }
595 
596  eventTree->Fill();
597  primaryInfoCA->Clear(); //needed to avoid duplication of the CA contents in even/odd events
598  beamInfoCA->Clear(); //needed to avoid duplication of the CA contents in even/odd events
599  theDataCA->Clear(); //needed to avoid duplication of the CA contents in even/odd events
600  //}
601  OnceAWhileDoIt();
602 
603 }
604 
605 //////////////////////////////////////////////////////////////////
606 /// Actions to perform in the analysis when classifying new tracks
607 void ActarSimROOTAnalysis::ClassifyNewTrack(const G4Track *aTrack,
608  G4ClassificationOfNewTrack *classification_ptr) {
609  if (aTrack){;} /* keep the compiler "quiet" */
610  if (classification_ptr){;} /* keep the compiler "quiet" */
611  // G4ClassificationOfNewTrack &classification = (*classification_ptr);
612 
613  if (gSystem) gSystem->ProcessEvents();
614 
615  OnceAWhileDoIt();
616 }
617 
618 //////////////////////////////////////////////////////////////////
619 /// Actions to perform in the analysis before the user tracking
621 
622  if (aTrack){;} /* keep the compiler "quiet" */
623  if (gSystem) gSystem->ProcessEvents();
624 
625  OnceAWhileDoIt();
626 }
627 
628 //////////////////////////////////////////////////////////////////
629 /// Actions to perform in the analysis after the user tracking
631  G4TrackStatus *status_ptr) {
632  // G4TrackStatus &status = (*status_ptr);
633  if (aTrack){;} /* keep the compiler "quiet" */
634  if (status_ptr){;} /* keep the compiler "quiet" */
635  if (gSystem) gSystem->ProcessEvents();
636 
637  OnceAWhileDoIt();
638 }
639 
640 
641 //////////////////////////////////////////////////////////////////
642 /// Actions to perform in the analysis after each step
644  //calling the actions defined for each detector
645  if(gasAnal) gasAnal->UserSteppingAction(aStep);
646  if(silAnal) silAnal->UserSteppingAction(aStep);
648  if(sciAnal) sciAnal->UserSteppingAction(aStep);
650  if(plaAnal) plaAnal->UserSteppingAction(aStep);
651 
652  // Processing the beam, in case of beamInteractionFlag on
653  // If a beam ion is being tracked with status 1 (ion beam being tracked) and if the present
654  // step corresponds to the primary (the ion itself!), checks if the z position of vertex,
655  // [calculated in ActarSimPrimaryGeneratorAction and stored in the ActarSimBeamInfo]
656  // is reached. If so, store the ion position and use it for vertex generation and abort the event.
657 
658  if(beamInteractionFlag=="on" && pBeamInfo->GetStatus() == 1){
659  G4double zVertex = pBeamInfo->GetZVertex();
660  if(aStep->GetTrack()->GetParentID()==0){
661  if(aStep->GetPreStepPoint()->GetPosition().z() < zVertex &&
662  aStep->GetPostStepPoint()->GetPosition().z() > zVertex){
663  const G4int verboseLevel = G4RunManager::GetRunManager()->GetVerboseLevel();
664  if(verboseLevel>0){
665  G4cout << G4endl
666  << " *************************************************** " << G4endl
667  << " * ActarSimROOTAnalysis::UserSteppingAction() " << G4endl
668  << " * beamInteractionFlag=on, beam.Status=1, primary particle (ion beam) " << G4endl
669  << " * zVertex at " << aStep->GetPreStepPoint()->GetPosition().z() << G4endl
670  << " * aborting the present event and moving to "<< G4endl;
671  G4cout << " *************************************************** "<< G4endl;
672  }
673  pBeamInfo->SetXVertex(aStep->GetPreStepPoint()->GetPosition().x()/CLHEP::mm);
674  pBeamInfo->SetYVertex(aStep->GetPreStepPoint()->GetPosition().y()/CLHEP::mm);
675  pBeamInfo->SetZVertex(aStep->GetPreStepPoint()->GetPosition().z()/CLHEP::mm);
676  pBeamInfo->SetEnergyVertex(aStep->GetTrack()->GetKineticEnergy()/CLHEP::MeV);
677  pBeamInfo->SetTimeVertex(aStep->GetTrack()->GetGlobalTime()/CLHEP::ns);
678 
679  // beam direction calculated by beam position at entrance and at vertex, needed for Euler transformation
680  G4ThreeVector beamDirection(pBeamInfo->GetXVertex()-pBeamInfo->GetXEntrance(),
683 
684  pBeamInfo->SetThetaVertex(beamDirection.theta());
685  pBeamInfo->SetPhiVertex(beamDirection.phi());
686 
687  pBeamInfo->SetStatus(2);
688  G4RunManager::GetRunManager()->AbortEvent();
689  }
690  }
691  }
692  OnceAWhileDoIt();
693 }
694 
695 //////////////////////////////////////////////////////////////////
696 /// Recursive controller
697 void ActarSimROOTAnalysis::OnceAWhileDoIt(const G4bool DoItNow) {
698  time_t Now = time(0); // get the current time (measured in seconds)
699  if ( (!DoItNow) && (LastDoItTime > (Now - 10)) ) return; // every 10 seconds
700  LastDoItTime = Now;
701 
702  if (gSystem) gSystem->ProcessEvents();
703 }
704 
705 //////////////////////////////////////////////////////////////////
706 /// Setter of the minimum stride length in the gas
708  if(gasAnal)
709  gasAnal->SetMinStrideLength(value);
710 }
void BeginOfRunAction(const G4Run *)
Actions to perform in the SciRingntillator anal at the begining of the run.
void SetMinStrideLength(G4double val)
void UserSteppingAction(const G4Step *)
Actions to perform in the scintillator detector analysis after each step.
Double_t GetThetaEntrance() const
void EndOfRunAction(const G4Run *)
Actions to perform in the analysis at the end of the run.
Double_t GetXVertex() const
TClonesArray * theDataCA
ClonesArray of the data objects.
void GeneratePrimaries(const G4Event *, G4double, G4double, G4double, G4double)
void SetNbPrimariesInEvent(Int_t nb)
void GeneratePrimaries(const G4Event *)
Actions to perform in the SciRingntillator anal when generating the primaries.
void SetTimeVertex(Double_t t)
ActarSimROOTAnalysis()
Constructor.
void BeginOfRunAction(const G4Run *)
Actions to perform in the silicon anal at the begining of the run.
ActarSimROOTAnalSciRing * sciRingAnal
Pointer to detector specific (scintillator ring) analysis class.
void BeginOfEventAction(const G4Event *)
Actions to perform in the silicon anal at the begining of the event.
Double_t GetYVertex() const
void SetPhiVertex(Double_t p)
void EndOfRunAction(const G4Run *)
Actions to perform in the analysis at the end of the run.
void ConstructProcess()
Actions to perform in the analysis during the processes construction.
void SetRunID(UInt_t rID)
void SetXVertex(Double_t x)
TH1D * hPrimEnergy
Histogram of primary energy.
G4int theEventID
Particle Event ID.
Double_t GetZVertex() const
ActarSimROOTAnalGas * gasAnal
Pointer to detector specific (gas chamber) analysis class.
void EndOfEventAction(const G4Event *)
void EndOfEventAction(const G4Event *)
Actions to perform in the analysis at the end of the event.
void PostUserTrackingAction(const G4Track *, G4TrackStatus *)
Actions to perform in the analysis after the user tracking.
G4int plaAnalIncludedFlag
Flag to turn on(1)/off(0) the plastic analysis.
void SetEnergyPrim1(Double_t energy)
Definition: ActarSimData.hh:52
void ClassifyNewTrack(const G4Track *, G4ClassificationOfNewTrack *)
Actions to perform in the analysis when classifying new tracks.
TFile * simFile
The ROOT file.
Double_t GetXEntrance() const
void SetMinStrideLength(Double_t value)
Setter of the minimum stride length in the gas.
void EndOfEventAction(const G4Event *)
Actions to perform in the scintillator anal at the beginning of the run.
void SetEventID(UInt_t eID)
G4int sciAnalIncludedFlag
Flag to turn on(1)/off(0) the scintillator analysis.
void UserSteppingAction(const G4Step *)
Actions to perform in the scintillator detector analysis after each step.
G4int sciRingAnalIncludedFlag
Flag to turn on(1)/off(0) the scintillator ring analysis.
void UserSteppingAction(const G4Step *)
Actions to perform in the analysis after each step.
void SetPhiPrim2(Double_t phi)
Definition: ActarSimData.hh:51
ActarSimROOTAnalSilRing * silRingAnal
Pointer to detector specific (silicon ring) analysis class.
void SetStatus(Int_t s)
G4int silRingAnalIncludedFlag
Flag to turn on(1)/off(0) the silicon ring analysis.
G4int theRunID
Particle Run ID.
void BeginOfRunAction(const G4Run *)
Actions to perform in the scintillator anal at the begining of the run.
void BeginOfEventAction(const G4Event *)
Actions to perform in the analysis at the begining of the event.
void BeginOfEventAction(const G4Event *)
Actions to perform in the scintillator anal at the begining of the event.
void BeginOfRunAction(const G4Run *)
Actions to perform in the analysis at the begining of the run.
void BeginOfEventAction(const G4Event *)
Actions to perform in the silicon anal at the begining of the event.
G4String beamInteractionFlag
Flag to turn "on"/"off" the beam interaction analysis.
TClonesArray * primaryInfoCA
ClonesArray of primaries info objects.
TH2F * hRecoilIonKinematic
Histogram with Cine Kinematic results for recoil ions.
void BeginOfEventAction(const G4Event *)
Actions to perform in the analysis at the beginning of the event.
TTree * eventTree
Events tree.
G4String storeHistogramsFlag
Flag to turn "on"/"off" the storage of general histograms.
G4String storeEventsFlag
Flag to turn "on"/"off" the storage fo events.
TH2D * hPrimEnergyVsTheta
Histogram of primary Energy vs Theta angle.
ActarSimPrimaryInfo ** thePrimaryInfo
Primary particles data.
void SetRunID(UInt_t rID)
void Construct(const G4VPhysicalVolume *)
Things to do while contructing...
Double_t GetZEntrance() const
void GeneratePrimaries(const G4Event *)
Actions to perform in the analysis when generating the primaries.
time_t LastDoItTime
Used in OnceAWhileDoIt method for recursivity.
ActarSimROOTAnalSci * sciAnal
Pointer to detector specific (scintillator) analysis class.
G4int gasAnalIncludedFlag
Flag to turn on(1)/off(0) the gas chamber analysis.
void SetCuts()
Actions to perform in the analysis during the cut setting.
void SetVertexPosition(Double_t x, Double_t y, Double_t z)
Sets the position of the vertex (origin of the primary particle)
void PreUserTrackingAction(const G4Track *)
Actions to perform in the analysis before the user tracking.
void GenerateBeam(const G4Event *)
Defining any beam related histogram or information in the output file.
void OnceAWhileDoIt(const G4bool DoItNow=false)
Recursive controller.
Double_t GetEnergyVertex() const
void SetThetaPrim2(Double_t theta)
Definition: ActarSimData.hh:49
ActarSimData * theData
Pointer to data object.
void GeneratePrimaries(const G4Event *)
Actions to perform in the scintillator anal when generating the primaries.
TH1D * hPrimTheta
Histogram of primary Theta angle.
void BeginOfRunAction(const G4Run *)
Actions to perform in the analysis at the beginning of the run.
void EndOfEventAction(const G4Event *)
void UserSteppingAction(const G4Step *)
Actions to perform in the ACTAR gas detector analysis after each step.
void SetPhiPrim1(Double_t phi)
Definition: ActarSimData.hh:50
ActarSimROOTAnalPla * plaAnal
Pointer to detector specific (plastic) analysis class.
void SetEnergyPrim2(Double_t energy)
Definition: ActarSimData.hh:53
TH2F * hScatteredIonKinematic
Histogram with Cine Kinematic results for scattered ions.
void GeneratePrimaries(const G4Event *)
Actions to perform in the silicon anal when generating the primaries.
char * newDirName
Directory name within ROOT file.
ActarSimROOTAnalysis * gActarSimROOTAnalysis
Global pointer to this soliton.
Double_t GetYEntrance() const
G4int silAnalIncludedFlag
Flag to turn on(1)/off(0) the silicon analysis.
Int_t GetStatus() const
void BeginOfEventAction(const G4Event *)
Actions to perform in the scintillator anal at the begining of the event.
void SetYVertex(Double_t y)
TClonesArray * beamInfoCA
ClonesArray of the beam info objects.
TH1D * hPrimPhi
Histogram of primary Phi angle.
~ActarSimROOTAnalysis()
Constructor. Save and close Files.
void SetZVertex(Double_t z)
void UserSteppingAction(const G4Step *)
Actions to perform in the ACTAR gas detector analysis after each step.
Double_t GetThetaVertex() const
void GeneratePrimaries(const G4Event *)
Actions to perform in the scintillator anal when generating the primaries.
void SetThetaVertex(Double_t t)
void UserSteppingAction(const G4Step *)
Actions to perform in the scintillator detector analysis after each step.
void GeneratePrimaries(const G4Event *)
Actions to perform in the silicon anal when generating the primaries.
TTree * tracksTree
Tracks tree.
ActarSimBeamInfo * pBeamInfo
Pointer to beam information object.
void SetThetaPrim1(Double_t theta)
Definition: ActarSimData.hh:48
ActarSimAnalysisMessenger * analMessenger
Pointer to the corresponding messenger.
Double_t GetEnergyEntrance() const
void EndOfEventAction(const G4Event *)
Actions to perform in the analysis at the end of the event.
void BeginOfRunAction(const G4Run *)
Actions to perform in the scintillator anal at the begining of the run.
ActarSimROOTAnalSil * silAnal
Pointer to detector specific (silicon) analysis class.
void BeginOfRunAction(const G4Run *)
Actions to perform in the silicon anal at the begining of the run.
void EndOfEventAction(const G4Event *)
Actions to perform in the scintillator anal at the beginning of the run.
void SetEnergyVertex(Double_t e)
void EndOfEventAction(const G4Event *)
Actions to perform in the scintillator anal at the beginning of the run.
void ConstructParticle()
Actions to perform in the analysis during the particle construction.
void UserSteppingAction(const G4Step *)
Actions to perform in the ACTAR gas detector analysis after each step.
void SetEventID(UInt_t eID)