]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGLF/RESONANCES/AliRsnLoopEff.cxx
Updated macros for D0 analysis (Massimo)
[u/mrichter/AliRoot.git] / PWGLF / RESONANCES / AliRsnLoopEff.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 "AliLog.h"
17 #include "AliRsnLoopEff.h"
18
19 ClassImp(AliRsnLoopEff)
20
21 //_____________________________________________________________________________
22 AliRsnLoopEff::AliRsnLoopEff(const char *name, Int_t nSteps, Double_t maxDist) :
23    AliRsnLoop(name),
24    fAddSteps(nSteps),
25    fSteps(0),
26    fOutput(0),
27    fMaxDistPV(maxDist)
28 {
29 //
30 // Default constructor
31 //
32
33    fVertex[0] = fVertex[1] = fVertex[2] = 0.0;
34 }
35
36 //_____________________________________________________________________________
37 AliRsnLoopEff::AliRsnLoopEff(const AliRsnLoopEff &copy) :
38    AliRsnLoop(copy),
39    fAddSteps(copy.fAddSteps),
40    fSteps(copy.fSteps),
41    fOutput(copy.fOutput),
42    fMaxDistPV(copy.fMaxDistPV)
43 {
44 //
45 // Copy constructor
46 //
47
48    fVertex[0] = fVertex[1] = fVertex[2] = 0.0;
49 }
50
51 //_____________________________________________________________________________
52 AliRsnLoopEff &AliRsnLoopEff::operator=(const AliRsnLoopEff &copy)
53 {
54 //
55 // Assignment operator
56 //
57
58    AliRsnLoop::operator=(copy);
59    if (this == &copy)
60       return *this;
61    fAddSteps = copy.fAddSteps;
62    fSteps = copy.fSteps;
63    fOutput = copy.fOutput;
64
65    return (*this);
66 }
67
68 //_____________________________________________________________________________
69 AliRsnLoopEff::~AliRsnLoopEff()
70 {
71 //
72 // Destructor
73 //
74
75    fSteps.Delete();
76    delete fOutput;
77 }
78
79 //_____________________________________________________________________________
80 void AliRsnLoopEff::CreateOutput()
81 {
82 //
83 // Create the unique output object of this loop
84 //
85
86    fOutput = new AliRsnListOutput(Form("%s_out", GetName()), AliRsnListOutput::kCFContainer);
87 }
88
89 //_____________________________________________________________________________
90 void AliRsnLoopEff::AddStep(TObject *cuts)
91 {
92 //
93 // Add a step on reconstruction
94 //
95
96    fSteps.AddLast(cuts);
97 }
98
99 //_____________________________________________________________________________
100 Bool_t AliRsnLoopEff::Init(const char *prefix, TList *list)
101 {
102 //
103 // Initialization function.
104 // Loops on all functions and eventual the ntuple, to initialize output objects.
105 //
106
107    if (!fOutputs.IsEmpty()) {
108       AliInfo("Clearing container of this efficiency loop.");
109       fOutputs.Delete();
110    }
111
112    Int_t nSteps = (Int_t)fSteps.GetEntries();
113    nSteps += fAddSteps;
114
115    fOutput->SetSteps(nSteps);
116    fOutput->SetSkipFailed(kFALSE);
117    AliRsnLoop::AddOutput(fOutput);
118
119    if (AliRsnLoop::Init(Form("%s_%s", prefix, GetName()), list)) {
120       fOutput = (AliRsnListOutput *)fOutputs[0];
121       return kTRUE;
122    } else {
123       fOutput = 0x0;
124       return kFALSE;
125    }
126 }
127
128 //_____________________________________________________________________________
129 Int_t AliRsnLoopEff::FindTrack(Int_t label, const AliVEvent *event)
130 {
131 //
132 // Loops an event and find all tracks which have a label
133 // equal to that passed as first argument.
134 //
135
136    Int_t   i = 0;
137    Int_t   ntracks = event->GetNumberOfTracks();
138    TArrayI array(100);
139
140    for (i = 0; i < ntracks; i++) {
141       AliVParticle *track = event->GetTrack(i);
142       if (TMath::Abs(track->GetLabel()) != label) continue;
143       return i;
144    }
145
146    return -1;
147 }
148
149 //__________________________________________________________________________________________________
150 Int_t AliRsnLoopEff::GetMatchedDaughter(Int_t label, AliRsnEvent *event)
151 {
152 //
153 // Searches an object among all possible daughters which matches the corresponding label
154 // and if it is found, assigns to the daughter and returns it
155 //
156
157    if (!event) return -1;
158
159    AliRsnDaughter out;
160
161    Int_t i, imax = event->GetAbsoluteSum();
162    for (i = 0; i < imax; i++) {
163       event->SetDaughter(out, i);
164       if (out.IsOK() && out.GetLabel() == label) return i;
165    }
166
167    return -1;
168 }
169
170 //__________________________________________________________________________________________________
171 Double_t AliRsnLoopEff::DistanceFromPV(Double_t x, Double_t y, Double_t z)
172 {
173 //
174 // Compute distance from current primary vertex
175 //
176
177    AliDebugClass(1, Form("Vertex = %.3f %.3f %.3f -- vprod = %.3f %.3f %.3f", fVertex[0], fVertex[1], fVertex[2], x, y, z));
178
179    x -= fVertex[0];
180    y -= fVertex[1];
181    z -= fVertex[2];
182
183    return TMath::Sqrt(x*x + y*y + z*z);
184 }
185
186