]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerBarrelGeomMultiplicity.cxx
- adding functionality for loading detector geometries from OCDB or ROOT file
[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 "TVector3.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
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
146   if (numberOfTracks>=fMinTracks) 
147     {
148       SetDescription(fTriggerDecisionPars->GetDescription());
149       AliHLTReadoutList readout(fTriggerDecisionPars->GetReadoutListParameter());
150       AliHLTTriggerDecision decision(
151                                      true,
152                                      fTriggerDecisionPars->GetTriggerName().Data(),
153                                      AliHLTTriggerDomain(readout),
154                                      fTriggerDecisionPars->GetDescription()
155                                      );
156       TriggerEvent(&decision);
157     }
158   
159   return iResult;
160
161 }
162
163 template<class T>
164 bool AliHLTTriggerBarrelGeomMultiplicity::CheckCondition(T* track, float b)
165 {
166   bool ret = false;
167
168   // see header file for class documentation
169   if (!track) return false;
170
171   ret = IsInDetectors(track, b);
172
173   return ret;
174
175 }
176
177 template<class T>
178 bool AliHLTTriggerBarrelGeomMultiplicity::IsInDetectors(T* track, float b)
179 {
180   // See header file for class documentation  
181   for(Int_t i = 0; i < fDetectorArray->GetEntries(); i++)
182     {
183       AliHLTTriggerDetectorGeom *det = static_cast<AliHLTTriggerDetectorGeom*>(fDetectorArray->At(i));
184
185       Double_t trackPoint[3];
186       Double_t normVector[3];
187
188       det->GetInitialPoint(trackPoint);
189       det->GetNormVector(normVector);
190
191       bool ret = track->Intersect(trackPoint, normVector, b);
192
193       if(ret)
194         {
195           if(det->IsInDetector(trackPoint)) return true;
196         }
197     }
198   return false;
199 }
200
201 int AliHLTTriggerBarrelGeomMultiplicity::DoInit(int argc, const char** argv)
202 {
203   // see header file for class documentation
204
205   // first configure the default
206   int iResult=0;
207
208   if (iResult>=0 && argc>0)
209     iResult=ConfigureFromArgumentString(argc, argv);
210
211   return iResult;
212 }
213
214 int AliHLTTriggerBarrelGeomMultiplicity::DoDeinit()
215  {
216   // see header file for class documentation
217   return 0;
218 }
219
220 int AliHLTTriggerBarrelGeomMultiplicity::ReadPreprocessorValues(const char* /*modules*/)
221 {
222   // see header file for class documentation
223
224   // TODO 2009-10-10: implementation
225   // for the moment very quick, just reload the magnetic field
226   return ConfigureFromCDBTObjString(kAliHLTCDBSolenoidBz);
227 }
228
229 int AliHLTTriggerBarrelGeomMultiplicity::GetDetectorGeomsFromCDBObject(const char *cdbEntry, const char* chainId)
230 {
231     // see header file for function documentation
232   int nDetectorGeoms=0;
233   const char *path = cdbEntry;
234   if(!path) path = fOCDBEntry;
235
236   if(path)
237     {
238       //     const char* chainId=GetChainId();
239       HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
240       AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
241       if (pEntry) 
242         {
243           TObjArray* pArr=dynamic_cast<TObjArray*>(pEntry->GetObject());
244           if (pArr) 
245             {
246
247               for(int i = 0; i < pArr->GetEntries(); i++)
248                 {
249                   if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDecisionParameters"))
250                     {
251                       fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
252                     }
253                   else if(pArr->At(i)->InheritsFrom("AliHLTTriggerDetectorGeom"))
254                     {
255                       fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
256                       nDetectorGeoms++;
257                       HLTWarning("received detector geometry of type %s", pArr->At(i)->ClassName());
258                     }
259                   else
260                     {
261                       HLTWarning("Unknown object of type %s in configuration object", pArr->At(i)->ClassName());
262                     }
263                 }
264             } 
265           else 
266             {
267               HLTError("configuration object \"%s\" has wrong type, required TObjArray", path);
268               nDetectorGeoms=-EINVAL;
269             }
270         }
271       else 
272         {
273           HLTError("can not fetch object \"%s\" from OCDB", path);
274           nDetectorGeoms=-ENOENT;
275         }
276     }
277   return nDetectorGeoms;
278 }
279
280 int AliHLTTriggerBarrelGeomMultiplicity::GetDetectorGeomsFromFile(const char *filename)
281 {
282     // see header file for function documentation
283   int nDetectorGeoms=0;
284
285   if (filename) 
286     {
287       TFile *geomfile = TFile::Open(filename, "READ");
288       
289       if(geomfile)
290         {
291           HLTInfo("configure from file \"%s\"", filename);
292           TObjArray* pArr=dynamic_cast<TObjArray*>(geomfile->Get("GeomConf"));
293           if (pArr) 
294             {
295
296               for(int i = 0; i < pArr->GetEntries(); i++)
297                 {
298                   if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDecisionParameters"))
299                     {
300                       fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
301                     }
302                   else if(pArr->At(i)->InheritsFrom("AliHLTTriggerDetectorGeom"))
303                     {
304                       fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
305                       nDetectorGeoms++;
306                       HLTWarning("received detector geometry of type %s", pArr->At(i)->ClassName());
307                     }
308                   else
309                     {
310                       HLTWarning("Unknown object of type %s in configuration object", pArr->At(i)->ClassName());
311                     }
312                 }
313             } 
314           else 
315             {
316               HLTError("configuration object has wrong type, required TObjArray");
317               nDetectorGeoms=-EINVAL;
318             }
319           } 
320       else 
321         {
322           HLTError("could not open file \"%s\"", filename);
323           nDetectorGeoms=-ENOENT;
324         }
325     }
326   HLTWarning("received TObjArray with %d detector geometries", nDetectorGeoms);
327
328   return nDetectorGeoms;
329 }
330
331 int AliHLTTriggerBarrelGeomMultiplicity::ScanConfigurationArgument(int argc, const char** argv)
332 {
333   // See header file for class documentation
334   if (argc<=0) return 0;
335   int i=0;
336   TString argument=argv[i];
337
338   if (argument.CompareTo("-geomfile")==0) 
339     {
340       if (++i>=argc) return -EPROTO;
341     
342       GetDetectorGeomsFromFile(argv[i]);
343     
344       return 2;
345     }    
346
347   if (argument.CompareTo("-triggername")==0) 
348     {
349       if (++i>=argc) return -EPROTO;
350       
351       fTriggerName = new char[128];
352       sprintf(fTriggerName, argv[i]);
353       
354       fOCDBEntry = fTriggerName;
355
356       return 2;
357   }    
358   return 0;
359 }