/// @file allpix.cc /// @brief Executable for the Allpix pixel detector simulation code. // Standard include statements. #include #include using namespace std; // GEANT4 include statements. #include "G4RunManager.hh" #include "G4UImanager.hh" #include "G4UIterminal.hh" #include "G4UItcsh.hh" #include "G4ios.hh" #ifdef G4VIS_USE #include "G4VisExecutive.hh" #endif // Allpix include statements. #include "AllPixPhysicsList.hh" #include "AllPixDetectorConstruction.hh" #include "AllPixPostDetConstruction.hh" #include "AllPixSteppingVerbose.hh" #include "AllPixRunAction.hh" #include "AllPixPrimaryGeneratorAction.hh" #include "AllPixEventAction.hh" #include "AllPixRun.hh" #include "Randomize.hh" /* #if defined(G4UI_USE_TCSH) #include "G4UIterminal.hh" #include "G4UItcsh.hh" #elif defined(G4UI_USE_XM) #include "G4UIXm.hh" #elif defined(G4UI_USE_WIN32) #include "G4UIWin32.hh" #elif defined(G4UI_USE_QT) #include "G4UIQt.hh" #include "G4Qt.hh" #else #include "G4UIterminal.hh" #endif */ // ROOT include statements. #include "TH1F.h" //#include "G4Qt.hh" //#include "G4UIQt.hh" // Input parameters // indexes for argv[] typedef enum { _MACRO = 1, _XML = 2, _OUTPUTDIR = 3, _DATASETID = 4, _EPF = 5, _FPF = 6, _RUN_BATCH // Run in batch mode in this case. } inputPars; // Forward declarations. void checkflags(int,char**); void SplashWindow(); // ROOT include statements. #include "TMatrix.h" #include "TRotMatrix.h" // Detector geometry include statements. #include "ReadGeoDescription.hh" /// @brief The allpix executable main function. /// /// @author John Idarraga (idarraga@cern.ch) /// @author Mathieu Benoit (benoit@lal.in2p3.fr) /// /// AllPix Geant4 /// Generic Geant4 implementation for pixel detectors /// Laboratoire de l'Accélérateur Linéaire Université Paris-Sud 11 /// int main(int argc, char** argv) { // Flags checkflags(argc, argv); G4String fileName = argv[_MACRO]; G4String xmlFileName = argv[_XML]; // Seed the random number generator manually time_t rawtime; time(&rawtime); G4long myseed = G4long(rawtime); // Output the program details. SplashWindow(); // Get the number of events to store to the ntuple per frame. G4int events_per_frame = atoi(argv[_EPF]); G4int frames_per_file = atoi(argv[_FPF]); // Display the input arguments. G4cout << "* Allpix: Input arguments " << G4endl << "*-------------------------" << G4endl << "*--> macro: '" << argv[_MACRO] << "'" << G4endl << "*--> detector XML: '" << argv[_XML] << "'" << G4endl << "*--> output path: '" << argv[_OUTPUTDIR] << "'" << G4endl << "*--> dataset ID: '" << argv[_DATASETID] << "'" << G4endl << "*--> ev/frame: " << events_per_frame << G4endl << "*--> frames/file: " << frames_per_file << G4endl << "*" << G4endl; // Display the random seed value. G4cout << "*" << G4endl << "* INFO: The random seed (based on localtime): " << myseed << G4endl; // Instantiate the user verbose output object. G4VSteppingVerbose* verbosity = new AllPixSteppingVerbose; G4VSteppingVerbose::SetInstance(verbosity); // Instantiate the run manager. G4RunManager* runManager = new G4RunManager; // Instantiate the detector construction. AllPixDetectorConstruction * detector = new AllPixDetectorConstruction(xmlFileName); // Set up the detector (via user initialisation). runManager->SetUserInitialization(detector); // Instantiate the physics list object. G4VUserPhysicsList * physics = new AllPixPhysicsList; runManager->SetUserInitialization(physics); // Hits ! --> Ntuple to store hits // creates AllPixRun to analyze hits at the end of event // TODO: Alter the constructor and the executable to take // arguments that allow the output directory to be entered from // the command line. // The detector settings should be read from the macro...??? // TW - these are now set from the command line. // TString dataset = "allPix"; // TString tempdir = ""; // Create a new run action instance, to run the simulation. AllPixRunAction * run_action = new AllPixRunAction( detector, argv[_DATASETID], //dataset, argv[_OUTPUTDIR], //tempdir, events_per_frame, frames_per_file, "lciobridge_allpix.txt", "lciobridge_allpix_dut.txt"); runManager->SetUserAction(run_action); // Set the source // Particle gun SourceType st = _GeneralParticleSource; //SourceType st = _HEPEvtInterface; // Instantiate the primary generator object. G4VUserPrimaryGeneratorAction * gen_action = new AllPixPrimaryGeneratorAction(st); runManager->SetUserAction(gen_action); // Digits ! --> calls Digitize, and makes ntuple to store digits AllPixEventAction * event_action = new AllPixEventAction(run_action); runManager->SetUserAction(event_action); // Initialize G4 kernel // // ATTENTION ! runManager->Initialize() calls AllPixDetectorConstruction::Construct() // but the macro has not been read and the position of the Medipixes is decided in the macro. // This automatic call won't have any effect. It only build devices when the use calls // /allpix/det/update from the macro. AllPixDetectorConstruction::Construct() is called from // AllPixDetectorConstruction::UpdateGeometry() //runManager->Initialize(); // now done through the DetectorConstructor Messenger via the macro // Set digitizers. I need to do it after // DetectorConstruction::Construct() is called // event_action->SetupDigitizers(); //event_action->SetDetectorDigitInput(8.*keV); // thl !!! CLHEP::HepRandom::setTheSeed(myseed); //G4cout << *(G4Material::GetMaterialTable()) << G4endl; // Visualisation //--------------- #ifdef G4VIS_USE // Initialize the visualization. G4VisManager* visManager = new G4VisExecutive; visManager->Initialize(); #endif // User interface //---------------- // Get the pointer to the User Interface manager. G4UImanager* UI = G4UImanager::GetUIpointer(); G4String command = "/control/execute "; // Determine if the program is in batch mode. //if (atoi(argv[6]) == -1) { if (argc-1 == _RUN_BATCH) { // Create the command to execute the simulation based on the input. G4String command = "/control/execute "; G4String fileName = argv[_MACRO]; // Run the simulation. UI->ApplyCommand(command+fileName); } else { // Run an interactive session with the User Interface (UI). G4UIsession * session = 0; /* #if defined(G4UI_USE_TCSH) session = new G4UIterminal(new G4UItcsh); #elif defined(G4UI_USE_XM) session = new G4UIXm(argc,argv); UI->ApplyCommand("/control/execute visTutor/gui.mac"); #elif defined(G4UI_USE_WIN32) session = new G4UIWin32(); UI->ApplyCommand("/control/execute visTutor/gui.mac"); #elif defined(G4UI_USE_QT) session = new G4UIQt(argc,argv); UI->ApplyCommand("/control/execute visTutor/gui.mac"); #else session = new G4UIterminal(); #endif #ifdef G4VIS_USE UI->ApplyCommand(command+fileName); //AllPixPostDetConstruction::GetInstance()->WriteTracks("tracks_G4.root"); #endif */ //session = new G4UIQt(argc,argv); //session = new G4UIXm(argc, argv); session = new G4UIterminal(); UI->ApplyCommand(command+fileName); //UI->ApplyCommand("/control/execute visTutor/gui.mac"); // Start the interactive session. session->SessionStart(); // Tidy up. delete session; }//end of batch session check. #ifdef G4VIS_USE delete visManager; #endif // The geometry description. extern ReadGeoDescription * g_GeoDsc; // already loaded ! :) map * geoMap = g_GeoDsc->GetDetectorsMap(); map::iterator detItr; // Frames ntuple closing // G4int nDigitizers = event_action->GetNumberOfDigitizers(); // TW - 2013-12-01 - turned off hits ntuple writing for now... // // hits ntuple closing // G4int nHC = event_action->GetNumberOfHC(); // for(G4int i = 0 ; i < nHC ; i++) { // Hits_WriteToNtuple::GetInstance("", "", "", nHC, i)->closeNtuple(); // } G4cout << "* INFO" << G4endl << "* INFO: Allpix simulation complete!" << G4endl << "* INFO" << G4endl; // Tidy up. delete runManager; delete verbosity; return 0; }// end of main function. /// @brief Check the input arguments. void checkflags(int argc, char** argv) { if (argc < 7) { G4cout << "* ERROR: usage should be" << G4endl << "* $ " << argv[0] << " " << "[macro] " << "[detector XML file] " << "[outputdir] " << "[datasetid] " << "[events-per-frame] " << "[frames-per-file] " << "{-1 (for batch running)}" << G4endl; exit(1); } } //end of checkflags function. /// @brief Output the Allpix authors and details. void SplashWindow() { G4cout << "*************************************************************" << G4endl; G4cout << " AllPix Geant4 (LAL Orsay)" << G4endl; G4cout << " Generic Geant4 implementation for pixel detectors" << G4endl; G4cout << " " << G4endl; G4cout << " John Idarraga " << G4endl; G4cout << " Mathieu Benoit " << G4endl; G4cout << "*************************************************************" << G4endl; G4cout << G4endl; }