end-of-line normalization
[u/mrichter/AliRoot.git] / PWGCF / Correlations / DPhi / AliAnalysisTaskContMC.cxx
CommitLineData
7fac8669 1/**************************************************************************
2 * Copyright(c) 1998-2009, 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//-----------------------------------------------------------------
17// AliAnalysisTaskContMC class
18//-----------------------------------------------------------------
19
20#include "TChain.h"
21#include "TTree.h"
22#include "TLegend.h"
23#include "TH1F.h"
24#include "TH2F.h"
25#include "TH3F.h"
26#include "TCanvas.h"
27#include "AliAnalysisTask.h"
28#include "AliAnalysisManager.h"
29#include "AliVTrack.h"
30#include "AliAODMCParticle.h"
31#include "AliVParticle.h"
32#include "AliAODEvent.h"
33#include "AliAODInputHandler.h"
34#include "AliAnalysisTaskContMC.h"
35#include "AliAnalysisTaskESDfilter.h"
36#include "AliAnalysisDataContainer.h"
37#include "AliHelperPID.h"
38#include "AliCentrality.h"
39#include "TProof.h"
40#include "AliPID.h"
41#include "AliVEvent.h"
42#include "AliPIDResponse.h"
43#include "AliStack.h"
44#include <TMCProcess.h>
45
46#include <iostream>
47
48using namespace std;
49
50ClassImp(AliAnalysisTaskContMC)
51
52//________________________________________________________________________
53AliAnalysisTaskContMC::AliAnalysisTaskContMC(const char *name) : AliAnalysisTaskSE(name), fAOD(0), fNSigmaPID(0), fIsMC(0), fOutput(0), fHistID(0)
54{
55 // Default constructor
56
57
58 DefineInput(0, TChain::Class());
59 //DefineOutput(1, AliHelperPID::Class());
60 DefineOutput(1, TList::Class());
61
62}
63//________________________________________________________________________
64//________________________________________________________________________
65void AliAnalysisTaskContMC::UserCreateOutputObjects()
66{
67 Printf("\n\n\n\n\n\n In CreateOutput Object:");
68
69 //create output objects
70 Printf("NSigma: %.1f",fNSigmaPID->GetNSigmaCut());
71 Printf("IsMC: %d",fNSigmaPID->GetisMC());
72 fOutput = new TList();
73 fOutput->SetOwner();
74 fOutput->SetName("list");
75
76 fHistID = new TH3F("fHistID","fHistID",6,-1.5,4.5,4,-1.5,2.5,38,0.2,4);
77 fOutput->Add(fHistID);
78
79 if(!fNSigmaPID)AliFatal("PID object should be set in the steering macro");
80 fOutput->Add(fNSigmaPID);
81
82 //PostData(1, fNSigmaPID );
83 PostData(1, fOutput );
84
85}
86
87//________________________________________________________________________
88void AliAnalysisTaskContMC::UserExec(Option_t *)
89{
90 const Int_t npart=4;
91 const Int_t pdgcode[npart+2]={-1,211,321,2212,11,13};
92 const Int_t partid[npart+2]={-1,0,1,2,3,4};
93 // main event loop
94 fAOD = dynamic_cast<AliAODEvent*>(fInputEvent);
95 if (!fAOD) {
96 AliWarning("ERROR: AliAODEvent not available \n");
97 return;
98 }
99
100 if (strcmp(fAOD->ClassName(), "AliAODEvent"))
101 {
102 AliFatal("Not processing AODs");
103 }
104 //MC Loop
105 TClonesArray *arrayMC = 0;
106 Printf("fIsMC: %d",fIsMC);
107 if (fIsMC)
108 {
109 arrayMC = (TClonesArray*) fAOD->GetList()->FindObject(AliAODMCParticle::StdBranchName());
110 if (!arrayMC) {
111 AliFatal("Error: MC particles branch not found!\n");
112 }
113 }
114 Double_t centrality = 0;
115
116 AliCentrality *centralityObj = fAOD->GetHeader()->GetCentralityP();
117 if (centralityObj)
118 {
119 centrality = centralityObj->GetCentralityPercentileUnchecked("V0M");
120 AliInfo(Form("Centrality is %f", centrality));
121 }
122 else
123 {
124 Printf("WARNING: Centrality object is 0");
125 centrality = -1;
126 }
127 if (centrality < 0)
128 return;
129
130
131 //vertex selection
132 Int_t nVertex = ((AliAODEvent*)fAOD)->GetNumberOfVertices();
133 if( nVertex > 0 ) {
134 AliAODVertex* vertex = (AliAODVertex*)((AliAODEvent*)fAOD)->GetPrimaryVertex();
135 //Int_t nTracksPrim = vertex->GetNContributors();
136 Double_t zVertex = vertex->GetZ();
137 //10 cm cut
138 if(TMath::Abs(zVertex)>10) return;
139 //AliInfo(Form(" Vertex in = %f with %d particles by %s data ...",zVertex,nTracksPrim,vertex->GetName()));
140 // Reject TPC only vertex
141 TString name(vertex->GetName());
142 if (name.CompareTo("PrimaryVertex") && name.CompareTo("SPDVertex"))return;
143 }
144
145 //Int_t count=0;
146 //track loop
147 for (Int_t iTracks = 0; iTracks < fAOD->GetNumberOfTracks(); iTracks++) {
148 AliAODTrack* track = fAOD->GetTrack(iTracks);
149 if(!(track->TestFilterBit(32)))continue;
150 if (TMath::Abs(track->Eta()) > .8 || track->Pt() < .2) continue;
151
152 Int_t pdg=-999;
153 Int_t isph=-999;
154 if (fIsMC && arrayMC) {
155 AliAODMCParticle *partMC = (AliAODMCParticle*) arrayMC->At(TMath::Abs(track->GetLabel()));
156 if (!partMC) {
157 AliError("Cannot get MC particle");
158 continue;
159 }
160 pdg=TMath::Abs(partMC->GetPdgCode());
161 isph=partMC->IsPhysicalPrimary();
162 }
163 if(!isph)continue;
164 //step 1, TOF Matching
165 UInt_t status;
166 status=track->GetStatus();
167 if((status&AliVTrack::kTOFout)==0 || (status&AliVTrack::kTIME)==0)continue;
168
169 //step 2, combined PID
170 Int_t IDTPCTOF=fNSigmaPID->GetParticleSpecies(track,1);
171 if(IDTPCTOF==999)IDTPCTOF=-1;
172 Int_t IDMC=-1;
173 for(Int_t ipart=0;ipart<npart+2;ipart++)if(TMath::Abs(pdg)==pdgcode[ipart])IDMC=partid[ipart];
174 fHistID->Fill(IDMC,IDTPCTOF,track->Pt());
175 } // end loop on tracks
176
177 PostData(1,fOutput);
178
179}
180
181//_________________________________________________________________
182void AliAnalysisTaskContMC::Terminate(Option_t *)
183{
184 // Terminate analysis
185 //
186 fOutput = dynamic_cast<TList*>(GetOutputData(1));
187 if (!fOutput) {
188 printf("ERROR: fOutput not available\n");
189 return;
190 }
191 fHistID = dynamic_cast<TH3F*>(fOutput->FindObject("fHistID"));
192 fNSigmaPID = dynamic_cast<AliHelperPID*>(fOutput->FindObject("fNSigmaPID"));
193}