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 **************************************************************************/
19 #include <TObjArray.h>
24 #include <TLinearFitter.h>
26 #include <TTreeStream.h>
29 #include "AliTRDCalibraVdriftLinearFit.h"
31 ClassImp(AliTRDCalibraVdriftLinearFit) /*FOLD00*/
33 //_____________________________________________________________________
34 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit() : /*FOLD00*/
37 fLinearFitterHistoArray(540),
38 fLinearFitterPArray(540),
39 fLinearFitterEArray(540)
42 // default constructor
45 //_____________________________________________________________________
46 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit(const AliTRDCalibraVdriftLinearFit &ped) : /*FOLD00*/
48 fVersion(ped.fVersion),
49 fLinearFitterHistoArray(540),
50 fLinearFitterPArray(540),
51 fLinearFitterEArray(540)
56 for (Int_t idet = 0; idet < 540; idet++){
57 const TVectorD *vectorE = (TVectorD*)ped.fLinearFitterEArray.UncheckedAt(idet);
58 const TVectorD *vectorP = (TVectorD*)ped.fLinearFitterPArray.UncheckedAt(idet);
59 const TH2F *hped = (TH2F*)ped.fLinearFitterHistoArray.UncheckedAt(idet);
61 if ( vectorE != 0x0 ) fLinearFitterEArray.AddAt(new TVectorD(*vectorE), idet);
62 if ( vectorP != 0x0 ) fLinearFitterPArray.AddAt(new TVectorD(*vectorP), idet);
64 TH2F *hNew = new TH2F(*hped);
65 hNew->SetDirectory(0);
66 fLinearFitterHistoArray.AddAt(hNew,idet);
71 //_____________________________________________________________________
72 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit(const TObjArray &obja) : /*FOLD00*/
75 fLinearFitterHistoArray(540),
76 fLinearFitterPArray(540),
77 fLinearFitterEArray(540)
80 // constructor from a TObjArray
82 for (Int_t idet = 0; idet < 540; idet++){
83 const TH2F *hped = (TH2F*)obja.UncheckedAt(idet);
85 TH2F *hNew = new TH2F(*hped);
86 hNew->SetDirectory(0);
87 fLinearFitterHistoArray.AddAt(hNew,idet);
91 //_____________________________________________________________________
92 AliTRDCalibraVdriftLinearFit& AliTRDCalibraVdriftLinearFit::operator = (const AliTRDCalibraVdriftLinearFit &source)
95 // assignment operator
97 if (&source == this) return *this;
98 new (this) AliTRDCalibraVdriftLinearFit(source);
102 //_____________________________________________________________________
103 AliTRDCalibraVdriftLinearFit::~AliTRDCalibraVdriftLinearFit() /*FOLD00*/
109 //_____________________________________________________________________
110 void AliTRDCalibraVdriftLinearFit::Add(AliTRDCalibraVdriftLinearFit *ped)
118 for (Int_t idet = 0; idet < 540; idet++){
119 const TH2F *hped = (TH2F*)ped->GetLinearFitterHisto(idet);
120 //printf("idet %d\n",idet);
123 TH2F *hped1 = GetLinearFitterHisto(idet,kTRUE);
125 hped1->SetDirectory(0);
132 //______________________________________________________________________________________
133 TH2F* AliTRDCalibraVdriftLinearFit::GetLinearFitterHisto(Int_t detector, Bool_t force)
136 // return pointer to TH2F histo
137 // if force is true create a new histo if it doesn't exist allready
139 if ( !force || fLinearFitterHistoArray.UncheckedAt(detector) )
140 return (TH2F*)fLinearFitterHistoArray.UncheckedAt(detector);
142 // if we are forced and TLinearFitter doesn't yes exist create it
145 TString name("LFDV");
150 TH2F *lfdv = new TH2F((const Char_t *)name,(const Char_t *) name
153 lfdv->SetXTitle("tan(phi_{track})");
154 lfdv->SetYTitle("dy/dt");
155 lfdv->SetZTitle("Number of clusters");
157 lfdv->SetDirectory(0);
159 fLinearFitterHistoArray.AddAt(lfdv,detector);
162 //______________________________________________________________________________________
163 Bool_t AliTRDCalibraVdriftLinearFit::GetParam(Int_t detector, TVectorD *param)
166 // return param for this detector
168 if ( fLinearFitterPArray.UncheckedAt(detector) ){
169 const TVectorD *vectorP = (TVectorD*)fLinearFitterPArray.UncheckedAt(detector);
170 if(!param) param = new TVectorD(2);
171 for(Int_t k = 0; k < 2; k++){
172 (*param)[k] = (*vectorP)[k];
179 //______________________________________________________________________________________
180 Bool_t AliTRDCalibraVdriftLinearFit::GetError(Int_t detector, TVectorD *error)
183 // return error for this detector
185 if ( fLinearFitterEArray.UncheckedAt(detector) ){
186 const TVectorD *vectorE = (TVectorD*)fLinearFitterEArray.UncheckedAt(detector);
187 if(!error) error = new TVectorD(3);
188 for(Int_t k = 0; k < 3; k++){
189 (*error)[k] = (*vectorE)[k];
196 //______________________________________________________________________________________
197 void AliTRDCalibraVdriftLinearFit::Update(Int_t detector, Float_t tnp, Float_t pars1)
200 // Fill the 2D histos for debugging
203 ((TH2F *) GetLinearFitterHisto(detector,kTRUE))->Fill(tnp,pars1);
206 //____________Functions fit Online CH2d________________________________________
207 void AliTRDCalibraVdriftLinearFit::FillPEArray()
210 // Fill fLinearFitterPArray and fLinearFitterEArray from inside
214 Int_t *arrayI = new Int_t[540];
215 for(Int_t k = 0; k< 540; k++){
220 for(Int_t cb = 0; cb < 540; cb++){
221 const TH2F *linearfitterhisto = (TH2F*)fLinearFitterHistoArray.UncheckedAt(cb);
222 //printf("Processing the detector cb %d we find %d\n",cb, (Bool_t) linearfitterhisto);
224 if ( linearfitterhisto != 0 ){
226 // Fill a linearfitter
227 TAxis *xaxis = linearfitterhisto->GetXaxis();
228 TAxis *yaxis = linearfitterhisto->GetYaxis();
229 TLinearFitter linearfitter = TLinearFitter(2,"pol1");
231 for(Int_t ibinx = 0; ibinx < linearfitterhisto->GetNbinsX(); ibinx++){
232 for(Int_t ibiny = 0; ibiny < linearfitterhisto->GetNbinsY(); ibiny++){
233 if(linearfitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
234 Double_t x = xaxis->GetBinCenter(ibinx+1);
235 Double_t y = yaxis->GetBinCenter(ibiny+1);
236 for(Int_t k = 0; k < (Int_t)linearfitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
237 linearfitter.AddPoint(&x,y);
244 //printf("Find %d entries for the detector %d\n",arrayI[cb],cb);
246 // Eval the linear fitter
248 TVectorD *par = new TVectorD(2);
249 TVectorD pare = TVectorD(2);
250 TVectorD *parE = new TVectorD(3);
252 linearfitter.GetParameters(*par);
253 linearfitter.GetErrors(pare);
254 Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter.GetChisquare())/arrayI[cb]);
255 (*parE)[0] = pare[0]*ppointError;
256 (*parE)[1] = pare[1]*ppointError;
257 (*parE)[2] = (Double_t) arrayI[cb];
258 fLinearFitterPArray.AddAt(par,cb);
259 fLinearFitterEArray.AddAt(parE,cb);