1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // Redo primary vertex on the fly, using the diamond constraint //
21 ///////////////////////////////////////////////////////////////////////////////
24 #include "AliESDEvent.h"
25 #include "AliTender.h"
26 #include "AliVParticle.h"
28 #include "AliOADBContainer.h"
29 #include "AliAnalysisManager.h"
30 #include "AliTrackFixTenderSupply.h"
31 #include "AliOADBTrackFix.h"
33 ClassImp(AliTrackFixTenderSupply)
35 AliTrackFixTenderSupply::AliTrackFixTenderSupply() :
39 fOADBObjPath("$OADB/PWGPP/data/CorrPTInv.root"),
40 fOADBObjName("CorrPTInv"),
46 //_____________________________________________________
47 AliTrackFixTenderSupply::AliTrackFixTenderSupply(const char *name, const AliTender *tender) :
48 AliTenderSupply(name,tender),
52 fOADBObjPath("$OADB/PWGPP/data/CorrPTInv.root"),
53 fOADBObjName("CorrPTInv"),
60 //_____________________________________________________
61 AliTrackFixTenderSupply::~AliTrackFixTenderSupply()
68 //_____________________________________________________
69 void AliTrackFixTenderSupply::ProcessEvent()
72 // Fix track kinematics
74 AliESDEvent *event=fTender->GetEvent();
77 if (fTender->RunChanged() && !GetRunCorrections(fTender->GetRun())) return;
79 int nTracks = event->GetNumberOfTracks();
80 fBz = event->GetMagneticField();
81 if (TMath::Abs(fBz) < kAlmost0Field) return;
83 const AliESDVertex *vtx = 0, *vtxTPC = 0;
85 vtx = event->GetPrimaryVertexTracks(); // vertex to be used for update via RelateToVertex
86 if (!vtx || vtx->GetStatus()<1) {
87 vtx = event->GetPrimaryVertexSPD();
88 if (vtx && vtx->GetStatus()<1) vtx = 0;
90 vtxTPC = event->GetPrimaryVertexTPC(); // vertex to be used for update via RelateToVertexTPC
91 if (vtxTPC && vtxTPC->GetStatus()<1) vtxTPC = 0;
93 AliExternalTrackParam* extPar = 0;
95 for (int itr=0;itr<nTracks;itr++) {
97 AliESDtrack* trc = event->GetTrack(itr);
98 if (!trc->IsOn(AliESDtrack::kTPCin)) continue;
100 double sideAfraction = GetSideAFraction(trc);
101 // correct the main parameterization
102 int cormode = trc->IsOn(AliESDtrack::kITSin) ? AliOADBTrackFix::kCorModeGlob : AliOADBTrackFix::kCorModeTPCInner;
104 double xIniCor = fParams->GetXIniPtInvCorr(cormode);
105 const AliExternalTrackParam* parInner = trc->GetInnerParam();
107 AliError("Failed to extract inner param");
110 double phi = parInner->Phi();
113 AliInfo(Form("Tr:%4d kITSin:%d Phi=%+5.2f at X=%+7.2f | SideA fraction: %.3f",itr,trc->IsOn(AliESDtrack::kITSin),phi,parInner->GetX(),sideAfraction));
114 AliInfo(Form("Main Param before corr. in mode %s, xIni:%.1f",cormode== AliOADBTrackFix::kCorModeGlob ? "Glo":"TPC",xIniCor));
115 trc->AliExternalTrackParam::Print();
118 if (xIniCor>0) trc->PropagateTo(xIniCor,fBz);
119 CorrectTrackPtInv(trc, cormode, sideAfraction, phi);
120 if (xIniCor>0) { // full update is requested
121 if (vtx) trc->RelateToVertex(vtx, fBz, kVeryBig); // redo DCA if vtx is available
122 else trc->PropagateTo(xOrig, fBz); // otherwise bring to original point
126 AliInfo("Main Param after corr.");
127 trc->AliExternalTrackParam::Print();
129 // correct TPCinner param
130 if ( (extPar=(AliExternalTrackParam*)trc->GetTPCInnerParam()) ) {
131 cormode = AliOADBTrackFix::kCorModeTPCInner;
132 xOrig = extPar->GetX();
133 xIniCor = fParams->GetXIniPtInvCorr(cormode);
135 AliInfo(Form("TPCinner Param before corr. in mode %s, xIni:%.1f",cormode== AliOADBTrackFix::kCorModeGlob ? "Glo":"TPC",xIniCor));
136 extPar->AliExternalTrackParam::Print();
139 if (xIniCor>0) extPar->PropagateTo(xIniCor,fBz);
140 CorrectTrackPtInv(extPar,cormode,sideAfraction, phi);
141 if (xIniCor>0) { // full update is requested
142 if (vtxTPC) trc->RelateToVertexTPC(vtxTPC, fBz, kVeryBig); // redo DCA if vtx is available
143 else extPar->PropagateTo(xOrig, fBz); // otherwise bring to original point
147 AliInfo("TPCinner Param after corr.");
148 extPar->AliExternalTrackParam::Print();
156 //_____________________________________________________
157 void AliTrackFixTenderSupply::CorrectTrackPtInv(AliExternalTrackParam* trc, Int_t mode, double sideAfraction, double phi) const
159 // fix track kinematics
161 double *param = (double*)trc->GetParameter();
162 param[4] += fParams->GetPtInvCorr(mode,sideAfraction,phi);
166 //_____________________________________________________
167 Bool_t AliTrackFixTenderSupply::LoadOADBObjects()
169 // Load OADB parameters
170 TString fileName = fOADBObjPath;
171 if (fileName.BeginsWith("$OADB")) fileName.ReplaceAll("$OADB",Form("%s/",AliAnalysisManager::GetOADBPath()));
172 gSystem->ExpandPathName(fileName);
173 AliInfo(Form("Loading correction parameters %s from %s",fOADBObjName.Data(),fileName.Data()));
175 fOADBCont = new AliOADBContainer("OADB");
176 if (fOADBCont->InitFromFile(fileName.Data(),fOADBObjName.Data())) {
177 AliError("Failed to load OADB Container");
186 //_____________________________________________________
187 Bool_t AliTrackFixTenderSupply::GetRunCorrections(int run)
189 // extract corrections for given run
191 if (!fOADBCont) if (!LoadOADBObjects()) return kFALSE;
192 fParams = dynamic_cast<AliOADBTrackFix*>(fOADBCont->GetObject(run,"default"));
193 if (!fParams) {AliError(Form("No correction parameters for found for run %d",run)); return kFALSE;}
194 AliInfo(Form("Loaded correction parameters for run %d",run));
199 //_____________________________________________________
200 Double_t AliTrackFixTenderSupply::GetSideAFraction(const AliESDtrack* track) const
202 // decide A-side fraction of trajectory length in TPC
203 // for the moment just a placeholder...
205 const AliExternalTrackParam *trIn = track->GetInnerParam();
206 if (!trIn) {AliError("Failed to onbtain InnerParam"); return 0.5;}
209 double sideAfrac = 0.5;
210 if (trIn->GetZ()>0) { sideAfrac = 1.; if (trIn->GetTgl()>-kAlmost0) return sideAfrac;}
211 else if (trIn->GetZ()<0) { sideAfrac = 0.; if (trIn->GetTgl()< kAlmost0) return sideAfrac;}
213 // track may cross the membrane
214 // convert to usual helix param:
215 // x(t)=(dca+R)*cos(phi0) -R*cos(t+phi0);
216 // y(t)=(dca+R)*sin(phi0) -R*sin(t+phi0);
219 int sqb = fBz<0 ? -trIn->Charge() : trIn->Charge();
220 double radq = TMath::Abs(trIn->GetC(fBz));
221 radq = radq>kAlmost0 ? 1./radq : 1e4; // track radius
222 if (sqb<0) radq = -radq;
223 double cstCphi0 = trIn->GetSnp(); // tC is current t
224 double sntCphi0 = -TMath::Sqrt((1.-cstCphi0)*(1+cstCphi0));
225 double xc0 = trIn->GetX() + radq*cstCphi0; // circle center
226 double yc0 = trIn->GetY() + radq*sntCphi0;
227 double phi0 = TMath::ATan2( yc0, xc0);
228 if (sqb<0) phi0 += TMath::Pi();
229 if (phi0 > TMath::Pi()) phi0 -= 2.*TMath::Pi();
230 else if (phi0 <-TMath::Pi()) phi0 += 2.*TMath::Pi();
232 double csphi0 = TMath::Cos(phi0);
233 double snphi0 = TMath::Sin(phi0);
234 double dca = xc0*csphi0 + yc0*snphi0 - radq;
235 double tC = TMath::ATan2(sntCphi0,cstCphi0) - phi0;
236 double tglR = radq*trIn->GetTgl();
237 double z0 = trIn->GetZ() + tglR*tC;
238 Double_t tCross = z0/tglR; // Z=0 is crossed at this t
239 // t is changed withing tCross:2pi range for the track moving forward
240 if (tCross<tC || tCross>TMath::Pi()) return sideAfrac; // on the way forward does not cross the membrane
242 // find max t reached by the track in the TPC
243 const double kROutTPC2 = 250.*250.;
244 // find t at which the outer radius is crossed
245 // r^2 = (dca+R)^2 + R^2 - 2R(R+dca)*cos(t)
246 double dcaR = dca+radq;
247 double rmax2 = dcaR*dcaR + radq*radq + 2*radq*dcaR; // max rad at t=pi
248 double tmax = TMath::Pi();
249 if (rmax2>kROutTPC2) { // traverses full TPC
250 double ct = 0.5*(dcaR/radq + radq/dcaR - kROutTPC2/radq/dcaR);
251 if (TMath::Abs(ct)<1-kAlmost0) tmax = TMath::ACos(ct);
253 if (tmax<tCross) return sideAfrac; // does not cross z=0
254 sideAfrac = sideAfrac>0.5 ? (tCross-tC)/(tmax-tC) : 1.-(tCross-tC)/(tmax-tC);