1 ////////////////////////////////////////////////////////////////////////
6 // author: Jiri Chudoba based on code of Jourij Belikov
9 // reconstructs of tracks in TPC inthe following steps:
10 // TPC cluster finding
13 // Int_t nEvents ... nr of events to process
14 // Int_t firstEventNr ... first event number (starts from 0)
15 // TString fileNameHits ... name of file with hits
16 // TString fileNameDigits .. name of file with TPC digits
17 // TString fileNameClusters .. name of file with TPC clusters (output)
18 // TString fileNameTracks .. name of file with TPC tracks (output)
20 // default file names correspond to pp production (2002-04)
24 // 22.08.2002 ... first version
26 ////////////////////////////////////////////////////////////////////////
28 #if !defined(__CINT__) || defined(__MAKECINT__)
33 #include "TPC/alles.h"
34 #include "TPC/AliTPCtracker.h"
35 #include "TPC/AliTPCclusterer.h"
36 #include "STEER/AliRun.h"
37 #include "STEER/AliHeader.h"
38 #include "STEER/AliGenEventHeader.h"
39 #include "STEER/AliMagF.h"
45 Int_t TPCFindClusters(Int_t nEvents=1, Int_t firstEvent=0,
46 TString fileNameDigits="rfio:galiceSDR.root",
47 TString fileNameClusters="tpc.clusters.root");
48 Int_t TPCFindClusters(Int_t nEvents, Int_t firstEvent,
49 TFile* fileDigits, TFile* fileClusters,
50 AliTPCParam* paramTPC=0);
51 Int_t TPCFindTracks(Int_t nEvents=1, Int_t firstEvent=0,
52 TString fileNameClusters="tpc.clusters.root",
53 TString fileNameTracks="tpc.tracks.root");
54 Int_t TPCFindTracks(Int_t nEvents, Int_t firstEvent,
55 TFile* fileClusters, TFile* fileTracks,
56 AliTPCParam* paramTPC=0);
58 AliTPCParam* LoadTPCParam(TFile *file);
59 void FindVertex(Int_t iEvent, Double_t *vertex);
60 void PrintVertex(TArrayF &primaryVertex);
61 Int_t SetFieldFactor(TString fileName, Bool_t closeFile = kTRUE);
62 Int_t SetFieldFactor(TFile* file, Bool_t deletegAlice = kTRUE);
63 Int_t SetFieldFactor();
65 Int_t AliTPCTracking(Int_t nEvents=1, Int_t firstEvent=0,
66 TString fileNameHits="rfio:galice.root",
67 TString fileNameDigits="rfio:galiceSDR.root",
68 TString fileNameClusters="tpc.clusters.root",
69 TString fileNameTracks="tpc.tracks.root");
71 ////////////////////////////////////////////////////////////////////////
72 Int_t AliTPCTracking( Int_t nEvents, Int_t firstEvent,
74 TString fileNameDigits,
75 TString fileNameClusters,
76 TString fileNameTracks) {
78 SetFieldFactor(fileNameHits,kFALSE);
80 // ********** Find TPC clusters *********** //
81 if (TPCFindClusters(nEvents,firstEvent,fileNameDigits,fileNameClusters)) {
82 cerr<<"Failed to get TPC clusters: !\n";
86 // ********** Find TPC tracks *********** //
87 if (TPCFindTracks(nEvents,firstEvent,fileNameClusters,fileNameTracks)) {
88 cerr<<"Failed to get TPC tracks !\n";
95 ////////////////////////////////////////////////////////////////////////
96 Int_t TPCFindClusters(Int_t nEvents, Int_t firstEvent,
97 TString fileNameDigits, TString fileNameClusters) {
100 const Char_t *name="TPCFindClusters";
101 if (gDEBUG>1) cout<<name<<" starts...\n";
102 if (gDEBUG>1) gBenchmark->Start(name);
103 TFile *fileClusters = TFile::Open(fileNameClusters,"recreate");
104 TFile *fileDigits = TFile::Open(fileNameDigits);
105 if (!fileDigits->IsOpen()) {
106 cerr<<"Cannnot open "<<fileNameDigits<<" !\n";
109 if (!fileClusters->IsOpen()) {
110 cerr<<"Cannnot open "<<fileNameClusters<<" !\n";
114 rc = TPCFindClusters(nEvents,firstEvent,fileDigits,fileClusters);
117 fileClusters->Close();
120 if (gDEBUG>1) gBenchmark->Stop(name);
121 if (gDEBUG>1) gBenchmark->Show(name);
125 ////////////////////////////////////////////////////////////////////////
126 Int_t TPCFindClusters(Int_t nEvents, Int_t firstEvent,
127 TFile* fileDigits, TFile* fileClusters,
128 AliTPCParam* paramTPC) {
131 if (!paramTPC) paramTPC = LoadTPCParam(fileDigits);
132 if (!paramTPC) return 1;
134 for (Int_t iEvent = firstEvent; iEvent < firstEvent+nEvents; iEvent++){
135 if (gDEBUG > 2) cout<<"TPCFindClusters: event "<<iEvent<<endl;
136 AliTPCclusterer::Digits2Clusters(paramTPC, fileClusters, iEvent);
140 ////////////////////////////////////////////////////////////////////////
141 Int_t TPCFindTracks(Int_t nEvents, Int_t firstEvent,
142 TString fileNameClusters, TString fileNameTracks) {
145 const Char_t *name="TPCFindTracks";
146 if (gDEBUG>1) cout<<name<<" starts"<<endl;
147 if (gDEBUG>1) gBenchmark->Start(name);
148 TFile *fileTracks = TFile::Open(fileNameTracks,"recreate");
149 TFile *fileClusters =TFile::Open(fileNameClusters);
151 rc = TPCFindTracks(nEvents, firstEvent, fileClusters, fileTracks);
153 fileClusters->Close();
157 if (gDEBUG>1) gBenchmark->Stop(name);
158 if (gDEBUG>1) gBenchmark->Show(name);
162 ////////////////////////////////////////////////////////////////////////
163 Int_t TPCFindTracks(Int_t nEvents, Int_t firstEvent,
164 TFile *fileClusters, TFile * fileTracks,
165 AliTPCParam* paramTPC) {
168 if (!paramTPC) paramTPC = LoadTPCParam(fileClusters);
169 if (!paramTPC) return 1;
171 for (Int_t iEvent = firstEvent; iEvent < firstEvent+nEvents; iEvent++){
172 if (gDEBUG > 2) cout<<"TPCFindTracks: event "<<iEvent<<endl;
173 AliTPCtracker *tracker = new AliTPCtracker(paramTPC,iEvent);
175 FindVertex(iEvent,vertex);
176 tracker->SetVertex(vertex);
178 rc = tracker->Clusters2Tracks(0,fileTracks);
184 ////////////////////////////////////////////////////////////////////////
185 Int_t SetFieldFactor() {
187 AliKalmanTrack::SetConvConst(1000/0.299792458/gAlice->Field()->SolenoidField());
188 if (gDEBUG > 2) cout<<"Magnetic field in kGauss: "<<gAlice->Field()->SolenoidField()<<endl;
191 ////////////////////////////////////////////////////////////////////////
192 Int_t SetFieldFactor(TFile *file, Bool_t deletegAlice) {
194 if (!(gAlice=(AliRun*)file->Get("gAlice"))) {
195 cerr<<"gAlice has not been found in file "<<file->GetName();
198 Int_t rc = SetFieldFactor();
205 ////////////////////////////////////////////////////////////////////////
206 Int_t SetFieldFactor(TString fileName, Bool_t closeFile) {
208 TFile *file=TFile::Open(fileName);
209 if (!file->IsOpen()) {cerr<<"Cannnot open "<<fileName<<" !\n"; return 1;}
210 Int_t rc = SetFieldFactor(file, closeFile) ;
211 if (closeFile) file->Close();
214 ////////////////////////////////////////////////////////////////////////
215 AliTPCParam* LoadTPCParam(TFile *file) {
218 sprintf(paramName,"75x40_100x60_150x60");
219 AliTPCParam *paramTPC=(AliTPCParam*)file->Get(paramName);
221 if (gDEBUG > 1) cout<<"TPC parameters "<<paramName<<" found."<<endl;
223 cerr<<"TPC parameters not found. Create new (they may be incorrect)."
225 paramTPC = new AliTPCParamSR;
229 // the older version of parameters can be accessed with this code.
230 // In some cases, we have old parameters saved in the file but
231 // digits were created with new parameters, it can be distinguish
232 // by the name of TPC TreeD. The code here is just for the case
233 // we would need to compare with old data, uncomment it if needed.
235 // char paramName[50];
236 // sprintf(paramName,"75x40_100x60");
237 // AliTPCParam *paramTPC=(AliTPCParam*)in->Get(paramName);
239 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
241 // sprintf(paramName,"75x40_100x60_150x60");
242 // paramTPC=(AliTPCParam*)in->Get(paramName);
244 // cout<<"TPC parameters "<<paramName<<" found."<<endl;
246 // cerr<<"TPC parameters not found. Create new (they may be incorrect)."
248 // paramTPC = new AliTPCParamSR;
255 ////////////////////////////////////////////////////////////////////////
256 void FindVertex(Int_t eventNr, Double_t *vertex) {
258 vertex[0] = vertex[1] = vertex[2] = 0.;
260 cerr<<"gAlice was not found! Using vertex position (0,0,0).\n";
264 gAlice->GetEvent(eventNr);
265 AliHeader *header = gAlice->GetHeader();
267 cerr<<"header was not found!\n";
270 AliGenEventHeader* genEventHeader = header->GenEventHeader();
271 if (!genEventHeader) {
272 cerr<<"AliGenEventHeader was not found!\n";
276 TArrayF primaryVertex(3);
277 genEventHeader->PrimaryVertex(primaryVertex);
278 PrintVertex(primaryVertex);
279 vertex[0] = static_cast<Double_t>(primaryVertex[0]);
280 vertex[1] = static_cast<Double_t>(primaryVertex[1]);
281 vertex[2] = static_cast<Double_t>(primaryVertex[2]);
283 delete genEventHeader;
287 ////////////////////////////////////////////////////////////////////////
288 void PrintVertex(TArrayF &primaryVertex)
291 <<primaryVertex[0]<<" "
292 <<primaryVertex[1]<<" "
293 <<primaryVertex[2]<<" "<<endl;
296 ////////////////////////////////////////////////////////////////////////