2 // *** Class AliRsnPair ***
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)
11 // authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
12 // M. Vala (email: martin.vala@cern.ch)
15 #include "TObjArray.h"
19 #include "AliRsnFunction.h"
20 #include "AliRsnPairParticle.h"
22 #include "AliRsnPair.h"
26 //_____________________________________________________________________________
27 AliRsnPair::AliRsnPair
28 (EPairType type, AliRsnPairDef *def, Int_t mixNum, Double_t mixVzCut, Int_t mixMultCut) :
37 fTypePID(AliRsnDaughter::kRealistic),
39 fFunctions("AliRsnFunction", 0)
42 // Default constructor
47 //_____________________________________________________________________________
48 AliRsnPair::~AliRsnPair()
55 //_____________________________________________________________________________
56 void AliRsnPair::SetUp(EPairType type)
59 // Sets up flag values by the pair types
65 SetAllFlags(AliRsnDaughter::kNoPID, kFALSE, kFALSE);
68 SetAllFlags(AliRsnDaughter::kNoPID, kTRUE, kFALSE);
71 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE, kFALSE);
73 case kRealisticPIDMix:
74 SetAllFlags(AliRsnDaughter::kRealistic, kTRUE, kFALSE);
77 // SetAllFlags (AliRsnDaughter::kPerfect, kFALSE, kFALSE);
78 SetAllFlags(AliRsnDaughter::kPerfect, kFALSE, kTRUE);
81 // SetAllFlags (AliRsnDaughter::kPerfect, kTRUE, kFALSE);
82 SetAllFlags(AliRsnDaughter::kPerfect, kTRUE, kTRUE);
85 AliWarning("Wrong type selected: setting up for kRealisticPID.");
86 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE, kFALSE);
91 //_____________________________________________________________________________
92 void AliRsnPair::SetAllFlags(AliRsnDaughter::EPIDMethod pidType, Bool_t isMix, Bool_t useMC)
95 // Sets up all flags values
103 //_____________________________________________________________________________
104 void AliRsnPair::Init()
110 fIsLikeSign = fPairDef->IsLikeSign();
114 //_____________________________________________________________________________
115 void AliRsnPair::Print()
118 // Prints info about pair
120 AliInfo(Form("%s", GetPairHistTitle(0x0).Data()));
121 AliInfo(Form("PDG %d %d", AliRsnPID::PDGCode(fPairDef->GetType(0)),
122 AliRsnPID::PDGCode(fPairDef->GetType(1))));
123 AliInfo(Form("Masses %f %f", fPairDef->GetMass(0), fPairDef->GetMass(1)));
124 AliInfo(Form("Number of functions %d", fFunctions.GetEntries()));
126 case AliRsnDaughter::kNoPID:
127 AliInfo("PID method: none");
129 case AliRsnDaughter::kRealistic:
130 AliInfo("PID method: realistic");
132 case AliRsnDaughter::kPerfect:
133 AliInfo("PID method: perfect");
136 AliInfo("PID method: undefined");
140 //_____________________________________________________________________________
141 void AliRsnPair::ProcessPair(AliRsnEventBuffer *buf)
144 // Process one event in this pair
147 AliRsnEvent *e1 = buf->GetCurrentEvent();
149 // if (e1->GetMultiplicity() < 1) return;
150 TArrayI* array1 = e1->GetTracksArray(fTypePID, fPairDef->GetCharge(0), fPairDef->GetType(0));
154 //Int_t lastOkEvent = buf->IndexOf(e1) - 2*fMixNum;
155 //if (lastOkEvent < 0) lastOkEvent = 0;
156 Int_t lastOkEvent = buf->IndexOf(e1) - 1;
158 for (i = 0; i < fMixNum; i++)
160 // find other event by event cut
162 e2 = FindEventByEventCut(buf, lastOkEvent);
165 //AliInfo(Form("ev1 = #%d -- ev2 = #%d -- nMixed = %d/%d", buf->IndexOf(e1), buf->IndexOf(e2), i, fMixNum));
166 //AliInfo(Form("Diff Mult = %d", TMath::Abs(e1->GetMultiplicity() - e2->GetMultiplicity())));
167 //AliInfo(Form("Diff Vz = %f", TMath::Abs(e1->GetVz() - e2->GetVz())));
168 //AliInfo(Form("Diff Phi = %f", TMath::Abs(e1->GetPhiMean() - e2->GetPhiMean())));
170 // if (e2->GetMultiplicity() < 1) continue;
171 array2 = e2->GetTracksArray(fTypePID, fPairDef->GetCharge(1), fPairDef->GetType(1));
172 LoopPair(e1, array1, e2, array2);
176 // if (fIsMixed) AliInfo (Form ("NumMixed = %d",numMixed));
179 //_____________________________________________________________________________
180 AliRsnEvent * AliRsnPair::FindEventByEventCut(AliRsnEventBuffer *buf, Int_t& num)
183 // For now it just returns num events before current event
185 // TODO event cut selection
188 AliRsnEvent *returnEvent = 0x0;
192 //returnEvent = buf->GetEvent(buf->GetEventsBufferIndex() - num);
193 returnEvent = buf->GetNextGoodEvent(num, fMixingCut);
197 returnEvent = buf->GetCurrentEvent();
203 //_____________________________________________________________________________
204 void AliRsnPair::LoopPair
205 (AliRsnEvent * ev1, TArrayI * a1, AliRsnEvent * ev2, TArrayI * a2)
208 // Loop on all pairs of tracks of the defined types/charges,
209 // using the arrays of indexes and the events containing them.
212 if (!a1) {AliDebug(4, "No TArrayI 1 from currentEvent->GetTracksArray(...)"); return;}
213 if (!a2) {AliDebug(4, "No TArrayI 2 from currentEvent->GetTracksArray(...)"); return;}
215 AliRsnDaughter::SetPIDMethod(fTypePID);
216 AliRsnDaughter *daughter1 = 0;
217 AliRsnDaughter *daughter2 = 0;
218 AliRsnFunction *fcn = 0;
220 for (Int_t i = 0; i < a1->GetSize(); i++)
223 daughter1 = (AliRsnDaughter *) ev1->GetTrack(a1->At(i));
224 if (!daughter1) continue;
226 if (!CutPass(daughter1)) continue;
229 // check starting index for searching the event:
230 // for like-sign pairs we avoid duplicating the pairs
231 if (fIsLikeSign) startj = i+1; else startj = 0;
232 // AliInfo(Form("%d",startj));
233 // loop on event for all track #2 to be combined with the found track #1
234 for (j = startj; j < a2->GetSize(); j++)
236 daughter2 = (AliRsnDaughter *) ev2->GetTrack(a2->At(j));
237 if (!daughter2) continue;
239 if (!CutPass(daughter2)) continue;
241 AliRsnPairParticle pairParticle;
242 pairParticle.SetPair(daughter1, daughter2);
244 if (!CutPass(&pairParticle)) continue;
245 // fill all histograms
246 TObjArrayIter nextFcn(&fFunctions);
247 while ( (fcn = (AliRsnFunction*)nextFcn()) ) {
248 fcn->Fill(&pairParticle, fPairDef);
254 //_____________________________________________________________________________
255 TList * AliRsnPair::GenerateHistograms(TString prefix)
258 // Generates needed histograms
261 TList *list = new TList();
262 list->SetName(GetPairHistName(0x0).Data());
264 Char_t hName[255], hTitle[255];
265 AliRsnFunction *fcn = 0;
266 for (Int_t i=0;i< fFunctions.GetEntries();i++)
268 fcn = (AliRsnFunction*)fFunctions.At(i);
269 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
270 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
271 TList *histos = fcn->Init(hName, hTitle);
279 //_____________________________________________________________________________
280 void AliRsnPair::GenerateHistograms(TString prefix, TList *tgt)
283 // Generates needed histograms
287 AliError("NULL target list!");
291 Char_t hName[255], hTitle[255];
292 AliRsnFunction *fcn = 0;
293 for (Int_t i=0;i< fFunctions.GetEntries();i++)
295 fcn = (AliRsnFunction*)fFunctions.At(i);
296 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
297 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
298 fcn->Init(hName, hTitle, tgt);
302 //_____________________________________________________________________________
303 TString AliRsnPair::GetPairTypeName(EPairType type)
306 // Returns type name, made with particle names ant chosen PID
310 case kNoPID : return ("NOPID_");break;
311 case kNoPIDMix : return ("NOPIDMIX_");break;
312 case kRealisticPID : return ("REALISTIC_");break;
313 case kRealisticPIDMix : return ("REALISTICMIX_");break;
314 case kPerfectPID : return ("PERFECT_");break;
315 case kPerfectPIDMix : return ("PERFECTMIX_");break;
316 case kTruePairs : return ("TRUEPAIRS_"); break;
318 AliWarning("Unrecognized value of EPairTypeName argument");
325 //_____________________________________________________________________________
326 TString AliRsnPair::GetPairName()
332 sName += GetPairTypeName(fPairType);
333 sName += fPairDef->GetPairName();
338 //_____________________________________________________________________________
339 TString AliRsnPair::GetPairHistName(AliRsnFunction *fcn, TString text)
342 // Returns eff. mass histogram name
348 sName = fcn->GetFcnName();
351 sName += GetPairName();
353 if (fCutMgr) sName += fCutMgr->GetName();
359 //_____________________________________________________________________________
360 TString AliRsnPair::GetPairHistTitle(AliRsnFunction *fcn, TString text)
363 // Returns eff. mass histogram title
369 sTitle = fcn->GetFcnTitle();
372 sTitle += GetPairName();
374 if (fCutMgr) sTitle += fCutMgr->GetTitle();
380 //_____________________________________________________________________________
381 void AliRsnPair::AddFunction(AliRsnFunction *fcn)
384 // Adds a new computing function
386 Int_t size = fFunctions.GetEntries();
387 new(fFunctions[size]) AliRsnFunction(*fcn);
390 //________________________________________________________________________________________
391 Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
394 // Check if the AliRsnDaughter argument pass its cuts.
395 // If the cut data member is not initialized for it, returns kTRUE.
397 if (!fCutMgr) return kTRUE;
398 else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
401 //________________________________________________________________________________________
402 Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
405 // Check if the AliRsnPairParticle argument pass its cuts.
406 // If the cut data member is not initialized for it, returns kTRUE.
407 // In this case, another separate check which could be necessary
408 // concerns the possibility that the two tracks are a "true pair" of
409 // daughters of the same resonance. If the corresponding flag is set,
410 // this further check is done, and the method returns kTRUE only
411 // when also this check is passed.
414 if (!fCutMgr) return kTRUE;
415 else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
418 //________________________________________________________________________________________
419 Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
422 // Check if the AliRsnEvent argument pass its cuts.
423 // If the cut data member is not initialized for it, returns kTRUE.
425 if (!fCutMgr) return kTRUE;
426 else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);