<commit_before>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id: AliAnalysisTaskESDfilter.cxx 24535 2008-03-16 22:43:30Z fca $ */
 
#include <TChain.h>
#include <TTree.h>
#include <TList.h>
#include <TArrayI.h>
#include <TRandom.h>
#include <TParticle.h>
#include <TFile.h>

#include "AliAnalysisTaskESDfilter.h"
#include "AliAnalysisManager.h"
#include "AliESDEvent.h"
#include "AliESDRun.h"
#include "AliStack.h"
#include "AliAODEvent.h"
#include "AliMCEvent.h"
#include "AliMCEventHandler.h"
#include "AliESDInputHandler.h"
#include "AliAODHandler.h"
#include "AliAODMCParticle.h"
#include "AliAnalysisFilter.h"
#include "AliESDMuonTrack.h"
#include "AliESDVertex.h"
#include "AliESDv0.h"
#include "AliESDkink.h"
#include "AliESDcascade.h"
#include "AliESDPmdTrack.h"
#include "AliESDCaloCluster.h"
#include "AliESDCaloCells.h"
#include "AliMultiplicity.h"
#include "AliLog.h"

ClassImp(AliAnalysisTaskESDfilter)

////////////////////////////////////////////////////////////////////////

AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter():
    AliAnalysisTaskSE(),
    fTrackFilter(0x0),
    fKinkFilter(0x0),
    fV0Filter(0x0),
    fCascadeFilter(0x0),
    fHighPthreshold(0),
    fPtshape(0x0),
    fEnableFillAOD(kTRUE)
{
  // Default constructor
}

AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter(const char* name):
    AliAnalysisTaskSE(name),
    fTrackFilter(0x0),
    fKinkFilter(0x0),
    fV0Filter(0x0),
    fCascadeFilter(0x0),
    fHighPthreshold(0),
    fPtshape(0x0),
    fEnableFillAOD(kTRUE)
{
  // Constructor
}

void AliAnalysisTaskESDfilter::UserCreateOutputObjects()
{
  //
  // Create Output Objects conenct filter to outputtree
  // 
  if(OutputTree()){
    OutputTree()->GetUserInfo()->Add(fTrackFilter);
  }
  else{
    AliError("No OutputTree() for adding the track filter");
  }
}

void AliAnalysisTaskESDfilter::Init()
{
    // Initialization
    if (fDebug > 1) AliInfo("Init() \n");
    // Call configuration file
}


void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)
{
// Execute analysis for current event
//
					    
  Long64_t ientry = Entry();
  
  if (fDebug > 0) {
      printf("Filter: Analysing event # %5d\n", (Int_t) ientry);
      if (fHighPthreshold == 0) AliInfo("detector PID signals are stored in each track");
      if (!fPtshape) AliInfo("detector PID signals are not stored below the pt threshold");
  }
  // Filters must explicitely enable AOD filling in their UserExec (AG)
  if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) AliFatal("Cannot run ESD filter without an output event handler");
  if(fEnableFillAOD) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);

  ConvertESDtoAOD();
}

void AliAnalysisTaskESDfilter::ConvertESDtoAOD() {
    // ESD Filter analysis task executed for each event

    AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
    if(!esd)return;
    AliESD*      old = esd->GetAliESDOld();

    // Fetch Stack for debuggging if available 
    AliMCEventHandler *mcH = 0;
    if(MCEvent()){
      mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); 
    }
    // set arrays and pointers
    Float_t posF[3];
    Double_t pos[3];
    Double_t p[3];
    Double_t momPos[3]; 
    Double_t momNeg[3];
    Double_t momBach[3];
    Double_t momPosAtV0vtx[3];
    Double_t momNegAtV0vtx[3];
    Double_t momBachAtCascadeVtx[3];
    Double_t covVtx[6];
    Double_t covTr[21];
    Double_t pid[10];

    for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;
    for (Int_t i = 0; i < 21; i++) covTr [i] = 0.;

    
    // loop over events and fill them
    // Multiplicity information needed by the header (to be revised!)
    Int_t nTracks    = esd->GetNumberOfTracks();
    for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) esd->GetTrack(iTrack)->SetESDEvent(esd);

    //    if (fDebug > 0) printf("-------------------Bo: Number of ESD tracks %d \n",nTracks);

    Int_t nPosTracks = 0;
    
    // Update the header

    AliAODHeader* header = AODEvent()->GetHeader();
    
    header->SetRunNumber(esd->GetRunNumber());
    header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
    TTree* tree = fInputHandler->GetTree();
    if (tree) {
	TFile* file = tree->GetCurrentFile();
	if (file) header->SetESDFileName(file->GetName());
    }
    
    if (old) {
	header->SetBunchCrossNumber(0);
	header->SetOrbitNumber(0);
	header->SetPeriodNumber(0);
	header->SetEventType(0);
	header->SetMuonMagFieldScale(-999.);
	header->SetCentrality(-999.);       
    } else {
	header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
	header->SetOrbitNumber(esd->GetOrbitNumber());
	header->SetPeriodNumber(esd->GetPeriodNumber());
	header->SetEventType(esd->GetEventType());
	header->SetCentrality(-999.);
	header->SetEventNumberESDFile(esd->GetHeader()->GetEventNumberInFile());
    }
    // Trigger
    header->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
    header->SetTriggerMask(esd->GetTriggerMask()); <commit_msg>Setting centrality in the AOD header<commit_after>/**************************************************************************
 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 *                                                                        *
 * Author: The ALICE Off-line Project.                                    *
 * Contributors are mentioned in the code where appropriate.              *
 *                                                                        *
 * Permission to use, copy, modify and distribute this software and its   *
 * documentation strictly for non-commercial purposes is hereby granted   *
 * without fee, provided that the above copyright notice appears in all   *
 * copies and that both the copyright notice and this permission notice   *
 * appear in the supporting documentation. The authors make no claims     *
 * about the suitability of this software for any purpose. It is          *
 * provided "as is" without express or implied warranty.                  *
 **************************************************************************/

/* $Id: AliAnalysisTaskESDfilter.cxx 24535 2008-03-16 22:43:30Z fca $ */
 
#include <TChain.h>
#include <TTree.h>
#include <TList.h>
#include <TArrayI.h>
#include <TRandom.h>
#include <TParticle.h>
#include <TFile.h>

#include "AliAnalysisTaskESDfilter.h"
#include "AliAnalysisManager.h"
#include "AliESDEvent.h"
#include "AliESDRun.h"
#include "AliStack.h"
#include "AliAODEvent.h"
#include "AliMCEvent.h"
#include "AliMCEventHandler.h"
#include "AliESDInputHandler.h"
#include "AliAODHandler.h"
#include "AliAODMCParticle.h"
#include "AliAnalysisFilter.h"
#include "AliESDMuonTrack.h"
#include "AliESDVertex.h"
#include "AliESDCentrality.h"
#include "AliESDv0.h"
#include "AliESDkink.h"
#include "AliESDcascade.h"
#include "AliESDPmdTrack.h"
#include "AliESDCaloCluster.h"
#include "AliESDCaloCells.h"
#include "AliMultiplicity.h"
#include "AliLog.h"

ClassImp(AliAnalysisTaskESDfilter)

////////////////////////////////////////////////////////////////////////

AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter():
    AliAnalysisTaskSE(),
    fTrackFilter(0x0),
    fKinkFilter(0x0),
    fV0Filter(0x0),
    fCascadeFilter(0x0),
    fHighPthreshold(0),
    fPtshape(0x0),
    fEnableFillAOD(kTRUE)
{
  // Default constructor
}

AliAnalysisTaskESDfilter::AliAnalysisTaskESDfilter(const char* name):
    AliAnalysisTaskSE(name),
    fTrackFilter(0x0),
    fKinkFilter(0x0),
    fV0Filter(0x0),
    fCascadeFilter(0x0),
    fHighPthreshold(0),
    fPtshape(0x0),
    fEnableFillAOD(kTRUE)
{
  // Constructor
}

void AliAnalysisTaskESDfilter::UserCreateOutputObjects()
{
  //
  // Create Output Objects conenct filter to outputtree
  // 
  if(OutputTree()){
    OutputTree()->GetUserInfo()->Add(fTrackFilter);
  }
  else{
    AliError("No OutputTree() for adding the track filter");
  }
}

void AliAnalysisTaskESDfilter::Init()
{
    // Initialization
    if (fDebug > 1) AliInfo("Init() \n");
    // Call configuration file
}


void AliAnalysisTaskESDfilter::UserExec(Option_t */*option*/)
{
// Execute analysis for current event
//
					    
  Long64_t ientry = Entry();
  
  if (fDebug > 0) {
      printf("Filter: Analysing event # %5d\n", (Int_t) ientry);
      if (fHighPthreshold == 0) AliInfo("detector PID signals are stored in each track");
      if (!fPtshape) AliInfo("detector PID signals are not stored below the pt threshold");
  }
  // Filters must explicitely enable AOD filling in their UserExec (AG)
  if (!AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()) AliFatal("Cannot run ESD filter without an output event handler");
  if(fEnableFillAOD) AliAnalysisManager::GetAnalysisManager()->GetOutputEventHandler()->SetFillAOD(kTRUE);

  ConvertESDtoAOD();
}

void AliAnalysisTaskESDfilter::ConvertESDtoAOD() {
    // ESD Filter analysis task executed for each event

    AliESDEvent* esd = dynamic_cast<AliESDEvent*>(InputEvent());
    if(!esd)return;
    AliESD*      old = esd->GetAliESDOld();

    // Fetch Stack for debuggging if available 
    AliMCEventHandler *mcH = 0;
    if(MCEvent()){
      mcH = (AliMCEventHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler()); 
    }
    // set arrays and pointers
    Float_t posF[3];
    Double_t pos[3];
    Double_t p[3];
    Double_t momPos[3]; 
    Double_t momNeg[3];
    Double_t momBach[3];
    Double_t momPosAtV0vtx[3];
    Double_t momNegAtV0vtx[3];
    Double_t momBachAtCascadeVtx[3];
    Double_t covVtx[6];
    Double_t covTr[21];
    Double_t pid[10];

    for (Int_t i = 0; i < 6; i++)  covVtx[i] = 0.;
    for (Int_t i = 0; i < 21; i++) covTr [i] = 0.;

    
    // loop over events and fill them
    // Multiplicity information needed by the header (to be revised!)
    Int_t nTracks    = esd->GetNumberOfTracks();
    for (Int_t iTrack=0; iTrack<nTracks; ++iTrack) esd->GetTrack(iTrack)->SetESDEvent(esd);

    //    if (fDebug > 0) printf("-------------------Bo: Number of ESD tracks %d \n",nTracks);

    Int_t nPosTracks = 0;
    
    // Update the header

    AliAODHeader* header = AODEvent()->GetHeader();
    
    header->SetRunNumber(esd->GetRunNumber());
    header->SetOfflineTrigger(fInputHandler->IsEventSelected()); // propagate the decision of the physics selection
    TTree* tree = fInputHandler->GetTree();
    if (tree) {
	TFile* file = tree->GetCurrentFile();
	if (file) header->SetESDFileName(file->GetName());
    }
    
    if (old) {
	header->SetBunchCrossNumber(0);
	header->SetOrbitNumber(0);
	header->SetPeriodNumber(0);
	header->SetEventType(0);
	header->SetMuonMagFieldScale(-999.);
	header->SetCentrality(-999.);       
    } else {
	header->SetBunchCrossNumber(esd->GetBunchCrossNumber());
	header->SetOrbitNumber(esd->GetOrbitNumber());
	header->SetPeriodNumber(esd->GetPeriodNumber());
	header->SetEventType(esd->GetEventType());

	header->SetEventNumberESDFile(esd->GetHeader()->GetEventNumberInFile());
	if(esd->GetCentrality()){
	  header->SetCentrality(esd->GetCentrality()->GetCentralityPercentile("V0M"));
	}
	else{
	  header->SetCentrality(-999.);
	}
    }
    
    // Trigger
    header->SetFiredTriggerClasses(esd->GetFiredTriggerClasses());
    header->SetTriggerMask(esd->GetTriggerMask()); 
{'fraction_non_alphanumeric': 0.15975757575757576, 'fraction_numerical': 0.01591919191919192, 'mean_word_length': 3.3839886645412682, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5984805', 'n_tokens_mistral': 4080, 'n_tokens_neox': 3936, 'n_words': 882}