#if !defined(__CINT__) || defined(__MAKECINT__) #include #include #include #include #include #include #include #include #include #include #include using namespace std; #endif //=================================== // global variables //=================================== PamLevel2 *event = NULL; TChain *tree = NULL; TFile *outfh = NULL; TFile *outft = NULL; TTree *otree = NULL; bool fillTree = false; bool fillHistos = false; //==================================== // Functions to be provided externally //==================================== bool Select(PamLevel2*); void CreateHistos(); void FillHistos(PamLevel2*); void SaveHistos(TFile *); //========================================== //000000000000000000000000000000000000000000 //========================================== bool Begin(){ //------------------------ // load magnetic field //------------------------ TString fieldpath = gSystem->Getenv("PAM_CALIB"); if(fieldpath.IsNull()){ cout << " **ERROR** : No PAMELA environment variables defined "<LoadField(fieldpath.Data()); //------------------------------ // create output histos/trees //------------------------------ if(fillHistos) CreateHistos(); if(fillTree) event->CreateCloneTrees(tree); cout << "\nBegin() - done\n\n"; return 1; } //========================================== //000000000000000000000000000000000000000000 //========================================== bool Process(int iev){ //------------------------------ // create output histos/trees //------------------------------ event->Clear(); tree->GetEntry(iev); if( !Select(event) )return false; // cout <TrkLevel2::ntrk()<FillCloneTrees(); // if(fillHistos)FillHistos(event); return true; } //========================================== //000000000000000000000000000000000000000000 //========================================== bool Finish(){ if(fillTree){ outft->cd(); event->WriteCloneTrees(); outft->Close(); } if(fillHistos){ SaveHistos(outfh); outfh->Close(); } cout << "Finish() - done\n"; return 1; } //========================================== //000000000000000000000000000000000000000000 //========================================== Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){ if(options.Contains("fillTree"))fillTree=true; if(options.Contains("fillHisto"))fillHistos=true; // ------------------- // create output files // ------------------- TString outfile_t =0; TString outfile_h =0; if( outfile.IsNull() ){ if(!list.IsNull())outfile = list(0,list.Last('.')); else outfile = "output"; }else{ if(outfile.Contains(".root"))outfile = outfile(0,outfile.Last('.')); } if(fillTree){ outfile_t = outfile; outfile_t.Append("-tree.root"); outft = (TFile*)gROOT->FindObject(outfile_t); if (outft) outft->Close(); outft = new TFile(outfile_t,"RECREATE"); if(outft->IsZombie()){ cout << "Output file could not be created\n"; return 1; }; cout << "Created output file: "<GetName()<FindObject(outfile_h); if (outfh) outfh->Close(); outfh = new TFile(outfile_h,"RECREATE"); if(outfh->IsZombie()){ cout << "Output file could not be created\n"; return 1; }; cout << "Created output file: "<GetName()< list-temp.txt"; cout << command.str().c_str() << endl; gSystem->Exec(command.str().c_str()); tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,"list-temp.txt"),options); }else{ tree = event->GetPamTree(event->GetListOfLevel2Files(ddir,list),options); }; tree->SetCacheSize(0); // --------------- // initializations // --------------- if( !Begin() )return 0;; // ----------------- // loop over events // ----------------- ULong64_t nevents = tree->GetEntriesFast(); if(!nmax)nmax = numeric_limits::max(); if(nevents < nmax)nmax=nevents; cout << endl<<" Start loop over events: "<< nmax<Start("event-loop"); TString current_file = ""; for(ULong64_t iev=60000; ievGetEntry(iev); if( Process(iev) )sel++; if(current_file.CompareTo(tree->GetFile()->GetName())){ current_file=tree->GetFile()->GetName(); cout << iev<< " -> "<< current_file << endl; // cout << tree->GetFile()->GetName() << endl; }; if(event->TrkLevel2::ntrk() >0)ntrk++; if(!(iev%100))cout << iev << endl; }; benchmark->Show("event-loop"); cout << ntrk <<" tracks over "<1){ if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ usage(); return(1); }; // ----------------------- // Read input parameters // ----------------------- /* DEBUG = false; DIR = gSystem->WorkingDirectory(); LIST = ""; OUTFILE = "TrkLevel1Report_output.root"; MAXEV = numeric_limits::max(); */ for (int i = 1; i < argc; i++){ // -----------------------------------------------------// if (!strcmp(argv[i], "-processDir")){ if (++i >= argc) throw -1; DIR = argv[i]; cout << "processDir "<= argc) throw -1; LIST = argv[i]; cout << "processList "<= argc) throw -1; OUTFILE = argv[i]; cout << "outputFile "<= argc) throw -1; MAXEV = atoi(argv[i]); cout << "NumEvents "<