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);
149 Bool_t AliTPCCalROC::MedianFilter(Int_t deltaRow, Int_t deltaPad, AliTPCCalROC* outlierROC, Bool_t doEdge){
152 // Modify content of the object - raplace value by median in neighorhood
154 Float_t *newBuffer=new Float_t[fNChannels] ;
155 Double_t *cacheBuffer=new Double_t[fNChannels];
157 for (Int_t iRow=0; iRow< Int_t(fNRows); iRow++){
158 Int_t nPads=GetNPads(iRow); // number of rows in current row
159 for (Int_t iPad=0; iPad<nPads; iPad++){
160 Double_t value=GetValue(iRow,iPad);
163 for (Int_t dRow=-deltaRow; dRow<=deltaRow; dRow++){
164 Int_t jRow=iRow+dRow; //take the row - mirror if ouside of range
166 if (jRow<0) sign0=-1.;
167 if (UInt_t(jRow)>=fNRows) sign0=-1.;
168 Int_t jPads= GetNPads(iRow+sign0*dRow);
169 Int_t offset=(nPads-jPads)/2.;
171 for (Int_t dPad=-deltaPad; dPad<=deltaPad; dPad++){
173 Int_t jPad=iPad+dPad+offset; //take the pad - mirror if ouside of range
176 if (jPad>=jPads) sign=-1;
179 jPad=iPad-dPad+offset;
180 if (!doEdge) continue;
182 if (IsInRange(UInt_t(kRow),jPad)){
183 Bool_t isOutlier=(outlierROC==NULL)?kFALSE:outlierROC->GetValue(kRow,jPad)>0;
185 cacheBuffer[counter]=sign*(GetValue(kRow,jPad)-value);
191 newBuffer[fkIndexes[iRow]+iPad]=0.;
192 if (counter>1) newBuffer[fkIndexes[iRow]+iPad] = TMath::Median(counter, cacheBuffer)+value;
195 memcpy(fData, newBuffer,GetNchannels()*sizeof(Float_t));
197 delete []cacheBuffer;
203 Bool_t AliTPCCalROC::LTMFilter(Int_t deltaRow, Int_t deltaPad, Float_t fraction, Int_t type, AliTPCCalROC* outlierROC, Bool_t doEdge){
208 // Modify content of the class
209 // write LTM mean or median
210 if (fraction<0 || fraction>1) return kFALSE;
211 Float_t *newBuffer=new Float_t[fNChannels] ;
212 Double_t *cacheBuffer=new Double_t[fNChannels];
214 for (Int_t iRow=0; iRow< Int_t(fNRows); iRow++){
215 Int_t nPads=GetNPads(iRow); // number of rows in current row
216 for (Int_t iPad=0; iPad<nPads; iPad++){
217 Double_t value=GetValue(iRow,iPad);
220 for (Int_t dRow=-deltaRow; dRow<=deltaRow; dRow++){
221 Int_t jRow=iRow+dRow; //take the row - mirror if ouside of range
223 if (jRow<0) sign0=-1.;
224 if (UInt_t(jRow)>=fNRows) sign0=-1.;
225 Int_t jPads= GetNPads(iRow+sign0*dRow);
226 Int_t offset=(nPads-jPads)/2.;
228 for (Int_t dPad=-deltaPad; dPad<=deltaPad; dPad++){
230 Int_t jPad=iPad+dPad+offset; //take the pad - mirror if ouside of range
233 if (jPad>=jPads) sign=-1;
235 if (!doEdge) continue;
237 jPad=iPad-dPad+offset;
239 if (IsInRange(UInt_t(kRow),jPad)){
240 Bool_t isOutlier=(outlierROC==NULL)?kFALSE:outlierROC->GetValue(kRow,jPad)>0;
242 cacheBuffer[counter]=sign*(GetValue(kRow,jPad)-value);
248 Double_t mean=0,rms=0;
249 if (TMath::Nint(fraction*Double_t(counter))>1 ) AliMathBase::EvaluateUni(counter,cacheBuffer,mean,rms,TMath::Nint(fraction*Double_t(counter)));
251 newBuffer[fkIndexes[iRow]+iPad] = (type==0)? mean:rms;
254 memcpy(fData, newBuffer,GetNchannels()*sizeof(Float_t));
256 delete []cacheBuffer;
260 Bool_t AliTPCCalROC::Convolute(Double_t sigmaPad, Double_t sigmaRow, AliTPCCalROC*outlierROC, TF1 */*fpad*/, TF1 */*frow*/){
262 // convolute the calibration with function fpad,frow
263 // in range +-4 sigma
265 Float_t *newBuffer=new Float_t[fNChannels] ;
267 for (Int_t iRow=0; iRow< Int_t(fNRows); iRow++){
268 Int_t nPads=GetNPads(iRow); // number of rows in current row
269 for (Int_t iPad=0; iPad<nPads; iPad++){
270 Int_t jRow0=TMath::Max(TMath::Nint(iRow-sigmaRow*4.),0);
271 Int_t jRow1=TMath::Min(TMath::Nint(iRow+sigmaRow*4.),Int_t(fNRows));
272 Int_t jPad0=TMath::Max(TMath::Nint(iPad-sigmaPad*4.),0);
273 Int_t jPad1=TMath::Min(TMath::Nint(iRow+sigmaPad*4.),Int_t(nPads));
277 for (Int_t jRow=jRow0; jRow<=jRow1; jRow++){
278 for (Int_t jPad=jPad0; jPad<=jPad1; jPad++){
279 if (!IsInRange(jRow,jPad)) continue;
280 Bool_t isOutlier=(outlierROC==NULL)?kFALSE:outlierROC->GetValue(jRow,jPad)>0;
282 Double_t weight= TMath::Gaus(jPad,iPad,sigmaPad)*TMath::Gaus(jRow,iRow,sigmaRow);
283 sumCal+=weight*GetValue(jRow,jPad);
290 newBuffer[fkIndexes[iRow]+iPad]=sumCal;
294 memcpy(fData, newBuffer,GetNchannels()*sizeof(Float_t));
308 void AliTPCCalROC::Add(Float_t c1){
310 // add c1 to each channel of the ROC
312 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata]+=c1;
316 void AliTPCCalROC::Multiply(Float_t c1){
318 // multiply each channel of the ROC with c1
320 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata]*=c1;
324 void AliTPCCalROC::Add(const AliTPCCalROC * roc, Double_t c1){
326 // multiply AliTPCCalROC roc by c1 and add each channel to the coresponing channel in the ROC
329 for (UInt_t idata = 0; idata< fNChannels; idata++){
330 fData[idata]+=roc->fData[idata]*c1;
335 void AliTPCCalROC::Multiply(const AliTPCCalROC* roc) {
337 // multiply each channel of the ROC with the coresponding channel of 'roc'
340 for (UInt_t idata = 0; idata< fNChannels; idata++){
341 fData[idata]*=roc->fData[idata];
346 void AliTPCCalROC::Divide(const AliTPCCalROC* roc) {
348 // divide each channel of the ROC by the coresponding channel of 'roc'
351 Float_t kEpsilon=0.00000000000000001;
352 for (UInt_t idata = 0; idata< fNChannels; idata++){
353 if (TMath::Abs(roc->fData[idata])>kEpsilon)
354 fData[idata]/=roc->fData[idata];
358 Double_t AliTPCCalROC::GetMean(AliTPCCalROC *const outlierROC) const {
360 // returns the mean value of the ROC
361 // pads with value != 0 in outlierROC are not used for the calculation
362 // return 0 if no data is accepted by the outlier cuts
364 if (!outlierROC) return TMath::Mean(fNChannels, fData);
365 Double_t *ddata = new Double_t[fNChannels];
367 for (UInt_t i=0;i<fNChannels;i++) {
368 if (!(outlierROC->GetValue(i))) {
369 ddata[nPoints]= fData[i];
375 mean = TMath::Mean(nPoints, ddata);
380 Double_t AliTPCCalROC::GetMedian(AliTPCCalROC *const outlierROC) const {
382 // returns the median value of the ROC
383 // pads with value != 0 in outlierROC are not used for the calculation
384 // return 0 if no data is accepted by the outlier cuts
386 if (!outlierROC) return TMath::Median(fNChannels, fData);
387 Double_t *ddata = new Double_t[fNChannels];
389 for (UInt_t i=0;i<fNChannels;i++) {
390 if (!(outlierROC->GetValue(i))) {
391 ddata[nPoints]= fData[i];
397 median = TMath::Median(nPoints, ddata);
402 Double_t AliTPCCalROC::GetRMS(AliTPCCalROC *const outlierROC) const {
404 // returns the RMS value of the ROC
405 // pads with value != 0 in outlierROC are not used for the calculation
406 // return 0 if no data is accepted by the outlier cuts
408 if (!outlierROC) return TMath::RMS(fNChannels, fData);
409 Double_t *ddata = new Double_t[fNChannels];
411 for (UInt_t i=0;i<fNChannels;i++) {
412 if (!(outlierROC->GetValue(i))) {
413 ddata[nPoints]= fData[i];
419 rms = TMath::RMS(nPoints, ddata);
424 Double_t AliTPCCalROC::GetLTM(Double_t *const sigma, Double_t fraction, AliTPCCalROC *const outlierROC){
426 // returns the LTM and sigma
427 // pads with value != 0 in outlierROC are not used for the calculation
428 // return 0 if no data is accepted by the outlier cuts
430 Double_t *ddata = new Double_t[fNChannels];
432 for (UInt_t i=0;i<fNChannels;i++) {
433 if (!outlierROC || !(outlierROC->GetValue(i))) {
434 ddata[nPoints]= fData[i];
439 Double_t ltm =0, lsigma=0;
441 Int_t hh = TMath::Min(TMath::Nint(fraction *nPoints), Int_t(nPoints));
442 AliMathBase::EvaluateUni(nPoints,ddata, ltm, lsigma, hh);
443 if (sigma) *sigma=lsigma;
450 TH1F * AliTPCCalROC::MakeHisto1D(Float_t min, Float_t max,Int_t type){
453 // type -1 = user defined range
454 // 0 = nsigma cut nsigma=min
455 // 1 = delta cut around median delta=min
460 Float_t mean = GetMean();
461 Float_t sigma = GetRMS();
462 Float_t nsigma = TMath::Abs(min);
463 min = mean-nsigma*sigma;
464 max = mean+nsigma*sigma;
468 Float_t mean = GetMedian();
475 // LTM mean +- nsigma
478 Float_t mean = GetLTM(&sigma,max);
484 TString name=Form("%s ROC 1D%d",GetTitle(),fSector);
485 TH1F * his = new TH1F(name.Data(),name.Data(),100, min,max);
486 for (UInt_t irow=0; irow<fNRows; irow++){
487 UInt_t npads = (Int_t)GetNPads(irow);
488 for (UInt_t ipad=0; ipad<npads; ipad++){
489 his->Fill(GetValue(irow,ipad));
497 TH2F * AliTPCCalROC::MakeHisto2D(Float_t min, Float_t max,Int_t type){
500 // type -1 = user defined range
501 // 0 = nsigma cut nsigma=min
502 // 1 = delta cut around median delta=min
507 Float_t mean = GetMean();
508 Float_t sigma = GetRMS();
509 Float_t nsigma = TMath::Abs(min);
510 min = mean-nsigma*sigma;
511 max = mean+nsigma*sigma;
515 Float_t mean = GetMedian();
522 Float_t mean = GetLTM(&sigma,max);
530 for (UInt_t irow=0; irow<fNRows; irow++){
531 if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
534 TString name=Form("%s ROC%d",GetTitle(),fSector);
535 TH2F * his = new TH2F(name.Data(),name.Data(),fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
536 for (UInt_t irow=0; irow<fNRows; irow++){
537 UInt_t npads = (Int_t)GetNPads(irow);
538 for (UInt_t ipad=0; ipad<npads; ipad++){
539 his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,GetValue(irow,ipad));
542 his->SetMaximum(max);
543 his->SetMinimum(min);
547 TH2F * AliTPCCalROC::MakeHistoOutliers(Float_t delta, Float_t fraction, Int_t type){
549 // Make Histogram with outliers
550 // mode = 0 - sigma cut used
551 // mode = 1 - absolute cut used
552 // fraction - fraction of values used to define sigma
553 // delta - in mode 0 - nsigma cut
554 // mode 1 - delta cut
557 Float_t mean = GetLTM(&sigma,fraction);
558 if (type==0) delta*=sigma;
560 for (UInt_t irow=0; irow<fNRows; irow++){
561 if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
564 TString name=Form("%s ROC Outliers%d",GetTitle(),fSector);
565 TH2F * his = new TH2F(name.Data(),name.Data(),fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
566 for (UInt_t irow=0; irow<fNRows; irow++){
567 UInt_t npads = (Int_t)GetNPads(irow);
568 for (UInt_t ipad=0; ipad<npads; ipad++){
569 if (TMath::Abs(GetValue(irow,ipad)-mean)>delta)
570 his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,1);
578 void AliTPCCalROC::Draw(Option_t* opt){
580 // create histogram with values and draw it
585 if (option.Contains("1D")){
598 void AliTPCCalROC::Test() {
600 // example function to show functionality and test AliTPCCalROC
603 Float_t kEpsilon=0.00001;
605 // create CalROC with defined values
606 AliTPCCalROC roc0(0);
607 for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
608 for (UInt_t ipad = 0; ipad <roc0.GetNPads(irow); ipad++){
609 Float_t value = irow+ipad/1000.;
610 roc0.SetValue(irow,ipad,value);
614 // copy CalROC, readout values and compare to original
615 AliTPCCalROC roc1(roc0);
616 for (UInt_t irow = 0; irow <roc1.GetNrows(); irow++){
617 for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
618 Float_t value = irow+ipad/1000.;
619 if (roc1.GetValue(irow,ipad)!=value){
620 printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);
625 // write original CalROC to file
626 TFile f("calcTest.root","recreate");
628 AliTPCCalROC * roc2 = (AliTPCCalROC*)f.Get("Roc0");
631 // read CalROC from file and compare to original CalROC
632 for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
633 if (roc0.GetNPads(irow)!=roc2->GetNPads(irow))
634 printf("NPads - Read/Write error\trow=%d\n",irow);
635 for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
636 Float_t value = irow+ipad/1000.;
637 if (roc2->GetValue(irow,ipad)!=value){
638 printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);
648 AliTPCCalROC roc3(roc0);
650 for (UInt_t irow = 0; irow <roc3.GetNrows(); irow++){
651 for (UInt_t ipad = 0; ipad <roc3.GetNPads(irow); ipad++){
652 Float_t value = irow+ipad/1000. + 1.5;
653 if (TMath::Abs(roc3.GetValue(irow,ipad)-value) > kEpsilon){
654 printf("Add constant - error\trow=%d\tpad=%d\n",irow,ipad);
659 // Add another CalROC
660 AliTPCCalROC roc4(roc0);
661 roc4.Add(&roc0, -1.5);
662 for (UInt_t irow = 0; irow <roc4.GetNrows(); irow++){
663 for (UInt_t ipad = 0; ipad <roc4.GetNPads(irow); ipad++){
664 Float_t value = irow+ipad/1000. - 1.5 * (irow+ipad/1000.);
665 if (TMath::Abs(roc4.GetValue(irow,ipad)-value) > kEpsilon){
666 printf("Add CalROC - error\trow=%d\tpad=%d\n",irow,ipad);
671 // Multiply with constant
672 AliTPCCalROC roc5(roc0);
674 for (UInt_t irow = 0; irow <roc5.GetNrows(); irow++){
675 for (UInt_t ipad = 0; ipad <roc5.GetNPads(irow); ipad++){
676 Float_t value = (irow+ipad/1000.) * (-1.4);
677 if (TMath::Abs(roc5.GetValue(irow,ipad)-value) > kEpsilon){
678 printf("Multiply with constant - error\trow=%d\tpad=%d\n",irow,ipad);
683 // Multiply another CalROC
684 AliTPCCalROC roc6(roc0);
685 roc6.Multiply(&roc0);
686 for (UInt_t irow = 0; irow <roc6.GetNrows(); irow++){
687 for (UInt_t ipad = 0; ipad <roc6.GetNPads(irow); ipad++){
688 Float_t value = (irow+ipad/1000.) * (irow+ipad/1000.);
689 if (TMath::Abs(roc6.GetValue(irow,ipad)-value) > kEpsilon*100){
690 printf("Multiply with CalROC - error\trow=%d\tpad=%d\n",irow,ipad);
697 AliTPCCalROC roc7(roc0);
699 for (UInt_t irow = 0; irow <roc7.GetNrows(); irow++){
700 for (UInt_t ipad = 0; ipad <roc7.GetNPads(irow); ipad++){
702 if (irow+ipad == 0) value = roc0.GetValue(irow,ipad);
703 if (TMath::Abs(roc7.GetValue(irow,ipad)-value) > kEpsilon){
704 printf("Multiply with CalROC - error\trow=%d\tpad=%d\n",irow,ipad);
713 // create CalROC with defined values
715 AliTPCCalROC sroc0(0);
716 for (UInt_t ichannel = 0; ichannel < sroc0.GetNchannels(); ichannel++){
717 Float_t value = rnd.Gaus(10., 2.);
718 sroc0.SetValue(ichannel,value);
721 printf("Mean (should be close to 10): %f\n", sroc0.GetMean());
722 printf("RMS (should be close to 2): %f\n", sroc0.GetRMS());
723 printf("Median (should be close to 10): %f\n", sroc0.GetMedian());
724 printf("LTM (should be close to 10): %f\n", sroc0.GetLTM());
726 //AliTPCCalROC* sroc1 = sroc0.LocalFit(4, 8);
730 // std::cout << TMath::Abs(roc5.GetValue(irow,ipad)-value) << std::endl;
734 AliTPCCalROC * AliTPCCalROC::LocalFit(Int_t rowRadius, Int_t padRadius, AliTPCCalROC* ROCoutliers, Bool_t robust, Double_t chi2Threshold, Double_t robustFraction) {
736 // MakeLocalFit - smoothing
737 // returns a AliTPCCalROC with smoothed data
738 // rowRadius and padRadius specifies a window around a given pad.
739 // The data of this window are fitted with a parabolic function.
740 // This function is evaluated at the pad's position.
741 // At the edges the window is shifted, so that the specified pad is not anymore in the center of the window.
742 // rowRadius - radius - rows to be used for smoothing
743 // padradius - radius - pads to be used for smoothing
744 // ROCoutlier - map of outliers - pads not to be used for local smoothing
745 // robust - robust method of fitting - (much slower)
746 // chi2Threshold: Threshold for chi2 when EvalRobust is called
747 // robustFraction: Fraction of data that will be used in EvalRobust
749 AliTPCCalROC * xROCfitted = new AliTPCCalROC(fSector);
750 TLinearFitter fitterQ(6,"hyp5");
751 // TLinearFitter fitterQ(6,"x0++x1++x2++x3++x4++x5");
752 fitterQ.StoreData(kTRUE);
753 for (UInt_t row=0; row < GetNrows(); row++) {
754 //std::cout << "Entering row " << row << " of " << GetNrows() << " @ sector "<< fSector << " for local fitting... "<< std::endl;
755 for (UInt_t pad=0; pad < GetNPads(row); pad++)
756 xROCfitted->SetValue(row, pad, GetNeighbourhoodValue(&fitterQ, row, pad, rowRadius, padRadius, ROCoutliers, robust, chi2Threshold, robustFraction));
762 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) {
764 // AliTPCCalROC::GetNeighbourhoodValue - smoothing - PRIVATE
765 // in this function the fit for LocalFit is done
768 fitterQ->ClearPoints();
769 TVectorD fitParam(6);
773 Float_t lPad[3] = {0};
774 Float_t localXY[3] = {0};
776 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
777 tpcROCinstance->GetPositionLocal(fSector, row, pad, lPad); // calculate position lPad by pad and row number
779 TArrayI *neighbourhoodRows = 0;
780 TArrayI *neighbourhoodPads = 0;
782 //std::cerr << "Trying to get neighbourhood for row " << row << ", pad " << pad << std::endl;
783 GetNeighbourhood(neighbourhoodRows, neighbourhoodPads, row, pad, rRadius, pRadius);
784 //std::cerr << "Got neighbourhood for row " << row << ", pad " << pad << std::endl;
787 for (Int_t i=0; i < (2*rRadius+1)*(2*pRadius+1); i++) {
788 r = neighbourhoodRows->At(i);
789 p = neighbourhoodPads->At(i);
790 if (r == -1 || p == -1) continue; // window is bigger than ROC
791 tpcROCinstance->GetPositionLocal(fSector, r, p, localXY); // calculate position localXY by pad and row number
792 dlx = lPad[0] - localXY[0];
793 dly = lPad[1] - localXY[1];
800 if (!ROCoutliers || ROCoutliers->GetValue(r,p) != 1) {
801 fitterQ->AddPoint(&xx[1], GetValue(r, p), 1);
806 delete neighbourhoodRows;
807 delete neighbourhoodPads;
809 if (npoints < 0.5 * ((2*rRadius+1)*(2*pRadius+1)) ) {
810 // std::cerr << "Too few data points for fitting @ row " << row << ", pad " << pad << " in sector " << fSector << std::endl;
811 return 0.; // for diagnostic
814 fitterQ->GetParameters(fitParam);
816 if (robust) chi2Q = fitterQ->GetChisquare()/(npoints-6.);
817 //if (robust) chi2Q = fitterQ->GetChisquare()/(npoints-6.);
818 if (robust && chi2Q > chi2Threshold) {
819 //std::cout << "robust fitter called... " << std::endl;
820 fitterQ->EvalRobust(robustFraction);
821 fitterQ->GetParameters(fitParam);
823 Double_t value = fitParam[0];
825 //if (value < 0) std::cerr << "negative fit-value " << value << " in sector "<< this->fSector << " @ row: " << row << " and pad: " << pad << ", with fitter Chi2 = " << chi2Q << std::endl;
832 void AliTPCCalROC::GetNeighbourhood(TArrayI* &rowArray, TArrayI* &padArray, Int_t row, Int_t pad, Int_t rRadius, Int_t pRadius) {
834 // AliTPCCalROC::GetNeighbourhood - PRIVATE
835 // in this function the window for LocalFit is determined
837 rowArray = new TArrayI((2*rRadius+1)*(2*pRadius+1));
838 padArray = new TArrayI((2*rRadius+1)*(2*pRadius+1));
840 Int_t rmin = row - rRadius;
841 UInt_t rmax = row + rRadius;
843 // if window goes out of ROC
848 if (rmax >= GetNrows()) {
849 rmin = rmin - (rmax - GetNrows()+1);
850 rmax = GetNrows() - 1;
851 if (rmin < 0 ) rmin = 0; // if the window is bigger than the ROC
857 for (UInt_t r = rmin; r <= rmax; r++) {
858 pmin = pad - pRadius;
859 pmax = pad + pRadius;
864 if (pmax >= (Int_t)GetNPads(r)) {
865 pmin = pmin - (pmax - GetNPads(r)+1);
866 pmax = GetNPads(r) - 1;
867 if (pmin < 0 ) pmin = 0; // if the window is bigger than the ROC
869 for (Int_t p = pmin; p <= pmax; p++) {
875 for (Int_t j = i; j < rowArray->GetSize(); j++){ // unused padArray-entries, in the case that the window is bigger than the ROC
876 //std::cout << "trying to write -1" << std::endl;
879 //std::cout << "writing -1" << std::endl;
885 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){
887 // Makes a GlobalFit for the given secotr and return fit-parameters, covariance and chi2
888 // The origin of the fit function is the center of the ROC!
889 // fitType == 0: fit plane function
890 // fitType == 1: fit parabolic function
891 // ROCoutliers - pads with value !=0 are not used in fitting procedure
892 // chi2Threshold: Threshold for chi2 when EvalRobust is called
893 // robustFraction: Fraction of data that will be used in EvalRobust
894 // err: error of the data points
896 TLinearFitter* fitterG = 0;
900 fitterG = new TLinearFitter (6,"x0++x1++x2++x3++x4++x5");
901 fitParam.ResizeTo(6);
902 covMatrix.ResizeTo(6,6);
904 fitterG = new TLinearFitter(3,"x0++x1++x2");
905 fitParam.ResizeTo(3);
906 covMatrix.ResizeTo(3,3);
908 fitterG->StoreData(kTRUE);
909 fitterG->ClearPoints();
913 Float_t centerPad[3] = {0};
914 Float_t localXY[3] = {0};
916 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
917 tpcROCinstance->GetPositionLocal(fSector, GetNrows()/2, GetNPads(GetNrows()/2)/2, centerPad); // calculate center of ROC
919 // loop over all channels and read data into fitterG
920 for (UInt_t irow = 0; irow < GetNrows(); irow++) {
921 for (UInt_t ipad = 0; ipad < GetNPads(irow); ipad++) {
923 if (ROCoutliers && ROCoutliers->GetValue(irow, ipad) != 0) continue;
924 tpcROCinstance->GetPositionLocal(fSector, irow, ipad, localXY); // calculate position localXY by pad and row number
925 dlx = localXY[0] - centerPad[0];
926 dly = localXY[1] - centerPad[1];
934 fitterG->AddPoint(xx, GetValue(irow, ipad), err);
937 if(npoints>10) { // make sure there is something to fit
939 fitterG->GetParameters(fitParam);
940 fitterG->GetCovarianceMatrix(covMatrix);
942 chi2 = fitterG->GetChisquare()/(npoints-6.);
943 else chi2 = fitterG->GetChisquare()/(npoints-3.);
944 if (robust && chi2 > chi2Threshold) {
945 // std::cout << "robust fitter called... " << std::endl;
946 fitterG->EvalRobust(robustFraction);
947 fitterG->GetParameters(fitParam);
950 // set parameteres to 0
951 Int_t nParameters = 3;
955 for(Int_t i = 0; i < nParameters; i++)
963 AliTPCCalROC* AliTPCCalROC::CreateGlobalFitCalROC(TVectorD &fitParam, Int_t sector){
965 // Create ROC with global fit parameters
966 // The origin of the fit function is the center of the ROC!
967 // loop over all channels, write fit values into new ROC and return it
970 Float_t centerPad[3] = {0};
971 Float_t localXY[3] = {0};
972 AliTPCCalROC * xROCfitted = new AliTPCCalROC(sector);
973 AliTPCROC* tpcROCinstance = AliTPCROC::Instance();
974 tpcROCinstance->GetPositionLocal(sector, xROCfitted->GetNrows()/2, xROCfitted->GetNPads(xROCfitted->GetNrows()/2)/2, centerPad); // calculate center of ROC
976 if (fitParam.GetNoElements() == 6) fitType = 1;
979 if (fitType == 1) { // parabolic fit
980 for (UInt_t irow = 0; irow < xROCfitted->GetNrows(); irow++) {
981 for (UInt_t ipad = 0; ipad < xROCfitted->GetNPads(irow); ipad++) {
982 tpcROCinstance->GetPositionLocal(sector, irow, ipad, localXY); // calculate position localXY by pad and row number
983 dlx = localXY[0] - centerPad[0];
984 dly = localXY[1] - centerPad[1];
985 value = fitParam[0] + fitParam[1]*dlx + fitParam[2]*dly + fitParam[3]*dlx*dlx + fitParam[4]*dly*dly + fitParam[5]*dlx*dly;
986 xROCfitted->SetValue(irow, ipad, value);
991 for (UInt_t irow = 0; irow < xROCfitted->GetNrows(); irow++) {
992 for (UInt_t ipad = 0; ipad < xROCfitted->GetNPads(irow); ipad++) {
993 tpcROCinstance->GetPositionLocal(sector, irow, ipad, localXY); // calculate position localXY by pad and row number
994 dlx = localXY[0] - centerPad[0];
995 dly = localXY[1] - centerPad[1];
996 value = fitParam[0] + fitParam[1]*dlx + fitParam[2]*dly;
997 xROCfitted->SetValue(irow, ipad, value);