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 "AliESDVertex.h"
32 #include "AliVEvent.h"
33 #include "AliVTrack.h"
34 #include "AliVfriendTrack.h"
35 #include "AliVfriendEvent.h"
37 #include "AliMathBase.h"
38 #include "AliTPCseed.h"
39 #include "AliTPCclusterMI.h"
41 #include "AliKFParticle.h"
42 #include "AliKFVertex.h"
44 #include "AliTrackPointArray.h"
45 #include "AliTPCcalibV0.h"
48 #include "TTreeStream.h"
49 #include "AliTPCcalibDB.h"
50 #include "AliTPCCorrection.h"
51 #include "AliGRPObject.h"
52 #include "AliTPCTransform.h"
53 #include "AliAnalysisManager.h"
57 ClassImp(AliTPCcalibV0)
60 AliTPCcalibV0::AliTPCcalibV0() :
73 AliTPCcalibV0::AliTPCcalibV0(const Text_t *name, const Text_t *title):
84 fPdg = new TDatabasePDG;
85 // create output histograms
90 AliTPCcalibV0::~AliTPCcalibV0(){
102 void AliTPCcalibV0::ProcessESD(AliVEvent *event){
107 AliKFParticle::SetField(event->GetMagneticField());
108 if (TMath::Abs(AliTracker::GetBz())<1) return;
110 DumpToTreeHPT(event);
113 void AliTPCcalibV0::DumpToTreeHPT(AliVEvent *event){
115 // Dump V0s fith full firend information to the
117 if (TMath::Abs(AliTracker::GetBz())<1) return;
118 const Int_t kMinCluster=110;
119 const Float_t kMinPt =4.;
120 AliVfriendEvent *friendEvent=event->FindFriend();
122 // Printf("ERROR: esdFriend not available");
126 Int_t ntracks=event->GetNumberOfTracks();
127 for (Int_t i=0;i<ntracks;++i) {
129 AliVTrack *track = event->GetVTrack(i);
130 if (track->GetTPCncls()<kMinCluster) continue;
131 if (TMath::Abs(AliTracker::GetBz())>1){ // cut on momenta if measured
132 if (track->Pt()>kMinPt) isOK=kTRUE;
134 if (TMath::Abs(AliTracker::GetBz())<1){ // require primary track for the B field OFF data
135 Bool_t isAccepted=kTRUE;
136 if (!track->IsOn(AliVTrack::kITSrefit)) isAccepted=kFALSE;
137 if (!track->IsOn(AliVTrack::kTPCrefit)) isAccepted=kFALSE;
138 if (!track->IsOn(AliVTrack::kTOFout)) isAccepted=kFALSE;
139 Float_t dvertex[2],cvertex[3];
140 track->GetImpactParametersTPC(dvertex,cvertex);
141 if (TMath::Abs(dvertex[0]/TMath::Sqrt(cvertex[0]+0.01))>20) isAccepted=kFALSE;
142 if (TMath::Abs(dvertex[1]/TMath::Sqrt(TMath::Abs(cvertex[2]+0.01)))>20) isAccepted=kFALSE;
143 track->GetImpactParameters(dvertex,cvertex);
144 if (TMath::Abs(dvertex[0]/TMath::Sqrt(cvertex[0]+0.01))>10) isAccepted=kFALSE;
145 if (TMath::Abs(dvertex[1]/TMath::Sqrt(TMath::Abs(cvertex[2]+0.01)))>10) isAccepted=kFALSE;
146 if (!isAccepted) isOK=kFALSE;
148 if ( track->GetTPCsignal()>100 && track->GetInnerParam()->Pt()>1 ){
149 if (track->IsOn(AliVTrack::kITSin)||track->IsOn(AliVTrack::kTRDout)||track->IsOn(AliVTrack::kTOFin))
152 TString filename(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
153 Int_t eventNumber = event->GetEventNumberInFile();
154 Bool_t hasFriend=(friendEvent) ? (friendEvent->GetTrack(i)!=0):0;
155 Bool_t hasITS=(track->GetNcls(0)>2);
156 printf("DUMPIONTrack:%s|%f|%d|%d|%d\n",filename.Data(),track->GetInnerParam()->Pt()*track->GetTPCsignal()/50., eventNumber,hasFriend,hasITS);
160 TString filename(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
161 Int_t eventNumber = event->GetEventNumberInFile();
162 Bool_t hasFriend=(friendEvent) ? (friendEvent->GetTrack(i)!=0):0;
163 Bool_t hasITS=(track->GetNcls(0)>2);
164 printf("DUMPHPTTrack:%s|%f|%d|%d|%d\n",filename.Data(),track->Pt(), eventNumber,hasFriend,hasITS);
166 if (!friendEvent) continue;
167 const AliVfriendTrack *friendTrack = friendEvent->GetTrack(i);
168 if (!friendTrack) continue;
173 TObject *calibObject;
174 AliTPCseed *seed = 0;
175 for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) {
176 if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
180 fHPTTree = new TTree("HPT","HPT");
181 fHPTTree->SetDirectory(0);
184 //**********************TEMPORARY!!*******************************************
185 // more investigation is needed with Tree ///!!!
186 //all dummy stuff here is just for code to compile and work with ESD
188 AliESDfriendTrack *dummyfriendTrack=(AliESDfriendTrack*)friendTrack;
189 AliESDtrack *dummytrack=(AliESDtrack*)track;
192 if (fHPTTree->GetEntries()==0){
194 fHPTTree->SetDirectory(0);
195 fHPTTree->Branch("t.",&dummytrack);
196 fHPTTree->Branch("ft.",&dummyfriendTrack);
197 fHPTTree->Branch("s.",&seed);
199 fHPTTree->SetBranchAddress("t.",&dummytrack);
200 fHPTTree->SetBranchAddress("ft.",&dummyfriendTrack);
201 fHPTTree->SetBranchAddress("s.",&seed);
210 void AliTPCcalibV0::DumpToTree(AliVEvent *event){
212 // Dump V0s fith full firend information to the
214 Int_t nV0s = fEvent->GetNumberOfV0s();
215 const Int_t kMinCluster=110;
216 const Double_t kDownscale=0.01;
217 const Float_t kMinPt =1.0;
218 const Float_t kMinMinPt =0.7;
219 AliVfriendEvent *friendEvent=event->FindFriend();
222 for (Int_t ivertex=0; ivertex<nV0s; ivertex++){
225 event->GetV0(dummyv0,ivertex);
226 AliESDv0 *v0=&dummyv0;
228 AliVTrack * track0 = fEvent->GetVTrack(v0->GetIndex(0)); // negative track
229 AliVTrack * track1 = fEvent->GetVTrack(v0->GetIndex(1)); // positive track
230 if (track0->GetTPCNcls()<kMinCluster) continue;
231 if (track0->GetKinkIndex(0)>0) continue;
232 if (track1->GetTPCNcls()<kMinCluster) continue;
233 if (track1->GetKinkIndex(0)>0) continue;
234 if (v0->GetOnFlyStatus()==kFALSE) continue;
236 if (TMath::Min(track0->Pt(),track1->Pt())<kMinMinPt) continue;
239 if (TMath::Max(track0->Pt(),track1->Pt())>kMinPt) isOK=kTRUE;
240 if (gRandom->Rndm()<kDownscale) isOK=kTRUE;
243 TString filename(AliAnalysisManager::GetAnalysisManager()->GetTree()->GetCurrentFile()->GetName());
244 Int_t eventNumber = event->GetEventNumberInFile();
245 Bool_t hasITS=(track0->GetNcls(0)+ track1->GetNcls(0)>4);
246 printf("DUMPHPTV0:%s|%f|%d|%d|%d\n",filename.Data(), (TMath::Min(track0->Pt(),track1->Pt())), eventNumber,(friendEvent!=0), hasITS);
248 if (!friendEvent) continue;
252 const AliVfriendTrack *ftrack0 = friendEvent->GetTrack(v0->GetIndex(0));
253 if (!ftrack0) continue;
254 const AliVfriendTrack *ftrack1 = friendEvent->GetTrack(v0->GetIndex(1));
255 if (!ftrack1) continue;
257 TObject *calibObject;
258 AliTPCseed *seed0 = 0;
259 AliTPCseed *seed1 = 0;
260 for (Int_t l=0;(calibObject=ftrack0->GetCalibObject(l));++l) {
261 if ((seed0=dynamic_cast<AliTPCseed*>(calibObject))) break;
263 for (Int_t l=0;(calibObject=ftrack1->GetCalibObject(l));++l) {
264 if ((seed1=dynamic_cast<AliTPCseed*>(calibObject))) break;
266 if (!seed0) continue;
267 if (!seed1) continue;
268 AliExternalTrackParam * paramIn0 = (AliExternalTrackParam *)track0->GetInnerParam();
269 AliExternalTrackParam * paramIn1 = (AliExternalTrackParam *)track1->GetInnerParam();
270 if (!paramIn0) continue;
271 if (!paramIn1) continue;
275 fV0Tree = new TTree("V0s","V0s");
276 fV0Tree->SetDirectory(0);
279 //**********************TEMPORARY!!*******************************************
280 // more investigation is needed with Tree ///!!!
281 //all dummy stuff here is just for code to compile and work with ESD
283 AliESDfriendTrack *dummyftrack0=(AliESDfriendTrack*)ftrack0;
284 AliESDfriendTrack *dummyftrack1=(AliESDfriendTrack*)ftrack1;
285 AliESDtrack *dummytrack0=(AliESDtrack*)track0;
286 AliESDtrack *dummytrack1=(AliESDtrack*)track1;
288 if (fV0Tree->GetEntries()==0){
290 fV0Tree->SetDirectory(0);
291 fV0Tree->Branch("v0.",&v0);
292 fV0Tree->Branch("t0.",&dummytrack0);
293 fV0Tree->Branch("t1.",&dummytrack1);
294 fV0Tree->Branch("ft0.",&dummyftrack0);
295 fV0Tree->Branch("ft1.",&dummyftrack1);
296 fV0Tree->Branch("s0.",&seed0);
297 fV0Tree->Branch("s1.",&seed1);
299 fV0Tree->SetBranchAddress("v0.",&v0);
300 fV0Tree->SetBranchAddress("t0.",&dummytrack0);
301 fV0Tree->SetBranchAddress("t1.",&dummytrack1);
302 fV0Tree->SetBranchAddress("ft0.",&dummyftrack0);
303 fV0Tree->SetBranchAddress("ft1.",&dummyftrack1);
304 fV0Tree->SetBranchAddress("s0.",&seed0);
305 fV0Tree->SetBranchAddress("s1.",&seed1);
312 Long64_t AliTPCcalibV0::Merge(TCollection *const li) {
314 TIterator* iter = li->MakeIterator();
315 AliTPCcalibV0* cal = 0;
317 while ((cal = (AliTPCcalibV0*)iter->Next())) {
320 fV0Tree = new TTree("V0s","V0s");
321 fV0Tree->SetDirectory(0);
323 if (cal->fV0Tree->GetEntries()>0) AliTPCcalibV0::AddTree(cal->fV0Tree);
324 if (cal->fHPTTree->GetEntries()>0) AliTPCcalibV0::AddTreeHPT(cal->fHPTTree);
331 void AliTPCcalibV0::AddTree(TTree * treeInput){
333 // Add the content of tree:
334 // Notice automatic copy of tree in ROOT does not work for such complicated tree
337 AliESDv0 * v0 = new AliESDv0;
339 AliESDtrack * track0 = 0; // negative track
340 AliESDtrack * track1 = 0; // positive track
341 AliESDfriendTrack *ftrack0 = 0;
342 AliESDfriendTrack *ftrack1 = 0;
343 AliTPCseed *seed0 = 0;
344 AliTPCseed *seed1 = 0;
345 treeInput->SetBranchStatus("ft0.",kFALSE);
346 treeInput->SetBranchStatus("ft1.",kFALSE);
348 Double_t massK0= pdg.GetParticle("K0")->Mass();
349 Double_t massLambda= pdg.GetParticle("Lambda0")->Mass();
351 Int_t entries= treeInput->GetEntries();
352 for (Int_t i=0; i<entries; i++){
353 treeInput->SetBranchAddress("v0.",&v0);
354 treeInput->SetBranchAddress("t0.",&track0);
355 treeInput->SetBranchAddress("t1.",&track1);
356 treeInput->SetBranchAddress("ft0.",&ftrack0);
357 treeInput->SetBranchAddress("ft1.",&ftrack1);
358 treeInput->SetBranchAddress("s0.",&seed0);
359 treeInput->SetBranchAddress("s1.",&seed1);
360 if (fV0Tree->GetEntries()==0){
361 fV0Tree->SetDirectory(0);
362 fV0Tree->Branch("v0.",&v0);
363 fV0Tree->Branch("t0.",&track0);
364 fV0Tree->Branch("t1.",&track1);
365 fV0Tree->Branch("ft0.",&ftrack0);
366 fV0Tree->Branch("ft1.",&ftrack1);
367 fV0Tree->Branch("s0.",&seed0);
368 fV0Tree->Branch("s1.",&seed1);
370 fV0Tree->SetBranchAddress("v0.",&v0);
371 fV0Tree->SetBranchAddress("t0.",&track0);
372 fV0Tree->SetBranchAddress("t1.",&track1);
373 fV0Tree->SetBranchAddress("ft0.",&ftrack0);
374 fV0Tree->SetBranchAddress("ft1.",&ftrack1);
375 fV0Tree->SetBranchAddress("s0.",&seed0);
376 fV0Tree->SetBranchAddress("s1.",&seed1);
379 treeInput->GetEntry(i);
380 //ftrack0->GetCalibContainer()->SetOwner(kTRUE);
381 //ftrack1->GetCalibContainer()->SetOwner(kTRUE);
383 if (v0->GetOnFlyStatus()==kFALSE) isOK=kFALSE;
384 if (track0->GetTPCncls()<100) isOK=kFALSE;
385 if (track1->GetTPCncls()<100) isOK=kFALSE;
386 if (TMath::Min(seed0->Pt(),seed1->Pt())<kMinPt) isOK=kFALSE;
387 if (TMath::Min(track0->Pt(),track1->Pt())<kMinPt) isOK=kFALSE;
389 if (TMath::Abs(v0->GetEffMass(2,2)-massK0)<0.05) isV0=kTRUE;
390 if (TMath::Abs(v0->GetEffMass(4,2)-massLambda)<0.05) isV0=kTRUE;
391 if (TMath::Abs(v0->GetEffMass(2,4)-massLambda)<0.05) isV0=kTRUE;
392 if (TMath::Abs(v0->GetEffMass(0,0))<0.02) isV0=kFALSE; //reject electrons
393 if (!isV0) isOK=kFALSE;
394 if (isOK) fV0Tree->Fill();
412 void AliTPCcalibV0::AddTreeHPT(TTree * treeInput){
414 // Add the content of tree:
415 // Notice automatic copy of tree in ROOT does not work for such complicated tree
418 AliESDtrack *track = 0;
419 AliESDfriendTrack *friendTrack = 0;
420 AliTPCseed *seed = 0;
421 if (!treeInput) return;
422 if (treeInput->GetEntries()==0) return;
424 Int_t entries= treeInput->GetEntries();
426 for (Int_t i=0; i<entries; i++){
431 treeInput->SetBranchAddress("t.",&track);
432 treeInput->SetBranchAddress("ft.",&friendTrack);
433 treeInput->SetBranchAddress("s.",&seed);
434 treeInput->GetEntry(i);
436 if (fHPTTree->GetEntries()==0){
437 fHPTTree->SetDirectory(0);
438 fHPTTree->Branch("t.",&track);
439 fHPTTree->Branch("ft.",&friendTrack);
440 fHPTTree->Branch("s.",&seed);
442 fHPTTree->SetBranchAddress("t.",&track);
443 fHPTTree->SetBranchAddress("ft.",&friendTrack);
444 fHPTTree->SetBranchAddress("s.",&seed);
447 if (!track->IsOn(AliESDtrack::kITSrefit)) isOK=kFALSE;
448 if (!track->IsOn(AliESDtrack::kTOFout)) isOK=kFALSE;
449 if (isOK) fHPTTree->Fill();
458 void AliTPCcalibV0::MakeFitTreeTrack(const TObjArray * corrArray, Double_t ptCut, Int_t /*run*/){
462 // 0. Loop over selected tracks
463 // 1. Loop over all transformation - refit the track with and without the
465 // 2. Dump the matching paramaeters to the debugStremer
469 const Int_t kMinNcl=120;
470 TFile f("TPCV0Objects.root");
471 AliTPCcalibV0 *v0TPC = (AliTPCcalibV0*) f.Get("v0TPC");
472 TTree * treeInput = v0TPC->GetHPTTree();
473 TTreeSRedirector *pcstream = new TTreeSRedirector("fitHPT.root");
474 AliESDtrack *track = 0;
475 AliESDfriendTrack *friendTrack = 0;
476 AliTPCseed *seed = 0;
477 if (!treeInput) return;
478 if (treeInput->GetEntries()==0) return;
480 treeInput->SetBranchAddress("t.",&track);
481 treeInput->SetBranchAddress("ft.",&friendTrack);
482 treeInput->SetBranchAddress("s.",&seed);
485 if (corrArray) ncorr = corrArray->GetEntries();
486 AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
487 // AliTPCParam *param = AliTPCcalibDB::Instance()->GetParameters();
488 // AliGRPObject* grp = AliTPCcalibDB::Instance()->GetGRP(run);
489 // Double_t time=0.5*(grp->GetTimeStart() +grp->GetTimeEnd());
493 Int_t ntracks= treeInput->GetEntries();
494 for (Int_t itrack=0; itrack<ntracks; itrack++){
495 treeInput->GetEntry(itrack);
496 if (!track) continue;
497 if (seed->Pt()<ptCut) continue;
498 if (track->Pt()<ptCut) continue;
499 if (track->GetTPCncls()<kMinNcl) continue;
501 // Reapply transformation
503 for (Int_t irow=0; irow<159; irow++){
504 AliTPCclusterMI *cluster=seed->GetClusterPointer(irow);
505 if (cluster &&cluster->GetX()>10){
506 Double_t x0[3]={ static_cast<Double_t>(cluster->GetRow()),cluster->GetPad(),cluster->GetTimeBin()};
507 Int_t index0[1]={cluster->GetDetector()};
508 transform->Transform(x0,index0,0,1);
509 cluster->SetX(x0[0]);
510 cluster->SetY(x0[1]);
511 cluster->SetZ(x0[2]);
516 AliExternalTrackParam* paramInner=0;
517 AliExternalTrackParam* paramOuter=0;
518 AliExternalTrackParam* paramIO=0;
520 for (Int_t icorr=-1; icorr<ncorr; icorr++){
522 AliTPCCorrection *corr = 0;
523 if (icorr>=0) corr = (AliTPCCorrection*)corrArray->At(icorr);
524 AliExternalTrackParam * trackInner = RefitTrack(seed, corr,85,134,0.1);
525 AliExternalTrackParam * trackIO = RefitTrack(seed, corr,245,85,0.1);
526 AliExternalTrackParam * trackOuter = RefitTrack(seed, corr,245,134,0.1 );
527 if (trackInner&&trackOuter&&trackIO){
528 trackOuter->Rotate(trackInner->GetAlpha());
529 trackOuter->PropagateTo(trackInner->GetX(),AliTracker::GetBz());
531 paramInner=trackInner;
532 paramOuter=trackOuter;
534 paramIO->Rotate(seed->GetAlpha());
535 paramIO->PropagateTo(seed->GetX(),AliTracker::GetBz());
542 if (paramOuter&& paramInner) {
543 // Bool_t isOK=kTRUE;
544 if (paramInner->GetSigmaY2()>0.01) isOK&=kFALSE;
545 if (paramOuter->GetSigmaY2()>0.01) isOK&=kFALSE;
546 if (paramInner->GetSigmaZ2()>0.01) isOK&=kFALSE;
547 if (paramOuter->GetSigmaZ2()>0.01) isOK&=kFALSE;
551 "pIn.="<<paramInner<<
552 "pOut.="<<paramOuter;
560 .x ../ConfigCalibTrain.C(run)
561 .L ../AddTaskTPCCalib.C
563 TFile fexb("../../RegisterCorrectionExB.root");
564 AliTPCComposedCorrection *cc= (AliTPCComposedCorrection*) fexb.Get("ComposedExB");
566 cc->Print("DA"); // Print used correction classes
567 TObjArray *array = cc->GetCorrections()
568 AliTPCcalibV0::MakeFitTreeTrack(array,2,run);
573 void AliTPCcalibV0::MakeFitTreeV0(const TObjArray * corrArray, Double_t ptCut, Int_t run){
577 // 0. Loop over selected tracks
578 // 1. Loop over all transformation - refit the track with and without the
580 // 2. Dump the matching paramaeters to the debugStremer
584 TFile f("TPCV0Objects.root");
585 AliTPCcalibV0 *v0TPC = (AliTPCcalibV0*) f.Get("v0TPC");
586 TTree * treeInput = v0TPC->GetV0Tree();
587 TTreeSRedirector *pcstream = new TTreeSRedirector("fitV0.root");
589 AliESDtrack *track0 = 0;
590 AliESDfriendTrack *friendTrack0 = 0;
591 AliTPCseed *seed0 = 0;
593 AliESDtrack *track1 = 0;
594 AliESDfriendTrack *friendTrack1 = 0;
596 AliTPCseed *seed1 = 0;
597 if (!treeInput) return;
598 if (treeInput->GetEntries()==0) return;
600 treeInput->SetBranchAddress("v0.",&v0);
601 treeInput->SetBranchAddress("t0.",&track0);
602 treeInput->SetBranchAddress("ft0.",&friendTrack0);
603 treeInput->SetBranchAddress("s0.",&s0);
604 treeInput->SetBranchAddress("t1.",&track1);
605 treeInput->SetBranchAddress("ft1.",&friendTrack1);
606 treeInput->SetBranchAddress("s1.",&s1);
610 if (corrArray) ncorr = corrArray->GetEntries();
611 AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
612 Double_t massK0= pdg.GetParticle("K0")->Mass();
613 Double_t massLambda= pdg.GetParticle("Lambda0")->Mass();
614 Double_t massPion=pdg.GetParticle("pi+")->Mass();
615 Double_t massProton=pdg.GetParticle("proton")->Mass();
616 Int_t pdgPion=pdg.GetParticle("pi+")->PdgCode();
617 Int_t pdgProton=pdg.GetParticle("proton")->PdgCode();
626 Int_t nv0s= treeInput->GetEntries();
627 for (Int_t iv0=0; iv0<nv0s; iv0++){
631 Int_t isAntiLambda=0;
632 treeInput->GetEntry(iv0);
633 if (TMath::Abs(v0->GetEffMass(2,2)-massK0)<0.03) {isK0=1; v0Type=1;} //select K0s
634 if (TMath::Abs(v0->GetEffMass(4,2)-massLambda)<0.01) {isLambda=1; v0Type=2;} //select Lambda
635 if (TMath::Abs(v0->GetEffMass(2,4)-massLambda)<0.01) {isAntiLambda=1;v0Type=3;} //select Anti Lambda
636 if (isK0+isLambda+isAntiLambda!=1) continue;
641 if (isLambda) {rmass0=massProton; pdg0=pdgProton;}
642 if (isAntiLambda) {rmass1=massProton; pdg1=pdgProton;}
644 if (isK0==0) massV0=massLambda;
647 seed0=(s0->GetSign()>0)?s0:s1;
648 seed1=(s0->GetSign()>0)?s1:s0;
649 if (seed0->GetZ()*seed1->GetZ()<0) continue; //remove membrane crossed tracks
650 if (seed0->Pt()<ptCut) continue;
651 if (seed1->Pt()<ptCut) continue;
653 // Reapply transformation
655 for (Int_t itype=0; itype<2; itype++){
656 AliTPCseed * seed = (itype==0) ? seed0: seed1;
657 for (Int_t irow=0; irow<159; irow++){
658 AliTPCclusterMI *cluster=seed->GetClusterPointer(irow);
659 if (cluster &&cluster->GetX()>10){
660 Double_t x0[3]={ static_cast<Double_t>(cluster->GetRow()),cluster->GetPad(),cluster->GetTimeBin()};
661 Int_t index0[1]={cluster->GetDetector()};
662 transform->Transform(x0,index0,0,1);
663 cluster->SetX(x0[0]);
664 cluster->SetY(x0[1]);
665 cluster->SetZ(x0[2]);
671 Double_t radius = v0->GetRr();
673 v0->GetXYZ(xyz[0],xyz[1],xyz[2]);
674 Double_t alpha = TMath::ATan2(xyz[1],xyz[0]);
675 TObjArray arrayV0in(ncorr+1);
676 TObjArray arrayV0io(ncorr+1);
677 TObjArray arrayT0(ncorr+1);
678 TObjArray arrayT1(ncorr+1);
679 arrayV0in.SetOwner(kTRUE);
680 arrayV0io.SetOwner(kTRUE);
682 for (Int_t icorr=-1; icorr<ncorr; icorr++){
683 AliTPCCorrection *corr =0;
684 if (icorr>=0) corr = (AliTPCCorrection*)corrArray->At(icorr);
686 AliExternalTrackParam * trackInner0 = RefitTrack(seed0, corr,160,85,rmass0);
687 AliExternalTrackParam * trackIO0 = RefitTrack(seed0, corr,245,85,rmass0);
688 AliExternalTrackParam * trackInner1 = RefitTrack(seed1, corr,160,85,rmass1);
689 AliExternalTrackParam * trackIO1 = RefitTrack(seed1, corr,245,85,rmass1);
690 if (!trackInner0) isOK=kFALSE;
691 if (!trackInner1) isOK=kFALSE;
692 if (!trackIO0) isOK=kFALSE;
693 if (!trackIO1) isOK=kFALSE;
695 if (!trackInner0->Rotate(alpha)) isOK=kFALSE;
696 if (!trackInner1->Rotate(alpha)) isOK=kFALSE;
697 if (!trackIO0->Rotate(alpha)) isOK=kFALSE;
698 if (!trackIO1->Rotate(alpha)) isOK=kFALSE;
700 if (!AliTracker::PropagateTrackToBxByBz(trackInner0, radius, rmass0, 1, kFALSE)) isOK=kFALSE;
701 if (!AliTracker::PropagateTrackToBxByBz(trackInner1, radius, rmass1, 1, kFALSE)) isOK=kFALSE;
702 if (!AliTracker::PropagateTrackToBxByBz(trackIO0, radius, rmass0, 1, kFALSE)) isOK=kFALSE;
703 if (!AliTracker::PropagateTrackToBxByBz(trackIO1, radius, rmass1, 1, kFALSE)) isOK=kFALSE;
705 arrayT0.AddAt(trackIO0->Clone(),icorr+1);
706 arrayT1.AddAt(trackIO1->Clone(),icorr+1);
707 Int_t charge=TMath::Nint(trackIO0->GetSign());
708 AliKFParticle pin0( *trackInner0, pdg0*charge);
709 AliKFParticle pin1( *trackInner1, -pdg1*charge);
710 AliKFParticle pio0( *trackIO0, pdg0*charge);
711 AliKFParticle pio1( *trackIO1, -pdg1*charge);
718 arrayV0in.AddAt(v0in.Clone(),icorr+1);
719 arrayV0io.AddAt(v0io.Clone(),icorr+1);
724 //AliKFParticle* pin0= (AliKFParticle*)arrayV0in.At(0);
725 AliKFParticle* pio0= (AliKFParticle*)arrayV0io.At(0);
726 AliExternalTrackParam *param0=(AliExternalTrackParam *)arrayT0.At(0);
727 AliExternalTrackParam *param1=(AliExternalTrackParam *)arrayT1.At(0);
728 Double_t mass0=0, mass0E=0;
729 pio0->GetMass( mass0,mass0E);
731 Double_t mean=mass0-massV0;
732 if (TMath::Abs(mean)>0.05) continue;
733 Double_t mass[10000];
735 Int_t dtype=30; // id for V0
736 Int_t ptype=5; // id for invariant mass
737 // Int_t id=TMath::Nint(100.*(param0->Pt()-param1->Pt())/(param0->Pt()+param1->Pt())); // K0s V0 asymetry
738 Int_t id=Int_t(1000.*(param0->Pt()-param1->Pt())); // K0s V0 asymetry
739 Double_t gx,gy,gz, px,py,pz;
740 Double_t pt = v0->Pt();
741 v0->GetXYZ(gx,gy,gz);
742 v0->GetPxPyPz(px,py,pz);
743 Double_t theta=pz/TMath::Sqrt(px*px+py*py);
744 Double_t phi=TMath::ATan2(py,px);
745 Double_t snp=0.5*(seed0->GetSnp()+seed1->GetSnp());
746 Double_t sector=9*phi/TMath::Pi();
747 Double_t dsec=sector-TMath::Nint(sector);
748 Double_t refX=TMath::Sqrt(gx*gx+gy*gy);
749 //Int_t nentries=v0Type;
750 Double_t bz=AliTracker::GetBz();
752 (*pcstream)<<"fitDebug"<<
760 (*pcstream)<<"fit"<< // dump valus for fit
761 "run="<<run<< //run number
762 "bz="<<bz<< // magnetic filed used
763 "dtype="<<dtype<< // detector match type 30
764 "ptype="<<ptype<< // parameter type
765 "theta="<<theta<< // theta
768 "mean="<<mean<< // mean dist value
769 "rms="<<mass0E<< // rms
773 "refX="<<refX<< // reference radius
774 "gx="<<gx<< // global position
775 "gy="<<gy<< // global position
776 "gz="<<gz<< // global position
777 "dRrec="<<dRrec<< // delta Radius in reconstruction
778 "pt="<<pt<< // pt of the particle
779 "id="<<id<< //delta of the momenta
780 "entries="<<v0Type;// type of the V0
781 for (Int_t icorr=0; icorr<ncorr; icorr++){
782 AliTPCCorrection *corr =0;
783 if (icorr>=0) corr = (AliTPCCorrection*)corrArray->At(icorr);
784 // AliKFParticle* pin= (AliKFParticle*)arrayV0in.At(icorr+1);
785 AliKFParticle* pio= (AliKFParticle*)arrayV0io.At(icorr+1);
786 AliExternalTrackParam *par0=(AliExternalTrackParam *)arrayT0.At(icorr+1);
787 AliExternalTrackParam *par1=(AliExternalTrackParam *)arrayT1.At(icorr+1);
789 pio->GetMass( mass[icorr],massE);
792 Form("%s=",corr->GetName())<<mass[icorr];
793 (*pcstream)<<"fitDebug"<<
794 Form("%s=",corr->GetName())<<mass[icorr]<<
795 Form("%sp0.=",corr->GetName())<<par0<<
796 Form("%sp1=",corr->GetName())<<par1;
798 (*pcstream)<<"fit"<< "isOK="<<isOK<<"\n";
799 (*pcstream)<<"fitDebug"<< "isOK="<<isOK<<"\n";
804 AliExternalTrackParam * AliTPCcalibV0::RefitTrack(AliTPCseed *seed, AliTPCCorrection * corr, Double_t xstart, Double_t xstop, Double_t mass){
807 // seed - tpc track with cluster
808 // corr - distrotion/correction class - apllied to the points
809 // xstart - radius to start propagate/update
810 // xstop - radius to stop propagate/update
812 const Double_t kResetCov=20.;
813 const Double_t kSigma=5.;
815 for (Int_t i=0;i<15;i++) covar[i]=0;
816 covar[0]=kSigma*kSigma;
817 covar[2]=kSigma*kSigma;
818 covar[5]=kSigma*kSigma/Float_t(150*150);
819 covar[9]=kSigma*kSigma/Float_t(150*150);
822 AliExternalTrackParam *refit = new AliExternalTrackParam(*seed);
823 refit->PropagateTo(xstart, AliTracker::GetBz());
824 refit->AddCovariance(covar);
825 refit->ResetCovariance(kResetCov);
826 Double_t xmin = TMath::Min(xstart,xstop);
827 Double_t xmax = TMath::Max(xstart,xstop);
831 for (Int_t index0=0; index0<159; index0++){
832 Int_t irow= (xstart<xstop)? index0:159-index0;
833 AliTPCclusterMI *cluster=seed->GetClusterPointer(irow); //cluster in local system
834 if (!cluster) continue;
835 if (cluster->GetX()<xmin) continue;
836 if (cluster->GetX()>xmax) continue;
837 Double_t alpha = TMath::Pi()*(cluster->GetDetector()+0.5)/9.;
838 if (!refit->Rotate(alpha)) isOK=kFALSE;
839 Double_t x = cluster->GetX();
840 Double_t y = cluster->GetY();
841 Double_t z = cluster->GetZ();
843 Float_t xyz[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()}; // original position
844 corr->DistortPointLocal(xyz,cluster->GetDetector());
849 if (!AliTracker::PropagateTrackToBxByBz(refit, x,mass,1.,kFALSE)) isOK=kFALSE;
851 Double_t cov[3]={0.01,0.,0.01};
852 Double_t yz[2]={y,z};
853 if (!refit->Update(yz,cov)) isOK=kFALSE;
856 if (!AliTracker::PropagateTrackToBxByBz(refit, xstop, mass,1.,kTRUE)) isOK=kFALSE;
876 AliKFParticle * AliTPCcalibV0::Fit(AliKFVertex & /*primVtx*/, AliESDv0 *v0, Int_t PDG1, Int_t PDG2){
880 AliKFParticle p1( *(v0->GetParamN()), PDG1 );
881 AliKFParticle p2( *(v0->GetParamP()), PDG2 );
882 AliKFParticle *V0 = new AliKFParticle;
885 V0->SetVtxGuess(x,y,z);
894 void AliTPCcalibV0::BinLogX(TH2F *h) {
898 TAxis *axis = h->GetXaxis();
899 int bins = axis->GetNbins();
901 Double_t from = axis->GetXmin();
902 Double_t to = axis->GetXmax();
903 Double_t *new_bins = new Double_t[bins + 1];
906 Double_t factor = pow(to/from, 1./bins);
908 for (int i = 1; i <= bins; i++) {
909 new_bins[i] = factor * new_bins[i-1];
911 axis->Set(bins, new_bins);
917 void AliTPCcalibV0::FilterV0s(AliVEvent *event){
921 const Double_t kChi2Cut=20;
922 const Double_t kMinR=2;
923 const Double_t ptCut=0.2;
924 const Int_t kMinNcl=110;
926 Int_t nv0 = event->GetNumberOfV0s();
927 //AliESDVertex *vertex= (AliESDVertex *)event->GetPrimaryVertex();
928 //AliKFVertex kfvertex=*vertex;
931 //event->GetPrimaryVertex(vtx);
932 //AliESDVertex *vertex=&vtx;
933 //AliKFVertex *kfvertex=(AliKFVertex*)vertex;
936 event->GetPrimaryVertex(vtx);
937 AliESDVertex *vertex=&vtx;
938 AliKFVertex kfvertex=*vertex;
941 for (Int_t iv0=0;iv0<nv0;iv0++){
943 event->GetV0(dummyv0,iv0);
944 AliESDv0 *v0=&dummyv0;
947 if (v0->GetPindex()<0) continue;
948 if (v0->GetNindex()<0) continue;
949 if (TMath::Max(v0->GetPindex(), v0->GetNindex())>event->GetNumberOfTracks()) continue;
952 AliExternalTrackParam pp=(v0->GetParamP()->GetSign()>0) ? (*(v0->GetParamP())):(*(v0->GetParamN()));
953 AliExternalTrackParam pn=(v0->GetParamP()->GetSign()>0) ? (*(v0->GetParamN())):(*(v0->GetParamP()));
954 AliKFParticle kfp1( pp, 211 );
955 AliKFParticle kfp2( pn, -211 );
956 AliKFParticle *v0KFK0 = new AliKFParticle(kfp1,kfp2);
957 AliKFParticle *v0KFK0CV = new AliKFParticle(*v0KFK0);
958 v0KFK0CV->SetProductionVertex(kfvertex);
959 v0KFK0CV->TransportToProductionVertex();
960 AliKFParticle *v0KFK0CVM = new AliKFParticle(*v0KFK0CV);
961 v0KFK0CVM->SetMassConstraint(pdg.GetParticle("K_S0")->Mass());
962 Double_t chi2K0 = v0KFK0CV->GetChi2();
963 Double_t chi2K0M= v0KFK0CVM->GetChi2();
964 Double_t massK0=v0KFK0CV->GetMass();
965 if (chi2K0>kChi2Cut) continue;
966 if (v0->GetRr()>kMinR) continue;
968 Double_t maxPt = TMath::Max(v0->GetParamP()->Pt(), v0->GetParamN()->Pt());
969 Double_t effMass22=v0->GetEffMass(2,2);
970 Double_t effMass42=v0->GetEffMass(4,2);
971 Double_t effMass24=v0->GetEffMass(2,4);
973 isV0|=TMath::Abs(effMass22-pdg.GetParticle("K_S0")->Mass())<0.1;
974 isV0|=TMath::Abs(effMass42-pdg.GetParticle("Lambda0")->Mass())<0.1;
975 isV0|=TMath::Abs(effMass24-pdg.GetParticle("Lambda0")->Mass())<0.1;
977 Double_t sign= v0->GetParamP()->GetSign()* v0->GetParamN()->GetSign();
978 if (sign<0&&v0->GetOnFlyStatus()>0.5&&maxPt>ptCut&&isV0){
979 AliVTrack * trackP = event->GetVTrack(v0->GetPindex());
980 AliVTrack * trackN = event->GetVTrack(v0->GetNindex());
981 if (!trackN) continue;
982 if (!trackP) continue;
983 Int_t nclP= (Int_t)trackP->GetTPCClusterInfo(2,1);
984 Int_t nclN= (Int_t)trackN->GetTPCClusterInfo(2,1);
985 if (TMath::Min(nclP,nclN)<kMinNcl) continue;
986 Double_t eta = TMath::Max(TMath::Abs(trackP->Eta()), TMath::Abs(trackN->Eta()));
987 Double_t ncls = TMath::Min(TMath::Abs(trackP->GetNcls(0)), TMath::Abs(trackN->GetNcls(0)));
988 if (eta<0.8&&ncls>2){
989 // 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);
990 (*fDebugStreamer)<<"v0tree"<<