spring cleaning, split flow lib into two
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowCommon / AliFlowEventSimple.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 #include "Riostream.h"
17 #include "TObjArray.h"
18 #include "TFile.h"
19 #include "TList.h"
20 #include "TMath.h"
21 #include "TH1F.h"
22 #include "TH1D.h"
23 #include "TProfile.h"
24 #include "AliFlowVector.h"
25 #include "AliFlowTrackSimple.h"
26 #include "AliFlowEventSimple.h"
27
28 /**************************************
29  * AliFlowEventSimple: A simple event *
30  *  for flow analysis                 * 
31  *                                    * 
32  * authors: Naomi van der Kolk        *
33  *           (kolk@nikhef.nl)         *  
34  *          Ante Bilandzic            *
35  *           (anteb@nikhef.nl)        * 
36  * ***********************************/
37  
38 ClassImp(AliFlowEventSimple)
39
40 //-----------------------------------------------------------------------
41
42   AliFlowEventSimple::AliFlowEventSimple(Int_t aLenght):
43     fTrackCollection(NULL),
44     fNumberOfTracks(0),
45     fEventNSelTracksIntFlow(0)
46 {
47   //constructor 
48   fTrackCollection =  new TObjArray(aLenght) ;
49 }
50
51 //-----------------------------------------------------------------------
52
53 AliFlowEventSimple::AliFlowEventSimple(const AliFlowEventSimple& anEvent):
54   TObject(),
55   fTrackCollection(anEvent.fTrackCollection),
56   fNumberOfTracks(anEvent.fNumberOfTracks),
57   fEventNSelTracksIntFlow(anEvent.fEventNSelTracksIntFlow)
58 {
59   //copy constructor 
60 }
61
62 //-----------------------------------------------------------------------
63
64 AliFlowEventSimple& AliFlowEventSimple::operator=(const AliFlowEventSimple& anEvent)
65 {
66   *fTrackCollection = *anEvent.fTrackCollection ;
67   fNumberOfTracks = anEvent.fNumberOfTracks;
68   fEventNSelTracksIntFlow = anEvent.fEventNSelTracksIntFlow;
69   
70   return *this;
71 }
72
73 //----------------------------------------------------------------------- 
74
75 AliFlowEventSimple::~AliFlowEventSimple()
76 {
77   //destructor
78   fTrackCollection->Delete() ; delete fTrackCollection ;
79 }
80
81 //----------------------------------------------------------------------- 
82
83 AliFlowTrackSimple* AliFlowEventSimple::GetTrack(Int_t i)
84 {
85   //get track i from collection
86   AliFlowTrackSimple* pTrack = (AliFlowTrackSimple*)TrackCollection()->At(i) ;
87   return pTrack;
88 }
89
90 //-----------------------------------------------------------------------   
91 AliFlowVector AliFlowEventSimple::GetQ(Int_t n, TList *weightsList, Bool_t usePhiWeights, Bool_t usePtWeights, Bool_t useEtaWeights) 
92 {
93   //calculate Q-vector in harmonic n without weights (default harmonic n=2)  
94   Double_t dQX = 0.;
95   Double_t dQY = 0.;
96   AliFlowVector vQ;
97   vQ.Set(0.,0.);
98   
99   Int_t iOrder = n;
100   Int_t iUsedTracks = 0;
101   Double_t dPhi=0.;
102   Double_t dPt=0;
103   Double_t dEta=0;
104   
105   AliFlowTrackSimple* pTrack = NULL;
106  
107   Int_t nBinsPhi=0; 
108   Double_t dBinWidthPt=0.;
109   Double_t dNormPt=0.;
110   Double_t dBinWidthEta=0.;
111   Double_t dNormEta=0.;
112  
113   Double_t wPhi=1.; //weight Phi  
114   Double_t wPt=1.;  //weight Pt 
115   Double_t wEta=1.; //weight Eta 
116   
117   TH1F *phiWeights = NULL;
118   TH1D *ptWeights = NULL;
119   TH1D *etaWeights = NULL;
120
121   if(weightsList)
122   {
123    if(usePhiWeights)
124    {
125     phiWeights = dynamic_cast<TH1F *>(weightsList->FindObject("phi_weights"));
126     if(phiWeights) nBinsPhi = phiWeights->GetNbinsX();
127    }          
128    if(usePtWeights)
129    {
130     ptWeights = dynamic_cast<TH1D *>(weightsList->FindObject("pt_weights"));
131     if(ptWeights)
132     {
133      dBinWidthPt = ptWeights->GetBinWidth(1); // assuming that all bins have the same width
134      dNormPt = ptWeights->Integral();
135     } 
136    }       
137    if(useEtaWeights)
138    {
139     etaWeights = dynamic_cast<TH1D *>(weightsList->FindObject("eta_weights"));
140     if(etaWeights)
141     {
142      dBinWidthEta = etaWeights->GetBinWidth(1); // assuming that all bins have the same width
143      dNormEta = etaWeights->Integral();
144     } 
145    }          
146   } // end of if(weightsList)
147
148   
149   // loop over tracks    
150   for(Int_t i=0;i<fNumberOfTracks;i++)                               
151   {
152    pTrack = (AliFlowTrackSimple*)TrackCollection()->At(i); 
153    if(pTrack)
154    {
155     if(pTrack->UseForIntegratedFlow()) 
156     {
157      dPhi = pTrack->Phi();
158      dPt  = pTrack->Pt();
159      dEta = pTrack->Eta();
160     
161      //determine Phi weight: (to be improved, I should here only access it + the treatment of gaps in the if statement)
162      if(phiWeights && (nBinsPhi!=0) && (phiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*nBinsPhi/TMath::TwoPi())))!=0))
163      {
164       wPhi=pow(nBinsPhi*phiWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPhi*nBinsPhi/TMath::TwoPi()))),-1);
165      }
166      //determine v'(pt) weight:    
167      if(ptWeights && dBinWidthPt && dNormPt)
168      {
169       wPt=ptWeights->GetBinContent(1+(Int_t)(TMath::Floor(dPt/dBinWidthPt)))/dNormPt; 
170      }            
171      //determine v'(eta) weight:    
172      if(etaWeights && dBinWidthEta && dNormEta)
173      {
174       wEta=etaWeights->GetBinContent(1+(Int_t)(TMath::Floor(dEta/dBinWidthEta)))/dNormEta; 
175      } 
176    
177      //building up the weighted Q-vector:       
178      dQX += wPhi*wPt*wEta*TMath::Cos(iOrder*dPhi);
179      dQY += wPhi*wPt*wEta*TMath::Sin(iOrder*dPhi); 
180      iUsedTracks++;
181      
182     }//end of if (pTrack->UseForIntegratedFlow())
183    }//end of if (pTrack)
184    else {cerr << "no particle!!!"<<endl;}
185   }//loop over particles
186     
187   vQ.Set(dQX,dQY);
188   vQ.SetMult(iUsedTracks);
189
190   return vQ;
191   
192 }
193
194
195
196
197
198
199
200
201
202