<commit_before>//===================== ANALYSIS TRAIN =========================================
// To use: copy this macro to your work directory, modify the global part to match
// your needs, then run root.
//    root[0] .L AnalysisTrain.C
// Grid full mode as below (other modes: test, offline, submit, terminate)
//    root[1] AnalysisTrainPWG-244Jets("grid", "full")
// CAF mode (requires root v5-23-02 + aliroot v4-16-Rev08)
//    root[2] AnalysisTrainPWG4Jets("proof")
// Local mode requires AliESds.root or AliAOD.root in ./data directory
//    root[3] AnalysisTrainPWG4Jets("local")
// In proof and grid modes, a token is needed and sourcing the produced environment file.
//
// If 'saveTrain' flag is set, the train will generate a directory name and run
// in this directory. A configuration file 'ConfigTrain.C' will be generated. 
// One can replay at any time the train via:
//    root[1] AnalysisTrainPWG4Jets(ana_mode, plugin_mode, "train_default_<date>/ConfigTrain.C")

// For Usage with fastjet run in "offline" first and then "submit"
// jdl and analysismacro are automatically patched after "offline" mode

// =============================================================================
// ### General Steering variables
// =============================================================================
//== general setup variables
TString     kTrainName         = "testAnalysis"; // *CHANGE ME* (no blancs or special characters)
TString     kJobTag            = "PWG4 Jet Tasks analysis train configured"; // *CHANGE ME*

// Usage of par files ONLY in grid mode and ONLY if the code is not available
// in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
// To refresh par files, remove the ones in the workdir, then do "make <target.par>" in 
// AliRoot.
Bool_t      kUsePAR             = kFALSE;  // use par files for extra libs
Bool_t      kUseCPAR            = kFALSE;  // use par files for common libs
Bool_t      kFillAOD = kFALSE;  // switch of AOD filling for on the fly analysis

//== general input and output variables

Int_t       iAODanalysis       = 1;      // Analysis on input AOD's
Int_t       iAODhandler        = 1;      // Analysis produces an AOD or dAOD's
Int_t       iESDfilter         = 0;      // ESD to AOD filter (barrel + muon tracks)
Int_t       iPhysicsSelection  = 1;      // ESD to AOD filter (barrel + muon tracks)
Bool_t      kUseKinefilter     = kFALSE; // use Kinematics filter
Bool_t      kUseMuonfilter     = kFALSE; // use Kinematics filter
TString     kCommonOutputFileName = "PWG4_JetTasksOutput.root";


//== general process variables

// ### Other flags to steer the analysis
//==============================================================================
Bool_t      kSkipTerminate      = kTRUE; // Do not call Teminate
Bool_t      kUseDate            = kFALSE; // use date in train name
Bool_t      kUseDebug           = kTRUE; // activate debugging
Int_t       kUseSysInfo         = 0; // activate debugging
Bool_t      kUseMC              = kTRUE;  // use MC info
Bool_t      kIsMC               = kTRUE;  // is MC info, if false it overwrites Use(AOD)MC
Bool_t      kUseAODMC           = kTRUE;  // use MC infA
Bool_t      kUseESDTags         = kFALSE; // use ESD tags for selection
Bool_t      kUseTR              = kFALSE;  // use track references
Bool_t      kUseAODTags         = kFALSE;  // use AOD tags
Bool_t      kSaveTrain          = kFALSE;  // save train configuration as: 


// ### Analysis modules to be included. Some may not be yet fully implemented.
//==============================================================================
Int_t       iJETAN             = 1;      // Jet analysis (PWG4) // 1 write standard 2 write non-standard jets, 3 wrtie both
Int_t       iDIJETAN           = 1;
Int_t       iJETANLib          = 1;
Int_t       iPWG1QASym         = 0;      // Eva's QA task compiled on the fly...
Int_t       iPWG4JetTasks      = 0;      // all jet tasks flag for lib laoding
Int_t       iPWG4JetServices   = 0;      // jet spectrum analysis
Int_t       iPWG4JetSpectrum   = 0;      // jet spectrum analysis
Int_t       iPWG4UE            = 0;      // Underlying Event analysis
Int_t       iPWG4TmpSourceSara = 0;      // Underlying Event analysis not in svn
Int_t       iPWG4TmpSourceFrag = 0;      // Bastian's Fragmentation function not in svn
Int_t       iPWG4JetChem       = 0;      // Jet chemistry 
Int_t       iPWG4PtQAMC        = 0;      // Marta's QA tasks 
Int_t       iPWG4PtSpectra     = 0;      // Marta's QA tasks 
Int_t       iPWG4PtQATPC       = 0;      // Marta's QA tasks 
Int_t       iPWG4ThreeJets     = 0;      // Sona's thrust task
Int_t       iPWG4KMeans        = 0;      // Andreas' KMeans task 
Int_t       iPWG4Cluster       = 0;      // CKB cluster task 
Int_t       iPWG4PartCorrLibs  = 0;      // Gustavo's part corr analysis
Int_t       iPWG4PartCorr      = 0;      // Gustavo's part corr analysis
Int_t       iPWG4CaloQA        = 0;      // Gustavo's part corr analysis
Int_t       iPWG4JetCorr       = 0;     // Paul's jet corr analysis
Int_t       iPWG4Tagged        = 0;      // Gustavo's part corr analysis
Int_t       iPWG4omega3pi      = 0;      // Omega to 3 pi analysis (PWG4) 
Int_t       iPWG4GammaConv     = 0;      // Gamma Conversio
Int_t       kHighPtFilterMask  = 16;     // change depending on the used AOD Filter
TString     kDeltaAODJetName   = "AliAOD.Jets.root";     
TString     kDeltaAODPartCorrName   = "deltaAODPartCorr.root";     


//==============================================================================
// ### PROOF Steering varibales
//==============================================================================
//== proof setup variables
TString     kProofCluster      = "alicecaf.cern.ch";
Bool_t      kProofUseAFPAR     = kFALSE;  // use AF special par file
TString     kProofAFversion          = "AF-v4-17";
//== proof input and output variables
TString     kProofDataSet      = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
Bool_t      kProofSaveToAlien   = kFALSE; // save proof outputs in AliEn train_[trainName]_ddMonthyyyy_time.C
TString     kProofOutdir       = "";
Bool_t      kProofClearPackages = kFALSE;
Int_t       kProofEvents = 10000;
Int_t       kProofOffset = 0;
//== proof process variables


//==============================================================================
// ### Grid plugin Steering varibiables
//==============================================================================
//== grid plugin setup variables
Bool_t      kPluginUse         = kTRUE;   // do not change
Bool_t      kPluginUseProductionMode  = kFALSE;   // use the plugin in production mode
TString     kPluginRootVersion       = "v5-26-00b-2";  // *CHANGE ME IF MORE RECENT IN GRID*
TString     kPluginAliRootVersion    = "v4-19-04-AN";  // *CHANGE ME IF MORE RECENT IN GRID*                                          
Bool_t      kPluginMergeViaJDL       = kTRUE;  // merge via JDL
Bool_t      kPluginFastReadOption   = kFALSE;  // use xrootd tweaks
Bool_t      kPluginOverwriteMode    = kTRUE;  // overwrite existing collections
Int_t       kPluginOutputToRunNumber = 1;     // write the output to subdirs named after run number
// TString kPluginExecutableCommand = "root -b -q";
TString     kPluginExecutableCommand = "source /Users/kleinb/setup_32bit_aliroot_trunk_clean_root_trunk.sh; alienroot -b -q ";

// == grid plugin input and output variables
TString     kGridDatadir      = "/alice/sim/PDC_08b/LHC09a1/AOD/";
TString     kGridLocalRunList = "";
TString     kGridOutdir       = ""; // AliEn output directory. If blank will become output_<kTrainName>
TString     kGridDataSet      = ""; // sub working directory not to confuse different run xmls 
Int_t       kGridRunRange[2]       =  {0, -1}; // Set the run range
TString     kGridRunPattern        = "%03d"; // important for leading zeroes!!
TString     kGridPassPattern       = "";
TString     kGridExtraFiles        = ""; // files that will be added to the input list in the JDL...
Int_t       kGridMaxMergeFiles      = 50; // Number of files merged in a chunkgridrunragn
TString     kGridMergeExclude       = "AliAOD.root"; // Files that should not be merged
TString     kGridOutputStorages      = "disk=2"; // Make replicas on the storages
// == grid process variables
Int_t       kGridRunsPerMaster     = 100; // Number of runs per master job
Int_t       kGridFilesPerJob       = 100; // Maximum number of files per job (gives size of AOD)

//==============================================================================
// ### Local Steering variables
//==============================================================================
//== local setup variables
//== local input and output variables
TString     kLocalXMLDataset   = ""; // Change local xml dataset for local interactive analysis
TString     kLocalDataList   = "local_deltaaod.txt"; // Change local xml dataset for local interactive analysis
// == local process variables



// Temporaries.
TString anaPars = "";
TString anaLibs = "";
TString anaLibsExtra = "";
TString anaSources = "";
// Function signatures
class AliAnalysisAlien;

//______________________________________________________________________________
void AnalysisTrainPWG4Jets(const char *analysis_mode="local", 
			   const char *plugin_mode="",
			   const char *config_file="",Int_t iOffset = 0)
{
// Main analysis train macro. If a configuration file is provided, all parameters
// are taken from there but may be altered by CheckModuleFlags.

   if (strlen(config_file) && !LoadConfig(config_file)) return;

   if(iOffset)kProofOffset = iOffset;
   TString smode(analysis_mode);
   smode.ToUpper();
   if (kSaveTrain)WriteConfig();
   // Check compatibility of selected modules
   CheckModuleFlags(smode);
   //   gROOT->ProcessLine(".trace");

   printf("==================================================================\n");
   printf("===========    RUNNING ANALYSIS TRAIN %s IN %s MODE   ==========\n", kTrainName.Data(),smode.Data());
   printf("==================================================================\n");
   printf("=  Configuring analysis train for:                               =\n");
   if (iAODanalysis) printf("=  AOD analysis                                                  =\n");
   else              printf("=  ESD analysis                                                  =\n");
   if (iPhysicsSelection)   printf("=  Physics selection                                                    =\n");
   if (iESDfilter)   printf("=  ESD filter                                                    =\n");
   if (iJETAN)       printf("=  Jet analysis                                                  =\n");
   printf("==================================================================\n");
   printf(":: use Fill AOD      %d\n", (UInt_t)kFillAOD);
   printf(":: use MC truth      %d\n", (UInt_t)kUseMC);
   printf(":: use KINE filter   %d\n", (UInt_t)kUseKinefilter);
   printf(":: use track refs    %d\n", (UInt_t)kUseTR);
   printf(":: use tags          %d\n", (UInt_t)kUseESDTags);
   printf(":: use AOD tags      %d\n", (UInt_t)kUseAODTags);
   printf(":: use debugging     %d\n", (UInt_t)kUseDebug);
   printf(":: use PAR files     %d\n", (UInt_t)kUsePAR);
   printf(":: use AliEn plugin  %d\n", (UInt_t)kPluginUse);
   printf(":: use PWG1 QA sym       %d\n", iPWG1QASym);
   printf(":: use PWG4 Source Sara  %d\n",iPWG4TmpSourceSara);
   printf(":: use PWG4 Source BB    %d\n",iPWG4TmpSourceFrag);
   printf(":: use PWG4 Jet Chem     %d\n",iPWG4JetChem);
   printf(":: use PWG4 Jet tasks    %d\n",iPWG4JetTasks);
   printf(":: use PWG4 Jet Services %d\n",iPWG4JetServices);     
   printf(":: use PWG4 Jet Spectrum %d\n",iPWG4JetSpectrum);
   printf(":: use PWG4 UE           %d \n",iPWG4UE); 
   printf(":: use PWG4 Pt QA MC     %d\n",iPWG4PtQAMC);
   printf(":: use PWG4 Pt Spectra   %d\n",iPWG4PtSpectra);
   printf(":: use PWG4 Pt QA TPC    %d\n",iPWG4PtQATPC);     
   printf(":: use PWG4 Three Jets   %d\n",iPWG4ThreeJets);
   printf(":: use PWG4 KMeans       %d\n",iPWG4KMeans);
   printf(":: use PWG4 Cluster       %d\n",iPWG4Cluster);
   printf(":: use PWG4 Part Corr    %d\n",iPWG4PartCorr);
   printf(":: use PWG4 Calo QA    %d\n",iPWG4CaloQA);
   printf(":: use PWG4 Jet Corr    %d\n",iPWG4JetCorr);
   printf(":: use PWG4 Tagged       %d\n",iPWG4Tagged);
   printf(":: use PWG4 omega to 3 pions %d\n",iPWG4omega3pi);

   printf(":: use PWG4 Gamma Conv   %d\n",iPWG4GammaConv);
   printf(":: use HighPt FilterMask %d\n",kHighPtFilterMask);    
   
   //==========================================================================
   // Connect to back-end system
   if (!Connect(smode)) {
      ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
      return;
   }   

   // Load common libraries and set include path
   if (!LoadCommonLibraries(smode)) {
      ::Error("AnalysisTrain", "Could not load common libraries");
      return;
   }


    
   // Make the analysis manager and connect event handlers
   AliAnalysisManager *mgr  = new AliAnalysisManager("PWG4Train", "pwg4 mini train");
   if (kCommonOutputFileName.Length()>0)mgr->SetCommonFileName(kCommonOutputFileName.Data());
   if (kProofSaveToAlien) mgr->SetSpecialOutputLocation(kProofOutdir);
   mgr->SetNSysInfo(0);
   if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
   if (kUseSysInfo)mgr->SetNSysInfo(kUseSysInfo);
   mgr->SetSkipTerminate(kSkipTerminate);

   // Load analysis specific libraries
   if (!LoadAnalysisLibraries(smode)) {
      ::Error("AnalysisTrain", "Could not load analysis libraries");
     return;
   }   

   // Create input handler (input container created automatically)
   if (iAODanalysis) {
   // AOD input handler
      AliAODInputHandler *aodH = new AliAODInputHandler();
      mgr->SetInputEventHandler(aodH);
      if (iPWG4JetTasks) aodH->AddFriend(Form("deltas/%s",kDeltaAODJetName.Data()));
      if (iPWG4PartCorr) aodH->AddFriend(Form("deltas/%s"kDeltaAODJetName.Data()));
   } else {   
   // ESD input handler
      AliESDInputHandler *esdHandler = new AliESDInputHandler();
      if (kUseESDTags) esdHandler->SetReadTags();
      esdHandler->SetReadFriends(kFALSE);
      mgr->SetInputEventHandler(esdHandler);       
      //      if(iPWG4PtQATPC&& !kTrainName.Contains("pass5"))esdHandler->SetActiveBranches("ESDfriend");

   }

   // Monte Carlo handler
   if (kUseMC && !iAODanalysis) {
      AliMCEventHandler* mcHandler = new AliMCEventHandler();
      mgr->SetMCtruthEventHandler(mcHandler);
      mcHandler->SetReadTR(kUseTR); 
   }   
   // AOD output container, created automatically when setting an AOD handler
   if (iAODhandler) {
      // AOD output handler
      AliAODHandler* aodHandler   = new AliAODHandler();
      aodHandler->SetOutputFileName("AliAOD.root");
      aodHandler->SetFillAODforRun(kFillAOD);
      
      mgr->SetOutputEventHandler(aodHandler);
      //
      if (iAODanalysis) {

	//         aodHandler->SetCreateNonStandardAOD();
	//	if (iJETAN)aodHandler->SetOutputFileName(kDeltaAODJetName.Data());
      } 
      AliAnalysisDataContainer * cout_aod = mgr->GetCommonOutputContainer();
      cout_aod->SetSpecialOutput();
   }
   // Debugging if needed

   if (kUseDebug){
     mgr->SetDebugLevel(3);
   }
   else{
     AliLog::SetGlobalLogLevel(AliLog::kError);
   }
   //==========================================================================
   // Create the chain. In this example it is created only from ALIEN files but
   // can be done to work in batch or grid mode as well.
   TChain *chain = CreateChain(smode, plugin_mode);
        
   //==========================================================================
   // Load the tasks configuration macros for all wagons. These files are supposed now to be
   // in the current workdir, but in AliEn they will be in the file catalog, 
   // mapped from AliRoot and pecified in the jdl input list.
    
   // For now connection to top input container and common AOD output container
   // is done in this macro, but in future these containers will be connected
   // from each task configuration macro.
   if(iPhysicsSelection && !iAODanalysis){
     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
     AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kIsMC,kTRUE);
   }

   if (iESDfilter && !iAODanalysis) {
      //  ESD filter task configuration.
      gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
      AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
   }   

   // AOD tags
   if (kUseAODTags) {
      AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
      mgr->AddTask(tagTask);
      AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag",  TTree::Class(), 
                                           AliAnalysisManager::kOutputContainer, "AOD.tag.root");
      mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
      mgr->ConnectOutput(tagTask, 1, coutTags);
   }   
    
    // Jet analysis
   if (iJETAN) {
      gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
      AliAnalysisTaskJets *taskjets = 0;
      if(iJETAN&1)taskjets = AddTaskJets(kHighPtFilterMask); 
      if(iJETAN&2){
	UInt_t selection = 0;
	if(!kFillAOD) selection = 0xffffff; //&~(1<<13);
	else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9;
	AddTaskJetsDelta(kDeltaAODJetName.Data(),kHighPtFilterMask,kUseAODMC,selection); 
      }
      if (!taskjets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
   }

   if (iDIJETAN) {
      gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskDiJets.C");
      AliAnalysisTaskDiJets *taskdijets = 0;
      taskdijets = AddTaskDiJets(); 
      if (!taskdijets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG1QASym){
     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PWG1macros/AddTaskQAsym.C");
     AliAnalysisTaskQASym *taskQASym = AddTaskQAsym(-1);
     if (!taskQASym) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQASym cannot run for this train conditions - EXCLUDED");
   }



   if(iPWG4TmpSourceSara){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskEta.C");
     AliAnalysisTaskEta *taskEta = AddTaskEta();
     if (!taskEta) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskEta cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4TmpSourceFrag){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskFragFunc.C");
     UInt_t selection = 1<<2;
     AliAnalysisTaskFragFunc *taskFrag = AddTaskFragFunc(kHighPtFilterMask, kUseAODMC,iPhysicsSelection, selection);
     if (!taskFrag) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskFragFunc cannot run for this train conditions - EXCLUDED");
   }


   if(iPWG4JetChem){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetChem.C");
     AliAnalysisTask *taskChem = AddTaskJetChem();
     if (!taskChem) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetChem cannot run for this train conditions - EXCLUDED");
   }


   if(iPWG4JetServices){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetServices.C");
     AliAnalysisTaskJetServices *taskjetServ = 0;
     taskjetServ = AddTaskJetServices();
     if (!taskjetServ) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetServices cannot run for this train conditions - EXCLUDED");
     if(kGridRunRange[0]>0)taskjetServ->SetRunRange(kGridRunRange[0],kGridRunRange[1]);
     else taskjetServ->SetRunRange(104000,125000);
     if(!kIsMC) taskjetServ->SetRealData(kTRUE);
     taskjetServ->SetUsePhysicsSelection((Bool_t)iPhysicsSelection);
     taskjetServ->SetDebugLevel(0);
   }

   if(iPWG4JetSpectrum){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetSpectrum2.C");
     AliAnalysisTaskJetSpectrum2 *taskjetSpectrum = 0;
     if(iPWG4JetSpectrum&1){
       taskjetSpectrum = AddTaskJetSpectrum2("jets","",kHighPtFilterMask,iPhysicsSelection);      
       if(!iAODanalysis){
	 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks32",32,iPhysicsSelection);       // tmp hack to give it a different name
	 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks64",64,iPhysicsSelection);      
       }
       if (!taskjetSpectrum) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetSpectrum2 cannot run for this train conditions - EXCLUDED");
       taskjetSpectrum->SetDebugLevel(1);
     }

     if(iPWG4JetSpectrum&2){
       UInt_t selection = 0;
       if(!iAODanalysis) selection = 0xffffff;
       else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
       AddTaskJetSpectrum2Delta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,selection);
     }
     if(iJETAN==3&&!kFillAOD&!iAODanalysis){
       AddTaskJetSpectrum2("jetsAOD_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
       if(kIsMC){
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
       }
     }
   }
   if(iPWG4UE){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
     AliAnalysisTaskUE *taskUE = 0;
     if(iPWG4UE&1)taskUE = AddTaskUE(); 
     if(iPWG4UE&2){
       taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJ","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJCC","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJ","TRANSV","MAP"); 
       taskUE = AddTaskUE("jetsAOD_ICDF","CDF","LJ","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_ICDF","CDF","LJCC","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_ICDF","CDF","LJCC","TRANSV","MAP"); 
       taskUE = AddTaskUE("jetsAOD_NONE","CDF","MP","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_NONE","CDF","MP","TRANSV","MAP");
       taskUE = AddTaskUE("jetsAOD_FASTKT04","CDF","LJ","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_FASTKT04","CDF","LJ","TRANSV","MAP");
     }

     if (!taskUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskUE cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4ThreeJets){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskThreeJets.C");
     AliAnalysisTaskThreeJets *taskThree = AddTaskThreeJets();
     if(!taskThree)::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskThreets cannot run for this train conditions - EXCLUDED");
   }
   if(iPWG4PtQAMC){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQAMC.C");
     AliPWG4HighPtQAMC *taskQAMC = AddTaskPWG4HighPtQAMC();
     if (!taskQAMC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQAMC cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4PtQATPC){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQATPConly.C");
     AliPWG4HighPtQATPConly *taskQATPC = AddTaskPWG4HighPtQATPConly();
     if (!taskQATPC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQATPC cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4PtSpectra){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtSpectra.C");
     AliPWG4HighPtSpectra *taskPtSpectra = AddTaskPWG4HighPtSpectra();
     if (!taskPtSpectra) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskPtSpectra cannot run for this train conditions - EXCLUDED");
   }
   if(iPWG4KMeans){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskKMeans.C");
     AliAnalysisTaskKMeans *taskKMeans = AddTaskKMeans();
     if (!taskKMeans) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskKMenans cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4Cluster){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCluster.C");
     AliAnalysisTaskJetCluster *taskCl = 0;
     if(iPWG4Cluster&1){
       taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelection,"KT");
     }
     if(iPWG4Cluster&2){
       UInt_t selection = 0;
       if(!iAODanalysis) selection = 0xffffff;
       else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
       AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"KT",selection);
     }
     if(iPWG4Cluster&4){
       UInt_t selection = 0;
       if(!iAODanalysis) selection = 0xffffff;
       else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
       taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelection,"CA");
       AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"CA",selection);
     }


     if (!taskCl) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskCluster cannot run for this train conditions - EXCLUDED");

   }
   if(iPWG4PartCorr){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
     AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS",kFALSE,kIsMC);
     if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
     AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL",kFALSE,kIsMC);
     if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
     if(kDeltaAODPartCorrName.Length()>0)mgr->RegisterExtraFile(kDeltaAODPartCorrName.Data()); // hmm this is written anyway.... but at least we do not register it...
   } 

   if(iPWG4CaloQA){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
     AliAnalysisTaskParticleCorrelation *taskcaloQA =  AddTaskCalorimeterQA("ESD",kFALSE,kIsMC);
     if(!taskcaloQA)::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation QA cannot run - EXCLUDED");
   } 

   if(iPWG4JetCorr){
     //     using namespace JetCorrelHD;

     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCorrel.C");
     AliAnalysisTaskJetCorrel *taskjetcorr = AddTaskJetCorrel();
     if (!taskjetcorr) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJetCorrel  cannot run for this train conditions - EXCLUDED");
   } 

   if(iPWG4Tagged){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskTaggedPhotons.C");
     AliAnalysisTaskTaggedPhotons * taskTagged = AddTaskTaggedPhotons(kFALSE); // EMCAL
     //     taskTagged = AddTaskTaggedPhotons(kTRUE); // PHOS 
     if (!taskTagged) ::Warning("AnalysisTrainNew", "AliAnalysisTaskTaggedPhotons  cannot run for this train conditions - EXCLUDED");     
   }
   if (iPWG4omega3pi) {
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
     AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
     if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run\
 for these train conditions - EXCLUDED");
   }

   // PWG4 gamma conversion analysis
   if (iPWG4GammaConv) {
      gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
      TString cdir = gSystem->WorkingDirectory();
      gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
      //      TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
      TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz -bg-off";<commit_msg>taking out -bg-off option for GammaConv, adapt new argument for physicsselection<commit_after>//===================== ANALYSIS TRAIN =========================================
// To use: copy this macro to your work directory, modify the global part to match
// your needs, then run root.
//    root[0] .L AnalysisTrain.C
// Grid full mode as below (other modes: test, offline, submit, terminate)
//    root[1] AnalysisTrainPWG-244Jets("grid", "full")
// CAF mode (requires root v5-23-02 + aliroot v4-16-Rev08)
//    root[2] AnalysisTrainPWG4Jets("proof")
// Local mode requires AliESds.root or AliAOD.root in ./data directory
//    root[3] AnalysisTrainPWG4Jets("local")
// In proof and grid modes, a token is needed and sourcing the produced environment file.
//
// If 'saveTrain' flag is set, the train will generate a directory name and run
// in this directory. A configuration file 'ConfigTrain.C' will be generated. 
// One can replay at any time the train via:
//    root[1] AnalysisTrainPWG4Jets(ana_mode, plugin_mode, "train_default_<date>/ConfigTrain.C")

// For Usage with fastjet run in "offline" first and then "submit"
// jdl and analysismacro are automatically patched after "offline" mode

// =============================================================================
// ### General Steering variables
// =============================================================================
//== general setup variables
TString     kTrainName         = "testAnalysis"; // *CHANGE ME* (no blancs or special characters)
TString     kJobTag            = "PWG4 Jet Tasks analysis train configured"; // *CHANGE ME*

// Usage of par files ONLY in grid mode and ONLY if the code is not available
// in the deployed AliRoot versions. Par file search path: local dir, if not there $ALICE_ROOT.
// To refresh par files, remove the ones in the workdir, then do "make <target.par>" in 
// AliRoot.
Bool_t      kUsePAR             = kFALSE;  // use par files for extra libs
Bool_t      kUseCPAR            = kFALSE;  // use par files for common libs
Bool_t      kFillAOD = kFALSE;  // switch of AOD filling for on the fly analysis

//== general input and output variables

Int_t       iAODanalysis       = 1;      // Analysis on input AOD's
Int_t       iAODhandler        = 1;      // Analysis produces an AOD or dAOD's
Int_t       iESDfilter         = 0;      // ESD to AOD filter (barrel + muon tracks)
Int_t       iPhysicsSelection  = 1;      // ESD to AOD filter (barrel + muon tracks)
Bool_t      kUseKinefilter     = kFALSE; // use Kinematics filter
Bool_t      kUseMuonfilter     = kFALSE; // use Kinematics filter
TString     kCommonOutputFileName = "PWG4_JetTasksOutput.root";


//== general process variables

// ### Other flags to steer the analysis
//==============================================================================
Bool_t      kSkipTerminate      = kTRUE; // Do not call Teminate
Bool_t      kUseDate            = kFALSE; // use date in train name
Bool_t      kUseDebug           = kTRUE; // activate debugging
Int_t       kUseSysInfo         = 0; // activate debugging
Bool_t      kUseMC              = kTRUE;  // use MC info
Bool_t      kIsMC               = kTRUE;  // is MC info, if false it overwrites Use(AOD)MC
Bool_t      kUseAODMC           = kTRUE;  // use MC infA
Bool_t      kUseESDTags         = kFALSE; // use ESD tags for selection
Bool_t      kUseTR              = kFALSE;  // use track references
Bool_t      kUseAODTags         = kFALSE;  // use AOD tags
Bool_t      kSaveTrain          = kFALSE;  // save train configuration as: 


// ### Analysis modules to be included. Some may not be yet fully implemented.
//==============================================================================
Int_t       iJETAN             = 1;      // Jet analysis (PWG4) // 1 write standard 2 write non-standard jets, 3 wrtie both
Int_t       iDIJETAN           = 1;
Int_t       iJETANLib          = 1;
Int_t       iPWG1QASym         = 0;      // Eva's QA task compiled on the fly...
Int_t       iPWG4JetTasks      = 0;      // all jet tasks flag for lib laoding
Int_t       iPWG4JetServices   = 0;      // jet spectrum analysis
Int_t       iPWG4JetSpectrum   = 0;      // jet spectrum analysis
Int_t       iPWG4UE            = 0;      // Underlying Event analysis
Int_t       iPWG4TmpSourceSara = 0;      // Underlying Event analysis not in svn
Int_t       iPWG4TmpSourceFrag = 0;      // Bastian's Fragmentation function not in svn
Int_t       iPWG4JetChem       = 0;      // Jet chemistry 
Int_t       iPWG4PtQAMC        = 0;      // Marta's QA tasks 
Int_t       iPWG4PtSpectra     = 0;      // Marta's QA tasks 
Int_t       iPWG4PtQATPC       = 0;      // Marta's QA tasks 
Int_t       iPWG4ThreeJets     = 0;      // Sona's thrust task
Int_t       iPWG4KMeans        = 0;      // Andreas' KMeans task 
Int_t       iPWG4Cluster       = 0;      // CKB cluster task 
Int_t       iPWG4PartCorrLibs  = 0;      // Gustavo's part corr analysis
Int_t       iPWG4PartCorr      = 0;      // Gustavo's part corr analysis
Int_t       iPWG4CaloQA        = 0;      // Gustavo's part corr analysis
Int_t       iPWG4JetCorr       = 0;     // Paul's jet corr analysis
Int_t       iPWG4Tagged        = 0;      // Gustavo's part corr analysis
Int_t       iPWG4omega3pi      = 0;      // Omega to 3 pi analysis (PWG4) 
Int_t       iPWG4GammaConv     = 0;      // Gamma Conversio
Int_t       kHighPtFilterMask  = 16;     // change depending on the used AOD Filter
TString     kDeltaAODJetName   = "AliAOD.Jets.root";     
TString     kDeltaAODPartCorrName   = "deltaAODPartCorr.root";     


//==============================================================================
// ### PROOF Steering varibales
//==============================================================================
//== proof setup variables
TString     kProofCluster      = "alicecaf.cern.ch";
Bool_t      kProofUseAFPAR     = kFALSE;  // use AF special par file
TString     kProofAFversion          = "AF-v4-17";
//== proof input and output variables
TString     kProofDataSet      = "/COMMON/COMMON/LHC09a4_run8100X#/esdTree";
Bool_t      kProofSaveToAlien   = kFALSE; // save proof outputs in AliEn train_[trainName]_ddMonthyyyy_time.C
TString     kProofOutdir       = "";
Bool_t      kProofClearPackages = kFALSE;
Int_t       kProofEvents = 10000;
Int_t       kProofOffset = 0;
//== proof process variables


//==============================================================================
// ### Grid plugin Steering varibiables
//==============================================================================
//== grid plugin setup variables
Bool_t      kPluginUse         = kTRUE;   // do not change
Bool_t      kPluginUseProductionMode  = kFALSE;   // use the plugin in production mode
TString     kPluginRootVersion       = "v5-26-00b-2";  // *CHANGE ME IF MORE RECENT IN GRID*
TString     kPluginAliRootVersion    = "v4-19-04-AN";  // *CHANGE ME IF MORE RECENT IN GRID*                                          
Bool_t      kPluginMergeViaJDL       = kTRUE;  // merge via JDL
Bool_t      kPluginFastReadOption   = kFALSE;  // use xrootd tweaks
Bool_t      kPluginOverwriteMode    = kTRUE;  // overwrite existing collections
Int_t       kPluginOutputToRunNumber = 1;     // write the output to subdirs named after run number
// TString kPluginExecutableCommand = "root -b -q";
TString     kPluginExecutableCommand = "source /Users/kleinb/setup_32bit_aliroot_trunk_clean_root_trunk.sh; alienroot -b -q ";

// == grid plugin input and output variables
TString     kGridDatadir      = "/alice/sim/PDC_08b/LHC09a1/AOD/";
TString     kGridLocalRunList = "";
TString     kGridOutdir       = ""; // AliEn output directory. If blank will become output_<kTrainName>
TString     kGridDataSet      = ""; // sub working directory not to confuse different run xmls 
Int_t       kGridRunRange[2]       =  {0, -1}; // Set the run range
TString     kGridRunPattern        = "%03d"; // important for leading zeroes!!
TString     kGridPassPattern       = "";
TString     kGridExtraFiles        = ""; // files that will be added to the input list in the JDL...
Int_t       kGridMaxMergeFiles      = 50; // Number of files merged in a chunkgridrunragn
TString     kGridMergeExclude       = "AliAOD.root"; // Files that should not be merged
TString     kGridOutputStorages      = "disk=2"; // Make replicas on the storages
// == grid process variables
Int_t       kGridRunsPerMaster     = 100; // Number of runs per master job
Int_t       kGridFilesPerJob       = 100; // Maximum number of files per job (gives size of AOD)

//==============================================================================
// ### Local Steering variables
//==============================================================================
//== local setup variables
//== local input and output variables
TString     kLocalXMLDataset   = ""; // Change local xml dataset for local interactive analysis
TString     kLocalDataList   = "local_deltaaod.txt"; // Change local xml dataset for local interactive analysis
// == local process variables



// Temporaries.
TString anaPars = "";
TString anaLibs = "";
TString anaLibsExtra = "";
TString anaSources = "";
// Function signatures
class AliAnalysisAlien;

//______________________________________________________________________________
void AnalysisTrainPWG4Jets(const char *analysis_mode="local", 
			   const char *plugin_mode="",
			   const char *config_file="",Int_t iOffset = 0)
{
// Main analysis train macro. If a configuration file is provided, all parameters
// are taken from there but may be altered by CheckModuleFlags.

   if (strlen(config_file) && !LoadConfig(config_file)) return;

   if(iOffset)kProofOffset = iOffset;
   TString smode(analysis_mode);
   smode.ToUpper();
   if (kSaveTrain)WriteConfig();
   // Check compatibility of selected modules
   CheckModuleFlags(smode);
   //   gROOT->ProcessLine(".trace");

   printf("==================================================================\n");
   printf("===========    RUNNING ANALYSIS TRAIN %s IN %s MODE   ==========\n", kTrainName.Data(),smode.Data());
   printf("==================================================================\n");
   printf("=  Configuring analysis train for:                               =\n");
   if (iAODanalysis) printf("=  AOD analysis                                                  =\n");
   else              printf("=  ESD analysis                                                  =\n");
   if (iPhysicsSelection)   printf("=  Physics selection                                                    =\n");
   if (iESDfilter)   printf("=  ESD filter                                                    =\n");
   if (iJETAN)       printf("=  Jet analysis                                                  =\n");
   printf("==================================================================\n");
   printf(":: use Fill AOD      %d\n", (UInt_t)kFillAOD);
   printf(":: use MC truth      %d\n", (UInt_t)kUseMC);
   printf(":: use KINE filter   %d\n", (UInt_t)kUseKinefilter);
   printf(":: use track refs    %d\n", (UInt_t)kUseTR);
   printf(":: use tags          %d\n", (UInt_t)kUseESDTags);
   printf(":: use AOD tags      %d\n", (UInt_t)kUseAODTags);
   printf(":: use debugging     %d\n", (UInt_t)kUseDebug);
   printf(":: use PAR files     %d\n", (UInt_t)kUsePAR);
   printf(":: use AliEn plugin  %d\n", (UInt_t)kPluginUse);
   printf(":: use PWG1 QA sym       %d\n", iPWG1QASym);
   printf(":: use PWG4 Source Sara  %d\n",iPWG4TmpSourceSara);
   printf(":: use PWG4 Source BB    %d\n",iPWG4TmpSourceFrag);
   printf(":: use PWG4 Jet Chem     %d\n",iPWG4JetChem);
   printf(":: use PWG4 Jet tasks    %d\n",iPWG4JetTasks);
   printf(":: use PWG4 Jet Services %d\n",iPWG4JetServices);     
   printf(":: use PWG4 Jet Spectrum %d\n",iPWG4JetSpectrum);
   printf(":: use PWG4 UE           %d \n",iPWG4UE); 
   printf(":: use PWG4 Pt QA MC     %d\n",iPWG4PtQAMC);
   printf(":: use PWG4 Pt Spectra   %d\n",iPWG4PtSpectra);
   printf(":: use PWG4 Pt QA TPC    %d\n",iPWG4PtQATPC);     
   printf(":: use PWG4 Three Jets   %d\n",iPWG4ThreeJets);
   printf(":: use PWG4 KMeans       %d\n",iPWG4KMeans);
   printf(":: use PWG4 Cluster       %d\n",iPWG4Cluster);
   printf(":: use PWG4 Part Corr    %d\n",iPWG4PartCorr);
   printf(":: use PWG4 Calo QA    %d\n",iPWG4CaloQA);
   printf(":: use PWG4 Jet Corr    %d\n",iPWG4JetCorr);
   printf(":: use PWG4 Tagged       %d\n",iPWG4Tagged);
   printf(":: use PWG4 omega to 3 pions %d\n",iPWG4omega3pi);

   printf(":: use PWG4 Gamma Conv   %d\n",iPWG4GammaConv);
   printf(":: use HighPt FilterMask %d\n",kHighPtFilterMask);    
   
   //==========================================================================
   // Connect to back-end system
   if (!Connect(smode)) {
      ::Error("AnalysisTrain", "Could not connect to %s back-end", analysis_mode);
      return;
   }   

   // Load common libraries and set include path
   if (!LoadCommonLibraries(smode)) {
      ::Error("AnalysisTrain", "Could not load common libraries");
      return;
   }


    
   // Make the analysis manager and connect event handlers
   AliAnalysisManager *mgr  = new AliAnalysisManager("PWG4Train", "pwg4 mini train");
   if (kCommonOutputFileName.Length()>0)mgr->SetCommonFileName(kCommonOutputFileName.Data());
   if (kProofSaveToAlien) mgr->SetSpecialOutputLocation(kProofOutdir);
   mgr->SetNSysInfo(0);
   if (!strcmp(plugin_mode, "test")) mgr->SetNSysInfo(1);
   if (kUseSysInfo)mgr->SetNSysInfo(kUseSysInfo);
   mgr->SetSkipTerminate(kSkipTerminate);

   // Load analysis specific libraries
   if (!LoadAnalysisLibraries(smode)) {
      ::Error("AnalysisTrain", "Could not load analysis libraries");
     return;
   }   

   // Create input handler (input container created automatically)
   if (iAODanalysis) {
   // AOD input handler
      AliAODInputHandler *aodH = new AliAODInputHandler();
      mgr->SetInputEventHandler(aodH);
      if (iPWG4JetTasks) aodH->AddFriend(Form("deltas/%s",kDeltaAODJetName.Data()));
      if (iPWG4PartCorr) aodH->AddFriend(Form("deltas/%s"kDeltaAODJetName.Data()));
   } else {   
   // ESD input handler
      AliESDInputHandler *esdHandler = new AliESDInputHandler();
      if (kUseESDTags) esdHandler->SetReadTags();
      esdHandler->SetReadFriends(kFALSE);
      mgr->SetInputEventHandler(esdHandler);       
      //      if(iPWG4PtQATPC&& !kTrainName.Contains("pass5"))esdHandler->SetActiveBranches("ESDfriend");

   }

   // Monte Carlo handler
   if (kUseMC && !iAODanalysis) {
      AliMCEventHandler* mcHandler = new AliMCEventHandler();
      mgr->SetMCtruthEventHandler(mcHandler);
      mcHandler->SetReadTR(kUseTR); 
   }   
   // AOD output container, created automatically when setting an AOD handler
   if (iAODhandler) {
      // AOD output handler
      AliAODHandler* aodHandler   = new AliAODHandler();
      aodHandler->SetOutputFileName("AliAOD.root");
      aodHandler->SetFillAODforRun(kFillAOD);
      
      mgr->SetOutputEventHandler(aodHandler);
      //
      if (iAODanalysis) {

	//         aodHandler->SetCreateNonStandardAOD();
	//	if (iJETAN)aodHandler->SetOutputFileName(kDeltaAODJetName.Data());
      } 
      AliAnalysisDataContainer * cout_aod = mgr->GetCommonOutputContainer();
      cout_aod->SetSpecialOutput();
   }
   // Debugging if needed

   if (kUseDebug){
     mgr->SetDebugLevel(3);
   }
   else{
     AliLog::SetGlobalLogLevel(AliLog::kError);
   }
   //==========================================================================
   // Create the chain. In this example it is created only from ALIEN files but
   // can be done to work in batch or grid mode as well.
   TChain *chain = CreateChain(smode, plugin_mode);
        
   //==========================================================================
   // Load the tasks configuration macros for all wagons. These files are supposed now to be
   // in the current workdir, but in AliEn they will be in the file catalog, 
   // mapped from AliRoot and pecified in the jdl input list.
    
   // For now connection to top input container and common AOD output container
   // is done in this macro, but in future these containers will be connected
   // from each task configuration macro.
   if(iPhysicsSelection && !iAODanalysis){
     gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskPhysicsSelection.C");
     AliPhysicsSelectionTask* physSelTask = AddTaskPhysicsSelection(kIsMC,kTRUE,kTRUE); // last flag also adds information on  
   }

   if (iESDfilter && !iAODanalysis) {
      //  ESD filter task configuration.
      gROOT->LoadMacro("$ALICE_ROOT/ANALYSIS/macros/AddTaskESDFilter.C");
      AliAnalysisTaskESDfilter *taskesdfilter = AddTaskESDFilter(kUseKinefilter,kUseMuonfilter);
   }   

   // AOD tags
   if (kUseAODTags) {
      AliAnalysisTaskTagCreator* tagTask = new AliAnalysisTaskTagCreator("AOD Tag Creator");
      mgr->AddTask(tagTask);
      AliAnalysisDataContainer *coutTags = mgr->CreateContainer("cTag",  TTree::Class(), 
                                           AliAnalysisManager::kOutputContainer, "AOD.tag.root");
      mgr->ConnectInput (tagTask, 0, mgr->GetCommonInputContainer());
      mgr->ConnectOutput(tagTask, 1, coutTags);
   }   
    
    // Jet analysis
   if (iJETAN) {
      gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJets.C");
      AliAnalysisTaskJets *taskjets = 0;
      if(iJETAN&1)taskjets = AddTaskJets(kHighPtFilterMask); 
      if(iJETAN&2){
	UInt_t selection = 0;
	if(!kFillAOD) selection = 0xffffff; //&~(1<<13);
	else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9;
	AddTaskJetsDelta(kDeltaAODJetName.Data(),kHighPtFilterMask,kUseAODMC,selection); 
      }
      if (!taskjets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
   }

   if (iDIJETAN) {
      gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskDiJets.C");
      AliAnalysisTaskDiJets *taskdijets = 0;
      taskdijets = AddTaskDiJets(); 
      if (!taskdijets) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJets cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG1QASym){
     gROOT->LoadMacro("$ALICE_ROOT/PWG1/PWG1macros/AddTaskQAsym.C");
     AliAnalysisTaskQASym *taskQASym = AddTaskQAsym(-1);
     if (!taskQASym) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQASym cannot run for this train conditions - EXCLUDED");
   }



   if(iPWG4TmpSourceSara){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskEta.C");
     AliAnalysisTaskEta *taskEta = AddTaskEta();
     if (!taskEta) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskEta cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4TmpSourceFrag){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskFragFunc.C");
     UInt_t selection = 1<<2;
     AliAnalysisTaskFragFunc *taskFrag = AddTaskFragFunc(kHighPtFilterMask, kUseAODMC,iPhysicsSelection, selection);
     if (!taskFrag) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskFragFunc cannot run for this train conditions - EXCLUDED");
   }


   if(iPWG4JetChem){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetChem.C");
     AliAnalysisTask *taskChem = AddTaskJetChem();
     if (!taskChem) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetChem cannot run for this train conditions - EXCLUDED");
   }


   if(iPWG4JetServices){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetServices.C");
     AliAnalysisTaskJetServices *taskjetServ = 0;
     taskjetServ = AddTaskJetServices();
     if (!taskjetServ) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetServices cannot run for this train conditions - EXCLUDED");
     if(kGridRunRange[0]>0)taskjetServ->SetRunRange(kGridRunRange[0],kGridRunRange[1]);
     else taskjetServ->SetRunRange(104000,125000);
     if(!kIsMC) taskjetServ->SetRealData(kTRUE);
     taskjetServ->SetUsePhysicsSelection((Bool_t)iPhysicsSelection);
     taskjetServ->SetDebugLevel(0);
   }

   if(iPWG4JetSpectrum){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetSpectrum2.C");
     AliAnalysisTaskJetSpectrum2 *taskjetSpectrum = 0;
     if(iPWG4JetSpectrum&1){
       taskjetSpectrum = AddTaskJetSpectrum2("jets","",kHighPtFilterMask,iPhysicsSelection);      
       if(!iAODanalysis){
	 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks32",32,iPhysicsSelection);       // tmp hack to give it a different name
	 taskjetSpectrum = AddTaskJetSpectrum2("jets","tracks64",64,iPhysicsSelection);      
       }
       if (!taskjetSpectrum) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskJetSpectrum2 cannot run for this train conditions - EXCLUDED");
       taskjetSpectrum->SetDebugLevel(1);
     }

     if(iPWG4JetSpectrum&2){
       UInt_t selection = 0;
       if(!iAODanalysis) selection = 0xffffff;
       else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
       AddTaskJetSpectrum2Delta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,selection);
     }
     if(iJETAN==3&&!kFillAOD&!iAODanalysis){
       AddTaskJetSpectrum2("jetsAOD_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
       AddTaskJetSpectrum2("jetsAOD_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
       if(kIsMC){
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT00","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT01","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT02","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT06","",kHighPtFilterMask,iPhysicsSelection);
	 AddTaskJetSpectrum2("jetsAODMC2b_FASTKT08","",kHighPtFilterMask,iPhysicsSelection);
       }
     }
   }
   if(iPWG4UE){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskUE.C");
     AliAnalysisTaskUE *taskUE = 0;
     if(iPWG4UE&1)taskUE = AddTaskUE(); 
     if(iPWG4UE&2){
       taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJ","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJCC","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_CDF07","CDF","LJ","TRANSV","MAP"); 
       taskUE = AddTaskUE("jetsAOD_ICDF","CDF","LJ","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_ICDF","CDF","LJCC","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_ICDF","CDF","LJCC","TRANSV","MAP"); 
       taskUE = AddTaskUE("jetsAOD_NONE","CDF","MP","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_NONE","CDF","MP","TRANSV","MAP");
       taskUE = AddTaskUE("jetsAOD_FASTKT04","CDF","LJ","TRANSV","MSP"); 
       taskUE = AddTaskUE("jetsAOD_FASTKT04","CDF","LJ","TRANSV","MAP");
     }

     if (!taskUE) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskUE cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4ThreeJets){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskThreeJets.C");
     AliAnalysisTaskThreeJets *taskThree = AddTaskThreeJets();
     if(!taskThree)::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskThreets cannot run for this train conditions - EXCLUDED");
   }
   if(iPWG4PtQAMC){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQAMC.C");
     AliPWG4HighPtQAMC *taskQAMC = AddTaskPWG4HighPtQAMC();
     if (!taskQAMC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQAMC cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4PtQATPC){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtQATPConly.C");
     AliPWG4HighPtQATPConly *taskQATPC = AddTaskPWG4HighPtQATPConly();
     if (!taskQATPC) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskQATPC cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4PtSpectra){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPWG4HighPtSpectra.C");
     AliPWG4HighPtSpectra *taskPtSpectra = AddTaskPWG4HighPtSpectra();
     if (!taskPtSpectra) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskPtSpectra cannot run for this train conditions - EXCLUDED");
   }
   if(iPWG4KMeans){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskKMeans.C");
     AliAnalysisTaskKMeans *taskKMeans = AddTaskKMeans();
     if (!taskKMeans) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskKMenans cannot run for this train conditions - EXCLUDED");
   }

   if(iPWG4Cluster){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCluster.C");
     AliAnalysisTaskJetCluster *taskCl = 0;
     if(iPWG4Cluster&1){
       taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelection,"KT");
     }
     if(iPWG4Cluster&2){
       UInt_t selection = 0;
       if(!iAODanalysis) selection = 0xffffff;
       else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
       AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"KT",selection);
     }
     if(iPWG4Cluster&4){
       UInt_t selection = 0;
       if(!iAODanalysis) selection = 0xffffff;
       else selection = 1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<7|1<<8|1<<9;
       taskCl = AddTaskJetCluster("AOD","",kHighPtFilterMask,iPhysicsSelection,"CA");
       AddTaskJetClusterDelta(kHighPtFilterMask,kUseAODMC,iPhysicsSelection,"CA",selection);
     }


     if (!taskCl) ::Warning("AnalysisTrainPWG4Jets", "AliAnalysisTaskCluster cannot run for this train conditions - EXCLUDED");

   }
   if(iPWG4PartCorr){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskPartCorr.C");
     AliAnalysisTaskParticleCorrelation *taskpartcorrPHOS = AddTaskPartCorr("AOD", "PHOS",kFALSE,kIsMC);
     if (!taskpartcorrPHOS) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation PHOS cannot run for this train conditions - EXCLUDED");
     AliAnalysisTaskParticleCorrelation *taskpartcorrEMCAL = AddTaskPartCorr("AOD", "EMCAL",kFALSE,kIsMC);
     if (!taskpartcorrEMCAL) ::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation EMCAL cannot run for this train conditions - EXCLUDED");
     if(kDeltaAODPartCorrName.Length()>0)mgr->RegisterExtraFile(kDeltaAODPartCorrName.Data()); // hmm this is written anyway.... but at least we do not register it...
   } 

   if(iPWG4CaloQA){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/QA/AddTaskCalorimeterQA.C");
     AliAnalysisTaskParticleCorrelation *taskcaloQA =  AddTaskCalorimeterQA("ESD",kFALSE,kIsMC);
     if(!taskcaloQA)::Warning("AnalysisTrainNew", "AliAnalysisTaskParticleCorrelation QA cannot run - EXCLUDED");
   } 

   if(iPWG4JetCorr){
     //     using namespace JetCorrelHD;

     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskJetCorrel.C");
     AliAnalysisTaskJetCorrel *taskjetcorr = AddTaskJetCorrel();
     if (!taskjetcorr) ::Warning("AnalysisTrainNew", "AliAnalysisTaskJetCorrel  cannot run for this train conditions - EXCLUDED");
   } 

   if(iPWG4Tagged){
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskTaggedPhotons.C");
     AliAnalysisTaskTaggedPhotons * taskTagged = AddTaskTaggedPhotons(kFALSE); // EMCAL
     //     taskTagged = AddTaskTaggedPhotons(kTRUE); // PHOS 
     if (!taskTagged) ::Warning("AnalysisTrainNew", "AliAnalysisTaskTaggedPhotons  cannot run for this train conditions - EXCLUDED");     
   }
   if (iPWG4omega3pi) {
     gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskomega3pi.C");
     AliAnalysisTaskOmegaPi0PiPi *taskomega3pi = AddTaskomega3pi();
     if (!taskomega3pi) ::Warning("AnalysisTrainNew", "AliAnalysisTaskomega3pi cannot run\
 for these train conditions - EXCLUDED");
   }

   // PWG4 gamma conversion analysis
   if (iPWG4GammaConv) {
      gROOT->LoadMacro("$ALICE_ROOT/PWG4/macros/AddTaskGammaConversion.C");
      TString cdir = gSystem->WorkingDirectory();
      gSystem->ChangeDirectory(gSystem->ExpandPathName("$ALICE_ROOT/PWG4/macros/"));
      //      TString gcArguments = "-run-on-train -run-jet -run-chic -run-neutralmeson -run-cf";
      TString gcArguments = "-run-on-train -run-jet -run-neutralmeson -run-cf -use-own-xyz";
{'fraction_non_alphanumeric': 0.15920095770722031, 'fraction_numerical': 0.01611664016295317, 'mean_word_length': 3.4366230677764564, 'pattern_counts': {'":': 60, '<': 165, '<?xml version=': 0, '>': 139, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1767241', 'n_tokens_mistral': 19282, 'n_tokens_neox': 17985, 'n_words': 3962}