/* $Id: $ */ //-------------------------------------------------- // Example macro to do analysis with the // analysis classes in PWG4PartCorr // Can be executed with Root and AliRoot // // Pay attention to the options and definitions // set in the lines below // // Author : Gustavo Conesa Balbastre (INFN-LNF) // //------------------------------------------------- enum anaModes {mLocal=0, mGRID=3}; //mLocal = 0: Analyze locally files in your computer //mGRID = 3: Analyze files on GRID //--------------------------------------------------------------------------- //Settings to read locally several files, only for "mLocal" mode //The different values are default, they can be set with environmental //variables: INDIR, PATTERN, NFILES, respectivelly char * kInDir = "/user/data/files/"; char * kPattern = ""; // Data are in files kInDir/kPattern+i Int_t kFile = 1; // Number of files //--------------------------------------------------------------------------- //Collection file for grid analysis char * kXML = "collection.xml"; //--------------------------------------------------------------------------- //Scale histograms from file. Change to kTRUE when xsection file exists //Put name of file containing xsection //Put number of events per ESD file //This is an specific case for normalization of Pythia files. const Bool_t kGetXSectionFromFileAndScale = kFALSE ; const char * kXSFileName = "pyxsec.root"; //--------------------------------------------------------------------------- const Bool_t kMC = kFALSE; //With real data kMC = kFALSE const TString kInputData = "ESD"; //ESD, AOD, MC, deltaAOD const Bool_t outAOD = kFALSE; //Some tasks doesnt need it. TString kTreeName; const Bool_t kUsePAR = kFALSE; //set to kFALSE for libraries const Int_t kFilter = kFALSE; //Use ESD filter void ana(Int_t mode=mLocal) { // Main //-------------------------------------------------------------------- // Load analysis libraries // Look at the method below, // change whatever you need for your analysis case // ------------------------------------------------------------------ LoadLibraries() ; // TGeoManager::Import("geometry.root") ; //need file "geometry.root" in local dir!!!! //------------------------------------------------------------------------------------------------- //Create chain from ESD and from cross sections files, look below for options. //------------------------------------------------------------------------------------------------- if(kInputData == "ESD") kTreeName = "esdTree" ; else if(kInputData.Contains("AOD")) kTreeName = "aodTree" ; else if (kInputData == "MC") kTreeName = "TE" ; else { cout<<"Wrong data type "<SetSkipTerminate(kTRUE); //mgr->SetNSysInfo(1); // MC handler if((kMC || kInputData == "MC") && !kInputData.Contains("AOD")){ AliMCEventHandler* mcHandler = new AliMCEventHandler(); mcHandler->SetReadTR(kFALSE);//Do not search TrackRef file mgr->SetMCtruthEventHandler(mcHandler); if( kInputData == "MC") { cout<<"MC INPUT EVENT HANDLER"<SetInputEventHandler(NULL); } } // AOD output handler if(kInputData!="deltaAOD" && outAOD){ cout<<"Init output handler"<SetOutputFileName("aod.root"); ////aodoutHandler->SetCreateNonStandardAOD(); mgr->SetOutputEventHandler(aodoutHandler); } //input if(kInputData == "ESD"){ // ESD handler AliESDInputHandler *esdHandler = new AliESDInputHandler(); esdHandler->SetReadFriends(kFALSE); mgr->SetInputEventHandler(esdHandler); cout<<"ESD handler "<GetInputEventHandler()<SetInputEventHandler(aodHandler); if(kInputData == "deltaAOD") aodHandler->AddFriend("deltaAODPartCorr.root"); cout<<"AOD handler "<GetInputEventHandler()<RegisterExternalFile("deltaAODPartCorr.root"); //mgr->SetDebugLevel(-1); // For debugging, do not uncomment if you want no messages. //------------------------------------------------------------------------- //Define task, put here any other task that you want to use. //------------------------------------------------------------------------- AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer(); AliAnalysisDataContainer *coutput1; if(outAOD){ coutput1 = mgr->GetCommonOutputContainer(); if(kInputData=="ESD"){ gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(); if(kFilter){ // Set of cuts //for standard global track cuts AliESDtrackCuts* esdTrackCutsGlobal = AliESDtrackCuts::GetStandardITSTPCTrackCuts2009(kTRUE); esdTrackCutsGlobal->SetName("StandardFromAliESDTrackCuts"); //for TPC tracks only // AliESDtrackCuts* esdTrackCutsTPC = AliESDtrackCuts::GetStandardTPCOnlyTrackCuts(); // esdTrackCutsTPC->SetRequireTPCRefit(kTRUE); // esdTrackCutsTPC->SetMinNClustersTPC(70); AliAnalysisFilter* trackFilter = new AliAnalysisFilter("trackFilter"); trackFilter->AddCuts(esdTrackCutsGlobal); //trackFilter->AddCuts(esdTrackCutsTPC); gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C"); AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kFALSE); esdfilter->SetTrackFilter(trackFilter); kInputData = "AOD" ; kTreeName = "aodTree" ; } } } gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C"); AliAnalysisTaskParticleCorrelation *taskEMCAL = AddTaskPartCorr(kInputData,"EMCAL", kFALSE,kFALSE, kFALSE); //mgr->ProfileTask("PartCorrEMCAL"); //AliAnalysisTaskParticleCorrelation *taskPHOS = AddTaskPartCorr(kInputData,"PHOS", kFALSE,kFALSE,kFALSE); //mgr->ProfileTask("PartCorrPHOS"); //gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C"); //AliAnalysisTaskParticleCorrelation *taskQA = AddTaskCalorimeterQA(kInputData,kFALSE,kFALSE); //mgr->ProfileTask("CalorimeterPerformance"); //----------------------- // Run the analysis //----------------------- mgr->InitAnalysis(); mgr->PrintStatus(); mgr->StartAnalysis("local",chain); cout <<" Analysis ended sucessfully "<< endl ; } else cout << "Chain was not produced ! "<Load("libTree.so"); gSystem->Load("libGeom.so"); gSystem->Load("libVMC.so"); gSystem->Load("libXMLIO.so"); gSystem->Load("libMatrix.so"); gSystem->Load("libPhysics.so"); if(kUsePAR){ //-------------------------------------------------------- //If you want to use root and par files from aliroot //-------------------------------------------------------- SetupPar("STEERBase"); SetupPar("ESD"); SetupPar("AOD"); SetupPar("ANALYSIS"); SetupPar("ANALYSISalice"); SetupPar("PHOSUtils"); SetupPar("EMCALUtils"); SetupPar("PWG4PartCorrBase"); SetupPar("PWG4PartCorrDep"); } else{ //-------------------------------------------------------- // If you want to use already compiled libraries // in the aliroot distribution //-------------------------------------------------------- gSystem->Load("libSTEERBase.so"); gSystem->Load("libESD.so"); gSystem->Load("libAOD.so"); gSystem->Load("libANALYSIS.so"); gSystem->Load("libANALYSISalice.so"); gSystem->Load("libPHOSUtils"); gSystem->Load("libEMCALUtils"); gSystem->Load("libPWG4PartCorrBase.so"); gSystem->Load("libPWG4PartCorrDep.so"); if(kFilter){ gSystem->Load("libCORRFW.so"); gSystem->Load("libPWG3base.so"); gSystem->Load("libPWG3muon.so"); } } } void SetupPar(char* pararchivename) { //Load par files, create analysis libraries //For testing, if par file already decompressed and modified //classes then do not decompress. TString cdir(Form("%s", gSystem->WorkingDirectory() )) ; TString parpar(Form("%s.par", pararchivename)) ; // if ( gSystem->AccessPathName(parpar.Data()) ) { // gSystem->ChangeDirectory(gSystem->Getenv("ALICE_ROOT")) ; // TString processline(Form(".! make %s", parpar.Data())) ; // gROOT->ProcessLine(processline.Data()) ; // gSystem->ChangeDirectory(cdir) ; // processline = Form(".! mv $ALICE_ROOT/%s .", parpar.Data()) ; // gROOT->ProcessLine(processline.Data()) ; // } if ( gSystem->AccessPathName(pararchivename) ) { TString processline = Form(".! tar xvzf %s",parpar.Data()) ; gROOT->ProcessLine(processline.Data()); } TString ocwd = gSystem->WorkingDirectory(); gSystem->ChangeDirectory(pararchivename); // check for BUILD.sh and execute if (!gSystem->AccessPathName("PROOF-INF/BUILD.sh")) { printf("*******************************\n"); printf("*** Building PAR archive ***\n"); cout<Exec("PROOF-INF/BUILD.sh")) { Error("runProcess","Cannot Build the PAR Archive! - Abort!"); return -1; } } // check for SETUP.C and execute if (!gSystem->AccessPathName("PROOF-INF/SETUP.C")) { printf("*******************************\n"); printf("*** Setup PAR archive ***\n"); cout<Macro("PROOF-INF/SETUP.C"); } gSystem->ChangeDirectory(ocwd.Data()); printf("Current dir: %s\n", ocwd.Data()); } void CreateChain(const anaModes mode, TChain * chain, TChain * chainxs){ //Fills chain with data TString ocwd = gSystem->WorkingDirectory(); //--------------------------------------- //Local files analysis //--------------------------------------- if(mode == mLocal){ //If you want to add several ESD files sitting in a common directory INDIR //Specify as environmental variables the directory (INDIR), the number of files //to analyze (NFILES) and the pattern name of the directories with files (PATTERN) if(gSystem->Getenv("INDIR")) kInDir = gSystem->Getenv("INDIR") ; else cout<<"INDIR not set, use default: "<Getenv("PATTERN")) kPattern = gSystem->Getenv("PATTERN") ; else cout<<"PATTERN not set, use default: "<Getenv("NFILES")) kFile = atoi(gSystem->Getenv("NFILES")) ; else cout<<"NFILES not set, use default: "<cd(kInDir) ) {//check if ESDs directory exist printf("%s does not exist\n", kInDir) ; return ; } //if(gSystem->Getenv("XSFILE")) //kXSFileName = gSystem->Getenv("XSFILE") ; //else cout<<" XS file name not set, use default: "<Getenv("GENER"); if(kGener) { cout<<"GENER "<Get(kTreeName) ) { printf("++++ Adding %s\n", file) ; chain->AddFile(file); chainxs->Add(filexs) ; } } else { printf("---- Skipping %s\n", file) ; skipped++ ; } } printf("number of entries # %lld, skipped %d\n", chain->GetEntries(), skipped*100) ; } else { TString input = "AliESDs.root" ; cout<<">>>>>> No list added, take a single file <<<<<<<<< "<AddFile(input); } }// local files analysis //------------------------------ //GRID xml files //----------------------------- else if(mode == mGRID){ //Get colection file. It is specified by the environmental //variable XML if(gSystem->Getenv("XML") ) kXML = gSystem->Getenv("XML"); else sprintf(kXML, "collection.xml") ; if (!TFile::Open(kXML)) { printf("No collection file with name -- %s -- was found\n",kXML); return ; } else cout<<"XML file "<Load("libNetx.so") ; gSystem->Load("libRAliEn.so"); TGrid::Connect("alien://") ; //Feed Grid with collection file //TGridCollection * collection = (TGridCollection*)gROOT->ProcessLine(Form("TAlienCollection::Open(\"%s\", 0)", kXML)); TGridCollection * collection = (TGridCollection*) TAlienCollection::Open(kXML); if (! collection) { AliError(Form("%s not found", kXML)) ; return kFALSE ; } TGridResult* result = collection->GetGridResult("",0 ,0); // Makes the ESD chain printf("*** Getting the Chain ***\n"); for (Int_t index = 0; index < result->GetEntries(); index++) { TString alienURL = result->GetKey(index, "turl") ; cout << "================== " << alienURL << endl ; chain->Add(alienURL) ; alienURL.ReplaceAll("AliESDs.root",kXSFileName); chainxs->Add(alienURL) ; } }// xml analysis gSystem->ChangeDirectory(ocwd.Data()); } //________________________________________________ void GetAverageXsection(TTree * tree, Double_t & xs, Float_t & ntr) { // Read the PYTHIA statistics from the file pyxsec.root created by // the function WriteXsection(): // integrated cross section (xsection) and // the number of Pyevent() calls (ntrials) // and calculate the weight per one event xsection/ntrials // The spectrum calculated by a user should be // multiplied by this weight, something like this: // TH1F *userSpectrum ... // book and fill the spectrum // userSpectrum->Scale(weight) // // Yuri Kharlov 19 June 2007 // Gustavo Conesa 15 April 2008 Double_t xsection = 0; UInt_t ntrials = 0; xs = 0; ntr = 0; Int_t nfiles = tree->GetEntries() ; if (tree && nfiles > 0) { tree->SetBranchAddress("xsection",&xsection); tree->SetBranchAddress("ntrials",&ntrials); for(Int_t i = 0; i < nfiles; i++){ tree->GetEntry(i); xs += xsection ; ntr += ntrials ; cout << "xsection " <>>> Empty tree !!!! <<<<< "<