9 #include "TDatabasePDG.h"
10 #include "AliRunLoader.h"
17 #include "TLinearFitter.h"
19 #include "TTreeStream.h"
25 #include "AliTracker.h"
26 #include "AliESDEvent.h"
27 #include "AliESDtrack.h"
28 #include "AliESDfriend.h"
29 #include "AliESDfriendTrack.h"
30 #include "AliMathBase.h"
31 #include "AliTPCseed.h"
32 #include "AliTPCclusterMI.h"
34 #include "AliKFParticle.h"
35 #include "AliKFVertex.h"
37 #include "AliTrackPointArray.h"
38 #include "AliTPCcalibV0.h"
41 #include "TTreeStream.h"
42 #include "AliTPCcalibDB.h"
43 #include "AliTPCCorrection.h"
44 #include "AliGRPObject.h"
45 #include "AliTPCTransform.h"
46 #include "AliAnalysisManager.h"
50 ClassImp(AliTPCcalibV0)
53 AliTPCcalibV0::AliTPCcalibV0() :
66 AliTPCcalibV0::AliTPCcalibV0(const Text_t *name, const Text_t *title):
77 fPdg = new TDatabasePDG;
78 // create output histograms
83 AliTPCcalibV0::~AliTPCcalibV0(){
95 void AliTPCcalibV0::ProcessESD(AliESDEvent *esd){
100 AliKFParticle::SetField(esd->GetMagneticField());
101 if (TMath::Abs(AliTracker::GetBz())<1) return;
106 void AliTPCcalibV0::DumpToTreeHPT(AliESDEvent *esd){
108 // Dump V0s fith full firend information to the
110 if (TMath::Abs(AliTracker::GetBz())<1) return;
111 const Int_t kMinCluster=110;
112 const Float_t kMinPt =4.;
113 AliESDfriend *esdFriend=static_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend"));
115 // Printf("ERROR: esdFriend not available");
119 Int_t ntracks=esd->GetNumberOfTracks();
120 for (Int_t i=0;i<ntracks;++i) {
122 AliESDtrack *track = esd->GetTrack(i);
123 if (track->GetTPCncls()<kMinCluster) continue;
124 if (TMath::Abs(AliTracker::GetBz())>1){ // cut on momenta if measured
125 if (track->Pt()>kMinPt) isOK=kTRUE;
127 if (TMath::Abs(AliTracker::GetBz())<1){ // require primary track for the B field OFF data
128 Bool_t isAccepted=kTRUE;
129 if (!track->IsOn(AliESDtrack::kITSrefit)) isAccepted=kFALSE;
130 if (!track->IsOn(AliESDtrack::kTPCrefit)) isAccepted=kFALSE;
131 if (!track->IsOn(AliESDtrack::kTOFout)) isAccepted=kFALSE;
132 Float_t dvertex[2],cvertex[3];
133 track->GetImpactParametersTPC(dvertex,cvertex);
134 if (TMath::Abs(dvertex[0]/TMath::Sqrt(cvertex[0]+0.01))>20) isAccepted=kFALSE;
135 if (TMath::Abs(dvertex[1]/TMath::Sqrt(TMath::Abs(cvertex[2]+0.01)))>20) isAccepted=kFALSE;
136 track->GetImpactParameters(dvertex,cvertex);
137 if (TMath::Abs(dvertex[0]/TMath::Sqrt(cvertex[0]+0.01))>10) isAccepted=kFALSE;
138 if (TMath::Abs(dvertex[1]/TMath::Sqrt(TMath::Abs(cvertex[2]+0.01)))>10) isAccepted=kFALSE;
139 if (!isAccepted) isOK=kFALSE;
141 if ( track->GetTPCsignal()>100 && track->GetInnerParam()->Pt()>1 ){
142 if (track->IsOn(AliESDtrack::kITSin)||track->IsOn(AliESDtrack::kTRDout)||track->IsOn(AliESDtrack::kTOFin))
145 TString filename(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
146 Int_t eventNumber = esd->GetEventNumberInFile();
147 Bool_t hasFriend=(esdFriend) ? (esdFriend->GetTrack(i)!=0):0;
148 Bool_t hasITS=(track->GetNcls(0)>2);
149 printf("DUMPIONTrack:%s|%f|%d|%d|%d\n",filename.Data(),track->GetInnerParam()->Pt()*track->GetTPCsignal()/50., eventNumber,hasFriend,hasITS);
153 TString filename(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
154 Int_t eventNumber = esd->GetEventNumberInFile();
155 Bool_t hasFriend=(esdFriend) ? (esdFriend->GetTrack(i)!=0):0;
156 Bool_t hasITS=(track->GetNcls(0)>2);
157 printf("DUMPHPTTrack:%s|%f|%d|%d|%d\n",filename.Data(),track->Pt(), eventNumber,hasFriend,hasITS);
159 if (!esdFriend) continue;
160 AliESDfriendTrack *friendTrack = esdFriend->GetTrack(i);
161 if (!friendTrack) continue;
166 TObject *calibObject;
167 AliTPCseed *seed = 0;
168 for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) {
169 if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
173 fHPTTree = new TTree("HPT","HPT");
174 fHPTTree->SetDirectory(0);
176 if (fHPTTree->GetEntries()==0){
178 fHPTTree->SetDirectory(0);
179 fHPTTree->Branch("t.",&track);
180 fHPTTree->Branch("ft.",&friendTrack);
181 fHPTTree->Branch("s.",&seed);
183 fHPTTree->SetBranchAddress("t.",&track);
184 fHPTTree->SetBranchAddress("ft.",&friendTrack);
185 fHPTTree->SetBranchAddress("s.",&seed);
194 void AliTPCcalibV0::DumpToTree(AliESDEvent *esd){
196 // Dump V0s fith full firend information to the
198 Int_t nV0s = fESD->GetNumberOfV0s();
199 const Int_t kMinCluster=110;
200 const Double_t kDownscale=0.01;
201 const Float_t kMinPt =1.0;
202 const Float_t kMinMinPt =0.7;
203 AliESDfriend *esdFriend=static_cast<AliESDfriend*>(esd->FindListObject("AliESDfriend"));
206 for (Int_t ivertex=0; ivertex<nV0s; ivertex++){
208 AliESDv0 * v0 = (AliESDv0*) esd->GetV0(ivertex);
209 AliESDtrack * track0 = fESD->GetTrack(v0->GetIndex(0)); // negative track
210 AliESDtrack * track1 = fESD->GetTrack(v0->GetIndex(1)); // positive track
211 if (track0->GetTPCNcls()<kMinCluster) continue;
212 if (track0->GetKinkIndex(0)>0) continue;
213 if (track1->GetTPCNcls()<kMinCluster) continue;
214 if (track1->GetKinkIndex(0)>0) continue;
215 if (v0->GetOnFlyStatus()==kFALSE) continue;
217 if (TMath::Min(track0->Pt(),track1->Pt())<kMinMinPt) continue;
220 if (TMath::Max(track0->Pt(),track1->Pt())>kMinPt) isOK=kTRUE;
221 if (gRandom->Rndm()<kDownscale) isOK=kTRUE;
224 TString filename(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
225 Int_t eventNumber = esd->GetEventNumberInFile();
226 Bool_t hasITS=(track0->GetNcls(0)+ track1->GetNcls(0)>4);
227 printf("DUMPHPTV0:%s|%f|%d|%d|%d\n",filename.Data(), (TMath::Min(track0->Pt(),track1->Pt())), eventNumber,(esdFriend!=0), hasITS);
229 if (!esdFriend) continue;
233 AliESDfriendTrack *ftrack0 = esdFriend->GetTrack(v0->GetIndex(0));
234 if (!ftrack0) continue;
235 AliESDfriendTrack *ftrack1 = esdFriend->GetTrack(v0->GetIndex(1));
236 if (!ftrack1) continue;
238 TObject *calibObject;
239 AliTPCseed *seed0 = 0;
240 AliTPCseed *seed1 = 0;
241 for (Int_t l=0;(calibObject=ftrack0->GetCalibObject(l));++l) {
242 if ((seed0=dynamic_cast<AliTPCseed*>(calibObject))) break;
244 for (Int_t l=0;(calibObject=ftrack1->GetCalibObject(l));++l) {
245 if ((seed1=dynamic_cast<AliTPCseed*>(calibObject))) break;
247 if (!seed0) continue;
248 if (!seed1) continue;
249 AliExternalTrackParam * paramIn0 = (AliExternalTrackParam *)track0->GetInnerParam();
250 AliExternalTrackParam * paramIn1 = (AliExternalTrackParam *)track1->GetInnerParam();
251 if (!paramIn0) continue;
252 if (!paramIn1) continue;
256 fV0Tree = new TTree("V0s","V0s");
257 fV0Tree->SetDirectory(0);
259 if (fV0Tree->GetEntries()==0){
261 fV0Tree->SetDirectory(0);
262 fV0Tree->Branch("v0.",&v0);
263 fV0Tree->Branch("t0.",&track0);
264 fV0Tree->Branch("t1.",&track1);
265 fV0Tree->Branch("ft0.",&ftrack0);
266 fV0Tree->Branch("ft1.",&ftrack1);
267 fV0Tree->Branch("s0.",&seed0);
268 fV0Tree->Branch("s1.",&seed1);
270 fV0Tree->SetBranchAddress("v0.",&v0);
271 fV0Tree->SetBranchAddress("t0.",&track0);
272 fV0Tree->SetBranchAddress("t1.",&track1);
273 fV0Tree->SetBranchAddress("ft0.",&ftrack0);
274 fV0Tree->SetBranchAddress("ft1.",&ftrack1);
275 fV0Tree->SetBranchAddress("s0.",&seed0);
276 fV0Tree->SetBranchAddress("s1.",&seed1);
283 Long64_t AliTPCcalibV0::Merge(TCollection *const li) {
285 TIterator* iter = li->MakeIterator();
286 AliTPCcalibV0* cal = 0;
288 while ((cal = (AliTPCcalibV0*)iter->Next())) {
291 fV0Tree = new TTree("V0s","V0s");
292 fV0Tree->SetDirectory(0);
294 if (cal->fV0Tree->GetEntries()>0) AliTPCcalibV0::AddTree(cal->fV0Tree);
295 if (cal->fHPTTree->GetEntries()>0) AliTPCcalibV0::AddTreeHPT(cal->fHPTTree);
302 void AliTPCcalibV0::AddTree(TTree * treeInput){
304 // Add the content of tree:
305 // Notice automatic copy of tree in ROOT does not work for such complicated tree
308 AliESDv0 * v0 = new AliESDv0;
310 AliESDtrack * track0 = 0; // negative track
311 AliESDtrack * track1 = 0; // positive track
312 AliESDfriendTrack *ftrack0 = 0;
313 AliESDfriendTrack *ftrack1 = 0;
314 AliTPCseed *seed0 = 0;
315 AliTPCseed *seed1 = 0;
316 treeInput->SetBranchStatus("ft0.",kFALSE);
317 treeInput->SetBranchStatus("ft1.",kFALSE);
319 Double_t massK0= pdg.GetParticle("K0")->Mass();
320 Double_t massLambda= pdg.GetParticle("Lambda0")->Mass();
322 Int_t entries= treeInput->GetEntries();
323 for (Int_t i=0; i<entries; i++){
324 treeInput->SetBranchAddress("v0.",&v0);
325 treeInput->SetBranchAddress("t0.",&track0);
326 treeInput->SetBranchAddress("t1.",&track1);
327 treeInput->SetBranchAddress("ft0.",&ftrack0);
328 treeInput->SetBranchAddress("ft1.",&ftrack1);
329 treeInput->SetBranchAddress("s0.",&seed0);
330 treeInput->SetBranchAddress("s1.",&seed1);
331 if (fV0Tree->GetEntries()==0){
332 fV0Tree->SetDirectory(0);
333 fV0Tree->Branch("v0.",&v0);
334 fV0Tree->Branch("t0.",&track0);
335 fV0Tree->Branch("t1.",&track1);
336 fV0Tree->Branch("ft0.",&ftrack0);
337 fV0Tree->Branch("ft1.",&ftrack1);
338 fV0Tree->Branch("s0.",&seed0);
339 fV0Tree->Branch("s1.",&seed1);
341 fV0Tree->SetBranchAddress("v0.",&v0);
342 fV0Tree->SetBranchAddress("t0.",&track0);
343 fV0Tree->SetBranchAddress("t1.",&track1);
344 fV0Tree->SetBranchAddress("ft0.",&ftrack0);
345 fV0Tree->SetBranchAddress("ft1.",&ftrack1);
346 fV0Tree->SetBranchAddress("s0.",&seed0);
347 fV0Tree->SetBranchAddress("s1.",&seed1);
350 treeInput->GetEntry(i);
351 //ftrack0->GetCalibContainer()->SetOwner(kTRUE);
352 //ftrack1->GetCalibContainer()->SetOwner(kTRUE);
354 if (v0->GetOnFlyStatus()==kFALSE) isOK=kFALSE;
355 if (track0->GetTPCncls()<100) isOK=kFALSE;
356 if (track1->GetTPCncls()<100) isOK=kFALSE;
357 if (TMath::Min(seed0->Pt(),seed1->Pt())<kMinPt) isOK=kFALSE;
358 if (TMath::Min(track0->Pt(),track1->Pt())<kMinPt) isOK=kFALSE;
360 if (TMath::Abs(v0->GetEffMass(2,2)-massK0)<0.05) isV0=kTRUE;
361 if (TMath::Abs(v0->GetEffMass(4,2)-massLambda)<0.05) isV0=kTRUE;
362 if (TMath::Abs(v0->GetEffMass(2,4)-massLambda)<0.05) isV0=kTRUE;
363 if (TMath::Abs(v0->GetEffMass(0,0))<0.02) isV0=kFALSE; //reject electrons
364 if (!isV0) isOK=kFALSE;
365 if (isOK) fV0Tree->Fill();
383 void AliTPCcalibV0::AddTreeHPT(TTree * treeInput){
385 // Add the content of tree:
386 // Notice automatic copy of tree in ROOT does not work for such complicated tree
389 AliESDtrack *track = 0;
390 AliESDfriendTrack *friendTrack = 0;
391 AliTPCseed *seed = 0;
392 if (!treeInput) return;
393 if (treeInput->GetEntries()==0) return;
395 Int_t entries= treeInput->GetEntries();
397 for (Int_t i=0; i<entries; i++){
402 treeInput->SetBranchAddress("t.",&track);
403 treeInput->SetBranchAddress("ft.",&friendTrack);
404 treeInput->SetBranchAddress("s.",&seed);
405 treeInput->GetEntry(i);
407 if (fHPTTree->GetEntries()==0){
408 fHPTTree->SetDirectory(0);
409 fHPTTree->Branch("t.",&track);
410 fHPTTree->Branch("ft.",&friendTrack);
411 fHPTTree->Branch("s.",&seed);
413 fHPTTree->SetBranchAddress("t.",&track);
414 fHPTTree->SetBranchAddress("ft.",&friendTrack);
415 fHPTTree->SetBranchAddress("s.",&seed);
418 if (!track->IsOn(AliESDtrack::kITSrefit)) isOK=kFALSE;
419 if (!track->IsOn(AliESDtrack::kTOFout)) isOK=kFALSE;
420 if (isOK) fHPTTree->Fill();
429 void AliTPCcalibV0::MakeFitTreeTrack(const TObjArray * corrArray, Double_t ptCut, Int_t /*run*/){
433 // 0. Loop over selected tracks
434 // 1. Loop over all transformation - refit the track with and without the
436 // 2. Dump the matching paramaeters to the debugStremer
440 const Int_t kMinNcl=120;
441 TFile f("TPCV0Objects.root");
442 AliTPCcalibV0 *v0TPC = (AliTPCcalibV0*) f.Get("v0TPC");
443 TTree * treeInput = v0TPC->GetHPTTree();
444 TTreeSRedirector *pcstream = new TTreeSRedirector("fitHPT.root");
445 AliESDtrack *track = 0;
446 AliESDfriendTrack *friendTrack = 0;
447 AliTPCseed *seed = 0;
448 if (!treeInput) return;
449 if (treeInput->GetEntries()==0) return;
451 treeInput->SetBranchAddress("t.",&track);
452 treeInput->SetBranchAddress("ft.",&friendTrack);
453 treeInput->SetBranchAddress("s.",&seed);
456 if (corrArray) ncorr = corrArray->GetEntries();
457 AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
458 // AliTPCParam *param = AliTPCcalibDB::Instance()->GetParameters();
459 // AliGRPObject* grp = AliTPCcalibDB::Instance()->GetGRP(run);
460 // Double_t time=0.5*(grp->GetTimeStart() +grp->GetTimeEnd());
464 Int_t ntracks= treeInput->GetEntries();
465 for (Int_t itrack=0; itrack<ntracks; itrack++){
466 treeInput->GetEntry(itrack);
467 if (!track) continue;
468 if (seed->Pt()<ptCut) continue;
469 if (track->Pt()<ptCut) continue;
470 if (track->GetTPCncls()<kMinNcl) continue;
472 // Reapply transformation
474 for (Int_t irow=0; irow<159; irow++){
475 AliTPCclusterMI *cluster=seed->GetClusterPointer(irow);
476 if (cluster &&cluster->GetX()>10){
477 Double_t x0[3]={cluster->GetRow(),cluster->GetPad(),cluster->GetTimeBin()};
478 Int_t index0[1]={cluster->GetDetector()};
479 transform->Transform(x0,index0,0,1);
480 cluster->SetX(x0[0]);
481 cluster->SetY(x0[1]);
482 cluster->SetZ(x0[2]);
487 AliExternalTrackParam* paramInner=0;
488 AliExternalTrackParam* paramOuter=0;
489 AliExternalTrackParam* paramIO=0;
491 for (Int_t icorr=-1; icorr<ncorr; icorr++){
493 AliTPCCorrection *corr = 0;
494 if (icorr>=0) corr = (AliTPCCorrection*)corrArray->At(icorr);
495 AliExternalTrackParam * trackInner = RefitTrack(seed, corr,85,134,0.1);
496 AliExternalTrackParam * trackIO = RefitTrack(seed, corr,245,85,0.1);
497 AliExternalTrackParam * trackOuter = RefitTrack(seed, corr,245,134,0.1 );
498 if (trackInner&&trackOuter&&trackIO){
499 trackOuter->Rotate(trackInner->GetAlpha());
500 trackOuter->PropagateTo(trackInner->GetX(),AliTracker::GetBz());
502 paramInner=trackInner;
503 paramOuter=trackOuter;
505 paramIO->Rotate(seed->GetAlpha());
506 paramIO->PropagateTo(seed->GetX(),AliTracker::GetBz());
513 if (paramOuter&& paramInner) {
514 // Bool_t isOK=kTRUE;
515 if (paramInner->GetSigmaY2()>0.01) isOK&=kFALSE;
516 if (paramOuter->GetSigmaY2()>0.01) isOK&=kFALSE;
517 if (paramInner->GetSigmaZ2()>0.01) isOK&=kFALSE;
518 if (paramOuter->GetSigmaZ2()>0.01) isOK&=kFALSE;
522 "pIn.="<<paramInner<<
523 "pOut.="<<paramOuter;
531 .x ../ConfigCalibTrain.C(run)
532 .L ../AddTaskTPCCalib.C
534 TFile fexb("../../RegisterCorrectionExB.root");
535 AliTPCComposedCorrection *cc= (AliTPCComposedCorrection*) fexb.Get("ComposedExB");
537 cc->Print("DA"); // Print used correction classes
538 TObjArray *array = cc->GetCorrections()
539 AliTPCcalibV0::MakeFitTreeTrack(array,2,run);
544 void AliTPCcalibV0::MakeFitTreeV0(const TObjArray * corrArray, Double_t ptCut, Int_t run){
548 // 0. Loop over selected tracks
549 // 1. Loop over all transformation - refit the track with and without the
551 // 2. Dump the matching paramaeters to the debugStremer
555 TFile f("TPCV0Objects.root");
556 AliTPCcalibV0 *v0TPC = (AliTPCcalibV0*) f.Get("v0TPC");
557 TTree * treeInput = v0TPC->GetV0Tree();
558 TTreeSRedirector *pcstream = new TTreeSRedirector("fitV0.root");
560 AliESDtrack *track0 = 0;
561 AliESDfriendTrack *friendTrack0 = 0;
562 AliTPCseed *seed0 = 0;
564 AliESDtrack *track1 = 0;
565 AliESDfriendTrack *friendTrack1 = 0;
567 AliTPCseed *seed1 = 0;
568 if (!treeInput) return;
569 if (treeInput->GetEntries()==0) return;
571 treeInput->SetBranchAddress("v0.",&v0);
572 treeInput->SetBranchAddress("t0.",&track0);
573 treeInput->SetBranchAddress("ft0.",&friendTrack0);
574 treeInput->SetBranchAddress("s0.",&s0);
575 treeInput->SetBranchAddress("t1.",&track1);
576 treeInput->SetBranchAddress("ft1.",&friendTrack1);
577 treeInput->SetBranchAddress("s1.",&s1);
581 if (corrArray) ncorr = corrArray->GetEntries();
582 AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
583 Double_t massK0= pdg.GetParticle("K0")->Mass();
584 Double_t massLambda= pdg.GetParticle("Lambda0")->Mass();
585 Double_t massPion=pdg.GetParticle("pi+")->Mass();
586 Double_t massProton=pdg.GetParticle("proton")->Mass();
587 Int_t pdgPion=pdg.GetParticle("pi+")->PdgCode();
588 Int_t pdgProton=pdg.GetParticle("proton")->PdgCode();
597 Int_t nv0s= treeInput->GetEntries();
598 for (Int_t iv0=0; iv0<nv0s; iv0++){
602 Int_t isAntiLambda=0;
603 treeInput->GetEntry(iv0);
604 if (TMath::Abs(v0->GetEffMass(2,2)-massK0)<0.03) {isK0=1; v0Type=1;} //select K0s
605 if (TMath::Abs(v0->GetEffMass(4,2)-massLambda)<0.01) {isLambda=1; v0Type=2;} //select Lambda
606 if (TMath::Abs(v0->GetEffMass(2,4)-massLambda)<0.01) {isAntiLambda=1;v0Type=3;} //select Anti Lambda
607 if (isK0+isLambda+isAntiLambda!=1) continue;
612 if (isLambda) {rmass0=massProton; pdg0=pdgProton;}
613 if (isAntiLambda) {rmass1=massProton; pdg1=pdgProton;}
615 if (isK0==0) massV0=massLambda;
618 seed0=(s0->GetSign()>0)?s0:s1;
619 seed1=(s0->GetSign()>0)?s1:s0;
620 if (seed0->GetZ()*seed1->GetZ()<0) continue; //remove membrane crossed tracks
621 if (seed0->Pt()<ptCut) continue;
622 if (seed1->Pt()<ptCut) continue;
624 // Reapply transformation
626 for (Int_t itype=0; itype<2; itype++){
627 AliTPCseed * seed = (itype==0) ? seed0: seed1;
628 for (Int_t irow=0; irow<159; irow++){
629 AliTPCclusterMI *cluster=seed->GetClusterPointer(irow);
630 if (cluster &&cluster->GetX()>10){
631 Double_t x0[3]={cluster->GetRow(),cluster->GetPad(),cluster->GetTimeBin()};
632 Int_t index0[1]={cluster->GetDetector()};
633 transform->Transform(x0,index0,0,1);
634 cluster->SetX(x0[0]);
635 cluster->SetY(x0[1]);
636 cluster->SetZ(x0[2]);
642 Double_t radius = v0->GetRr();
644 v0->GetXYZ(xyz[0],xyz[1],xyz[2]);
645 Double_t alpha = TMath::ATan2(xyz[1],xyz[0]);
646 TObjArray arrayV0in(ncorr+1);
647 TObjArray arrayV0io(ncorr+1);
648 TObjArray arrayT0(ncorr+1);
649 TObjArray arrayT1(ncorr+1);
650 arrayV0in.SetOwner(kTRUE);
651 arrayV0io.SetOwner(kTRUE);
653 for (Int_t icorr=-1; icorr<ncorr; icorr++){
654 AliTPCCorrection *corr =0;
655 if (icorr>=0) corr = (AliTPCCorrection*)corrArray->At(icorr);
657 AliExternalTrackParam * trackInner0 = RefitTrack(seed0, corr,160,85,rmass0);
658 AliExternalTrackParam * trackIO0 = RefitTrack(seed0, corr,245,85,rmass0);
659 AliExternalTrackParam * trackInner1 = RefitTrack(seed1, corr,160,85,rmass1);
660 AliExternalTrackParam * trackIO1 = RefitTrack(seed1, corr,245,85,rmass1);
661 if (!trackInner0) isOK=kFALSE;
662 if (!trackInner1) isOK=kFALSE;
663 if (!trackIO0) isOK=kFALSE;
664 if (!trackIO1) isOK=kFALSE;
666 if (!trackInner0->Rotate(alpha)) isOK=kFALSE;
667 if (!trackInner1->Rotate(alpha)) isOK=kFALSE;
668 if (!trackIO0->Rotate(alpha)) isOK=kFALSE;
669 if (!trackIO1->Rotate(alpha)) isOK=kFALSE;
671 if (!AliTracker::PropagateTrackToBxByBz(trackInner0, radius, rmass0, 1, kFALSE)) isOK=kFALSE;
672 if (!AliTracker::PropagateTrackToBxByBz(trackInner1, radius, rmass1, 1, kFALSE)) isOK=kFALSE;
673 if (!AliTracker::PropagateTrackToBxByBz(trackIO0, radius, rmass0, 1, kFALSE)) isOK=kFALSE;
674 if (!AliTracker::PropagateTrackToBxByBz(trackIO1, radius, rmass1, 1, kFALSE)) isOK=kFALSE;
676 arrayT0.AddAt(trackIO0->Clone(),icorr+1);
677 arrayT1.AddAt(trackIO1->Clone(),icorr+1);
678 Int_t charge=TMath::Nint(trackIO0->GetSign());
679 AliKFParticle pin0( *trackInner0, pdg0*charge);
680 AliKFParticle pin1( *trackInner1, -pdg1*charge);
681 AliKFParticle pio0( *trackIO0, pdg0*charge);
682 AliKFParticle pio1( *trackIO1, -pdg1*charge);
689 arrayV0in.AddAt(v0in.Clone(),icorr+1);
690 arrayV0io.AddAt(v0io.Clone(),icorr+1);
695 //AliKFParticle* pin0= (AliKFParticle*)arrayV0in.At(0);
696 AliKFParticle* pio0= (AliKFParticle*)arrayV0io.At(0);
697 AliExternalTrackParam *param0=(AliExternalTrackParam *)arrayT0.At(0);
698 AliExternalTrackParam *param1=(AliExternalTrackParam *)arrayT1.At(0);
699 Double_t mass0=0, mass0E=0;
700 pio0->GetMass( mass0,mass0E);
702 Double_t mean=mass0-massV0;
703 if (TMath::Abs(mean)>0.05) continue;
704 Double_t mass[10000];
706 Int_t dtype=30; // id for V0
707 Int_t ptype=5; // id for invariant mass
708 // Int_t id=TMath::Nint(100.*(param0->Pt()-param1->Pt())/(param0->Pt()+param1->Pt())); // K0s V0 asymetry
709 Int_t id=Int_t(1000.*(param0->Pt()-param1->Pt())); // K0s V0 asymetry
710 Double_t gx,gy,gz, px,py,pz;
711 Double_t pt = v0->Pt();
712 v0->GetXYZ(gx,gy,gz);
713 v0->GetPxPyPz(px,py,pz);
714 Double_t theta=pz/TMath::Sqrt(px*px+py*py);
715 Double_t phi=TMath::ATan2(py,px);
716 Double_t snp=0.5*(seed0->GetSnp()+seed1->GetSnp());
717 Double_t sector=9*phi/TMath::Pi();
718 Double_t dsec=sector-TMath::Nint(sector);
719 Double_t refX=TMath::Sqrt(gx*gx+gy*gy);
720 //Int_t nentries=v0Type;
721 Double_t bz=AliTracker::GetBz();
723 (*pcstream)<<"fitDebug"<<
731 (*pcstream)<<"fit"<< // dump valus for fit
732 "run="<<run<< //run number
733 "bz="<<bz<< // magnetic filed used
734 "dtype="<<dtype<< // detector match type 30
735 "ptype="<<ptype<< // parameter type
736 "theta="<<theta<< // theta
739 "mean="<<mean<< // mean dist value
740 "rms="<<mass0E<< // rms
744 "refX="<<refX<< // reference radius
745 "gx="<<gx<< // global position
746 "gy="<<gy<< // global position
747 "gz="<<gz<< // global position
748 "dRrec="<<dRrec<< // delta Radius in reconstruction
749 "pt="<<pt<< // pt of the particle
750 "id="<<id<< //delta of the momenta
751 "entries="<<v0Type;// type of the V0
752 for (Int_t icorr=0; icorr<ncorr; icorr++){
753 AliTPCCorrection *corr =0;
754 if (icorr>=0) corr = (AliTPCCorrection*)corrArray->At(icorr);
755 // AliKFParticle* pin= (AliKFParticle*)arrayV0in.At(icorr+1);
756 AliKFParticle* pio= (AliKFParticle*)arrayV0io.At(icorr+1);
757 AliExternalTrackParam *par0=(AliExternalTrackParam *)arrayT0.At(icorr+1);
758 AliExternalTrackParam *par1=(AliExternalTrackParam *)arrayT1.At(icorr+1);
760 pio->GetMass( mass[icorr],massE);
763 Form("%s=",corr->GetName())<<mass[icorr];
764 (*pcstream)<<"fitDebug"<<
765 Form("%s=",corr->GetName())<<mass[icorr]<<
766 Form("%sp0.=",corr->GetName())<<par0<<
767 Form("%sp1=",corr->GetName())<<par1;
769 (*pcstream)<<"fit"<< "isOK="<<isOK<<"\n";
770 (*pcstream)<<"fitDebug"<< "isOK="<<isOK<<"\n";
775 AliExternalTrackParam * AliTPCcalibV0::RefitTrack(AliTPCseed *seed, AliTPCCorrection * corr, Double_t xstart, Double_t xstop, Double_t mass){
778 // seed - tpc track with cluster
779 // corr - distrotion/correction class - apllied to the points
780 // xstart - radius to start propagate/update
781 // xstop - radius to stop propagate/update
783 const Double_t kResetCov=20.;
784 const Double_t kSigma=5.;
786 for (Int_t i=0;i<15;i++) covar[i]=0;
787 covar[0]=kSigma*kSigma;
788 covar[2]=kSigma*kSigma;
789 covar[5]=kSigma*kSigma/Float_t(150*150);
790 covar[9]=kSigma*kSigma/Float_t(150*150);
793 AliExternalTrackParam *refit = new AliExternalTrackParam(*seed);
794 refit->PropagateTo(xstart, AliTracker::GetBz());
795 refit->AddCovariance(covar);
796 refit->ResetCovariance(kResetCov);
797 Double_t xmin = TMath::Min(xstart,xstop);
798 Double_t xmax = TMath::Max(xstart,xstop);
802 for (Int_t index0=0; index0<159; index0++){
803 Int_t irow= (xstart<xstop)? index0:159-index0;
804 AliTPCclusterMI *cluster=seed->GetClusterPointer(irow); //cluster in local system
805 if (!cluster) continue;
806 if (cluster->GetX()<xmin) continue;
807 if (cluster->GetX()>xmax) continue;
808 Double_t alpha = TMath::Pi()*(cluster->GetDetector()+0.5)/9.;
809 if (!refit->Rotate(alpha)) isOK=kFALSE;
810 Double_t x = cluster->GetX();
811 Double_t y = cluster->GetY();
812 Double_t z = cluster->GetZ();
814 Float_t xyz[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()}; // original position
815 corr->DistortPointLocal(xyz,cluster->GetDetector());
820 if (!AliTracker::PropagateTrackToBxByBz(refit, x,mass,1.,kFALSE)) isOK=kFALSE;
822 Double_t cov[3]={0.01,0.,0.01};
823 Double_t yz[2]={y,z};
824 if (!refit->Update(yz,cov)) isOK=kFALSE;
827 if (!AliTracker::PropagateTrackToBxByBz(refit, xstop, mass,1.,kTRUE)) isOK=kFALSE;
847 AliKFParticle * AliTPCcalibV0::Fit(AliKFVertex & /*primVtx*/, AliESDv0 *v0, Int_t PDG1, Int_t PDG2){
851 AliKFParticle p1( *(v0->GetParamN()), PDG1 );
852 AliKFParticle p2( *(v0->GetParamP()), PDG2 );
853 AliKFParticle *V0 = new AliKFParticle;
856 V0->SetVtxGuess(x,y,z);
865 void AliTPCcalibV0::BinLogX(TH2F *h) {
869 TAxis *axis = h->GetXaxis();
870 int bins = axis->GetNbins();
872 Double_t from = axis->GetXmin();
873 Double_t to = axis->GetXmax();
874 Double_t *new_bins = new Double_t[bins + 1];
877 Double_t factor = pow(to/from, 1./bins);
879 for (int i = 1; i <= bins; i++) {
880 new_bins[i] = factor * new_bins[i-1];
882 axis->Set(bins, new_bins);
888 void AliTPCcalibV0::FilterV0s(AliESDEvent* event){
892 const Double_t kChi2Cut=20;
893 const Double_t kMinR=2;
894 const Double_t ptCut=0.2;
895 const Int_t kMinNcl=110;
897 Int_t nv0 = event->GetNumberOfV0s();
898 AliESDVertex *vertex= (AliESDVertex *)event->GetPrimaryVertex();
899 AliKFVertex kfvertex=*vertex;
901 for (Int_t iv0=0;iv0<nv0;iv0++){
902 AliESDv0 *v0 = event->GetV0(iv0);
904 if (v0->GetPindex()<0) continue;
905 if (v0->GetNindex()<0) continue;
906 if (TMath::Max(v0->GetPindex(), v0->GetNindex())>event->GetNumberOfTracks()) continue;
909 AliExternalTrackParam pp=(v0->GetParamP()->GetSign()>0) ? (*(v0->GetParamP())):(*(v0->GetParamN()));
910 AliExternalTrackParam pn=(v0->GetParamP()->GetSign()>0) ? (*(v0->GetParamN())):(*(v0->GetParamP()));
911 AliKFParticle kfp1( pp, 211 );
912 AliKFParticle kfp2( pn, -211 );
913 AliKFParticle *v0KFK0 = new AliKFParticle(kfp1,kfp2);
914 AliKFParticle *v0KFK0CV = new AliKFParticle(*v0KFK0);
915 v0KFK0CV->SetProductionVertex(kfvertex);
916 v0KFK0CV->TransportToProductionVertex();
917 AliKFParticle *v0KFK0CVM = new AliKFParticle(*v0KFK0CV);
918 v0KFK0CVM->SetMassConstraint(pdg.GetParticle("K_S0")->Mass());
919 Double_t chi2K0 = v0KFK0CV->GetChi2();
920 Double_t chi2K0M= v0KFK0CVM->GetChi2();
921 Double_t massK0=v0KFK0CV->GetMass();
922 if (chi2K0>kChi2Cut) continue;
923 if (v0->GetRr()>kMinR) continue;
925 Double_t maxPt = TMath::Max(v0->GetParamP()->Pt(), v0->GetParamN()->Pt());
926 Double_t effMass22=v0->GetEffMass(2,2);
927 Double_t effMass42=v0->GetEffMass(4,2);
928 Double_t effMass24=v0->GetEffMass(2,4);
930 isV0|=TMath::Abs(effMass22-pdg.GetParticle("K_S0")->Mass())<0.1;
931 isV0|=TMath::Abs(effMass42-pdg.GetParticle("Lambda0")->Mass())<0.1;
932 isV0|=TMath::Abs(effMass24-pdg.GetParticle("Lambda0")->Mass())<0.1;
934 Double_t sign= v0->GetParamP()->GetSign()* v0->GetParamN()->GetSign();
935 if (sign<0&&v0->GetOnFlyStatus()>0.5&&maxPt>ptCut&&isV0){
936 AliESDtrack * trackP = event->GetTrack(v0->GetPindex());
937 AliESDtrack * trackN = event->GetTrack(v0->GetNindex());
938 if (!trackN) continue;
939 if (!trackP) continue;
940 Int_t nclP= (Int_t)trackP->GetTPCClusterInfo(2,1);
941 Int_t nclN= (Int_t)trackN->GetTPCClusterInfo(2,1);
942 if (TMath::Min(nclP,nclN)<kMinNcl) continue;
943 Double_t eta = TMath::Max(TMath::Abs(trackP->Eta()), TMath::Abs(trackN->Eta()));
944 Double_t ncls = TMath::Min(TMath::Abs(trackP->GetNcls(0)), TMath::Abs(trackN->GetNcls(0)));
945 if (eta<0.8&&ncls>2){
946 // printf("%d\t%f\t%f\t%d\t%d\t%f\t%f\n",i, v0->Pt(), maxPt, v0->GetNindex(),v0->GetPindex(),v0->GetRr(),effMass22);
947 (*fDebugStreamer)<<"v0tree"<<