1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
19 // This class analyses TPC cosmics data from the ESD and the ESDfriend
21 // Authors: Jan.Fiete.Grosse-Oetringhaus@cern.ch, Claus.Jorgensen@cern.ch
24 #include "AliROCESDAnalysisSelector.h"
28 #include <AliESDfriend.h>
29 #include <../TPC/AliTPCclusterMI.h>
30 #include <../TPC/AliTPCseed.h>
36 #include <TObjArray.h>
38 #include "TPC/AliTPCClusterHistograms.h"
40 ClassImp(AliROCESDAnalysisSelector)
42 AliROCESDAnalysisSelector::AliROCESDAnalysisSelector() :
48 // Constructor. Initialization of pointers
50 fMinNumberOfRowsIsTrack = 5;
52 fObjectsToSave = new TObjArray();
54 for (Int_t i=0; i<kTPCHists; i++)
55 fClusterHistograms[i] = 0;
58 AliROCESDAnalysisSelector::~AliROCESDAnalysisSelector()
65 void AliROCESDAnalysisSelector::SlaveBegin(TTree* tree)
69 AliSelector::SlaveBegin(tree);
72 void AliROCESDAnalysisSelector::Init(TTree *tree)
74 // The Init() function is called when the selector needs to initialize
75 // a new tree or chain. Typically here the branch addresses of the tree
76 // will be set. It is normaly not necessary to make changes to the
77 // generated code, but the routine can be extended by the user if needed.
78 // Init() will be called many times when running with PROOF.
80 AliSelector::Init(tree);
82 printf("Init called %p\n", (void*) fESDfriend);
87 tree->SetBranchAddress("ESDfriend", &fESDfriend);
89 tree->SetBranchStatus("*", 0);
90 tree->SetBranchStatus("fTracks.*", 1);
91 tree->SetBranchStatus("fTimeStamp", 1);
92 //tree->SetBranchStatus("fTracks.fCalibContainer", 0);
96 AliDebug(AliLog::kInfo, "INFO: Found ESDfriend branch in chain.");
99 Bool_t AliROCESDAnalysisSelector::Process(Long64_t entry)
102 // Implement your analysis here. Do not forget to call the parent class Process by
103 // if (AliSelector::Process(entry) == kFALSE)
107 if (AliSelector::Process(entry) == kFALSE)
110 // Check prerequisites
113 AliDebug(AliLog::kError, "ESD branch not available");
117 // Check prerequisites
120 AliDebug(AliLog::kError, "ESDfriend branch not available");
124 fESD->SetESDfriend(fESDfriend);
126 Int_t flag = ProcessEvent(kFALSE);
128 ProcessEvent(kTRUE, Form("flash_entry%d",entry));
130 // TODO This should not be needed, the TTree::GetEntry() should take care of this, maybe because it has a reference member, to be analyzed
131 // if the ESDfriend is not deleted we get a major memory leak
132 // here the esdfriend seems to be also deleted, very weird behaviour....
144 Int_t AliROCESDAnalysisSelector::ProcessEvent(Bool_t detailedHistogram, const Char_t* label)
147 // Looping over tracks and clusters in event and filling histograms
149 // - if detailedHistogram = kTRUE special histograms are saved (in fObjectsToSave)
150 // - the method returns
151 // 1 : if a "flash" is detected something special in this event
154 // save maximum 100 objects
155 if (detailedHistogram)
156 if (fObjectsToSave->GetSize()>10)
159 // for saving single events
160 AliTPCClusterHistograms* clusterHistograms[kTPCSectors];
161 for (Int_t i=0; i<kTPCSectors; i++)
162 clusterHistograms[i] = 0;
164 Bool_t intToReturn = 0;
166 Int_t nTracks = fESD->GetNumberOfTracks();
168 Int_t nSkippedSeeds = 0;
169 Int_t nSkippedTracks = 0;
171 // for "flash" detection
173 Float_t clusterQtotSumVsTime[250];
174 for (Int_t z=0; z<250; z++)
175 clusterQtotSumVsTime[z] = 0;
177 // loop over esd tracks
178 for (Int_t t=0; t<nTracks; t++)
180 AliESDtrack* esdTrack = dynamic_cast<AliESDtrack*> (fESD->GetTrack(t));
183 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve track %d.", t));
187 AliESDfriendTrack* friendtrack = const_cast<AliESDfriendTrack*> (dynamic_cast<const AliESDfriendTrack*> (esdTrack->GetFriendTrack()));
190 AliDebug(AliLog::kError, Form("ERROR: Could not retrieve friend of track %d.", t));
194 const AliTPCseed* seed = dynamic_cast<const AliTPCseed*> (friendtrack->GetCalibObject(0));
197 AliDebug(AliLog::kDebug, Form("ERROR: Could not retrieve seed of track %d.", t));
202 if (!AcceptTrack(seed, fMinNumberOfRowsIsTrack))
204 AliDebug(AliLog::kDebug, Form("INFO: Rejected track %d.", t));
209 for (Int_t clusterID = 0; clusterID < 160; clusterID++)
211 AliTPCclusterMI* cluster = seed->GetClusterPointer(clusterID);
215 Int_t detector = cluster->GetDetector();
217 if (detector < 0 || detector >= kTPCSectors) {
218 AliDebug(AliLog::kDebug, Form("We found a cluster from invalid sector %d", detector));
222 if (!detailedHistogram) {
224 // TODO: find a clever way to handle the time
227 if (fESD->GetTimeStamp()>1160000000)
228 time = fESD->GetTimeStamp();
230 if (!fClusterHistograms[detector])
231 fClusterHistograms[detector] = new AliTPCClusterHistograms(detector,"",time,time+5*60*60);
233 if (!fClusterHistograms[detector+kTPCSectors])
234 fClusterHistograms[detector+kTPCSectors] = new AliTPCClusterHistograms(detector,"",time,time+5*60*60, kTRUE);
236 fClusterHistograms[detector]->FillCluster(cluster, time);
237 fClusterHistograms[detector+kTPCSectors]->FillCluster(cluster, time);
239 Int_t z = Int_t(cluster->GetZ());
242 clusterQtotSumVsTime[z] += cluster->GetQ();
244 } // end of if !detailedHistograms
246 // if we need the detailed histograms for this event
247 if (!clusterHistograms[detector])
248 clusterHistograms[detector] = new AliTPCClusterHistograms(detector,label);
250 clusterHistograms[detector]->FillCluster(cluster);
255 for (Int_t i=0; i<kTPCHists; i++)
256 if (fClusterHistograms[i])
257 fClusterHistograms[i]->FillTrack(seed);
261 // check if there's a very large q deposit ("flash")
262 if (!detailedHistogram) {
263 for (Int_t z=0; z<250; z++) {
264 if (clusterQtotSumVsTime[z] > 150000) {
265 printf(Form(" \n -> sum of clusters at time %d %f \n \n", z, clusterQtotSumVsTime[z]));
271 for (Int_t i=0; i< kTPCSectors; i++) {
272 if (clusterHistograms[i]) {
273 if (fObjectsToSave->GetSize()<100) {
274 fObjectsToSave->Expand(fObjectsToSave->GetSize()+1);
275 fObjectsToSave->AddAt(clusterHistograms[i], fObjectsToSave->GetSize()-1);
282 // if (nSkippedSeeds > 0)
283 // printf("WARNING: The seed was not found for %d out of %d tracks.\n", nSkippedSeeds, nTracks);
284 // if (nSkippedTracks > 0)
285 // printf("INFO: Rejected %d out of %d tracks.\n", nSkippedTracks, nTracks);
290 Bool_t AliROCESDAnalysisSelector::AcceptTrack(const AliTPCseed* track, Int_t minRowsIncluded) {
292 // check if the track should be accepted.
294 const Int_t kMinClusters = 5;
295 const Float_t kMinRatio = 0.75;
296 const Float_t kMax1pt = 0.5;
298 Int_t nRowsUsedByTracks = 0;
299 Bool_t rowIncluded[96];
301 Float_t totalQtot = 0;
304 for(Int_t r=0; r<96; r++)
305 rowIncluded[r] = kFALSE;
307 for (Int_t clusterID = 0; clusterID < 160; clusterID++) {
308 AliTPCclusterMI* cluster = track->GetClusterPointer(clusterID);
313 Float_t qTot = cluster->GetQ();
318 if (!rowIncluded[cluster->GetRow()]) {
320 rowIncluded[cluster->GetRow()] = kTRUE;
324 Float_t meanQtot = totalQtot/nClusters;
329 if (nRowsUsedByTracks < minRowsIncluded)
332 // printf(Form(" TRACK: n clusters = %d, n pad rows = %d \n",track->GetNumberOfClusters(), nRowsUsedByTracks));
334 if (track->GetNumberOfClusters()<kMinClusters) return kFALSE;
335 Float_t ratio = track->GetNumberOfClusters()/(track->GetNFoundable()+1.);
336 if (ratio<kMinRatio) return kFALSE;
337 Float_t mpt = track->Get1Pt();
338 if (TMath::Abs(mpt)>kMax1pt) return kFALSE;
340 //if (TMath::Abs(track->GetZ())>240.) return kFALSE;
341 //if (TMath::Abs(track->GetZ())<10.) return kFALSE;
342 //if (TMath::Abs(track->GetTgl())>0.03) return kFALSE;
347 void AliROCESDAnalysisSelector::SlaveTerminate()
353 for (Int_t i=0; i<kTPCHists; i++)
354 if (fClusterHistograms[i])
355 fOutput->Add(fClusterHistograms[i]);
359 void AliROCESDAnalysisSelector::Terminate()
362 // read the objects from the output list and write them to a file
363 // the filename is modified by the object comment passed in the tree info or input list
370 for (Int_t i=0; i<kTPCSectors; i++)
371 fClusterHistograms[i] = dynamic_cast<AliTPCClusterHistograms*> (fOutput->FindObject(AliTPCClusterHistograms::FormDetectorName(i, kFALSE)));
372 for (Int_t i=0; i<kTPCSectors; i++)
373 fClusterHistograms[kTPCSectors+i] = dynamic_cast<AliTPCClusterHistograms*> (fOutput->FindObject(AliTPCClusterHistograms::FormDetectorName(i, kTRUE)));
377 if (fTree && fTree->GetUserInfo())
378 comment = dynamic_cast<TNamed*>(fTree->GetUserInfo()->FindObject("comment"));
379 if (!comment && fInput)
380 comment = dynamic_cast<TNamed*>(fInput->FindObject("comment"));
384 AliDebug(AliLog::kInfo, Form("INFO: Found comment in input list: %s \n", comment->GetTitle()));
389 TFile* file = TFile::Open(Form("rocESD_%s.root",comment->GetTitle()), "RECREATE");
391 for (Int_t i=0; i<kTPCHists; i++)
392 if (fClusterHistograms[i]) {
393 fClusterHistograms[i]->SaveHistograms();
394 TCanvas* c = fClusterHistograms[i]->DrawHistograms();
395 c->SaveAs(Form("plots_%s_%s.eps",comment->GetTitle(),c->GetName()));
396 c->SaveAs(Form("plots_%s_%s.gif",comment->GetTitle(),c->GetName()));
402 gDirectory->mkdir("saved_objects");
403 gDirectory->cd("saved_objects");
405 for (Int_t i=0; i<fObjectsToSave->GetSize(); i++) {
406 if (fObjectsToSave->At(i)) {
407 AliTPCClusterHistograms* clusterHistograms = dynamic_cast<AliTPCClusterHistograms*> (fObjectsToSave->At(i));
408 if (clusterHistograms)
409 clusterHistograms->SaveHistograms();
411 fObjectsToSave->At(i)->Write();
415 gDirectory->cd("../");