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 ///////////////////////////////////////////////////////////////////////////////
25 #include "AliTPCCalROC.h"
31 #include "AliMathBase.h"
32 ClassImp(AliTPCCalROC)
35 //_____________________________________________________________________________
36 AliTPCCalROC::AliTPCCalROC()
45 // Default constructor
50 //_____________________________________________________________________________
51 AliTPCCalROC::AliTPCCalROC(UInt_t sector)
60 // Constructor that initializes a given sector
63 fNChannels = AliTPCROC::Instance()->GetNChannels(fSector);
64 fNRows = AliTPCROC::Instance()->GetNRows(fSector);
65 fIndexes = AliTPCROC::Instance()->GetRowIndexes(fSector);
66 fData = new Float_t[fNChannels];
67 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata] = 0.;
70 //_____________________________________________________________________________
71 AliTPCCalROC::AliTPCCalROC(const AliTPCCalROC &c)
80 // AliTPCCalROC copy constructor
83 fNChannels = AliTPCROC::Instance()->GetNChannels(fSector);
84 fNRows = AliTPCROC::Instance()->GetNRows(fSector);
85 fIndexes = AliTPCROC::Instance()->GetRowIndexes(fSector);
87 fData = new Float_t[fNChannels];
88 for (UInt_t idata = 0; idata< fNChannels; idata++) fData[idata] = c.fData[idata];
90 //____________________________________________________________________________
91 AliTPCCalROC & AliTPCCalROC::operator =(const AliTPCCalROC & param)
94 // assignment operator - dummy
101 //_____________________________________________________________________________
102 AliTPCCalROC::~AliTPCCalROC()
105 // AliTPCCalROC destructor
115 void AliTPCCalROC::Streamer(TBuffer &R__b)
117 // Stream an object of class AliTPCCalROC.
118 if (R__b.IsReading()) {
119 AliTPCCalROC::Class()->ReadBuffer(R__b, this);
120 fIndexes = AliTPCROC::Instance()->GetRowIndexes(fSector);
122 AliTPCCalROC::Class()->WriteBuffer(R__b,this);
127 Double_t AliTPCCalROC::GetLTM(Double_t *sigma, Double_t fraction){
129 // Calculate LTM mean and sigma
131 Double_t *ddata = new Double_t[fNChannels];
132 Double_t mean=0, lsigma=0;
133 Int_t hh = TMath::Min(TMath::Nint(fraction *fNChannels), Int_t(fNChannels));
134 for (UInt_t i=0;i<fNChannels;i++) ddata[i]= fData[i];
135 AliMathBase::EvaluateUni(UInt_t(fNChannels),ddata, mean, lsigma, hh);
136 if (sigma) *sigma=lsigma;
141 TH1F * AliTPCCalROC::MakeHisto1D(Float_t min, Float_t max,Int_t type){
144 // type -1 = user defined range
145 // 0 = nsigma cut nsigma=min
146 // 1 = delta cut around median delta=min
150 Float_t mean = GetMean();
151 Float_t sigma = GetRMS();
152 Float_t nsigma = TMath::Abs(min);
153 min = mean-nsigma*sigma;
154 max = mean+nsigma*sigma;
158 Float_t mean = GetMedian();
165 // LTM mean +- nsigma
168 Float_t mean = GetLTM(&sigma,max);
175 sprintf(name,"%s ROC 1D%d",GetTitle(),fSector);
176 TH1F * his = new TH1F(name,name,100, min,max);
177 for (UInt_t irow=0; irow<fNRows; irow++){
178 UInt_t npads = (Int_t)GetNPads(irow);
179 for (UInt_t ipad=0; ipad<=npads; ipad++){
180 his->Fill(GetValue(irow,ipad));
188 TH2F * AliTPCCalROC::MakeHisto2D(Float_t min, Float_t max,Int_t type){
191 // type -1 = user defined range
192 // 0 = nsigma cut nsigma=min
193 // 1 = delta cut around median delta=min
197 Float_t mean = GetMean();
198 Float_t sigma = GetRMS();
199 Float_t nsigma = TMath::Abs(min);
200 min = mean-nsigma*sigma;
201 max = mean+nsigma*sigma;
205 Float_t mean = GetMedian();
212 Float_t mean = GetLTM(&sigma,max);
220 for (UInt_t irow=0; irow<fNRows; irow++){
221 if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
224 sprintf(name,"%s ROC%d",GetTitle(),fSector);
225 TH2F * his = new TH2F(name,name,fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
226 for (UInt_t irow=0; irow<fNRows; irow++){
227 UInt_t npads = (Int_t)GetNPads(irow);
228 for (UInt_t ipad=0; ipad<=npads; ipad++){
229 his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,GetValue(irow,ipad));
232 his->SetMaximum(max);
233 his->SetMinimum(min);
237 TH2F * AliTPCCalROC::MakeHistoOutliers(Float_t delta, Float_t fraction, Int_t type){
239 // Make Histogram with outliers
240 // mode = 0 - sigma cut used
241 // mode = 1 - absolute cut used
242 // fraction - fraction of values used to define sigma
243 // delta - in mode 0 - nsigma cut
244 // mode 1 - delta cut
246 Float_t mean = GetLTM(&sigma,fraction);
247 if (type==0) delta*=sigma;
249 for (UInt_t irow=0; irow<fNRows; irow++){
250 if (GetNPads(irow)>maxPad) maxPad = GetNPads(irow);
254 sprintf(name,"%s ROC Outliers%d",GetTitle(),fSector);
255 TH2F * his = new TH2F(name,name,fNRows+10,-5, fNRows+5, maxPad+10, -(Int_t(maxPad/2))-5, maxPad/2+5);
256 for (UInt_t irow=0; irow<fNRows; irow++){
257 UInt_t npads = (Int_t)GetNPads(irow);
258 for (UInt_t ipad=0; ipad<=npads; ipad++){
259 if (TMath::Abs(GetValue(irow,ipad)-mean)>delta)
260 his->Fill(irow+0.5,Int_t(ipad)-Int_t(npads/2)+0.5,1);
268 void AliTPCCalROC::Draw(Option_t* opt){
270 // create histogram with values and draw it
275 if (option.Contains("1D")){
288 void AliTPCCalROC::Test(){
290 // example function to show functionality and tes AliTPCCalROC
292 AliTPCCalROC roc0(0);
293 for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
294 for (UInt_t ipad = 0; ipad <roc0.GetNPads(irow); ipad++){
295 Float_t value = irow+ipad/1000.;
296 roc0.SetValue(irow,ipad,value);
300 AliTPCCalROC roc1(roc0);
301 for (UInt_t irow = 0; irow <roc1.GetNrows(); irow++){
302 for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
303 Float_t value = irow+ipad/1000.;
304 if (roc1.GetValue(irow,ipad)!=value){
305 printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);
309 TFile f("calcTest.root","recreate");
311 AliTPCCalROC * roc2 = (AliTPCCalROC*)f.Get("Roc0");
314 for (UInt_t irow = 0; irow <roc0.GetNrows(); irow++){
315 if (roc0.GetNPads(irow)!=roc2->GetNPads(irow))
316 printf("NPads - Read/Write error\trow=%d\n",irow);
317 for (UInt_t ipad = 0; ipad <roc1.GetNPads(irow); ipad++){
318 Float_t value = irow+ipad/1000.;
319 if (roc2->GetValue(irow,ipad)!=value){
320 printf("Read/Write error\trow=%d\tpad=%d\n",irow,ipad);