]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnPair.cxx
Made a general review to fix as possible most coding conventions violations.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPair.cxx
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
15 #include <TList.h>
16
17 #include "AliLog.h"
18
19 #include "AliRsnEvent.h"
20 #include "AliRsnFunction.h"
21 #include "AliRsnPIDIndex.h"
22 #include "AliRsnCutMgr.h"
23 #include "AliRsnCutStd.h"
24
25 #include "AliRsnPair.h"
26
27 ClassImp(AliRsnPair)
28
29 //_____________________________________________________________________________
30 AliRsnPair::AliRsnPair(EPairType type, AliRsnPairDef *def) :
31     TObject(),
32     fOnlyTrue(kFALSE),
33     fIsMixed(kFALSE),
34     fPairType(type),
35     fPIDMethod(AliRsnDaughter::kRealistic),
36     fPairDef(def),
37     fCutMgr(0),
38     fFunctions("AliRsnFunction", 0),
39     fTrack1(),
40     fTrack2(),
41     fPairParticle()
42 {
43 //
44 // Default constructor
45 //
46   AliDebug(AliLog::kDebug+2,"<-");
47   AliDebug(AliLog::kDebug+2,"->");
48   SetUp(type);
49 }
50 //_____________________________________________________________________________
51 AliRsnPair::~AliRsnPair()
52 {
53 //
54 // Destructor
55 //
56   AliDebug(AliLog::kDebug+2,"<-");
57   AliDebug(AliLog::kDebug+2,"->");
58 }
59
60 //_____________________________________________________________________________
61 void AliRsnPair::SetUp(EPairType type)
62 {
63 //
64 // Sets up flag values by the pair types
65 //
66   AliDebug(AliLog::kDebug+2,"<-");
67   switch (type) {
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;
90   }
91   AliDebug(AliLog::kDebug+2,"->");
92 }
93
94 //_____________________________________________________________________________
95 void AliRsnPair::Print(Option_t* /*option*/) const
96 {
97 //
98 // Prints info about pair
99 //
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()));
106
107   switch (fPIDMethod) {
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");
119   }
120   AliDebug(AliLog::kDebug+2,"->");
121 }
122
123 //_____________________________________________________________________________
124 void AliRsnPair::LoopPair(AliRsnPIDIndex *const pidIndex1, AliRsnEvent *const ev1, AliRsnPIDIndex *const pidIndex2, AliRsnEvent *const ev2)
125 {
126 //
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.
135 //
136
137   AliDebug(AliLog::kDebug+2,"<-");
138
139   TArrayI *a1 = 0;
140   TArrayI *a2 = 0;
141
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);
147     else
148       a2 = pidIndex1->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), AliPID::kUnknown);
149   } else {
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,"->");
161 }
162
163 //_____________________________________________________________________________
164 void AliRsnPair::LoopPair(TArrayI *a1, TArrayI *a2, AliRsnEvent *ev1, AliRsnEvent *ev2)
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.
169 // This method is private, for safety reasons.
170 //
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) {
178       AliDebug(AliLog::kDebug+1, "ev2 is null and fIsMixed is true. Skipping ...");
179       return;
180     }
181     ev2 = ev1;
182   }
183
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;}
186
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;}
190
191   AliDebug(AliLog::kDebug,Form("Indexes_a1=%d Indexes_a2=%d",a1->GetSize(),a2->GetSize()));
192
193   // cuts on events
194   if (!CutPass(ev1) || !CutPass(ev2)) return;
195   AliDebug(AliLog::kDebug+1,"Event cut passed...");
196   AliRsnDaughter::SetPIDMethod(fPIDMethod);
197   AliRsnFunction *fcn = 0;
198
199   Bool_t isLikeSign = fPairDef->IsLikeSign();
200   Int_t j, startj = 0;
201
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;
206     // assign the required PID type to track #1
207     fTrack1.SetRequiredPID(fPairDef->GetType(0));
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 ...");
220       // assign the required PID type to track #2
221       fTrack2.SetRequiredPID(fPairDef->GetType(1));
222       // cuts on track #2
223       if (!CutPass(&fTrack2)) continue;
224       AliDebug(AliLog::kDebug+1,"daughter2 cut passed ...");
225       // make pair
226       fPairParticle.SetPair(&fTrack1, &fTrack2);
227       // in case of request, check that it is true pair
228       if (fOnlyTrue)
229       {
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;
233       }
234       // cuts on pair
235       if (!CutPass(&fPairParticle)) continue;
236       AliDebug(AliLog::kDebug+1, "pairParticle cut passed");
237
238       if (AliLog::GetDebugLevel("",GetName()) == AliLog::kDebug)
239         fPairParticle.PrintInfo();
240
241       // fill all histograms
242       TObjArrayIter nextFcn(&fFunctions);
243       while ((fcn = (AliRsnFunction*)nextFcn())) {
244         fcn->SetPairDef(fPairDef);
245         fcn->SetPair(&fPairParticle);
246         fcn->SetEvent(ev1);
247         fcn->Fill();
248       }
249     }
250   }
251   AliDebug(AliLog::kDebug+2,"->");
252 }
253
254 //_____________________________________________________________________________
255 TList * AliRsnPair::GenerateHistograms(TString prefix,TList *list)
256 {
257 //
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.
261 //
262 // All generated histograms are stored into the output TList.
263 //
264   AliDebug(AliLog::kDebug+2,"<-");
265 //   if (!list){
266 //     TList *list = new TList();
267 //     list->SetName(GetPairHistName(0x0).Data());
268 //   }
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));
278     //histos->Print();
279     //list->Add(histos);
280   }
281 //   cout << "PRINTING LIST" << endl;
282 //   list->Print();
283   AliDebug(AliLog::kDebug+2,"->");
284   return list;
285 }
286
287
288
289 //_____________________________________________________________________________
290 TString AliRsnPair::GetPairTypeName(EPairType type) const
291 {
292 //
293 // Returns type name, made with particle names ant chosen PID
294 //
295   AliDebug(AliLog::kDebug+2,"<-");
296   AliDebug(AliLog::kDebug+2,"->");
297   switch (type) {
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;
304   default:
305     AliWarning("Unrecognized value of EPairTypeName argument");
306     break;
307   }
308
309   return "NOTYPE";
310 }
311
312 //_____________________________________________________________________________
313 TString AliRsnPair::GetPairName() const
314 {
315 //
316 // Retruns pair name
317 //
318   AliDebug(AliLog::kDebug+2,"<-");
319   TString sName;
320   sName += GetPairTypeName(fPairType);
321   sName += fPairDef->GetPairName();
322   AliDebug(AliLog::kDebug+2,"->");
323   return sName;
324 }
325
326 //_____________________________________________________________________________
327 TString AliRsnPair::GetPairHistName(AliRsnFunction *const fcn, TString text) const
328 {
329 //
330 // Returns definitive histogram name
331 //
332   AliDebug(AliLog::kDebug+2,"<-");
333   TString sName;
334   if (fcn) {
335     sName = fcn->GetName();
336     sName += "_";
337   }
338   sName += GetPairName();
339   sName += "_";
340   if (fCutMgr) sName += fCutMgr->GetName();
341   sName += text;
342   AliDebug(AliLog::kDebug+2,"->");
343   return sName;
344 }
345
346 //_____________________________________________________________________________
347 TString AliRsnPair::GetPairHistTitle(AliRsnFunction *const fcn, TString text) const
348 {
349 //
350 // Returns definitive histogram title
351 //
352   AliDebug(AliLog::kDebug+2,"<-");
353   TString sTitle;
354   if (fcn) {
355     sTitle = fcn->GetTitle();
356     sTitle += " ";
357   }
358   sTitle += GetPairName();
359   sTitle +=" ";
360   if (fCutMgr) sTitle += fCutMgr->GetTitle();
361   sTitle += text;
362   AliDebug(AliLog::kDebug+2,"->");
363   return sTitle;
364 }
365
366 //_____________________________________________________________________________
367 void AliRsnPair::AddFunction(AliRsnFunction *const fcn)
368 {
369 //
370 // Adds a new computing function
371 //
372   AliDebug(AliLog::kDebug+2,"<-");
373   Int_t size = fFunctions.GetEntries();
374   new(fFunctions[size]) AliRsnFunction(*fcn);
375   AliDebug(AliLog::kDebug+2,"->");
376 }
377
378 //________________________________________________________________________________________
379 Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
380 {
381 //
382 // Check if the AliRsnDaughter argument pass its cuts.
383 // If the cut data member is not initialized for it, returns kTRUE.
384 //
385   AliDebug(AliLog::kDebug+2,"<-AliRsnDaughter");
386   AliDebug(AliLog::kDebug+2,"->");
387   if (!fCutMgr) return kTRUE;
388   else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
389 }
390
391 //________________________________________________________________________________________
392 Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
393 {
394 //
395 // Check if the AliRsnPairParticle argument pass its cuts.
396 // If the cut data member is not initialized for it, returns kTRUE.
397 //
398   AliDebug(AliLog::kDebug+2,"<-AliRsnPairParticle");
399   AliDebug(AliLog::kDebug+2,"->");
400   if (!fCutMgr) return kTRUE;
401   else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
402 }
403
404 //________________________________________________________________________________________
405 Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
406 {
407 //
408 // Check if the AliRsnEvent argument pass its cuts.
409 // If the cut data member is not initialized for it, returns kTRUE.
410 //
411   AliDebug(AliLog::kDebug+2,"<-AliRsnEvent");
412   AliDebug(AliLog::kDebug+2,"->");
413   if (!fCutMgr) return kTRUE;
414   else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);
415
416 }