]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalTrackMatcherComponent.cxx
make AliVVevent abstract (=0)
[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 #include "AliHLTProcessor.h"
23 #include "AliHLTGlobalTrackMatcherComponent.h"
24 #include "AliHLTGlobalTrackMatcher.h"
25 #include "TObjArray.h"
26 #include "AliESDEvent.h"
27 #include "AliESDtrack.h"
28 #include "AliHLTGlobalBarrelTrack.h"
29 #include "AliHLTCaloClusterDataStruct.h"
30 #include "AliHLTCaloClusterReader.h"
31 #include "AliCDBEntry.h"
32 #include "AliCDBManager.h"
33 #include "TGeoManager.h"
34 #include "TRefArray.h"
35 #include "TString.h"
36 #include "TMap.h"
37
38 using namespace std;
39
40 /** ROOT macro for the implementation of ROOT specific class methods */
41 AliHLTGlobalTrackMatcherComponent gAliHLTGlobalTrackMatcherComponent;
42
43 ClassImp(AliHLTGlobalTrackMatcherComponent);
44
45 AliHLTGlobalTrackMatcherComponent::AliHLTGlobalTrackMatcherComponent() :
46   fOCDBEntry("HLT/ConfigHLT/GlobalTrackMatcher"), //TODO
47   fMethod(1), //Method 1(PbPb) 2(pp)
48   fTrackMatcher(NULL),
49   fNEvents(0),
50   fBz(-9999999),
51   fClusterReader(NULL),
52   fTrackArray(NULL)
53 {
54   // see header file for class documentation
55   // or
56   // refer to README to build package
57   // or
58   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59
60 }
61
62 AliHLTGlobalTrackMatcherComponent::~AliHLTGlobalTrackMatcherComponent()
63 {
64   // see header file for class documentation
65   if(fTrackMatcher)
66     delete fTrackMatcher;
67   fTrackMatcher = NULL;
68
69   if(fClusterReader)
70     delete fClusterReader;
71   fClusterReader = NULL;
72
73 }
74
75
76 // Public functions to implement AliHLTComponent's interface.
77 // These functions are required for the registration process
78 const char* AliHLTGlobalTrackMatcherComponent::GetComponentID()
79 {
80   // see header file for class documentation
81   return "TrackMatcher";
82 }
83
84 void AliHLTGlobalTrackMatcherComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
85 {
86   // see header file for class documentation
87   list.clear();
88   list.push_back( kAliHLTDataTypeTrack );
89   list.push_back( kAliHLTDataTypeCaloCluster );
90 }
91
92 AliHLTComponentDataType AliHLTGlobalTrackMatcherComponent::GetOutputDataType()
93 {
94   // see header file for class documentation
95   return kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny;
96 }
97
98 void AliHLTGlobalTrackMatcherComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
99 {
100   // see header file for class documentation
101   // XXX TODO: Find more realistic values.
102   constBase = 80000;
103   inputMultiplier = 1;
104 }
105
106 AliHLTComponent* AliHLTGlobalTrackMatcherComponent::Spawn()
107 {
108   // see header file for class documentation
109   return new AliHLTGlobalTrackMatcherComponent;
110 }
111
112 int AliHLTGlobalTrackMatcherComponent::DoInit( int argc, const char** argv ) 
113 {
114   Int_t iResult=ConfigureFromCDBTObjString(fOCDBEntry); //MARCEL
115     // configure from the command line parameters if specified
116   if (iResult>=0 && argc>0) {
117     iResult=ConfigureFromArgumentString(argc, argv);
118     HLTImportant("Extrapolation Method from argument string:  %d", fMethod);   
119   } else if ( iResult >=0 ) {
120     HLTImportant("Extrapolation Method from OCDB database entry:  %d", fMethod);   
121   } 
122   
123   
124   //BALLE TODO, use command line values to initialise matching vaules
125  // init
126 //   Int_t iResult = argc;
127 //   iResult = argc;
128   
129   if(argc > 0){
130     HLTWarning("Ignoring all configuration args, starting with: argv %s", argv[0]);
131   }
132
133   if(!fClusterReader)
134     fClusterReader = new AliHLTCaloClusterReader();
135
136   fBz = GetBz();
137   if(fBz == -999999) {
138     HLTError("Magnetic field not properly set, current value: %d", fBz);
139   }
140
141   if(!fTrackMatcher)
142     fTrackMatcher = new AliHLTGlobalTrackMatcher();
143
144   fNEvents = 0;
145
146   if(!fTrackArray){
147     fTrackArray = new TObjArray();
148     fTrackArray->SetOwner(kFALSE);
149   }
150
151   //*** GeoManager ***
152    AliCDBPath path("GRP","Geometry","Data");
153    AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);
154    if (pEntry) {
155       if(!gGeoManager) {
156       gGeoManager = (TGeoManager*)pEntry->GetObject();
157       }
158    }
159    else {
160       HLTError("can not fetch object \"%s\" from CDB",path.GetPath().Data());
161    }
162    // ****
163
164
165   return iResult; 
166 }
167   
168 int AliHLTGlobalTrackMatcherComponent::DoDeinit() 
169 {
170   // see header file for class documentation
171   Int_t iResult = 1;
172   
173   if(fTrackMatcher)
174     delete fTrackMatcher;
175   fTrackMatcher = NULL;
176   
177   if(fClusterReader)
178     delete fClusterReader;
179   fClusterReader = NULL;
180   
181
182   fNEvents = 0;
183
184   return iResult;
185 }
186
187 int AliHLTGlobalTrackMatcherComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/) 
188 {
189   
190   //See header file for documentation
191   Int_t iResult = 0;
192   
193   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) )
194     return 0;
195   
196   if(!IsDataEvent()){//marcel test
197     return 0;//marcel test
198   }//marcel test
199
200   fNEvents++;
201
202   //Loop over TPC blocks
203   //BALLE TODO check that the tracks in the TObjArray are fine over several blocks
204   
205    fTrackArray->Clear();
206    vector<AliHLTGlobalBarrelTrack> tracks;
207    
208    for (const AliHLTComponentBlockData* pBlock = GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginTPC); pBlock!=NULL; pBlock=GetNextInputBlock()) {
209
210      if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>=0) {
211        for(UInt_t it = 0; it < tracks.size(); it++) {
212          AliHLTGlobalBarrelTrack track = tracks.at(it);
213         fTrackArray->AddLast(dynamic_cast<TObject*>(&(tracks.at(it))));
214                }
215      } else {
216               HLTWarning("Converting tracks to vector failed");
217      }
218     
219      //     //Push the TPC block on, without any changes
220      //PushBack(pBlock->fPtr, pBlock->fSize, pBlock->fDataType, pBlock->fSpecification);
221
222    }
223     
224    AliHLTCaloClusterDataStruct * caloClusterStruct;
225    //Get the PHOS Clusters
226    vector<AliHLTCaloClusterDataStruct*> phosClustersVector;
227    
228    for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginPHOS); pBlock!=NULL; pBlock=GetNextInputBlock()) {
229      AliHLTCaloClusterHeaderStruct *caloClusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
230      fClusterReader->SetMemory(caloClusterHeader);
231      if ( (caloClusterHeader->fNClusters) < 0) {
232        HLTWarning("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (caloClusterHeader->fNClusters));
233        continue;
234      } else {    
235        phosClustersVector.reserve( (int) (caloClusterHeader->fNClusters) + phosClustersVector.size() ); 
236        while( (caloClusterStruct = fClusterReader->NextCluster()) != 0) {
237          phosClustersVector.push_back(caloClusterStruct);  
238        }
239      }
240    }
241
242     //Get the EMCAL Clusters
243    vector<AliHLTCaloClusterDataStruct*> emcalClustersVector;
244    for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginEMCAL); pBlock!=NULL; pBlock=GetNextInputBlock()) {
245      AliHLTCaloClusterHeaderStruct *caloClusterHeader = reinterpret_cast<AliHLTCaloClusterHeaderStruct*>(pBlock->fPtr);
246      fClusterReader->SetMemory(caloClusterHeader);
247 //           HLTInfo("\n EMCAL: estou aqui");//marcel
248      if ( (caloClusterHeader->fNClusters) < 0) {
249        HLTWarning("Event has negative number of clusters: %d! Very bad for vector resizing", (Int_t) (caloClusterHeader->fNClusters));
250        continue;
251      } else {    
252        emcalClustersVector.reserve( (int) (caloClusterHeader->fNClusters) + emcalClustersVector.size() ); 
253        while( (caloClusterStruct = fClusterReader->NextCluster()) != 0) {
254          emcalClustersVector.push_back(caloClusterStruct);  
255        }
256      }
257    }
258
259       iResult = fTrackMatcher->Match(fTrackArray, phosClustersVector, emcalClustersVector, fBz,fMethod); //With Method String
260
261
262    //Push the blocks on
263    for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeCaloCluster | kAliHLTDataOriginAny); pBlock!=NULL; pBlock=GetNextInputBlock()) {
264      PushBack(pBlock->fPtr, pBlock->fSize, pBlock->fDataType, pBlock->fSpecification);
265     }
266    
267    fTrackArray->Clear();
268
269    return iResult;
270 }
271
272 int AliHLTGlobalTrackMatcherComponent::ScanConfigurationArgument(int argc, const char** argv) {
273   // see header file for class documentation
274   if (argc<=0) return 0;
275   int i=0;
276   TString argument=argv[i];
277
278   // -maxpt
279   if (argument.CompareTo("-method")==0) {
280     if (++i>=argc) return -EPROTO;
281     argument=argv[i];
282     fMethod=argument.Atoi(); // 
283     return 2;
284   }    
285
286 // unknown argument
287   return -EINVAL;
288 }
289
290 // int AliHLTGlobalTrackMatcherComponent::Configure(const char* arguments)
291 // {
292 //   Int_t iResult = 1;
293 //   return iResult;
294 // }
295
296 // int AliHLTGlobalTrackMatcherComponent::Reconfigure(const char* cdbEntry, const char* chainId)
297 // {
298 //   Int_t iResult = 1;
299 //   return iResult;
300 // }
301
302 int AliHLTGlobalTrackMatcherComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/) {
303   // configure from the specified antry or the default one
304   const char* entry=cdbEntry;
305   if (!entry || entry[0]==0) entry=fOCDBEntry;
306
307   return ConfigureFromCDBTObjString(entry);
308 }
309
310 void AliHLTGlobalTrackMatcherComponent::GetOCDBObjectDescription( TMap* const targetMap) {
311   
312   // Get a list of OCDB object description.
313   if (!targetMap) return;
314   targetMap->Add(new TObjString(fOCDBEntry),
315                  new TObjString(Form("Track-Matcher Method OCDB object") ) 
316                  );
317 }
318
319