<commit_before>#include "TPDGCode.h"
#include "TFile.h"
#include "TTree.h"
#include "TEventList.h"
#include "TObjArray.h"
#include "TH2.h"

#include "AliLog.h"
#include "AliESDtrack.h"
#include "AliTrackReference.h"

#include "AliTRDReconstructor.h"
#include "AliTRDtrackV1.h"
#include "AliTRDseedV1.h"
#include "AliTRDpidRefMaker.h"
#include "info/AliTRDv0Info.h"
#include "info/AliTRDpidInfo.h"


// Defines and implements basic functionality for building reference data for TRD PID. 
// 
// Here is the list of functionality provided by this class
// 1.
// 2.
// 
// Authors:
//   <NAME> <<EMAIL>>
//   <NAME>    <<EMAIL>>
//   <NAME> <<EMAIL>>
//   <NAME> <<EMAIL>>
// 

ClassImp(AliTRDpidRefMaker)

//________________________________________________________________________
AliTRDpidRefMaker::AliTRDpidRefMaker() 
  :AliTRDrecoTask()
  ,fReconstructor(NULL)
  ,fV0s(NULL)
  ,fData(NULL)
  ,fInfo(NULL)
  ,fPIDdataArray(NULL)
  ,fRefPID(kMC)
  ,fRefP(kMC)
  ,fFreq(1.)
  ,fP(-1.)
  ,fPthreshold(0.)
{
  //
  // Default constructor
  //
  SetNameTitle("PIDrefMaker", "PID Reference Maker");
}

//________________________________________________________________________
AliTRDpidRefMaker::AliTRDpidRefMaker(const char *name, const char *title) 
  :AliTRDrecoTask(name, title)
  ,fReconstructor(NULL)
  ,fV0s(NULL)
  ,fData(NULL)
  ,fInfo(NULL)
  ,fPIDdataArray(NULL)
  ,fRefPID(kMC)
  ,fRefP(kMC)
  ,fFreq(1.)
  ,fP(-1.)
  ,fPthreshold(0.5)
{
  //
  // Default constructor
  //

  fReconstructor = new AliTRDReconstructor();
  fReconstructor->SetRecoParam(AliTRDrecoParam::GetLowFluxParam());
  memset(fdEdx, 0, 10*sizeof(Float_t));
  memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t));

  DefineInput(2, TObjArray::Class()); // v0 list
  DefineInput(3, TObjArray::Class()); // pid info list 
  DefineOutput(2, TTree::Class());
}


//________________________________________________________________________
AliTRDpidRefMaker::~AliTRDpidRefMaker() 
{
  if(fPIDdataArray) delete fPIDdataArray;
  if(fReconstructor) delete fReconstructor;
}

//________________________________________________________________________
Bool_t AliTRDpidRefMaker::CheckQuality(AliTRDseedV1* /*trklt*/)
{
// Place holder for checking tracklet quality for PID.
  return kTRUE;  
}


//________________________________________________________________________
Float_t* AliTRDpidRefMaker::CookdEdx(AliTRDseedV1 *trklt)
{
  trklt->CookdEdx(AliTRDpidUtil::kNNslices);
  memcpy(fdEdx, trklt->GetdEdx(), AliTRDpidUtil::kNNslices*sizeof(Float_t));
  return fdEdx;
}


//________________________________________________________________________
void AliTRDpidRefMaker::UserCreateOutputObjects()
{
  // Create histograms
  // Called once

  fContainer = new TObjArray();
  fContainer->SetName(Form("Moni%s", GetName()));

  TH2 *h2 = new TH2I("hPDG","Particle abundance", AliPID::kSPECIES, -0.5, 4.5, AliTRDCalPID::kNMom, -0.5, AliTRDCalPID::kNMom-0.5);
  TAxis *ax = h2->GetXaxis();
  ax->SetNdivisions(505);
  ax->SetTitle("Particle species");
  for(Int_t is=AliPID::kSPECIES; is--;) ax->SetBinLabel(is+1, AliPID::ParticleShortName(is));
  h2->GetYaxis()->SetTitle("P bins");
  h2->GetYaxis()->SetNdivisions(511);
  fContainer->AddAt(h2, 0);

  fData = new TTree("RefPID", "Reference data for PID");
  fData->Branch("data", &fPIDdataArray);
}

//________________________________________________________________________
void AliTRDpidRefMaker::UserExec(Option_t *) 
{
  // Main loop
  // Called for each event

  if(!(fTracks = dynamic_cast<TObjArray*>(GetInputData(1)))) return;
  if(!(fV0s    = dynamic_cast<TObjArray*>(GetInputData(2)))) return;
  if(!(fInfo   = dynamic_cast<TObjArray*>(GetInputData(3)))) return;

  AliDebug(1, Form("Entries: Tracks[%d] V0[%d] PID[%d]", fTracks->GetEntriesFast(), fV0s->GetEntriesFast(), fInfo->GetEntriesFast()));
  AliTRDtrackInfo     *track = NULL;
  AliTRDtrackV1    *trackTRD = NULL;
  AliTrackReference     *ref = NULL;
  const AliTRDtrackInfo::AliESDinfo *infoESD = NULL;
  for(Int_t itrk=0; itrk<fTracks->GetEntriesFast(); itrk++){
    track = (AliTRDtrackInfo*)fTracks->UncheckedAt(itrk);
    if(!track->HasESDtrack()) continue;
    trackTRD = track->GetTrack();
    infoESD  = track->GetESDinfo();
    Double32_t *infoPID = infoESD->GetSliceIter();
    Int_t n = infoESD->GetNSlices() - AliTRDgeometry::kNlayer;
    if(n==0){
      AliWarning(Form("dEdx info missing in ESD track %d", itrk));
      continue;
    }
    Double32_t *p = &infoPID[n];
    AliDebug(4, Form("n[%d] p[GeV/c]{%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f}", n, p[0], p[1], p[2], p[3], p[4], p[5]));

    ULong_t status = track->GetStatus();
    if(!(status&AliESDtrack::kTPCout)) continue;

    // fill the pid information
    SetRefPID(fRefPID, track, fPID);
    // get particle type
    Int_t idx(TMath::LocMax(AliPID::kSPECIES, fPID)); 
    if(idx == 0 && fPID[0]<1.e-5) continue;<commit_msg>Set acceptance condition on kTRDpid (Alex W)<commit_after>#include "TPDGCode.h"
#include "TFile.h"
#include "TTree.h"
#include "TEventList.h"
#include "TObjArray.h"
#include "TH2.h"

#include "AliLog.h"
#include "AliESDtrack.h"
#include "AliTrackReference.h"

#include "AliTRDReconstructor.h"
#include "AliTRDtrackV1.h"
#include "AliTRDseedV1.h"
#include "AliTRDpidRefMaker.h"
#include "info/AliTRDv0Info.h"
#include "info/AliTRDpidInfo.h"


// Defines and implements basic functionality for building reference data for TRD PID. 
// 
// Here is the list of functionality provided by this class
// 1.
// 2.
// 
// Authors:
//   <NAME> <<EMAIL>>
//   <NAME>    <<EMAIL>>
//   <NAME> <<EMAIL>>
//   <NAME> <<EMAIL>>
// 

ClassImp(AliTRDpidRefMaker)

//________________________________________________________________________
AliTRDpidRefMaker::AliTRDpidRefMaker() 
  :AliTRDrecoTask()
  ,fReconstructor(NULL)
  ,fV0s(NULL)
  ,fData(NULL)
  ,fInfo(NULL)
  ,fPIDdataArray(NULL)
  ,fRefPID(kMC)
  ,fRefP(kMC)
  ,fFreq(1.)
  ,fP(-1.)
  ,fPthreshold(0.)
{
  //
  // Default constructor
  //
  SetNameTitle("PIDrefMaker", "PID Reference Maker");
}

//________________________________________________________________________
AliTRDpidRefMaker::AliTRDpidRefMaker(const char *name, const char *title) 
  :AliTRDrecoTask(name, title)
  ,fReconstructor(NULL)
  ,fV0s(NULL)
  ,fData(NULL)
  ,fInfo(NULL)
  ,fPIDdataArray(NULL)
  ,fRefPID(kMC)
  ,fRefP(kMC)
  ,fFreq(1.)
  ,fP(-1.)
  ,fPthreshold(0.5)
{
  //
  // Default constructor
  //

  fReconstructor = new AliTRDReconstructor();
  fReconstructor->SetRecoParam(AliTRDrecoParam::GetLowFluxParam());
  memset(fdEdx, 0, 10*sizeof(Float_t));
  memset(fPID, 0, AliPID::kSPECIES*sizeof(Float_t));

  DefineInput(2, TObjArray::Class()); // v0 list
  DefineInput(3, TObjArray::Class()); // pid info list 
  DefineOutput(2, TTree::Class());
}


//________________________________________________________________________
AliTRDpidRefMaker::~AliTRDpidRefMaker() 
{
  if(fPIDdataArray) delete fPIDdataArray;
  if(fReconstructor) delete fReconstructor;
}

//________________________________________________________________________
Bool_t AliTRDpidRefMaker::CheckQuality(AliTRDseedV1* /*trklt*/)
{
// Place holder for checking tracklet quality for PID.
  return kTRUE;  
}


//________________________________________________________________________
Float_t* AliTRDpidRefMaker::CookdEdx(AliTRDseedV1 *trklt)
{
  trklt->CookdEdx(AliTRDpidUtil::kNNslices);
  memcpy(fdEdx, trklt->GetdEdx(), AliTRDpidUtil::kNNslices*sizeof(Float_t));
  return fdEdx;
}


//________________________________________________________________________
void AliTRDpidRefMaker::UserCreateOutputObjects()
{
  // Create histograms
  // Called once

  fContainer = new TObjArray();
  fContainer->SetName(Form("Moni%s", GetName()));

  TH2 *h2 = new TH2I("hPDG","Particle abundance", AliPID::kSPECIES, -0.5, 4.5, AliTRDCalPID::kNMom, -0.5, AliTRDCalPID::kNMom-0.5);
  TAxis *ax = h2->GetXaxis();
  ax->SetNdivisions(505);
  ax->SetTitle("Particle species");
  for(Int_t is=AliPID::kSPECIES; is--;) ax->SetBinLabel(is+1, AliPID::ParticleShortName(is));
  h2->GetYaxis()->SetTitle("P bins");
  h2->GetYaxis()->SetNdivisions(511);
  fContainer->AddAt(h2, 0);

  fData = new TTree("RefPID", "Reference data for PID");
  fData->Branch("data", &fPIDdataArray);
}

//________________________________________________________________________
void AliTRDpidRefMaker::UserExec(Option_t *) 
{
  // Main loop
  // Called for each event

  if(!(fTracks = dynamic_cast<TObjArray*>(GetInputData(1)))) return;
  if(!(fV0s    = dynamic_cast<TObjArray*>(GetInputData(2)))) return;
  if(!(fInfo   = dynamic_cast<TObjArray*>(GetInputData(3)))) return;

  AliDebug(1, Form("Entries: Tracks[%d] V0[%d] PID[%d]", fTracks->GetEntriesFast(), fV0s->GetEntriesFast(), fInfo->GetEntriesFast()));
  AliTRDtrackInfo     *track = NULL;
  AliTRDtrackV1    *trackTRD = NULL;
  AliTrackReference     *ref = NULL;
  const AliTRDtrackInfo::AliESDinfo *infoESD = NULL;
  for(Int_t itrk=0; itrk<fTracks->GetEntriesFast(); itrk++){
    track = (AliTRDtrackInfo*)fTracks->UncheckedAt(itrk);
    if(!track->HasESDtrack()) continue;
    trackTRD = track->GetTrack();
    infoESD  = track->GetESDinfo();
    Double32_t *infoPID = infoESD->GetSliceIter();
    Int_t n = infoESD->GetNSlices() - AliTRDgeometry::kNlayer;
    if(n==0){
      AliWarning(Form("dEdx info missing in ESD track %d", itrk));
      continue;
    }
    Double32_t *p = &infoPID[n];
    AliDebug(4, Form("n[%d] p[GeV/c]{%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f}", n, p[0], p[1], p[2], p[3], p[4], p[5]));

    ULong_t status = track->GetStatus();
    if(!(status&AliESDtrack::kTRDpid)) continue;

    // fill the pid information
    SetRefPID(fRefPID, track, fPID);
    // get particle type
    Int_t idx(TMath::LocMax(AliPID::kSPECIES, fPID)); 
    if(idx == 0 && fPID[0]<1.e-5) continue;
{'fraction_non_alphanumeric': 0.15785706982926082, 'fraction_numerical': 0.01738063592679685, 'mean_word_length': 5.109931292941911, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4414855', 'n_tokens_mistral': 3756, 'n_tokens_neox': 3615, 'n_words': 617}