ACTARSim
ACTAR TPC Simulation Reference Guide
ActarSimROOTAnalPla.cc
Go to the documentation of this file.
1 // - AUTHOR: Hector Alvarez-Pol 05/2008
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 ActarSimROOTAnalPla
11 /// The Plastic Scintillator detector part of the ROOT Analysis
12 /////////////////////////////////////////////////////////////////
13 
14 #include "ActarSimROOTAnalPla.hh"
15 #include "ActarSimPlaHit.hh"
16 #include "ActarSimPlaGeantHit.hh"
17 
18 #include "G4ios.hh"
19 #include "G4RunManager.hh"
20 #include "G4SDManager.hh"
21 #include "G4Event.hh"
22 #include "G4Run.hh"
23 #include "G4Track.hh"
24 #include "G4ClassificationOfNewTrack.hh"
25 #include "G4TrackStatus.hh"
26 #include "G4Step.hh"
27 #include "G4Types.hh"
28 
29 //#include "G4PhysicalConstants.hh"
30 //#include "G4SystemOfUnits.hh"
31 
32 #include "TROOT.h"
33 //#include "TApplication.h"
34 //#include "TSystem.h"
35 //#include "TH1.h"
36 //#include "TTree.h"
37 //#include "TPad.h"
38 //#include "TCanvas.h"
39 #include "TTree.h"
40 #include "TFile.h"
41 #include "TClonesArray.h"
42 
43 //////////////////////////////////////////////////////////////////
44 /// Constructor
46  //The simulation file
48  simFile->cd();
49 
50  //The tree
52 
53  //TODO->Implement SimHits/Hits duality as R3B...
54 
55  //The clones array of Sci Hits
56  plaHitCA = new TClonesArray("ActarSimPlaHit",2);
57 
58  plaHitsBranch = eventTree->Branch("plaHits",&plaHitCA);
59 }
60 
61 //////////////////////////////////////////////////////////////////
62 /// Destructor. Makes nothing
64 }
65 
66 //////////////////////////////////////////////////////////////////
67 /// Actions to perform in the scintillator anal when generating the primaries
68 void ActarSimROOTAnalPla::GeneratePrimaries(const G4Event *anEvent){
69  if(anEvent){;} // to quiet the compiler
70 }
71 
72 //////////////////////////////////////////////////////////////////
73 /// Actions to perform in the scintillator anal at the begining of the run
74 void ActarSimROOTAnalPla::BeginOfRunAction(const G4Run *aRun) {
75 
76  if (aRun){;} /* keep the compiler "quiet" */
77 
78  //Storing the runID
79  SetTheRunID(aRun->GetRunID());
80 
81  char newDirName[255];
82  sprintf(newDirName,"%s%i","Histos",aRun->GetRunID());
83  simFile->cd(newDirName);
84 
85  dirName = new char[255];
86 
87  sprintf(dirName,"%s","pla");
88  gDirectory->mkdir(dirName,dirName);
89  gDirectory->cd(dirName);
90 
91  simFile->cd();
92 }
93 
94 //////////////////////////////////////////////////////////////////
95 /// Actions to perform in the scintillator anal at the begining of the event
96 void ActarSimROOTAnalPla::BeginOfEventAction(const G4Event *anEvent) {
97  SetTheEventID(anEvent->GetEventID());
98 }
99 
100 //////////////////////////////////////////////////////////////////
101 /// Actions to perform in the scintillator anal at the beginning of the run
102 void ActarSimROOTAnalPla::EndOfEventAction(const G4Event *anEvent) {
103  FillingHits(anEvent);
104 }
105 
106 //////////////////////////////////////////////////////////////////
107 /// Actions to perform in the scintillator detector analysis after each step
108 void ActarSimROOTAnalPla::UserSteppingAction(const G4Step *aStep){
109  if(aStep){;} // to quiet the compiler
110 }
111 
112 //////////////////////////////////////////////////////////////////
113 /// Defining the ActarSimSciHits from the ActarSimSciGeantHits
114 void ActarSimROOTAnalPla::FillingHits(const G4Event *anEvent) {
115  //Hit Container ID for ActarSimSciGeantHit
116  G4int hitsCollectionID =
117  G4SDManager::GetSDMpointer()->GetCollectionID("PlaCollection");
118 
119  G4HCofThisEvent* HCofEvent = anEvent->GetHCofThisEvent();
120 
121  ActarSimPlaGeantHitsCollection* hitsCollection =
122  (ActarSimPlaGeantHitsCollection*) HCofEvent->GetHC(hitsCollectionID);
123 
124  //Number of R3BCalGeantHit (or steps) in the hitsCollection
125  G4int NbHits = hitsCollection->entries();
126  //G4int NbHitsWithSomeEnergy = NbHits;
127  //G4cout << " NbHits: " << NbHits << G4endl;
128 
129  G4int indepHits = 0; //number of Hits
130  G4int* trackIDtable; //stores the trackID of primary particles for each (valid) GeantHit
131  trackIDtable = new G4int[NbHits];
132  G4int* detIDtable; //stores the detIDs for each (valid) GeantHit
133  detIDtable = new G4int[NbHits];
134  G4int* IDtable; //stores the order in previous array for each (valid) GeantHit
135  IDtable = new G4int[NbHits];
136 
137 
138  for (G4int i=0;i<NbHits;i++) {
139  if((*hitsCollection)[i]->GetParentID()==0) { //step from primary
140  if(indepHits==0) { //only for the first Hit
141  trackIDtable[indepHits] = (*hitsCollection)[i]->GetTrackID();
142  detIDtable[indepHits] = (*hitsCollection)[i]->GetDetID();
143  IDtable[i] = indepHits;
144  indepHits++;
145  }
146  else { // this part is never reached. Maybe because there is always only one indepHits that has parentID equals to 0.
147  for(G4int j=0; j<indepHits;j++) {
148  if( (*hitsCollection)[i]->GetTrackID() == trackIDtable[j] &&
149  (*hitsCollection)[i]->GetDetID() == detIDtable[j]) { //checking trackID and detID
150  IDtable[i] = j;
151  break; //not a new Hit
152  }
153  if(j==indepHits-1){ //we got the last hit and there was no match!
154  trackIDtable[indepHits] = (*hitsCollection)[i]->GetTrackID();
155  detIDtable[indepHits] = (*hitsCollection)[i]->GetDetID();
156  IDtable[i] = indepHits;
157  indepHits++;
158  }
159  }
160  }
161  }
162  }
163 
164  //Let us create as many ActarSimSilHit as independent primary particles
165  thePlaHit = new ActarSimPlaHit*[indepHits];
166  for (G4int i=0;i<indepHits;i++)
167  thePlaHit[i] = new ActarSimPlaHit();
168 
169  //Clear the ClonesArray before filling it
170  plaHitCA->Clear();
171 
172  //a variable to check if the Hit was already created
173  G4int* existing;
174  existing = new G4int[indepHits];
175  for(G4int i=0;i<indepHits;i++) existing[i] = 0;
176 
177  for(G4int i=0;i<NbHits;i++) {
178  if( (*hitsCollection)[i]->GetParentID()==0 ) { //step from primary
179  //the IDtable[i] contains the order in the indepHits list
180  if( existing[IDtable[i]]==0) { //if the indepHits does not exist
181  AddCalPlaHit(thePlaHit[IDtable[i]],(*hitsCollection)[i],0);
182  existing[IDtable[i]] = 1;
183  }
184  else
185  AddCalPlaHit(thePlaHit[IDtable[i]],(*hitsCollection)[i],1);
186  }
187  }
188 
189  //at the end, fill the ClonesArray
190  for (G4int i=0;i<indepHits;i++)
191  new((*plaHitCA)[i])ActarSimPlaHit(*thePlaHit[i]);
192 
193  delete [] trackIDtable;
194  delete [] IDtable;
195  delete [] existing;
196  delete [] detIDtable;
197  for (G4int i=0;i<indepHits;i++) delete thePlaHit[i];
198  delete [] thePlaHit;
199 }
200 
201 //CsI-like hit pattern
202 /*
203  //We accept edep=0 GeantHits, we have to remove them
204  //from the total number of GeantHits accepted for creating a real CrystalHit
205  for (G4int i=0;i<NbHits;i++)
206  if((*hitsCollection)[i]->GetEdep()==0.)
207  NbHitsWithSomeEnergy--;
208  //G4cout << " NbHitsWithSomeEnergy: " << NbHitsWithSomeEnergy << G4endl;
209 
210  G4int NbCrystalsWithHit=NbHitsWithSomeEnergy;
211  G4String* nameWithSomeEnergy;
212  G4int* detIDWithSomeEnergy;
213  detIDWithSomeEnergy = new G4int[NbHitsWithSomeEnergy];
214  nameWithSomeEnergy = new G4String[NbHitsWithSomeEnergy];
215 
216  //keep the crystal identifiers of the GeantHits with some energy
217  G4int hitsWithEnergyCounter=0;
218  for (G4int i=0;i<NbHits;i++) {
219  if((*hitsCollection)[i]->GetEdep()>0.){
220  nameWithSomeEnergy[hitsWithEnergyCounter] = (*hitsCollection)[i]->GetDetName();
221  detIDWithSomeEnergy[hitsWithEnergyCounter] = (*hitsCollection)[i]->GetDetID();
222  //G4cout << "with some energy: name:" << nameWithSomeEnergy[hitsWithEnergyCounter]
223  // << " detID:"<<detIDWithSomeEnergy[hitsWithEnergyCounter] << G4endl;
224  hitsWithEnergyCounter++;
225  }
226  }
227 
228  //if(hitsWithEnergyCounter != NbHitsWithSomeEnergy) {
229  // G4cout << "ERROR in ActarSimROOTAnalSci::FillingHits(): hitsWithEnergyCounter!=NbHitsWithSomeEnergy" << G4endl;
230  // G4cout << " hitsWithEnergyCounter = " << hitsWithEnergyCounter << " while NbHitsWithSomeEnergy = " << NbHitsWithSomeEnergy << G4endl;
231  //}
232 
233  //We ask for the number of crystals with signal and
234  //this loop calculates them from the number of ActarSimSciGeantHits with energy
235  for (G4int i=0;i<NbHitsWithSomeEnergy;i++) {
236  for(G4int j=0;j<i;j++){
237  if(nameWithSomeEnergy[i] == nameWithSomeEnergy[j] && detIDWithSomeEnergy[i] == detIDWithSomeEnergy[j]){
238  NbCrystalsWithHit--;
239  break; //break stops the second for() sentence as soon as one repetition is found
240  }
241  }
242  }
243  //G4cout << " NbCrystalsWithHit: " << NbCrystalsWithHit << G4endl;
244 
245  G4String* nameWithHit;
246  G4int* detIDWithHit;
247  detIDWithHit = new G4int[NbCrystalsWithHit];
248  nameWithHit = new G4String[NbCrystalsWithHit];
249  hitsWithEnergyCounter=0;
250 
251  //keep the crystal identifiers of the final crystalHits
252  G4int hitsCounter=0;
253  for (G4int i=0;i<NbHits;i++) {
254  if ((*hitsCollection)[i]->GetEdep()>0.) {
255  if(hitsCounter==0) { //the first geantHit with energy always creates a newHit
256  nameWithHit[hitsCounter] = (*hitsCollection)[i]->GetDetName();
257  detIDWithHit[hitsCounter] = (*hitsCollection)[i]->GetDetID();
258  //G4cout << "with hit: name:" << nameWithHit[hitsCounter]
259  // << " detID:"<<detIDWithHit[hitsCounter] << G4endl;
260  hitsCounter++;
261  }
262  else {
263  for (G4int j=0;j<hitsCounter;j++) {
264  if ( (*hitsCollection)[i]->GetDetName() == nameWithHit[j] &&
265  (*hitsCollection)[i]->GetDetID() == detIDWithHit[j] ) {
266  break; //break stops the second for() sentence as soon as one repetition is found
267  }
268  if(j==hitsCounter-1){ //when the previous if was never true, there is no repetition
269  nameWithHit[hitsCounter] = (*hitsCollection)[i]->GetDetName();
270  detIDWithHit[hitsCounter] = (*hitsCollection)[i]->GetDetID();
271  //G4cout << "with hit: name:" << nameWithHit[hitsCounter]
272  // << " detID:"<<detIDWithHit[hitsCounter] << G4endl;
273  hitsCounter++;
274  }
275  }
276  }
277  }
278  }
279  //DELETE ME AFTER THE PRELIMINARY TESTS!
280  //if(hitsCounter != NbCrystalsWithHit) {
281  // G4cout << "ERROR in R3BROOTAnalCal::FillingHits(): hitsCounter!=NbCrystalsWithHit" << G4endl;
282  // G4cout << " hitsCounter = " << hitsCounter << " while NbCrystalsWithHit = " << NbCrystalsWithHit << G4endl;
283  //}
284 
285  //Let us create as many R3BCalCrystalHit as NbCrystalsWithHit
286  //TODO->Recover here the simhit/hit duality if needed!!
287  //if(((ActarSimROOTAnalysis*)gActarSimROOTAnalysis)->GetUseCrystalHitSim()==0){
288  thePlaHit = new ActarSimPlaHit*[NbCrystalsWithHit];
289  for (G4int i=0;i<NbCrystalsWithHit;i++)
290  thePlaHit[i] = new ActarSimPlaHit();
291  //}
292  //else{ //In case that the simulated hits were used!
293  // theSciHit = new ActarSimSciHit*[NbCrystalsWithHit];
294  // for (G4int i=0;i<NbCrystalsWithHit;i++)
295  // theSciHit[i] = new ActarSimSciHitSim();
296  //}
297 
298  //Clear the ClonesArray before filling it
299  plaHitCA->Clear();
300 
301  G4bool counted = 0;
302  hitsCounter = 0; //now this variable is going to count the added GeantHits
303  G4String* name;
304  G4int* detID;
305  detID = new G4int[NbCrystalsWithHit];
306  name = new G4String[NbCrystalsWithHit];
307 
308  G4bool shouldThisBeStored = 0;
309  //Filling the ActarSimSciHit from the R3BCalGeantHit (or step)
310  for (G4int i=0;i<NbHits;i++) {
311  //do not accept GeantHits with edep=0
312  //if there is no other GeantHit with edep>0 in the same crystal!
313  shouldThisBeStored=0;
314  counted =0;
315  //G4cout << "ADDING THE HITS. GeantHit with name:" << (*hitsCollection)[i]->GetDetName()
316  // << " detID:"<< (*hitsCollection)[i]->GetDetID() << " edep:"<< (*hitsCollection)[i]->GetEdep() <<" under consideration"<< G4endl;
317  for (G4int j=0;j<NbCrystalsWithHit;j++) {
318  if( (*hitsCollection)[i]->GetDetName() == nameWithHit[j] &&
319  (*hitsCollection)[i]->GetDetID() == detIDWithHit[j] ) {
320  shouldThisBeStored=1;
321  break; //break stops the for() sentence as soon as one "energetic" partner is found
322  }
323  }
324  if(!shouldThisBeStored) continue; //so, continue with next, if there is no "energetic partner"
325  if(hitsCounter==0){ //only for the first geantHit accepted for storage
326  name[hitsCounter] = (*hitsCollection)[i]->GetDetName();
327  detID[hitsCounter] = (*hitsCollection)[i]->GetDetID();
328  AddCalPlaHit(thePlaHit[hitsCounter],(*hitsCollection)[i],0);
329  //G4cout << "ADD hit: name:" << name[hitsCounter]
330  // << " detID:"<<detID[hitsCounter] << " with code 0 (initial)" << G4endl;
331  hitsCounter++;
332  }
333  else { // from the second in advance, compare if a R3BCalCrystalHit
334  // in the same volume already exists
335  for (G4int j=0;j<hitsCounter;j++) {
336  if( (*hitsCollection)[i]->GetDetName() == name[j] &&
337  (*hitsCollection)[i]->GetDetID() == detID[j] ){ //identical Hit already present
338  AddCalPlaHit(thePlaHit[j],(*hitsCollection)[i],1);
339  //G4cout << "ADD hit: name:" << name[j]
340  // << " detID:"<< detID[j] << " with code 1" << G4endl;
341  counted = 1;
342  break; // stops the for() loop; the info is written in the first identical Hit
343  }
344  }
345  if(counted==0) { //No identical Hit present.
346  name[hitsCounter] = (*hitsCollection)[i]->GetDetName();
347  detID[hitsCounter] = (*hitsCollection)[i]->GetDetID();
348  AddCalPlaHit(thePlaHit[hitsCounter],(*hitsCollection)[i],0);
349  //G4cout << "ADD hit: name:" << name[hitsCounter]
350  // << " detID:"<<detID[hitsCounter] << " with code 0" << G4endl;
351  hitsCounter++;
352  }
353  }
354  }
355 
356  //BORRAME
357  //G4cout << G4endl <<"************************ END OF DEBUGGING *****************************************" << G4endl;
358  //G4cout <<"************************************************************************************" << G4endl;
359 
360  //at the end, fill the ClonesArray
361  //TODO-> Recover here the simhit/hit duality if needed!!
362  //if(((ActarSimROOTAnalysis*)gActarSimROOTAnalysis)->GetUseCrystalHitSim()==0){
363  for (G4int i=0;i<NbCrystalsWithHit;i++)
364  new((*plaHitCA)[i])ActarSimPlaHit(*thePlaHit[i]);
365  //}
366  //else{ //In case that the simulated hits were used!
367  // ActarSimSciHitSim* testSim;
368  // for (G4int i=0;i<NbCrystalsWithHit;i++) {
369  // testSim = (ActarSimSciHitSim*) (theSciHit[i]);
370  // new((*sciHitCA)[i])ActarSimSciHitSim(*testSim);
371  // }
372  //}
373 
374  // all branches at the same time!
375  //G4cout << " #@BITCOUNT "<< crystalHitsBranch->Fill() << G4endl;
376  //G4cout << " #@BITCOUNT "<< theR3BTree->Fill() << G4endl;
377 
378  delete [] detIDWithSomeEnergy;
379  delete [] nameWithSomeEnergy;
380  delete [] detIDWithHit;
381  delete [] nameWithHit;
382  delete [] detID;
383  delete [] name;
384  for (G4int i=0;i<NbCrystalsWithHit;i++) delete thePlaHit[i];
385  delete [] thePlaHit;
386 
387  }
388 
389  */
390 //End of CsI Like hit
391 
392 //////////////////////////////////////////////////////////////////
393 /// Function to move the information from the ActarSimSciGeantHit (a step hit)
394 /// to ActarSimSciHit (an event hit) for the Darmstadt-Heidelberg Crystall Ball.
395 /// Two modes are possible:
396 /// - mode == 0 : creation; the ActarSimSciHit is void and is
397 /// filled by the data from the ActarSimSciGeantHit
398 /// - mode == 1 : addition; the ActarSimSciHit was already created
399 /// by other ActarSimSciGeantHit and some data members are updated
401  ActarSimPlaGeantHit* gHit,
402  G4int mode) {
403 
404  if(mode == 0) { //creation
405  if( gHit->GetDetName() == "plaPhys" ) ; //cHit->SetType(1);
406  else G4cout << "ERROR in R3BROOTAnalCal::AddCalCrystalHit()." << G4endl
407  << "Unknown Detector Name: "<< gHit->GetDetName() << G4endl << G4endl;
408 
409  cHit->SetDetectorID(gHit->GetDetID());
410 
411  cHit->SetXPos(gHit->GetLocalPrePos().x()/CLHEP::mm);
412  cHit->SetYPos(gHit->GetLocalPrePos().y()/CLHEP::mm);
413  cHit->SetZPos(gHit->GetLocalPrePos().z()/CLHEP::mm);
414 
415  cHit->SetTime(gHit->GetToF()/CLHEP::ns);
416  cHit->SetEnergy(gHit->GetEdep()/CLHEP::MeV);
417  cHit->SetEBeforePla(gHit->GetEBeforePla()/CLHEP::MeV);
418  cHit->SetEAfterPla(gHit->GetEAfterPla()/CLHEP::MeV);
419 
420  cHit->SetTrackID(gHit->GetTrackID());
421  cHit->SetEventID(GetTheEventID());
422  cHit->SetRunID(GetTheRunID());
423 
424  cHit->SetParticleID(gHit->GetParticleID());
425  cHit->SetParticleCharge(gHit->GetParticleCharge());
426  cHit->SetParticleMass(gHit->GetParticleMass());
427 
428  cHit->SetStepsContributing(1);
429 
430 
431  //CsI Like
432  /* cHit->SetCopy(gHit->GetDetID());
433 
434  cHit->SetEnergy(gHit->GetEdep()/ MeV);
435  cHit->SetTime(gHit->GetToF() / ns);
436 
437  cHit->SetTrackID(gHit->GetTrackID());
438  cHit->SetEventID(GetTheEventID());
439  cHit->SetRunID(GetTheRunID());
440 
441  cHit->SetParticleID(gHit->GetParticleID());
442  cHit->SetParticleCharge(gHit->GetParticleCharge());
443  cHit->SetParticleMass(gHit->GetParticleMass());*/ //CsI-like
444 
445  //TODO-> Recover here the simhit/hit duality if needed!!
446  /*
447  if(((ActarSimROOTAnalysis*)gActarSimROOTAnalysis)->GetUseCrystalHitSim()!=0){
448  if( fabs(gHit->GetLocalPos().z())> 120 )
449  ((ActarSimSciHitSim*)cHit)->SetEnergyPerZone(24,gHit->GetEdep()/ MeV);
450  else {
451  G4int bin = (G4int)((gHit->GetLocalPos().z()/10) + 12);
452  ((ActarSimSciHitSim*)cHit)->SetEnergyPerZone( bin,
453  gHit->GetEdep()/ MeV);
454  //G4cout << G4endl << "Initial posZ:" << gHit->GetLocalPos().z() << " bin " << bin
455  // << " E:" << ((ActarSimSciHitSim*)cHit)->GetEnergyPerZone( bin ) << G4endl << G4endl;
456  }
457  ((ActarSimSciHitSim*)cHit)->SetNbOfSteps(1);
458  ((ActarSimSciHitSim*)cHit)->SetTimeFirstStep(gHit->GetToF() / ns);
459  ((ActarSimSciHitSim*)cHit)->SetTimeLastStep(gHit->GetToF() / ns);
460  ((ActarSimSciHitSim*)cHit)->SetNbOfPrimaries(GetPrimNbOfParticles());
461  ((ActarSimSciHitSim*)cHit)->SetEnergyPrimary(GetPrimEnergy() / MeV);
462  ((ActarSimSciHitSim*)cHit)->SetThetaPrimary(GetPrimTheta() / rad);
463  ((ActarSimSciHitSim*)cHit)->SetPhiPrimary(GetPrimPhi() / rad);
464  if(gHit->GetProcessName()=="phot") ((ActarSimSciHitSim*)cHit)->SetFirstInteractionType(1);
465  else if(gHit->GetProcessName()=="compt") ((ActarSimSciHitSim*)cHit)->SetFirstInteractionType(2);
466  else if(gHit->GetProcessName()=="conv") ((ActarSimSciHitSim*)cHit)->SetFirstInteractionType(3);
467  else if(gHit->GetProcessName()=="msc") ((ActarSimSciHitSim*)cHit)->SetFirstInteractionType(4);
468  else if(gHit->GetProcessName()=="eBrem") ((ActarSimSciHitSim*)cHit)->SetFirstInteractionType(5);
469  else if(gHit->GetProcessName()=="Transportation") ((ActarSimSciHitSim*)cHit)->SetFirstInteractionType(6);
470  else ((ActarSimSciHitSim*)cHit)->SetFirstInteractionType(0);
471  ((ActarSimSciHitSim*)cHit)->SetFirstInteractionX(gHit->GetLocalPos().x());
472  ((ActarSimSciHitSim*)cHit)->SetFirstInteractionY(gHit->GetLocalPos().y());
473  ((ActarSimSciHitSim*)cHit)->SetFirstInteractionZ(gHit->GetLocalPos().z());
474  }
475  */
476  }
477  else if(mode==1){ //addition
478  cHit->SetEnergy(cHit->GetEnergy() + gHit->GetEdep()/ CLHEP::MeV);
479  //taking the smaller outgoing energy of the geantHits
480  if(cHit->GetEAfterPla()>gHit->GetEAfterPla()) cHit->SetEAfterPla(gHit->GetEAfterPla()/CLHEP::MeV);
481  //taking the larger incoming energy of the geantHits
482  if(cHit->GetEBeforePla()<gHit->GetEBeforePla()) cHit->SetEBeforePla(gHit->GetEBeforePla()/CLHEP::MeV);
483 
485  // The mean value of a distribution {x_i} can also be computed iteratively
486  // if the values x_i are drawn one-by-one. After a new value x, the new mean is:
487  // mean(t) = mean(t-1) + (1/t)(x-mean(t-1))
488  cHit->SetXPos(cHit->GetXPos() +
489  (gHit->GetLocalPrePos().x()-cHit->GetXPos())/((G4double)cHit->GetStepsContributing()));
490  cHit->SetYPos(cHit->GetYPos() +
491  (gHit->GetLocalPrePos().y()-cHit->GetYPos())/((G4double)cHit->GetStepsContributing()));
492  cHit->SetZPos(cHit->GetZPos() +
493  (gHit->GetLocalPrePos().z()-cHit->GetZPos())/((G4double)cHit->GetStepsContributing()));
494 
495  //taking the shorter time of the geantHits
496  if(gHit->GetToF()<cHit->GetTime()) cHit->SetTime(gHit->GetToF()/CLHEP::ns);
497 
498  //TODO-> Recover here the simhit/hit duality if needed!!
499  /*
500  if(((ActarSimROOTAnalysis*)gActarSimROOTAnalysis)->GetUseCrystalHitSim()!=0){
501  if( fabs(gHit->GetLocalPos().z())> 120 )
502  ((R3BCalCrystalHitSim*)cHit)->SetEnergyPerZone(24,
503  ((R3BCalCrystalHitSim*)cHit)->GetEnergyPerZone(24)+gHit->GetEdep()/ MeV);
504  else {
505  G4int bin = (G4int)((gHit->GetLocalPos().z()/10) + 12);
506  ((R3BCalCrystalHitSim*)cHit)->SetEnergyPerZone( bin,
507  ((R3BCalCrystalHitSim*)cHit)->GetEnergyPerZone(bin)+gHit->GetEdep()/ MeV);
508  //G4cout << G4endl << "Adding posZ:" << gHit->GetLocalPos().z() << " bin " << bin << " E:"
509  // << ((R3BCalCrystalHitSim*)cHit)->GetEnergyPerZone( bin ) << G4endl << G4endl;
510  }
511  ((R3BCalCrystalHitSim*)cHit)->SetNbOfSteps(((R3BCalCrystalHitSim*)cHit)->GetNbOfSteps()+1);
512  if(gHit->GetToF()<((R3BCalCrystalHitSim*)cHit)->GetTime()){
513  ((R3BCalCrystalHitSim*)cHit)->SetTime(gHit->GetToF()/ ns);
514  ((R3BCalCrystalHitSim*)cHit)->SetTimeFirstStep(gHit->GetToF() / ns);
515  if(gHit->GetProcessName()=="phot") ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionType(1);
516  else if(gHit->GetProcessName()=="compt") ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionType(2);
517  else if(gHit->GetProcessName()=="conv") ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionType(3);
518  else if(gHit->GetProcessName()=="msc") ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionType(4);
519  else if(gHit->GetProcessName()=="eBrem") ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionType(5);
520  else if(gHit->GetProcessName()=="Transportation") ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionType(6);
521  else ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionType(0);
522  ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionX(gHit->GetLocalPos().x());
523  ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionY(gHit->GetLocalPos().y());
524  ((R3BCalCrystalHitSim*)cHit)->SetFirstInteractionZ(gHit->GetLocalPos().z());
525  }
526  else if(gHit->GetToF()>((R3BCalCrystalHitSim*)cHit)->GetTimeLastStep())
527  ((R3BCalCrystalHitSim*)cHit)->SetTimeLastStep(gHit->GetToF());
528  }
529 */
530  }
531 }
G4THitsCollection< ActarSimPlaGeantHit > ActarSimPlaGeantHitsCollection
void SetEBeforePla(Double_t eb)
void SetParticleCharge(Double_t pdgCharge)
Double_t GetEnergy()
Double_t GetZPos()
void SetStepsContributing(UInt_t step)
void SetXPos(Double_t x)
UInt_t GetStepsContributing()
Double_t GetXPos()
Double_t GetTime()
void SetEnergy(Double_t ed)
void SetEAfterPla(Double_t ea)
void SetTheRunID(G4int id)
void SetZPos(Double_t z)
Double_t GetEBeforePla()
void SetEventID(UInt_t ev)
TBranch * plaHitsBranch
Local branch for plastics.
void SetTheEventID(G4int id)
ActarSimROOTAnalPla()
Constructor.
ActarSimROOTAnalysis * gActarSimROOTAnalysis
Global pointer to this soliton.
void FillingHits(const G4Event *anEvent)
Defining the ActarSimSciHits from the ActarSimSciGeantHits.
void SetDetectorID(Int_t det)
TTree * eventTree
Local pointer to the event tree.
void SetRunID(UInt_t run)
void AddCalPlaHit(ActarSimPlaHit *, ActarSimPlaGeantHit *, G4int)
Double_t GetEAfterPla()
void SetParticleMass(Double_t pdgMass)
TFile * simFile
Local pointer to simFile.
void SetYPos(Double_t y)
TClonesArray * plaHitCA
ClonesArray of the hits in the plastic.
void SetTrackID(UInt_t track)
void BeginOfEventAction(const G4Event *)
Actions to perform in the scintillator anal at the begining of the event.
ActarSimPlaHit ** thePlaHit
Pointer to the hits in the plastic.
void GeneratePrimaries(const G4Event *)
Actions to perform in the scintillator anal when generating the primaries.
~ActarSimROOTAnalPla()
Destructor. Makes nothing.
void UserSteppingAction(const G4Step *)
Actions to perform in the scintillator detector analysis after each step.
G4ThreeVector GetLocalPrePos()
Double_t GetYPos()
void BeginOfRunAction(const G4Run *)
Actions to perform in the scintillator anal at the begining of the run.
void SetParticleID(UInt_t pdgID)
void SetTime(Double_t ti)
void EndOfEventAction(const G4Event *)
Actions to perform in the scintillator anal at the beginning of the run.