]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcherComponent.cxx
Cosmetics
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalTrackMatcherComponent.cxx
1 //**************************************************************************
2 //* This file is property of and copyright by the ALICE HLT Project        * 
3 //* ALICE Experiment at CERN, All rights reserved.                         *
4 //*                                                                        *
5 //* Primary Authors: Svein Lindal <svein.lindal@gmail.com>                 *
6 //*                  for The ALICE HLT Project.                            *
7 //*                                                                        *
8 //* Permission to use, copy, modify and distribute this software and its   *
9 //* documentation strictly for non-commercial purposes is hereby granted   *
10 //* without fee, provided that the above copyright notice appears in all   *
11 //* copies and that both the copyright notice and this permission notice   *
12 //* appear in the supporting documentation. The authors make no claims     *
13 //* about the suitability of this software for any purpose. It is          *
14 //* provided "as is" without express or implied warranty.                  *
15 //**************************************************************************
16
17 /** @file   AliHLTGlobalTrackMatcherComponent.cxx
18     @author Svein Lindal
19     @brief  Component to match TPC tracks to Calo Clusters
20 */
21
22 #if __GNUC__>= 3
23 using namespace std;
24 #endif
25
26 #include "AliHLTProcessor.h"
27 #include "AliHLTGlobalTrackMatcherComponent.h"
28 #include "AliHLTGlobalTrackMatcher.h"
29 #include "TObjArray.h"
30 #include "AliESDEvent.h"
31 #include "AliESDtrack.h"
32 #include "AliHLTGlobalBarrelTrack.h"
33 #include "AliHLTCaloClusterDataStruct.h"
34 #include "AliHLTCaloClusterReader.h"
35
36
37 /** ROOT macro for the implementation of ROOT specific class methods */
38 AliHLTGlobalTrackMatcherComponent gAliHLTGlobalTrackMatcherComponent;
39
40 ClassImp(AliHLTGlobalTrackMatcherComponent);
41
42 AliHLTGlobalTrackMatcherComponent::AliHLTGlobalTrackMatcherComponent() :
43   fTrackMatcher(NULL),
44   fNEvents(0),
45   fBz(-9999999),
46   fClusterReader(NULL),
47   fTrackArray(NULL)
48 {
49   // see header file for class documentation
50   // or
51   // refer to README to build package
52   // or
53   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
54
55 }
56
57 AliHLTGlobalTrackMatcherComponent::~AliHLTGlobalTrackMatcherComponent()
58 {
59   // see header file for class documentation
60   if(fTrackMatcher)
61     delete fTrackMatcher;
62   fTrackMatcher = NULL;
63
64   if(fClusterReader)
65     delete fClusterReader;
66   fClusterReader = NULL;
67
68 }
69
70
71 // Public functions to implement AliHLTComponent's interface.
72 // These functions are required for the registration process
73 const char* AliHLTGlobalTrackMatcherComponent::GetComponentID()
74 {
75   // see header file for class documentation
76   return "TrackMatcher";
77 }
78
79 void AliHLTGlobalTrackMatcherComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
80 {
81   // see header file for class documentation
82   list.clear();
83   list.push_back( kAliHLTDataTypeTrack );
84   list.push_back( kAliHLTDataTypeCaloCluster );
85 }
86
87 AliHLTComponentDataType AliHLTGlobalTrackMatcherComponent::GetOutputDataType()
88 {
89   // see header file for class documentation
90   return kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny;
91 }
92
93 void AliHLTGlobalTrackMatcherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
94 {
95   // see header file for class documentation
96   // XXX TODO: Find more realistic values.
97   constBase = 80000;
98   inputMultiplier = 1;
99 }
100
101 AliHLTComponent* AliHLTGlobalTrackMatcherComponent::Spawn()
102 {
103   // see header file for class documentation
104   return new AliHLTGlobalTrackMatcherComponent;
105 }
106
107 int AliHLTGlobalTrackMatcherComponent::DoInit( int argc, const char** argv ) 
108 {
109  
110   //BALLE TODO, use command line values to initialise matching vaules
111  // init
112   Int_t iResult = argc;
113   
114   if(argc > 0){
115     HLTWarning("Ignoring all configuration args, starting with: argv %s", argv[0]);
116   }
117
118   if(!fClusterReader)
119     fClusterReader = new AliHLTCaloClusterReader();
120
121   fBz = GetBz();
122   if(fBz == -999999) {
123     HLTError("Magnetic field not properly set, current value: %d", fBz);
124   }
125
126   if(!fTrackMatcher)
127     fTrackMatcher = new AliHLTGlobalTrackMatcher();
128
129   fNEvents = 0;
130
131   if(!fTrackArray){
132     fTrackArray = new TObjArray();
133     fTrackArray->SetOwner(kFALSE);
134   }
135
136   return iResult; 
137 }
138   
139 int AliHLTGlobalTrackMatcherComponent::DoDeinit() 
140 {
141   // see header file for class documentation
142   Int_t iResult = 1;
143   
144   if(fTrackMatcher)
145     delete fTrackMatcher;
146   fTrackMatcher = NULL;
147   
148   if(fClusterReader)
149     delete fClusterReader;
150   fClusterReader = NULL;
151   
152
153   fNEvents = 0;
154
155   return iResult;
156 }
157
158 int AliHLTGlobalTrackMatcherComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) 
159 {
160   
161   //See header file for documentation
162   Int_t iResult = 0;
163   
164   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
165     return 0;
166
167
168   fNEvents++;
169
170   //Loop over TPC blocks
171   //BALLE TODO check that the tracks in the TObjArray are fine over several blocks
172
173    fTrackArray->Clear();
174    vector<AliHLTGlobalBarrelTrack> tracks;
175    
176    for (const AliHLTComponentBlockData* pBlock = GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); pBlock!=NULL; pBlock=GetNextInputBlock()) {
177
178      if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
179        for(UInt_t it = 0; it < tracks.size(); it++) 
180          {
181            AliHLTGlobalBarrelTrack track = tracks.at(it);
182            fTrackArray->AddLast(dynamic_cast<TObject*>(&(tracks.at(it))));
183          }
184      } 
185      else 
186        {
187          HLTWarning("Converting tracks to vector failed");
188        }
189     
190      //     //Push the TPC block on, without any changes
191      PushBack(pBlock->fPtr, pBlock->fSize, pBlock->fDataType, pBlock->fSpecification);
192
193    }
194
195    AliHLTCaloClusterDataStruct * caloClusterStruct;
196    //Get the PHOS Clusters
197    vector<AliHLTCaloClusterDataStruct*> phosClustersVector;
198    
199    for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock()) 
200      {
201        AliHLTCaloClusterHeaderStruct *caloClusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
202        fClusterReader->SetMemory(caloClusterHeader);
203        
204        if ( (caloClusterHeader->fNClusters) < 0) 
205          {
206            HLTWarning("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (caloClusterHeader->fNClusters));
207            continue;
208          } else 
209          {    
210            phosClustersVector.reserve( (int) (caloClusterHeader->fNClusters) + phosClustersVector.size() ); 
211            while( (caloClusterStruct = fClusterReader->NextCluster()) != 0) {
212              phosClustersVector.push_back(caloClusterStruct);  
213            }
214          }
215      }
216    
217
218    //Get the EMCAL Clusters
219    vector<AliHLTCaloClusterDataStruct*> emcalClustersVector;
220    for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL); pBlock!=NULL; pBlock=GetNextInputBlock()) {
221      AliHLTCaloClusterHeaderStruct *caloClusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
222      fClusterReader->SetMemory(caloClusterHeader);
223      if ( (caloClusterHeader->fNClusters) < 0) 
224        {
225          HLTWarning("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (caloClusterHeader->fNClusters));
226          continue;
227      } else 
228        {    
229          emcalClustersVector.reserve( (int) (caloClusterHeader->fNClusters) + emcalClustersVector.size() ); 
230          
231          while( (caloClusterStruct = fClusterReader->NextCluster()) != 0  ) 
232            {
233              emcalClustersVector.push_back(caloClusterStruct);  
234            }
235       
236        }
237    }
238    
239    iResult = fTrackMatcher->Match(fTrackArray, phosClustersVector, emcalClustersVector, fBz);
240
241    //Push the blocks on
242    for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny); pBlock!=NULL; pBlock=GetNextInputBlock()) 
243      {
244        PushBack(pBlock->fPtr, pBlock->fSize, pBlock->fDataType, pBlock->fSpecification);
245      }
246    
247    fTrackArray->Clear();
248    return iResult;
249 }
250
251 // int AliHLTGlobalTrackMatcherComponent::Configure(const char* arguments)
252 // {
253 //   Int_t iResult = 1;
254 //   return iResult;
255 // }
256
257 // int AliHLTGlobalTrackMatcherComponent::Reconfigure(const char* cdbEntry, const char* chainId)
258 // {
259 //   Int_t iResult = 1;
260 //   return iResult;
261 // }