//------------------------------------------------------------------------- /*! \file Main.cc \brief Main entry point for the P. Auger Detector Simulation Program \author Sylvie Dagoret-Campagne \date June 2001 (last update) \ingroup APPLICATION */ //------------------------------------------------------------------------- #include #include "TFile.h" #include #include #include "Main.h" #include "utilities.h" // contains input params libs #include "EVTSim_ROOT.h"// event definition #include "SDSim.h" // simulation of surface array #include "ObsAuger_ROOT.h" // defines the site observatory #include "Shower_ROOT.h"//defines the shower #include "Parameters.h" // The parameters obtained from the input config file #include "Globals.h" #include #include #include #include "unixsignals.h" // global variables defined in Main : // ----------------------------------------------------------------------- Params parameters; // contains selected input parameters (sample type) TROOT root("Main","PAO Simulation Program");// ROOT workspace Shower_ROOT* shower; // the shower ObsAuger_ROOT* observatory; // the surface array Parameters* P; // the parameters (FDSim type) TFile* inrootfile,*outrootfile; string inrootfilename; string outrootfilename; const int NBGEN=5; TRandom r[NBGEN]; // array of random generators //------------------------------------------------------------------------- static TTree* ineventtree; // pointers for event tree at input static TBranch* ineventbranch; static TTree* outeventtree;// pointers for event tree at output static TBranch* outeventbranch; //------------------------------------------------------------------------- //extern double UToC_E0, UToC_N0, UToC_alpha, UToC_beta, UToC_gamma; // are erased somewhere ?? //extern UToC_Coeff coeffs; //------------------------------------------------------------------------- extern struct unixsigflags flags; // int main(int argc,char **argv) { // init_unix_signals(); clock_t starttime,stoptime,difftime; time_t starttime2,stoptime2,difftime2,currtime; time(&currtime); cout << " START P. AUGER OBSERVATORY SIMULATION AT DATE " << ctime(&currtime) << endl; Parser parser(argc,argv); if(P!=NULL) { if(P->DEBUG_LEVEL()>=1) P->Output(cout); } else { cerr << " !!! Parameters not initialize !!! " << endl; exit(1); } Initializ initializer; if(!initializer.initAll()) // init Root, the shower and the observatory exit(1); SDSim* sdsim; //pointer one of the SDSim classes if(P->SD_SIM()) { // select here the simulation type dynamically sdsim= new SDSim; if(P->DEBUG_LEVEL()>=1) cout << " Simulation of Surface array selected " << endl; } if(P->FD_SIM()) { if(P->DEBUG_LEVEL()>=1) cout << " Simulation of Flurescence detector selected " << endl; } // loop on the events Event_ROOT* event; Event_ROOT* inevent; outrootfile= new TFile(outrootfilename.c_str(),"RECREATE"); bool nextevent; unsigned int numevent=0; unsigned int nbentriesintree; unsigned int nbeventtot=0; unsigned int nbeventreq=P->N_EVENT(); if(P->GB_READEVENT()) { nbentriesintree=(int)ineventtree->GetEntries(); if(nbeventreq==0) nbeventtot=nbentriesintree; else nbeventtot=nbeventreq; } else { nbeventtot= nbeventreq; } if(nbeventtot >0) nextevent=true; //Now start the Main Loop of Events while(nextevent && (!flags.inter)) { numevent++; event= new Event_ROOT(numevent); if(numevent>=nbeventtot) nextevent=false; if(P->GB_READEVENT()) // read the event in the tree { inevent=new Event_ROOT; inrootfile->cd(); // select the root file for input ineventbranch->SetAddress(&inevent); ineventtree->GetEvent(numevent-1); *event=*inevent; event->updateread(); //clean fields in event according required processing cout << " \t read event ::" << numevent<< " , "<< nbeventtot<< endl; cout << " \t ---------------- " << endl; } else if(P->GB_READSHOWER() && !P->GB_READEVENT()) // generate the event { // event->eventHeader()->generate(P->NORTH_MIN(),P->EAST_MIN(),P->D_NORTH(),P->D_EAST()); double theta=shower->GetHeader()->GetPrimaryZenAng(); double phi=shower->GetHeader()->GetPrimaryAzAng(); double energy=shower->GetHeader()->GetPrimaryEnGev(); int primary=shower->GetHeader()->GetPrimaryType(); // set main shower property event->eventHeader()->setEnergy(energy); event->eventHeader()->setPrimary(primary); // set the geometry event->eventHeader()->computeCosDir(theta,phi); // get the random impact point event->eventHeader()->generate(); cout << " \t SDSim Event # " <SD_SIM()) { sdsim->process(event); } if(P->FD_SIM()) { } stoptime=clock(); time(&stoptime2); difftime=stoptime-starttime; difftime2=stoptime2-starttime2; outeventbranch->SetAddress(&event); cout << "+.+.+.+. New event " << numevent << " +.+.+.+ " << endl; cout << *event; cout << " CPU time(sec) for simulation : " << difftime/CLOCKS_PER_SEC << endl; cout << " User time for simulation : " << ctime(&difftime2) << endl; event->updatewrite(); // outrootfile->cd(); outeventtree->Fill(); //cout << " ==> Backup the Tree : for event " << numevent << endl; if(numevent==1) { if(P->SD_DEBUGLEVEL()>=1) cout << " -- Back up the observatory before the first event output " << endl; if(P->GB_WRITEOBSERVATORY()) observatory->Write(); } /* if(P->GB_WRITEEVENT()) { outeventtree->Write(); if(P->SD_DEBUGLEVEL()>=0) cout << " event " << numevent << " saved in file !!! " << endl; } */ if(P->SD_DEBUGLEVEL()>=1) { outrootfile->Map(); outrootfile->ls(); } inrootfile->cd(); if(P->SD_DEBUGLEVEL()>=0) cout << " *************************************************************" << endl; delete event; } // exit of the event loop if(P->SD_DEBUGLEVEL()>=2) outeventtree->Print(); outrootfile->cd(); //select the output file if(P->GB_WRITEEVENT()) outeventtree->Write(); //outrootfile->cd(); //select the output file // if(P->GB_WRITEOBSERVATORY()) // observatory->Write(); outrootfile->cd(); //select the output file if(P->GB_WRITESHOWER()) shower->Write("Header_ROOT"); if(P->SD_DEBUGLEVEL()>=1) cout << "$$$$$$$$$$$$$$$$$$$$ END OF SIMULATION $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" << endl; if(P->SD_DEBUGLEVEL()>=2) { cout << " ROOT info on output file " << endl; outrootfile->Print(); outrootfile->Map(); outrootfile->ls(); } outrootfile->Write(); outrootfile->Close(); } //------------------------------------------------------------------------- //------------------------------------------------------------------------- Parser::Parser(int argc, char** argv) { argc_=argc; argv_=argv; // check the argument string configFile; // input file name string inputdataFile; string outputdataFile; // Get the input filename and check if the file exists if (argc_ < 2) { cerr << " +++ Not enough parameters parameters "<< endl; usage(); exit(1); } else if(argc_==2) { configFile = parameterfile; inrootfilename=argv[1]; outrootfilename=outputrootfile; } else if(argc_==3) { configFile = parameterfile; inrootfilename=argv[1]; outrootfilename=argv[2]; } else if(argc_==4) { inrootfilename=argv[1]; outrootfilename=argv[2]; configFile = argv[3]; } else { cerr << " +++ Too many parameters "<< endl; usage(); exit(1); } if(inrootfilename==outrootfilename) { cerr << " !!! error same input-root-file and output-root-file !!! " << endl; exit(1); } cout << " **************************************************" << endl; cout << " * \t input root file : " << inrootfilename << endl; cout << " * \t output root file : " << outrootfilename << endl; cout << " * \t configuration file : " << configFile << endl; cout << " **************************************************" << endl; // now check if the files exists struct stat buf; if(stat(inrootfilename.c_str(),&buf)) { cerr << " Not existing File " << inrootfilename << endl; exit(1); } if(stat(configFile.c_str(),&buf)) { cerr << " Not existing File " << configFile << endl; exit(1); } ifstream Input (string_new_cstring(configFile), ios::in|ios::nocreate); if (!Input) { cout << "FATAL ERROR: cannot open file " << configFile << ".\n"; P=NULL; exit(1); } else { P = new Parameters (string_new_cstring(configFile)); } } //------------------------------------------------------------------------- //------------------------------------------------------------------------- Parser::~Parser() { if(P!=NULL) delete P; } //------------------------------------------------------------------------- //------------------------------------------------------------------------- void Parser::usage() const { cerr << " --------------------------------------------------------------" << endl; cerr << " +++ usage : " << argv_[0] << " inputrootfile [outputrootfile] [configfile]" << endl; cerr << " - with the 'inputrootfile' being the name of the root filecontaining the shower at input " <GB_READSHOWER()) { TObject* p=NULL; if((p=(Shower_ROOT*)inrootfile->Get("Header_ROOT"))!=NULL) { cout << " Shower_ROOT object found in input file " << endl; shower=new Shower_ROOT(string_new_cstring(inrootfilename)); shower->showerGrnd()->QuickLook(); } else { cerr << " !!!! Shower_ROOT object NOT found in input file !!!"<< endl; exit(1); } } if(P->GB_READOBSERVATORY()) { if((observatory=(ObsAuger_ROOT*)inrootfile->Get("ObsAuger_ROOT"))!=NULL) { cout << " ObsAuger_ROOT object found in input file " << endl; } else { cerr << " !!!! Observatory_ROOT object NOT found in input file !!!"<< endl; exit(1); } } Event_ROOT* event= new Event_ROOT; // dummy event adress ineventtree=NULL; ineventbranch=NULL; // check if event tree exist at input if(P->GB_READEVENT()) { if((ineventtree=(TTree*)inrootfile->Get("TreeEvent"))!=NULL) { cout << " Event Tree object found in input file " << endl; ineventbranch= ineventtree->GetBranch("event"); if(ineventbranch!=NULL) { /* int tot=(int)ineventtree->GetEntries(); for(int i=0; i< tot; i++) { ineventbranch->SetAddress(&event); ineventtree->GetEvent(i); cout << *event; } */ ; } else { cerr <<"!!! event Branch of Event Tree object found !!! " << endl; exit(1); } } else { cerr << " !!!! Event Tree object NOT found in input file !!!" << endl; exit(1); } } else { ineventtree=NULL; ineventbranch=NULL; } // now create the event tree for output int bufsize=1000000; int split=0; outeventtree=new TTree("TreeEvent"," Tree for Event_ROOT objects"); outeventtree->SetAutoSave(10000); outeventbranch= outeventtree->Branch("event","Event_ROOT",&event,bufsize,split); delete event; return true; } //------------------------------------------------------------------------- //------------------------------------------------------------------------- bool Initializ::initShower() { if(P->GB_READSHOWER()) { ShowerProperties* properties= new ShowerProperties; theta_=shower->GetHeader()->GetPrimaryZenAng(); phi_=shower->GetHeader()->GetPrimaryAzAng(); properties->computeCosDir(theta_,phi_); shower->setshowerProps(properties); } return true; } //------------------------------------------------------------------------- //------------------------------------------------------------------------- bool Initializ::initObservatory() { if(!P->GB_READOBSERVATORY()) { observatory=new ObsAuger_ROOT; if(P->SD_FARRAY()) observatory->surfaceArray()->buildArray(P->N_STAT_ARRAY(),P->NORTH_MIN_ARRAY(),P->EAST_MIN_ARRAY()); else if(P->SD_EARRAY()) // new description of EA surface array observatory->surfaceArray()->buildArray("eastations.txt"); else if(P->SD_SHOWERARRAY()) { cout << " Build the array for theta = " << theta_ << " phi = " << phi_ << endl; } else { cerr << " Initializ::initObservatory : No valid observatory selection : " << endl; cerr << " \t SD_FARRAY flag = " << P->SD_FARRAY() << endl; cerr << " \t SD_EARRAY flag = " << P->SD_EARRAY() << endl; cerr << " \t SD_SHOWERARRAY flag = " << P->SD_SHOWERARRAY() << endl; return false; } } if(P->DEBUG_LEVEL()>=1) cout << *observatory << endl; return true; } //------------------------------------------------------------------------- //------------------------------------------------------------------------- bool Initializ::initGeometry() { ComputeCoeff_UTMtoCart(UTM_ELLIPSE_NUM, LATITUDE_CENTER,LONGITUDE_CENTER,ALTITUDE_AUGER,SD_EAST_SIZE,SD_NORTH_SIZE); return true; } //------------------------------------------------------------------------- //------------------------------------------------------------------------- bool Initializ::initAll() { // random number generators if(P->SD_RANDOMSEED()) for(int i=0; i