added AliTPCClusterHistograms
[u/mrichter/AliRoot.git] / PWG0 / TPC / AliROCESDAnalysisSelector.cxx
CommitLineData
df71af87 1/**************************************************************************
2 * Copyright(c) 1998-1999, 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/* $Id$ */
17
18// The ESD is available as member fESD
19//
20// The Process function is nearly empty. Implement your analysis there and look at the other listed below functions you
21// might need.
22//
23// The following methods can be overrriden. Please do not forgot to call the base class function.
24//
25// Begin(): called everytime a loop on the tree starts,
26// a convenient place to create your histograms.
27// SlaveBegin(): called after Begin(), when on PROOF called only on the
28// slave servers.
29// Init(): called for each new tree. Enable/Disable branches here.
30// Process(): called for each event, in this function you decide what
31// to read and fill your histograms.
32// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
33// called only on the slave servers.
34// Terminate(): called at the end of the loop on the tree,
35// a convenient place to draw/fit your histograms.
36//
37// Author: Jan.Fiete.Grosse-Oetringhaus@cern.ch
38
39#include "AliROCESDAnalysisSelector.h"
40
41#include <AliLog.h>
42#include <AliESD.h>
43#include <AliESDfriend.h>
44#include <../TPC/AliTPCclusterMI.h>
45#include <../TPC/AliTPCseed.h>
46
df71af87 47#include <TFile.h>
48#include <TTree.h>
49#include <TCanvas.h>
2d9e89d4 50
51#include "TPC/AliTPCClusterHistograms.h"
df71af87 52
53ClassImp(AliROCESDAnalysisSelector)
54
55AliROCESDAnalysisSelector::AliROCESDAnalysisSelector() :
56 AliSelector(),
57 fESDfriend(0),
2d9e89d4 58 fClusterHistograms(0)
df71af87 59{
60 //
61 // Constructor. Initialization of pointers
62 //
63}
64
65AliROCESDAnalysisSelector::~AliROCESDAnalysisSelector()
66{
67 //
68 // Destructor
69 //
2d9e89d4 70
71 if (fClusterHistograms) {
72 delete fClusterHistograms;
73 fClusterHistograms = 0;
74 }
75
df71af87 76}
77
78void AliROCESDAnalysisSelector::SlaveBegin(TTree* tree)
79{
80 //
81
82 AliSelector::SlaveBegin(tree);
2d9e89d4 83
84 fClusterHistograms = new AliTPCClusterHistograms("test","test");
85
df71af87 86}
87
88void AliROCESDAnalysisSelector::Init(TTree *tree)
89{
90 // The Init() function is called when the selector needs to initialize
91 // a new tree or chain. Typically here the branch addresses of the tree
92 // will be set. It is normaly not necessary to make changes to the
93 // generated code, but the routine can be extended by the user if needed.
94 // Init() will be called many times when running with PROOF.
95
96 AliSelector::Init(tree);
97
98 // Set branch address
99 if (tree)
100 tree->SetBranchAddress("ESDfriend", &fESDfriend);
101
102 if (fESDfriend != 0)
103 AliDebug(AliLog::kInfo, "INFO: Found ESDfriend branch in chain.");
104}
105
106Bool_t AliROCESDAnalysisSelector::Process(Long64_t entry)
107{
108 //
109 // Implement your analysis here. Do not forget to call the parent class Process by
110 // if (AliSelector::Process(entry) == kFALSE)
111 // return kFALSE;
112 //
113
114 if (AliSelector::Process(entry) == kFALSE)
115 return kFALSE;
116
117 // Check prerequisites
118 if (!fESD)
119 {
120 AliDebug(AliLog::kError, "ESD branch not available");
121 return kFALSE;
122 }
123
124 // Check prerequisites
125 if (!fESDfriend)
126 {
127 AliDebug(AliLog::kError, "ESDfriend branch not available");
128 return kFALSE;
129 }
130
131 fESD->SetESDfriend(fESDfriend);
132
133 Int_t nTracks = fESD->GetNumberOfTracks();
134
135 // loop over esd tracks
136 for (Int_t t=0; t<nTracks; t++)
137 {
138 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (fESD->GetTrack(t));
139 if (!esdTrack)
140 {
141 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", t));
142 continue;
143 }
144
145 AliESDfriendTrack* friendtrack = const_cast<AliESDfriendTrack*> (dynamic_cast<const AliESDfriendTrack*> (esdTrack->GetFriendTrack()));
146 if (!friendtrack)
147 {
148 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve friend of track %d.", t));
149 continue;
150 }
151
152 const AliTPCseed* seed = dynamic_cast<const AliTPCseed*> (friendtrack->GetCalibObject(0));
153 if (!seed)
154 {
155 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve seed of track %d.", t));
156 continue;
157 }
158
159 for (Int_t clusterID = 0; clusterID < 160; clusterID++)
160 {
161 AliTPCclusterMI* cluster = seed->GetClusterPointer(clusterID);
162 if (!cluster)
163 {
164 //AliDebug(AliLog::kError, Form("ERROR: Could not retrieve cluster %d of track %d.", clusterID, t));
165 continue;
166 }
167
168 //AliDebug(AliLog::kDebug, Form("We found a cluster from sector %d", cluster->GetDetector()));
169
170 if (cluster->GetDetector() != 5)
171 continue;
172
2d9e89d4 173 fClusterHistograms->FillCluster(cluster);
df71af87 174 }
175 }
176
177 return kTRUE;
178}
179
180void AliROCESDAnalysisSelector::SlaveTerminate()
181{
182 //
183
2d9e89d4 184 fOutput->Add(fClusterHistograms);
df71af87 185}
186
187void AliROCESDAnalysisSelector::Terminate()
188{
189 //
df71af87 190
191 TFile* file = TFile::Open("rocESD.root", "RECREATE");
2d9e89d4 192
193 fClusterHistograms->SaveHistograms();
df71af87 194 file->Close();
195}