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