]>
Commit | Line | Data |
---|---|---|
5c33329d | 1 | #include "TChain.h" |
2cd42194 | 2 | #include "TList.h" |
5c33329d | 3 | #include "TCanvas.h" |
4 | #include "TLorentzVector.h" | |
5 | #include "TGraphErrors.h" | |
2cd42194 | 6 | #include "TH1F.h" |
5c33329d | 7 | |
2cd42194 | 8 | #include "AliAnalysisTaskSE.h" |
5c33329d | 9 | #include "AliAnalysisManager.h" |
10 | ||
2cd42194 | 11 | #include "AliESDVertex.h" |
5c33329d | 12 | #include "AliESDEvent.h" |
13 | #include "AliESDInputHandler.h" | |
cd54a838 | 14 | #include "AliAODEvent.h" |
6c60d885 | 15 | #include "AliAODTrack.h" |
cd54a838 | 16 | #include "AliAODInputHandler.h" |
17 | #include "AliMCEventHandler.h" | |
18 | #include "AliMCEvent.h" | |
19 | #include "AliStack.h" | |
5115b492 | 20 | #include "AliESDtrackCuts.h" |
5c33329d | 21 | |
22 | #include "AliBalance.h" | |
23 | ||
24 | #include "AliAnalysisTaskBF.h" | |
25 | ||
26 | // Analysis task for the BF code | |
27 | // Authors: Panos Cristakoglou@cern.ch | |
28 | ||
29 | ClassImp(AliAnalysisTaskBF) | |
30 | ||
31 | //________________________________________________________________________ | |
32 | AliAnalysisTaskBF::AliAnalysisTaskBF(const char *name) | |
09bb7bf4 | 33 | : AliAnalysisTaskSE(name), |
34 | fBalance(0), | |
35 | fList(0), | |
36 | fHistEventStats(0), | |
37 | fHistVx(0), | |
38 | fHistVy(0), | |
39 | fHistVz(0), | |
40 | fESDtrackCuts(0), | |
41 | fUseOfflineTrigger(kFALSE), | |
42 | fVxMax(0.3), | |
43 | fVyMax(0.3), | |
44 | fVzMax(10.) { | |
5c33329d | 45 | // Constructor |
46 | ||
47 | // Define input and output slots here | |
48 | // Input slot #0 works with a TChain | |
49 | DefineInput(0, TChain::Class()); | |
50 | // Output slot #0 writes into a TH1 container | |
2cd42194 | 51 | DefineOutput(1, AliBalance::Class()); |
52 | DefineOutput(2, TList::Class()); | |
5c33329d | 53 | } |
54 | ||
55 | //________________________________________________________________________ | |
2cd42194 | 56 | void AliAnalysisTaskBF::UserCreateOutputObjects() { |
57 | // Create histograms | |
5c33329d | 58 | // Called once |
2cd42194 | 59 | if(!fBalance) { |
60 | fBalance = new AliBalance(); | |
61 | fBalance->SetAnalysisLevel("ESD"); | |
62 | fBalance->SetAnalysisType(1); | |
63 | fBalance->SetNumberOfBins(18); | |
64 | fBalance->SetInterval(-0.9,0.9); | |
5c33329d | 65 | } |
5c33329d | 66 | |
09bb7bf4 | 67 | //QA list |
2cd42194 | 68 | fList = new TList(); |
69 | fList->SetName("listQA"); | |
70 | ||
09bb7bf4 | 71 | //Event stats. |
2cd42194 | 72 | TString gCutName[4] = {"Total","Offline trigger", |
73 | "Vertex","Analyzed"}; | |
74 | fHistEventStats = new TH1F("fHistEventStats", | |
75 | "Event statistics;;N_{events}", | |
76 | 4,0.5,4.5); | |
77 | for(Int_t i = 1; i <= 4; i++) | |
78 | fHistEventStats->GetXaxis()->SetBinLabel(i,gCutName[i-1].Data()); | |
79 | fList->Add(fHistEventStats); | |
80 | ||
09bb7bf4 | 81 | //Vertex distributions |
82 | fHistVx = new TH1F("fHistVx","Primary vertex distribution - x coordinate;V_{x} (cm);Entries",100,-0.5,0.5); | |
83 | fList->Add(fHistVx); | |
84 | fHistVy = new TH1F("fHistVy","Primary vertex distribution - y coordinate;V_{y} (cm);Entries",100,-0.5,0.5); | |
85 | fList->Add(fHistVy); | |
86 | fHistVz = new TH1F("fHistVz","Primary vertex distribution - z coordinate;V_{z} (cm);Entries",100,-20.,20.); | |
87 | fList->Add(fHistVz); | |
88 | ||
5115b492 | 89 | if(fESDtrackCuts) fList->Add(fESDtrackCuts); |
90 | ||
2cd42194 | 91 | // Post output data. |
92 | PostData(1, fBalance); | |
93 | PostData(2, fList); | |
5c33329d | 94 | } |
95 | ||
96 | //________________________________________________________________________ | |
2cd42194 | 97 | void AliAnalysisTaskBF::UserExec(Option_t *) { |
5c33329d | 98 | // Main loop |
99 | // Called for each event | |
cd54a838 | 100 | TString gAnalysisLevel = fBalance->GetAnalysisLevel(); |
5c33329d | 101 | |
102 | TObjArray *array = new TObjArray(); | |
cd54a838 | 103 | |
104 | //ESD analysis | |
105 | if(gAnalysisLevel == "ESD") { | |
2cd42194 | 106 | AliESDEvent* gESD = dynamic_cast<AliESDEvent*>(InputEvent()); // from TaskSE |
107 | if (!gESD) { | |
108 | Printf("ERROR: gESD not available"); | |
cd54a838 | 109 | return; |
5c33329d | 110 | } |
2cd42194 | 111 | |
112 | fHistEventStats->Fill(1); //all events | |
09bb7bf4 | 113 | Bool_t isSelected = kTRUE; |
114 | if(fUseOfflineTrigger) | |
115 | isSelected = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected(); | |
2cd42194 | 116 | if(isSelected) { |
117 | fHistEventStats->Fill(2); //triggered events | |
118 | ||
119 | const AliESDVertex *vertex = gESD->GetPrimaryVertex(); | |
120 | if(vertex) { | |
7f94638c | 121 | if(vertex->GetNContributors() > 0) { |
122 | if(vertex->GetZRes() != 0) { | |
123 | fHistEventStats->Fill(3); //events with a proper vertex | |
124 | if(TMath::Abs(vertex->GetXv()) < fVxMax) { | |
125 | if(TMath::Abs(vertex->GetYv()) < fVyMax) { | |
126 | if(TMath::Abs(vertex->GetZv()) < fVzMax) { | |
127 | fHistEventStats->Fill(4); //analayzed events | |
09bb7bf4 | 128 | fHistVx->Fill(vertex->GetXv()); |
129 | fHistVy->Fill(vertex->GetYv()); | |
130 | fHistVz->Fill(vertex->GetZv()); | |
131 | ||
132 | //Printf("There are %d tracks in this event", gESD->GetNumberOfTracks()); | |
7f94638c | 133 | for (Int_t iTracks = 0; iTracks < gESD->GetNumberOfTracks(); iTracks++) { |
134 | AliESDtrack* track = gESD->GetTrack(iTracks); | |
135 | if (!track) { | |
136 | Printf("ERROR: Could not receive track %d", iTracks); | |
137 | continue; | |
138 | } | |
139 | ||
140 | //ESD track cuts | |
141 | if(fESDtrackCuts) | |
142 | if(!fESDtrackCuts->AcceptTrack(track)) continue; | |
143 | array->Add(track); | |
144 | } //track loop | |
145 | }//Vz cut | |
146 | }//Vy cut | |
147 | }//Vx cut | |
148 | }//proper vertex resolution | |
149 | }//proper number of contributors | |
2cd42194 | 150 | }//vertex object valid |
151 | }//triggered event | |
cd54a838 | 152 | }//ESD analysis |
153 | //AOD analysis | |
154 | else if(gAnalysisLevel == "AOD") { | |
2cd42194 | 155 | AliAODEvent* gAOD = dynamic_cast<AliAODEvent*>(InputEvent()); // from TaskSE |
156 | if(!gAOD) { | |
157 | Printf("ERROR: gAOD not available"); | |
cd54a838 | 158 | return; |
159 | } | |
2cd42194 | 160 | |
161 | Printf("There are %d tracks in this event", gAOD->GetNumberOfTracks()); | |
162 | for (Int_t iTracks = 0; iTracks < gAOD->GetNumberOfTracks(); iTracks++) { | |
163 | AliAODTrack* track = gAOD->GetTrack(iTracks); | |
cd54a838 | 164 | if (!track) { |
165 | Printf("ERROR: Could not receive track %d", iTracks); | |
166 | continue; | |
167 | } | |
168 | array->Add(track); | |
169 | } //track loop | |
170 | }//AOD analysis | |
171 | //MC analysis | |
172 | else if(gAnalysisLevel == "MC") { | |
2cd42194 | 173 | |
174 | AliMCEvent* mcEvent = MCEvent(); | |
175 | if (!mcEvent) { | |
176 | Printf("ERROR: mcEvent not available"); | |
cd54a838 | 177 | return; |
178 | } | |
179 | ||
2cd42194 | 180 | Printf("There are %d tracks in this event", mcEvent->GetNumberOfPrimaries()); |
181 | for (Int_t iTracks = 0; iTracks < mcEvent->GetNumberOfPrimaries(); iTracks++) { | |
182 | AliMCParticle* track = dynamic_cast<AliMCParticle *>(mcEvent->GetTrack(iTracks)); | |
cd54a838 | 183 | if (!track) { |
184 | Printf("ERROR: Could not receive particle %d", iTracks); | |
185 | continue; | |
186 | } | |
187 | array->Add(track); | |
188 | } //track loop | |
189 | }//MC analysis | |
190 | ||
5c33329d | 191 | fBalance->CalculateBalance(array); |
192 | ||
193 | delete array; | |
2cd42194 | 194 | |
5c33329d | 195 | } |
196 | ||
197 | //________________________________________________________________________ | |
198 | void AliAnalysisTaskBF::Terminate(Option_t *) { | |
199 | // Draw result to the screen | |
200 | // Called once at the end of the query | |
2cd42194 | 201 | fBalance = dynamic_cast<AliBalance*> (GetOutputData(1)); |
5c33329d | 202 | if (!fBalance) { |
203 | Printf("ERROR: fBalance not available"); | |
204 | return; | |
205 | } | |
206 | ||
207 | TGraphErrors *gr = fBalance->DrawBalance(); | |
208 | gr->SetMarkerStyle(20); | |
209 | gr->Draw("AP"); | |
210 | ||
211 | fBalance->PrintResults(); | |
212 | } |