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