]>
Commit | Line | Data |
---|---|---|
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 | ||
1d7991a5 | 18 | // |
19 | // This class analyses TPC cosmics data from the ESD and the ESDfriend | |
df71af87 | 20 | // |
1d7991a5 | 21 | // Authors: Jan.Fiete.Grosse-Oetringhaus@cern.ch, Claus.Jorgensen@cern.ch |
df71af87 | 22 | // |
df71af87 | 23 | |
24 | #include "AliROCESDAnalysisSelector.h" | |
25 | ||
26 | #include <AliLog.h> | |
27 | #include <AliESD.h> | |
28 | #include <AliESDfriend.h> | |
29 | #include <../TPC/AliTPCclusterMI.h> | |
30 | #include <../TPC/AliTPCseed.h> | |
31 | ||
df71af87 | 32 | #include <TFile.h> |
33 | #include <TTree.h> | |
34 | #include <TCanvas.h> | |
2d9e89d4 | 35 | |
36 | #include "TPC/AliTPCClusterHistograms.h" | |
df71af87 | 37 | |
38 | ClassImp(AliROCESDAnalysisSelector) | |
39 | ||
40 | AliROCESDAnalysisSelector::AliROCESDAnalysisSelector() : | |
41 | AliSelector(), | |
9cc7192c | 42 | fESDfriend(0) |
df71af87 | 43 | { |
44 | // | |
45 | // Constructor. Initialization of pointers | |
46 | // | |
9cc7192c | 47 | |
1d7991a5 | 48 | for (Int_t i=0; i<kTPCHists; i++) |
9cc7192c | 49 | fClusterHistograms[i] = 0; |
df71af87 | 50 | } |
51 | ||
52 | AliROCESDAnalysisSelector::~AliROCESDAnalysisSelector() | |
53 | { | |
54 | // | |
55 | // Destructor | |
56 | // | |
57 | } | |
58 | ||
59 | void AliROCESDAnalysisSelector::SlaveBegin(TTree* tree) | |
60 | { | |
61 | // | |
62 | ||
63 | AliSelector::SlaveBegin(tree); | |
df71af87 | 64 | } |
65 | ||
66 | void AliROCESDAnalysisSelector::Init(TTree *tree) | |
67 | { | |
68 | // The Init() function is called when the selector needs to initialize | |
69 | // a new tree or chain. Typically here the branch addresses of the tree | |
70 | // will be set. It is normaly not necessary to make changes to the | |
71 | // generated code, but the routine can be extended by the user if needed. | |
72 | // Init() will be called many times when running with PROOF. | |
73 | ||
74 | AliSelector::Init(tree); | |
1d7991a5 | 75 | |
76 | printf("Init called %p\n", (void*) fESDfriend); | |
df71af87 | 77 | |
78 | // Set branch address | |
1d7991a5 | 79 | if (tree) |
80 | { | |
81 | tree->SetBranchAddress("ESDfriend", &fESDfriend); | |
82 | ||
6c3d6245 | 83 | tree->SetBranchStatus("*", 0); |
84 | tree->SetBranchStatus("fTracks.*", 1); | |
85 | tree->SetBranchStatus("fTimeStamp", 1); | |
1d7991a5 | 86 | //tree->SetBranchStatus("fTracks.fCalibContainer", 0); |
6c3d6245 | 87 | } |
1d7991a5 | 88 | |
df71af87 | 89 | if (fESDfriend != 0) |
90 | AliDebug(AliLog::kInfo, "INFO: Found ESDfriend branch in chain."); | |
91 | } | |
92 | ||
93 | Bool_t AliROCESDAnalysisSelector::Process(Long64_t entry) | |
94 | { | |
95 | // | |
96 | // Implement your analysis here. Do not forget to call the parent class Process by | |
97 | // if (AliSelector::Process(entry) == kFALSE) | |
98 | // return kFALSE; | |
99 | // | |
100 | ||
101 | if (AliSelector::Process(entry) == kFALSE) | |
102 | return kFALSE; | |
103 | ||
104 | // Check prerequisites | |
105 | if (!fESD) | |
106 | { | |
107 | AliDebug(AliLog::kError, "ESD branch not available"); | |
108 | return kFALSE; | |
109 | } | |
110 | ||
111 | // Check prerequisites | |
112 | if (!fESDfriend) | |
113 | { | |
114 | AliDebug(AliLog::kError, "ESDfriend branch not available"); | |
115 | return kFALSE; | |
116 | } | |
1d7991a5 | 117 | |
df71af87 | 118 | fESD->SetESDfriend(fESDfriend); |
119 | ||
120 | Int_t nTracks = fESD->GetNumberOfTracks(); | |
121 | ||
9cc7192c | 122 | Int_t nSkippedSeeds = 0; |
123 | ||
df71af87 | 124 | // loop over esd tracks |
125 | for (Int_t t=0; t<nTracks; t++) | |
126 | { | |
6c3d6245 | 127 | |
df71af87 | 128 | AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (fESD->GetTrack(t)); |
129 | if (!esdTrack) | |
130 | { | |
131 | AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", t)); | |
132 | continue; | |
133 | } | |
134 | ||
135 | AliESDfriendTrack* friendtrack = const_cast<AliESDfriendTrack*> (dynamic_cast<const AliESDfriendTrack*> (esdTrack->GetFriendTrack())); | |
136 | if (!friendtrack) | |
137 | { | |
138 | AliDebug(AliLog::kError, Form("ERROR: Could not retrieve friend of track %d.", t)); | |
139 | continue; | |
140 | } | |
141 | ||
142 | const AliTPCseed* seed = dynamic_cast<const AliTPCseed*> (friendtrack->GetCalibObject(0)); | |
143 | if (!seed) | |
144 | { | |
9cc7192c | 145 | AliDebug(AliLog::kDebug, Form("ERROR: Could not retrieve seed of track %d.", t)); |
146 | nSkippedSeeds++; | |
df71af87 | 147 | continue; |
148 | } | |
149 | ||
150 | for (Int_t clusterID = 0; clusterID < 160; clusterID++) | |
151 | { | |
152 | AliTPCclusterMI* cluster = seed->GetClusterPointer(clusterID); | |
153 | if (!cluster) | |
154 | { | |
155 | //AliDebug(AliLog::kError, Form("ERROR: Could not retrieve cluster %d of track %d.", clusterID, t)); | |
156 | continue; | |
157 | } | |
158 | ||
159 | //AliDebug(AliLog::kDebug, Form("We found a cluster from sector %d", cluster->GetDetector())); | |
160 | ||
9cc7192c | 161 | Int_t detector = cluster->GetDetector(); |
162 | ||
eb884e16 | 163 | if (detector < 0 || detector >= kTPCSectors) { |
164 | AliDebug(AliLog::kDebug, Form("We found a cluster from invalid sector %d", detector)); | |
165 | continue; | |
9cc7192c | 166 | } |
eb884e16 | 167 | |
483b1eb8 | 168 | // TODO: find a clever way to handle the time |
169 | // if (fESD->GetTimeStamp()<1160000000) | |
170 | // continue; | |
171 | ||
9cc7192c | 172 | if (!fClusterHistograms[detector]) |
eb884e16 | 173 | fClusterHistograms[detector] = new AliTPCClusterHistograms(detector,"",fESD->GetTimeStamp(),fESD->GetTimeStamp()+7*60*60); |
df71af87 | 174 | |
1d7991a5 | 175 | if (!fClusterHistograms[detector+kTPCSectors]) |
176 | fClusterHistograms[detector+kTPCSectors] = new AliTPCClusterHistograms(detector,"",fESD->GetTimeStamp(),fESD->GetTimeStamp()+7*60*60, kTRUE); | |
177 | ||
483b1eb8 | 178 | fClusterHistograms[detector]->FillCluster(cluster, fESD->GetTimeStamp()); |
1d7991a5 | 179 | fClusterHistograms[detector+kTPCSectors]->FillCluster(cluster, fESD->GetTimeStamp()); |
df71af87 | 180 | } |
181 | } | |
9cc7192c | 182 | |
183 | if (nSkippedSeeds > 0) | |
184 | printf("WARNING: The seed was not found for %d out of %d tracks.\n", nSkippedSeeds, nTracks); | |
1d7991a5 | 185 | |
186 | // TODO This should not be needed, the TTree::GetEntry() should take care of this, maybe because it has a reference member, to be analyzed | |
187 | // if the ESDfriend is not deleted we get a major memory leak | |
188 | // here the esdfriend seems to be also deleted, very weird behaviour.... | |
189 | delete fESD; | |
190 | fESD = 0; | |
191 | ||
192 | //delete fESDfriend; | |
193 | //fESDfriend = 0; | |
df71af87 | 194 | |
195 | return kTRUE; | |
196 | } | |
197 | ||
198 | void AliROCESDAnalysisSelector::SlaveTerminate() | |
199 | { | |
200 | // | |
201 | ||
1d7991a5 | 202 | if (fOutput) |
203 | { | |
204 | for (Int_t i=0; i<kTPCHists; i++) | |
205 | if (fClusterHistograms[i]) | |
9cc7192c | 206 | fOutput->Add(fClusterHistograms[i]); |
1d7991a5 | 207 | } |
df71af87 | 208 | } |
209 | ||
210 | void AliROCESDAnalysisSelector::Terminate() | |
211 | { | |
1d7991a5 | 212 | // |
213 | // read the objects from the output list and write them to a file | |
214 | // the filename is modified by the object comment passed in the tree info or input list | |
215 | // | |
216 | ||
217 | if (fOutput) | |
218 | { | |
219 | fOutput->Print(); | |
220 | ||
221 | for (Int_t i=0; i<kTPCSectors; i++) | |
222 | fClusterHistograms[i] = dynamic_cast<AliTPCClusterHistograms*> (fOutput->FindObject(AliTPCClusterHistograms::FormDetectorName(i, kFALSE))); | |
223 | for (Int_t i=0; i<kTPCSectors; i++) | |
224 | fClusterHistograms[kTPCSectors+i] = dynamic_cast<AliTPCClusterHistograms*> (fOutput->FindObject(AliTPCClusterHistograms::FormDetectorName(i, kTRUE))); | |
225 | } | |
226 | ||
227 | TNamed* comment = 0; | |
228 | if (fTree && fTree->GetUserInfo()) | |
229 | comment = dynamic_cast<TNamed*>(fTree->GetUserInfo()->FindObject("comment")); | |
230 | if (!comment && fInput) | |
231 | comment = dynamic_cast<TNamed*>(fInput->FindObject("comment")); | |
6c3d6245 | 232 | |
233 | if (comment) | |
1d7991a5 | 234 | { |
6c3d6245 | 235 | AliDebug(AliLog::kInfo, Form("INFO: Found comment in input list: %s \n", comment->GetTitle())); |
1d7991a5 | 236 | } |
237 | else | |
238 | return; | |
6c3d6245 | 239 | |
240 | TFile* file = TFile::Open(Form("rocESD_%s.root",comment->GetTitle()), "RECREATE"); | |
2d9e89d4 | 241 | |
1d7991a5 | 242 | for (Int_t i=0; i<kTPCHists; i++) |
483b1eb8 | 243 | if (fClusterHistograms[i]) { |
9cc7192c | 244 | fClusterHistograms[i]->SaveHistograms(); |
483b1eb8 | 245 | TCanvas* c = fClusterHistograms[i]->DrawHistograms(); |
6c3d6245 | 246 | c->SaveAs(Form("plots_%s_%s.eps",comment->GetTitle(),c->GetName())); |
247 | c->SaveAs(Form("plots_%s_%s.gif",comment->GetTitle(),c->GetName())); | |
248 | ||
249 | c->Close(); | |
250 | delete c; | |
483b1eb8 | 251 | } |
df71af87 | 252 | file->Close(); |
253 | } |