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

Last change on this file since 68 was 68, checked in by campagne, 18 years ago

Introduction of the MEMPHYS namespace

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