source: MEMPHYS/HEAD/applications/MEMPHYS_session.cxx @ 57

Last change on this file since 57 was 57, checked in by barrand, 19 years ago

G.Barrand : handle digits in visualization

File size: 4.2 KB
Line 
1
2// Geant4:
3#include "G4ios.hh"
4#include "G4RunManager.hh"
5#include "G4UImanager.hh"
6
7//AIDA :
8#include <AIDA/IAnalysisFactory.h>
9
10// std::
11#include <iostream>
12
13// Lib :
14#include <Lib/Interfaces/IManager.h>
15#include <Lib/System.h>
16#include <Lib/Cast.h>
17
18// G4Lab :
19#include <G4Lab/UIOnX.h>
20#include <G4Lab/TrackingAction.h>
21#include <G4Lab/Helpers.h>
22#include <G4Lab/DigitsCollectionType.h>
23
24//MEMPHYS:
25#include "MEMPHYS/MEMPHYSAnalysis.hh"
26#include "MEMPHYS/MEMPHYSDetectorConstruction.hh"
27#include "MEMPHYS/MEMPHYSPhysicsList.hh"
28#include "MEMPHYS/MEMPHYSPhysicsMessenger.hh"
29#include "MEMPHYS/MEMPHYSPrimaryGeneratorAction.hh"
30#include "MEMPHYS/MEMPHYSEventAction.hh"
31#include "MEMPHYS/MEMPHYSRunAction.hh"
32#include "MEMPHYS/MEMPHYSStackingAction.hh"
33#include "MEMPHYS/MEMPHYSTrackingAction.hh"
34#include "MEMPHYS/MEMPHYSWCDigi.hh"
35
36// Create a manager to access the MEMPHYSAnalysis from the callbacks :
37
38class MEMPHYSAnalysisManager 
39  :public virtual IManager
40  ,public MEMPHYSAnalysis  {
41 public: //IManager
42  virtual const std::string& name() const { return fName;}
43  virtual void* cast(const std::string& aTo) const {
44    if(aTo=="MEMPHYSAnalysisManager") {
45      return Lib_SCast(MEMPHYSAnalysisManager);
46    } else if(aTo=="MEMPHYSIAnalysis") {
47      return Lib_SCast(MEMPHYSIAnalysis);
48    } else if(aTo=="MEMPHYSAnalysis") {
49      return Lib_SCast(MEMPHYSAnalysis);
50    } else if(aTo=="IManager") {
51      return Lib_SCast(IManager);
52    } else {
53      return 0;
54    }
55  }
56 public:
57  MEMPHYSAnalysisManager(AIDA::IAnalysisFactory& aAIDA,bool aBatch)
58    :MEMPHYSAnalysis(aAIDA,aBatch),fName("MEMPHYSAnalysisManager") {}
59  virtual ~MEMPHYSAnalysisManager(){}
60 private:
61  std::string fName;
62};
63
64
65//////////////////////////////////////////////////////////////////////////////
66int main(
67         int aArgc
68         ,char** aArgv
69         ) 
70//////////////////////////////////////////////////////////////////////////////
71//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
72{
73  //Lib::Debug::checkByClass(true);
74
75  G4RunManager* runManager = new G4RunManager;
76
77  // Need to pass the G4RunManager at UIOnX creation
78  std::string gui = "$MEMPHYSROOT/scripts/OnX/MEMPHYS_session.onx";
79  G4Lab::UIOnX* session = new G4Lab::UIOnX(*runManager,gui,aArgc,aArgv);
80
81  MEMPHYSAnalysisManager* analysisManager = 0;
82
83  AIDA::IAnalysisFactory* aida = G4Lab::UIOnX_aida(*session);
84  if(!aida) {
85    std::cout << "MEMPHYS_session : AIDA not found." << std::endl;
86  } else {
87    analysisManager = new MEMPHYSAnalysisManager(*aida,false);
88    session->addManager(analysisManager);
89  }
90  if(session->session()) {
91    //GB 07/12/2005 : declare DigitsCollections types.
92    //FIXME : Why can't we be generic as for hits collection ?
93    //FIXME : From G4VDigiCollection, we can't loop on G4VDigi !
94    session->addType
95      (new G4Lab::DigitsCollectionType<MEMPHYSWCDigi>
96        (*(session->session()),"WCDigitizedCollection"));
97  }
98
99  G4UImanager* UI = G4UImanager::GetUIpointer();
100  if (UI) {
101    std::string file = 
102      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/jobOptions.mac";
103    UI->ApplyCommand("/control/execute "+file); 
104  }
105
106 
107  //JEC 18/11/05 give the "analysis" to fill geometry ITuple
108  MEMPHYSDetectorConstruction* MEMPHYSdetector = 
109    new MEMPHYSDetectorConstruction(*analysisManager); 
110
111  runManager->SetUserInitialization(MEMPHYSdetector);
112
113  runManager->SetUserInitialization(new MEMPHYSPhysicsList);
114
115  // Set user action classes
116  MEMPHYSPrimaryGeneratorAction* myGeneratorAction = 
117    new MEMPHYSPrimaryGeneratorAction(MEMPHYSdetector);
118  runManager->SetUserAction(myGeneratorAction);
119
120  MEMPHYSRunAction* myRunAction = new MEMPHYSRunAction();
121
122  runManager->SetUserAction(myRunAction);
123
124
125  runManager->SetUserAction(new MEMPHYSEventAction(*analysisManager,
126                                                   myRunAction, 
127                                                   MEMPHYSdetector,
128                                                   myGeneratorAction));
129  runManager->SetUserAction(new MEMPHYSTrackingAction);
130
131  runManager->SetUserAction(new MEMPHYSStackingAction);
132
133
134  // Initialize G4 kernel
135  runManager->Initialize();
136
137  if (UI) {
138    std::string file = 
139      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/init.g4m";
140    UI->ApplyCommand("/control/execute "+file); 
141  }
142
143
144  // Main UI loop :
145  session->SessionStart();
146
147  delete session; //It will delete the analysisManager.
148
149  delete runManager;
150
151  return 0;
152}
153
Note: See TracBrowser for help on using the repository browser.