ROOT logo
//
// Computator for single daughters.
// Implements a simple loop on tracks from one of the entry lists
// filled by the task AliRsnInputHandler, adding a check on their
// definition specified in the daughter def.
// Author: A. Pulvirenti
//

#include <Riostream.h>
#include <TEntryList.h>

#include "AliLog.h"

#include "AliRsnEvent.h"
#include "AliRsnDaughterDef.h"
#include "AliRsnDaughterSelector.h"

#include "AliRsnLoopDaughter.h"

ClassImp(AliRsnLoopDaughter)

//_____________________________________________________________________________
AliRsnLoopDaughter::AliRsnLoopDaughter(const char *name, Int_t listID, AliRsnDaughterDef *def) :
   AliRsnLoop(name),
   fTrueMC(kFALSE),
   fOnlyTrue(kFALSE),
   fUseMCRef(kFALSE),
   fListID(listID),
   fDef(def),
   fDaughter()
{
//
// Default constructor
//
}

//_____________________________________________________________________________
AliRsnLoopDaughter::AliRsnLoopDaughter(const AliRsnLoopDaughter &copy) :
   AliRsnLoop(copy),
   fTrueMC(copy.fTrueMC),
   fOnlyTrue(copy.fOnlyTrue),
   fUseMCRef(copy.fUseMCRef),
   fListID(copy.fListID),
   fDef(copy.fDef),
   fDaughter(copy.fDaughter)
{
//
// Copy constructor
//
}

//_____________________________________________________________________________
AliRsnLoopDaughter &AliRsnLoopDaughter::operator=(const AliRsnLoopDaughter &copy)
{
//
// Assignment operator
//

   AliRsnLoop::operator=(copy);
   if (this == &copy)
      return *this;
   fTrueMC = copy.fTrueMC;
   fOnlyTrue = copy.fOnlyTrue;
   fUseMCRef = copy.fUseMCRef;
   fListID = copy.fListID;
   fDaughter = copy.fDaughter;
   fDef = copy.fDef;

   return (*this);
}

//_____________________________________________________________________________
AliRsnLoopDaughter::~AliRsnLoopDaughter()
{
//
// Destructor
//
}

//_____________________________________________________________________________
void AliRsnLoopDaughter::Print(Option_t * /*option*/) const
{
//
// Prints info about pair
//
}

//_____________________________________________________________________________
Bool_t AliRsnLoopDaughter::Init(const char *prefix, TList *list)
{
//
// Initialization function.
// Loops on all functions and eventual the ntuple, to initialize output objects.
//

   return AliRsnLoop::Init(Form("%s_%s", prefix, GetName()), list);
}

//_____________________________________________________________________________
Int_t AliRsnLoopDaughter::DoLoop
(AliRsnEvent *evMain, AliRsnDaughterSelector *selMain, AliRsnEvent *, AliRsnDaughterSelector *)
{
//
// Loop function.
// Computes what is needed from passed events.
// Returns the number of pairs successfully processed.
//

   if (!OkEvent(evMain)) return 0;

   Int_t i, il, nadd = 0, nlist = 0;
   TEntryList *list[2] = {0, 0};

   if (fDef->IsChargeDefined()) {
      list[0] = selMain->GetSelected(fListID, fDef->GetChargeC());
      list[1] = 0x0;
      nlist = 1;
   } else {
      list[0] = selMain->GetSelected(fListID, '+');
      if (list[0]) {
         list[1] = selMain->GetSelected(fListID, '-');
         nlist = 2;
      } else {
         list[0] = selMain->GetSelected(fListID, '0');
         list[1] = 0x0;
         nlist = 1;
      }
   }

   // if it is required to loop over True MC, do this here and skip the rest of the method
   if (fTrueMC) return LoopTrueMC(evMain);

   TObjArrayIter next(&fOutputs);
   AliRsnListOutput *out = 0x0;

   for (il = 0; il < nlist; il++) {
      if (!list[il]) {
         AliError(Form("List #%d is null", il));
         continue;
      }
      for (i = 0; i < list[il]->GetN(); i++) {
         evMain->SetDaughter(fDaughter, (Int_t)list[il]->GetEntry(i));
         // check matching
         if (fOnlyTrue && !fDef->MatchesPID(&fDaughter)) continue;
         if (!fDef->MatchesCharge(&fDaughter)) continue;
         if (!fDef->MatchesRefType(&fDaughter)) continue;
         fDaughter.FillP(fDef->GetMass());
         // fill outputs
         nadd++;
         next.Reset();
         while ( (out = (AliRsnListOutput *)next()) ) {
            out->Fill(&fDaughter);
         }
      }
   }

   return nadd;
}

//_____________________________________________________________________________
Int_t AliRsnLoopDaughter::LoopTrueMC(AliRsnEvent *rsn)
{
//
// Loop on event and fill containers
//

   // check presence of MC reference
   if (!rsn->GetRefMC()) {
      AliError("Need a MC to compute efficiency");
      return 0;
   }

   // check event type:
   // must be ESD or AOD, and then use a bool to know in the rest
   if (!rsn->IsESD() && !rsn->IsAOD()) {
      AliError("Need to process ESD or AOD input");
      return 0;
   }

   // retrieve the MC primary vertex position
   // and do some additional coherence checks
   Int_t npart = 0;
   TClonesArray *listAOD = 0x0;
   if (rsn->IsESD()) {
      npart = rsn->GetRefMCESD()->GetNumberOfTracks();
   } else {
      AliAODEvent *aod = rsn->GetRefMCAOD();
      listAOD = (TClonesArray *)(aod->GetList()->FindObject(AliAODMCParticle::StdBranchName()));
      if (listAOD) npart = listAOD->GetEntries();
   }

   // check number of particles
   if (!npart) {
      AliInfo("Empty event");
      return 0;
   }

   // utility variables
   Int_t ipart, count = 0;
   TObjArrayIter next(&fOutputs);
   AliRsnListOutput *out = 0x0;
   Int_t pdg = AliRsnDaughter::SpeciesPDG(fDef->GetPID());


   // loop over particles
   for (ipart = 0; ipart < npart; ipart++) {
      // check i-th particle
      if (rsn->IsESD()) {
         if (!rsn->GetRefMCESD()->Stack()->IsPhysicalPrimary(ipart)) continue;
         AliMCParticle *part = (AliMCParticle *)rsn->GetRefMCESD()->GetTrack(ipart);
         if (TMath::Abs(part->Particle()->GetPdgCode()) != pdg) continue;
         fDaughter.SetRef  (rsn->GetRefMCESD()->GetTrack(ipart));
         fDaughter.SetRefMC(rsn->GetRefMCESD()->GetTrack(ipart));
      } else {
         AliAODMCParticle *part = (AliAODMCParticle *)listAOD->At(ipart);
         if (!part->IsPhysicalPrimary()) continue;
         if (TMath::Abs(part->GetPdgCode()) != pdg) continue;
         fDaughter.SetRef  ((AliAODMCParticle *)listAOD->At(ipart));
         fDaughter.SetRefMC((AliAODMCParticle *)listAOD->At(ipart));
      }
      //if (fDaughter.GetPDG() != AliRsnDaughter::SpeciesPDG(fDef->GetPID())) continue;
      fDaughter.FillP(fDef->GetMass());
      // fill outputs
      count++;
      next.Reset();
      while ( (out = (AliRsnListOutput *)next()) ) {
         out->Fill(&fDaughter);
      }
   }

   return count;
}
 AliRsnLoopDaughter.cxx:1
 AliRsnLoopDaughter.cxx:2
 AliRsnLoopDaughter.cxx:3
 AliRsnLoopDaughter.cxx:4
 AliRsnLoopDaughter.cxx:5
 AliRsnLoopDaughter.cxx:6
 AliRsnLoopDaughter.cxx:7
 AliRsnLoopDaughter.cxx:8
 AliRsnLoopDaughter.cxx:9
 AliRsnLoopDaughter.cxx:10
 AliRsnLoopDaughter.cxx:11
 AliRsnLoopDaughter.cxx:12
 AliRsnLoopDaughter.cxx:13
 AliRsnLoopDaughter.cxx:14
 AliRsnLoopDaughter.cxx:15
 AliRsnLoopDaughter.cxx:16
 AliRsnLoopDaughter.cxx:17
 AliRsnLoopDaughter.cxx:18
 AliRsnLoopDaughter.cxx:19
 AliRsnLoopDaughter.cxx:20
 AliRsnLoopDaughter.cxx:21
 AliRsnLoopDaughter.cxx:22
 AliRsnLoopDaughter.cxx:23
 AliRsnLoopDaughter.cxx:24
 AliRsnLoopDaughter.cxx:25
 AliRsnLoopDaughter.cxx:26
 AliRsnLoopDaughter.cxx:27
 AliRsnLoopDaughter.cxx:28
 AliRsnLoopDaughter.cxx:29
 AliRsnLoopDaughter.cxx:30
 AliRsnLoopDaughter.cxx:31
 AliRsnLoopDaughter.cxx:32
 AliRsnLoopDaughter.cxx:33
 AliRsnLoopDaughter.cxx:34
 AliRsnLoopDaughter.cxx:35
 AliRsnLoopDaughter.cxx:36
 AliRsnLoopDaughter.cxx:37
 AliRsnLoopDaughter.cxx:38
 AliRsnLoopDaughter.cxx:39
 AliRsnLoopDaughter.cxx:40
 AliRsnLoopDaughter.cxx:41
 AliRsnLoopDaughter.cxx:42
 AliRsnLoopDaughter.cxx:43
 AliRsnLoopDaughter.cxx:44
 AliRsnLoopDaughter.cxx:45
 AliRsnLoopDaughter.cxx:46
 AliRsnLoopDaughter.cxx:47
 AliRsnLoopDaughter.cxx:48
 AliRsnLoopDaughter.cxx:49
 AliRsnLoopDaughter.cxx:50
 AliRsnLoopDaughter.cxx:51
 AliRsnLoopDaughter.cxx:52
 AliRsnLoopDaughter.cxx:53
 AliRsnLoopDaughter.cxx:54
 AliRsnLoopDaughter.cxx:55
 AliRsnLoopDaughter.cxx:56
 AliRsnLoopDaughter.cxx:57
 AliRsnLoopDaughter.cxx:58
 AliRsnLoopDaughter.cxx:59
 AliRsnLoopDaughter.cxx:60
 AliRsnLoopDaughter.cxx:61
 AliRsnLoopDaughter.cxx:62
 AliRsnLoopDaughter.cxx:63
 AliRsnLoopDaughter.cxx:64
 AliRsnLoopDaughter.cxx:65
 AliRsnLoopDaughter.cxx:66
 AliRsnLoopDaughter.cxx:67
 AliRsnLoopDaughter.cxx:68
 AliRsnLoopDaughter.cxx:69
 AliRsnLoopDaughter.cxx:70
 AliRsnLoopDaughter.cxx:71
 AliRsnLoopDaughter.cxx:72
 AliRsnLoopDaughter.cxx:73
 AliRsnLoopDaughter.cxx:74
 AliRsnLoopDaughter.cxx:75
 AliRsnLoopDaughter.cxx:76
 AliRsnLoopDaughter.cxx:77
 AliRsnLoopDaughter.cxx:78
 AliRsnLoopDaughter.cxx:79
 AliRsnLoopDaughter.cxx:80
 AliRsnLoopDaughter.cxx:81
 AliRsnLoopDaughter.cxx:82
 AliRsnLoopDaughter.cxx:83
 AliRsnLoopDaughter.cxx:84
 AliRsnLoopDaughter.cxx:85
 AliRsnLoopDaughter.cxx:86
 AliRsnLoopDaughter.cxx:87
 AliRsnLoopDaughter.cxx:88
 AliRsnLoopDaughter.cxx:89
 AliRsnLoopDaughter.cxx:90
 AliRsnLoopDaughter.cxx:91
 AliRsnLoopDaughter.cxx:92
 AliRsnLoopDaughter.cxx:93
 AliRsnLoopDaughter.cxx:94
 AliRsnLoopDaughter.cxx:95
 AliRsnLoopDaughter.cxx:96
 AliRsnLoopDaughter.cxx:97
 AliRsnLoopDaughter.cxx:98
 AliRsnLoopDaughter.cxx:99
 AliRsnLoopDaughter.cxx:100
 AliRsnLoopDaughter.cxx:101
 AliRsnLoopDaughter.cxx:102
 AliRsnLoopDaughter.cxx:103
 AliRsnLoopDaughter.cxx:104
 AliRsnLoopDaughter.cxx:105
 AliRsnLoopDaughter.cxx:106
 AliRsnLoopDaughter.cxx:107
 AliRsnLoopDaughter.cxx:108
 AliRsnLoopDaughter.cxx:109
 AliRsnLoopDaughter.cxx:110
 AliRsnLoopDaughter.cxx:111
 AliRsnLoopDaughter.cxx:112
 AliRsnLoopDaughter.cxx:113
 AliRsnLoopDaughter.cxx:114
 AliRsnLoopDaughter.cxx:115
 AliRsnLoopDaughter.cxx:116
 AliRsnLoopDaughter.cxx:117
 AliRsnLoopDaughter.cxx:118
 AliRsnLoopDaughter.cxx:119
 AliRsnLoopDaughter.cxx:120
 AliRsnLoopDaughter.cxx:121
 AliRsnLoopDaughter.cxx:122
 AliRsnLoopDaughter.cxx:123
 AliRsnLoopDaughter.cxx:124
 AliRsnLoopDaughter.cxx:125
 AliRsnLoopDaughter.cxx:126
 AliRsnLoopDaughter.cxx:127
 AliRsnLoopDaughter.cxx:128
 AliRsnLoopDaughter.cxx:129
 AliRsnLoopDaughter.cxx:130
 AliRsnLoopDaughter.cxx:131
 AliRsnLoopDaughter.cxx:132
 AliRsnLoopDaughter.cxx:133
 AliRsnLoopDaughter.cxx:134
 AliRsnLoopDaughter.cxx:135
 AliRsnLoopDaughter.cxx:136
 AliRsnLoopDaughter.cxx:137
 AliRsnLoopDaughter.cxx:138
 AliRsnLoopDaughter.cxx:139
 AliRsnLoopDaughter.cxx:140
 AliRsnLoopDaughter.cxx:141
 AliRsnLoopDaughter.cxx:142
 AliRsnLoopDaughter.cxx:143
 AliRsnLoopDaughter.cxx:144
 AliRsnLoopDaughter.cxx:145
 AliRsnLoopDaughter.cxx:146
 AliRsnLoopDaughter.cxx:147
 AliRsnLoopDaughter.cxx:148
 AliRsnLoopDaughter.cxx:149
 AliRsnLoopDaughter.cxx:150
 AliRsnLoopDaughter.cxx:151
 AliRsnLoopDaughter.cxx:152
 AliRsnLoopDaughter.cxx:153
 AliRsnLoopDaughter.cxx:154
 AliRsnLoopDaughter.cxx:155
 AliRsnLoopDaughter.cxx:156
 AliRsnLoopDaughter.cxx:157
 AliRsnLoopDaughter.cxx:158
 AliRsnLoopDaughter.cxx:159
 AliRsnLoopDaughter.cxx:160
 AliRsnLoopDaughter.cxx:161
 AliRsnLoopDaughter.cxx:162
 AliRsnLoopDaughter.cxx:163
 AliRsnLoopDaughter.cxx:164
 AliRsnLoopDaughter.cxx:165
 AliRsnLoopDaughter.cxx:166
 AliRsnLoopDaughter.cxx:167
 AliRsnLoopDaughter.cxx:168
 AliRsnLoopDaughter.cxx:169
 AliRsnLoopDaughter.cxx:170
 AliRsnLoopDaughter.cxx:171
 AliRsnLoopDaughter.cxx:172
 AliRsnLoopDaughter.cxx:173
 AliRsnLoopDaughter.cxx:174
 AliRsnLoopDaughter.cxx:175
 AliRsnLoopDaughter.cxx:176
 AliRsnLoopDaughter.cxx:177
 AliRsnLoopDaughter.cxx:178
 AliRsnLoopDaughter.cxx:179
 AliRsnLoopDaughter.cxx:180
 AliRsnLoopDaughter.cxx:181
 AliRsnLoopDaughter.cxx:182
 AliRsnLoopDaughter.cxx:183
 AliRsnLoopDaughter.cxx:184
 AliRsnLoopDaughter.cxx:185
 AliRsnLoopDaughter.cxx:186
 AliRsnLoopDaughter.cxx:187
 AliRsnLoopDaughter.cxx:188
 AliRsnLoopDaughter.cxx:189
 AliRsnLoopDaughter.cxx:190
 AliRsnLoopDaughter.cxx:191
 AliRsnLoopDaughter.cxx:192
 AliRsnLoopDaughter.cxx:193
 AliRsnLoopDaughter.cxx:194
 AliRsnLoopDaughter.cxx:195
 AliRsnLoopDaughter.cxx:196
 AliRsnLoopDaughter.cxx:197
 AliRsnLoopDaughter.cxx:198
 AliRsnLoopDaughter.cxx:199
 AliRsnLoopDaughter.cxx:200
 AliRsnLoopDaughter.cxx:201
 AliRsnLoopDaughter.cxx:202
 AliRsnLoopDaughter.cxx:203
 AliRsnLoopDaughter.cxx:204
 AliRsnLoopDaughter.cxx:205
 AliRsnLoopDaughter.cxx:206
 AliRsnLoopDaughter.cxx:207
 AliRsnLoopDaughter.cxx:208
 AliRsnLoopDaughter.cxx:209
 AliRsnLoopDaughter.cxx:210
 AliRsnLoopDaughter.cxx:211
 AliRsnLoopDaughter.cxx:212
 AliRsnLoopDaughter.cxx:213
 AliRsnLoopDaughter.cxx:214
 AliRsnLoopDaughter.cxx:215
 AliRsnLoopDaughter.cxx:216
 AliRsnLoopDaughter.cxx:217
 AliRsnLoopDaughter.cxx:218
 AliRsnLoopDaughter.cxx:219
 AliRsnLoopDaughter.cxx:220
 AliRsnLoopDaughter.cxx:221
 AliRsnLoopDaughter.cxx:222
 AliRsnLoopDaughter.cxx:223
 AliRsnLoopDaughter.cxx:224
 AliRsnLoopDaughter.cxx:225
 AliRsnLoopDaughter.cxx:226
 AliRsnLoopDaughter.cxx:227
 AliRsnLoopDaughter.cxx:228
 AliRsnLoopDaughter.cxx:229
 AliRsnLoopDaughter.cxx:230
 AliRsnLoopDaughter.cxx:231
 AliRsnLoopDaughter.cxx:232