]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnPair.cxx
Bug fix (A. Maire)
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPair.cxx
CommitLineData
aec0ec32 1//
2// *** Class AliRsnPair ***
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
922688c0 15#include <Riostream.h>
aec0ec32 16#include "TObjArray.h"
17
18#include "AliLog.h"
19
20#include "AliRsnFunction.h"
21#include "AliRsnPairParticle.h"
22
23#include "AliRsnPair.h"
24
25ClassImp(AliRsnPair)
26
27//_____________________________________________________________________________
28AliRsnPair::AliRsnPair
78b94cbd 29(EPairType type, AliRsnPairDef *def, Int_t mixNum) :
e0baff8c 30 TObject(),
31 fIsMixed(kFALSE),
32 fUseMC(kFALSE),
33 fIsLikeSign(kFALSE),
34 fMixNum(mixNum),
35 fMixingCut(0x0),
922688c0 36 fMatched(mixNum),
e0baff8c 37 fPairDef(def),
38 fPairType(type),
39 fTypePID(AliRsnDaughter::kRealistic),
40 fCutMgr(0),
41 fFunctions("AliRsnFunction", 0)
aec0ec32 42{
43//
44// Default constructor
45//
46
47 SetUp(type);
922688c0 48 if (!fIsMixed) fMatched.Set(1);
aec0ec32 49}
50//_____________________________________________________________________________
51AliRsnPair::~AliRsnPair()
52{
53//
54// Destructor
55//
56}
57
58//_____________________________________________________________________________
59void AliRsnPair::SetUp(EPairType type)
60{
61//
62// Sets up flag values by the pair types
63//
64
65 switch (type)
66 {
67 case kNoPID:
68 SetAllFlags(AliRsnDaughter::kNoPID, kFALSE, kFALSE);
69 break;
70 case kNoPIDMix:
71 SetAllFlags(AliRsnDaughter::kNoPID, kTRUE, kFALSE);
72 break;
73 case kRealisticPID:
74 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE, kFALSE);
75 break;
76 case kRealisticPIDMix:
77 SetAllFlags(AliRsnDaughter::kRealistic, kTRUE, kFALSE);
78 break;
79 case kPerfectPID:
80 // SetAllFlags (AliRsnDaughter::kPerfect, kFALSE, kFALSE);
81 SetAllFlags(AliRsnDaughter::kPerfect, kFALSE, kTRUE);
82 break;
83 case kPerfectPIDMix:
84 // SetAllFlags (AliRsnDaughter::kPerfect, kTRUE, kFALSE);
85 SetAllFlags(AliRsnDaughter::kPerfect, kTRUE, kTRUE);
86 break;
87 default :
88 AliWarning("Wrong type selected: setting up for kRealisticPID.");
89 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE, kFALSE);
90 break;
91 }
92}
93
94//_____________________________________________________________________________
95void AliRsnPair::SetAllFlags(AliRsnDaughter::EPIDMethod pidType, Bool_t isMix, Bool_t useMC)
96{
97//
98// Sets up all flags values
99//
100
101 fTypePID = pidType;
102 fIsMixed = isMix;
103 fUseMC = useMC;
104}
105
106//_____________________________________________________________________________
107void AliRsnPair::Init()
108{
109//
110// Init pair
111//
112
113 fIsLikeSign = fPairDef->IsLikeSign();
114 Print();
115}
116
117//_____________________________________________________________________________
78b94cbd 118void AliRsnPair::Print(Option_t* /*option*/) const
aec0ec32 119{
120//
121// Prints info about pair
122//
123 AliInfo(Form("%s", GetPairHistTitle(0x0).Data()));
124 AliInfo(Form("PDG %d %d", AliRsnPID::PDGCode(fPairDef->GetType(0)),
125 AliRsnPID::PDGCode(fPairDef->GetType(1))));
126 AliInfo(Form("Masses %f %f", fPairDef->GetMass(0), fPairDef->GetMass(1)));
127 AliInfo(Form("Number of functions %d", fFunctions.GetEntries()));
128 switch(fTypePID) {
129 case AliRsnDaughter::kNoPID:
e0baff8c 130 AliInfo("PID method: none");
131 break;
aec0ec32 132 case AliRsnDaughter::kRealistic:
e0baff8c 133 AliInfo("PID method: realistic");
134 break;
aec0ec32 135 case AliRsnDaughter::kPerfect:
e0baff8c 136 AliInfo("PID method: perfect");
137 break;
aec0ec32 138 default:
e0baff8c 139 AliInfo("PID method: undefined");
aec0ec32 140 }
141}
142
143//_____________________________________________________________________________
144void AliRsnPair::ProcessPair(AliRsnEventBuffer *buf)
145{
146//
922688c0 147// Process current event in the passed buffer.
148// If this pair is a single-event pair, only that event is processed,
149// otherwise, if it is a mixing pair, all good matches are found and mixed.
aec0ec32 150//
151
922688c0 152 if (fIsMixed && buf->GetEventsBufferIndex() >= fMixNum) ProcessPairMix(buf);
153 else ProcessPairSingle(buf);
154
155 /*
156 // track type/charge #0 in pairDef is taken from this event,
157 // track tipe/charge #1 is taken from the matched event
aec0ec32 158 AliRsnEvent *e1 = buf->GetCurrentEvent();
159 if (!e1) return;
aec0ec32 160 TArrayI* array1 = e1->GetTracksArray(fTypePID, fPairDef->GetCharge(0), fPairDef->GetType(0));
922688c0 161
162 // reset array of matched events
163 Int_t i;
164 for (i = 0; i < fMixNum; i++) fMatched[i] = -1;
165
166 // here searches for all matched events:
167 // in case of single-event pairs, there will be only one, equal to current,
168 // otherwise there will be many
0ef90328 169 Int_t lastOkEvent = buf->IndexOf(e1) - 1;
922688c0 170 Double_t nMatched = 0.0;
171 if (fIsMixed) {
172 for (i = 0; i < fMixNum; i++) {
173 // find other event by event cut
174 AliRsnEvent *e2 = FindEventByEventCut(buf, lastOkEvent);
175 if (!e2) break;
176 fMatched[i] = lastOkEvent;
177 lastOkEvent--;
178 nMatched++;
179 }
180 if (fMatched.GetSize() < 0) {
181 AliWarning(Form("Event #%d: found no events to match", buf->IndexOf(e1)));
182 return;
78b94cbd 183 }
922688c0 184 }
185 else {
186 fMatched[0] = buf->IndexOf(e1);
187 nMatched = 1;
188 }
189
190 // in order to balance the problem that different events could be matched
191 // a different number of times (between 1 and the maximum allowd quantity),
192 // for each event, the histograms are filled with a variable weight depending
193 // on the number of matches found:
194 Double_t weight = (Double_t)fMixNum / (Double_t)nMatched;
195
196 // now that matched events are found, they are used to fill the histograms
197 TArrayI* array2 = 0;
198 for (i = 0; i < fMixNum; i++) {
199 if (fMatched[i] < 0) break;
200 AliRsnEvent *e2 = buf->GetEvent(fMatched[i]);
aec0ec32 201 array2 = e2->GetTracksArray(fTypePID, fPairDef->GetCharge(1), fPairDef->GetType(1));
922688c0 202 if (fIsMixed) LoopPair(e1, array1, e2, array2, weight);
203 else LoopPair(e1, array1, e2, array2);
204 }
205 */
206}
207
208//_____________________________________________________________________________
209void AliRsnPair::ProcessPairSingle(AliRsnEventBuffer *buf)
210{
211//
212// SINGLE EVENT PROCESSING
213// This function fills the functions' histograms using tracks
214// from the same event for both components of the defined pair.
215// This function is used for signal, like-sign and rotated background.
216//
217
218 AliRsnEvent *event = buf->GetCurrentEvent();
219 if (!event) return;
220
221 TArrayI* array1 = event->GetTracksArray(fTypePID, fPairDef->GetCharge(0), fPairDef->GetType(0));
222 TArrayI* array2 = event->GetTracksArray(fTypePID, fPairDef->GetCharge(1), fPairDef->GetType(1));
223
224 LoopPair(event, array1, event, array2);
225}
226
227//_____________________________________________________________________________
228void AliRsnPair::ProcessPairMix(AliRsnEventBuffer *buf)
229{
230//
231// MIXED EVENT PROCESSING
232// This function fills the functions' histograms using
233// tracks from different events.
234// Used for event mixing.
235//
236
237 // track type/charge #0 in pairDef is taken from this event,
238 // track tipe/charge #1 is taken from the matched events
239 AliRsnEvent *e1 = buf->GetCurrentEvent();
240 if (!e1) return;
241 TArrayI* array10 = e1->GetTracksArray(fTypePID, fPairDef->GetCharge(0), fPairDef->GetType(0));
242 TArrayI* array11 = e1->GetTracksArray(fTypePID, fPairDef->GetCharge(1), fPairDef->GetType(1));
243
244 // find matched events
245 Int_t i, iev = buf->GetEventsBufferIndex();
246 Int_t nMatched = FindMatchedEvents(iev, buf);
247 if (!nMatched) {
248 AliWarning(Form("Event #%d: found no events to match", iev));
249 return;
250 }
251 else if (nMatched < fMixNum) {
252 AliWarning(Form("Event #%d: found only %d events to match", iev, nMatched));
253 return;
254 }
255
256 /*
257 else {
258 TString str("Matched events: ");
259 for (i = 0; i < nMatched; i++) str.Append(Form("%d ", fMatched[i]));
260 AliInfo(Form("Event #%d: %s", iev, str.Data()));
261 }
262 */
263
264 // in order to balance the problem that different events could be matched
265 // a different number of times (between 1 and the maximum allowd quantity),
266 // for each event, the histograms are filled with a variable weight depending
267 // on the number of matches found:
268 // Double_t weight = 0.5 * (Double_t)fMixNum / (Double_t)nMatched;
269
270 // now that matched events are found, they are used to fill the histograms
271 TArrayI *array20 = 0, *array21 = 0;
272 for (i = 0; i < fMixNum; i++) {
273 if (fMatched[i] < 0) break;
274 AliRsnEvent *e2 = buf->GetEvent(fMatched[i]);
275 array20 = e2->GetTracksArray(fTypePID, fPairDef->GetCharge(0), fPairDef->GetType(0));
276 array21 = e2->GetTracksArray(fTypePID, fPairDef->GetCharge(1), fPairDef->GetType(1));
277 // track type/charge #0 from event1, track type/charge #1 from event2
278 LoopPair(e1, array10, e2, array21);
279 // track type/charge #1 from event1, track type/charge #0 from event2
280 LoopPair(e1, array11, e2, array20);
281 }
282}
283
284//_____________________________________________________________________________
285Int_t AliRsnPair::FindMatchedEvents(Int_t evIndex, AliRsnEventBuffer *buf)
286{
287//
288// Resets the 'fMatched' data member and stores into it
289// a number of well-matched events found in the buffer,
290// (maximum amount = fMixNum).
291// The argument is the index of the event to be matched,
292// in the event buffer.
293//
294
295 // reset array of matched events
296 Int_t i;
297 for (i = 0; i < fMixNum; i++) fMatched[i] = -1;
298
299 // starts from the position behind the one
300 // of the event to be matched and goes backward
301 // if it reaches the value 0, stops
302 AliRsnEvent *eventToBeMatched = buf->GetCurrentEvent();
303 AliRsnEvent *matchEvent = 0x0;
304 Int_t checkIndex = evIndex - 1, curIndex = 0;
305 for (;;checkIndex--) {
306 if (checkIndex < 0) checkIndex = buf->GetEventsBufferSize() - 1;
307 if (checkIndex == evIndex) break;
308 matchEvent = buf->GetEvent(checkIndex);
309 if (!matchEvent) continue;
310 if (fMixingCut) {
311 if (fMixingCut->IsSelected(AliRsnCut::kMixEvent, eventToBeMatched, matchEvent)) continue;
312 }
313 // assign to current array slot the matched event
314 // and increment current slot and stops if it exceeds array size
315 fMatched[curIndex++] = checkIndex;
316 if (curIndex >= fMixNum) break;
aec0ec32 317 }
922688c0 318
319 // returns the current index value,
320 // which is also the number of matched events found
321 return curIndex;
aec0ec32 322}
323
324//_____________________________________________________________________________
325AliRsnEvent * AliRsnPair::FindEventByEventCut(AliRsnEventBuffer *buf, Int_t& num)
326{
327//
328// For now it just returns num events before current event
329// in buffer (buf)
330// TODO event cut selection
331//
332
333 AliRsnEvent *returnEvent = 0x0;
334
335 if (fIsMixed)
336 {
e0baff8c 337 //returnEvent = buf->GetEvent(buf->GetEventsBufferIndex() - num);
0ef90328 338 returnEvent = buf->GetNextGoodEvent(num, fMixingCut);
aec0ec32 339 }
340 else
341 {
342 returnEvent = buf->GetCurrentEvent();
343 }
344
345 return returnEvent;
346}
347
348//_____________________________________________________________________________
349void AliRsnPair::LoopPair
922688c0 350(AliRsnEvent * ev1, TArrayI * a1, AliRsnEvent * ev2, TArrayI * a2, Double_t weight)
aec0ec32 351{
352//
353// Loop on all pairs of tracks of the defined types/charges,
354// using the arrays of indexes and the events containing them.
355//
356
e0baff8c 357 if (!a1) {AliDebug(4, "No TArrayI 1 from currentEvent->GetTracksArray(...)"); return;}
358 if (!a2) {AliDebug(4, "No TArrayI 2 from currentEvent->GetTracksArray(...)"); return;}
aec0ec32 359
360 AliRsnDaughter::SetPIDMethod(fTypePID);
361 AliRsnDaughter *daughter1 = 0;
362 AliRsnDaughter *daughter2 = 0;
363 AliRsnFunction *fcn = 0;
364 Int_t j, startj = 0;
365 for (Int_t i = 0; i < a1->GetSize(); i++)
366 {
367 // get track #1
368 daughter1 = (AliRsnDaughter *) ev1->GetTrack(a1->At(i));
369 if (!daughter1) continue;
370 // cuts on track #1
371 if (!CutPass(daughter1)) continue;
372 // get track #2
373 daughter2 = 0;
374 // check starting index for searching the event:
375 // for like-sign pairs we avoid duplicating the pairs
376 if (fIsLikeSign) startj = i+1; else startj = 0;
377 // AliInfo(Form("%d",startj));
378 // loop on event for all track #2 to be combined with the found track #1
379 for (j = startj; j < a2->GetSize(); j++)
380 {
381 daughter2 = (AliRsnDaughter *) ev2->GetTrack(a2->At(j));
382 if (!daughter2) continue;
383 // cuts on track #2
384 if (!CutPass(daughter2)) continue;
385 // make pair
386 AliRsnPairParticle pairParticle;
387 pairParticle.SetPair(daughter1, daughter2);
388 // cuts on pair
389 if (!CutPass(&pairParticle)) continue;
390 // fill all histograms
391 TObjArrayIter nextFcn(&fFunctions);
392 while ( (fcn = (AliRsnFunction*)nextFcn()) ) {
922688c0 393 fcn->Fill(&pairParticle, fPairDef, weight);
aec0ec32 394 }
395 }
396 }
397}
398
399//_____________________________________________________________________________
400TList * AliRsnPair::GenerateHistograms(TString prefix)
401{
402//
403// Generates needed histograms
404//
405
406 TList *list = new TList();
407 list->SetName(GetPairHistName(0x0).Data());
408
409 Char_t hName[255], hTitle[255];
410 AliRsnFunction *fcn = 0;
411 for (Int_t i=0;i< fFunctions.GetEntries();i++)
412 {
413 fcn = (AliRsnFunction*)fFunctions.At(i);
414 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
415 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
416 TList *histos = fcn->Init(hName, hTitle);
417 histos->Print();
418 list->Add(histos);
419 }
420
421 return list;
422}
423
424//_____________________________________________________________________________
425void AliRsnPair::GenerateHistograms(TString prefix, TList *tgt)
426{
427//
428// Generates needed histograms
429//
430
431 if (!tgt) {
432 AliError("NULL target list!");
433 return;
434 }
435
436 Char_t hName[255], hTitle[255];
437 AliRsnFunction *fcn = 0;
438 for (Int_t i=0;i< fFunctions.GetEntries();i++)
439 {
440 fcn = (AliRsnFunction*)fFunctions.At(i);
441 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
442 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
443 fcn->Init(hName, hTitle, tgt);
444 }
445}
446
447//_____________________________________________________________________________
78b94cbd 448TString AliRsnPair::GetPairTypeName(EPairType type) const
aec0ec32 449{
450//
451// Returns type name, made with particle names ant chosen PID
452//
453 switch (type)
454 {
455 case kNoPID : return ("NOPID_");break;
456 case kNoPIDMix : return ("NOPIDMIX_");break;
457 case kRealisticPID : return ("REALISTIC_");break;
458 case kRealisticPIDMix : return ("REALISTICMIX_");break;
459 case kPerfectPID : return ("PERFECT_");break;
460 case kPerfectPIDMix : return ("PERFECTMIX_");break;
461 case kTruePairs : return ("TRUEPAIRS_"); break;
462 default:
463 AliWarning("Unrecognized value of EPairTypeName argument");
464 break;
465 }
466
467 return "NOTYPE";
468}
469
470//_____________________________________________________________________________
78b94cbd 471TString AliRsnPair::GetPairName() const
aec0ec32 472{
473//
474// Retruns pair name
475//
476 TString sName;
477 sName += GetPairTypeName(fPairType);
478 sName += fPairDef->GetPairName();
479
480 return sName;
481}
482
483//_____________________________________________________________________________
78b94cbd 484TString AliRsnPair::GetPairHistName(AliRsnFunction *fcn, TString text) const
aec0ec32 485{
486//
487// Returns eff. mass histogram name
488//
489
490 TString sName;
491 if (fcn)
492 {
493 sName = fcn->GetFcnName();
494 sName += "_";
495 }
496 sName += GetPairName();
497 sName += "_";
498 if (fCutMgr) sName += fCutMgr->GetName();
499 sName += text;
500
501 return sName;
502}
503
504//_____________________________________________________________________________
78b94cbd 505TString AliRsnPair::GetPairHistTitle(AliRsnFunction *fcn, TString text) const
aec0ec32 506{
507//
508// Returns eff. mass histogram title
509//
510
511 TString sTitle;
512 if (fcn)
513 {
514 sTitle = fcn->GetFcnTitle();
515 sTitle += " ";
516 }
517 sTitle += GetPairName();
518 sTitle +=" ";
519 if (fCutMgr) sTitle += fCutMgr->GetTitle();
520 sTitle += text;
521
522 return sTitle;
523}
524
525//_____________________________________________________________________________
526void AliRsnPair::AddFunction(AliRsnFunction *fcn)
527{
528//
529// Adds a new computing function
530//
aec0ec32 531 Int_t size = fFunctions.GetEntries();
532 new(fFunctions[size]) AliRsnFunction(*fcn);
aec0ec32 533}
534
535//________________________________________________________________________________________
536Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
537{
538//
539// Check if the AliRsnDaughter argument pass its cuts.
540// If the cut data member is not initialized for it, returns kTRUE.
541//
542 if (!fCutMgr) return kTRUE;
543 else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
544}
545
546//________________________________________________________________________________________
547Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
548{
549//
550// Check if the AliRsnPairParticle argument pass its cuts.
551// If the cut data member is not initialized for it, returns kTRUE.
552// In this case, another separate check which could be necessary
553// concerns the possibility that the two tracks are a "true pair" of
554// daughters of the same resonance. If the corresponding flag is set,
555// this further check is done, and the method returns kTRUE only
556// when also this check is passed.
557//
558
559 if (!fCutMgr) return kTRUE;
560 else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
561}
562
563//________________________________________________________________________________________
564Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
565{
566//
567// Check if the AliRsnEvent argument pass its cuts.
568// If the cut data member is not initialized for it, returns kTRUE.
569//
570 if (!fCutMgr) return kTRUE;
571 else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);
572}