]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnPair.cxx
few modifications on package, waiting for AOD compliance corrections
[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 <Riostream.h>
16 #include <TObjArray.h>
17
18 #include "AliLog.h"
19
20 #include "AliRsnFunction.h"
21 #include "AliRsnPairParticle.h"
22
23 #include "AliRsnPair.h"
24
25 ClassImp(AliRsnPair)
26
27 //_____________________________________________________________________________
28 AliRsnPair::AliRsnPair(EPairType type, AliRsnPairDef *def) :
29   TObject(),
30   fIsMixed(kFALSE),
31   fPairType(type),
32   fPIDMethod(AliRsnDaughter::kRealistic),
33   fPairDef(def),
34   fCutMgr(0),
35   fFunctions("AliRsnFunction", 0)
36 {
37 //
38 // Default constructor
39 //
40
41   SetUp(type);
42 }
43 //_____________________________________________________________________________
44 AliRsnPair::~AliRsnPair()
45 {
46 //
47 // Destructor
48 //
49 }
50
51 //_____________________________________________________________________________
52 void AliRsnPair::SetUp(EPairType type)
53 {
54 //
55 // Sets up flag values by the pair types
56 //
57
58   switch (type)
59   {
60     case kNoPID:
61       SetAllFlags(AliRsnDaughter::kNoPID, kFALSE);
62       break;
63     case kNoPIDMix:
64       SetAllFlags(AliRsnDaughter::kNoPID, kTRUE);
65       break;
66     case kRealisticPID:
67       SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
68       break;
69     case kRealisticPIDMix:
70       SetAllFlags(AliRsnDaughter::kRealistic, kTRUE);
71       break;
72     case kPerfectPID:
73       SetAllFlags (AliRsnDaughter::kPerfect, kFALSE);
74       break;
75     case kPerfectPIDMix:
76       SetAllFlags (AliRsnDaughter::kPerfect, kTRUE);
77       break;
78     default :
79       AliWarning("Wrong type selected: setting up for realistic PID - no mixing.");
80       SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
81       break;
82   }
83 }
84
85 //_____________________________________________________________________________
86 void AliRsnPair::Print(Option_t* /*option*/) const
87 {
88 //
89 // Prints info about pair
90 //
91
92   AliInfo(Form("%s", GetPairHistTitle(0x0).Data()));
93   AliInfo(Form("PDG %d %d", AliRsnPID::PDGCode(fPairDef->GetType(0)),
94                AliRsnPID::PDGCode(fPairDef->GetType(1))));
95   AliInfo(Form("Masses %f %f", fPairDef->GetMass(0), fPairDef->GetMass(1)));
96   AliInfo(Form("Number of functions %d", fFunctions.GetEntries()));
97
98   switch(fPIDMethod)
99   {
100     case AliRsnDaughter::kNoPID:
101       AliInfo("PID method: none");
102       break;
103     case AliRsnDaughter::kRealistic:
104       AliInfo("PID method: realistic");
105       break;
106     case AliRsnDaughter::kPerfect:
107       AliInfo("PID method: perfect");
108       break;
109     default:
110       AliInfo("PID method: undefined");
111   }
112 }
113
114 //_____________________________________________________________________________
115 void AliRsnPair::ProcessPair(AliRsnEvent *ev1, AliRsnEvent *ev2)
116 {
117 //
118 // Fills the functions' histograms using tracks from passed events.
119 // What tracks are taken in each event depend from the order of
120 // track types defined in the AliRsnPairDef for this object:
121 //  - tracks of type 0 are the ones stored as pairDef data members with index [0]
122 //    ---> taken from first argument (ev1)
123 //  - tracks of type 1 are the ones stored as pairDef data members with index [1]
124 //    ---> taken from second argument (ev2)
125 //
126 // When doing single-event analysis (e.g. signal, like-sign), second argument
127 // can be NULL, and it will be forced to point to the same object of first one.
128 //
129
130   if (!ev2) ev2 = ev1;
131
132   TArrayI *array1 = ev1->GetTracksArray(fPIDMethod, fPairDef->GetCharge(0), fPairDef->GetType(0));
133   TArrayI *array2 = ev2->GetTracksArray(fPIDMethod, fPairDef->GetCharge(1), fPairDef->GetType(1));
134
135   LoopPair(ev1, array1, ev2, array2);
136 }
137
138 //_____________________________________________________________________________
139 void AliRsnPair::LoopPair
140 (AliRsnEvent * ev1, TArrayI * a1, AliRsnEvent * ev2, TArrayI * a2)
141 {
142 //
143 // Loop on all pairs of tracks of the defined types/charges,
144 // using the arrays of indexes and the events containing them.
145 // This method is private, for safety reasons.
146 //
147
148   if (!a1) {AliDebug(4, "No TArrayI 1 from currentEvent->GetTracksArray(...)"); return;}
149   if (!a2) {AliDebug(4, "No TArrayI 2 from currentEvent->GetTracksArray(...)"); return;}
150
151   // cuts on events
152   if (!CutPass(ev1) || !CutPass(ev2)) return;
153
154   AliRsnDaughter::SetPIDMethod(fPIDMethod);
155   AliRsnDaughter *daughter1 = 0;
156   AliRsnDaughter *daughter2 = 0;
157   AliRsnFunction *fcn = 0;
158   //AliRsnFunctionNew *fnew = 0;
159
160   Bool_t isLikeSign = fPairDef->IsLikeSign();
161   Int_t j, startj = 0;
162
163     for (Int_t i = 0; i < a1->GetSize(); i++)
164     {
165         // get track #1
166         daughter1 = (AliRsnDaughter *) ev1->GetTrack(a1->At(i));
167         if (!daughter1) continue;
168         // assign PID and mass of particle of type #1
169         daughter1->AssignPID(fPairDef->GetType(0));
170         // cuts on track #1
171         if (!CutPass(daughter1)) continue;
172         // get track #2
173         daughter2 = 0;
174         // check starting index for searching the event:
175         // for like-sign pairs we avoid duplicating the pairs
176         if (isLikeSign) startj = i+1; else startj = 0;
177         // AliInfo(Form("%d",startj));
178         // loop on event for all track #2 to be combined with the found track #1
179         for (j = startj; j < a2->GetSize(); j++)
180         {
181             daughter2 = (AliRsnDaughter *) ev2->GetTrack(a2->At(j));
182             if (!daughter2) continue;
183             // assign PID and mass of particle of type #2
184             daughter2->AssignPID(fPairDef->GetType(0));
185             // cuts on track #2
186             if (!CutPass(daughter2)) continue;
187             // make pair
188             AliRsnPairParticle pairParticle;
189             pairParticle.SetPair(daughter1, daughter2);
190             // cuts on pair
191             if (!CutPass(&pairParticle)) continue;
192             // fill all histograms
193             TObjArrayIter nextFcn(&fFunctions);
194             while ( (fcn = (AliRsnFunction*)nextFcn()) ) {
195                 fcn->Fill(&pairParticle, fPairDef);
196             }
197             /*
198             while ( (fnew = (AliRsnFunction*)nextFcn()) ) {
199               fnew->Fill(&pairParticle, fPairDef);
200             }
201             */
202         }
203     }
204 }
205
206 //_____________________________________________________________________________
207 TList * AliRsnPair::GenerateHistograms(TString prefix)
208 {
209 //
210 // Generates needed histograms, giving them a name based on
211 // the flags defined here, on the pair definition, and attaches
212 // a prefix to it, according to the argument.
213 //
214 // All generated histograms are stored into the output TList.
215 //
216
217   TList *list = new TList();
218   list->SetName(GetPairHistName(0x0).Data());
219
220   Char_t hName[255], hTitle[255];
221   AliRsnFunction *fcn = 0;
222   for (Int_t i=0;i< fFunctions.GetEntries();i++)
223   {
224     fcn = (AliRsnFunction*)fFunctions.At(i);
225     sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
226     sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
227     TList *histos = fcn->Init(hName, hTitle);
228     //histos->Print();
229     list->Add(histos);
230   }
231
232   return list;
233 }
234
235 //_____________________________________________________________________________
236 void AliRsnPair::GenerateHistograms(TString prefix, TList *tgt)
237 {
238 //
239 // Generates needed histograms, giving them a name based on
240 // the flags defined here, on the pair definition, and attaches
241 // a prefix to it, according to the argument.
242 //
243 // All generated histograms are stored into the TList passed as argument
244 //
245
246   if (!tgt) {
247     AliError("NULL target list!");
248     return;
249   }
250
251   Char_t hName[255], hTitle[255];
252   AliRsnFunction *fcn = 0;
253   for (Int_t i=0;i< fFunctions.GetEntries();i++)
254   {
255     fcn = (AliRsnFunction*)fFunctions.At(i);
256     sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
257     sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
258     fcn->Init(hName, hTitle, tgt);
259   }
260 }
261
262 //_____________________________________________________________________________
263 TString AliRsnPair::GetPairTypeName(EPairType type) const
264 {
265 //
266 // Returns type name, made with particle names ant chosen PID
267 //
268
269   switch (type)
270   {
271     case kNoPID : return ("NOPID_");break;
272     case kNoPIDMix : return ("NOPIDMIX_");break;
273     case kRealisticPID : return ("REALISTIC_");break;
274     case kRealisticPIDMix : return ("REALISTICMIX_");break;
275     case kPerfectPID : return ("PERFECT_");break;
276     case kPerfectPIDMix : return ("PERFECTMIX_");break;
277     default:
278       AliWarning("Unrecognized value of EPairTypeName argument");
279       break;
280   }
281
282   return "NOTYPE";
283 }
284
285 //_____________________________________________________________________________
286 TString AliRsnPair::GetPairName() const
287 {
288 //
289 // Retruns pair name
290 //
291
292   TString sName;
293   sName += GetPairTypeName(fPairType);
294   sName += fPairDef->GetPairName();
295
296   return sName;
297 }
298
299 //_____________________________________________________________________________
300 TString AliRsnPair::GetPairHistName(AliRsnFunction *fcn, TString text) const
301 {
302 //
303 // Returns definitive histogram name
304 //
305
306   TString sName;
307   if (fcn)
308   {
309     sName = fcn->GetFcnName();
310     sName += "_";
311   }
312   sName += GetPairName();
313   sName += "_";
314   if (fCutMgr) sName += fCutMgr->GetName();
315   sName += text;
316
317   return sName;
318 }
319
320 //_____________________________________________________________________________
321 TString AliRsnPair::GetPairHistTitle(AliRsnFunction *fcn, TString text) const
322 {
323 //
324 // Returns definitive histogram title
325 //
326
327   TString sTitle;
328   if (fcn)
329   {
330     sTitle = fcn->GetFcnTitle();
331     sTitle += " ";
332   }
333   sTitle += GetPairName();
334   sTitle +=" ";
335   if (fCutMgr) sTitle += fCutMgr->GetTitle();
336   sTitle += text;
337
338   return sTitle;
339 }
340
341 //_____________________________________________________________________________
342 void AliRsnPair::AddFunction(AliRsnFunction *fcn)
343 {
344 //
345 // Adds a new computing function
346 //
347
348   Int_t size = fFunctions.GetEntries();
349   new (fFunctions[size]) AliRsnFunction(*fcn);
350 }
351
352 /*
353 //_____________________________________________________________________________
354 void AliRsnPair::AddFunction(AliRsnFunctionDef *fcn)
355 {
356 //
357 // Adds a new computing function
358 //
359
360   Int_t size = fFunctions.GetEntries();
361   new (fFunctions[size]) AliRsnFunctionNew(fcn);
362 }
363 */
364
365 //________________________________________________________________________________________
366 Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
367 {
368 //
369 // Check if the AliRsnDaughter argument pass its cuts.
370 // If the cut data member is not initialized for it, returns kTRUE.
371 //
372
373   if (!fCutMgr) return kTRUE;
374   else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
375 }
376
377 //________________________________________________________________________________________
378 Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
379 {
380 //
381 // Check if the AliRsnPairParticle argument pass its cuts.
382 // If the cut data member is not initialized for it, returns kTRUE.
383 //
384
385   if (!fCutMgr) return kTRUE;
386   else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
387 }
388
389 //________________________________________________________________________________________
390 Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
391 {
392 //
393 // Check if the AliRsnEvent argument pass its cuts.
394 // If the cut data member is not initialized for it, returns kTRUE.
395 //
396
397   if (!fCutMgr) return kTRUE;
398   else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);
399 }