- adding AliHLTTriggerDecisionParameters to configure the geom trigger from OCDB.
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerBarrelGeomMultiplicity.cxx
CommitLineData
46906312 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
1ecefac2 20/// @brief HLT trigger component for charged particle multiplicity
21/// within a geometrical acceptance in the central barrel.
46906312 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"
1ecefac2 30#include "AliHLTTriggerDetectorGeom.h"
fde46e9e 31#include "AliHLTTriggerDecisionParameters.h"
46906312 32#include "AliESDEvent.h"
33#include "AliHLTTriggerDecision.h"
34#include "AliHLTDomainEntry.h"
35#include "AliHLTGlobalBarrelTrack.h"
36#include "TObjArray.h"
37#include "TObjString.h"
1ecefac2 38#include "TObjArray.h"
39#include "TVector3.h"
40#include "AliCDBEntry.h"
41#include "AliCDBManager.h"
42#include "TFile.h"
43#include "AliHLTTrigger.h"
46906312 44
45/** ROOT macro for the implementation of ROOT specific class methods */
46ClassImp(AliHLTTriggerBarrelGeomMultiplicity)
47
48AliHLTTriggerBarrelGeomMultiplicity::AliHLTTriggerBarrelGeomMultiplicity()
49 : AliHLTTrigger()
1ecefac2 50 , fSolenoidBz(0)
fde46e9e 51 , fMinTracks(1)
1ecefac2 52 , fDetectorArray(0)
46906312 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
fde46e9e 59 fDetectorArray = new TObjArray(1);
46906312 60
61}
62
46906312 63AliHLTTriggerBarrelGeomMultiplicity::~AliHLTTriggerBarrelGeomMultiplicity()
64{
65 // see header file for class documentation
66}
67
1ecefac2 68const char* AliHLTTriggerBarrelGeomMultiplicity::GetTriggerName() const
46906312 69{
70 // see header file for class documentation
fde46e9e 71 // const char* name = fTriggerName;
72 // if(name) return name;
46906312 73 return "BarrelGeomMultiplicityTrigger";
74}
75
76AliHLTComponent* AliHLTTriggerBarrelGeomMultiplicity::Spawn()
77{
78 // see header file for class documentation
79 return new AliHLTTriggerBarrelGeomMultiplicity;
80}
81
1ecefac2 82int 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
46906312 98int 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;
1ecefac2 108 if (esd != NULL)
109 {
110 numberOfTracks=0;
111 esd->GetStdContent();
46906312 112
1ecefac2 113 for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++)
114 {
115 if (CheckCondition(esd->GetTrack(i), esd->GetMagneticField())) numberOfTracks++;
116 }
46906312 117 }
46906312 118
119 // try the AliHLTExternal track data as input
1ecefac2 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 }
46906312 140 }
46906312 141 }
1ecefac2 142 if (numberOfTracks>=fMinTracks)
143 {
1ecefac2 144
fde46e9e 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);
46906312 154 }
1ecefac2 155
46906312 156 return iResult;
1ecefac2 157
46906312 158}
159
160template<class T>
161bool AliHLTTriggerBarrelGeomMultiplicity::CheckCondition(T* track, float b)
162{
1ecefac2 163 bool ret = false;
164
46906312 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
174template<class T>
1ecefac2 175bool AliHLTTriggerBarrelGeomMultiplicity::IsInDetectors(T* track, float b)
46906312 176{
1ecefac2 177 // See header file for class documentation
178 for(Int_t i = 0; i < fDetectorArray->GetEntries(); i++)
46906312 179 {
1ecefac2 180 AliHLTTriggerDetectorGeom *det = static_cast<AliHLTTriggerDetectorGeom*>(fDetectorArray->At(i));
46906312 181 Double_t trackPoint[3];
1ecefac2 182
46906312 183 det->GetInitialPoint(trackPoint);
1ecefac2 184
46906312 185 bool ret = track->Intersect(trackPoint, det->NormVector(), b);
186
46906312 187 }
188 return false;
189}
190
191int 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;
46906312 197
46906312 198 if (iResult>=0 && argc>0)
199 iResult=ConfigureFromArgumentString(argc, argv);
1ecefac2 200
fde46e9e 201 HLTWarning("TEST");
46906312 202 return iResult;
203}
204
205int AliHLTTriggerBarrelGeomMultiplicity::DoDeinit()
1ecefac2 206 {
46906312 207 // see header file for class documentation
208 return 0;
209}
210
1ecefac2 211int AliHLTTriggerBarrelGeomMultiplicity::ReadPreprocessorValues(const char* /*modules*/)
46906312 212{
213 // see header file for class documentation
214
1ecefac2 215 // TODO 2009-10-10: implementation
216 // for the moment very quick, just reload the magnetic field
217 return ConfigureFromCDBTObjString(kAliHLTCDBSolenoidBz);
218}
219
220int 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;
46906312 226
1ecefac2 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 {
fde46e9e 242 fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
1ecefac2 243 }
244 else if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDetectorGeom"))
245 {
246 fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
247 nDetectorGeoms++;
fde46e9e 248 HLTWarning("received TObjArray of %d detector geometries", nDetectorGeoms);
1ecefac2 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;
46906312 269}
270
1ecefac2 271int AliHLTTriggerBarrelGeomMultiplicity::GetDetectorGeomsFromFile(const char *filename)
46906312 272{
1ecefac2 273 // see header file for function documentation
274 int nDetectorGeoms=0;
46906312 275
1ecefac2 276 if (filename)
277 {
278 TFile *geomfile = TFile::Open(filename, "READ");
279
280 if(geomfile)
281 {
282
283 HLTInfo("configure from file \"%s\"", filename);
fde46e9e 284 TObjArray* pArr=dynamic_cast<TObjArray*>(geomfile->Get("GeomConf"));
1ecefac2 285 if (pArr)
286 {
287
288 for(int i = 0; i < pArr->GetEntries(); i++)
289 {
fde46e9e 290 if(!strcmp(pArr->At(i)->ClassName(), "AliHLTTriggerDecisionParameters"))
1ecefac2 291 {
fde46e9e 292 fTriggerDecisionPars = dynamic_cast<AliHLTTriggerDecisionParameters*>(pArr->At(i));
1ecefac2 293 }
fde46e9e 294 else if(pArr->At(i)->InheritsFrom("AliHLTTriggerDetectorGeom"))
1ecefac2 295 {
296 fDetectorArray->AddLast(dynamic_cast<AliHLTTriggerDetectorGeom*>(pArr->At(i)));
297 nDetectorGeoms++;
fde46e9e 298 HLTWarning("received detector geometry of type %s", pArr->At(i)->ClassName());
1ecefac2 299 }
300 else
301 {
fde46e9e 302 HLTWarning("Unknown object of type %s in configuration object", pArr->At(i)->ClassName());
1ecefac2 303 }
304 }
305 }
306 else
307 {
308 HLTError("configuration object has wrong type, required TObjArray");
309 nDetectorGeoms=-EINVAL;
310 }
311 }
312 else
313 {
fde46e9e 314 HLTError("could not open file \"%s\"", filename);
1ecefac2 315 nDetectorGeoms=-ENOENT;
316 }
317 }
fde46e9e 318 HLTWarning("received TObjArray with %d detector geometries", nDetectorGeoms);
319
1ecefac2 320 return nDetectorGeoms;
46906312 321}
322
323int AliHLTTriggerBarrelGeomMultiplicity::ScanConfigurationArgument(int argc, const char** argv)
324{
1ecefac2 325 // See header file for class documentation
46906312 326 if (argc<=0) return 0;
327 int i=0;
328 TString argument=argv[i];
329
330 // -maxpt
1ecefac2 331 if (argument.CompareTo("-geomfile")==0)
332 {
333 if (++i>=argc) return -EPROTO;
334
335 GetDetectorGeomsFromFile(argv[i]);
336
337 return 2;
338 }
46906312 339
fde46e9e 340 if (argument.CompareTo("-trgname")==0)
1ecefac2 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;
46906312 350 }
46906312 351}