7 #include "AliAnalysisTask.h"
8 #include "AliAnalysisManager.h"
10 #include "AliESDEvent.h"
11 #include "AliESDtrackCuts.h"
12 #include "AliVEventHandler.h"
13 #include "AliTPCseed.h"
14 #include "AliTPCclusterMI.h"
15 #include "AliVfriendEvent.h"
16 #include "AliVfriendTrack.h"
17 #include "AliESDInputHandler.h"
19 #include "AliAnalysisTaskPt.h"
21 // example of an analysis task creating a p_t spectrum
22 // Authors: Panos Cristakoglou, Jan Fiete Grosse-Oetringhaus, Christian Klein-Boesing
24 ClassImp(AliAnalysisTaskPt)
26 //________________________________________________________________________
27 AliAnalysisTaskPt::AliAnalysisTaskPt(const char *name)
28 : AliAnalysisTask(name, ""), fESD(0), fESDfriend(0), fHistPt(0), fCuts(0), fEv(0), fHistQ(0), fListOut(0), fUseFriends(kFALSE), fHistNTPCCl(0), fHistNESDtracks(0), fHistNESDfriendtracks(0)
33 // Define input and output slots here
34 // Input slot #0 works with a TChain
35 DefineInput(0, TChain::Class());
36 // Output slot #0 writes into a TH1 container
37 DefineOutput(0, TList::Class());
40 //________________________________________________________________________
41 void AliAnalysisTaskPt::ConnectInputData(Option_t *)
43 // Connect ESD or AOD here
46 printf("----> AliAnalysisTaskPt::ConnectInputData\n");
47 TTree* tree = dynamic_cast<TTree*> (GetInputData(0));
49 Printf("ERROR: Could not read chain from input slot 0");
52 // Disable all branches and enable only the needed ones
53 // The next two lines are different when data produced as AliESDEvent is read
55 tree->SetBranchStatus("*", kFALSE);
56 tree->SetBranchStatus("fTracks.*", kTRUE);
59 AliVEventHandler *esdH = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
60 TString classInputHandler;
63 Printf("ERROR: Could not get ESDInputHandler");
66 classInputHandler = esdH->ClassName();
67 Printf("----> AliAnalysisTaskPt: ClassName of handler = %s", classInputHandler.Data());
68 Printf("----> AliAnalysisTaskPt::ConnectInputData Getting the event from handler %p", esdH);
69 fESD = esdH->GetEvent();
71 Printf("...We have to use the friends...");
72 if (classInputHandler.Contains("HLT")) { // we are running in HLT
73 fESDfriend = esdH->GetVfriendEvent();
75 else { /// we are running offline
76 if (esdH && esdH->GetTree()) {
77 Printf("...We got the tree...");
78 if (esdH->GetTree()->GetBranch("ESDfriend.")){
79 Printf("Yu-huuuu!!! friend branch found");
80 fESDfriend = ((AliESDInputHandler*)esdH)->GetESDfriend();
83 Printf("No friend branch found");
87 Printf("and the result is: fESDfriend = %p", fESDfriend);
90 Printf("The friends are not requested");
94 Printf("ERROR, no ESD event");
96 if (fUseFriends && !fESDfriend) {
97 Printf("ERROR, no ESD friend");
101 Printf("fESD = %p, fESDfriend = %p", fESD, fESDfriend);
102 printf("<---- AliAnalysisTaskPt::ConnectInputData\n");
105 //________________________________________________________________________
106 void AliAnalysisTaskPt::CreateOutputObjects()
111 fListOut = new TList();
112 fListOut->SetOwner();
113 fListOut->SetName("listHistos");
115 fHistPt = new TH1F("fHistPt", "P_{T} distribution", 15, 0.1, 3.1);
116 fHistPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
117 fHistPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
118 fHistPt->SetMarkerStyle(kFullCircle);
120 fHistQ = new TH1F("fHistQ", "TPC clusters: Q distribution", 1000, 0, 10000);
121 fHistQ->GetXaxis()->SetTitle("Q");
122 fHistQ->GetYaxis()->SetTitle("dN/dQ");
123 fHistQ->SetMarkerStyle(kFullCircle);
125 fHistNTPCCl = new TH1F("fHistNTPCCl", "Number of TPC clusters", 160, -0.5, 159.5);
126 fHistNTPCCl->GetXaxis()->SetTitle("n. TPC Cl.");
127 fHistNTPCCl->GetYaxis()->SetTitle("dN/d(n. TPC Cl)");
128 fHistNTPCCl->SetMarkerStyle(kFullCircle);
130 fHistNESDtracks = new TH1F("fHistNESDtracks", "Number of ESD friend tracks", 1000, -0.5, 999.5);
131 fHistNESDtracks->GetXaxis()->SetTitle("n. ESD friend tracks");
132 fHistNESDtracks->GetYaxis()->SetTitle("dN/d(n. ESD friend tracks)");
133 fHistNESDtracks->SetMarkerStyle(kFullCircle);
135 fHistNESDfriendtracks = new TH1F("fHistNESDfriendtracks", "Number of ESD tracks", 1000, -0.5, 999.5);
136 fHistNESDfriendtracks->GetXaxis()->SetTitle("n. ESD tracks");
137 fHistNESDfriendtracks->GetYaxis()->SetTitle("dN/d(n. ESD tracks)");
138 fHistNESDfriendtracks->SetMarkerStyle(kFullCircle);
140 fListOut->Add(fHistPt);
141 fListOut->Add(fHistQ);
142 fListOut->Add(fHistNTPCCl);
143 fListOut->Add(fHistNESDtracks);
144 fListOut->Add(fHistNESDfriendtracks);
146 PostData(0, fListOut);
148 fCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(1);
151 //________________________________________________________________________
152 void AliAnalysisTaskPt::Exec(Option_t *)
155 // Called for each event
158 Printf("ERROR: fESD not available");
164 Printf("In Exec: ...We have to use the friends...");
165 fESDfriend = fESD->FindFriend();
166 Printf("...and we got friends = %p", fESDfriend);
168 Printf("ERROR: fESDfriend not available");
175 Printf("In Exec: ...We have to use the friends...");
176 Printf("...and we got friends = %p", fESDfriend);
178 Printf("ERROR: fESDfriend not available");
183 Int_t nESDtracks = fESD->GetNumberOfTracks();
184 Int_t nESDfriendtracks = 0;
185 if (fUseFriends) nESDfriendtracks = fESDfriend->GetNumberOfTracks();
186 Printf("There are %d tracks in this event", nESDtracks);
187 Printf("... and there are %d friends in this event", nESDfriendtracks);
189 fHistNESDtracks->Fill(nESDtracks);
190 fHistNESDfriendtracks->Fill(nESDfriendtracks);
192 // Track loop to fill a pT spectrum
193 for (Int_t iTracks = 0; iTracks < nESDtracks; iTracks++) {
194 Printf("Checking track %d", iTracks);
195 const AliVTrack* track = dynamic_cast<AliVTrack*>(fESD->GetTrack(iTracks));
197 Printf("ERROR: Could not receive track %d", iTracks);
200 Printf("track %d has pt = %f", iTracks, track->Pt());
201 fHistPt->Fill(track->Pt());
202 fHistNTPCCl->Fill(track->GetTPCNcls());
207 Printf("In the loop over the friends");
209 for (Int_t iFriend = 0; iFriend < nESDfriendtracks; iFriend++) {
210 Printf("Getting friend %d", iFriend);
211 const AliVfriendTrack* friendTrack = fESDfriend->GetTrack(iFriend);
213 Printf("ERROR: Could not receive track %d", iFriend);
217 Printf("friend track = %p", friendTrack);
221 Int_t err = friendTrack->GetTPCseed( seed );
222 Printf("err = %d", err);
224 Printf("Found TPC seed" );
225 for (Int_t irow = 0; irow < 160; irow++){
226 AliTPCclusterMI* cluMI = seed.GetClusterPointer(irow);
228 Printf("Found cluster at row %d", irow);
229 Float_t q = cluMI->GetQ();
234 Printf("Row %d does not contain clusters", irow);
239 //Printf("Schade... seed is %p", seed);
245 PostData(0, fListOut);
249 //________________________________________________________________________
250 void AliAnalysisTaskPt::Terminate(Option_t *)
252 // Draw result to the screen
253 // Called once at the end of the query
255 Printf("Terminate called: fESD = %p", fESD);
257 fListOut = dynamic_cast<TList*> (GetOutputData(0));
260 fHistPt = dynamic_cast<TH1F*>(fListOut->FindObject("fHistPt"));
262 Printf("ERROR: fHistPt not available");
266 TCanvas *c1 = new TCanvas("AliAnalysisTaskPt","Pt",10,10,510,510);
267 c1->cd(1)->SetLogy();
268 fHistPt->DrawCopy("E");
271 Printf("In Terminate: no TList found");