removed obsolete commented methods
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPair.cxx
CommitLineData
aec0ec32 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
922688c0 15#include <Riostream.h>
15d5fd02 16#include <TObjArray.h>
aec0ec32 17
18#include "AliLog.h"
19
20#include "AliRsnFunction.h"
aec0ec32 21
22#include "AliRsnPair.h"
23
24ClassImp(AliRsnPair)
25
26//_____________________________________________________________________________
15d5fd02 27AliRsnPair::AliRsnPair(EPairType type, AliRsnPairDef *def) :
5eb970a4 28 TObject(),
29 fIsMixed(kFALSE),
30 fPairType(type),
31 fPIDMethod(AliRsnDaughter::kRealistic),
32 fPairDef(def),
33 fCutMgr(0),
34 fFunctions("AliRsnFunction", 0),
35 fTrack1(),
e79f56bd 36 fTrack2(),
37 fPairParticle()
aec0ec32 38{
39//
40// Default constructor
41//
5eb970a4 42 AliDebug(AliLog::kDebug+2,"<-");
43 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 44 SetUp(type);
45}
46//_____________________________________________________________________________
47AliRsnPair::~AliRsnPair()
48{
49//
50// Destructor
51//
5eb970a4 52 AliDebug(AliLog::kDebug+2,"<-");
53 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 54}
55
56//_____________________________________________________________________________
57void AliRsnPair::SetUp(EPairType type)
58{
59//
60// Sets up flag values by the pair types
61//
5eb970a4 62 AliDebug(AliLog::kDebug+2,"<-");
63 switch (type) {
aec0ec32 64 case kNoPID:
15d5fd02 65 SetAllFlags(AliRsnDaughter::kNoPID, kFALSE);
aec0ec32 66 break;
67 case kNoPIDMix:
15d5fd02 68 SetAllFlags(AliRsnDaughter::kNoPID, kTRUE);
aec0ec32 69 break;
70 case kRealisticPID:
15d5fd02 71 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
aec0ec32 72 break;
73 case kRealisticPIDMix:
15d5fd02 74 SetAllFlags(AliRsnDaughter::kRealistic, kTRUE);
aec0ec32 75 break;
76 case kPerfectPID:
15d5fd02 77 SetAllFlags (AliRsnDaughter::kPerfect, kFALSE);
aec0ec32 78 break;
79 case kPerfectPIDMix:
15d5fd02 80 SetAllFlags (AliRsnDaughter::kPerfect, kTRUE);
aec0ec32 81 break;
82 default :
15d5fd02 83 AliWarning("Wrong type selected: setting up for realistic PID - no mixing.");
84 SetAllFlags(AliRsnDaughter::kRealistic, kFALSE);
aec0ec32 85 break;
86 }
5eb970a4 87 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 88}
89
aec0ec32 90//_____________________________________________________________________________
78b94cbd 91void AliRsnPair::Print(Option_t* /*option*/) const
aec0ec32 92{
93//
94// Prints info about pair
95//
5eb970a4 96 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 97 AliInfo(Form("%s", GetPairHistTitle(0x0).Data()));
5eb970a4 98 AliInfo(Form("PDG %d %d", AliPID::ParticleCode(fPairDef->GetType(0)),
99 AliPID::ParticleCode(fPairDef->GetType(1))));
aec0ec32 100 AliInfo(Form("Masses %f %f", fPairDef->GetMass(0), fPairDef->GetMass(1)));
101 AliInfo(Form("Number of functions %d", fFunctions.GetEntries()));
15d5fd02 102
5eb970a4 103 switch (fPIDMethod) {
aec0ec32 104 case AliRsnDaughter::kNoPID:
e0baff8c 105 AliInfo("PID method: none");
106 break;
aec0ec32 107 case AliRsnDaughter::kRealistic:
e0baff8c 108 AliInfo("PID method: realistic");
109 break;
aec0ec32 110 case AliRsnDaughter::kPerfect:
e0baff8c 111 AliInfo("PID method: perfect");
112 break;
aec0ec32 113 default:
e0baff8c 114 AliInfo("PID method: undefined");
922688c0 115 }
5eb970a4 116 AliDebug(AliLog::kDebug+2,"->");
922688c0 117}
118
119//_____________________________________________________________________________
5eb970a4 120void AliRsnPair::LoopPair
121(AliRsnPIDIndex *pidIndex1, AliRsnEvent *ev1, AliRsnPIDIndex *pidIndex2, AliRsnEvent *ev2)
922688c0 122{
123//
5eb970a4 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.
922688c0 132//
133
5eb970a4 134 AliDebug(AliLog::kDebug+2,"<-");
922688c0 135
5eb970a4 136 TArrayI *a1 = 0;
137 TArrayI *a2 = 0;
922688c0 138
5eb970a4 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,"->");
aec0ec32 161}
162
163//_____________________________________________________________________________
5eb970a4 164void AliRsnPair::LoopPair(TArrayI *a1, TArrayI *a2, AliRsnEvent *ev1, AliRsnEvent *ev2)
aec0ec32 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.
15d5fd02 169// This method is private, for safety reasons.
aec0ec32 170//
5eb970a4 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;}
aec0ec32 190
aec0ec32 191
15d5fd02 192 // cuts on events
193 if (!CutPass(ev1) || !CutPass(ev2)) return;
5eb970a4 194 AliDebug(AliLog::kDebug+1,"Event cut passed...");
15d5fd02 195 AliRsnDaughter::SetPIDMethod(fPIDMethod);
aec0ec32 196 AliRsnFunction *fcn = 0;
15d5fd02 197
198 Bool_t isLikeSign = fPairDef->IsLikeSign();
aec0ec32 199 Int_t j, startj = 0;
15d5fd02 200
5eb970a4 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;
5bd59e02 205 // assign the required PID type to track #1
206 fTrack1.SetRequiredPID(fPairDef->GetType(0));
5eb970a4 207 AliDebug(AliLog::kDebug+1,"daughter1 is OK ...");
208 // cuts on track #1
209 if (!CutPass(&fTrack1)) continue;
210 AliDebug(AliLog::kDebug+1,"daughter1 cut passed ...");
211 // check starting index for searching the event:
212 // for like-sign pairs we avoid duplicating the pairs
213 if (isLikeSign) startj = i+1; else startj = 0;
214 // loop on event for all track #2 to be combined with the found track #1
215 for (j = startj; j < a2->GetSize(); j++) {
216 ev2->SetDaughter(fTrack2, a2->At(j));
217 if (!fTrack2.IsOK()) continue;
218 AliDebug(AliLog::kDebug+1,"daughter2 is OK ...");
5bd59e02 219 // assign the required PID type to track #2
220 fTrack2.SetRequiredPID(fPairDef->GetType(1));
5eb970a4 221 // cuts on track #2
222 if (!CutPass(&fTrack2)) continue;
223 AliDebug(AliLog::kDebug+1,"daughter2 cut passed ...");
224 // make pair
225 fPairParticle.SetPair(&fTrack1, &fTrack2);
226
227 // cuts on pair
228 if (!CutPass(&fPairParticle)) continue;
229 AliDebug(AliLog::kDebug+1, "pairParticle cut passed");
230
231// pairParticle.PrintInfo();
232
233 // fill all histograms
234 TObjArrayIter nextFcn(&fFunctions);
235 while ( (fcn = (AliRsnFunction*)nextFcn()) ) {
236 fcn->SetPairDef(fPairDef);
237 fcn->SetPair(&fPairParticle);
238 fcn->SetEvent(ev1);
239 fcn->Fill();
240 }
aec0ec32 241 }
5eb970a4 242 }
243 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 244}
245
246//_____________________________________________________________________________
247TList * AliRsnPair::GenerateHistograms(TString prefix)
248{
249//
15d5fd02 250// Generates needed histograms, giving them a name based on
251// the flags defined here, on the pair definition, and attaches
252// a prefix to it, according to the argument.
253//
254// All generated histograms are stored into the output TList.
aec0ec32 255//
5eb970a4 256 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 257 TList *list = new TList();
258 list->SetName(GetPairHistName(0x0).Data());
259
260 Char_t hName[255], hTitle[255];
5eb970a4 261 //AliRsnFunction *fcn = 0;
aec0ec32 262 AliRsnFunction *fcn = 0;
5eb970a4 263 for (Int_t i=0;i< fFunctions.GetEntries();i++) {
aec0ec32 264 fcn = (AliRsnFunction*)fFunctions.At(i);
265 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
266 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
5eb970a4 267 //TList *histos = fcn->Init(hName, hTitle);
268 list->Add(fcn->CreateHistogram(hName, hTitle));
15d5fd02 269 //histos->Print();
5eb970a4 270 //list->Add(histos);
aec0ec32 271 }
5eb970a4 272 cout << "PRINTING LIST" << endl;
273 list->Print();
274 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 275 return list;
276}
277
aec0ec32 278
aec0ec32 279
280//_____________________________________________________________________________
78b94cbd 281TString AliRsnPair::GetPairTypeName(EPairType type) const
aec0ec32 282{
283//
284// Returns type name, made with particle names ant chosen PID
285//
5eb970a4 286 AliDebug(AliLog::kDebug+2,"<-");
287 AliDebug(AliLog::kDebug+2,"->");
288 switch (type) {
aec0ec32 289 case kNoPID : return ("NOPID_");break;
290 case kNoPIDMix : return ("NOPIDMIX_");break;
291 case kRealisticPID : return ("REALISTIC_");break;
292 case kRealisticPIDMix : return ("REALISTICMIX_");break;
293 case kPerfectPID : return ("PERFECT_");break;
294 case kPerfectPIDMix : return ("PERFECTMIX_");break;
aec0ec32 295 default:
296 AliWarning("Unrecognized value of EPairTypeName argument");
297 break;
298 }
299
300 return "NOTYPE";
301}
302
303//_____________________________________________________________________________
78b94cbd 304TString AliRsnPair::GetPairName() const
aec0ec32 305{
306//
307// Retruns pair name
308//
5eb970a4 309 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 310 TString sName;
311 sName += GetPairTypeName(fPairType);
312 sName += fPairDef->GetPairName();
5eb970a4 313 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 314 return sName;
315}
316
317//_____________________________________________________________________________
78b94cbd 318TString AliRsnPair::GetPairHistName(AliRsnFunction *fcn, TString text) const
aec0ec32 319{
320//
15d5fd02 321// Returns definitive histogram name
aec0ec32 322//
5eb970a4 323 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 324 TString sName;
5eb970a4 325 if (fcn) {
326 sName = fcn->GetName();
aec0ec32 327 sName += "_";
328 }
329 sName += GetPairName();
330 sName += "_";
331 if (fCutMgr) sName += fCutMgr->GetName();
332 sName += text;
5eb970a4 333 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 334 return sName;
335}
336
337//_____________________________________________________________________________
78b94cbd 338TString AliRsnPair::GetPairHistTitle(AliRsnFunction *fcn, TString text) const
aec0ec32 339{
340//
15d5fd02 341// Returns definitive histogram title
aec0ec32 342//
5eb970a4 343 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 344 TString sTitle;
5eb970a4 345 if (fcn) {
346 sTitle = fcn->GetTitle();
aec0ec32 347 sTitle += " ";
348 }
349 sTitle += GetPairName();
350 sTitle +=" ";
351 if (fCutMgr) sTitle += fCutMgr->GetTitle();
352 sTitle += text;
5eb970a4 353 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 354 return sTitle;
355}
356
357//_____________________________________________________________________________
358void AliRsnPair::AddFunction(AliRsnFunction *fcn)
359{
360//
361// Adds a new computing function
362//
5eb970a4 363 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 364 Int_t size = fFunctions.GetEntries();
15d5fd02 365 new (fFunctions[size]) AliRsnFunction(*fcn);
5eb970a4 366 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 367}
368
369//________________________________________________________________________________________
370Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
371{
372//
373// Check if the AliRsnDaughter argument pass its cuts.
374// If the cut data member is not initialized for it, returns kTRUE.
375//
5eb970a4 376 AliDebug(AliLog::kDebug+2,"<-AliRsnDaughter");
377 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 378 if (!fCutMgr) return kTRUE;
379 else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
380}
381
382//________________________________________________________________________________________
383Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
384{
385//
386// Check if the AliRsnPairParticle argument pass its cuts.
387// If the cut data member is not initialized for it, returns kTRUE.
aec0ec32 388//
5eb970a4 389 AliDebug(AliLog::kDebug+2,"<-AliRsnPairParticle");
390 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 391 if (!fCutMgr) return kTRUE;
392 else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
393}
394
395//________________________________________________________________________________________
396Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
397{
398//
399// Check if the AliRsnEvent argument pass its cuts.
400// If the cut data member is not initialized for it, returns kTRUE.
401//
5eb970a4 402 AliDebug(AliLog::kDebug+2,"<-AliRsnEvent");
403 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 404 if (!fCutMgr) return kTRUE;
405 else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);
5eb970a4 406
aec0ec32 407}