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>
27 #include <TGraphErrors.h>
29 #include "AliBalance.h"
33 //----------------------------------------//
34 AliBalance::AliBalance()
36 // Default constructor
37 for(Int_t i = 0; i < MAXIMUM_NUMBER_OF_STEPS; i++)
56 //----------------------------------------//
57 AliBalance::AliBalance(Double_t p2Start, Double_t p2Stop, Int_t p2Bins)
60 for(Int_t i = 0; i < MAXIMUM_NUMBER_OF_STEPS; i++)
76 fNumberOfBins = p2Bins;
77 fP2Step = TMath::Abs(fP2Start - fP2Stop) / (Double_t)fNumberOfBins;
80 //----------------------------------------//
81 AliBalance::~AliBalance()
86 //----------------------------------------//
87 void AliBalance::SetNumberOfBins(Int_t ibins)
89 // Sets the number of bins for the analyzed interval
90 fNumberOfBins = ibins ;
93 //----------------------------------------//
94 void AliBalance::SetInterval(Double_t p2Start, Double_t p2Stop)
96 // Sets the analyzed interval.
97 // The analysis variable is set by SetAnalysisType
100 fP2Step = TMath::Abs(p2Start - p2Stop) / (Double_t)fNumberOfBins;
103 //----------------------------------------//
104 void AliBalance::SetAnalysisType(Int_t iType)
106 //0:y - 1:eta - 2:Qlong - 3:Qout - 4:Qside - 5:Qinv - 6:phi
107 this->fAnalysisType = iType;
110 cout<<" ====================== "<<endl;
111 cout<<"||Analysis selected: y||"<<endl;
112 cout<<" ====================== "<<endl;
114 else if(fAnalysisType==1)
116 cout<<" ======================== "<<endl;
117 cout<<"||Analysis selected: eta||"<<endl;
118 cout<<" ======================== "<<endl;
120 else if(fAnalysisType==2)
122 cout<<" ========================== "<<endl;
123 cout<<"||Analysis selected: Qlong||"<<endl;
124 cout<<" ========================== "<<endl;
126 else if(fAnalysisType==3)
128 cout<<" ========================= "<<endl;
129 cout<<"||Analysis selected: Qout||"<<endl;
130 cout<<" ========================= "<<endl;
132 else if(fAnalysisType==4)
134 cout<<" ========================== "<<endl;
135 cout<<"||Analysis selected: Qside||"<<endl;
136 cout<<" ========================== "<<endl;
138 else if(fAnalysisType==5)
140 cout<<" ========================= "<<endl;
141 cout<<"||Analysis selected: Qinv||"<<endl;
142 cout<<" ========================= "<<endl;
144 else if(fAnalysisType==6)
146 cout<<" ======================== "<<endl;
147 cout<<"||Analysis selected: phi||"<<endl;
148 cout<<" ======================== "<<endl;
152 cout<<"Selection of analysis mode failed!!!"<<endl;
153 cout<<"Choices are: 0:y - 1:eta - 2:Qlong - 3:Qout - 4:Qside - 5:Qinv - 6:phi"<<endl;
158 //----------------------------------------//
159 void AliBalance::SetParticles(TLorentzVector *P, Double_t *charge, Int_t dim)
161 // Sets a new particle with given 4-momentum and charge.
162 // dim is the size of the array of charges and corresponds
163 // to the number of selected tracks.
165 this->fCharge = charge;
170 //----------------------------------------//
171 void AliBalance::CalculateBalance()
173 // Calculates the balance function
178 for(i = 0; i < fNtrack; i++)
186 //0:y - 1:eta - 2:Qlong - 3:Qout - 4:Qside - 5:Qinv - 6:phi
189 for(i = 1; i < fNtrack; i++)
191 for(j = 0; j < i; j++)
193 Double_t rap1 = 0.5*log((fV[i].E() + fV[i].Pz())/(fV[i].E() - fV[i].Pz()));
194 Double_t rap2 = 0.5*log((fV[j].E() + fV[j].Pz())/(fV[j].E() - fV[j].Pz()));
195 Double_t dy = TMath::Abs(rap1 - rap2);
196 ibin = Int_t(dy/fP2Step);
197 if((fCharge[i] > 0)&&(fCharge[j] > 0))
199 if((fCharge[i] < 0)&&(fCharge[j] < 0))
201 if((fCharge[i] > 0)&&(fCharge[j] < 0))
203 if((fCharge[i] < 0)&&(fCharge[j] > 0))
210 for(i = 1; i < fNtrack; i++)
212 for(j = 0; j < i; j++)
214 Double_t p1 = sqrt(pow(fV[i].Px(),2) + pow(fV[i].Py(),2) + pow(fV[i].Pz(),2));
215 Double_t p2 = sqrt(pow(fV[j].Px(),2) + pow(fV[j].Py(),2) + pow(fV[j].Pz(),2));
216 Double_t eta1 = 0.5*log((p1 + fV[i].Pz())/(p1 - fV[i].Pz()));
217 Double_t eta2 = 0.5*log((p2 + fV[j].Pz())/(p2 - fV[j].Pz()));
218 Double_t deta = TMath::Abs(eta1 - eta2);
219 ibin = Int_t(deta/fP2Step);
220 if((fCharge[i] > 0)&&(fCharge[j] > 0))
222 if((fCharge[i] < 0)&&(fCharge[j] < 0))
224 if((fCharge[i] > 0)&&(fCharge[j] < 0))
226 if((fCharge[i] < 0)&&(fCharge[j] > 0))
233 for(i = 1; i < fNtrack; i++)
235 for(j = 0; j < i; j++)
237 Double_t eTot = fV[i].E() + fV[j].E();
238 Double_t pxTot = fV[i].Px() + fV[j].Px();
239 Double_t pyTot = fV[i].Py() + fV[j].Py();
240 Double_t pzTot = fV[i].Pz() + fV[j].Pz();
241 Double_t q0Tot = fV[i].E() - fV[j].E();
242 Double_t qzTot = fV[i].Pz() - fV[j].Pz();
243 Double_t snn = pow(eTot,2) - pow(pxTot,2) - pow(pyTot,2) - pow(pzTot,2);
244 Double_t ptTot = sqrt( pow(pxTot,2) + pow(pyTot,2));
245 Double_t qLong = TMath::Abs(eTot*qzTot - pzTot*q0Tot)/sqrt(snn + pow(ptTot,2));
246 ibin = Int_t(qLong/fP2Step);
248 if((fCharge[i] > 0)&&(fCharge[j] > 0))
250 if((fCharge[i] < 0)&&(fCharge[j] < 0))
252 if((fCharge[i] > 0)&&(fCharge[j] < 0))
254 if((fCharge[i] < 0)&&(fCharge[j] > 0))
261 for(i = 1; i < fNtrack; i++)
263 for(j = 0; j < i; j++)
265 Double_t eTot = fV[i].E() + fV[j].E();
266 Double_t pxTot = fV[i].Px() + fV[j].Px();
267 Double_t pyTot = fV[i].Py() + fV[j].Py();
268 Double_t pzTot = fV[i].Pz() + fV[j].Pz();
269 Double_t qxTot = fV[i].Px() - fV[j].Px();
270 Double_t qyTot = fV[i].Py() - fV[j].Py();
271 Double_t snn = pow(eTot,2) - pow(pxTot,2) - pow(pyTot,2) - pow(pzTot,2);
272 Double_t ptTot = sqrt( pow(pxTot,2) + pow(pyTot,2));
273 Double_t qOut = sqrt(snn/(snn + pow(ptTot,2))) * TMath::Abs(pxTot*qxTot + pyTot*qyTot)/ptTot;
274 ibin = Int_t(qOut/fP2Step);
276 if((fCharge[i] > 0)&&(fCharge[j] > 0))
278 if((fCharge[i] < 0)&&(fCharge[j] < 0))
280 if((fCharge[i] > 0)&&(fCharge[j] < 0))
282 if((fCharge[i] < 0)&&(fCharge[j] > 0))
289 for(i = 1; i < fNtrack; i++)
291 for(j = 0; j < i; j++)
293 Double_t pxTot = fV[i].Px() + fV[j].Px();
294 Double_t pyTot = fV[i].Py() + fV[j].Py();
295 Double_t qxTot = fV[i].Px() - fV[j].Px();
296 Double_t qyTot = fV[i].Py() - fV[j].Py();
297 Double_t ptTot = sqrt( pow(pxTot,2) + pow(pyTot,2));
298 Double_t qSide = TMath::Abs(pxTot*qyTot - pyTot*qxTot)/ptTot;
299 ibin = Int_t(qSide/fP2Step);
301 if((fCharge[i] > 0)&&(fCharge[j] > 0))
303 if((fCharge[i] < 0)&&(fCharge[j] < 0))
305 if((fCharge[i] > 0)&&(fCharge[j] < 0))
307 if((fCharge[i] < 0)&&(fCharge[j] > 0))
314 for(i = 1; i < fNtrack; i++)
316 for(j = 0; j < i; j++)
318 Double_t q0Tot = fV[i].E() - fV[j].E();
319 Double_t qxTot = fV[i].Px() - fV[j].Px();
320 Double_t qyTot = fV[i].Py() - fV[j].Py();
321 Double_t qzTot = fV[i].Pz() - fV[j].Pz();
322 Double_t qInv = sqrt(TMath::Abs(-pow(q0Tot,2) +pow(qxTot,2) +pow(qyTot,2) +pow(qzTot,2)));
323 ibin = Int_t(qInv/fP2Step);
325 if((fCharge[i] > 0)&&(fCharge[j] > 0))
327 if((fCharge[i] < 0)&&(fCharge[j] < 0))
329 if((fCharge[i] > 0)&&(fCharge[j] < 0))
331 if((fCharge[i] < 0)&&(fCharge[j] > 0))
338 for(i = 1; i < fNtrack; i++)
340 for(j = 0; j < i; j++)
342 Double_t phi1 = TMath::ATan(fV[i].Py()/fV[i].Px())*180.0/TMath::Pi();
343 Double_t phi2 = TMath::ATan(fV[j].Py()/fV[j].Px())*180.0/TMath::Pi();
344 Double_t dphi = TMath::Abs(phi1 - phi2);
345 ibin = Int_t(dphi/fP2Step);
346 if((fCharge[i] > 0)&&(fCharge[j] > 0))
348 if((fCharge[i] < 0)&&(fCharge[j] < 0))
350 if((fCharge[i] > 0)&&(fCharge[j] < 0))
352 if((fCharge[i] < 0)&&(fCharge[j] > 0))
359 //----------------------------------------//
360 Double_t AliBalance::GetBalance(Int_t p2)
362 // Returns the value of the balance function in bin p2
363 fB[p2] = 0.5*(((fNpn[p2] - 2.0*fNnn[p2])/fNn) + ((fNpn[p2] - 2.0*fNpp[p2])/fNp))/fP2Step;
368 //----------------------------------------//
369 Double_t AliBalance::GetError(Int_t p2)
371 // Returns the error on the BF value for bin p2
372 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;
377 //----------------------------------------//
378 void AliBalance::PrintResults()
380 // Prints the results
381 Double_t x[MAXIMUM_NUMBER_OF_STEPS];
382 Double_t fSumXi = 0.0, fSumBi = 0.0, fSumBiXi = 0.0;
383 Double_t fSumBiXi2 = 0.0, fSumBi2Xi2 = 0.0;
384 Double_t fSumDeltaBi2 = 0.0, fSumXi2DeltaBi2 = 0.0;
385 Double_t deltaBalP2 = 0.0, integral = 0.0;
386 Double_t deltaErrorNew = 0.0;
388 cout<<"=================================================="<<endl;
389 for(Int_t i = 0; i < fNumberOfBins; i++)
391 x[i] = fP2Start + fP2Step*i + fP2Step/2 ;
392 cout<<"B: "<<fB[i]<<"\t Error: "<<ferror[i]<<"\t bin: "<<x[i]<<endl;
394 cout<<"=================================================="<<endl;
395 for(Int_t i = 1; i < fNumberOfBins; i++)
399 fSumBiXi += fB[i]*x[i];
400 fSumBiXi2 += fB[i]*pow(x[i],2);
401 fSumBi2Xi2 += pow(fB[i],2)*pow(x[i],2);
402 fSumDeltaBi2 += pow(ferror[i],2) ;
403 fSumXi2DeltaBi2 += pow(x[i],2) * pow(ferror[i],2) ;
405 deltaBalP2 += fP2Step*pow(ferror[i],2) ;
406 integral += fP2Step*fB[i] ;
408 for(Int_t i = 1; i < fNumberOfBins; i++)
410 deltaErrorNew += ferror[i]*(x[i]*fSumBi - fSumBiXi)/pow(fSumBi,2);
412 Double_t integralError = sqrt(deltaBalP2) ;
414 Double_t delta = fSumBiXi / fSumBi ;
415 Double_t deltaError = (fSumBiXi / fSumBi) * sqrt(pow((sqrt(fSumXi2DeltaBi2)/fSumBiXi),2) + pow((fSumDeltaBi2/fSumBi),2) ) ;
417 cout<<"Analyzed events: "<<fAnalyzedEvents<<endl;
418 cout<<"Width: "<<delta<<"\t Error: "<<deltaError<<endl;
419 cout<<"New error: "<<deltaErrorNew<<endl;
420 cout<<"Interval: "<<integral<<"\t Error: "<<integralError<<endl;
421 cout<<"=================================================="<<endl;
424 //----------------------------------------//
425 TGraphErrors *AliBalance::DrawBalance()
428 Double_t x[MAXIMUM_NUMBER_OF_STEPS];
429 Double_t xer[MAXIMUM_NUMBER_OF_STEPS];
430 Double_t b[MAXIMUM_NUMBER_OF_STEPS];
431 Double_t ber[MAXIMUM_NUMBER_OF_STEPS];
433 if((fNp == 0)||(fNn == 0))
435 cout<<"Couldn't find any particles in the analyzed interval!!!"<<endl;
436 cout<<"Aborting....."<<endl;
440 for(Int_t i = 0; i < fNumberOfBins; i++)
442 b[i] = GetBalance(i);
443 ber[i] = GetError(i);
444 x[i] = fP2Start + fP2Step*i + fP2Step/2 ;
448 TGraphErrors *gr = new TGraphErrors(fNumberOfBins,x,b,xer,ber) ;
449 gr->SetMarkerStyle(25) ;
450 gr->GetXaxis()->SetTitleColor(1);
453 gr->GetXaxis()->SetTitle("#Delta y");
454 gr->GetYaxis()->SetTitle("B(#Delta y)");
458 gr->GetXaxis()->SetTitle("#Delta #eta");
459 gr->GetYaxis()->SetTitle("B(#Delta #eta)");
463 gr->GetXaxis()->SetTitle("Q_{long} [GeV]");
464 gr->GetYaxis()->SetTitle("B(Q_{long})");
468 gr->GetXaxis()->SetTitle("Q_{out} [GeV]");
469 gr->GetYaxis()->SetTitle("B(Q_{out})");
473 gr->GetXaxis()->SetTitle("Q_{side} [GeV]");
474 gr->GetYaxis()->SetTitle("B(Q_{side})");
478 gr->GetXaxis()->SetTitle("Q_{inv} [GeV]");
479 gr->GetYaxis()->SetTitle("B(Q_{inv})");
483 gr->GetXaxis()->SetTitle("#Delta #phi");
484 gr->GetYaxis()->SetTitle("B(#Delta #phi)");