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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // AliTRDCalibraVdriftLinearFit //
22 // Does the Vdrift an ExB calibration by applying a linear fit //
25 // R. Bailhache (R.Bailhache@gsi.de) //
27 ////////////////////////////////////////////////////////////////////////////
30 #include <TObjArray.h>
35 #include <TLinearFitter.h>
37 #include <TTreeStream.h>
40 #include "AliTRDCalibraVdriftLinearFit.h"
42 ClassImp(AliTRDCalibraVdriftLinearFit) /*FOLD00*/
44 //_____________________________________________________________________
45 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit() : /*FOLD00*/
48 fLinearFitterHistoArray(540),
49 fLinearFitterPArray(540),
50 fLinearFitterEArray(540)
53 // default constructor
56 //_____________________________________________________________________
57 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit(const AliTRDCalibraVdriftLinearFit &ped) : /*FOLD00*/
59 fVersion(ped.fVersion),
60 fLinearFitterHistoArray(540),
61 fLinearFitterPArray(540),
62 fLinearFitterEArray(540)
67 for (Int_t idet = 0; idet < 540; idet++){
68 const TVectorD *vectorE = (TVectorD*)ped.fLinearFitterEArray.UncheckedAt(idet);
69 const TVectorD *vectorP = (TVectorD*)ped.fLinearFitterPArray.UncheckedAt(idet);
70 const TH2F *hped = (TH2F*)ped.fLinearFitterHistoArray.UncheckedAt(idet);
72 if ( vectorE != 0x0 ) fLinearFitterEArray.AddAt(new TVectorD(*vectorE), idet);
73 if ( vectorP != 0x0 ) fLinearFitterPArray.AddAt(new TVectorD(*vectorP), idet);
75 TH2F *hNew = new TH2F(*hped);
76 hNew->SetDirectory(0);
77 fLinearFitterHistoArray.AddAt(hNew,idet);
82 //_____________________________________________________________________
83 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit(const TObjArray &obja) : /*FOLD00*/
86 fLinearFitterHistoArray(540),
87 fLinearFitterPArray(540),
88 fLinearFitterEArray(540)
91 // constructor from a TObjArray
93 for (Int_t idet = 0; idet < 540; idet++){
94 const TH2F *hped = (TH2F*)obja.UncheckedAt(idet);
96 TH2F *hNew = new TH2F(*hped);
97 hNew->SetDirectory(0);
98 fLinearFitterHistoArray.AddAt(hNew,idet);
102 //_____________________________________________________________________
103 AliTRDCalibraVdriftLinearFit& AliTRDCalibraVdriftLinearFit::operator = (const AliTRDCalibraVdriftLinearFit &source)
106 // assignment operator
108 if (&source == this) return *this;
109 new (this) AliTRDCalibraVdriftLinearFit(source);
113 //_____________________________________________________________________
114 AliTRDCalibraVdriftLinearFit::~AliTRDCalibraVdriftLinearFit() /*FOLD00*/
119 fLinearFitterHistoArray.Delete();
120 fLinearFitterPArray.Delete();
121 fLinearFitterEArray.Delete();
124 //_____________________________________________________________________________
125 void AliTRDCalibraVdriftLinearFit::Copy(TObject &c) const
131 AliTRDCalibraVdriftLinearFit& target = (AliTRDCalibraVdriftLinearFit &) c;
133 // Copy only the histos
134 for (Int_t idet = 0; idet < 540; idet++){
135 if(fLinearFitterHistoArray.UncheckedAt(idet)){
136 TH2F *hped1 = target.GetLinearFitterHisto(idet,kTRUE);
137 hped1->SetDirectory(0);
138 hped1->Add((const TH1F *)fLinearFitterHistoArray.UncheckedAt(idet));
146 //_____________________________________________________________________________
147 Long64_t AliTRDCalibraVdriftLinearFit::Merge(TCollection* list)
149 // Merge list of objects (needed by PROOF)
157 TIterator* iter = list->MakeIterator();
160 // collection of generated histograms
162 while((obj = iter->Next()) != 0)
164 AliTRDCalibraVdriftLinearFit* entry = dynamic_cast<AliTRDCalibraVdriftLinearFit*>(obj);
165 if (entry == 0) continue;
167 // Copy only the histos
168 for (Int_t idet = 0; idet < 540; idet++){
169 if(entry->GetLinearFitterHisto(idet)){
170 TH2F *hped1 = GetLinearFitterHisto(idet,kTRUE);
171 hped1->SetDirectory(0);
172 hped1->Add(entry->GetLinearFitterHisto(idet));
182 //_____________________________________________________________________
183 void AliTRDCalibraVdriftLinearFit::Add(AliTRDCalibraVdriftLinearFit *ped)
191 for (Int_t idet = 0; idet < 540; idet++){
192 const TH2F *hped = (TH2F*)ped->GetLinearFitterHisto(idet);
193 //printf("idet %d\n",idet);
196 TH2F *hped1 = GetLinearFitterHisto(idet,kTRUE);
198 hped1->SetDirectory(0);
205 //______________________________________________________________________________________
206 TH2F* AliTRDCalibraVdriftLinearFit::GetLinearFitterHisto(Int_t detector, Bool_t force)
209 // return pointer to TH2F histo
210 // if force is true create a new histo if it doesn't exist allready
212 if ( !force || fLinearFitterHistoArray.UncheckedAt(detector) )
213 return (TH2F*)fLinearFitterHistoArray.UncheckedAt(detector);
215 // if we are forced and TLinearFitter doesn't yes exist create it
218 TString name("LFDV");
223 TH2F *lfdv = new TH2F((const Char_t *)name,(const Char_t *) name
226 lfdv->SetXTitle("tan(phi_{track})");
227 lfdv->SetYTitle("dy/dt");
228 lfdv->SetZTitle("Number of clusters");
230 lfdv->SetDirectory(0);
232 fLinearFitterHistoArray.AddAt(lfdv,detector);
235 //______________________________________________________________________________________
236 Bool_t AliTRDCalibraVdriftLinearFit::GetParam(Int_t detector, TVectorD *param)
239 // return param for this detector
241 if ( fLinearFitterPArray.UncheckedAt(detector) ){
242 const TVectorD *vectorP = (TVectorD*)fLinearFitterPArray.UncheckedAt(detector);
243 if(!param) param = new TVectorD(2);
244 for(Int_t k = 0; k < 2; k++){
245 (*param)[k] = (*vectorP)[k];
252 //______________________________________________________________________________________
253 Bool_t AliTRDCalibraVdriftLinearFit::GetError(Int_t detector, TVectorD *error)
256 // return error for this detector
258 if ( fLinearFitterEArray.UncheckedAt(detector) ){
259 const TVectorD *vectorE = (TVectorD*)fLinearFitterEArray.UncheckedAt(detector);
260 if(!error) error = new TVectorD(3);
261 for(Int_t k = 0; k < 3; k++){
262 (*error)[k] = (*vectorE)[k];
269 //______________________________________________________________________________________
270 void AliTRDCalibraVdriftLinearFit::Update(Int_t detector, Float_t tnp, Float_t pars1)
273 // Fill the 2D histos for debugging
276 ((TH2F *) GetLinearFitterHisto(detector,kTRUE))->Fill(tnp,pars1);
279 //____________Functions fit Online CH2d________________________________________
280 void AliTRDCalibraVdriftLinearFit::FillPEArray()
283 // Fill fLinearFitterPArray and fLinearFitterEArray from inside
287 Int_t *arrayI = new Int_t[540];
288 for(Int_t k = 0; k< 540; k++){
293 for(Int_t cb = 0; cb < 540; cb++){
294 const TH2F *linearfitterhisto = (TH2F*)fLinearFitterHistoArray.UncheckedAt(cb);
295 //printf("Processing the detector cb %d we find %d\n",cb, (Bool_t) linearfitterhisto);
297 if ( linearfitterhisto != 0 ){
299 // Fill a linearfitter
300 TAxis *xaxis = linearfitterhisto->GetXaxis();
301 TAxis *yaxis = linearfitterhisto->GetYaxis();
302 TLinearFitter linearfitter = TLinearFitter(2,"pol1");
304 for(Int_t ibinx = 0; ibinx < linearfitterhisto->GetNbinsX(); ibinx++){
305 for(Int_t ibiny = 0; ibiny < linearfitterhisto->GetNbinsY(); ibiny++){
306 if(linearfitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
307 Double_t x = xaxis->GetBinCenter(ibinx+1);
308 Double_t y = yaxis->GetBinCenter(ibiny+1);
309 for(Int_t k = 0; k < (Int_t)linearfitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
310 linearfitter.AddPoint(&x,y);
317 //printf("Find %d entries for the detector %d\n",arrayI[cb],cb);
319 // Eval the linear fitter
321 TVectorD *par = new TVectorD(2);
322 TVectorD pare = TVectorD(2);
323 TVectorD *parE = new TVectorD(3);
325 linearfitter.GetParameters(*par);
326 linearfitter.GetErrors(pare);
327 Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter.GetChisquare())/arrayI[cb]);
328 (*parE)[0] = pare[0]*ppointError;
329 (*parE)[1] = pare[1]*ppointError;
330 (*parE)[2] = (Double_t) arrayI[cb];
331 fLinearFitterPArray.AddAt(par,cb);
332 fLinearFitterEArray.AddAt(parE,cb);