--- calo/flight/CaloBragg/doc/example.cpp 2008/06/13 08:11:03 1.1.1.1 +++ calo/flight/CaloBragg/doc/example.cpp 2010/08/19 11:55:32 1.2 @@ -1,6 +1,3 @@ -//Nella release 4 ci sono i TGraph e i fit sui TGraph. Ho perso così l'info in Z che avevo. - - #include #include #include @@ -33,69 +30,230 @@ #include #include -#include // ADD HEADER FILE HERE +#include // ADD HEADER FILE HERE using namespace std; - -void example(TString dir, TString flist, TString treelist="+ALL"){ - +//=================================== +// global variables +//=================================== +Bool_t DEBUG; +Bool_t SIMU; +TString DIR; +TString LIST; +TString OPTIONS; +ULong64_t MAXEV; +TString OUTFILE; + +PamLevel2 *pam_event = NULL; +TFile *outfv = NULL; + +bool fillTree = false; +bool fillHistos = false; + + +//========================================== +//000000000000000000000000000000000000000000 +//========================================== +Int_t Loop(TString ddir,TString list, ULong64_t nmax, TString options, TString outfile){ - PamLevel2 *pam_event = new PamLevel2(dir,flist); // << create pamela event - TChain *T = pam_event->GetPamTree(); - - CaloNuclei *cn = new CaloNuclei(pam_event); // CREATE CaloNuclei OBJECT GIVING PamLevel2 POINTER - - - Int_t nevent = pam_event->GetEntries(); - cout<< " Events= "<FindObject(outfile_t); + if (outfv) outfv->Close(); + outfv = new TFile(outfile_t,"RECREATE"); + if(outfv->IsZombie()){ + cout << "Output file could not be created\n"; + return 1; + }; + cout << "Created output file: "<GetName()<GetEntries(); + if(!nmax)nmax = numeric_limits::max(); + if(nevents < nmax)nmax=nevents; + cout << endl<<" Start loop over events: "<< nmax<GetEntry(i); // get the entry, also pam_event->GetEntry is fine - - cn->Print(); // this will simply print on the terminal the determined CaloNuclei values - - Float_t mip1 = cn->Get_dEdx1(); // here how you can use the "old" dE/dx on the first plane - - if ( cn->Get_qpremeanN() > 0. && cn->Get_interplane()>9 ) { // other new variables + pam_event->Clear(); + if( pam_event->GetEntry(i) ){ // get the entry // - // do something - // - }; + cn->Print(); // this will simply print on the terminal the determined CaloNuclei values + // + Float_t zeta = cn->Get_lpz(); // here how you can use the "old" dE/dx on the first plane + printf(" Event number %llu zeta %f \n",i,zeta); + hzeta->Fill(zeta); + + } + }; + pam_event->Clear(); + // + // save histo to file + // + gROOT->cd(); + outfv->cd(); + // + hzeta->Write(); + outfv->Close(); + // + printf(" end!\n"); + return 0; + +} - // if ( nrig > 5. ) caloz->Fill(mip1); +///////////////////////////////////////////////////////////////// - // - // if you want to do it for other tracks and not only for the track number 0 (default) you can do this way: - // - Float_t mipt[100]; - memset(mipt,0.,100*sizeof(Float_t)); - for (Int_t nt = 0; nt < pam_event->GetTrkLevel2()->GetNTracks(); nt++){ - PamTrack *track = pam_event->GetTrack(nt); - cn->Process(nt); - if ( nt < 100 ) mipt[nt] = cn->Get_dEdx1(); - if ( nt > 0 ){ - cn->Print(); - }; - }; - // +void usage(){ - } - printf(" end!\n"); - -}; + cout << "------------------------------------------------------------"< create an output file with histograms \n"; + cout << " fillTree --> create an output file with trees storing the selected events \n "; + cout << " +(-)ALL --> inlcude(exclude) all trees and branches \n " ; + cout << " +(-)TRK1 +(-)TRK2 +(-)CAL1 +(-)CAL2 +(-)TOF +(-)TRG +(-)ND +(-)S4 +(-)ORB --> inlcude(exclude) trees and branches \n" ; + cout << "------------------------------------------------------------"<1){ + + if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") ){ + usage(); + return(1); + }; + // ----------------------- + // Read input parameters + // ----------------------- + DEBUG = false; + SIMU = false; + DIR = gSystem->WorkingDirectory(); + LIST = ""; + OUTFILE = ""; + OPTIONS = "+AUTO fillTree"; + MAXEV = 0; + + + 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 "<= argc) throw -1; + OPTIONS = argv[i]; + if( OPTIONS.Contains("[") ){ + do{ + if (++i >= argc) throw -1; + OPTIONS.Append(argv[i]); + }while(!OPTIONS.Contains("]")); + }else cout << "wrong option format --> ignoring " << endl; + } + // -----------------------------------------------------// + else if (!strcmp(argv[i], "--debug") || !strcmp(argv[i], "-g")){ + DEBUG = true; + continue; + } + else if (!strcmp(argv[i], "--simu") || !strcmp(argv[i], "-s")){ + SIMU = true; + continue; + } + // -----------------------------------------------------// + else{ + cout << "Unidentified input parameter. Ignored."<< endl; + }; + }; + }else{ + usage(); + return(1); + }; + // ----------------------- + // Check input parameters + // ----------------------- + + + return(0); + +}; +// +int main(int argc, char **argv) +{ + + if( HandleInputPar(argc,argv) )return(1); + + // Loop(DIR,LIST,MAXEV,"-ALL+TRK1+TRK2+CAL1+CAL2+TOF+AC",OUTFILE); + cout << "OPTIONS "<