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