8 // This class estiamtes the material budget of the inner detectors in ALICE based
9 // on the "upper/lower track matching"-method of the ALICE TPC.
26 #include "TGeoGlobalMagField.h"
29 #include <TTreeStream.h>
30 #include <AliAnalysisManager.h>
31 #include <AliESDInputHandler.h>
33 #include "AliMCEvent.h"
34 #include "AliMCEventHandler.h"
37 #include "AliMaterialBudget.h"
38 #include "AliGenInfoMaker.h"
42 #include "AliMCInfo.h"
43 #include "AliESDRecInfo.h"
44 #include "AliTPCParamSR.h"
45 #include "AliTracker.h"
46 #include "AliTPCseed.h"
53 ClassImp(AliMaterialBudget)
55 //________________________________________________________________________
56 AliMaterialBudget::AliMaterialBudget() :
58 fMCinfo(0), //! MC event handler
66 fCutMaxD(5), // maximal distance in rfi ditection
67 fCutMaxDz(40), // maximal distance in z ditection
68 fCutTheta(0.03), // maximal distan theta
69 fCutMinDir(-0.99) // direction vector products
72 // Default constructor (should not be used)
76 AliMaterialBudget::AliMaterialBudget(const AliMaterialBudget& /*info*/) :
78 fMCinfo(0), //! MC event handler
87 fCutMaxD(5), // maximal distance in rfi ditection
88 fCutMaxDz(40), // maximal distance in z ditection
89 fCutTheta(0.03), // maximal distan theta
90 fCutMinDir(-0.99) // direction vector products
93 // Default constructor
99 //________________________________________________________________________
100 AliMaterialBudget::AliMaterialBudget(const char *name) :
101 AliAnalysisTask(name, "AliMaterialBudget"),
102 fMCinfo(0), //! MC event handler
110 fCutMaxD(5), // maximal distance in rfi ditection
111 fCutMaxDz(40), // maximal distance in z ditection
112 fCutTheta(0.03), // maximal distan theta
113 fCutMinDir(-0.99) // direction vector products
116 // Normal constructor
118 // Input slot #0 works with a TChain
119 DefineInput(0, TChain::Class());
120 // Output slot #0 writes into a TList
121 DefineOutput(0, TList::Class());
126 AliMaterialBudget::~AliMaterialBudget(){
130 if (fDebugLevel>0) printf("AliMaterialBudget::~AliMaterialBudget\n");
131 if (fDebugStreamer) delete fDebugStreamer;
136 //________________________________________________________________________
137 void AliMaterialBudget::ConnectInputData(Option_t *)
140 // Connect the input data
143 cout << "AnalysisTaskTPCCluster::ConnectInputData()" << endl;
145 TTree* tree=dynamic_cast<TTree*>(GetInputData(0));
147 //Printf("ERROR: Could not read chain from input slot 0");
150 AliESDInputHandler *esdH = dynamic_cast<AliESDInputHandler*> (AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
152 //Printf("ERROR: Could not get ESDInputHandler");
155 esdH->SetActiveBranches("ESDfriend");
156 fESD = esdH->GetEvent();
157 //Printf("*** CONNECTED NEW EVENT ****");
160 AliMCEventHandler* mcinfo = (AliMCEventHandler*) (AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler());
161 mcinfo->SetReadTR(kTRUE);
163 fMCinfo = mcinfo->MCEvent();
173 //________________________________________________________________________
174 void AliMaterialBudget::CreateOutputObjects()
177 // Connect the output objects
180 cout << "AnalysisTaskTPCCluster::CreateOutputObjects()" << endl;
182 fListHist = new TList();
183 fListHist->SetOwner();
185 fHistMult = new TH1F("HistMult", "Number of Tracks per Event; number of tracks per event; number of tracks",501,-0.5,500.5);
186 fListHist->Add(fHistMult);
192 //________________________________________________________________________
193 void AliMaterialBudget::Exec(Option_t *) {
195 // Execute analysis for current event
199 cout << "AliMaterialBudget::Exec()" << endl;
201 fHistMult->Fill(fESD->GetNumberOfTracks());
202 //FindPairs(fESD); // nearly everything takes place in find pairs...
204 // If MC has been connected
207 cout << "Not MC info\n" << endl;
214 PostData(0, fListHist);
220 //________________________________________________________________________
221 void AliMaterialBudget::Terminate(Option_t *) {
226 printf("AliMaterialBudget: Terminate() \n");
228 if (fDebugLevel>0) printf("AliMCtrackingTestTask::Terminate\n");
229 if (fDebugStreamer) delete fDebugStreamer;
236 TTreeSRedirector *AliMaterialBudget::GetDebugStreamer(){
238 // Get Debug streamer
239 // In case debug streamer not yet initialized and StreamLevel>0 create new one
241 if (fStreamLevel==0) return 0;
242 if (fDebugStreamer) return fDebugStreamer;
245 dsName+="Debug.root";
246 dsName.ReplaceAll(" ","");
247 fDebugStreamer = new TTreeSRedirector(dsName.Data());
248 return fDebugStreamer;
256 AliExternalTrackParam * AliMaterialBudget::MakeTrack(const AliTrackReference* ref, TParticle*part)
259 // Make track out of the track ref
260 // part - TParticle used to determine chargr
261 // the covariance matrix - equal 0 - starting from ideal MC position
262 if (!part->GetPDG()) return 0;
263 Double_t xyz[3]={ref->X(),ref->Y(),ref->Z()};
264 Double_t pxyz[3]={ref->Px(),ref->Py(),ref->Pz()};
265 Int_t charge = TMath::Nint(part->GetPDG()->Charge()/3.);
266 if (ref->X()*ref->Px()+ref->Y()*ref->Py() <0){
273 for (Int_t i=0; i<21;i++) cv[i]=0;
274 AliExternalTrackParam * param = new AliExternalTrackParam(xyz,pxyz,cv,charge);
278 Bool_t AliMaterialBudget::PropagateToPoint(AliExternalTrackParam *param, Double_t *xyz, Double_t mass, Float_t step){
280 // Propagate track to point xyz using
281 // AliTracker::PropagateTo functionality
283 // param - track parameters
284 // xyz - position to propagate
285 // mass - particle mass
286 // step - step to be used
287 Double_t radius=TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
288 AliTracker::PropagateTrackToBxByBz(param, radius+step, mass, step, kTRUE,0.99);
289 AliTracker::PropagateTrackToBxByBz(param, radius+0.5, mass, step*0.1, kTRUE,0.99);
290 Double_t sxyz[3]={0,0,0};
291 AliESDVertex vertex(xyz,sxyz);
292 Bool_t isOK = param->PropagateToDCA(&vertex,AliTracker::GetBz(),10);
297 void AliMaterialBudget::ProcessMCInfo(){
303 const Double_t kPcut=0.05;
304 const Double_t kMinDrITS = 2.; // minimal distance between references
305 const Double_t kMinDrTRD = 8.; // minimal distance between references
306 const Double_t kMinDrTOF = 10.; // minimal distance between references
311 Int_t npart = fMCinfo->GetNumberOfTracks();
312 if (npart==0) return;
313 Double_t vertex[4]={0,0,0,0};
315 TClonesArray * trefs = new TClonesArray("AliTrackReference");
316 TParticle * particle= new TParticle;
318 if(particle && trefs) {
319 fMCinfo->GetParticleAndTR(0, particle, trefs);
324 vertex[0]=particle->Vx();
325 vertex[1]=particle->Vy();
326 vertex[2]=particle->Vz();
327 vertex[3]=particle->R();
331 AliTrackReference dummy,*pdummy= &dummy;
332 AliExternalTrackParam epdummy,*pepdummy= &epdummy;
337 AliTrackReference * refITS0, *refITS1;
338 AliTrackReference * refTPC0, *refTPC1;
339 AliTrackReference * refTPCIn0, *refTPCIn1;
340 AliTrackReference * refTRD0, *refTRD1;
341 AliTrackReference * refTOF0, *refTOF1;
342 AliTrackReference *refMinR;
344 if(!particle) return;
345 for (Int_t ipart=0;ipart<npart;ipart++){
346 //Int_t status = fMCinfo->GetParticleAndTR(ipart, particle, trefs);
347 AliMCParticle * pp = (AliMCParticle*) fMCinfo->GetTrack(ipart);
349 if (particle->P()<kPcut) continue;
350 Double_t mass = particle->GetMass();
357 refITS0=pdummy; refITS1=pdummy;
358 refTPC0=pdummy; refTPC1=pdummy;
359 refTPCIn0=pdummy; refTPCIn1=pdummy;
360 refTRD0=pdummy; refTRD1=pdummy;
361 refTOF0=pdummy; refTOF1=pdummy;
364 Int_t nref = pp->GetNumberOfTrackReferences();
365 if (nref==0) continue;
366 for (Int_t iref = 0; iref < nref; iref++) {
367 AliTrackReference *ref = pp->GetTrackReference(iref);
368 if (ref->DetectorId()==AliTrackReference::kDisappeared) continue;
369 // if (ref.Px()*particle.Px()+ref.Py()*particle.Py()<0) break; // returning track
371 if (ref->DetectorId()==AliTrackReference::kITS){
372 if (TMath::Abs(ref->R()-refITS1->R())>kMinDrITS) {
376 if (refITS0==pdummy) refITS0=ref;
378 if (ref->DetectorId()==AliTrackReference::kTPC){
381 if (refTPC0==pdummy) refTPC0=ref;
383 if (ref->DetectorId()==AliTrackReference::kTRD){
384 if (TMath::Abs(ref->R()-refTRD1->R())>kMinDrTRD) {
388 if (refTRD0==pdummy) refTRD0=ref;
390 if (ref->DetectorId()==AliTrackReference::kTOF){
391 if (TMath::Abs(ref->X()-refTOF1->X()) + TMath::Abs(ref->Y()-refTOF1->Y()) + TMath::Abs(ref->Z()-refTOF1->Z())>kMinDrTOF) {
395 if (refTOF0==pdummy) refTOF0=ref;
398 // "find inner track ref"
399 if (ref->DetectorId()==AliTrackReference::kTPC){
400 if (ref->Px()*ref->X()+ref->Py()*ref->Y()<0){
402 if (refTPCIn0 == pdummy) refTPCIn0=ref;
403 if (refTPCIn0 != pdummy && refTPCIn0->R()>ref->R())
406 if (ref->Px()*ref->X()+ref->Py()*ref->Y()>0){
408 if (refTPCIn1 == pdummy) refTPCIn1=ref;
409 if (refTPCIn1 != pdummy && refTPCIn1->R()>ref->R())
415 if (refMinR==pdummy && ref->P()>0 ){
418 if (refMinR->R()>ref->R() && ref->P()>0 ) refMinR=ref;
422 AliExternalTrackParam * trackMC = pepdummy;
423 //track0->GetDZ(0,0,0,bz,dvertex0)
424 Float_t dist[2]={0,0};
425 AliMagF* field = (AliMagF*) TGeoGlobalMagField::Instance()->GetField();
426 Double_t esdfield= fESD->GetMagneticField();
427 Double_t xyz[3]={0,0,0};
428 Double_t bxyz[3]={0,0,0};
429 field->Field(xyz,bxyz);
430 if (refMinR->P()>0) {
431 trackMC = MakeTrack(refMinR,particle);
432 trackMC->GetDZ(0,0,0,bxyz[2],dist);
434 Double_t alphaTOF0 = TMath::ATan2(refTOF0->Y(),refTOF0->X());
435 Double_t alphaTOF1 = TMath::ATan2(refTOF1->Y(),refTOF1->X());
436 Int_t dsecTOF = TMath::Nint(180*(alphaTOF0-alphaTOF1)/(TMath::Pi()*20.)-0.5);
438 // make the two different TPC tracks and propagate them to their DCA
441 Bool_t statusProp = kFALSE;
444 AliExternalTrackParam * track0 = pepdummy;
445 AliExternalTrackParam * track1 = pepdummy;
446 AliExternalTrackParam * otrack0 = pepdummy;
447 AliExternalTrackParam * otrack1 = pepdummy;
448 if (refTPCIn0!=pdummy && refTPCIn1!=pdummy) {
449 track0 = MakeTrack(refTPCIn0,particle);
450 track1 = MakeTrack(refTPCIn1,particle);
451 otrack0 = MakeTrack(refTPCIn0,particle);
452 otrack1 = MakeTrack(refTPCIn1,particle);
453 dP = track0->P() - track1->P(); // momentum loss
454 statusProp = AliMaterialBudget::PropagateCosmicToDCA(track0,track1,mass);
456 dY = track0->GetY() - track1->GetY();
457 dZ = track0->GetZ() - track1->GetZ();
461 TTreeSRedirector *pcstream = GetDebugStreamer();
464 for (Int_t id=0; id<3;id++){
466 // if (id==0) sprintf(name,"mcAll"); // all tracks: inconvenient to cut if on is only interest in tracks which reach the TPC
467 if (id==0) continue; // require TPC
468 if (id==1) snprintf(name,100,"mcITS");
469 if (id==2) snprintf(name,100,"mcTPC");
470 if (id==1&& nRefITS==0) continue;
471 if (id==2&& nRefTPC==0) continue;
477 "tbfield="<<bxyz[2]<<
478 "esdbfield="<<esdfield<<
481 "nRefITS="<<nRefITS<<
482 "nRefTPC="<<nRefTPC<<
483 "nRefTRD="<<nRefTRD<<
484 "nRefTOF="<<nRefTOF<<
486 "refMinR.="<<refMinR<<
487 "refITS0.="<<refITS0<<
488 "refITS1.="<<refITS1<<
489 "refTPC0.="<<refTPC0<<
490 "refTPC1.="<<refTPC1<<
491 "refTPCIn0.="<<refTPCIn0<<
492 "refTPCIn1.="<<refTPCIn1<<
493 "refTRD0.="<<refTRD0<<
494 "refTRD1.="<<refTRD1<<
495 "refTOF0.="<<refTOF0<<
496 "refTOF1.="<<refTOF1<<
498 "dsecTOF="<<dsecTOF<< // delta TOF sectors
499 "aTOF0="<<alphaTOF0<<
500 "aTOF1="<<alphaTOF1<<
507 "status="<<statusProp<<
509 "otrack0.="<<otrack0<<
510 "otrack1.="<<otrack1<<
523 void AliMaterialBudget::ProcessRefTracker(AliTrackReference* refIn, AliTrackReference* refOut, TParticle*part,Int_t type){
525 // Test propagation from In to out
527 AliExternalTrackParam *param = 0;
528 AliExternalTrackParam *paramMC = 0;
529 Double_t xyzIn[3]={refIn->X(),refIn->Y(), refIn->Z()};
530 Double_t mass = part->GetMass();
533 param=MakeTrack(refOut,part);
534 paramMC=MakeTrack(refOut,part);
536 if (type<3) PropagateToPoint(param,xyzIn, mass, step);
539 seed.Set(param->GetX(),param->GetAlpha(),param->GetParameter(),param->GetCovariance());
540 Float_t alpha= TMath::ATan2(refIn->Y(),refIn->X());
541 if(seed.Rotate(alpha-seed.GetAlpha()) == kFALSE) return;
543 for (Float_t xlayer= seed.GetX(); xlayer>refIn->R(); xlayer-=step){
544 seed.PropagateTo(xlayer);
546 seed.PropagateTo(refIn->R());
547 param->Set(seed.GetX(),seed.GetAlpha(),seed.GetParameter(),seed.GetCovariance());
549 TTreeSRedirector *pcstream = GetDebugStreamer();
552 param->GetXYZ(gpos.GetMatrixArray());
553 param->GetPxPyPz(gmom.GetMatrixArray());
570 void AliMaterialBudget::FitTrackRefs(TParticle * part, TClonesArray * trefs){
575 const Int_t kMinRefs=6;
576 Int_t nrefs = trefs->GetEntries();
577 if (nrefs<kMinRefs) return; // we should have enough references
581 for (Int_t iref=0; iref<nrefs; iref++){
582 AliTrackReference * ref = (AliTrackReference*)trefs->At(iref);
584 Float_t dir = ref->X()*ref->Px()+ref->Y()*ref->Py();
586 if (ref->DetectorId()!=AliTrackReference::kTPC) continue;
587 if (iref0<0) iref0 = iref;
590 if (iref1-iref0<kMinRefs) return;
592 for (Int_t icov=0; icov<15; icov++) covar[icov]=0;
599 AliTrackReference * refIn = (AliTrackReference*)trefs->At(iref0);
600 AliTrackReference * refOut = (AliTrackReference*)trefs->At(iref1);
601 AliExternalTrackParam *paramPropagate= MakeTrack(refIn,part);
602 AliExternalTrackParam *paramUpdate = MakeTrack(refIn,part);
603 paramUpdate->AddCovariance(covar);
604 Double_t mass = part->GetMass();
605 Double_t charge = part->GetPDG()->Charge()/3.;
607 Float_t alphaIn= TMath::ATan2(refIn->Y(),refIn->X());
608 Float_t radiusIn= refIn->R();
609 Float_t alphaOut= TMath::ATan2(refOut->Y(),refOut->X());
610 Float_t radiusOut= refOut->R();
614 AliMagF * field = (AliMagF*) TGeoGlobalMagField::Instance()->GetField();
615 for (Int_t iref = iref0; iref<=iref1; iref++){
616 AliTrackReference * ref = (AliTrackReference*)trefs->At(iref);
617 Float_t alphaC= TMath::ATan2(ref->Y(),ref->X());
618 Double_t pos[3] = {ref->X(), ref->Y(), ref->Z()};
620 field->Field(pos,mag);
621 isOKP&=paramPropagate->Rotate(alphaC);
622 isOKU&=paramUpdate->Rotate(alphaC);
623 for (Float_t xref= paramPropagate->GetX(); xref<ref->R(); xref++){
624 isOKP&=paramPropagate->PropagateTo(xref, mag[2]);
625 isOKU&=paramUpdate->PropagateTo(xref, mag[2]);
627 isOKP&=paramPropagate->PropagateTo(ref->R(), mag[2]);
628 isOKU&=paramUpdate->PropagateTo(ref->R(), mag[2]);
629 Double_t clpos[2] = {0, ref->Z()};
630 Double_t clcov[3] = { 0.005,0,0.005};
631 isOKU&= paramUpdate->Update(clpos, clcov);
633 TTreeSRedirector *pcstream = GetDebugStreamer();
639 paramUpdate->GetXYZ(gposU.GetMatrixArray());
640 paramUpdate->GetPxPyPz(gmomU.GetMatrixArray());
641 paramPropagate->GetXYZ(gposP.GetMatrixArray());
642 paramPropagate->GetPxPyPz(gmomP.GetMatrixArray());
644 (*pcstream)<<"MCupdate"<<
652 "pP.="<<paramPropagate<<
653 "pU.="<<paramUpdate<<
664 void AliMaterialBudget::FindPairs(AliESDEvent * event) {
666 // This function matches the cosmic tracks and calculates the energy loss in the material.
667 // If accessible the "true" energy loss is determined with the MC track references.
672 // Track0 is choosen in upper TPC part
673 // Track1 is choosen in lower TPC part
676 cout << "AliMaterialBudget::FindPairs()" << endl;
679 AliESDfriend *ESDfriend=static_cast<AliESDfriend*>(event->FindListObject("AliESDfriend"));
680 Int_t ntracks=event->GetNumberOfTracks();
681 TObjArray tpcSeeds(ntracks);
682 if (ntracks==0) return;
683 Double_t vtxx[3]={0,0,0};
684 Double_t svtxx[3]={0.000001,0.000001,100.};
685 AliESDVertex vtx(vtxx,svtxx);
689 for (Int_t i=0;i<ntracks;++i) {
690 AliESDtrack *track = event->GetTrack(i);
691 const AliExternalTrackParam * trackIn = track->GetInnerParam();
692 const AliExternalTrackParam * trackOut = track->GetOuterParam();
693 if (!trackIn) continue;
694 if (!trackOut) continue;
695 AliESDfriendTrack *friendTrack = ESDfriend->GetTrack(i);
696 if (!friendTrack) continue;
697 TObject *calibObject;
698 AliTPCseed *seed = 0;
699 for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) {
700 if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
702 if (seed) tpcSeeds.AddAt(seed,i);
705 if (ntracks<2) return;
709 for (Int_t i=0;i<ntracks;++i) {
710 AliESDtrack *track0 = event->GetTrack(i);
711 // track0 - choosen upper part
712 if (!track0) continue;
713 if (!track0->GetOuterParam()) continue;
714 if (track0->GetOuterParam()->GetAlpha()<0) continue;
716 track0->GetDirection(dir0);
717 for (Int_t j=0;j<ntracks;++j) {
719 AliESDtrack *track1 = event->GetTrack(j);
721 if (!track1) continue;
722 if (!track1->GetOuterParam()) continue;
723 if (track1->GetOuterParam()->GetAlpha()>0) continue;
726 track1->GetDirection(dir1);
728 AliTPCseed * seed0 = (AliTPCseed*) tpcSeeds.At(i);
729 AliTPCseed * seed1 = (AliTPCseed*) tpcSeeds.At(j);
730 if (! seed0) continue;
731 if (! seed1) continue;
733 Float_t dir = (dir0[0]*dir1[0] + dir0[1]*dir1[1] + dir0[2]*dir1[2]);
734 Float_t d0 = track0->GetLinearD(0,0);
735 Float_t d1 = track1->GetLinearD(0,0);
737 // conservative cuts - convergence to be guarantied
738 // applying before track propagation
739 if (TMath::Abs(d0+d1)>fCutMaxD) continue; // distance to the 0,0
740 if (dir>fCutMinDir) continue; // direction vector product
741 Float_t bz = AliTracker::GetBz();
742 Float_t dvertex0[2]; //distance to 0,0
743 Float_t dvertex1[2]; //distance to 0,0
744 track0->GetDZ(0,0,0,bz,dvertex0);
745 track1->GetDZ(0,0,0,bz,dvertex1);
746 if (TMath::Abs(dvertex0[1])>250) continue;
747 if (TMath::Abs(dvertex1[1])>250) continue;
751 Float_t dmax = TMath::Max(TMath::Abs(d0),TMath::Abs(d1));
752 AliExternalTrackParam param0(*track0);
753 AliExternalTrackParam param1(*track1);
755 // Propagate using Magnetic field and correct fo material budget
757 AliTracker::PropagateTrackToBxByBz(¶m0,dmax+1,0.0005,3,kTRUE);
758 AliTracker::PropagateTrackToBxByBz(¶m1,dmax+1,0.0005,3,kTRUE);
760 // Propagate rest to the 0,0 DCA - z should be ignored
762 Bool_t b0 = param0.PropagateToDCA(&vtx,bz,1000);
763 Bool_t b1 = param1.PropagateToDCA(&vtx,bz,1000);
765 param0.GetDZ(0,0,0,bz,dvertex0);
766 param1.GetDZ(0,0,0,bz,dvertex1);
767 if (TMath::Abs(param0.GetZ()-param1.GetZ())>fCutMaxDz) continue;
769 Double_t xyz0[3];//,pxyz0[3];
770 Double_t xyz1[3];//,pxyz1[3];
773 Bool_t isPair = IsPair(¶m0,¶m1);
775 // HERE WE WILL PUT THE ACCESS TO THE MC TRACKS AND MATCH THESE !!!!
777 Int_t label0 = TMath::Abs(track0->GetLabel());
778 AliMCParticle *mcParticle0 = (AliMCParticle*) fMCinfo->GetTrack(label0);
779 TParticle *particle0 = mcParticle0->Particle();
780 AliTrackReference *ref0 = GetFirstTPCTrackRef(mcParticle0); // get the first TPC track reference
782 AliExternalTrackParam *paramMC0 = 0;
783 paramMC0 = MakeTrack(ref0, particle0);
785 Int_t label1 = TMath::Abs(track1->GetLabel());
786 AliMCParticle *mcParticle1 = (AliMCParticle*) fMCinfo->GetTrack(label1);
787 TParticle *particle1 = mcParticle1->Particle();
788 AliTrackReference *ref1 = GetFirstTPCTrackRef(mcParticle1); // get the first TPC track reference
790 AliExternalTrackParam *paramMC1 = 0;
791 paramMC1 = MakeTrack(ref1, particle1);
793 // ACCESS TOF INFORMATION
794 Int_t nTrackRefTOF0 = 0;
795 Int_t nTrackRefITS0 = 0;
796 AliTrackReference * refLastTOF0 = 0;
797 AliTrackReference * refFirstTOF0 = GetAllTOFinfo(mcParticle0, nTrackRefTOF0, nTrackRefITS0);
798 Float_t alphaTOF0 = 0;
799 if (refFirstTOF0) alphaTOF0 = refFirstTOF0->Alpha();
801 Int_t nTrackRefTOF1 = 0;
802 Int_t nTrackRefITS1 = 0;
803 AliTrackReference * refLastTOF1 = 0;
804 AliTrackReference * refFirstTOF1 =GetAllTOFinfo(mcParticle1, nTrackRefTOF1, nTrackRefITS1);
805 Float_t alphaTOF1 = 0;
806 if (refFirstTOF1) alphaTOF1 = refFirstTOF1->Alpha();
807 //cout << " STATUS "<<nTrackRefTOF0<<" "<<refFirstTOF0<<" "<<refLastTOF0<<" " <<refFirstTOF1<<" "<<refLastTOF1<<endl;
812 TTreeSRedirector * cstream = GetDebugStreamer();
813 AliExternalTrackParam *ip0 = (AliExternalTrackParam *)track0->GetInnerParam();
814 AliExternalTrackParam *ip1 = (AliExternalTrackParam *)track1->GetInnerParam();
815 AliExternalTrackParam *op0 = (AliExternalTrackParam *)track0->GetOuterParam();
816 AliExternalTrackParam *op1 = (AliExternalTrackParam *)track1->GetOuterParam();
821 (*cstream) << "Track0" <<
822 "dir="<<dir<< // direction
823 "OK="<<isPair<< // will be accepted
824 "b0="<<b0<< // propagate status
825 "b1="<<b1<< // propagate status
827 "Particle.="<<particle0<< // TParticle with generated momentum
828 "NTrackRefTOF0="<<nTrackRefTOF0<< // Number of TOF track references upper
829 "NTrackRefTOF1="<<nTrackRefTOF1<< // Number of TOF track references lower
830 "NTrackRefITS0="<<nTrackRefITS0<< // Number of ITS track references upper
831 "NTrackRefITS1="<<nTrackRefITS1<< // Number of ITS track references lower
832 "Alpha0="<<alphaTOF0<< // alpha upper
833 "Alpha1="<<alphaTOF1<< // alpha lower
834 "RefFirstTOF0.="<<refFirstTOF0<< // first tof reference upper
835 "RefLastTOF0.="<<refLastTOF0<< // last tof reference upper
836 "RefFirstTOF1.="<<refFirstTOF1<< // first tof reference lower
837 "RefLastTOF1.="<<refLastTOF1<< // last tof reference lower
839 "Orig0.=" << track0 << // original track 0
840 "Orig1.=" << track1 << // original track 1
841 "Tr0.="<<¶m0<< // track propagated to the DCA 0,0
842 "Tr1.="<<¶m1<< // track propagated to the DCA 0,0
843 "Ip0.="<<ip0<< // inner param - upper
844 "Ip1.="<<ip1<< // inner param - lower
845 "Op0.="<<op0<< // outer param - upper
846 "Op1.="<<op1<< // outer param - lower
848 "paramTrackRef0.="<<paramMC0<< // "ideal" MC true track parameters from track references - upper
849 "paramTrackRef1.="<<paramMC1<< // "ideal" MC true track parameters from track references - lower
851 "v00="<<dvertex0[0]<< // distance using kalman
852 "v01="<<dvertex0[1]<< //
853 "v10="<<dvertex1[0]<< //
854 "v11="<<dvertex1[1]<< //
855 "d0="<<d0<< // linear distance to 0,0
856 "d1="<<d1<< // linear distance to 0,0
860 "x00="<<xyz0[0]<< // global position close to vertex
864 "x10="<<xyz1[0]<< // global position close to vertex
868 "dir00="<<dir0[0]<< // direction upper
872 "dir10="<<dir1[0]<< // direction lower
877 "Seed0.=" << seed0 << // original seed 0
878 "Seed1.=" << seed1 << // original seed 1
893 Bool_t AliMaterialBudget::IsPair(AliExternalTrackParam *tr0, AliExternalTrackParam *tr1){
897 // 0. Same direction - OPOSITE - cutDir +cutT
898 TCut cutDir("cutDir","dir<-0.99")
900 TCut cutT("cutT","abs(Tr1.fP[3]+Tr0.fP[3])<0.03")
903 TCut cutD("cutD","abs(Tr0.fP[0]+Tr1.fP[0])<5")
907 TCut cutPt("cutPt","abs(Tr1.fP[4]+Tr0.fP[4])<1&&abs(Tr0.fP[4])+abs(Tr1.fP[4])<10");
910 const Double_t *p0 = tr0->GetParameter();
911 const Double_t *p1 = tr1->GetParameter();
912 if (TMath::Abs(p0[3]+p1[3])>fCutTheta) return kFALSE;
913 if (TMath::Abs(p0[1]-p1[1])>fCutMaxDz) return kFALSE;
914 if (TMath::Abs(p0[0]+p1[0])>fCutMaxD) return kFALSE;
916 Double_t d0[3], d1[3];
917 tr0->GetDirection(d0);
918 tr1->GetDirection(d1);
919 if (d0[0]*d1[0] + d0[1]*d1[1] + d0[2]*d1[2] >fCutMinDir) return kFALSE;
925 AliTrackReference * AliMaterialBudget::GetFirstTPCTrackRef(AliMCParticle *mcParticle)
927 // return first TPC track reference
928 if(!mcParticle) return 0;
930 // find first track reference
931 // check direction to select proper reference point for looping tracks
932 Int_t nTrackRef = mcParticle->GetNumberOfTrackReferences();
933 AliTrackReference *ref = 0;
934 AliTrackReference *refIn = 0;
935 for (Int_t iref = 0; iref < nTrackRef; iref++) {
936 ref = mcParticle->GetTrackReference(iref);
937 if(ref && (ref->DetectorId()==AliTrackReference::kTPC))
939 //Float_t dir = ref->X()*ref->Px()+ref->Y()*ref->Py();
940 //if(dir < 0.) break;
951 AliTrackReference * AliMaterialBudget::GetAllTOFinfo(AliMCParticle *mcParticle, Int_t &nTrackRef, Int_t &nTrackRefITS, Int_t retValue) {
956 if(!mcParticle) return 0;
960 AliTrackReference *ref = 0;
961 for (Int_t iref = 0; iref < mcParticle->GetNumberOfTrackReferences(); iref++) {
962 ref = mcParticle->GetTrackReference(iref);
963 if(ref && (ref->DetectorId()==AliTrackReference::kTOF)) {
967 if(ref && (ref->DetectorId()==AliTrackReference::kITS)) nTrackRefITS++;
969 if (nTrackRef ==0) return 0;
970 if (retValue == 0) return mcParticle->GetTrackReference(counter - nTrackRef +1);
971 return mcParticle->GetTrackReference(counter);
976 void AliMaterialBudget::FinishTaskOutput()
979 // According description in AliAnalisysTask this method is call
980 // on the slaves before sending data
983 gSystem->Exec("pwd");
984 RegisterDebugOutput();
989 void AliMaterialBudget::RegisterDebugOutput(){
994 // store - copy debug output to the destination position
995 // currently ONLY for local copy
998 dsName+="Debug.root";
999 dsName.ReplaceAll(" ","");
1000 TString dsName2=fDebugOutputPath.Data();
1001 gSystem->MakeDirectory(dsName2.Data());
1002 dsName2+=gSystem->HostName();
1003 gSystem->MakeDirectory(dsName2.Data());
1005 dsName2+=gSystem->BaseName(gSystem->pwd());
1007 gSystem->MakeDirectory(dsName2.Data());
1009 AliInfo(Form("copy %s\t%s\n",dsName.Data(),dsName2.Data()));
1010 printf("copy %s\t%s\n",dsName.Data(),dsName2.Data());
1011 TFile::Cp(dsName.Data(),dsName2.Data());
1015 Bool_t AliMaterialBudget::PropagateCosmicToDCA(AliExternalTrackParam *param0, AliExternalTrackParam *param1, Double_t mass){
1017 // param0 - upper part of cosmic track
1018 // param1 - lower part of cosmic track
1020 // 0. Propagate both tracks to DCA to (0,0,0)
1021 // 1. After propagation to DCA rotate track param1 to corrdinate system of track1 <-> rotate param0 to coordinate system of param 1 ????
1022 // 2. Propagate track 1 to refernce x from track0
1027 Float_t d0 = param0->GetLinearD(0,0);
1028 Float_t d1 = param1->GetLinearD(0,0);
1029 Float_t dmax = TMath::Max(TMath::Abs(d0),TMath::Abs(d1));
1031 // propagate in the beginning taking all material into account
1033 AliTracker::PropagateTrackToBxByBz(param0,dmax+1.,mass,0.5,kTRUE,0.99,-1.);
1034 AliTracker::PropagateTrackToBxByBz(param1,dmax+1.,mass,0.5,kTRUE,0.99,1.);
1036 Double_t vtxx[3]={0,0,0};
1037 Double_t svtxx[3]={0.000001,0.000001,100.};
1038 AliESDVertex vtx(vtxx,svtxx);
1040 Bool_t b0 = param0->PropagateToDCA(&vtx,AliTracker::GetBz(),1000);
1041 Bool_t b1 = param1->PropagateToDCA(&vtx,AliTracker::GetBz(),1000);
1043 if (!(b0 && b1)) return 0;
1047 Float_t dAlpha = param0->GetAlpha();
1048 param1->Rotate(dAlpha);
1052 Float_t refX = param0->GetX();
1053 param1->PropagateTo(refX,AliTracker::GetBz());