<commit_before>// Configuration macro for analysis of isolated photon spectra
// Author : <NAME>;  <NAME>.

TString kAnaIsoPhotonName = "";
Int_t   kDebug         = -1;
TString kCalorimeter   = "EMCAL";
TString kData = "";
TString kPrint = 0 ;
 
AliAnalysisTaskCaloTrackCorrelation *AddTaskIsoPhoton(const Float_t  cone          = 0.4,
                                                      const Float_t  pth           = 2.,
                                                      const Bool_t   leading       = kFALSE,
                                                      const Bool_t   timecut       = kFALSE,
                                                      const TString  calorimeter   = "EMCAL",
                                                      const Bool_t   simu          = kFALSE,
                                                      const Bool_t   exotic        = kTRUE,
                                                      const Bool_t   nonlin        = kFALSE,
                                                      const TString  trigger       = "EMC7",
                                                      const Bool_t   tm            = kTRUE,
                                                      const Int_t    minCen        = -1,
                                                      const Int_t    maxCen        = -1,
                                                      const Float_t  deltaphicut   = 0.03,
                                                      const Float_t  deltaetacut   = 0.02,
                                                      const Float_t  tmin          = -30.,
                                                      const Float_t  tmax          = 30.,
                                                      const Int_t    disttobad     = 2,
                                                      const Int_t    nlmMax        =  20,
                                                      const Bool_t   qaan          = kFALSE,
                                                      const Bool_t   primvtx       = kTRUE,
                                                      const Bool_t   notrackcut    = kTRUE,
                                                      const Bool_t   rdmtrigger    = kFALSE,
                                                      const Int_t    debug         = -1,
                                                      const Bool_t   print         = kFALSE
                                                      )
{
kDebug = debug;
kCalorimeter  = calorimeter ;
kPrint = print ;
  // Creates a CaloTrackCorr task, configures it and adds it to the analysis manager.
  
  printf("AddTaskIsoPhoton() - Settings: cone %2.2f, pth %2.2f, timeCut On %d, NLM max cut %d, calorimeter %s, simu %d, exotic %d, non lin %d, trigger %s, TM %d, qa %d, debug %d, centrality %d-%d\n",
                                         cone,    pth,    timecut   ,    nlmMax,      calorimeter.Data(),simu, exotic,    nonlin,     trigger.Data(), tm,    qaan,   debug, minCen, maxCen );
  
  // Get the pointer to the existing analysis manager via the static access method.
  
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) 
  {
    ::Error("AddTask", "No analysis manager to connect to.");
    return NULL;
  }  
  
  // Check the analysis type using the event handlers connected to the analysis manager.
  
  if (!mgr->GetInputEventHandler()) 
  {
    ::Error("AddTask", "This task requires an input event handler");
    return NULL;
  }

  // Make sure the B field is enabled for track selection, some cuts need it
  ((AliInputEventHandler*)mgr->GetInputEventHandler())->SetNeedField(kTRUE);
  
  Bool_t useKinematics = kFALSE;
  useKinematics = (mgr->GetMCtruthEventHandler())?kTRUE:kFALSE;

  // Name for containers
  
  kAnaIsoPhotonName = Form("%s_Trig%s_TM%d_%1.3f_dB%d_R%1.1f_Pt%1.1f",calorimeter.Data(), trigger.Data(),tm,deltaphicut,disttobad,cone,pth);

  if(maxCen>=0) kAnaIsoPhotonName+=Form("Cen%d_%d",minCen,maxCen);
    
  printf("<<<< NAME: %s >>>>>\n",kAnaIsoPhotonName.Data());
  
  // #### Configure analysis ####
    
  AliAnaCaloTrackCorrMaker * maker = new AliAnaCaloTrackCorrMaker();
  
  //maker->SetScaleFactor(scaleFactor); // for MC, negative (not scaled) by default
  
  // General frame setting and configuration
  maker->SetReader   (ConfigureReader   (mgr->GetInputEventHandler()->GetDataType(),useKinematics,simu,
                                         calorimeter,nonlin, timecut, primvtx, notrackcut,tmin,tmax,minCen, maxCen, debug,print));
  maker->SetCaloUtils(ConfigureCaloUtils(nonlin,exotic,simu,timecut,debug,print));
  
  // Analysis tasks setting and configuration
  Int_t n = 0;//Analysis number, order is important

  // Isolation settings
  Int_t partInCone = AliIsolationCut::kNeutralAndCharged; // kOnlyCharged;
  //  Int_t thresType  = AliIsolationCut::kPtThresIC;//  AliIsolationCut::kSumPtFracIC ; 
  Int_t thresType  = AliIsolationCut::kSumPtIC ; 
  
 if(!rdmtrigger)
{
  // Photon analysis
  maker->AddAnalysis(ConfigurePhotonAnalysis(calorimeter,tm,deltaphicut,deltaetacut,disttobad,nlmMax,simu,debug,print), n++); // Photon cluster selection
  
  // Isolation analysis
  maker->AddAnalysis(ConfigureIsolationAnalysis(calorimeter,"Photon", partInCone,thresType,cone, pth,tm,leading,kFALSE,simu,debug,print), n++); // Photon isolation
}
else
{
  maker->AddAnalysis(ConfigureRandomTriggerAnalysis(), n++); 
  maker->AddAnalysis(ConfigureIsolationAnalysis(calorimeter,Form("RandomTrigger%s",kCalorimeter.Data()), partInCone,thresType,cone, pth,tm,leading,kFALSE,simu,debug,print), n++);// Ghost trigger isolation  
}


  // QA histograms on clusters or tracks
  if(qaan)
  {
    maker->AddAnalysis(ConfigureQAAnalysis(calorimeter,simu,debug,print),n++);
    maker->AddAnalysis(ConfigureChargedAnalysis(simu,debug), n++); // charged tracks plots
  }
  
  maker->SetAnaDebug(debug)  ;
  maker->SwitchOnHistogramsMaker()  ;
  maker->SwitchOnAODsMaker()  ;
  
  if(print) maker->Print("");
  
  maker->SwitchOffDataControlHistograms();
  
  printf("<< End Configuration of %d analysis for calorimeter %s >>\n",n, calorimeter.Data());
 
  // Create task
  
  AliAnalysisTaskCaloTrackCorrelation * task = new AliAnalysisTaskCaloTrackCorrelation (Form("CaloTrackCorr%s",kAnaIsoPhotonName.Data()));
  task->SetConfigFileName(""); //Don't configure the analysis via configuration file.
  task->SetDebugLevel(debug);
  task->SetBranches("ESD:AliESDRun.,AliESDHeader"); 
  task->SetAnalysisMaker(maker);
  mgr->AddTask(task);
  
  //Create containers
  
  TString outputfile = AliAnalysisManager::GetCommonFileName();
  
  AliAnalysisDataContainer *cout_pc   = mgr->CreateContainer(kAnaIsoPhotonName, TList::Class(), 
                                                             AliAnalysisManager::kOutputContainer, 
                                                             Form("%s",outputfile.Data()));
	
  AliAnalysisDataContainer *cout_cuts = mgr->CreateContainer(Form("Param_%s",kAnaIsoPhotonName.Data()), TList::Class(), 
                                                             AliAnalysisManager::kParamContainer, 
                                                             "AnalysisParameters.root");
  
  // Create ONLY the output containers for the data produced by the task.
  // Get and connect other common input/output containers via the manager as below
  //==============================================================================
  mgr->ConnectInput  (task, 0, mgr->GetCommonInputContainer());
  // AOD output slot will be used in a different way in future
  mgr->ConnectOutput (task, 1, cout_pc);
  mgr->ConnectOutput (task, 2, cout_cuts);

  // Set the trigger selection
  UInt_t mask =  SetTriggerMaskFromName(trigger);
  task->SelectCollisionCandidates(mask);
  
  return task;
}

//____________________________________
AliCaloTrackReader * ConfigureReader(TString inputDataType = "AOD", Bool_t useKinematics = kFALSE, Bool_t simu = kFALSE,
                                     TString calorimeter = "EMCAL", Bool_t nonlin = kTRUE, Bool_t timecut = kFALSE,
                                     Bool_t primvtx = kFALSE, Bool_t notrackcut = kFALSE, Float_t tmin, Float_t tmax,
                                     Float_t minCen = -1, Float_t maxCen = -1, Int_t debug = -1, Bool_t print = kFALSE)
{
  // Init reader settings: event selection, basic cluster track cuts, etc
  
  if(simu)
  {
    if (!useKinematics && inputDataType=="AOD") useKinematics = kTRUE; //AOD primary should be available ...
  }
  
  cout<<"********* ACCESS KINE? "<<useKinematics<< endl;

  AliCaloTrackReader * reader = 0;
  if     (inputDataType=="AOD") reader = new AliCaloTrackAODReader();
  else if(inputDataType=="ESD") reader = new AliCaloTrackESDReader();
  else  printf("AliCaloTrackReader::ConfigureReader() - Data not known inputData=%s\n",inputDataType.Data());
  
  reader->SetDebug(debug);//10 for lots of messages
  
  reader->SwitchOffTriggerPatchMatching();
  reader->SwitchOffBadTriggerEventsRemoval();
  
  reader->SwitchOffWriteDeltaAOD()  ;
  
  // MC settings
  if(useKinematics)
  {
    if(inputDataType == "ESD")
    {
      reader->SwitchOnStack();          
      reader->SwitchOffAODMCParticles(); 
    }
    else if(inputDataType == "AOD")
    {
      reader->SwitchOffStack();          
      reader->SwitchOnAODMCParticles(); 
    }
  }  
  
  //------------------------
  // Detector input filling
  //------------------------
  
  //Min cluster/track E
  reader->SetEMCALEMin(0.3); 
  reader->SetEMCALEMax(1000); 
  reader->SetPHOSEMin(0.3);
  reader->SetPHOSEMax(1000);
  reader->SetCTSPtMin(0.2);
  reader->SetCTSPtMax(1000);

  // Time cuts
  if(simu)
  {
    reader->SwitchOffUseTrackTimeCut();
    reader->SwitchOffUseParametrizedTimeCut();
    reader->SwitchOffUseEMCALTimeCut();
    reader->SetEMCALTimeCut(-1e10,1e10); // Open time cut
  }
  else
  {
    reader->SwitchOffUseParametrizedTimeCut();

    if(timecut)
    {
      printf("Set time cut \n");
      reader->SwitchOnUseEMCALTimeCut();
      //Absolute window
      reader->SetEMCALTimeCut(tmin,tmax); // default is -25ns-20ns
    }
    else
    {
      printf("Off time cuts time cut \n");
      reader->SwitchOffUseEMCALTimeCut();
      //Absolute window
      reader->SetEMCALTimeCut(-1.e6,1.e6);
    }
  }
  
  reader->SwitchOffFiducialCut();
  reader->GetFiducialCut()->SetSimpleCTSFiducialCut(0.8, 0, 360) ;

  // Tracks
  reader->SwitchOnCTS();


  reader->SwitchOffRecalculateVertexBC();
  reader->SwitchOffVertexBCEventSelection();
  
  reader->SwitchOffUseTrackTimeCut();
  reader->SetTrackTimeCut(0,50);
  
  reader->SwitchOffUseTrackDCACut();
  //reader->SetTrackDCACut(0,0.0105);
  //reader->SetTrackDCACut(1,0.035);
  //reader->SetTrackDCACut(2,1.1);
  
  if(inputDataType=="ESD")
  {
    gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/CreateTrackCutsPWGJE.C");
    //AliESDtrackCuts * esdTrackCuts = CreateTrackCutsPWGJE(10041004);
    //reader->SetTrackCuts(esdTrackCuts);
    //reader->SwitchOnConstrainTrackToVertex();
    
//    if(kYears>2010)
//    {
      //Hybrids 2011<commit_msg>modif from Alexis: including option to cut in track time using TOF data<commit_after>// Configuration macro for analysis of isolated photon spectra
// Author : <NAME>;  <NAME>.

TString kAnaIsoPhotonName = "";
Int_t   kDebug         = -1;
TString kCalorimeter   = "EMCAL";
TString kData = "";
TString kPrint = 0 ;
 
AliAnalysisTaskCaloTrackCorrelation *AddTaskIsoPhoton(const Float_t  cone          = 0.4,
                                                      const Float_t  pth           = 2.,
                                                      const Bool_t   leading       = kFALSE,
                                                      const Bool_t   timecut       = kFALSE,
                                                      const TString  calorimeter   = "EMCAL",
                                                      const Bool_t   simu          = kFALSE,
                                                      const Bool_t   exotic        = kTRUE,
                                                      const Bool_t   nonlin        = kFALSE,
                                                      const TString  trigger       = "EMC7",
                                                      const Bool_t   tm            = kTRUE,
                                                      const Int_t    minCen        = -1,
                                                      const Int_t    maxCen        = -1,
                                                      const Float_t  deltaphicut   = 0.03,
                                                      const Float_t  deltaetacut   = 0.02,
                                                      const Float_t  tmin          = -30.,
                                                      const Float_t  tmax          = 30.,
                                                      const Bool_t   trackTcut     = kFALSE,
                                                      const Int_t    disttobad     = 2,
                                                      const Int_t    nlmMax        =  20,
                                                      const Bool_t   qaan          = kFALSE,
                                                      const Bool_t   primvtx       = kTRUE,
                                                      const Bool_t   notrackcut    = kTRUE,
                                                      const Bool_t   rdmtrigger    = kFALSE,
                                                      const Int_t    debug         = -1,
                                                      const Bool_t   print         = kFALSE
                                                      )
{
kDebug = debug;
kCalorimeter  = calorimeter ;
kPrint = print ;
  // Creates a CaloTrackCorr task, configures it and adds it to the analysis manager.
  
  printf("AddTaskIsoPhoton() - Settings: cone %2.2f, pth %2.2f, timeCut On %d, NLM max cut %d, calorimeter %s, simu %d, exotic %d, non lin %d, trigger %s, TM %d, qa %d, debug %d, centrality %d-%d\n",
                                         cone,    pth,    timecut   ,    nlmMax,      calorimeter.Data(),simu, exotic,    nonlin,     trigger.Data(), tm,    qaan,   debug, minCen, maxCen );
  
  // Get the pointer to the existing analysis manager via the static access method.
  
  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
  if (!mgr) 
  {
    ::Error("AddTask", "No analysis manager to connect to.");
    return NULL;
  }  
  
  // Check the analysis type using the event handlers connected to the analysis manager.
  
  if (!mgr->GetInputEventHandler()) 
  {
    ::Error("AddTask", "This task requires an input event handler");
    return NULL;
  }

  // Make sure the B field is enabled for track selection, some cuts need it
  ((AliInputEventHandler*)mgr->GetInputEventHandler())->SetNeedField(kTRUE);
  
  Bool_t useKinematics = kFALSE;
  useKinematics = (mgr->GetMCtruthEventHandler())?kTRUE:kFALSE;

  // Name for containers
  
  kAnaIsoPhotonName = Form("%s_Trig%s_TM%d_%1.3f_dB%d_R%1.1f_Pt%1.1f",calorimeter.Data(), trigger.Data(),tm,deltaphicut,disttobad,cone,pth);

  if(maxCen>=0) kAnaIsoPhotonName+=Form("Cen%d_%d",minCen,maxCen);
    
  printf("<<<< NAME: %s >>>>>\n",kAnaIsoPhotonName.Data());
  
  // #### Configure analysis ####
    
  AliAnaCaloTrackCorrMaker * maker = new AliAnaCaloTrackCorrMaker();
  
  //maker->SetScaleFactor(scaleFactor); // for MC, negative (not scaled) by default
  
  // General frame setting and configuration
  maker->SetReader   (ConfigureReader   (mgr->GetInputEventHandler()->GetDataType(),useKinematics,simu,
                                         calorimeter,nonlin, timecut, primvtx, notrackcut,tmin,tmax,trackTcut,minCen, maxCen, debug,print));
  maker->SetCaloUtils(ConfigureCaloUtils(nonlin,exotic,simu,timecut,debug,print));
  
  // Analysis tasks setting and configuration
  Int_t n = 0;//Analysis number, order is important

  // Isolation settings
  Int_t partInCone = AliIsolationCut::kNeutralAndCharged; // kOnlyCharged;
  //  Int_t thresType  = AliIsolationCut::kPtThresIC;//  AliIsolationCut::kSumPtFracIC ; 
  Int_t thresType  = AliIsolationCut::kSumPtIC ; 
  
 if(!rdmtrigger)
{
  // Photon analysis
  maker->AddAnalysis(ConfigurePhotonAnalysis(calorimeter,tm,deltaphicut,deltaetacut,disttobad,nlmMax,simu,debug,print), n++); // Photon cluster selection
  
  // Isolation analysis
  maker->AddAnalysis(ConfigureIsolationAnalysis(calorimeter,"Photon", partInCone,thresType,cone, pth,tm,leading,kFALSE,simu,debug,print), n++); // Photon isolation
}
else
{
  maker->AddAnalysis(ConfigureRandomTriggerAnalysis(), n++); 
  maker->AddAnalysis(ConfigureIsolationAnalysis(calorimeter,Form("RandomTrigger%s",kCalorimeter.Data()), partInCone,thresType,cone, pth,tm,leading,kFALSE,simu,debug,print), n++);// Ghost trigger isolation  
}


  // QA histograms on clusters or tracks
  if(qaan)
  {
    maker->AddAnalysis(ConfigureQAAnalysis(calorimeter,simu,debug,print),n++);
    maker->AddAnalysis(ConfigureChargedAnalysis(simu,debug), n++); // charged tracks plots
  }
  
  maker->SetAnaDebug(debug)  ;
  maker->SwitchOnHistogramsMaker()  ;
  maker->SwitchOnAODsMaker()  ;
  
  if(print) maker->Print("");
  
  maker->SwitchOffDataControlHistograms();
  
  printf("<< End Configuration of %d analysis for calorimeter %s >>\n",n, calorimeter.Data());
 
  // Create task
  
  AliAnalysisTaskCaloTrackCorrelation * task = new AliAnalysisTaskCaloTrackCorrelation (Form("CaloTrackCorr%s",kAnaIsoPhotonName.Data()));
  task->SetConfigFileName(""); //Don't configure the analysis via configuration file.
  task->SetDebugLevel(debug);
  task->SetBranches("ESD:AliESDRun.,AliESDHeader"); 
  task->SetAnalysisMaker(maker);
  mgr->AddTask(task);
  
  //Create containers
  
  TString outputfile = AliAnalysisManager::GetCommonFileName();
  
  AliAnalysisDataContainer *cout_pc   = mgr->CreateContainer(kAnaIsoPhotonName, TList::Class(), 
                                                             AliAnalysisManager::kOutputContainer, 
                                                             Form("%s",outputfile.Data()));
	
  AliAnalysisDataContainer *cout_cuts = mgr->CreateContainer(Form("Param_%s",kAnaIsoPhotonName.Data()), TList::Class(), 
                                                             AliAnalysisManager::kParamContainer, 
                                                             "AnalysisParameters.root");
  
  // Create ONLY the output containers for the data produced by the task.
  // Get and connect other common input/output containers via the manager as below
  //==============================================================================
  mgr->ConnectInput  (task, 0, mgr->GetCommonInputContainer());
  // AOD output slot will be used in a different way in future
  mgr->ConnectOutput (task, 1, cout_pc);
  mgr->ConnectOutput (task, 2, cout_cuts);

  // Set the trigger selection
  UInt_t mask =  SetTriggerMaskFromName(trigger);
  task->SelectCollisionCandidates(mask);
  
  return task;
}

//____________________________________
AliCaloTrackReader * ConfigureReader(TString inputDataType = "AOD", Bool_t useKinematics = kFALSE, Bool_t simu = kFALSE,
                                     TString calorimeter = "EMCAL", Bool_t nonlin = kTRUE, Bool_t timecut = kFALSE,
                                     Bool_t primvtx = kFALSE, Bool_t notrackcut = kFALSE, Float_t tmin, Float_t tmax,
                                     Bool_t trackTcut = kFALSE, Float_t minCen = -1, Float_t maxCen = -1,
                                     Int_t debug = -1, Bool_t print = kFALSE)
{
  // Init reader settings: event selection, basic cluster track cuts, etc
  
  if(simu)
  {
    if (!useKinematics && inputDataType=="AOD") useKinematics = kTRUE; //AOD primary should be available ...
  }
  
  cout<<"********* ACCESS KINE? "<<useKinematics<< endl;

  AliCaloTrackReader * reader = 0;
  if     (inputDataType=="AOD") reader = new AliCaloTrackAODReader();
  else if(inputDataType=="ESD") reader = new AliCaloTrackESDReader();
  else  printf("AliCaloTrackReader::ConfigureReader() - Data not known inputData=%s\n",inputDataType.Data());
  
  reader->SetDebug(debug);//10 for lots of messages
  
  reader->SwitchOffTriggerPatchMatching();
  reader->SwitchOffBadTriggerEventsRemoval();
  
  reader->SwitchOffWriteDeltaAOD()  ;
  
  // MC settings
  if(useKinematics)
  {
    if(inputDataType == "ESD")
    {
      reader->SwitchOnStack();          
      reader->SwitchOffAODMCParticles(); 
    }
    else if(inputDataType == "AOD")
    {
      reader->SwitchOffStack();          
      reader->SwitchOnAODMCParticles(); 
    }
  }  
  
  //------------------------
  // Detector input filling
  //------------------------
  
  //Min cluster/track E
  reader->SetEMCALEMin(0.3); 
  reader->SetEMCALEMax(1000); 
  reader->SetPHOSEMin(0.3);
  reader->SetPHOSEMax(1000);
  reader->SetCTSPtMin(0.2);
  reader->SetCTSPtMax(1000);

  // Time cuts
  if(simu)
  {
    reader->SwitchOffUseTrackTimeCut();
    reader->SwitchOffUseParametrizedTimeCut();
    reader->SwitchOffUseEMCALTimeCut();
    reader->SetEMCALTimeCut(-1e10,1e10); // Open time cut
  }
  else
  {
    reader->SwitchOffUseParametrizedTimeCut();

    if(timecut)
    {
      printf("Set time cut \n");
      reader->SwitchOnUseEMCALTimeCut();
      //Absolute window
      reader->SetEMCALTimeCut(tmin,tmax); // default is -25ns-20ns
    }
    else
    {
      printf("Off time cuts time cut \n");
      reader->SwitchOffUseEMCALTimeCut();
      //Absolute window
      reader->SetEMCALTimeCut(-1.e6,1.e6);
    }
  }
  
  reader->SwitchOffFiducialCut();
  reader->GetFiducialCut()->SetSimpleCTSFiducialCut(0.8, 0, 360) ;

  // Tracks
  reader->SwitchOnCTS();


  reader->SwitchOffRecalculateVertexBC();
  reader->SwitchOffVertexBCEventSelection();
  
if(trackTcut)
  reader->SwitchOnUseTrackTimeCut();
else
  reader->SwitchOffUseTrackTimeCut();

  reader->SetTrackTimeCut(0,50);
  
  reader->SwitchOffUseTrackDCACut();
  //reader->SetTrackDCACut(0,0.0105);
  //reader->SetTrackDCACut(1,0.035);
  //reader->SetTrackDCACut(2,1.1);
  
  if(inputDataType=="ESD")
  {
    gROOT->LoadMacro("$ALICE_ROOT/PWGJE/macros/CreateTrackCutsPWGJE.C");
    //AliESDtrackCuts * esdTrackCuts = CreateTrackCutsPWGJE(10041004);
    //reader->SetTrackCuts(esdTrackCuts);
    //reader->SwitchOnConstrainTrackToVertex();
    
//    if(kYears>2010)
//    {
      //Hybrids 2011
{'fraction_non_alphanumeric': 0.11732115947167804, 'fraction_numerical': 0.010105487102207251, 'mean_word_length': 1.9813689217758985, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 166, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 129, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4934983', 'n_tokens_mistral': 6748, 'n_tokens_neox': 6423, 'n_words': 1323}