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 // Component for redoing the reconstruction from the clusters and tracks
21 // The new calibration data used
23 // In reality it overwrites the content of the ESD
28 gSystem->Load("libANALYSIS");
29 gSystem->Load("libTPCcalib");
31 gSystem->AddIncludePath("-I$ALICE_ROOT/TPC/macros");
32 gROOT->LoadMacro("$ALICE_ROOT/TPC/macros/AliXRDPROOFtoolkit.cxx+")
33 AliXRDPROOFtoolkit tool;
34 TChain * chainCl = tool.MakeChain("calib.txt","Clusters",0,1);
36 TChain * chainTr = tool.MakeChain("calib.txt","Tracks",0,1);
45 // marian.ivanov@cern.ch
47 #include "AliTPCcalibCalib.h"
50 #include "TTreeStream.h"
52 #include "TTimeStamp.h"
53 #include "AliESDEvent.h"
54 #include "AliESDfriend.h"
55 #include "AliESDtrack.h"
56 #include "AliTracker.h"
57 #include "AliTPCClusterParam.h"
58 #include "AliTPCParam.h"
60 #include "AliTPCcalibDB.h"
61 #include "AliTPCTransform.h"
62 #include "AliTPCRecoParam.h"
63 #include "AliTPCclusterMI.h"
64 #include "AliTPCseed.h"
65 #include <TGeoManager.h>
66 #include <TGeoPhysicalNode.h>
67 #include "TDatabasePDG.h"
68 ClassImp(AliTPCcalibCalib)
70 AliTPCcalibCalib::AliTPCcalibCalib():
72 fApplyExBCorrection(1), // apply ExB correction
73 fApplyTOFCorrection(1), // apply TOF correction
74 fApplyPositionCorrection(1), // apply position correction
75 fApplySectorAlignment(1), // apply sector alignment
76 fApplyRPhiCorrection(1), // apply R-Phi correction
77 fApplyRCorrection(1) // apply Radial correction
86 AliTPCcalibCalib::AliTPCcalibCalib(const Text_t *name, const Text_t *title)
88 fApplyExBCorrection(1), // apply ExB correction
89 fApplyTOFCorrection(1), // apply TOF correction
90 fApplyPositionCorrection(1), // apply position correction
91 fApplySectorAlignment(1), // apply sector alignment
92 fApplyRPhiCorrection(1), // apply R-Phi correction
93 fApplyRCorrection(1) // apply Radial correction
100 AliTPCcalibCalib::AliTPCcalibCalib(const AliTPCcalibCalib&calib):
101 AliTPCcalibBase(calib),
102 fApplyExBCorrection(calib.GetApplyExBCorrection()),
103 fApplyTOFCorrection(calib.GetApplyTOFCorrection()),
104 fApplyPositionCorrection(calib.GetApplyPositionCorrection()),
105 fApplySectorAlignment(calib.GetApplySectorAlignment()),
106 fApplyRPhiCorrection(calib.GetApplyRPhiCorrection()),
107 fApplyRCorrection(calib.GetApplyRCorrection())
115 AliTPCcalibCalib &AliTPCcalibCalib::operator=(const AliTPCcalibCalib&calib){
119 ((AliTPCcalibBase *)this)->operator=(calib);
124 AliTPCcalibCalib::~AliTPCcalibCalib() {
131 void AliTPCcalibCalib::Process(AliESDEvent *event){
138 AliESDfriend *ESDfriend=static_cast<AliESDfriend*>(event->FindListObject("AliESDfriend"));
142 if (ESDfriend->TestSkipBit()) return;
143 if (GetDebugLevel()>20) printf("Hallo world: Im here\n");
144 Int_t ntracks=ESDfriend->GetNumberOfTracks();
145 //AliTPCcalibDB::Instance()->SetExBField(fMagF);
151 for (Int_t i=0;i<ntracks;++i) {
152 AliESDtrack *track = event->GetTrack(i);
153 AliESDfriendTrack *friendTrack = (AliESDfriendTrack*) ESDfriend->GetTrack(i);
154 if (!friendTrack) continue;
155 //track->SetFriendTrack(friendTrack);
156 fCurrentFriendTrack=friendTrack;
157 const AliExternalTrackParam * trackIn = track->GetInnerParam();
158 const AliExternalTrackParam * trackOut = track->GetOuterParam();
159 AliExternalTrackParam * tpcOut = (AliExternalTrackParam *)friendTrack->GetTPCOut();
160 if (!trackIn) continue;
161 if (!trackOut) continue;
162 if (!tpcOut) continue;
163 TObject *calibObject;
164 AliTPCseed *seed = 0;
165 for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) {
166 if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
169 RefitTrack(track, seed, event->GetMagneticField());
170 (*tpcOut)=*(track->GetOuterParam());
175 Bool_t AliTPCcalibCalib::RefitTrack(AliESDtrack * track, AliTPCseed *seed, Float_t magesd){
178 // if magesd==0 forget the curvature
181 // 0 - Setup transform object
183 const Double_t kxIFC = 83.; // position of IFC
184 const Double_t kxOFC = 250.; // position of OFC
185 const Double_t kaFC = 1.; // amplitude
186 const Double_t ktFC = 5.0; // slope of error
187 //cov[0]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
188 //cov[2]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
190 static Int_t streamCounter=0;
192 AliESDfriendTrack *friendTrack = fCurrentFriendTrack;
194 AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
195 AliTPCParam *param = AliTPCcalibDB::Instance()->GetParameters();
196 transform->SetCurrentRun(fRun);
197 transform->SetCurrentTimeStamp((UInt_t)fTime);
198 if(!fApplyExBCorrection) { // disable ExB correction in transform
199 if(transform->GetCurrentRecoParam())
200 transform->GetCurrentRecoParamNonConst()->SetUseExBCorrection(0);
202 if(!fApplyTOFCorrection) { // disable TOF correction in transform
203 if(transform->GetCurrentRecoParam())
204 transform->GetCurrentRecoParamNonConst()->SetUseTOFCorrection(kFALSE);
208 // First apply calibration
210 // AliTPCPointCorrection * corr = AliTPCPointCorrection::Instance();
211 TVectorD vec(5, seed->GetParameter());
212 for (Int_t irow=0;irow<159;irow++) {
213 AliTPCclusterMI *cluster=seed->GetClusterPointer(irow);
214 if (!cluster) continue;
215 AliTPCclusterMI cl0(*cluster);
216 Double_t x[3]={cluster->GetRow(),cluster->GetPad(),cluster->GetTimeBin()};
217 Int_t i[1]={cluster->GetDetector()};
218 AliTPCTrackerPoint * point = seed->GetTrackPoint(irow);
222 ty = TMath::Abs(point->GetAngleY());
223 tz = TMath::Abs(point->GetAngleZ()*TMath::Sqrt(1+ty*ty));
225 transform->Transform(x,i,0,1);
227 // get position correction
230 if (cluster->GetDetector()>35) ipad=1;
231 Float_t dy =0;//AliTPCClusterParam::SPosCorrection(0,ipad,cluster->GetPad(),cluster->GetTimeBin(),cluster->GetZ(),cluster->GetSigmaY2(),cluster->GetSigmaZ2(),cluster->GetMax());
232 Float_t dz =0;//AliTPCClusterParam::SPosCorrection(1,ipad,cluster->GetPad(),cluster->GetTimeBin(),cluster->GetZ(),cluster->GetSigmaY2(),cluster->GetSigmaZ2(),cluster->GetMax());
241 if (transform->GetCurrentRecoParam()->GetUseSectorAlignment()){
242 if (!param->IsGeoRead()) param->ReadGeoMatrices();
243 TGeoHMatrix *mat = param->GetClusterMatrix(cluster->GetDetector());
245 Double_t pos[3]= {cluster->GetX(),cluster->GetY(),cluster->GetZ()};
246 Double_t posC[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()};
247 if (mat) mat->LocalToMaster(pos,posC);
249 // chack Loading of Geo matrices from GeoManager - TEMPORARY FIX
251 cluster->SetX(posC[0]);
252 cluster->SetY(posC[1]);
253 cluster->SetZ(posC[2]);
258 if (fStreamLevel>2 && gRandom->Rndm()<0.1 ){
259 // dump debug info if required
260 TTreeSRedirector *cstream = GetDebugStreamer();
262 (*cstream)<<"Clusters"<<
263 "run="<<fRun<< // run number
264 "event="<<fEvent<< // event number
265 "time="<<fTime<< // time stamp of event
266 "trigger="<<fTrigger<< // trigger
267 "triggerClass="<<&fTriggerClass<< // trigger
268 "mag="<<fMagF<< // magnetic field
275 "vec.="<<&vec<< //track parameters
283 Int_t ncl = seed->GetNumberOfClusters();
284 const Double_t kResetCov=4.;
285 const Double_t kSigma=5.;
287 for (Int_t i=0;i<15;i++) covar[i]=0;
288 covar[0]=kSigma*kSigma;
289 covar[2]=kSigma*kSigma;
290 covar[5]=kSigma*kSigma/Float_t(ncl*ncl);
291 covar[9]=kSigma*kSigma/Float_t(ncl*ncl);
293 if (TMath::Abs(magesd)<0.05) {
294 covar[14]=0.025*0.025;
299 AliExternalTrackParam * trackInOld = (AliExternalTrackParam*)track->GetInnerParam();
300 AliExternalTrackParam * trackOuter = (AliExternalTrackParam*)track->GetOuterParam();
301 AliExternalTrackParam * trackOutOld = (AliExternalTrackParam *)friendTrack->GetTPCOut();
302 Double_t mass = TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
306 AliExternalTrackParam trackIn = *trackOutOld;
307 trackIn.ResetCovariance(kResetCov);
308 trackIn.AddCovariance(covar);
309 if (TMath::Abs(magesd)<0.05) {
310 ((Double_t&)(trackIn.GetParameter()[4]))=0.000000001;
311 ((Double_t&)(trackIn.GetCovariance()[14]))=covar[14]; // fix the line
315 Int_t nclIn=0,nclOut=0;
319 for (Int_t irow=159; irow>0; irow--){
320 AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
322 if (cl->GetX()<80) continue;
323 Int_t sector = cl->GetDetector();
324 Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackIn.GetAlpha();
325 if (TMath::Abs(dalpha)>0.01){
326 if (!trackIn.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
328 Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
329 Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
330 AliTPCseed::GetError(cl, &trackIn,cov[0],cov[2]);
333 cov[0]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
334 cov[2]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
336 // Double_t bz = AliTracker::GetBz(xyz);
338 // if (!trackIn.PropagateTo(r[0],bz)) continue;
339 if (!AliTracker::PropagateTrackToBxByBz(&trackIn, r[0],mass,1.,kFALSE)) continue;
341 if (RejectCluster(cl,&trackIn)) continue;
343 trackIn.Update(&r[1],cov);
346 AliExternalTrackParam trackOut = trackIn;
347 trackOut.ResetCovariance(kResetCov);
348 trackOut.AddCovariance(covar);
349 if (TMath::Abs(magesd)<0.05) {
350 ((Double_t&)(trackOut.GetParameter()[4]))=0.000000001;
351 ((Double_t&)(trackOut.GetCovariance()[14]))=covar[14]; // fix the line
357 //Bool_t lastEdge=kFALSE;
358 for (Int_t irow=0; irow<160; irow++){
359 AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
361 if (cl->GetX()<80) continue;
362 Int_t sector = cl->GetDetector();
363 Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackOut.GetAlpha();
365 if (TMath::Abs(dalpha)>0.01){
366 if (!trackOut.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
368 Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
370 Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
371 AliTPCseed::GetError(cl, &trackOut,cov[0],cov[2]);
374 cov[0]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
375 cov[2]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
376 trackOut.GetXYZ(xyz);
377 //Double_t bz = AliTracker::GetBz(xyz);
378 // if (!trackOut.PropagateTo(r[0],bz)) continue;
379 if (!AliTracker::PropagateTrackToBxByBz(&trackOut, r[0],mass,1.,kFALSE)) continue;
381 if (RejectCluster(cl,&trackOut)) continue;
383 trackOut.Update(&r[1],cov);
384 //if (cl->GetType()<0) lastEdge=kTRUE;
385 //if (cl->GetType()>=0) lastEdge=kFALSE;
392 trackIn.ResetCovariance(kResetCov);
393 if (TMath::Abs(magesd)<0.05) {
394 ((Double_t&)(trackIn.GetParameter()[4]))=0.000000001;
395 ((Double_t&)(trackIn.GetCovariance()[14]))=covar[14]; // fix the line
398 // Refit in one more time
400 for (Int_t irow=159; irow>0; irow--){
401 AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
403 if (cl->GetX()<80) continue;
404 Int_t sector = cl->GetDetector();
405 Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackIn.GetAlpha();
406 if (TMath::Abs(dalpha)>0.01){
407 if (!trackIn.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
409 Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
410 Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
411 AliTPCseed::GetError(cl, &trackIn,cov[0],cov[2]);
414 cov[0]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
415 cov[2]+= kaFC*(TMath::Exp(-TMath::Abs(cl->GetX()-kxIFC)/ktFC)+TMath::Exp(-TMath::Abs(cl->GetX()-kxOFC)/ktFC));
418 //Double_t bz = AliTracker::GetBz(xyz);
420 // if (!trackIn.PropagateTo(r[0],bz)) continue;
421 if (!AliTracker::PropagateTrackToBxByBz(&trackIn, r[0],mass,1,kFALSE)) continue;
423 if (RejectCluster(cl,&trackIn)) continue;
425 trackIn.Update(&r[1],cov);
429 trackIn.Rotate(trackInOld->GetAlpha());
430 trackOut.Rotate(trackOutOld->GetAlpha());
432 trackInOld->GetXYZ(xyz);
433 Double_t bz = AliTracker::GetBz(xyz);
434 trackIn.PropagateTo(trackInOld->GetX(),bz);
436 trackOutOld->GetXYZ(xyz);
437 bz = AliTracker::GetBz(xyz);
438 trackOut.PropagateTo(trackOutOld->GetX(),bz);
441 if (fStreamLevel>0 && streamCounter<100*fStreamLevel){
442 TTreeSRedirector *cstream = GetDebugStreamer();
444 (*cstream)<<"Tracks"<<
445 "run="<<fRun<< // run number
446 "event="<<fEvent<< // event number
447 "time="<<fTime<< // time stamp of event
448 "trigger="<<fTrigger<< // trigger
449 "triggerClass="<<&fTriggerClass<< // trigger
450 "mag="<<fMagF<< // magnetic field
456 "TrIn0.="<<trackInOld<<
457 "TrOut0.="<<trackOutOld<<
458 "TrIn1.="<<&trackIn<<
459 "TrOut1.="<<&trackOut<<
464 // And now rewrite ESDtrack and TPC seed
467 (*trackInOld) = trackIn;
468 (*trackOutOld) = trackOut;
469 (*trackOuter) = trackOut;
470 AliExternalTrackParam *t = &trackIn;
471 //track->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
472 seed->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
473 seed->SetNumberOfClusters((nclIn+nclOut)/2);
479 Bool_t AliTPCcalibCalib::RejectCluster(AliTPCclusterMI* cl, AliExternalTrackParam * param){
481 // check the acceptance of cluster
482 // Cut on edge effects
484 if (!param) return kTRUE;
485 Float_t kEdgeCut=2.5;
488 Bool_t isReject = kFALSE;
489 Float_t edgeY = cl->GetX()*TMath::Tan(TMath::Pi()/18);
490 Float_t dist = edgeY - TMath::Abs(cl->GetY());
491 dist = TMath::Abs(edgeY - TMath::Abs(param->GetY()));
492 if (dist<kEdgeCut) isReject=kTRUE;
494 Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
495 AliTPCseed::GetError(cl, param,cov[0],cov[2]);
496 if (param->GetSigmaY2()<0 || param->GetSigmaZ2()<0){
497 AliError("Wrong parameters");
500 Double_t py = (cl->GetY()-param->GetY())/TMath::Sqrt(cov[0]*cov[0]+param->GetSigmaY2());
501 Double_t pz = (cl->GetZ()-param->GetZ())/TMath::Sqrt(cov[2]*cov[2]+param->GetSigmaZ2());
503 if ((py*py+pz*pz)>kSigmaCut*kSigmaCut) isReject=kTRUE;