coverity fix
[u/mrichter/AliRoot.git] / TPC / AliTPCcalibTime.cxx
CommitLineData
c74c5f6c 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/*
74235403 17Comments to be written here:
c74c5f6c 18
74235403 191. What do we calibrate.
20
21 Time dependence of gain and drift velocity in order to account for changes in: temperature, pressure, gas composition.
c74c5f6c 22
23 AliTPCcalibTime *calibTime = new AliTPCcalibTime("cosmicTime","cosmicTime",0, 1213.9e+06, 1213.96e+06, 0.04e+04, 0.04e+04);
24
c74c5f6c 25*/
26
c74c5f6c 27#include "Riostream.h"
2811495d 28#include "TDatabasePDG.h"
29#include "TGraphErrors.h"
c74c5f6c 30#include "TH1F.h"
c74c5f6c 31#include "THnSparse.h"
32#include "TList.h"
33#include "TMath.h"
2811495d 34#include "TTimeStamp.h"
35#include "TTree.h"
c74c5f6c 36#include "TVectorD.h"
2811495d 37//#include "TChain.h"
38//#include "TFile.h"
39
40#include "AliDCSSensor.h"
41#include "AliDCSSensorArray.h"
c74c5f6c 42#include "AliESDEvent.h"
c74c5f6c 43#include "AliESDInputHandler.h"
2811495d 44#include "AliESDVertex.h"
45#include "AliESDfriend.h"
c74c5f6c 46#include "AliLog.h"
817766d5 47#include "AliRelAlignerKalman.h"
2811495d 48#include "AliTPCCalROC.h"
49#include "AliTPCParam.h"
c74c5f6c 50#include "AliTPCTracklet.h"
da6c0bc9 51#include "AliTPCcalibDB.h"
52#include "AliTPCcalibLaser.h"
2811495d 53#include "AliTPCcalibTime.h"
54#include "AliTPCclusterMI.h"
55#include "AliTPCseed.h"
817766d5 56#include "AliTrackPointArray.h"
2811495d 57#include "AliTracker.h"
70036ef3 58#include "AliKFVertex.h"
660f0543 59#include <AliLog.h>
60
c74c5f6c 61ClassImp(AliTPCcalibTime)
62
63
64AliTPCcalibTime::AliTPCcalibTime()
660f0543 65 :AliTPCcalibBase(),
66 fMemoryMode(1), // 0 -do not fill THnSparse with residuals 1- fill only important QA THn 2 - Fill all THnsparse for calibration
da6c0bc9 67 fLaser(0), // pointer to laser calibration
68 fDz(0), // current delta z
d3ce44cb 69 fCutMaxD(3), // maximal distance in rfi ditection
70 fCutMaxDz(25), // maximal distance in rfi ditection
c74c5f6c 71 fCutTheta(0.03), // maximal distan theta
2be25cc9 72 fCutMinDir(-0.99), // direction vector products
b9ab8e40 73 fCutTracks(2500),
97d3fea0 74 fArrayLaserA(0), //laser fit parameters C
75 fArrayLaserC(0), //laser fit parameters A
dde68d36 76 fArrayDz(0), //NEW! Tmap of V drifts for different triggers
817766d5 77 fAlignITSTPC(0), //alignemnt array ITS TPC match
78 fAlignTRDTPC(0), //alignemnt array TRD TPC match
79 fAlignTOFTPC(0), //alignemnt array TOF TPC match
97d3fea0 80 fTimeKalmanBin(60*15), //time bin width for kalman - 15 minutes default
2be25cc9 81 fTimeBins(0),
82 fTimeStart(0),
83 fTimeEnd(0),
84 fPtBins(0),
85 fPtStart(0),
86 fPtEnd(0),
87 fVdriftBins(0),
88 fVdriftStart(0),
89 fVdriftEnd(0),
90 fRunBins(0),
91 fRunStart(0),
92 fRunEnd(0)
c74c5f6c 93{
6ba68367 94 //
95 // default constructor
96 //
c74c5f6c 97 AliInfo("Default Constructor");
2be25cc9 98 for (Int_t i=0;i<3;i++) {
99 fHistVdriftLaserA[i]=0;
100 fHistVdriftLaserC[i]=0;
101 }
d3ce44cb 102 for (Int_t i=0;i<10;i++) {
74235403 103 fCosmiMatchingHisto[i]=0;
104 }
391ffdb2 105 //
106 for (Int_t i=0;i<5;i++) {
b9908d0b 107 fResHistoTPCCE[i]=0;
391ffdb2 108 fResHistoTPCITS[i]=0;
109 fResHistoTPCTRD[i]=0;
0b736a46 110 fResHistoTPCTOF[i]=0;
391ffdb2 111 fResHistoTPCvertex[i]=0;
70036ef3 112 fTPCVertex[i]=0;
113 }
114 for (Int_t i=0;i<12;i++) {
115 fTPCVertex[i]=0;
391ffdb2 116 }
b1fea14f 117 for (Int_t i=0;i<5;i++) {
118 fTPCVertexCorrelation[i]=0;
119 }
660f0543 120 static Int_t counter=0;
121 if (1) {
122 TTimeStamp s;
123 Int_t time=s;
124 AliInfo(Form("Counter Constructor\t%d\t%d",counter,time));
125 counter++;
126 }
127
c74c5f6c 128}
129
660f0543 130AliTPCcalibTime::AliTPCcalibTime(const Text_t *name, const Text_t *title, UInt_t StartTime, UInt_t EndTime, Int_t deltaIntegrationTimeVdrift, Int_t memoryMode)
c74c5f6c 131 :AliTPCcalibBase(),
660f0543 132 fMemoryMode(memoryMode), // 0 -do not fill THnSparse with residuals 1- fill only important QA THn 2 - Fill all THnsparse for calibration
d3ce44cb 133 fLaser(0), // pointer to laser calibration
134 fDz(0), // current delta z
135 fCutMaxD(5*0.5356), // maximal distance in rfi ditection
dde68d36 136 fCutMaxDz(40), // maximal distance in rfi ditection
d3ce44cb 137 fCutTheta(5*0.004644),// maximal distan theta
138 fCutMinDir(-0.99), // direction vector products
b9ab8e40 139 fCutTracks(2500),
97d3fea0 140 fArrayLaserA(new TObjArray(1000)), //laser fit parameters C
141 fArrayLaserC(new TObjArray(1000)), //laser fit parameters A
dde68d36 142 fArrayDz(0), //Tmap of V drifts for different triggers
817766d5 143 fAlignITSTPC(0), //alignemnt array ITS TPC match
144 fAlignTRDTPC(0), //alignemnt array TRD TPC match
145 fAlignTOFTPC(0), //alignemnt array TOF TPC match
97d3fea0 146 fTimeKalmanBin(60*15), //time bin width for kalman - 15 minutes default
2be25cc9 147 fTimeBins(0),
148 fTimeStart(0),
149 fTimeEnd(0),
150 fPtBins(0),
151 fPtStart(0),
152 fPtEnd(0),
153 fVdriftBins(0),
154 fVdriftStart(0),
155 fVdriftEnd(0),
156 fRunBins(0),
157 fRunStart(0),
158 fRunEnd(0)
c74c5f6c 159{
6ba68367 160 //
161 // Non deafaul constructor - to be used in the Calibration setups
162 //
163
c74c5f6c 164 SetName(name);
165 SetTitle(title);
2be25cc9 166 for (Int_t i=0;i<3;i++) {
167 fHistVdriftLaserA[i]=0;
168 fHistVdriftLaserC[i]=0;
169 }
c74c5f6c 170
391ffdb2 171 for (Int_t i=0;i<5;i++) {
b9908d0b 172 fResHistoTPCCE[i]=0;
391ffdb2 173 fResHistoTPCITS[i]=0;
174 fResHistoTPCTRD[i]=0;
0b736a46 175 fResHistoTPCTOF[i]=0;
391ffdb2 176 fResHistoTPCvertex[i]=0;
177 }
178
179
c74c5f6c 180 AliInfo("Non Default Constructor");
74235403 181 fTimeBins =(EndTime-StartTime)/deltaIntegrationTimeVdrift;
2be25cc9 182 fTimeStart =StartTime; //(((TObjString*)(mapGRP->GetValue("fAliceStartTime")))->GetString()).Atoi();
183 fTimeEnd =EndTime; //(((TObjString*)(mapGRP->GetValue("fAliceStopTime")))->GetString()).Atoi();
dde68d36 184 fPtBins = 400;
2be25cc9 185 fPtStart = -0.04;
186 fPtEnd = 0.04;
dde68d36 187 fVdriftBins = 500;
188 fVdriftStart= -0.1;
189 fVdriftEnd = 0.1;
32100b1d 190 fRunBins = 1000001;
dde68d36 191 fRunStart = -1.5;
32100b1d 192 fRunEnd = 999999.5;
2be25cc9 193
194 Int_t binsVdriftLaser[4] = {fTimeBins , fPtBins , fVdriftBins*20, fRunBins };
195 Double_t xminVdriftLaser[4] = {fTimeStart, fPtStart, fVdriftStart , fRunStart};
196 Double_t xmaxVdriftLaser[4] = {fTimeEnd , fPtEnd , fVdriftEnd , fRunEnd };
dde68d36 197 TString axisTitle[4]={
198 "T",
199 "#delta_{P/T}",
200 "value",
201 "run"
202 };
203 TString histoName[3]={
204 "Loffset",
205 "Lcorr",
206 "Lgy"
207 };
2be25cc9 208
dde68d36 209
2be25cc9 210 for (Int_t i=0;i<3;i++) {
211 fHistVdriftLaserA[i] = new THnSparseF("HistVdriftLaser","HistVdriftLaser;time;p/T ratio;Vdrift;run",4,binsVdriftLaser,xminVdriftLaser,xmaxVdriftLaser);
212 fHistVdriftLaserC[i] = new THnSparseF("HistVdriftLaser","HistVdriftLaser;time;p/T ratio;Vdrift;run",4,binsVdriftLaser,xminVdriftLaser,xmaxVdriftLaser);
dde68d36 213 fHistVdriftLaserA[i]->SetName(histoName[i]);
214 fHistVdriftLaserC[i]->SetName(histoName[i]);
215 for (Int_t iaxis=0; iaxis<4;iaxis++){
216 fHistVdriftLaserA[i]->GetAxis(iaxis)->SetName(axisTitle[iaxis]);
217 fHistVdriftLaserC[i]->GetAxis(iaxis)->SetName(axisTitle[iaxis]);
218 }
2be25cc9 219 }
220 fBinsVdrift[0] = fTimeBins;
221 fBinsVdrift[1] = fPtBins;
222 fBinsVdrift[2] = fVdriftBins;
223 fBinsVdrift[3] = fRunBins;
224 fXminVdrift[0] = fTimeStart;
225 fXminVdrift[1] = fPtStart;
226 fXminVdrift[2] = fVdriftStart;
227 fXminVdrift[3] = fRunStart;
228 fXmaxVdrift[0] = fTimeEnd;
229 fXmaxVdrift[1] = fPtEnd;
230 fXmaxVdrift[2] = fVdriftEnd;
231 fXmaxVdrift[3] = fRunEnd;
232
dde68d36 233 fArrayDz=new TObjArray();
817766d5 234 fAlignITSTPC = new TObjArray; //alignemnt array ITS TPC match
235 fAlignTRDTPC = new TObjArray; //alignemnt array ITS TPC match
236 fAlignTOFTPC = new TObjArray; //alignemnt array ITS TPC match
3e55050f 237 fAlignITSTPC->SetOwner(kTRUE);
238 fAlignTRDTPC->SetOwner(kTRUE);
239 fAlignTOFTPC->SetOwner(kTRUE);
240
c74c5f6c 241
d3ce44cb 242 fCosmiMatchingHisto[0]=new TH1F("Cosmics matching","p0-all" ,100,-10*0.5356 ,10*0.5356 );
243 fCosmiMatchingHisto[1]=new TH1F("Cosmics matching","p1-all" ,100,-10*4.541 ,10*4.541 );
244 fCosmiMatchingHisto[2]=new TH1F("Cosmics matching","p2-all" ,100,-10*0.01134 ,10*0.01134 );
245 fCosmiMatchingHisto[3]=new TH1F("Cosmics matching","p3-all" ,100,-10*0.004644,10*0.004644);
246 fCosmiMatchingHisto[4]=new TH1F("Cosmics matching","p4-all" ,100,-10*0.03773 ,10*0.03773 );
247 fCosmiMatchingHisto[5]=new TH1F("Cosmics matching","p0-isPair",100,-10*0.5356 ,10*0.5356 );
248 fCosmiMatchingHisto[6]=new TH1F("Cosmics matching","p1-isPair",100,-10*4.541 ,10*4.541 );
249 fCosmiMatchingHisto[7]=new TH1F("Cosmics matching","p2-isPair",100,-10*0.01134 ,10*0.01134 );
250 fCosmiMatchingHisto[8]=new TH1F("Cosmics matching","p3-isPair",100,-10*0.004644,10*0.004644);
251 fCosmiMatchingHisto[9]=new TH1F("Cosmics matching","p4-isPair",100,-10*0.03773 ,10*0.03773 );
70036ef3 252 for (Int_t i=0;i<12;i++) {
253 fTPCVertex[i]=0;
254 }
b1fea14f 255 for (Int_t i=0;i<5;i++) {
256 fTPCVertexCorrelation[i]=0;
257 }
391ffdb2 258 BookDistortionMaps();
70036ef3 259
74235403 260}
c74c5f6c 261
262AliTPCcalibTime::~AliTPCcalibTime(){
263 //
6ba68367 264 // Virtual Destructor
c74c5f6c 265 //
660f0543 266 static Int_t counter=0;
267 if (1) {
268 TTimeStamp s;
269 Int_t time=s;
270 AliInfo(Form("Counter Destructor\t%s\t%d\t%d",GetName(),counter,time));
271 counter++;
272 }
d3ce44cb 273 for(Int_t i=0;i<3;i++){
274 if(fHistVdriftLaserA[i]){
275 delete fHistVdriftLaserA[i];
276 fHistVdriftLaserA[i]=NULL;
277 }
278 if(fHistVdriftLaserC[i]){
279 delete fHistVdriftLaserC[i];
280 fHistVdriftLaserC[i]=NULL;
281 }
282 }
dde68d36 283 if(fArrayDz){
284 fArrayDz->SetOwner();
285 fArrayDz->Delete();
286 delete fArrayDz;
287 fArrayDz=NULL;
2be25cc9 288 }
d3ce44cb 289 for(Int_t i=0;i<5;i++){
290 if(fCosmiMatchingHisto[i]){
291 delete fCosmiMatchingHisto[i];
292 fCosmiMatchingHisto[i]=NULL;
293 }
74235403 294 }
391ffdb2 295
296 for (Int_t i=0;i<5;i++) {
b9908d0b 297 delete fResHistoTPCCE[i];
391ffdb2 298 delete fResHistoTPCITS[i];
299 delete fResHistoTPCTRD[i];
0b736a46 300 delete fResHistoTPCTOF[i];
391ffdb2 301 delete fResHistoTPCvertex[i];
b9908d0b 302 fResHistoTPCCE[i]=0;
391ffdb2 303 fResHistoTPCITS[i]=0;
304 fResHistoTPCTRD[i]=0;
0b736a46 305 fResHistoTPCTOF[i]=0;
391ffdb2 306 fResHistoTPCvertex[i]=0;
307 }
308
472f0066 309 if (fTPCVertex[0]) {
70036ef3 310 for (Int_t i=0;i<12;i++) delete fTPCVertex[i];
311 }
472f0066 312 if (fTPCVertexCorrelation[0]) {
b1fea14f 313 for (Int_t i=0;i<5;i++) delete fTPCVertexCorrelation[i];
314 }
3e55050f 315
8951e9f5 316 if (fAlignITSTPC){
317 fAlignITSTPC->SetOwner(kTRUE);
318 fAlignTRDTPC->SetOwner(kTRUE);
319 fAlignTOFTPC->SetOwner(kTRUE);
320
321 fAlignITSTPC->Delete();
322 fAlignTRDTPC->Delete();
323 fAlignTOFTPC->Delete();
324 delete fAlignITSTPC;
325 delete fAlignTRDTPC;
326 delete fAlignTOFTPC;
327 }
c74c5f6c 328}
2be25cc9 329
9170f0f0 330// Bool_t AliTPCcalibTime::IsLaser(const AliESDEvent *const /*event*/) const{
331// //
332// // Indicator is laser event not yet implemented - to be done using trigger info or event specie
333// //
334// return kTRUE; //More accurate creteria to be added
335// }
336// Bool_t AliTPCcalibTime::IsCosmics(const AliESDEvent *const /*event*/){
337// //
338// // Indicator is cosmic event not yet implemented - to be done using trigger info or event specie
339// //
340
341// return kTRUE; //More accurate creteria to be added
342// }
343// Bool_t AliTPCcalibTime::IsBeam(const AliESDEvent *const /*event*/) const{
344// //
345// // Indicator is physic event not yet implemented - to be done using trigger info or event specie
346// //
347
348// return kTRUE; //More accurate creteria to be added
349// }
350void AliTPCcalibTime::ResetCurrent(){
6ba68367 351 //
9170f0f0 352 //ResetCurrent
6ba68367 353 //
dde68d36 354 fDz=0; //Reset current dz
2be25cc9 355}
6ba68367 356
357
358
2be25cc9 359void AliTPCcalibTime::Process(AliESDEvent *event){
6ba68367 360 //
361 // main function to make calibration
362 //
2be25cc9 363 if(!event) return;
55d90f9a 364 if (event->GetNumberOfTracks()<2) return;
365 AliESDfriend *ESDfriend=static_cast<AliESDfriend*>(event->FindListObject("AliESDfriend"));
366 if (!ESDfriend) {
367 return;
368 }
369 if (ESDfriend->TestSkipBit()) return;
370
2be25cc9 371 ResetCurrent();
9170f0f0 372 //if(IsLaser (event))
373 ProcessLaser (event);
374 //if(IsCosmics(event))
375 ProcessCosmic(event);
376 //if(IsBeam (event))
377 ProcessBeam (event);
2be25cc9 378}
379
380void AliTPCcalibTime::ProcessLaser(AliESDEvent *event){
c74c5f6c 381 //
2be25cc9 382 // Fit drift velocity using laser
383 //
384 // 0. cuts
dde68d36 385 const Int_t kMinTracks = 40; // minimal number of laser tracks
386 const Int_t kMinTracksSide = 20; // minimal number of tracks per side
387 const Float_t kMaxDeltaZ = 30.; // maximal trigger delay
388 const Float_t kMaxDeltaV = 0.05; // maximal deltaV
2be25cc9 389 const Float_t kMaxRMS = 0.1; // maximal RMS of tracks
dde68d36 390 //
2be25cc9 391 /*
392 TCut cutRMS("sqrt(laserA.fElements[4])<0.1&&sqrt(laserC.fElements[4])<0.1");
393 TCut cutZ("abs(laserA.fElements[0]-laserC.fElements[0])<3");
394 TCut cutV("abs(laserA.fElements[1]-laserC.fElements[1])<0.01");
395 TCut cutY("abs(laserA.fElements[2]-laserC.fElements[2])<2");
396 TCut cutAll = cutRMS+cutZ+cutV+cutY;
397 */
398 if (event->GetNumberOfTracks()<kMinTracks) return;
c74c5f6c 399 //
2be25cc9 400 if(!fLaser) fLaser = new AliTPCcalibLaser("laserTPC","laserTPC",kFALSE);
401 fLaser->Process(event);
402 if (fLaser->GetNtracks()<kMinTracks) return; // small amount of tracks cut
dde68d36 403 if (fLaser->fFitAside->GetNrows()==0 && fLaser->fFitCside->GetNrows()==0) return; // no fit neither a or C side
c74c5f6c 404 //
2be25cc9 405 // debug streamer - activate stream level
406 // Use it for tuning of the cuts
da6c0bc9 407 //
dde68d36 408 // cuts to be applied
409 //
410 Int_t isReject[2]={0,0};
411 //
412 // not enough tracks
413 if (TMath::Abs((*fLaser->fFitAside)[3]) < kMinTracksSide) isReject[0]|=1;
414 if (TMath::Abs((*fLaser->fFitCside)[3]) < kMinTracksSide) isReject[1]|=1;
415 // unreasonable z offset
416 if (TMath::Abs((*fLaser->fFitAside)[0])>kMaxDeltaZ) isReject[0]|=2;
417 if (TMath::Abs((*fLaser->fFitCside)[0])>kMaxDeltaZ) isReject[1]|=2;
418 // unreasonable drift velocity
419 if (TMath::Abs((*fLaser->fFitAside)[1]-1)>kMaxDeltaV) isReject[0]|=4;
420 if (TMath::Abs((*fLaser->fFitCside)[1]-1)>kMaxDeltaV) isReject[1]|=4;
421 // big chi2
422 if (TMath::Sqrt(TMath::Abs((*fLaser->fFitAside)[4]))>kMaxRMS ) isReject[0]|=8;
423 if (TMath::Sqrt(TMath::Abs((*fLaser->fFitCside)[4]))>kMaxRMS ) isReject[1]|=8;
424
425
426
427
2be25cc9 428 if (fStreamLevel>0){
429 printf("Trigger: %s\n",event->GetFiredTriggerClasses().Data());
430
da6c0bc9 431 TTreeSRedirector *cstream = GetDebugStreamer();
432 if (cstream){
433 TTimeStamp tstamp(fTime);
2be25cc9 434 (*cstream)<<"laserInfo"<<
da6c0bc9 435 "run="<<fRun<< // run number
436 "event="<<fEvent<< // event number
437 "time="<<fTime<< // time stamp of event
438 "trigger="<<fTrigger<< // trigger
439 "mag="<<fMagF<< // magnetic field
da6c0bc9 440 //laser
dde68d36 441 "rejectA="<<isReject[0]<<
442 "rejectC="<<isReject[1]<<
2be25cc9 443 "laserA.="<<fLaser->fFitAside<<
444 "laserC.="<<fLaser->fFitCside<<
445 "laserAC.="<<fLaser->fFitACside<<
446 "trigger="<<event->GetFiredTriggerClasses()<<
da6c0bc9 447 "\n";
448 }
449 }
2be25cc9 450 //
2be25cc9 451 // fill histos
452 //
012c4694 453 TVectorD vdriftA(5), vdriftC(5),vdriftAC(6);
2be25cc9 454 vdriftA=*(fLaser->fFitAside);
455 vdriftC=*(fLaser->fFitCside);
456 vdriftAC=*(fLaser->fFitACside);
457 Int_t npointsA=0, npointsC=0;
458 Float_t chi2A=0, chi2C=0;
459 npointsA= TMath::Nint(vdriftA[3]);
460 chi2A= vdriftA[4];
461 npointsC= TMath::Nint(vdriftC[3]);
462 chi2C= vdriftC[4];
2be25cc9 463
97d3fea0 464 if (npointsA>kMinTracksSide || npointsC>kMinTracksSide){
465 TVectorD *fitA = new TVectorD(6);
466 TVectorD *fitC = new TVectorD(6);
467 for (Int_t ipar=0; ipar<5; ipar++){
468 (*fitA)[ipar]=vdriftA[ipar];
469 (*fitC)[ipar]=vdriftC[ipar];
470 }
471 (*fitA)[5]=fTime;
472 (*fitC)[5]=fTime;
473 fArrayLaserA->AddLast(fitA);
474 fArrayLaserC->AddLast(fitC);
475 }
476 //
477
2be25cc9 478 TTimeStamp tstamp(fTime);
479 Double_t ptrelative0 = AliTPCcalibDB::GetPTRelative(tstamp,fRun,0);
480 Double_t ptrelative1 = AliTPCcalibDB::GetPTRelative(tstamp,fRun,1);
dde68d36 481 Double_t driftA=0, driftC=0;
482 if (vdriftA[1]>1.-kMaxDeltaV) driftA = 1./vdriftA[1]-1.;
483 if (vdriftC[1]>1.-kMaxDeltaV) driftC = 1./vdriftC[1]-1.;
484 //
485 Double_t vecDriftLaserA[4]={fTime,(ptrelative0+ptrelative1)/2.0,driftA,event->GetRunNumber()};
486 Double_t vecDriftLaserC[4]={fTime,(ptrelative0+ptrelative1)/2.0,driftC,event->GetRunNumber()};
487 // Double_t vecDrift[4] ={fTime,(ptrelative0+ptrelative1)/2.0,1./((*(fLaser->fFitACside))[1])-1,event->GetRunNumber()};
488
489 for (Int_t icalib=0;icalib<3;icalib++){
490 if (icalib==0){ //z0 shift
491 vecDriftLaserA[2]=vdriftA[0]/250.;
492 vecDriftLaserC[2]=vdriftC[0]/250.;
2be25cc9 493 }
dde68d36 494 if (icalib==1){ //vdrel shift
495 vecDriftLaserA[2]=driftA;
496 vecDriftLaserC[2]=driftC;
2be25cc9 497 }
dde68d36 498 if (icalib==2){ //gy shift - full gy - full drift
499 vecDriftLaserA[2]=vdriftA[2]/250.;
500 vecDriftLaserC[2]=vdriftC[2]/250.;
2be25cc9 501 }
391ffdb2 502 //if (isReject[0]==0) fHistVdriftLaserA[icalib]->Fill(vecDriftLaserA);
503 //if (isReject[1]==0) fHistVdriftLaserC[icalib]->Fill(vecDriftLaserC);
504 fHistVdriftLaserA[icalib]->Fill(vecDriftLaserA);
505 fHistVdriftLaserC[icalib]->Fill(vecDriftLaserC);
2be25cc9 506 }
2be25cc9 507}
c74c5f6c 508
2811495d 509void AliTPCcalibTime::ProcessCosmic(const AliESDEvent *const event){
6ba68367 510 //
511 // process Cosmic event - track matching A side C side
512 //
c74c5f6c 513 if (!event) {
514 Printf("ERROR: ESD not available");
515 return;
516 }
517 if (event->GetTimeStamp() == 0 ) {
518 Printf("no time stamp!");
519 return;
520 }
74235403 521
2be25cc9 522 //fd
c74c5f6c 523 // Find cosmic pairs
524 //
525 // Track0 is choosen in upper TPC part
526 // Track1 is choosen in lower TPC part
527 //
cc65e4f5 528 const Int_t kMinClustersCross =30;
529 const Int_t kMinClusters =80;
c74c5f6c 530 Int_t ntracks=event->GetNumberOfTracks();
531 if (ntracks==0) return;
74235403 532 if (ntracks > fCutTracks) return;
533
a390f11f 534 if (GetDebugLevel()>20) printf("Hallo world: Im here\n");
3e0d9569 535 AliESDfriend *esdFriend=(AliESDfriend*)(((AliESDEvent*)event)->FindListObject("AliESDfriend"));
c74c5f6c 536
537 TObjArray tpcSeeds(ntracks);
538 Double_t vtxx[3]={0,0,0};
539 Double_t svtxx[3]={0.000001,0.000001,100.};
540 AliESDVertex vtx(vtxx,svtxx);
541 //
542 // track loop
543 //
cc65e4f5 544 TArrayI clusterSideA(ntracks);
545 TArrayI clusterSideC(ntracks);
c74c5f6c 546 for (Int_t i=0;i<ntracks;++i) {
cc65e4f5 547 clusterSideA[i]=0;
548 clusterSideC[i]=0;
74235403 549 AliESDtrack *track = event->GetTrack(i);
550
551 const AliExternalTrackParam * trackIn = track->GetInnerParam();
552 const AliExternalTrackParam * trackOut = track->GetOuterParam();
553 if (!trackIn) continue;
554 if (!trackOut) continue;
555
6ba68367 556 AliESDfriendTrack *friendTrack = esdFriend->GetTrack(i);
b1c27e4f 557 if (!friendTrack) continue;
3e55050f 558 if (friendTrack) ProcessSame(track,friendTrack,event);
6ba68367 559 if (friendTrack) ProcessAlignITS(track,friendTrack,event,esdFriend);
0dac7b3a 560 if (friendTrack) ProcessAlignTRD(track,friendTrack);
817766d5 561 if (friendTrack) ProcessAlignTOF(track,friendTrack);
74235403 562 TObject *calibObject;
563 AliTPCseed *seed = 0;
564 for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
cc65e4f5 565 if (seed) {
566 tpcSeeds.AddAt(seed,i);
567 Int_t nA=0, nC=0;
568 for (Int_t irow=159;irow>0;irow--) {
569 AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
570 if (!cl) continue;
571 if ((cl->GetDetector()%36)<18) nA++;
572 if ((cl->GetDetector()%36)>=18) nC++;
573 }
574 clusterSideA[i]=nA;
575 clusterSideC[i]=nC;
576 }
c74c5f6c 577 }
c74c5f6c 578 if (ntracks<2) return;
579 //
580 // Find pairs
581 //
d3ce44cb 582
c74c5f6c 583 for (Int_t i=0;i<ntracks;++i) {
74235403 584 AliESDtrack *track0 = event->GetTrack(i);
c74c5f6c 585 // track0 - choosen upper part
586 if (!track0) continue;
587 if (!track0->GetOuterParam()) continue;
588 if (track0->GetOuterParam()->GetAlpha()<0) continue;
589 Double_t d1[3];
590 track0->GetDirection(d1);
591 for (Int_t j=0;j<ntracks;++j) {
592 if (i==j) continue;
74235403 593 AliESDtrack *track1 = event->GetTrack(j);
594 //track 1 lower part
595 if (!track1) continue;
596 if (!track1->GetOuterParam()) continue;
cc65e4f5 597 if (track0->GetTPCNcls()+ track1->GetTPCNcls()< kMinClusters) continue;
598 Int_t nAC = TMath::Max( TMath::Min(clusterSideA[i], clusterSideC[j]),
599 TMath::Min(clusterSideC[i], clusterSideA[j]));
600 if (nAC<kMinClustersCross) continue;
601 Int_t nA0=clusterSideA[i];
602 Int_t nC0=clusterSideC[i];
603 Int_t nA1=clusterSideA[j];
604 Int_t nC1=clusterSideC[j];
3e55050f 605 // if (track1->GetOuterParam()->GetAlpha()>0) continue;
74235403 606 //
607 Double_t d2[3];
608 track1->GetDirection(d2);
609
610 AliTPCseed * seed0 = (AliTPCseed*) tpcSeeds.At(i);
611 AliTPCseed * seed1 = (AliTPCseed*) tpcSeeds.At(j);
612 if (! seed0) continue;
613 if (! seed1) continue;
614 Float_t dir = (d1[0]*d2[0] + d1[1]*d2[1] + d1[2]*d2[2]);
615 Float_t dist0 = track0->GetLinearD(0,0);
616 Float_t dist1 = track1->GetLinearD(0,0);
617 //
618 // conservative cuts - convergence to be guarantied
619 // applying before track propagation
3e55050f 620 if (TMath::Abs(TMath::Abs(dist0)-TMath::Abs(dist1))>fCutMaxD) continue; // distance to the 0,0
621 if (TMath::Abs(dir)<TMath::Abs(fCutMinDir)) continue; // direction vector product
74235403 622 Float_t bz = AliTracker::GetBz();
623 Float_t dvertex0[2]; //distance to 0,0
624 Float_t dvertex1[2]; //distance to 0,0
625 track0->GetDZ(0,0,0,bz,dvertex0);
626 track1->GetDZ(0,0,0,bz,dvertex1);
627 if (TMath::Abs(dvertex0[1])>250) continue;
628 if (TMath::Abs(dvertex1[1])>250) continue;
629 //
630 //
631 //
632 Float_t dmax = TMath::Max(TMath::Abs(dist0),TMath::Abs(dist1));
633 AliExternalTrackParam param0(*track0);
634 AliExternalTrackParam param1(*track1);
635 //
636 // Propagate using Magnetic field and correct fo material budget
637 //
9963b5e2 638 AliTracker::PropagateTrackTo(&param0,dmax+1,TDatabasePDG::Instance()->GetParticle("e-")->Mass(),3,kTRUE);
639 AliTracker::PropagateTrackTo(&param1,dmax+1,TDatabasePDG::Instance()->GetParticle("e-")->Mass(),3,kTRUE);
74235403 640 //
641 // Propagate rest to the 0,0 DCA - z should be ignored
642 //
643 //Bool_t b0 = ;
644 param0.PropagateToDCA(&vtx,bz,1000);
645 //Bool_t b1 =
646 param1.PropagateToDCA(&vtx,bz,1000);
74235403 647 param0.GetDZ(0,0,0,bz,dvertex0);
648 param1.GetDZ(0,0,0,bz,dvertex1);
dde68d36 649 Double_t xyz0[3];
650 Double_t xyz1[3];
74235403 651 param0.GetXYZ(xyz0);
652 param1.GetXYZ(xyz1);
653 Bool_t isPair = IsPair(&param0,&param1);
d3ce44cb 654 Bool_t isCross = IsCross(track0, track1);
dde68d36 655 Bool_t isSame = IsSame(track0, track1);
d3ce44cb 656
dde68d36 657 THnSparse* hist=new THnSparseF("","HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
658 TString shortName=hist->ClassName();
659 shortName+="_MEAN_VDRIFT_COSMICS_";
660 delete hist;
661 hist=NULL;
662
3e55050f 663 if((isSame) || (isCross && isPair)){
664 if (track0->GetTPCNcls()+ track1->GetTPCNcls()> 80) {
74235403 665 fDz = param0.GetZ() - param1.GetZ();
cc65e4f5 666 Double_t sign=(nA0>nA1)? 1:-1;
667 fDz*=sign;
74235403 668 TTimeStamp tstamp(fTime);
669 Double_t ptrelative0 = AliTPCcalibDB::GetPTRelative(tstamp,fRun,0);
670 Double_t ptrelative1 = AliTPCcalibDB::GetPTRelative(tstamp,fRun,1);
dde68d36 671 Double_t vecDrift[4]={fTime,(ptrelative0+ptrelative1)/2.0,fDz/500.0,event->GetRunNumber()};
672 THnSparse* curHist=NULL;
673 TString name="";
674
675 name=shortName;
676 name+=event->GetFiredTriggerClasses();
677 name.ToUpper();
678 curHist=(THnSparseF*)fArrayDz->FindObject(name);
74235403 679 if(!curHist){
dde68d36 680 curHist=new THnSparseF(name,"HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
681 fArrayDz->AddLast(curHist);
74235403 682 }
dde68d36 683// curHist=(THnSparseF*)(fMapDz->GetValue(event->GetFiredTriggerClasses()));
684// if(!curHist){
685// curHist=new THnSparseF(event->GetFiredTriggerClasses(),"HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
686// fMapDz->Add(new TObjString(event->GetFiredTriggerClasses()),curHist);
687// }
688 curHist->Fill(vecDrift);
74235403 689
dde68d36 690 name=shortName;
691 name+="ALL";
692 name.ToUpper();
693 curHist=(THnSparseF*)fArrayDz->FindObject(name);
74235403 694 if(!curHist){
dde68d36 695 curHist=new THnSparseF(name,"HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
696 fArrayDz->AddLast(curHist);
74235403 697 }
dde68d36 698// curHist=(THnSparseF*)(fMapDz->GetValue("all"));
699// if(!curHist){
700// curHist=new THnSparseF("all","HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
701// fMapDz->Add(new TObjString("all"),curHist);
702// }
703 curHist->Fill(vecDrift);
74235403 704 }
705 }
d3ce44cb 706 TTreeSRedirector *cstream = GetDebugStreamer();
707 if (fStreamLevel>0){
708 if (cstream){
709 (*cstream)<<"trackInfo"<<
710 "tr0.="<<track0<<
711 "tr1.="<<track1<<
712 "p0.="<<&param0<<
713 "p1.="<<&param1<<
cc65e4f5 714 "nAC="<<nAC<<
715 "nA0="<<nA0<<
716 "nA1="<<nA1<<
717 "nC0="<<nC0<<
718 "nC1="<<nC1<<
d3ce44cb 719 "isPair="<<isPair<<
720 "isCross="<<isCross<<
dde68d36 721 "isSame="<<isSame<<
d3ce44cb 722 "fDz="<<fDz<<
723 "fRun="<<fRun<<
724 "fTime="<<fTime<<
725 "\n";
726 }
727 }
c74c5f6c 728 } // end 2nd order loop
729 } // end 1st order loop
74235403 730
2be25cc9 731 if (fStreamLevel>0){
732 TTreeSRedirector *cstream = GetDebugStreamer();
733 if (cstream){
2be25cc9 734 (*cstream)<<"timeInfo"<<
735 "run="<<fRun<< // run number
736 "event="<<fEvent<< // event number
737 "time="<<fTime<< // time stamp of event
738 "trigger="<<fTrigger<< // trigger
739 "mag="<<fMagF<< // magnetic field
740 // Environment values
2be25cc9 741 //
742 // accumulated values
743 //
744 "fDz="<<fDz<< //! current delta z
2be25cc9 745 "trigger="<<event->GetFiredTriggerClasses()<<
746 "\n";
747 }
748 }
a390f11f 749 if (GetDebugLevel()>20) printf("Trigger: %s\n",event->GetFiredTriggerClasses().Data());
c74c5f6c 750}
751
70036ef3 752void AliTPCcalibTime::ProcessBeam(const AliESDEvent *const event){
753 //
e0ef0ad7 754 // Process beam data - calculates vartex
755 // from A side and C side
756 // Histogram the differences
70036ef3 757 //
758 const Int_t kMinClusters =80;
b1fea14f 759 const Int_t kMinTracks =2; // minimal number of tracks to define the vertex
760 const Int_t kMinTracksVertex=30; // minimal number of tracks to define the cumulative vertex
70036ef3 761 const Double_t kMaxTgl =1.2; // maximal Tgl (z angle)
b1fea14f 762 const Double_t kMinPt =0.2; // minimal pt
763 const Double_t kMaxD0 =5.; // cut on distance to the primary vertex first guess
70036ef3 764 const Double_t kMaxZ0 =20;
b1fea14f 765 const Double_t kMaxD =2.5; // cut on distance to the primary vertex
766 const Double_t kMaxZ =4; // maximal z distance between tracks form the same side
767 const Double_t kMaxChi2 =15; // maximal chi2 of the TPCvertex
768 const Double_t kCumulCovarXY=0.003; //increase the error of cumul vertex 30 microns profile
769 const Double_t kCumulCovarZ=250.; //increase the error of cumul vertex
770 const Double_t kMaxDvertex = 1.0; // cut to accept the vertex;
771 //
772 Int_t flags=0;
773 const Int_t kBuffSize=100;
774 static Double_t deltaZ[kBuffSize]={0};
775 static Int_t counterZ=0;
776 static AliKFVertex cumulVertexA, cumulVertexC, cumulVertexAC; // cumulative vertex
777 AliKFVertex vertexA, vertexC;
70036ef3 778
779 Float_t dca0[2]={0,0};
780 Double_t dcaVertex[2]={0,0};
70036ef3 781 Int_t ntracks=event->GetNumberOfTracks();
782 if (ntracks==0) return;
012c4694 783 if (ntracks > fCutTracks) return;
70036ef3 784 //
785 AliESDfriend *esdFriend=(AliESDfriend*)(((AliESDEvent*)event)->FindListObject("AliESDfriend"));
786 //
787 // Divide tracks to A and C side tracks - using the cluster indexes
788 TObjArray tracksA(ntracks);
789 TObjArray tracksC(ntracks);
6ba68367 790 //
70036ef3 791 AliESDVertex *vertexSPD = (AliESDVertex *)event->GetPrimaryVertexSPD();
792 AliESDVertex *vertex = (AliESDVertex *)event->GetPrimaryVertex();
793 AliESDVertex *vertexTracks = (AliESDVertex *)event->GetPrimaryVertexTracks();
794 Double_t vertexZA[10000], vertexZC[10000];
6ba68367 795 //
70036ef3 796 Int_t ntracksA= 0;
797 Int_t ntracksC= 0;
798 //
799 for (Int_t itrack=0;itrack<ntracks;itrack++) {
800 AliESDtrack *track = event->GetTrack(itrack);
801 AliESDfriendTrack *friendTrack = esdFriend->GetTrack(itrack);
802 if (!friendTrack) continue;
803 if (TMath::Abs(track->GetTgl())>kMaxTgl) continue;
804 if (TMath::Abs(track->Pt())<kMinPt) continue;
805 const AliExternalTrackParam * trackIn = track->GetInnerParam();
806 TObject *calibObject=0;
807 AliTPCseed *seed = 0;
808 Int_t nA=0, nC=0;
809 for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
810 if (seed) {
811 for (Int_t irow=159;irow>0;irow--) {
812 AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
813 if (!cl) continue;
814 if ((cl->GetDetector()%36)<18) nA++;
815 if ((cl->GetDetector()%36)>=18) nC++;
816 }
817 if ((nA>kMinClusters || nC>kMinClusters) && (nA*nC==0) ){
818 track->GetImpactParameters(dca0[0],dca0[1]);
819 if (TMath::Abs(dca0[0])>kMaxD0) continue;
820 if (TMath::Abs(dca0[1])>kMaxZ0) continue;
821 AliExternalTrackParam pTPCvertex(*trackIn);
822 if (!AliTracker::PropagateTrackToBxByBz(&pTPCvertex,4.+4.*TMath::Abs(dca0[0]),0.1,2,kTRUE)) continue;
823 pTPCvertex.PropagateToDCA(vertex,AliTracker::GetBz(), kMaxD, dcaVertex,0);
824 if (TMath::Abs(dcaVertex[0])>kMaxD) continue;
825 if (nA>kMinClusters &&nC==0) { tracksA.AddLast(pTPCvertex.Clone()); vertexZA[ntracksA++] = pTPCvertex.GetZ();}
826 if (nC>kMinClusters &&nA==0) {tracksC.AddLast(pTPCvertex.Clone()); vertexZC[ntracksC++] = pTPCvertex.GetZ();}
827 }
828 }
829 }
b1fea14f 830 Double_t medianZA=TMath::Median(ntracksA, vertexZA); // tracks median
831 Double_t medianZC=TMath::Median(ntracksC, vertexZC); // tracks median
70036ef3 832 //
833 ntracksA= tracksA.GetEntriesFast();
834 ntracksC= tracksC.GetEntriesFast();
835 if (ntracksA>kMinTracks && ntracksC>kMinTracks){
b1fea14f 836 deltaZ[counterZ%kBuffSize]=medianZA-medianZC;
70036ef3 837 counterZ+=1;
b1fea14f 838 Double_t medianDelta=(counterZ>=kBuffSize)? TMath::Median(kBuffSize, deltaZ): TMath::Median(counterZ, deltaZ);
70036ef3 839 if (TMath::Abs(medianDelta-(medianZA-medianZC))>kMaxZ) flags+=16;
840 // increse the error of cumulative vertex at the beginning of event
841 cumulVertexA.Covariance(0,0)+=kCumulCovarXY*kCumulCovarXY;
842 cumulVertexA.Covariance(1,1)+=kCumulCovarXY*kCumulCovarXY;
843 cumulVertexA.Covariance(2,2)+=kCumulCovarZ*kCumulCovarZ;
844 cumulVertexC.Covariance(0,0)+=kCumulCovarXY*kCumulCovarXY;
845 cumulVertexC.Covariance(1,1)+=kCumulCovarXY*kCumulCovarXY;
846 cumulVertexC.Covariance(2,2)+=kCumulCovarZ*kCumulCovarZ;
847 cumulVertexAC.Covariance(0,0)+=kCumulCovarXY*kCumulCovarXY;
848 cumulVertexAC.Covariance(1,1)+=kCumulCovarXY*kCumulCovarXY;
849 cumulVertexAC.Covariance(2,2)+=kCumulCovarZ*kCumulCovarZ;
850 //
851 for (Int_t iA=0; iA<ntracksA; iA++){
852 if (flags!=0) continue;
853 AliExternalTrackParam *aliTrack = (AliExternalTrackParam *)tracksA.At(iA);
854 if (TMath::Abs(aliTrack->GetZ()-medianZA)>kMaxZ) continue;
855 AliKFParticle part(*aliTrack,211);
856 vertexA+=part;
70036ef3 857 }
858 for (Int_t iC=0; iC<ntracksC; iC++){
859 if (flags!=0) continue;
860 AliExternalTrackParam *aliTrack = (AliExternalTrackParam *)tracksC.At(iC);
861 if (TMath::Abs(aliTrack->GetZ()-medianZC)>kMaxZ) continue;
862 AliKFParticle part(*aliTrack,211);
863 vertexC+=part;
70036ef3 864 }
b1fea14f 865 //
70036ef3 866 if (vertexA.GetNDF()<kMinTracks) flags+=32;
867 if (vertexC.GetNDF()<kMinTracks) flags+=32;
868 if (TMath::Abs(vertexA.Z()-medianZA)>kMaxZ) flags+=1; //apply cuts
869 if (TMath::Abs(vertexC.Z()-medianZC)>kMaxZ) flags+=2;
870 if (TMath::Abs(vertexA.GetChi2()/vertexA.GetNDF()+vertexC.GetChi2()/vertexC.GetNDF())> kMaxChi2) flags+=4;
b1fea14f 871 //
872 if (flags==0){
873 for (Int_t iA=0; iA<ntracksA; iA++){
874 if (flags!=0) continue;
875 AliExternalTrackParam *aliTrack = (AliExternalTrackParam *)tracksA.At(iA);
876 if (TMath::Abs(aliTrack->GetZ()-medianZA)>kMaxZ) continue;
877 AliKFParticle part(*aliTrack,211);
878 cumulVertexA+=part;
879 cumulVertexAC+=part;
880 }
881 for (Int_t iC=0; iC<ntracksC; iC++){
882 if (flags!=0) continue;
883 AliExternalTrackParam *aliTrack = (AliExternalTrackParam *)tracksC.At(iC);
884 if (TMath::Abs(aliTrack->GetZ()-medianZC)>kMaxZ) continue;
885 AliKFParticle part(*aliTrack,211);
886 cumulVertexC+=part;
887 cumulVertexAC+=part;
888 }
70036ef3 889 //
b1fea14f 890 if (TMath::Abs(cumulVertexA.X()-vertexA.X())>kMaxDvertex) flags+=64;
891 if (TMath::Abs(cumulVertexA.Y()-vertexA.Y())>kMaxDvertex) flags+=64;
892 if (TMath::Abs(cumulVertexA.Z()-vertexA.Z())>kMaxDvertex) flags+=64;
70036ef3 893 //
b1fea14f 894 if (TMath::Abs(cumulVertexC.X()-vertexC.X())>kMaxDvertex) flags+=64;
895 if (TMath::Abs(cumulVertexC.Y()-vertexC.Y())>kMaxDvertex) flags+=64;
896 if (TMath::Abs(cumulVertexC.Z()-vertexC.Z())>kMaxDvertex) flags+=64;
897
898
899 if ( flags==0 && cumulVertexC.GetNDF()>kMinTracksVertex&&cumulVertexA.GetNDF()>kMinTracksVertex){
900 Double_t cont[2]={0,fTime};
901 //
902 cont[0]= cumulVertexA.X();
903 fTPCVertex[0]->Fill(cont);
904 cont[0]= cumulVertexC.X();
905 fTPCVertex[1]->Fill(cont);
906 cont[0]= 0.5*(cumulVertexA.X()-cumulVertexC.X());
907 fTPCVertex[2]->Fill(cont);
908 cont[0]= 0.5*(cumulVertexA.X()+cumulVertexC.X())-vertexSPD->GetX();
909 fTPCVertex[3]->Fill(cont);
910 //
911 cont[0]= cumulVertexA.Y();
912 fTPCVertex[4]->Fill(cont);
913 cont[0]= cumulVertexC.Y();
914 fTPCVertex[5]->Fill(cont);
915 cont[0]= 0.5*(cumulVertexA.Y()-cumulVertexC.Y());
916 fTPCVertex[6]->Fill(cont);
917 cont[0]= 0.5*(cumulVertexA.Y()+cumulVertexC.Y())-vertexSPD->GetY();
918 fTPCVertex[7]->Fill(cont);
919 //
920 //
921 cont[0]= 0.5*(cumulVertexA.Z()+cumulVertexC.Z());
922 fTPCVertex[8]->Fill(cont);
923 cont[0]= 0.5*(cumulVertexA.Z()-cumulVertexC.Z());
924 fTPCVertex[9]->Fill(cont);
925 cont[0]= 0.5*(cumulVertexA.Z()-cumulVertexC.Z());
926 fTPCVertex[10]->Fill(cont);
927 cont[0]= 0.5*(cumulVertexA.Z()+cumulVertexC.Z())-vertexSPD->GetZ();
928 fTPCVertex[11]->Fill(cont);
929 //
930 Double_t correl[2]={0,0};
931 //
932 correl[0]=cumulVertexC.Z();
933 correl[1]=cumulVertexA.Z();
934 fTPCVertexCorrelation[0]->Fill(correl); // fill A side :TPC
935 correl[0]=cumulVertexA.Z();
936 correl[1]=cumulVertexC.Z();
937 fTPCVertexCorrelation[1]->Fill(correl); // fill C side :TPC
938 //
939 correl[0]=vertexSPD->GetZ();
940 correl[1]=cumulVertexA.Z()-correl[0];
941 fTPCVertexCorrelation[2]->Fill(correl); // fill A side :ITS
942 correl[1]=cumulVertexC.Z()-correl[0];
943 fTPCVertexCorrelation[3]->Fill(correl); // fill C side :ITS
944 correl[1]=0.5*(cumulVertexA.Z()+cumulVertexC.Z())-correl[0];
945 fTPCVertexCorrelation[4]->Fill(correl); // fill C side :ITS
946 }
947 }
70036ef3 948 TTreeSRedirector *cstream = GetDebugStreamer();
949 if (cstream){
950 /*
951 TCut cutChi2= "sqrt(vA.fChi2/vA.fNDF+vC.fChi2/vC.fNDF)<10"; // chi2 Cut e.g 10
952 TCut cutXY= "sqrt((vA.fP[0]-vC.fP[0])^2+(vA.fP[0]-vC.fP[1])^2)<5"; // vertex Cut
953 TCut cutZ= "abs(vA.fP[2]-mZA)<3&&abs(vC.fP[2]-mZC)<5"; // vertex Cut
954 tree->Draw("sqrt(vA.fChi2/vA.fNDF)","sqrt(vA.fChi2/vA.fNDF)<100","")
955
956 */
660f0543 957 //vertexA.Print();
958 //vertexC.Print();
70036ef3 959 (*cstream)<<"vertexTPC"<<
960 "flags="<<flags<< // rejection flags
961 "vSPD.="<<vertexSPD<< // SPD vertex
962 "vT.="<<vertexTracks<< // track vertex
963 "v.="<<vertex<< // esd vertex
964 "mZA="<<medianZA<< // median Z position at vertex A side
965 "mZC="<<medianZC<< // median Z position at vertex C side
966 "mDelta="<<medianDelta<< // median delta A side -C side
967 "counter="<<counterZ<< // counter Z
968 //
969 "vA.="<<&vertexA<< // vertex A side
970 "vC.="<<&vertexC<< // vertex C side
971 "cvA.="<<&cumulVertexA<< // cumulative vertex A side
972 "cvC.="<<&cumulVertexC<< // cumulative vertex C side
973 "cvAC.="<<&cumulVertexAC<< // cumulative vertex A+C side
974 "nA="<<ntracksA<< // contributors
975 "nC="<<ntracksC<< // contributors
976 "\n";
977 }
978 }
979 tracksA.Delete();
980 tracksC.Delete();
dde68d36 981}
982
6ba68367 983void AliTPCcalibTime::Analyze(){
984 //
985 // Special macro to analyze result of calibration and extract calibration entries
986 // Not yet ported to the Analyze function yet
987 //
988}
74235403 989
2811495d 990THnSparse* AliTPCcalibTime::GetHistoDrift(const char* name) const
991{
6ba68367 992 //
993 // Get histogram for given trigger mask
994 //
dde68d36 995 TIterator* iterator = fArrayDz->MakeIterator();
996 iterator->Reset();
997 TString newName=name;
998 newName.ToUpper();
999 THnSparse* newHist=new THnSparseF(newName,"HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
1000 THnSparse* addHist=NULL;
1001 while((addHist=(THnSparseF*)iterator->Next())){
472f0066 1002 // if(!addHist) continue;
dde68d36 1003 TString histName=addHist->GetName();
1004 if(!histName.Contains(newName)) continue;
1005 addHist->Print();
1006 newHist->Add(addHist);
74235403 1007 }
dde68d36 1008 return newHist;
74235403 1009}
1010
2811495d 1011TObjArray* AliTPCcalibTime::GetHistoDrift() const
1012{
6ba68367 1013 //
1014 // return array of histograms
1015 //
dde68d36 1016 return fArrayDz;
74235403 1017}
1018
1019TGraphErrors* AliTPCcalibTime::GetGraphDrift(const char* name){
6ba68367 1020 //
1021 // Make a drift velocity (delta Z) graph
1022 //
dde68d36 1023 THnSparse* histoDrift=GetHistoDrift(name);
1024 TGraphErrors* graphDrift=NULL;
1025 if(histoDrift){
1026 graphDrift=FitSlices(histoDrift,2,0,400,100,0.05,0.95, kTRUE);
1027 TString end=histoDrift->GetName();
1028 Int_t pos=end.Index("_");
1029 end=end(pos,end.Capacity()-pos);
1030 TString graphName=graphDrift->ClassName();
1031 graphName+=end;
1032 graphName.ToUpper();
1033 graphDrift->SetName(graphName);
74235403 1034 }
1035 return graphDrift;
1036}
1037
dde68d36 1038TObjArray* AliTPCcalibTime::GetGraphDrift(){
6ba68367 1039 //
1040 // make a array of drift graphs
1041 //
dde68d36 1042 TObjArray* arrayGraphDrift=new TObjArray();
1043 TIterator* iterator=fArrayDz->MakeIterator();
74235403 1044 iterator->Reset();
dde68d36 1045 THnSparse* addHist=NULL;
1046 while((addHist=(THnSparseF*)iterator->Next())) arrayGraphDrift->AddLast(GetGraphDrift(addHist->GetName()));
1047 return arrayGraphDrift;
74235403 1048}
1049
dde68d36 1050AliSplineFit* AliTPCcalibTime::GetFitDrift(const char* name){
6ba68367 1051 //
1052 // Make a fit AliSplinefit of drift velocity
1053 //
d3ce44cb 1054 TGraph* graphDrift=GetGraphDrift(name);
dde68d36 1055 AliSplineFit* fitDrift=NULL;
74235403 1056 if(graphDrift && graphDrift->GetN()){
dde68d36 1057 fitDrift=new AliSplineFit();
1058 fitDrift->SetGraph(graphDrift);
1059 fitDrift->SetMinPoints(graphDrift->GetN()+1);
1060 fitDrift->InitKnots(graphDrift,2,0,0.001);
1061 fitDrift->SplineFit(0);
1062 TString end=graphDrift->GetName();
1063 Int_t pos=end.Index("_");
1064 end=end(pos,end.Capacity()-pos);
1065 TString fitName=fitDrift->ClassName();
1066 fitName+=end;
1067 fitName.ToUpper();
1068 //fitDrift->SetName(fitName);
74235403 1069 delete graphDrift;
dde68d36 1070 graphDrift=NULL;
74235403 1071 }
1072 return fitDrift;
1073}
1074
74235403 1075
2811495d 1076Long64_t AliTPCcalibTime::Merge(TCollection *const li) {
6ba68367 1077 //
1078 // Object specific merging procedure
1079 //
c74c5f6c 1080 TIterator* iter = li->MakeIterator();
1081 AliTPCcalibTime* cal = 0;
660f0543 1082 //
c74c5f6c 1083 while ((cal = (AliTPCcalibTime*)iter->Next())) {
1084 if (!cal->InheritsFrom(AliTPCcalibTime::Class())) {
1085 Error("Merge","Attempt to add object of class %s to a %s", cal->ClassName(), this->ClassName());
1086 return -1;
1087 }
2be25cc9 1088 for (Int_t imeas=0; imeas<3; imeas++){
1089 if (cal->GetHistVdriftLaserA(imeas) && cal->GetHistVdriftLaserA(imeas)){
1090 fHistVdriftLaserA[imeas]->Add(cal->GetHistVdriftLaserA(imeas));
1091 fHistVdriftLaserC[imeas]->Add(cal->GetHistVdriftLaserC(imeas));
1092 }
1093 }
9112627b 1094 //
55d90f9a 1095 if (fTPCVertexCorrelation[0] && cal->fTPCVertexCorrelation[0]){
b1fea14f 1096 for (Int_t imeas=0; imeas<5; imeas++){
1097 if (fTPCVertexCorrelation[imeas] && cal->fTPCVertexCorrelation[imeas]) fTPCVertexCorrelation[imeas]->Add(cal->fTPCVertexCorrelation[imeas]);
1098 }
1099 }
1100
472f0066 1101 if (fTPCVertex[0] && cal->fTPCVertex[0])
70036ef3 1102 for (Int_t imeas=0; imeas<12; imeas++){
660f0543 1103 if (fTPCVertex[imeas] && cal->fTPCVertex[imeas]) fTPCVertex[imeas]->Add(cal->fTPCVertex[imeas]);
70036ef3 1104 }
1105
660f0543 1106 if (fMemoryMode>0) for (Int_t imeas=0; imeas<5; imeas++){
1107 if (fMemoryMode>1){
1108 if ( cal->GetResHistoTPCCE(imeas) && cal->GetResHistoTPCCE(imeas)){
1109 fResHistoTPCCE[imeas]->Add(cal->fResHistoTPCCE[imeas]);
1110 }else{
1111 fResHistoTPCCE[imeas]=(THnSparse*)cal->fResHistoTPCCE[imeas]->Clone();
1112 }
b9908d0b 1113 }
660f0543 1114 //
1115 if ((fMemoryMode>0) &&cal->GetResHistoTPCITS(imeas) && cal->GetResHistoTPCITS(imeas)){
1116 if (fMemoryMode>1 || (imeas%2)==1) fResHistoTPCITS[imeas]->Add(cal->fResHistoTPCITS[imeas]);
1117 if (fMemoryMode>1) fResHistoTPCvertex[imeas]->Add(cal->fResHistoTPCvertex[imeas]);
33fc6b9e 1118 }
660f0543 1119 //
1120 if ((fMemoryMode>1) && cal->fResHistoTPCTRD[imeas]){
33fc6b9e 1121 if (fResHistoTPCTRD[imeas])
1122 fResHistoTPCTRD[imeas]->Add(cal->fResHistoTPCTRD[imeas]);
1123 else
1124 fResHistoTPCTRD[imeas]=(THnSparse*)cal->fResHistoTPCTRD[imeas]->Clone();
1125 }
660f0543 1126 //
1127 if ((fMemoryMode>1) && cal->fResHistoTPCTOF[imeas]){
33fc6b9e 1128 if (fResHistoTPCTOF[imeas])
1129 fResHistoTPCTOF[imeas]->Add(cal->fResHistoTPCTOF[imeas]);
1130 else
1131 fResHistoTPCTOF[imeas]=(THnSparse*)cal->fResHistoTPCTOF[imeas]->Clone();
9112627b 1132 }
660f0543 1133 //
97d3fea0 1134 if (cal->fArrayLaserA){
1135 fArrayLaserA->Expand(fArrayLaserA->GetEntriesFast()+cal->fArrayLaserA->GetEntriesFast());
1136 fArrayLaserC->Expand(fArrayLaserC->GetEntriesFast()+cal->fArrayLaserC->GetEntriesFast());
1137 for (Int_t ical=0; ical<cal->fArrayLaserA->GetEntriesFast(); ical++){
1138 if (cal->fArrayLaserA->UncheckedAt(ical)) fArrayLaserA->AddLast(cal->fArrayLaserA->UncheckedAt(ical)->Clone());
1139 if (cal->fArrayLaserC->UncheckedAt(ical)) fArrayLaserC->AddLast(cal->fArrayLaserC->UncheckedAt(ical)->Clone());
1140 }
1141 }
1142
9112627b 1143 }
dde68d36 1144 TObjArray* addArray=cal->GetHistoDrift();
1145 if(!addArray) return 0;
1146 TIterator* iterator = addArray->MakeIterator();
2be25cc9 1147 iterator->Reset();
dde68d36 1148 THnSparse* addHist=NULL;
660f0543 1149 if ((fMemoryMode>1)) while((addHist=(THnSparseF*)iterator->Next())){
472f0066 1150 // if(!addHist) continue;
2be25cc9 1151 addHist->Print();
dde68d36 1152 THnSparse* localHist=(THnSparseF*)fArrayDz->FindObject(addHist->GetName());
2be25cc9 1153 if(!localHist){
1154 localHist=new THnSparseF(addHist->GetName(),"HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
dde68d36 1155 fArrayDz->AddLast(localHist);
2be25cc9 1156 }
1157 localHist->Add(addHist);
1158 }
391ffdb2 1159
d3ce44cb 1160 for(Int_t i=0;i<10;i++) if (cal->GetCosmiMatchingHisto(i)) fCosmiMatchingHisto[i]->Add(cal->GetCosmiMatchingHisto(i));
3e55050f 1161 //
1162 // Merge alignment
1163 //
ab24faca 1164 const Int_t kMinUpdates=10;
1165 const Float_t kMaxOut=0.1;
3e55050f 1166 for (Int_t itype=0; itype<3; itype++){
1167 //
1168 //
1169 TObjArray *arr0= 0;
1170 TObjArray *arr1= 0;
1171 if (itype==0) {arr0=fAlignITSTPC; arr1=cal->fAlignITSTPC;}
1172 if (itype==1) {arr0=fAlignTRDTPC; arr1=cal->fAlignTRDTPC;}
1173 if (itype==2) {arr0=fAlignTOFTPC; arr1=cal->fAlignTOFTPC;}
1174 if (!arr1) continue;
1175 if (!arr0) arr0=new TObjArray(arr1->GetEntriesFast());
1176 if (arr1->GetEntriesFast()>arr0->GetEntriesFast()){
1177 arr0->Expand(arr1->GetEntriesFast());
1178 }
1179 for (Int_t i=0;i<arr1->GetEntriesFast(); i++){
1180 AliRelAlignerKalman *kalman1 = (AliRelAlignerKalman *)arr1->UncheckedAt(i);
1181 AliRelAlignerKalman *kalman0 = (AliRelAlignerKalman *)arr0->UncheckedAt(i);
1182 if (!kalman1) continue;
ab24faca 1183 if (kalman1->GetNUpdates()<kMinUpdates) continue;
1184 if (kalman1->GetNOutliers()>(kalman1->GetNUpdates()*kMaxOut)) continue;
3e55050f 1185 if (!kalman0) {arr0->AddAt(new AliRelAlignerKalman(*kalman1),i); continue;}
1186 kalman0->SetRejectOutliers(kFALSE);
1187 kalman0->Merge(kalman1);
1188 }
1189 }
1190
c74c5f6c 1191 }
c74c5f6c 1192 return 0;
c74c5f6c 1193}
1194
e0ef0ad7 1195Bool_t AliTPCcalibTime::IsPair(const AliExternalTrackParam *tr0, const AliExternalTrackParam *tr1){
c74c5f6c 1196 /*
1197 // 0. Same direction - OPOSITE - cutDir +cutT
1198 TCut cutDir("cutDir","dir<-0.99")
1199 // 1.
1200 TCut cutT("cutT","abs(Tr1.fP[3]+Tr0.fP[3])<0.03")
1201 //
1202 // 2. The same rphi
1203 TCut cutD("cutD","abs(Tr0.fP[0]+Tr1.fP[0])<5")
1204 //
c74c5f6c 1205 TCut cutPt("cutPt","abs(Tr1.fP[4]+Tr0.fP[4])<1&&abs(Tr0.fP[4])+abs(Tr1.fP[4])<10");
1206 // 1/Pt diff cut
1207 */
1208 const Double_t *p0 = tr0->GetParameter();
1209 const Double_t *p1 = tr1->GetParameter();
74235403 1210 fCosmiMatchingHisto[0]->Fill(p0[0]+p1[0]);
1211 fCosmiMatchingHisto[1]->Fill(p0[1]-p1[1]);
d3ce44cb 1212 fCosmiMatchingHisto[2]->Fill(tr1->GetAlpha()-tr0->GetAlpha()+TMath::Pi());
74235403 1213 fCosmiMatchingHisto[3]->Fill(p0[3]+p1[3]);
1214 fCosmiMatchingHisto[4]->Fill(p0[4]+p1[4]);
1215
c74c5f6c 1216 if (TMath::Abs(p0[3]+p1[3])>fCutTheta) return kFALSE;
1217 if (TMath::Abs(p0[0]+p1[0])>fCutMaxD) return kFALSE;
da6c0bc9 1218 if (TMath::Abs(p0[1]-p1[1])>fCutMaxDz) return kFALSE;
c74c5f6c 1219 Double_t d0[3], d1[3];
1220 tr0->GetDirection(d0);
1221 tr1->GetDirection(d1);
1222 if (d0[0]*d1[0] + d0[1]*d1[1] + d0[2]*d1[2] >fCutMinDir) return kFALSE;
74235403 1223
d3ce44cb 1224 fCosmiMatchingHisto[5]->Fill(p0[0]+p1[0]);
1225 fCosmiMatchingHisto[6]->Fill(p0[1]-p1[1]);
1226 fCosmiMatchingHisto[7]->Fill(tr1->GetAlpha()-tr0->GetAlpha()+TMath::Pi());
1227 fCosmiMatchingHisto[8]->Fill(p0[3]+p1[3]);
1228 fCosmiMatchingHisto[9]->Fill(p0[4]+p1[4]);
1229
c74c5f6c 1230 return kTRUE;
1231}
e0ef0ad7 1232Bool_t AliTPCcalibTime::IsCross(const AliESDtrack *const tr0, const AliESDtrack *const tr1){
cc65e4f5 1233 //
1234 // check if the cosmic pair of tracks crossed A/C side
1235 //
1236 Bool_t result= tr0->GetOuterParam()->GetZ()*tr1->GetOuterParam()->GetZ()<0;
1237 if (result==kFALSE) return result;
1238 result=kTRUE;
1239 return result;
d3ce44cb 1240}
1241
e0ef0ad7 1242Bool_t AliTPCcalibTime::IsSame(const AliESDtrack *const tr0, const AliESDtrack *const tr1){
3e55050f 1243 //
1244 // track crossing the CE
1245 // 0. minimal number of clusters
1246 // 1. Same sector +-1
1247 // 2. Inner and outer track param on opposite side
1248 // 3. Outer and inner track parameter close each to other
1249 // 3.
1250 Bool_t result=kTRUE;
1251 //
1252 // inner and outer on opposite sides in z
1253 //
1254 const Int_t knclCut0 = 30;
1255 const Double_t kalphaCut = 0.4;
1256 //
1257 // 0. minimal number of clusters
1258 //
1259 if (tr0->GetTPCNcls()<knclCut0) return kFALSE;
1260 if (tr1->GetTPCNcls()<knclCut0) return kFALSE;
1261 //
1262 // 1. alpha cut - sector+-1
1263 //
1264 if (TMath::Abs(tr0->GetOuterParam()->GetAlpha()-tr1->GetOuterParam()->GetAlpha())>kalphaCut) return kFALSE;
1265 //
1266 // 2. Z crossing
1267 //
1268 if (tr0->GetOuterParam()->GetZ()*tr0->GetInnerParam()->GetZ()>0) result&=kFALSE;
1269 if (tr1->GetOuterParam()->GetZ()*tr1->GetInnerParam()->GetZ()>0) result&=kFALSE;
1270 if (result==kFALSE){
1271 return result;
1272 }
1273 //
1274 //
1275 const Double_t *p0I = tr0->GetInnerParam()->GetParameter();
1276 const Double_t *p1I = tr1->GetInnerParam()->GetParameter();
1277 const Double_t *p0O = tr0->GetOuterParam()->GetParameter();
1278 const Double_t *p1O = tr1->GetOuterParam()->GetParameter();
1279 //
1280 if (TMath::Abs(p0I[0]-p1I[0])>fCutMaxD) result&=kFALSE;
1281 if (TMath::Abs(p0I[1]-p1I[1])>fCutMaxDz) result&=kFALSE;
1282 if (TMath::Abs(p0I[2]-p1I[2])>fCutTheta) result&=kFALSE;
1283 if (TMath::Abs(p0I[3]-p1I[3])>fCutTheta) result&=kFALSE;
1284 if (TMath::Abs(p0O[0]-p1O[0])>fCutMaxD) result&=kFALSE;
1285 if (TMath::Abs(p0O[1]-p1O[1])>fCutMaxDz) result&=kFALSE;
1286 if (TMath::Abs(p0O[2]-p1O[2])>fCutTheta) result&=kFALSE;
1287 if (TMath::Abs(p0O[3]-p1O[3])>fCutTheta) result&=kFALSE;
1288 if (result==kTRUE){
1289 result=kTRUE; // just to put break point here
1290 }
1291 return result;
dde68d36 1292}
1293
31aa7c5c 1294
e0ef0ad7 1295void AliTPCcalibTime::ProcessSame(const AliESDtrack *const track, AliESDfriendTrack *const friendTrack, const AliESDEvent *const event){
3e55050f 1296 //
1297 // Process TPC tracks crossing CE
1298 //
1299 // 0. Select only track crossing the CE
1300 // 1. Cut on the track length
b9908d0b 1301 // 2. Refit the the track on A and C side separatelly
3e55050f 1302 // 3. Fill time histograms
1303 const Int_t kMinNcl=100;
1304 const Int_t kMinNclS=25; // minimul number of clusters on the sides
b9908d0b 1305 const Double_t pimass=TDatabasePDG::Instance()->GetParticle("pi+")->Mass();
1306 const Double_t kMaxDy=1; // maximal distance in y
1307 const Double_t kMaxDsnp=0.05; // maximal distance in snp
1308 const Double_t kMaxDtheta=0.05; // maximal distance in theta
1309
3e55050f 1310 if (!friendTrack->GetTPCOut()) return;
1311 //
1312 // 0. Select only track crossing the CE
1313 //
1314 if (track->GetInnerParam()->GetZ()*friendTrack->GetTPCOut()->GetZ()>0) return;
1315 //
1316 // 1. cut on track length
1317 //
1318 if (track->GetTPCNcls()<kMinNcl) return;
1319 //
1320 // 2. Refit track sepparatel on A and C side
1321 //
1322 TObject *calibObject;
1323 AliTPCseed *seed = 0;
1324 for (Int_t l=0;(calibObject=friendTrack->GetCalibObject(l));++l) {
1325 if ((seed=dynamic_cast<AliTPCseed*>(calibObject))) break;
1326 }
1327 if (!seed) return;
1328 //
1329 AliExternalTrackParam trackIn(*track->GetInnerParam());
1330 AliExternalTrackParam trackOut(*track->GetOuterParam());
1331 Double_t cov[3]={0.01,0.,0.01}; //use the same errors
1332 Double_t xyz[3]={0,0.,0.0};
1333 Double_t bz =0;
1334 Int_t nclIn=0,nclOut=0;
70036ef3 1335 trackIn.ResetCovariance(1000.);
1336 trackOut.ResetCovariance(1000.);
3e55050f 1337 //
1338 //2.a Refit inner
1339 //
b9908d0b 1340 Int_t sideIn=0;
3e55050f 1341 for (Int_t irow=0;irow<159;irow++) {
1342 AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
1343 if (!cl) continue;
1344 if (cl->GetX()<80) continue;
b9908d0b 1345 if (sideIn==0){
1346 if (cl->GetDetector()%36<18) sideIn=1;
1347 if (cl->GetDetector()%36>=18) sideIn=-1;
1348 }
1349 if (sideIn== -1 && (cl->GetDetector()%36)<18) break;
1350 if (sideIn== 1 &&(cl->GetDetector()%36)>=18) break;
3e55050f 1351 Int_t sector = cl->GetDetector();
1352 Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackIn.GetAlpha();
1353 if (TMath::Abs(dalpha)>0.01){
1354 if (!trackIn.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
1355 }
1356 Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
1357 trackIn.GetXYZ(xyz);
1358 bz = AliTracker::GetBz(xyz);
8951e9f5 1359 AliTracker::PropagateTrackToBxByBz(&trackIn,r[0],pimass,1.,kFALSE);
3e55050f 1360 if (!trackIn.PropagateTo(r[0],bz)) break;
1361 nclIn++;
1362 trackIn.Update(&r[1],cov);
1363 }
1364 //
1365 //2.b Refit outer
b9908d0b 1366 //
1367 Int_t sideOut=0;
3e55050f 1368 for (Int_t irow=159;irow>0;irow--) {
1369 AliTPCclusterMI *cl=seed->GetClusterPointer(irow);
1370 if (!cl) continue;
1371 if (cl->GetX()<80) continue;
b9908d0b 1372 if (sideOut==0){
1373 if (cl->GetDetector()%36<18) sideOut=1;
1374 if (cl->GetDetector()%36>=18) sideOut=-1;
1375 if (sideIn==sideOut) break;
1376 }
1377 if (sideOut== -1 && (cl->GetDetector()%36)<18) break;
1378 if (sideOut== 1 &&(cl->GetDetector()%36)>=18) break;
1379 //
3e55050f 1380 Int_t sector = cl->GetDetector();
1381 Float_t dalpha = TMath::DegToRad()*(sector%18*20.+10.)-trackOut.GetAlpha();
1382 if (TMath::Abs(dalpha)>0.01){
1383 if (!trackOut.Rotate(TMath::DegToRad()*(sector%18*20.+10.))) break;
1384 }
1385 Double_t r[3]={cl->GetX(),cl->GetY(),cl->GetZ()};
1386 trackOut.GetXYZ(xyz);
1387 bz = AliTracker::GetBz(xyz);
8951e9f5 1388 AliTracker::PropagateTrackToBxByBz(&trackOut,r[0],pimass,1.,kFALSE);
3e55050f 1389 if (!trackOut.PropagateTo(r[0],bz)) break;
1390 nclOut++;
1391 trackOut.Update(&r[1],cov);
1392 }
1393 trackOut.Rotate(trackIn.GetAlpha());
1394 Double_t meanX = (trackIn.GetX()+trackOut.GetX())*0.5;
1395 trackIn.PropagateTo(meanX,bz);
1396 trackOut.PropagateTo(meanX,bz);
b9908d0b 1397 if (TMath::Abs(trackIn.GetY()-trackOut.GetY())>kMaxDy) return;
1398 if (TMath::Abs(trackIn.GetSnp()-trackOut.GetSnp())>kMaxDsnp) return;
1399 if (TMath::Abs(trackIn.GetTgl()-trackOut.GetTgl())>kMaxDtheta) return;
1400 if (TMath::Min(nclIn,nclOut)>kMinNclS){
1401 FillResHistoTPCCE(&trackIn,&trackOut);
1402 }
3e55050f 1403 TTreeSRedirector *cstream = GetDebugStreamer();
1404 if (cstream){
1405 TVectorD gxyz(3);
1406 trackIn.GetXYZ(gxyz.GetMatrixArray());
1407 TTimeStamp tstamp(fTime);
3e55050f 1408 (*cstream)<<"tpctpc"<<
1409 "run="<<fRun<< // run number
1410 "event="<<fEvent<< // event number
1411 "time="<<fTime<< // time stamp of event
1412 "trigger="<<fTrigger<< // trigger
1413 "mag="<<fMagF<< // magnetic field
3e55050f 1414 //
b9908d0b 1415 "sideIn="<<sideIn<< // side at inner part
1416 "sideOut="<<sideOut<< // side at puter part
3e55050f 1417 "xyz.="<<&gxyz<< // global position
1418 "tIn.="<<&trackIn<< // refitterd track in
1419 "tOut.="<<&trackOut<< // refitter track out
1420 "nclIn="<<nclIn<< //
1421 "nclOut="<<nclOut<< //
1422 "\n";
1423 }
1424 //
1425 // 3. Fill time histograms
1426 // Debug stremaer expression
1427 // chainTPCTPC->Draw("(tIn.fP[1]-tOut.fP[1])*sign(-tIn.fP[3]):tIn.fP[3]","min(nclIn,nclOut)>30","")
1428 if (TMath::Min(nclIn,nclOut)>kMinNclS){
1429 fDz = trackOut.GetZ()-trackIn.GetZ();
1430 if (trackOut.GetTgl()<0) fDz*=-1.;
1431 TTimeStamp tstamp(fTime);
1432 Double_t ptrelative0 = AliTPCcalibDB::GetPTRelative(tstamp,fRun,0);
1433 Double_t ptrelative1 = AliTPCcalibDB::GetPTRelative(tstamp,fRun,1);
1434 Double_t vecDrift[4]={fTime,(ptrelative0+ptrelative1)/2.0,fDz/500.0,event->GetRunNumber()};
1435 //
1436 // fill histograms per trigger class and itegrated
1437 //
1438 THnSparse* curHist=NULL;
1439 for (Int_t itype=0; itype<2; itype++){
1440 TString name="MEAN_VDRIFT_CROSS_";
1441 if (itype==0){
1442 name+=event->GetFiredTriggerClasses();
1443 name.ToUpper();
1444 }else{
1445 name+="ALL";
1446 }
1447 curHist=(THnSparseF*)fArrayDz->FindObject(name);
1448 if(!curHist){
1449 curHist=new THnSparseF(name,"HistVdrift;time;p/T ratio;Vdrift;run",4,fBinsVdrift,fXminVdrift,fXmaxVdrift);
1450 fArrayDz->AddLast(curHist);
1451 }
1452 curHist->Fill(vecDrift);
1453 }
1454 }
1455
1456}
817766d5 1457
e0ef0ad7 1458void AliTPCcalibTime::ProcessAlignITS(AliESDtrack *const track, const AliESDfriendTrack *const friendTrack, const AliESDEvent *const event, AliESDfriend *const esdFriend){
817766d5 1459 //
3e55050f 1460 // Process track - Update TPC-ITS alignment
1461 // Updates:
1462 // 0. Apply standartd cuts
1463 // 1. Recalucluate the current statistic median/RMS
1464 // 2. Apply median+-rms cut
1465 // 3. Update kalman filter
1466 //
1467 const Int_t kMinTPC = 80; // minimal number of TPC cluster
1468 const Int_t kMinITS = 3; // minimal number of ITS cluster
1469 const Double_t kMinZ = 10; // maximal dz distance
b96c3aef 1470 const Double_t kMaxDy = 2.; // maximal dy distance
b1fea14f 1471 const Double_t kMaxAngle= 0.07; // maximal angular distance
3e55050f 1472 const Double_t kSigmaCut= 5; // maximal sigma distance to median
1473 const Double_t kVdErr = 0.1; // initial uncertainty of the vd correction
97d3fea0 1474 const Double_t kT0Err = 3.; // initial uncertainty of the T0 time
3e55050f 1475 const Double_t kVdYErr = 0.05; // initial uncertainty of the vd correction
4195eb99 1476 const Double_t kOutCut = 3.0; // outlyer cut in AliRelAlgnmentKalman
b96c3aef 1477 const Double_t kMinPt = 0.3; // minimal pt
b1fea14f 1478 const Double_t kMax1Pt=0.5; //maximal 1/pt distance
be67055b 1479 const Int_t kN=50; // deepnes of history
3e55050f 1480 static Int_t kglast=0;
1481 static Double_t* kgdP[4]={new Double_t[kN], new Double_t[kN], new Double_t[kN], new Double_t[kN]};
817766d5 1482 //
3e55050f 1483 // 0. Apply standard cuts
b1fea14f 1484 //
817766d5 1485 Int_t dummycl[1000];
817766d5 1486 if (track->GetTPCNcls()<kMinTPC) return; // minimal amount of clusters cut
b96c3aef 1487 if (!track->IsOn(AliESDtrack::kTPCrefit)) return;
817766d5 1488 if (!track->GetInnerParam()) return;
1489 if (!track->GetOuterParam()) return;
b842d904 1490 if (track->GetInnerParam()->Pt()<kMinPt) return;
817766d5 1491 // exclude crossing track
1492 if (track->GetOuterParam()->GetZ()*track->GetInnerParam()->GetZ()<0) return;
70036ef3 1493 if (TMath::Abs(track->GetInnerParam()->GetZ())<kMinZ/3.) return;
b96c3aef 1494 if (track->GetInnerParam()->GetX()>90) return;
817766d5 1495 //
1496 AliExternalTrackParam &pTPC=(AliExternalTrackParam &)(*(track->GetInnerParam()));
b1fea14f 1497 //
1498 AliExternalTrackParam pITS; // ITS standalone if possible
1499 AliExternalTrackParam pITS2; //TPC-ITS track
1500 if (friendTrack->GetITSOut()){
1501 pITS2=(*(friendTrack->GetITSOut())); //TPC-ITS track - snapshot ITS out
1502 pITS2.Rotate(pTPC.GetAlpha());
1503 AliTracker::PropagateTrackToBxByBz(&pITS2,pTPC.GetX(),0.1,0.1,kFALSE);
1504 }
be67055b 1505
b842d904 1506 AliESDfriendTrack *itsfriendTrack=0;
1507 //
1508 // try to find standalone ITS track corresponing to the TPC if possible
1509 //
1510 Bool_t hasAlone=kFALSE;
1511 Int_t ntracks=event->GetNumberOfTracks();
1512 for (Int_t i=0; i<ntracks; i++){
b1fea14f 1513 AliESDtrack * trackITS = event->GetTrack(i);
1514 if (!trackITS) continue;
1515 if (trackITS->GetITSclusters(dummycl)<kMinITS) continue; // minimal amount of clusters
6ba68367 1516 itsfriendTrack = esdFriend->GetTrack(i);
b842d904 1517 if (!itsfriendTrack) continue;
1518 if (!itsfriendTrack->GetITSOut()) continue;
b1fea14f 1519
1520 if (TMath::Abs(pTPC.GetTgl()-itsfriendTrack->GetITSOut()->GetTgl())> kMaxAngle) continue;
1521 if (TMath::Abs(pTPC.GetSigned1Pt()-itsfriendTrack->GetITSOut()->GetSigned1Pt())> kMax1Pt) continue;
b842d904 1522 pITS=(*(itsfriendTrack->GetITSOut()));
1523 //
1524 pITS.Rotate(pTPC.GetAlpha());
be67055b 1525 AliTracker::PropagateTrackToBxByBz(&pITS,pTPC.GetX(),0.1,0.1,kFALSE);
b1fea14f 1526 if (TMath::Abs(pTPC.GetY()-pITS.GetY())> kMaxDy) continue;
1527 if (TMath::Abs(pTPC.GetSnp()-pITS.GetSnp())> kMaxAngle) continue;
b842d904 1528 hasAlone=kTRUE;
1529 }
b1fea14f 1530 if (!hasAlone) {
1531 if (track->GetITSclusters(dummycl)<kMinITS) return;
1532 pITS=pITS2; // use combined track if it has ITS
1533 }
b842d904 1534 //
3e55050f 1535 if (TMath::Abs(pITS.GetY()-pTPC.GetY()) >kMaxDy) return;
1536 if (TMath::Abs(pITS.GetSnp()-pTPC.GetSnp())>kMaxAngle) return;
1537 if (TMath::Abs(pITS.GetTgl()-pTPC.GetTgl())>kMaxAngle) return;
1538 //
1539 // 1. Update median and RMS info
1540 //
b322e06a 1541 TVectorD vecDelta(5),vecMedian(5), vecRMS(5);
3e55050f 1542 TVectorD vecDeltaN(5);
1543 Double_t sign=(pITS.GetParameter()[1]>0)? 1.:-1.;
1544 vecDelta[4]=0;
1545 for (Int_t i=0;i<4;i++){
1546 vecDelta[i]=(pITS.GetParameter()[i]-pTPC.GetParameter()[i])*sign;
1547 kgdP[i][kglast%kN]=vecDelta[i];
1548 }
1549 kglast=(kglast+1);
1550 Int_t entries=(kglast<kN)?kglast:kN;
1551 for (Int_t i=0;i<4;i++){
1552 vecMedian[i] = TMath::Median(entries,kgdP[i]);
1553 vecRMS[i] = TMath::RMS(entries,kgdP[i]);
1554 vecDeltaN[i] = 0;
1555 if (vecRMS[i]>0.){
1556 vecDeltaN[i] = (vecDelta[i]-vecMedian[i])/vecRMS[i];
1557 vecDeltaN[4]+= TMath::Abs(vecDeltaN[i]); //sum of abs residuals
1558 }
1559 }
817766d5 1560 //
3e55050f 1561 // 2. Apply median+-rms cut
817766d5 1562 //
3e55050f 1563 if (kglast<3) return; //median and RMS to be defined
1564 if ( vecDeltaN[4]/4.>kSigmaCut) return;
1565 //
1566 // 3. Update alignment
817766d5 1567 //
97d3fea0 1568 Int_t htime = (fTime-fTimeKalmanBin/2)/fTimeKalmanBin; //time bins number
4486a91f 1569 if (fAlignITSTPC->GetEntriesFast()<htime){
817766d5 1570 fAlignITSTPC->Expand(htime*2+20);
1571 }
1572 AliRelAlignerKalman* align = (AliRelAlignerKalman*)fAlignITSTPC->At(htime);
1573 if (!align){
3e55050f 1574 // make Alignment object if doesn't exist
817766d5 1575 align=new AliRelAlignerKalman();
3e55050f 1576 align->SetRunNumber(fRun);
1577 (*align->GetStateCov())(6,6)=kVdErr*kVdErr;
97d3fea0 1578 (*align->GetStateCov())(7,7)=kT0Err*kT0Err;
3e55050f 1579 (*align->GetStateCov())(8,8)=kVdYErr*kVdYErr;
1580 align->SetOutRejSigma(kOutCut+kOutCut*kN);
4195eb99 1581 // align->SetRejectOutliers(kFALSE);
1582 align->SetRejectOutliers(kTRUE);
1583 align->SetRejectOutliersSigma2Median(kTRUE);
3e55050f 1584
1585 align->SetTPCvd(AliTPCcalibDB::Instance()->GetParameters()->GetDriftV()/1000000.);
817766d5 1586 align->SetMagField(fMagF);
1587 fAlignITSTPC->AddAt(align,htime);
1588 }
817766d5 1589 align->AddTrackParams(&pITS,&pTPC);
5647625c 1590 Double_t averageTime = fTime;
1591 if (align->GetTimeStamp()>0&&align->GetNUpdates()>0){
97d3fea0 1592 averageTime=((Double_t(align->GetTimeStamp())*Double_t(align->GetNUpdates())+Double_t(fTime)))/(Double_t(align->GetNUpdates())+1.);
5647625c 1593 }
1594 align->SetTimeStamp(Int_t(averageTime));
1595
3e55050f 1596 align->SetRunNumber(fRun );
391ffdb2 1597 Float_t dca[2],cov[3];
1598 track->GetImpactParameters(dca,cov);
882f5c06 1599 if (TMath::Abs(dca[0])<kMaxDy){
391ffdb2 1600 FillResHistoTPCITS(&pTPC,&pITS);
1601 FillResHistoTPC(track);
1602 }
3e55050f 1603 //
1604 Int_t nupdates=align->GetNUpdates();
4195eb99 1605 align->SetOutRejSigma(kOutCut+kOutCut*kN/Double_t(nupdates+1));
1606 // align->SetRejectOutliers(kFALSE);
1607 align->SetRejectOutliers(kTRUE);
1608 align->SetRejectOutliersSigma2Median(kTRUE);
1609
817766d5 1610 TTreeSRedirector *cstream = GetDebugStreamer();
1611 if (cstream && align->GetState() && align->GetState()->GetNrows()>2 ){
817766d5 1612 TVectorD gpTPC(3), gdTPC(3);
1613 TVectorD gpITS(3), gdITS(3);
1614 pTPC.GetXYZ(gpTPC.GetMatrixArray());
1615 pTPC.GetDirection(gdTPC.GetMatrixArray());
1616 pITS.GetXYZ(gpITS.GetMatrixArray());
1617 pITS.GetDirection(gdITS.GetMatrixArray());
1618 (*cstream)<<"itstpc"<<
1619 "run="<<fRun<< // run number
1620 "event="<<fEvent<< // event number
1621 "time="<<fTime<< // time stamp of event
1622 "trigger="<<fTrigger<< // trigger
1623 "mag="<<fMagF<< // magnetic field
817766d5 1624 //
b842d904 1625 "hasAlone="<<hasAlone<< // has ITS standalone ?
1626 "track.="<<track<< // track info
3e55050f 1627 "nmed="<<kglast<< // number of entries to define median and RMS
1628 "vMed.="<<&vecMedian<< // median of deltas
1629 "vRMS.="<<&vecRMS<< // rms of deltas
1630 "vDelta.="<<&vecDelta<< // delta in respect to median
1631 "vDeltaN.="<<&vecDeltaN<< // normalized delta in respect to median
3e55050f 1632 "a.="<<align<< // current alignment
b842d904 1633 "pITS.="<<&pITS<< // track param ITS
1634 "pITS2.="<<&pITS2<< // track param ITS+TPC
3e55050f 1635 "pTPC.="<<&pTPC<< // track param TPC
1636 "gpTPC.="<<&gpTPC<< // global position TPC
1637 "gdTPC.="<<&gdTPC<< // global direction TPC
1638 "gpITS.="<<&gpITS<< // global position ITS
1639 "gdITS.="<<&gdITS<< // global position ITS
817766d5 1640 "\n";
1641 }
817766d5 1642}
3e55050f 1643
1644
1645
1646
e0ef0ad7 1647void AliTPCcalibTime::ProcessAlignTRD(AliESDtrack *const track, const AliESDfriendTrack *const friendTrack){
0dac7b3a 1648 //
3e55050f 1649 // Process track - Update TPC-TRD alignment
1650 // Updates:
1651 // 0. Apply standartd cuts
1652 // 1. Recalucluate the current statistic median/RMS
1653 // 2. Apply median+-rms cut
1654 // 3. Update kalman filter
1655 //
1656 const Int_t kMinTPC = 80; // minimal number of TPC cluster
1657 const Int_t kMinTRD = 50; // minimal number of TRD cluster
1658 const Double_t kMinZ = 20; // maximal dz distance
9112627b 1659 const Double_t kMaxDy = 5.; // maximal dy distance
1660 const Double_t kMaxAngle= 0.1; // maximal angular distance
1661 const Double_t kSigmaCut= 10; // maximal sigma distance to median
3e55050f 1662 const Double_t kVdErr = 0.1; // initial uncertainty of the vd correction
97d3fea0 1663 const Double_t kT0Err = 3.; // initial uncertainty of the T0 time
3e55050f 1664 const Double_t kVdYErr = 0.05; // initial uncertainty of the vd correction
4195eb99 1665 const Double_t kOutCut = 3.0; // outlyer cut in AliRelAlgnmentKalman
be67055b 1666 const Double_t kRefX = 275; // reference X
1667 const Int_t kN=50; // deepnes of history
3e55050f 1668 static Int_t kglast=0;
1669 static Double_t* kgdP[4]={new Double_t[kN], new Double_t[kN], new Double_t[kN], new Double_t[kN]};
0dac7b3a 1670 //
3e55050f 1671 // 0. Apply standard cuts
0dac7b3a 1672 //
1673 Int_t dummycl[1000];
1674 if (track->GetTRDclusters(dummycl)<kMinTRD) return; // minimal amount of clusters
1675 if (track->GetTPCNcls()<kMinTPC) return; // minimal amount of clusters cut
3e55050f 1676 if (!friendTrack->GetTRDIn()) return;
be67055b 1677 if (!track->IsOn(AliESDtrack::kTRDrefit)) return;
1678 if (!track->IsOn(AliESDtrack::kTRDout)) return;
0dac7b3a 1679 if (!track->GetInnerParam()) return;
be67055b 1680 if (!friendTrack->GetTPCOut()) return;
0dac7b3a 1681 // exclude crossing track
be67055b 1682 if (friendTrack->GetTPCOut()->GetZ()*track->GetInnerParam()->GetZ()<0) return;
3e55050f 1683 if (TMath::Abs(track->GetInnerParam()->GetZ())<kMinZ) return;
0dac7b3a 1684 //
be67055b 1685 AliExternalTrackParam &pTPC=(AliExternalTrackParam &)(*(friendTrack->GetTPCOut()));
1686 AliTracker::PropagateTrackToBxByBz(&pTPC,kRefX,0.1,0.1,kFALSE);
0dac7b3a 1687 AliExternalTrackParam pTRD(*(friendTrack->GetTRDIn()));
3e55050f 1688 pTRD.Rotate(pTPC.GetAlpha());
be67055b 1689 // pTRD.PropagateTo(pTPC.GetX(),fMagF);
1690 AliTracker::PropagateTrackToBxByBz(&pTRD,pTPC.GetX(),0.1,0.1,kFALSE);
1691
3e55050f 1692 ((Double_t*)pTRD.GetCovariance())[2]+=3.*3.; // increas sys errors
1693 ((Double_t*)pTRD.GetCovariance())[9]+=0.1*0.1; // increse sys errors
1694
1695 if (TMath::Abs(pTRD.GetY()-pTPC.GetY()) >kMaxDy) return;
1696 if (TMath::Abs(pTRD.GetSnp()-pTPC.GetSnp())>kMaxAngle) return;
9112627b 1697 // if (TMath::Abs(pTRD.GetTgl()-pTPC.GetTgl())>kMaxAngle) return;
0dac7b3a 1698 //
3e55050f 1699 // 1. Update median and RMS info
0dac7b3a 1700 //
b322e06a 1701 TVectorD vecDelta(5),vecMedian(5), vecRMS(5);
3e55050f 1702 TVectorD vecDeltaN(5);
1703 Double_t sign=(pTRD.GetParameter()[1]>0)? 1.:-1.;
1704 vecDelta[4]=0;
1705 for (Int_t i=0;i<4;i++){
1706 vecDelta[i]=(pTRD.GetParameter()[i]-pTPC.GetParameter()[i])*sign;
1707 kgdP[i][kglast%kN]=vecDelta[i];
1708 }
1709 kglast=(kglast+1);
1710 Int_t entries=(kglast<kN)?kglast:kN;
1711 for (Int_t i=0;i<4;i++){
1712 vecMedian[i] = TMath::Median(entries,kgdP[i]);
be67055b 1713
3e55050f 1714 vecRMS[i] = TMath::RMS(entries,kgdP[i]);
1715 vecDeltaN[i] = 0;
1716 if (vecRMS[i]>0.){
1717 vecDeltaN[i] = (vecDelta[i]-vecMedian[i])/vecRMS[i];
1718 vecDeltaN[4]+= TMath::Abs(vecDeltaN[i]); //sum of abs residuals
1719 }
1720 }
1721 //
1722 // 2. Apply median+-rms cut
1723 //
1724 if (kglast<3) return; //median and RMS to be defined
1725 if ( vecDeltaN[4]/4.>kSigmaCut) return;
1726 //
1727 // 3. Update alignment
0dac7b3a 1728 //
5647625c 1729 //Int_t htime = fTime/3600; //time in hours
97d3fea0 1730 Int_t htime = (Int_t)(fTime-fTimeKalmanBin/2)/fTimeKalmanBin; //time in half hour
4486a91f 1731 if (fAlignTRDTPC->GetEntriesFast()<htime){
0dac7b3a 1732 fAlignTRDTPC->Expand(htime*2+20);
1733 }
1734 AliRelAlignerKalman* align = (AliRelAlignerKalman*)fAlignTRDTPC->At(htime);
1735 if (!align){
3e55050f 1736 // make Alignment object if doesn't exist
0dac7b3a 1737 align=new AliRelAlignerKalman();
3e55050f 1738 align->SetRunNumber(fRun);
1739 (*align->GetStateCov())(6,6)=kVdErr*kVdErr;
97d3fea0 1740 (*align->GetStateCov())(7,7)=kT0Err*kT0Err;
3e55050f 1741 (*align->GetStateCov())(8,8)=kVdYErr*kVdYErr;
1742 align->SetOutRejSigma(kOutCut+kOutCut*kN);
4195eb99 1743 // align->SetRejectOutliers(kFALSE);
1744 align->SetRejectOutliers(kTRUE);
1745 align->SetRejectOutliersSigma2Median(kTRUE);
1746
3e55050f 1747 align->SetTPCvd(AliTPCcalibDB::Instance()->GetParameters()->GetDriftV()/1000000.);
0dac7b3a 1748 align->SetMagField(fMagF);
1749 fAlignTRDTPC->AddAt(align,htime);
1750 }
0dac7b3a 1751 align->AddTrackParams(&pTRD,&pTPC);
5647625c 1752 //align->SetTimeStamp(fTime);
1753 Double_t averageTime = fTime;
1754 if (align->GetTimeStamp()>0 && align->GetNUpdates()>0) {
1755 averageTime = (((Double_t)fTime) + ((Double_t)align->GetTimeStamp())*align->GetNUpdates()) / (align->GetNUpdates() + 1.);
1756 //printf("align->GetTimeStamp() %d, align->GetNUpdates() %d \n", align->GetTimeStamp(), align->GetNUpdates());
1757 }
1758 align->SetTimeStamp((Int_t)averageTime);
1759
1760 //printf("fTime %d, averageTime %d \n", fTime, (Int_t)averageTime);
1761
3e55050f 1762 align->SetRunNumber(fRun );
0b736a46 1763 Float_t dca[2],cov[3];
1764 track->GetImpactParameters(dca,cov);
1765 if (TMath::Abs(dca[0])<kMaxDy){
1766 FillResHistoTPCTRD(&pTPC,&pTRD); //only primaries
1767 }
3e55050f 1768 //
1769 Int_t nupdates=align->GetNUpdates();
4195eb99 1770 align->SetOutRejSigma(kOutCut+kOutCut*kN/Double_t(nupdates+1));
1771 // align->SetRejectOutliers(kFALSE);
1772 align->SetRejectOutliers(kTRUE);
1773 align->SetRejectOutliersSigma2Median(kTRUE);
1774
0dac7b3a 1775 TTreeSRedirector *cstream = GetDebugStreamer();
1776 if (cstream && align->GetState() && align->GetState()->GetNrows()>2 ){
0dac7b3a 1777 TVectorD gpTPC(3), gdTPC(3);
1778 TVectorD gpTRD(3), gdTRD(3);
1779 pTPC.GetXYZ(gpTPC.GetMatrixArray());
1780 pTPC.GetDirection(gdTPC.GetMatrixArray());
1781 pTRD.GetXYZ(gpTRD.GetMatrixArray());
1782 pTRD.GetDirection(gdTRD.GetMatrixArray());
3e55050f 1783 (*cstream)<<"trdtpc"<<
0dac7b3a 1784 "run="<<fRun<< // run number
1785 "event="<<fEvent<< // event number
1786 "time="<<fTime<< // time stamp of event
1787 "trigger="<<fTrigger<< // trigger
1788 "mag="<<fMagF<< // magnetic field
0dac7b3a 1789 //
3e55050f 1790 "nmed="<<kglast<< // number of entries to define median and RMS
1791 "vMed.="<<&vecMedian<< // median of deltas
1792 "vRMS.="<<&vecRMS<< // rms of deltas
1793 "vDelta.="<<&vecDelta<< // delta in respect to median
1794 "vDeltaN.="<<&vecDeltaN<< // normalized delta in respect to median
1795 "t.="<<track<< // ful track - find proper cuts
1796 "a.="<<align<< // current alignment
1797 "pTRD.="<<&pTRD<< // track param TRD
1798 "pTPC.="<<&pTPC<< // track param TPC
1799 "gpTPC.="<<&gpTPC<< // global position TPC
1800 "gdTPC.="<<&gdTPC<< // global direction TPC
1801 "gpTRD.="<<&gpTRD<< // global position TRD
1802 "gdTRD.="<<&gdTRD<< // global position TRD
0dac7b3a 1803 "\n";
1804 }
0dac7b3a 1805}
817766d5 1806
1807
e0ef0ad7 1808void AliTPCcalibTime::ProcessAlignTOF(AliESDtrack *const track, const AliESDfriendTrack *const friendTrack){
817766d5 1809 //
817766d5 1810 //
3e55050f 1811 // Process track - Update TPC-TOF alignment
1812 // Updates:
1813 // -1. Make a TOF "track"
1814 // 0. Apply standartd cuts
1815 // 1. Recalucluate the current statistic median/RMS
1816 // 2. Apply median+-rms cut
1817 // 3. Update kalman filter
1818 //
1819 const Int_t kMinTPC = 80; // minimal number of TPC cluster
b842d904 1820 // const Double_t kMinZ = 10; // maximal dz distance
3e55050f 1821 const Double_t kMaxDy = 5.; // maximal dy distance
70036ef3 1822 const Double_t kMaxAngle= 0.05; // maximal angular distance
3e55050f 1823 const Double_t kSigmaCut= 5; // maximal sigma distance to median
1824 const Double_t kVdErr = 0.1; // initial uncertainty of the vd correction
97d3fea0 1825 const Double_t kT0Err = 3.; // initial uncertainty of the T0 time
3e55050f 1826 const Double_t kVdYErr = 0.05; // initial uncertainty of the vd correction
1827
4195eb99 1828 const Double_t kOutCut = 3.0; // outlyer cut in AliRelAlgnmentKalman
be67055b 1829 const Int_t kN=50; // deepnes of history
3e55050f 1830 static Int_t kglast=0;
1831 static Double_t* kgdP[4]={new Double_t[kN], new Double_t[kN], new Double_t[kN], new Double_t[kN]};
817766d5 1832 //
3e55050f 1833 // -1. Make a TOF track-
1834 // Clusters are not in friends - use alingment points
1835 //
1836 if (track->GetTOFsignal()<=0) return;
1837 if (!friendTrack->GetTPCOut()) return;
1838 if (!track->GetInnerParam()) return;
be67055b 1839 if (!friendTrack->GetTPCOut()) return;
817766d5 1840 const AliTrackPointArray *points=friendTrack->GetTrackPointArray();
1841 if (!points) return;
be67055b 1842 AliExternalTrackParam pTPC(*(friendTrack->GetTPCOut()));
3e55050f 1843 AliExternalTrackParam pTOF(pTPC);
1844 Double_t mass = TDatabasePDG::Instance()->GetParticle("mu+")->Mass();
817766d5 1845 Int_t npoints = points->GetNPoints();
1846 AliTrackPoint point;
3e55050f 1847 Int_t naccept=0;
817766d5 1848 //
1849 for (Int_t ipoint=0;ipoint<npoints;ipoint++){
817766d5 1850 points->GetPoint(point,ipoint);
1851 Float_t xyz[3];
1852 point.GetXYZ(xyz);
1853 Double_t r=TMath::Sqrt(xyz[0]*xyz[0]+xyz[1]*xyz[1]);
3e55050f 1854 if (r<350) continue;
817766d5 1855 if (r>400) continue;
3e55050f 1856 AliTracker::PropagateTrackToBxByBz(&pTPC,r,mass,2.,kTRUE);
1857 AliTracker::PropagateTrackToBxByBz(&pTPC,r,mass,0.1,kTRUE);
1858 AliTrackPoint lpoint = point.Rotate(pTPC.GetAlpha());
1859 pTPC.PropagateTo(lpoint.GetX(),fMagF);
1860 pTOF=pTPC;
817766d5 1861 ((Double_t*)pTOF.GetParameter())[0] =lpoint.GetY();
1862 ((Double_t*)pTOF.GetParameter())[1] =lpoint.GetZ();
3e55050f 1863 ((Double_t*)pTOF.GetCovariance())[0]+=3.*3./12.;
1864 ((Double_t*)pTOF.GetCovariance())[2]+=3.*3./12.;
0dac7b3a 1865 ((Double_t*)pTOF.GetCovariance())[5]+=0.1*0.1;
1866 ((Double_t*)pTOF.GetCovariance())[9]+=0.1*0.1;
3e55050f 1867 naccept++;
1868 }
1869 if (naccept==0) return; // no tof match clusters
1870 //
1871 // 0. Apply standard cuts
1872 //
1873 if (track->GetTPCNcls()<kMinTPC) return; // minimal amount of clusters cut
1874 // exclude crossing track
be67055b 1875 if (friendTrack->GetTPCOut()->GetZ()*track->GetInnerParam()->GetZ()<0) return;
3e55050f 1876 //
1877 if (TMath::Abs(pTOF.GetY()-pTPC.GetY()) >kMaxDy) return;
1878 if (TMath::Abs(pTOF.GetSnp()-pTPC.GetSnp())>kMaxAngle) return;
1879 if (TMath::Abs(pTOF.GetTgl()-pTPC.GetTgl())>kMaxAngle) return;
1880 //
1881 // 1. Update median and RMS info
1882 //
b322e06a 1883 TVectorD vecDelta(5),vecMedian(5), vecRMS(5);
3e55050f 1884 TVectorD vecDeltaN(5);
1885 Double_t sign=(pTOF.GetParameter()[1]>0)? 1.:-1.;
1886 vecDelta[4]=0;
1887 for (Int_t i=0;i<4;i++){
1888 vecDelta[i]=(pTOF.GetParameter()[i]-pTPC.GetParameter()[i])*sign;
1889 kgdP[i][kglast%kN]=vecDelta[i];
1890 }
1891 kglast=(kglast+1);
1892 Int_t entries=(kglast<kN)?kglast:kN;
1893 Bool_t isOK=kTRUE;
1894 for (Int_t i=0;i<4;i++){
1895 vecMedian[i] = TMath::Median(entries,kgdP[i]);
1896 vecRMS[i] = TMath::RMS(entries,kgdP[i]);
1897 vecDeltaN[i] = 0;
1898 if (vecRMS[i]>0.){
1899 vecDeltaN[i] = (vecDelta[i]-vecMedian[i])/(vecRMS[i]+1.);
1900 vecDeltaN[4]+= TMath::Abs(vecDeltaN[i]); //sum of abs residuals
1901 if (TMath::Abs(vecDeltaN[i])>kSigmaCut) isOK=kFALSE;
817766d5 1902 }
3e55050f 1903 }
1904 //
1905 // 2. Apply median+-rms cut
1906 //
1907 if (kglast<10) return; //median and RMS to be defined
1908 if (!isOK) return;
1909 //
1910 // 3. Update alignment
1911 //
5647625c 1912 //Int_t htime = fTime/3600; //time in hours
97d3fea0 1913 Int_t htime = (Int_t)(fTime-fTimeKalmanBin)/fTimeKalmanBin; //time bin
4486a91f 1914 if (fAlignTOFTPC->GetEntriesFast()<htime){
3e55050f 1915 fAlignTOFTPC->Expand(htime*2+20);
1916 }
1917 AliRelAlignerKalman* align = (AliRelAlignerKalman*)fAlignTOFTPC->At(htime);
1918 if (!align){
1919 // make Alignment object if doesn't exist
1920 align=new AliRelAlignerKalman();
1921 align->SetRunNumber(fRun);
1922 (*align->GetStateCov())(6,6)=kVdErr*kVdErr;
97d3fea0 1923 (*align->GetStateCov())(7,7)=kT0Err*kT0Err;
3e55050f 1924 (*align->GetStateCov())(8,8)=kVdYErr*kVdYErr;
1925 align->SetOutRejSigma(kOutCut+kOutCut*kN);
4195eb99 1926 // align->SetRejectOutliers(kFALSE);
1927 align->SetRejectOutliers(kTRUE);
1928 align->SetRejectOutliersSigma2Median(kTRUE);
1929
3e55050f 1930 align->SetTPCvd(AliTPCcalibDB::Instance()->GetParameters()->GetDriftV()/1000000.);
1931 align->SetMagField(fMagF);
1932 fAlignTOFTPC->AddAt(align,htime);
1933 }
1934 align->AddTrackParams(&pTOF,&pTPC);
0b736a46 1935 Float_t dca[2],cov[3];
1936 track->GetImpactParameters(dca,cov);
1937 if (TMath::Abs(dca[0])<kMaxDy){
1938 FillResHistoTPCTOF(&pTPC,&pTOF);
1939 }
5647625c 1940 //align->SetTimeStamp(fTime);
1941 Double_t averageTime = fTime;
1942 if (align->GetTimeStamp()>0 && align->GetNUpdates()>0) {
1943 averageTime = (((Double_t)fTime) + ((Double_t)align->GetTimeStamp())*align->GetNUpdates()) / (align->GetNUpdates() + 1.);
1944 //printf("align->GetTimeStamp() %d, align->GetNUpdates() %d \n", align->GetTimeStamp(), align->GetNUpdates());
1945 }
1946 align->SetTimeStamp((Int_t)averageTime);
1947
1948 //printf("fTime %d, averageTime %d \n", fTime, (Int_t)averageTime);
1949
3e55050f 1950 align->SetRunNumber(fRun );
1951 //
1952 Int_t nupdates=align->GetNUpdates();
4195eb99 1953 align->SetOutRejSigma(kOutCut+kOutCut*kN/Double_t(nupdates+1));
1954 // align->SetRejectOutliers(kFALSE);
1955 align->SetRejectOutliers(kTRUE);
1956 align->SetRejectOutliersSigma2Median(kTRUE);
1957
3e55050f 1958 TTreeSRedirector *cstream = GetDebugStreamer();
1959 if (cstream && align->GetState() && align->GetState()->GetNrows()>2 ){
3e55050f 1960 TVectorD gpTPC(3), gdTPC(3);
1961 TVectorD gpTOF(3), gdTOF(3);
1962 pTPC.GetXYZ(gpTPC.GetMatrixArray());
1963 pTPC.GetDirection(gdTPC.GetMatrixArray());
1964 pTOF.GetXYZ(gpTOF.GetMatrixArray());
1965 pTOF.GetDirection(gdTOF.GetMatrixArray());
1966 (*cstream)<<"toftpc"<<
1967 "run="<<fRun<< // run number
1968 "event="<<fEvent<< // event number
1969 "time="<<fTime<< // time stamp of event
1970 "trigger="<<fTrigger<< // trigger
1971 "mag="<<fMagF<< // magnetic field
3e55050f 1972 //
1973 "nmed="<<kglast<< // number of entries to define median and RMS
1974 "vMed.="<<&vecMedian<< // median of deltas
1975 "vRMS.="<<&vecRMS<< // rms of deltas
1976 "vDelta.="<<&vecDelta<< // delta in respect to median
1977 "vDeltaN.="<<&vecDeltaN<< // normalized delta in respect to median
1978 "t.="<<track<< // ful track - find proper cuts
1979 "a.="<<align<< // current alignment
1980 "pTOF.="<<&pTOF<< // track param TOF
1981 "pTPC.="<<&pTPC<< // track param TPC
1982 "gpTPC.="<<&gpTPC<< // global position TPC
1983 "gdTPC.="<<&gdTPC<< // global direction TPC
1984 "gpTOF.="<<&gpTOF<< // global position TOF
1985 "gdTOF.="<<&gdTOF<< // global position TOF
1986 "\n";
817766d5 1987 }
817766d5 1988}
3e55050f 1989
1990
391ffdb2 1991void AliTPCcalibTime::BookDistortionMaps(){
1992 //
1993 // Book ndimensional histograms of distortions/residuals
1994 // Only primary tracks are selected for analysis
1995 //
1996
b9908d0b 1997 Double_t xminTrack[5], xmaxTrack[5];
1998 Int_t binsTrack[5];
1999 TString axisName[5];
2000 TString axisTitle[5];
391ffdb2 2001 //
882f5c06 2002 binsTrack[0] =50;
391ffdb2 2003 axisName[0] ="#Delta";
2004 axisTitle[0] ="#Delta";
2005 //
70036ef3 2006 binsTrack[1] =44;
2007 xminTrack[1] =-1.1; xmaxTrack[1]=1.1;
391ffdb2 2008 axisName[1] ="tanTheta";
2009 axisTitle[1] ="tan(#Theta)";
2010 //
70036ef3 2011 binsTrack[2] =180;
391ffdb2 2012 xminTrack[2] =-TMath::Pi(); xmaxTrack[2]=TMath::Pi();
2013 axisName[2] ="phi";
2014 axisTitle[2] ="#phi";
2015 //
2016 binsTrack[3] =20;
2017 xminTrack[3] =-1.; xmaxTrack[3]=1.; // 0.33 GeV cut
2018 axisName[3] ="snp";
b9908d0b 2019 axisTitle[3] ="snp";
2020 //
2021 binsTrack[4] =10;
2022 xminTrack[4] =120.; xmaxTrack[4]=215.; // crossing radius for CE only
2023 axisName[4] ="r";
2024 axisTitle[4] ="r(cm)";
391ffdb2 2025 //
2026 // delta y
be67055b 2027 xminTrack[0] =-1.5; xmaxTrack[0]=1.5; //
b9908d0b 2028 fResHistoTPCCE[0] = new THnSparseS("TPCCE#Delta_{Y} (cm)","#Delta_{Y} (cm)", 5, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2029 fResHistoTPCITS[0] = new THnSparseS("TPCITS#Delta_{Y} (cm)","#Delta_{Y} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
2030 fResHistoTPCvertex[0] = new THnSparseS("TPCVertex#Delta_{Y} (cm)","#Delta_{Y} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
be67055b 2031 xminTrack[0] =-1.5; xmaxTrack[0]=1.5; //
391ffdb2 2032 fResHistoTPCTRD[0] = new THnSparseS("TPCTRD#Delta_{Y} (cm)","#Delta_{Y} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
0b736a46 2033 xminTrack[0] =-5; xmaxTrack[0]=5; //
2034 fResHistoTPCTOF[0] = new THnSparseS("TPCTOF#Delta_{Y} (cm)","#Delta_{Y} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2035 //
2036 // delta z
4195eb99 2037 xminTrack[0] =-6.; xmaxTrack[0]=6.; //
b9908d0b 2038 fResHistoTPCCE[1] = new THnSparseS("TPCCE#Delta_{Z} (cm)","#Delta_{Z} (cm)", 5, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2039 fResHistoTPCITS[1] = new THnSparseS("TPCITS#Delta_{Z} (cm)","#Delta_{Z} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
2040 fResHistoTPCvertex[1] = new THnSparseS("TPCVertex#Delta_{Z} (cm)","#Delta_{Z} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
2041 fResHistoTPCTRD[1] = new THnSparseS("TPCTRD#Delta_{Z} (cm)","#Delta_{Z} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
0b736a46 2042 xminTrack[0] =-5.; xmaxTrack[0]=5.; //
2043 fResHistoTPCTOF[1] = new THnSparseS("TPCTOF#Delta_{Z} (cm)","#Delta_{Z} (cm)", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2044 //
2045 // delta snp-P2
882f5c06 2046 xminTrack[0] =-0.015; xmaxTrack[0]=0.015; //
b9908d0b 2047 fResHistoTPCCE[2] = new THnSparseS("TPCCE#Delta_{#phi}","#Delta_{#phi}", 5, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2048 fResHistoTPCITS[2] = new THnSparseS("TPCITS#Delta_{#phi}","#Delta_{#phi}", 4, binsTrack,xminTrack, xmaxTrack);
9112627b 2049 fResHistoTPCvertex[2] = new THnSparseS("TPCITSv#Delta_{#phi}","#Delta_{#phi}", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2050 fResHistoTPCTRD[2] = new THnSparseS("TPCTRD#Delta_{#phi}","#Delta_{#phi}", 4, binsTrack,xminTrack, xmaxTrack);
0b736a46 2051 fResHistoTPCTOF[2] = new THnSparseS("TPCTOF#Delta_{#phi}","#Delta_{#phi}", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2052 //
2053 // delta theta-P3
4195eb99 2054 xminTrack[0] =-0.05; xmaxTrack[0]=0.05; //
b9908d0b 2055 fResHistoTPCCE[3] = new THnSparseS("TPCCE#Delta_{#theta}","#Delta_{#theta}", 5, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2056 fResHistoTPCITS[3] = new THnSparseS("TPCITS#Delta_{#theta}","#Delta_{#theta}", 4, binsTrack,xminTrack, xmaxTrack);
9112627b 2057 fResHistoTPCvertex[3] = new THnSparseS("TPCITSv#Delta_{#theta}","#Delta_{#theta}", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2058 fResHistoTPCTRD[3] = new THnSparseS("TPCTRD#Delta_{#theta}","#Delta_{#theta}", 4, binsTrack,xminTrack, xmaxTrack);
0b736a46 2059 fResHistoTPCTOF[3] = new THnSparseS("TPCTOF#Delta_{#theta}","#Delta_{#theta}", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2060 //
2061 // delta theta-P4
9112627b 2062 xminTrack[0] =-0.2; xmaxTrack[0]=0.2; //
b9908d0b 2063 fResHistoTPCCE[4] = new THnSparseS("TPCCE#Delta_{1/pt}","#Delta_{1/pt}", 5, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2064 fResHistoTPCITS[4] = new THnSparseS("TPCITS#Delta_{1/pt}","#Delta_{1/pt}", 4, binsTrack,xminTrack, xmaxTrack);
9112627b 2065 fResHistoTPCvertex[4] = new THnSparseS("TPCITSv#Delta_{1/pt}","#Delta_{1/pt}", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2066 fResHistoTPCTRD[4] = new THnSparseS("TPCTRD#Delta_{1/pt}","#Delta_{1/pt}", 4, binsTrack,xminTrack, xmaxTrack);
0b736a46 2067 fResHistoTPCTOF[4] = new THnSparseS("TPCTOF#Delta_{1/pt}","#Delta_{1/pt}", 4, binsTrack,xminTrack, xmaxTrack);
391ffdb2 2068 //
2069 for (Int_t ivar=0;ivar<4;ivar++){
b9908d0b 2070 for (Int_t ivar2=0;ivar2<5;ivar2++){
2071 fResHistoTPCCE[ivar]->GetAxis(ivar2)->SetName(axisName[ivar2].Data());
2072 fResHistoTPCCE[ivar]->GetAxis(ivar2)->SetTitle(axisTitle[ivar2].Data());
2073 if (ivar2<4){
2074 fResHistoTPCITS[ivar]->GetAxis(ivar2)->SetName(axisName[ivar2].Data());
2075 fResHistoTPCITS[ivar]->GetAxis(ivar2)->SetTitle(axisTitle[ivar2].Data());
2076 fResHistoTPCTRD[ivar]->GetAxis(ivar2)->SetName(axisName[ivar2].Data());
2077 fResHistoTPCTRD[ivar]->GetAxis(ivar2)->SetTitle(axisTitle[ivar2].Data());
2078 fResHistoTPCvertex[ivar]->GetAxis(ivar2)->SetName(axisName[ivar2].Data());
2079 fResHistoTPCvertex[ivar]->GetAxis(ivar2)->SetTitle(axisTitle[ivar2].Data());
2080 }
391ffdb2 2081 }
2082 }
70036ef3 2083 //
2084 // Book vertex: time histograms
2085 //
2086 Int_t binsVertex[2]={500, fTimeBins};
2087 Double_t aminVertex[2]={-5,fTimeStart};
2088 Double_t amaxVertex[2]={5, fTimeEnd};
2089 const char* hnames[12]={"TPCXAside", "TPCXCside","TPCXACdiff","TPCXAPCdiff",
2090 "TPCYAside", "TPCYCside","TPCYACdiff","TPCYAPCdiff",
2091 "TPCZAPCside", "TPCZAMCside","TPCZACdiff","TPCZAPCdiff"};
2092 const char* anames[12]={"x (cm) - A side ", "x (cm) - C side","#Delta_{x} (cm) - TPC-A-C","#Delta_{x} (cm) - TPC-Common",
2093 "y (cm) - A side ", "y (cm) - C side","#Delta_{x} (cm) - TPC-A-C","#Delta_{y} (cm) - TPC-Common",
2094 "z (cm)", "#Delta_{Z} (cm) A-C side","#Delta_{x} (cm) - TPC-A-C","#Delta_{Z} (cm) TPC-common"};
2095 for (Int_t ihis=0; ihis<12; ihis++) {
2096 if (ihis>=8) aminVertex[0]=-20.;
2097 if (ihis>=8) amaxVertex[0]=20.;
2098 fTPCVertex[ihis]=new THnSparseF(hnames[ihis],hnames[ihis],2,binsVertex,aminVertex,amaxVertex);
2099 fTPCVertex[ihis]->GetAxis(1)->SetTitle("Time");
2100 fTPCVertex[ihis]->GetAxis(0)->SetTitle(anames[ihis]);
2101 }
b1fea14f 2102
2103 Int_t binsVertexC[2]={40, 300};
2104 Double_t aminVertexC[2]={-20,-30};
2105 Double_t amaxVertexC[2]={20,30};
2106 const char* hnamesC[5]={"TPCA_TPC","TPCC_TPC","TPCA_ITS","TPCC_ITS","TPC_ITS"};
2107 for (Int_t ihis=0; ihis<5; ihis++) {
2108 fTPCVertexCorrelation[ihis]=new THnSparseF(hnamesC[ihis],hnamesC[ihis],2,binsVertexC,aminVertexC,amaxVertexC);
2109 fTPCVertexCorrelation[ihis]->GetAxis(1)->SetTitle("z (cm)");
2110 fTPCVertexCorrelation[ihis]->GetAxis(0)->SetTitle("z (cm)");
2111 }
391ffdb2 2112}
2113
2114
b9908d0b 2115void AliTPCcalibTime::FillResHistoTPCCE(const AliExternalTrackParam * pTPCIn, const AliExternalTrackParam * pTPCOut ){
2116 //
2117 // fill residual histograms pTPCOut-pTPCin - trac crossing CE
2118 // Histogram
2119 //
660f0543 2120 if (fMemoryMode<2) return;
b9908d0b 2121 Double_t histoX[5];
2122 Double_t xyz[3];
2123 pTPCIn->GetXYZ(xyz);
2124 Double_t phi= TMath::ATan2(xyz[1],xyz[0]);
2125 histoX[1]= pTPCIn->GetTgl();
2126 histoX[2]= phi;
2127 histoX[3]= pTPCIn->GetSnp();
2128 histoX[4]= pTPCIn->GetX();
2129 AliExternalTrackParam lout(*pTPCOut);
2130 lout.Rotate(pTPCIn->GetAlpha());
2131 lout.PropagateTo(pTPCIn->GetX(),fMagF);
2132 //
2133 for (Int_t ihisto=0; ihisto<5; ihisto++){
2134 histoX[0]=lout.GetParameter()[ihisto]-pTPCIn->GetParameter()[ihisto];
2135 fResHistoTPCCE[ihisto]->Fill(histoX);
2136 }
2137}
391ffdb2 2138void AliTPCcalibTime::FillResHistoTPCITS(const AliExternalTrackParam * pTPCIn, const AliExternalTrackParam * pITSOut ){
2139 //
2140 // fill residual histograms pTPCIn-pITSOut
2141 // Histogram is filled only for primary tracks
2142 //
2143 Double_t histoX[4];
2144 Double_t xyz[3];
2145 pTPCIn->GetXYZ(xyz);
2146 Double_t phi= TMath::ATan2(xyz[1],xyz[0]);
2147 histoX[1]= pTPCIn->GetTgl();
2148 histoX[2]= phi;
2149 histoX[3]= pTPCIn->GetSnp();
9112627b 2150 AliExternalTrackParam lits(*pITSOut);
2151 lits.Rotate(pTPCIn->GetAlpha());
2152 lits.PropagateTo(pTPCIn->GetX(),fMagF);
391ffdb2 2153 //
2154 for (Int_t ihisto=0; ihisto<5; ihisto++){
9112627b 2155 histoX[0]=pTPCIn->GetParameter()[ihisto]-lits.GetParameter()[ihisto];
391ffdb2 2156 fResHistoTPCITS[ihisto]->Fill(histoX);
2157 }
2158}
2159
2160
2161void AliTPCcalibTime::FillResHistoTPC(const AliESDtrack * pTrack){
2162 //
2163 // fill residual histograms pTPC - vertex
2164 // Histogram is filled only for primary tracks
2165 //
660f0543 2166 if (fMemoryMode<2) return;
391ffdb2 2167 Double_t histoX[4];
2168 const AliExternalTrackParam * pTPCIn = pTrack->GetInnerParam();
be67055b 2169 AliExternalTrackParam pTPCvertex(*(pTrack->GetInnerParam()));
9112627b 2170 //
2171 AliExternalTrackParam lits(*pTrack);
be67055b 2172 if (TMath::Abs(pTrack->GetY())>3) return; // beam pipe
2173 pTPCvertex.Rotate(lits.GetAlpha());
2174 //pTPCvertex.PropagateTo(pTPCvertex->GetX(),fMagF);
2175 AliTracker::PropagateTrackToBxByBz(&pTPCvertex,lits.GetX(),0.1,2,kFALSE);
2176 AliTracker::PropagateTrackToBxByBz(&pTPCvertex,lits.GetX(),0.1,0.1,kFALSE);
391ffdb2 2177 Double_t xyz[3];
2178 pTPCIn->GetXYZ(xyz);
2179 Double_t phi= TMath::ATan2(xyz[1],xyz[0]);
2180 histoX[1]= pTPCIn->GetTgl();
2181 histoX[2]= phi;
2182 histoX[3]= pTPCIn->GetSnp();
2183 //
2184 Float_t dca[2], cov[3];
2185 pTrack->GetImpactParametersTPC(dca,cov);
882f5c06 2186 for (Int_t ihisto=0; ihisto<5; ihisto++){
be67055b 2187 histoX[0]=pTPCvertex.GetParameter()[ihisto]-lits.GetParameter()[ihisto];
2188 // if (ihisto<2) histoX[0]=dca[ihisto];
9112627b 2189 fResHistoTPCvertex[ihisto]->Fill(histoX);
391ffdb2 2190 }
2191}
2192
2193
2194void AliTPCcalibTime::FillResHistoTPCTRD(const AliExternalTrackParam * pTPCOut, const AliExternalTrackParam * pTRDIn ){
2195 //
2196 // fill resuidual histogram TPCout-TRDin
2197 //
660f0543 2198 if (fMemoryMode<2) return;
391ffdb2 2199 Double_t histoX[4];
2200 Double_t xyz[3];
2201 pTPCOut->GetXYZ(xyz);
2202 Double_t phi= TMath::ATan2(xyz[1],xyz[0]);
2203 histoX[1]= pTPCOut->GetTgl();
2204 histoX[2]= phi;
2205 histoX[3]= pTPCOut->GetSnp();
2206 //
882f5c06 2207 AliExternalTrackParam ltrd(*pTRDIn);
2208 ltrd.Rotate(pTPCOut->GetAlpha());
be67055b 2209 // ltrd.PropagateTo(pTPCOut->GetX(),fMagF);
2210 AliTracker::PropagateTrackToBxByBz(&ltrd,pTPCOut->GetX(),0.1,0.1,kFALSE);
882f5c06 2211
391ffdb2 2212 for (Int_t ihisto=0; ihisto<5; ihisto++){
882f5c06 2213 histoX[0]=pTPCOut->GetParameter()[ihisto]-ltrd.GetParameter()[ihisto];
391ffdb2 2214 fResHistoTPCTRD[ihisto]->Fill(histoX);
2215 }
2216
2217}
0b736a46 2218
2219void AliTPCcalibTime::FillResHistoTPCTOF(const AliExternalTrackParam * pTPCOut, const AliExternalTrackParam * pTOFIn ){
2220 //
2221 // fill resuidual histogram TPCout-TOFin
2222 // track propagated to the TOF position
660f0543 2223 if (fMemoryMode<2) return;
0b736a46 2224 Double_t histoX[4];
2225 Double_t xyz[3];
2226
2227 AliExternalTrackParam ltpc(*pTPCOut);
2228 ltpc.Rotate(pTOFIn->GetAlpha());
2229 AliTracker::PropagateTrackToBxByBz(&ltpc,pTOFIn->GetX(),0.1,0.1,kFALSE);
2230 //
2231 ltpc.GetXYZ(xyz);
2232 Double_t phi= TMath::ATan2(xyz[1],xyz[0]);
2233 histoX[1]= ltpc.GetTgl();
2234 histoX[2]= phi;
2235 histoX[3]= ltpc.GetSnp();
2236 //
2237 for (Int_t ihisto=0; ihisto<2; ihisto++){
2238 histoX[0]=ltpc.GetParameter()[ihisto]-pTOFIn->GetParameter()[ihisto];
2239 fResHistoTPCTOF[ihisto]->Fill(histoX);
2240 }
2241
2242}