GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSHitsAction.h
Go to the documentation of this file.
1 /*
2  * GGSHitsAction.h
3  *
4  * Created on: Oct 8, 2010
5  * Author: Elena Vanuccini and Nicola Mori
6  * Reworked on: 17 Aug 2011
7  * Author: Nicola mori
8  * Content: MC truth (GGSTSimEvent) moved to another action. Name changed.
9  * Only hits are handled by this action.
10  */
11 
14 #ifndef GGSHITSACTION_H_
15 #define GGSHITSACTION_H_
16 
17 // GEANT4 headers
18 #include "G4Event.hh"
19 #include "G4GenericMessenger.hh"
20 #include "G4HCofThisEvent.hh"
21 #include "G4LogicalVolumeStore.hh"
22 #include "G4PhysicalVolumeStore.hh"
23 #include "G4Run.hh"
24 #include "G4SDManager.hh"
25 #include "G4VHitsCollection.hh"
26 
27 // ROOT headers
28 #include "TClonesArray.h"
29 #include "TFile.h"
30 #include "TObjString.h"
31 #include "TString.h"
32 #include "TTree.h"
33 
34 // GGS headers
39 
40 // messenger
41 class GGSHitsMessenger;
42 
43 #include <iostream>
44 #include <unordered_map>
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
64 class GGSHitsAction : public GGSUserAction {
65 
66 public:
68  GGSHitsAction();
69 
72 
79  void BeginOfRunAction(const G4Run *run);
80 
88  void EndOfRunAction(const G4Run *run);
89 
96  void BeginOfEventAction(const G4Event *event);
97 
104  void EndOfEventAction(const G4Event *event);
105 
117  void SetOutputFileBase(const std::string &outFileBase) { _outFileBase = outFileBase; }
118 
126  void SetOutputTreeName(const std::string &outTreeName) { _outTreeName = outTreeName; }
127 
133  void SetOutputIntHitClass(std::string detectorName, const std::string &className);
134 
140  void SetOutputPartHitClass(std::string detectorName, const std::string &className);
141 
147  void SetOutputPosHitClass(std::string detectorName, const std::string &className);
148 
171  void SetHitThreshold(const std::string &detectorName, const std::string &hitType, const std::string &valueStr,
172  const std::string &unit);
173 
174 private:
175  G4GenericMessenger _messenger;
176  std::string _outFileBase;
177 
178  TFile *_outFile;
179  TTree *_outTree;
180  TString _outTreeName;
181 
182  // Struct which groups all the output tools for a given detector.
183  struct OutputHandle {
184  std::string intHitClassName, partHitClassName, posHitClassName;
185  std::unique_ptr<GGSTClonesArrayService> partHitCAService, posHitCAService;
186  std::unique_ptr<TClonesArray> intHitArray;
187  std::unique_ptr<TObjArray> partHitArray, posHitArray;
188  float intHitThreshold, partHitThreshold, posHitThreshold; // In internal G4 energy units
189  OutputHandle()
190  : intHitClassName("GGSTIntHit"), partHitClassName("GGSTPartHit"), posHitClassName("GGSTPosHit"),
191  intHitThreshold(0.), partHitThreshold(0.), posHitThreshold(0.) {}
192  };
193 
194  std::unordered_map<std::string, OutputHandle> _outputHandles;
195 
196  struct ThresholdStruct {
197  std::string detectorName;
198  int hitType;
199  float value;
200  };
201 
202  std::vector<ThresholdStruct> _thresholds;
203 
204  void _GiveBackAllArrays(); // Give back to GGSTClonesArrayServices all the TClonesArrays.
205 
216  void _Convert(const GGSPosHitsCollection &posHits, TClonesArray &tPosHits, OutputHandle &handle);
217 
229  void _Convert(const GGSPartHitsCollection &partHits, TClonesArray &tPartHits, OutputHandle &handle);
230 
242  void _Convert(const GGSIntHitsCollection &intHits, TClonesArray &tIntHits, OutputHandle &handle,
243  const std::string &detectorName);
244 
251  class GGSHitsActionPrivateMessenger : public G4UImessenger {
252  public:
257  GGSHitsActionPrivateMessenger(GGSHitsAction *hitsAction);
258 
266  void SetNewValue(G4UIcommand *command, G4String newValue);
267 
268  private:
269  std::unique_ptr<G4UIcommand> _setThreshCmd;
270  GGSHitsAction *_hitsAction;
271  };
272 
273  friend class GGSHitsActionPrivateMessenger;
274  GGSHitsActionPrivateMessenger _privateMessenger;
275 };
276 
277 #endif /* GGSHITSACTION_H_ */
G4THitsCollection< GGSPosHit > GGSPosHitsCollection
Alias for G4 template hits collection for GGSPosHit.
Definition: GGSPosHit.h:194
void EndOfRunAction(const G4Run *run)
Actions executed at end of run.
void SetOutputTreeName(const std::string &outTreeName)
Sets the output tree name.
void SetHitThreshold(const std::string &detectorName, const std::string &hitType, const std::string &valueStr, const std::string &unit)
Sets a lower energy deposit threshold for hits.
GGSHitsAction()
Constructor.
~GGSHitsAction()
Destructor.
void EndOfEventAction(const G4Event *event)
Actions executed at end of event.
void BeginOfEventAction(const G4Event *event)
Actions executed at beginning of event.
void BeginOfRunAction(const G4Run *run)
Actions executed at beginning of run.
G4THitsCollection< GGSIntHit > GGSIntHitsCollection
Alias for G4 template hits collection for GGSIntHit.
Definition: GGSIntHit.h:256
void SetOutputPartHitClass(std::string detectorName, const std::string &className)
Sets the name of the particle hit class to be used for output.
An action which saves hits in sensitive volumes on ROOT file.
Definition: GGSHitsAction.h:64
G4THitsCollection< GGSPartHit > GGSPartHitsCollection
Alias for G4 template hits collection for GGSPartHit.
Definition: GGSPartHit.h:238
Mother class for user actions in GGS.
Definition: GGSUserAction.h:27
void SetOutputPosHitClass(std::string detectorName, const std::string &className)
Sets the name of the position hit class to be used for output.
void SetOutputFileBase(const std::string &outFileBase)
Sets the output file base name.
void SetOutputIntHitClass(std::string detectorName, const std::string &className)
Sets the name of the integrated hit class to be used for output of a given detector.