]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TPC/AliTPCcalibCalib.cxx
Warning removal
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibCalib.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 //   Component for redoing the reconstruction from the clusters and tracks
20 //      
21 //   The new calibration data used 
22 //
23 //   In reality it overwrites the content of the ESD 
24 //    
25
26 /*
27
28   gSystem->Load("libANALYSIS");
29   gSystem->Load("libTPCcalib");
30   //
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);
35   chainCl->Lookup();
36   TChain * chainTr = tool.MakeChain("calib.txt","Tracks",0,1);
37   chainTr->Lookup();
38
39
40
41 */
42
43
44
45 //  marian.ivanov@cern.ch
46 // 
47 #include "AliTPCcalibCalib.h"
48 #include "TSystem.h"
49 #include "TFile.h"
50 #include "TTreeStream.h"
51 #include "AliLog.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"
59
60 #include "AliTPCcalibDB.h"
61 #include "AliTPCTransform.h"
62 #include "AliTPCRecoParam.h"
63 #include "AliTPCclusterMI.h"
64 #include "AliTPCseed.h"
65 #include "AliTPCPointCorrection.h"
66 #include <TGeoManager.h>
67 #include <TGeoPhysicalNode.h>
68 #include "TDatabasePDG.h"
69 ClassImp(AliTPCcalibCalib)
70
71 AliTPCcalibCalib::AliTPCcalibCalib():
72 AliTPCcalibBase(),
73   fApplyExBCorrection(1),      // apply ExB correction
74   fApplyTOFCorrection(1),      // apply TOF correction
75   fApplyPositionCorrection(1), // apply position correction
76   fApplySectorAlignment(1),    // apply sector alignment
77   fApplyRPhiCorrection(1),     // apply R-Phi correction
78   fApplyRCorrection(1)         // apply Radial correction
79
80 {
81   //
82   // Constructor
83   //
84 }
85
86
87 AliTPCcalibCalib::AliTPCcalibCalib(const Text_t *name, const Text_t *title) 
88   :AliTPCcalibBase(),
89   fApplyExBCorrection(1),      // apply ExB correction
90   fApplyTOFCorrection(1),      // apply TOF correction
91   fApplyPositionCorrection(1), // apply position correction
92   fApplySectorAlignment(1),    // apply sector alignment
93   fApplyRPhiCorrection(1),     // apply R-Phi correction
94   fApplyRCorrection(1)         // apply Radial correction
95 {  
96   SetName(name);
97   SetTitle(title);
98 }
99
100
101 AliTPCcalibCalib::AliTPCcalibCalib(const AliTPCcalibCalib&calib):
102   AliTPCcalibBase(calib),
103   fApplyExBCorrection(calib.GetApplyExBCorrection()),
104   fApplyTOFCorrection(calib.GetApplyTOFCorrection()),
105   fApplyPositionCorrection(calib.GetApplyPositionCorrection()),
106   fApplySectorAlignment(calib.GetApplySectorAlignment()),
107   fApplyRPhiCorrection(calib.GetApplyRPhiCorrection()),
108   fApplyRCorrection(calib.GetApplyRCorrection())
109
110 {
111   //
112   // copy constructor
113   //
114 }
115
116 AliTPCcalibCalib &AliTPCcalibCalib::operator=(const AliTPCcalibCalib&calib){
117   //
118   //
119   //
120   ((AliTPCcalibBase *)this)->operator=(calib);
121   return *this;
122 }
123
124
125 AliTPCcalibCalib::~AliTPCcalibCalib() {
126   //
127   // destructor
128   //
129 }
130
131
132 void     AliTPCcalibCalib::Process(AliESDEvent *event){
133   //
134   // 
135   //
136   if (!event) {
137     return;
138   }  
139   AliESDfriend *ESDfriend=static_cast<AliESDfriend*>(event->FindListObject("AliESDfriend"));
140   if (!ESDfriend) {
141    return;
142   }
143   
144   if (GetDebugLevel()>20) printf("Hallo world: Im here\n");
145   Int_t ntracks=event->GetNumberOfTracks();   
146   //AliTPCcalibDB::Instance()->SetExBField(fMagF);
147
148   //
149   //
150   //
151
152   for (Int_t i=0;i<ntracks;++i) {
153     AliESDtrack *track = event->GetTrack(i);     
154     AliESDfriendTrack *friendTrack = (AliESDfriendTrack*) ESDfriend->GetTrack(i);
155     if (!friendTrack) continue;
156     track->SetFriendTrack(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;
167     }
168     if (!seed) continue;
169     RefitTrack(track, seed, event->GetMagneticField());
170     (*tpcOut)=*(track->GetOuterParam());  
171   }
172   return;
173 }
174
175 Bool_t  AliTPCcalibCalib::RefitTrack(AliESDtrack * track, AliTPCseed *seed, Float_t magesd){
176   //
177   // Refit track
178   // if magesd==0 forget the curvature
179
180   //
181   // 0 - Setup transform object
182   //
183   AliESDfriendTrack *friendTrack = (AliESDfriendTrack *)track->GetFriendTrack();
184
185   AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
186   AliTPCParam     *param     = AliTPCcalibDB::Instance()->GetParameters();
187   transform->SetCurrentRun(fRun);
188   transform->SetCurrentTimeStamp((UInt_t)fTime);
189   if(!fApplyExBCorrection) { // disable ExB correction in transform
190     if(transform->GetCurrentRecoParam())
191       transform->GetCurrentRecoParamNonConst()->SetUseExBCorrection(0);
192   }
193   if(!fApplyTOFCorrection) { // disable TOF correction in transform
194     if(transform->GetCurrentRecoParam())
195       transform->GetCurrentRecoParamNonConst()->SetUseTOFCorrection(kFALSE);
196   }
197
198   //
199   // First apply calibration
200   //
201   //  AliTPCPointCorrection * corr =  AliTPCPointCorrection::Instance();
202   for (Int_t irow=0;irow<159;irow++) {
203     AliTPCclusterMI *cluster=seed->GetClusterPointer(irow);
204     if (!cluster) continue; 
205     AliTPCclusterMI cl0(*cluster);
206     Double_t x[3]={cluster->GetRow(),cluster->GetPad(),cluster->GetTimeBin()};
207     Int_t i[1]={cluster->GetDetector()};
208
209     transform->Transform(x,i,0,1);
210     //
211     // get position correction
212     //
213     Int_t ipad=0;
214     if (cluster->GetDetector()>35) ipad=1;
215     Float_t dy =0;//AliTPCClusterParam::SPosCorrection(0,ipad,cluster->GetPad(),cluster->GetTimeBin(),cluster->GetZ(),cluster->GetSigmaY2(),cluster->GetSigmaZ2(),cluster->GetMax());
216     Float_t dz =0;//AliTPCClusterParam::SPosCorrection(1,ipad,cluster->GetPad(),cluster->GetTimeBin(),cluster->GetZ(),cluster->GetSigmaY2(),cluster->GetSigmaZ2(),cluster->GetMax());
217     //
218     cluster->SetX(x[0]);
219     cluster->SetY(x[1]);
220     cluster->SetZ(x[2]);
221     
222     //
223     // Apply alignemnt
224     //
225     if (transform->GetCurrentRecoParam()->GetUseSectorAlignment()){
226       if (!param->IsGeoRead()) param->ReadGeoMatrices();
227       TGeoHMatrix  *mat = param->GetClusterMatrix(cluster->GetDetector());
228       //TGeoHMatrix  mat;
229       Double_t pos[3]= {cluster->GetX(),cluster->GetY(),cluster->GetZ()};
230       Double_t posC[3]={cluster->GetX(),cluster->GetY(),cluster->GetZ()};
231       if (mat) mat->LocalToMaster(pos,posC);
232       else{
233         // chack Loading of Geo matrices from GeoManager - TEMPORARY FIX
234       }
235       cluster->SetX(posC[0]);
236       cluster->SetY(posC[1]);
237       cluster->SetZ(posC[2]);
238     }
239
240
241
242     if (fStreamLevel>2){
243       TTreeSRedirector *cstream = GetDebugStreamer();
244       if (cstream){
245         (*cstream)<<"Clusters"<<
246           "run="<<fRun<<              //  run number
247           "event="<<fEvent<<          //  event number
248           "time="<<fTime<<            //  time stamp of event
249           "trigger="<<fTrigger<<      //  trigger
250           "triggerClass="<<&fTriggerClass<<      //  trigger      
251           "mag="<<fMagF<<             //  magnetic field
252           "cl0.="<<&cl0<<
253           "cl.="<<cluster<<
254           "cy="<<dy<<
255           "cz="<<dz<<
256           //      "cY="<<corrclY<<
257           //      "cR="<<corrR<<
258           "\n";
259       }
260     }
261   }
262   //
263   //
264   //
265   Int_t ncl = seed->GetNumberOfClusters();
266   const Double_t kResetCov=4.;
267   const Double_t kSigma=5.;
268   Double_t covar[15];
269   for (Int_t i=0;i<15;i++) covar[i]=0;
270   covar[0]=kSigma*kSigma;
271   covar[2]=kSigma*kSigma;
272   covar[5]=kSigma*kSigma/Float_t(ncl*ncl);
273   covar[9]=kSigma*kSigma/Float_t(ncl*ncl);
274   covar[14]=0.2*0.2;
275   if (TMath::Abs(magesd)<0.05) {
276      covar[14]=0.025*0.025;
277   }
278   // 
279   // And now do refit
280   //
281   AliExternalTrackParam * trackInOld  = (AliExternalTrackParam*)track->GetInnerParam();
282   AliExternalTrackParam * trackOuter = (AliExternalTrackParam*)track->GetOuterParam();
283   AliExternalTrackParam * trackOutOld   = (AliExternalTrackParam *)friendTrack->GetTPCOut();
284   Double_t mass =    TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
285
286     
287
288   AliExternalTrackParam trackIn  = *trackOutOld;
289   trackIn.ResetCovariance(kResetCov);
290   trackIn.AddCovariance(covar);
291   if (TMath::Abs(magesd)<0.05) {
292     ((Double_t&)(trackIn.GetParameter()[4]))=0.000000001;
293     ((Double_t&)(trackIn.GetCovariance()[14]))=covar[14];  // fix the line
294   }  
295
296   Double_t xyz[3];
297   Int_t nclIn=0,nclOut=0;
298   //
299   // Refit in
300   //
301   for (Int_t irow=159; irow>0; irow--){
302     AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
303     if (!cl) continue;
304     if (cl->GetX()<80) continue;
305     Int_t sector = cl->GetDetector();
306     Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackIn.GetAlpha();
307     if (TMath::Abs(dalpha)>0.01){
308       if (!trackIn.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
309     }
310     Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
311     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
312     AliTPCseed::GetError(cl, &trackIn,cov[0],cov[2]);
313     cov[0]*=cov[0];
314     cov[2]*=cov[2];
315     trackIn.GetXYZ(xyz);
316     //    Double_t bz = AliTracker::GetBz(xyz);
317
318     //    if (!trackIn.PropagateTo(r[0],bz)) continue;
319     if (!AliTracker::PropagateTrackToBxByBz(&trackIn, r[0],mass,1.,kFALSE)) continue;
320
321     if (RejectCluster(cl,&trackIn)) continue;
322     nclIn++;
323     trackIn.Update(&r[1],cov);    
324   }
325   //
326   AliExternalTrackParam trackOut = trackIn;
327   trackOut.ResetCovariance(kResetCov);
328   trackOut.AddCovariance(covar);
329   if (TMath::Abs(magesd)<0.05) {
330     ((Double_t&)(trackOut.GetParameter()[4]))=0.000000001;
331     ((Double_t&)(trackOut.GetCovariance()[14]))=covar[14];  // fix the line
332   }
333
334   //
335   // Refit out
336   //
337   //Bool_t lastEdge=kFALSE;
338   for (Int_t irow=0; irow<160; irow++){
339     AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
340     if (!cl) continue;
341     if (cl->GetX()<80) continue;
342     Int_t sector = cl->GetDetector();
343     Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackOut.GetAlpha();
344
345     if (TMath::Abs(dalpha)>0.01){
346       if (!trackOut.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
347     }
348     Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
349
350     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation    
351     AliTPCseed::GetError(cl, &trackOut,cov[0],cov[2]);
352     cov[0]*=cov[0];
353     cov[2]*=cov[2];
354     trackOut.GetXYZ(xyz);
355     //Double_t bz = AliTracker::GetBz(xyz);
356     //    if (!trackOut.PropagateTo(r[0],bz)) continue;
357     if (!AliTracker::PropagateTrackToBxByBz(&trackOut, r[0],mass,1.,kFALSE)) continue;
358
359     if (RejectCluster(cl,&trackOut)) continue;
360     nclOut++;
361     trackOut.Update(&r[1],cov);         
362     //if (cl->GetType()<0) lastEdge=kTRUE;
363     //if (cl->GetType()>=0) lastEdge=kFALSE;    
364   }
365   //
366   //
367   //
368   nclIn=0;
369   trackIn  = trackOut;
370   trackIn.ResetCovariance(kResetCov);
371   if (TMath::Abs(magesd)<0.05) {
372     ((Double_t&)(trackIn.GetParameter()[4]))=0.000000001;
373     ((Double_t&)(trackIn.GetCovariance()[14]))=covar[14];  // fix the line
374   }
375   //
376   // Refit in one more time
377   //
378   for (Int_t irow=159; irow>0; irow--){
379     AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
380     if (!cl) continue;
381     if (cl->GetX()<80) continue;
382     Int_t sector = cl->GetDetector();
383     Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackIn.GetAlpha();
384     if (TMath::Abs(dalpha)>0.01){
385       if (!trackIn.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
386     }
387     Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
388     Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation
389     AliTPCseed::GetError(cl, &trackIn,cov[0],cov[2]);
390     cov[0]*=cov[0];
391     cov[2]*=cov[2];
392     trackIn.GetXYZ(xyz);
393     //Double_t bz = AliTracker::GetBz(xyz);
394
395     //    if (!trackIn.PropagateTo(r[0],bz)) continue;
396     if (!AliTracker::PropagateTrackToBxByBz(&trackIn, r[0],mass,1,kFALSE)) continue;
397
398     if (RejectCluster(cl,&trackIn)) continue;
399     nclIn++;
400     trackIn.Update(&r[1],cov);    
401   }
402
403
404   trackIn.Rotate(trackInOld->GetAlpha());
405   trackOut.Rotate(trackOutOld->GetAlpha());
406   //
407   trackInOld->GetXYZ(xyz);
408   Double_t bz = AliTracker::GetBz(xyz);
409   trackIn.PropagateTo(trackInOld->GetX(),bz);
410   //
411   trackOutOld->GetXYZ(xyz);
412   bz = AliTracker::GetBz(xyz);  
413   trackOut.PropagateTo(trackOutOld->GetX(),bz);
414   
415
416   if (fStreamLevel>0){
417     TTreeSRedirector *cstream = GetDebugStreamer();
418     if (cstream){
419       (*cstream)<<"Tracks"<<
420         "run="<<fRun<<              //  run number
421         "event="<<fEvent<<          //  event number
422         "time="<<fTime<<            //  time stamp of event
423         "trigger="<<fTrigger<<      //  trigger
424         "triggerClass="<<&fTriggerClass<<      //  trigger
425         "mag="<<fMagF<<             //  magnetic field
426         "nclIn="<<nclIn<<
427         "nclOut="<<nclOut<<
428         "ncl="<<ncl<<
429         "TrIn0.="<<trackInOld<<
430         "TrOut0.="<<trackOutOld<<
431         "TrIn1.="<<&trackIn<<
432         "TrOut1.="<<&trackOut<<
433         "\n";
434     }
435   }
436   //
437   // And now rewrite ESDtrack and TPC seed
438   //
439  
440   (*trackInOld)  = trackIn;
441   (*trackOutOld) = trackOut;
442   (*trackOuter) = trackOut;
443   AliExternalTrackParam *t = &trackIn;
444   //track->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
445   seed->Set(t->GetX(),t->GetAlpha(),t->GetParameter(),t->GetCovariance());
446   seed->SetNumberOfClusters((nclIn+nclOut)/2);
447   return kTRUE;
448 }
449
450
451
452 Bool_t AliTPCcalibCalib::RejectCluster(AliTPCclusterMI* cl, AliExternalTrackParam * param){
453   //
454   // check the acceptance of cluster
455   // Cut on edge effects
456   //
457   Float_t kEdgeCut=2.5;
458   Float_t kSigmaCut=6;
459
460   Bool_t isReject = kFALSE;
461   Float_t edgeY = cl->GetX()*TMath::Tan(TMath::Pi()/18);
462   Float_t dist  = edgeY - TMath::Abs(cl->GetY());
463   if (param)  dist  = TMath::Abs(edgeY - TMath::Abs(param->GetY()));
464   if (dist<kEdgeCut) isReject=kTRUE;
465
466   Double_t cov[3]={0.01,0.,0.01}; //TODO: correct error parametrisation    
467   AliTPCseed::GetError(cl, param,cov[0],cov[2]);
468   if (param->GetSigmaY2()<0 || param->GetSigmaZ2()<0){
469     AliError("Wrong parameters");
470     return kFALSE;
471   }
472   Double_t py = (cl->GetY()-param->GetY())/TMath::Sqrt(cov[0]*cov[0]+param->GetSigmaY2());
473   Double_t pz = (cl->GetZ()-param->GetZ())/TMath::Sqrt(cov[2]*cov[2]+param->GetSigmaZ2());
474   //
475   if ((py*py+pz*pz)>kSigmaCut*kSigmaCut) isReject=kTRUE;
476   
477   return isReject;
478 }
479
480
481