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