]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/trigger/AliHLTD0Trigger.cxx
Updates
[u/mrichter/AliRoot.git] / HLT / trigger / AliHLTD0Trigger.cxx
CommitLineData
5f4502cc 1// $Id: AliHLTD0Trigger.cxx
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: Gaute Ovrebekk *
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 AliHLTD0Trigger.cxx
19/// @author Gaute Ovrebekk
20/// @date 2009-10-28
21/// @brief HLT trigger component for D0->Kpi
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 "AliHLTD0Trigger.h"
30#include "AliESDEvent.h"
5f4502cc 31#include "AliESDv0.h"
32#include "AliHLTTriggerDecision.h"
33#include "AliHLTDomainEntry.h"
34#include "AliHLTGlobalBarrelTrack.h"
35#include "TObjArray.h"
36#include "TObjString.h"
37#include "TDatabasePDG.h"
38#include "AliESDVertex.h"
39#include "TH1F.h"
40#include "AliHLTD0toKpi.h"
9929f8f5 41#include "AliAODVertex.h"
629b904b 42#include "AliESDVertex.h"
3a626a12 43#include "AliAODRecoDecay.h"
2a743e38 44#include "AliHLTMCEvent.h"
45#include "AliStack.h"
46#include "TParticle.h"
10d746a6 47#include "TMap.h"
5f4502cc 48
49/** ROOT macro for the implementation of ROOT specific class methods */
50ClassImp(AliHLTD0Trigger)
51
52AliHLTD0Trigger::AliHLTD0Trigger()
53 : AliHLTTrigger()
54 , fPtMin(0.0)
55 , fdca(0.0)
56 , finvMass(0.0)
57 , fcosThetaStar(0.0)
58 , fd0(0.0)
59 , fd0d0(0.0)
60 , fcosPoint(0.0)
9929f8f5 61 , fplothisto(false)
62 , fUseV0(false)
052f676e 63 , fD0PDG(TDatabasePDG::Instance()->GetParticle(421)->Mass())
5f4502cc 64 , fD0mass(NULL)
252bba71 65 , fD0pt(NULL)
9929f8f5 66 , fPos()
67 , fNeg()
68 , fd0calc(NULL)
69 , ftwoTrackArray(NULL)
70 , fTotalD0(0)
9f96f527 71 , fTotalD0Onetrue(0)
2a743e38 72 , fTotalD0true(0)
2a743e38 73 , fEvent(NULL)
15f6cee9 74 , fuseKF(false)
5f4502cc 75{
9929f8f5 76
5f4502cc 77 // see header file for class documentation
78 // or
79 // refer to README to build package
80 // or
81 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
82
83}
84
85const char* AliHLTD0Trigger::fgkOCDBEntry="HLT/ConfigHLT/D0Trigger";
86
87AliHLTD0Trigger::~AliHLTD0Trigger()
88{
a7cf6e02 89
5f4502cc 90}
9929f8f5 91
5f4502cc 92const char* AliHLTD0Trigger::GetTriggerName() const
93{
94 // see header file for class documentation
95 return "D0Trigger";
96}
97
98AliHLTComponent* AliHLTD0Trigger::Spawn()
99{
100 // see header file for class documentation
101 return new AliHLTD0Trigger;
102}
103
104int AliHLTD0Trigger::DoTrigger()
105{
9929f8f5 106 // -- Iterator over Data Blocks --
107 //const AliHLTComponentBlockData* iter = NULL;
5f4502cc 108
9929f8f5 109 if (!IsDataEvent()) return 0;
5f4502cc 110
9f96f527 111 HLTDebug("Used Cuts: pT: %f , DCA: %f , InvMass: %f , CosThetaStar: %f , d0: %f , d0xd0: %f , CosPointingAngle: %f",fPtMin,fdca,finvMass,fcosThetaStar,fd0,fd0d0,fcosPoint);
112
9929f8f5 113 Int_t nD0=0;
9f96f527 114 Int_t nD0Onetrue=0;
2a743e38 115 Int_t nD0true=0;
9929f8f5 116 TString description;
5f4502cc 117
2a743e38 118 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeMCObject|kAliHLTDataOriginHLT); iter != NULL; iter = GetNextInputObject() ) {
119 fEvent = dynamic_cast<AliHLTMCEvent*>(const_cast<TObject*>( iter ) );
120 if ( ! fEvent ) {
121 HLTError( "No MC Event present!" );
122 break;
123 }
124 }
125
a7cf6e02 126 const AliESDVertex *Vertex=NULL;
8d9d674e 127
9929f8f5 128 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDObject); iter != NULL; iter = GetNextInputObject() ) {
129 if(fUseV0){
130 nD0=RecV0(iter);
131 }
132 else{
629b904b 133 AliESDEvent *event = dynamic_cast<AliESDEvent*>(const_cast<TObject*>( iter ) );
134 event->GetStdContent();
14978adc 135 Double_t field = event->GetMagneticField();
a7cf6e02 136 Vertex = event->GetPrimaryVertexTracks();
137 if(!Vertex || Vertex->GetNContributors()<2){
9f96f527 138 HLTDebug("Contributors in ESD vertex to low or not been set");
3a626a12 139 continue;
140 }
629b904b 141 for(Int_t it=0;it<event->GetNumberOfTracks();it++){
14978adc 142 SingleTrackSelect(event->GetTrack(it),Vertex,field);
629b904b 143 }
14978adc 144 RecD0(nD0,nD0Onetrue,nD0true,Vertex,field);
5f4502cc 145 }
5f4502cc 146 }
9929f8f5 147
3a626a12 148 for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDVertex|kAliHLTDataOriginOut);
629b904b 149 iter != NULL; iter = GetNextInputObject() ) {
a7cf6e02 150 Vertex = dynamic_cast<const AliESDVertex*>(iter);
151 if(!Vertex){
3a626a12 152 HLTError("Vertex object is corrupted");
629b904b 153 //iResult = -EINVAL;
154 }
155 }
156
157 for ( const AliHLTComponentBlockData* iter = GetFirstInputBlock(kAliHLTDataTypeTrack|kAliHLTDataOriginITS);
158 iter != NULL; iter = GetNextInputBlock() ) {
159 vector<AliHLTGlobalBarrelTrack> tracksVector;
160 AliHLTGlobalBarrelTrack::ConvertTrackDataArray(reinterpret_cast<const AliHLTTracksData*>(iter->fPtr), iter->fSize, tracksVector);
161
14978adc 162 Double_t field = GetBz();
a7cf6e02 163 if (Vertex){
164 for(UInt_t i=0;i<tracksVector.size();i++){
14978adc 165 SingleTrackSelect(&tracksVector[i],Vertex,field);
a7cf6e02 166 }
14978adc 167 RecD0(nD0,nD0Onetrue,nD0true,Vertex,field);
a7cf6e02 168 }
169 }
170
9929f8f5 171 fTotalD0+=nD0;
9f96f527 172 fTotalD0Onetrue += nD0Onetrue;
2a743e38 173 fTotalD0true += nD0true;
174
9929f8f5 175 ftwoTrackArray->Clear();
176 fPos.clear();
177 fNeg.clear();
629b904b 178
2a743e38 179 HLTDebug("Number of D0 found: %d",nD0);
9f96f527 180 HLTDebug("Number of D0 candidates with one track as D0 decay: %d",nD0Onetrue);
2a743e38 181 HLTDebug("Number of True D0 found: %d",nD0true);
182 HLTDebug("Total Number of D0 found: %d",fTotalD0);
9f96f527 183 HLTDebug("Number of D0 candidates with one track as D0 decay: %d",fTotalD0Onetrue);
2a743e38 184 HLTDebug("Total Number of True D0 found: %d",fTotalD0true);
5f4502cc 185
252bba71 186 if(fplothisto){
187 PushBack( (TObject*) fD0mass, kAliHLTDataTypeHistogram,0);
188 PushBack( (TObject*) fD0pt, kAliHLTDataTypeHistogram,0);
189 }
5f4502cc 190
9929f8f5 191 //if (iResult>=0) {
192 if (1) {
5f4502cc 193
194 if (nD0>=1) {
195 description.Form("Event contains %d D0(s)", nD0);
196 SetDescription(description.Data());
197 // Enable the central detectors for readout.
198 GetReadoutList().Enable(
199 AliHLTReadoutList::kITSSPD |
200 AliHLTReadoutList::kITSSDD |
201 AliHLTReadoutList::kITSSSD |
202 AliHLTReadoutList::kTPC |
203 AliHLTReadoutList::kTRD |
204 AliHLTReadoutList::kTOF |
205 AliHLTReadoutList::kHMPID |
206 AliHLTReadoutList::kPHOS
207 );
208 // Add the available HLT information for readout too.
209 GetTriggerDomain().Add("CLUSTERS", "TPC ");
210 TriggerEvent(true);
211 return 0;
212 }
213 description.Form("No D0");
214 } else {
215 description.Form("No input blocks found");
216 }
217 SetDescription(description.Data());
218 TriggerEvent(false);
9929f8f5 219 //return iResult;
220 return 0;
5f4502cc 221}
222
223int AliHLTD0Trigger::DoInit(int argc, const char** argv)
224{
9929f8f5 225
226 fd0calc = new AliHLTD0toKpi();
227 ftwoTrackArray = new TObjArray(2);
228
5f4502cc 229 fplothisto=false;
230 // see header file for class documentation
9929f8f5 231 fD0mass = new TH1F("hMass","D^{0} mass plot",100,1.7,2);
252bba71 232 fD0pt = new TH1F("hPt","D^{0} Pt plot",20,0,20);
5f4502cc 233 // first configure the default
234 int iResult=0;
235 if (iResult>=0) iResult=ConfigureFromCDBTObjString(fgkOCDBEntry);
236
237 // configure from the command line parameters if specified
238 if (iResult>=0 && argc>0)
239 iResult=ConfigureFromArgumentString(argc, argv);
240 return iResult;
241}
242
243int AliHLTD0Trigger::DoDeinit()
244{
245 // see header file for class documentation
a7cf6e02 246 if(fd0calc){delete fd0calc; fd0calc = NULL;}
247 if(fD0mass){delete fD0mass; fD0mass = NULL;}
925bbd08 248 if(fD0pt){delete fD0pt; fD0pt=NULL;}
249 if(ftwoTrackArray){delete ftwoTrackArray; ftwoTrackArray=NULL;}
a7cf6e02 250
5f4502cc 251 return 0;
252}
253
254int AliHLTD0Trigger::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
255{
256 // see header file for class documentation
257
258 // configure from the specified antry or the default one
259 const char* entry=cdbEntry;
260 if (!entry || entry[0]==0) {
261 entry=fgkOCDBEntry;
262 }
263
264 return ConfigureFromCDBTObjString(entry);
265}
266
267int AliHLTD0Trigger::ScanConfigurationArgument(int argc, const char** argv)
268{
269 // see header file for class documentation
270 if (argc<=0) return 0;
271 int i=0;
272 TString argument=argv[i];
273 // -minpt for decay
274 if (argument.CompareTo("-pt")==0) {
275 if (++i>=argc) return -EPROTO;
276 argument=argv[i];
277 fPtMin=argument.Atof();
278 return 2;
279 }
280 // minimum dca for decay tracks
281 if (argument.CompareTo("-dca")==0) {
282 if (++i>=argc) return -EPROTO;
283 argument=argv[i];
284 fdca=argument.Atof();
285 return 2;
286 }
287 // inv. mass half width.
288 if (argument.CompareTo("-invmass")==0) {
289 if (++i>=argc) return -EPROTO;
290 argument=argv[i];
291 finvMass=argument.Atof();
292 return 2;
293 }
294
295// cos theta for decay angle
296 if (argument.CompareTo("-costhetastar")==0) {
297 if (++i>=argc) return -EPROTO;
298 argument=argv[i];
299 fcosThetaStar=argument.Atof();
300 return 2;
301 }
302
303 // impact parameter for decay
304 if (argument.CompareTo("-d0")==0) {
305 if (++i>=argc) return -EPROTO;
306 argument=argv[i];
307 fd0=argument.Atof();
308 return 2;
309 }
310 // product of impact parameter
311 if (argument.CompareTo("-d0d0")==0) {
312 if (++i>=argc) return -EPROTO;
313 argument=argv[i];
314 fd0d0=argument.Atof();
315 return 2;
316 }
317 // product of impact parameter
318 if (argument.CompareTo("-cospoint")==0) {
319 if (++i>=argc) return -EPROTO;
320 argument=argv[i];
321 fcosPoint=argument.Atof();
322 return 2;
323 }
324 if (argument.CompareTo("-plothistogram")==0) {
5f4502cc 325 fplothisto=true;
9929f8f5 326 return 1;
327 }
328 if (argument.CompareTo("-usev0")==0) {
329 fUseV0=true;
330 return 1;
5f4502cc 331 }
15f6cee9 332 if (argument.CompareTo("-useKF")==0) {
333 fuseKF=true;
334 return 1;
335 }
5f4502cc 336 // unknown argument
337 return -EINVAL;
338}
9929f8f5 339
14978adc 340void AliHLTD0Trigger::SingleTrackSelect(AliExternalTrackParam* t, const AliESDVertex* pv,Double_t field){
a7cf6e02 341 // Offline uses || on the cuts of decay products
342 if (!pv) return;
8d9d674e 343
a7cf6e02 344 Double_t pvpos[3];
345 pv->GetXYZ(pvpos);
629b904b 346
9929f8f5 347 if(t->Pt()<fPtMin){return;}
14978adc 348 if(TMath::Abs(t->GetD(pvpos[0],pvpos[1],field)) > fd0){return;}
9929f8f5 349
350 if(t->Charge()>0){
351 fPos.push_back(t);
352 }
353 else{
354 fNeg.push_back(t);
355 }
356}
357
14978adc 358void AliHLTD0Trigger::RecD0(Int_t& nD0,Int_t& nD0Onetrue ,Int_t& nD0true,const AliESDVertex* pv,Double_t field){
a7cf6e02 359 // Default way of reconstructing D0's. Both from ESD and Barreltracks
9929f8f5 360 Double_t D0,D0bar,xdummy,ydummy;
361 Double_t d0[2];
362 Double_t svpos[3];
363 Double_t pvpos[3];
364
a7cf6e02 365 if(!pv){
629b904b 366 HLTError("No Vertex is set");
2a743e38 367 return;
9929f8f5 368 }
a7cf6e02 369 pv->GetXYZ(pvpos);
629b904b 370
371 for(UInt_t ip=0;ip<fPos.size();ip++){
372 AliExternalTrackParam *tP=fPos[ip];
373 for(UInt_t in=0;in<fNeg.size();in++){
374 AliExternalTrackParam *tN=fNeg[in];
375
14978adc 376 tP->PropagateToDCA(pv,field,kVeryBig); //do I need this??????
377 tN->PropagateToDCA(pv,field,kVeryBig);
9929f8f5 378
14978adc 379 Double_t dcatPtN = tP->GetDCA(tN,field,xdummy,ydummy);
9929f8f5 380 if(dcatPtN>fdca) { continue; }
381
629b904b 382 ftwoTrackArray->AddAt(tP,0);
383 ftwoTrackArray->AddAt(tN,1);
14978adc 384 AliAODVertex *vertexp1n1 = fd0calc->ReconstructSecondaryVertex(ftwoTrackArray,field,pv,fuseKF);
9929f8f5 385 if(!vertexp1n1) {
386 ftwoTrackArray->Clear();
387 continue;
388 }
389
390 vertexp1n1->GetXYZ(svpos);
391
14978adc 392 tP->PropagateToDCA(vertexp1n1,field,kVeryBig);
393 tN->PropagateToDCA(vertexp1n1,field,kVeryBig);
9929f8f5 394
3a626a12 395 /*
396 Double_t px[2],py[2],pz[2];
397 Double_t momentum[3];
398 tP->GetPxPyPz(momentum);
399 px[0] = momentum[0]; py[0] = momentum[1]; pz[0] = momentum[2];
400 tN->GetPxPyPz(momentum);
401 px[1] = momentum[0]; py[1] = momentum[1]; pz[1] = momentum[2];
402
403 Short_t dummycharge=0;
404 Double_t *dummyd0 = new Double_t[2];
405 Int_t nprongs = 2;
406
407 for(Int_t ipr=0;ipr<nprongs;ipr++) dummyd0[ipr]=0.;
408 AliAODRecoDecay *rd = new AliAODRecoDecay(0x0,nprongs,dummycharge,px,py,pz,dummyd0);
409 delete [] dummyd0; dummyd0=NULL;
410
411 UInt_t pdg2[2],pdg2bar[2];
412 Double_t mPDG,minv,minvbar;
413
414 pdg2[0]=211; pdg2[1]=321; pdg2bar[0]=321; pdg2bar[1]=211;
415 minv = rd->InvMass(nprongs,pdg2);
416 minvbar = rd->InvMass(nprongs,pdg2bar);
052f676e 417 if(TMath::Abs(minv-fD0PDG)>finvMass && TMath::Abs(minv-fD0PDG)>finvMass) {continue; delete vertexp1n1; delete rd;}
3a626a12 418 */
052f676e 419 if((TMath::Abs(fd0calc->InvMass(tN,tP)-fD0PDG)) > finvMass && TMath::Abs((fd0calc->InvMass(tP,tN))-fD0PDG) > finvMass){continue;}
9929f8f5 420 fd0calc->cosThetaStar(tN,tP,D0,D0bar);
421 if(TMath::Abs(D0) > fcosThetaStar && TMath::Abs(D0bar) > fcosThetaStar){continue;}
14978adc 422 d0[0] = tP->GetD(pvpos[0],pvpos[1],field);
423 d0[1] = tN->GetD(pvpos[0],pvpos[1],field);
9929f8f5 424 if((d0[0]*d0[1]) > fd0d0){continue;}
425 if(fd0calc->pointingAngle(tN,tP,pvpos,svpos) < fcosPoint){continue;}
426
427 if(fplothisto){
3a626a12 428 //fD0mass->Fill(minv);
429 //fD0mass->Fill(minvbar);
430 fD0mass->Fill(fd0calc->InvMass(tN,tP));
431 fD0mass->Fill(fd0calc->InvMass(tP,tN));
252bba71 432 fD0pt->Fill(fd0calc->Pt(tP,tN));
3a626a12 433 /*
052f676e 434 if((fd0calc->InvMass(tN,tP) - fD0PDG) > finvMass){
9929f8f5 435 fD0mass->Fill(fd0calc->InvMass(tN,tP));
436 }
437 else{
438 fD0mass->Fill(fd0calc->InvMass(tP,tN));
3a626a12 439 }
440 */
9929f8f5 441 }
3a626a12 442
9f96f527 443 if(CheckTrackMC(tP,tN)==2){
2a743e38 444 nD0true++;
445 }
9f96f527 446 if(CheckTrackMC(tP,tN)==1){
447 nD0Onetrue++;
448 }
2a743e38 449
9929f8f5 450 nD0++;
052f676e 451 vertexp1n1->RemoveCovMatrix();
9929f8f5 452 delete vertexp1n1;
453 }
454 }
9929f8f5 455}
456
457Int_t AliHLTD0Trigger::RecV0(const TObject* iter){
a7cf6e02 458 // Reconstruction D0's from the V0 found by the V0 finder
9929f8f5 459 int nD0=0;
460 Double_t d0[2];
461 Double_t D0,D0bar;
462 Double_t svpos[3];
463 Double_t pvpos[3];
464
465 AliESDEvent *event = dynamic_cast<AliESDEvent*>(const_cast<TObject*>( iter ) );
466 event->GetStdContent();
467 Int_t nV0 = event->GetNumberOfV0s();
468 Double_t field = event->GetMagneticField();
469 const AliESDVertex* pv = event->GetPrimaryVertexTracks();
470 pv->GetXYZ(pvpos);
471
472 for (Int_t iv=0; iv<nV0; iv++) {
473
474 AliESDtrack *tN=event->GetTrack( event->GetV0(iv)->GetNindex());
475 AliESDtrack *tP=event->GetTrack( event->GetV0(iv)->GetPindex());
476
477 if(tN->Pt()<fPtMin && tP->Pt()<fPtMin){continue;} //||????
478
479 d0[0] = tP->GetD(pvpos[0],pvpos[1],field);
480 d0[1] = tN->GetD(pvpos[0],pvpos[1],field);
481
482 if(d0[0]>fd0 && d0[0]>fd0){continue;} // make sure < or>
483
484 event->GetV0(iv)->GetXYZ(svpos[0],svpos[1],svpos[2]);
485
486 if(!tN->PropagateTo(svpos[0],field) && !tP->PropagateTo(svpos[0],field)){
487 HLTInfo("Tracks could not be propagated to secondary vertex");
488 continue;
489 }
490
491 Double_t tmp1, tmp2;
492 if(tN->GetDCA(tP,field,tmp1,tmp2) > fdca){continue;}
493
052f676e 494 if((fd0calc->InvMass(tN,tP) - fD0PDG) > finvMass && (fd0calc->InvMass(tP,tN) - fD0PDG) > finvMass){continue;}
9929f8f5 495 fd0calc->cosThetaStar(tN,tP,D0,D0bar);
496 if(D0 > fcosThetaStar && D0bar > fcosThetaStar){continue;}
497 if((d0[0]*d0[1]) > fd0d0){continue;}
498 if(fd0calc->pointingAngle(tN,tP,pvpos,svpos) < fcosPoint){continue;}
499
500 nD0++;
052f676e 501 if((fd0calc->InvMass(tN,tP) - fD0PDG) > finvMass){
9929f8f5 502 fD0mass->Fill(fd0calc->InvMass(tN,tP));
503 }
504 else{
505 fD0mass->Fill(fd0calc->InvMass(tP,tN));
506 }
507 }
508 return nD0;
509
510}
9f96f527 511int AliHLTD0Trigger::CheckTrackMC(AliExternalTrackParam* pt, AliExternalTrackParam* pn){
a7cf6e02 512 // Checks if decay products both came from a D0 or one.
9f96f527 513 if(!fEvent){return 0;}
2a743e38 514
515 int lP = pt->GetLabel();
516 int lN = pn->GetLabel();
517
518 if(lN>=0 && lP>=0){
519
520 int imP = (fEvent->Particle(lP))->GetFirstMother();
521 int imN = (fEvent->Particle(lN))->GetFirstMother();
522
523 if(imP>=0 && imN>=0){
524 TParticle * mP = fEvent->Particle(imP);
525 TParticle * mN = fEvent->Particle(imN);
dd2e5959 526 if((fabs(mP->GetPdgCode())==421 && fabs(mN->GetPdgCode())==421) && imP == imN){
9f96f527 527 return 2;
528 }
dd2e5959 529 if((fabs(mP->GetPdgCode())==421 || fabs(mN->GetPdgCode())==421) && imP == imN){
9f96f527 530 return 1;
2a743e38 531 }
532 }
533 }
9f96f527 534 return 0;
2a743e38 535}
10d746a6 536void AliHLTD0Trigger::GetOCDBObjectDescription( TMap* const targetMap)
537{
538 // Get a list of OCDB object description.
539 if (!targetMap) return;
540 targetMap->Add(new TObjString("HLT/ConfigHLT/D0Trigger"),new TObjString("Object with default cuts for D0 reconstruction" ));
541}