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 = esdH->ClassName();
62 Printf("----> AliAnalysisTaskPt: ClassName of handler = %s", classInputHandler.Data());
65 Printf("ERROR: Could not get ESDInputHandler");
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");
88 Printf("and the result is: fESDfriend = %p", fESDfriend);
91 Printf("The friends are not requested");
95 Printf("ERROR, no ESD event");
97 if (fUseFriends && !fESDfriend) {
98 Printf("ERROR, no ESD friend");
102 Printf("fESD = %p, fESDfriend = %p", fESD, fESDfriend);
103 printf("<---- AliAnalysisTaskPt::ConnectInputData\n");
106 //________________________________________________________________________
107 void AliAnalysisTaskPt::CreateOutputObjects()
112 fListOut = new TList();
113 fListOut->SetOwner();
114 fListOut->SetName("listHistos");
116 fHistPt = new TH1F("fHistPt", "P_{T} distribution", 15, 0.1, 3.1);
117 fHistPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
118 fHistPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
119 fHistPt->SetMarkerStyle(kFullCircle);
121 fHistQ = new TH1F("fHistQ", "TPC clusters: Q distribution", 1000, 0, 10000);
122 fHistQ->GetXaxis()->SetTitle("Q");
123 fHistQ->GetYaxis()->SetTitle("dN/dQ");
124 fHistQ->SetMarkerStyle(kFullCircle);
126 fHistNTPCCl = new TH1F("fHistNTPCCl", "Number of TPC clusters", 160, -0.5, 159.5);
127 fHistNTPCCl->GetXaxis()->SetTitle("n. TPC Cl.");
128 fHistNTPCCl->GetYaxis()->SetTitle("dN/d(n. TPC Cl)");
129 fHistNTPCCl->SetMarkerStyle(kFullCircle);
131 fHistNESDtracks = new TH1F("fHistNESDtracks", "Number of ESD friend tracks", 1000, -0.5, 999.5);
132 fHistNESDtracks->GetXaxis()->SetTitle("n. ESD friend tracks");
133 fHistNESDtracks->GetYaxis()->SetTitle("dN/d(n. ESD friend tracks)");
134 fHistNESDtracks->SetMarkerStyle(kFullCircle);
136 fHistNESDfriendtracks = new TH1F("fHistNESDfriendtracks", "Number of ESD tracks", 1000, -0.5, 999.5);
137 fHistNESDfriendtracks->GetXaxis()->SetTitle("n. ESD tracks");
138 fHistNESDfriendtracks->GetYaxis()->SetTitle("dN/d(n. ESD tracks)");
139 fHistNESDfriendtracks->SetMarkerStyle(kFullCircle);
141 fListOut->Add(fHistPt);
142 fListOut->Add(fHistQ);
143 fListOut->Add(fHistNTPCCl);
144 fListOut->Add(fHistNESDtracks);
145 fListOut->Add(fHistNESDfriendtracks);
147 PostData(0, fListOut);
149 fCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(1);
152 //________________________________________________________________________
153 void AliAnalysisTaskPt::Exec(Option_t *)
156 // Called for each event
159 Printf("ERROR: fESD not available");
165 Printf("In Exec: ...We have to use the friends...");
166 fESDfriend = fESD->FindFriend();
167 Printf("...and we got friends = %p", fESDfriend);
169 Printf("ERROR: fESDfriend not available");
176 Printf("In Exec: ...We have to use the friends...");
177 Printf("...and we got friends = %p", fESDfriend);
179 Printf("ERROR: fESDfriend not available");
184 Int_t nESDtracks = fESD->GetNumberOfTracks();
185 Int_t nESDfriendtracks = 0;
186 if (fUseFriends) nESDfriendtracks = fESDfriend->GetNumberOfTracks();
187 Printf("There are %d tracks in this event", nESDtracks);
188 Printf("... and there are %d friends in this event", nESDfriendtracks);
190 fHistNESDtracks->Fill(nESDtracks);
191 fHistNESDfriendtracks->Fill(nESDfriendtracks);
193 // Track loop to fill a pT spectrum
194 for (Int_t iTracks = 0; iTracks < nESDtracks; iTracks++) {
195 Printf("Checking track %d", iTracks);
196 const AliVTrack* track = dynamic_cast<AliVTrack*>(fESD->GetTrack(iTracks));
198 Printf("ERROR: Could not receive track %d", iTracks);
201 Printf("track %d has pt = %f", iTracks, track->Pt());
202 fHistPt->Fill(track->Pt());
203 fHistNTPCCl->Fill(track->GetTPCNcls());
208 Printf("In the loop over the friends");
210 for (Int_t iFriend = 0; iFriend < nESDfriendtracks; iFriend++) {
211 Printf("Getting friend %d", iFriend);
212 const AliVfriendTrack* friendTrack = fESDfriend->GetTrack(iFriend);
214 Printf("ERROR: Could not receive track %d", iFriend);
218 Printf("friend track = %p", friendTrack);
222 Int_t err = friendTrack->GetTPCseed( seed );
223 Printf("err = %d", err);
225 Printf("Found TPC seed" );
226 for (Int_t irow = 0; irow < 160; irow++){
227 AliTPCclusterMI* cluMI = seed.GetClusterPointer(irow);
229 Printf("Found cluster at row %d", irow);
230 Float_t q = cluMI->GetQ();
235 Printf("Row %d does not contain clusters", irow);
240 //Printf("Schade... seed is %p", seed);
246 PostData(0, fListOut);
250 //________________________________________________________________________
251 void AliAnalysisTaskPt::Terminate(Option_t *)
253 // Draw result to the screen
254 // Called once at the end of the query
256 Printf("Terminate called: fESD = %p", fESD);
258 fListOut = dynamic_cast<TList*> (GetOutputData(0));
261 fHistPt = dynamic_cast<TH1F*>(fListOut->FindObject("fHistPt"));
263 Printf("ERROR: fHistPt not available");
267 TCanvas *c1 = new TCanvas("AliAnalysisTaskPt","Pt",10,10,510,510);
268 c1->cd(1)->SetLogy();
269 fHistPt->DrawCopy("E");
272 Printf("In Terminate: no TList found");