]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerBarrelGeomMultiplicity.cxx
ab42b9f9999d5d726e0b808b01eb7c4f793b5224
[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: Matthias Richter <Matthias.Richter@ift.uib.no>        *
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 {
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   fDetectorArray = new TObjArray;
60
61 }
62
63 AliHLTTriggerBarrelGeomMultiplicity::~AliHLTTriggerBarrelGeomMultiplicity()
64 {
65   // see header file for class documentation
66 }
67
68 const char* AliHLTTriggerBarrelGeomMultiplicity::GetTriggerName() const 
69 {
70   // see header file for class documentation
71   //  const char* name = fTriggerName;
72   //  if(name) return name;
73   return "BarrelGeomMultiplicityTrigger";
74 }
75
76 AliHLTComponent* AliHLTTriggerBarrelGeomMultiplicity::Spawn()
77 {
78   // see header file for class documentation
79   return new AliHLTTriggerBarrelGeomMultiplicity;
80 }
81
82 int AliHLTTriggerBarrelGeomMultiplicity::Reconfigure(const char *cdbEntry, const char *chainId)
83 {
84   // see header file for class documentation
85
86   // configure from the specified entry or the default
87   const char* entry=cdbEntry;
88
89   if (!entry)
90     {
91       HLTDebug("No CDB path specified");
92       entry = fOCDBEntry; 
93     }
94
95   return GetDetectorGeomsFromCDBObject(entry, chainId);
96
97
98 int AliHLTTriggerBarrelGeomMultiplicity::DoTrigger()
99 {
100   // see header file for class documentation
101   int iResult=0;
102   int numberOfTracks=-1;
103
104   // try the ESD as input
105   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
106   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
107   TString description;
108   if (esd != NULL) 
109     {
110       numberOfTracks=0;
111       esd->GetStdContent();
112     
113       for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++) 
114         {
115           if (CheckCondition(esd->GetTrack(i), esd->GetMagneticField())) numberOfTracks++;
116         }
117     }
118
119   // try the AliHLTExternal track data as input
120   if (iResult>=0 && numberOfTracks<0) 
121     {
122       for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack);
123            pBlock!=NULL; pBlock=GetNextInputBlock()) 
124         {
125           if (numberOfTracks<0) numberOfTracks=0;
126           vector<AliHLTGlobalBarrelTrack> tracks;
127           if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) 
128             {
129               for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
130                    element!=tracks.end(); element++) 
131                 {
132                   if (CheckCondition(&(*element), fSolenoidBz)) numberOfTracks++;
133                 }
134             } 
135           else if (iResult<0) 
136             {
137               HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d", 
138                        DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
139             }
140         }
141     }
142   if (numberOfTracks>=fMinTracks) 
143     {
144
145       SetDescription(fTriggerDecisionPars->GetDescription());
146       AliHLTReadoutList readout(fTriggerDecisionPars->GetReadoutListParameter());
147       AliHLTTriggerDecision decision(
148                                      true,
149                                      fTriggerDecisionPars->GetTriggerName().Data(),
150                                      AliHLTTriggerDomain(readout),
151                                      fTriggerDecisionPars->GetDescription()
152                                      );
153       TriggerEvent(&decision);
154     }
155   
156   return iResult;
157
158 }
159
160 template<class T>
161 bool AliHLTTriggerBarrelGeomMultiplicity::CheckCondition(T* track, float b)
162 {
163   bool ret = false;
164
165   // see header file for class documentation
166   if (!track) return false;
167
168   ret = IsInDetectors(track, b);
169
170   return ret;
171
172 }
173
174 template<class T>
175 bool AliHLTTriggerBarrelGeomMultiplicity::IsInDetectors(T* track, float b)
176 {
177   // See header file for class documentation  
178   for(Int_t i = 0; i < fDetectorArray->GetEntries(); i++)
179     {
180       AliHLTTriggerDetectorGeom *det = static_cast<AliHLTTriggerDetectorGeom*>(fDetectorArray->At(i));
181       Double_t trackPoint[3];
182       
183       det->GetInitialPoint(trackPoint);
184       
185       bool ret = track->Intersect(trackPoint, det->NormVector(), b);
186
187     }
188   return false;
189 }
190
191 int AliHLTTriggerBarrelGeomMultiplicity::DoInit(int argc, const char** argv)
192 {
193   // see header file for class documentation
194
195   // first configure the default
196   int iResult=0;
197
198   if (iResult>=0 && argc>0)
199     iResult=ConfigureFromArgumentString(argc, argv);
200
201   HLTWarning("TEST");
202   return iResult;
203 }
204
205 int AliHLTTriggerBarrelGeomMultiplicity::DoDeinit()
206  {
207   // see header file for class documentation
208   return 0;
209 }
210
211 int AliHLTTriggerBarrelGeomMultiplicity::ReadPreprocessorValues(const char* /*modules*/)
212 {
213   // see header file for class documentation
214
215   // TODO 2009-10-10: implementation
216   // for the moment very quick, just reload the magnetic field
217   return ConfigureFromCDBTObjString(kAliHLTCDBSolenoidBz);
218 }
219
220 int AliHLTTriggerBarrelGeomMultiplicity::GetDetectorGeomsFromCDBObject(const char *cdbEntry, const char* chainId)
221 {
222     // see header file for function documentation
223   int nDetectorGeoms=0;
224   const char *path = cdbEntry;
225   if(!path) path = fOCDBEntry;
226
227   if(path)
228     {
229       //     const char* chainId=GetChainId();
230       HLTInfo("configure from entry %s, chain id %s", path, (chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
231       AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
232       if (pEntry) 
233         {
234           TObjArray* pArr=dynamic_cast<TObjArray*>(pEntry->GetObject());
235           if (pArr) 
236             {
237
238               for(int i = 0; i < pArr->GetEntries(); i++)
239                 {
240                   if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDecision"))
241                     {
242                       fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
243                     }
244                   else if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDetectorGeom"))
245                     {
246                       fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
247                       nDetectorGeoms++;
248                       HLTWarning("received TObjArray of %d detector geometries", nDetectorGeoms);
249                     }
250                   else
251                     {
252                       HLTWarning("Unknown object in configuration object");
253                     }
254                 }
255             } 
256           else 
257             {
258               HLTError("configuration object \"%s\" has wrong type, required TObjArray", path);
259               nDetectorGeoms=-EINVAL;
260             }
261         }
262       else 
263         {
264           HLTError("can not fetch object \"%s\" from OCDB", path);
265           nDetectorGeoms=-ENOENT;
266         }
267     }
268   return nDetectorGeoms;
269 }
270
271 int AliHLTTriggerBarrelGeomMultiplicity::GetDetectorGeomsFromFile(const char *filename)
272 {
273     // see header file for function documentation
274   int nDetectorGeoms=0;
275
276   if (filename) 
277     {
278       TFile *geomfile = TFile::Open(filename, "READ");
279       
280       if(geomfile)
281         {
282           
283           HLTInfo("configure from file \"%s\"", filename);
284           TObjArray* pArr=dynamic_cast<TObjArray*>(geomfile->Get("GeomConf"));
285           if (pArr) 
286             {
287
288               for(int i = 0; i < pArr->GetEntries(); i++)
289                 {
290                   if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDecisionParameters"))
291                     {
292                       fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
293                     }
294                   else if(pArr->At(i)->InheritsFrom("AliHLTTriggerDetectorGeom"))
295                     {
296                       fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
297                       nDetectorGeoms++;
298                       HLTWarning("received detector geometry of type %s", pArr->At(i)->ClassName());
299                     }
300                   else
301                     {
302                       HLTWarning("Unknown object of type %s in configuration object", pArr->At(i)->ClassName());
303                     }
304                 }
305             } 
306           else 
307             {
308               HLTError("configuration object has wrong type, required TObjArray");
309               nDetectorGeoms=-EINVAL;
310             }
311           } 
312       else 
313         {
314           HLTError("could not open file \"%s\"", filename);
315           nDetectorGeoms=-ENOENT;
316         }
317     }
318   HLTWarning("received TObjArray with %d detector geometries", nDetectorGeoms);
319
320   return nDetectorGeoms;
321 }
322
323 int AliHLTTriggerBarrelGeomMultiplicity::ScanConfigurationArgument(int argc, const char** argv)
324 {
325   // See header file for class documentation
326   if (argc<=0) return 0;
327   int i=0;
328   TString argument=argv[i];
329
330   // -maxpt
331   if (argument.CompareTo("-geomfile")==0) 
332     {
333       if (++i>=argc) return -EPROTO;
334     
335       GetDetectorGeomsFromFile(argv[i]);
336     
337       return 2;
338     }    
339
340   if (argument.CompareTo("-trgname")==0) 
341     {
342       if (++i>=argc) return -EPROTO;
343       
344       fTriggerName = new char[128];
345       sprintf(fTriggerName, argv[i]);
346       
347       fOCDBEntry = fTriggerName;
348
349       return 2;
350   }    
351 }