]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnPair.cxx
fix for bug #70582 (change from L. Molnar)
[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
4fbb2459 15#include <TList.h>
aec0ec32 16
17#include "AliLog.h"
18
4fbb2459 19#include "AliRsnEvent.h"
aec0ec32 20#include "AliRsnFunction.h"
4fbb2459 21#include "AliRsnPIDIndex.h"
22#include "AliRsnCutMgr.h"
23#include "AliRsnCutStd.h"
aec0ec32 24
25#include "AliRsnPair.h"
26
27ClassImp(AliRsnPair)
28
29//_____________________________________________________________________________
15d5fd02 30AliRsnPair::AliRsnPair(EPairType type, AliRsnPairDef *def) :
5eb970a4 31 TObject(),
4fbb2459 32 fOnlyTrue(kFALSE),
5eb970a4 33 fIsMixed(kFALSE),
34 fPairType(type),
35 fPIDMethod(AliRsnDaughter::kRealistic),
36 fPairDef(def),
37 fCutMgr(0),
38 fFunctions("AliRsnFunction", 0),
39 fTrack1(),
e79f56bd 40 fTrack2(),
41 fPairParticle()
aec0ec32 42{
43//
44// Default constructor
45//
5eb970a4 46 AliDebug(AliLog::kDebug+2,"<-");
47 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 48 SetUp(type);
49}
413bbf44 50
51//_____________________________________________________________________________
52AliRsnPair::AliRsnPair(const AliRsnPair& copy) :
53 TObject(),
54 fOnlyTrue(copy.fOnlyTrue),
55 fIsMixed(copy.fIsMixed),
56 fPairType(copy.fPairType),
57 fPIDMethod(copy.fPIDMethod),
58 fPairDef(copy.fPairDef),
59 fCutMgr(copy.fCutMgr),
60 fFunctions(copy.fFunctions),
61 fTrack1(copy.fTrack1),
62 fTrack2(copy.fTrack2),
63 fPairParticle(copy.fPairParticle)
64{
65//
66// Default constructor
67//
68 AliDebug(AliLog::kDebug+2,"<-");
69 AliDebug(AliLog::kDebug+2,"->");
70}
71
72//_____________________________________________________________________________
73AliRsnPair& AliRsnPair::operator=(const AliRsnPair& copy)
74{
75 fOnlyTrue = copy.fOnlyTrue;
76 fIsMixed = copy.fIsMixed;
77 fPairType = copy.fPairType;
78 fPIDMethod = copy.fPIDMethod;
79 fPairDef = copy.fPairDef;
80 fCutMgr = copy.fCutMgr;
81 fTrack1 = copy.fTrack1;
82 fTrack2 = copy.fTrack2;
83 fPairParticle = copy.fPairParticle;
84
85 Int_t i, n = copy.fFunctions.GetEntries();
86 for (i = 0; i < n; i++)
87 {
88 AliRsnFunction *fcn = (AliRsnFunction*)copy.fFunctions[i];
89 if (fcn) AddFunction(fcn);
90 }
91
92 return (*this);
93}
94
aec0ec32 95//_____________________________________________________________________________
96AliRsnPair::~AliRsnPair()
97{
98//
99// Destructor
100//
5eb970a4 101 AliDebug(AliLog::kDebug+2,"<-");
102 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 103}
104
105//_____________________________________________________________________________
106void AliRsnPair::SetUp(EPairType type)
107{
108//
109// Sets up flag values by the pair types
110//
5eb970a4 111 AliDebug(AliLog::kDebug+2,"<-");
112 switch (type) {
4fbb2459 113 case kNoPID:
114 SetAllFlags(AliRsnDaughter::kNoPID, kFALSE);
115 break;
116 case kNoPIDMix:
117 SetAllFlags(AliRsnDaughter::kNoPID, kTRUE);
118 break;
119 case kRealisticPID:
120 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
121 break;
122 case kRealisticPIDMix:
123 SetAllFlags(AliRsnDaughter::kRealistic, kTRUE);
124 break;
125 case kPerfectPID:
126 SetAllFlags(AliRsnDaughter::kPerfect, kFALSE);
127 break;
128 case kPerfectPIDMix:
129 SetAllFlags(AliRsnDaughter::kPerfect, kTRUE);
130 break;
131 default :
132 AliWarning("Wrong type selected: setting up for realistic PID - no mixing.");
133 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
134 break;
aec0ec32 135 }
5eb970a4 136 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 137}
138
aec0ec32 139//_____________________________________________________________________________
78b94cbd 140void AliRsnPair::Print(Option_t* /*option*/) const
aec0ec32 141{
142//
143// Prints info about pair
144//
5eb970a4 145 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 146 AliInfo(Form("%s", GetPairHistTitle(0x0).Data()));
5eb970a4 147 AliInfo(Form("PDG %d %d", AliPID::ParticleCode(fPairDef->GetType(0)),
148 AliPID::ParticleCode(fPairDef->GetType(1))));
aec0ec32 149 AliInfo(Form("Masses %f %f", fPairDef->GetMass(0), fPairDef->GetMass(1)));
150 AliInfo(Form("Number of functions %d", fFunctions.GetEntries()));
15d5fd02 151
5eb970a4 152 switch (fPIDMethod) {
4fbb2459 153 case AliRsnDaughter::kNoPID:
154 AliInfo("PID method: none");
155 break;
156 case AliRsnDaughter::kRealistic:
157 AliInfo("PID method: realistic");
158 break;
159 case AliRsnDaughter::kPerfect:
160 AliInfo("PID method: perfect");
161 break;
162 default:
163 AliInfo("PID method: undefined");
922688c0 164 }
5eb970a4 165 AliDebug(AliLog::kDebug+2,"->");
922688c0 166}
167
168//_____________________________________________________________________________
4fbb2459 169void AliRsnPair::LoopPair(AliRsnPIDIndex *const pidIndex1, AliRsnEvent *const ev1, AliRsnPIDIndex *const pidIndex2, AliRsnEvent *const ev2)
922688c0 170{
171//
5eb970a4 172// Prepare the loop for computation of functions.
173// Each PIDIndex is used to retrieve the appropriate array of indexes
174// of the tracks to be used in each event.
175// In case of single-event analysis, only the first two arguments are used
176// and both arrays are taken from the same PIDIndex and will loop on the same event
177// In case of mixing, all arguments are used, and first set of tracks will be found
178// in the first event with the first PIDIndex, and the second set of tracks will
179// be found in second event with second PIDIndex.
922688c0 180//
181
5eb970a4 182 AliDebug(AliLog::kDebug+2,"<-");
922688c0 183
5eb970a4 184 TArrayI *a1 = 0;
185 TArrayI *a2 = 0;
922688c0 186
4fbb2459 187 if (fPIDMethod == AliRsnDaughter::kNoPID) {
5eb970a4 188 AliDebug(AliLog::kDebug+2, Form("Returning indexes of with NO PID (%d) ...", fPIDMethod));
189 a1 = pidIndex1->GetTracksArray(fPIDMethod, fPairDef->GetCharge(0), AliPID::kUnknown);
190 if (pidIndex2 && ev2)
191 a2 = pidIndex2->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), AliPID::kUnknown);
192 else
193 a2 = pidIndex1->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), AliPID::kUnknown);
4fbb2459 194 } else {
5eb970a4 195 AliDebug(AliLog::kDebug+2, Form("Returning indexes of with PID (%d) ...", fPIDMethod));
196 a1 = pidIndex1->GetTracksArray(fPIDMethod,fPairDef->GetCharge(0), (AliPID::EParticleType)fPairDef->GetType(0));
197 if (pidIndex2 && ev2)
198 a2 = pidIndex2->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), (AliPID::EParticleType)fPairDef->GetType(1));
199 else
200 a2 = pidIndex1->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), (AliPID::EParticleType)fPairDef->GetType(1));
201 }
202
203 LoopPair(a1, a2, ev1, ev2);
204
205 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 206}
207
208//_____________________________________________________________________________
5eb970a4 209void AliRsnPair::LoopPair(TArrayI *a1, TArrayI *a2, AliRsnEvent *ev1, AliRsnEvent *ev2)
aec0ec32 210{
211//
212// Loop on all pairs of tracks of the defined types/charges,
213// using the arrays of indexes and the events containing them.
15d5fd02 214// This method is private, for safety reasons.
aec0ec32 215//
5eb970a4 216 AliDebug(AliLog::kDebug+2,"<-");
217 if (!ev1) {AliError(Form("ev1 is %p. skipping LoopPair() ...",ev1))return;}
218 AliDebug(AliLog::kDebug+1,"ev1 is OK ...");
219
220
221 if (!ev2) {
222 if (fIsMixed) {
4fbb2459 223 AliDebug(AliLog::kDebug+1, "ev2 is null and fIsMixed is true. Skipping ...");
5eb970a4 224 return;
225 }
226 ev2 = ev1;
227 }
228
9477aa42 229 if (!(ev1 == ev2)) {
230 AliDebug(AliLog::kDebug+1,"ev1 is different then ev2 ...");
231 }
232
4fbb2459 233 if (!a1) {AliDebug(AliLog::kDebug+1, "No TArrayI 1 from currentEvent->GetTracksArray(...)"); return;}
234 if (!a2) {AliDebug(AliLog::kDebug+1, "No TArrayI 2 from currentEvent->GetTracksArray(...)"); return;}
5eb970a4 235
236 AliDebug(AliLog::kDebug+1,Form("a1=%d a2=%d",a1->GetSize(),a2->GetSize()));
4fbb2459 237 if (a1->GetSize()<=0) {AliDebug(AliLog::kDebug+1, "Size of TArrayI 1 is 0 or less ..."); return;}
238 if (a2->GetSize()<=0) {AliDebug(AliLog::kDebug+1, "Size of TArrayI 2 is 0 or less ..."); return;}
aec0ec32 239
4fbb2459 240 AliDebug(AliLog::kDebug,Form("Indexes_a1=%d Indexes_a2=%d",a1->GetSize(),a2->GetSize()));
aec0ec32 241
15d5fd02 242 // cuts on events
243 if (!CutPass(ev1) || !CutPass(ev2)) return;
5eb970a4 244 AliDebug(AliLog::kDebug+1,"Event cut passed...");
15d5fd02 245 AliRsnDaughter::SetPIDMethod(fPIDMethod);
aec0ec32 246 AliRsnFunction *fcn = 0;
15d5fd02 247
248 Bool_t isLikeSign = fPairDef->IsLikeSign();
aec0ec32 249 Int_t j, startj = 0;
15d5fd02 250
5eb970a4 251 for (Int_t i = 0; i < a1->GetSize(); i++) {
252 // get track #1
253 ev1->SetDaughter(fTrack1, a1->At(i));
254 if (!fTrack1.IsOK()) continue;
5bd59e02 255 // assign the required PID type to track #1
256 fTrack1.SetRequiredPID(fPairDef->GetType(0));
5eb970a4 257 AliDebug(AliLog::kDebug+1,"daughter1 is OK ...");
258 // cuts on track #1
259 if (!CutPass(&fTrack1)) continue;
260 AliDebug(AliLog::kDebug+1,"daughter1 cut passed ...");
261 // check starting index for searching the event:
262 // for like-sign pairs we avoid duplicating the pairs
263 if (isLikeSign) startj = i+1; else startj = 0;
264 // loop on event for all track #2 to be combined with the found track #1
265 for (j = startj; j < a2->GetSize(); j++) {
266 ev2->SetDaughter(fTrack2, a2->At(j));
267 if (!fTrack2.IsOK()) continue;
268 AliDebug(AliLog::kDebug+1,"daughter2 is OK ...");
5bd59e02 269 // assign the required PID type to track #2
270 fTrack2.SetRequiredPID(fPairDef->GetType(1));
39a3e819 271 // skip by default the case where the two tracks have the same index
272 if (ev1 == ev2 && a1->At(i) == a2->At(j)) continue;
5eb970a4 273 // cuts on track #2
274 if (!CutPass(&fTrack2)) continue;
275 AliDebug(AliLog::kDebug+1,"daughter2 cut passed ...");
276 // make pair
277 fPairParticle.SetPair(&fTrack1, &fTrack2);
4fbb2459 278 // in case of request, check that it is true pair
279 if (fOnlyTrue)
280 {
281 if (fPairParticle.CommonMother() != fPairDef->GetMotherPDG()) continue;
282 if (fPairParticle.GetDaughter(0)->PerfectPID() != fPairDef->GetType(0)) continue;
283 if (fPairParticle.GetDaughter(1)->PerfectPID() != fPairDef->GetType(1)) continue;
284 }
5eb970a4 285 // cuts on pair
286 if (!CutPass(&fPairParticle)) continue;
287 AliDebug(AliLog::kDebug+1, "pairParticle cut passed");
288
4fbb2459 289 if (AliLog::GetDebugLevel("",GetName()) == AliLog::kDebug)
290 fPairParticle.PrintInfo();
9477aa42 291 AliDebug(AliLog::kDebug, "================= FILLING TO HISTOGRAM ==================");
5eb970a4 292 // fill all histograms
293 TObjArrayIter nextFcn(&fFunctions);
4fbb2459 294 while ((fcn = (AliRsnFunction*)nextFcn())) {
5eb970a4 295 fcn->SetPairDef(fPairDef);
296 fcn->SetPair(&fPairParticle);
297 fcn->SetEvent(ev1);
298 fcn->Fill();
299 }
aec0ec32 300 }
5eb970a4 301 }
302 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 303}
304
305//_____________________________________________________________________________
6f4a992c 306TList * AliRsnPair::GenerateHistograms(TString prefix,TList *list)
aec0ec32 307{
308//
15d5fd02 309// Generates needed histograms, giving them a name based on
310// the flags defined here, on the pair definition, and attaches
311// a prefix to it, according to the argument.
312//
313// All generated histograms are stored into the output TList.
aec0ec32 314//
5eb970a4 315 AliDebug(AliLog::kDebug+2,"<-");
4fbb2459 316// if (!list){
317// TList *list = new TList();
318// list->SetName(GetPairHistName(0x0).Data());
319// }
aec0ec32 320 Char_t hName[255], hTitle[255];
5eb970a4 321 //AliRsnFunction *fcn = 0;
aec0ec32 322 AliRsnFunction *fcn = 0;
5eb970a4 323 for (Int_t i=0;i< fFunctions.GetEntries();i++) {
aec0ec32 324 fcn = (AliRsnFunction*)fFunctions.At(i);
325 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
326 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
5eb970a4 327 //TList *histos = fcn->Init(hName, hTitle);
9477aa42 328 //list->Add(fcn->CreateHistogram(hName, hTitle));
eb079724 329 if (fcn->IsUsingTH1()) list->Add(fcn->CreateHistogram(hName, hTitle));
330 else list->Add(fcn->CreateHistogramSparse(hName, hTitle));
15d5fd02 331 //histos->Print();
5eb970a4 332 //list->Add(histos);
aec0ec32 333 }
4fbb2459 334// cout << "PRINTING LIST" << endl;
335// list->Print();
5eb970a4 336 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 337 return list;
338}
339
aec0ec32 340
aec0ec32 341
342//_____________________________________________________________________________
78b94cbd 343TString AliRsnPair::GetPairTypeName(EPairType type) const
aec0ec32 344{
345//
346// Returns type name, made with particle names ant chosen PID
347//
5eb970a4 348 AliDebug(AliLog::kDebug+2,"<-");
349 AliDebug(AliLog::kDebug+2,"->");
350 switch (type) {
4fbb2459 351 case kNoPID : return ("NOPID_");break;
352 case kNoPIDMix : return ("NOPIDMIX_");break;
353 case kRealisticPID : return ("REALISTIC_");break;
354 case kRealisticPIDMix : return ("REALISTICMIX_");break;
355 case kPerfectPID : return ("PERFECT_");break;
356 case kPerfectPIDMix : return ("PERFECTMIX_");break;
357 default:
358 AliWarning("Unrecognized value of EPairTypeName argument");
359 break;
aec0ec32 360 }
361
362 return "NOTYPE";
363}
364
365//_____________________________________________________________________________
78b94cbd 366TString AliRsnPair::GetPairName() const
aec0ec32 367{
368//
369// Retruns pair name
370//
5eb970a4 371 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 372 TString sName;
373 sName += GetPairTypeName(fPairType);
374 sName += fPairDef->GetPairName();
5eb970a4 375 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 376 return sName;
377}
378
379//_____________________________________________________________________________
4fbb2459 380TString AliRsnPair::GetPairHistName(AliRsnFunction *const fcn, TString text) const
aec0ec32 381{
382//
15d5fd02 383// Returns definitive histogram name
aec0ec32 384//
5eb970a4 385 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 386 TString sName;
5eb970a4 387 if (fcn) {
388 sName = fcn->GetName();
aec0ec32 389 sName += "_";
390 }
391 sName += GetPairName();
392 sName += "_";
393 if (fCutMgr) sName += fCutMgr->GetName();
394 sName += text;
5eb970a4 395 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 396 return sName;
397}
398
399//_____________________________________________________________________________
4fbb2459 400TString AliRsnPair::GetPairHistTitle(AliRsnFunction *const fcn, TString text) const
aec0ec32 401{
402//
15d5fd02 403// Returns definitive histogram title
aec0ec32 404//
5eb970a4 405 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 406 TString sTitle;
5eb970a4 407 if (fcn) {
408 sTitle = fcn->GetTitle();
aec0ec32 409 sTitle += " ";
410 }
411 sTitle += GetPairName();
412 sTitle +=" ";
413 if (fCutMgr) sTitle += fCutMgr->GetTitle();
414 sTitle += text;
5eb970a4 415 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 416 return sTitle;
417}
418
419//_____________________________________________________________________________
4fbb2459 420void AliRsnPair::AddFunction(AliRsnFunction *const fcn)
aec0ec32 421{
422//
423// Adds a new computing function
424//
5eb970a4 425 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 426 Int_t size = fFunctions.GetEntries();
4fbb2459 427 new(fFunctions[size]) AliRsnFunction(*fcn);
5eb970a4 428 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 429}
430
431//________________________________________________________________________________________
432Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
433{
434//
435// Check if the AliRsnDaughter argument pass its cuts.
436// If the cut data member is not initialized for it, returns kTRUE.
437//
5eb970a4 438 AliDebug(AliLog::kDebug+2,"<-AliRsnDaughter");
439 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 440 if (!fCutMgr) return kTRUE;
441 else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
442}
443
444//________________________________________________________________________________________
445Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
446{
447//
448// Check if the AliRsnPairParticle argument pass its cuts.
449// If the cut data member is not initialized for it, returns kTRUE.
aec0ec32 450//
5eb970a4 451 AliDebug(AliLog::kDebug+2,"<-AliRsnPairParticle");
452 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 453 if (!fCutMgr) return kTRUE;
454 else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
455}
456
457//________________________________________________________________________________________
458Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
459{
460//
461// Check if the AliRsnEvent argument pass its cuts.
462// If the cut data member is not initialized for it, returns kTRUE.
463//
5eb970a4 464 AliDebug(AliLog::kDebug+2,"<-AliRsnEvent");
465 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 466 if (!fCutMgr) return kTRUE;
467 else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);
5eb970a4 468
aec0ec32 469}