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