]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerBarrelGeomMultiplicity.cxx
- adding debug output to trigger component
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerBarrelGeomMultiplicity.cxx
1 // $Id$
2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project        * 
4 //* ALICE Experiment at CERN, All rights reserved.                         *
5 //*                                                                        *
6 //* Primary Authors: Oystein Djuvsland                                     *
7 //*                  for The ALICE HLT Project.                            *
8 //*                                                                        *
9 //* Permission to use, copy, modify and distribute this software and its   *
10 //* documentation strictly for non-commercial purposes is hereby granted   *
11 //* without fee, provided that the above copyright notice appears in all   *
12 //* copies and that both the copyright notice and this permission notice   *
13 //* appear in the supporting documentation. The authors make no claims     *
14 //* about the suitability of this software for any purpose. It is          *
15 //* provided "as is" without express or implied warranty.                  *
16 //**************************************************************************
17
18 /// @file   AliHLTTriggerBarrelGeomMultiplicity.cxx
19 /// @author Oystein Djuvsland
20 /// @date   2009-10-08
21 /// @brief  HLT trigger component for charged particle multiplicity 
22 ///         within a geometrical acceptance in the central barrel.
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30 #include "AliHLTTriggerBarrelGeomMultiplicity.h"
31 #include "AliHLTTriggerDetectorGeom.h"
32 #include "AliHLTTriggerDecisionParameters.h"
33 #include "AliESDEvent.h"
34 #include "AliHLTTriggerDecision.h"
35 #include "AliHLTDomainEntry.h"
36 #include "AliHLTGlobalBarrelTrack.h"
37 #include "TObjArray.h"
38 #include "TObjString.h"
39 #include "TObjArray.h"
40 #include "AliCDBEntry.h"
41 #include "AliCDBManager.h"
42 #include "TFile.h"
43 #include "AliHLTTrigger.h"
44
45 /** ROOT macro for the implementation of ROOT specific class methods */
46 ClassImp(AliHLTTriggerBarrelGeomMultiplicity)
47
48 AliHLTTriggerBarrelGeomMultiplicity::AliHLTTriggerBarrelGeomMultiplicity()
49   : AliHLTTrigger()
50   , fSolenoidBz(0)
51   , fMinTracks(1)
52   , fDetectorArray(0)
53   , fTriggerDecisionPars(0)
54   , fTriggerName(0)
55   , fOCDBEntry(0)
56 {
57   // see header file for class documentation
58   // or
59   // refer to README to build package
60   // or
61   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62   fDetectorArray = new TObjArray(1);
63
64   fDetectorArray = new TObjArray;
65
66 }
67
68 AliHLTTriggerBarrelGeomMultiplicity::~AliHLTTriggerBarrelGeomMultiplicity()
69 {
70   // see header file for class documentation
71 }
72
73 const char* AliHLTTriggerBarrelGeomMultiplicity::GetTriggerName() const 
74 {
75   // see header file for class documentation
76
77   return "BarrelGeomMultiplicityTrigger";
78 }
79
80 AliHLTComponent* AliHLTTriggerBarrelGeomMultiplicity::Spawn()
81 {
82   // see header file for class documentation
83   return new AliHLTTriggerBarrelGeomMultiplicity;
84 }
85
86 int AliHLTTriggerBarrelGeomMultiplicity::Reconfigure(const char *cdbEntry, const char *chainId)
87 {
88   // see header file for class documentation
89
90   // configure from the specified entry or the default
91   const char* entry=cdbEntry;
92
93   if (!entry)
94     {
95       HLTDebug("No CDB path specified");
96       entry = fOCDBEntry; 
97     }
98
99   return GetDetectorGeomsFromCDBObject(entry, chainId);
100
101
102 int AliHLTTriggerBarrelGeomMultiplicity::DoTrigger()
103 {
104   // see header file for class documentation
105   int iResult=0;
106   int numberOfTracks=-1;
107
108   if (!fTriggerDecisionPars) {
109     iResult=-ENODEV;
110   }
111
112   // try the ESD as input
113   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
114 n  AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
115   TString description;
116
117   if (esd != NULL) 
118     {
119       numberOfTracks=0;
120       esd->GetStdContent();
121       for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++) 
122         {
123           if (CheckCondition(esd->GetTrack(i), esd->GetMagneticField())) numberOfTracks++;
124         }
125     }
126
127   // try the AliHLTExternal track data as input
128   if (iResult>=0 && numberOfTracks<0) 
129     {
130       for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack);
131            pBlock!=NULL; pBlock=GetNextInputBlock()) 
132         {
133           if (numberOfTracks<0) numberOfTracks=0;
134           vector<AliHLTGlobalBarrelTrack> tracks;
135           if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) 
136             {
137               for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
138                    element!=tracks.end(); element++) 
139                 {
140                   if (CheckCondition(&(*element), fSolenoidBz)) numberOfTracks++;
141                 }
142             } 
143           else if (iResult<0) 
144             {
145               HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d", 
146                        DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
147             }
148         }
149     }
150
151   bool condition=false;
152   description="Geometrical conditions not matched";
153   AliHLTReadoutList readout;
154
155   if (numberOfTracks>=fMinTracks) 
156     {
157       condition=true;
158       description=fTriggerDecisionPars->GetDescription();
159       readout=fTriggerDecisionPars->GetReadoutListParameter();
160       HLTDebug("Geometrical acceptance trigger %s triggered", fTriggerDecisionPars->GetTriggerName().Data());
161     }
162
163   AliHLTTriggerDecision decision(
164                                  condition,
165                                  fTriggerDecisionPars->GetTriggerName().Data(),
166                                  AliHLTTriggerDomain(readout),
167                                  description.Data()
168                                  );
169   TriggerEvent(&decision, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
170
171   return iResult;
172
173 }
174
175 template<class T>
176 bool AliHLTTriggerBarrelGeomMultiplicity::CheckCondition(T* track, float b)
177 {
178   bool ret = false;
179
180   // see header file for class documentation
181   if (!track) return false;
182
183   ret = IsInDetectors(track, b);
184
185   return ret;
186
187 }
188
189 template<class T>
190 bool AliHLTTriggerBarrelGeomMultiplicity::IsInDetectors(T* track, float b)
191 {
192   // See header file for class documentation  
193   for(Int_t i = 0; i < fDetectorArray->GetEntries(); i++)
194     {
195       AliHLTTriggerDetectorGeom *det = static_cast<AliHLTTriggerDetectorGeom*>(fDetectorArray->At(i));
196
197       Double_t trackPoint[3];
198       Double_t normVector[3];
199
200       det->GetInitialPoint(trackPoint);
201       det->GetNormVector(normVector);
202
203       bool ret = track->Intersect(trackPoint, normVector, b);
204
205       if(ret)
206         {
207           if(det->IsInDetector(trackPoint)) return true;
208         }
209     }
210   return false;
211 }
212
213 int AliHLTTriggerBarrelGeomMultiplicity::DoInit(int argc, const char** argv)
214 {
215   // see header file for class documentation
216
217   // first configure the default
218   int iResult=0;
219
220   if (iResult>=0 && argc>0)
221     iResult=ConfigureFromArgumentString(argc, argv);
222
223   if (!fTriggerDecisionPars) {
224     HLTError("decision parameter not initialized");
225     iResult=-ENODEV;
226   }
227
228   return iResult;
229 }
230
231 int AliHLTTriggerBarrelGeomMultiplicity::DoDeinit()
232  {
233   // see header file for class documentation
234   return 0;
235 }
236
237 int AliHLTTriggerBarrelGeomMultiplicity::ReadPreprocessorValues(const char* /*modules*/)
238 {
239     // see header file for function documentation
240   int nDetectorGeoms=0;
241
242   // TODO 2009-10-10: implementation
243   // for the moment very quick, just reload the magnetic field
244   return ConfigureFromCDBTObjString(kAliHLTCDBSolenoidBz);
245 }
246
247 int AliHLTTriggerBarrelGeomMultiplicity::GetDetectorGeomsFromCDBObject(const char *cdbEntry, const char* chainId)
248 {
249     // see header file for function documentation
250   int nDetectorGeoms=0;
251
252   if(fDetectorArray)
253     {
254       fDetectorArray->Clear();
255     }
256   else
257     {
258       fDetectorArray = new TObjArray();
259     }
260   
261   const char *path = cdbEntry;
262
263   if(!path) path = fOCDBEntry;
264   
265   if(path)
266     {
267       //     const char* chainId=GetChainId();
268       HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
269       AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
270       if (pEntry) 
271         {
272           TObjArray* pArr=dynamic_cast<TObjArray*>(pEntry->GetObject());
273           if (pArr) 
274             {
275
276               for(int i = 0; i < pArr->GetEntries(); i++)
277                 {
278                   if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDecisionParameters"))
279                     {
280                       fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
281                     }
282                   else if(pArr->At(i)->InheritsFrom("AliHLTTriggerDetectorGeom"))
283                     {
284                       fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
285                       nDetectorGeoms++;
286                       HLTDebug("received detector geometry of type %s", pArr->At(i)->ClassName());
287                     }
288                   else
289                     {
290                       HLTWarning("Unknown object of type %s in configuration object", pArr->At(i)->ClassName());
291                     }
292                 }
293             } 
294           else 
295             {
296               HLTError("configuration object \"%s\" has wrong type, required TObjArray", path);
297               nDetectorGeoms=-EINVAL;
298             }
299         }
300       else 
301         {
302           HLTError("can not fetch object \"%s\" from OCDB", path);
303           nDetectorGeoms=-ENOENT;
304         }
305     }
306
307   HLTInfo("received %d detector geometries", nDetectorGeoms);
308
309   return nDetectorGeoms;
310 }
311
312 int AliHLTTriggerBarrelGeomMultiplicity::GetDetectorGeomsFromFile(const char *filename)
313 {
314     // see header file for function documentation
315   int nDetectorGeoms=0;
316
317   if(fDetectorArray)
318     {
319       fDetectorArray->Clear();
320     }
321   else
322     {
323       fDetectorArray = new TObjArray();
324     }
325   
326
327   if (filename) 
328     {
329       TFile *geomfile = TFile::Open(filename, "READ");
330       
331       if(geomfile)
332         {
333           HLTInfo("configure from file \"%s\"", filename);
334           TObjArray* pArr=dynamic_cast<TObjArray*>(geomfile->Get("GeomConf"));
335           if (pArr) 
336             {
337
338               for(int i = 0; i < pArr->GetEntries(); i++)
339                 {
340                   if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDecisionParameters"))
341                     {
342                       fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
343                     }
344                   else if(pArr->At(i)->InheritsFrom("AliHLTTriggerDetectorGeom"))
345                     {
346                       fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
347                       nDetectorGeoms++;
348                       HLTDebug("received detector geometry of type %s", pArr->At(i)->ClassName());
349                     }
350                   else
351                     {
352                       HLTWarning("Unknown object of type %s in configuration object", pArr->At(i)->ClassName());
353                     }
354                 }
355             } 
356           else 
357             {
358               HLTError("configuration object has wrong type, required TObjArray");
359               nDetectorGeoms=-EINVAL;
360             }
361           } 
362       else 
363         {
364           HLTError("could not open file \"%s\"", filename);
365           nDetectorGeoms=-ENOENT;
366         }
367     }
368   else
369     {
370       HLTError("ROOT file name not specified");
371     }
372   HLTInfo("received %d detector geometries", nDetectorGeoms);
373
374
375   return nDetectorGeoms;
376 }
377
378 int AliHLTTriggerBarrelGeomMultiplicity::ScanConfigurationArgument(int argc, const char** argv)
379 {
380   // See header file for class documentation
381   if (argc<=0) return 0;
382   int i=0;
383   TString argument=argv[i];
384
385   if (argument.CompareTo("-geomfile")==0) 
386     {
387       if (++i>=argc) return -EPROTO;
388     
389       GetDetectorGeomsFromFile(argv[i]);
390     
391       return 2;
392     }    
393
394   if (argument.CompareTo("-triggername")==0) 
395     {
396       if (++i>=argc) return -EPROTO;
397       
398       fTriggerName = new char[128];
399       sprintf(fTriggerName, argv[i]);
400       
401       fOCDBEntry = fTriggerName;
402
403       return 2;
404   }    
405   return 0;
406 }
407