]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerBarrelMultiplicity.cxx
cd1e4c59d02738838516ccb1133c198b51142cb5
[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 //*                  for The ALICE HLT Project.                            *
8 //*                                                                        *
9 //* Permission to use, copy, modify and distribute this software and its   *
10 //* documentation strictly for non-commercial purposes is hereby granted   *
11 //* without fee, provided that the above copyright notice appears in all   *
12 //* copies and that both the copyright notice and this permission notice   *
13 //* appear in the supporting documentation. The authors make no claims     *
14 //* about the suitability of this software for any purpose. It is          *
15 //* provided "as is" without express or implied warranty.                  *
16 //**************************************************************************
17
18 /// @file   AliHLTTriggerBarrelMultiplicity.cxx
19 /// @author Matthias Richter
20 /// @date   2009-06-30
21 /// @brief  HLT trigger component for charged particle multiplicity in
22 ///         the central barrel.
23
24 // see header file for class documentation
25 // or
26 // refer to README to build package
27 // or
28 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
29
30 #include "AliHLTTriggerBarrelMultiplicity.h"
31 #include "AliESDEvent.h"
32 #include "AliHLTTriggerDecision.h"
33 #include "AliHLTDomainEntry.h"
34 #include "AliHLTGlobalBarrelTrack.h"
35 #include "TObjArray.h"
36 #include "TObjString.h"
37
38 /** ROOT macro for the implementation of ROOT specific class methods */
39 ClassImp(AliHLTTriggerBarrelMultiplicity)
40
41 AliHLTTriggerBarrelMultiplicity::AliHLTTriggerBarrelMultiplicity()
42   : AliHLTTrigger()
43   , fPtMin(0.0)
44   , fPtMax(0.0)
45   , fMinTracks(1)
46   , fDCAReference()
47   , fMinLDca(-1.)
48   , fMaxLDca(-1.)
49   , fMinTDca(-1.)
50   , fMaxTDca(-1.)
51   , fSolenoidBz(0.0)
52 {
53   // see header file for class documentation
54   // or
55   // refer to README to build package
56   // or
57   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
58
59   for (int i=0; i<fgkDCAReferenceSize; i++) fDCAReference[i]=0.0;
60 }
61
62 const char* AliHLTTriggerBarrelMultiplicity::fgkOCDBEntry="HLT/ConfigHLT/BarrelMultiplicityTrigger";
63
64 AliHLTTriggerBarrelMultiplicity::~AliHLTTriggerBarrelMultiplicity()
65 {
66   // see header file for class documentation
67 }
68
69 const char* AliHLTTriggerBarrelMultiplicity::GetTriggerName() const
70 {
71   // see header file for class documentation
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   int iResult=0;
85   int numberOfTracks=-1;
86
87   // try the ESD as input
88   const TObject* obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
89   AliESDEvent* esd = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
90   TString description;
91   TString ptcut,tdca,ldca,dcaref,op1st,op2nd;
92   if (esd != NULL) {
93     numberOfTracks=0;
94     esd->GetStdContent();
95     
96     for (Int_t i = 0; i < esd->GetNumberOfTracks(); i++) {
97       if (CheckCondition(esd->GetTrack(i), esd->GetMagneticField())) numberOfTracks++;
98     }
99   }
100
101   // try the AliHLTExternal track data as input
102   if (iResult>=0 && numberOfTracks<0) {
103     for (const AliHLTComponentBlockData* pBlock=GetFirstInputBlock(kAliHLTDataTypeTrack);
104          pBlock!=NULL; pBlock=GetNextInputBlock()) {
105       if (numberOfTracks<0) numberOfTracks=0;
106       vector<AliHLTGlobalBarrelTrack> tracks;
107       if ((iResult=AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(pBlock->fPtr), pBlock->fSize, tracks))>0) {
108         for (vector<AliHLTGlobalBarrelTrack>::iterator element=tracks.begin();
109              element!=tracks.end(); element++) {
110           if (CheckCondition(&(*element), fSolenoidBz)) numberOfTracks++;
111         }
112       } else if (iResult<0) {
113         HLTError("can not extract tracks from data block of type %s (specification %08x) of size %d: error %d", 
114                  DataType2Text(pBlock->fDataType).c_str(), pBlock->fSpecification, pBlock->fSize, iResult);
115       }
116     }
117   }
118
119   if (iResult>=0 && numberOfTracks>=0) {
120     if (fPtMax>fPtMin) {
121       ptcut.Form(" %.02f GeV/c <= pt < %.02f GeV/c", fPtMin, fPtMax);
122     } else {
123       ptcut.Form(" pt >= %.02f GeV/c", fPtMin);
124     }
125
126     if (fMinTDca>=0.0) {
127       if (fMaxTDca>=0.0) {
128         tdca.Form(", %.02f<=transverse_dca<=%.02f", fMinTDca, fMaxTDca);
129       } else {
130         tdca.Form(" transverse_dca >= %.02f", fMinTDca);
131       }
132     } else if (fMaxTDca>=0.0) {
133         tdca.Form(" transverse_dca<=%.02f", fMaxTDca);
134     }
135     if (!tdca.IsNull()) {
136       if (op1st.IsNull()) op1st=" && ";
137       else op2nd=" && ";
138     }
139
140     if (fMinLDca>=0.0) {
141       if (fMaxLDca>=0.0) {
142         ldca.Form(" %.02f<=longitudinal_dca<=%.02f", fMinLDca, fMaxLDca);
143       } else {
144         ldca.Form(" longitudinal_dca >= %.02f", fMinLDca);
145       }
146     } else if (fMaxLDca>=0.0) {
147         ldca.Form(" longitudinal_dca<=%.02f", fMaxLDca);
148     }
149     if (!ldca.IsNull()) {
150       if (op1st.IsNull()) op1st=" && ";
151       else op2nd=" && ";
152     }
153
154     if (fMinTDca>=0.0 || fMaxTDca>=0 || fMinLDca>=0.0 || fMaxLDca>=0) {
155       dcaref.Form(" (%.01f,%.01f,%.01f)", fDCAReference[0], fDCAReference[1], fDCAReference[2]);
156     }
157
158     if (numberOfTracks>=fMinTracks) {
159       description.Form("Event contains %d track(s) with ", numberOfTracks);
160       description+=ptcut;
161       description+=op1st;
162       description+=ldca;
163       description+=op2nd;
164       description+=tdca;
165       description+=dcaref;
166       SetDescription(description.Data());
167       // Enable the central detectors for readout.
168       GetReadoutList().Enable(
169                               AliHLTReadoutList::kITSSPD |
170                               AliHLTReadoutList::kITSSDD |
171                               AliHLTReadoutList::kITSSSD |
172                               AliHLTReadoutList::kTPC |
173                               AliHLTReadoutList::kTRD |
174                               AliHLTReadoutList::kTOF |
175                               AliHLTReadoutList::kHMPID |
176                               AliHLTReadoutList::kPHOS
177                               );
178       // Add the available HLT information for readout too.
179       GetTriggerDomain().Add("CLUSTERS", "TPC ");
180       TriggerEvent(true);
181       return 0;
182     }
183     description.Form("No tracks matching the tresholds found in the central barrel (min tracks %d, ", fMinTracks);
184     description+=ptcut;
185     description+=op1st;
186     description+=ldca;
187     description+=op2nd;
188     description+=tdca;
189     description+=dcaref;
190     description+=")";
191   } else {
192     description.Form("No input blocks found");
193   }
194   SetDescription(description.Data());
195   TriggerEvent(false);
196   return iResult;
197 }
198
199 template<class T>
200 bool AliHLTTriggerBarrelMultiplicity::CheckCondition(T* track, float b)
201 {
202   // see header file for class documentation
203   if (!track) return false;
204
205   // check on ptransverse momentum
206   if (TMath::Abs(track->Pt()) < fPtMin || (fPtMax>fPtMin && TMath::Abs(track->Pt()) > fPtMax)) {
207     return false;
208   }
209
210   // check on transverse and longitudinal DCA
211   if (fMinTDca>=0.0 || fMaxTDca>=0 || fMinLDca>=0.0 || fMaxLDca>=0) {
212     Float_t dz[2]={0.0,0.0};
213     track->GetDZ(fDCAReference[0], fDCAReference[1], fDCAReference[2], b, dz);
214     HLTDebug("checking dca condition: transversal %f logitudinal %f", dz[0], dz[1]);
215     if (fMinTDca>=0 && TMath::Abs(dz[0])<fMinTDca) return false;
216     if (fMaxTDca>=0 && TMath::Abs(dz[0])>fMaxTDca) return false;
217     if (fMinLDca>=0 && TMath::Abs(dz[1])<fMinLDca) return false;
218     if (fMaxLDca>=0 && TMath::Abs(dz[1])>fMaxLDca) return false;
219   }
220
221   return true;
222 }
223
224 int AliHLTTriggerBarrelMultiplicity::DoInit(int argc, const char** argv)
225 {
226   // see header file for class documentation
227
228   // first configure the default
229   int iResult=0;
230   iResult=ConfigureFromCDBTObjString(kAliHLTCDBSolenoidBz);
231   if (iResult>=0) iResult=ConfigureFromCDBTObjString(fgkOCDBEntry);
232
233   // configure from the command line parameters if specified
234   if (iResult>=0 && argc>0)
235     iResult=ConfigureFromArgumentString(argc, argv);
236   return iResult;
237 }
238
239 int AliHLTTriggerBarrelMultiplicity::DoDeinit()
240 {
241   // see header file for class documentation
242   return 0;
243 }
244
245 int AliHLTTriggerBarrelMultiplicity::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
246 {
247   // see header file for class documentation
248
249   // configure from the specified antry or the default one
250   const char* entry=cdbEntry;
251   if (!entry || entry[0]==0) {
252     ConfigureFromCDBTObjString(kAliHLTCDBSolenoidBz);
253     entry=fgkOCDBEntry;
254   }
255
256   return ConfigureFromCDBTObjString(entry);
257 }
258
259 int AliHLTTriggerBarrelMultiplicity::ReadPreprocessorValues(const char* /*modules*/)
260 {
261   // see header file for class documentation
262
263   // TODO 2009-09-10: implementation
264   // for the moment very quick, just reload the magnetic field
265   return ConfigureFromCDBTObjString(kAliHLTCDBSolenoidBz);
266 }
267
268 int AliHLTTriggerBarrelMultiplicity::ScanConfigurationArgument(int argc, const char** argv)
269 {
270   // see header file for class documentation
271   if (argc<=0) return 0;
272   int i=0;
273   TString argument=argv[i];
274
275   // -maxpt
276   if (argument.CompareTo("-maxpt")==0) {
277     if (++i>=argc) return -EPROTO;
278     argument=argv[i];
279     fPtMax=argument.Atof();
280     return 2;
281   }    
282
283   // -minpt
284   if (argument.CompareTo("-minpt")==0) {
285     if (++i>=argc) return -EPROTO;
286     argument=argv[i];
287     fPtMin=argument.Atof();
288     return 2;
289   }    
290
291   // -mintracks
292   if (argument.CompareTo("-mintracks")==0) {
293     if (++i>=argc) return -EPROTO;
294     argument=argv[i];
295     fMinTracks=argument.Atoi();
296     return 2;
297   }    
298
299   // -dca-reference
300   // reference point for the transverse and longitudinal dca cut
301   if (argument.CompareTo("-dca-reference")==0) {
302     if (++i>=argc) return -EPROTO;
303     argument=argv[i];
304     // scan x,y,z
305     TObjArray* pTokens=argument.Tokenize("'");
306     if (pTokens) {
307       for (int c=0; c<pTokens->GetEntriesFast() && c<fgkDCAReferenceSize; c++) {
308         argument=((TObjString*)pTokens->At(c))->GetString();
309         fDCAReference[i]=argument.Atof();
310       }
311       delete pTokens;
312     }
313     return 2;
314   }
315
316   // -min-ldca
317   // minimum longitudinal dca to reference point
318   if (argument.CompareTo("-min-ldca")==0) {
319     if (++i>=argc) return -EPROTO;
320     argument=argv[i];
321     fMinLDca=argument.Atof();
322     return 2;
323   }
324   
325   // -max-ldca
326   // maximum longitudinal dca to reference point
327   if (argument.CompareTo("-max-ldca")==0) {
328     if (++i>=argc) return -EPROTO;
329     argument=argv[i];
330     fMaxLDca=argument.Atof();
331     return 2;
332   }
333
334   // -min-tdca
335   // minimum transverse dca to reference point
336   if (argument.CompareTo("-min-tdca")==0) {
337     if (++i>=argc) return -EPROTO;
338     argument=argv[i];
339     fMinTDca=argument.Atof();
340     return 2;
341   }
342   
343   // -max-tdca
344   // maximum transverse dca to reference point
345   if (argument.CompareTo("-max-tdca")==0) {
346     if (++i>=argc) return -EPROTO;
347     argument=argv[i];
348     fMaxTDca=argument.Atof();
349     return 2;
350   }
351
352   // -solenoidBz
353   if (argument.CompareTo("-solenoidBz")==0) {
354     if (++i>=argc) return -EPROTO;
355     argument=argv[i];
356     fSolenoidBz=argument.Atof();
357     return 2;
358   }
359
360   // unknown argument
361   return -EINVAL;
362 }