// fill GEANT ROOT tree and open new file if necessary // // called from gudigi.F // // last modified on 14/10/99 by R.Holzmann #include "filltree.h" #include "hgeantmedia.h" #include "hgeantmaxtrk.h" #include using namespace std; void opennewfile(void); struct EVT_DEF { // structure mapped to EVENTBUF Fortran COMMON block Int_t abort1; Int_t stop1; Int_t nlept1; Int_t eventid1; Float_t ebeam1; Float_t bpar1; Float_t phi_event1; Int_t npart1; Int_t nloop1; Int_t nmaxloop1; Int_t nogamma1; Int_t eventnr1; Int_t nReqEvts1; Int_t nAccEvts1; Int_t itype1[MAXTRKKINE]; Float_t vtx1 [MAXTRKKINE][3]; Float_t pmom1 [MAXTRKKINE][3]; Float_t ubuf1 [MAXTRKKINE][5]; Float_t tof1 [MAXTRKKINE]; }; #define EVENTBUF COMMON_BLOCK(EVENTBUF,eventbuf) COMMON_BLOCK_DEF(EVT_DEF,EVENTBUF); void filltree() { // printf("\n Filling Geant ROOT HTree\n"); if(EVENTBUF.nmaxloop1 > 0 && ( EVENTBUF.stop1 == 0 && EVENTBUF.nloop1 != 0)){ return; // conversion case: not all wanted particles in acceptance // do another loop of the same event. do not fill output // if the last repeating loop did not succed, take the event anyway // to keep the number of events (needed for match event vertex) } HTree* pHGeantTree = gHades->getTree(); pHGeantTree->Fill(); TFile* pHGeantFile = gHades->getOutputFile(); if(pHGeantFile->GetBytesWritten() > MAXFILESIZE) { printf("\n Maximum allowed file size exceeded\n"); opennewfile(); } } FCALLSCSUB0(filltree,FILLTREE,filltree) PROTOCCALLSFSUB2(KUPATL,kupatl,PSTRING,PINT) #define KUPATL(COMMAND,NARG) CCALLSFSUB2(KUPATL,kupatl,PSTRING,PINT,COMMAND,NARG) PROTOCCALLSFSUB2(KUGETC,kugetc,PSTRING,PINT) #define KUGETC(NAME,NLEN) CCALLSFSUB2(KUGETC,kugetc,PSTRING,PINT,NAME,NLEN) // MEDIA Common Block #define NMAXCHAR 200 #define MEDMAXNO 100 struct MEDIA_DEF { int ndefmedia; char mediumname[MEDMAXNO][NMAXCHAR]; int mediumindex[MEDMAXNO]; }; #define GEAMEDIA COMMON_BLOCK(GEAMEDIA,geamedia) COMMON_BLOCK_DEF(MEDIA_DEF,GEAMEDIA); void opennewfile(void) { // close ROOT file and open new one delete gHades; // throw away Hades object ... gHades = new Hades(); // ... and make new on HRecEvent* pHGeantEvent = new HRecEvent(); // create a new event gHades->setEvent(pHGeantEvent); pHGeantEvent->addPartialEvent(catSimul,"Simul","Simulated event"); char cstring[100]; int narg; if(batch<2) { // we are in interactive mode KUPATL(cstring,narg); // get HGeant command string and nb of arguments if(strcmp(cstring,"CLOSEFILE") == 0) { // close file SETITUP(0); // set itup to 0 (no file open) UHBOOK(); // call Fortran routine uhbook once more return; } if(strcmp(cstring,"NEWFILE") == 0) { // called as HGeant command NEWFILE char newName[100]; int len; KUGETC(newName,len); // get new file name and put into gRootFileName newName[len+1]='\0'; TString s=newName; s.ToLower(); s.Strip(s.kBoth); if (s.Length()>0) { gRootFileName = s; gRootFileNumber = 0; } SETITUP(1); } } gRootFileNumber++; // increment file counter for file name TString newFileName = gRootFileName; newFileName += gRootFileNumber; // insert file number into name newFileName += ".root"; gHades->setOutputFile((char*)newFileName.Data(),"RECREATE","HGeant data",2); // open file // write the media to the file // (same as in hgeahropen.cc for the first output file) HGeantMedia media("GeantMedia","List of Geant media"); for (Int_t k=0;k