3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Gaute Ovrebekk <ovrebekk@ift.uib.no> *
8 //* for The ALICE HLT Project. *
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 //**************************************************************************
19 /** @file AliHLTTPCTrackHistoComponent.cxx
20 @author Gaute Ovrebekk, Matthias Richter
22 @brief The TPC conformal mapping tracker component.
30 #include "AliHLTTPCTrackHistoComponent.h"
31 #include "AliHLTTPCTransform.h"
32 #include "AliHLTTPCClusterDataFormat.h"
33 #include "AliHLTTPCTrackletDataFormat.h"
34 #include "AliHLTTPCMemHandler.h"
35 #include "AliHLTTPCDefinitions.h"
39 #include "TObjString.h"
40 #include "TObjArray.h"
41 #include "AliHLTTPCTrackArray.h"
42 #include "AliHLTTPCTrack.h"
44 //#include "AliHLTTPC.h"
48 AliHLTTPCTrackHistoComponent gAliHLTTPCTrackHistoComponent;
50 /** ROOT macro for the implementation of ROOT specific class methods */
51 ClassImp(AliHLTTPCTrackHistoComponent)
53 AliHLTTPCTrackHistoComponent::AliHLTTPCTrackHistoComponent()
60 // see header file for class documentation
62 // refer to README to build package
64 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
68 AliHLTTPCTrackHistoComponent::~AliHLTTPCTrackHistoComponent()
70 // see header file for class documentation
73 // Public functions to implement AliHLTComponent's interface.
74 // These functions are required for the registration process
76 const char* AliHLTTPCTrackHistoComponent::GetComponentID()
78 // see header file for class documentation
80 return "TPCTrackHisto";
83 void AliHLTTPCTrackHistoComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
85 // see header file for class documentation
87 list.push_back( AliHLTTPCDefinitions::fgkClustersDataType );
88 list.push_back( AliHLTTPCDefinitions::fgkTrackSegmentsDataType );
89 list.push_back( AliHLTTPCDefinitions::fgkTracksDataType );
92 AliHLTComponentDataType AliHLTTPCTrackHistoComponent::GetOutputDataType()
94 // see header file for class documentation
95 return kAliHLTDataTypeTNtuple;
99 void AliHLTTPCTrackHistoComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
101 // see header file for class documentation
102 // XXX TODO: Find more realistic values.
107 AliHLTComponent* AliHLTTPCTrackHistoComponent::Spawn()
109 // see header file for class documentation
110 return new AliHLTTPCTrackHistoComponent;
113 int AliHLTTPCTrackHistoComponent::DoInit( int argc, const char** argv )
116 fClusters = new TNtuple("fCluster", "fCluster", "charge:qmax:residualY:residualZ:used:event");
117 fTracks = new TNtuple("fTracks", "fTracks", "pt:eta:psi:nclusters:event");
118 fTracksArray=new AliHLTTPCTrackArray();
121 TString configuration="";
123 for (int i=0; i<argc && iResult>=0; i++) {
125 if (!configuration.IsNull()) configuration+=" ";
126 configuration+=argument;
129 if (!configuration.IsNull()) {
130 iResult=Configure(configuration.Data());
135 int AliHLTTPCTrackHistoComponent::DoDeinit()
137 // see header file for class documentation
146 int AliHLTTPCTrackHistoComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
148 if(!fTracksArray){fTracksArray=new AliHLTTPCTrackArray();}
150 const AliHLTComponentBlockData* iter = NULL;
152 if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
155 Int_t TotalTrack = 0;
157 //Reading Merged Tracks
158 for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTracksDataType); iter != NULL; iter = GetNextInputBlock() ) {
159 if(iter->fDataType!=AliHLTTPCDefinitions::fgkTracksDataType){continue;}
160 ReadTracks(iter,TotalTrack);
163 //Reading Tracks form slice
164 for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkTrackSegmentsDataType); iter != NULL; iter = GetNextInputBlock() ) {
165 if(iter->fDataType!=AliHLTTPCDefinitions::fgkTrackSegmentsDataType){continue;}
166 ReadTracks(iter,TotalTrack);
169 int TotalSpacePoint = 0;
172 for ( iter = GetFirstInputBlock(AliHLTTPCDefinitions::fgkClustersDataType); iter != NULL; iter = GetNextInputBlock() ) {
174 if(iter->fDataType!=AliHLTTPCDefinitions::fgkClustersDataType){continue;}
176 AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
177 AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
179 //HLTDebug ( "Input Data - TPC cluster - Slice/Patch: %d/%d.", slice, patch );
180 const AliHLTTPCClusterData* clusterData = (const AliHLTTPCClusterData*) iter->fPtr;
181 Int_t nSpacepoint = (Int_t) clusterData->fSpacePointCnt;
182 TotalSpacePoint += nSpacepoint;
183 //HLTInfo("TrackHisto found %d Spacepoints in slice %d patch %d", nSpacepoint, slice, patch);
184 AliHLTTPCSpacePointData *clusters = (AliHLTTPCSpacePointData*) clusterData->fSpacePoints;
186 if (fClustersArray[slice][patch]!=NULL) {
187 delete(fClustersArray[slice][patch]);
188 fClustersArray[slice][patch]=NULL;
190 Int_t arraysize=nSpacepoint*sizeof(AliHLTTPCSpacePointData);
191 fClustersArray[slice][patch] = (AliHLTTPCSpacePointData*)new Byte_t[arraysize];
192 if (fClustersArray[slice][patch]) {
193 memcpy(fClustersArray[slice][patch], clusters, arraysize);
194 fNcl[slice][patch]=nSpacepoint;
196 fNcl[slice][patch]=nSpacepoint;
197 HLTError ( "Memory allocation failed!" );
200 for(int i=0;i<nSpacepoint;i++){
201 UInt_t idCluster = clusters[i].fID;
202 Int_t sliceCl = (idCluster>>25) & 0x7f;
203 Int_t patchCl = (idCluster>>22) & 0x7;
204 UInt_t pos = idCluster&0x3fffff;
206 Float_t resy = 0, resz = 0;
207 for(UInt_t id=0;id<fTrackClusterID[sliceCl][patchCl].size();id++){
208 if(fTrackClusterID[sliceCl][patchCl][id]==pos){
209 clusters[i].fUsed=kTRUE;
212 FillResidual(pos,sliceCl,patchCl,resy,resz);
216 fClusters->Fill(clusters[i].fCharge,clusters[i].fQMax,resy,resz,used,GetEventId());
219 fClusters->Fill(clusters[i].fCharge,clusters[i].fQMax,-100,-100,used,GetEventId());
224 HLTInfo("TrackHisto found %d Spacepoints",TotalSpacePoint);
225 HLTInfo("TrackHisto found %d Tracks",TotalTrack);
232 for(UInt_t i=0;i<36;i++){
233 for(UInt_t j=0;j<6;j++){
234 fTrackClusterID[i][j].clear();
241 int AliHLTTPCTrackHistoComponent::Configure(const char* arguments)
245 if (!arguments) return iResult;
247 TString allArgs=arguments;
250 TObjArray* pTokens=allArgs.Tokenize(" ");
252 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
253 argument=((TObjString*)pTokens->At(i))->GetString();
254 if (argument.IsNull()) continue;
256 HLTError("unknown argument %s", argument.Data());
266 void AliHLTTPCTrackHistoComponent::ReadTracks(const AliHLTComponentBlockData* iter,Int_t &tt){
268 AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( *iter );
269 //AliHLTUInt8_t patch = AliHLTTPCDefinitions::GetMinPatchNr( *iter );
271 //HLTDebug ( "Input Data - TPC cluster - Slice/Patch: %d/%d.", slice, patch );
272 AliHLTTPCTrackletData* trackData = (AliHLTTPCTrackletData*) iter->fPtr;
273 AliHLTUInt32_t nTracks = trackData->fTrackletCnt;
274 fTracksArray->FillTracksChecked(trackData->fTracklets,trackData->fTrackletCnt,iter->fSize,slice,true);
276 //HLTInfo("TrackHisto found %d Tracks in slice %d patch %d", nTracks, slice, patch);
277 AliHLTTPCTrackSegmentData *tracks = (AliHLTTPCTrackSegmentData*) trackData->fTracklets;
279 for(AliHLTUInt32_t i=0;i<nTracks;i++){
280 UInt_t nHits = tracks->fNPoints;
282 fTracks->Fill(tracks->fPt,tracks->fPsi,tracks->fTgl,nHits,GetEventId());
284 const UInt_t *hitnum = tracks->fPointIDs;
285 for(UInt_t h=0; h<nHits; h++){
286 UInt_t idTrack = hitnum[h];
287 Int_t sliceTrack = (idTrack>>25) & 0x7f;
288 Int_t patchTrack = (idTrack>>22) & 0x7;
289 UInt_t pos = idTrack&0x3fffff;
290 fTrackClusterID[sliceTrack][patchTrack].push_back(pos);
292 UChar_t *tmpP = (UChar_t*)tracks;
293 tmpP += sizeof(AliHLTTPCTrackSegmentData)+tracks->fNPoints*sizeof(UInt_t);
294 tracks = (AliHLTTPCTrackSegmentData*)tmpP;
298 void AliHLTTPCTrackHistoComponent::PushHisto(){
300 AliHLTUInt32_t fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(0,35,0,5);
301 PushBack( (TObject*) fTracks,kAliHLTDataTypeTNtuple, fSpecification);
302 PushBack( (TObject*) fClusters,kAliHLTDataTypeTNtuple, fSpecification);
305 void AliHLTTPCTrackHistoComponent::FillResidual( UInt_t pos,AliHLTUInt8_t slice,AliHLTUInt8_t patch,Float_t& resy,Float_t& resz){
307 AliHLTTPCSpacePointData *cl = &fClustersArray[slice][patch][pos];
310 AliHLTTPCTrack *gtrack = NULL;
312 for(int i;i<fTracksArray->GetNTracks();i++){
313 AliHLTTPCTrack *tt = fTracksArray->GetCheckedTrack(i);
314 UInt_t *hitnum =tt->GetHitNumbers();
315 Int_t nHits = tt->GetNHits();
316 for(Int_t h=0; h<nHits; h++){
318 Int_t Tslice = (id>>25) & 0x7f;
319 Int_t Tpatch = (id>>22) & 0x7;
320 UInt_t Tpos = id&0x3fffff;
321 if(Tslice==slice && Tpatch==patch && Tpos==pos) {
330 Int_t tslice = gtrack->GetSector();
331 Double_t radius = gtrack->GetRadius(); // radius
332 Double_t kappa = gtrack->GetKappa(); // curvature = 1/R , signed
333 Double_t lambda = atan( gtrack->GetTgl() ); // dipAngle lambda
335 // ------------------------------------
336 // ++ Get first/last point of the track
338 Double_t xyzL[3]; // lastpoint of track
339 Double_t xyzF[3]; // firstpoint of track
341 xyzF[0] = gtrack->GetFirstPointX();
342 xyzF[1] = gtrack->GetFirstPointY();
343 xyzF[2] = gtrack->GetFirstPointZ();
345 xyzL[0] = gtrack->GetLastPointX();
346 xyzL[1] = gtrack->GetLastPointY();
347 xyzL[2] = gtrack->GetLastPointZ();
349 // --------------------------
350 // ++ Calculate length of the track
352 Double_t s = 0.; // length of the track
353 if ( AliHLTTPCTransform::GetBFieldValue() == 0. || kappa == 0 )
354 s = sqrt ( (xyzL[0] - xyzF[0])*(xyzL[0] - xyzF[0]) + (xyzL[1] - xyzF[1])*(xyzL[1] - xyzF[1]) );
356 // Calculate the length of the track. If it is to flat in in s,z plane use sxy, otherwise use sz
357 if (fabs(lambda) > 0.05){
358 // length of track calculated out of z
359 s = fabs( (xyzL[2] - xyzF[2]) / sin(lambda) ); // length of track calculated out of z
362 Double_t d = (xyzL[0] - xyzF[0])*(xyzL[0] - xyzF[0]) + (xyzL[1] - xyzF[1])*(xyzL[1] - xyzF[1]);
363 // length of track calculated out of xy
364 s = fabs ( acos( 0.5 * (2 - (d / (radius*radius)))) / ( kappa * cos(lambda) ) );
368 gtrack->Rotate(tslice,kTRUE);
370 Double_t padrows = 0;
372 Float_t xyzC[3]; // cluster tmp
373 Float_t xyzTtmp[3]; // track tmp
379 Int_t padrow = AliHLTTPCTransform::GetPadRow(cl->fX);
381 xyzTtmp[0] = gtrack->GetFirstPointX();
383 if(gtrack->GetCrossingPoint(padrow,xyzTtmp)) {
384 // ----------------------
385 // ++ Calculate Residuals
387 Float_t deltaY = ( xyzC[1] - xyzTtmp[1] );
388 Float_t deltaZ = ( xyzC[2] - xyzTtmp[2] );