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 <AliDCSSensorArray.h>
33 #include <AliDCSSensor.h>
34 #include "AliTPCcalibDB.h"
35 #include "AliTPCCalPad.h"
36 #include "AliTPCCalROC.h"
37 #include "AliTPCROC.h"
38 #include "AliTPCmapper.h"
39 #include "AliTPCParam.h"
40 #include "AliTPCCalibRaw.h"
42 #include "AliTPCcalibDButil.h"
44 ClassImp(AliTPCcalibDButil)
45 AliTPCcalibDButil::AliTPCcalibDButil() :
47 fCalibDB(AliTPCcalibDB::Instance()),
53 fPulserOutlier(new AliTPCCalPad("PulserOutliers","PulserOutliers")),
60 fMapper(new AliTPCmapper(0x0)),
64 fPulTmaxLimitAbs(1.5),
72 //_____________________________________________________________________________________
73 AliTPCcalibDButil::~AliTPCcalibDButil()
78 delete fPulserOutlier;
81 //_____________________________________________________________________________________
82 void AliTPCcalibDButil::UpdateFromCalibDB()
85 // Update pointers from calibDB
87 fPadNoise=fCalibDB->GetPadNoise();
88 fPedestals=fCalibDB->GetPedestals();
89 fPulserTmean=fCalibDB->GetPulserTmean();
90 fPulserTrms=fCalibDB->GetPulserTrms();
91 fPulserQmean=fCalibDB->GetPulserQmean();
92 fCETmean=fCalibDB->GetCETmean();
93 fCETrms=fCalibDB->GetCETrms();
94 fCEQmean=fCalibDB->GetCEQmean();
95 fALTROMasked=fCalibDB->GetALTROMasked();
96 fGoofieArray=fCalibDB->GetGoofieSensors(fCalibDB->GetRun());
97 fCalibRaw=fCalibDB->GetCalibRaw();
98 UpdatePulserOutlierMap();
100 //_____________________________________________________________________________________
101 void AliTPCcalibDButil::ProcessCEdata(const char* fitFormula, TVectorD &fitResultsA, TVectorD &fitResultsC, Int_t &noutliersCE)
104 // Process the CE data for this run
105 // the return TVectorD arrays contian the results of the fit
106 // noutliersCE contains the number of pads marked as outliers,
107 // not including masked and edge pads
110 //retrieve CE and ALTRO data
112 TString fitString(fitFormula);
113 fitString.ReplaceAll("++","#");
114 Int_t ndim=fitString.CountChar('#')+2;
115 fitResultsA.ResizeTo(ndim);
116 fitResultsC.ResizeTo(ndim);
124 AliTPCCalPad out("out","out");
125 AliTPCCalROC *rocMasked=0x0;
126 //loop over all channels
127 for (UInt_t iroc=0;iroc<fCETmean->kNsec;++iroc){
128 AliTPCCalROC *rocData=fCETmean->GetCalROC(iroc);
129 if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(iroc);
130 AliTPCCalROC *rocOut=out.GetCalROC(iroc);
132 noutliersCE+=AliTPCROC::Instance()->GetNChannels(iroc);
135 //add time offset to IROCs
136 if (iroc<AliTPCROC::Instance()->GetNInnerSector())
137 rocData->Add(fIrocTimeOffset);
139 UInt_t nrows=rocData->GetNrows();
140 for (UInt_t irow=0;irow<nrows;++irow){
141 UInt_t npads=rocData->GetNPads(irow);
142 for (UInt_t ipad=0;ipad<npads;++ipad){
143 //exclude masked pads
144 if (rocMasked && rocMasked->GetValue(irow,ipad)) {
145 rocOut->SetValue(iroc,ipad,1);
149 if (ipad==0||ipad==npads-1) rocOut->SetValue(iroc,ipad,1);
150 Float_t valTmean=rocData->GetValue(iroc,ipad);
151 //exclude values that are exactly 0
153 rocOut->SetValue(iroc,ipad,1);
156 // exclude channels with too large variations
157 if (TMath::Abs(valTmean)>fCETmaxLimitAbs) {
158 rocOut->SetValue(iroc,ipad,1);
167 fCETmean->GlobalSidesFit(&out,fitFormula,fitResultsA,fitResultsC,dummy,dummy,chi2A,chi2C);
169 //_____________________________________________________________________________________
170 void AliTPCcalibDButil::ProcessCEgraphs(TVectorD &vecTEntries, TVectorD &vecTMean, TVectorD &vecTRMS, TVectorD &vecTMedian,
171 TVectorD &vecQEntries, TVectorD &vecQMean, TVectorD &vecQRMS, TVectorD &vecQMedian,
172 Float_t &driftTimeA, Float_t &driftTimeC )
175 // Calculate statistical information from the CE graphs for drift time and charge
179 vecTEntries.ResizeTo(72);
180 vecTMean.ResizeTo(72);
181 vecTRMS.ResizeTo(72);
182 vecTMedian.ResizeTo(72);
183 vecQEntries.ResizeTo(72);
184 vecQMean.ResizeTo(72);
185 vecQRMS.ResizeTo(72);
186 vecQMedian.ResizeTo(72);
197 TObjArray *arrT=fCalibDB->GetCErocTtime();
198 TObjArray *arrQ=fCalibDB->GetCErocQtime();
200 for (Int_t isec=0;isec<74;++isec){
201 TGraph *gr=(TGraph*)arrT->At(isec);
204 Int_t npoints = gr->GetN();
205 values.ResizeTo(npoints);
207 //skip first points, theres always some problems with finding the CE position
208 for (Int_t ipoint=4; ipoint<npoints; ipoint++){
209 if (gr->GetY()[ipoint]>500 && gr->GetY()[ipoint]<1020 ){
210 values[nused]=gr->GetY()[ipoint];
215 if (isec<72) vecTEntries[isec]= nused;
218 vecTMedian[isec] = TMath::Median(nused,values.GetMatrixArray());
219 vecTMean[isec] = TMath::Mean(nused,values.GetMatrixArray());
220 vecTRMS[isec] = TMath::RMS(nused,values.GetMatrixArray());
221 } else if (isec==72){
222 driftTimeA=TMath::Median(nused,values.GetMatrixArray());
223 } else if (isec==73){
224 driftTimeC=TMath::Median(nused,values.GetMatrixArray());
230 for (Int_t isec=0;isec<arrQ->GetEntriesFast();++isec){
231 TGraph *gr=(TGraph*)arrQ->At(isec);
234 Int_t npoints = gr->GetN();
235 values.ResizeTo(npoints);
237 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
238 if (gr->GetY()[ipoint]>500 && gr->GetY()[ipoint]<1000 ){
239 values[nused]=gr->GetY()[ipoint];
244 vecQEntries[isec]= nused;
246 vecQMedian[isec] = TMath::Median(nused,values.GetMatrixArray());
247 vecQMean[isec] = TMath::Mean(nused,values.GetMatrixArray());
248 vecQRMS[isec] = TMath::RMS(nused,values.GetMatrixArray());
254 //_____________________________________________________________________________________
255 void AliTPCcalibDButil::ProcessNoiseData(TVectorD &vNoiseMean, TVectorD &vNoiseMeanSenRegions,
256 TVectorD &vNoiseRMS, TVectorD &vNoiseRMSSenRegions,
257 Int_t &nonMaskedZero)
260 // process noise data
261 // vNoiseMean/RMS contains the Mean/RMS noise of the complete TPC [0], IROCs only [1],
262 // OROCs small pads [2] and OROCs large pads [3]
263 // vNoiseMean/RMSsenRegions constains the same information, but only for the sensitive regions (edge pads, corners, IROC spot)
264 // nonMaskedZero contains the number of pads which show zero noise and were not masked. This might indicate an error
267 //set proper size and reset
268 const UInt_t infoSize=4;
269 vNoiseMean.ResizeTo(infoSize);
270 vNoiseMeanSenRegions.ResizeTo(infoSize);
271 vNoiseRMS.ResizeTo(infoSize);
272 vNoiseRMSSenRegions.ResizeTo(infoSize);
274 vNoiseMeanSenRegions.Zero();
276 vNoiseRMSSenRegions.Zero();
279 TVectorD c(infoSize);
280 TVectorD cs(infoSize);
284 //retrieve noise and ALTRO data
285 if (!fPadNoise) return;
286 AliTPCCalROC *rocMasked=0x0;
287 //create IROC, OROC1, OROC2 and sensitive region masks
288 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
289 AliTPCCalROC *noiseROC=fPadNoise->GetCalROC(isec);
290 if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(isec);
291 UInt_t nrows=noiseROC->GetNrows();
292 for (UInt_t irow=0;irow<nrows;++irow){
293 UInt_t npads=noiseROC->GetNPads(irow);
294 for (UInt_t ipad=0;ipad<npads;++ipad){
295 //don't use masked channels;
296 if (rocMasked && rocMasked->GetValue(irow,ipad)) continue;
297 Float_t noiseVal=noiseROC->GetValue(irow,ipad);
304 if ( !(noiseVal<10000000) ){
305 printf ("Warning: nan detected in (sec,row,pad - val): %02d,%02d,%03d - %.1f\n",isec,irow,ipad,noiseVal);
308 Int_t cpad=(Int_t)ipad-(Int_t)npads/2;
309 Int_t masksen=1; // sensitive pards are not masked (0)
310 if (ipad<2||npads-ipad-1<2) masksen=0; //don't mask edge pads (sensitive)
311 if (isec<AliTPCROC::Instance()->GetNInnerSector()){
313 if (irow>19&&irow<46){
314 if (TMath::Abs(cpad)<7) masksen=0; //IROC spot
317 vNoiseMean[type]+=noiseVal;
318 vNoiseRMS[type]+=noiseVal*noiseVal;
321 vNoiseMeanSenRegions[type]+=noiseVal;
322 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
327 //define sensive regions
328 if ((nrows-irow-1)<3) masksen=0; //last three rows in OROCs are sensitive
330 Int_t padEdge=(Int_t)TMath::Min(ipad,npads-ipad);
331 if (padEdge<((((Int_t)irow-76)/4+1))*2) masksen=0; //OROC outer corners are sensitive
333 if ((Int_t)irow<par.GetNRowUp1()){
336 vNoiseMean[type]+=noiseVal;
337 vNoiseRMS[type]+=noiseVal*noiseVal;
340 vNoiseMeanSenRegions[type]+=noiseVal;
341 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
347 vNoiseMean[type]+=noiseVal;
348 vNoiseRMS[type]+=noiseVal*noiseVal;
351 vNoiseMeanSenRegions[type]+=noiseVal;
352 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
359 vNoiseMean[type]+=noiseVal;
360 vNoiseRMS[type]+=noiseVal*noiseVal;
363 vNoiseMeanSenRegions[type]+=noiseVal;
364 vNoiseRMSSenRegions[type]+=noiseVal*noiseVal;
369 }//end loop sectors (rocs)
371 //calculate mean and RMS
372 const Double_t verySmall=0.0000000001;
373 for (UInt_t i=0;i<infoSize;++i){
380 // printf ("i: %d - m: %.3f, c: %.0f, r: %.3f\n",i,vNoiseMean[i],c[i],vNoiseRMS[i]);
381 mean=vNoiseMean[i]/c[i];
383 rms=TMath::Sqrt(TMath::Abs(rms/c[i]-mean*mean));
388 if (cs[i]>verySmall){
389 meanSen=vNoiseMeanSenRegions[i]/cs[i];
390 rmsSen=vNoiseRMSSenRegions[i];
391 rmsSen=TMath::Sqrt(TMath::Abs(rmsSen/cs[i]-meanSen*meanSen));
393 vNoiseMeanSenRegions[i]=meanSen;
394 vNoiseRMSSenRegions[i]=rmsSen;
398 //_____________________________________________________________________________________
399 void AliTPCcalibDButil::ProcessPulser(TVectorD &vMeanTime)
402 // Process the Pulser information
403 // vMeanTime: pulser mean time position in IROC-A, IROC-C, OROC-A, OROC-C
406 const UInt_t infoSize=4;
407 //reset counters to error number
408 vMeanTime.ResizeTo(infoSize);
411 TVectorD c(infoSize);
412 //retrieve pulser and ALTRO data
413 if (!fPulserTmean) return;
416 AliTPCCalROC *rocOut=0x0;
417 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
418 AliTPCCalROC *tmeanROC=fPulserTmean->GetCalROC(isec);
419 if (!tmeanROC) continue;
420 rocOut=fPulserOutlier->GetCalROC(isec);
421 UInt_t nchannels=tmeanROC->GetNchannels();
422 for (UInt_t ichannel=0;ichannel<nchannels;++ichannel){
423 if (rocOut && rocOut->GetValue(ichannel)) continue;
424 Float_t val=tmeanROC->GetValue(ichannel);
426 vMeanTime[type]+=val;
431 for (UInt_t itype=0; itype<infoSize; ++itype){
432 if (c[itype]>0) vMeanTime[itype]/=c[itype];
433 else vMeanTime[itype]=0;
436 //_____________________________________________________________________________________
437 void AliTPCcalibDButil::ProcessALTROConfig(Int_t &nMasked)
440 // Get Values from ALTRO configuration data
443 if (!fALTROMasked) return;
445 for (Int_t isec=0;isec<fALTROMasked->kNsec; ++isec){
446 AliTPCCalROC *rocMasked=fALTROMasked->GetCalROC(isec);
447 for (UInt_t ichannel=0; ichannel<rocMasked->GetNchannels();++ichannel){
448 if (rocMasked->GetValue(ichannel)) ++nMasked;
452 //_____________________________________________________________________________________
453 void AliTPCcalibDButil::ProcessGoofie(TVectorD & vecEntries, TVectorD & vecMedian, TVectorD &vecMean, TVectorD &vecRMS)
456 // Proces Goofie values, return statistical information of the currently set goofieArray
457 // The meaning of the entries are given below
459 1 TPC_ANODE_I_A00_STAT
461 3 TPC_DVM_DriftVelocity
466 8 TPC_DVM_NumberOfSparks
467 9 TPC_DVM_PeakAreaFar
468 10 TPC_DVM_PeakAreaNear
469 11 TPC_DVM_PeakPosFar
470 12 TPC_DVM_PeakPosNear
476 18 TPC_DVM_TemperatureS1
480 vecEntries.ResizeTo(nsensors);
481 vecMedian.ResizeTo(nsensors);
482 vecMean.ResizeTo(nsensors);
483 vecRMS.ResizeTo(nsensors);
490 Double_t kEpsilon=0.0000000001;
491 Double_t kBig=100000000000.;
492 Int_t nsensors = fGoofieArray->NumSensors();
493 vecEntries.ResizeTo(nsensors);
494 vecMedian.ResizeTo(nsensors);
495 vecMean.ResizeTo(nsensors);
496 vecRMS.ResizeTo(nsensors);
498 for (Int_t isensor=0; isensor<fGoofieArray->NumSensors();isensor++){
499 AliDCSSensor *gsensor = fGoofieArray->GetSensor(isensor);
500 if (gsensor && gsensor->GetGraph()){
501 Int_t npoints = gsensor->GetGraph()->GetN();
503 values.ResizeTo(npoints);
505 for (Int_t ipoint=0; ipoint<npoints; ipoint++){
506 if (TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])>kEpsilon &&
507 TMath::Abs(gsensor->GetGraph()->GetY()[ipoint])<kBig ){
508 values[nused]=gsensor->GetGraph()->GetY()[ipoint];
513 vecEntries[isensor]= nused;
515 vecMedian[isensor] = TMath::Median(nused,values.GetMatrixArray());
516 vecMean[isensor] = TMath::Mean(nused,values.GetMatrixArray());
517 vecRMS[isensor] = TMath::RMS(nused,values.GetMatrixArray());
523 //_____________________________________________________________________________________
524 void AliTPCcalibDButil::UpdatePulserOutlierMap()
527 // Create a map that contains outliers from the Pulser calibration data.
528 // The outliers include masked channels, edge pads and pads with
529 // too large timing and charge variations.
530 // nonMaskedZero is the number of outliers in the Pulser calibration data.
531 // those do not contain masked and edge pads
533 if (!fPulserTmean||!fPulserQmean) {
535 fPulserOutlier->Multiply(0.);
539 AliTPCCalROC *rocMasked=0x0;
543 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
544 AliTPCCalROC *tmeanROC=fPulserTmean->GetCalROC(isec);
545 AliTPCCalROC *qmeanROC=fPulserQmean->GetCalROC(isec);
546 AliTPCCalROC *outROC=fPulserOutlier->GetCalROC(isec);
547 if (!tmeanROC||!qmeanROC) {
548 //reset outliers in this ROC
549 outROC->Multiply(0.);
552 if (fALTROMasked) rocMasked=fALTROMasked->GetCalROC(isec);
554 // Float_t qmedian=qmeanROC->GetLTM(&dummy,.5);
555 // Float_t tmedian=tmeanROC->GetLTM(&dummy,.5);
556 UInt_t nrows=tmeanROC->GetNrows();
557 for (UInt_t irow=0;irow<nrows;++irow){
558 UInt_t npads=tmeanROC->GetNPads(irow);
559 for (UInt_t ipad=0;ipad<npads;++ipad){
560 Int_t outlier=0,masked=0;
561 Float_t q=qmeanROC->GetValue(irow,ipad);
562 Float_t t=tmeanROC->GetValue(irow,ipad);
563 //masked channels are outliers
564 if (rocMasked && rocMasked->GetValue(irow,ipad)) masked=1;
565 //edge pads are outliers
566 if (ipad==0||ipad==npads-1) masked=1;
567 //channels with too large charge or timing deviation from the meadian are outliers
568 // if (TMath::Abs(q-qmedian)>fPulQmaxLimitAbs || TMath::Abs(t-tmedian)>fPulTmaxLimitAbs) outlier=1;
569 if (q<fPulQminLimit && !masked) outlier=1;
571 if ( !(q<10000000) || !(t<10000000)) outlier=1;
572 outROC->SetValue(irow,ipad,outlier+masked);
573 fNpulserOutliers+=outlier;
578 //_____________________________________________________________________________________
579 AliTPCCalPad* AliTPCcalibDButil::CreatePadTime0(Int_t model)
582 // Create pad time0 object from pulser and/or CE data, depending on the selected model
583 // Model 0: normalise each readout chamber to its mean, outlier cutted, only Pulser
584 // Model 1: normalise IROCs/OROCs of each readout side to its mean, only Pulser
588 AliTPCCalPad *padTime0=new AliTPCCalPad("PadTime0",Form("PadTime0-Model_%d",model));
589 // decide between different models
590 if (model==0||model==1){
592 if (model==1) ProcessPulser(vMean);
593 for (UInt_t isec=0;isec<AliTPCCalPad::kNsec;++isec){
594 AliTPCCalROC *rocPulTmean=fPulserTmean->GetCalROC(isec);
595 if (!rocPulTmean) continue;
596 AliTPCCalROC *rocTime0=padTime0->GetCalROC(isec);
597 AliTPCCalROC *rocOut=fPulserOutlier->GetCalROC(isec);
598 Float_t mean=rocPulTmean->GetMean(rocOut);
599 //treat case where a whole partition is masked
600 if (mean==0) mean=rocPulTmean->GetMean();
605 UInt_t nrows=rocTime0->GetNrows();
606 for (UInt_t irow=0;irow<nrows;++irow){
607 UInt_t npads=rocTime0->GetNPads(irow);
608 for (UInt_t ipad=0;ipad<npads;++ipad){
609 Float_t time=rocPulTmean->GetValue(irow,ipad);
610 //in case of an outlier pad use the mean of the altro values.
611 //This should be the most precise guess in that case.
612 if (rocOut->GetValue(irow,ipad)) {
613 time=GetMeanAltro(rocPulTmean,irow,ipad,rocOut);
614 if (time==0) time=mean;
616 Float_t val=time-mean;
617 rocTime0->SetValue(irow,ipad,val);
627 //_____________________________________________________________________________________
628 Float_t AliTPCcalibDButil::GetMeanAltro(const AliTPCCalROC *roc, const Int_t row, const Int_t pad, AliTPCCalROC *rocOut)
630 if (roc==0) return 0.;
631 const Int_t sector=roc->GetSector();
632 AliTPCROC *tpcRoc=AliTPCROC::Instance();
633 const UInt_t altroRoc=fMapper->GetFEC(sector,row,pad)*8+fMapper->GetChip(sector,row,pad);
637 //loop over a small range around the requested pad (+-10 rows/pads)
638 for (Int_t irow=row-10;irow<row+10;++irow){
639 if (irow<0||irow>(Int_t)tpcRoc->GetNRows(sector)-1) continue;
640 for (Int_t ipad=pad-10; ipad<pad+10;++ipad){
641 if (ipad<0||ipad>(Int_t)tpcRoc->GetNPads(sector,irow)-1) continue;
642 const UInt_t altroCurr=fMapper->GetFEC(sector,irow,ipad)*8+fMapper->GetChip(sector,irow,ipad);
643 if (altroRoc!=altroCurr) continue;
644 if ( rocOut && rocOut->GetValue(irow,ipad) ) continue;
645 Float_t val=roc->GetValue(irow,ipad);