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)
19 #include "AliRsnEvent.h"
20 #include "AliRsnFunction.h"
21 #include "AliRsnPIDIndex.h"
22 #include "AliRsnCutMgr.h"
23 #include "AliRsnCutStd.h"
25 #include "AliRsnPair.h"
29 //_____________________________________________________________________________
30 AliRsnPair::AliRsnPair(EPairType type, AliRsnPairDef *def) :
35 fPIDMethod(AliRsnDaughter::kRealistic),
38 fFunctions("AliRsnFunction", 0),
44 // Default constructor
46 AliDebug(AliLog::kDebug+2,"<-");
47 AliDebug(AliLog::kDebug+2,"->");
50 //_____________________________________________________________________________
51 AliRsnPair::~AliRsnPair()
56 AliDebug(AliLog::kDebug+2,"<-");
57 AliDebug(AliLog::kDebug+2,"->");
60 //_____________________________________________________________________________
61 void AliRsnPair::SetUp(EPairType type)
64 // Sets up flag values by the pair types
66 AliDebug(AliLog::kDebug+2,"<-");
69 SetAllFlags(AliRsnDaughter::kNoPID, kFALSE);
72 SetAllFlags(AliRsnDaughter::kNoPID, kTRUE);
75 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
77 case kRealisticPIDMix:
78 SetAllFlags(AliRsnDaughter::kRealistic, kTRUE);
81 SetAllFlags(AliRsnDaughter::kPerfect, kFALSE);
84 SetAllFlags(AliRsnDaughter::kPerfect, kTRUE);
87 AliWarning("Wrong type selected: setting up for realistic PID - no mixing.");
88 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
91 AliDebug(AliLog::kDebug+2,"->");
94 //_____________________________________________________________________________
95 void AliRsnPair::Print(Option_t* /*option*/) const
98 // Prints info about pair
100 AliDebug(AliLog::kDebug+2,"<-");
101 AliInfo(Form("%s", GetPairHistTitle(0x0).Data()));
102 AliInfo(Form("PDG %d %d", AliPID::ParticleCode(fPairDef->GetType(0)),
103 AliPID::ParticleCode(fPairDef->GetType(1))));
104 AliInfo(Form("Masses %f %f", fPairDef->GetMass(0), fPairDef->GetMass(1)));
105 AliInfo(Form("Number of functions %d", fFunctions.GetEntries()));
107 switch (fPIDMethod) {
108 case AliRsnDaughter::kNoPID:
109 AliInfo("PID method: none");
111 case AliRsnDaughter::kRealistic:
112 AliInfo("PID method: realistic");
114 case AliRsnDaughter::kPerfect:
115 AliInfo("PID method: perfect");
118 AliInfo("PID method: undefined");
120 AliDebug(AliLog::kDebug+2,"->");
123 //_____________________________________________________________________________
124 void AliRsnPair::LoopPair(AliRsnPIDIndex *const pidIndex1, AliRsnEvent *const ev1, AliRsnPIDIndex *const pidIndex2, AliRsnEvent *const ev2)
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.
137 AliDebug(AliLog::kDebug+2,"<-");
142 if (fPIDMethod == AliRsnDaughter::kNoPID) {
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);
148 a2 = pidIndex1->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), AliPID::kUnknown);
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));
155 a2 = pidIndex1->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), (AliPID::EParticleType)fPairDef->GetType(1));
158 LoopPair(a1, a2, ev1, ev2);
160 AliDebug(AliLog::kDebug+2,"->");
163 //_____________________________________________________________________________
164 void AliRsnPair::LoopPair(TArrayI *a1, TArrayI *a2, AliRsnEvent *ev1, AliRsnEvent *ev2)
167 // Loop on all pairs of tracks of the defined types/charges,
168 // using the arrays of indexes and the events containing them.
169 // This method is private, for safety reasons.
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 ...");
178 AliDebug(AliLog::kDebug+1, "ev2 is null and fIsMixed is true. Skipping ...");
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;}
187 AliDebug(AliLog::kDebug+1,Form("a1=%d a2=%d",a1->GetSize(),a2->GetSize()));
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;}
191 AliDebug(AliLog::kDebug,Form("Indexes_a1=%d Indexes_a2=%d",a1->GetSize(),a2->GetSize()));
194 if (!CutPass(ev1) || !CutPass(ev2)) return;
195 AliDebug(AliLog::kDebug+1,"Event cut passed...");
196 AliRsnDaughter::SetPIDMethod(fPIDMethod);
197 AliRsnFunction *fcn = 0;
199 Bool_t isLikeSign = fPairDef->IsLikeSign();
202 for (Int_t i = 0; i < a1->GetSize(); i++) {
204 ev1->SetDaughter(fTrack1, a1->At(i));
205 if (!fTrack1.IsOK()) continue;
206 // assign the required PID type to track #1
207 fTrack1.SetRequiredPID(fPairDef->GetType(0));
208 AliDebug(AliLog::kDebug+1,"daughter1 is OK ...");
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 ...");
220 // assign the required PID type to track #2
221 fTrack2.SetRequiredPID(fPairDef->GetType(1));
223 if (!CutPass(&fTrack2)) continue;
224 AliDebug(AliLog::kDebug+1,"daughter2 cut passed ...");
226 fPairParticle.SetPair(&fTrack1, &fTrack2);
227 // in case of request, check that it is true pair
230 if (fPairParticle.CommonMother() != fPairDef->GetMotherPDG()) continue;
231 if (fPairParticle.GetDaughter(0)->PerfectPID() != fPairDef->GetType(0)) continue;
232 if (fPairParticle.GetDaughter(1)->PerfectPID() != fPairDef->GetType(1)) continue;
235 if (!CutPass(&fPairParticle)) continue;
236 AliDebug(AliLog::kDebug+1, "pairParticle cut passed");
238 if (AliLog::GetDebugLevel("",GetName()) == AliLog::kDebug)
239 fPairParticle.PrintInfo();
241 // fill all histograms
242 TObjArrayIter nextFcn(&fFunctions);
243 while ((fcn = (AliRsnFunction*)nextFcn())) {
244 fcn->SetPairDef(fPairDef);
245 fcn->SetPair(&fPairParticle);
251 AliDebug(AliLog::kDebug+2,"->");
254 //_____________________________________________________________________________
255 TList * AliRsnPair::GenerateHistograms(TString prefix,TList *list)
258 // Generates needed histograms, giving them a name based on
259 // the flags defined here, on the pair definition, and attaches
260 // a prefix to it, according to the argument.
262 // All generated histograms are stored into the output TList.
264 AliDebug(AliLog::kDebug+2,"<-");
266 // TList *list = new TList();
267 // list->SetName(GetPairHistName(0x0).Data());
269 Char_t hName[255], hTitle[255];
270 //AliRsnFunction *fcn = 0;
271 AliRsnFunction *fcn = 0;
272 for (Int_t i=0;i< fFunctions.GetEntries();i++) {
273 fcn = (AliRsnFunction*)fFunctions.At(i);
274 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
275 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
276 //TList *histos = fcn->Init(hName, hTitle);
277 list->Add(fcn->CreateHistogram(hName, hTitle));
281 // cout << "PRINTING LIST" << endl;
283 AliDebug(AliLog::kDebug+2,"->");
289 //_____________________________________________________________________________
290 TString AliRsnPair::GetPairTypeName(EPairType type) const
293 // Returns type name, made with particle names ant chosen PID
295 AliDebug(AliLog::kDebug+2,"<-");
296 AliDebug(AliLog::kDebug+2,"->");
298 case kNoPID : return ("NOPID_");break;
299 case kNoPIDMix : return ("NOPIDMIX_");break;
300 case kRealisticPID : return ("REALISTIC_");break;
301 case kRealisticPIDMix : return ("REALISTICMIX_");break;
302 case kPerfectPID : return ("PERFECT_");break;
303 case kPerfectPIDMix : return ("PERFECTMIX_");break;
305 AliWarning("Unrecognized value of EPairTypeName argument");
312 //_____________________________________________________________________________
313 TString AliRsnPair::GetPairName() const
318 AliDebug(AliLog::kDebug+2,"<-");
320 sName += GetPairTypeName(fPairType);
321 sName += fPairDef->GetPairName();
322 AliDebug(AliLog::kDebug+2,"->");
326 //_____________________________________________________________________________
327 TString AliRsnPair::GetPairHistName(AliRsnFunction *const fcn, TString text) const
330 // Returns definitive histogram name
332 AliDebug(AliLog::kDebug+2,"<-");
335 sName = fcn->GetName();
338 sName += GetPairName();
340 if (fCutMgr) sName += fCutMgr->GetName();
342 AliDebug(AliLog::kDebug+2,"->");
346 //_____________________________________________________________________________
347 TString AliRsnPair::GetPairHistTitle(AliRsnFunction *const fcn, TString text) const
350 // Returns definitive histogram title
352 AliDebug(AliLog::kDebug+2,"<-");
355 sTitle = fcn->GetTitle();
358 sTitle += GetPairName();
360 if (fCutMgr) sTitle += fCutMgr->GetTitle();
362 AliDebug(AliLog::kDebug+2,"->");
366 //_____________________________________________________________________________
367 void AliRsnPair::AddFunction(AliRsnFunction *const fcn)
370 // Adds a new computing function
372 AliDebug(AliLog::kDebug+2,"<-");
373 Int_t size = fFunctions.GetEntries();
374 new(fFunctions[size]) AliRsnFunction(*fcn);
375 AliDebug(AliLog::kDebug+2,"->");
378 //________________________________________________________________________________________
379 Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
382 // Check if the AliRsnDaughter argument pass its cuts.
383 // If the cut data member is not initialized for it, returns kTRUE.
385 AliDebug(AliLog::kDebug+2,"<-AliRsnDaughter");
386 AliDebug(AliLog::kDebug+2,"->");
387 if (!fCutMgr) return kTRUE;
388 else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
391 //________________________________________________________________________________________
392 Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
395 // Check if the AliRsnPairParticle argument pass its cuts.
396 // If the cut data member is not initialized for it, returns kTRUE.
398 AliDebug(AliLog::kDebug+2,"<-AliRsnPairParticle");
399 AliDebug(AliLog::kDebug+2,"->");
400 if (!fCutMgr) return kTRUE;
401 else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
404 //________________________________________________________________________________________
405 Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
408 // Check if the AliRsnEvent argument pass its cuts.
409 // If the cut data member is not initialized for it, returns kTRUE.
411 AliDebug(AliLog::kDebug+2,"<-AliRsnEvent");
412 AliDebug(AliLog::kDebug+2,"->");
413 if (!fCutMgr) return kTRUE;
414 else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);