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

Last change on this file since 10 was 10, checked in by campagne, 19 years ago

import first modified version of JHF2km for MEMPHYS

File size: 4.1 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/ISession.h>
15#include <Lib/Manager.h>
16#include <Lib/System.h>
17//#include <Lib/Debug.h>
18
19// G4Lab :
20#include <G4Lab/UIOnX.h>
21#include <G4Lab/TrackingAction.h>
22
23//MEMPHYS:
24#include "MEMPHYS/MEMPHYSAnalysis.hh"
25#include "MEMPHYS/MEMPHYSDetectorConstruction.hh"
26#include "MEMPHYS/MEMPHYSPhysicsList.hh"
27#include "MEMPHYS/MEMPHYSPhysicsMessenger.hh"
28#include "MEMPHYS/MEMPHYSPrimaryGeneratorAction.hh"
29#include "MEMPHYS/MEMPHYSEventAction.hh"
30#include "MEMPHYS/MEMPHYSRunAction.hh"
31#include "MEMPHYS/MEMPHYSStackingAction.hh"
32#include "MEMPHYS/MEMPHYSTrackingAction.hh"
33
34
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 (MEMPHYSAnalysisManager*)this;
46    } else if(aTo=="MEMPHYSIAnalysis") {
47      return (MEMPHYSIAnalysis*)this;
48    } else if(aTo=="MEMPHYSAnalysis") {
49      return (MEMPHYSAnalysis*)this;
50    } else if(aTo=="IManager") {
51      return (IManager*)this;
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  // Declare actions that needs some UI or analysis facilities :
84  ISession* onxSession = session->session();
85  if(onxSession) {
86    // Get theg AIDA Lab implementation :
87    AIDA::IAnalysisFactory* aida = 
88      Lib_findManager(*onxSession,"AnalysisFactory",AIDA::IAnalysisFactory);
89    if(!aida) {
90      std::cout << "MEMPHYS_session :"
91                << " AnalysisFactory not found." << std::endl;
92    } else {
93      analysisManager = new MEMPHYSAnalysisManager(*aida,false);
94      onxSession->addManager(analysisManager);
95    }
96  }
97
98  G4UImanager* UI = G4UImanager::GetUIpointer();
99  if (UI) {
100    std::string file = 
101      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/jobOptions.mac";
102    UI->ApplyCommand("/control/execute "+file); 
103  }
104
105 
106  //JEC 18/11/05 give the "analysis" to fill geometry ITuple
107  MEMPHYSDetectorConstruction* MEMPHYSdetector = 
108    new MEMPHYSDetectorConstruction(*analysisManager); 
109
110  runManager->SetUserInitialization(MEMPHYSdetector);
111
112  runManager->SetUserInitialization(new MEMPHYSPhysicsList);
113
114  // Set user action classes
115  MEMPHYSPrimaryGeneratorAction* myGeneratorAction = new MEMPHYSPrimaryGeneratorAction(MEMPHYSdetector);
116  runManager->SetUserAction(myGeneratorAction);
117
118  MEMPHYSRunAction* myRunAction = new MEMPHYSRunAction();
119
120  runManager->SetUserAction(myRunAction);
121
122
123  runManager->SetUserAction(new MEMPHYSEventAction(*analysisManager,
124                                                   myRunAction, 
125                                                   MEMPHYSdetector,
126                                                   myGeneratorAction));
127  runManager->SetUserAction(new MEMPHYSTrackingAction);
128
129  runManager->SetUserAction(new MEMPHYSStackingAction);
130
131
132  // Initialize G4 kernel
133  runManager->Initialize();
134
135  if (UI) {
136    std::string file = 
137      Lib::System::getenv("MEMPHYSROOT")+"/scripts/Geant4/init.g4m";
138    UI->ApplyCommand("/control/execute "+file); 
139  }
140
141  // Main UI loop :
142  session->SessionStart();
143
144  delete session; //It will delete the analysisManager.
145
146  delete runManager;
147
148  return 0;
149}
150
Note: See TracBrowser for help on using the repository browser.