<commit_before>enum anaModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};
//mLocal: Analyze locally files in your computer using aliroot
//mLocalPAR: Analyze locally files in your computer using root + PAR files
//mPROOF: Analyze CAF files with PROOF
//mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
//mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package

//Analysis modes
const TString analysisMode = "TPC"; //"TPC", "Global"

//Centrality stuff
Int_t binfirst = 0;  //where do we start numbering bins
Int_t binlast = 8;  //where do we stop numbering bins
const Int_t numberOfCentralityBins = 9;
Double_t centralityArray[numberOfCentralityBins+1] = {0.,5.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
Bool_t kUsePID = kFALSE;
const TString  centralityEstimator = "V0M";
Double_t vertexZ = 10.;

//output file
TString commonOutputFileName = "outputEfficiency";

//void runEfficiencyTaskCentralityTrain(Int_t mode = mPROOF, 
//Int_t nRuns = 600000, 
//Bool_t DATA = kFALSE, 
//const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_4plus#esdTree", Int_t offset=0) {
void runBalancePsiEfficiencyTaskCentralityTrain(Int_t mode = mLocal, Bool_t DATA = kFALSE) {
//void runEfficiencyTaskCentralityTrain(const char* runListFileName = "listOfRuns.txt",Int_t mode = mGrid,  Bool_t DATA = kFALSE) {
  // Time:
  TStopwatch timer;
  timer.Start();
  
  // Load needed libraries:
  LoadLibraries(mode);
  
  // Create and configure the AliEn plug-in:
  if(mode == mGrid || mode == mGridPAR) {
    gROOT->LoadMacro("CreateAlienHandler.C");
    AliAnalysisGrid *alienHandler = CreateAlienHandler(runListFileName);  
    if (!alienHandler) return;
    gROOT->LoadMacro("AliAnalysisTaskEfficiencyBF.cxx++");  //gROOT->LoadMacro("AliAnalysisEfficiencyTaskCentralityTrain.cxx++");
  }
  // Chains:   
  if(mode==mLocal || mode == mLocalPAR) {
    //gROOT->LoadMacro("AliAnalysisEfficiencyTaskCentralityTrain.cxx++");
    //gROOT->LoadMacro("AliAnalysisTaskEfficiencyBF.cxx++");
    TChain* chain = new TChain("esdTree");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set1/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set2/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set3/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set4/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set5/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set6/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set7/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set8/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set9/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set10/AliESDs.root");
  }
  //Proof
  if(mode == mPROOF) {
    gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
    gProof->Load("AliAnalysisTaskEfficiencyBF.cxx++");
  }

  // Create analysis manager:
  AliAnalysisManager *mgr = new AliAnalysisManager("bfPsiCorrectionManager");
  // Connect plug-in to the analysis manager:
  if(mode == mGrid || mode == mGridPAR) { 
    mgr->SetGridHandler(alienHandler);
  }
  // Event handlers:
  AliVEventHandler* esdH = new AliESDInputHandler;
  mgr->SetInputEventHandler(esdH);
  AliMCEventHandler *mc = new AliMCEventHandler();
  //mc->SetReadTR(kFALSE);
  mgr->SetMCtruthEventHandler(mc); 
    
  // Task to check the offline trigger:
  //if(mode == mLocal || mode == mGrid || mode == mGridPAR)
  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
  AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection(!DATA);
  physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();
  // Enable debug printouts:
  mgr->SetDebugLevel(2);
  
  //Add the centrality determination task
  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
  AliCentralitySelectionTask *centralityTask = AddTaskCentrality();
  centralityTask->SetMCInput();
  //centralityTask->SetPass(2);
  //AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
  //taskCentrality->SelectCollisionCandidates(AliVEvent::kMB);

  if(kUsePID) {
    gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
    AddTaskPIDResponse(1); 
  }

  // Load the analysis task:
  gROOT->LoadMacro("$ALICE_ROOT/PWGCF/EBYE/macros/AddTaskBalancePsiEfficiency.C");
  
  //for (Int_t i=binfirst; i<binlast+1; i++) {
  for (Int_t i = 0; i < 9; i++) {
    Double_t lowCentralityBinEdge = centralityArray[i];
    Double_t highCentralityBinEdge = centralityArray[i+1];
    Printf("\nWagon for centrality bin %i: %.0f-%.0f",i,lowCentralityBinEdge,highCentralityBinEdge);
    AddTaskBalancePsiEfficiency(centralityEstimator.Data(), lowCentralityBinEdge, highCentralityBinEdge, vertexZ, commonOutputFileName.Data());
  } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)

  // Run the analysis:
  if(!mgr->InitAnalysis()){return;}
  mgr->PrintStatus(); 
  if(mode == mLocal || mode == mLocalPAR) 
    mgr->StartAnalysis("local",chain);
  else if(mode == mPROOF) 
    mgr->StartAnalysis("proof",dataDir,nRuns,offset);
  else if(mode == mGrid || mode == mGridPAR) 
    mgr->StartAnalysis("grid");

  // Print real and CPU time used for analysis:  
  timer.Stop();
  timer.Print();
  
} // end of void runTaskFluctuations(...)

//=============================================================//
void LoadLibraries(const anaModes mode) {  
  //--------------------------------------
  // Load the needed libraries most of them already loaded by aliroot
  //--------------------------------------
  gSystem->Load("libTree");
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libXMLIO");
  gSystem->Load("libPhysics");
  
  //----------------------------------------------------------
  // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
  //----------------------------------------------------------
  if (mode==mLocal || mode==mGrid || mode == mGridPAR) {
    //--------------------------------------------------------
    // If you want to use already compiled libraries 
    // in the aliroot distribution
    //--------------------------------------------------------
    gSystem->Load("libSTEERBase");
    gSystem->Load("libESD");
    gSystem->Load("libAOD");
    gSystem->Load("libANALYSIS");
    gSystem->Load("libANALYSISalice");
    gSystem->Load("libEventMixing.so");
    gSystem->Load("libCORRFW.so");
    gSystem->Load("libPWGTools.so");
    gSystem->Load("libPWGCFebye.so");

    // Use AliRoot includes to compile our task                                   
    gROOT->ProcessLine(".include $ALICE_ROOT/include");
  }
  
  else if (mode == mLocalPAR) {
    //--------------------------------------------------------
    //If you want to use root and par files from aliroot
    //--------------------------------------------------------  
    SetupPar("STEERBase");
    SetupPar("ESD");
    SetupPar("AOD");
    SetupPar("ANALYSIS");
    SetupPar("ANALYSISalice");
}
  
  //---------------------------------------------------------
  // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
  //---------------------------------------------------------
  else if (mode==mPROOF) {
    // Connect to proof
    printf("*** Connect to PROOF ***\n");
    gEnv->SetValue("XSec.GSI.DelegProxy","2");
    // Put appropriate username here
    TProof::Open("alice-caf.cern.ch");
    //TProof::Open("skaf.saske.sk");
    //TProof::Open("prf000-iep-grid.saske.sk");

    gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-12-AN");
  }  
  
} // end of void LoadLibraries(const anaModes mode)

//===============================================================================================

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 /tmp/%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();<commit_msg>Adding extra libs for proof<commit_after>enum anaModes {mLocal,mLocalPAR,mPROOF,mGrid,mGridPAR};
//mLocal: Analyze locally files in your computer using aliroot
//mLocalPAR: Analyze locally files in your computer using root + PAR files
//mPROOF: Analyze CAF files with PROOF
//mGrid: Analyze files on Grid via AliEn plug-in and using precompiled FLOW libraries
//mGridPAR: Analyze files on Grid via AliEn plug-in and using par files for FLOW package

//Analysis modes
const TString analysisMode = "TPC"; //"TPC", "Global"

//Centrality stuff
Int_t binfirst = 0;  //where do we start numbering bins
Int_t binlast = 7;  //where do we stop numbering bins
const Int_t numberOfCentralityBins = 8;
Double_t centralityArray[numberOfCentralityBins+1] = {0.,10.,20.,30.,40.,50.,60.,70.,80.}; // in centrality percentile
Bool_t kUsePID = kFALSE;
const TString  centralityEstimator = "V0M";
Double_t vertexZ = 10.;

//output file
TString commonOutputFileName = "outputEfficiency";

//void runEfficiencyTaskCentralityTrain(Int_t mode = mPROOF, 
//Int_t nRuns = 600000, 
//Bool_t DATA = kFALSE, 
//const Char_t* dataDir="/alice/data/LHC10h_000137161_p1_4plus#esdTree", Int_t offset=0) {
void runBalancePsiEfficiencyTaskCentralityTrain(Int_t mode = mLocal, Bool_t DATA = kFALSE) {
//void runEfficiencyTaskCentralityTrain(const char* runListFileName = "listOfRuns.txt",Int_t mode = mGrid,  Bool_t DATA = kFALSE) {
  // Time:
  TStopwatch timer;
  timer.Start();
  
  // Load needed libraries:
  LoadLibraries(mode);
  
  // Create and configure the AliEn plug-in:
  if(mode == mGrid || mode == mGridPAR) {
    gROOT->LoadMacro("CreateAlienHandler.C");
    AliAnalysisGrid *alienHandler = CreateAlienHandler(runListFileName);  
    if (!alienHandler) return;
    gROOT->LoadMacro("AliAnalysisTaskEfficiencyBF.cxx++");  //gROOT->LoadMacro("AliAnalysisEfficiencyTaskCentralityTrain.cxx++");
  }
  // Chains:   
  if(mode==mLocal || mode == mLocalPAR) {
    //gROOT->LoadMacro("AliAnalysisEfficiencyTaskCentralityTrain.cxx++");
    //gROOT->LoadMacro("AliAnalysisTaskEfficiencyBF.cxx++");
    TChain* chain = new TChain("esdTree");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set1/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set2/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set3/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set4/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set5/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set6/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set7/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set8/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set9/AliESDs.root");
    chain->Add("/glusterfs/alice1/alice2/pchrist/HeavyIons/MC/Set10/AliESDs.root");
  }
  //Proof
  if(mode == mPROOF) {
    gROOT->ProcessLine(Form(".include %s/include", gSystem->ExpandPathName("$ALICE_ROOT")));
    gProof->Load("AliAnalysisTaskEfficiencyBF.cxx++");
  }

  // Create analysis manager:
  AliAnalysisManager *mgr = new AliAnalysisManager("bfPsiCorrectionManager");
  // Connect plug-in to the analysis manager:
  if(mode == mGrid || mode == mGridPAR) { 
    mgr->SetGridHandler(alienHandler);
  }
  // Event handlers:
  AliVEventHandler* esdH = new AliESDInputHandler;
  mgr->SetInputEventHandler(esdH);
  AliMCEventHandler *mc = new AliMCEventHandler();
  //mc->SetReadTR(kFALSE);
  mgr->SetMCtruthEventHandler(mc); 
    
  // Task to check the offline trigger:
  //if(mode == mLocal || mode == mGrid || mode == mGridPAR)
  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C"); 
  AliPhysicsSelectionTask* physicsSelTask = AddTaskPhysicsSelection(!DATA);
  physicsSelTask->GetPhysicsSelection()->SetAnalyzeMC();
  // Enable debug printouts:
  mgr->SetDebugLevel(2);
  
  //Add the centrality determination task
  gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskCentrality.C");
  AliCentralitySelectionTask *centralityTask = AddTaskCentrality();
  centralityTask->SetMCInput();
  //centralityTask->SetPass(2);
  //AliCentralitySelectionTask *taskCentrality = AddTaskCentrality();
  //taskCentrality->SelectCollisionCandidates(AliVEvent::kMB);

  if(kUsePID) {
    gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPIDResponse.C");
    AddTaskPIDResponse(1); 
  }

  // Load the analysis task:
  gROOT->LoadMacro("$ALICE_ROOT/PWGCF/EBYE/macros/AddTaskBalancePsiEfficiency.C");
  
  for (Int_t i=binfirst; i<binlast+1; i++) {
    //for (Int_t i = 0; i < 9; i++) {
    Double_t lowCentralityBinEdge = centralityArray[i];
    Double_t highCentralityBinEdge = centralityArray[i+1];
    Printf("\nWagon for centrality bin %i: %.0f-%.0f",i,lowCentralityBinEdge,highCentralityBinEdge);
    AddTaskBalancePsiEfficiency(centralityEstimator.Data(), lowCentralityBinEdge, highCentralityBinEdge, vertexZ, commonOutputFileName.Data());
  } // end of for (Int_t i=0; i<numberOfCentralityBins; i++)

  // Run the analysis:
  if(!mgr->InitAnalysis()){return;}
  mgr->PrintStatus(); 
  if(mode == mLocal || mode == mLocalPAR) 
    mgr->StartAnalysis("local",chain);
  else if(mode == mPROOF) 
    mgr->StartAnalysis("proof",dataDir,nRuns,offset);
  else if(mode == mGrid || mode == mGridPAR) 
    mgr->StartAnalysis("grid");

  // Print real and CPU time used for analysis:  
  timer.Stop();
  timer.Print();
  
} // end of void runTaskFluctuations(...)

//=============================================================//
void LoadLibraries(const anaModes mode) {  
  //--------------------------------------
  // Load the needed libraries most of them already loaded by aliroot
  //--------------------------------------
  gSystem->Load("libTree");
  gSystem->Load("libGeom");
  gSystem->Load("libVMC");
  gSystem->Load("libXMLIO");
  gSystem->Load("libPhysics");
  
  //----------------------------------------------------------
  // >>>>>>>>>>> Local mode <<<<<<<<<<<<<< 
  //----------------------------------------------------------
  if (mode==mLocal || mode==mGrid || mode == mGridPAR) {
    //--------------------------------------------------------
    // If you want to use already compiled libraries 
    // in the aliroot distribution
    //--------------------------------------------------------
    gSystem->Load("libSTEERBase");
    gSystem->Load("libESD");
    gSystem->Load("libAOD");
    gSystem->Load("libANALYSIS");
    gSystem->Load("libANALYSISalice");
    gSystem->Load("libEventMixing.so");
    gSystem->Load("libCORRFW.so");
    gSystem->Load("libPWGTools.so");
    gSystem->Load("libPWGCFebye.so");

    // Use AliRoot includes to compile our task                                   
    gROOT->ProcessLine(".include $ALICE_ROOT/include");
  }
  
  else if (mode == mLocalPAR) {
    //--------------------------------------------------------
    //If you want to use root and par files from aliroot
    //--------------------------------------------------------  
    SetupPar("STEERBase");
    SetupPar("ESD");
    SetupPar("AOD");
    SetupPar("ANALYSIS");
    SetupPar("ANALYSISalice");
}
  
  //---------------------------------------------------------
  // <<<<<<<<<< PROOF mode >>>>>>>>>>>>
  //---------------------------------------------------------
  else if (mode==mPROOF) {
    // Connect to proof
    printf("*** Connect to PROOF ***\n");
    gEnv->SetValue("XSec.GSI.DelegProxy","2");
    // Put appropriate username here
    TProof::Open("alice-caf.cern.ch");
    //TProof::Open("skaf.saske.sk");
    //TProof::Open("prf000-iep-grid.saske.sk");

    gProof->EnablePackage("VO_ALICE@AliRoot::v4-21-12-AN");
 
    TString extraLibs = "";
    extraLibs += "CORRFW:PWGTools";

    TList *list = new TList();
    list->Add(new TNamed("ALIROOT_EXTRA_LIBS",extraLibs.Data()));

    gProof->EnablePackage("VO_ALICE@AliRoot::v5-03-46-AN",list);
  }  
  
} // end of void LoadLibraries(const anaModes mode)

//===============================================================================================

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 /tmp/%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();
{'fraction_non_alphanumeric': 0.22273520635099375, 'fraction_numerical': 0.010922808400427904, 'mean_word_length': 3.127817801533814, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 179, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6035171', 'n_tokens_mistral': 6093, 'n_tokens_neox': 5866, 'n_words': 1020}