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