]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/TRD/AliHLTTRDTrackerComponent.cxx
Moved old AliMagFCheb to AliMagF, small fixes/optimizations in field classes
[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"
f51cb94a 41#include "AliMagFMaps.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)
58 , fField(NULL)
59 , fGeometryFileName("")
60 , fGeometryFile(NULL)
61 , fGeoManager(NULL)
62 , fTracker(NULL)
0af7cb2e 63{
3b021c25 64 // Default constructor
0af7cb2e 65
66 fGeometryFileName = getenv("ALICE_ROOT");
67 fGeometryFileName += "/HLT/TRD/geometry.root";
68}
69
70AliHLTTRDTrackerComponent::~AliHLTTRDTrackerComponent()
71{
3b021c25 72 // Destructor
0af7cb2e 73}
74
75const char* AliHLTTRDTrackerComponent::GetComponentID()
76{
3b021c25 77 // Return the component ID const char *
0af7cb2e 78 return "TRDTracker"; // The ID of this component
79}
80
81void AliHLTTRDTrackerComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
82{
3b021c25 83 // Get the list of input data
0af7cb2e 84 list.clear(); // We do not have any requirements for our input data type(s).
efbd3157 85 list.push_back( AliHLTTRDDefinitions::fgkClusterDataType );
0af7cb2e 86}
87
88AliHLTComponent_DataType AliHLTTRDTrackerComponent::GetOutputDataType()
89{
3b021c25 90 // Get the output data type
efbd3157 91 return AliHLTTRDDefinitions::fgkClusterDataType;
0af7cb2e 92}
93
94void AliHLTTRDTrackerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
95{
3b021c25 96 // Get the output data size
0af7cb2e 97 constBase = 0;
98 inputMultiplier = ((double)fOutputPercentage)/100.0;
99}
100
101// Spawn function, return new instance of this class
102AliHLTComponent* AliHLTTRDTrackerComponent::Spawn()
103{
3b021c25 104 // Spawn function, return new instance of this class
0af7cb2e 105 return new AliHLTTRDTrackerComponent;
106};
107
108int AliHLTTRDTrackerComponent::DoInit( int argc, const char** argv )
109{
110 // perform initialization. We check whether our relative output size is specified in the arguments.
111 fOutputPercentage = 100;
112 int i = 0;
113 char* cpErr;
114 while ( i < argc )
115 {
886e8d3d 116 HLTDebug("argv[%d] == %s", i, argv[i] );
0af7cb2e 117 if ( !strcmp( argv[i], "output_percentage" ) )
118 {
119 if ( i+1>=argc )
120 {
886e8d3d 121 HLTError("Missing output_percentage parameter");
0af7cb2e 122 return ENOTSUP;
123 }
886e8d3d 124 HLTDebug("Arguments", "argv[%d+1] == %s", i, argv[i+1] );
0af7cb2e 125 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
126 if ( *cpErr )
127 {
886e8d3d 128 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
0af7cb2e 129 return EINVAL;
130 }
886e8d3d 131 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
0af7cb2e 132 i += 2;
133 continue;
134 }
135
136 if ( strcmp( argv[i], "-cdb" ) == 0)
137 {
138 if ( i+1 >= argc )
139 {
886e8d3d 140 HLTError("Missing -cdb argument");
0af7cb2e 141 return ENOTSUP;
142 }
143 fStrorageDBpath = argv[i+1];
886e8d3d 144 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
0af7cb2e 145 i += 2;
146 continue;
147 }
148
149 if ( strcmp( argv[i], "-geometry" ) == 0)
150 {
151 if ( i+1 >= argc )
152 {
886e8d3d 153 HLTError("Missing -geometry argument");
0af7cb2e 154 return ENOTSUP;
155 }
156 fGeometryFileName = argv[i+1];
886e8d3d 157 HLTInfo("GeomFile storage is %s", fGeometryFileName.c_str() );
0af7cb2e 158 i += 2;
159 continue;
160 }
161
886e8d3d 162 HLTError("Unknown option '%s'", argv[i] );
0af7cb2e 163 return EINVAL;
164 }
165
f51cb94a 166 //init alifield map - temporarly fixed - should come from a DB
167 fField = new AliMagFMaps("Maps","Maps", 2, 1., 10., 1);
168 if (fField)
169 AliTracker::SetFieldMap(fField,1);
170 else
886e8d3d 171 HLTError("Unable to init the field");
b0517ac4 172
173 fCDB = AliCDBManager::Instance();
174 if (!fCDB)
175 {
886e8d3d 176 HLTError("Could not get CDB instance", "fCDB 0x%x", fCDB);
b0517ac4 177 }
178 else
179 {
180 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
181 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
886e8d3d 182 HLTDebug("fCDB 0x%x", fCDB);
b0517ac4 183 }
f51cb94a 184
0af7cb2e 185 fGeometryFile = TFile::Open(fGeometryFileName.c_str());
186 if (fGeometryFile)
187 {
188 fGeoManager = (TGeoManager *)fGeometryFile->Get("Geometry");
051a0e2d 189 //fTracker = new AliTRDtrackerHLT(fGeometryFile);
886e8d3d 190 AliTRDrecoParam *fPars = AliTRDrecoParam::GetLowFluxParam();
191 //fPars->SetSeeding(kTRUE);
192 //fPars->SetStreamLevel(0);
193 AliTRDReconstructor reconstructor; reconstructor.SetRecoParam(fPars);
194 // write clusters [cw] = true
195 // track seeding (stand alone tracking) [sa] = true
196 // PID method in reconstruction (NN) [nn] = true
197 // write online tracklets [tw] = false
198 // drift gas [ar] = false
199 reconstructor.SetOption("cw,sa");
051a0e2d 200 fTracker = new AliTRDtracker(fGeometryFile);
886e8d3d 201 //fTracker = new AliTRDtracker(fGeometryFile);
0af7cb2e 202 }
203 else
204 {
886e8d3d 205 HLTError("Unable to open file. FATAL!");
0af7cb2e 206 return -1;
207 }
208
209 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
210 if (calibra == 0)
211 {
886e8d3d 212 HLTError("Calibration Histos ::Instance failed");
0af7cb2e 213 return -1;
214 }
215 else
216 {
0af7cb2e 217 calibra->Init2Dhistos();
218 }
219
220 return 0;
221}
222
223int AliHLTTRDTrackerComponent::DoDeinit()
224{
3b021c25 225 // Deinitialization of the component
226
f51cb94a 227 delete fField;
3b021c25 228 fField = 0;
f51cb94a 229
0af7cb2e 230 delete fTracker;
231 fTracker = 0;
232
233 if (fGeometryFile)
234 {
235 fGeometryFile->Close();
236 delete fGeometryFile;
3b021c25 237 fGeometryFile = 0;
0af7cb2e 238 }
239
240 AliTRDCalibraFillHisto *calibra = AliTRDCalibraFillHisto::Instance();
241 if (calibra)
242 {
3b021c25 243 // should not write in here!
0af7cb2e 244 calibra->Write2d();
245 calibra->Destroy();
246 }
247
248 return 0;
249}
250
4646c6e3 251int AliHLTTRDTrackerComponent::DoEvent( const AliHLTComponentEventData & /*evtData*/,
252 AliHLTComponentTriggerData & /*trigData*/ )
0af7cb2e 253{
3b021c25 254 // Process an event
255
886e8d3d 256 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
4646c6e3 257 HLTInfo("NofBlocks %lu", GetNumberOfInputBlocks() );
0af7cb2e 258
c7500dae 259 AliHLTUInt32_t dBlockSpecification = 0;
0af7cb2e 260
051a0e2d 261 //implement a usage of the following
886e8d3d 262 // AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
263 // AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
264 // void *triggerData = trigData.fData;
4646c6e3 265 //HLTDebug("Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
051a0e2d 266
efbd3157 267 AliHLTComponentBlockData *dblock = (AliHLTComponentBlockData *)GetFirstInputBlock( AliHLTTRDDefinitions::fgkClusterDataType );
0af7cb2e 268 if (dblock != 0)
269 {
c7500dae 270 dBlockSpecification = dblock->fSpecification;
0af7cb2e 271 }
272 else
273 {
886e8d3d 274 HLTWarning("First Input Block not found! 0x%x", dblock);
0af7cb2e 275 return -1;
276 }
277
278 int ibForce = 0;
051a0e2d 279 TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkClusterDataType, "TTree", ibForce);
886e8d3d 280 HLTInfo("Pointer = 0x%x", tobjin);
0af7cb2e 281
051a0e2d 282 TTree *clusterTree = (TTree*)tobjin;
283 if (!clusterTree)
284 {
886e8d3d 285 HLTWarning("First Input Block not a tree! 0x%x", tobjin);
051a0e2d 286 return -1;
287 }
288
886e8d3d 289 HLTInfo("Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
051a0e2d 290
0af7cb2e 291 while (tobjin != 0)
292 {
051a0e2d 293 if (clusterTree)
0af7cb2e 294 {
886e8d3d 295 HLTInfo("Pointer = 0x%x Name = %s", clusterTree, clusterTree->GetName());
051a0e2d 296 Int_t iNentries = clusterTree->GetEntries();
886e8d3d 297 HLTInfo("N of tree entries = %d", iNentries);
051a0e2d 298 fTracker->LoadClusters(clusterTree);
0af7cb2e 299 }
300 else
301 {
886e8d3d 302 HLTError("Tree Pointer = 0x%x", clusterTree);
0af7cb2e 303 }
304
305 tobjin = (TObject *)GetNextInputObject( ibForce );
886e8d3d 306 HLTInfo("Pointer = 0x%x", tobjin);
051a0e2d 307 clusterTree = (TTree*)tobjin;
0af7cb2e 308 }
309
808618f5 310 fTracker->SetAddTRDseeds();
311
312 AliESDfriend *esdFriend = new AliESDfriend();
313
af885e0f 314 AliESDEvent *esd = new AliESDEvent();
315 esd->CreateStdContent();
0af7cb2e 316 fTracker->PropagateBack(esd);
051a0e2d 317 fTracker->RefitInward(esd);
808618f5 318 fTracker->Clusters2Tracks(esd);
0af7cb2e 319
808618f5 320 esd->GetESDfriend(esdFriend);
0af7cb2e 321 //here transport the esd tracks further
051a0e2d 322
323 Int_t nTracks = esd->GetNumberOfTracks();
324 Int_t nTRDTracks = esd->GetNumberOfTrdTracks();
886e8d3d 325 HLTInfo( "Number of tracks %d Number of TRD tracks %d", nTracks, nTRDTracks);
051a0e2d 326
051a0e2d 327
328 for (Int_t it = 0; it < nTracks; it++)
329 {
330 AliESDtrack* track = esd->GetTrack(it);
886e8d3d 331 HLTInfo("Track %d 0x%x Pt %1.2f", it, track, track->Pt());
c7500dae 332 PushBack(track, AliHLTTRDDefinitions::fgkTRDSATracksDataType, ++dBlockSpecification);
051a0e2d 333 }
334
0af7cb2e 335 delete esd;
808618f5 336 delete esdFriend;
337
051a0e2d 338 delete clusterTree;
339
0af7cb2e 340 return 0;
341}