GGS(GenericGEANT4Simulation)Software  2.7.0
 All Data Structures Namespaces Files Functions Variables Typedefs Macros
GGSFileManager.cpp
1 #include "TEveBrowser.h"
2 #include "TEveManager.h"
3 #include "TGLViewer.h"
4 #include "TObject.h"
5 
6 #include "application/Application.h"
7 #include "application/event/GGSFileManager.h"
8 
9 GGSFileManager::GGSFileManager() : GGSTRootReader() {
10 
11  static const std::string routineName("GGSFileManager::GGSFileManager");
12 
13  _currEvent = -1;
14  _fileLoaded = kFALSE;
15 }
16 GGSFileManager::~GGSFileManager() {}
17 
18 void GGSFileManager::Load(TString fileName) {
19 
20  static const std::string routineName("GGSFileManager::Load");
21 
22  if (gEve)
23  gEve->GetDefaultGLViewer()->GetClipSet()->SetClipType(TGLClip::EType(0));
24 
25  COUT(DEBUG) << "Opening " << fileName << ENDL;
26 
27  GGSTFilesHandler *hand = Open(fileName.Data(), NULL);
28  if (hand == NULL) {
29  COUT(ERROR) << "There was an error opening file " << fileName << ENDL;
30  return;
31  }
32 
33  COUT(DEBUG) << hand->GetNFiles() << " files in the handler" << ENDL;
34  COUT(DEBUG) << hand->GetFileName(0) << ENDL;
35 
36  _Reader = GetReader<GGSTHitsReader>(hand);
37  _detList = _Reader->GetListOfDetectors();
38  for (TString _det : _detList) {
39  _Reader->SetDetector(_det, _Reader->HasPartHits(_det));
40  COUT(DEBUG) << "Adding " << _det << " to detlist" << ENDL;
41  }
42 
43  _MCTruthReader = GetReader<GGSTMCTruthReader>(hand);
44 
45  _pTree = new InteractionTree<GGSTPartHit *>;
46 
47  COUT(DEBUG) << "_Reader at " << _Reader << ENDL;
48  COUT(DEBUG) << "_pTree at " << _pTree << ENDL;
49 
50  _fileLoaded = kTRUE;
51 
52  // ReadEvent( 0 );
53 }
54 
55 void GGSFileManager::PrevEvent() {
56  static const std::string routineName("GGSFileManager::PrevEvent");
57 
58  COUT(DEBUG) << "Click!" << ENDL;
59  if (!_fileLoaded) {
60  COUT(ERROR) << "You must open a file before clicking!" << ENDL;
61  return;
62  }
63  ReadEvent(_currEvent - 1);
64  ((MainWindow *)gEve)->LoadEvent();
65 }
66 
67 void GGSFileManager::NextEvent() {
68  static const std::string routineName("GGSFileManager::NextEvent");
69 
70  COUT(DEBUG) << "Click!" << ENDL;
71  if (!_fileLoaded) {
72  COUT(ERROR) << "You must open a file before clicking!" << ENDL;
73  return;
74  }
75  ReadEvent(_currEvent + 1);
76  ((MainWindow *)gEve)->LoadEvent();
77 }
78 
79 void GGSFileManager::ReadEvent(int iev, bool force) {
80  static const std::string routineName("GGSFileManager::ReadEvent");
81 
82  COUT(DEBUG) << "Click! " << iev << ENDL;
83  if (!_fileLoaded) {
84  COUT(ERROR) << "You must open a file before clicking!" << ENDL;
85  return;
86  }
87  if (!force && (iev < 0 || _currEvent == iev))
88  return;
89 
90  GetEntry(iev);
91  BuildInteractionTree();
92  ((MainWindow *)gEve)->LoadEvent();
93 
94  _currEvent = iev;
95 }
96 
97 void GGSFileManager::BuildInteractionTree() {
98  static const std::string routineName("GGSFileManager::BuildInteractionTree");
99 
100  _pTree->Clear();
101 
102  COUT(DEBUG) << _pTree->hashMap.size() << ENDL;
103 
104  for (TString _det : _detList) {
105  if (_Reader->HasPartHits(_det)) {
106 
107  int nHits = _Reader->GetNHits(_det);
108  GGSTIntHitBase *thisHit = nullptr;
109  GGSTPartHit *thisPHit = nullptr;
110 
111  bool partHitClassChecked = false;
112  for (int iHit = 0; iHit < nHits; iHit++) {
113  thisHit = _Reader->GetHit(_det, iHit);
114  if (!partHitClassChecked) {
115  if (thisHit->GetPartHitsClassName() != "GGSTPartHit") {
116  COUT(WARNING) << "Particle hits for detector " << _det
117  << " are not of class GGSTPartHit. Interaction teree for them will not be built." << ENDL;
118  return;
119  } else {
120  partHitClassChecked = true;
121  }
122  }
123  int nPHits = thisHit->GetNPartHits();
124  for (int iPHit = 0; iPHit < nPHits; iPHit++) {
125  thisPHit = (GGSTPartHit *)(_Reader->GetHit(_det, iHit)->GetPartHit(iPHit));
126  _pTree->AddHit(thisPHit->trackID, thisPHit);
127  }
128  }
129  }
130  }
131 
132  _pTree->SortHits([](GGSTPartHit *h1, GGSTPartHit *h2) -> bool { return h1->time < h2->time; });
133 }
bool HasPartHits(const char *detector)
Check if particle hits data is available for the specified detector.
GGSTIntHitBase * GetHit(const char *detector, unsigned int iHit)
Get the specified hit.
Class to manage ROOT output readers.
GGSTPartHitBase * GetPartHit(unsigned int iHit)
Get the specified particle hit.
Definition: GGSTHits.cpp:182
#define ENDL
Definition: GGSSmartLog.h:105
#define COUT(level)
Smart log macro. It writes on stdout only if the specified verbosity level is lesser than the maximum...
Definition: GGSSmartLog.h:76
Float_t time
Time of the hit.
Definition: GGSTHits.h:178
void GetEntry(Long64_t entry)
Reads an event.
Class to store G4 particle hits.
Definition: GGSTHits.h:176
Int_t trackID
GEANT4 track ID.
Definition: GGSTHits.h:184
Class to handle group of Root files.
Int_t GetNHits(const char *detector)
Gets the number of hits for the specified detector.
GGSTFilesHandler * Open(const std::string &fileName, GGSTFilesHandler *filesHandler=nullptr, bool force=false)
Open ROOT files.
unsigned int GetNFiles()
The number of files handled by this object.
std::string GetPartHitsClassName()
Gets the name of the class of the particle hits.
Definition: GGSTHits.cpp:190
const std::string & GetFileName(unsigned int iFile)
Fetch the name of a handled file.
std::vector< TString > GetListOfDetectors()
Returns the list of detectors which are present in hits tree on standard output.
Int_t GetNPartHits()
Gets the number of particle hits.
Definition: GGSTHits.cpp:175
Base class for storing G4 integrated hits.
Definition: GGSTHits.h:218
void SetDetector(const char *detector, bool readPartHits=false, bool readPosHits=false)
Enables reading hit informations of the specified detector.