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