32dcb3a4d9132d743004e3df6c37557cd42102bb
[u/mrichter/AliRoot.git] / PWG2 / FLOW / AliFlowAnalysisWithScalarProduct.cxx
1 /*************************************************************************
2 * Copyright(c) 1998-2008, 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 #define AliFlowAnalysisWithScalarProduct_cxx
17  
18 #include "Riostream.h"  //needed as include
19 #include "TFile.h"      //needed as include
20 #include "TList.h"
21 #include "TMath.h"
22 #include "TProfile.h"
23 #include "TVector2.h"
24
25 class TH1F;
26
27 #include "AliFlowCommonConstants.h"    //needed as include
28 #include "AliFlowEventSimple.h"
29 #include "AliFlowTrackSimple.h"
30 #include "AliFlowCommonHist.h"
31 //#include "AliFlowCommonHistResults.h"
32 #include "AliFlowAnalysisWithScalarProduct.h"
33
34 class AliFlowVector;
35
36 // AliFlowAnalysisWithScalarProduct:
37 // Description: 
38 // Maker to analyze Flow with the Scalar product method.
39 //
40 // author: N. van der Kolk (kolk@nikhef.nl)
41
42 ClassImp(AliFlowAnalysisWithScalarProduct)
43
44   //-----------------------------------------------------------------------
45  
46  AliFlowAnalysisWithScalarProduct::AliFlowAnalysisWithScalarProduct():
47   fQ(NULL),
48   fU(NULL),
49   fEventNumber(0),
50   fDebug(kFALSE),
51   fHistList(NULL),
52   fHistProUQ(NULL),
53   fCommonHists(NULL)
54 {
55   // Constructor.
56   fU = new TVector2;
57   fQ = new AliFlowVector;
58   fHistList = new TList(); 
59   //  fQ.Set(0.,0.);           // flow vector
60   //  fU.Set(0.,0.);           // particle unit vector
61 }
62  //-----------------------------------------------------------------------
63
64
65  AliFlowAnalysisWithScalarProduct::~AliFlowAnalysisWithScalarProduct() 
66  {
67    delete fU;
68    delete fQ;
69    delete fHistList;
70    //destructor
71    
72  }
73  
74
75 //-----------------------------------------------------------------------
76 void AliFlowAnalysisWithScalarProduct::Init() {
77
78   //Define all histograms
79   cout<<"---Analysis with the Scalar Product Method--- Init"<<endl;
80
81   Int_t fNbinsPt = AliFlowCommonConstants::GetNbinsPt();
82   Double_t  fPtMin = AliFlowCommonConstants::GetPtMin();             
83   Double_t  fPtMax = AliFlowCommonConstants::GetPtMax();
84
85   // analysis file (output)
86
87   fHistProUQ = new TProfile("Flow_UQ_SP","Flow_UQ_SP",fNbinsPt,fPtMin,fPtMax);
88   fHistProUQ->SetXTitle("p_t (GeV)");
89   fHistProUQ->SetYTitle("<uQ>");
90   fHistList->Add(fHistProUQ);
91
92   fCommonHists = new AliFlowCommonHist("SP");
93   //fCommonHistsRes = new AliFlowCommonHistResults("SP");
94   fHistList->Add(fCommonHists); 
95
96   fEventNumber = 0;  //set number of events to zero
97       
98
99  
100 //-----------------------------------------------------------------------
101  
102 void AliFlowAnalysisWithScalarProduct::Make(AliFlowEventSimple* anEvent) {
103
104   //Fill histogram
105   if (anEvent) {
106
107     //fill control histograms     
108     fCommonHists->FillControlHistograms(anEvent);
109          
110     //get the Q vector from the FlowEvent
111     *fQ = anEvent->GetQ();
112     //Double_t fMult =  fQ.GetMult();
113             
114     //loop over the tracks of the event
115     AliFlowTrackSimple*   fTrack = NULL; 
116     Int_t fNumberOfTracks = anEvent->NumberOfTracks(); 
117     for (Int_t i=0;i<fNumberOfTracks;i++) 
118       {
119
120         fTrack = anEvent->GetTrack(i) ; 
121         if (fTrack){
122           if (fTrack->UseForDifferentialFlow()) {
123           Double_t fPhi = fTrack->Phi();
124
125           //calculate fU
126           Double_t fUX = TMath::Cos(2*fPhi);
127           Double_t fUY = TMath::Sin(2*fPhi);
128           //      fU.Set(fUX,fUY);
129           fU->Set(fUX,fUY);
130           //      Double_t fModulus = fU.Mod();
131           Double_t fModulus = fU->Mod();
132           //      if (fModulus!=0.) fU.Set(fUX/fModulus,fUY/fModulus);  // make length 1
133           if (fModulus!=0.) fU->Set(fUX/fModulus,fUY/fModulus);  // make length 1
134           else cerr<<"fModulus is zero!"<<endl;
135
136           TVector2 fQm = *fQ;
137           //subtrackt particle from the flowvector if used to define it
138           if (fTrack->UseForIntegratedFlow()) {
139             Double_t fQmX = fQm.X() - fUX;
140             Double_t fQmY = fQm.Y() - fUY;
141             fQm.Set(fQmX,fQmY);
142           }
143
144           //Double_t fUQ = scalar product of fU and fQm
145           //      Double_t fUQ = fU*fQm;
146           Double_t fUQ = *fU * fQm;
147           Double_t fPt = fTrack->Pt();
148           //fill the profile histogram
149           fHistProUQ->Fill(fPt,fUQ); 
150           }  
151         }//track selected
152       }//loop over tracks
153          
154     fEventNumber++;
155     cout<<"@@@@@ "<<fEventNumber<<" events processed"<<endl;
156   }
157 }
158
159   //--------------------------------------------------------------------    
160 void AliFlowAnalysisWithScalarProduct::Finish() {
161    
162   //*************make histograms etc. 
163   if (fDebug) cout<<"AliFlowAnalysisWithScalarProduct::Terminate()"<<endl;
164
165   fHistProUQ->Draw();
166
167   // write to file
168 //  fHistFile->Write();
169           
170   cout<<".....finished"<<endl;
171  }
172
173