Ad-hoc implementation of cuts for pions/kaons/protons for 2010 analysis
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnLoopPair.cxx
CommitLineData
c865cb1d 1//
2// *** Class AliRsnLoopPair ***
3//
4// "Core" method for defining the work on a pari of particles.
5// For one analysis, one must setup one of this for each pair he wants to analyze,
6// adding to it all analysis which he desires to do.
7// Here he defines the cuts, and the particle types and charges, and can add
8// functions which do different operations on the same pair, and some binning
9// with respect to some kinematic variables (eta, momentum)
10//
11// authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
12// M. Vala (email: martin.vala@cern.ch)
13//
14
f34f960b 15#include <Riostream.h>
c865cb1d 16#include <TList.h>
17#include <TEntryList.h>
18
19#include "AliLog.h"
20
21#include "AliRsnMother.h"
22#include "AliRsnCutSet.h"
23#include "AliRsnDaughterSelector.h"
24
25#include "AliRsnLoopPair.h"
26
27ClassImp(AliRsnLoopPair)
28
29//_____________________________________________________________________________
30AliRsnLoopPair::AliRsnLoopPair(const char *name, AliRsnPairDef *def, Bool_t isMixed) :
31 AliRsnLoop(name, isMixed),
32 fOnlyTrue(kFALSE),
33 fCheckDecay(kFALSE),
34 fPairDef(def),
35 fPairCuts(0x0),
36 fMother()
37{
38//
39// Default constructor
40//
41
42 fListID[0] = -1;
43 fListID[1] = -1;
44}
45
46//_____________________________________________________________________________
47AliRsnLoopPair::AliRsnLoopPair(const AliRsnLoopPair& copy) :
48 AliRsnLoop(copy),
49 fOnlyTrue(copy.fOnlyTrue),
50 fCheckDecay(copy.fCheckDecay),
51 fPairDef(copy.fPairDef),
52 fPairCuts(copy.fPairCuts),
53 fMother(copy.fMother)
54{
55//
56// Copy constructor
57//
58
59 fListID[0] = copy.fListID[0];
60 fListID[1] = copy.fListID[1];
61}
62
63//_____________________________________________________________________________
64AliRsnLoopPair& AliRsnLoopPair::operator=(const AliRsnLoopPair& copy)
65{
66 AliRsnLoop::operator=(copy);
67
68 fOnlyTrue = copy.fOnlyTrue;
69 fCheckDecay = copy.fCheckDecay;
70 fPairDef = copy.fPairDef;
71 fPairCuts = copy.fPairCuts;
72 fMother = copy.fMother;
73 fListID[0] = copy.fListID[0];
74 fListID[1] = copy.fListID[1];
75
76 return (*this);
77}
78
79//_____________________________________________________________________________
80AliRsnLoopPair::~AliRsnLoopPair()
81{
82//
83// Destructor
84//
85}
86
87//_____________________________________________________________________________
88void AliRsnLoopPair::Print(Option_t* /*option*/) const
89{
90//
91// Prints info about pair
92//
93
94 AliRsnLoop::Print();
95}
96
97//_____________________________________________________________________________
98Bool_t AliRsnLoopPair::Init(const char *prefix, TList *list)
99{
100//
101// Initialization function.
102// Loops on all functions and eventual the ntuple, to initialize output objects.
103//
104
105 // assign data members relations
106 fMother.SetDaughter(0, &fDaughter[0]);
107 fMother.SetDaughter(1, &fDaughter[1]);
108 AliInfo(Form("[%s] Initialization", GetName()));
109
110 TString name(prefix);
111 name += '_';
112 name += GetName();
113 if (IsMixed()) name.Prepend("mix_");
114
115 return AliRsnLoop::Init(name.Data(), list);
116}
117
118//_____________________________________________________________________________
119Int_t AliRsnLoopPair::DoLoop
120(AliRsnEvent *evMain, AliRsnDaughterSelector *selMain, AliRsnEvent *evMix, AliRsnDaughterSelector *selMix)
121{
122//
123// Loop function.
124// Computes what is needed from passed events.
125// Returns the number of pairs successfully processed.
126//
127
128 if (fIsMixed) {
129 AliDebugClass(1, Form("[%s]: event-mixing loop", GetName()));
130 if (!evMix || !selMix) {
131 AliError(Form("[%s] NULL mixed event when mixing is required: cannot process", GetName()));
132 return 0;
133 }
134 } else {
135 AliDebugClass(1, Form("[%s]: single-event loop", GetName()));
136 evMix = evMain;
137 selMix = selMain;
138 }
139 fMother.SetRefEvent(evMain);
140
141 // check cuts
142 if (!OkEvent(evMain)) {
143 AliDebugClass(1, Form("[%s]: main event not accepted", GetName()));
144 return 0;
145 }
146 if (!OkEvent(evMix)) {
147 AliDebugClass(1, Form("[%s]: mixed event not accepted", GetName()));
148 return 0;
149 }
150
151 Int_t i0, i1, start, npairs = 0;
152
153 TEntryList *list0 = selMain->GetSelected(fListID[0], fPairDef->GetDef1().GetChargeC());
154 TEntryList *list1 = selMix ->GetSelected(fListID[1], fPairDef->GetDef2().GetChargeC());
155 if (!list0 || !list1) {
156 AliError("Can't process NULL lists");
157 return 0;
158 }
159 AliDebugClass(2, Form("[%s]: list counts: %d, %d", GetName(), (Int_t)list0->GetN(), (Int_t)list1->GetN()));
160 if (!list0->GetN() || !list1->GetN()) {
161 AliDebugClass(2, Form("[%s]: at least one list is empty", GetName()));
162 return 0;
163 }
164
165 TObjArrayIter next(&fOutputs);
166 AliRsnListOutput *out = 0x0;
167
168 for (i0 = 0; i0 < list0->GetN(); i0++) {
f34f960b 169 evMain->SetDaughter(fDaughter[0], (Int_t)list0->GetEntry(i0));
170 fDaughter[0].FillP(fPairDef->GetDef1().GetMass());
c865cb1d 171 start = 0;
c865cb1d 172 if (!fIsMixed && list0 == list1) start = i0 + 1;
173 for (i1 = start; i1 < list1->GetN(); i1++) {
f34f960b 174 AliDebugClass(4, Form("Checking entries pair: %d (%d) with %d (%d)", (Int_t)i0, (Int_t)list0->GetEntry(i0), (Int_t)i1, (Int_t)list1->GetEntry(i1)));
175 evMix->SetDaughter(fDaughter[1], (Int_t)list1->GetEntry(i1));
176 fDaughter[1].FillP(fPairDef->GetDef2().GetMass());
177 fMother.Sum(0) = fDaughter[0].Prec() + fDaughter[1].Prec();
178 fMother.Sum(1) = fDaughter[0].Psim() + fDaughter[1].Psim();
179 fMother.Ref(0).SetXYZM(fMother.Sum(0).X(), fMother.Sum(0).Y(), fMother.Sum(0).Z(), fPairDef->GetMotherMass());
180 fMother.Ref(1).SetXYZM(fMother.Sum(1).X(), fMother.Sum(1).Y(), fMother.Sum(1).Z(), fPairDef->GetMotherMass());
181 // check cuts
182 if (fPairCuts) {
183 if (!fPairCuts->IsSelected(&fMother)) {
184 AliDebugClass(2, Form("[%s]: candidate mother didn't pass the cuts", GetName()));
185 continue;
186 }
c865cb1d 187 }
188 // check mother
f34f960b 189 if (fOnlyTrue) {
190 if (!IsTrueMother()) {
191 AliDebugClass(2, Form("[%s]: candidate mother is not true", GetName()));
192 continue;
193 }
c865cb1d 194 }
195 // fill outputs
196 next.Reset();
197 while ( (out = (AliRsnListOutput*)next()) ) {
198 if (out->Fill(&fMother)) npairs++;
199 else AliDebugClass(3, Form("[%s]: failed computation", GetName()));
200 }
201 }
202 }
f34f960b 203
c865cb1d 204 return npairs;
205}
206
207//_____________________________________________________________________________
f34f960b 208Bool_t AliRsnLoopPair::IsTrueMother()
c865cb1d 209{
210//
f34f960b 211// Checks to see if the mother comes from a true resonance.
212// It is triggered by the 'SetOnlyTrue()' function
c865cb1d 213//
f34f960b 214
215 // check #1:
216 // daughters have same mother with the right PDG code
217 Int_t commonPDG = fMother.CommonMother();
218 if (commonPDG != fPairDef->GetMotherPDG()) return kFALSE;
219 AliDebugClass(4, "Found a true mother");
c865cb1d 220
f34f960b 221 // check #2:
222 // checks if daughter have the right particle type
223 // (activated by fCheckDecay)
224 if (fCheckDecay) {
225 AliRsnDaughterDef &def1 = fPairDef->GetDef1();
226 AliRsnDaughterDef &def2 = fPairDef->GetDef2();
227 if (!def1.MatchesPID(&fDaughter[0])) return kFALSE;
228 if (!def2.MatchesPID(&fDaughter[1])) return kFALSE;
c865cb1d 229 }
f34f960b 230 AliDebugClass(4, "Decay products match");
c865cb1d 231
f34f960b 232 return kTRUE;
c865cb1d 233}