<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$

//
// Implementation of a branch replicator 
// to produce slim muon and dimuon aods.
//
// This replicator is in charge of replicating the tracks,vertices and dimuons
// branches of the standard AOD into muon AODs (AliAOD.Muons.root and
// AliAOD.Dimuons.root)
// 
// The tracks are filtered so that only muon tracks (and only muon tracks
// that pass the trackCut if present) make it to the output aods
//
// The vertices are filtered so that only the primary vertices make it
// to the output aods.
//
// The dimuons are recreated here, according to the set of tracks
// that pass the trackCut (that set may be the same as the input set,
// but to be 100% safe, we always recreate the dimuons).
// 
// Author: <NAME> (Subatech)

#include "AliAODMuonReplicator.h"
#include "AliAnalysisCuts.h"
#include "AliAODEvent.h"
#include "AliAODTrack.h"
#include "AliAODDimuon.h"
#include "AliAODMCHeader.h"
#include "AliAODMCParticle.h"
#include <cassert>

ClassImp(AliAODMuonReplicator)

//_____________________________________________________________________________
AliAODMuonReplicator::AliAODMuonReplicator(const char* name, const char* title,
                                           AliAnalysisCuts* trackCut,
                                           AliAnalysisCuts* vertexCut,
                                           Int_t mcMode)
:AliAODBranchReplicator(name,title), 
fTrackCut(trackCut), fTracks(0x0), 
fVertexCut(vertexCut), fVertices(0x0), 
fDimuons(0x0),
fList(0x0),
fMCParticles(0x0),
fMCHeader(0x0),
fMCMode(mcMode),
fLabelMap(),
fParticleSelected()
{
  // default ctor
}

//_____________________________________________________________________________
AliAODMuonReplicator::~AliAODMuonReplicator()
{
  // dtor
  delete fTrackCut;
  delete fVertexCut;
  delete fList;
}

//_____________________________________________________________________________
void AliAODMuonReplicator::SelectParticle(Int_t i)
{
  // taking the absolute values here, need to take care 
  // of negative daughter and mother
  // IDs when setting!
  
  if (!IsParticleSelected(TMath::Abs(i)))
  {
    fParticleSelected.Add(TMath::Abs(i),1);    
  }
}

//_____________________________________________________________________________
Bool_t AliAODMuonReplicator::IsParticleSelected(Int_t i)  
{
  // taking the absolute values here, need to take 
  // care with negative daughter and mother
  // IDs when setting!
  return (fParticleSelected.GetValue(TMath::Abs(i))==1);
}


//_____________________________________________________________________________
void AliAODMuonReplicator::CreateLabelMap(const AliAODEvent& source)
{  
  //
  // this should be called once all selections are done 
  //
  
  fLabelMap.Delete();
  
  TClonesArray* mcParticles = static_cast<TClonesArray*>(source.FindListObject(AliAODMCParticle::StdBranchName()));
  
  Int_t i(0);
  Int_t j(0);
  
  TIter next(mcParticles);
  
  while ( next() ) 
  {
    if (IsParticleSelected(i))
    {
      fLabelMap.Add(i,j++);
    }
    ++i;
  }
}

//_____________________________________________________________________________
Int_t AliAODMuonReplicator::GetNewLabel(Int_t i) 
{
  // Gets the label from the new created Map
  // Call CreatLabelMap before
  // otherwise only 0 returned
  return fLabelMap.GetValue(TMath::Abs(i));
}

//_____________________________________________________________________________
void AliAODMuonReplicator::FilterMC(const AliAODEvent& source)
{
  // Filter MC information

  fMCHeader->Reset();
  fMCParticles->Clear("C");

  AliAODMCHeader* mcHeader(0x0);
  TClonesArray* mcParticles(0x0);
  
  fParticleSelected.Delete();
  
  if ( !fTracks->GetEntries() ) return;
  // only copy MC information for events where there's at least one muon track
    
  mcHeader = static_cast<AliAODMCHeader*>(source.FindListObject(AliAODMCHeader::StdBranchName()));
  
  if ( mcHeader ) 
  {
    *fMCHeader = *mcHeader;
  }
  
  mcParticles = static_cast<TClonesArray*>(source.FindListObject(AliAODMCParticle::StdBranchName()));
  
  if ( mcParticles && fMCMode>=2 )
  {
    // loop on (kept) muon tracks to find their ancestors
    TIter nextMT(fTracks);
    AliAODTrack* mt;
    int outLabel(0);
    
    while ( ( mt = static_cast<AliAODTrack*>(nextMT()) ) )
    {
      Int_t label = mt->GetLabel();
      
      while ( label >= 0 ) 
      {
        SelectParticle(label);
        AliAODMCParticle* mother = static_cast<AliAODMCParticle*>(mcParticles->UncheckedAt(label));
        if (!mother)
        {
          AliError("Got a null mother ! Check that !");
          label = -1;
        }
        else
        {
          label = mother->GetMother();
        }
      }
    }
    
    CreateLabelMap(source);
    <commit_msg>Warning fix (Laurent)<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$

//
// Implementation of a branch replicator 
// to produce slim muon and dimuon aods.
//
// This replicator is in charge of replicating the tracks,vertices and dimuons
// branches of the standard AOD into muon AODs (AliAOD.Muons.root and
// AliAOD.Dimuons.root)
// 
// The tracks are filtered so that only muon tracks (and only muon tracks
// that pass the trackCut if present) make it to the output aods
//
// The vertices are filtered so that only the primary vertices make it
// to the output aods.
//
// The dimuons are recreated here, according to the set of tracks
// that pass the trackCut (that set may be the same as the input set,
// but to be 100% safe, we always recreate the dimuons).
// 
// Author: <NAME> (Subatech)

#include "AliAODMuonReplicator.h"
#include "AliAnalysisCuts.h"
#include "AliAODEvent.h"
#include "AliAODTrack.h"
#include "AliAODDimuon.h"
#include "AliAODMCHeader.h"
#include "AliAODMCParticle.h"
#include <cassert>

ClassImp(AliAODMuonReplicator)

//_____________________________________________________________________________
AliAODMuonReplicator::AliAODMuonReplicator(const char* name, const char* title,
                                           AliAnalysisCuts* trackCut,
                                           AliAnalysisCuts* vertexCut,
                                           Int_t mcMode)
:AliAODBranchReplicator(name,title), 
fTrackCut(trackCut), fTracks(0x0), 
fVertexCut(vertexCut), fVertices(0x0), 
fDimuons(0x0),
fList(0x0),
fMCParticles(0x0),
fMCHeader(0x0),
fMCMode(mcMode),
fLabelMap(),
fParticleSelected()
{
  // default ctor
}

//_____________________________________________________________________________
AliAODMuonReplicator::~AliAODMuonReplicator()
{
  // dtor
  delete fTrackCut;
  delete fVertexCut;
  delete fList;
}

//_____________________________________________________________________________
void AliAODMuonReplicator::SelectParticle(Int_t i)
{
  // taking the absolute values here, need to take care 
  // of negative daughter and mother
  // IDs when setting!
  
  if (!IsParticleSelected(TMath::Abs(i)))
  {
    fParticleSelected.Add(TMath::Abs(i),1);    
  }
}

//_____________________________________________________________________________
Bool_t AliAODMuonReplicator::IsParticleSelected(Int_t i)  
{
  // taking the absolute values here, need to take 
  // care with negative daughter and mother
  // IDs when setting!
  return (fParticleSelected.GetValue(TMath::Abs(i))==1);
}


//_____________________________________________________________________________
void AliAODMuonReplicator::CreateLabelMap(const AliAODEvent& source)
{  
  //
  // this should be called once all selections are done 
  //
  
  fLabelMap.Delete();
  
  TClonesArray* mcParticles = static_cast<TClonesArray*>(source.FindListObject(AliAODMCParticle::StdBranchName()));
  
  Int_t i(0);
  Int_t j(0);
  
  TIter next(mcParticles);
  
  while ( next() ) 
  {
    if (IsParticleSelected(i))
    {
      fLabelMap.Add(i,j++);
    }
    ++i;
  }
}

//_____________________________________________________________________________
Int_t AliAODMuonReplicator::GetNewLabel(Int_t i) 
{
  // Gets the label from the new created Map
  // Call CreatLabelMap before
  // otherwise only 0 returned
  return fLabelMap.GetValue(TMath::Abs(i));
}

//_____________________________________________________________________________
void AliAODMuonReplicator::FilterMC(const AliAODEvent& source)
{
  // Filter MC information

  fMCHeader->Reset();
  fMCParticles->Clear("C");

  AliAODMCHeader* mcHeader(0x0);
  TClonesArray* mcParticles(0x0);
  
  fParticleSelected.Delete();
  
  if ( !fTracks->GetEntries() ) return;
  // only copy MC information for events where there's at least one muon track
    
  mcHeader = static_cast<AliAODMCHeader*>(source.FindListObject(AliAODMCHeader::StdBranchName()));
  
  if ( mcHeader ) 
  {
    *fMCHeader = *mcHeader;
  }
  
  mcParticles = static_cast<TClonesArray*>(source.FindListObject(AliAODMCParticle::StdBranchName()));
  
  if ( mcParticles && fMCMode>=2 )
  {
    // loop on (kept) muon tracks to find their ancestors
    TIter nextMT(fTracks);
    AliAODTrack* mt;
    
    while ( ( mt = static_cast<AliAODTrack*>(nextMT()) ) )
    {
      Int_t label = mt->GetLabel();
      
      while ( label >= 0 ) 
      {
        SelectParticle(label);
        AliAODMCParticle* mother = static_cast<AliAODMCParticle*>(mcParticles->UncheckedAt(label));
        if (!mother)
        {
          AliError("Got a null mother ! Check that !");
          label = -1;
        }
        else
        {
          label = mother->GetMother();
        }
      }
    }
    
    CreateLabelMap(source);
    
{'fraction_non_alphanumeric': 0.11788653096578605, 'fraction_numerical': 0.006149848419229103, 'mean_word_length': 3.0957786449095424, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3848282', 'n_tokens_mistral': 3380, 'n_tokens_neox': 3252, 'n_words': 870}