1 /**************************************************************************
2 * Author: Panos Christakoglou. *
3 * Contributors are mentioned in the code where appropriate. *
5 * Permission to use, copy, modify and distribute this software and its *
6 * documentation strictly for non-commercial purposes is hereby granted *
7 * without fee, provided that the above copyright notice appears in all *
8 * copies and that both the copyright notice and this permission notice *
9 * appear in the supporting documentation. The authors make no claims *
10 * about the suitability of this software for any purpose. It is *
11 * provided "as is" without express or implied warranty. *
12 **************************************************************************/
16 //-----------------------------------------------------------------
17 // Balance Function class
18 // This is the class to deal with the Balance Function analysis
19 // Origin: Panos Christakoglou, UOA-CERN, Panos.Christakoglou@cern.ch
20 //-----------------------------------------------------------------
24 #include <Riostream.h>
26 #include <TLorentzVector.h>
28 #include "AliBalance.h"
32 //----------------------------------------//
33 AliBalance::AliBalance()
35 // Default constructor
36 for(Int_t i = 0; i < MAXIMUM_NUMBER_OF_STEPS; i++)
55 //----------------------------------------//
56 AliBalance::AliBalance(Double_t p2Start, Double_t p2Stop, Int_t p2Bins)
59 for(Int_t i = 0; i < MAXIMUM_NUMBER_OF_STEPS; i++)
75 fNumberOfBins = p2Bins;
76 fP2Step = TMath::Abs(fP2Start - fP2Stop) / (Double_t)fNumberOfBins;
79 //----------------------------------------//
80 AliBalance::~AliBalance()
85 //----------------------------------------//
86 void AliBalance::SetNumberOfBins(Int_t ibins)
88 // Sets the number of bins for the analyzed interval
89 fNumberOfBins = ibins ;
92 //----------------------------------------//
93 void AliBalance::SetInterval(Double_t p2Start, Double_t p2Stop)
95 // Sets the analyzed interval.
96 // The analysis variable is set by SetAnalysisType
99 fP2Step = TMath::Abs(p2Start - p2Stop) / (Double_t)fNumberOfBins;
102 //----------------------------------------//
103 void AliBalance::SetAnalysisType(Int_t iType)
105 //0:y - 1:eta - 2:Qlong - 3:Qout - 4:Qside - 5:Qinv - 6:phi
106 this->fAnalysisType = iType;
109 cout<<" ====================== "<<endl;
110 cout<<"||Analysis selected: y||"<<endl;
111 cout<<" ====================== "<<endl;
113 else if(fAnalysisType==1)
115 cout<<" ======================== "<<endl;
116 cout<<"||Analysis selected: eta||"<<endl;
117 cout<<" ======================== "<<endl;
119 else if(fAnalysisType==2)
121 cout<<" ========================== "<<endl;
122 cout<<"||Analysis selected: Qlong||"<<endl;
123 cout<<" ========================== "<<endl;
125 else if(fAnalysisType==3)
127 cout<<" ========================= "<<endl;
128 cout<<"||Analysis selected: Qout||"<<endl;
129 cout<<" ========================= "<<endl;
131 else if(fAnalysisType==4)
133 cout<<" ========================== "<<endl;
134 cout<<"||Analysis selected: Qside||"<<endl;
135 cout<<" ========================== "<<endl;
137 else if(fAnalysisType==5)
139 cout<<" ========================= "<<endl;
140 cout<<"||Analysis selected: Qinv||"<<endl;
141 cout<<" ========================= "<<endl;
143 else if(fAnalysisType==6)
145 cout<<" ======================== "<<endl;
146 cout<<"||Analysis selected: phi||"<<endl;
147 cout<<" ======================== "<<endl;
151 cout<<"Selection of analysis mode failed!!!"<<endl;
152 cout<<"Choices are: 0:y - 1:eta - 2:Qlong - 3:Qout - 4:Qside - 5:Qinv - 6:phi"<<endl;
157 //----------------------------------------//
158 void AliBalance::SetParticles(TLorentzVector *P, Double_t *charge, Int_t dim)
160 // Sets a new particle with given 4-momentum and charge.
161 // dim is the size of the array of charges and corresponds
162 // to the number of selected tracks.
164 this->fCharge = charge;
169 //----------------------------------------//
170 void AliBalance::CalculateBalance()
172 // Calculates the balance function
177 for(i = 0; i < fNtrack; i++)
185 //0:y - 1:eta - 2:Qlong - 3:Qout - 4:Qside - 5:Qinv - 6:phi
188 for(i = 1; i < fNtrack; i++)
190 for(j = 0; j < i; j++)
192 Double_t rap1 = 0.5*log((fV[i].E() - fV[i].Pz())/(fV[i].E() + fV[i].Pz()));
193 Double_t rap2 = 0.5*log((fV[j].E() - fV[j].Pz())/(fV[j].E() + fV[j].Pz()));
194 Double_t dy = TMath::Abs(rap1 - rap2);
195 ibin = Int_t(dy/fP2Step);
196 if((fCharge[i] > 0)&&(fCharge[j] > 0))
198 if((fCharge[i] < 0)&&(fCharge[j] < 0))
200 if((fCharge[i] > 0)&&(fCharge[j] < 0))
202 if((fCharge[i] < 0)&&(fCharge[j] > 0))
209 for(i = 1; i < fNtrack; i++)
211 for(j = 0; j < i; j++)
213 Double_t p1 = sqrt(pow(fV[i].Px(),2) + pow(fV[i].Py(),2) + pow(fV[i].Pz(),2));
214 Double_t p2 = sqrt(pow(fV[j].Px(),2) + pow(fV[j].Py(),2) + pow(fV[j].Pz(),2));
215 Double_t eta1 = 0.5*log((p1 - fV[i].Pz())/(p1 + fV[i].Pz()));
216 Double_t eta2 = 0.5*log((p2 - fV[j].Pz())/(p2 + fV[j].Pz()));
217 Double_t deta = TMath::Abs(eta1 - eta2);
218 ibin = Int_t(deta/fP2Step);
219 if((fCharge[i] > 0)&&(fCharge[j] > 0))
221 if((fCharge[i] < 0)&&(fCharge[j] < 0))
223 if((fCharge[i] > 0)&&(fCharge[j] < 0))
225 if((fCharge[i] < 0)&&(fCharge[j] > 0))
232 for(i = 1; i < fNtrack; i++)
234 for(j = 0; j < i; j++)
236 Double_t eTot = fV[i].E() + fV[j].E();
237 Double_t pxTot = fV[i].Px() + fV[j].Px();
238 Double_t pyTot = fV[i].Py() + fV[j].Py();
239 Double_t pzTot = fV[i].Pz() + fV[j].Pz();
240 Double_t q0Tot = fV[i].E() - fV[j].E();
241 Double_t qzTot = fV[i].Pz() - fV[j].Pz();
242 Double_t snn = pow(eTot,2) - pow(pxTot,2) - pow(pyTot,2) - pow(pzTot,2);
243 Double_t ptTot = sqrt( pow(pxTot,2) + pow(pyTot,2));
244 Double_t qLong = TMath::Abs(eTot*qzTot - pzTot*q0Tot)/sqrt(snn + pow(ptTot,2));
245 ibin = Int_t(qLong/fP2Step);
247 if((fCharge[i] > 0)&&(fCharge[j] > 0))
249 if((fCharge[i] < 0)&&(fCharge[j] < 0))
251 if((fCharge[i] > 0)&&(fCharge[j] < 0))
253 if((fCharge[i] < 0)&&(fCharge[j] > 0))
260 for(i = 1; i < fNtrack; i++)
262 for(j = 0; j < i; j++)
264 Double_t eTot = fV[i].E() + fV[j].E();
265 Double_t pxTot = fV[i].Px() + fV[j].Px();
266 Double_t pyTot = fV[i].Py() + fV[j].Py();
267 Double_t pzTot = fV[i].Pz() + fV[j].Pz();
268 Double_t qxTot = fV[i].Px() - fV[j].Px();
269 Double_t qyTot = fV[i].Py() - fV[j].Py();
270 Double_t snn = pow(eTot,2) - pow(pxTot,2) - pow(pyTot,2) - pow(pzTot,2);
271 Double_t ptTot = sqrt( pow(pxTot,2) + pow(pyTot,2));
272 Double_t qOut = sqrt(snn/(snn + pow(ptTot,2))) * TMath::Abs(pxTot*qxTot + pyTot*qyTot)/ptTot;
273 ibin = Int_t(qOut/fP2Step);
275 if((fCharge[i] > 0)&&(fCharge[j] > 0))
277 if((fCharge[i] < 0)&&(fCharge[j] < 0))
279 if((fCharge[i] > 0)&&(fCharge[j] < 0))
281 if((fCharge[i] < 0)&&(fCharge[j] > 0))
288 for(i = 1; i < fNtrack; i++)
290 for(j = 0; j < i; j++)
292 Double_t pxTot = fV[i].Px() + fV[j].Px();
293 Double_t pyTot = fV[i].Py() + fV[j].Py();
294 Double_t qxTot = fV[i].Px() - fV[j].Px();
295 Double_t qyTot = fV[i].Py() - fV[j].Py();
296 Double_t ptTot = sqrt( pow(pxTot,2) + pow(pyTot,2));
297 Double_t qSide = TMath::Abs(pxTot*qyTot - pyTot*qxTot)/ptTot;
298 ibin = Int_t(qSide/fP2Step);
300 if((fCharge[i] > 0)&&(fCharge[j] > 0))
302 if((fCharge[i] < 0)&&(fCharge[j] < 0))
304 if((fCharge[i] > 0)&&(fCharge[j] < 0))
306 if((fCharge[i] < 0)&&(fCharge[j] > 0))
313 for(i = 1; i < fNtrack; i++)
315 for(j = 0; j < i; j++)
317 Double_t q0Tot = fV[i].E() - fV[j].E();
318 Double_t qxTot = fV[i].Px() - fV[j].Px();
319 Double_t qyTot = fV[i].Py() - fV[j].Py();
320 Double_t qzTot = fV[i].Pz() - fV[j].Pz();
321 Double_t qInv = sqrt(TMath::Abs(-pow(q0Tot,2) +pow(qxTot,2) +pow(qyTot,2) +pow(qzTot,2)));
322 ibin = Int_t(qInv/fP2Step);
324 if((fCharge[i] > 0)&&(fCharge[j] > 0))
326 if((fCharge[i] < 0)&&(fCharge[j] < 0))
328 if((fCharge[i] > 0)&&(fCharge[j] < 0))
330 if((fCharge[i] < 0)&&(fCharge[j] > 0))
337 for(i = 1; i < fNtrack; i++)
339 for(j = 0; j < i; j++)
341 Double_t phi1 = TMath::ATan(fV[i].Py()/fV[i].Px())*180.0/TMath::Pi();
342 Double_t phi2 = TMath::ATan(fV[j].Py()/fV[j].Px())*180.0/TMath::Pi();
343 Double_t dphi = TMath::Abs(phi1 - phi2);
344 ibin = Int_t(dphi/fP2Step);
345 if((fCharge[i] > 0)&&(fCharge[j] > 0))
347 if((fCharge[i] < 0)&&(fCharge[j] < 0))
349 if((fCharge[i] > 0)&&(fCharge[j] < 0))
351 if((fCharge[i] < 0)&&(fCharge[j] > 0))
358 //----------------------------------------//
359 Double_t AliBalance::GetBalance(Int_t p2)
361 // Returns the value of the balance function in bin p2
362 fB[p2] = 0.5*(((fNpn[p2] - 2.0*fNnn[p2])/fNn) + ((fNpn[p2] - 2.0*fNpp[p2])/fNp))/fP2Step;
367 //----------------------------------------//
368 Double_t AliBalance::GetError(Int_t p2)
370 // Returns the error on the BF value for bin p2
371 ferror[p2] = sqrt( Double_t(fNpp[p2])/(Double_t(fNp)*Double_t(fNp)) + Double_t(fNnn[p2])/(Double_t(fNn)*Double_t(fNn)) + Double_t(fNpn[p2])*pow((0.5/Double_t(fNp) + 0.5/Double_t(fNn)),2))/fP2Step;
376 //----------------------------------------//
377 void AliBalance::PrintResults()
379 // Prints the results
380 Double_t x[MAXIMUM_NUMBER_OF_STEPS];
381 Double_t fSumXi = 0.0, fSumBi = 0.0, fSumBiXi = 0.0;
382 Double_t fSumBiXi2 = 0.0, fSumBi2Xi2 = 0.0;
383 Double_t fSumDeltaBi2 = 0.0, fSumXi2DeltaBi2 = 0.0;
384 Double_t deltaBalP2 = 0.0, integral = 0.0;
385 Double_t deltaErrorNew = 0.0;
387 cout<<"=================================================="<<endl;
388 for(Int_t i = 0; i < fNumberOfBins; i++)
390 x[i] = fP2Start + fP2Step*i + fP2Step/2 ;
391 cout<<"B: "<<fB[i]<<"\t Error: "<<ferror[i]<<"\t bin: "<<x[i]<<endl;
393 cout<<"=================================================="<<endl;
394 for(Int_t i = 1; i < fNumberOfBins; i++)
398 fSumBiXi += fB[i]*x[i];
399 fSumBiXi2 += fB[i]*pow(x[i],2);
400 fSumBi2Xi2 += pow(fB[i],2)*pow(x[i],2);
401 fSumDeltaBi2 += pow(ferror[i],2) ;
402 fSumXi2DeltaBi2 += pow(x[i],2) * pow(ferror[i],2) ;
404 deltaBalP2 += fP2Step*pow(ferror[i],2) ;
405 integral += fP2Step*fB[i] ;
407 for(Int_t i = 1; i < fNumberOfBins; i++)
409 deltaErrorNew += ferror[i]*(x[i]*fSumBi - fSumBiXi)/pow(fSumBi,2);
411 Double_t integralError = sqrt(deltaBalP2) ;
413 Double_t delta = fSumBiXi / fSumBi ;
414 Double_t deltaError = (fSumBiXi / fSumBi) * sqrt(pow((sqrt(fSumXi2DeltaBi2)/fSumBiXi),2) + pow((fSumDeltaBi2/fSumBi),2) ) ;
416 cout<<"Analyzed events: "<<fAnalyzedEvents<<endl;
417 cout<<"Width: "<<delta<<"\t Error: "<<deltaError<<endl;
418 cout<<"New error: "<<deltaErrorNew<<endl;
419 cout<<"Interval: "<<integral<<"\t Error: "<<integralError<<endl;
420 cout<<"=================================================="<<endl;