AliRoot Core  edcc906 (edcc906)
AliTPCcalibDButil.cxx
Go to the documentation of this file.
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 
19 
20 #include <TMath.h>
21 #include <TVectorT.h>
22 #include <TObjArray.h>
23 #include <TGraph.h>
24 #include <TFile.h>
25 #include <TDirectory.h>
26 #include <TMap.h>
27 #include <TGraphErrors.h>
28 #include <AliCDBStorage.h>
29 #include <AliDCSSensorArray.h>
30 #include <AliTPCSensorTempArray.h>
31 #include <AliDCSSensor.h>
32 #include <AliLog.h>
33 #include <AliCDBEntry.h>
34 #include <AliCDBManager.h>
35 #include <AliCDBId.h>
36 #include <AliSplineFit.h>
37 #include "AliTPCcalibDB.h"
38 #include "AliTPCCalPad.h"
39 #include "AliTPCCalROC.h"
40 #include "AliTPCROC.h"
41 #include "AliTPCmapper.h"
42 #include "AliTPCParam.h"
43 #include "AliTPCCalibRaw.h"
45 #include "AliTPCdataQA.h"
46 #include "AliLog.h"
47 #include "AliTPCcalibDButil.h"
48 #include "AliTPCCalibVdrift.h"
49 #include "AliMathBase.h"
50 #include "AliRelAlignerKalman.h"
51 #include "TTree.h"
52 #include "TROOT.h"
53 #include "TKey.h"
54 
55 const Float_t kAlmost0=1.e-30;
56 
58 ClassImp(AliTPCcalibDButil)
61  TObject(),
62  fCalibDB(0),
63  fPadNoise(0x0),
64  fPedestals(0x0),
65  fPulserTmean(0x0),
66  fPulserTrms(0x0),
67  fPulserQmean(0x0),
68  fPulserOutlier(new AliTPCCalPad("PulserOutliers","PulserOutliers")),
69  fCETmean(0x0),
70  fCETrms(0x0),
71  fCEQmean(0x0),
72  fALTROMasked(0x0),
73  fCalibRaw(0x0),
74  fDataQA(0x0),
75  fRefMap(0x0),
76  fCurrentRefMap(0x0),
77  fRefValidity(""),
78  fRefPadNoise(0x0),
79  fRefPedestals(0x0),
80  fRefPedestalMasked(0x0),
81  fRefPulserTmean(0x0),
82  fRefPulserTrms(0x0),
83  fRefPulserQmean(0x0),
84  fRefPulserOutlier(new AliTPCCalPad("RefPulserOutliers","RefPulserOutliers")),
85  fRefPulserMasked(0x0),
86  fRefCETmean(0x0),
87  fRefCETrms(0x0),
88  fRefCEQmean(0x0),
89  fRefCEMasked(0x0),
90  fRefALTROFPED(0x0),
91  fRefALTROZsThr(0x0),
92  fRefALTROAcqStart(0x0),
93  fRefALTROAcqStop(0x0),
94  fRefALTROMasked(0x0),
95  fRefCalibRaw(0x0),
96  fRefDataQA(0x0),
97  fGoofieArray(0x0),
98  fMapper(new AliTPCmapper(0x0)),
99  fNpulserOutliers(-1),
100  fIrocTimeOffset(0),
101  fCETmaxLimitAbs(1.5),
102  fPulTmaxLimitAbs(1.5),
103  fPulQmaxLimitAbs(5),
104  fPulQminLimit(11),
105  fRuns(0), // run list with OCDB info
106  fRunsStart(0), // start time for given run
107  fRunsStop(0) // stop time for given run
108 {
109  //
110  // Default ctor
111  //
112 }
113 //_____________________________________________________________________________________
115 {
117 
118  delete fPulserOutlier;
119  delete fRefPulserOutlier;
120  delete fMapper;
121  if (fRefPadNoise) delete fRefPadNoise;
122  if (fRefPedestals) delete fRefPedestals;
124  if (fRefPulserTmean) delete fRefPulserTmean;
125  if (fRefPulserTrms) delete fRefPulserTrms;
126  if (fRefPulserQmean) delete fRefPulserQmean;
128  if (fRefCETmean) delete fRefCETmean;
129  if (fRefCETrms) delete fRefCETrms;
130  if (fRefCEQmean) delete fRefCEQmean;
131  if (fRefCEMasked) delete fRefCEMasked;
132  if (fRefALTROFPED) delete fRefALTROFPED;
133  if (fRefALTROZsThr) delete fRefALTROZsThr;
136  if (fRefALTROMasked) delete fRefALTROMasked;
137  if (fRefCalibRaw) delete fRefCalibRaw;
138  if (fCurrentRefMap) delete fCurrentRefMap;
139 }
140 //_____________________________________________________________________________________
142 {
144 
146  fCalibDB->UpdateNonRec(); // load all infromation now
160 // SetReferenceRun();
161 // UpdateRefDataFromOCDB();
162 }
163 //_____________________________________________________________________________________
164 void AliTPCcalibDButil::ProcessCEdata(const char* fitFormula, TVectorD &fitResultsA, TVectorD &fitResultsC,
165  Int_t &noutliersCE, Double_t & chi2A, Double_t &chi2C, AliTPCCalPad * const outCE)
166 {
171 
172  //retrieve CE and ALTRO data
173  if (!fCETmean){
174  TString fitString(fitFormula);
175  fitString.ReplaceAll("++","#");
176  Int_t ndim=fitString.CountChar('#')+2;
177  fitResultsA.ResizeTo(ndim);
178  fitResultsC.ResizeTo(ndim);
179  fitResultsA.Zero();
180  fitResultsC.Zero();
181  noutliersCE=-1;
182  return;
183  }
184  noutliersCE=0;
185  //create outlier map
186  AliTPCCalPad *out=0;
187  if (outCE) out=outCE;
188  else out=new AliTPCCalPad("outCE","outCE");
189  AliTPCCalROC *rocMasked=0x0;
190  //loop over all channels
191  for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
192  AliTPCCalROC *rocData=fCETmean->GetCalROC(iroc);
193  if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(iroc);
194  AliTPCCalROC *rocOut=out->GetCalROC(iroc);
195  if (!rocData) {
196  noutliersCE+=AliTPCROC::Instance()->GetNChannels(iroc);
197  rocOut->Add(1.);
198  continue;
199  }
200  //add time offset to IROCs
201  if (iroc<AliTPCROC::Instance()->GetNInnerSector())
202  rocData->Add(fIrocTimeOffset);
203  //select outliers
204  UInt_t nrows=rocData->GetNrows();
205  for (UInt_t irow=0;irow<nrows;++irow){
206  UInt_t npads=rocData->GetNPads(irow);
207  for (UInt_t ipad=0;ipad<npads;++ipad){
208  rocOut->SetValue(irow,ipad,0);
209  //exclude masked pads
210  if (rocMasked && rocMasked->GetValue(irow,ipad)) {
211  rocOut->SetValue(irow,ipad,1);
212  continue;
213  }
214  //exclude first two rows in IROC and last two rows in OROC
215  if (iroc<36){
216  if (irow<2) rocOut->SetValue(irow,ipad,1);
217  } else {
218  if (irow>nrows-3) rocOut->SetValue(irow,ipad,1);
219  }
220  //exclude edge pads
221  if (ipad==0||ipad==npads-1) rocOut->SetValue(irow,ipad,1);
222  Float_t valTmean=rocData->GetValue(irow,ipad);
223  //exclude values that are exactly 0
224  if ( !(TMath::Abs(valTmean)>kAlmost0) ) {
225  rocOut->SetValue(irow,ipad,1);
226  ++noutliersCE;
227  }
228  // exclude channels with too large variations
229  if (TMath::Abs(valTmean)>fCETmaxLimitAbs) {
230  rocOut->SetValue(irow,ipad,1);
231  ++noutliersCE;
232  }
233  }
234  }
235  }
236  //perform fit
237  TMatrixD dummy;
238  Float_t chi2Af,chi2Cf;
239  fCETmean->GlobalSidesFit(out,fitFormula,fitResultsA,fitResultsC,dummy,dummy,chi2Af,chi2Cf);
240  chi2A=chi2Af;
241  chi2C=chi2Cf;
242  if (!outCE) delete out;
243 }
244 //_____________________________________________________________________________________
245 void AliTPCcalibDButil::ProcessCEgraphs(TVectorD &vecTEntries, TVectorD &vecTMean, TVectorD &vecTRMS, TVectorD &vecTMedian,
246  TVectorD &vecQEntries, TVectorD &vecQMean, TVectorD &vecQRMS, TVectorD &vecQMedian,
247  Float_t &driftTimeA, Float_t &driftTimeC )
248 {
250 
251  //reset arrays
252  vecTEntries.ResizeTo(72);
253  vecTMean.ResizeTo(72);
254  vecTRMS.ResizeTo(72);
255  vecTMedian.ResizeTo(72);
256  vecQEntries.ResizeTo(72);
257  vecQMean.ResizeTo(72);
258  vecQRMS.ResizeTo(72);
259  vecQMedian.ResizeTo(72);
260  vecTEntries.Zero();
261  vecTMean.Zero();
262  vecTRMS.Zero();
263  vecTMedian.Zero();
264  vecQEntries.Zero();
265  vecQMean.Zero();
266  vecQRMS.Zero();
267  vecQMedian.Zero();
268  driftTimeA=0;
269  driftTimeC=0;
272  if (arrT){
273  for (Int_t isec=0;isec<74;++isec){
274  TGraph *gr=(TGraph*)arrT->At(isec);
275  if (!gr) continue;
276  TVectorD values;
277  Int_t npoints = gr->GetN();
278  values.ResizeTo(npoints);
279  Int_t nused =0;
280  //skip first points, theres always some problems with finding the CE position
281  for (Int_t ipoint=4; ipoint<npoints; ipoint++){
282  if (gr->GetY()[ipoint]>500 && gr->GetY()[ipoint]<1020 ){
283  values[nused]=gr->GetY()[ipoint];
284  nused++;
285  }
286  }
287  //
288  if (isec<72) vecTEntries[isec]= nused;
289  if (nused>1){
290  if (isec<72){
291  vecTMedian[isec] = TMath::Median(nused,values.GetMatrixArray());
292  vecTMean[isec] = TMath::Mean(nused,values.GetMatrixArray());
293  vecTRMS[isec] = TMath::RMS(nused,values.GetMatrixArray());
294  } else if (isec==72){
295  driftTimeA=TMath::Median(nused,values.GetMatrixArray());
296  } else if (isec==73){
297  driftTimeC=TMath::Median(nused,values.GetMatrixArray());
298  }
299  }
300  }
301  }
302  if (arrQ){
303  for (Int_t isec=0;isec<arrQ->GetEntriesFast();++isec){
304  TGraph *gr=(TGraph*)arrQ->At(isec);
305  if (!gr) continue;
306  TVectorD values;
307  Int_t npoints = gr->GetN();
308  values.ResizeTo(npoints);
309  Int_t nused =0;
310  for (Int_t ipoint=0; ipoint<npoints; ipoint++){
311  if (gr->GetY()[ipoint]>10 && gr->GetY()[ipoint]<500 ){
312  values[nused]=gr->GetY()[ipoint];
313  nused++;
314  }
315  }
316  //
317  vecQEntries[isec]= nused;
318  if (nused>1){
319  vecQMedian[isec] = TMath::Median(nused,values.GetMatrixArray());
320  vecQMean[isec] = TMath::Mean(nused,values.GetMatrixArray());
321  vecQRMS[isec] = TMath::RMS(nused,values.GetMatrixArray());
322  }
323  }
324  }
325 }
326 
327 //_____________________________________________________________________________________
328 void AliTPCcalibDButil::ProcessNoiseData(TVectorD &vNoiseMean, TVectorD &vNoiseMeanSenRegions,
329  TVectorD &vNoiseRMS, TVectorD &vNoiseRMSSenRegions,
330  Int_t &nonMaskedZero, Int_t &nNaN)
331 {
337 
338  //set proper size and reset
339  const UInt_t infoSize=4;
340  vNoiseMean.ResizeTo(infoSize);
341  vNoiseMeanSenRegions.ResizeTo(infoSize);
342  vNoiseRMS.ResizeTo(infoSize);
343  vNoiseRMSSenRegions.ResizeTo(infoSize);
344  vNoiseMean.Zero();
345  vNoiseMeanSenRegions.Zero();
346  vNoiseRMS.Zero();
347  vNoiseRMSSenRegions.Zero();
348  nonMaskedZero=0;
349  nNaN=0;
350  //counters
351  TVectorD c(infoSize);
352  TVectorD cs(infoSize);
353  //tpc parameters
354  AliTPCParam par;
355  par.Update();
356  //retrieve noise and ALTRO data
357  if (!fPadNoise) return;
358  AliTPCCalROC *rocMasked=0x0;
359  //create IROC, OROC1, OROC2 and sensitive region masks
360  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
361  AliTPCCalROC *noiseROC=fPadNoise->GetCalROC(isec);
362  if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(isec);
363  UInt_t nrows=noiseROC->GetNrows();
364  for (UInt_t irow=0;irow<nrows;++irow){
365  UInt_t npads=noiseROC->GetNPads(irow);
366  for (UInt_t ipad=0;ipad<npads;++ipad){
367  //don't use masked channels;
368  if (rocMasked && rocMasked->GetValue(irow,ipad)) continue;
369  Float_t noiseVal=noiseROC->GetValue(irow,ipad);
370  //check if noise==0
371  if (noiseVal<kAlmost0) {
372  ++nonMaskedZero;
373  continue;
374  }
375  //check for nan
376  if ( !(noiseVal<10000000) ){
377  AliInfo(Form("Warning: nan detected in (sec,row,pad - val): %02d,%02d,%03d - %.1f\n",isec,irow,ipad,noiseVal));
378  ++nNaN;
379  continue;
380  }
381  Int_t cpad=(Int_t)ipad-(Int_t)npads/2;
382  Int_t masksen=1; // sensitive pards are not masked (0)
383  if (ipad<2||npads-ipad-1<2) masksen=0; //don't mask edge pads (sensitive)
384  if (isec<AliTPCROC::Instance()->GetNInnerSector()){
385  //IROCs
386  if (irow>19&&irow<46){
387  if (TMath::Abs(cpad)<7) masksen=0; //IROC spot
388  }
389  Int_t type=1;
390  vNoiseMean[type]+=noiseVal;
391  vNoiseRMS[type]+=noiseVal*noiseVal;
392  ++c[type];
393  if (!masksen){
394  vNoiseMeanSenRegions[type]+=noiseVal;
395  vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
396  ++cs[type];
397  }
398  } else {
399  //OROCs
400  //define sensive regions
401  if ((nrows-irow-1)<3) masksen=0; //last three rows in OROCs are sensitive
402  if ( irow>75 ){
403  Int_t padEdge=(Int_t)TMath::Min(ipad,npads-ipad);
404  if (padEdge<((((Int_t)irow-76)/4+1))*2) masksen=0; //OROC outer corners are sensitive
405  }
406  if ((Int_t)irow<par.GetNRowUp1()){
407  //OROC1
408  Int_t type=2;
409  vNoiseMean[type]+=noiseVal;
410  vNoiseRMS[type]+=noiseVal*noiseVal;
411  ++c[type];
412  if (!masksen){
413  vNoiseMeanSenRegions[type]+=noiseVal;
414  vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
415  ++cs[type];
416  }
417  }else{
418  //OROC2
419  Int_t type=3;
420  vNoiseMean[type]+=noiseVal;
421  vNoiseRMS[type]+=noiseVal*noiseVal;
422  ++c[type];
423  if (!masksen){
424  vNoiseMeanSenRegions[type]+=noiseVal;
425  vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
426  ++cs[type];
427  }
428  }
429  }
430  //whole tpc
431  Int_t type=0;
432  vNoiseMean[type]+=noiseVal;
433  vNoiseRMS[type]+=noiseVal*noiseVal;
434  ++c[type];
435  if (!masksen){
436  vNoiseMeanSenRegions[type]+=noiseVal;
437  vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
438  ++cs[type];
439  }
440  }//end loop pads
441  }//end loop rows
442  }//end loop sectors (rocs)
443 
444  //calculate mean and RMS
445  const Double_t verySmall=0.0000000001;
446  for (UInt_t i=0;i<infoSize;++i){
447  Double_t mean=0;
448  Double_t rms=0;
449  Double_t meanSen=0;
450  Double_t rmsSen=0;
451 
452  if (c[i]>verySmall){
453  AliInfo(Form("i: %d - m: %.3f, c: %.0f, r: %.3f\n",i,vNoiseMean[i],c[i],vNoiseRMS[i]));
454  mean=vNoiseMean[i]/c[i];
455  rms=vNoiseRMS[i];
456  rms=TMath::Sqrt(TMath::Abs(rms/c[i]-mean*mean));
457  }
458  vNoiseMean[i]=mean;
459  vNoiseRMS[i]=rms;
460 
461  if (cs[i]>verySmall){
462  meanSen=vNoiseMeanSenRegions[i]/cs[i];
463  rmsSen=vNoiseRMSSenRegions[i];
464  rmsSen=TMath::Sqrt(TMath::Abs(rmsSen/cs[i]-meanSen*meanSen));
465  }
466  vNoiseMeanSenRegions[i]=meanSen;
467  vNoiseRMSSenRegions[i]=rmsSen;
468  }
469 }
470 
471 //_____________________________________________________________________________________
473  TVectorD &vQaQmax)
474 {
478 
479 
480  const UInt_t infoSize = 72;
481  //reset counters to error number
482  vQaOcc.ResizeTo(infoSize);
483  vQaOcc.Zero();
484  vQaQtot.ResizeTo(infoSize);
485  vQaQtot.Zero();
486  vQaQmax.ResizeTo(infoSize);
487  vQaQmax.Zero();
488  //counter
489  //retrieve pulser and ALTRO data
490 
491  if (!fDataQA) {
492 
493  AliInfo("No QA data");
494  return;
495  }
496  if (fDataQA->GetEventCounter()<=0) {
497 
498  AliInfo("No QA data");
499  return; // no data processed
500  }
501  //
502  fDataQA->Analyse();
503 
504  TVectorD normOcc(infoSize);
505  TVectorD normQ(infoSize);
506 
507  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
508 
509  AliInfo(Form("Sector %d\n", isec));
510  AliTPCCalROC* occupancyROC = fDataQA->GetNoThreshold()->GetCalROC(isec);
511  AliTPCCalROC* nclusterROC = fDataQA->GetNLocalMaxima()->GetCalROC(isec);
512  AliTPCCalROC* qROC = fDataQA->GetMeanCharge()->GetCalROC(isec);
513  AliTPCCalROC* qmaxROC = fDataQA->GetMaxCharge()->GetCalROC(isec);
514  if (!occupancyROC) continue;
515  if (!nclusterROC) continue;
516  if (!qROC) continue;
517  if (!qmaxROC) continue;
518 
519  const UInt_t nchannels=occupancyROC->GetNchannels();
520 
521  AliInfo(Form("Nchannels %d\n", nchannels));
522 
523  for (UInt_t ichannel=0;ichannel<nchannels;++ichannel){
524 
525  vQaOcc[isec] += occupancyROC->GetValue(ichannel);
526  ++normOcc[isec];
527 
528  Float_t nClusters = nclusterROC->GetValue(ichannel);
529  normQ[isec] += nClusters;
530  vQaQtot[isec]+=nClusters*qROC->GetValue(ichannel);
531  vQaQmax[isec]+=nClusters*qmaxROC->GetValue(ichannel);
532  }
533  }
534 
535  //calculate mean values
536  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
537 
538  if (normOcc[isec]>0) vQaOcc[isec] /= normOcc[isec];
539  else vQaOcc[isec] = 0;
540 
541  if (normQ[isec]>0) {
542  vQaQtot[isec] /= normQ[isec];
543  vQaQmax[isec] /= normQ[isec];
544  }else {
545 
546  vQaQtot[isec] = 0;
547  vQaQmax[isec] = 0;
548  }
549  }
550 }
551 
552 //_____________________________________________________________________________________
554 {
557 
558  const UInt_t infoSize=4;
559  //reset counters to error number
560  vMeanTime.ResizeTo(infoSize);
561  vMeanTime.Zero();
562  //counter
563  TVectorD c(infoSize);
564  //retrieve pulser and ALTRO data
565  if (!fPulserTmean) return;
566  //
567  //get Outliers
568  AliTPCCalROC *rocOut=0x0;
569  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
570  AliTPCCalROC *tmeanROC=fPulserTmean->GetCalROC(isec);
571  if (!tmeanROC) continue;
572  rocOut=fPulserOutlier->GetCalROC(isec);
573  UInt_t nchannels=tmeanROC->GetNchannels();
574  for (UInt_t ichannel=0;ichannel<nchannels;++ichannel){
575  if (rocOut && rocOut->GetValue(ichannel)) continue;
576  Float_t val=tmeanROC->GetValue(ichannel);
577  Int_t type=isec/18;
578  vMeanTime[type]+=val;
579  ++c[type];
580  }
581  }
582  //calculate mean
583  for (UInt_t itype=0; itype<infoSize; ++itype){
584  if (c[itype]>0) vMeanTime[itype]/=c[itype];
585  else vMeanTime[itype]=0;
586  }
587 }
588 //_____________________________________________________________________________________
590 {
592 
593  nMasked=-1;
594  if (!fALTROMasked) return;
595  nMasked=0;
596  for (Int_t isec=0;isec<fALTROMasked->kNsec; ++isec){
597  AliTPCCalROC *rocMasked=fALTROMasked->GetCalROC(isec);
598  for (UInt_t ichannel=0; ichannel<rocMasked->GetNchannels();++ichannel){
599  if (rocMasked->GetValue(ichannel)) ++nMasked;
600  }
601  }
602 }
603 //_____________________________________________________________________________________
604 void AliTPCcalibDButil::ProcessGoofie(TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS)
605 {
608 
609  /*
610  1 TPC_ANODE_I_A00_STAT
611  2 TPC_DVM_CO2
612  3 TPC_DVM_DriftVelocity
613  4 TPC_DVM_FCageHV
614  5 TPC_DVM_GainFar
615  6 TPC_DVM_GainNear
616  7 TPC_DVM_N2
617  8 TPC_DVM_NumberOfSparks
618  9 TPC_DVM_PeakAreaFar
619  10 TPC_DVM_PeakAreaNear
620  11 TPC_DVM_PeakPosFar
621  12 TPC_DVM_PeakPosNear
622  13 TPC_DVM_PickupHV
623  14 TPC_DVM_Pressure
624  15 TPC_DVM_T1_Over_P
625  16 TPC_DVM_T2_Over_P
626  17 TPC_DVM_T_Over_P
627  18 TPC_DVM_TemperatureS1
628  */
629  if (!fGoofieArray){
630  Int_t nsensors=19;
631  vecEntries.ResizeTo(nsensors);
632  vecMedian.ResizeTo(nsensors);
633  vecMean.ResizeTo(nsensors);
634  vecRMS.ResizeTo(nsensors);
635  vecEntries.Zero();
636  vecMedian.Zero();
637  vecMean.Zero();
638  vecRMS.Zero();
639  return;
640  }
641  Double_t kEpsilon=0.0000000001;
642  Double_t kBig=100000000000.;
643  Int_t nsensors = fGoofieArray->NumSensors();
644  vecEntries.ResizeTo(nsensors);
645  vecMedian.ResizeTo(nsensors);
646  vecMean.ResizeTo(nsensors);
647  vecRMS.ResizeTo(nsensors);
648  TVectorF values;
649  for (Int_t isensor=0; isensor<fGoofieArray->NumSensors();isensor++){
650  AliDCSSensor *gsensor = fGoofieArray->GetSensor(isensor);
651  if (gsensor && gsensor->GetGraph()){
652  Int_t npoints = gsensor->GetGraph()->GetN();
653  // filter zeroes
654  values.ResizeTo(npoints);
655  Int_t nused =0;
656  for (Int_t ipoint=0; ipoint<npoints; ipoint++){
657  if (TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])>kEpsilon &&
658  TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])<kBig ){
659  values[nused]=gsensor->GetGraph()->GetY()[ipoint];
660  nused++;
661  }
662  }
663  //
664  vecEntries[isensor]= nused;
665  if (nused>1){
666  vecMedian[isensor] = TMath::Median(nused,values.GetMatrixArray());
667  vecMean[isensor] = TMath::Mean(nused,values.GetMatrixArray());
668  vecRMS[isensor] = TMath::RMS(nused,values.GetMatrixArray());
669  }
670  }
671  }
672 }
673 //_____________________________________________________________________________________
674 void AliTPCcalibDButil::ProcessPedestalVariations(TVectorF &pedestalDeviations)
675 {
678 
679  const Int_t npar=4;
680  TVectorF vThres(npar); //thresholds
681  Int_t nActive=0; //number of active channels
682 
683  //reset and set thresholds
684  pedestalDeviations.ResizeTo(npar);
685  for (Int_t i=0;i<npar;++i){
686  pedestalDeviations.GetMatrixArray()[i]=0;
687  vThres.GetMatrixArray()[i]=(i+1)*.5;
688  }
689  //check all needed data is available
690  if (!fRefPedestals || !fPedestals || !fALTROMasked || !fRefALTROMasked) return;
691  //loop over all channels
692  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
693  AliTPCCalROC *pROC=fPedestals->GetCalROC(isec);
694  AliTPCCalROC *pRefROC=fRefPedestals->GetCalROC(isec);
695  AliTPCCalROC *mROC=fALTROMasked->GetCalROC(isec);
696  AliTPCCalROC *mRefROC=fRefALTROMasked->GetCalROC(isec);
697  UInt_t nrows=mROC->GetNrows();
698  for (UInt_t irow=0;irow<nrows;++irow){
699  UInt_t npads=mROC->GetNPads(irow);
700  for (UInt_t ipad=0;ipad<npads;++ipad){
701  //don't use masked channels;
702  if (mROC ->GetValue(irow,ipad)) continue;
703  if (mRefROC->GetValue(irow,ipad)) continue;
704  Float_t deviation=TMath::Abs(pROC->GetValue(irow,ipad)-pRefROC->GetValue(irow,ipad));
705  for (Int_t i=0;i<npar;++i){
706  if (deviation>vThres[i])
707  ++pedestalDeviations.GetMatrixArray()[i];
708  }
709  ++nActive;
710  }//end ipad
711  }//ind irow
712  }//end isec
713  if (nActive>0){
714  for (Int_t i=0;i<npar;++i){
715  pedestalDeviations.GetMatrixArray()[i]/=nActive;
716  }
717  }
718 }
719 //_____________________________________________________________________________________
720 void AliTPCcalibDButil::ProcessNoiseVariations(TVectorF &noiseDeviations)
721 {
724 
725  const Int_t npar=4;
726  TVectorF vThres(npar); //thresholds
727  Int_t nActive=0; //number of active channels
728 
729  //reset and set thresholds
730  noiseDeviations.ResizeTo(npar);
731  for (Int_t i=0;i<npar;++i){
732  noiseDeviations.GetMatrixArray()[i]=0;
733  vThres.GetMatrixArray()[i]=(i+1)*.05;
734  }
735  //check all needed data is available
736  if (!fRefPadNoise || !fPadNoise || !fALTROMasked || !fRefALTROMasked) return;
737  //loop over all channels
738  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
739  AliTPCCalROC *nROC=fPadNoise->GetCalROC(isec);
740  AliTPCCalROC *nRefROC=fRefPadNoise->GetCalROC(isec);
741  AliTPCCalROC *mROC=fALTROMasked->GetCalROC(isec);
742  AliTPCCalROC *mRefROC=fRefALTROMasked->GetCalROC(isec);
743  UInt_t nrows=mROC->GetNrows();
744  for (UInt_t irow=0;irow<nrows;++irow){
745  UInt_t npads=mROC->GetNPads(irow);
746  for (UInt_t ipad=0;ipad<npads;++ipad){
747  //don't use masked channels;
748  if (mROC ->GetValue(irow,ipad)) continue;
749  if (mRefROC->GetValue(irow,ipad)) continue;
750  if (nRefROC->GetValue(irow,ipad)==0) continue;
751  Float_t deviation=(nROC->GetValue(irow,ipad)/nRefROC->GetValue(irow,ipad))-1;
752  for (Int_t i=0;i<npar;++i){
753  if (deviation>vThres[i])
754  ++noiseDeviations.GetMatrixArray()[i];
755  }
756  ++nActive;
757  }//end ipad
758  }//ind irow
759  }//end isec
760  if (nActive>0){
761  for (Int_t i=0;i<npar;++i){
762  noiseDeviations.GetMatrixArray()[i]/=nActive;
763  }
764  }
765 }
766 //_____________________________________________________________________________________
767 void AliTPCcalibDButil::ProcessPulserVariations(TVectorF &pulserQdeviations, Float_t &varQMean,
768  Int_t &npadsOutOneTB, Int_t &npadsOffAdd)
769 {
772 
773  const Int_t npar=4;
774  TVectorF vThres(npar); //thresholds
775  Int_t nActive=0; //number of active channels
776 
777  //reset and set thresholds
778  pulserQdeviations.ResizeTo(npar);
779  for (Int_t i=0;i<npar;++i){
780  pulserQdeviations.GetMatrixArray()[i]=0;
781  }
782  npadsOutOneTB=0;
783  npadsOffAdd=0;
784  varQMean=0;
785  vThres.GetMatrixArray()[0]=.005;
786  vThres.GetMatrixArray()[1]=.01;
787  vThres.GetMatrixArray()[2]=.05;
788  vThres.GetMatrixArray()[3]=.1;
789  //check all needed data is available
791  //
793  //loop over all channels
794  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
795  AliTPCCalROC *pqROC=fPulserQmean->GetCalROC(isec);
796  AliTPCCalROC *pqRefROC=fRefPulserQmean->GetCalROC(isec);
797  AliTPCCalROC *ptROC=fPulserTmean->GetCalROC(isec);
798 // AliTPCCalROC *ptRefROC=fRefPulserTmean->GetCalROC(isec);
799  AliTPCCalROC *mROC=fALTROMasked->GetCalROC(isec);
800  AliTPCCalROC *mRefROC=fRefALTROMasked->GetCalROC(isec);
802  Float_t ptmean=ptROC->GetMean(oROC);
803  UInt_t nrows=mROC->GetNrows();
804  for (UInt_t irow=0;irow<nrows;++irow){
805  UInt_t npads=mROC->GetNPads(irow);
806  for (UInt_t ipad=0;ipad<npads;++ipad){
807  //don't use masked channels;
808  if (mROC ->GetValue(irow,ipad)) continue;
809  if (mRefROC->GetValue(irow,ipad)) continue;
810  //don't user edge pads
811  if (ipad==0||ipad==npads-1) continue;
812  //data
813  Float_t pq=pqROC->GetValue(irow,ipad);
814  Float_t pqRef=pqRefROC->GetValue(irow,ipad);
815  Float_t pt=ptROC->GetValue(irow,ipad);
816 // Float_t ptRef=ptRefROC->GetValue(irow,ipad);
817  //comparisons q
818  Float_t deviation=TMath::Abs(pqRef)>1e-20?TMath::Abs(pq/pqRef-1):-999;
819  for (Int_t i=0;i<npar;++i){
820  if (deviation>vThres[i])
821  ++pulserQdeviations.GetMatrixArray()[i];
822  }
823  if (pqRef>11&&pq<11) ++npadsOffAdd;
824  varQMean+=pq-pqRef;
825  //comparisons t
826  if (TMath::Abs(pt-ptmean)>1) ++npadsOutOneTB;
827  ++nActive;
828  }//end ipad
829  }//ind irow
830  }//end isec
831  if (nActive>0){
832  for (Int_t i=0;i<npar;++i){
833  pulserQdeviations.GetMatrixArray()[i]/=nActive;
834  varQMean/=nActive;
835  }
836  }
837 }
838 //_____________________________________________________________________________________
840 {
842 
844 }
845 //_____________________________________________________________________________________
847 {
849 
851 }
852 //_____________________________________________________________________________________
854 {
860 
861  if (!pulT||!pulQ) {
862  //reset map
863  pulOut->Multiply(0.);
864  fNpulserOutliers=-1;
865  return;
866  }
867  AliTPCCalROC *rocMasked=0x0;
869 
870  //Create Outlier Map
871  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
872  AliTPCCalROC *tmeanROC=pulT->GetCalROC(isec);
873  AliTPCCalROC *qmeanROC=pulQ->GetCalROC(isec);
874  AliTPCCalROC *outROC=pulOut->GetCalROC(isec);
875  if (!tmeanROC||!qmeanROC) {
876  //reset outliers in this ROC
877  outROC->Multiply(0.);
878  continue;
879  }
880  if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(isec);
881 // Double_t dummy=0;
882 // Float_t qmedian=qmeanROC->GetLTM(&dummy,.5);
883 // Float_t tmedian=tmeanROC->GetLTM(&dummy,.5);
884  UInt_t nrows=tmeanROC->GetNrows();
885  for (UInt_t irow=0;irow<nrows;++irow){
886  UInt_t npads=tmeanROC->GetNPads(irow);
887  for (UInt_t ipad=0;ipad<npads;++ipad){
888  Int_t outlier=0,masked=0;
889  Float_t q=qmeanROC->GetValue(irow,ipad);
890  Float_t t=tmeanROC->GetValue(irow,ipad);
891  //masked channels are outliers
892  if (rocMasked && rocMasked->GetValue(irow,ipad)) masked=1;
893  //edge pads are outliers
894  if (ipad==0||ipad==npads-1) masked=1;
895  //channels with too large charge or timing deviation from the meadian are outliers
896 // if (TMath::Abs(q-qmedian)>fPulQmaxLimitAbs || TMath::Abs(t-tmedian)>fPulTmaxLimitAbs) outlier=1;
897  if (q<fPulQminLimit && !masked) outlier=1;
898  //check for nan
899  if ( !(q<10000000) || !(t<10000000)) outlier=1;
900  outROC->SetValue(irow,ipad,outlier+masked);
901  fNpulserOutliers+=outlier;
902  }
903  }
904  }
905 }
906 //_____________________________________________________________________________________
907 AliTPCCalPad* AliTPCcalibDButil::CreatePadTime0(Int_t model, Double_t &gyA, Double_t &gyC, Double_t &chi2A, Double_t &chi2C )
908 {
915 
916  gyA=0;
917  gyC=0;
918  AliTPCCalPad *padTime0=new AliTPCCalPad("PadTime0",Form("PadTime0-Model_%d",model));
919  // decide between different models
920  if (model==0||model==1){
921  TVectorD vMean;
922  if (model==1) ProcessPulser(vMean);
923  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
924  AliTPCCalROC *rocPulTmean=fPulserTmean->GetCalROC(isec);
925  if (!rocPulTmean) continue;
926  AliTPCCalROC *rocTime0=padTime0->GetCalROC(isec);
927  AliTPCCalROC *rocOut=fPulserOutlier->GetCalROC(isec);
928  Float_t mean=rocPulTmean->GetMean(rocOut);
929  //treat case where a whole partition is masked
930  if ( TMath::Abs(mean)<kAlmost0 ) mean=rocPulTmean->GetMean();
931  if (model==1) {
932  Int_t type=isec/18;
933  mean=vMean[type];
934  }
935  UInt_t nrows=rocTime0->GetNrows();
936  for (UInt_t irow=0;irow<nrows;++irow){
937  UInt_t npads=rocTime0->GetNPads(irow);
938  for (UInt_t ipad=0;ipad<npads;++ipad){
939  Float_t time=rocPulTmean->GetValue(irow,ipad);
940  //in case of an outlier pad use the mean of the altro values.
941  //This should be the most precise guess in that case.
942  if (rocOut->GetValue(irow,ipad)) {
943  time=GetMeanAltro(rocPulTmean,irow,ipad,rocOut);
944  if ( TMath::Abs(time)<kAlmost0 ) time=mean;
945  }
946  Float_t val=time-mean;
947  rocTime0->SetValue(irow,ipad,val);
948  }
949  }
950  }
951  } else if (model==2){
952  Double_t pgya,pgyc,pchi2a,pchi2c;
953  AliTPCCalPad * padPulser = CreatePadTime0(1,pgya,pgyc,pchi2a,pchi2c);
954  fCETmean->Add(padPulser,-1.);
955  TVectorD vA,vC;
956  AliTPCCalPad outCE("outCE","outCE");
957  Int_t nOut;
958  ProcessCEdata("(sector<36)++gy++gx++(lx-134)++(sector<36)*(lx-134)++(ly/lx)^2",vA,vC,nOut,chi2A, chi2C,&outCE);
959  AliTPCCalPad *padFit=AliTPCCalPad::CreateCalPadFit("1++0++gy++0++(lx-134)++0++0",vA,vC);
960 // AliTPCCalPad *padFit=AliTPCCalPad::CreateCalPadFit("1++(sector<36)++gy++gx++(lx-134)++(sector<36)*(lx-134)",vA,vC);
961  if (!padFit) { delete padPulser; return 0;}
962  gyA=vA[2];
963  gyC=vC[2];
964  fCETmean->Add(padPulser,1.);
965  padTime0->Add(fCETmean);
966  padTime0->Add(padFit,-1);
967  delete padPulser;
968  TVectorD vFitROC;
969  TMatrixD mFitROC;
970  Float_t chi2;
971  for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
972  AliTPCCalROC *rocPulTmean=fPulserTmean->GetCalROC(isec);
973  AliTPCCalROC *rocTime0=padTime0->GetCalROC(isec);
974  AliTPCCalROC *rocOutPul=fPulserOutlier->GetCalROC(isec);
975  AliTPCCalROC *rocOutCE=outCE.GetCalROC(isec);
976  rocTime0->GlobalFit(rocOutCE,kFALSE,vFitROC,mFitROC,chi2);
977  AliTPCCalROC *rocCEfit=AliTPCCalROC::CreateGlobalFitCalROC(vFitROC, isec);
978  Float_t mean=rocPulTmean->GetMean(rocOutPul);
979  if ( TMath::Abs(mean)<kAlmost0 ) mean=rocPulTmean->GetMean();
980  UInt_t nrows=rocTime0->GetNrows();
981  for (UInt_t irow=0;irow<nrows;++irow){
982  UInt_t npads=rocTime0->GetNPads(irow);
983  for (UInt_t ipad=0;ipad<npads;++ipad){
984  Float_t timePulser=rocPulTmean->GetValue(irow,ipad)-mean;
985  if (rocOutCE->GetValue(irow,ipad)){
986  Float_t valOut=rocCEfit->GetValue(irow,ipad);
987  if (!rocOutPul->GetValue(irow,ipad)) valOut+=timePulser;
988  rocTime0->SetValue(irow,ipad,valOut);
989  }
990  }
991  }
992  delete rocCEfit;
993  }
994  delete padFit;
995  }
996  Double_t median = padTime0->GetMedian();
997  padTime0->Add(-median); // normalize to median
998  return padTime0;
999 }
1000 //_____________________________________________________________________________________
1001 Float_t AliTPCcalibDButil::GetMeanAltro(const AliTPCCalROC *roc, const Int_t row, const Int_t pad, AliTPCCalROC *const rocOut)
1002 {
1004 
1005  if (roc==0) return 0.;
1006  const Int_t sector=roc->GetSector();
1007  AliTPCROC *tpcRoc=AliTPCROC::Instance();
1008  const UInt_t altroRoc=fMapper->GetFEC(sector,row,pad)*8+fMapper->GetChip(sector,row,pad);
1009  Float_t mean=0;
1010  Int_t n=0;
1011 
1012  //loop over a small range around the requested pad (+-10 rows/pads)
1013  for (Int_t irow=row-10;irow<row+10;++irow){
1014  if (irow<0||irow>(Int_t)tpcRoc->GetNRows(sector)-1) continue;
1015  for (Int_t ipad=pad-10; ipad<pad+10;++ipad){
1016  if (ipad<0||ipad>(Int_t)tpcRoc->GetNPads(sector,irow)-1) continue;
1017  const UInt_t altroCurr=fMapper->GetFEC(sector,irow,ipad)*8+fMapper->GetChip(sector,irow,ipad);
1018  if (altroRoc!=altroCurr) continue;
1019  if ( rocOut && rocOut->GetValue(irow,ipad) ) continue;
1020  Float_t val=roc->GetValue(irow,ipad);
1021  mean+=val;
1022  ++n;
1023  }
1024  }
1025  if (n>0) mean/=n;
1026  return mean;
1027 }
1028 //_____________________________________________________________________________________
1029 void AliTPCcalibDButil::SetRefFile(const char* filename)
1030 {
1032 
1033  TDirectory *currDir=gDirectory;
1034  TFile f(filename);
1035  fRefPedestals=(AliTPCCalPad*)f.Get("Pedestals");
1036  fRefPadNoise=(AliTPCCalPad*)f.Get("PadNoise");
1037  //pulser data
1038  fRefPulserTmean=(AliTPCCalPad*)f.Get("PulserTmean");
1039  fRefPulserTrms=(AliTPCCalPad*)f.Get("PulserTrms");
1040  fRefPulserQmean=(AliTPCCalPad*)f.Get("PulserQmean");
1041  //CE data
1042  fRefCETmean=(AliTPCCalPad*)f.Get("CETmean");
1043  fRefCETrms=(AliTPCCalPad*)f.Get("CETrms");
1044  fRefCEQmean=(AliTPCCalPad*)f.Get("CEQmean");
1045  //Altro data
1046 // fRefALTROAcqStart=(AliTPCCalPad*)f.Get("ALTROAcqStart");
1047 // fRefALTROZsThr=(AliTPCCalPad*)f.Get("ALTROZsThr");
1048 // fRefALTROFPED=(AliTPCCalPad*)f.Get("ALTROFPED");
1049 // fRefALTROAcqStop=(AliTPCCalPad*)f.Get("ALTROAcqStop");
1050  fRefALTROMasked=(AliTPCCalPad*)f.Get("ALTROMasked");
1051  f.Close();
1052  currDir->cd();
1053 }
1054 //_____________________________________________________________________________________
1056 {
1058 
1059  if (!fRefMap) {
1060  AliWarning("Referenc map not set!");
1061  return;
1062  }
1063 
1064  TString cdbPath;
1065  AliCDBEntry* entry = 0x0;
1066  Bool_t hasAnyChanged=kFALSE;
1067 
1068  //pedestals
1069  cdbPath="TPC/Calib/Pedestals";
1070  if (HasRefChanged(cdbPath.Data())){
1071  hasAnyChanged=kTRUE;
1072  //delete old entries
1073  if (fRefPedestals) delete fRefPedestals;
1076  //get new entries
1077  entry=GetRefEntry(cdbPath.Data());
1078  if (entry){
1079  entry->SetOwner(kTRUE);
1080  fRefPedestals=GetRefCalPad(entry);
1081  delete entry;
1082  fRefPedestalMasked=GetAltroMasked(cdbPath, "MaskedPedestals");
1083  }
1084  }
1085 
1086  //noise
1087  cdbPath="TPC/Calib/PadNoise";
1088  if (HasRefChanged(cdbPath.Data())){
1089  hasAnyChanged=kTRUE;
1090  //delete old entry
1091  if (fRefPadNoise) delete fRefPadNoise;
1092  fRefPadNoise=0x0;
1093  //get new entry
1094  entry=GetRefEntry(cdbPath.Data());
1095  if (entry){
1096  entry->SetOwner(kTRUE);
1097  fRefPadNoise=GetRefCalPad(entry);
1098  delete entry;
1099  }
1100  }
1101 
1102  //pulser
1103  cdbPath="TPC/Calib/Pulser";
1104  if (HasRefChanged(cdbPath.Data())){
1105  hasAnyChanged=kTRUE;
1106  //delete old entries
1107  if (fRefPulserTmean) delete fRefPulserTmean;
1108  if (fRefPulserTrms) delete fRefPulserTrms;
1109  if (fRefPulserQmean) delete fRefPulserQmean;
1110  if (fRefPulserMasked) delete fRefPulserMasked;
1112  //get new entries
1113  entry=GetRefEntry(cdbPath.Data());
1114  if (entry){
1115  entry->SetOwner(kTRUE);
1116  fRefPulserTmean=GetRefCalPad(entry,"PulserTmean");
1117  fRefPulserTrms=GetRefCalPad(entry,"PulserTrms");
1118  fRefPulserQmean=GetRefCalPad(entry,"PulserQmean");
1119  delete entry;
1120  fRefPulserMasked=GetAltroMasked(cdbPath, "MaskedPulser");
1121  }
1122  }
1123 
1124  //ce
1125  cdbPath="TPC/Calib/CE";
1126  if (HasRefChanged(cdbPath.Data())){
1127  hasAnyChanged=kTRUE;
1128  //delete old entries
1129  if (fRefCETmean) delete fRefCETmean;
1130  if (fRefCETrms) delete fRefCETrms;
1131  if (fRefCEQmean) delete fRefCEQmean;
1132  if (fRefCEMasked) delete fRefCEMasked;
1134  //get new entries
1135  entry=GetRefEntry(cdbPath.Data());
1136  if (entry){
1137  entry->SetOwner(kTRUE);
1138  fRefCETmean=GetRefCalPad(entry,"CETmean");
1139  fRefCETrms=GetRefCalPad(entry,"CETrms");
1140  fRefCEQmean=GetRefCalPad(entry,"CEQmean");
1141  delete entry;
1142  fRefCEMasked=GetAltroMasked(cdbPath, "MaskedCE");
1143  }
1144  }
1145 
1146  //altro data
1147  cdbPath="TPC/Calib/AltroConfig";
1148  if (HasRefChanged(cdbPath.Data())){
1149  hasAnyChanged=kTRUE;
1150  //delete old entries
1151  if (fRefALTROFPED) delete fRefALTROFPED;
1152  if (fRefALTROZsThr) delete fRefALTROZsThr;
1154  if (fRefALTROAcqStop) delete fRefALTROAcqStop;
1155  if (fRefALTROMasked) delete fRefALTROMasked;
1157  //get new entries
1158  entry=GetRefEntry(cdbPath.Data());
1159  if (entry){
1160  entry->SetOwner(kTRUE);
1161  fRefALTROFPED=GetRefCalPad(entry,"FPED");
1162  fRefALTROZsThr=GetRefCalPad(entry,"ZsThr");
1163  fRefALTROAcqStart=GetRefCalPad(entry,"AcqStart");
1164  fRefALTROAcqStop=GetRefCalPad(entry,"AcqStop");
1165  fRefALTROMasked=GetRefCalPad(entry,"Masked");
1166  delete entry;
1167  }
1168  }
1169 
1170  //raw data
1171  /*
1172  cdbPath="TPC/Calib/Raw";
1173  if (HasRefChanged(cdbPath.Data())){
1174  hasAnyChanged=kTRUE;
1175  //delete old entry
1176  if (fRefCalibRaw) delete fRefCalibRaw;
1177  //get new entry
1178  entry=GetRefEntry(cdbPath.Data());
1179  if (entry){
1180  entry->SetOwner(kTRUE);
1181  TObjArray *arr=(TObjArray*)entry->GetObject();
1182  if (!arr){
1183  AliError(Form("Could not get object from entry '%s'\nPlease check!!!",entry->GetId().GetPath().Data()));
1184  } else {
1185  fRefCalibRaw=(AliTPCCalibRaw*)arr->At(0)->Clone();
1186  }
1187  }
1188  }
1189  */
1190 
1191  //data qa
1192  cdbPath="TPC/Calib/QA";
1193  if (HasRefChanged(cdbPath.Data())){
1194  hasAnyChanged=kTRUE;
1195  //delete old entry
1196  if (fRefDataQA) delete fRefDataQA;
1197  //get new entry
1198  entry=GetRefEntry(cdbPath.Data());
1199  if (entry){
1200  entry->SetOwner(kTRUE);
1201  fRefDataQA=dynamic_cast<AliTPCdataQA*>(entry->GetObject());
1202  if (!fRefDataQA){
1203  AliError(Form("Could not get object from entry '%s'\nPlease check!!!",entry->GetId().GetPath().Data()));
1204  } else {
1205  fRefDataQA=(AliTPCdataQA*)fRefDataQA->Clone();
1206  }
1207  delete entry;
1208  }
1209  }
1210 
1211 
1212 //update current reference maps
1213  if (hasAnyChanged){
1214  if (fCurrentRefMap) delete fCurrentRefMap;
1215  fCurrentRefMap=(TMap*)fRefMap->Clone();
1216  }
1217 }
1218 //_____________________________________________________________________________________
1220 {
1223 
1224  AliTPCCalPad *pad=0x0;
1225  TObjArray *arr=(TObjArray*)entry->GetObject();
1226  if (!arr){
1227  AliError(Form("Could not get object from entry '%s'\nPlease check!!!",entry->GetId().GetPath().Data()));
1228  return pad;
1229  }
1230  pad=(AliTPCCalPad*)arr->FindObject(objName);
1231  if (!pad) {
1232  AliError(Form("Could not get '%s' from TObjArray in entry '%s'\nPlease check!!!",objName,entry->GetId().GetPath().Data()));
1233  return pad;
1234  }
1235  return (AliTPCCalPad*)pad->Clone();
1236 }
1237 //_____________________________________________________________________________________
1239 {
1242 
1243  AliTPCCalPad *pad=(AliTPCCalPad*)entry->GetObject();
1244  if (!pad) {
1245  AliError(Form("Could not get object from entry '%s'\nPlease check!!!",entry->GetId().GetPath().Data()));
1246  return 0x0;
1247  }
1248  pad=(AliTPCCalPad*)pad->Clone();
1249  return pad;
1250 }
1251 //_____________________________________________________________________________________
1252 AliTPCCalPad* AliTPCcalibDButil::GetAltroMasked(const char* cdbPath, const char* name)
1253 {
1255 
1256  AliTPCCalPad* pad=0x0;
1257  const Int_t run=GetReferenceRun(cdbPath);
1258  if (run<0) {
1259  AliError(Form("Could not get reference run number for object '%s'\nPlease check availability!!!",cdbPath));
1260  return pad;
1261  }
1262  AliCDBEntry *entry=AliCDBManager::Instance()->Get("TPC/Calib/AltroConfig", run);
1263  if (!entry) {
1264  AliError(Form("Could not get reference object '%s'\nPlease check availability!!!",cdbPath));
1265  return pad;
1266  }
1267  pad=GetRefCalPad(entry,"Masked");
1268  if (pad) pad->SetNameTitle(name,name);
1269  entry->SetOwner(kTRUE);
1270  delete entry;
1271  return pad;
1272 }
1273 //_____________________________________________________________________________________
1276 
1277  if (run<0) run=fCalibDB->GetRun();
1278  TString cdbPath="TPC/Calib/Ref";
1279  AliCDBEntry *entry=AliCDBManager::Instance()->Get(cdbPath.Data(), run);
1280  if (!entry) {
1281  AliError(Form("Could not get reference object '%s'\nPlease check availability!!!",cdbPath.Data()));
1282  fRefMap=0;
1283  return;
1284  }
1285  entry->SetOwner(kTRUE);
1286  fRefMap=(TMap*)(entry->GetObject());
1287  AliCDBId &id=entry->GetId();
1288  fRefValidity.Form("%d_%d_v%d_s%d",id.GetFirstRun(),id.GetLastRun(),id.GetVersion(),id.GetSubVersion());
1289 }
1290 //_____________________________________________________________________________________
1291 Bool_t AliTPCcalibDButil::HasRefChanged(const char *cdbPath)
1292 {
1294 
1295  if (!fCurrentRefMap) return kTRUE;
1296  if (GetReferenceRun(cdbPath)!=GetCurrentReferenceRun(cdbPath)) return kTRUE;
1297  return kFALSE;
1298 }
1299 //_____________________________________________________________________________________
1301 {
1303 
1304  const Int_t run=GetReferenceRun(cdbPath);
1305  if (run<0) {
1306  AliError(Form("Could not get reference run number for object '%s'\nPlease check availability!!!",cdbPath));
1307  return 0;
1308  }
1309  AliCDBEntry *entry=AliCDBManager::Instance()->Get(cdbPath, run);
1310  if (!entry) {
1311  AliError(Form("Could not get reference object '%s'\nPlease check availability!!!",cdbPath));
1312  return 0;
1313  }
1314  return entry;
1315 }
1316 //_____________________________________________________________________________________
1317 Int_t AliTPCcalibDButil::GetCurrentReferenceRun(const char* type) const {
1319 
1320  if (!fCurrentRefMap) return -2;
1321  TObjString *str=dynamic_cast<TObjString*>(fCurrentRefMap->GetValue(type));
1322  if (!str) return -2;
1323  return (Int_t)str->GetString().Atoi();
1324 }
1325 //_____________________________________________________________________________________
1326 Int_t AliTPCcalibDButil::GetReferenceRun(const char* type) const{
1328 
1329  if (!fRefMap) return -1;
1330  TObjString *str=dynamic_cast<TObjString*>(fRefMap->GetValue(type));
1331  if (!str) return -1;
1332  return (Int_t)str->GetString().Atoi();
1333 }
1334 //_____________________________________________________________________________________
1335 AliTPCCalPad *AliTPCcalibDButil::CreateCEOutlyerMap( Int_t & noutliersCE, AliTPCCalPad * const ceOut, Float_t minSignal, Float_t cutTrmsMin, Float_t cutTrmsMax, Float_t cutMaxDistT){
1355 
1356  noutliersCE=0;
1357  //create outlier map
1358  AliTPCCalPad *out=ceOut;
1359  if (!out) out= new AliTPCCalPad("outCE","outCE");
1360  AliTPCCalROC *rocMasked=0x0;
1361  if (!fCETmean) return 0;
1362  if (!fCETrms) return 0;
1363  if (!fCEQmean) return 0;
1364  //
1365  //loop over all channels
1366  //
1367  Double_t rmsMedian = fCETrms->GetMedian();
1368  for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
1369  AliTPCCalROC *rocData=fCETmean->GetCalROC(iroc);
1370  if (!rocData) continue;
1371  if (fALTROMasked) rocMasked= fALTROMasked->GetCalROC(iroc);
1372  AliTPCCalROC *rocOut = out->GetCalROC(iroc);
1373  AliTPCCalROC *rocCEQ = fCEQmean->GetCalROC(iroc);
1374  AliTPCCalROC *rocCETrms = fCETrms->GetCalROC(iroc);
1375  Double_t trocMedian = rocData->GetMedian();
1376  //
1377  if (!rocData || !rocCEQ || !rocCETrms || !rocData) {
1378  noutliersCE+=AliTPCROC::Instance()->GetNChannels(iroc);
1379  rocOut->Add(1.);
1380  continue;
1381  }
1382  //
1383  //select outliers
1384  UInt_t nrows=rocData->GetNrows();
1385  for (UInt_t irow=0;irow<nrows;++irow){
1386  UInt_t npads=rocData->GetNPads(irow);
1387  for (UInt_t ipad=0;ipad<npads;++ipad){
1388  rocOut->SetValue(irow,ipad,0);
1389  Float_t valTmean=rocData->GetValue(irow,ipad);
1390  Float_t valQmean=rocCEQ->GetValue(irow,ipad);
1391  Float_t valTrms =rocCETrms->GetValue(irow,ipad);
1392  //0. exclude masked pads
1393  if (rocMasked && rocMasked->GetValue(irow,ipad)) {
1394  rocOut->SetValue(irow,ipad,1);
1395  continue;
1396  }
1397  //1. exclude first two rows in IROC and last two rows in OROC
1398  if (iroc<36){
1399  if (irow<2) rocOut->SetValue(irow,ipad,1);
1400  } else {
1401  if (irow>nrows-3) rocOut->SetValue(irow,ipad,1);
1402  }
1403  //2. exclude edge pads
1404  if (ipad==0||ipad==npads-1) rocOut->SetValue(irow,ipad,1);
1405  //exclude values that are exactly 0
1406  if ( TMath::Abs(valTmean)<kAlmost0) {
1407  rocOut->SetValue(irow,ipad,1);
1408  ++noutliersCE;
1409  }
1410  //3. exclude channels with too large variations
1411  if (TMath::Abs(valTmean)>fCETmaxLimitAbs) {
1412  rocOut->SetValue(irow,ipad,1);
1413  ++noutliersCE;
1414  }
1415  //
1416  //4. exclude channels with too small signal
1417  if (valQmean<minSignal) {
1418  rocOut->SetValue(irow,ipad,1);
1419  ++noutliersCE;
1420  }
1421  //
1422  //5. exclude channels with too small rms
1423  if (valTrms<cutTrmsMin*rmsMedian || valTrms>cutTrmsMax*rmsMedian){
1424  rocOut->SetValue(irow,ipad,1);
1425  ++noutliersCE;
1426  }
1427  //
1428  //6. exclude channels to far from the chamber median
1429  if (TMath::Abs(valTmean-trocMedian)>cutMaxDistT){
1430  rocOut->SetValue(irow,ipad,1);
1431  ++noutliersCE;
1432  }
1433  }
1434  }
1435  }
1436  //
1437  return out;
1438 }
1439 
1440 
1441 AliTPCCalPad *AliTPCcalibDButil::CreatePulserOutlyerMap(Int_t &noutliersPulser, AliTPCCalPad * const pulserOut,Float_t cutTime, Float_t cutnRMSQ, Float_t cutnRMSrms){
1456 
1457  noutliersPulser=0;
1458  AliTPCCalPad *out=pulserOut;
1459  if (!out) out= new AliTPCCalPad("outPulser","outPulser");
1460  AliTPCCalROC *rocMasked=0x0;
1461  if (!fPulserTmean) return 0;
1462  if (!fPulserTrms) return 0;
1463  if (!fPulserQmean) return 0;
1464  //
1465  //loop over all channels
1466  //
1467  for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
1468  if (fALTROMasked) rocMasked= fALTROMasked->GetCalROC(iroc);
1469  AliTPCCalROC *rocData = fPulserTmean->GetCalROC(iroc);
1470  AliTPCCalROC *rocOut = out->GetCalROC(iroc);
1471  AliTPCCalROC *rocPulserQ = fPulserQmean->GetCalROC(iroc);
1472  AliTPCCalROC *rocPulserTrms = fPulserTrms->GetCalROC(iroc);
1473  //
1474  Double_t rocMedianT = rocData->GetMedian();
1475  Double_t rocMedianQ = rocPulserQ->GetMedian();
1476  Double_t rocRMSQ = rocPulserQ->GetRMS();
1477  Double_t rocMedianTrms = rocPulserTrms->GetMedian();
1478  Double_t rocRMSTrms = rocPulserTrms->GetRMS();
1479  for (UInt_t ichannel=0;ichannel<rocData->GetNchannels();++ichannel){
1480  rocOut->SetValue(ichannel,0);
1481  Float_t valTmean=rocData->GetValue(ichannel);
1482  Float_t valQmean=rocPulserQ->GetValue(ichannel);
1483  Float_t valTrms =rocPulserTrms->GetValue(ichannel);
1484  Float_t valMasked =0;
1485  if (rocMasked) valMasked = rocMasked->GetValue(ichannel);
1486  Int_t isOut=0;
1487  if (valMasked>0.5) isOut=1;
1488  if (TMath::Abs(valTmean-rocMedianT)>cutTime) isOut=1;
1489  if (TMath::Abs(valQmean-rocMedianQ)>cutnRMSQ*rocRMSQ) isOut=1;
1490  if (TMath::Abs(valTrms-rocMedianTrms)>cutnRMSrms*rocRMSTrms) isOut=1;
1491  rocOut->SetValue(ichannel,isOut);
1492  if (isOut) noutliersPulser++;
1493  }
1494  }
1495  return out;
1496 }
1497 
1498 
1499 AliTPCCalPad *AliTPCcalibDButil::CreatePadTime0CE(TVectorD &fitResultsA, TVectorD&fitResultsC, Int_t &nOut, Double_t &chi2A, Double_t &chi2C, const char *dumpfile){
1531 
1532  // fit formula
1533  const char *formulaIn="(-1.+2.*(sector<36))*0.5++gx++gy++(lx-134.)++(-1.+2.*(sector<36))*0.5*(lx-134)++((ly/lx)^2/(0.1763)^2)";
1534  // output for fit formula
1535  const char *formulaAll="1++(-1.+2.*(sector<36))*0.5++gx++gy++(lx-134.)++(-1.+2.*(sector<36))*0.5*(lx-134)++((ly/lx)^2/(0.1763)^2)";
1536  // gy part of formula
1537  const char *formulaOut="0++0*(-1.+2.*(sector<36))*0.5++0*gx++gy++0*(lx-134.)++0*(-1.+2.*(sector<36))*0.5*(lx-134)++0*((ly/lx)^2/(0.1763)^2)";
1538  //
1539  //
1540  if (!fCETmean) return 0;
1541  Double_t pgya,pgyc,pchi2a,pchi2c;
1542  AliTPCCalPad * padPulserOut = CreatePulserOutlyerMap(nOut);
1543  AliTPCCalPad * padCEOut = CreateCEOutlyerMap(nOut);
1544 
1545  AliTPCCalPad * padPulser = CreatePadTime0(1,pgya,pgyc,pchi2a,pchi2c);
1546  AliTPCCalPad * padCE = new AliTPCCalPad(*fCETmean);
1547  AliTPCCalPad * padCEIn = new AliTPCCalPad(*fCETmean);
1548  AliTPCCalPad * padOut = new AliTPCCalPad("padOut","padOut");
1549  padPulser->SetName("padPulser");
1550  padPulserOut->SetName("padPulserOut");
1551  padCE->SetName("padCE");
1552  padCEIn->SetName("padCEIn");
1553  padCEOut->SetName("padCEOut");
1554  padOut->SetName("padOut");
1555 
1556  //
1557  // make combined outlyers map
1558  // and replace outlyers in maps with median for chamber
1559  //
1560  for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
1561  AliTPCCalROC * rocOut = padOut->GetCalROC(iroc);
1562  AliTPCCalROC * rocPulser = padPulser->GetCalROC(iroc);
1563  AliTPCCalROC * rocPulserOut = padPulserOut->GetCalROC(iroc);
1564  AliTPCCalROC * rocCEOut = padCEOut->GetCalROC(iroc);
1565  AliTPCCalROC * rocCE = padCE->GetCalROC(iroc);
1566  Double_t ceMedian = rocCE->GetMedian(rocCEOut);
1567  Double_t pulserMedian = rocPulser->GetMedian(rocCEOut);
1568  for (UInt_t ichannel=0;ichannel<rocOut->GetNchannels();++ichannel){
1569  if (rocPulserOut->GetValue(ichannel)>0) {
1570  rocPulser->SetValue(ichannel,pulserMedian);
1571  rocOut->SetValue(ichannel,1);
1572  }
1573  if (rocCEOut->GetValue(ichannel)>0) {
1574  rocCE->SetValue(ichannel,ceMedian);
1575  rocOut->SetValue(ichannel,1);
1576  }
1577  }
1578  }
1579  //
1580  // remove pulser time 0
1581  //
1582  padCE->Add(padPulser,-1);
1583  //
1584  // Make fits
1585  //
1586  TMatrixD dummy;
1587  Float_t chi2Af,chi2Cf;
1588  padCE->GlobalSidesFit(padOut,formulaIn,fitResultsA,fitResultsC,dummy,dummy,chi2Af,chi2Cf);
1589  chi2A=chi2Af;
1590  chi2C=chi2Cf;
1591  //
1592  AliTPCCalPad *padCEFitGY=AliTPCCalPad::CreateCalPadFit(formulaOut,fitResultsA,fitResultsC);
1593  padCEFitGY->SetName("padCEFitGy");
1594  //
1595  AliTPCCalPad *padCEFit =AliTPCCalPad::CreateCalPadFit(formulaAll,fitResultsA,fitResultsC);
1596  padCEFit->SetName("padCEFit");
1597  //
1598  AliTPCCalPad* padCEDiff = new AliTPCCalPad(*padCE);
1599  padCEDiff->SetName("padCEDiff");
1600  padCEDiff->Add(padCEFit,-1.);
1601  //
1602  //
1603  padCE->Add(padCEFitGY,-1.);
1604 
1605  padCE->Add(padPulser,1.);
1606  Double_t padmedian = padCE->GetMedian();
1607  padCE->Add(-padmedian); // normalize to median
1608  //
1609  // Replace outliers by fit value - median of diff per given chamber -GY fit
1610  //
1611  for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
1612  AliTPCCalROC * rocOut = padOut->GetCalROC(iroc);
1613  AliTPCCalROC * rocCE = padCE->GetCalROC(iroc);
1614  AliTPCCalROC * rocCEFit = padCEFit->GetCalROC(iroc);
1615  AliTPCCalROC * rocCEFitGY = padCEFitGY->GetCalROC(iroc);
1616  AliTPCCalROC * rocCEDiff = padCEDiff->GetCalROC(iroc);
1617  //
1618  Double_t diffMedian = rocCEDiff->GetMedian(rocOut);
1619  for (UInt_t ichannel=0;ichannel<rocOut->GetNchannels();++ichannel){
1620  if (rocOut->GetValue(ichannel)==0) continue;
1621  Float_t value=rocCEFit->GetValue(ichannel)-rocCEFitGY->GetValue(ichannel)-diffMedian-padmedian;
1622  rocCE->SetValue(ichannel,value);
1623  }
1624  }
1625  //
1626  //
1627  if (dumpfile){
1628  //dump to the file - result can be visualized
1629  AliTPCPreprocessorOnline preprocesor;
1630  preprocesor.AddComponent(new AliTPCCalPad(*padCE));
1631  preprocesor.AddComponent(new AliTPCCalPad(*padCEIn));
1632  preprocesor.AddComponent(new AliTPCCalPad(*padCEFit));
1633  preprocesor.AddComponent(new AliTPCCalPad(*padOut));
1634  //
1635  preprocesor.AddComponent(new AliTPCCalPad(*padCEFitGY));
1636  preprocesor.AddComponent(new AliTPCCalPad(*padCEDiff));
1637  //
1638  preprocesor.AddComponent(new AliTPCCalPad(*padCEOut));
1639  preprocesor.AddComponent(new AliTPCCalPad(*padPulser));
1640  preprocesor.AddComponent(new AliTPCCalPad(*padPulserOut));
1641  preprocesor.DumpToFile(dumpfile);
1642  }
1643  delete padPulser;
1644  delete padPulserOut;
1645  delete padCEIn;
1646  delete padCEOut;
1647  delete padOut;
1648  delete padCEDiff;
1649  delete padCEFitGY;
1650  return padCE;
1651 }
1652 
1653 
1654 
1655 
1656 
1657 Int_t AliTPCcalibDButil::GetNearest(TGraph *graph, Double_t xref, Double_t &dx, Double_t &y){
1660 
1661  dx = 0;
1662  y = 0;
1663 
1664  if(!graph) return 0;
1665  if(graph->GetN() < 1) return 0;
1666 
1667  Int_t index=0;
1668  index = TMath::BinarySearch(graph->GetN(), graph->GetX(),xref);
1669  if (index<0) index=0;
1670  if(graph->GetN()==1) {
1671  dx = xref-graph->GetX()[index];
1672  }
1673  else {
1674  if (index>=graph->GetN()-1) index=graph->GetN()-2;
1675  if (xref-graph->GetX()[index]>graph->GetX()[index]-xref) index++;
1676  dx = xref-graph->GetX()[index];
1677  }
1678  y = graph->GetY()[index];
1679  return index;
1680 }
1681 
1682 Double_t AliTPCcalibDButil::GetTriggerOffsetTPC(Int_t run, Int_t timeStamp, Double_t deltaT, Double_t deltaTLaser, Int_t valType){
1696 
1697  const Float_t kLaserCut=0.0005;
1698  const Int_t kMaxPeriod=3600*24*30*12; // one year max
1699  const Int_t kMinPoints=20;
1700  //
1702  if (!array) {
1704  }
1706  if (!array) return 0;
1707  //
1708  TGraphErrors *laserA[3]={0,0,0};
1709  TGraphErrors *laserC[3]={0,0,0};
1710  TGraphErrors *cosmicAll=0;
1711  laserA[1]=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
1712  laserC[1]=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_C");
1713  cosmicAll =(TGraphErrors*)array->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
1714  //
1715  //
1716  if (!cosmicAll) return 0;
1717  Int_t nmeasC=cosmicAll->GetN();
1718  Float_t *tdelta = new Float_t[nmeasC];
1719  Int_t nused=0;
1720  for (Int_t i=0;i<nmeasC;i++){
1721  if (TMath::Abs(cosmicAll->GetX()[i]-timeStamp)>deltaT) continue;
1722  Float_t ccosmic=cosmicAll->GetY()[i];
1723  Double_t yA=0,yC=0,dA=0,dC=0;
1724  if (laserA[1]) GetNearest(laserA[1], cosmicAll->GetX()[i],dA,yA);
1725  if (laserC[1]) GetNearest(laserC[1], cosmicAll->GetX()[i],dC,yC);
1726  //yA=laserA[1]->Eval(cosmicAll->GetX()[i]);
1727  //yC=laserC[1]->Eval(cosmicAll->GetX()[i]);
1728  //
1729  if (TMath::Sqrt(dA*dA+dC*dC)>deltaTLaser) continue;
1730  Float_t claser=0;
1731  if (TMath::Abs(yA-yC)<kLaserCut) {
1732  claser=(yA-yC)*0.5;
1733  }else{
1734  if (i%2==0) claser=yA;
1735  if (i%2==1) claser=yC;
1736  }
1737  tdelta[nused]=ccosmic-claser;
1738  nused++;
1739  }
1740  if (nused<kMinPoints &&deltaT<kMaxPeriod) {
1741  delete [] tdelta;
1742  return AliTPCcalibDButil::GetTriggerOffsetTPC(run, timeStamp, deltaT*2,deltaTLaser);
1743  }
1744  if (nused<kMinPoints) {
1745  delete [] tdelta;
1746  //AliWarning("AliFatal: No time offset calibration available\n");
1747  return 0;
1748  }
1749  Double_t median = TMath::Median(nused,tdelta);
1750  Double_t mean = TMath::Mean(nused,tdelta);
1751  delete [] tdelta;
1752  return (valType==0) ? median:mean;
1753 }
1754 
1755 Double_t AliTPCcalibDButil::GetVDriftTPC(Double_t &dist, Int_t run, Int_t timeStamp, Double_t deltaT, Double_t deltaTLaser, Int_t valType){
1770 
1772  if (!array) {
1774  }
1776  if (!array) return 0;
1777  TGraphErrors *cosmicAll=0;
1778  cosmicAll =(TGraphErrors*)array->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
1779  if (!cosmicAll) return 0;
1780  Double_t grY=0;
1781  AliTPCcalibDButil::GetNearest(cosmicAll,timeStamp,dist,grY);
1782 
1783  Double_t t0= AliTPCcalibDButil::GetTriggerOffsetTPC(run,timeStamp, deltaT, deltaTLaser,valType);
1784  Double_t vcosmic = AliTPCcalibDButil::EvalGraphConst(cosmicAll, timeStamp);
1785  if (timeStamp>cosmicAll->GetX()[cosmicAll->GetN()-1]) vcosmic=cosmicAll->GetY()[cosmicAll->GetN()-1];
1786  if (timeStamp<cosmicAll->GetX()[0]) vcosmic=cosmicAll->GetY()[0];
1787  return vcosmic-t0;
1788 
1789  /*
1790  Example usage:
1791 
1792  Int_t run=89000
1793  TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1794  cosmicAll =(TGraphErrors*)array->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
1795  laserA=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
1796  //
1797  Double_t *yvd= new Double_t[cosmicAll->GetN()];
1798  Double_t *yt0= new Double_t[cosmicAll->GetN()];
1799  for (Int_t i=0; i<cosmicAll->GetN();i++) yvd[i]=AliTPCcalibDButil::GetVDriftTPC(run,cosmicAll->GetX()[i]);
1800  for (Int_t i=0; i<cosmicAll->GetN();i++) yt0[i]=AliTPCcalibDButil::GetTriggerOffsetTPC(run,cosmicAll->GetX()[i]);
1801 
1802  TGraph *pcosmicVd=new TGraph(cosmicAll->GetN(), cosmicAll->GetX(), yvd);
1803  TGraph *pcosmicT0=new TGraph(cosmicAll->GetN(), cosmicAll->GetX(), yt0);
1804 
1805  */
1806 
1807 }
1808 
1810 {
1812 
1813  return Form("guiRefTreeRun%s.root",GetRefValidity());
1814 }
1815 
1816 Bool_t AliTPCcalibDButil::CreateGUIRefTree(const char* filename)
1817 {
1822 
1823  if (!AliCDBManager::Instance()->GetDefaultStorage()){
1824  AliError("Default Storage not set. Cannot create reference calibration Tree!");
1825  return kFALSE;
1826  }
1827 
1828  TString file=filename;
1829  if (file.IsNull()) file=GetGUIRefTreeDefaultName();
1830 
1832  //noise and pedestals
1834  if (fRefPadNoise ) prep.AddComponent(new AliTPCCalPad(*(fRefPadNoise)));
1836  //pulser data
1841  //CE data
1842  if (fRefCETmean) prep.AddComponent(new AliTPCCalPad(*(fRefCETmean)));
1843  if (fRefCETrms ) prep.AddComponent(new AliTPCCalPad(*(fRefCETrms)));
1844  if (fRefCEQmean) prep.AddComponent(new AliTPCCalPad(*(fRefCEQmean)));
1846  //Altro data
1852  //QA
1853  AliTPCdataQA *dataQA=fRefDataQA;
1854  if (dataQA) {
1855  if (dataQA->GetNLocalMaxima())
1856  prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNLocalMaxima())));
1857  if (dataQA->GetMaxCharge())
1858  prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMaxCharge())));
1859  if (dataQA->GetMeanCharge())
1860  prep.AddComponent(new AliTPCCalPad(*(dataQA->GetMeanCharge())));
1861  if (dataQA->GetNoThreshold())
1862  prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNoThreshold())));
1863  if (dataQA->GetNTimeBins())
1864  prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNTimeBins())));
1865  if (dataQA->GetNPads())
1866  prep.AddComponent(new AliTPCCalPad(*(dataQA->GetNPads())));
1867  if (dataQA->GetTimePosition())
1868  prep.AddComponent(new AliTPCCalPad(*(dataQA->GetTimePosition())));
1869  }
1870  prep.DumpToFile(file.Data());
1871  return kTRUE;
1872 }
1873 
1874 Double_t AliTPCcalibDButil::GetVDriftTPCLaserTracks(Double_t &dist, Int_t run, Int_t timeStamp, Double_t deltaT, Int_t side){
1882 
1884 
1885  return GetVDriftTPCLaserTracksCommon(dist, timeStamp, deltaT, side, array);
1886 }
1887 
1888 Double_t AliTPCcalibDButil::GetVDriftTPCLaserTracksOnline(Double_t &dist, Int_t /*run*/, Int_t timeStamp, Double_t deltaT, Int_t side){
1896 
1898 
1899  Double_t dv = GetVDriftTPCLaserTracksCommon(dist, timeStamp, deltaT, side, array);
1901  if (!param) return 0;
1902 
1903  //the drift velocity is hard wired in the AliTPCCalibCE class, since online there is no access to OCDB
1904  dv*=param->GetDriftV()/2.61301900000000000e+06;
1905  if (dv>1e-20) dv=1/dv-1;
1906  else return 0;
1907  // T/P correction
1909 
1910  AliTPCSensorTempArray *temp = (AliTPCSensorTempArray*)cearray->FindObject("TempMap");
1911  AliDCSSensor *press = (AliDCSSensor*)cearray->FindObject("CavernAtmosPressure");
1912 
1913  Double_t corrPTA=0;
1914  Double_t corrPTC=0;
1915 
1916  if (temp&&press) {
1917  AliTPCCalibVdrift corr(temp,press,0);
1918  corrPTA=corr.GetPTRelative(timeStamp,0);
1919  corrPTC=corr.GetPTRelative(timeStamp,1);
1920  }
1921 
1922  if (side==0) dv -= corrPTA;
1923  if (side==1) dv -= corrPTC;
1924  if (side==2) dv -= (corrPTA+corrPTC)/2;
1925 
1926  return dv;
1927 }
1928 
1929 Double_t AliTPCcalibDButil::GetVDriftTPCLaserTracksCommon(Double_t &dist, Int_t timeStamp, Double_t deltaT,
1930  Int_t side, TObjArray * const array){
1932 
1933  TGraphErrors *grlaserA=0;
1934  TGraphErrors *grlaserC=0;
1935  Double_t vlaserA=0, vlaserC=0;
1936  if (!array) return 0;
1937  grlaserA=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
1938  grlaserC=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_C");
1939  Double_t deltaY;
1940  if (grlaserA && grlaserA->GetN()>0) {
1941  AliTPCcalibDButil::GetNearest(grlaserA,timeStamp,dist,deltaY);
1942  if (TMath::Abs(dist)>deltaT) vlaserA= deltaY;
1943  else vlaserA = AliTPCcalibDButil::EvalGraphConst(grlaserA,timeStamp);
1944  }
1945  if (grlaserC && grlaserC->GetN()>0) {
1946  AliTPCcalibDButil::GetNearest(grlaserC,timeStamp,dist,deltaY);
1947  if (TMath::Abs(dist)>deltaT) vlaserC= deltaY;
1948  else vlaserC = AliTPCcalibDButil::EvalGraphConst(grlaserC,timeStamp);
1949  }
1950  if (side==0) return vlaserA;
1951  if (side==1) return vlaserC;
1952  Double_t mdrift=(vlaserA+vlaserC)*0.5;
1953  if (!grlaserA) return vlaserC;
1954  if (!grlaserC) return vlaserA;
1955  return mdrift;
1956 }
1957 
1958 
1959 Double_t AliTPCcalibDButil::GetVDriftTPCCE(Double_t &dist,Int_t run, Int_t timeStamp, Double_t deltaT, Int_t side){
1968 
1970  if (!arrT) return 0;
1973  AliTPCCalibVdrift * driftCalib = (AliTPCCalibVdrift *)cearray->FindObject("driftPTCE");
1974  //
1975  //
1976  Double_t corrPTA = 0, corrPTC=0;
1977  Double_t ltime0A = 0, ltime0C=0;
1978  Double_t gry=0;
1979  Double_t corrA=0, corrC=0;
1980  Double_t timeA=0, timeC=0;
1981  const Double_t kEpsilon = 0.00001;
1982  TGraph *graphA = (TGraph*)arrT->At(72);
1983  TGraph *graphC = (TGraph*)arrT->At(73);
1984  if (!graphA && !graphC) return 0.;
1985  if (graphA &&graphA->GetN()>0) {
1986  AliTPCcalibDButil::GetNearest(graphA,timeStamp,dist,gry);
1987  timeA = AliTPCcalibDButil::EvalGraphConst(graphA,timeStamp);
1988  Int_t mtime =TMath::Nint((graphA->GetX()[0]+graphA->GetX()[graphA->GetN()-1])*0.5);
1989  ltime0A = GetLaserTime0(run,mtime,TMath::Nint(deltaT),0);
1990  if(ltime0A < kEpsilon) return 0;
1991  if (driftCalib) corrPTA = driftCalib->GetPTRelative(timeStamp,0);
1992  corrA = (param->GetZLength(36)/(timeA*param->GetTSample()*(1.-ltime0A)-param->GetL1Delay()-0*param->GetZSigma()/param->GetDriftV()))/param->GetDriftV()-1;
1993  corrA-=corrPTA;
1994  }
1995  if (graphC&&graphC->GetN()>0){
1996  AliTPCcalibDButil::GetNearest(graphC,timeStamp,dist,gry);
1997  timeC=AliTPCcalibDButil::EvalGraphConst(graphC,timeStamp);
1998  Int_t mtime=TMath::Nint((graphC->GetX()[0]+graphC->GetX()[graphC->GetN()-1])*0.5);
1999  ltime0C = GetLaserTime0(run,mtime,TMath::Nint(deltaT),0);
2000  if(ltime0C < kEpsilon) return 0;
2001 if (driftCalib) corrPTC = driftCalib->GetPTRelative(timeStamp,0);
2002  corrC = (param->GetZLength(54)/(timeC*param->GetTSample()*(1.-ltime0C)-param->GetL1Delay()-0*param->GetZSigma()/param->GetDriftV()))/param->GetDriftV()-1;
2003  corrC-=corrPTC;
2004  }
2005 
2006  if (side ==0 ) return corrA;
2007  if (side ==1 ) return corrC;
2008  Double_t corrM= (corrA+corrC)*0.5;
2009  if (!graphA) corrM=corrC;
2010  if (!graphC) corrM=corrA;
2011  return corrM;
2012 }
2013 
2014 Double_t AliTPCcalibDButil::GetVDriftTPCITS(Double_t &dist, Int_t run, Int_t timeStamp){
2017 
2019  TGraphErrors *graph=0;
2020  dist=0;
2021  if (!array) return 0;
2022  //array->ls();
2023  graph = (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_DRIFTVD");
2024  if (!graph) graph = (TGraphErrors*)array->FindObject("ALIGN_TOFB_TPC_DRIFTVD");
2025  if (!graph) return 0;
2026  Double_t deltaY;
2027  AliTPCcalibDButil::GetNearest(graph,timeStamp,dist,deltaY);
2028  Double_t value = AliTPCcalibDButil::EvalGraphConst(graph,timeStamp);
2029  return value;
2030 }
2031 
2032 Double_t AliTPCcalibDButil::GetTime0TPCITS(Double_t &dist, Int_t run, Int_t timeStamp){
2039 
2041  TGraphErrors *graph=0;
2042  dist=0;
2043  if (!array) return 0;
2044  graph = (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_T0");
2045  if (!graph) graph = (TGraphErrors*)array->FindObject("ALIGN_ITSB_TPC_T0");
2046  if (!graph) return 0;
2047  Double_t deltaY;
2048  AliTPCcalibDButil::GetNearest(graph,timeStamp,dist,deltaY);
2049  Double_t value = AliTPCcalibDButil::EvalGraphConst(graph,timeStamp);
2050  return value;
2051 }
2052 
2053 
2054 
2055 
2056 
2057 Int_t AliTPCcalibDButil::MakeRunList(Int_t startRun, Int_t stopRun){
2061 
2062  AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("TPC/Calib/Temperature");
2063  if (!storage) storage = AliCDBManager::Instance()->GetDefaultStorage();
2064  if (!storage) return 0;
2065  TString path=storage->GetURI();
2066  TString runsT;
2067  {
2068  TString command;
2069  if (path.Contains("local")){ // find the list if local system
2070  path.ReplaceAll("local://","");
2071  path+="TPC/Calib/Temperature";
2072  command=Form("ls %s | sed s/_/\\ /g | awk '{print \"r\"$2}' ",path.Data());
2073  }
2074  runsT=gSystem->GetFromPipe(command);
2075  }
2076  TObjArray *arr= runsT.Tokenize("r");
2077  if (!arr) return 0;
2078  //
2079  TArrayI indexes(arr->GetEntries());
2080  TArrayI runs(arr->GetEntries());
2081  Int_t naccept=0;
2082  {for (Int_t irun=0;irun<arr->GetEntries();irun++){
2083  Int_t irunN = atoi(arr->At(irun)->GetName());
2084  if (irunN<startRun) continue;
2085  if (irunN>stopRun) continue;
2086  runs[naccept]=irunN;
2087  naccept++;
2088  }}
2089  delete arr;
2090  fRuns.Set(naccept);
2091  fRunsStart.Set(fRuns.fN);
2092  fRunsStop.Set(fRuns.fN);
2093  TMath::Sort(fRuns.fN, runs.fArray, indexes.fArray,kFALSE);
2094  for (Int_t irun=0; irun<fRuns.fN; irun++) fRuns[irun]=runs[indexes[irun]];
2095 
2096  //
2097  AliCDBEntry * entry = 0;
2098  {for (Int_t irun=0;irun<fRuns.fN; irun++){
2099  entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",fRuns[irun]);
2100  if (!entry) continue;
2101  AliTPCSensorTempArray * tmpRun = dynamic_cast<AliTPCSensorTempArray*>(entry->GetObject());
2102  if (!tmpRun) continue;
2103  fRunsStart[irun]=tmpRun->GetStartTime().GetSec();
2104  fRunsStop[irun]=tmpRun->GetEndTime().GetSec();
2105  //AliInfo(Form("irun\t%d\tRun\t%d\t%d\t%d\n",irun,fRuns[irun],tmpRun->GetStartTime().GetSec(),tmpRun->GetEndTime().GetSec()));
2106  }}
2107  return fRuns.fN;
2108 }
2109 
2110 
2111 Int_t AliTPCcalibDButil::FindRunTPC(Int_t itime, Bool_t debug){
2113 
2114  Int_t index0 = TMath::BinarySearch(fRuns.fN, fRunsStop.fArray,itime);
2115  Int_t index1 = TMath::BinarySearch(fRuns.fN, fRunsStart.fArray,itime);
2116  Int_t cindex = -1;
2117  for (Int_t index=index0; index<=index1; index++){
2118  if (fRunsStart[index]<=itime && fRunsStop[index]>=itime) cindex=index;
2119  if (debug) {
2120  AliInfo(Form("%d\t%d\t%d\n",fRuns[index], fRunsStart[index]-itime, fRunsStop[index]-itime));
2121  }
2122  }
2123  if (cindex<0) cindex =(index0+index1)/2;
2124  if (cindex<0) {
2125  return 0;
2126  }
2127  return fRuns[cindex];
2128 }
2129 
2130 
2131 
2132 
2133 
2134 TGraph* AliTPCcalibDButil::FilterGraphMedian(TGraph * graph, Float_t sigmaCut,Double_t &medianY){
2137 
2138  if (!graph) return 0;
2139  Int_t kMinPoints=2;
2140  Int_t npoints0 = graph->GetN();
2141  Int_t npoints=0;
2142  Float_t rmsY=0;
2143  //
2144  //
2145  if (npoints0<kMinPoints) return 0;
2146 
2147  Double_t *outx=new Double_t[npoints0];
2148  Double_t *outy=new Double_t[npoints0];
2149  for (Int_t iter=0; iter<3; iter++){
2150  npoints=0;
2151  for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
2152  if (graph->GetY()[ipoint]==0) continue;
2153  if (iter>0 &&TMath::Abs(graph->GetY()[ipoint]-medianY)>sigmaCut*rmsY) continue;
2154  outx[npoints] = graph->GetX()[ipoint];
2155  outy[npoints] = graph->GetY()[ipoint];
2156  npoints++;
2157  }
2158  if (npoints<=1) break;
2159  medianY =TMath::Median(npoints,outy);
2160  rmsY =TMath::RMS(npoints,outy);
2161  }
2162  TGraph *graphOut=0;
2163  if (npoints>1) graphOut= new TGraph(npoints,outx,outy);
2164  delete [] outx;
2165  delete [] outy;
2166  return graphOut;
2167 }
2168 
2169 
2170 TGraph* AliTPCcalibDButil::FilterGraphMedianAbs(TGraph * graph, Float_t cut,Double_t &medianY){
2173 
2174  if (!graph) return 0;
2175  Int_t kMinPoints=2;
2176  Int_t npoints0 = graph->GetN();
2177  Int_t npoints=0;
2178 // Float_t rmsY=0;
2179  //
2180  //
2181  if (npoints0<kMinPoints) return 0;
2182 
2183  Double_t *outx=new Double_t[npoints0];
2184  Double_t *outy=new Double_t[npoints0];
2185  for (Int_t iter=0; iter<3; iter++){
2186  npoints=0;
2187  for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
2188  if (graph->GetY()[ipoint]==0) continue;
2189  if (iter>0 &&TMath::Abs(graph->GetY()[ipoint]-medianY)>cut) continue;
2190  outx[npoints] = graph->GetX()[ipoint];
2191  outy[npoints] = graph->GetY()[ipoint];
2192  npoints++;
2193  }
2194  if (npoints<=1) break;
2195  medianY =TMath::Median(npoints,outy);
2196 // rmsY =TMath::RMS(npoints,outy);
2197  }
2198  TGraph *graphOut=0;
2199  if (npoints>1) graphOut= new TGraph(npoints,outx,outy);
2200  delete [] outx;
2201  delete [] outy;
2202  return graphOut;
2203 }
2204 
2205 
2206 
2207 TGraphErrors* AliTPCcalibDButil::FilterGraphMedianErr(TGraphErrors * const graph, Float_t sigmaCut,Double_t &medianY){
2210 
2211  Int_t kMinPoints=10;
2212  Int_t npoints0 = graph->GetN();
2213  Int_t npoints=0;
2214  Float_t medianErr=0, rmsErr=0;
2215  //
2216  //
2217  if (npoints0<kMinPoints) return 0;
2218 
2219  Double_t *outx=new Double_t[npoints0];
2220  Double_t *outy=new Double_t[npoints0];
2221  Double_t *erry=new Double_t[npoints0];
2222  Double_t *nerry=new Double_t[npoints0];
2223  Double_t *errx=new Double_t[npoints0];
2224 
2225  for (Int_t iter=0; iter<3; iter++){
2226  npoints=0;
2227  for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
2228  nerry[npoints] = graph->GetErrorY(ipoint);
2229  if (iter>0 &&TMath::Abs(nerry[npoints]-medianErr)>sigmaCut*rmsErr) continue;
2230  erry[npoints] = graph->GetErrorY(ipoint);
2231  outx[npoints] = graph->GetX()[ipoint];
2232  outy[npoints] = graph->GetY()[ipoint];
2233  errx[npoints] = graph->GetErrorY(ipoint);
2234  npoints++;
2235  }
2236  if (npoints==0) break;
2237  medianErr=TMath::Median(npoints,erry);
2238  medianY =TMath::Median(npoints,outy);
2239  rmsErr =TMath::RMS(npoints,erry);
2240  }
2241  TGraphErrors *graphOut=0;
2242  if (npoints>1) graphOut= new TGraphErrors(npoints,outx,outy,errx,erry);
2243  delete []outx;
2244  delete []outy;
2245  delete []erry;
2246  delete []nerry;
2247  delete []errx;
2248  return graphOut;
2249 }
2250 
2251 
2252 void AliTPCcalibDButil::Sort(TGraph *graph){
2254 
2255  Int_t npoints = graph->GetN();
2256  Int_t *indexes=new Int_t[npoints];
2257  Double_t *outx=new Double_t[npoints];
2258  Double_t *outy=new Double_t[npoints];
2259  TMath::Sort(npoints, graph->GetX(),indexes,kFALSE);
2260  for (Int_t i=0;i<npoints;i++) outx[i]=graph->GetX()[indexes[i]];
2261  for (Int_t i=0;i<npoints;i++) outy[i]=graph->GetY()[indexes[i]];
2262  for (Int_t i=0;i<npoints;i++) graph->GetX()[i]=outx[i];
2263  for (Int_t i=0;i<npoints;i++) graph->GetY()[i]=outy[i];
2264 
2265  delete [] indexes;
2266  delete [] outx;
2267  delete [] outy;
2268 }
2269 void AliTPCcalibDButil::SmoothGraph(TGraph *graph, Double_t delta){
2271 
2272  Sort(graph);
2273  Int_t npoints = graph->GetN();
2274  Double_t *outy=new Double_t[npoints];
2275 
2276  for (Int_t ipoint=0; ipoint<npoints; ipoint++){
2277  Double_t lx=graph->GetX()[ipoint];
2278  Int_t index0=TMath::BinarySearch(npoints, graph->GetX(),lx-delta);
2279  Int_t index1=TMath::BinarySearch(npoints, graph->GetX(),lx+delta);
2280  if (index0<0) index0=0;
2281  if (index1>=npoints-1) index1=npoints-1;
2282  if ((index1-index0)>1){
2283  outy[ipoint] = TMath::Mean(index1-index0, &(graph->GetY()[index0]));
2284  }else{
2285  outy[ipoint]=graph->GetY()[ipoint];
2286  }
2287  }
2288  // TLinearFitter fitter(3,"pol2");
2289 // for (Int_t ipoint=0; ipoint<npoints; ipoint++){
2290 // Double_t lx=graph->GetX()[ipoint];
2291 // Int_t index0=TMath::BinarySearch(npoints, graph->GetX(),lx-delta);
2292 // Int_t index1=TMath::BinarySearch(npoints, graph->GetX(),lx+delta);
2293 // if (index0<0) index0=0;
2294 // if (index1>=npoints-1) index1=npoints-1;
2295 // fitter.ClearPoints();
2296 // for (Int_t jpoint=0;jpoint<index1-index0; jpoint++)
2297 // if ((index1-index0)>1){
2298 // outy[ipoint] = TMath::Mean(index1-index0, &(graph->GetY()[index0]));
2299 // }else{
2300 // outy[ipoint]=graph->GetY()[ipoint];
2301 // }
2302 // }
2303 
2304 
2305 
2306  for (Int_t ipoint=0; ipoint<npoints; ipoint++){
2307  graph->GetY()[ipoint] = outy[ipoint];
2308  }
2309  delete[] outy;
2310 }
2311 
2312 Double_t AliTPCcalibDButil::EvalGraphConst(TGraph * const graph, Double_t xref){
2314 
2315  if (!graph) {
2316  AliInfoGeneral("AliTPCcalibDButil","AliTPCcalibDButil::EvalGraphConst: 0 pointer\n");
2317  return 0;
2318  }
2319 
2320  if (graph->GetN()<1){
2321  AliInfoGeneral("AliTPCcalibDButil","AliTPCcalibDButil::EvalGraphConst: Empty graph \n");
2322  return 0;
2323  }
2324 
2325 
2326  if (xref<graph->GetX()[0]) return graph->GetY()[0];
2327  if (xref>graph->GetX()[graph->GetN()-1]) return graph->GetY()[graph->GetN()-1];
2328 
2329  // AliInfo(Form("graph->Eval(graph->GetX()[0]) %f, graph->Eval(xref) %f \n",graph->Eval(graph->GetX()[0]), graph->Eval(xref)));
2330 
2331  if(graph->GetN()==1)
2332  return graph->Eval(graph->GetX()[0]);
2333 
2334 
2335  return graph->Eval(xref);
2336 }
2337 
2338 Double_t AliTPCcalibDButil::EvalGraphConst(AliSplineFit *graph, Double_t xref){
2340 
2341  if (!graph) {
2342  AliInfoGeneral("AliTPCcalibDButil","AliTPCcalibDButil::EvalGraphConst: 0 pointer\n");
2343  return 0;
2344  }
2345  if (graph->GetKnots()<1){
2346  AliInfoGeneral("AliTPCcalibDButil","AliTPCcalibDButil::EvalGraphConst: Empty graph");
2347  return 0;
2348  }
2349  if (xref<graph->GetX()[0]) return graph->GetY0()[0];
2350  if (xref>graph->GetX()[graph->GetKnots()-1]) return graph->GetY0()[graph->GetKnots()-1];
2351  return graph->Eval( xref);
2352 }
2353 
2354 Float_t AliTPCcalibDButil::FilterSensor(AliDCSSensor * sensor, Double_t ymin, Double_t ymax, Double_t maxdy, Double_t sigmaCut){
2367 
2368  AliSplineFit * fit = sensor->GetFit();
2369  if (!fit) return 0.;
2370  Int_t nknots = fit->GetKnots();
2371  if (nknots==0) {
2372  delete fit;
2373  sensor->SetFit(0);
2374  return 0;
2375  }
2376  //
2377  Double_t *yin0 = new Double_t[nknots];
2378  Double_t *yin1 = new Double_t[nknots];
2379  Int_t naccept=0;
2380 
2381  for (Int_t iknot=0; iknot< nknots; iknot++){
2382  if (fit->GetY0()[iknot]>ymin && fit->GetY0()[iknot]<ymax){
2383  yin0[naccept] = fit->GetY0()[iknot];
2384  yin1[naccept] = fit->GetY1()[iknot];
2385  if (TMath::Abs(fit->GetY1()[iknot])>maxdy) yin1[naccept]=0;
2386  naccept++;
2387  }
2388  }
2389  if (naccept<1) {
2390  delete fit;
2391  sensor->SetFit(0);
2392  delete [] yin0;
2393  delete [] yin1;
2394  return 0.;
2395  }
2396 
2397  Double_t medianY0=0, medianY1=0;
2398  Double_t rmsY0 =0, rmsY1=0;
2399  medianY0 = TMath::Median(naccept, yin0);
2400  medianY1 = TMath::Median(naccept, yin1);
2401  rmsY0 = TMath::RMS(naccept, yin0);
2402  rmsY1 = TMath::RMS(naccept, yin1);
2403  naccept=0;
2404  //
2405  // 1. Filter out outliers - median+-sigmaCut*rms
2406  // values replaced by median
2407  // if replaced the derivative set to 0
2408  //
2409  for (Int_t iknot=0; iknot< nknots; iknot++){
2410  Bool_t isOK=kTRUE;
2411  if (TMath::Abs(fit->GetY0()[iknot]-medianY0)>sigmaCut*rmsY0) isOK=kFALSE;
2412  if (TMath::Abs(fit->GetY1()[iknot]-medianY1)>sigmaCut*rmsY1) isOK=kFALSE;
2413  if (nknots<2) fit->GetY1()[iknot]=0;
2414  if (TMath::Abs(fit->GetY1()[iknot])>maxdy) fit->GetY1()[iknot]=0;
2415  if (!isOK){
2416  fit->GetY0()[iknot]=medianY0;
2417  fit->GetY1()[iknot]=0;
2418  }else{
2419  naccept++;
2420  }
2421  }
2422  delete [] yin0;
2423  delete [] yin1;
2424  return Float_t(naccept)/Float_t(nknots);
2425 }
2426 
2427 Float_t AliTPCcalibDButil::FilterTemperature(AliTPCSensorTempArray *tempArray, Double_t ymin, Double_t ymax, Double_t sigmaCut){
2434 
2435  const Double_t kMaxDy=0.1;
2436  Int_t nsensors=tempArray->NumSensors();
2437  if (nsensors==0) return 0.;
2438  Int_t naccept=0;
2439  for (Int_t isensor=0; isensor<nsensors; isensor++){
2440  AliDCSSensor *sensor = tempArray->GetSensorNum(isensor);
2441  if (!sensor) continue;
2442  FilterSensor(sensor,ymin,ymax,kMaxDy, sigmaCut);
2443  if (sensor->GetFit()==0){
2444  //delete sensor;
2445  tempArray->RemoveSensorNum(isensor);
2446  }else{
2447  naccept++;
2448  }
2449  }
2450  return Float_t(naccept)/Float_t(nsensors);
2451 }
2452 
2453 
2454 void AliTPCcalibDButil::FilterCE(Double_t deltaT, Double_t cutAbs, Double_t cutSigma, TTreeSRedirector * const pcstream){
2471 
2472  const Int_t kMinPoints =10; // minimal number of points to define the CE
2473  const Int_t kMinSectors=12; // minimal number of sectors to define sideCE
2474  const Int_t kMinTime =400; // minimal arrival time of CE
2476  Double_t medianY=0;
2478  if (!cearray) return;
2479  Double_t tmin=-1;
2480  Double_t tmax=-1;
2481  //
2482  //
2483  AliTPCSensorTempArray *tempMapCE = (AliTPCSensorTempArray *)cearray->FindObject("TempMap");
2484  AliDCSSensor * cavernPressureCE = (AliDCSSensor *) cearray->FindObject("CavernAtmosPressure");
2485  if ( tempMapCE && cavernPressureCE){
2486  //
2487  // Bool_t isOK = FilterTemperature(tempMapCE)>0.1;
2488  // FilterSensor(cavernPressureCE,960,1050,10, 5.);
2489  // if (cavernPressureCE->GetFit()==0) isOK=kFALSE;
2490  Bool_t isOK=kTRUE;
2491  if (isOK) {
2492  // recalculate P/T correction map for time of the CE
2493  AliTPCCalibVdrift * driftCalib = new AliTPCCalibVdrift(tempMapCE,cavernPressureCE ,0);
2494  driftCalib->SetName("driftPTCE");
2495  driftCalib->SetTitle("driftPTCE");
2496  cearray->AddLast(driftCalib);
2497  }
2498  }
2499  //
2500  // 0. Filter almost emty graphs
2501  //
2502 
2503  for (Int_t i=0; i<72;i++){
2504  TGraph *graph= (TGraph*)arrT->At(i);
2505  if (!graph) continue;
2506  graph->Sort();
2507  if (graph->GetN()<kMinPoints){
2508  arrT->AddAt(0,i);
2509  delete graph; // delete empty graph
2510  continue;
2511  }
2512  if (tmin<0) tmin = graph->GetX()[0];
2513  if (tmax<0) tmax = graph->GetX()[graph->GetN()-1];
2514  //
2515  if (tmin>graph->GetX()[0]) tmin=graph->GetX()[0];
2516  if (tmax<graph->GetX()[graph->GetN()-1]) tmax=graph->GetX()[graph->GetN()-1];
2517  }
2518  //
2519  // 1. calculate median and RMS per side
2520  //
2521  TArrayF arrA(100000), arrC(100000);
2522  Int_t nA=0, nC=0;
2523  Double_t medianA=0, medianC=0;
2524  Double_t rmsA=0, rmsC=0;
2525  for (Int_t isec=0; isec<72;isec++){
2526  TGraph *graph= (TGraph*)arrT->At(isec);
2527  if (!graph) continue;
2528  for (Int_t ipoint=kMinPoints-1; ipoint<graph->GetN();ipoint++){
2529  if (graph->GetY()[ipoint]<kMinTime) continue;
2530  if (nA>=arrA.fN) arrA.Set(nA*2);
2531  if (nC>=arrC.fN) arrC.Set(nC*2);
2532  if (isec%36<18) arrA[nA++]= graph->GetY()[ipoint];
2533  if (isec%36>=18) arrC[nC++]= graph->GetY()[ipoint];
2534  }
2535  }
2536  if (nA>0){
2537  medianA=TMath::Median(nA,arrA.fArray);
2538  rmsA =TMath::RMS(nA,arrA.fArray);
2539  }
2540  if (nC>0){
2541  medianC=TMath::Median(nC,arrC.fArray);
2542  rmsC =TMath::RMS(nC,arrC.fArray);
2543  }
2544  //
2545  // 2. Filter graphs - in respect with side medians
2546  //
2547  TArrayD vecX(100000), vecY(100000);
2548  for (Int_t isec=0; isec<72;isec++){
2549  TGraph *graph= (TGraph*)arrT->At(isec);
2550  if (!graph) continue;
2551  Double_t median = (isec%36<18) ? medianA: medianC;
2552  Double_t rms = (isec%36<18) ? rmsA: rmsC;
2553  Int_t naccept=0;
2554  // for (Int_t ipoint=kMinPoints-1; ipoint<graph->GetN();ipoint++){ //not neccessary to remove first points
2555  for (Int_t ipoint=0; ipoint<graph->GetN();ipoint++){
2556  if (TMath::Abs(graph->GetY()[ipoint]-median)>cutAbs) continue;
2557  if (TMath::Abs(graph->GetY()[ipoint]-median)>cutSigma*rms) continue;
2558  vecX[naccept]= graph->GetX()[ipoint];
2559  vecY[naccept]= graph->GetY()[ipoint];
2560  naccept++;
2561  }
2562  if (naccept<kMinPoints){
2563  arrT->AddAt(0,isec);
2564  delete graph; // delete empty graph
2565  continue;
2566  }
2567  TGraph *graph2 = new TGraph(naccept, vecX.fArray, vecY.fArray);
2568  delete graph;
2569  arrT->AddAt(graph2,isec);
2570  }
2571  //
2572  // 3. Cut in respect wit the graph median
2573  //
2574  for (Int_t i=0; i<72;i++){
2575  TGraph *graph= (TGraph*)arrT->At(i);
2576  if (!graph) continue;
2577  //
2578  // filter in range
2579  //
2580  TGraph* graphTS0= FilterGraphMedianAbs(graph,cutAbs,medianY);
2581  if (!graphTS0) continue;
2582  if (graphTS0->GetN()<kMinPoints) {
2583  delete graphTS0;
2584  delete graph;
2585  arrT->AddAt(0,i);
2586  continue;
2587  }
2588  TGraph* graphTS= FilterGraphMedian(graphTS0,cutSigma,medianY);
2589  if (!graphTS) continue;
2590  graphTS->Sort();
2591  AliTPCcalibDButil::SmoothGraph(graphTS,deltaT);
2592  if (pcstream){
2593  Int_t run = AliTPCcalibDB::Instance()->GetRun();
2594  (*pcstream)<<"filterCE"<<
2595  "run="<<run<<
2596  "isec="<<i<<
2597  "mY="<<medianY<<
2598  "graph.="<<graph<<
2599  "graphTS0.="<<graphTS0<<
2600  "graphTS.="<<graphTS<<
2601  "\n";
2602  }
2603  delete graphTS0;
2604  arrT->AddAt(graphTS,i);
2605  delete graph;
2606  }
2607  //
2608  // Recalculate the mean time A side C side
2609  //
2610  TArrayF xA(200), yA(200), eA(200), xC(200),yC(200), eC(200);
2611  Int_t meanPoints=(nA+nC)/72; // mean number of points
2612  for (Int_t itime=0; itime<200; itime++){
2613  nA=0, nC=0;
2614  Double_t time=tmin+(tmax-tmin)*Float_t(itime)/200.;
2615  for (Int_t i=0; i<72;i++){
2616  TGraph *graph= (TGraph*)arrT->At(i);
2617  if (!graph) continue;
2618  if (graph->GetN()<(meanPoints/4)) continue;
2619  if ( (i%36)<18 ) arrA[nA++]=graph->Eval(time);
2620  if ( (i%36)>=18 ) arrC[nC++]=graph->Eval(time);
2621  }
2622  xA[itime]=time;
2623  xC[itime]=time;
2624  yA[itime]=(nA>0)? TMath::Mean(nA,arrA.fArray):0;
2625  yC[itime]=(nC>0)? TMath::Mean(nC,arrC.fArray):0;
2626  eA[itime]=(nA>0)? TMath::RMS(nA,arrA.fArray):0;
2627  eC[itime]=(nC>0)? TMath::RMS(nC,arrC.fArray):0;
2628  }
2629  //
2630  Double_t rmsTA = TMath::RMS(200,yA.fArray)+TMath::Mean(200,eA.fArray);
2631  Double_t rmsTC = TMath::RMS(200,yC.fArray)+TMath::Mean(200,eC.fArray);
2632  if (pcstream){
2633  Int_t run = AliTPCcalibDB::Instance()->GetRun();
2634  (*pcstream)<<"filterAC"<<
2635  "run="<<run<<
2636  "nA="<<nA<<
2637  "nC="<<nC<<
2638  "rmsTA="<<rmsTA<<
2639  "rmsTC="<<rmsTC<<
2640  "\n";
2641  }
2642  //
2643  TGraphErrors *grA = new TGraphErrors(200,xA.fArray,yA.fArray,0, eA.fArray);
2644  TGraphErrors *grC = new TGraphErrors(200,xC.fArray,yC.fArray,0, eC.fArray);
2645  TGraph* graphTSA= FilterGraphMedian(grA,cutSigma,medianY);
2646  if (graphTSA&&graphTSA->GetN()) SmoothGraph(graphTSA,deltaT);
2647  TGraph* graphTSC= FilterGraphMedian(grC,cutSigma,medianY);
2648  if (graphTSC&&graphTSC->GetN()>0) SmoothGraph(graphTSC,deltaT);
2649  delete grA;
2650  delete grC;
2651  if (nA<kMinSectors) arrT->AddAt(0,72);
2652  else arrT->AddAt(graphTSA,72);
2653  if (nC<kMinSectors) arrT->AddAt(0,73);
2654  else arrT->AddAt(graphTSC,73);
2655 }
2656 
2657 
2658 void AliTPCcalibDButil::FilterTracks(Int_t run, Double_t cutSigma, TTreeSRedirector * const pcstream){
2662 
2663  const Int_t kMinPoints=1; // minimal number of points to define value
2665  Double_t medianY=0;
2666  if (!arrT) return;
2667  for (Int_t i=0; i<arrT->GetEntries();i++){
2668  TGraphErrors *graph= dynamic_cast<TGraphErrors*>(arrT->At(i));
2669  if (!graph) continue;
2670  if (graph->GetN()<kMinPoints){
2671  delete graph;
2672  arrT->AddAt(0,i);
2673  continue;
2674  }
2675  TGraphErrors *graph2 = NULL;
2676  if(graph->GetN()<10) {
2677  graph2 = new TGraphErrors(graph->GetN(),graph->GetX(),graph->GetY(),graph->GetEX(),graph->GetEY());
2678  if (!graph2) {
2679  delete graph; arrT->AddAt(0,i); continue;
2680  }
2681  }
2682  else {
2683  graph2= FilterGraphMedianErr(graph,cutSigma,medianY);
2684  if (!graph2) {
2685  delete graph; arrT->AddAt(0,i); continue;
2686  }
2687  }
2688  if (graph2->GetN()<1) {
2689  delete graph; arrT->AddAt(0,i); continue;
2690  }
2691  graph2->SetName(graph->GetName());
2692  graph2->SetTitle(graph->GetTitle());
2693  arrT->AddAt(graph2,i);
2694  if (pcstream){
2695  (*pcstream)<<"filterTracks"<<
2696  "run="<<run<<
2697  "isec="<<i<<
2698  "mY="<<medianY<<
2699  "graph.="<<graph<<
2700  "graph2.="<<graph2<<
2701  "\n";
2702  }
2703  delete graph;
2704  }
2705 }
2706 
2707 
2708 
2709 
2710 
2711 Double_t AliTPCcalibDButil::GetLaserTime0(Int_t run, Int_t timeStamp, Int_t deltaT, Int_t side){
2716 
2717  Int_t kMinPoints=1;
2718  Double_t kMinDelay=0.01;
2719  Double_t kMinDelayErr=0.0001;
2720 
2722  if (!array) return 0;
2723  TGraphErrors *tlaser=0;
2724  if (array){
2725  if (side==0) tlaser=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DELAY_LASER_ALL_A");
2726  if (side==1) tlaser=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DELAY_LASER_ALL_C");
2727  }
2728  if (!tlaser) return 0;
2729  Int_t npoints0= tlaser->GetN();
2730  if (npoints0==0) return 0;
2731  Double_t *xlaser = new Double_t[npoints0];
2732  Double_t *ylaser = new Double_t[npoints0];
2733  Int_t npoints=0;
2734  for (Int_t i=0;i<npoints0;i++){
2735  //printf("%d\n",i);
2736  if (tlaser->GetY()[i]<=kMinDelay) continue; // filter zeros
2737  if (tlaser->GetErrorY(i)>TMath::Abs(kMinDelayErr)) continue;
2738  xlaser[npoints]=tlaser->GetX()[npoints];
2739  ylaser[npoints]=tlaser->GetY()[npoints];
2740  npoints++;
2741  }
2742  //
2743  //
2744  Int_t index0=TMath::BinarySearch(npoints, xlaser, Double_t(timeStamp-deltaT))-1;
2745  Int_t index1=TMath::BinarySearch(npoints, xlaser, Double_t(timeStamp+deltaT))+1;
2746  //if (index1-index0 <kMinPoints) { index1+=kMinPoints; index0-=kMinPoints;}
2747  if (index0<0) index0=0;
2748  if (index1>=npoints-1) index1=npoints-1;
2749  if (index1-index0<kMinPoints) {
2750  delete [] ylaser;
2751  delete [] xlaser;
2752  return 0;
2753  }
2754  //
2755  //Double_t median = TMath::Median(index1-index0, &(ylaser[index0]));
2756  Double_t mean = TMath::Mean(index1-index0, &(ylaser[index0]));
2757  delete [] ylaser;
2758  delete [] xlaser;
2759  return mean;
2760 }
2761 
2762 
2763 
2764 
2765 void AliTPCcalibDButil::FilterGoofie(AliDCSSensorArray * goofieArray, Double_t deltaT, Double_t cutSigma, Double_t minVd, Double_t maxVd, TTreeSRedirector * const pcstream){
2774 
2775  const Int_t kMinPoints = 3;
2776  //
2777 
2778  TGraph *graphvd = goofieArray->GetSensorNum(2)->GetGraph();
2779  TGraph *graphan = goofieArray->GetSensorNum(8)->GetGraph();
2780  TGraph *graphaf = goofieArray->GetSensorNum(9)->GetGraph();
2781  TGraph *graphpt = goofieArray->GetSensorNum(15)->GetGraph();
2782  if (!graphvd) return;
2783  if (graphvd->GetN()<kMinPoints){
2784  delete graphvd;
2785  goofieArray->GetSensorNum(2)->SetGraph(0);
2786  return;
2787  }
2788  //
2789  // 1. Caluclate medians of critical variables
2790  // drift velcocity
2791  // P/T
2792  // area near peak
2793  // area far peak
2794  //
2795  Double_t medianpt=0;
2796  Double_t medianvd=0, sigmavd=0;
2797  Double_t medianan=0;
2798  Double_t medianaf=0;
2799  Int_t entries=graphvd->GetN();
2800  Double_t yvdn[10000];
2801  Int_t nvd=0;
2802  //
2803  for (Int_t ipoint=0; ipoint<entries; ipoint++){
2804  if (graphpt->GetY()[ipoint]<=0.0000001) continue;
2805  if (graphvd->GetY()[ipoint]/graphpt->GetY()[ipoint]<minVd) continue;
2806  if (graphvd->GetY()[ipoint]/graphpt->GetY()[ipoint]>maxVd) continue;
2807  yvdn[nvd++]=graphvd->GetY()[ipoint];
2808  }
2809  if (nvd<kMinPoints){
2810  delete graphvd;
2811  goofieArray->GetSensorNum(2)->SetGraph(0);
2812  return;
2813  }
2814  //
2815  Int_t nuni = TMath::Min(TMath::Nint(nvd*0.4+2), nvd-1);
2816  if (nuni>=kMinPoints){
2817  AliMathBase::EvaluateUni(nvd, yvdn, medianvd,sigmavd,nuni);
2818  }else{
2819  medianvd = TMath::Median(nvd, yvdn);
2820  }
2821 
2822  TGraph * graphpt0 = AliTPCcalibDButil::FilterGraphMedianAbs(graphpt,10,medianpt);
2823  TGraph * graphpt1 = AliTPCcalibDButil::FilterGraphMedian(graphpt0,2,medianpt);
2824  TGraph * graphan0 = AliTPCcalibDButil::FilterGraphMedianAbs(graphan,10,medianan);
2825  TGraph * graphan1 = AliTPCcalibDButil::FilterGraphMedian(graphan0,2,medianan);
2826  TGraph * graphaf0 = AliTPCcalibDButil::FilterGraphMedianAbs(graphaf,10,medianaf);
2827  TGraph * graphaf1 = AliTPCcalibDButil::FilterGraphMedian(graphaf0,2,medianaf);
2828  delete graphpt0;
2829  delete graphpt1;
2830  delete graphan0;
2831  delete graphan1;
2832  delete graphaf0;
2833  delete graphaf1;
2834  //
2835  // 2. Make outlyer graph
2836  //
2837  Int_t nOK=0;
2838  TGraph graphOut(*graphvd);
2839  for (Int_t i=0; i<entries;i++){
2840  //
2841  Bool_t isOut=kFALSE;
2842  if (graphpt->GetY()[i]<=0.0000001) { graphOut.GetY()[i]=1; continue;}
2843  if (graphvd->GetY()[i]/graphpt->GetY()[i]<minVd || graphvd->GetY()[i]/graphpt->GetY()[i]>maxVd) { graphOut.GetY()[i]=1; continue;}
2844 
2845  if (TMath::Abs((graphvd->GetY()[i]/graphpt->GetY()[i])/medianvd-1.)<0.05)
2846  isOut|=kTRUE;
2847  if (TMath::Abs(graphpt->GetY()[i]/medianpt-1.)>0.02) isOut|=kTRUE;
2848  if (TMath::Abs(graphan->GetY()[i]/medianan-1.)>0.2) isOut|=kTRUE;
2849  if (TMath::Abs(graphaf->GetY()[i]/medianaf-1.)>0.2) isOut|=kTRUE;
2850  graphOut.GetY()[i]= (isOut)?1:0;
2851  if (!isOut) nOK++;
2852  }
2853  if (nOK<kMinPoints) {
2854  delete graphvd;
2855  goofieArray->GetSensorNum(2)->SetGraph(0);
2856  return;
2857  }
2858  //
2859  // 3. Filter out outlyers - and smooth
2860  //
2861  TVectorF vmedianArray(goofieArray->NumSensors());
2862  TVectorF vrmsArray(goofieArray->NumSensors());
2863  Double_t xnew[10000];
2864  Double_t ynew[10000];
2865  TObjArray junk;
2866  junk.SetOwner(kTRUE);
2867  Bool_t isOK=kTRUE;
2868  //
2869  //
2870  for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
2871  isOK=kTRUE;
2872  AliDCSSensor *sensor = goofieArray->GetSensorNum(isensor);
2873  TGraph *graphOld=0, *graphNew=0, * graphNew0=0,*graphNew1=0,*graphNew2=0;
2874  //
2875  if (!sensor) continue;
2876  graphOld = sensor->GetGraph();
2877  if (graphOld) {
2878  sensor->SetGraph(0);
2879  Int_t nused=0;
2880  for (Int_t i=0;i<entries;i++){
2881  if (graphOut.GetY()[i]>0.5) continue;
2882  xnew[nused]=graphOld->GetX()[i];
2883  ynew[nused]=graphOld->GetY()[i];
2884  nused++;
2885  }
2886  graphNew = new TGraph(nused,xnew,ynew);
2887  junk.AddLast(graphNew);
2888  junk.AddLast(graphOld);
2889  Double_t median=0;
2890  graphNew0 = AliTPCcalibDButil::FilterGraphMedian(graphNew,cutSigma,median);
2891  if (graphNew0!=0){
2892  junk.AddLast(graphNew0);
2893  graphNew1 = AliTPCcalibDButil::FilterGraphMedian(graphNew0,cutSigma,median);
2894  if (graphNew1!=0){
2895  junk.AddLast(graphNew1);
2896  graphNew2 = AliTPCcalibDButil::FilterGraphMedian(graphNew1,cutSigma,median);
2897  if (graphNew2!=0) {
2898  vrmsArray[isensor] =TMath::RMS(graphNew2->GetN(),graphNew2->GetY());
2899  AliTPCcalibDButil::SmoothGraph(graphNew2,deltaT);
2900  AliTPCcalibDButil::SmoothGraph(graphNew2,deltaT);
2901  AliTPCcalibDButil::SmoothGraph(graphNew2,deltaT);
2902  // AliInfo(Form("%d\t%f\t%f\n",isensor, median,vrmsArray[isensor]));
2903  vmedianArray[isensor]=median;
2904  //
2905  }
2906  }
2907  }
2908  }
2909  if (!graphOld) { isOK=kFALSE; graphOld =&graphOut;}
2910  if (!graphNew0) { isOK=kFALSE; graphNew0=graphOld;}
2911  if (!graphNew1) { isOK=kFALSE; graphNew1=graphOld;}
2912  if (!graphNew2) { isOK=kFALSE; graphNew2=graphOld;}
2913  (*pcstream)<<"goofieA"<<
2914  Form("isOK_%d.=",isensor)<<isOK<<
2915  Form("s_%d.=",isensor)<<sensor<<
2916  Form("gr_%d.=",isensor)<<graphOld<<
2917  Form("gr0_%d.=",isensor)<<graphNew0<<
2918  Form("gr1_%d.=",isensor)<<graphNew1<<
2919  Form("gr2_%d.=",isensor)<<graphNew2;
2920  if (isOK) sensor->SetGraph(graphNew2);
2921  }
2922  (*pcstream)<<"goofieA"<<
2923  "vmed.="<<&vmedianArray<<
2924  "vrms.="<<&vrmsArray<<
2925  "\n";
2926  junk.Delete(); // delete temoprary graphs
2927 
2928 }
2929 
2930 
2931 
2932 
2933 
2934 TMatrixD* AliTPCcalibDButil::MakeStatRelKalman(TObjArray * const array, Float_t minFraction, Int_t minStat, Float_t maxvd){
2944 
2945  if (!array) return 0;
2946  if (array->GetEntries()<=0) return 0;
2947  // Int_t entries = array->GetEntries();
2948  Int_t entriesFast = array->GetEntriesFast();
2949  TVectorD state(9);
2950  TVectorD *valArray[9];
2951  for (Int_t i=0; i<9; i++){
2952  valArray[i] = new TVectorD(entriesFast);
2953  }
2954  Int_t naccept=0;
2955  for (Int_t ikalman=0; ikalman<entriesFast; ikalman++){
2956  AliRelAlignerKalman * kalman = (AliRelAlignerKalman *) array->UncheckedAt(ikalman);
2957  if (!kalman) continue;
2958  if (TMath::Abs(kalman->GetTPCvdCorr()-1)>maxvd) continue;
2959  if (kalman->GetNUpdates()<minStat) continue;
2960  if (Float_t(kalman->GetNUpdates())/Float_t(kalman->GetNTracks())<minFraction) continue;
2961  kalman->GetState(state);
2962  for (Int_t ipar=0; ipar<9; ipar++)
2963  (*valArray[ipar])[naccept]=state[ipar];
2964  naccept++;
2965  }
2966  //if (naccept<2) return 0;
2967  if (naccept<1) return 0;
2968  TMatrixD *pstat=new TMatrixD(9,3);
2969  TMatrixD &stat=*pstat;
2970  for (Int_t ipar=0; ipar<9; ipar++){
2971  stat(ipar,0)=TMath::Mean(naccept, valArray[ipar]->GetMatrixArray());
2972  stat(ipar,1)=TMath::Median(naccept, valArray[ipar]->GetMatrixArray());
2973  stat(ipar,2)=TMath::RMS(naccept, valArray[ipar]->GetMatrixArray());
2974  }
2975  for (Int_t i=0; i<9; i++){
2976  delete valArray[i];
2977  }
2978  return pstat;
2979 }
2980 
2981 
2982 TObjArray *AliTPCcalibDButil::SmoothRelKalman(TObjArray * const array, const TMatrixD* statP, Bool_t direction, Float_t sigmaCut){
2989 
2990  if (!array) return 0;
2991  if (array->GetEntries()<=0) return 0;
2992  if (!statP) return 0;
2993  const TMatrixD& stat = *statP;
2994  // error increase in 1 hour
2995  const Double_t kerrsTime[9]={
2996  0.00001, 0.00001, 0.00001,
2997  0.001, 0.001, 0.001,
2998  0.002, 0.01, 0.001};
2999  //
3000  //
3001  Int_t entries = array->GetEntriesFast();
3002  TObjArray *sArray= new TObjArray(entries);
3003  AliRelAlignerKalman * sKalman =0;
3004  TVectorD state(9);
3005  for (Int_t i=0; i<entries; i++){
3006  Int_t index=(direction)? entries-i-1:i;
3007  AliRelAlignerKalman * kalman = (AliRelAlignerKalman *) array->UncheckedAt(index);
3008  if (!kalman) continue;
3009  Bool_t isOK=kTRUE;
3010  kalman->GetState(state);
3011  for (Int_t ipar=0; ipar<9; ipar++){
3012  if (TMath::Abs(state[ipar]-stat(ipar,1))>sigmaCut*stat(ipar,2)) isOK=kFALSE;
3013  }
3014  if (!sKalman &&isOK) {
3015  sKalman=new AliRelAlignerKalman(*kalman);
3016  sKalman->SetRejectOutliers(kFALSE);
3017  sKalman->SetRunNumber(kalman->GetRunNumber());
3018  sKalman->SetTimeStamp(kalman->GetTimeStamp());
3019  }
3020  if (!sKalman) continue;
3021  Double_t deltaT=TMath::Abs(Int_t(kalman->GetTimeStamp())-Int_t(sKalman->GetTimeStamp()))/3600.;
3022  for (Int_t ipar=0; ipar<9; ipar++){
3023 // (*(sKalman->GetStateCov()))(6,6)+=deltaT*errvd*errvd;
3024 // (*(sKalman->GetStateCov()))(7,7)+=deltaT*errt0*errt0;
3025 // (*(sKalman->GetStateCov()))(8,8)+=deltaT*errvy*errvy;
3026  (*(sKalman->GetStateCov()))(ipar,ipar)+=deltaT*kerrsTime[ipar]*kerrsTime[ipar];
3027  }
3028  sKalman->SetRunNumber(kalman->GetRunNumber());
3029  if (!isOK) sKalman->SetRunNumber(0);
3030  sArray->AddAt(new AliRelAlignerKalman(*sKalman),index);
3031  if (!isOK) continue;
3032  sKalman->SetRejectOutliers(kFALSE);
3033  sKalman->SetRunNumber(kalman->GetRunNumber());
3034  sKalman->SetTimeStamp(kalman->GetTimeStamp());
3035  sKalman->Merge(kalman);
3036  sArray->AddAt(new AliRelAlignerKalman(*sKalman),index);
3037  //sKalman->Print();
3038  }
3039  return sArray;
3040 }
3041 
3047 
3048  if (!arrayP) return 0;
3049  if (arrayP->GetEntries()<=0) return 0;
3050  if (!arrayM) return 0;
3051  if (arrayM->GetEntries()<=0) return 0;
3052 
3053  Int_t entries = arrayP->GetEntriesFast();
3054  TObjArray *array = new TObjArray(arrayP->GetEntriesFast());
3055 
3056  for (Int_t i=0; i<entries; i++){
3057  AliRelAlignerKalman * kalmanP = (AliRelAlignerKalman *) arrayP->UncheckedAt(i);
3058  AliRelAlignerKalman * kalmanM = (AliRelAlignerKalman *) arrayM->UncheckedAt(i);
3059  if (!kalmanP) continue;
3060  if (!kalmanM) continue;
3061 
3062  AliRelAlignerKalman *kalman = NULL;
3063  if(kalmanP->GetRunNumber() != 0 && kalmanM->GetRunNumber() != 0) {
3064  kalman = new AliRelAlignerKalman(*kalmanP);
3065  kalman->Merge(kalmanM);
3066  }
3067  else if (kalmanP->GetRunNumber() == 0) {
3068  kalman = new AliRelAlignerKalman(*kalmanM);
3069  }
3070  else if (kalmanM->GetRunNumber() == 0) {
3071  kalman = new AliRelAlignerKalman(*kalmanP);
3072  }
3073  else
3074  continue;
3075 
3076  array->AddAt(kalman,i);
3077  }
3078 
3079  return array;
3080 }
3081 
3082 //_____________________________________________________________________________________
3084 {
3091 
3092 
3093  // === add main tree, which will be a mapping file ================
3094  TFile *fin = TFile::Open(Form("%s/map/treeMapping.root",baseDir.Data()));
3095  gROOT->cd();
3096  TTree *tMain = (TTree*)fin->Get("calPads");
3097  tMain->SetAlias("Pad0","MapPadLength.fElements==7.5"); // pad types
3098  tMain->SetAlias("Pad1","MapPadLength.fElements==10.0");
3099  tMain->SetAlias("Pad2","MapPadLength.fElements==15.0");
3100  //
3101  tMain->SetAlias("dRowNorm0","(row.fElements/32-1)"); // normalized distance to the center of the chamber in lx (-1,1)
3102  tMain->SetAlias("dRowNorm1","(row.fElements/32-1)"); //
3103  tMain->SetAlias("dRowNorm2","((row.fElements-63)/16-1)"); //
3104  tMain->SetAlias("dRowNorm","(row.fElements<63)*(row.fElements/32-1)+(row.fElements>63)*((row.fElements-63)/16-1)");
3105  tMain->SetAlias("dPhiNorm","(ly.fElements/lx.fElements)/(pi/18)"); // normalized distance to the center of the chamber in phi (-1,1)
3106  //
3107  tMain->SetAlias("fsector","(sector%36)+(0.5+9*atan2(ly.fElements,lx.fElements)/pi)"); // float sector number
3108  tMain->SetAlias("posEdge","((pi/18.)-abs(atan(ly.fElements/lx.fElements)))*lx.fElements"); //distance to the edge
3109 
3110  // === add the krypton calibration trees ==========================
3111  TString inputTreesKrCalib = gSystem->GetFromPipe(Form("ls %s/KryptonCalib/20*/calibKr/*.tree.root",baseDir.Data()));
3112  TObjArray *arrInputTreesKrCalib = inputTreesKrCalib.Tokenize("\n");
3113 
3114  for (Int_t itree=0; itree<arrInputTreesKrCalib->GetEntriesFast(); ++itree) {
3115  TFile *fin2 = TFile::Open(arrInputTreesKrCalib->At(itree)->GetName());
3116  TTree *tin = (TTree*)fin2->Get("calPads");
3117  gROOT->cd();
3118  TString friendName=gSystem->BaseName(arrInputTreesKrCalib->At(itree)->GetName());
3119  friendName.ReplaceAll("calibKr.","");
3120  friendName.ReplaceAll(".tree.root","");
3121  friendName="Kr."+friendName;
3122  tMain->AddFriend(tin,friendName.Data());
3123 
3124  // set aliases
3125 
3126  // TODO: finish implementation of alias via lists
3127 // const Int_t nbranchAlias = 2;
3128 // const char* branchNames[nbranchAlias]={"spectrMean","fitMean"};
3129 // const Int_t nbranchStat = 2;
3130 // const char* statNames[nbranchStat] = {"Median","LTM"};
3131 //
3132 // for (Int_t iname=0; iname<nbranchAlias; ++iname) {
3133 // TString branchName = TString::Format("%s.%s", friendName.Data(), bNames[i]);
3134 //
3135 // for (Int_t istat=0; istat<nbranchStat; ++istat) {
3136 //
3137 // }
3138 // }
3139 
3140  tMain->SetAlias((friendName+".spectrMean_LTMRatio").Data(),
3141  TString::Format("(%s.spectrMean.fElements/(%s.spectrMean_LTM+0))",
3142  friendName.Data(),friendName.Data()).Data());
3143 
3144  tMain->SetAlias((friendName+".spectrMean_MedianRatio").Data(),
3145  TString::Format("(%s.spectrMean.fElements/(%s.spectrMean_Median+0))",
3146  friendName.Data(),friendName.Data()).Data());
3147  tMain->SetAlias((friendName+".spectrMean_MeanRatio").Data(),
3148  TString::Format("(%s.spectrMean.fElements/(%s.spectrMean_Mean+0))",
3149  friendName.Data(),friendName.Data()).Data());
3150  tMain->SetAlias((friendName+".spectrMean_MeanRatio").Data(),
3151  TString::Format("(%s.spectrMean.fElements/%s.spectrMean_Mean)",
3152  friendName.Data(),friendName.Data()).Data());
3153 
3154  tMain->SetAlias((friendName+".fitMean_LTMRatio").Data(),
3155  TString::Format("(%s.fitMean.fElements/(%s.fitMean_LTM+0))",
3156  friendName.Data(),friendName.Data()).Data());
3157  tMain->SetAlias((friendName+".fitRMS_LTMRatio").Data(),
3158  TString::Format("(%s.fitRMS.fElements/(%s.fitRMS_LTM+0))",
3159  friendName.Data(),friendName.Data()).Data());
3160 
3161  tMain->SetAlias((friendName+".fitMean_MedianRatio").Data(),
3162  TString::Format("(%s.fitMean.fElements/(%s.fitMean_Median+0))",
3163  friendName.Data(),friendName.Data()).Data());
3164  tMain->SetAlias((friendName+".fitRMS_MedianRatio").Data(),
3165  TString::Format("(%s.fitRMS.fElements/(%s.fitRMS_Median+0))",
3166  friendName.Data(),friendName.Data()).Data());
3167  tMain->SetAlias((friendName+".fitMean_MeanRatio").Data(),
3168  TString::Format("(%s.fitMean.fElements/(%s.fitMean_Mean+0))",
3169  friendName.Data(),friendName.Data()).Data());
3170  tMain->SetAlias((friendName+".fitRMS_MeanRatio").Data(),
3171  TString::Format("(%s.fitRMS.fElements/(%s.fitRMS_Mean+0))",
3172  friendName.Data(),friendName.Data()).Data());
3173  tMain->SetAlias((friendName+".fitMean_MeanRatio").Data(),
3174  TString::Format("(%s.fitMean.fElements/%s.fitMean_Mean)",
3175  friendName.Data(),friendName.Data()).Data());
3176 
3177  }
3178 
3179  // === add the calibQA trees ======================================
3180  TString inputTreesQACalib = gSystem->GetFromPipe(Form("ls %s/calibQAdEdx/20*/*.tree.root",baseDir.Data()));
3181  TObjArray *arrInputTreesQACalib = inputTreesQACalib.Tokenize("\n");
3182 
3183  for (Int_t itree=0; itree<arrInputTreesQACalib->GetEntriesFast(); ++itree) {
3184  TFile *fin2 = TFile::Open(arrInputTreesQACalib->At(itree)->GetName());
3185  TTree *tin = (TTree*)fin2->Get("calPads");
3186  gROOT->cd();
3187  TString friendName=gSystem->BaseName(arrInputTreesQACalib->At(itree)->GetName());
3188  friendName.ReplaceAll("calibQA.","");
3189  friendName.ReplaceAll(".tree.root","");
3190  friendName="QA."+friendName;
3191  tMain->AddFriend(tin,friendName.Data());
3192 
3193  // set aliases
3194  tMain->SetAlias((friendName+".MaxCharge_LTMRatio").Data(),
3195  TString::Format("(%s.MaxCharge.fElements/%s.MaxCharge_LTM)",
3196  friendName.Data(),friendName.Data()).Data());
3197 
3198  tMain->SetAlias((friendName+".MaxCharge_MedianRatio").Data(),
3199  TString::Format("(%s.MaxCharge.fElements/%s.MaxCharge_Median)",
3200  friendName.Data(),friendName.Data()).Data());
3201  tMain->SetAlias((friendName+".MaxCharge_MeanRatio").Data(),
3202  TString::Format("(%s.MaxCharge.fElements/%s.MaxCharge_Mean)",
3203  friendName.Data(),friendName.Data()).Data());
3204 
3205  tMain->SetAlias((friendName+".MeanCharge_LTMRatio").Data(),
3206  TString::Format("(%s.MeanCharge.fElements/%s.MeanCharge_LTM)",
3207  friendName.Data(),friendName.Data()).Data());
3208 
3209  tMain->SetAlias((friendName+".MeanCharge_MedianRatio").Data(),
3210  TString::Format("(%s.MeanCharge.fElements/%s.MeanCharge_Median)",
3211  friendName.Data(),friendName.Data()).Data());
3212  tMain->SetAlias((friendName+".MeanCharge_MeanRatio").Data(),
3213  TString::Format("(%s.MeanCharge.fElements/%s.MeanCharge_Mean)",
3214  friendName.Data(),friendName.Data()).Data());
3215 
3216  }
3217 
3218  return tMain;
3219 }
3220 
3221 
3222 //_____________________________________________________________________________________
3224 {
3229 
3230  TString inputTreesPulserCalib = gSystem->GetFromPipe(Form("ls %s/calibPulser/20*/*.tree.root",baseDir.Data()));
3231  TObjArray *arrInputTreesPulserCalib = inputTreesPulserCalib.Tokenize("\n");
3232  for (Int_t itree=0; itree<arrInputTreesPulserCalib->GetEntriesFast(); ++itree) {
3233  TFile *fin2 = TFile::Open(arrInputTreesPulserCalib->At(itree)->GetName());
3234  TTree *tin = (TTree*)fin2->Get("calPads");
3235  gROOT->cd();
3236  TString friendName=gSystem->BaseName(arrInputTreesPulserCalib->At(itree)->GetName());
3237  friendName.ReplaceAll("calibPulser.","");
3238  friendName.ReplaceAll(".tree.root","");
3239  friendName="Pulser."+friendName;
3240  tMain->AddFriend(tin,friendName.Data());
3241  // set aliases
3242 
3243  tMain->SetAlias((friendName+".CEQmean_LTMRatio").Data(),
3244  TString::Format("(%s.CEQmean.fElements/%s.CEQmean_LTM)",
3245  friendName.Data(),friendName.Data()).Data());
3246  tMain->SetAlias((friendName+".CEQmean_MedianRatio").Data(),
3247  TString::Format("(%s.CEQmean.fElements/%s.CEQmean_Median)",
3248  friendName.Data(),friendName.Data()).Data());
3249  tMain->SetAlias((friendName+".CEQmean_MeanRatio").Data(),
3250  TString::Format("(%s.CEQmean.fElements/%s.CEQmean_Mean)",
3251  friendName.Data(),friendName.Data()).Data());
3252  //
3253  tMain->SetAlias((friendName+".CETmean_LTMDelta").Data(),
3254  TString::Format("(%s.CETmean.fElements-%s.CETmean_LTM)",
3255  friendName.Data(),friendName.Data()).Data());
3256  tMain->SetAlias((friendName+".CETmean_MedianDelta").Data(),
3257  TString::Format("(%s.CETmean.fElements-%s.CETmean_Median)",
3258  friendName.Data(),friendName.Data()).Data());
3259  tMain->SetAlias((friendName+".CETmean_MeanDelta").Data(),
3260  TString::Format("(%s.CETmean.fElements-%s.CETmean_Mean)",
3261  friendName.Data(),friendName.Data()).Data());
3262  }
3263  return tMain;
3264 }
3265 
3266 
3267 TTree* AliTPCcalibDButil::ConnectDistortionTrees(TString baseDir, TString selection, TTree *tMain){
3276 
3277  TString inputTreesDistortionCalib = "";
3278  if (selection.Contains(".list")){
3279  inputTreesDistortionCalib=gSystem->GetFromPipe(Form("cat %s",selection.Data()));
3280  }else{
3281  inputTreesDistortionCalib=gSystem->GetFromPipe(Form("find %s -iname \"%s\"",baseDir.Data(),selection.Data()));
3282  }
3283  TObjArray *arrInputTreesDistortionCalib = inputTreesDistortionCalib.Tokenize("\n");
3284  //
3285  TString treePrefix="";
3286  for (Int_t itree=0; itree<arrInputTreesDistortionCalib->GetEntriesFast(); ++itree) {
3287  TString fstring = arrInputTreesDistortionCalib->At(itree)->GetName();
3288  if (fstring.Index("Prefix:")==0){ //get tree descriptor
3289  treePrefix=TString(&(fstring[7]));
3290  continue;
3291  }
3292  if (fstring.Index("#")==0){ // ignore comment field
3293  continue;
3294  }
3295  TFile *finput= TFile::Open(arrInputTreesDistortionCalib->At(itree)->GetName());
3296  TString strFile=arrInputTreesDistortionCalib->At(itree)->GetName();
3297  TObjArray *path=strFile.Tokenize("/");
3298  Int_t plength=path->GetEntries();
3299  if (!finput) continue;
3300  TList* list = finput->GetListOfKeys();
3301  Int_t nkeys=list->GetEntries();
3302  for (Int_t ikey=0; ikey<nkeys; ikey++){
3303  TKey * key = (TKey*)list->At(ikey);
3304  if (strstr(key->GetClassName(),"TTree")==0) continue;
3305  TTree * tree = dynamic_cast<TTree*>(finput->Get(list->At(ikey)->GetName()));
3306  if (!tree) continue;
3307  TString friendName="";
3308  if (treePrefix.Length()==0) {
3309  friendName=TString::Format("%s.%s.%s",path->At(plength-3)->GetName(),path->At(plength-2)->GetName(), tree->GetName());
3310  }else{
3311  friendName=TString::Format("%s.%s",treePrefix.Data(), tree->GetName());
3312  }
3313  ::Info("AliTPCcalibDButil::ConnectDistortionTrees","%s",friendName.Data());
3314  if (tMain==0) {
3315  tMain=tree;
3316  tree = dynamic_cast<TTree*>(finput->Get(list->At(ikey)->GetName()));
3317  }
3318  tMain->AddFriend(tree,friendName.Data());
3319  }
3320  }
3321  // tMain->SetAlias("");
3322  return tMain;
3323 }
3324 
3325 
3326 //_____________________________________________________________________________________
3327 TTree* AliTPCcalibDButil::ConnectCalPadTrees(TString baseDir, TString pattern, TTree *tMain, Bool_t checkAliases)
3328 {
3335 
3336  //
3337  // === add the calibPulser trees ======================================
3338  TString inputTreesCalPad = gSystem->GetFromPipe(Form("ls %s/%s",baseDir.Data(), pattern.Data()));
3339  TObjArray *arrInputTreesCalPad = inputTreesCalPad.Tokenize("\n");
3340  //
3341  for (Int_t itree=0; itree<arrInputTreesCalPad->GetEntriesFast(); ++itree) {
3342  TFile *fin2 = TFile::Open(arrInputTreesCalPad->At(itree)->GetName());
3343  TTree *tin = (TTree*)fin2->Get("calPads");
3344  gROOT->cd();
3345  TString friendName=arrInputTreesCalPad->At(itree)->GetName();
3346  friendName.ReplaceAll("//","/");
3347  friendName.ReplaceAll(baseDir.Data(),"");
3348  friendName.ReplaceAll("^/","");
3349  friendName.ReplaceAll("/",".");
3350  friendName.ReplaceAll(".tree.",".");
3351  friendName.ReplaceAll(".root","");
3352  printf("%s\n", friendName.Data());
3353  ::Info("AliTPCcalibDButil::ConnectCalPadTrees","%s",friendName.Data());
3354  if (tMain==0) tMain=tin;
3355  tMain->AddFriend(tin,friendName.Data());
3356  TObjArray * branches=tin->GetListOfBranches();
3357  Int_t nBranches=branches->GetEntries();
3358  for (Int_t ibranch=0; ibranch<nBranches; ibranch++){
3359  TString bname=branches->At(ibranch)->GetName();
3360  if (bname.Contains(".")>0){
3361  bname.ReplaceAll(".","");
3362  // replace elements
3363  tin->SetAlias((bname).Data(), (bname+".fElements").Data());
3364  tMain->SetAlias((friendName+"."+bname).Data(), (friendName+"."+bname+".fElements").Data());
3365  //
3366  // make normalized values per chamber
3367  //
3368  if (branches->FindObject(bname+"_LTM")!=0){
3369  tMain->SetAlias((friendName+"."+bname+"_MeanRatio").Data(), (friendName+"."+bname+".fElements/"+friendName+"."+bname+"_Mean").Data());
3370  tMain->SetAlias((friendName+"."+bname+"_MedianRatio").Data(), (friendName+"."+bname+".fElements/"+friendName+"."+bname+"_Median").Data());
3371  tMain->SetAlias((friendName+"."+bname+"_LTMRatio").Data(), (friendName+"."+bname+".fElements/"+friendName+"."+bname+"_LTM").Data());
3372  tMain->SetAlias((friendName+"."+bname+"_MeanDelta").Data(), (friendName+"."+bname+".fElements-"+friendName+"."+bname+"_Mean").Data());
3373  tMain->SetAlias((friendName+"."+bname+"_MedianDelta").Data(), (friendName+"."+bname+".fElements-"+friendName+"."+bname+"_Median").Data());
3374  tMain->SetAlias((friendName+"."+bname+"_LTMDelta").Data(), (friendName+"."+bname+".fElements-"+friendName+"."+bname+"_LTM").Data());
3375  }
3376  // if (branches->FindObject(bname+"_Med3.")!=0){
3377  tMain->SetAlias((friendName+"."+bname+"_Med3Ratio").Data(), (friendName+"."+bname+".fElements/"+friendName+"."+bname+"Med3.fElements").Data());
3378  tMain->SetAlias((friendName+"."+bname+"_Med5Ratio").Data(), (friendName+"."+bname+".fElements/"+friendName+"."+bname+"Med5.fElements").Data());
3379  tMain->SetAlias((friendName+"."+bname+"_Par6GRatio").Data(), (friendName+"."+bname+".fElements/"+friendName+"."+bname+"Par6G.fElements").Data());
3380  tMain->SetAlias((friendName+"."+bname+"_Med3Delta").Data(), (friendName+"."+bname+".fElements-"+friendName+"."+bname+"Med3.fElements").Data());
3381  tMain->SetAlias((friendName+"."+bname+"_Med5Delta").Data(), (friendName+"."+bname+".fElements-"+friendName+"."+bname+"Med5.fElements").Data());
3382  tMain->SetAlias((friendName+"."+bname+"_Par6GDelta").Data(), (friendName+"."+bname+".fElements-"+friendName+"."+bname+"Par6G.fElements").Data());
3383  // }
3384  }
3385  }
3386  }
3387  //
3388  //
3389  //
3390  if (checkAliases){
3391  // to be implemented
3392  }
3393  return tMain;
3394 }
3395 
3396 
3397 
static AliTPCcalibDB * Instance()
const TString & GetURI() const
Definition: AliCDBStorage.h:34
TObjArray * GetCEfitsDrift() const
static Double_t EvalGraphConst(TGraph *const graph, Double_t xref)
AliTPCCalPad * fCETmean
central electrode mean time information
TMap * fCurrentRefMap
reference data map of entries currently loaded
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
AliTPCCalPad * fRefPulserTrms
Reference pulser rms time information.
UInt_t GetNPads(UInt_t sector, UInt_t row) const
Definition: AliTPCROC.h:30
const Double_t kEpsilon
Float_t GetZSigma() const
Definition: AliTPCParam.h:369
TObjArray * GetCEData() const
Float_t fCETmaxLimitAbs
maximum variation in CE data before pads will be treated as outliers
TFile * Open(const char *filename, Long64_t &nevents)
AliTPCCalPad * fRefCETrms
Reference central electrode rms time information.
AliTPCCalPad * fRefPadNoise
Reference noise information.
void ProcessGoofie(TVectorD &vecEntries, TVectorD &vecMedian, TVectorD &vecMean, TVectorD &vecRMS)
AliTPCCalROC * GetCalROC(Int_t sector) const
Definition: AliTPCCalPad.h:39
AliSplineFit * GetFit() const
Definition: AliDCSSensor.h:54
AliTPCCalPad * fRefALTROAcqStop
Reference accquistion stop time bin.
static TTree * ConnectCalPadTrees(TString baseDir, TString pattern, TTree *tMain, Bool_t checkAliases)
AliTPCCalPad * fRefPedestalMasked
Reference masked channels in pedestal run.
AliTPCCalPad * fRefPedestals
Reference pedestal information.
AliTPCCalPad * CreatePulserOutlyerMap(Int_t &noutliersPulser, AliTPCCalPad *const pulserOut=0, Float_t cutTime=3, Float_t cutnRMSQ=5, Float_t cutnRMSrms=5)
void SetTimeStamp(const UInt_t ts)
Double_t * GetX() const
Definition: AliSplineFit.h:37
Float_t GetMeanAltro(const AliTPCCalROC *roc, const Int_t row, const Int_t pad, AliTPCCalROC *const rocOut=0x0)
AliCDBStorage * GetSpecificStorage(const char *calibType)
void SetGraph(TGraph *gr)
Definition: AliDCSSensor.h:64
static Int_t GetNearest(TGraph *graph, Double_t xref, Double_t &dx, Double_t &y)
void Add(Float_t c1)
TArrayI fRunsStart
start time for given run
AliTPCCalPad * GetMaxCharge() const
Definition: AliTPCdataQA.h:60
static Double_t GetVDriftTPC(Double_t &dist, Int_t run, Int_t timeStamp, Double_t deltaT=86400, Double_t deltaTLaser=3600, Int_t valType=0)
static void FilterGoofie(AliDCSSensorArray *goofieArray, Double_t deltaT=2, Double_t cutSigma=4., Double_t minVdn=8.5, Double_t maxVdn=9.05, TTreeSRedirector *const pcstream=0)
Double_t GetMedian(AliTPCCalROC *const outlierROC=0, EPadType padType=kAll) const
#define TObjArray
Double_t GetRMS(AliTPCCalROC *const outlierROC=0, EPadType padType=kAll) const
Double_t * GetY1() const
Definition: AliSplineFit.h:39
AliTPCCalPad * GetAltroMasked(const char *cdbPath, const char *name)
Int_t NumSensors() const
Bool_t CreateGUIRefTree(const char *filename="")
AliTPCmapper * fMapper
TPC mapping handler.
void ProcessQAData(TVectorD &vQaOcc, TVectorD &vQaQtot, TVectorD &vQaQmax)
const char * path
Bool_t Merge(const AliRelAlignerKalman *al)
Manager and of geomety classes for set: TPC.
Definition: AliTPCParam.h:18
static void FilterTracks(Int_t run, Double_t cutSigma=20., TTreeSRedirector *const pcstream=0)
AliTPCmapper.
Definition: AliTPCmapper.h:15
UInt_t GetNRows(UInt_t sector) const
Definition: AliTPCROC.h:28
Float_t GetDriftV() const
Definition: AliTPCParam.h:342
Int_t GetReferenceRun(const char *type) const
Float_t fIrocTimeOffset
timing offset between IROC and OROC in timebins
void RemoveSensorNum(Int_t ind)
static TObjArray * SmoothRelKalman(TObjArray *const array, const TMatrixD *statP, Bool_t direction, Float_t sigmaCut)
Float_t GetValue(UInt_t row, UInt_t pad) const
Definition: AliTPCCalROC.h:38
void Multiply(Float_t c1)
AliTPCCalPad * fRefPulserTmean
Reference pulser mean time information.
AliTPCdataQA * fRefDataQA
Reference data QA.
TROOT * gROOT
Double_t GetMedian(AliTPCCalPad *outlierPad=0, AliTPCCalROC::EPadType padType=AliTPCCalROC::kAll) const
static TGraphErrors * FilterGraphMedianErr(TGraphErrors *graph, Float_t sigmaCut, Double_t &medianY)
static Float_t FilterSensor(AliDCSSensor *sensor, Double_t ymin, Double_t ymax, Double_t maxdy, Double_t sigmaCut)
TTreeSRedirector * pcstream
UInt_t GetNChannels(UInt_t sector) const
Definition: AliTPCROC.h:29
TObjArray * arrInputTreesDistortionCalib
AliTPCParam * GetParameters() const
static Double_t GetVDriftTPCCE(Double_t &dist, Int_t run, Int_t timeStamp, Double_t deltaT=43200, Int_t side=2)
AliTPCCalPad * fRefCETmean
Reference central electrode mean time information.
AliTPCCalPad * GetPedestals() const
Definition: AliTPCcalibDB.h:83
AliDCSSensor * GetSensor(Int_t IdDCS)
static void FilterCE(Double_t deltaT=100, Double_t cutAbs=10, Double_t cutSigma=4., TTreeSRedirector *const pcstream=0)
AliTPCCalPad * GetNTimeBins() const
Definition: AliTPCdataQA.h:66
void GlobalFit(const AliTPCCalROC *ROCoutliers, Bool_t robust, TVectorD &fitParam, TMatrixD &covMatrix, Float_t &chi2, Int_t fitType=1, Double_t chi2Threshold=5, Double_t robustFraction=0.7, Double_t err=1, EPadType padType=kAll)
TString fRefValidity
validity range of reference data
Int_t GetEventCounter() const
Definition: AliTPCdataQA.h:93
Float_t fPulQminLimit
minimum charge value for Pulser Signals before pads will be treated as outliers
AliTPCCalPad * GetTimePosition() const
Definition: AliTPCdataQA.h:68
TTree * tree
npoints
Definition: driftITSTPC.C:85
AliTPCdataQA * GetDataQA() const
AliSplineFit fit
Definition: CalibTime.C:30
AliTPCCalPad * fRefALTROMasked
Reference ALTRO masked channels information.
const Float_t kAlmost0
Int_t GetFEC(Int_t roc, Int_t padrow, Int_t pad) const
void SetFit(AliSplineFit *f)
Definition: AliDCSSensor.h:65
static Double_t GetTime0TPCITS(Double_t &dist, Int_t run, Int_t timeStamp)
Float_t GetL1Delay() const
Definition: AliTPCParam.h:398
Class providing the calculation of derived quantities (mean,rms,fits,...) of calibration entries...
void ProcessNoiseVariations(TVectorF &noiseDeviations)
#define AliWarning(message)
Definition: AliLog.h:541
AliTPCCalPad * CreatePadTime0(Int_t model, Double_t &gyA, Double_t &gyC, Double_t &chi2A, Double_t &chi2C)
TStatToolkit stat
Definition: AnalyzeLaser.C:5
static TMatrixD * MakeStatRelKalman(TObjArray *const array, Float_t minFraction, Int_t minStat, Float_t maxvd)
AliTPCCalPad * fPedestals
pedestal information
static AliTPCCalPad * CreateCalPadFit(const char *fitFormula, const TVectorD &fitParamSideA, const TVectorD &fitParamSideC)
Int_t fNpulserOutliers
number of outliers from Pulser calibration
TObjArray * array
Definition: AnalyzeLaser.C:12
AliCDBEntry * Get(const AliCDBId &query, Bool_t forceCaching=kFALSE)
AliDCSSensorArray * fGoofieArray
Goofie Data.
TArrayI fRuns
run list with OCDB info
AliTPCCalPad * fPulserOutlier
pulser outlier map
static TGraph * FilterGraphMedian(TGraph *const graph, Float_t sigmaCut, Double_t &medianY)
void ProcessPulser(TVectorD &vMeanTime)
static Float_t FilterTemperature(AliTPCSensorTempArray *tempArray, Double_t ymin=15, Double_t ymax=22, Double_t sigmaCut=5)
UInt_t GetNPads(UInt_t row) const
Definition: AliTPCCalROC.h:37
Double_t sigmaCut
Definition: DIMUONFakes.C:36
AliTPCCalPad * GetRefCalPad(AliCDBEntry *entry, const char *objName)
TObject * GetObject()
Definition: AliCDBEntry.h:56
AliTPCCalPad * fRefALTROFPED
Reference fixed pedestal value.
void GetStateCov(TMatrixDSym &cov) const
Double_t chi2
Definition: AnalyzeLaser.C:7
AliTPCCalPad * fPulserQmean
pulser mean q information
UInt_t GetNInnerSector() const
Definition: AliTPCROC.h:47
AliTPCCalPad * GetCEQmean() const
const char * GetRefValidity() const
TArrayI fRunsStop
stop time for given run
TObjArray * GetCErocTtime() const
Bool_t HasRefChanged(const char *cdbPath)
void ProcessNoiseData(TVectorD &vNoiseMean, TVectorD &vNoiseMeanSenRegions, TVectorD &vNoiseRMS, TVectorD &vNoiseRMSSenRegions, Int_t &nonMaskedZero, Int_t &nNaN)
AliTPCCalPad * fPadNoise
noise information
Double_t GetMean(AliTPCCalROC *const outlierROC=0, EPadType padType=kAll) const
void PulserOutlierMap(AliTPCCalPad *pulOut, const AliTPCCalPad *pulT, const AliTPCCalPad *pulQ)
void UpdateRunInformations(Int_t run, Bool_t force=kFALSE)
#define AliInfo(message)
Definition: AliLog.h:484
TGraph * GetGraph() const
Definition: AliDCSSensor.h:53
TGraph * gr
Definition: CalibTime.C:25
AliTPCCalPad * fRefPulserOutlier
Reference pulser outlier map.
TString treePrefix
Geometry class for a single ROC.
Definition: AliTPCROC.h:14
Float_t GetTSample() const
Definition: AliTPCParam.h:366
std::vector< RunInfo > runs
AliTPCCalPad * fRefCEQmean
Reference central electrode mean q information.
AliTPCCalPad * GetPulserQmean() const
void SetValue(UInt_t row, UInt_t pad, Float_t vd)
Definition: AliTPCCalROC.h:40
void Add(Float_t c1)
void SetRunNumber(const Int_t rn)
void ProcessPedestalVariations(TVectorF &pedestalDeviations)
AliTPCCalPad * GetCETmean() const
AliTPCCalPad * GetPadNoise() const
Definition: AliTPCcalibDB.h:82
AliTPCCalPad * GetPulserTmean() const
AliTPCCalPad * GetPulserTrms() const
Int_t GetRunNumber() const
AliTPCCalibRaw * fRefCalibRaw
Reference raw calibration object.
AliTPCCalPad * fCETrms
central electrode rms time information
AliTPCCalibRaw * fCalibRaw
raw calibration object
TObjArray * GetTimeVdriftSplineRun(Int_t run)
void ProcessALTROConfig(Int_t &nMasked)
void SetRejectOutliers(const Bool_t r=kTRUE)
AliTPCCalPad * fPulserTmean
pulser mean time information
Int_t GetChip(Int_t roc, Int_t padrow, Int_t pad) const
return tMain
TPC calibration base class for one ROC.
Definition: AliTPCCalROC.h:20
Double_t Eval(Double_t x, Int_t deriv=0) const
AliTPCCalPad * GetNPads() const
Definition: AliTPCdataQA.h:67
virtual Bool_t Update()
TString baseDir
Definition: UnitTest.C:38
AliTPCCalPad * fRefALTROZsThr
Reference zero suppression threshol.
static void Sort(TGraph *graph)
static TGraph * FilterGraphMedianAbs(TGraph *graph, Float_t cut, Double_t &medianY)
Definition: AliCDBEntry.h:18
Int_t GetCurrentReferenceRun(const char *type) const
TF1 * f
Definition: interpolTest.C:21
const char * GetGUIRefTreeDefaultName()
AliTPCCalPad * GetMeanCharge() const
Definition: AliTPCdataQA.h:61
TString * fitString
Definition: MakeGlobalFit.C:71
UInt_t GetNchannels() const
Definition: AliTPCCalROC.h:34
UInt_t GetSector() const
Definition: AliTPCCalROC.h:32
AliTPCCalPad * fRefALTROAcqStart
Reference accquistion start time bin.
Double_t GetTPCvdCorr() const
AliDCSSensorArray * GetGoofieSensors(Int_t run)
void DumpToFile(const char *fileName)
Long64_t GetRun() const
Definition: AliTPCcalibDB.h:59
Double_t chi2A[6]
AliTPCCalPad * fRefPulserQmean
Reference pulser mean q information.
TObjArray * GetCErocQtime() const
static Double_t GetVDriftTPCLaserTracksCommon(Double_t &dist, Int_t timeStamp, Double_t deltaT, Int_t side, TObjArray *const array)
static TTree * ConnectGainTrees(TString baseDir)
Preprocessor class for HLT and DAQ.
void SetReferenceRun(Int_t run=-1)
#define AliInfoGeneral(scope, message)
Definition: AliLog.h:494
void ProcessPulserVariations(TVectorF &pulserQdeviations, Float_t &varQMean, Int_t &npadsOutOneTB, Int_t &npadsOffAdd)
TPC calibration class for parameters which saved per pad.
static void SmoothGraph(TGraph *graph, Double_t delta)
void SetRefFile(const char *filename)
static Double_t GetVDriftTPCITS(Double_t &dist, Int_t run, Int_t timeStamp)
AliCDBEntry * GetRefEntry(const char *cdbPath)
AliTPCCalPad * GetNLocalMaxima() const
Definition: AliTPCdataQA.h:62
Int_t GetKnots() const
Definition: AliSplineFit.h:36
const TString & GetPath() const
Definition: AliCDBId.h:40
TTimeStamp GetStartTime() const
AliCDBStorage * GetDefaultStorage() const
Definition: AliCDBManager.h:61
static Double_t GetVDriftTPCLaserTracks(Double_t &dist, Int_t run, Int_t timeStamp, Double_t deltaT=43200, Int_t side=2)
AliTPCCalPad * CreateCEOutlyerMap(Int_t &noutliersCE, AliTPCCalPad *const ceOut=0, Float_t minSignal=10, Float_t cutTrmsMin=0.9, Float_t cutTrmsMax=1.2, Float_t cutMaxDistT=0.7)
Int_t MakeRunList(Int_t startRun, Int_t stopRun)
void GetState(TVectorD &state) const
TMap * fRefMap
latest map to reference information
static Double_t GetLaserTime0(Int_t run, Int_t timeStamp, Int_t deltaT, Int_t side)
static AliTPCROC * Instance()
Definition: AliTPCROC.cxx:34
AliDCSSensor * GetSensorNum(Int_t ind)
void SetOwner(Bool_t owner)
Definition: AliCDBEntry.h:64
class TVectorT< Double_t > TVectorD
void GlobalSidesFit(const AliTPCCalPad *PadOutliers, const char *fitFormula, TVectorD &fitParamSideA, TVectorD &fitParamSideC, TMatrixD &covMatrixSideA, TMatrixD &covMatrixSideC, Float_t &chi2SideA, Float_t &chi2SideC, AliTPCCalPad *pointError=0, Bool_t robust=kFALSE, Double_t robustFraction=0.7)
#define AliError(message)
Definition: AliLog.h:591
static AliTPCCalROC * CreateGlobalFitCalROC(TVectorD &fitParam, Int_t sector, EPadType padType=kAll, AliTPCCalROC *oldTPCCalROC=0)
TCut cut
Definition: MakeGlobalFit.C:75
AliCDBId & GetId()
Definition: AliCDBEntry.h:51
Float_t GetZLength(Int_t sector=0) const
Definition: AliTPCParam.h:841
static AliCDBManager * Instance(TMap *entryCache=NULL, Int_t run=-1)
AliTPCCalPad * GetNoThreshold() const
Definition: AliTPCdataQA.h:59
static TTree * ConnectPulserTrees(TString baseDir, TTree *tree=0)
AliTPCCalPad * fCEQmean
central electrode mean q information
UInt_t GetTimeStamp() const
AliTPCCalPad * fRefCEMasked
Reference masked channels in laser run.
AliTPCCalPad * fPulserTrms
pulser rms time information
AliTPCCalPad * CreatePadTime0CE(TVectorD &fitResultsA, TVectorD &fitResultsC, Int_t &nOut, Double_t &chi2A, Double_t &chi2C, const char *dumpfile=0)
AliTPCCalPad * GetALTROMasked() const
Definition: AliTPCcalibDB.h:93
static TTree * ConnectDistortionTrees(TString baseDir, TString selection, TTree *tMain)
static void EvaluateUni(const Int_t nvectors, const Double_t *data, Double_t &mean, Double_t &sigma, const Int_t hSub)
Definition: AliMathBase.cxx:62
Int_t debug
AliTPCdataQA * fDataQA
data qa
void ProcessCEdata(const char *fitFormula, TVectorD &fitResultsA, TVectorD &fitResultsC, Int_t &noutliersCE, Double_t &chi2A, Double_t &chi2C, AliTPCCalPad *const outCE=0)
AliTPCCalPad * fRefPulserMasked
Reference masked channels in pulser run.
AliTPCcalibDB * fCalibDB
pointer to calibDB object
AliTPCCalPad * GetCETrms() const
void Multiply(Float_t c1)
void ProcessCEgraphs(TVectorD &vecTEntries, TVectorD &vecTMean, TVectorD &vecTRMS, TVectorD &vecTMedian, TVectorD &vecQEntries, TVectorD &vecQMean, TVectorD &vecQRMS, TVectorD &vecQMedian, Float_t &driftTimeA, Float_t &driftTimeC)
class TMatrixT< Double_t > TMatrixD
Int_t GetNUpdates() const
Double_t GetPTRelative(UInt_t absTimeSec, Int_t side)
TTimeStamp GetEndTime() const
UInt_t GetNrows() const
Definition: AliTPCCalROC.h:33
TCut cutTime
Definition: CalibQA.C:14
Double_t * GetY0() const
Definition: AliSplineFit.h:38
AliTPCCalibRaw * GetCalibRaw() const
Int_t FindRunTPC(Int_t itime, Bool_t debug=kFALSE)
static Double_t GetVDriftTPCLaserTracksOnline(Double_t &dist, Int_t, Int_t timeStamp, Double_t deltaT=43200, Int_t side=2)
Int_t GetNRowUp1() const
static Double_t GetTriggerOffsetTPC(Int_t run, Int_t timeStamp, Double_t deltaT=86400, Double_t deltaTLaser=3600, Int_t valType=0)
AliTPCCalPad * fALTROMasked
ALTRO masked channels information.