GGS(GenericGEANT4Simulation)Software  2.6.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 "G4Run.hh"
20 #include "G4LogicalVolumeStore.hh"
21 #include "G4PhysicalVolumeStore.hh"
22 #include "G4HCofThisEvent.hh"
23 #include "G4VHitsCollection.hh"
24 #include "G4SDManager.hh"
25 #include "G4GenericMessenger.hh"
26 
27 // ROOT headers
28 #include "TString.h"
29 #include "TObjString.h"
30 #include "TFile.h"
31 #include "TTree.h"
32 #include "TClonesArray.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 
65 public:
66 
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) {
118  _outFileBase = outFileBase;
119  }
120 
128  void SetOutputTreeName(const std::string &outTreeName) {
129  _outTreeName = outTreeName;
130  }
131 
137  void SetOutputIntHitClass(std::string detectorName, const std::string &className);
138 
144  void SetOutputPartHitClass(std::string detectorName, const std::string &className);
145 
151  void SetOutputPosHitClass(std::string detectorName, const std::string &className);
152 
175  void SetHitThreshold(const std::string &detectorName, const std::string &hitType, const std::string &valueStr,
176  const std::string &unit);
177 
178 private:
179 
180  G4GenericMessenger _messenger;
181  std::string _outFileBase;
182 
183  TFile* _outFile;
184  TTree* _outTree;
185  TString _outTreeName;
186 
187  // Struct which groups all the output tools for a given detector.
188  struct OutputHandle {
189  std::string intHitClassName, partHitClassName, posHitClassName;
190  std::unique_ptr<GGSTClonesArrayService> partHitCAService, posHitCAService;
191  std::unique_ptr<TClonesArray> intHitArray;
192  std::unique_ptr<TObjArray> partHitArray, posHitArray;
193  float intHitThreshold, partHitThreshold, posHitThreshold; // In internal G4 energy units
194  OutputHandle() :
195  intHitClassName("GGSTIntHit"), partHitClassName("GGSTPartHit"), posHitClassName("GGSTPosHit"), intHitThreshold(
196  std::numeric_limits<float>::lowest()), partHitThreshold(std::numeric_limits<float>::lowest()), posHitThreshold(
197  std::numeric_limits<float>::lowest()) {
198  }
199  };
200 
201  std::unordered_map<std::string, OutputHandle> _outputHandles;
202 
203  struct ThresholdStruct {
204  std::string detectorName;
205  int hitType;
206  float value;
207  };
208 
209  std::vector<ThresholdStruct> _thresholds;
210 
211  void _GiveBackAllArrays(); // Give back to GGSTClonesArrayServices all the TClonesArrays.
212 
221  void _Convert(const GGSPosHitsCollection &posHits, TClonesArray &tPosHits, OutputHandle &handle);
222 
232  void _Convert(const GGSPartHitsCollection &partHits, TClonesArray &tPartHits, OutputHandle &handle);
233 
243  void _Convert(const GGSIntHitsCollection &intHits, TClonesArray &tIntHits, OutputHandle &handle,
244  const std::string &detectorName);
245 
252  class GGSHitsActionPrivateMessenger: public G4UImessenger {
253  public:
258  GGSHitsActionPrivateMessenger(GGSHitsAction *hitsAction);
259 
267  void SetNewValue(G4UIcommand *command, G4String newValue);
268  private:
269  std::unique_ptr<G4UIcommand> _setThreshCmd;
270  GGSHitsAction *_hitsAction;
271  };
272 
273  friend class GGSHitsActionPrivateMessenger;
274  GGSHitsActionPrivateMessenger _privateMessenger;
275 
276 };
277 
278 #endif /* GGSHITSACTION_H_ */
G4THitsCollection< GGSPosHit > GGSPosHitsCollection
Alias for G4 template hits collection for GGSPosHit.
Definition: GGSPosHit.h:223
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:272
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:63
G4THitsCollection< GGSPartHit > GGSPartHitsCollection
Alias for G4 template hits collection for GGSPartHit.
Definition: GGSPartHit.h:259
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.