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 // Calibration base class for a single ROC //
20 // Contains one float value per pad //
21 // mapping of the pads taken form AliTPCROC //
23 ///////////////////////////////////////////////////////////////////////////////
37 #include "AliTPCCalROC.h"
38 #include "AliMathBase.h"
40 #include "TRandom3.h" // only needed by the AliTPCCalROCTest() method
42 ClassImp(AliTPCCalROC)
45 //_____________________________________________________________________________
46 AliTPCCalROC::AliTPCCalROC()
55 // Default constructor
60 //_____________________________________________________________________________
61 AliTPCCalROC::AliTPCCalROC(UInt_t sector)
70 // Constructor that initializes a given sector
73 fNChannels = AliTPCROC::Instance()->GetNChannels(fSector);
74 fNRows = AliTPCROC::Instance()->GetNRows(fSector);
75 fkIndexes = AliTPCROC::Instance()->GetRowIndexes(fSector);
76 fData = new Float_t[fNChannels];
77 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata] = 0.;
80 //_____________________________________________________________________________
81 AliTPCCalROC::AliTPCCalROC(const AliTPCCalROC &c)
90 // AliTPCCalROC copy constructor
93 fNChannels = AliTPCROC::Instance()->GetNChannels(fSector);
94 fNRows = AliTPCROC::Instance()->GetNRows(fSector);
95 fkIndexes = AliTPCROC::Instance()->GetRowIndexes(fSector);
97 fData = new Float_t[fNChannels];
98 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata] = c.fData[idata];
100 //____________________________________________________________________________
101 AliTPCCalROC & AliTPCCalROC::operator =(const AliTPCCalROC & param)
104 // assignment operator - dummy
106 if (this == ¶m) return (*this);
107 fSector = param.fSector;
108 fNChannels = AliTPCROC::Instance()->GetNChannels(fSector);
109 fNRows = AliTPCROC::Instance()->GetNRows(fSector);
110 fkIndexes = AliTPCROC::Instance()->GetRowIndexes(fSector);
112 if (fData) delete [] fData;
113 fData = new Float_t[fNChannels];
114 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata] = param.fData[idata];
119 //_____________________________________________________________________________
120 AliTPCCalROC::~AliTPCCalROC()
123 // AliTPCCalROC destructor
133 void AliTPCCalROC::Streamer(TBuffer &R__b)
136 // Stream an object of class AliTPCCalROC.
138 if (R__b.IsReading()) {
139 AliTPCCalROC::Class()->ReadBuffer(R__b, this);
140 fkIndexes = AliTPCROC::Instance()->GetRowIndexes(fSector);
142 AliTPCCalROC::Class()->WriteBuffer(R__b,this);
146 Bool_t AliTPCCalROC::MedianFilter(Int_t deltaRow, Int_t deltaPad){
148 // Modify content of the class
150 Float_t *newBuffer=new Float_t[fNChannels] ;
151 Float_t *cacheBuffer=new Float_t[fNChannels] ;
153 for (UInt_t iRow=0; iRow<fNRows; iRow++){
154 Int_t nPads=GetNPads(iRow); // number of rows in current row
155 for (Int_t iPad=0; iPad<nPads; iPad++){
157 for (Int_t dRow=-deltaRow; dRow<=deltaRow; dRow++){
158 Int_t jRow=iRow+dRow;
159 Int_t jPads= GetNPads(jRow);
160 if (jPads==0) continue;
161 Int_t offset=(nPads-jPads)/2.;
162 for (Int_t dPad=-deltaPad; dPad<=deltaPad; dPad++){
163 Int_t jPad=iPad+dPad+offset;
164 if (jPad<0 || jPad>=jPads) continue;
165 cacheBuffer[counter++]=GetValue(jRow,jPad);
168 newBuffer[fkIndexes[iRow]+iPad] = TMath::Median(counter,cacheBuffer);
171 memcpy(fData, newBuffer,GetNchannels()*sizeof(Float_t));
173 delete []cacheBuffer;
177 Bool_t AliTPCCalROC::LTMFilter(Int_t deltaRow, Int_t deltaPad, Float_t fraction, Int_t type){
181 // Modify content of the class
183 if (fraction<0 || fraction>1) return kFALSE;
184 Float_t *newBuffer=new Float_t[fNChannels] ;
185 Double_t *cacheBuffer=new Double_t[fNChannels];
187 for (UInt_t iRow=0; iRow<fNRows; iRow++){
188 Int_t nPads=GetNPads(iRow); // number of rows in current row
189 for (Int_t iPad=0; iPad<nPads; iPad++){
191 for (Int_t dRow=-deltaRow; dRow<=deltaRow; dRow++){
192 Int_t jRow=iRow+dRow;
193 Int_t jPads= GetNPads(jRow);
194 if (jPads==0) continue;
195 Int_t offset=(nPads-jPads)/2.;
196 for (Int_t dPad=-deltaPad; dPad<=deltaPad; dPad++){
197 Int_t jPad=iPad+dPad+offset;
198 if (jPad<0 || jPad>=jPads) continue;
199 cacheBuffer[counter++]=GetValue(jRow,jPad);
203 AliMathBase::EvaluateUni(counter,cacheBuffer,mean,rms,fraction*Double_t(counter));
204 newBuffer[fkIndexes[iRow]+iPad] = (type==0)? mean:rms;
207 memcpy(fData, newBuffer,GetNchannels()*sizeof(Float_t));
209 delete []cacheBuffer;
217 void AliTPCCalROC::Add(Float_t c1){
219 // add c1 to each channel of the ROC
221 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata]+=c1;
225 void AliTPCCalROC::Multiply(Float_t c1){
227 // multiply each channel of the ROC with c1
229 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata]*=c1;
233 void AliTPCCalROC::Add(const AliTPCCalROC * roc, Double_t c1){
235 // multiply AliTPCCalROC roc by c1 and add each channel to the coresponing channel in the ROC
238 for (UInt_t idata = 0; idata< fNChannels; idata++){
239 fData[idata]+=roc->fData[idata]*c1;
244 void AliTPCCalROC::Multiply(const AliTPCCalROC* roc) {
246 // multiply each channel of the ROC with the coresponding channel of 'roc'
249 for (UInt_t idata = 0; idata< fNChannels; idata++){
250 fData[idata]*=roc->fData[idata];
255 void AliTPCCalROC::Divide(const AliTPCCalROC* roc) {
257 // divide each channel of the ROC by the coresponding channel of 'roc'
260 Float_t kEpsilon=0.00000000000000001;
261 for (UInt_t idata = 0; idata< fNChannels; idata++){
262 if (TMath::Abs(roc->fData[idata])>kEpsilon)
263 fData[idata]/=roc->fData[idata];
267 Double_t AliTPCCalROC::GetMean(AliTPCCalROC *const outlierROC) const {
269 // returns the mean value of the ROC
270 // pads with value != 0 in outlierROC are not used for the calculation
271 // return 0 if no data is accepted by the outlier cuts
273 if (!outlierROC) return TMath::Mean(fNChannels, fData);
274 Double_t *ddata = new Double_t[fNChannels];
276 for (UInt_t i=0;i<fNChannels;i++) {
277 if (!(outlierROC->GetValue(i))) {
278 ddata[nPoints]= fData[i];
284 mean = TMath::Mean(nPoints, ddata);
289 Double_t AliTPCCalROC::GetMedian(AliTPCCalROC *const outlierROC) const {
291 // returns the median value of the ROC
292 // pads with value != 0 in outlierROC are not used for the calculation
293 // return 0 if no data is accepted by the outlier cuts
295 if (!outlierROC) return TMath::Median(fNChannels, fData);
296 Double_t *ddata = new Double_t[fNChannels];
298 for (UInt_t i=0;i<fNChannels;i++) {
299 if (!(outlierROC->GetValue(i))) {
300 ddata[nPoints]= fData[i];
306 median = TMath::Median(nPoints, ddata);
311 Double_t AliTPCCalROC::GetRMS(AliTPCCalROC *const outlierROC) const {
313 // returns the RMS value of the ROC
314 // pads with value != 0 in outlierROC are not used for the calculation
315 // return 0 if no data is accepted by the outlier cuts
317 if (!outlierROC) return TMath::RMS(fNChannels, fData);
318 Double_t *ddata = new Double_t[fNChannels];
320 for (UInt_t i=0;i<fNChannels;i++) {
321 if (!(outlierROC->GetValue(i))) {
322 ddata[nPoints]= fData[i];
328 rms = TMath::RMS(nPoints, ddata);
333 Double_t AliTPCCalROC::GetLTM(Double_t *const sigma, Double_t fraction, AliTPCCalROC *const outlierROC){
335 // returns the LTM and sigma
336 // pads with value != 0 in outlierROC are not used for the calculation
337 // return 0 if no data is accepted by the outlier cuts
339 Double_t *ddata = new Double_t[fNChannels];
341 for (UInt_t i=0;i<fNChannels;i++) {
342 if (!outlierROC || !(outlierROC->GetValue(i))) {
343 ddata[nPoints]= fData[i];
348 Double_t ltm =0, lsigma=0;
350 Int_t hh = TMath::Min(TMath::Nint(fraction *nPoints), Int_t(nPoints));
351 AliMathBase::EvaluateUni(nPoints,ddata, ltm, lsigma, hh);
352 if (sigma) *sigma=lsigma;
359 TH1F * AliTPCCalROC::MakeHisto1D(Float_t min, Float_t max,Int_t type){
362 // type -1 = user defined range
363 // 0 = nsigma cut nsigma=min
364 // 1 = delta cut around median delta=min
369 Float_t mean = GetMean();
370 Float_t sigma = GetRMS();
371 Float_t nsigma = TMath::Abs(min);
372 min = mean-nsigma*sigma;
373 max = mean+nsigma*sigma;
377 Float_t mean = GetMedian();
384 // LTM mean +- nsigma
387 Float_t mean = GetLTM(&sigma,max);
393 TString name=Form("%s ROC 1D%d",GetTitle(),fSector);
394 TH1F * his = new TH1F(name.Data(),name.Data(),100, min,max);
395 for (UInt_t irow=0; irow<fNRows; irow++){
396 UInt_t npads = (Int_t)GetNPads(irow);
397 for (UInt_t ipad=0; ipad<npads; ipad++){
398 his->Fill(GetValue(irow,ipad));
406 TH2F * AliTPCCalROC::MakeHisto2D(Float_t min, Float_t max,Int_t type){
409 // type -1 = user defined range
410 // 0 = nsigma cut nsigma=min
411 // 1 = delta cut around median delta=min
416 Float_t mean = GetMean();
417 Float_t sigma = GetRMS();
418 Float_t nsigma = TMath::Abs(min);
419 min = mean-nsigma*sigma;
420 max = mean+nsigma*sigma;
424 Float_t mean = GetMedian();
431 Float_t mean = GetLTM(&sigma,max);
439 for (UInt_t irow=0; irow<fNRows; irow++){
440 if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
443 TString name=Form("%s ROC%d",GetTitle(),fSector);
444 TH2F * his = new TH2F(name.Data(),name.Data(),fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
445 for (UInt_t irow=0; irow<fNRows; irow++){
446 UInt_t npads = (Int_t)GetNPads(irow);
447 for (UInt_t ipad=0; ipad<npads; ipad++){
448 his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,GetValue(irow,ipad));
451 his->SetMaximum(max);
452 his->SetMinimum(min);
456 TH2F * AliTPCCalROC::MakeHistoOutliers(Float_t delta, Float_t fraction, Int_t type){
458 // Make Histogram with outliers
459 // mode = 0 - sigma cut used
460 // mode = 1 - absolute cut used
461 // fraction - fraction of values used to define sigma
462 // delta - in mode 0 - nsigma cut
463 // mode 1 - delta cut
466 Float_t mean = GetLTM(&sigma,fraction);
467 if (type==0) delta*=sigma;
469 for (UInt_t irow=0; irow<fNRows; irow++){
470 if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
473 TString name=Form("%s ROC Outliers%d",GetTitle(),fSector);
474 TH2F * his = new TH2F(name.Data(),name.Data(),fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
475 for (UInt_t irow=0; irow<fNRows; irow++){
476 UInt_t npads = (Int_t)GetNPads(irow);
477 for (UInt_t ipad=0; ipad<npads; ipad++){
478 if (TMath::Abs(GetValue(irow,ipad)-mean)>delta)
479 his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,1);
487 void AliTPCCalROC::Draw(Option_t* opt){
489 // create histogram with values and draw it
494 if (option.Contains("1D")){
507 void AliTPCCalROC::Test() {
509 // example function to show functionality and test AliTPCCalROC
512 Float_t kEpsilon=0.00001;
514 // create CalROC with defined values
515 AliTPCCalROC roc0(0);
516 for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
517 for (UInt_t ipad = 0; ipad <roc0.GetNPads(irow); ipad++){
518 Float_t value = irow+ipad/1000.;
519 roc0.SetValue(irow,ipad,value);
523 // copy CalROC, readout values and compare to original
524 AliTPCCalROC roc1(roc0);
525 for (UInt_t irow = 0; irow <roc1.GetNrows(); irow++){
526 for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
527 Float_t value = irow+ipad/1000.;
528 if (roc1.GetValue(irow,ipad)!=value){
529 printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);
534 // write original CalROC to file
535 TFile f("calcTest.root","recreate");
537 AliTPCCalROC * roc2 = (AliTPCCalROC*)f.Get("Roc0");
540 // read CalROC from file and compare to original CalROC
541 for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
542 if (roc0.GetNPads(irow)!=roc2->GetNPads(irow))
543 printf("NPads - Read/Write error\trow=%d\n",irow);
544 for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
545 Float_t value = irow+ipad/1000.;
546 if (roc2->GetValue(irow,ipad)!=value){
547 printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);
557 AliTPCCalROC roc3(roc0);
559 for (UInt_t irow = 0; irow <roc3.GetNrows(); irow++){
560 for (UInt_t ipad = 0; ipad <roc3.GetNPads(irow); ipad++){
561 Float_t value = irow+ipad/1000. + 1.5;
562 if (TMath::Abs(roc3.GetValue(irow,ipad)-value) > kEpsilon){
563 printf("Add constant - error\trow=%d\tpad=%d\n",irow,ipad);
568 // Add another CalROC
569 AliTPCCalROC roc4(roc0);
570 roc4.Add(&roc0, -1.5);
571 for (UInt_t irow = 0; irow <roc4.GetNrows(); irow++){
572 for (UInt_t ipad = 0; ipad <roc4.GetNPads(irow); ipad++){
573 Float_t value = irow+ipad/1000. - 1.5 * (irow+ipad/1000.);
574 if (TMath::Abs(roc4.GetValue(irow,ipad)-value) > kEpsilon){
575 printf("Add CalROC - error\trow=%d\tpad=%d\n",irow,ipad);
580 // Multiply with constant
581 AliTPCCalROC roc5(roc0);
583 for (UInt_t irow = 0; irow <roc5.GetNrows(); irow++){
584 for (UInt_t ipad = 0; ipad <roc5.GetNPads(irow); ipad++){
585 Float_t value = (irow+ipad/1000.) * (-1.4);
586 if (TMath::Abs(roc5.GetValue(irow,ipad)-value) > kEpsilon){
587 printf("Multiply with constant - error\trow=%d\tpad=%d\n",irow,ipad);
592 // Multiply another CalROC
593 AliTPCCalROC roc6(roc0);
594 roc6.Multiply(&roc0);
595 for (UInt_t irow = 0; irow <roc6.GetNrows(); irow++){
596 for (UInt_t ipad = 0; ipad <roc6.GetNPads(irow); ipad++){
597 Float_t value = (irow+ipad/1000.) * (irow+ipad/1000.);
598 if (TMath::Abs(roc6.GetValue(irow,ipad)-value) > kEpsilon*100){
599 printf("Multiply with CalROC - error\trow=%d\tpad=%d\n",irow,ipad);
606 AliTPCCalROC roc7(roc0);
608 for (UInt_t irow = 0; irow <roc7.GetNrows(); irow++){
609 for (UInt_t ipad = 0; ipad <roc7.GetNPads(irow); ipad++){
611 if (irow+ipad == 0) value = roc0.GetValue(irow,ipad);
612 if (TMath::Abs(roc7.GetValue(irow,ipad)-value) > kEpsilon){
613 printf("Multiply with CalROC - error\trow=%d\tpad=%d\n",irow,ipad);
622 // create CalROC with defined values
624 AliTPCCalROC sroc0(0);
625 for (UInt_t ichannel = 0; ichannel < sroc0.GetNchannels(); ichannel++){
626 Float_t value = rnd.Gaus(10., 2.);
627 sroc0.SetValue(ichannel,value);
630 printf("Mean (should be close to 10): %f\n", sroc0.GetMean());
631 printf("RMS (should be close to 2): %f\n", sroc0.GetRMS());
632 printf("Median (should be close to 10): %f\n", sroc0.GetMedian());
633 printf("LTM (should be close to 10): %f\n", sroc0.GetLTM());
635 //AliTPCCalROC* sroc1 = sroc0.LocalFit(4, 8);
639 // std::cout << TMath::Abs(roc5.GetValue(irow,ipad)-value) << std::endl;
643 AliTPCCalROC * AliTPCCalROC::LocalFit(Int_t rowRadius, Int_t padRadius, AliTPCCalROC* ROCoutliers, Bool_t robust, Double_t chi2Threshold, Double_t robustFraction) {
645 // MakeLocalFit - smoothing
646 // returns a AliTPCCalROC with smoothed data
647 // rowRadius and padRadius specifies a window around a given pad.
648 // The data of this window are fitted with a parabolic function.
649 // This function is evaluated at the pad's position.
650 // At the edges the window is shifted, so that the specified pad is not anymore in the center of the window.
651 // rowRadius - radius - rows to be used for smoothing
652 // padradius - radius - pads to be used for smoothing
653 // ROCoutlier - map of outliers - pads not to be used for local smoothing
654 // robust - robust method of fitting - (much slower)
655 // chi2Threshold: Threshold for chi2 when EvalRobust is called
656 // robustFraction: Fraction of data that will be used in EvalRobust
658 AliTPCCalROC * xROCfitted = new AliTPCCalROC(fSector);
659 TLinearFitter fitterQ(6,"hyp5");
660 // TLinearFitter fitterQ(6,"x0++x1++x2++x3++x4++x5");
661 fitterQ.StoreData(kTRUE);
662 for (UInt_t row=0; row < GetNrows(); row++) {
663 //std::cout << "Entering row " << row << " of " << GetNrows() << " @ sector "<< fSector << " for local fitting... "<< std::endl;
664 for (UInt_t pad=0; pad < GetNPads(row); pad++)
665 xROCfitted->SetValue(row, pad, GetNeighbourhoodValue(&fitterQ, row, pad, rowRadius, padRadius, ROCoutliers, robust, chi2Threshold, robustFraction));
671 Double_t AliTPCCalROC::GetNeighbourhoodValue(TLinearFitter* fitterQ, Int_t row, Int_t pad, Int_t rRadius, Int_t pRadius, AliTPCCalROC *const ROCoutliers, Bool_t robust, Double_t chi2Threshold, Double_t robustFraction) {
673 // AliTPCCalROC::GetNeighbourhoodValue - smoothing - PRIVATE
674 // in this function the fit for LocalFit is done
677 fitterQ->ClearPoints();
678 TVectorD fitParam(6);
682 Float_t lPad[3] = {0};
683 Float_t localXY[3] = {0};
685 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
686 tpcROCinstance->GetPositionLocal(fSector, row, pad, lPad); // calculate position lPad by pad and row number
688 TArrayI *neighbourhoodRows = 0;
689 TArrayI *neighbourhoodPads = 0;
691 //std::cerr << "Trying to get neighbourhood for row " << row << ", pad " << pad << std::endl;
692 GetNeighbourhood(neighbourhoodRows, neighbourhoodPads, row, pad, rRadius, pRadius);
693 //std::cerr << "Got neighbourhood for row " << row << ", pad " << pad << std::endl;
696 for (Int_t i=0; i < (2*rRadius+1)*(2*pRadius+1); i++) {
697 r = neighbourhoodRows->At(i);
698 p = neighbourhoodPads->At(i);
699 if (r == -1 || p == -1) continue; // window is bigger than ROC
700 tpcROCinstance->GetPositionLocal(fSector, r, p, localXY); // calculate position localXY by pad and row number
701 dlx = lPad[0] - localXY[0];
702 dly = lPad[1] - localXY[1];
709 if (!ROCoutliers || ROCoutliers->GetValue(r,p) != 1) {
710 fitterQ->AddPoint(&xx[1], GetValue(r, p), 1);
715 delete neighbourhoodRows;
716 delete neighbourhoodPads;
718 if (npoints < 0.5 * ((2*rRadius+1)*(2*pRadius+1)) ) {
719 // std::cerr << "Too few data points for fitting @ row " << row << ", pad " << pad << " in sector " << fSector << std::endl;
720 return 0.; // for diagnostic
723 fitterQ->GetParameters(fitParam);
725 if (robust) chi2Q = fitterQ->GetChisquare()/(npoints-6.);
726 //if (robust) chi2Q = fitterQ->GetChisquare()/(npoints-6.);
727 if (robust && chi2Q > chi2Threshold) {
728 //std::cout << "robust fitter called... " << std::endl;
729 fitterQ->EvalRobust(robustFraction);
730 fitterQ->GetParameters(fitParam);
732 Double_t value = fitParam[0];
734 //if (value < 0) std::cerr << "negative fit-value " << value << " in sector "<< this->fSector << " @ row: " << row << " and pad: " << pad << ", with fitter Chi2 = " << chi2Q << std::endl;
741 void AliTPCCalROC::GetNeighbourhood(TArrayI* &rowArray, TArrayI* &padArray, Int_t row, Int_t pad, Int_t rRadius, Int_t pRadius) {
743 // AliTPCCalROC::GetNeighbourhood - PRIVATE
744 // in this function the window for LocalFit is determined
746 rowArray = new TArrayI((2*rRadius+1)*(2*pRadius+1));
747 padArray = new TArrayI((2*rRadius+1)*(2*pRadius+1));
749 Int_t rmin = row - rRadius;
750 UInt_t rmax = row + rRadius;
752 // if window goes out of ROC
757 if (rmax >= GetNrows()) {
758 rmin = rmin - (rmax - GetNrows()+1);
759 rmax = GetNrows() - 1;
760 if (rmin < 0 ) rmin = 0; // if the window is bigger than the ROC
766 for (UInt_t r = rmin; r <= rmax; r++) {
767 pmin = pad - pRadius;
768 pmax = pad + pRadius;
773 if (pmax >= (Int_t)GetNPads(r)) {
774 pmin = pmin - (pmax - GetNPads(r)+1);
775 pmax = GetNPads(r) - 1;
776 if (pmin < 0 ) pmin = 0; // if the window is bigger than the ROC
778 for (Int_t p = pmin; p <= pmax; p++) {
784 for (Int_t j = i; j < rowArray->GetSize(); j++){ // unused padArray-entries, in the case that the window is bigger than the ROC
785 //std::cout << "trying to write -1" << std::endl;
788 //std::cout << "writing -1" << std::endl;
794 void AliTPCCalROC::GlobalFit(const AliTPCCalROC* ROCoutliers, Bool_t robust, TVectorD &fitParam, TMatrixD &covMatrix, Float_t & chi2, Int_t fitType, Double_t chi2Threshold, Double_t robustFraction, Double_t err){
796 // Makes a GlobalFit for the given secotr and return fit-parameters, covariance and chi2
797 // The origin of the fit function is the center of the ROC!
798 // fitType == 0: fit plane function
799 // fitType == 1: fit parabolic function
800 // ROCoutliers - pads with value !=0 are not used in fitting procedure
801 // chi2Threshold: Threshold for chi2 when EvalRobust is called
802 // robustFraction: Fraction of data that will be used in EvalRobust
803 // err: error of the data points
805 TLinearFitter* fitterG = 0;
809 fitterG = new TLinearFitter (6,"x0++x1++x2++x3++x4++x5");
810 fitParam.ResizeTo(6);
811 covMatrix.ResizeTo(6,6);
813 fitterG = new TLinearFitter(3,"x0++x1++x2");
814 fitParam.ResizeTo(3);
815 covMatrix.ResizeTo(3,3);
817 fitterG->StoreData(kTRUE);
818 fitterG->ClearPoints();
822 Float_t centerPad[3] = {0};
823 Float_t localXY[3] = {0};
825 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
826 tpcROCinstance->GetPositionLocal(fSector, GetNrows()/2, GetNPads(GetNrows()/2)/2, centerPad); // calculate center of ROC
828 // loop over all channels and read data into fitterG
829 for (UInt_t irow = 0; irow < GetNrows(); irow++) {
830 for (UInt_t ipad = 0; ipad < GetNPads(irow); ipad++) {
832 if (ROCoutliers && ROCoutliers->GetValue(irow, ipad) != 0) continue;
833 tpcROCinstance->GetPositionLocal(fSector, irow, ipad, localXY); // calculate position localXY by pad and row number
834 dlx = localXY[0] - centerPad[0];
835 dly = localXY[1] - centerPad[1];
843 fitterG->AddPoint(xx, GetValue(irow, ipad), err);
846 if(npoints>10) { // make sure there is something to fit
848 fitterG->GetParameters(fitParam);
849 fitterG->GetCovarianceMatrix(covMatrix);
851 chi2 = fitterG->GetChisquare()/(npoints-6.);
852 else chi2 = fitterG->GetChisquare()/(npoints-3.);
853 if (robust && chi2 > chi2Threshold) {
854 // std::cout << "robust fitter called... " << std::endl;
855 fitterG->EvalRobust(robustFraction);
856 fitterG->GetParameters(fitParam);
859 // set parameteres to 0
860 Int_t nParameters = 3;
864 for(Int_t i = 0; i < nParameters; i++)
872 AliTPCCalROC* AliTPCCalROC::CreateGlobalFitCalROC(TVectorD &fitParam, Int_t sector){
874 // Create ROC with global fit parameters
875 // The origin of the fit function is the center of the ROC!
876 // loop over all channels, write fit values into new ROC and return it
879 Float_t centerPad[3] = {0};
880 Float_t localXY[3] = {0};
881 AliTPCCalROC * xROCfitted = new AliTPCCalROC(sector);
882 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
883 tpcROCinstance->GetPositionLocal(sector, xROCfitted->GetNrows()/2, xROCfitted->GetNPads(xROCfitted->GetNrows()/2)/2, centerPad); // calculate center of ROC
885 if (fitParam.GetNoElements() == 6) fitType = 1;
888 if (fitType == 1) { // parabolic fit
889 for (UInt_t irow = 0; irow < xROCfitted->GetNrows(); irow++) {
890 for (UInt_t ipad = 0; ipad < xROCfitted->GetNPads(irow); ipad++) {
891 tpcROCinstance->GetPositionLocal(sector, irow, ipad, localXY); // calculate position localXY by pad and row number
892 dlx = localXY[0] - centerPad[0];
893 dly = localXY[1] - centerPad[1];
894 value = fitParam[0] + fitParam[1]*dlx + fitParam[2]*dly + fitParam[3]*dlx*dlx + fitParam[4]*dly*dly + fitParam[5]*dlx*dly;
895 xROCfitted->SetValue(irow, ipad, value);
900 for (UInt_t irow = 0; irow < xROCfitted->GetNrows(); irow++) {
901 for (UInt_t ipad = 0; ipad < xROCfitted->GetNPads(irow); ipad++) {
902 tpcROCinstance->GetPositionLocal(sector, irow, ipad, localXY); // calculate position localXY by pad and row number
903 dlx = localXY[0] - centerPad[0];
904 dly = localXY[1] - centerPad[1];
905 value = fitParam[0] + fitParam[1]*dlx + fitParam[2]*dly;
906 xROCfitted->SetValue(irow, ipad, value);