7 #include "AliAnalysisTask.h"
8 #include "AliAnalysisManager.h"
10 #include "AliESDEvent.h"
11 #include "AliVVevent.h"
12 #include "AliVVtrack.h"
13 #include "AliESDtrackCuts.h"
14 #include "AliVEventHandler.h"
15 #include "AliTPCseed.h"
16 #include "AliTPCclusterMI.h"
17 #include "AliVVfriendEvent.h"
18 #include "AliVVfriendTrack.h"
20 #include "AliAnalysisTaskPt.h"
22 // example of an analysis task creating a p_t spectrum
23 // Authors: Panos Cristakoglou, Jan Fiete Grosse-Oetringhaus, Christian Klein-Boesing
25 ClassImp(AliAnalysisTaskPt)
27 //________________________________________________________________________
28 AliAnalysisTaskPt::AliAnalysisTaskPt(const char *name)
29 : AliAnalysisTask(name, ""), fESD(0), fESDfriend(0), fHistPt(0), fCuts(0), fEv(0), fHistQ(0), fListOut(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");
51 // Disable all branches and enable only the needed ones
52 // The next two lines are different when data produced as AliESDEvent is read
54 tree->SetBranchStatus("*", kFALSE);
55 tree->SetBranchStatus("fTracks.*", kTRUE);
58 AliVEventHandler *esdH = AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler();
61 Printf("ERROR: Could not get ESDInputHandler");
63 Printf("----> AliAnalysisTaskPt::ConnectInputData Getting the event from handler %p", esdH);
64 //fESD = dynamic_cast<AliESDEvent*>(esdH->GetEvent());
65 fESD = esdH->GetEvent();
66 fESDfriend = esdH->GetFriendEvent();
69 Printf("ERROR, no ESD event");
72 Printf("ERROR, no ESD friend");
76 Printf("fESD = %p, fESDfriend = %p", fESD, fESDfriend);
77 printf("<---- AliAnalysisTaskPt::ConnectInputData\n");
80 //________________________________________________________________________
81 void AliAnalysisTaskPt::CreateOutputObjects()
86 fListOut = new TList();
88 fListOut->SetName("listHistos");
90 fHistPt = new TH1F("fHistPt", "P_{T} distribution", 15, 0.1, 3.1);
91 fHistPt->GetXaxis()->SetTitle("P_{T} (GeV/c)");
92 fHistPt->GetYaxis()->SetTitle("dN/dP_{T} (c/GeV)");
93 fHistPt->SetMarkerStyle(kFullCircle);
95 fHistQ = new TH1F("fHistQ", "TPC clusters: Q distribution", 1000, 0, 10000);
96 fHistQ->GetXaxis()->SetTitle("Q");
97 fHistQ->GetYaxis()->SetTitle("dN/dQ");
98 fHistQ->SetMarkerStyle(kFullCircle);
100 fListOut->Add(fHistPt);
101 fListOut->Add(fHistQ);
103 PostData(0, fListOut);
105 fCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(1);
108 //________________________________________________________________________
109 void AliAnalysisTaskPt::Exec(Option_t *)
112 // Called for each event
115 Printf("ERROR: fESD not available");
119 Printf("ERROR: fESDfriend not available");
123 Printf("There are %d tracks in this event", fESD->GetNumberOfTracks());
124 Printf("... and there are %d friends in this event", fESDfriend->GetNumberOfTracks());
126 // Track loop to fill a pT spectrum
127 for (Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++) {
128 AliVVtrack* track = fESD->GetTrack(iTracks);
130 Printf("ERROR: Could not receive track %d", iTracks);
134 fHistPt->Fill(track->Pt());
139 for (Int_t iFriend = 0; iFriend < fESDfriend->GetNumberOfTracks(); iFriend++) {
140 const AliVVfriendTrack* friendTrack = fESDfriend->GetTrack(iFriend);
142 Printf("ERROR: Could not receive track %d", iFriend);
145 TObject* calibObject;
146 AliTPCseed* seed = NULL;
147 for (Int_t idx = 0; (calibObject = friendTrack->GetCalibObject(idx)); ++idx) {
148 Printf(" |Cal %d = %p", idx, calibObject);
149 if ((seed = dynamic_cast<AliTPCseed*>(calibObject))) {
150 Printf("Found TPC seed");
151 for (Int_t irow = 0; irow < 160; irow++){
152 AliTPCclusterMI* cluMI = seed->GetClusterPointer(irow);
154 Printf("Found cluster at row %d", irow);
155 Float_t q = cluMI->GetQ();
160 Printf("Row %d does not contain clusters", irow);
168 PostData(0, fListOut);
172 //________________________________________________________________________
173 void AliAnalysisTaskPt::Terminate(Option_t *)
175 // Draw result to the screen
176 // Called once at the end of the query
178 Printf("Terminate called: fESD = %p", fESD);
180 fListOut = dynamic_cast<TList*> (GetOutputData(0));
183 fHistPt = dynamic_cast<TH1F*>(fListOut->FindObject("fHistPt"));
185 Printf("ERROR: fHistPt not available");
189 TCanvas *c1 = new TCanvas("AliAnalysisTaskPt","Pt",10,10,510,510);
190 c1->cd(1)->SetLogy();
191 fHistPt->DrawCopy("E");
194 Printf("In Terminate: no TList found");