]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG0/TPC/AliROCESDAnalysisSelector.cxx
adding analysis class for each sector
[u/mrichter/AliRoot.git] / PWG0 / TPC / AliROCESDAnalysisSelector.cxx
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
47 #include <TFile.h>
48 #include <TTree.h>
49 #include <TCanvas.h>
50
51 #include "TPC/AliTPCClusterHistograms.h"
52
53 ClassImp(AliROCESDAnalysisSelector)
54
55 AliROCESDAnalysisSelector::AliROCESDAnalysisSelector() :
56   AliSelector(),
57   fESDfriend(0)
58 {
59   //
60   // Constructor. Initialization of pointers
61   //
62   
63   for (Int_t i=0; i<kTPCSectors; i++)
64     fClusterHistograms[i] = 0;
65 }
66
67 AliROCESDAnalysisSelector::~AliROCESDAnalysisSelector()
68 {
69   //
70   // Destructor
71   //
72 }
73
74 void AliROCESDAnalysisSelector::SlaveBegin(TTree* tree)
75 {
76   //
77   
78   AliSelector::SlaveBegin(tree);
79
80
81 void AliROCESDAnalysisSelector::Init(TTree *tree)
82 {
83   // The Init() function is called when the selector needs to initialize
84   // a new tree or chain. Typically here the branch addresses of the tree
85   // will be set. It is normaly not necessary to make changes to the
86   // generated code, but the routine can be extended by the user if needed.
87   // Init() will be called many times when running with PROOF.
88
89   AliSelector::Init(tree);
90
91   // Set branch address
92   if (tree)
93     tree->SetBranchAddress("ESDfriend", &fESDfriend);
94     
95   if (fESDfriend != 0)
96     AliDebug(AliLog::kInfo, "INFO: Found ESDfriend branch in chain.");
97 }
98
99 Bool_t AliROCESDAnalysisSelector::Process(Long64_t entry)
100 {
101   //
102   // Implement your analysis here. Do not forget to call the parent class Process by
103   // if (AliSelector::Process(entry) == kFALSE)
104   //   return kFALSE;
105   //
106
107   if (AliSelector::Process(entry) == kFALSE)
108     return kFALSE;
109
110   // Check prerequisites
111   if (!fESD)
112   {
113     AliDebug(AliLog::kError, "ESD branch not available");
114     return kFALSE;
115   }
116
117   // Check prerequisites
118   if (!fESDfriend)
119   {
120     AliDebug(AliLog::kError, "ESDfriend branch not available");
121     return kFALSE;
122   }
123
124   fESD->SetESDfriend(fESDfriend);
125
126   Int_t nTracks = fESD->GetNumberOfTracks();
127   
128   Int_t nSkippedSeeds = 0;
129   
130   // loop over esd tracks
131   for (Int_t t=0; t<nTracks; t++)
132   {
133     AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (fESD->GetTrack(t));
134     if (!esdTrack)
135     {
136       AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", t));
137       continue;
138     }
139     
140     AliESDfriendTrack* friendtrack = const_cast<AliESDfriendTrack*> (dynamic_cast<const AliESDfriendTrack*> (esdTrack->GetFriendTrack()));
141     if (!friendtrack)
142     {
143       AliDebug(AliLog::kError, Form("ERROR: Could not retrieve friend of track %d.", t));
144       continue;
145     }
146     
147     const AliTPCseed* seed = dynamic_cast<const AliTPCseed*> (friendtrack->GetCalibObject(0));
148     if (!seed)
149     {
150       AliDebug(AliLog::kDebug, Form("ERROR: Could not retrieve seed of track %d.", t));
151       nSkippedSeeds++;
152       continue;
153     }
154     
155     for (Int_t clusterID = 0; clusterID < 160; clusterID++)
156     {
157       AliTPCclusterMI* cluster = seed->GetClusterPointer(clusterID);
158       if (!cluster)
159       {
160         //AliDebug(AliLog::kError, Form("ERROR: Could not retrieve cluster %d of track %d.", clusterID, t));
161         continue;
162       }
163       
164       //AliDebug(AliLog::kDebug, Form("We found a cluster from sector %d", cluster->GetDetector()));
165
166       Int_t detector = cluster->GetDetector();
167       
168       if (detector < 0 || detector >= kTPCSectors)
169       {
170         AliDebug(AliLog::kDebug, Form("We found a cluster from invalid sector %d", detector));
171         continue;
172       }
173       
174       if (!fClusterHistograms[detector])
175       {
176         TString title;
177         title.Form("sector_%d", detector); 
178         // TODO claus will put a nice title here
179         fClusterHistograms[detector] = new AliTPCClusterHistograms(Form("sector_%d", detector), title);
180       }
181       
182       fClusterHistograms[detector]->FillCluster(cluster);
183     }
184   }
185   
186   if (nSkippedSeeds > 0)
187     printf("WARNING: The seed was not found for %d out of %d tracks.\n", nSkippedSeeds, nTracks);
188    
189   return kTRUE;
190 }
191
192 void AliROCESDAnalysisSelector::SlaveTerminate()
193 {
194   //
195   
196   for (Int_t i=0; i<kTPCSectors; i++)
197     if (fClusterHistograms[i])
198         fOutput->Add(fClusterHistograms[i]);
199
200
201 void AliROCESDAnalysisSelector::Terminate()
202 {
203   // TODO read from output list for PROOF
204     
205   TFile* file = TFile::Open("rocESD.root", "RECREATE");
206   
207   for (Int_t i=0; i<kTPCSectors; i++)
208     if (fClusterHistograms[i])
209       fClusterHistograms[i]->SaveHistograms();
210
211   file->Close();
212