]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnPair.cxx
Modifications in the balance function code + addition of the very first version of...
[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
6f4a992c 231// fPairParticle.PrintInfo();
5eb970a4 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//_____________________________________________________________________________
6f4a992c 247TList * AliRsnPair::GenerateHistograms(TString prefix,TList *list)
aec0ec32 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,"<-");
6f4a992c 257 if (!list){
258 TList *list = new TList();
259 list->SetName(GetPairHistName(0x0).Data());
260 }
aec0ec32 261 Char_t hName[255], hTitle[255];
5eb970a4 262 //AliRsnFunction *fcn = 0;
aec0ec32 263 AliRsnFunction *fcn = 0;
5eb970a4 264 for (Int_t i=0;i< fFunctions.GetEntries();i++) {
aec0ec32 265 fcn = (AliRsnFunction*)fFunctions.At(i);
266 sprintf(hName, "%s_%s", prefix.Data(), GetPairHistName(fcn).Data());
267 sprintf(hTitle, "%s", GetPairHistTitle(fcn).Data());
5eb970a4 268 //TList *histos = fcn->Init(hName, hTitle);
269 list->Add(fcn->CreateHistogram(hName, hTitle));
15d5fd02 270 //histos->Print();
5eb970a4 271 //list->Add(histos);
aec0ec32 272 }
5eb970a4 273 cout << "PRINTING LIST" << endl;
274 list->Print();
275 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 276 return list;
277}
278
aec0ec32 279
aec0ec32 280
281//_____________________________________________________________________________
78b94cbd 282TString AliRsnPair::GetPairTypeName(EPairType type) const
aec0ec32 283{
284//
285// Returns type name, made with particle names ant chosen PID
286//
5eb970a4 287 AliDebug(AliLog::kDebug+2,"<-");
288 AliDebug(AliLog::kDebug+2,"->");
289 switch (type) {
aec0ec32 290 case kNoPID : return ("NOPID_");break;
291 case kNoPIDMix : return ("NOPIDMIX_");break;
292 case kRealisticPID : return ("REALISTIC_");break;
293 case kRealisticPIDMix : return ("REALISTICMIX_");break;
294 case kPerfectPID : return ("PERFECT_");break;
295 case kPerfectPIDMix : return ("PERFECTMIX_");break;
aec0ec32 296 default:
297 AliWarning("Unrecognized value of EPairTypeName argument");
298 break;
299 }
300
301 return "NOTYPE";
302}
303
304//_____________________________________________________________________________
78b94cbd 305TString AliRsnPair::GetPairName() const
aec0ec32 306{
307//
308// Retruns pair name
309//
5eb970a4 310 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 311 TString sName;
312 sName += GetPairTypeName(fPairType);
313 sName += fPairDef->GetPairName();
5eb970a4 314 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 315 return sName;
316}
317
318//_____________________________________________________________________________
78b94cbd 319TString AliRsnPair::GetPairHistName(AliRsnFunction *fcn, TString text) const
aec0ec32 320{
321//
15d5fd02 322// Returns definitive histogram name
aec0ec32 323//
5eb970a4 324 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 325 TString sName;
5eb970a4 326 if (fcn) {
327 sName = fcn->GetName();
aec0ec32 328 sName += "_";
329 }
330 sName += GetPairName();
331 sName += "_";
332 if (fCutMgr) sName += fCutMgr->GetName();
333 sName += text;
5eb970a4 334 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 335 return sName;
336}
337
338//_____________________________________________________________________________
78b94cbd 339TString AliRsnPair::GetPairHistTitle(AliRsnFunction *fcn, TString text) const
aec0ec32 340{
341//
15d5fd02 342// Returns definitive histogram title
aec0ec32 343//
5eb970a4 344 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 345 TString sTitle;
5eb970a4 346 if (fcn) {
347 sTitle = fcn->GetTitle();
aec0ec32 348 sTitle += " ";
349 }
350 sTitle += GetPairName();
351 sTitle +=" ";
352 if (fCutMgr) sTitle += fCutMgr->GetTitle();
353 sTitle += text;
5eb970a4 354 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 355 return sTitle;
356}
357
358//_____________________________________________________________________________
359void AliRsnPair::AddFunction(AliRsnFunction *fcn)
360{
361//
362// Adds a new computing function
363//
5eb970a4 364 AliDebug(AliLog::kDebug+2,"<-");
aec0ec32 365 Int_t size = fFunctions.GetEntries();
15d5fd02 366 new (fFunctions[size]) AliRsnFunction(*fcn);
5eb970a4 367 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 368}
369
370//________________________________________________________________________________________
371Bool_t AliRsnPair::CutPass(AliRsnDaughter *d)
372{
373//
374// Check if the AliRsnDaughter argument pass its cuts.
375// If the cut data member is not initialized for it, returns kTRUE.
376//
5eb970a4 377 AliDebug(AliLog::kDebug+2,"<-AliRsnDaughter");
378 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 379 if (!fCutMgr) return kTRUE;
380 else return fCutMgr->IsSelected(AliRsnCut::kParticle, d);
381}
382
383//________________________________________________________________________________________
384Bool_t AliRsnPair::CutPass(AliRsnPairParticle *p)
385{
386//
387// Check if the AliRsnPairParticle argument pass its cuts.
388// If the cut data member is not initialized for it, returns kTRUE.
aec0ec32 389//
5eb970a4 390 AliDebug(AliLog::kDebug+2,"<-AliRsnPairParticle");
391 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 392 if (!fCutMgr) return kTRUE;
393 else return fCutMgr->IsSelected(AliRsnCut::kPair, p);
394}
395
396//________________________________________________________________________________________
397Bool_t AliRsnPair::CutPass(AliRsnEvent *e)
398{
399//
400// Check if the AliRsnEvent argument pass its cuts.
401// If the cut data member is not initialized for it, returns kTRUE.
402//
5eb970a4 403 AliDebug(AliLog::kDebug+2,"<-AliRsnEvent");
404 AliDebug(AliLog::kDebug+2,"->");
aec0ec32 405 if (!fCutMgr) return kTRUE;
406 else return fCutMgr->IsSelected(AliRsnCut::kEvent, e);
5eb970a4 407
aec0ec32 408}