]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerBarrelMultiplicity.cxx
changed HLT "fastjet" trigger: new set methods in AliFJWrapper using chars.... re...
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerBarrelMultiplicity.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: Matthias Richter <Matthias.Richter@ift.uib.no>        *
7 //*                  Jochen Thaeder <jochen@thaeder.de>                    *
8 //*                  for The ALICE HLT Project.                            *
9 //*                                                                        *
10 //* Permission to use, copy, modify and distribute this software and its   *
11 //* documentation strictly for non-commercial purposes is hereby granted   *
12 //* without fee, provided that the above copyright notice appears in all   *
13 //* copies and that both the copyright notice and this permission notice   *
14 //* appear in the supporting documentation. The authors make no claims     *
15 //* about the suitability of this software for any purpose. It is          *
16 //* provided "as is" without express or implied warranty.                  *
17 //**************************************************************************
18
19 /// @file   AliHLTTriggerBarrelMultiplicity.cxx
20 /// @author Matthias Richter, Jochen Thaeder
21 /// @date   2009-06-30
22 /// @brief  HLT trigger component for charged particle multiplicity in
23 ///         the central barrel.
24
25 // see header file for class documentation
26 // or
27 // refer to README to build package
28 // or
29 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
30
31 #include "AliHLTTriggerBarrelMultiplicity.h"
32 #include "AliHLTESDTrackCuts.h"
33 #include "AliESDtrack.h"
34 #include "AliESDEvent.h"
35 #include "AliHLTTriggerDecision.h"
36 #include "AliHLTDomainEntry.h"
37 #include "AliHLTGlobalBarrelTrack.h"
38 #include "AliHLTErrorGuard.h"
39 #include "TObjArray.h"
40 #include "TObjString.h"
41
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTTriggerBarrelMultiplicity)
44
45 AliHLTTriggerBarrelMultiplicity::AliHLTTriggerBarrelMultiplicity()
46   : AliHLTTrigger()
47   , fHLTESDTrackCuts(NULL)
48   , fMinTracks(1)
49   , fName()
50 {
51   // see header file for class documentation
52   // or
53   // refer to README to build package
54   // or
55   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
56 }
57
58 const char* AliHLTTriggerBarrelMultiplicity::fgkDefaultOCDBEntry="HLT/ConfigHLT/BarrelMultiplicityTrigger";
59
60 AliHLTTriggerBarrelMultiplicity::~AliHLTTriggerBarrelMultiplicity()
61 {
62   // see header file for class documentation
63 }
64
65 const char* AliHLTTriggerBarrelMultiplicity::GetTriggerName() const
66 {
67   // see header file for class documentation
68
69   if (!fName.IsNull())
70     return fName.Data();
71   else
72     return "BarrelMultiplicityTrigger";
73 }
74
75 AliHLTComponent* AliHLTTriggerBarrelMultiplicity::Spawn()
76 {
77   // see header file for class documentation
78   return new AliHLTTriggerBarrelMultiplicity;
79 }
80
81 int AliHLTTriggerBarrelMultiplicity::DoTrigger()
82 {
83   // see header file for class documentation
84
85   if (!IsDataEvent()) {
86     IgnoreEvent();  // dont generate any trigger decision.
87   }
88
89   int iResult=0;
90   int numberOfTracks=-1;
91
92   // try the ESD as input
93   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
94   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
95   
96   if (esd != NULL) {
97     numberOfTracks=0;
98     esd->GetStdContent();
99     
100     for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++) {
101       AliESDtrack *esdTrack = esd->GetTrack(i);
102       if ( !esdTrack )
103         continue;
104
105       if ( fHLTESDTrackCuts->IsSelected(esdTrack) )
106         numberOfTracks++;
107     }
108   }
109
110   // try the AliHLTExternal track data as input
111   // TODO: 2010-08-27
112   // AliHLTTrackCuts needs an AliESDtrack object and not just AliExternalTrackParam
113   // this part needs to be revised to work correctly with the track array as input
114   // - think about specific conversion method in AliHLTGlobalBarrelTrack
115   // - make sure that all necessary parameters are set
116   // - clarify what to do about the track flags
117   if (iResult>=0 && numberOfTracks<0) {
118     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack);
119          pBlock!=NULL; pBlock=GetNextInputBlock()) {
120       if (numberOfTracks<0) numberOfTracks=0;
121       vector<AliHLTGlobalBarrelTrack> tracks;
122       if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
123         for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
124              element!=tracks.end(); element++) {
125           ALIHLTERRORGUARD(1, "component needs to be revised to work with track array as input");
126           // TODO CHECK CONDITION HERE
127         }
128       } else if (iResult<0) {
129         HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d", 
130                  DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
131       }
132     }
133   }
134
135   bool condition=false;
136   TString description;
137
138   if (iResult>=0 && numberOfTracks>=0) {
139     if (numberOfTracks>=fMinTracks) {
140       description.Form("Event contains %d track(s) with : ", numberOfTracks);
141       description += fHLTESDTrackCuts->GetTitle();
142       condition=true;
143     } else {
144       description.Form("No tracks matching the tresholds found in the central barrel (min tracks %d) with : ", fMinTracks);
145       description += fHLTESDTrackCuts->GetTitle();
146     }
147   } else {
148     if(IsDataEvent()) {
149       description.Form("No input blocks found");
150     } else {
151       description.Form("No DataEvent found");
152     }
153   }
154   
155   SetDescription(description.Data());
156
157   // add a specific trigger decision object with initialized name
158   // the readout list however is fixed 
159   AliHLTTriggerDecision decision(
160                                  condition,
161                                  GetTriggerName(),
162                                  GetReadoutList(),
163                                  GetDescription()
164                                  );
165   TriggerEvent(&decision, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
166
167   return iResult;
168 }
169
170 int AliHLTTriggerBarrelMultiplicity::DoInit(int argc, const char** argv)
171 {
172   // see header file for class documentation
173   int iResult=0;
174
175   // check if the -triggername argument is used
176   // the name of the trigger determines the following initialization
177   vector<const char*> remainingArgs;
178   for (int i=0; i<argc; i++) {
179     if (strcmp(argv[i], "-triggername")==0) {
180       if (++i<argc) fName=argv[i];
181       else {
182         HLTError("invalid parameter for argument '-triggername', string expected");
183         return -EINVAL;
184       }
185       continue;
186     }
187     remainingArgs.push_back(argv[i]);
188   }
189
190   // get path from triggername, use default object otherwise
191   TString cdbPath;
192   if (!fName.IsNull()) {
193     cdbPath="HLT/ConfigHLT/";
194     cdbPath+=fName;
195   } else {
196     cdbPath=fgkDefaultOCDBEntry;
197   }
198
199   // -- Check if CDB object is AliHLTESDTrackCuts or TObjString 
200   //    and configure from it. Replace "-" by "_._" if needed in the cdbPath
201   iResult = ConfigureFromCDBObject(cdbPath);
202
203   // -- Configure from the command line parameters if specified
204   if (iResult>=0 && argc>0)
205     iResult=ConfigureFromArgumentString(remainingArgs.size(), &(remainingArgs[0]));
206
207   // -- Check if we have the track cuts for triggering
208   if (!fHLTESDTrackCuts) {
209     HLTError("No AliHLTESDTrackCuts object has been created as basis for triggering.");
210     iResult=-ENOENT;
211   }
212   else {
213     if (!fName.IsNull()) {
214       if (fName.Contains("Barrel_pT_Single"))
215         fMinTracks = 1;
216     }
217   }
218
219   return iResult;
220 }
221
222 int AliHLTTriggerBarrelMultiplicity::DoDeinit()
223 {
224   // see header file for class documentation
225
226   if (fHLTESDTrackCuts)
227     delete fHLTESDTrackCuts;
228   fHLTESDTrackCuts = NULL;
229
230   return 0;
231 }
232
233 int AliHLTTriggerBarrelMultiplicity::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
234 {
235   // see header file for class documentation
236
237   // configure from the specified antry or the default one
238   TString cdbPath;
239   if (!cdbEntry || cdbEntry[0]==0) {
240     if (!fName.IsNull()) {
241       cdbPath="HLT/ConfigHLT/";
242       cdbPath+=fName;
243     } else {
244       cdbPath=fgkDefaultOCDBEntry;
245     }
246   } else {
247     cdbPath=cdbEntry;
248   }
249
250   return ConfigureFromCDBObject(cdbPath);
251 }
252
253 int AliHLTTriggerBarrelMultiplicity::ReadPreprocessorValues(const char* /*modules*/)
254 {
255   // see header file for class documentation
256
257   // nothing to do for the moment
258   return 0;
259 }
260
261 Int_t AliHLTTriggerBarrelMultiplicity::ConfigureFromCDBObject(TString cdbPath)
262 {
263   // see header file for class documentation
264
265   Int_t iResult = 0;
266   TString arguments;
267
268   // -- check for "-" and replace by "_._" in the path name
269   cdbPath.ReplaceAll("-",1,"_._",3);
270
271   TObject* pCDBObject = LoadAndExtractOCDBObject(cdbPath);
272   if (pCDBObject) {
273     AliHLTESDTrackCuts *pCuts = dynamic_cast<AliHLTESDTrackCuts*>(pCDBObject);
274     if (pCuts) {
275       HLTInfo("Received AliHLTESDTrackCuts configuration object : \'%s\'", pCuts->GetTitle());
276       if (fHLTESDTrackCuts)
277         delete fHLTESDTrackCuts;
278       fHLTESDTrackCuts = pCuts;
279     }
280     else {
281       TObjString* pString = dynamic_cast<TObjString*>(pCDBObject);
282       if (pString) {
283         HLTInfo("Received configuration object string: \'%s\'", pString->GetString().Data());
284         arguments+=pString->GetString().Data();
285       } 
286       else {
287         HLTError("Configuration object \"%s\" has wrong type, required AliHLTESDTrackCuts or TObjString", cdbPath.Data());
288         iResult=-EINVAL;
289       }
290     }
291   } 
292   else {
293     HLTError("Can not fetch object \"%s\" from CDB", cdbPath.Data());
294     iResult=-ENOENT;
295   }
296   
297   if ( iResult>=0 && !arguments.IsNull() ) {
298     const Char_t* array = arguments.Data();
299     iResult = ConfigureFromArgumentString(1, &array);
300   }
301
302   return iResult;
303 }
304
305 int AliHLTTriggerBarrelMultiplicity::ScanConfigurationArgument(int argc, const char** argv)
306 {
307   // see header file for class documentation
308   if (argc<=0) return 0;
309   int i=0;
310   TString argument=argv[i];
311
312   if (!fHLTESDTrackCuts)
313     fHLTESDTrackCuts = new AliHLTESDTrackCuts("AliHLTESDTrackCuts","No track cuts");
314
315   // -maxpt
316   if (argument.CompareTo("-maxpt")==0) {
317     if (++i>=argc) return -EPROTO;
318     argument=argv[i];
319
320     Float_t minPt, maxPt;
321     fHLTESDTrackCuts->GetPtRange(minPt,maxPt);
322     maxPt = argument.Atof(); 
323     fHLTESDTrackCuts->SetPtRange(minPt,maxPt);
324
325     TString title = fHLTESDTrackCuts->GetTitle();
326     if (!title.CompareTo("No track cuts")) title = "";
327     else title += " && ";
328     title += Form("p_t < %f", maxPt);
329     fHLTESDTrackCuts->SetTitle(title);
330     return 2;
331   }    
332
333   // -minpt
334   if (argument.CompareTo("-minpt")==0) {
335     if (++i>=argc) return -EPROTO;
336     argument=argv[i];
337
338     Float_t minPt, maxPt;
339     fHLTESDTrackCuts->GetPtRange(minPt,maxPt);
340     minPt = argument.Atof(); 
341     fHLTESDTrackCuts->SetPtRange(minPt,maxPt);
342
343     TString title = fHLTESDTrackCuts->GetTitle();
344     if (!title.CompareTo("No track cuts")) title = "";
345     else title += " && ";
346     title += Form("p_t > %f", minPt);
347     fHLTESDTrackCuts->SetTitle(title);
348     return 2;
349   }    
350
351   // -mintracks
352   if (argument.CompareTo("-mintracks")==0) {
353     if (++i>=argc) return -EPROTO;
354     argument=argv[i];
355     fMinTracks=argument.Atoi();
356     return 2;
357   }    
358
359   // -min-ldca
360   // minimum longitudinal dca to vertex
361   if (argument.CompareTo("-min-ldca")==0) {
362     if (++i>=argc) return -EPROTO;
363     argument=argv[i];
364
365     fHLTESDTrackCuts->SetMinDCAToVertexZ(argument.Atof());
366     TString title = fHLTESDTrackCuts->GetTitle();
367     if (!title.CompareTo("No track cuts")) title = "";
368     else title += " && ";
369     title += Form("DCAz > %f", argument.Atof());
370     fHLTESDTrackCuts->SetTitle(title);
371     return 2;
372   }
373   
374   // -max-ldca
375   // maximum longitudinal dca to vertex
376   if (argument.CompareTo("-max-ldca")==0) {
377     if (++i>=argc) return -EPROTO;
378     argument=argv[i];
379
380     fHLTESDTrackCuts->SetMaxDCAToVertexZ(argument.Atof());
381     TString title = fHLTESDTrackCuts->GetTitle();
382     if (!title.CompareTo("No track cuts")) title = "";
383     else title += " && ";
384     title += Form("DCAz < %f", argument.Atof());
385     fHLTESDTrackCuts->SetTitle(title);
386     return 2;
387   }
388
389   // -min-tdca
390   // minimum transverse dca to vertex
391   if (argument.CompareTo("-min-tdca")==0) {
392     if (++i>=argc) return -EPROTO;
393     argument=argv[i];
394
395     fHLTESDTrackCuts->SetMinDCAToVertexXY(argument.Atof());
396     TString title = fHLTESDTrackCuts->GetTitle();
397     if (!title.CompareTo("No track cuts")) title = "";
398     else title += " && ";
399     title += Form("DCAr > %f", argument.Atof());
400     fHLTESDTrackCuts->SetTitle(title);
401     return 2;
402   }
403   
404   // -max-tdca
405   // maximum transverse dca to vertex
406   if (argument.CompareTo("-max-tdca")==0) {
407     if (++i>=argc) return -EPROTO;
408     argument=argv[i];
409
410     fHLTESDTrackCuts->SetMaxDCAToVertexXY(argument.Atof());
411     TString title = fHLTESDTrackCuts->GetTitle();
412     if (!title.CompareTo("No track cuts")) title = "";
413     else title += " && ";
414     title += Form("DCAr < %f", argument.Atof());
415     fHLTESDTrackCuts->SetTitle(title);
416     return 2;
417   }
418
419   // -- deprecated
420
421   // -dca-reference
422   // reference point for the transverse and longitudinal dca cut
423   if (argument.CompareTo("-dca-reference")==0) {
424     if (++i>=argc) return -EPROTO;
425     HLTWarning("argument -dca-reference deprecated, ESDTrackCuts only allow for DCA to vertex");
426     return 2;
427   }
428
429   // -solenoidBz
430   if (argument.CompareTo("-solenoidBz")==0) {
431     if (++i>=argc) return -EPROTO;
432     HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
433     return 2;
434   }
435
436   // unknown argument
437   return -EINVAL;
438 }