/*************************************************************************** * Author : Tiago Perez * * II Physikalisches Institut * * Universitaet Giessen * * * * Project: HYDRA Event Hypothesys (HADES) * * Description: * * * * Modified : * * 2005.02.11 T. Perez Created * * 8.8.2004 Ingo (command line interface) * * * ***************************************************************************/ #define USEORA 1 #include "fillHypDstApr07.h" #include "hhypreconstructor.h" #include "hparasciifileio.h" #include #include "hpidtrackcleaner.h" // here you have to include all algorythms you want to use #include "hhypAllFillerAlg.h" #include "hhypAllProjector.h" #include "hhypXKine.h" #include "hhypRemoveAllButBest.h" #define MAXARGS 200 #define MAXLINELEN 200 using namespace std; char binary_file[MAXLINELEN]; FILE *schedule_fp; static const int MAX_FILES = 10000; TString paramFile1; TString paramFile2; TString inFile; TString inDir; TString outDir; TString outDirNtup; TString hypNtFile; TString standardHypOption; Int_t nEvents; Int_t startEvt; Int_t hypLevel; Bool_t simflag; Bool_t substitutehypflag; TFile * hfile; Int_t nRunId; Int_t qaLevel; void EmptyFunction(HHypList *mylist,TLorentzVector *beam) { } void add_hyp(HHypReconstructor * hyp) { // event hypothesis tasks hfile = new TFile(hypNtFile,"RECREATE","HYP ntuple"); cout << "======== HypLevel: " <1000 maybe for differt beamtimes Int_t beam_pid=14, target_pid=14;// PIDs for Beam and Target TVector3 mymom( 0, 0, 2994.73);// ideal beam in MeV // TVector3 mymom(-5.011, 6.559, 2994.717);// real(?) beam in MeV // TLorentzVector * beam = new TLorentzVector(0,0,1976.91,3126.54); // beam + target !!!!!!!!!! Double_t ta, pr;// Masses ta=HPhysicsConstants::mass(target_pid); pr=HPhysicsConstants::mass(beam_pid); TLorentzVector * beam = new TLorentzVector(mymom,ta+TMath::Sqrt(mymom.Mag2()+pr*pr)); hyp->SetBeam(beam); hyp->SetBeamPID(beam_pid); hyp->SetTargetPID(target_pid); HypMomErr.setJan04(); cout << "Set Beam and Target for Jan04 pp @ 2.2GeV"<2000 maybe for differt beamtimes Int_t beam_pid=14, target_pid=14;// PIDs for Beam and Target TVector3 mymom( 0, 0, 4337.96);// ideal beam in MeV Double_t ta, pr;// Masses ta=HPhysicsConstants::mass(target_pid); pr=HPhysicsConstants::mass(beam_pid); TLorentzVector * beam = new TLorentzVector(mymom,ta+TMath::Sqrt(mymom.Mag2()+pr*pr)); hyp->SetBeam(beam); hyp->SetBeamPID(beam_pid); hyp->SetTargetPID(target_pid); HypMomErr.setApr07(); cout << "Set Beam and Target for Apr07 pp @ 3.5GeV"<3000 maybe for differt beamtimes Int_t beam_pid=14, target_pid=14;// PIDs for Beam and Target TVector3 mymom( 0, 0, 1976.912);// ideal beam in MeV Double_t ta, pr;// Masses ta=HPhysicsConstants::mass(target_pid); pr=HPhysicsConstants::mass(beam_pid); TLorentzVector * beam = new TLorentzVector(mymom,ta+TMath::Sqrt(mymom.Mag2()+pr*pr)); hyp->SetBeam(beam); hyp->SetBeamPID(beam_pid); hyp->SetTargetPID(target_pid); HypMomErr.setApr06(); cout << "Set Beam and Target for Apr06 pp @ 1.25GeV"<AddAlgorithm("empty",new HHypAllFillerAlg("all Filler",standardHypOption+ ",Reactions=" "(p pi+ pi- ; p )" ),"channelname"); // Project ntuple hyp->AddAlgorithm("channelname",new HHypAllProjector("all projector", "TRIGGER,LORENTZ,DTOF_REFIT"), "ntuple", hfile); // do a kinematic fitting on that reaction hyp->AddAlgorithm("channelname",new HHypXKine("kine refit"), "channelname_KineX",hfile); // Project ntuple hyp->AddAlgorithm("channelname_KineX",new HHypAllProjector("all projector", "TRIGGER,LORENTZ,DTOF_REFIT,MDC_VERTEX"), "ntuple", hfile); // select only best combination hyp->AddAlgorithm("channelname_KineX",new HHypRemoveAllButBest("kine refit"), "channelname_KineX_best"); // Project ntuple hyp->AddAlgorithm("channelname_KineX_best",new HHypAllProjector("all projector", "TRIGGER,LORENTZ,DTOF_REFIT,MDC_VERTEX"), "ntuple", hfile); } if (qaLevel == 2) hyp->AddQA(hfile,"trqa"); else if (qaLevel == 1) hyp->AddQA(hfile); } ////////////////////////////////////////////////////////////////////////// // no need to change something below ////////////////////////////////////////////////////////////////////////// int get_next_file(void) { char * line = NULL; size_t len = 0; ssize_t read; Bool_t loop = kTRUE; while (loop) { if ((read = getline(&line, &len, schedule_fp) == -1)) // EOF return 0; if (strlen(line)>2) { if (*line != '#') { loop = kFALSE; if (strlen(line) > MAXLINELEN) { cout << "error: line too long: " << endl << line << endl; return 0; } strcpy(binary_file,line); if (binary_file[strlen(binary_file)-1] == '\n') binary_file[strlen(binary_file)-1] = 0; } } } return 1; } void GetBaseName(TString & BaseName, TString & FilePath) { ////////////////////////////////////////////////////////////////////////////// TString fp = FilePath; Int_t n1, n2; n1 = 0; while (1) { if ((n2 = fp.Index("/", n1)) == -1) break; n1 = n2 + 1; } BaseName = FilePath; BaseName = BaseName(n1, BaseName.Length() - n1); } int fillHypDst(void) { // real or simulation char *context; if (simflag) context="simulation"; else context="real"; cout << "Context is " << context << endl; TString inputFile;//=inFile+".root"; TString outFile;//=outDir+inFile+"_hyp.root"; cout << "Store HYP-DSTs in: " << outDir << endl; TString pidNtFile;//=outDir+inFile+"_pid_ntup.root"; TString pdfNtFile;//=outDir+inFile+"_pdf_ntup.root"; // hypNtFile=outDirNtup+inFile+"_hyp_ntup.root"; {// create all the filenames TString tmp; cout <<"----- check for "<BaseName(inFile.Data()); tmp.Resize(tmp.Length() - 9); }else if (inFile.EndsWith(".root")) {// end with .root tmp=inFile; tmp.Resize(tmp.Length() - 5); //tmp=BaseName(inFile.Data()); inputFile=tmp+".root"; }else{ // then its a .root file without a ".root" // or a .schedule file without a ".schedule" FileStat_t a; // now we check if files exist if( gSystem->GetPathInfo(inFile+".schedule",a)==0){ cout <<"----- Schedule file -------" << endl; tmp=gSystem->BaseName(inFile.Data()); inFile+=".schedule"; cout <GetPathInfo(inFile+".root",a)==0){ cout <<"----- Root file -------" << endl; tmp=inFile+".root"; tmp.Resize(tmp.Length() - 5); inputFile=tmp+".root"; cout <setTreeBufferSize(8000); cout<< " Setting configuration..." << endl; HSpectrometer* spec = gHades->getSetup(); { cout << "Here is put some \"standard\" HPidTrackCleaner, you should modify this to YOUR needs!"<getTaskSet(context)->add(cleaner); } // now comes the (main) hyp tasks HHypReconstructor * hyp = new HHypReconstructor("name","title","skipempty"); add_hyp(hyp); //Set batch (needed for TCanvas's) gROOT->SetBatch(); //Add input files HRootSource *source=new HRootSource; source->setDirectory((Text_t*)inDir.Data()); if (inFile.EndsWith(".schedule")) { //reads each file from schedule list if ((schedule_fp = fopen((char*)inFile.Data(), "r"))==NULL) { cout << "Binfile::Binfile -> Cannot open " << inFile.Data() << endl; return 1; } while (get_next_file()) { cout << "attaching file " << binary_file<addFile(binary_file); } }else{// root file source->addFile((Text_t*)inputFile.Data()); } gHades->setDataSource(source); if (nRunId) { source->setGlobalRefId(nRunId); source->setRefId(nRunId,nRunId); } //------------ UPDATE these categories to the Tree ------------- if(substitutehypflag){ Cat_t SubstituteHypCat[] = { catHypList, catHypComb, catHypKine }; for(UInt_t j=0;jdisableCategory(SubstituteHypCat[j])<< endl; } //parameter files HRuntimeDb* rtdb=gHades->getRuntimeDb(); if (paramFile1.EndsWith("txt")) { cout << "First Input is TXT "<< (Text_t*)paramFile1.Data() << endl; HParAsciiFileIo *input1=new HParAsciiFileIo; input1->open((Text_t*)paramFile1.Data(),"in"); rtdb->setFirstInput(input1); } #ifdef USEORA #warning "compiled WITH ora" else if (paramFile1.EndsWith("ora")) { HParOraIo *ora=new HParOraIo() ; ora->open(); ora->setHistoryDate("now"); if (!ora->check()) { Error("ora->check","no connection to Oracle \n exiting...!"); exit(EXIT_FAILURE); } rtdb->setFirstInput(ora); } #else #warning "compiled withOUT ora" #endif else { HParRootFileIo *input1=new HParRootFileIo; input1->open((Text_t*)paramFile1.Data(),"READ"); rtdb->setFirstInput(input1); } if (paramFile2.EndsWith("txt")) { cout << "Second Input is TXT" << endl; HParAsciiFileIo *input2=new HParAsciiFileIo; input2->open((Text_t*)paramFile2.Data(),"in"); rtdb->setSecondInput(input2); } #ifdef USEORA else if (paramFile2.EndsWith("ora")) { HParOraIo *ora=new HParOraIo() ; ora->open(); ora->setHistoryDate("now"); if (!ora->check()) { Error("ora->check","no connection to Oracle \n exiting...!"); exit(EXIT_FAILURE); } rtdb->setSecondInput(ora); } #endif else { HParRootFileIo *input2=new HParRootFileIo; input2->open((Text_t*)paramFile2.Data(),"READ"); rtdb->setSecondInput(input2); } //------------------------ Add THE HYP Task ----------------------------- gHades->getTaskSet(context)->add(hyp); gHades->getTaskSet(context)->print(); //------------------------ Initialization ---------------------------- cout<<"gHades->init()\n"; gHades->makeCounter(1000); if(!gHades->init()) cerr<<"Error gHades->init() returns false\n"; //Set output if (! (outDir.EndsWith("null") || outDir.EndsWith("none") || outDir=="")) { gHades->setOutputFile((Text_t*)outFile.Data(),"RECREATE","Test",2); gHades->makeTree(); } //-------------------------------------------------------------------- gHades->printDefinedTaskSets(); gHades->setQuietMode(0); cout<<"Processing events...\n"; timer.Reset(); timer.Start(); if ((nEvents<1) && (startEvt == 0) ) { evN=gHades->eventLoop(); } else { evN=gHades->eventLoop(nEvents,startEvt); } gHades->getTaskSet(context)->printTimer(); hfile->Close(); printf("rtdb deleted\n"); delete gHades; timer.Stop(); cout<<"------------------------------------------------------\n"; cout<<"Events processed: "< paramfile 1 (default is 'ora')" << endl; cout << "-2, --paramfile2= paramfile 2 (default is 'ora')" << endl; cout << "-r, --refID= Gobal ref ID" << endl; cout << "-l, --hyplevel= Level: 0 means produce HYP-DST, 1 projection step" << endl; cout << "-q, --qalevel= Level: 0: no QA, 1: QA, 2: TRQA" << endl; cout << "-j, Discard all existing hyp categories" << endl; cout << "-d, --inputdir= input directory" << endl; cout << "-o, --outputdir= output HypDST directory" << endl; cout << "-n, --ntupledir= output ntuple directory" << endl; cout << "-#, --numofevents= number of events" << endl; cout << "-$, --startevent= start event" << endl; cout << "-?, --help display this text" << endl; } #ifndef __CINT__ int main(int argc, char **argv) { int myargc=1; char *myargv[MAXARGS]; myargv[0] = argv[0]; //name itself cout << "Arguments given were:" < Cannot open " << optfile.Data() << endl; return 1; } while (get_next_file()) { //cout << "'" << binary_file << "'" << endl; myargv[myargc]= new char[strlen(binary_file)+1]; strcpy(myargv[myargc], binary_file); myargc++; if (myargc == MAXARGS) { cout << "Optfile -> Too many lines in " << optfile.Data() << endl; return 1; } } //now attach the old argv for (int i=2; i