]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/TenderSupplies/AliTrackFixTenderSupply.cxx
Added debug mode + few fixes
[u/mrichter/AliRoot.git] / ANALYSIS / TenderSupplies / AliTrackFixTenderSupply.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 // Redo primary vertex on the fly, using the diamond constraint              //
20 //                                                                           //
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include <TSystem.h>
24 #include "AliESDEvent.h"
25 #include "AliTender.h"
26 #include "AliVParticle.h"
27 #include "AliLog.h"
28 #include "AliOADBContainer.h"
29 #include "AliAnalysisManager.h"
30 #include "AliTrackFixTenderSupply.h"
31 #include "AliOADBTrackFix.h"
32
33 ClassImp(AliTrackFixTenderSupply)
34
35 AliTrackFixTenderSupply::AliTrackFixTenderSupply() :
36 fDebug(0),
37   fBz(0),
38   fParams(0),
39   fOADBObjPath("$OADB/PWGPP/data/CorrPTInv.root"),
40   fOADBObjName("CorrPTInv"),
41   fOADBCont(0)
42 {
43   // default ctor
44 }
45
46 //_____________________________________________________
47 AliTrackFixTenderSupply::AliTrackFixTenderSupply(const char *name, const AliTender *tender) :
48   AliTenderSupply(name,tender),
49   fDebug(0),
50   fBz(0),
51   fParams(0),
52   fOADBObjPath("$OADB/PWGPP/data/CorrPTInv.root"),
53   fOADBObjName("CorrPTInv"),
54   fOADBCont(0)
55 {
56   // named ctor
57   //
58 }
59
60 //_____________________________________________________
61 AliTrackFixTenderSupply::~AliTrackFixTenderSupply()
62 {
63   // d-tor
64   delete fOADBCont;
65 }
66
67
68 //_____________________________________________________
69 void AliTrackFixTenderSupply::ProcessEvent()
70 {
71   //
72   // Fix track kinematics
73   //
74   AliESDEvent *event=fTender->GetEvent();
75   if (!event) return;
76   //
77   if (fTender->RunChanged() && !GetRunCorrections(fTender->GetRun())) return;
78   //
79   int nTracks = event->GetNumberOfTracks();
80   fBz = event->GetMagneticField();
81   if (TMath::Abs(fBz) < kAlmost0Field) return;
82   //
83   const AliESDVertex *vtx = 0, *vtxTPC = 0;
84   //
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;
89   }
90   vtxTPC = event->GetPrimaryVertexTPC(); // vertex to be used for update via RelateToVertexTPC
91   if (vtxTPC && vtxTPC->GetStatus()<1) vtxTPC = 0;
92   //  
93   AliExternalTrackParam* extPar = 0;
94   double xOrig = 0;
95   for (int itr=0;itr<nTracks;itr++) {
96     //
97     AliESDtrack* trc = event->GetTrack(itr);
98     if (!trc->IsOn(AliESDtrack::kTPCin)) continue;
99     //
100     double sideAfraction = GetSideAFraction(trc);
101     // correct the main parameterization
102     int cormode = trc->IsOn(AliESDtrack::kITSin) ? AliOADBTrackFix::kCorModeGlob : AliOADBTrackFix::kCorModeTPCInner;
103     xOrig = trc->GetX();
104     double xIniCor = fParams->GetXIniPtInvCorr(cormode);
105     const AliExternalTrackParam* parInner = trc->GetInnerParam();
106     if (!parInner) {
107       AliError("Failed to extract inner param");
108       continue;
109     }
110     double phi = parInner->Phi();
111     //
112     if (fDebug>1) {
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();
116     }
117     //
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
123     }
124     // 
125     if (fDebug>1) {
126       AliInfo("Main Param after corr.");
127       trc->AliExternalTrackParam::Print();
128     }
129     // correct TPCinner param
130     if ( (extPar=(AliExternalTrackParam*)trc->GetTPCInnerParam()) ) {
131       cormode = AliOADBTrackFix::kCorModeTPCInner;
132       xOrig = extPar->GetX();
133       xIniCor = fParams->GetXIniPtInvCorr(cormode);
134       if (fDebug>1) {
135         AliInfo(Form("TPCinner Param before corr. in mode %s, xIni:%.1f",cormode== AliOADBTrackFix::kCorModeGlob ?  "Glo":"TPC",xIniCor));
136         extPar->AliExternalTrackParam::Print();
137       }
138       //
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
144       }
145       //
146       if (fDebug>1) {
147         AliInfo("TPCinner Param after corr.");
148         extPar->AliExternalTrackParam::Print();
149       }      
150     }
151     //
152   }
153   //
154 }
155
156 //_____________________________________________________
157 void AliTrackFixTenderSupply::CorrectTrackPtInv(AliExternalTrackParam* trc, Int_t mode, double sideAfraction, double phi) const
158 {
159   // fix track kinematics
160   if (!trc) return;
161   double *param = (double*)trc->GetParameter();
162   param[4] += fParams->GetPtInvCorr(mode,sideAfraction,phi);
163   //
164 }
165
166 //_____________________________________________________
167 Bool_t AliTrackFixTenderSupply::LoadOADBObjects()
168 {
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()));
174   //
175   fOADBCont = new AliOADBContainer("OADB");
176   if (fOADBCont->InitFromFile(fileName.Data(),fOADBObjName.Data())) {
177     AliError("Failed to load OADB Container");
178     delete fOADBCont;
179     fOADBCont = 0;
180     return kFALSE;
181   }
182   //
183   return kTRUE;
184 }
185
186 //_____________________________________________________
187 Bool_t AliTrackFixTenderSupply::GetRunCorrections(int run)
188 {
189   // extract corrections for given run
190   fParams = 0;
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));
195   //
196   return kTRUE;
197 }
198
199 //_____________________________________________________
200 Double_t AliTrackFixTenderSupply::GetSideAFraction(const AliESDtrack* track) const
201 {
202   // decide A-side fraction of trajectory length in TPC 
203   // for the moment just a placeholder...
204   //
205   const AliExternalTrackParam *trIn = track->GetInnerParam();
206   if (!trIn) {AliError("Failed to onbtain InnerParam"); return 0.5;}
207   //
208   // easy cases:
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;}
212   //
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);
217   // z(t)=z0 - R*t*tgl
218   //
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();
231   //
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
241   //
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);
252   }
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);
255   return sideAfrac;
256 }