]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliInvmass.cxx
New geometry files from R.Barbera
[u/mrichter/AliRoot.git] / RALICE / AliInvmass.cxx
1 #include "AliInvmass.h"
2  
3 ClassImp(AliInvmass) // Class implementation to enable ROOT I/O
4  
5 AliInvmass::AliInvmass()
6 {
7 // Creation of an AliInvmass object and initialisation of parameters
8  fPi=acos(-1.);
9  fMode=2;
10  fBkg=0;
11  fNewtheta=1;
12  fNewphi=1;
13  fMinv=0;
14  fMbkg=0;
15 }
16 ////////////////////////////////////////////////////////////////////////////////
17 AliInvmass::~AliInvmass()
18 {
19 // Destructor to delete dynamically allocated memory
20  if (fMinv)
21  {
22   fMinv->Delete();
23   delete fMinv;
24   fMinv=0;
25  }
26
27  if (fMbkg)
28  {
29   fMbkg->Delete();
30   delete fMbkg;
31   fMbkg=0;
32  }
33 }
34 ////////////////////////////////////////////////////////////////////////////////
35 void AliInvmass::SetStorageMode(Int_t m)
36 {
37 // Set storage mode for the result arrays for inv. mass and comb. background
38  fMode=2;
39  if (m==1) fMode=1;
40 }
41 ////////////////////////////////////////////////////////////////////////////////
42 void AliInvmass::SetThetaSwitch(Int_t i)
43 {
44 // Enable/Disable (1/0) switching of theta angle in comb. bkg. reconstruction.
45 // Default : Switching of theta is enabled.
46  fNewtheta=1;
47  if (i==0) fNewtheta=0;
48 }
49 ////////////////////////////////////////////////////////////////////////////////
50 void AliInvmass::SetPhiSwitch(Int_t i)
51 {
52 // Enable/Disable (1/0) switching of phi angle in comb. bkg. reconstruction.
53 // Default : Switching of phi is enabled.
54  fNewphi=1;
55  if (i==0) fNewphi=0;
56 }
57 ////////////////////////////////////////////////////////////////////////////////
58 Int_t AliInvmass::GetStorageMode()
59 {
60 // Provide mode of storage for the result arrays for inv. mass and comb. background
61  return fMode;
62 }
63 ////////////////////////////////////////////////////////////////////////////////
64 Int_t AliInvmass::GetThetaSwitch()
65 {
66 // Provide the theta switching flag
67  return fNewtheta;
68 }
69 ////////////////////////////////////////////////////////////////////////////////
70 Int_t AliInvmass::GetPhiSwitch()
71 {
72 // Provide the phi switching flag
73  return fNewphi;
74 }
75 ////////////////////////////////////////////////////////////////////////////////
76 TObjArray* AliInvmass::Invmass(TObjArray* a1,TObjArray* a2)
77 {
78 // Perform two-particle invariant mass reconstruction
79  fBkg=0;
80  Combine(a1,a2);
81  return fMinv;
82 }
83 ////////////////////////////////////////////////////////////////////////////////
84 TObjArray* AliInvmass::CombBkg(TObjArray* a1,TObjArray* a2)
85 {
86 // Perform two-particle combinatorial background reconstruction
87  fBkg=1;
88  Combine(a1,a2);
89  if (fMode != 1)
90  {
91   return fMbkg;
92  }
93  else
94  {
95   return fMinv;
96  }
97 }
98 ////////////////////////////////////////////////////////////////////////////////
99 void AliInvmass::Combine(TObjArray* a1,TObjArray* a2)
100 {
101 // Perform two-particle invariant mass reconstruction
102  
103  if ((!fBkg || fMode==1) && fMinv)
104  {
105   fMinv->Delete();
106   delete fMinv;
107   fMinv=0;
108  }
109  
110  if (fBkg && (fMode !=1) && fMbkg)
111  {
112   fMbkg->Delete();
113   delete fMbkg;
114   fMbkg=0;
115  }
116
117  Int_t isame; // Indicates whether both lists are identical
118  isame=0;
119  if (a1==a2) isame=1;
120
121  // Index i must loop over the shortest of a1 and a2
122  TObjArray* listi=a1;
123  TObjArray* listj=a2;
124  Int_t ni=a1->GetEntries();
125  Int_t nj=a2->GetEntries();
126  if (nj < ni)
127  {
128   ni=a2->GetEntries();
129   nj=a1->GetEntries();
130   listi=a2;
131   listj=a1;
132  }
133
134  AliTrack* p1=0;  
135  AliTrack* p2=0;
136  AliTrack* px=0;
137  Ali4Vector ptot;
138  AliTrack* t=0;
139  Double_t v2[4],vx[4];
140  Float_t q1,q2;
141  
142  Int_t jmin; // Start index for list j
143  Int_t jx;   // Index for randomly picked particle for comb. bkg. reconstruction 
144  
145  for (Int_t i=0; i<ni; i++) // Select first a particle from list i
146  {
147   p1=(AliTrack*)listi->At(i);
148   p2=0;
149
150   if (!p1) continue;
151
152   jmin=0;
153   if (isame) jmin=i+1;
154   for (Int_t j=jmin; j<nj; j++) // Select also a particle from list j
155   {
156    p2=(AliTrack*)listj->At(j);
157    if (p1==p2) p2=0; // Don't combine particle with itself
158
159    if (!p2) continue;
160
161    p2->GetVector(v2,"sph");
162
163    // Take theta and phi from randomly chosen other list j particle for bkg. reconstr.
164    if (fBkg)
165    {
166     px=0; 
167     if ((!isame && nj>1) || (isame && nj>2))
168     {
169      jx=int(fRndm.Uniform(0,float(nj)));
170      px=(AliTrack*)listj->At(jx);
171      
172      while (!px || px==p2 || px==p1)
173      {
174       jx++;
175       if (jx >= nj) jx=0;
176       px=(AliTrack*)listj->At(jx);
177      }
178
179      px->GetVector(vx,"sph");
180      if (fNewtheta) v2[2]=vx[2]; // Replace the theta angle in the v2 vector
181      if (fNewphi) v2[3]=vx[3]; // Replace the phi angle in the v2 vector
182     }
183    }
184  
185    if ((!fBkg && p2) || (fBkg && px))
186    {
187     // Store the data of this two-particle combination
188     ptot.SetVector(v2,"sph");
189     ptot=(Ali4Vector)(ptot+(*p1));
190     q1=p1->GetCharge();
191     q2=p2->GetCharge();
192     t=new AliTrack;
193     t->Set4Momentum(ptot);
194     t->SetCharge(q1+q2);
195     if (!fBkg || fMode==1) 
196     {
197      if (!fMinv) fMinv=new TObjArray();
198      fMinv->Add(t);
199     }
200     else
201     {
202      if (!fMbkg) fMbkg=new TObjArray();
203      fMbkg->Add(t);
204     }
205    }
206
207   } // End of second particle loop
208
209  } // End of first particle loop
210 }
211 ////////////////////////////////////////////////////////////////////////////////