]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG2/RESONANCES/AliRsnPair.cxx
Attempt to make the HV filtering more robust
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPair.cxx
index 1627fd1bb69493008ef10076f7e94526f8142839..cbaf2b00b03ab7df66bf4ad5c056f5c0dccb63e7 100644 (file)
 //          M. Vala (email: martin.vala@cern.ch)
 //
 
-#include "TObjArray.h"
+#include <TList.h>
 
 #include "AliLog.h"
 
-#include "AliRsnFunction.h"
-#include "AliRsnPairParticle.h"
+#include "AliRsnMother.h"
+#include "AliRsnCutSet.h"
 
 #include "AliRsnPair.h"
 
 ClassImp(AliRsnPair)
 
 //_____________________________________________________________________________
-AliRsnPair::AliRsnPair
-(EPairType type, AliRsnPairDef *def, Int_t mixNum, Double_t mixVzCut, Int_t mixMultCut) :
-  TObject(),
-  fIsMixed(kFALSE),
-  fUseMC(kFALSE),
-  fIsLikeSign(kFALSE),
-  fMixNum(mixNum),
-  fMixingCut(0x0),
-  fPairDef(def),
-  fPairType(type),
-  fTypePID(AliRsnDaughter::kRealistic),
-  fCutMgr(0),
-  fFunctions("AliRsnFunction", 0)
+AliRsnPair::AliRsnPair(const char *name, AliRsnPairDef *def) :
+   TNamed(name, ""),
+   fOnlyTrue(kFALSE),
+   fCheckDecay(kFALSE),
+   fIsMixed(kFALSE),
+   fCount(0),
+   fPairDef(def),
+   fCutManager(Form("cutMgr_%s", name)),
+   fMother()
 {
 //
 // Default constructor
-//
-
-  SetUp(type);
-}
-//_____________________________________________________________________________
-AliRsnPair::~AliRsnPair()
-{
-//
-// Destructor
 //
 }
 
 //_____________________________________________________________________________
-void AliRsnPair::SetUp(EPairType type)
+AliRsnPair::AliRsnPair(const AliRsnPair& copy) :
+   TNamed(copy),
+   fOnlyTrue(copy.fOnlyTrue),
+   fCheckDecay(copy.fCheckDecay),
+   fIsMixed(copy.fIsMixed),
+   fCount(copy.fCount),
+   fPairDef(copy.fPairDef),
+   fCutManager(copy.fCutManager),
+   fMother(copy.fMother)
 {
 //
-// Sets up flag values by the pair types
+// Default constructor
 //
-
-  switch (type)
-  {
-    case kNoPID:
-      SetAllFlags(AliRsnDaughter::kNoPID, kFALSE, kFALSE);
-      break;
-    case kNoPIDMix:
-      SetAllFlags(AliRsnDaughter::kNoPID, kTRUE, kFALSE);
-      break;
-    case kRealisticPID:
-      SetAllFlags(AliRsnDaughter::kRealistic, kFALSE, kFALSE);
-      break;
-    case kRealisticPIDMix:
-      SetAllFlags(AliRsnDaughter::kRealistic, kTRUE, kFALSE);
-      break;
-    case kPerfectPID:
-      // SetAllFlags (AliRsnDaughter::kPerfect, kFALSE, kFALSE);
-      SetAllFlags(AliRsnDaughter::kPerfect, kFALSE, kTRUE);
-      break;
-    case kPerfectPIDMix:
-      // SetAllFlags (AliRsnDaughter::kPerfect, kTRUE, kFALSE);
-      SetAllFlags(AliRsnDaughter::kPerfect, kTRUE, kTRUE);
-      break;
-    default :
-      AliWarning("Wrong type selected: setting up for kRealisticPID.");
-      SetAllFlags(AliRsnDaughter::kRealistic, kFALSE, kFALSE);
-      break;
-  }
 }
 
 //_____________________________________________________________________________
-void AliRsnPair::SetAllFlags(AliRsnDaughter::EPIDMethod pidType, Bool_t isMix, Bool_t useMC)
+AliRsnPair& AliRsnPair::operator=(const AliRsnPair& copy)
 {
-//
-// Sets up all flags values
-//
+   fOnlyTrue = copy.fOnlyTrue;
+   fCheckDecay = copy.fCheckDecay;
+   fIsMixed = copy.fIsMixed;
+   fCount = copy.fCount;
+   fPairDef = copy.fPairDef;
+   fMother = copy.fMother;
+   fCutManager = copy.fCutManager;
 
-  fTypePID = pidType;
-  fIsMixed = isMix;
-  fUseMC = useMC;
+   return (*this);
 }
 
 //_____________________________________________________________________________
-void AliRsnPair::Init()
+AliRsnPair::~AliRsnPair()
 {
 //
-// Init pair
+// Destructor
 //
-
-  fIsLikeSign = fPairDef->IsLikeSign();
-  Print();
 }
 
 //_____________________________________________________________________________
-void AliRsnPair::Print(
+void AliRsnPair::Print(Option_t* /*option*/) const
 {
 //
 // Prints info about pair
 //
-  AliInfo(Form("%s", GetPairHistTitle(0x0).Data()));
-  AliInfo(Form("PDG %d %d", AliRsnPID::PDGCode(fPairDef->GetType(0)),
-               AliRsnPID::PDGCode(fPairDef->GetType(1))));
-  AliInfo(Form("Masses %f %f", fPairDef->GetMass(0), fPairDef->GetMass(1)));
-  AliInfo(Form("Number of functions %d", fFunctions.GetEntries()));
-  switch(fTypePID) {
-    case AliRsnDaughter::kNoPID:
-      AliInfo("PID method: none");
-      break;
-    case AliRsnDaughter::kRealistic:
-      AliInfo("PID method: realistic");
-      break;
-    case AliRsnDaughter::kPerfect:
-      AliInfo("PID method: perfect");
-      break;
-    default:
-      AliInfo("PID method: undefined");
-    }
-}
-
-//_____________________________________________________________________________
-void AliRsnPair::ProcessPair(AliRsnEventBuffer *buf)
-{
-//
-// Process one event in this pair
-//
-
-  AliRsnEvent *e1 = buf->GetCurrentEvent();
-  if (!e1) return;
-//   if (e1->GetMultiplicity() < 1) return;
-  TArrayI* array1 = e1->GetTracksArray(fTypePID, fPairDef->GetCharge(0), fPairDef->GetType(0));
-  
-  Int_t i = 0;
-  Int_t numMixed = 0;
-  Int_t lastOkEvent = 0;
-  TArrayI* array2 = 0;
-  for (i = 0; i < fMixNum; i++)
-  {
-    // find other event by event cut
-    AliRsnEvent *e2 = 0;
-    e2 = FindEventByEventCut(buf, lastOkEvent);
-    if (!e2) return;
-//     if (e2->GetMultiplicity() < 1) continue;
-    array2 = e2->GetTracksArray(fTypePID, fPairDef->GetCharge(1), fPairDef->GetType(1));
-    LoopPair(e1, array1, e2, array2);
-    numMixed++;
-    lastOkEvent++;
-  }
-//  if (fIsMixed) AliInfo (Form ("NumMixed = %d",numMixed));
-}
-
-//_____________________________________________________________________________
-AliRsnEvent * AliRsnPair::FindEventByEventCut(AliRsnEventBuffer *buf, Int_t& num)
-{
-//
-// For now it just returns num events before current event
-// in buffer (buf)
-// TODO event cut selection
-//
-
-  AliRsnEvent *returnEvent = 0x0;
-
-  if (fIsMixed)
-  {
-    //returnEvent = buf->GetEvent(buf->GetEventsBufferIndex() - num);
-    returnEvent = buf->GetNextGoodEvent(num);
-  }
-  else
-  {
-    returnEvent = buf->GetCurrentEvent();
-  }
-
-  return returnEvent;
-}
-
-//_____________________________________________________________________________
-void AliRsnPair::LoopPair
-(AliRsnEvent * ev1, TArrayI * a1, AliRsnEvent * ev2, TArrayI * a2)
-{
-//
-// Loop on all pairs of tracks of the defined types/charges,
-// using the arrays of indexes and the events containing them.
-//
-
-  if (!a1) {AliDebug(4, "No TArrayI 1 from currentEvent->GetTracksArray(...)"); return;}
-  if (!a2) {AliDebug(4, "No TArrayI 2 from currentEvent->GetTracksArray(...)"); return;}
-
-  AliRsnDaughter::SetPIDMethod(fTypePID);
-  AliRsnDaughter *daughter1 = 0;
-  AliRsnDaughter *daughter2 = 0;
-  AliRsnFunction *fcn = 0;
-  Int_t j, startj = 0;
-    for (Int_t i = 0; i < a1->GetSize(); i++)
-    {
-        // get track #1
-        daughter1 = (AliRsnDaughter *) ev1->GetTrack(a1->At(i));
-        if (!daughter1) continue;
-        // cuts on track #1
-        if (!CutPass(daughter1)) continue;
-        // get track #2
-        daughter2 = 0;
-        // check starting index for searching the event:
-        // for like-sign pairs we avoid duplicating the pairs
-        if (fIsLikeSign) startj = i+1; else startj = 0;
-        // AliInfo(Form("%d",startj));
-        // loop on event for all track #2 to be combined with the found track #1
-        for (j = startj; j < a2->GetSize(); j++)
-        {
-            daughter2 = (AliRsnDaughter *) ev2->GetTrack(a2->At(j));
-            if (!daughter2) continue;
-            // cuts on track #2
-            if (!CutPass(daughter2)) continue;
-            // make pair
-            AliRsnPairParticle pairParticle;
-            pairParticle.SetPair(daughter1, daughter2);
-            // cuts on pair
-            if (!CutPass(&pairParticle)) continue;
-            // fill all histograms
-            TObjArrayIter nextFcn(&fFunctions);
-            while ( (fcn = (AliRsnFunction*)nextFcn()) ) {
-                fcn->Fill(&pairParticle, fPairDef);
-            }
-        }
-    }
-}
-
-//_____________________________________________________________________________
-TList * AliRsnPair::GenerateHistograms(TString prefix)
-{
-//
-// Generates needed histograms
-//
-
-  TList *list = new TList();
-  list->SetName(GetPairHistName(0x0).Data());
-
-  Char_t hName[255], hTitle[255];
-  AliRsnFunction *fcn = 0;
-  for (Int_t i=0;i< fFunctions.GetEntries();i++)
-  {
-    fcn = (AliRsnFunction*)fFunctions.At(i);
-    sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
-    sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
-    TList *histos = fcn->Init(hName, hTitle);
-    histos->Print();
-    list->Add(histos);
-  }
-
-  return list;
-}
-
-//_____________________________________________________________________________
-void AliRsnPair::GenerateHistograms(TString prefix, TList *tgt)
-{
-//
-// Generates needed histograms
-//
-
-  if (!tgt) {
-    AliError("NULL target list!");
-    return;
-  }
-
-  Char_t hName[255], hTitle[255];
-  AliRsnFunction *fcn = 0;
-  for (Int_t i=0;i< fFunctions.GetEntries();i++)
-  {
-    fcn = (AliRsnFunction*)fFunctions.At(i);
-    sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
-    sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
-    fcn->Init(hName, hTitle, tgt);
-  }
-}
-
-//_____________________________________________________________________________
-TString AliRsnPair::GetPairTypeName(EPairType type) 
-{
-//
-// Returns type name, made with particle names ant chosen PID
-//
-  switch (type)
-  {
-    case kNoPID : return ("NOPID_");break;
-    case kNoPIDMix : return ("NOPIDMIX_");break;
-    case kRealisticPID : return ("REALISTIC_");break;
-    case kRealisticPIDMix : return ("REALISTICMIX_");break;
-    case kPerfectPID : return ("PERFECT_");break;
-    case kPerfectPIDMix : return ("PERFECTMIX_");break;
-    case kTruePairs : return ("TRUEPAIRS_"); break;
-    default:
-      AliWarning("Unrecognized value of EPairTypeName argument");
-      break;
-  }
-
-  return "NOTYPE";
 }
 
 //_____________________________________________________________________________
-TString AliRsnPair::GetPairName() 
+Bool_t AliRsnPair::Fill
+(AliRsnDaughter *daughter1, AliRsnDaughter *daughter2, Bool_t refFirst)
 {
 //
-// Retruns pair name
+// Checks that first argument matches definitions for first daughter
+// and the same for second argument, where the order is defined by
+// the AliRsnPairDef data member.
+// If the matching is successful, the AliRsnMother data member is 
+// initialized using the mass hypotheses defined here and the momenta
+// in the passed daughters.
+// The third argument is necessary to choose which one of the possible two
+// events owning the two daughter will be used as reference.
 //
-  TString sName;
-  sName += GetPairTypeName(fPairType);
-  sName += fPairDef->GetPairName();
+   
+   // check matching and exit if one of them fails
+   // if true pair is required, this is taken into account:
+   // if both true pairs and correct decay tree is required,
+   // then we must be sure that also the true PID of daughters matches,
+   // instead if correct decay tree is not required this additional check is not done
+   if (!fPairDef->GetDef1()->MatchesDaughter(daughter1, fOnlyTrue && fCheckDecay)) return kFALSE;
+   if (!fPairDef->GetDef2()->MatchesDaughter(daughter2, fOnlyTrue && fCheckDecay)) return kFALSE;
+   
+   // if matching is successful
+   // compute 4-momenta of daughters and mother
+   fMother.SetDaughter(0, daughter1);
+   fMother.SetDaughter(1, daughter2);
+   fMother.ComputeSum(fPairDef->GetMass1(), fPairDef->GetMass2());
+   
+   // assign reference event
+   if (refFirst) fMother.SetRefEvent(daughter1->GetOwnerEvent()); else fMother.SetRefEvent(daughter2->GetOwnerEvent());
+   
+   // if required a true pair, check this here and eventually return a fail message
+   // this is done using the method AliRsnMother::CommonMother with 2 arguments
+   // passed by reference, where the real GEANT label of the particle is stored
+   // and one can check if these tracks are both really secondaries (ID >= 0)
+   if (fOnlyTrue) {
+      Int_t m0, m1, common;
+      common = fMother.CommonMother(m0, m1);
+      if (m0 < 0 || m1 < 0) return kFALSE;
+      if (common != fPairDef->GetMotherPDG()) return kFALSE;
+   }
+   
+   // point to first event as reference
+   // and checks the pair cuts,
+   // (done first because it is more likely 
+   // that it is not passed and execution is faster)
+   if (!fCutManager.PassMotherCuts(&fMother)) return kFALSE;
 
-  return sName;
-}
+   // cuts on track #1 & common
+   if (!fCutManager.PassDaughter1Cuts(daughter1)) {
+      AliDebug(AliLog::kDebug + 2, "Specific cuts for track #1 not passed");
+      return kFALSE;
+   }
+   if (!fCutManager.PassCommonDaughterCuts(daughter1)) {
+      AliDebug(AliLog::kDebug + 2, "Common cuts for track #1 not passed");
+      return kFALSE;
+   }
 
-//_____________________________________________________________________________
-TString AliRsnPair::GetPairHistName(AliRsnFunction *fcn, TString text)
-{
-//
-// Returns eff. mass histogram name
-//
+   // cuts on track #2 & common
+   if (!fCutManager.PassDaughter2Cuts(daughter2)) {
+      AliDebug(AliLog::kDebug + 2, "Specific cuts for track #2 not passed");
+      return kFALSE;
+   }
+   if (!fCutManager.PassCommonDaughterCuts(daughter2)) {
+      AliDebug(AliLog::kDebug + 2, "Common cuts for track #2 not passed");
+      return kFALSE;
+   }
 
-  TString sName;
-  if (fcn)
-  {
-    sName = fcn->GetFcnName();
-    sName += "_";
-  }
-  sName += GetPairName();
-  sName += "_";
-  if (fCutMgr) sName += fCutMgr->GetName();
-  sName += text;
+   // if pair is accepted, increment counter
+   ++fCount;
 
-  return sName;
+   return kTRUE;
 }
 
 //_____________________________________________________________________________
-TString AliRsnPair::GetPairHistTitle(AliRsnFunction *fcn, TString text)
+void AliRsnPair::Compute()
 {
 //
-// Returns eff. mass histogram title
+// Virtual method to compute pair quantities of interest
 //
 
-  TString sTitle;
-  if (fcn)
-  {
-    sTitle = fcn->GetFcnTitle();
-    sTitle += " ";
-  }
-  sTitle += GetPairName();
-  sTitle +=" ";
-  if (fCutMgr) sTitle += fCutMgr->GetTitle();
-  sTitle += text;
-
-  return sTitle;
+   AliWarning("Implement this method in derived classes");
 }
 
 //_____________________________________________________________________________
-void AliRsnPair::AddFunction(AliRsnFunction *fcn)
+void AliRsnPair::Init(const char* /*prefix*/, TList* /*list*/)
 {
 //
-// Adds a new computing function
+// Virtual method to compute pair quantities of interest
 //
-  Int_t size = fFunctions.GetEntries();
-  new(fFunctions[size]) AliRsnFunction(*fcn);
-}
 
-//________________________________________________________________________________________
-Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
-{
-//
-// Check if the AliRsnDaughter argument pass its cuts.
-// If the cut data member is not initialized for it, returns kTRUE.
-//
-  if (!fCutMgr) return kTRUE;
-  else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
-}
-
-//________________________________________________________________________________________
-Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
-{
-//
-// Check if the AliRsnPairParticle argument pass its cuts.
-// If the cut data member is not initialized for it, returns kTRUE.
-// In this case, another separate check which could be necessary
-// concerns the possibility that the two tracks are a "true pair" of
-// daughters of the same resonance. If the corresponding flag is set,
-// this further check is done, and the method returns kTRUE only
-// when also this check is passed.
-//
-
-  if (!fCutMgr) return kTRUE;
-  else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
-}
-
-//________________________________________________________________________________________
-Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
-{
-//
-// Check if the AliRsnEvent argument pass its cuts.
-// If the cut data member is not initialized for it, returns kTRUE.
-//
-  if (!fCutMgr) return kTRUE;
-  else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);
+   AliWarning("Implement this method in derived classes");
 }