]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/trigger/AliHLTTriggerCosmics.cxx
Reverting the change to the statistics printing since it leads to a bug, cannot be...
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTTriggerCosmics.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: Kalliopi Kanaki <Kalliopi.Kanaki@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   AliHLTTriggerCosmics.cxx
19 /// @author Kalliopi Kanaki
20 /// @date   2011-02-25
21 /// @brief  HLT trigger component for tagging cosmics tracks in the TPC
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 "AliHLTTriggerCosmics.h"
30 #include "AliESDtrack.h"
31 #include "AliESDEvent.h"
32 #include "AliHLTTriggerDecision.h"
33 #include "AliHLTDomainEntry.h"
34 #include "AliHLTGlobalBarrelTrack.h"
35 #include "AliHLTErrorGuard.h"
36 #include "AliTPCcalibTime.h"
37 #include "AliTracker.h"
38
39 #include "TObjArray.h"
40 #include "TObjString.h"
41 #include "TDatabasePDG.h"
42
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTTriggerCosmics)
45
46 AliHLTTriggerCosmics::AliHLTTriggerCosmics()
47   : AliHLTTrigger()
48   , fName()
49   , fTrackSelection()
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* AliHLTTriggerCosmics::fgkDefaultOCDBEntry="HLT/ConfigHLT/CosmicsTrigger";
59
60 AliHLTTriggerCosmics::~AliHLTTriggerCosmics(){
61 // see header file for class documentation
62 }
63
64 const char* AliHLTTriggerCosmics::GetTriggerName() const{
65 // see header file for class documentation
66
67   if (!fName.IsNull())
68     return fName.Data();
69   else
70     return "CosmicsTrigger";
71 }
72
73 AliHLTComponent* AliHLTTriggerCosmics::Spawn(){
74   // see header file for class documentation
75   return new AliHLTTriggerCosmics;
76 }
77
78 int AliHLTTriggerCosmics::DoTrigger(){
79 // see header file for class documentation
80  
81   if (!IsDataEvent()) {
82     IgnoreEvent();  // dont generate any trigger decision.
83   }
84
85   int iResult=0;
86   int numberOfCosmics=-1;
87
88   const TObject *obj = GetFirstInputObject(kAliHLTAllDataTypes, "AliESDEvent");
89   AliESDEvent *esd   = dynamic_cast<AliESDEvent*>(const_cast<TObject*>(obj));
90   if(!esd){
91      printf("Empty ESD\n"); 
92      return 0;
93   }
94   esd->GetStdContent();
95   
96   Int_t startTime = esd->GetTimeStamp()-60*60*1;  //Start time one hour before first event, will make precise cuts later.
97   Int_t   endTime = esd->GetTimeStamp()+60*60*23; //End time 23 hours after first event.
98   fTrackSelection = new AliTPCcalibTime("calibTime","time dependent Vdrift calibration", startTime, endTime, 20*60);
99   
100   fTrackSelection->UpdateEventInfo(esd); // needed for getting the run number and time stamp information correct on the offline side
101     
102   //TArrayI clusterSideA(esd->GetNumberOfTracks());
103   //TArrayI clusterSideC(esd->GetNumberOfTracks());
104   Float_t bz = AliTracker::GetBz();
105   Double_t vtxx[3]={0,0,0};
106   Double_t svtxx[3]={0.000001,0.000001,100.};
107   AliESDVertex vtx(vtxx,svtxx);
108
109   for(Int_t i=0; i<esd->GetNumberOfTracks(); ++i){
110
111     AliESDtrack *track0 = esd->GetTrack(i); // track 0 upper part   
112     if(!track0) continue;    
113     if(!track0->GetOuterParam()) continue;
114     if(track0->GetOuterParam()->GetAlpha()<0) continue;
115     Double_t d1[3];
116     track0->GetDirection(d1);    
117
118     for(Int_t j=0; j<esd->GetNumberOfTracks(); ++j){
119       
120       if(i==j) continue;
121       AliESDtrack *track1 = esd->GetTrack(j); //track 1 lower part
122       if(!track1) continue; 
123       if(!track1->GetOuterParam()) continue;
124       if( track0->GetTPCNcls() + track1->GetTPCNcls()< 80 /*kMinClusters*/) continue;
125       
126       //Int_t nAC = TMath::Max( TMath::Min(clusterSideA[i], clusterSideC[j]), TMath::Min(clusterSideC[i], clusterSideA[j]));
127       //if(nAC<30/*kMinClustersCross*/) continue; 
128       //Int_t nA0 = clusterSideA[i];
129       //Int_t nC0 = clusterSideC[i];
130       //Int_t nA1 = clusterSideA[j];
131       //Int_t nC1 = clusterSideC[j];
132       //      if (track1->GetOuterParam()->GetAlpha()>0) continue;
133       //
134       Double_t d2[3];
135       track1->GetDirection(d2);
136       
137 //       AliTPCseed * seed0 = (AliTPCseed*) tpcSeeds.At(i);
138 //       AliTPCseed * seed1 = (AliTPCseed*) tpcSeeds.At(j);
139 //       if (! seed0) continue; 
140 //       if (! seed1) continue;
141       Float_t dir = (d1[0]*d2[0] + d1[1]*d2[1] + d1[2]*d2[2]);
142       Float_t dist0  = track0->GetLinearD(0,0);
143       Float_t dist1  = track1->GetLinearD(0,0);
144       //
145       // conservative cuts - convergence to be guarantied
146       // applying before track propagation
147       if (TMath::Abs(TMath::Abs(dist0)-TMath::Abs(dist1))>3 /*fCutMaxD*/) continue;   // distance to the 0,0
148       if (TMath::Abs(dir)<TMath::Abs(-0.99/*fCutMinDir*/)) continue;               // direction vector product
149                   
150       Float_t dvertex0[2];   //distance to 0,0
151       Float_t dvertex1[2];   //distance to 0,0 
152       track0->GetDZ(0,0,0,bz,dvertex0);
153       track1->GetDZ(0,0,0,bz,dvertex1);
154       if (TMath::Abs(dvertex0[1])>250) continue;
155       if (TMath::Abs(dvertex1[1])>250) continue;
156
157       Float_t dmax = TMath::Max(TMath::Abs(dist0),TMath::Abs(dist1));
158       AliExternalTrackParam param0(*track0);
159       AliExternalTrackParam param1(*track1);
160       //
161       // Propagate using Magnetic field and correct for material budget
162       //    
163       
164       AliTracker::PropagateTrackTo(&param0,dmax+1,TDatabasePDG::Instance()->GetParticle("e-")->Mass(),3,kTRUE);
165       AliTracker::PropagateTrackTo(&param1,dmax+1,TDatabasePDG::Instance()->GetParticle("e-")->Mass(),3,kTRUE);
166             
167       // Propagate rest to the 0,0 DCA - z should be ignored
168
169       param0.PropagateToDCA(&vtx,bz,1000);
170       param1.PropagateToDCA(&vtx,bz,1000);
171       param0.GetDZ(0,0,0,bz,dvertex0);
172       param1.GetDZ(0,0,0,bz,dvertex1);
173       
174       Double_t xyz0[3];
175       Double_t xyz1[3];
176       param0.GetXYZ(xyz0);
177       param1.GetXYZ(xyz1);
178       Bool_t isPair  = fTrackSelection->IsPair(&param0,&param1);
179       Bool_t isCross = fTrackSelection->IsCross(track0, track1);
180       Bool_t isSame  = fTrackSelection->IsSame(track0, track1);
181
182       if((isSame) || (isCross && isPair)){
183         if( track0->GetTPCNcls() + track1->GetTPCNcls()> 80 ){
184            numberOfCosmics++;
185         }
186       }
187     } // end 2nd order loop        
188   } // end 1st order loop
189   
190   bool condition = false;
191   TString description;
192  
193   if(numberOfCosmics>0){    
194      description.Form("Event contains %d cosmics", numberOfCosmics);
195      condition = true;
196   } 
197   else {
198     if(IsDataEvent()) {
199       description.Form("No input blocks found");
200     } else {
201       description.Form("No DataEvent found");
202     }
203   }
204    
205    SetDescription(description.Data());
206  
207   // add a specific trigger decision object with initialized name
208   // the readout list however is fixed 
209   AliHLTTriggerDecision decision(
210                                  condition,
211                                  GetTriggerName(),
212                                  GetReadoutList(),
213                                  GetDescription()
214                                  );
215   TriggerEvent(&decision, kAliHLTDataTypeTObject|kAliHLTDataOriginOut);
216
217   return iResult;
218 }
219
220 int AliHLTTriggerCosmics::DoInit(int argc, const char** argv){
221 // see header file for class documentation
222
223   int iResult = 0;
224
225   // check if the -triggername argument is used
226   // the name of the trigger determines the following initialization
227   vector<const char*> remainingArgs;
228   for (int i=0; i<argc; i++) {
229     if (strcmp(argv[i], "-triggername")==0) {
230       if (++i<argc) fName=argv[i];
231       else {
232         HLTError("invalid parameter for argument '-triggername', string expected");
233         return -EINVAL;
234       }
235       continue;
236     }
237     remainingArgs.push_back(argv[i]);
238   }
239
240   // get path from triggername, use default object otherwise
241   TString cdbPath;
242   if (!fName.IsNull()) {
243     cdbPath="HLT/ConfigHLT/";
244     cdbPath+=fName;
245   } else {
246     cdbPath=fgkDefaultOCDBEntry;
247   }
248
249   iResult = ConfigureFromCDBObject(cdbPath);
250
251   // -- Configure from the command line parameters if specified
252   if (iResult>=0 && argc>0) iResult = ConfigureFromArgumentString(remainingArgs.size(), &(remainingArgs[0]));
253
254   return iResult;
255 }
256
257 int AliHLTTriggerCosmics::DoDeinit(){
258 // see header file for class documentation
259
260   if(fTrackSelection) delete fTrackSelection; fTrackSelection = NULL;
261   return 0;
262 }
263
264 int AliHLTTriggerCosmics::Reconfigure(const char* cdbEntry, const char* /*chainId*/){
265 // see header file for class documentation
266
267   // configure from the specified antry or the default one
268   TString cdbPath;
269   if (!cdbEntry || cdbEntry[0]==0) {
270     if (!fName.IsNull()) {
271       cdbPath="HLT/ConfigHLT/";
272       cdbPath+=fName;
273     } else {
274       cdbPath=fgkDefaultOCDBEntry;
275     }
276   } else {
277     cdbPath=cdbEntry;
278   }
279
280   return ConfigureFromCDBObject(cdbPath);
281 }
282
283 int AliHLTTriggerCosmics::ReadPreprocessorValues(const char* /*modules*/){
284 // see header file for class documentation
285   return 0;
286 }
287
288 Int_t AliHLTTriggerCosmics::ConfigureFromCDBObject(TString cdbPath){
289 // see header file for class documentation
290
291   Int_t iResult = 0;
292   TString arguments;
293
294   // -- check for "-" and replace by "_._" in the path name
295   cdbPath.ReplaceAll("-",1,"_._",3);
296
297   TObject *pCDBObject = LoadAndExtractOCDBObject(cdbPath);
298   if (pCDBObject) {
299 //     AliHLTESDTrackCuts *pCuts = dynamic_cast<AliHLTESDTrackCuts*>(pCDBObject);
300 //     if (pCuts) {
301 //       HLTInfo("Received AliHLTESDTrackCuts configuration object : \'%s\'", pCuts->GetTitle());
302 //       if (fHLTESDTrackCuts)
303 //      delete fHLTESDTrackCuts;
304 //       fHLTESDTrackCuts = pCuts;
305 //     }
306 //     else {
307 //       TObjString *pString = dynamic_cast<TObjString*>(pCDBObject);
308 //       if(pString){
309 //      HLTInfo("Received configuration object string: \'%s\'", pString->GetString().Data());
310 //      arguments+=pString->GetString().Data();
311 //       } 
312 //       else{
313 //      HLTError("Configuration object \"%s\" has wrong type, required AliHLTESDTrackCuts or TObjString", cdbPath.Data());
314 //      iResult=-EINVAL;
315 //       }
316 //     }
317   } 
318   else {
319     HLTError("Cannot fetch object \"%s\" from CDB", cdbPath.Data());
320     iResult=-ENOENT;
321   }
322   
323   if( iResult>=0 && !arguments.IsNull() ){
324     const Char_t* array = arguments.Data();
325     iResult = ConfigureFromArgumentString(1, &array);
326   }
327
328   return iResult;
329 }
330
331 //int AliHLTTriggerCosmics::ScanConfigurationArgument(int argc, const char** argv){
332 // see header file for class documentation
333
334 //   if (argc<=0) return 0;
335 //   int i=0;
336 //   TString argument=argv[i];
337 // 
338 //   if (!fHLTESDTrackCuts)
339 //     fHLTESDTrackCuts = new AliHLTESDTrackCuts("AliHLTESDTrackCuts","No track cuts");
340 // 
341 //   // -maxpt
342 //   if (argument.CompareTo("-maxpt")==0) {
343 //     if (++i>=argc) return -EPROTO;
344 //     argument=argv[i];
345 // 
346 //     Float_t minPt, maxPt;
347 //     fHLTESDTrackCuts->GetPtRange(minPt,maxPt);
348 //     maxPt = argument.Atof(); 
349 //     fHLTESDTrackCuts->SetPtRange(minPt,maxPt);
350 // 
351 //     TString title = fHLTESDTrackCuts->GetTitle();
352 //     if (!title.CompareTo("No track cuts")) title = "";
353 //     else title += " && ";
354 //     title += Form("p_t < %f", maxPt);
355 //     fHLTESDTrackCuts->SetTitle(title);
356 //     return 2;
357 //   }    
358 // 
359 //   // -minpt
360 //   if (argument.CompareTo("-minpt")==0) {
361 //     if (++i>=argc) return -EPROTO;
362 //     argument=argv[i];
363 // 
364 //     Float_t minPt, maxPt;
365 //     fHLTESDTrackCuts->GetPtRange(minPt,maxPt);
366 //     minPt = argument.Atof(); 
367 //     fHLTESDTrackCuts->SetPtRange(minPt,maxPt);
368 // 
369 //     TString title = fHLTESDTrackCuts->GetTitle();
370 //     if (!title.CompareTo("No track cuts")) title = "";
371 //     else title += " && ";
372 //     title += Form("p_t > %f", minPt);
373 //     fHLTESDTrackCuts->SetTitle(title);
374 //     return 2;
375 //   }    
376 // 
377 //   // -mintracks
378 //   if (argument.CompareTo("-mintracks")==0) {
379 //     if (++i>=argc) return -EPROTO;
380 //     argument=argv[i];
381 //     fMinTracks=argument.Atoi();
382 //     return 2;
383 //   }    
384 // 
385 //   // -min-ldca
386 //   // minimum longitudinal dca to vertex
387 //   if (argument.CompareTo("-min-ldca")==0) {
388 //     if (++i>=argc) return -EPROTO;
389 //     argument=argv[i];
390 // 
391 //     fHLTESDTrackCuts->SetMinDCAToVertexZ(argument.Atof());
392 //     TString title = fHLTESDTrackCuts->GetTitle();
393 //     if (!title.CompareTo("No track cuts")) title = "";
394 //     else title += " && ";
395 //     title += Form("DCAz > %f", argument.Atof());
396 //     fHLTESDTrackCuts->SetTitle(title);
397 //     return 2;
398 //   }
399 //   
400 //   // -max-ldca
401 //   // maximum longitudinal dca to vertex
402 //   if (argument.CompareTo("-max-ldca")==0) {
403 //     if (++i>=argc) return -EPROTO;
404 //     argument=argv[i];
405 // 
406 //     fHLTESDTrackCuts->SetMaxDCAToVertexZ(argument.Atof());
407 //     TString title = fHLTESDTrackCuts->GetTitle();
408 //     if (!title.CompareTo("No track cuts")) title = "";
409 //     else title += " && ";
410 //     title += Form("DCAz < %f", argument.Atof());
411 //     fHLTESDTrackCuts->SetTitle(title);
412 //     return 2;
413 //   }
414 // 
415 //   // -min-tdca
416 //   // minimum transverse dca to vertex
417 //   if (argument.CompareTo("-min-tdca")==0) {
418 //     if (++i>=argc) return -EPROTO;
419 //     argument=argv[i];
420 // 
421 //     fHLTESDTrackCuts->SetMinDCAToVertexXY(argument.Atof());
422 //     TString title = fHLTESDTrackCuts->GetTitle();
423 //     if (!title.CompareTo("No track cuts")) title = "";
424 //     else title += " && ";
425 //     title += Form("DCAr > %f", argument.Atof());
426 //     fHLTESDTrackCuts->SetTitle(title);
427 //     return 2;
428 //   }
429 //   
430 //   // -max-tdca
431 //   // maximum transverse dca to vertex
432 //   if (argument.CompareTo("-max-tdca")==0) {
433 //     if (++i>=argc) return -EPROTO;
434 //     argument=argv[i];
435 // 
436 //     fHLTESDTrackCuts->SetMaxDCAToVertexXY(argument.Atof());
437 //     TString title = fHLTESDTrackCuts->GetTitle();
438 //     if (!title.CompareTo("No track cuts")) title = "";
439 //     else title += " && ";
440 //     title += Form("DCAr < %f", argument.Atof());
441 //     fHLTESDTrackCuts->SetTitle(title);
442 //     return 2;
443 //   }
444 // 
445 //   // -- deprecated
446 // 
447 //   // -dca-reference
448 //   // reference point for the transverse and longitudinal dca cut
449 //   if (argument.CompareTo("-dca-reference")==0) {
450 //     if (++i>=argc) return -EPROTO;
451 //     HLTWarning("argument -dca-reference deprecated, ESDTrackCuts only allow for DCA to vertex");
452 //     return 2;
453 //   }
454 // 
455 //   // -solenoidBz
456 //   if (argument.CompareTo("-solenoidBz")==0) {
457 //     if (++i>=argc) return -EPROTO;
458 //     HLTWarning("argument -solenoidBz is deprecated, magnetic field set up globally (%f)", GetBz());
459 //     return 2;
460 //   }
461 // 
462 //   // unknown argument
463 //   return -EINVAL;
464 //}