]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TRD/AliHLTTRDTrackerComponent.cxx
The present commit corresponds to an important change in the way the
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDTrackerComponent.cxx
CommitLineData
0af7cb2e 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTTRDTrackerComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
21 @date
22 @brief A TRDTracker processing component for the HLT. */
23
24#if __GNUC__ >= 3
25using namespace std;
26#endif
27
28#include "TFile.h"
051a0e2d 29#include "TChain.h"
0af7cb2e 30
31#include "AliHLTTRDTrackerComponent.h"
32#include "AliHLTTRDDefinitions.h"
0af7cb2e 33#include "AliCDBManager.h"
f51cb94a 34
0af7cb2e 35#include "AliTRDReconstructor.h"
9fa37a91 36#include "AliTRDrecoParam.h"
af885e0f 37#include "AliESDEvent.h"
808618f5 38//#include "AliTRDtrackerHLT.h"
051a0e2d 39#include "AliTRDtracker.h"
0af7cb2e 40#include "AliTRDCalibraFillHisto.h"
f7a1cc68 41#include "AliMagF.h"
0af7cb2e 42#include "AliTRDcluster.h"
808618f5 43#include "AliESDfriend.h"
0af7cb2e 44#include <cstdlib>
45#include <cerrno>
46#include <string>
47
48// this is a global object used for automatic component registration, do not use this
49AliHLTTRDTrackerComponent gAliHLTTRDTrackerComponent;
50
51ClassImp(AliHLTTRDTrackerComponent);
52
53AliHLTTRDTrackerComponent::AliHLTTRDTrackerComponent()
3b021c25 54 : AliHLTProcessor()
55 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
56 , fStrorageDBpath("local://$ALICE_ROOT")
57 , fCDB(NULL)
3b021c25 58 , fGeometryFileName("")
59 , fGeometryFile(NULL)
60 , fGeoManager(NULL)
61 , fTracker(NULL)
0af7cb2e 62{
3b021c25 63 // Default constructor
0af7cb2e 64
65 fGeometryFileName = getenv("ALICE_ROOT");
66 fGeometryFileName += "/HLT/TRD/geometry.root";
67}
68
69AliHLTTRDTrackerComponent::~AliHLTTRDTrackerComponent()
70{
3b021c25 71 // Destructor
0af7cb2e 72}
73
74const char* AliHLTTRDTrackerComponent::GetComponentID()
75{
3b021c25 76 // Return the component ID const char *
0af7cb2e 77 return "TRDTracker"; // The ID of this component
78}
79
80void AliHLTTRDTrackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
81{
3b021c25 82 // Get the list of input data
0af7cb2e 83 list.clear(); // We do not have any requirements for our input data type(s).
efbd3157 84 list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
0af7cb2e 85}
86
87AliHLTComponent_DataType AliHLTTRDTrackerComponent::GetOutputDataType()
88{
3b021c25 89 // Get the output data type
efbd3157 90 return AliHLTTRDDefinitions::fgkClusterDataType;
0af7cb2e 91}
92
93void AliHLTTRDTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
94{
3b021c25 95 // Get the output data size
0af7cb2e 96 constBase = 0;
97 inputMultiplier = ((double)fOutputPercentage)/100.0;
98}
99
100// Spawn function, return new instance of this class
101AliHLTComponent* AliHLTTRDTrackerComponent::Spawn()
102{
3b021c25 103 // Spawn function, return new instance of this class
0af7cb2e 104 return new AliHLTTRDTrackerComponent;
105};
106
107int AliHLTTRDTrackerComponent::DoInit( int argc, const char** argv )
108{
109 // perform initialization. We check whether our relative output size is specified in the arguments.
110 fOutputPercentage = 100;
111 int i = 0;
112 char* cpErr;
113 while ( i < argc )
114 {
886e8d3d 115 HLTDebug("argv[%d] == %s", i, argv[i] );
0af7cb2e 116 if ( !strcmp( argv[i], "output_percentage" ) )
117 {
118 if ( i+1>=argc )
119 {
886e8d3d 120 HLTError("Missing output_percentage parameter");
0af7cb2e 121 return ENOTSUP;
122 }
886e8d3d 123 HLTDebug("Arguments", "argv[%d+1] == %s", i, argv[i+1] );
0af7cb2e 124 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
125 if ( *cpErr )
126 {
886e8d3d 127 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
0af7cb2e 128 return EINVAL;
129 }
886e8d3d 130 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
0af7cb2e 131 i += 2;
132 continue;
133 }
134
135 if ( strcmp( argv[i], "-cdb" ) == 0)
136 {
137 if ( i+1 >= argc )
138 {
886e8d3d 139 HLTError("Missing -cdb argument");
0af7cb2e 140 return ENOTSUP;
141 }
142 fStrorageDBpath = argv[i+1];
886e8d3d 143 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
0af7cb2e 144 i += 2;
145 continue;
146 }
147
148 if ( strcmp( argv[i], "-geometry" ) == 0)
149 {
150 if ( i+1 >= argc )
151 {
886e8d3d 152 HLTError("Missing -geometry argument");
0af7cb2e 153 return ENOTSUP;
154 }
155 fGeometryFileName = argv[i+1];
886e8d3d 156 HLTInfo("GeomFile storage is %s", fGeometryFileName.c_str() );
0af7cb2e 157 i += 2;
158 continue;
159 }
160
886e8d3d 161 HLTError("Unknown option '%s'", argv[i] );
0af7cb2e 162 return EINVAL;
163 }
164
b0517ac4 165
166 fCDB = AliCDBManager::Instance();
167 if (!fCDB)
168 {
886e8d3d 169 HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
b0517ac4 170 }
171 else
172 {
173 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
174 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
886e8d3d 175 HLTDebug("fCDB 0x%x", fCDB);
b0517ac4 176 }
f51cb94a 177
0af7cb2e 178 fGeometryFile = TFile::Open(fGeometryFileName.c_str());
179 if (fGeometryFile)
180 {
181 fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
051a0e2d 182 //fTracker = new AliTRDtrackerHLT(fGeometryFile);
886e8d3d 183 AliTRDrecoParam *fPars = AliTRDrecoParam::GetLowFluxParam();
184 //fPars->SetSeeding(kTRUE);
185 //fPars->SetStreamLevel(0);
186 AliTRDReconstructor reconstructor; reconstructor.SetRecoParam(fPars);
187 // write clusters [cw] = true
188 // track seeding (stand alone tracking) [sa] = true
189 // PID method in reconstruction (NN) [nn] = true
190 // write online tracklets [tw] = false
191 // drift gas [ar] = false
192 reconstructor.SetOption("cw,sa");
051a0e2d 193 fTracker = new AliTRDtracker(fGeometryFile);
886e8d3d 194 //fTracker = new AliTRDtracker(fGeometryFile);
0af7cb2e 195 }
196 else
197 {
886e8d3d 198 HLTError("Unable to open file. FATAL!");
0af7cb2e 199 return -1;
200 }
201
202 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
203 if (calibra == 0)
204 {
886e8d3d 205 HLTError("Calibration Histos ::Instance failed");
0af7cb2e 206 return -1;
207 }
208 else
209 {
0af7cb2e 210 calibra->Init2Dhistos();
211 }
212
213 return 0;
214}
215
216int AliHLTTRDTrackerComponent::DoDeinit()
217{
3b021c25 218 // Deinitialization of the component
219
0af7cb2e 220 delete fTracker;
221 fTracker = 0;
222
223 if (fGeometryFile)
224 {
225 fGeometryFile->Close();
226 delete fGeometryFile;
3b021c25 227 fGeometryFile = 0;
0af7cb2e 228 }
229
230 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
231 if (calibra)
232 {
3b021c25 233 // should not write in here!
0af7cb2e 234 calibra->Write2d();
235 calibra->Destroy();
236 }
237
238 return 0;
239}
240
4646c6e3 241int AliHLTTRDTrackerComponent::DoEvent( const AliHLTComponentEventData & /*evtData*/,
242 AliHLTComponentTriggerData & /*trigData*/ )
0af7cb2e 243{
3b021c25 244 // Process an event
245
886e8d3d 246 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
4646c6e3 247 HLTInfo("NofBlocks %lu", GetNumberOfInputBlocks() );
0af7cb2e 248
c7500dae 249 AliHLTUInt32_t dBlockSpecification = 0;
0af7cb2e 250
051a0e2d 251 //implement a usage of the following
886e8d3d 252 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
253 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
254 // void *triggerData = trigData.fData;
4646c6e3 255 //HLTDebug("Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
051a0e2d 256
efbd3157 257 AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
0af7cb2e 258 if (dblock != 0)
259 {
c7500dae 260 dBlockSpecification = dblock->fSpecification;
0af7cb2e 261 }
262 else
263 {
886e8d3d 264 HLTWarning("First Input Block not found! 0x%x", dblock);
0af7cb2e 265 return -1;
266 }
267
268 int ibForce = 0;
051a0e2d 269 TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
886e8d3d 270 HLTInfo("Pointer = 0x%x", tobjin);
0af7cb2e 271
051a0e2d 272 TTree *clusterTree = (TTree*)tobjin;
273 if (!clusterTree)
274 {
886e8d3d 275 HLTWarning("First Input Block not a tree! 0x%x", tobjin);
051a0e2d 276 return -1;
277 }
278
886e8d3d 279 HLTInfo("Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
051a0e2d 280
0af7cb2e 281 while (tobjin != 0)
282 {
051a0e2d 283 if (clusterTree)
0af7cb2e 284 {
886e8d3d 285 HLTInfo("Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
051a0e2d 286 Int_t iNentries = clusterTree->GetEntries();
886e8d3d 287 HLTInfo("N of tree entries = %d", iNentries);
051a0e2d 288 fTracker->LoadClusters(clusterTree);
0af7cb2e 289 }
290 else
291 {
886e8d3d 292 HLTError("Tree Pointer = 0x%x", clusterTree);
0af7cb2e 293 }
294
295 tobjin = (TObject *)GetNextInputObject( ibForce );
886e8d3d 296 HLTInfo("Pointer = 0x%x", tobjin);
051a0e2d 297 clusterTree = (TTree*)tobjin;
0af7cb2e 298 }
299
808618f5 300 fTracker->SetAddTRDseeds();
301
302 AliESDfriend *esdFriend = new AliESDfriend();
303
af885e0f 304 AliESDEvent *esd = new AliESDEvent();
305 esd->CreateStdContent();
0af7cb2e 306 fTracker->PropagateBack(esd);
051a0e2d 307 fTracker->RefitInward(esd);
808618f5 308 fTracker->Clusters2Tracks(esd);
0af7cb2e 309
808618f5 310 esd->GetESDfriend(esdFriend);
0af7cb2e 311 //here transport the esd tracks further
051a0e2d 312
313 Int_t nTracks = esd->GetNumberOfTracks();
314 Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
886e8d3d 315 HLTInfo( "Number of tracks %d Number of TRD tracks %d", nTracks, nTRDTracks);
051a0e2d 316
051a0e2d 317
318 for (Int_t it = 0; it < nTracks; it++)
319 {
320 AliESDtrack* track = esd->GetTrack(it);
886e8d3d 321 HLTInfo("Track %d 0x%x Pt %1.2f", it, track, track->Pt());
c7500dae 322 PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType, ++dBlockSpecification);
051a0e2d 323 }
324
0af7cb2e 325 delete esd;
808618f5 326 delete esdFriend;
327
051a0e2d 328 delete clusterTree;
329
0af7cb2e 330 return 0;
331}