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>
41 #include "AliTRDCalibraVdriftLinearFit.h"
43 ClassImp(AliTRDCalibraVdriftLinearFit) /*FOLD00*/
45 //_____________________________________________________________________
46 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit() : /*FOLD00*/
49 fLinearFitterHistoArray(540),
50 fLinearFitterPArray(540),
51 fLinearFitterEArray(540)
54 // default constructor
57 //_____________________________________________________________________
58 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit(const AliTRDCalibraVdriftLinearFit &ped) : /*FOLD00*/
60 fVersion(ped.fVersion),
61 fLinearFitterHistoArray(540),
62 fLinearFitterPArray(540),
63 fLinearFitterEArray(540)
68 for (Int_t idet = 0; idet < 540; idet++){
70 const TVectorD *vectorE = (TVectorD*)ped.fLinearFitterEArray.UncheckedAt(idet);
71 const TVectorD *vectorP = (TVectorD*)ped.fLinearFitterPArray.UncheckedAt(idet);
72 const TH2S *hped = (TH2S*)ped.fLinearFitterHistoArray.UncheckedAt(idet);
74 if ( vectorE != 0x0 ) fLinearFitterEArray.AddAt(new TVectorD(*vectorE), idet);
75 if ( vectorP != 0x0 ) fLinearFitterPArray.AddAt(new TVectorD(*vectorP), idet);
77 TH2S *hNew = (TH2S *)hped->Clone();
78 //hNew->SetDirectory(0);
79 fLinearFitterHistoArray.AddAt(hNew,idet);
83 //_____________________________________________________________________
84 AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit(const TObjArray &obja) : /*FOLD00*/
87 fLinearFitterHistoArray(540),
88 fLinearFitterPArray(540),
89 fLinearFitterEArray(540)
92 // constructor from a TObjArray
94 for (Int_t idet = 0; idet < 540; idet++){
95 const TH2S *hped = (TH2S*)obja.UncheckedAt(idet);
97 TH2S *hNew = (TH2S *)hped->Clone();
98 //hNew->SetDirectory(0);
99 fLinearFitterHistoArray.AddAt(hNew,idet);
103 //_____________________________________________________________________
104 AliTRDCalibraVdriftLinearFit& AliTRDCalibraVdriftLinearFit::operator = (const AliTRDCalibraVdriftLinearFit &source)
107 // assignment operator
109 if (&source == this) return *this;
110 new (this) AliTRDCalibraVdriftLinearFit(source);
114 //_____________________________________________________________________
115 AliTRDCalibraVdriftLinearFit::~AliTRDCalibraVdriftLinearFit() /*FOLD00*/
120 fLinearFitterHistoArray.SetOwner();
121 fLinearFitterPArray.SetOwner();
122 fLinearFitterEArray.SetOwner();
124 fLinearFitterHistoArray.Delete();
125 fLinearFitterPArray.Delete();
126 fLinearFitterEArray.Delete();
129 //_____________________________________________________________________________
130 void AliTRDCalibraVdriftLinearFit::Copy(TObject &c) const
136 AliTRDCalibraVdriftLinearFit& target = (AliTRDCalibraVdriftLinearFit &) c;
138 // Copy only the histos
139 for (Int_t idet = 0; idet < 540; idet++){
140 if(fLinearFitterHistoArray.UncheckedAt(idet)){
141 TH2S *hped1 = (TH2S *)target.GetLinearFitterHisto(idet,kTRUE);
142 //hped1->SetDirectory(0);
143 hped1->Add((const TH2S *)fLinearFitterHistoArray.UncheckedAt(idet));
150 //_____________________________________________________________________________
151 Long64_t AliTRDCalibraVdriftLinearFit::Merge(const TCollection* list)
153 // Merge list of objects (needed by PROOF)
161 TIterator* iter = list->MakeIterator();
164 // collection of generated histograms
166 while((obj = iter->Next()) != 0)
168 AliTRDCalibraVdriftLinearFit* entry = dynamic_cast<AliTRDCalibraVdriftLinearFit*>(obj);
169 if (entry == 0) continue;
171 // Copy only the histos
172 for (Int_t idet = 0; idet < 540; idet++){
173 if(entry->GetLinearFitterHisto(idet)){
174 TH2S *hped1 = (TH2S *)GetLinearFitterHisto(idet,kTRUE);
175 Double_t entriesa = hped1->GetEntries();
176 Double_t entriesb = ((TH2S *)entry->GetLinearFitterHisto(idet))->GetEntries();
177 if((entriesa + entriesb) < 5*32767) hped1->Add(entry->GetLinearFitterHisto(idet));
186 //_____________________________________________________________________
187 void AliTRDCalibraVdriftLinearFit::Add(const AliTRDCalibraVdriftLinearFit *ped)
195 for (Int_t idet = 0; idet < 540; idet++){
196 const TH2S *hped = (TH2S*)ped->GetLinearFitterHistoNoForce(idet);
197 //printf("idet %d\n",idet);
200 TH2S *hped1 = (TH2S *)GetLinearFitterHisto(idet,kTRUE);
201 Double_t entriesa = hped1->GetEntries();
202 Double_t entriesb = hped->GetEntries();
203 if((entriesa + entriesb) < 5*32767) hped1->Add(hped);
207 //______________________________________________________________________________________
208 TH2S* AliTRDCalibraVdriftLinearFit::GetLinearFitterHisto(Int_t detector, Bool_t force)
211 // return pointer to TH2F histo
212 // if force is true create a new histo if it doesn't exist allready
214 if ( !force || fLinearFitterHistoArray.UncheckedAt(detector) )
215 return (TH2S*)fLinearFitterHistoArray.UncheckedAt(detector);
217 return GetLinearFitterHistoForce(detector);
220 //______________________________________________________________________________________
221 TH2S* AliTRDCalibraVdriftLinearFit::GetLinearFitterHistoForce(Int_t detector)
224 // return pointer to TH2F histo
225 // if NULL create a new histo if it doesn't exist allready
227 if (fLinearFitterHistoArray.UncheckedAt(detector))
228 return (TH2S*)fLinearFitterHistoArray.UncheckedAt(detector);
230 // if we are forced and TLinearFitter doesn't yes exist create it
233 TString name("LFDV");
238 TH2S *lfdv = new TH2S((const Char_t *)name,(const Char_t *) name
241 lfdv->SetXTitle("tan(phi_{track})");
242 lfdv->SetYTitle("dy/dt");
243 lfdv->SetZTitle("Number of clusters");
245 lfdv->SetDirectory(0);
247 fLinearFitterHistoArray.AddAt(lfdv,detector);
250 //______________________________________________________________________________________
251 Bool_t AliTRDCalibraVdriftLinearFit::GetParam(Int_t detector, TVectorD *param)
254 // return param for this detector
256 if ( fLinearFitterPArray.UncheckedAt(detector) ){
257 const TVectorD *vectorP = (TVectorD*)fLinearFitterPArray.UncheckedAt(detector);
258 if(!param) param = new TVectorD(2);
259 for(Int_t k = 0; k < 2; k++){
260 (*param)[k] = (*vectorP)[k];
267 //______________________________________________________________________________________
268 Bool_t AliTRDCalibraVdriftLinearFit::GetError(Int_t detector, TVectorD *error)
271 // return error for this detector
273 if ( fLinearFitterEArray.UncheckedAt(detector) ){
274 const TVectorD *vectorE = (TVectorD*)fLinearFitterEArray.UncheckedAt(detector);
275 if(!error) error = new TVectorD(3);
276 for(Int_t k = 0; k < 3; k++){
277 (*error)[k] = (*vectorE)[k];
284 //______________________________________________________________________________________
285 void AliTRDCalibraVdriftLinearFit::Update(Int_t detector, Float_t tnp, Float_t pars1)
288 // Fill the 2D histos for debugging
291 TH2S *h = ((TH2S *) GetLinearFitterHisto(detector,kTRUE));
292 Double_t nbentries = h->GetEntries();
293 if(nbentries < 5*32767) h->Fill(tnp,pars1);
296 //____________Functions fit Online CH2d________________________________________
297 void AliTRDCalibraVdriftLinearFit::FillPEArray()
300 // Fill fLinearFitterPArray and fLinearFitterEArray from inside
304 Int_t *arrayI = new Int_t[540];
305 for(Int_t k = 0; k< 540; k++){
310 for(Int_t cb = 0; cb < 540; cb++){
311 const TH2S *linearfitterhisto = (TH2S*)fLinearFitterHistoArray.UncheckedAt(cb);
312 //printf("Processing the detector cb %d we find %d\n",cb, (Bool_t) linearfitterhisto);
314 if ( linearfitterhisto != 0 ){
316 // Fill a linearfitter
317 TAxis *xaxis = linearfitterhisto->GetXaxis();
318 TAxis *yaxis = linearfitterhisto->GetYaxis();
319 TLinearFitter linearfitter = TLinearFitter(2,"pol1");
321 for(Int_t ibinx = 0; ibinx < linearfitterhisto->GetNbinsX(); ibinx++){
322 for(Int_t ibiny = 0; ibiny < linearfitterhisto->GetNbinsY(); ibiny++){
323 if(linearfitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){
324 Double_t x = xaxis->GetBinCenter(ibinx+1);
325 Double_t y = yaxis->GetBinCenter(ibiny+1);
326 for(Int_t k = 0; k < (Int_t)linearfitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){
327 linearfitter.AddPoint(&x,y);
334 //printf("Find %d entries for the detector %d\n",arrayI[cb],cb);
336 // Eval the linear fitter
338 TVectorD *par = new TVectorD(2);
339 TVectorD pare = TVectorD(2);
340 TVectorD *parE = new TVectorD(3);
342 linearfitter.GetParameters(*par);
343 linearfitter.GetErrors(pare);
344 Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter.GetChisquare())/arrayI[cb]);
345 (*parE)[0] = pare[0]*ppointError;
346 (*parE)[1] = pare[1]*ppointError;
347 (*parE)[2] = (Double_t) arrayI[cb];
348 fLinearFitterPArray.AddAt(par,cb);
349 fLinearFitterEArray.AddAt(parE,cb);
354 //delete linearfitterhisto;