1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 ///////////////////////////////////////////////////////////////////////////////
19 // Class providing the calculation of derived quantities (mean,rms,fits,...) //
20 // of calibration entries //
25 ////////////////////////////////////////////////////////////////////////////////
29 #include <TObjArray.h>
32 #include <TDirectory.h>
33 #include <AliCDBStorage.h>
34 #include <AliDCSSensorArray.h>
35 #include <AliTPCSensorTempArray.h>
36 #include <AliDCSSensor.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"
44 #include "TGraphErrors.h"
46 #include "AliTPCcalibDButil.h"
47 #include "AliTPCPreprocessorOnline.h"
48 #include "AliTPCCalibVdrift.h"
50 ClassImp(AliTPCcalibDButil)
51 AliTPCcalibDButil::AliTPCcalibDButil() :
59 fPulserOutlier(new AliTPCCalPad("PulserOutliers","PulserOutliers")),
70 fRefPulserOutlier(new AliTPCCalPad("RefPulserOutliers","RefPulserOutliers")),
77 fMapper(new AliTPCmapper(0x0)),
81 fPulTmaxLimitAbs(1.5),
84 fRuns(0), // run list with OCDB info
85 fRunsStart(0), // start time for given run
86 fRunsStop(0) // stop time for given run
92 //_____________________________________________________________________________________
93 AliTPCcalibDButil::~AliTPCcalibDButil()
98 delete fPulserOutlier;
99 delete fRefPulserOutlier;
101 if (fRefPadNoise) delete fRefPadNoise;
102 if (fRefPedestals) delete fRefPedestals;
103 if (fRefPulserTmean) delete fRefPulserTmean;
104 if (fRefPulserTrms) delete fRefPulserTrms;
105 if (fRefPulserQmean) delete fRefPulserQmean;
106 if (fRefCETmean) delete fRefCETmean;
107 if (fRefCETrms) delete fRefCETrms;
108 if (fRefCEQmean) delete fRefCEQmean;
109 if (fRefALTROMasked) delete fRefALTROMasked;
110 if (fRefCalibRaw) delete fRefCalibRaw;
113 //_____________________________________________________________________________________
114 void AliTPCcalibDButil::UpdateFromCalibDB()
117 // Update pointers from calibDB
119 if (!fCalibDB) fCalibDB=AliTPCcalibDB::Instance();
120 fPadNoise=fCalibDB->GetPadNoise();
121 fPedestals=fCalibDB->GetPedestals();
122 fPulserTmean=fCalibDB->GetPulserTmean();
123 fPulserTrms=fCalibDB->GetPulserTrms();
124 fPulserQmean=fCalibDB->GetPulserQmean();
125 fCETmean=fCalibDB->GetCETmean();
126 fCETrms=fCalibDB->GetCETrms();
127 fCEQmean=fCalibDB->GetCEQmean();
128 fALTROMasked=fCalibDB->GetALTROMasked();
129 fGoofieArray=fCalibDB->GetGoofieSensors(fCalibDB->GetRun());
130 fCalibRaw=fCalibDB->GetCalibRaw();
131 UpdatePulserOutlierMap();
133 //_____________________________________________________________________________________
134 void AliTPCcalibDButil::ProcessCEdata(const char* fitFormula, TVectorD &fitResultsA, TVectorD &fitResultsC,
135 Int_t &noutliersCE, Double_t & chi2A, Double_t &chi2C, AliTPCCalPad *outCE)
138 // Process the CE data for this run
139 // the return TVectorD arrays contian the results of the fit
140 // noutliersCE contains the number of pads marked as outliers,
141 // not including masked and edge pads
144 //retrieve CE and ALTRO data
146 TString fitString(fitFormula);
147 fitString.ReplaceAll("++","#");
148 Int_t ndim=fitString.CountChar('#')+2;
149 fitResultsA.ResizeTo(ndim);
150 fitResultsC.ResizeTo(ndim);
159 if (outCE) out=outCE;
160 else out=new AliTPCCalPad("outCE","outCE");
161 AliTPCCalROC *rocMasked=0x0;
162 //loop over all channels
163 for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
164 AliTPCCalROC *rocData=fCETmean->GetCalROC(iroc);
165 if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(iroc);
166 AliTPCCalROC *rocOut=out->GetCalROC(iroc);
168 noutliersCE+=AliTPCROC::Instance()->GetNChannels(iroc);
172 //add time offset to IROCs
173 if (iroc<AliTPCROC::Instance()->GetNInnerSector())
174 rocData->Add(fIrocTimeOffset);
176 UInt_t nrows=rocData->GetNrows();
177 for (UInt_t irow=0;irow<nrows;++irow){
178 UInt_t npads=rocData->GetNPads(irow);
179 for (UInt_t ipad=0;ipad<npads;++ipad){
180 rocOut->SetValue(irow,ipad,0);
181 //exclude masked pads
182 if (rocMasked && rocMasked->GetValue(irow,ipad)) {
183 rocOut->SetValue(irow,ipad,1);
186 //exclude first two rows in IROC and last two rows in OROC
188 if (irow<2) rocOut->SetValue(irow,ipad,1);
190 if (irow>nrows-3) rocOut->SetValue(irow,ipad,1);
193 if (ipad==0||ipad==npads-1) rocOut->SetValue(irow,ipad,1);
194 Float_t valTmean=rocData->GetValue(irow,ipad);
195 //exclude values that are exactly 0
197 rocOut->SetValue(irow,ipad,1);
200 // exclude channels with too large variations
201 if (TMath::Abs(valTmean)>fCETmaxLimitAbs) {
202 rocOut->SetValue(irow,ipad,1);
210 Float_t chi2Af,chi2Cf;
211 fCETmean->GlobalSidesFit(out,fitFormula,fitResultsA,fitResultsC,dummy,dummy,chi2Af,chi2Cf);
214 if (!outCE) delete out;
216 //_____________________________________________________________________________________
217 void AliTPCcalibDButil::ProcessCEgraphs(TVectorD &vecTEntries, TVectorD &vecTMean, TVectorD &vecTRMS, TVectorD &vecTMedian,
218 TVectorD &vecQEntries, TVectorD &vecQMean, TVectorD &vecQRMS, TVectorD &vecQMedian,
219 Float_t &driftTimeA, Float_t &driftTimeC )
222 // Calculate statistical information from the CE graphs for drift time and charge
226 vecTEntries.ResizeTo(72);
227 vecTMean.ResizeTo(72);
228 vecTRMS.ResizeTo(72);
229 vecTMedian.ResizeTo(72);
230 vecQEntries.ResizeTo(72);
231 vecQMean.ResizeTo(72);
232 vecQRMS.ResizeTo(72);
233 vecQMedian.ResizeTo(72);
244 TObjArray *arrT=fCalibDB->GetCErocTtime();
245 TObjArray *arrQ=fCalibDB->GetCErocQtime();
247 for (Int_t isec=0;isec<74;++isec){
248 TGraph *gr=(TGraph*)arrT->At(isec);
251 Int_t npoints = gr->GetN();
252 values.ResizeTo(npoints);
254 //skip first points, theres always some problems with finding the CE position
255 for (Int_t ipoint=4; ipoint<npoints; ipoint++){
256 if (gr->GetY()[ipoint]>500 && gr->GetY()[ipoint]<1020 ){
257 values[nused]=gr->GetY()[ipoint];
262 if (isec<72) vecTEntries[isec]= nused;
265 vecTMedian[isec] = TMath::Median(nused,values.GetMatrixArray());
266 vecTMean[isec] = TMath::Mean(nused,values.GetMatrixArray());
267 vecTRMS[isec] = TMath::RMS(nused,values.GetMatrixArray());
268 } else if (isec==72){
269 driftTimeA=TMath::Median(nused,values.GetMatrixArray());
270 } else if (isec==73){
271 driftTimeC=TMath::Median(nused,values.GetMatrixArray());
277 for (Int_t isec=0;isec<arrQ->GetEntriesFast();++isec){
278 TGraph *gr=(TGraph*)arrQ->At(isec);
281 Int_t npoints = gr->GetN();
282 values.ResizeTo(npoints);
284 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
285 if (gr->GetY()[ipoint]>10 && gr->GetY()[ipoint]<500 ){
286 values[nused]=gr->GetY()[ipoint];
291 vecQEntries[isec]= nused;
293 vecQMedian[isec] = TMath::Median(nused,values.GetMatrixArray());
294 vecQMean[isec] = TMath::Mean(nused,values.GetMatrixArray());
295 vecQRMS[isec] = TMath::RMS(nused,values.GetMatrixArray());
301 //_____________________________________________________________________________________
302 void AliTPCcalibDButil::ProcessNoiseData(TVectorD &vNoiseMean, TVectorD &vNoiseMeanSenRegions,
303 TVectorD &vNoiseRMS, TVectorD &vNoiseRMSSenRegions,
304 Int_t &nonMaskedZero)
307 // process noise data
308 // vNoiseMean/RMS contains the Mean/RMS noise of the complete TPC [0], IROCs only [1],
309 // OROCs small pads [2] and OROCs large pads [3]
310 // vNoiseMean/RMSsenRegions constains the same information, but only for the sensitive regions (edge pads, corners, IROC spot)
311 // nonMaskedZero contains the number of pads which show zero noise and were not masked. This might indicate an error
314 //set proper size and reset
315 const UInt_t infoSize=4;
316 vNoiseMean.ResizeTo(infoSize);
317 vNoiseMeanSenRegions.ResizeTo(infoSize);
318 vNoiseRMS.ResizeTo(infoSize);
319 vNoiseRMSSenRegions.ResizeTo(infoSize);
321 vNoiseMeanSenRegions.Zero();
323 vNoiseRMSSenRegions.Zero();
326 TVectorD c(infoSize);
327 TVectorD cs(infoSize);
331 //retrieve noise and ALTRO data
332 if (!fPadNoise) return;
333 AliTPCCalROC *rocMasked=0x0;
334 //create IROC, OROC1, OROC2 and sensitive region masks
335 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
336 AliTPCCalROC *noiseROC=fPadNoise->GetCalROC(isec);
337 if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(isec);
338 UInt_t nrows=noiseROC->GetNrows();
339 for (UInt_t irow=0;irow<nrows;++irow){
340 UInt_t npads=noiseROC->GetNPads(irow);
341 for (UInt_t ipad=0;ipad<npads;++ipad){
342 //don't use masked channels;
343 if (rocMasked && rocMasked->GetValue(irow,ipad)) continue;
344 Float_t noiseVal=noiseROC->GetValue(irow,ipad);
351 if ( !(noiseVal<10000000) ){
352 printf ("Warning: nan detected in (sec,row,pad - val): %02d,%02d,%03d - %.1f\n",isec,irow,ipad,noiseVal);
355 Int_t cpad=(Int_t)ipad-(Int_t)npads/2;
356 Int_t masksen=1; // sensitive pards are not masked (0)
357 if (ipad<2||npads-ipad-1<2) masksen=0; //don't mask edge pads (sensitive)
358 if (isec<AliTPCROC::Instance()->GetNInnerSector()){
360 if (irow>19&&irow<46){
361 if (TMath::Abs(cpad)<7) masksen=0; //IROC spot
364 vNoiseMean[type]+=noiseVal;
365 vNoiseRMS[type]+=noiseVal*noiseVal;
368 vNoiseMeanSenRegions[type]+=noiseVal;
369 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
374 //define sensive regions
375 if ((nrows-irow-1)<3) masksen=0; //last three rows in OROCs are sensitive
377 Int_t padEdge=(Int_t)TMath::Min(ipad,npads-ipad);
378 if (padEdge<((((Int_t)irow-76)/4+1))*2) masksen=0; //OROC outer corners are sensitive
380 if ((Int_t)irow<par.GetNRowUp1()){
383 vNoiseMean[type]+=noiseVal;
384 vNoiseRMS[type]+=noiseVal*noiseVal;
387 vNoiseMeanSenRegions[type]+=noiseVal;
388 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
394 vNoiseMean[type]+=noiseVal;
395 vNoiseRMS[type]+=noiseVal*noiseVal;
398 vNoiseMeanSenRegions[type]+=noiseVal;
399 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
406 vNoiseMean[type]+=noiseVal;
407 vNoiseRMS[type]+=noiseVal*noiseVal;
410 vNoiseMeanSenRegions[type]+=noiseVal;
411 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
416 }//end loop sectors (rocs)
418 //calculate mean and RMS
419 const Double_t verySmall=0.0000000001;
420 for (UInt_t i=0;i<infoSize;++i){
427 // printf ("i: %d - m: %.3f, c: %.0f, r: %.3f\n",i,vNoiseMean[i],c[i],vNoiseRMS[i]);
428 mean=vNoiseMean[i]/c[i];
430 rms=TMath::Sqrt(TMath::Abs(rms/c[i]-mean*mean));
435 if (cs[i]>verySmall){
436 meanSen=vNoiseMeanSenRegions[i]/cs[i];
437 rmsSen=vNoiseRMSSenRegions[i];
438 rmsSen=TMath::Sqrt(TMath::Abs(rmsSen/cs[i]-meanSen*meanSen));
440 vNoiseMeanSenRegions[i]=meanSen;
441 vNoiseRMSSenRegions[i]=rmsSen;
445 //_____________________________________________________________________________________
446 void AliTPCcalibDButil::ProcessPulser(TVectorD &vMeanTime)
449 // Process the Pulser information
450 // vMeanTime: pulser mean time position in IROC-A, IROC-C, OROC-A, OROC-C
453 const UInt_t infoSize=4;
454 //reset counters to error number
455 vMeanTime.ResizeTo(infoSize);
458 TVectorD c(infoSize);
459 //retrieve pulser and ALTRO data
460 if (!fPulserTmean) return;
463 AliTPCCalROC *rocOut=0x0;
464 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
465 AliTPCCalROC *tmeanROC=fPulserTmean->GetCalROC(isec);
466 if (!tmeanROC) continue;
467 rocOut=fPulserOutlier->GetCalROC(isec);
468 UInt_t nchannels=tmeanROC->GetNchannels();
469 for (UInt_t ichannel=0;ichannel<nchannels;++ichannel){
470 if (rocOut && rocOut->GetValue(ichannel)) continue;
471 Float_t val=tmeanROC->GetValue(ichannel);
473 vMeanTime[type]+=val;
478 for (UInt_t itype=0; itype<infoSize; ++itype){
479 if (c[itype]>0) vMeanTime[itype]/=c[itype];
480 else vMeanTime[itype]=0;
483 //_____________________________________________________________________________________
484 void AliTPCcalibDButil::ProcessALTROConfig(Int_t &nMasked)
487 // Get Values from ALTRO configuration data
490 if (!fALTROMasked) return;
492 for (Int_t isec=0;isec<fALTROMasked->kNsec; ++isec){
493 AliTPCCalROC *rocMasked=fALTROMasked->GetCalROC(isec);
494 for (UInt_t ichannel=0; ichannel<rocMasked->GetNchannels();++ichannel){
495 if (rocMasked->GetValue(ichannel)) ++nMasked;
499 //_____________________________________________________________________________________
500 void AliTPCcalibDButil::ProcessGoofie(TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS)
503 // Proces Goofie values, return statistical information of the currently set goofieArray
504 // The meaning of the entries are given below
506 1 TPC_ANODE_I_A00_STAT
508 3 TPC_DVM_DriftVelocity
513 8 TPC_DVM_NumberOfSparks
514 9 TPC_DVM_PeakAreaFar
515 10 TPC_DVM_PeakAreaNear
516 11 TPC_DVM_PeakPosFar
517 12 TPC_DVM_PeakPosNear
523 18 TPC_DVM_TemperatureS1
527 vecEntries.ResizeTo(nsensors);
528 vecMedian.ResizeTo(nsensors);
529 vecMean.ResizeTo(nsensors);
530 vecRMS.ResizeTo(nsensors);
537 Double_t kEpsilon=0.0000000001;
538 Double_t kBig=100000000000.;
539 Int_t nsensors = fGoofieArray->NumSensors();
540 vecEntries.ResizeTo(nsensors);
541 vecMedian.ResizeTo(nsensors);
542 vecMean.ResizeTo(nsensors);
543 vecRMS.ResizeTo(nsensors);
545 for (Int_t isensor=0; isensor<fGoofieArray->NumSensors();isensor++){
546 AliDCSSensor *gsensor = fGoofieArray->GetSensor(isensor);
547 if (gsensor && gsensor->GetGraph()){
548 Int_t npoints = gsensor->GetGraph()->GetN();
550 values.ResizeTo(npoints);
552 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
553 if (TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])>kEpsilon &&
554 TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])<kBig ){
555 values[nused]=gsensor->GetGraph()->GetY()[ipoint];
560 vecEntries[isensor]= nused;
562 vecMedian[isensor] = TMath::Median(nused,values.GetMatrixArray());
563 vecMean[isensor] = TMath::Mean(nused,values.GetMatrixArray());
564 vecRMS[isensor] = TMath::RMS(nused,values.GetMatrixArray());
569 //_____________________________________________________________________________________
570 void AliTPCcalibDButil::ProcessPedestalVariations(TVectorF &pedestalDeviations)
573 // check the variations of the pedestal data to the reference pedestal data
574 // thresholds are 0.5, 1.0, 1.5 and 2 timebins respectively.
577 TVectorF vThres(npar); //thresholds
578 Int_t nActive=0; //number of active channels
580 //reset and set thresholds
581 pedestalDeviations.ResizeTo(npar);
582 for (Int_t i=0;i<npar;++i){
583 pedestalDeviations.GetMatrixArray()[i]=0;
584 vThres.GetMatrixArray()[i]=(i+1)*.5;
586 //check all needed data is available
587 if (!fRefPedestals || !fPedestals || !fALTROMasked || !fRefALTROMasked) return;
588 //loop over all channels
589 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
590 AliTPCCalROC *pROC=fPedestals->GetCalROC(isec);
591 AliTPCCalROC *pRefROC=fRefPedestals->GetCalROC(isec);
592 AliTPCCalROC *mROC=fALTROMasked->GetCalROC(isec);
593 AliTPCCalROC *mRefROC=fRefALTROMasked->GetCalROC(isec);
594 UInt_t nrows=mROC->GetNrows();
595 for (UInt_t irow=0;irow<nrows;++irow){
596 UInt_t npads=mROC->GetNPads(irow);
597 for (UInt_t ipad=0;ipad<npads;++ipad){
598 //don't use masked channels;
599 if (mROC ->GetValue(irow,ipad)) continue;
600 if (mRefROC->GetValue(irow,ipad)) continue;
601 Float_t deviation=TMath::Abs(pROC->GetValue(irow,ipad)-pRefROC->GetValue(irow,ipad));
602 for (Int_t i=0;i<npar;++i){
603 if (deviation>vThres[i])
604 ++pedestalDeviations.GetMatrixArray()[i];
611 for (Int_t i=0;i<npar;++i){
612 pedestalDeviations.GetMatrixArray()[i]/=nActive;
616 //_____________________________________________________________________________________
617 void AliTPCcalibDButil::ProcessNoiseVariations(TVectorF &noiseDeviations)
620 // check the variations of the noise data to the reference noise data
621 // thresholds are 5, 10, 15 and 20 percent respectively.
624 TVectorF vThres(npar); //thresholds
625 Int_t nActive=0; //number of active channels
627 //reset and set thresholds
628 noiseDeviations.ResizeTo(npar);
629 for (Int_t i=0;i<npar;++i){
630 noiseDeviations.GetMatrixArray()[i]=0;
631 vThres.GetMatrixArray()[i]=(i+1)*.05;
633 //check all needed data is available
634 if (!fRefPadNoise || !fPadNoise || !fALTROMasked || !fRefALTROMasked) return;
635 //loop over all channels
636 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
637 AliTPCCalROC *nROC=fPadNoise->GetCalROC(isec);
638 AliTPCCalROC *nRefROC=fRefPadNoise->GetCalROC(isec);
639 AliTPCCalROC *mROC=fALTROMasked->GetCalROC(isec);
640 AliTPCCalROC *mRefROC=fRefALTROMasked->GetCalROC(isec);
641 UInt_t nrows=mROC->GetNrows();
642 for (UInt_t irow=0;irow<nrows;++irow){
643 UInt_t npads=mROC->GetNPads(irow);
644 for (UInt_t ipad=0;ipad<npads;++ipad){
645 //don't use masked channels;
646 if (mROC ->GetValue(irow,ipad)) continue;
647 if (mRefROC->GetValue(irow,ipad)) continue;
648 Float_t deviation=(nROC->GetValue(irow,ipad)/nRefROC->GetValue(irow,ipad))-1;
649 for (Int_t i=0;i<npar;++i){
650 if (deviation>vThres[i])
651 ++noiseDeviations.GetMatrixArray()[i];
658 for (Int_t i=0;i<npar;++i){
659 noiseDeviations.GetMatrixArray()[i]/=nActive;
663 //_____________________________________________________________________________________
664 void AliTPCcalibDButil::ProcessPulserVariations(TVectorF &pulserQdeviations, Float_t &varQMean,
665 Int_t &npadsOutOneTB, Int_t &npadsOffAdd)
668 // check the variations of the pulserQmean data to the reference pulserQmean data: pulserQdeviations
669 // thresholds are .5, 1, 5 and 10 percent respectively.
673 TVectorF vThres(npar); //thresholds
674 Int_t nActive=0; //number of active channels
676 //reset and set thresholds
677 pulserQdeviations.ResizeTo(npar);
678 for (Int_t i=0;i<npar;++i){
679 pulserQdeviations.GetMatrixArray()[i]=0;
684 vThres.GetMatrixArray()[0]=.005;
685 vThres.GetMatrixArray()[1]=.01;
686 vThres.GetMatrixArray()[2]=.05;
687 vThres.GetMatrixArray()[3]=.1;
688 //check all needed data is available
689 if (!fRefPulserTmean || !fPulserTmean || !fPulserQmean || !fRefPulserQmean || !fALTROMasked || !fRefALTROMasked) return;
691 UpdateRefPulserOutlierMap();
692 //loop over all channels
693 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
694 AliTPCCalROC *pqROC=fPulserQmean->GetCalROC(isec);
695 AliTPCCalROC *pqRefROC=fRefPulserQmean->GetCalROC(isec);
696 AliTPCCalROC *ptROC=fPulserTmean->GetCalROC(isec);
697 // AliTPCCalROC *ptRefROC=fRefPulserTmean->GetCalROC(isec);
698 AliTPCCalROC *mROC=fALTROMasked->GetCalROC(isec);
699 AliTPCCalROC *mRefROC=fRefALTROMasked->GetCalROC(isec);
700 AliTPCCalROC *oROC=fPulserOutlier->GetCalROC(isec);
701 Float_t pt_mean=ptROC->GetMean(oROC);
702 UInt_t nrows=mROC->GetNrows();
703 for (UInt_t irow=0;irow<nrows;++irow){
704 UInt_t npads=mROC->GetNPads(irow);
705 for (UInt_t ipad=0;ipad<npads;++ipad){
706 //don't use masked channels;
707 if (mROC ->GetValue(irow,ipad)) continue;
708 if (mRefROC->GetValue(irow,ipad)) continue;
709 //don't user edge pads
710 if (ipad==0||ipad==npads-1) continue;
712 Float_t pq=pqROC->GetValue(irow,ipad);
713 Float_t pqRef=pqRefROC->GetValue(irow,ipad);
714 Float_t pt=ptROC->GetValue(irow,ipad);
715 // Float_t ptRef=ptRefROC->GetValue(irow,ipad);
717 Float_t deviation=TMath::Abs(pq/pqRef-1);
718 for (Int_t i=0;i<npar;++i){
719 if (deviation>vThres[i])
720 ++pulserQdeviations.GetMatrixArray()[i];
722 if (pqRef>11&&pq<11) ++npadsOffAdd;
725 if (TMath::Abs(pt-pt_mean)>1) ++npadsOutOneTB;
731 for (Int_t i=0;i<npar;++i){
732 pulserQdeviations.GetMatrixArray()[i]/=nActive;
737 //_____________________________________________________________________________________
738 void AliTPCcalibDButil::UpdatePulserOutlierMap()
743 PulserOutlierMap(fPulserOutlier,fPulserTmean, fPulserQmean);
745 //_____________________________________________________________________________________
746 void AliTPCcalibDButil::UpdateRefPulserOutlierMap()
751 PulserOutlierMap(fRefPulserOutlier,fRefPulserTmean, fRefPulserQmean);
753 //_____________________________________________________________________________________
754 void AliTPCcalibDButil::PulserOutlierMap(AliTPCCalPad *pulOut, const AliTPCCalPad *pulT, const AliTPCCalPad *pulQ)
757 // Create a map that contains outliers from the Pulser calibration data.
758 // The outliers include masked channels, edge pads and pads with
759 // too large timing and charge variations.
760 // fNpulserOutliers is the number of outliers in the Pulser calibration data.
761 // those do not contain masked and edge pads
765 pulOut->Multiply(0.);
769 AliTPCCalROC *rocMasked=0x0;
773 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
774 AliTPCCalROC *tmeanROC=pulT->GetCalROC(isec);
775 AliTPCCalROC *qmeanROC=pulQ->GetCalROC(isec);
776 AliTPCCalROC *outROC=pulOut->GetCalROC(isec);
777 if (!tmeanROC||!qmeanROC) {
778 //reset outliers in this ROC
779 outROC->Multiply(0.);
782 if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(isec);
784 // Float_t qmedian=qmeanROC->GetLTM(&dummy,.5);
785 // Float_t tmedian=tmeanROC->GetLTM(&dummy,.5);
786 UInt_t nrows=tmeanROC->GetNrows();
787 for (UInt_t irow=0;irow<nrows;++irow){
788 UInt_t npads=tmeanROC->GetNPads(irow);
789 for (UInt_t ipad=0;ipad<npads;++ipad){
790 Int_t outlier=0,masked=0;
791 Float_t q=qmeanROC->GetValue(irow,ipad);
792 Float_t t=tmeanROC->GetValue(irow,ipad);
793 //masked channels are outliers
794 if (rocMasked && rocMasked->GetValue(irow,ipad)) masked=1;
795 //edge pads are outliers
796 if (ipad==0||ipad==npads-1) masked=1;
797 //channels with too large charge or timing deviation from the meadian are outliers
798 // if (TMath::Abs(q-qmedian)>fPulQmaxLimitAbs || TMath::Abs(t-tmedian)>fPulTmaxLimitAbs) outlier=1;
799 if (q<fPulQminLimit && !masked) outlier=1;
801 if ( !(q<10000000) || !(t<10000000)) outlier=1;
802 outROC->SetValue(irow,ipad,outlier+masked);
803 fNpulserOutliers+=outlier;
808 //_____________________________________________________________________________________
809 AliTPCCalPad* AliTPCcalibDButil::CreatePadTime0(Int_t model, Double_t &gyA, Double_t &gyC, Double_t &chi2A, Double_t &chi2C )
812 // Create pad time0 object from pulser and/or CE data, depending on the selected model
813 // Model 0: normalise each readout chamber to its mean, outlier cutted, only Pulser
814 // Model 1: normalise IROCs/OROCs of each readout side to its mean, only Pulser
815 // Model 2: use CE data and a combination CE fit + pulser in the outlier regions.
817 // In case model 2 is invoked - gy arival time gradient is also returned
821 AliTPCCalPad *padTime0=new AliTPCCalPad("PadTime0",Form("PadTime0-Model_%d",model));
822 // decide between different models
823 if (model==0||model==1){
825 if (model==1) ProcessPulser(vMean);
826 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
827 AliTPCCalROC *rocPulTmean=fPulserTmean->GetCalROC(isec);
828 if (!rocPulTmean) continue;
829 AliTPCCalROC *rocTime0=padTime0->GetCalROC(isec);
830 AliTPCCalROC *rocOut=fPulserOutlier->GetCalROC(isec);
831 Float_t mean=rocPulTmean->GetMean(rocOut);
832 //treat case where a whole partition is masked
833 if (mean==0) mean=rocPulTmean->GetMean();
838 UInt_t nrows=rocTime0->GetNrows();
839 for (UInt_t irow=0;irow<nrows;++irow){
840 UInt_t npads=rocTime0->GetNPads(irow);
841 for (UInt_t ipad=0;ipad<npads;++ipad){
842 Float_t time=rocPulTmean->GetValue(irow,ipad);
843 //in case of an outlier pad use the mean of the altro values.
844 //This should be the most precise guess in that case.
845 if (rocOut->GetValue(irow,ipad)) {
846 time=GetMeanAltro(rocPulTmean,irow,ipad,rocOut);
847 if (time==0) time=mean;
849 Float_t val=time-mean;
850 rocTime0->SetValue(irow,ipad,val);
854 } else if (model==2){
855 Double_t pgya,pgyc,pchi2a,pchi2c;
856 AliTPCCalPad * padPulser = CreatePadTime0(1,pgya,pgyc,pchi2a,pchi2c);
857 fCETmean->Add(padPulser,-1.);
859 AliTPCCalPad outCE("outCE","outCE");
861 ProcessCEdata("(sector<36)++gy++gx++(lx-134)++(sector<36)*(lx-134)++(ly/lx)^2",vA,vC,nOut,chi2A, chi2C,&outCE);
862 AliTPCCalPad *padFit=AliTPCCalPad::CreateCalPadFit("1++0++gy++0++(lx-134)++0++0",vA,vC);
863 // AliTPCCalPad *padFit=AliTPCCalPad::CreateCalPadFit("1++(sector<36)++gy++gx++(lx-134)++(sector<36)*(lx-134)",vA,vC);
864 if (!padFit) { delete padPulser; return 0;}
867 fCETmean->Add(padPulser,1.);
868 padTime0->Add(fCETmean);
869 padTime0->Add(padFit,-1);
874 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
875 AliTPCCalROC *rocPulTmean=fPulserTmean->GetCalROC(isec);
876 AliTPCCalROC *rocTime0=padTime0->GetCalROC(isec);
877 AliTPCCalROC *rocOutPul=fPulserOutlier->GetCalROC(isec);
878 AliTPCCalROC *rocOutCE=outCE.GetCalROC(isec);
879 rocTime0->GlobalFit(rocOutCE,kFALSE,vFitROC,mFitROC,chi2);
880 AliTPCCalROC *rocCEfit=AliTPCCalROC::CreateGlobalFitCalROC(vFitROC, isec);
881 Float_t mean=rocPulTmean->GetMean(rocOutPul);
882 if (mean==0) mean=rocPulTmean->GetMean();
883 UInt_t nrows=rocTime0->GetNrows();
884 for (UInt_t irow=0;irow<nrows;++irow){
885 UInt_t npads=rocTime0->GetNPads(irow);
886 for (UInt_t ipad=0;ipad<npads;++ipad){
887 Float_t timePulser=rocPulTmean->GetValue(irow,ipad)-mean;
888 if (rocOutCE->GetValue(irow,ipad)){
889 Float_t valOut=rocCEfit->GetValue(irow,ipad);
890 if (!rocOutPul->GetValue(irow,ipad)) valOut+=timePulser;
891 rocTime0->SetValue(irow,ipad,valOut);
899 Double_t median = padTime0->GetMedian();
900 padTime0->Add(-median); // normalize to median
903 //_____________________________________________________________________________________
904 Float_t AliTPCcalibDButil::GetMeanAltro(const AliTPCCalROC *roc, const Int_t row, const Int_t pad, AliTPCCalROC *rocOut)
906 if (roc==0) return 0.;
907 const Int_t sector=roc->GetSector();
908 AliTPCROC *tpcRoc=AliTPCROC::Instance();
909 const UInt_t altroRoc=fMapper->GetFEC(sector,row,pad)*8+fMapper->GetChip(sector,row,pad);
913 //loop over a small range around the requested pad (+-10 rows/pads)
914 for (Int_t irow=row-10;irow<row+10;++irow){
915 if (irow<0||irow>(Int_t)tpcRoc->GetNRows(sector)-1) continue;
916 for (Int_t ipad=pad-10; ipad<pad+10;++ipad){
917 if (ipad<0||ipad>(Int_t)tpcRoc->GetNPads(sector,irow)-1) continue;
918 const UInt_t altroCurr=fMapper->GetFEC(sector,irow,ipad)*8+fMapper->GetChip(sector,irow,ipad);
919 if (altroRoc!=altroCurr) continue;
920 if ( rocOut && rocOut->GetValue(irow,ipad) ) continue;
921 Float_t val=roc->GetValue(irow,ipad);
929 //_____________________________________________________________________________________
930 void AliTPCcalibDButil::SetRefFile(const char* filename)
933 // load cal pad objects form the reference file
935 TDirectory *currDir=gDirectory;
937 fRefPedestals=(AliTPCCalPad*)f.Get("Pedestals");
938 fRefPadNoise=(AliTPCCalPad*)f.Get("PadNoise");
940 fRefPulserTmean=(AliTPCCalPad*)f.Get("PulserTmean");
941 fRefPulserTrms=(AliTPCCalPad*)f.Get("PulserTrms");
942 fRefPulserQmean=(AliTPCCalPad*)f.Get("PulserQmean");
944 fRefCETmean=(AliTPCCalPad*)f.Get("CETmean");
945 fRefCETrms=(AliTPCCalPad*)f.Get("CETrms");
946 fRefCEQmean=(AliTPCCalPad*)f.Get("CEQmean");
948 // fRefALTROAcqStart=(AliTPCCalPad*)f.Get("ALTROAcqStart");
949 // fRefALTROZsThr=(AliTPCCalPad*)f.Get("ALTROZsThr");
950 // fRefALTROFPED=(AliTPCCalPad*)f.Get("ALTROFPED");
951 // fRefALTROAcqStop=(AliTPCCalPad*)f.Get("ALTROAcqStop");
952 fRefALTROMasked=(AliTPCCalPad*)f.Get("ALTROMasked");
960 AliTPCCalPad *AliTPCcalibDButil::CreateCEOutlyerMap( Int_t & noutliersCE, AliTPCCalPad *ceOut, Float_t minSignal, Float_t cutTrmsMin, Float_t cutTrmsMax, Float_t cutMaxDistT){
962 // Author: marian.ivanov@cern.ch
964 // Create outlier map for CE study
966 // Return value - outlyer map
967 // noutlyersCE - number of outlyers
968 // minSignal - minimal total Q signal
969 // cutRMSMin - minimal width of the signal in respect to the median
970 // cutRMSMax - maximal width of the signal in respect to the median
971 // cutMaxDistT - maximal deviation from time median per chamber
973 // Outlyers criteria:
974 // 0. Exclude masked pads
975 // 1. Exclude first two rows in IROC and last two rows in OROC
976 // 2. Exclude edge pads
977 // 3. Exclude channels with too large variations
978 // 4. Exclude pads with too small signal
979 // 5. Exclude signal with outlyers RMS
980 // 6. Exclude channels to far from the chamber median
983 AliTPCCalPad *out=ceOut;
984 if (!out) out= new AliTPCCalPad("outCE","outCE");
985 AliTPCCalROC *rocMasked=0x0;
986 if (!fCETmean) return 0;
987 if (!fCETrms) return 0;
988 if (!fCEQmean) return 0;
990 //loop over all channels
992 Double_t rmsMedian = fCETrms->GetMedian();
993 for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
994 AliTPCCalROC *rocData=fCETmean->GetCalROC(iroc);
995 if (fALTROMasked) rocMasked= fALTROMasked->GetCalROC(iroc);
996 AliTPCCalROC *rocOut = out->GetCalROC(iroc);
997 AliTPCCalROC *rocCEQ = fCEQmean->GetCalROC(iroc);
998 AliTPCCalROC *rocCETrms = fCETrms->GetCalROC(iroc);
999 Double_t trocMedian = rocData->GetMedian();
1002 noutliersCE+=AliTPCROC::Instance()->GetNChannels(iroc);
1008 UInt_t nrows=rocData->GetNrows();
1009 for (UInt_t irow=0;irow<nrows;++irow){
1010 UInt_t npads=rocData->GetNPads(irow);
1011 for (UInt_t ipad=0;ipad<npads;++ipad){
1012 rocOut->SetValue(irow,ipad,0);
1013 Float_t valTmean=rocData->GetValue(irow,ipad);
1014 Float_t valQmean=rocCEQ->GetValue(irow,ipad);
1015 Float_t valTrms =rocCETrms->GetValue(irow,ipad);
1016 //0. exclude masked pads
1017 if (rocMasked && rocMasked->GetValue(irow,ipad)) {
1018 rocOut->SetValue(irow,ipad,1);
1021 //1. exclude first two rows in IROC and last two rows in OROC
1023 if (irow<2) rocOut->SetValue(irow,ipad,1);
1025 if (irow>nrows-3) rocOut->SetValue(irow,ipad,1);
1027 //2. exclude edge pads
1028 if (ipad==0||ipad==npads-1) rocOut->SetValue(irow,ipad,1);
1029 //exclude values that are exactly 0
1031 rocOut->SetValue(irow,ipad,1);
1034 //3. exclude channels with too large variations
1035 if (TMath::Abs(valTmean)>fCETmaxLimitAbs) {
1036 rocOut->SetValue(irow,ipad,1);
1040 //4. exclude channels with too small signal
1041 if (valQmean<minSignal) {
1042 rocOut->SetValue(irow,ipad,1);
1046 //5. exclude channels with too small rms
1047 if (valTrms<cutTrmsMin*rmsMedian || valTrms>cutTrmsMax*rmsMedian){
1048 rocOut->SetValue(irow,ipad,1);
1052 //6. exclude channels to far from the chamber median
1053 if (TMath::Abs(valTmean-trocMedian)>cutMaxDistT){
1054 rocOut->SetValue(irow,ipad,1);
1065 AliTPCCalPad *AliTPCcalibDButil::CreatePulserOutlyerMap(Int_t &noutliersPulser, AliTPCCalPad *pulserOut,Float_t cutTime, Float_t cutnRMSQ, Float_t cutnRMSrms){
1067 // Author: marian.ivanov@cern.ch
1069 // Create outlier map for Pulser
1071 // Return value - outlyer map
1072 // noutlyersPulser - number of outlyers
1073 // cutTime - absolute cut - distance to the median of chamber
1074 // cutnRMSQ - nsigma cut from median q distribution per chamber
1075 // cutnRMSrms - nsigma cut from median rms distribution
1076 // Outlyers criteria:
1077 // 0. Exclude masked pads
1078 // 1. Exclude time outlyers (default 3 time bins)
1079 // 2. Exclude q outlyers (default 5 sigma)
1080 // 3. Exclude rms outlyers (default 5 sigma)
1082 AliTPCCalPad *out=pulserOut;
1083 if (!out) out= new AliTPCCalPad("outPulser","outPulser");
1084 AliTPCCalROC *rocMasked=0x0;
1085 if (!fPulserTmean) return 0;
1086 if (!fPulserTrms) return 0;
1087 if (!fPulserQmean) return 0;
1089 //loop over all channels
1091 for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
1092 if (fALTROMasked) rocMasked= fALTROMasked->GetCalROC(iroc);
1093 AliTPCCalROC *rocData = fPulserTmean->GetCalROC(iroc);
1094 AliTPCCalROC *rocOut = out->GetCalROC(iroc);
1095 AliTPCCalROC *rocPulserQ = fPulserQmean->GetCalROC(iroc);
1096 AliTPCCalROC *rocPulserTrms = fPulserTrms->GetCalROC(iroc);
1098 Double_t rocMedianT = rocData->GetMedian();
1099 Double_t rocMedianQ = rocPulserQ->GetMedian();
1100 Double_t rocRMSQ = rocPulserQ->GetRMS();
1101 Double_t rocMedianTrms = rocPulserTrms->GetMedian();
1102 Double_t rocRMSTrms = rocPulserTrms->GetRMS();
1103 for (UInt_t ichannel=0;ichannel<rocData->GetNchannels();++ichannel){
1104 rocOut->SetValue(ichannel,0);
1105 Float_t valTmean=rocData->GetValue(ichannel);
1106 Float_t valQmean=rocPulserQ->GetValue(ichannel);
1107 Float_t valTrms =rocPulserTrms->GetValue(ichannel);
1109 if (TMath::Abs(valTmean-rocMedianT)>cutTime) isOut=1;
1110 if (TMath::Abs(valQmean-rocMedianQ)>cutnRMSQ*rocRMSQ) isOut=1;
1111 if (TMath::Abs(valTrms-rocMedianTrms)>cutnRMSrms*rocRMSTrms) isOut=1;
1112 rocOut->SetValue(ichannel,isOut);
1113 if (isOut) noutliersPulser++;
1120 AliTPCCalPad *AliTPCcalibDButil::CreatePadTime0CE(TVectorD &fitResultsA, TVectorD&fitResultsC, Int_t &nOut, Double_t &chi2A, Double_t &chi2C, const char *dumpfile){
1122 // Author : Marian Ivanov
1123 // Create pad time0 correction map using information from the CE and from pulser
1126 // Return PadTime0 to be used for time0 relative alignment
1127 // if dump file specified intermediat results are dumped to the fiel and can be visualized
1128 // using $ALICE_ROOT/TPC/script/gui application
1130 // fitResultsA - fitParameters A side
1131 // fitResultsC - fitParameters C side
1132 // chi2A - chi2/ndf for A side (assuming error 1 time bin)
1133 // chi2C - chi2/ndf for C side (assuming error 1 time bin)
1137 // 1. Find outlier map for CE
1138 // 2. Find outlier map for Pulser
1139 // 3. Replace outlier by median at given sector (median without outliers)
1140 // 4. Substract from the CE data pulser
1141 // 5. Fit the CE with formula
1142 // 5.1) (IROC-OROC) offset
1146 // 5.5) (IROC-OROC)*(lx-xmid)
1148 // 6. Substract gy fit dependence from the CE data
1149 // 7. Add pulser back to CE data
1150 // 8. Replace outliers by fit value - median of diff per given chamber -GY fit
1151 // 9. return CE data
1153 // Time0 <= padCE = padCEin -padCEfitGy - if not outlier
1154 // Time0 <= padCE = padFitAll-padCEfitGy - if outlier
1157 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)";
1158 // output for fit formula
1159 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)";
1160 // gy part of formula
1161 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)";
1164 if (!fCETmean) return 0;
1165 Double_t pgya,pgyc,pchi2a,pchi2c;
1166 AliTPCCalPad * padPulserOut = CreatePulserOutlyerMap(nOut);
1167 AliTPCCalPad * padCEOut = CreateCEOutlyerMap(nOut);
1169 AliTPCCalPad * padPulser = CreatePadTime0(1,pgya,pgyc,pchi2a,pchi2c);
1170 AliTPCCalPad * padCE = new AliTPCCalPad(*fCETmean);
1171 AliTPCCalPad * padCEIn = new AliTPCCalPad(*fCETmean);
1172 AliTPCCalPad * padOut = new AliTPCCalPad("padOut","padOut");
1173 padPulser->SetName("padPulser");
1174 padPulserOut->SetName("padPulserOut");
1175 padCE->SetName("padCE");
1176 padCEIn->SetName("padCEIn");
1177 padCEOut->SetName("padCEOut");
1178 padOut->SetName("padOut");
1181 // make combined outlyers map
1182 // and replace outlyers in maps with median for chamber
1184 for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
1185 AliTPCCalROC * rocOut = padOut->GetCalROC(iroc);
1186 AliTPCCalROC * rocPulser = padPulser->GetCalROC(iroc);
1187 AliTPCCalROC * rocPulserOut = padPulserOut->GetCalROC(iroc);
1188 AliTPCCalROC * rocCEOut = padCEOut->GetCalROC(iroc);
1189 AliTPCCalROC * rocCE = padCE->GetCalROC(iroc);
1190 Double_t ceMedian = rocCE->GetMedian(rocCEOut);
1191 Double_t pulserMedian = rocPulser->GetMedian(rocCEOut);
1192 for (UInt_t ichannel=0;ichannel<rocOut->GetNchannels();++ichannel){
1193 if (rocPulserOut->GetValue(ichannel)>0) {
1194 rocPulser->SetValue(ichannel,pulserMedian);
1195 rocOut->SetValue(ichannel,1);
1197 if (rocCEOut->GetValue(ichannel)>0) {
1198 rocCE->SetValue(ichannel,ceMedian);
1199 rocOut->SetValue(ichannel,1);
1204 // remove pulser time 0
1206 padCE->Add(padPulser,-1);
1211 Float_t chi2Af,chi2Cf;
1212 padCE->GlobalSidesFit(padOut,formulaIn,fitResultsA,fitResultsC,dummy,dummy,chi2Af,chi2Cf);
1216 AliTPCCalPad *padCEFitGY=AliTPCCalPad::CreateCalPadFit(formulaOut,fitResultsA,fitResultsC);
1217 padCEFitGY->SetName("padCEFitGy");
1219 AliTPCCalPad *padCEFit =AliTPCCalPad::CreateCalPadFit(formulaAll,fitResultsA,fitResultsC);
1220 padCEFit->SetName("padCEFit");
1222 AliTPCCalPad* padCEDiff = new AliTPCCalPad(*padCE);
1223 padCEDiff->SetName("padCEDiff");
1224 padCEDiff->Add(padCEFit,-1.);
1227 padCE->Add(padCEFitGY,-1.);
1229 padCE->Add(padPulser,1.);
1230 Double_t padmedian = padCE->GetMedian();
1231 padCE->Add(-padmedian); // normalize to median
1233 // Replace outliers by fit value - median of diff per given chamber -GY fit
1235 for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
1236 AliTPCCalROC * rocOut = padOut->GetCalROC(iroc);
1237 AliTPCCalROC * rocCE = padCE->GetCalROC(iroc);
1238 AliTPCCalROC * rocCEFit = padCEFit->GetCalROC(iroc);
1239 AliTPCCalROC * rocCEFitGY = padCEFitGY->GetCalROC(iroc);
1240 AliTPCCalROC * rocCEDiff = padCEDiff->GetCalROC(iroc);
1242 Double_t diffMedian = rocCEDiff->GetMedian(rocOut);
1243 for (UInt_t ichannel=0;ichannel<rocOut->GetNchannels();++ichannel){
1244 if (rocOut->GetValue(ichannel)==0) continue;
1245 Float_t value=rocCEFit->GetValue(ichannel)-rocCEFitGY->GetValue(ichannel)-diffMedian-padmedian;
1246 rocCE->SetValue(ichannel,value);
1252 //dump to the file - result can be visualized
1253 AliTPCPreprocessorOnline preprocesor;
1254 preprocesor.AddComponent(new AliTPCCalPad(*padCE));
1255 preprocesor.AddComponent(new AliTPCCalPad(*padCEIn));
1256 preprocesor.AddComponent(new AliTPCCalPad(*padCEFit));
1257 preprocesor.AddComponent(new AliTPCCalPad(*padOut));
1259 preprocesor.AddComponent(new AliTPCCalPad(*padCEFitGY));
1260 preprocesor.AddComponent(new AliTPCCalPad(*padCEDiff));
1262 preprocesor.AddComponent(new AliTPCCalPad(*padCEOut));
1263 preprocesor.AddComponent(new AliTPCCalPad(*padPulser));
1264 preprocesor.AddComponent(new AliTPCCalPad(*padPulserOut));
1265 preprocesor.DumpToFile(dumpfile);
1268 delete padPulserOut;
1281 Int_t AliTPCcalibDButil::GetNearest(TGraph *graph, Double_t xref, Double_t &dx, Double_t &y){
1283 // find the closest point to xref in x direction
1284 // return dx and value
1286 index = TMath::BinarySearch(graph->GetN(), graph->GetX(),xref);
1287 if (index<0) index=0;
1288 if (index>=graph->GetN()-1) index=graph->GetN()-2;
1289 if (xref-graph->GetX()[index]>graph->GetX()[index]-xref) index++;
1290 dx = xref-graph->GetX()[index];
1291 y = graph->GetY()[index];
1296 Double_t AliTPCcalibDButil::GetTriggerOffsetTPC(Int_t run, Int_t timeStamp, Double_t deltaT, Double_t deltaTLaser, Int_t valType){
1298 // Get the correction of the trigger offset
1299 // combining information from the laser track calibration
1300 // and from cosmic calibration
1303 // timeStamp - tim stamp in seconds
1304 // deltaT - integration period to calculate offset
1305 // deltaTLaser -max validity of laser data
1306 // valType - 0 - median, 1- mean
1308 // Integration vaues are just recomendation - if not possible to get points
1309 // automatically increase the validity by factor 2
1310 // (recursive algorithm until one month of data taking)
1313 const Float_t kLaserCut=0.0005;
1314 const Int_t kMaxPeriod=3600*24*30*3; // 3 month max
1315 const Int_t kMinPoints=20;
1317 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1319 AliTPCcalibDB::Instance()->UpdateRunInformations(run,kFALSE);
1321 array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1322 if (!array) return 0;
1324 TGraphErrors *laserA[3]={0,0,0};
1325 TGraphErrors *laserC[3]={0,0,0};
1326 TGraphErrors *cosmicAll=0;
1327 laserA[1]=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
1328 laserC[1]=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_C");
1329 cosmicAll =(TGraphErrors*)array->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
1332 if (!cosmicAll) return 0;
1333 Int_t nmeasC=cosmicAll->GetN();
1334 Float_t *tdelta = new Float_t[nmeasC];
1336 for (Int_t i=0;i<nmeasC;i++){
1337 if (TMath::Abs(cosmicAll->GetX()[i]-timeStamp)>deltaT) continue;
1338 Float_t ccosmic=cosmicAll->GetY()[i];
1339 Double_t yA=0,yC=0,dA=0,dC=0;
1340 if (laserA[1]) GetNearest(laserA[1], cosmicAll->GetX()[i],dA,yA);
1341 if (laserC[1]) GetNearest(laserC[1], cosmicAll->GetX()[i],dC,yC);
1342 //yA=laserA[1]->Eval(cosmicAll->GetX()[i]);
1343 //yC=laserC[1]->Eval(cosmicAll->GetX()[i]);
1345 if (TMath::Sqrt(dA*dA+dC*dC)>deltaTLaser) continue;
1347 if (TMath::Abs(yA-yC)<kLaserCut) {
1350 if (i%2==0) claser=yA;
1351 if (i%2==1) claser=yC;
1353 tdelta[nused]=ccosmic-claser;
1356 if (nused<kMinPoints &&deltaT<kMaxPeriod) return AliTPCcalibDButil::GetTriggerOffsetTPC(run, timeStamp, deltaT*2,deltaTLaser);
1357 Double_t median = TMath::Median(nused,tdelta);
1358 Double_t mean = TMath::Mean(nused,tdelta);
1360 return (valType==0) ? median:mean;
1363 Double_t AliTPCcalibDButil::GetVDriftTPC(Double_t &dist, Int_t run, Int_t timeStamp, Double_t deltaT, Double_t deltaTLaser, Int_t valType){
1365 // Get the correction of the drift velocity
1366 // combining information from the laser track calibration
1367 // and from cosmic calibration
1369 // dist - return value - distance to closest point in graph
1371 // timeStamp - tim stamp in seconds
1372 // deltaT - integration period to calculate time0 offset
1373 // deltaTLaser -max validity of laser data
1374 // valType - 0 - median, 1- mean
1376 // Integration vaues are just recomendation - if not possible to get points
1377 // automatically increase the validity by factor 2
1378 // (recursive algorithm until one month of data taking)
1382 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1384 AliTPCcalibDB::Instance()->UpdateRunInformations(run,kFALSE);
1386 array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1387 if (!array) return 0;
1388 TGraphErrors *cosmicAll=0;
1389 cosmicAll =(TGraphErrors*)array->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
1390 if (!cosmicAll) return 0;
1392 AliTPCcalibDButil::GetNearest(cosmicAll,timeStamp,dist,grY);
1394 Double_t t0= AliTPCcalibDButil::GetTriggerOffsetTPC(run,timeStamp, deltaT, deltaTLaser,valType);
1395 Double_t vcosmic= AliTPCcalibDButil::EvalGraphConst(cosmicAll, timeStamp);
1396 if (timeStamp>cosmicAll->GetX()[cosmicAll->GetN()-1]) vcosmic=cosmicAll->GetY()[cosmicAll->GetN()-1];
1397 if (timeStamp<cosmicAll->GetX()[0]) vcosmic=cosmicAll->GetY()[0];
1404 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1405 cosmicAll =(TGraphErrors*)array->FindObject("TGRAPHERRORS_MEAN_VDRIFT_COSMICS_ALL");
1406 laserA=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
1408 Double_t *yvd= new Double_t[cosmicAll->GetN()];
1409 Double_t *yt0= new Double_t[cosmicAll->GetN()];
1410 for (Int_t i=0; i<cosmicAll->GetN();i++) yvd[i]=AliTPCcalibDButil::GetVDriftTPC(run,cosmicAll->GetX()[i]);
1411 for (Int_t i=0; i<cosmicAll->GetN();i++) yt0[i]=AliTPCcalibDButil::GetTriggerOffsetTPC(run,cosmicAll->GetX()[i]);
1413 TGraph *pcosmicVd=new TGraph(cosmicAll->GetN(), cosmicAll->GetX(), yvd);
1414 TGraph *pcosmicT0=new TGraph(cosmicAll->GetN(), cosmicAll->GetX(), yt0);
1420 Double_t AliTPCcalibDButil::GetVDriftTPCLaserTracks(Double_t &dist, Int_t run, Int_t timeStamp, Double_t deltaT, Int_t side){
1422 // Get the correction of the drift velocity using the laser tracks calbration
1425 // timeStamp - tim stamp in seconds
1426 // deltaT - integration period to calculate time0 offset
1427 // side - 0 - A side, 1 - C side, 2 - mean from both sides
1428 // Note in case no data form both A and C side - the value from active side used
1429 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
1430 TGraphErrors *grlaserA=0;
1431 TGraphErrors *grlaserC=0;
1432 Double_t vlaserA=0, vlaserC=0;
1433 if (!array) return 0;
1434 grlaserA=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_A");
1435 grlaserC=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DRIFT_LASER_ALL_C");
1438 AliTPCcalibDButil::GetNearest(grlaserA,timeStamp,dist,deltaY);
1439 if (TMath::Abs(dist)>deltaT) vlaserA= deltaY;
1440 else vlaserA = AliTPCcalibDButil::EvalGraphConst(grlaserA,timeStamp);
1443 AliTPCcalibDButil::GetNearest(grlaserC,timeStamp,dist,deltaY);
1444 if (TMath::Abs(dist)>deltaT) vlaserC= deltaY;
1445 else vlaserC = AliTPCcalibDButil::EvalGraphConst(grlaserC,timeStamp);
1447 if (side==0) return vlaserA;
1448 if (side==1) return vlaserC;
1449 Double_t mdrift=(vlaserA+vlaserC)*0.5;
1450 if (!grlaserA) return vlaserC;
1451 if (!grlaserC) return vlaserA;
1456 Double_t AliTPCcalibDButil::GetVDriftTPCCE(Double_t &dist,Int_t run, Int_t timeStamp, Double_t deltaT, Int_t side){
1458 // Get the correction of the drift velocity using the CE laser data
1459 // combining information from the CE, laser track calibration
1460 // and P/T calibration
1463 // timeStamp - tim stamp in seconds
1464 // deltaT - integration period to calculate time0 offset
1465 // side - 0 - A side, 1 - C side, 2 - mean from both sides
1466 TObjArray *arrT =AliTPCcalibDB::Instance()->GetCErocTtime();
1467 if (!arrT) return 0;
1468 AliTPCParam *param =AliTPCcalibDB::Instance()->GetParameters();
1469 TObjArray* cearray =AliTPCcalibDB::Instance()->GetCEData();
1470 AliTPCCalibVdrift * driftCalib = (AliTPCCalibVdrift *)cearray->FindObject("driftPTCE");
1473 Double_t corrPTA = 0, corrPTC=0;
1474 Double_t ltime0A = 0, ltime0C=0;
1476 Double_t corrA=0, corrC=0;
1477 Double_t timeA=0, timeC=0;
1478 TGraph *graphA = (TGraph*)arrT->At(72);
1479 TGraph *graphC = (TGraph*)arrT->At(73);
1480 if (!graphA && !graphC) return 0.;
1481 if (graphA &&graphA->GetN()>0) {
1482 AliTPCcalibDButil::GetNearest(graphA,timeStamp,dist,gry);
1483 timeA = AliTPCcalibDButil::EvalGraphConst(graphA,timeStamp);
1484 Int_t mtime =TMath::Nint((graphA->GetX()[0]+graphA->GetX()[graphA->GetN()-1])*0.5);
1485 ltime0A = GetLaserTime0(run,mtime,TMath::Nint(deltaT),0);
1486 if (driftCalib) corrPTA = driftCalib->GetPTRelative(timeStamp,0);
1487 corrA = (param->GetZLength(36)/(timeA*param->GetTSample()*(1.-ltime0A)-param->GetL1Delay()-0*param->GetZSigma()/param->GetDriftV()))/param->GetDriftV()-1;
1490 if (graphC&&graphC->GetN()>0){
1491 AliTPCcalibDButil::GetNearest(graphC,timeStamp,dist,gry);
1492 timeC=AliTPCcalibDButil::EvalGraphConst(graphC,timeStamp);
1493 Int_t mtime=TMath::Nint((graphC->GetX()[0]+graphC->GetX()[graphC->GetN()-1])*0.5);
1494 ltime0C = GetLaserTime0(run,mtime,TMath::Nint(deltaT),0);
1495 if (driftCalib) corrPTC = driftCalib->GetPTRelative(timeStamp,0);
1496 corrC = (param->GetZLength(54)/(timeC*param->GetTSample()*(1.-ltime0C)-param->GetL1Delay()-0*param->GetZSigma()/param->GetDriftV()))/param->GetDriftV()-1;
1500 if (side ==0 ) return corrA;
1501 if (side ==1 ) return corrC;
1502 Double_t corrM= (corrA+corrC)*0.5;
1503 if (!graphA) corrM=corrC;
1504 if (!graphC) corrM=corrA;
1511 Int_t AliTPCcalibDButil::MakeRunList(Int_t startRun, Int_t stopRun){
1513 // VERY obscure method - we need something in framework
1514 // Find the TPC runs with temperature OCDB entry
1515 // cache the start and end of the run
1517 AliCDBStorage* storage = AliCDBManager::Instance()->GetSpecificStorage("TPC/Calib/Temperature");
1518 if (!storage) storage = AliCDBManager::Instance()->GetDefaultStorage();
1519 if (!storage) return 0;
1520 TString path=storage->GetURI();
1524 if (path.Contains("local")){ // find the list if local system
1525 path.ReplaceAll("local://","");
1526 path+="TPC/Calib/Temperature";
1527 command=Form("ls %s | sed s/_/\\ /g | awk '{print \"r\"$2}' ",path.Data());
1529 runsT=gSystem->GetFromPipe(command);
1531 TObjArray *arr= runsT.Tokenize("r");
1534 TArrayI indexes(arr->GetEntries());
1535 TArrayI runs(arr->GetEntries());
1537 {for (Int_t irun=0;irun<arr->GetEntries();irun++){
1538 Int_t irunN = atoi(arr->At(irun)->GetName());
1539 if (irunN<startRun) continue;
1540 if (irunN>stopRun) continue;
1541 runs[naccept]=irunN;
1545 fRunsStart.Set(fRuns.fN);
1546 fRunsStop.Set(fRuns.fN);
1547 TMath::Sort(fRuns.fN, runs.fArray, indexes.fArray,kFALSE);
1548 for (Int_t irun=0; irun<fRuns.fN; irun++) fRuns[irun]=runs[indexes[irun]];
1551 AliCDBEntry * entry = 0;
1552 {for (Int_t irun=0;irun<fRuns.fN; irun++){
1553 entry = AliCDBManager::Instance()->Get("TPC/Calib/Temperature",fRuns[irun]);
1554 if (!entry) continue;
1555 AliTPCSensorTempArray * tmpRun = dynamic_cast<AliTPCSensorTempArray*>(entry->GetObject());
1556 if (!tmpRun) continue;
1557 fRunsStart[irun]=tmpRun->GetStartTime().GetSec();
1558 fRunsStop[irun]=tmpRun->GetEndTime().GetSec();
1559 // printf("irun\t%d\tRun\t%d\t%d\t%d\n",irun,fRuns[irun],tmpRun->GetStartTime().GetSec(),tmpRun->GetEndTime().GetSec());
1565 Int_t AliTPCcalibDButil::FindRunTPC(Int_t itime, Bool_t debug){
1567 // binary search - find the run for given time stamp
1569 Int_t index0 = TMath::BinarySearch(fRuns.fN, fRunsStop.fArray,itime);
1570 Int_t index1 = TMath::BinarySearch(fRuns.fN, fRunsStart.fArray,itime);
1572 for (Int_t index=index0; index<=index1; index++){
1573 if (fRunsStart[index]<=itime && fRunsStop[index]>=itime) cindex=index;
1575 printf("%d\t%d\t%d\n",fRuns[index], fRunsStart[index]-itime, fRunsStop[index]-itime);
1578 if (cindex<0) cindex =(index0+index1)/2;
1582 return fRuns[cindex];
1589 TGraph* AliTPCcalibDButil::FilterGraphMedian(TGraph * graph, Float_t sigmaCut,Double_t &medianY){
1591 // filter outlyer measurement
1592 // Only points around median +- sigmaCut filtered
1593 if (!graph) return 0;
1595 Int_t npoints0 = graph->GetN();
1598 Double_t *outx=new Double_t[npoints0];
1599 Double_t *outy=new Double_t[npoints0];
1602 if (npoints0<kMinPoints) return 0;
1603 for (Int_t iter=0; iter<3; iter++){
1605 for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
1606 if (graph->GetY()[ipoint]==0) continue;
1607 if (iter>0 &&TMath::Abs(graph->GetY()[ipoint]-medianY)>sigmaCut*rmsY) continue;
1608 outx[npoints] = graph->GetX()[ipoint];
1609 outy[npoints] = graph->GetY()[ipoint];
1612 if (npoints<=1) break;
1613 medianY =TMath::Median(npoints,outy);
1614 rmsY =TMath::RMS(npoints,outy);
1617 if (npoints>1) graphOut= new TGraph(npoints,outx,outy);
1622 TGraph* AliTPCcalibDButil::FilterGraphMedianAbs(TGraph * graph, Float_t cut,Double_t &medianY){
1624 // filter outlyer measurement
1625 // Only points around median +- cut filtered
1626 if (!graph) return 0;
1628 Int_t npoints0 = graph->GetN();
1631 Double_t *outx=new Double_t[npoints0];
1632 Double_t *outy=new Double_t[npoints0];
1635 if (npoints0<kMinPoints) return 0;
1636 for (Int_t iter=0; iter<3; iter++){
1638 for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
1639 if (graph->GetY()[ipoint]==0) continue;
1640 if (iter>0 &&TMath::Abs(graph->GetY()[ipoint]-medianY)>cut) continue;
1641 outx[npoints] = graph->GetX()[ipoint];
1642 outy[npoints] = graph->GetY()[ipoint];
1645 if (npoints<=1) break;
1646 medianY =TMath::Median(npoints,outy);
1647 rmsY =TMath::RMS(npoints,outy);
1650 if (npoints>1) graphOut= new TGraph(npoints,outx,outy);
1656 TGraphErrors* AliTPCcalibDButil::FilterGraphMedianErr(TGraphErrors * graph, Float_t sigmaCut,Double_t &medianY){
1658 // filter outlyer measurement
1659 // Only points with normalized errors median +- sigmaCut filtered
1661 Int_t kMinPoints=10;
1662 Int_t npoints0 = graph->GetN();
1664 Float_t medianErr=0, rmsErr=0;
1665 Double_t *outx=new Double_t[npoints0];
1666 Double_t *outy=new Double_t[npoints0];
1667 Double_t *erry=new Double_t[npoints0];
1668 Double_t *nerry=new Double_t[npoints0];
1669 Double_t *errx=new Double_t[npoints0];
1672 if (npoints0<kMinPoints) return 0;
1673 for (Int_t iter=0; iter<3; iter++){
1675 for (Int_t ipoint=0; ipoint<npoints0; ipoint++){
1676 nerry[npoints] = graph->GetErrorY(ipoint);
1677 if (iter>0 &&TMath::Abs(nerry[npoints]-medianErr)>sigmaCut*rmsErr) continue;
1678 erry[npoints] = graph->GetErrorY(ipoint);
1679 outx[npoints] = graph->GetX()[ipoint];
1680 outy[npoints] = graph->GetY()[ipoint];
1681 errx[npoints] = graph->GetErrorY(ipoint);
1684 if (npoints==0) break;
1685 medianErr=TMath::Median(npoints,erry);
1686 medianY =TMath::Median(npoints,outy);
1687 rmsErr =TMath::RMS(npoints,erry);
1689 TGraphErrors *graphOut=0;
1690 if (npoints>1) graphOut= new TGraphErrors(npoints,outx,outy,errx,erry);
1699 void AliTPCcalibDButil::Sort(TGraph *graph){
1701 // sort array - neccessay for approx
1703 Int_t npoints = graph->GetN();
1704 Int_t *indexes=new Int_t[npoints];
1705 Double_t *outx=new Double_t[npoints];
1706 Double_t *outy=new Double_t[npoints];
1707 TMath::Sort(npoints, graph->GetX(),indexes,kFALSE);
1708 for (Int_t i=0;i<npoints;i++) outx[i]=graph->GetX()[indexes[i]];
1709 for (Int_t i=0;i<npoints;i++) outy[i]=graph->GetY()[indexes[i]];
1710 for (Int_t i=0;i<npoints;i++) graph->GetX()[i]=outx[i];
1711 for (Int_t i=0;i<npoints;i++) graph->GetY()[i]=outy[i];
1714 void AliTPCcalibDButil::SmoothGraph(TGraph *graph, Double_t delta){
1716 // smmoth graph - mean on the interval
1719 Int_t npoints = graph->GetN();
1720 Double_t *outy=new Double_t[npoints];
1722 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
1723 Double_t lx=graph->GetX()[ipoint];
1724 Int_t index0=TMath::BinarySearch(npoints, graph->GetX(),lx-delta);
1725 Int_t index1=TMath::BinarySearch(npoints, graph->GetX(),lx+delta);
1726 if (index0<0) index0=0;
1727 if (index1>=npoints-1) index1=npoints-1;
1728 if ((index1-index0)>1){
1729 outy[ipoint] = TMath::Mean(index1-index0, &(graph->GetY()[index0]));
1731 outy[ipoint]=graph->GetY()[ipoint];
1734 // TLinearFitter fitter(3,"pol2");
1735 // for (Int_t ipoint=0; ipoint<npoints; ipoint++){
1736 // Double_t lx=graph->GetX()[ipoint];
1737 // Int_t index0=TMath::BinarySearch(npoints, graph->GetX(),lx-delta);
1738 // Int_t index1=TMath::BinarySearch(npoints, graph->GetX(),lx+delta);
1739 // if (index0<0) index0=0;
1740 // if (index1>=npoints-1) index1=npoints-1;
1741 // fitter.ClearPoints();
1742 // for (Int_t jpoint=0;jpoint<index1-index0; jpoint++)
1743 // if ((index1-index0)>1){
1744 // outy[ipoint] = TMath::Mean(index1-index0, &(graph->GetY()[index0]));
1746 // outy[ipoint]=graph->GetY()[ipoint];
1752 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
1753 graph->GetY()[ipoint] = outy[ipoint];
1758 Double_t AliTPCcalibDButil::EvalGraphConst(TGraph *graph, Double_t xref){
1760 // Use constant interpolation outside of range
1763 printf("AliTPCcalibDButil::EvalGraphConst: 0 pointer\n");
1766 if (graph->GetN()<1){
1767 printf("AliTPCcalibDButil::EvalGraphConst: Empty graph");
1770 if (xref<graph->GetX()[0]) return graph->GetY()[0];
1771 if (xref>graph->GetX()[graph->GetN()-1]) return graph->GetY()[graph->GetN()-1];
1772 return graph->Eval( xref);
1775 Float_t AliTPCcalibDButil::FilterSensor(AliDCSSensor * sensor, Double_t ymin, Double_t ymax, Double_t maxdy, Double_t sigmaCut){
1777 // Filter DCS sensor information
1778 // ymin - minimal value
1780 // maxdy - maximal deirivative
1781 // sigmaCut - cut on values and derivative in terms of RMS distribution
1782 // Return value - accepted fraction
1786 // 0. Calculate median and rms of values in specified range
1787 // 1. Filter out outliers - median+-sigmaCut*rms
1788 // values replaced by median
1790 AliSplineFit * fit = sensor->GetFit();
1791 if (!fit) return 0.;
1792 Int_t nknots = fit->GetKnots();
1799 Double_t *yin0 = new Double_t[nknots];
1800 Double_t *yin1 = new Double_t[nknots];
1803 for (Int_t iknot=0; iknot< nknots; iknot++){
1804 if (fit->GetY0()[iknot]>ymin && fit->GetY0()[iknot]<ymax){
1805 yin0[naccept] = fit->GetY0()[iknot];
1806 yin1[naccept] = fit->GetY1()[iknot];
1807 if (TMath::Abs(fit->GetY1()[iknot])>maxdy) yin1[naccept]=0;
1817 Double_t medianY0=0, medianY1=0;
1818 Double_t rmsY0 =0, rmsY1=0;
1819 medianY0 = TMath::Median(naccept, yin0);
1820 medianY1 = TMath::Median(naccept, yin1);
1821 rmsY0 = TMath::RMS(naccept, yin0);
1822 rmsY1 = TMath::RMS(naccept, yin1);
1825 // 1. Filter out outliers - median+-sigmaCut*rms
1826 // values replaced by median
1827 // if replaced the derivative set to 0
1829 for (Int_t iknot=0; iknot< nknots; iknot++){
1831 if (TMath::Abs(fit->GetY0()[iknot]-medianY0)>sigmaCut*rmsY0) isOK=kFALSE;
1832 if (TMath::Abs(fit->GetY1()[iknot]-medianY1)>sigmaCut*rmsY1) isOK=kFALSE;
1833 if (nknots<2) fit->GetY1()[iknot]=0;
1834 if (TMath::Abs(fit->GetY1()[iknot])>maxdy) fit->GetY1()[iknot]=0;
1836 fit->GetY0()[iknot]=medianY0;
1837 fit->GetY1()[iknot]=0;
1844 return Float_t(naccept)/Float_t(nknots);
1847 Float_t AliTPCcalibDButil::FilterTemperature(AliTPCSensorTempArray *tempArray, Double_t ymin, Double_t ymax, Double_t sigmaCut){
1849 // Filter temperature array
1850 // tempArray - array of temperatures -
1851 // ymin - minimal accepted temperature - default 15
1852 // ymax - maximal accepted temperature - default 22
1853 // sigmaCut - values filtered on interval median+-sigmaCut*rms - defaut 5
1854 // return value - fraction of filtered sensors
1855 const Double_t kMaxDy=0.1;
1856 Int_t nsensors=tempArray->NumSensors();
1857 if (nsensors==0) return 0.;
1859 for (Int_t isensor=0; isensor<nsensors; isensor++){
1860 AliDCSSensor *sensor = tempArray->GetSensorNum(isensor);
1861 if (!sensor) continue;
1862 //printf("%d\n",isensor);
1863 FilterSensor(sensor,ymin,ymax,kMaxDy, sigmaCut);
1864 if (sensor->GetFit()==0){
1866 tempArray->RemoveSensorNum(isensor);
1871 return Float_t(naccept)/Float_t(nsensors);
1875 void AliTPCcalibDButil::FilterCE(Double_t deltaT, Double_t cutAbs, Double_t cutSigma, TTreeSRedirector *pcstream){
1878 // Input parameters:
1879 // deltaT - smoothing window (in seconds)
1880 // cutAbs - max distance of the time info to the median (in time bins)
1881 // cutSigma - max distance (in the RMS)
1882 // pcstream - optional debug streamer to store original and filtered info
1883 // Hardwired parameters:
1884 // kMinPoints =10; // minimal number of points to define the CE
1885 // kMinSectors=12; // minimal number of sectors to define sideCE
1887 // 0. Filter almost emty graphs (kMinPoints=10)
1888 // 1. calculate median and RMS per side
1889 // 2. Filter graphs - in respect with side medians
1890 // - cutAbs and cutDelta used
1891 // 3. Cut in respect wit the graph median - cutAbs and cutRMS used
1892 // 4. Calculate mean for A side and C side
1894 const Int_t kMinPoints =10; // minimal number of points to define the CE
1895 const Int_t kMinSectors=12; // minimal number of sectors to define sideCE
1896 const Int_t kMinTime =400; // minimal arrival time of CE
1897 TObjArray *arrT=AliTPCcalibDB::Instance()->GetCErocTtime();
1899 TObjArray* cearray =AliTPCcalibDB::Instance()->GetCEData();
1900 if (!cearray) return;
1905 AliTPCSensorTempArray *tempMapCE = (AliTPCSensorTempArray *)cearray->FindObject("TempMap");
1906 AliDCSSensor * cavernPressureCE = (AliDCSSensor *) cearray->FindObject("CavernPressure");
1907 if ( tempMapCE && cavernPressureCE){
1909 Bool_t isOK = FilterTemperature(tempMapCE)>0.1;
1910 FilterSensor(cavernPressureCE,960,1050,10, 5.);
1911 if (cavernPressureCE->GetFit()==0) isOK=kFALSE;
1913 // recalculate P/T correction map for time of the CE
1914 AliTPCCalibVdrift * driftCalib = new AliTPCCalibVdrift(tempMapCE,cavernPressureCE ,0);
1915 driftCalib->SetName("driftPTCE");
1916 driftCalib->SetTitle("driftPTCE");
1917 cearray->AddLast(driftCalib);
1921 // 0. Filter almost emty graphs
1924 for (Int_t i=0; i<72;i++){
1925 TGraph *graph= (TGraph*)arrT->At(i);
1926 if (!graph) continue;
1927 if (graph->GetN()<kMinPoints){
1929 delete graph; // delete empty graph
1932 if (tmin<0) tmin = graph->GetX()[0];
1933 if (tmax<0) tmax = graph->GetX()[graph->GetN()-1];
1935 if (tmin>graph->GetX()[0]) tmin=graph->GetX()[0];
1936 if (tmax<graph->GetX()[graph->GetN()-1]) tmax=graph->GetX()[graph->GetN()-1];
1939 // 1. calculate median and RMS per side
1941 TArrayF arrA(100000), arrC(100000);
1943 Double_t medianA=0, medianC=0;
1944 Double_t rmsA=0, rmsC=0;
1945 for (Int_t isec=0; isec<72;isec++){
1946 TGraph *graph= (TGraph*)arrT->At(isec);
1947 if (!graph) continue;
1948 for (Int_t ipoint=kMinPoints-1; ipoint<graph->GetN();ipoint++){
1949 if (graph->GetY()[ipoint]<kMinTime) continue;
1950 if (nA>=arrA.fN) arrA.Set(nA*2);
1951 if (nC>=arrC.fN) arrC.Set(nC*2);
1952 if (isec%36<18) arrA[nA++]= graph->GetY()[ipoint];
1953 if (isec%36>=18) arrC[nC++]= graph->GetY()[ipoint];
1957 medianA=TMath::Median(nA,arrA.fArray);
1958 rmsA =TMath::RMS(nA,arrA.fArray);
1961 medianC=TMath::Median(nC,arrC.fArray);
1962 rmsC =TMath::RMS(nC,arrC.fArray);
1965 // 2. Filter graphs - in respect with side medians
1967 TArrayD vecX(100000), vecY(100000);
1968 for (Int_t isec=0; isec<72;isec++){
1969 TGraph *graph= (TGraph*)arrT->At(isec);
1970 if (!graph) continue;
1971 Double_t median = (isec%36<18) ? medianA: medianC;
1972 Double_t rms = (isec%36<18) ? rmsA: rmsC;
1974 for (Int_t ipoint=kMinPoints-1; ipoint<graph->GetN();ipoint++){
1975 if (TMath::Abs(graph->GetY()[ipoint]-median)>cutAbs) continue;
1976 if (TMath::Abs(graph->GetY()[ipoint]-median)>cutSigma*rms) continue;
1977 vecX[naccept]= graph->GetX()[ipoint];
1978 vecY[naccept]= graph->GetY()[ipoint];
1981 if (naccept<kMinPoints){
1982 arrT->AddAt(0,isec);
1983 delete graph; // delete empty graph
1986 TGraph *graph2 = new TGraph(naccept, vecX.fArray, vecY.fArray);
1988 arrT->AddAt(graph2,isec);
1991 // 3. Cut in respect wit the graph median
1993 for (Int_t i=0; i<72;i++){
1994 TGraph *graph= (TGraph*)arrT->At(i);
1995 if (!graph) continue;
1999 TGraph* graphTS0= FilterGraphMedianAbs(graph,cutAbs,medianY);
2000 if (!graphTS0) continue;
2001 if (graphTS0->GetN()<kMinPoints) {
2007 TGraph* graphTS= FilterGraphMedian(graphTS0,cutSigma,medianY);
2009 AliTPCcalibDButil::SmoothGraph(graphTS,deltaT);
2011 Int_t run = AliTPCcalibDB::Instance()->GetRun();
2012 (*pcstream)<<"filterCE"<<
2017 "graphTS0.="<<graphTS0<<
2018 "graphTS.="<<graphTS<<
2022 if (!graphTS) continue;
2023 arrT->AddAt(graphTS,i);
2027 // Recalculate the mean time A side C side
2029 TArrayF xA(200), yA(200), eA(200), xC(200),yC(200), eC(200);
2030 Int_t meanPoints=(nA+nC)/72; // mean number of points
2031 for (Int_t itime=0; itime<200; itime++){
2033 Double_t time=tmin+(tmax-tmin)*Float_t(itime)/200.;
2034 for (Int_t i=0; i<72;i++){
2035 TGraph *graph= (TGraph*)arrT->At(i);
2036 if (!graph) continue;
2037 if (graph->GetN()<(meanPoints/4)) continue;
2038 if ( (i%36)<18 ) arrA[nA++]=graph->Eval(time);
2039 if ( (i%36)>=18 ) arrC[nC++]=graph->Eval(time);
2043 yA[itime]=(nA>0)? TMath::Mean(nA,arrA.fArray):0;
2044 yC[itime]=(nC>0)? TMath::Mean(nC,arrC.fArray):0;
2045 eA[itime]=(nA>0)? TMath::RMS(nA,arrA.fArray):0;
2046 eC[itime]=(nC>0)? TMath::RMS(nC,arrC.fArray):0;
2049 Double_t rmsTA = TMath::RMS(200,yA.fArray)+TMath::Mean(200,eA.fArray);
2050 Double_t rmsTC = TMath::RMS(200,yC.fArray)+TMath::Mean(200,eC.fArray);
2052 Int_t run = AliTPCcalibDB::Instance()->GetRun();
2053 (*pcstream)<<"filterAC"<<
2062 TGraphErrors *grA = new TGraphErrors(200,xA.fArray,yA.fArray,0, eA.fArray);
2063 TGraphErrors *grC = new TGraphErrors(200,xC.fArray,yC.fArray,0, eC.fArray);
2064 TGraph* graphTSA= FilterGraphMedian(grA,cutSigma,medianY);
2065 if (graphTSA&&graphTSA->GetN()) SmoothGraph(graphTSA,deltaT);
2066 TGraph* graphTSC= FilterGraphMedian(grC,cutSigma,medianY);
2067 if (graphTSC&&graphTSC->GetN()>0) SmoothGraph(graphTSC,deltaT);
2070 if (nA<kMinSectors) arrT->AddAt(0,72);
2071 else arrT->AddAt(graphTSA,72);
2072 if (nC<kMinSectors) arrT->AddAt(0,73);
2073 else arrT->AddAt(graphTSC,73);
2077 void AliTPCcalibDButil::FilterTracks(Int_t run, Double_t cutSigma, TTreeSRedirector *pcstream){
2079 // Filter Drift velocity measurement using the tracks
2080 // 0. remove outlyers - error based
2084 const Int_t kMinPoints=1; // minimal number of points to define value
2085 TObjArray *arrT=AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
2088 for (Int_t i=0; i<arrT->GetEntries();i++){
2089 TGraphErrors *graph= (TGraphErrors*)arrT->At(i);
2090 if (!graph) continue;
2091 if (graph->GetN()<kMinPoints){
2096 TGraphErrors *graph2= FilterGraphMedianErr(graph,cutSigma,medianY);
2098 delete graph; arrT->AddAt(0,i); continue;
2100 if (graph2->GetN()<1) {
2101 delete graph; arrT->AddAt(0,i); continue;
2103 graph2->SetName(graph->GetName());
2104 graph2->SetTitle(graph->GetTitle());
2105 arrT->AddAt(graph2,i);
2107 (*pcstream)<<"filterTracks"<<
2112 "graph2.="<<graph2<<
2123 Double_t AliTPCcalibDButil::GetLaserTime0(Int_t run, Int_t timeStamp, Int_t deltaT, Int_t side){
2126 // get laser time offset
2127 // median around timeStamp+-deltaT
2128 // QA - chi2 needed for later usage - to be added
2129 // - currently cut on error
2132 Double_t kMinDelay=0.01;
2133 Double_t kMinDelayErr=0.0001;
2135 TObjArray *array =AliTPCcalibDB::Instance()->GetTimeVdriftSplineRun(run);
2136 if (!array) return 0;
2137 TGraphErrors *tlaser=0;
2139 if (side==0) tlaser=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DELAY_LASER_ALL_A");
2140 if (side==1) tlaser=(TGraphErrors*)array->FindObject("GRAPH_MEAN_DELAY_LASER_ALL_C");
2142 if (!tlaser) return 0;
2143 Int_t npoints0= tlaser->GetN();
2144 if (npoints0==0) return 0;
2145 Double_t *xlaser = new Double_t[npoints0];
2146 Double_t *ylaser = new Double_t[npoints0];
2148 for (Int_t i=0;i<npoints0;i++){
2150 if (tlaser->GetY()[i]<=kMinDelay) continue; // filter zeros
2151 if (tlaser->GetErrorY(i)>TMath::Abs(kMinDelayErr)) continue;
2152 xlaser[npoints]=tlaser->GetX()[npoints];
2153 ylaser[npoints]=tlaser->GetY()[npoints];
2158 Int_t index0=TMath::BinarySearch(npoints, xlaser, Double_t(timeStamp-deltaT))-1;
2159 Int_t index1=TMath::BinarySearch(npoints, xlaser, Double_t(timeStamp+deltaT))+1;
2160 //if (index1-index0 <kMinPoints) { index1+=kMinPoints; index0-=kMinPoints;}
2161 if (index0<0) index0=0;
2162 if (index1>=npoints-1) index1=npoints-1;
2163 if (index1-index0<kMinPoints) return 0;
2165 //Double_t median = TMath::Median(index1-index0, &(ylaser[index0]));
2166 Double_t mean = TMath::Mean(index1-index0, &(ylaser[index0]));
2175 void AliTPCcalibDButil::FilterGoofie(AliDCSSensorArray * goofieArray, Double_t deltaT, Double_t cutSigma, TTreeSRedirector *pcstream){
2177 // Filter Goofie data
2180 // Ignore goofie if not enough points
2182 const Int_t kMinPoints = 3;
2185 TGraph *graphvd = goofieArray->GetSensorNum(2)->GetGraph();
2186 TGraph *graphan = goofieArray->GetSensorNum(8)->GetGraph();
2187 TGraph *graphaf = goofieArray->GetSensorNum(9)->GetGraph();
2188 TGraph *graphpt = goofieArray->GetSensorNum(15)->GetGraph();
2189 if (!graphvd) return;
2190 if (graphvd->GetN()<kMinPoints){
2192 goofieArray->GetSensorNum(2)->SetGraph(0);
2196 // 1. Caluclate medians of critical variables
2202 Double_t medianpt=0;
2203 Double_t medianvd=0;
2204 Double_t medianan=0;
2205 Double_t medianaf=0;
2206 Int_t entries=graphvd->GetN();
2207 TGraph * graphvd0 = AliTPCcalibDButil::FilterGraphMedianAbs(graphvd,0.03,medianvd);
2208 TGraph * graphvd1 = AliTPCcalibDButil::FilterGraphMedian(graphvd0,2,medianvd);
2209 TGraph * graphpt0 = AliTPCcalibDButil::FilterGraphMedianAbs(graphpt,10,medianpt);
2210 TGraph * graphpt1 = AliTPCcalibDButil::FilterGraphMedian(graphpt0,2,medianpt);
2211 TGraph * graphan0 = AliTPCcalibDButil::FilterGraphMedianAbs(graphan,10,medianan);
2212 TGraph * graphan1 = AliTPCcalibDButil::FilterGraphMedian(graphan0,2,medianan);
2213 TGraph * graphaf0 = AliTPCcalibDButil::FilterGraphMedianAbs(graphaf,10,medianaf);
2214 TGraph * graphaf1 = AliTPCcalibDButil::FilterGraphMedian(graphaf0,2,medianaf);
2224 // 2. Make outlyer graph
2227 TGraph graphOut(*graphvd);
2228 for (Int_t i=0; i<entries;i++){
2230 Bool_t isOut=kFALSE;
2231 if (TMath::Abs(graphvd->GetY()[i]/medianvd-1.)>0.02) isOut|=kTRUE;
2232 if (TMath::Abs(graphpt->GetY()[i]/medianpt-1.)>0.02) isOut|=kTRUE;
2233 if (TMath::Abs(graphan->GetY()[i]/medianan-1.)>0.03) isOut|=kTRUE;
2234 if (TMath::Abs(graphaf->GetY()[i]/medianaf-1.)>0.03) isOut|=kTRUE;
2235 graphOut.GetY()[i]= (isOut)?1:0;
2238 if (nOut<kMinPoints) return;
2240 // 3. Filter out outlyers - and smooth
2242 TVectorF vmedianArray(goofieArray->NumSensors());
2243 TVectorF vrmsArray(goofieArray->NumSensors());
2244 Double_t xnew[10000];
2245 Double_t ynew[10000];
2247 junk.SetOwner(kTRUE);
2251 for (Int_t isensor=0; isensor<goofieArray->NumSensors();isensor++){
2253 AliDCSSensor *sensor = goofieArray->GetSensorNum(isensor);
2254 TGraph *graphOld=0, *graphNew=0, * graphNew0=0,*graphNew1=0,*graphNew2=0;
2256 if (!sensor) continue;
2257 graphOld = sensor->GetGraph();
2259 sensor->SetGraph(0);
2261 for (Int_t i=0;i<entries;i++){
2262 if (graphOut.GetY()[i]>0.5) continue;
2263 xnew[nused]=graphOld->GetX()[i];
2264 ynew[nused]=graphOld->GetY()[i];
2267 graphNew = new TGraph(nused,xnew,ynew);
2268 junk.AddLast(graphNew);
2269 junk.AddLast(graphOld);
2271 graphNew0 = AliTPCcalibDButil::FilterGraphMedian(graphNew,cutSigma,median);
2273 junk.AddLast(graphNew0);
2274 graphNew1 = AliTPCcalibDButil::FilterGraphMedian(graphNew0,cutSigma,median);
2276 junk.AddLast(graphNew1);
2277 graphNew2 = AliTPCcalibDButil::FilterGraphMedian(graphNew1,cutSigma,median);
2279 AliTPCcalibDButil::SmoothGraph(graphNew2,deltaT);
2280 AliTPCcalibDButil::SmoothGraph(graphNew2,deltaT);
2281 AliTPCcalibDButil::SmoothGraph(graphNew2,deltaT);
2282 printf("%d\t%f\n",isensor, median);
2283 vmedianArray[isensor]=median;
2284 vrmsArray[isensor] =median;
2290 if (!graphOld) { isOK=kFALSE; graphOld =&graphOut;}
2291 if (!graphNew0) { isOK=kFALSE; graphNew0=graphOld;}
2292 if (!graphNew1) { isOK=kFALSE; graphNew1=graphOld;}
2293 if (!graphNew2) { isOK=kFALSE; graphNew2=graphOld;}
2294 (*pcstream)<<"goofieA"<<
2295 Form("isOK_%d.=",isensor)<<isOK<<
2296 Form("s_%d.=",isensor)<<sensor<<
2297 Form("gr_%d.=",isensor)<<graphOld<<
2298 Form("gr0_%d.=",isensor)<<graphNew0<<
2299 Form("gr1_%d.=",isensor)<<graphNew1<<
2300 Form("gr2_%d.=",isensor)<<graphNew2;
2301 sensor->SetGraph(graphNew2);
2303 (*pcstream)<<"goofieA"<<
2304 "vmed.="<<&vmedianArray<<
2306 junk.Delete(); // delete temoprary graphs