]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcherComponent.cxx
Changed CaloHistoComponent to take caloCluster struct input
[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 = 0;
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          AliHLTGlobalBarrelTrack track = tracks.at(it);
181         fTrackArray->AddLast(dynamic_cast<TObject*>(&(tracks.at(it))));
182                }
183      } else {
184               HLTWarning("Converting tracks to vector failed");
185      }
186     
187      //     //Push the TPC block on, without any changes
188      PushBack(pBlock->fPtr, pBlock->fSize, pBlock->fDataType, pBlock->fSpecification);
189
190    }
191
192   //Get the clusters
193   AliHLTCaloClusterDataStruct * caloClusterStruct;
194   vector<AliHLTCaloClusterDataStruct*> phosClustersVector;
195   
196    for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny); pBlock!=NULL; pBlock=GetNextInputBlock()) {
197      AliHLTCaloClusterHeaderStruct *caloClusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
198      fClusterReader->SetMemory(caloClusterHeader);
199      
200      if ( (caloClusterHeader->fNClusters) < 0) {
201        HLTWarning("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (caloClusterHeader->fNClusters));
202      } else {    
203        HLTInfo("Event has positive number of clusters: %d", (Int_t ) (caloClusterHeader->fNClusters));
204
205        //BALLE, TODO, make it able to do EMCAL as well!!!
206        phosClustersVector.resize((int) (caloClusterHeader->fNClusters)); 
207        Int_t nClusters = 0;
208        cout << "nclustes " << caloClusterHeader->fNClusters << endl;
209        while( (caloClusterStruct = fClusterReader->NextCluster()) != 0) {
210          cout << caloClusterStruct->fEnergy << "BALLE ENERGY" <<endl;
211          //BALLE stil just phos
212          phosClustersVector[nClusters++] = caloClusterStruct;  
213        }
214        
215        iResult = fTrackMatcher->Match(fTrackArray, phosClustersVector, fBz);
216      }
217      
218      if(iResult <0) {
219        HLTWarning("Error in track matcher");
220      }
221      PushBack(pBlock->fPtr, pBlock->fSize, pBlock->fDataType, pBlock->fSpecification);
222      //PushBack(pBlock->fPtr, pBlock->fSize, kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny );
223   }
224
225
226    fTrackArray->Clear();
227    //BALLE TODO phos only !!!!
228    
229    return iResult;
230
231 }
232
233 // int AliHLTGlobalTrackMatcherComponent::Configure(const char* arguments)
234 // {
235 //   Int_t iResult = 1;
236 //   return iResult;
237 // }
238
239 // int AliHLTGlobalTrackMatcherComponent::Reconfigure(const char* cdbEntry, const char* chainId)
240 // {
241 //   Int_t iResult = 1;
242 //   return iResult;
243 // }