]>
Commit | Line | Data |
---|---|---|
3a0f6479 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | //Root includes | |
19 | #include <TObjArray.h> | |
20 | #include <TH2F.h> | |
21 | #include <TString.h> | |
22 | #include <TVectorD.h> | |
23 | #include <TAxis.h> | |
24 | #include <TLinearFitter.h> | |
25 | #include <TMath.h> | |
26 | #include <TTreeStream.h> | |
27 | ||
28 | //header file | |
29 | #include "AliTRDCalibraVdriftLinearFit.h" | |
30 | ||
31 | ClassImp(AliTRDCalibraVdriftLinearFit) /*FOLD00*/ | |
32 | ||
33 | //_____________________________________________________________________ | |
34 | AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit() : /*FOLD00*/ | |
35 | TObject(), | |
36 | fVersion(0), | |
37 | fLinearFitterHistoArray(540), | |
38 | fLinearFitterPArray(540), | |
39 | fLinearFitterEArray(540) | |
40 | { | |
41 | // | |
42 | // default constructor | |
43 | // | |
44 | } | |
45 | ||
46 | //_____________________________________________________________________ | |
47 | AliTRDCalibraVdriftLinearFit::AliTRDCalibraVdriftLinearFit(const AliTRDCalibraVdriftLinearFit &ped) : /*FOLD00*/ | |
48 | TObject(ped), | |
49 | fVersion(ped.fVersion), | |
50 | fLinearFitterHistoArray(540), | |
51 | fLinearFitterPArray(540), | |
52 | fLinearFitterEArray(540) | |
53 | { | |
54 | // | |
55 | // copy constructor | |
56 | // | |
57 | for (Int_t idet = 0; idet < 540; idet++){ | |
58 | const TVectorD *vectorE = (TVectorD*)ped.fLinearFitterEArray.UncheckedAt(idet); | |
59 | const TVectorD *vectorP = (TVectorD*)ped.fLinearFitterPArray.UncheckedAt(idet); | |
60 | const TH2F *hped = (TH2F*)ped.fLinearFitterHistoArray.UncheckedAt(idet); | |
61 | ||
62 | if ( vectorE != 0x0 ) fLinearFitterEArray.AddAt(new TVectorD(*vectorE), idet); | |
63 | if ( vectorP != 0x0 ) fLinearFitterPArray.AddAt(new TVectorD(*vectorP), idet); | |
64 | if ( hped != 0x0 ){ | |
65 | TH2F *hNew = new TH2F(*hped); | |
66 | hNew->SetDirectory(0); | |
67 | fLinearFitterHistoArray.AddAt(hNew,idet); | |
68 | } | |
69 | ||
70 | } | |
71 | } | |
72 | //_____________________________________________________________________ | |
73 | AliTRDCalibraVdriftLinearFit& AliTRDCalibraVdriftLinearFit::operator = (const AliTRDCalibraVdriftLinearFit &source) | |
74 | { | |
75 | // | |
76 | // assignment operator | |
77 | // | |
78 | if (&source == this) return *this; | |
79 | new (this) AliTRDCalibraVdriftLinearFit(source); | |
80 | ||
81 | return *this; | |
82 | } | |
83 | //_____________________________________________________________________ | |
84 | AliTRDCalibraVdriftLinearFit::~AliTRDCalibraVdriftLinearFit() /*FOLD00*/ | |
85 | { | |
86 | // | |
87 | // destructor | |
88 | // | |
89 | } | |
90 | //_____________________________________________________________________ | |
91 | void AliTRDCalibraVdriftLinearFit::Add(AliTRDCalibraVdriftLinearFit *ped) | |
92 | { | |
93 | // | |
94 | // Add histo | |
95 | // | |
96 | ||
97 | fVersion++; | |
98 | ||
99 | for (Int_t idet = 0; idet < 540; idet++){ | |
100 | const TH2F *hped = (TH2F*)ped->GetLinearFitterHisto(idet); | |
101 | //printf("idet %d\n",idet); | |
102 | if ( hped != 0x0 ){ | |
103 | //printf("add\n"); | |
104 | TH2F *hped1 = GetLinearFitterHisto(idet,kTRUE); | |
105 | //printf("test2\n"); | |
106 | hped1->SetDirectory(0); | |
107 | //printf("test4\n"); | |
108 | hped1->Add(hped); | |
109 | //printf("test3\n"); | |
110 | } | |
111 | } | |
112 | } | |
113 | //______________________________________________________________________________________ | |
114 | TH2F* AliTRDCalibraVdriftLinearFit::GetLinearFitterHisto(Int_t detector, Bool_t force) | |
115 | { | |
116 | // | |
117 | // return pointer to TH2F histo | |
118 | // if force is true create a new histo if it doesn't exist allready | |
119 | // | |
120 | if ( !force || fLinearFitterHistoArray.UncheckedAt(detector) ) | |
121 | return (TH2F*)fLinearFitterHistoArray.UncheckedAt(detector); | |
122 | ||
123 | // if we are forced and TLinearFitter doesn't yes exist create it | |
124 | ||
125 | // new TH2F | |
126 | TString name("LFDV"); | |
127 | name += detector; | |
128 | name += "version"; | |
129 | name += fVersion; | |
130 | ||
131 | TH2F *lfdv = new TH2F((const Char_t *)name,(const Char_t *) name | |
132 | ,100,-1.0,1.0,100 | |
133 | ,-2.0,2.0); | |
134 | lfdv->SetXTitle("tan(phi_{track})"); | |
135 | lfdv->SetYTitle("dy/dt"); | |
136 | lfdv->SetZTitle("Number of clusters"); | |
137 | lfdv->SetStats(0); | |
138 | lfdv->SetDirectory(0); | |
139 | ||
140 | fLinearFitterHistoArray.AddAt(lfdv,detector); | |
141 | return lfdv; | |
142 | } | |
143 | //______________________________________________________________________________________ | |
144 | Bool_t AliTRDCalibraVdriftLinearFit::GetParam(Int_t detector, TVectorD *param) | |
145 | { | |
146 | // | |
147 | // return param for this detector | |
148 | // | |
149 | if ( fLinearFitterPArray.UncheckedAt(detector) ){ | |
150 | const TVectorD *vectorP = (TVectorD*)fLinearFitterPArray.UncheckedAt(detector); | |
151 | if(!param) param = new TVectorD(2); | |
152 | for(Int_t k = 0; k < 2; k++){ | |
153 | (*param)[k] = (*vectorP)[k]; | |
154 | } | |
155 | return kTRUE; | |
156 | } | |
157 | else return kFALSE; | |
158 | ||
159 | } | |
160 | //______________________________________________________________________________________ | |
161 | Bool_t AliTRDCalibraVdriftLinearFit::GetError(Int_t detector, TVectorD *error) | |
162 | { | |
163 | // | |
164 | // return error for this detector | |
165 | // | |
166 | if ( fLinearFitterEArray.UncheckedAt(detector) ){ | |
167 | const TVectorD *vectorE = (TVectorD*)fLinearFitterEArray.UncheckedAt(detector); | |
168 | if(!error) error = new TVectorD(3); | |
169 | for(Int_t k = 0; k < 3; k++){ | |
170 | (*error)[k] = (*vectorE)[k]; | |
171 | } | |
172 | return kTRUE; | |
173 | } | |
174 | else return kFALSE; | |
175 | ||
176 | } | |
177 | //______________________________________________________________________________________ | |
178 | void AliTRDCalibraVdriftLinearFit::Update(Int_t detector, Float_t tnp, Float_t pars1) | |
179 | { | |
180 | // | |
181 | // Fill the 2D histos for debugging | |
182 | // | |
183 | ||
184 | ((TH2F *) GetLinearFitterHisto(detector,kTRUE))->Fill(tnp,pars1); | |
185 | ||
186 | } | |
187 | //____________Functions fit Online CH2d________________________________________ | |
188 | void AliTRDCalibraVdriftLinearFit::FillPEArray() | |
189 | { | |
190 | // | |
191 | // Fill fLinearFitterPArray and fLinearFitterEArray from inside | |
192 | // | |
193 | ||
194 | ||
195 | Int_t *arrayI = new Int_t[540]; | |
196 | for(Int_t k = 0; k< 540; k++){ | |
197 | arrayI[k] = 0; | |
198 | } | |
199 | ||
200 | // Loop over histos | |
201 | for(Int_t cb = 0; cb < 540; cb++){ | |
202 | const TH2F *linearfitterhisto = (TH2F*)fLinearFitterHistoArray.UncheckedAt(cb); | |
203 | //printf("Processing the detector cb %d we find %d\n",cb, (Bool_t) linearfitterhisto); | |
204 | ||
205 | if ( linearfitterhisto != 0 ){ | |
206 | ||
207 | // Fill a linearfitter | |
208 | TAxis *xaxis = linearfitterhisto->GetXaxis(); | |
209 | TAxis *yaxis = linearfitterhisto->GetYaxis(); | |
210 | TLinearFitter linearfitter = TLinearFitter(2,"pol1"); | |
211 | //printf("test\n"); | |
212 | for(Int_t ibinx = 0; ibinx < linearfitterhisto->GetNbinsX(); ibinx++){ | |
213 | for(Int_t ibiny = 0; ibiny < linearfitterhisto->GetNbinsY(); ibiny++){ | |
214 | if(linearfitterhisto->GetBinContent(ibinx+1,ibiny+1)>0){ | |
215 | Double_t x = xaxis->GetBinCenter(ibinx+1); | |
216 | Double_t y = yaxis->GetBinCenter(ibiny+1); | |
217 | for(Int_t k = 0; k < (Int_t)linearfitterhisto->GetBinContent(ibinx+1,ibiny+1); k++){ | |
218 | linearfitter.AddPoint(&x,y); | |
219 | arrayI[cb]++; | |
220 | } | |
221 | } | |
222 | } | |
223 | } | |
224 | ||
225 | //printf("Find %d entries for the detector %d\n",arrayI[cb],cb); | |
226 | ||
227 | // Eval the linear fitter | |
228 | if(arrayI[cb]>10){ | |
229 | TVectorD *par = new TVectorD(2); | |
230 | TVectorD pare = TVectorD(2); | |
231 | TVectorD *parE = new TVectorD(3); | |
232 | linearfitter.Eval(); | |
233 | linearfitter.GetParameters(*par); | |
234 | linearfitter.GetErrors(pare); | |
235 | Float_t ppointError = TMath::Sqrt(TMath::Abs(linearfitter.GetChisquare())/arrayI[cb]); | |
236 | (*parE)[0] = pare[0]*ppointError; | |
237 | (*parE)[1] = pare[1]*ppointError; | |
238 | (*parE)[2] = (Double_t) arrayI[cb]; | |
239 | fLinearFitterPArray.AddAt(par,cb); | |
240 | fLinearFitterEArray.AddAt(parE,cb); | |
241 | //par->Print(); | |
242 | //parE->Print(); | |
243 | } | |
244 | }// if something | |
245 | } | |
246 | ||
247 | } |