1 /*************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 // AliFlowAnalysisWithMCEventPlane:
16 // Description: Maker to analyze Flow from the generated MC reaction plane.
17 // This class is used to get the real value of the flow
18 // to compare the other methods to when analysing simulated events
19 // author: N. van der Kolk (kolk@nikhef.nl)
21 #define AliFlowAnalysisWithMCEventPlane_cxx
23 #include "Riostream.h"
26 #include "TProfile2D.h"
31 #include "AliFlowCommonConstants.h"
32 #include "AliFlowEventSimple.h"
33 #include "AliFlowTrackSimple.h"
34 #include "AliFlowCommonHist.h"
35 #include "AliFlowCommonHistResults.h"
36 #include "AliFlowAnalysisWithMCEventPlane.h"
40 ClassImp(AliFlowAnalysisWithMCEventPlane)
42 //-----------------------------------------------------------------------
44 AliFlowAnalysisWithMCEventPlane::AliFlowAnalysisWithMCEventPlane():
51 fCommonHistsRes(NULL),
53 fHistProIntFlow(NULL),
54 fHistProDiffFlowPtEtaRP(NULL),
55 fHistProDiffFlowPtRP(NULL),
56 fHistProDiffFlowEtaRP(NULL),
57 fHistProDiffFlowPtEtaPOI(NULL),
58 fHistProDiffFlowPtPOI(NULL),
59 fHistProDiffFlowEtaPOI(NULL),
60 fHistSpreadOfFlow(NULL),
65 fHistList = new TList();
67 fQsum = new TVector2; // flow vector sum
71 //-----------------------------------------------------------------------
74 AliFlowAnalysisWithMCEventPlane::~AliFlowAnalysisWithMCEventPlane()
81 //-----------------------------------------------------------------------
83 void AliFlowAnalysisWithMCEventPlane::WriteHistograms(TString* outputFileName)
85 //store the final results in output .root file
86 TFile *output = new TFile(outputFileName->Data(),"RECREATE");
87 //output->WriteObject(fHistList, "cobjMCEP","SingleKey");
88 fHistList->SetName("cobjMCEP");
89 fHistList->SetOwner(kTRUE);
90 fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
94 //-----------------------------------------------------------------------
96 void AliFlowAnalysisWithMCEventPlane::WriteHistograms(TString outputFileName)
98 //store the final results in output .root file
99 TFile *output = new TFile(outputFileName.Data(),"RECREATE");
100 //output->WriteObject(fHistList, "cobjMCEP","SingleKey");
101 fHistList->SetName("cobjMCEP");
102 fHistList->SetOwner(kTRUE);
103 fHistList->Write(fHistList->GetName(), TObject::kSingleKey);
107 //-----------------------------------------------------------------------
109 void AliFlowAnalysisWithMCEventPlane::WriteHistograms(TDirectoryFile *outputFileName)
111 //store the final results in output .root file
112 fHistList->SetName("cobjMCEP");
113 fHistList->SetOwner(kTRUE);
114 outputFileName->Add(fHistList);
115 outputFileName->Write(outputFileName->GetName(), TObject::kSingleKey);
118 //-----------------------------------------------------------------------
119 void AliFlowAnalysisWithMCEventPlane::Init() {
121 //Define all histograms
122 cout<<"---Analysis with the real MC Event Plane---"<<endl;
124 //save old value and prevent histograms from being added to directory
125 //to avoid name clashes in case multiple analaysis objects are used
127 Bool_t oldHistAddStatus = TH1::AddDirectoryStatus();
128 TH1::AddDirectory(kFALSE);
130 Int_t iNbinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
131 Double_t dPtMin = AliFlowCommonConstants::GetMaster()->GetPtMin();
132 Double_t dPtMax = AliFlowCommonConstants::GetMaster()->GetPtMax();
134 Int_t iNbinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
135 Double_t dEtaMin = AliFlowCommonConstants::GetMaster()->GetEtaMin();
136 Double_t dEtaMax = AliFlowCommonConstants::GetMaster()->GetEtaMax();
138 fCommonHists = new AliFlowCommonHist("AliFlowCommonHistMCEP");
139 fHistList->Add(fCommonHists);
140 fCommonHistsRes = new AliFlowCommonHistResults("AliFlowCommonHistResultsMCEP");
141 fHistList->Add(fCommonHistsRes);
143 // store harmonic in common control histogram:
144 (fCommonHists->GetHarmonic())->Fill(0.5,fHarmonic);
146 fHistRP = new TH1F("Flow_RP_MCEP","Flow_RP_MCEP",100,0.,3.14);
147 fHistRP->SetXTitle("Reaction Plane Angle");
148 fHistRP->SetYTitle("Counts");
149 fHistList->Add(fHistRP);
151 fHistProIntFlow = new TProfile("FlowPro_V_MCEP","FlowPro_V_MCEP",1,0.,1.);
152 fHistProIntFlow->SetLabelSize(0.06);
153 (fHistProIntFlow->GetXaxis())->SetBinLabel(1,"v_{n}{2}");
154 fHistProIntFlow->SetYTitle("");
155 fHistList->Add(fHistProIntFlow);
157 fHistProDiffFlowPtEtaRP = new TProfile2D("FlowPro_VPtEtaRP_MCEP","FlowPro_VPtEtaRP_MCEP",iNbinsPt,dPtMin,dPtMax,iNbinsEta,dEtaMin,dEtaMax);
158 fHistProDiffFlowPtEtaRP->SetXTitle("P_{t}");
159 fHistProDiffFlowPtEtaRP->SetYTitle("#eta");
160 fHistList->Add(fHistProDiffFlowPtEtaRP);
162 fHistProDiffFlowPtRP = new TProfile("FlowPro_VPtRP_MCEP","FlowPro_VPtRP_MCEP",iNbinsPt,dPtMin,dPtMax);
163 fHistProDiffFlowPtRP->SetXTitle("P_{t}");
164 fHistProDiffFlowPtRP->SetYTitle("");
165 fHistList->Add(fHistProDiffFlowPtRP);
167 fHistProDiffFlowEtaRP = new TProfile("FlowPro_VetaRP_MCEP","FlowPro_VetaRP_MCEP",iNbinsEta,dEtaMin,dEtaMax);
168 fHistProDiffFlowEtaRP->SetXTitle("#eta");
169 fHistProDiffFlowEtaRP->SetYTitle("");
170 fHistList->Add(fHistProDiffFlowEtaRP);
172 fHistProDiffFlowPtEtaPOI = new TProfile2D("FlowPro_VPtEtaPOI_MCEP","FlowPro_VPtEtaPOI_MCEP",iNbinsPt,dPtMin,dPtMax,iNbinsEta,dEtaMin,dEtaMax);
173 fHistProDiffFlowPtEtaPOI->SetXTitle("P_{t}");
174 fHistProDiffFlowPtEtaPOI->SetYTitle("#eta");
175 fHistList->Add(fHistProDiffFlowPtEtaPOI);
177 fHistProDiffFlowPtPOI = new TProfile("FlowPro_VPtPOI_MCEP","FlowPro_VPtPOI_MCEP",iNbinsPt,dPtMin,dPtMax);
178 fHistProDiffFlowPtPOI->SetXTitle("P_{t}");
179 fHistProDiffFlowPtPOI->SetYTitle("");
180 fHistList->Add(fHistProDiffFlowPtPOI);
182 fHistProDiffFlowEtaPOI = new TProfile("FlowPro_VetaPOI_MCEP","FlowPro_VetaPOI_MCEP",iNbinsEta,dEtaMin,dEtaMax);
183 fHistProDiffFlowEtaPOI->SetXTitle("#eta");
184 fHistProDiffFlowEtaPOI->SetYTitle("");
185 fHistList->Add(fHistProDiffFlowEtaPOI);
187 fHistSpreadOfFlow = new TH1D("fHistSpreadOfFlow","fHistSpreadOfFlow",1000,-1,1);
188 fHistSpreadOfFlow->SetXTitle("v_{2}");
189 fHistSpreadOfFlow->SetYTitle("counts");
190 fHistList->Add(fHistSpreadOfFlow);
192 fEventNumber = 0; //set number of events to zero
194 TH1::AddDirectory(oldHistAddStatus);
197 //-----------------------------------------------------------------------
199 void AliFlowAnalysisWithMCEventPlane::Make(AliFlowEventSimple* anEvent) {
201 //Calculate v2 from the MC reaction plane
204 // get the MC reaction plane angle
205 Double_t aRP = anEvent->GetMCReactionPlaneAngle();
206 //fill control histograms
207 fCommonHists->FillControlHistograms(anEvent);
209 //get the Q vector from the FlowEvent
210 AliFlowVector vQ = anEvent->GetQ(fHarmonic);
211 //cout<<"vQ.Mod() = " << vQ.Mod() << endl;
212 //for chi calculation:
214 //cout<<"fQsum.Mod() = "<<fQsum.Mod()<<endl;
216 //cout<<"fQ2sum = "<<fQ2sum<<endl;
224 //Double_t dPi = TMath::Pi();
226 // profile to calculate flow e-b-y:
227 TProfile *flowEBE = new TProfile("flowEBE","flowEBE",1,0,1);
230 //loop over the tracks of the event
231 Int_t iNumberOfTracks = anEvent->NumberOfTracks();
232 for (Int_t i=0;i<iNumberOfTracks;i++)
234 AliFlowTrackSimple* pTrack = anEvent->GetTrack(i) ;
236 if (pTrack->InRPSelection()){
237 dPhi = pTrack->Phi();
238 dv = TMath::Cos(fHarmonic*(dPhi-aRP));
240 dEta = pTrack->Eta();
241 //no-name int. flow (to be improved = name needed!):
242 fHistProIntFlow->Fill(0.,dv);
243 //no-name int. flow e-b-e (to be improved = name needed!):
244 flowEBE->Fill(0.,dv);
245 //differential flow (Pt, Eta, RP):
246 fHistProDiffFlowPtEtaRP->Fill(dPt,dEta,dv,1.);
247 //differential flow (Pt, RP):
248 fHistProDiffFlowPtRP->Fill(dPt,dv,1.);
249 //differential flow (Eta, RP):
250 fHistProDiffFlowEtaRP->Fill(dEta,dv,1.);
252 if (pTrack->InPOISelection()) {
253 dPhi = pTrack->Phi();
254 //if (dPhi<0.) dPhi+=2*TMath::Pi();
256 dv = TMath::Cos(fHarmonic*(dPhi-aRP));
258 dEta = pTrack->Eta();
259 //differential flow (Pt, Eta, POI):
260 fHistProDiffFlowPtEtaPOI->Fill(dPt,dEta,dv,1.);
261 //differential flow (Pt, POI):
262 fHistProDiffFlowPtPOI->Fill(dPt,dv,1.);
263 //differential flow (Eta, POI):
264 fHistProDiffFlowEtaPOI->Fill(dEta,dv,1.);
270 // cout<<"@@@@@ "<<fEventNumber<<" events processed"<<endl;
272 // store flow value for this event:
273 fHistSpreadOfFlow->Fill(flowEBE->GetBinContent(1),flowEBE->GetBinEntries(1));
277 //--------------------------------------------------------------------
279 void AliFlowAnalysisWithMCEventPlane::GetOutputHistograms(TList *outputListHistos) {
280 // get the pointers to all output histograms before calling Finish()
281 if (outputListHistos) {
282 //Get the common histograms from the output list
283 AliFlowCommonHist *pCommonHists = dynamic_cast<AliFlowCommonHist*>
284 (outputListHistos->FindObject("AliFlowCommonHistMCEP"));
285 AliFlowCommonHistResults *pCommonHistResults =
286 dynamic_cast<AliFlowCommonHistResults*>
287 (outputListHistos->FindObject("AliFlowCommonHistResultsMCEP"));
289 TProfile *pHistProIntFlow = dynamic_cast<TProfile*>
290 (outputListHistos->FindObject("FlowPro_V_MCEP"));
292 TProfile2D *pHistProDiffFlowPtEtaRP = dynamic_cast<TProfile2D*>
293 (outputListHistos->FindObject("FlowPro_VPtEtaRP_MCEP"));
295 TProfile *pHistProDiffFlowPtRP = dynamic_cast<TProfile*>
296 (outputListHistos->FindObject("FlowPro_VPtRP_MCEP"));
298 TProfile *pHistProDiffFlowEtaRP = dynamic_cast<TProfile*>
299 (outputListHistos->FindObject("FlowPro_VetaRP_MCEP"));
301 TProfile2D *pHistProDiffFlowPtEtaPOI = dynamic_cast<TProfile2D*>
302 (outputListHistos->FindObject("FlowPro_VPtEtaPOI_MCEP"));
304 TProfile *pHistProDiffFlowPtPOI = dynamic_cast<TProfile*>
305 (outputListHistos->FindObject("FlowPro_VPtPOI_MCEP"));
307 TProfile *pHistProDiffFlowEtaPOI = dynamic_cast<TProfile*>
308 (outputListHistos->FindObject("FlowPro_VetaPOI_MCEP"));
310 if (pCommonHists && pCommonHistResults && pHistProIntFlow &&
311 pHistProDiffFlowPtRP && pHistProDiffFlowEtaRP &&
312 pHistProDiffFlowPtPOI && pHistProDiffFlowEtaPOI) {
313 this->SetCommonHists(pCommonHists);
314 this->SetCommonHistsRes(pCommonHistResults);
315 this->SetHistProIntFlow(pHistProIntFlow);
316 this->SetHistProDiffFlowPtEtaRP(pHistProDiffFlowPtEtaRP);
317 this->SetHistProDiffFlowPtRP(pHistProDiffFlowPtRP);
318 this->SetHistProDiffFlowEtaRP(pHistProDiffFlowEtaRP);
319 this->SetHistProDiffFlowPtEtaPOI(pHistProDiffFlowPtEtaPOI);
320 this->SetHistProDiffFlowPtPOI(pHistProDiffFlowPtPOI);
321 this->SetHistProDiffFlowEtaPOI(pHistProDiffFlowEtaPOI);
323 cout<<"WARNING: Histograms needed to run Finish() are not accessible!"<<endl; }
325 //fListHistos->Print();
326 } else { cout << "histogram list pointer is empty" << endl;}
330 //--------------------------------------------------------------------
331 void AliFlowAnalysisWithMCEventPlane::Finish() {
333 //*************make histograms etc.
334 if (fDebug) cout<<"AliFlowAnalysisWithMCEventPlane::Terminate()"<<endl;
336 Int_t iNbinsPt = AliFlowCommonConstants::GetMaster()->GetNbinsPt();
337 Int_t iNbinsEta = AliFlowCommonConstants::GetMaster()->GetNbinsEta();
340 if(fCommonHists && fCommonHists->GetHarmonic())
342 fHarmonic = (Int_t)(fCommonHists->GetHarmonic())->GetBinContent(1); // to be improved (moved somewhere else?)
345 // no-name int. flow (to be improved):
346 Double_t dV = fHistProIntFlow->GetBinContent(1);
347 Double_t dErrV = fHistProIntFlow->GetBinError(1); // to be improved (treatment of errors for non-Gaussian distribution needed!)
348 // fill no-name int. flow (to be improved):
349 fCommonHistsRes->FillIntegratedFlow(dV,dErrV);
350 cout<<"dV"<<fHarmonic<<"{MC} is "<<dV<<" +- "<<dErrV<<endl;
353 TH1F* fHistPtRP = fCommonHists->GetHistPtRP();
354 Double_t dYieldPtRP = 0.;
356 Double_t dErrVRP = 0.;
357 Double_t dSumRP = 0.;
358 //differential flow (RP, Pt):
359 Double_t dvPtRP = 0.;
360 Double_t dErrvPtRP = 0.;
361 for(Int_t b=1;b<=iNbinsPt;b++)
363 dvPtRP = fHistProDiffFlowPtRP->GetBinContent(b);
364 dErrvPtRP = fHistProDiffFlowPtRP->GetBinError(b);//to be improved (treatment of errors for non-Gaussian distribution needed!)
365 fCommonHistsRes->FillDifferentialFlowPtRP(b, dvPtRP, dErrvPtRP);
367 //integrated flow (RP)
368 dYieldPtRP = fHistPtRP->GetBinContent(b);
369 dVRP += dvPtRP*dYieldPtRP;
370 dSumRP += dYieldPtRP;
371 //error on integrated flow
372 dErrVRP += dYieldPtRP*dYieldPtRP*dErrvPtRP*dErrvPtRP;
375 if (TMath::AreEqualAbs(dSumRP, 0.0, 1e-10) ) {
376 dVRP /= dSumRP; //because pt distribution should be normalised
377 dErrVRP /= (dSumRP*dSumRP);
378 dErrVRP = TMath::Sqrt(dErrVRP);
380 // fill integrated flow (RP):
381 fCommonHistsRes->FillIntegratedFlowRP(dVRP,dErrVRP);
382 cout<<"dV"<<fHarmonic<<"{MC} (RP) is "<<dVRP<<" +- "<<dErrVRP<<endl;
384 //differential flow (RP, Eta):
385 Double_t dvEtaRP = 0.;
386 Double_t dErrvEtaRP = 0.;
387 for(Int_t b=1;b<=iNbinsEta;b++)
389 dvEtaRP = fHistProDiffFlowEtaRP->GetBinContent(b);
390 dErrvEtaRP = fHistProDiffFlowEtaRP->GetBinError(b);//to be improved (treatment of errors for non-Gaussian distribution needed!)
391 fCommonHistsRes->FillDifferentialFlowEtaRP(b, dvEtaRP, dErrvEtaRP);
395 TH1F* fHistPtPOI = fCommonHists->GetHistPtPOI();
396 Double_t dYieldPtPOI = 0.;
398 Double_t dErrVPOI = 0.;
399 Double_t dSumPOI = 0.;
400 Double_t dvproPtPOI = 0.;
401 Double_t dErrdifcombPtPOI = 0.;
402 Double_t dvproEtaPOI = 0.;
403 Double_t dErrdifcombEtaPOI = 0.;
405 if(fHistProDiffFlowPtPOI) {
406 for(Int_t b=1;b<=iNbinsPt;b++){
407 dvproPtPOI = fHistProDiffFlowPtPOI->GetBinContent(b);
408 dErrdifcombPtPOI = fHistProDiffFlowPtPOI->GetBinError(b);//to be improved (treatment of errors for non-Gaussian distribution needed!)
410 fCommonHistsRes->FillDifferentialFlowPtPOI(b, dvproPtPOI, dErrdifcombPtPOI);
412 //integrated flow (POI)
413 dYieldPtPOI = fHistPtPOI->GetBinContent(b);
414 dVPOI += dvproPtPOI*dYieldPtPOI;
415 dSumPOI += dYieldPtPOI;
416 //error on integrated flow
417 dErrVPOI += dYieldPtPOI*dYieldPtPOI*dErrdifcombPtPOI*dErrdifcombPtPOI;
419 }//end of for(Int_t b=0;b<iNbinsPt;b++)
420 } else { cout<<"fHistProFlow is NULL"<<endl; }
421 if ( TMath::AreEqualAbs(dSumPOI, 0.0, 1e-10) ) {
422 dVPOI /= dSumPOI; //because pt distribution should be normalised
423 dErrVPOI /= (dSumPOI*dSumPOI);
424 dErrVPOI = TMath::Sqrt(dErrVPOI);
426 cout<<"dV"<<fHarmonic<<"{MC} (POI) is "<<dVPOI<<" +- "<<dErrVPOI<<endl;
428 fCommonHistsRes->FillIntegratedFlowPOI(dVPOI,dErrVPOI);
431 if(fHistProDiffFlowEtaPOI)
433 for(Int_t b=1;b<=iNbinsEta;b++)
435 dvproEtaPOI = fHistProDiffFlowEtaPOI->GetBinContent(b);
436 dErrdifcombEtaPOI = fHistProDiffFlowEtaPOI->GetBinError(b);//to be improved (treatment of errors for non-Gaussian distribution needed!)
437 //fill common hist results:
438 fCommonHistsRes->FillDifferentialFlowEtaPOI(b, dvproEtaPOI, dErrdifcombEtaPOI);
443 //cout<<".....finished"<<endl;