GGS(GenericGEANT4Simulation)Software  2.99.0
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Macros
GGSFileManager.cpp
1 #include "TEveBrowser.h"
2 #include "TEveManager.h"
3 #include "TGLViewer.h"
4 #include "TObject.h"
5 
6 #include "display/application/Application.h"
7 #include "display/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  GGSCOUT(DEBUG) << "Opening " << fileName << GGSENDL;
26 
27  GGSTFilesHandler *hand = Open(fileName.Data(), NULL);
28  if (hand == NULL) {
29  GGSCOUT(ERROR) << "There was an error opening file " << fileName << GGSENDL;
30  return;
31  }
32 
33  GGSCOUT(DEBUG) << hand->GetNFiles() << " files in the handler" << GGSENDL;
34  GGSCOUT(DEBUG) << hand->GetFileName(0) << GGSENDL;
35 
36  _Reader = GetReader<GGSTHitsReader>(hand);
37  _detList = _Reader->GetListOfDetectors();
38  for (TString _det : _detList) {
39  _Reader->SetDetector(_det, _Reader->HasPartHits(_det));
40  GGSCOUT(DEBUG) << "Adding " << _det << " to detlist" << GGSENDL;
41  }
42 
43  _MCTruthReader = GetReader<GGSTMCTruthReader>(hand);
44 
45  _pTree = new InteractionTree<GGSTPartHit *>;
46 
47  GGSCOUT(DEBUG) << "_Reader at " << _Reader << GGSENDL;
48  GGSCOUT(DEBUG) << "_pTree at " << _pTree << GGSENDL;
49 
50  _fileLoaded = kTRUE;
51 
52  // ReadEvent( 0 );
53 }
54 
55 void GGSFileManager::PrevEvent() {
56  static const std::string routineName("GGSFileManager::PrevEvent");
57 
58  GGSCOUT(DEBUG) << "Click!" << GGSENDL;
59  if (!_fileLoaded) {
60  GGSCOUT(ERROR) << "You must open a file before clicking!" << GGSENDL;
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  GGSCOUT(DEBUG) << "Click!" << GGSENDL;
71  if (!_fileLoaded) {
72  GGSCOUT(ERROR) << "You must open a file before clicking!" << GGSENDL;
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  GGSCOUT(DEBUG) << "Click! " << iev << GGSENDL;
83  if (!_fileLoaded) {
84  GGSCOUT(ERROR) << "You must open a file before clicking!" << GGSENDL;
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  GGSCOUT(DEBUG) << _pTree->hashMap.size() << GGSENDL;
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  GGSCOUT(WARNING) << "Particle hits for detector " << _det
117  << " are not of class GGSTPartHit. Interaction teree for them will not be built."
118  << GGSENDL;
119  return;
120  } else {
121  partHitClassChecked = true;
122  }
123  }
124  int nPHits = thisHit->GetNPartHits();
125  for (int iPHit = 0; iPHit < nPHits; iPHit++) {
126  thisPHit = (GGSTPartHit *)(_Reader->GetHit(_det, iHit)->GetPartHit(iPHit));
127  _pTree->AddHit(thisPHit->trackID, thisPHit);
128  }
129  }
130  }
131  }
132 
133  _pTree->SortHits([](GGSTPartHit *h1, GGSTPartHit *h2) -> bool { return h1->time < h2->time; });
134 }
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.
#define GGSENDL
Definition: GGSSmartLog.h:131
GGSTPartHitBase * GetPartHit(unsigned int iHit)
Get the specified particle hit.
Definition: GGSTHits.cpp:182
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.