]>
Commit | Line | Data |
---|---|---|
348f80b7 | 1 | /************************************************************************** |
2 | * Copyright(c) 2007-2009, 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 | **************************************************************************/ | |
456ec396 | 15 | #include <TFile.h> |
348f80b7 | 16 | #include "AliITSOnlineSDDInjectors.h" |
456ec396 | 17 | #include "AliLog.h" |
348f80b7 | 18 | #include <TH2F.h> |
915c0469 | 19 | #include <TF1.h> |
348f80b7 | 20 | #include <TGraphErrors.h> |
21 | #include <TMath.h> | |
22 | ||
4c82df4c | 23 | /* $Id$ */ |
24 | ||
348f80b7 | 25 | /////////////////////////////////////////////////////////////////// |
26 | // // | |
27 | // Implementation of the class used for SDD injector analysis // | |
28 | // Origin: F.Prino, Torino, prino@to.infn.it // | |
29 | // // | |
30 | /////////////////////////////////////////////////////////////////// | |
31 | ||
32 | ClassImp(AliITSOnlineSDDInjectors) | |
33 | ||
34 | const Float_t AliITSOnlineSDDInjectors::fgkSaturation = 1008.; | |
9f026db8 | 35 | const Float_t AliITSOnlineSDDInjectors::fgkDefaultLThreshold = 5.; |
36 | const Float_t AliITSOnlineSDDInjectors::fgkDefaultHThreshold = 25.; | |
37 | const Float_t AliITSOnlineSDDInjectors::fgkDefaultMinSpeed = 5.5; | |
38 | const Float_t AliITSOnlineSDDInjectors::fgkDefaultMaxSpeed = 9.0; | |
39 | const Float_t AliITSOnlineSDDInjectors::fgkDefaultMaxErr = 1.5; | |
915c0469 | 40 | const Int_t AliITSOnlineSDDInjectors::fgkDefaultPolDegree = 3; |
f4e26d31 | 41 | const Float_t AliITSOnlineSDDInjectors::fgkDefaultTimeStep = 50.; |
42 | const UShort_t AliITSOnlineSDDInjectors::fgkDefaultTbMin[kInjLines] = {10,50,100}; | |
43 | const UShort_t AliITSOnlineSDDInjectors::fgkDefaultTbMax[kInjLines] = {20,70,120}; | |
348f80b7 | 44 | |
45 | //______________________________________________________________________ | |
915c0469 | 46 | AliITSOnlineSDDInjectors::AliITSOnlineSDDInjectors():AliITSOnlineSDD(),fHisto(),fTbZero(0.),fRMSTbZero(0.),fNEvents(0),fParam(),fPolDegree(0),fActualPolDegree(0),fMinDriftSpeed(0.),fMaxDriftSpeed(0.),fMaxDriftSpeedErr(0.),fLowThreshold(0.),fHighThreshold(0.),fFirstPadForFit(0),fLastPadForFit(0),fPadStatusCutForFit(0),fTimeStep(0.),fUseTimeZeroSignal(kFALSE) |
348f80b7 | 47 | { |
48 | // default constructor | |
348f80b7 | 49 | SetPositions(); |
9f026db8 | 50 | SetDefaults(); |
f4e26d31 | 51 | SetTimeStep(fgkDefaultTimeStep); |
348f80b7 | 52 | } |
53 | //______________________________________________________________________ | |
915c0469 | 54 | AliITSOnlineSDDInjectors::AliITSOnlineSDDInjectors(Int_t nddl, Int_t ncarlos, Int_t sid):AliITSOnlineSDD(nddl,ncarlos,sid),fHisto(),fTbZero(0.),fRMSTbZero(0.),fNEvents(0),fParam(),fPolDegree(0),fActualPolDegree(0),fMinDriftSpeed(0.),fMaxDriftSpeed(0.),fMaxDriftSpeedErr(0.),fLowThreshold(0.),fHighThreshold(0.),fFirstPadForFit(0),fLastPadForFit(0),fPadStatusCutForFit(0),fTimeStep(0.),fUseTimeZeroSignal(kFALSE) |
beb262b4 | 55 | { |
56 | // standard constructor | |
348f80b7 | 57 | SetPositions(); |
9f026db8 | 58 | SetDefaults(); |
f4e26d31 | 59 | SetTimeStep(fgkDefaultTimeStep); |
348f80b7 | 60 | } |
61 | //______________________________________________________________________ | |
62 | AliITSOnlineSDDInjectors::~AliITSOnlineSDDInjectors(){ | |
63 | // Destructor | |
19f1458a | 64 | // fHisto should not be deleted here because it points to an histo created |
65 | // by the external code which calls the method AnalyzeEvent | |
66 | // if(fHisto) delete fHisto; | |
348f80b7 | 67 | if(fParam) delete [] fParam; |
68 | } | |
69 | //______________________________________________________________________ | |
9f026db8 | 70 | void AliITSOnlineSDDInjectors::SetDefaults(){ |
1397fe91 | 71 | for(Int_t i=0;i<kInjLines;i++) { |
9f026db8 | 72 | SetInjLineRange(i,fgkDefaultTbMin[i],fgkDefaultTbMax[i]); |
1397fe91 | 73 | SetUseLine(i,kTRUE); |
74 | } | |
9f026db8 | 75 | SetThresholds(fgkDefaultLThreshold,fgkDefaultHThreshold); |
915c0469 | 76 | SetPolDegree(fgkDefaultPolDegree); |
9f026db8 | 77 | SetMinDriftSpeed(fgkDefaultMinSpeed); |
78 | SetMaxDriftSpeed(fgkDefaultMaxSpeed); | |
79 | SetMaxDriftSpeedErr(fgkDefaultMaxErr); | |
80 | SetFitLimits(1,kInjPads-2); // exclude first and last pad | |
81 | SetPadStatusCutForFit(); | |
82 | } | |
83 | //______________________________________________________________________ | |
348f80b7 | 84 | void AliITSOnlineSDDInjectors::SetPositions(){ |
85 | // | |
2ca27861 | 86 | Double_t xLinFromCenterUm[kInjLines]={31860.,17460.,660.}; |
87 | Double_t xAnodeFromCenterUm=35085; | |
9f026db8 | 88 | for(Int_t i=0;i<kInjLines;i++){ |
89 | fPosition[i]=xAnodeFromCenterUm-xLinFromCenterUm[i]; | |
348f80b7 | 90 | fPosition[i]/=10000.; // from microns to cm |
91 | } | |
92 | } | |
93 | //______________________________________________________________________ | |
94 | void AliITSOnlineSDDInjectors::Reset(){ | |
beb262b4 | 95 | // |
9f026db8 | 96 | for(Int_t i=0;i<kInjPads;i++){ |
97 | fDriftSpeed[i]=0.; | |
98 | fDriftSpeedErr[i]=0.; | |
348f80b7 | 99 | } |
9f026db8 | 100 | for(Int_t i=0;i<kInjPads;i++){ |
101 | for(Int_t j=0;j<kInjLines;j++){ | |
348f80b7 | 102 | fGoodInj[i][j]=0; |
103 | fCentroid[i][j]=0.; | |
104 | fRMSCentroid[i][j]=0.; | |
105 | } | |
106 | } | |
107 | } | |
108 | //______________________________________________________________________ | |
109 | void AliITSOnlineSDDInjectors::AnalyzeEvent(TH2F* his){ | |
110 | // | |
456ec396 | 111 | AddEvent(his); |
9f026db8 | 112 | FitDriftSpeedVsAnode(); |
348f80b7 | 113 | } |
114 | //______________________________________________________________________ | |
2ca27861 | 115 | void AliITSOnlineSDDInjectors::AddEvent(TH2F* his){ |
116 | // Add the drift speed from current event to the average value | |
117 | if(fNEvents==0){ | |
118 | for(Int_t i=0;i<kInjPads;i++){ | |
119 | fSumDriftSpeed[i]=0.; | |
120 | fSumSqDriftSpeed[i]=0.; | |
121 | } | |
122 | } | |
123 | Reset(); | |
124 | fHisto=his; | |
125 | FindGoodInjectors(); | |
126 | FindCentroids(); | |
127 | CalcTimeBinZero(); | |
128 | for(Int_t j=0;j<kInjPads;j++){ | |
129 | CalcDriftSpeed(j); | |
130 | fSumDriftSpeed[j]+=fDriftSpeed[j]; | |
131 | fSumSqDriftSpeed[j]+=fDriftSpeed[j]*fDriftSpeed[j]; | |
132 | } | |
133 | ++fNEvents; | |
134 | } | |
135 | //______________________________________________________________________ | |
136 | Double_t AliITSOnlineSDDInjectors::GetRMSDriftSpeed(Int_t ipad) const { | |
137 | // | |
138 | if(fNEvents<=1) return 0.; | |
139 | Double_t mean=fSumDriftSpeed[ipad]/(Double_t)fNEvents; | |
140 | Double_t diff=fSumSqDriftSpeed[ipad]/(Double_t)fNEvents-mean*mean; | |
141 | if(diff<0.) diff=0.; | |
142 | return TMath::Sqrt(diff); | |
143 | } | |
144 | ||
145 | //______________________________________________________________________ | |
146 | void AliITSOnlineSDDInjectors::FitMeanDriftSpeedVsAnode(){ | |
147 | // Calculates | |
148 | if(fNEvents==0) return; | |
149 | for(Int_t i=0;i<kInjPads;i++){ | |
150 | fDriftSpeed[i]=GetMeanDriftSpeed(i); | |
151 | if(fNEvents>1){ | |
152 | Double_t rms=GetRMSDriftSpeed(i); | |
153 | if(rms>0.) fDriftSpeedErr[i]=rms/TMath::Sqrt(fNEvents); | |
154 | } | |
155 | } | |
156 | FitDriftSpeedVsAnode(); | |
157 | } | |
158 | //______________________________________________________________________ | |
9f026db8 | 159 | TGraphErrors* AliITSOnlineSDDInjectors::GetTimeVsDistGraph(Int_t jpad) const{ |
348f80b7 | 160 | // |
9f026db8 | 161 | const Int_t kPts=kInjLines+1; |
162 | Float_t x[kPts],y[kPts],ex[kPts],ey[kPts]; | |
348f80b7 | 163 | x[0]=0.; |
164 | ex[0]=0.; | |
165 | y[0]=fTbZero; | |
166 | ey[0]=0.; | |
9f026db8 | 167 | for(Int_t i=0;i<kInjLines;i++){ |
348f80b7 | 168 | x[i+1]=fPosition[i]; |
169 | ex[i+1]=0.; | |
9f026db8 | 170 | y[i+1]=fCentroid[jpad][i]; |
171 | ey[i+1]=fRMSCentroid[jpad][i]; | |
348f80b7 | 172 | } |
173 | TGraphErrors *g=new TGraphErrors(4,x,y,ex,ey); | |
174 | return g; | |
175 | } | |
9f026db8 | 176 | |
348f80b7 | 177 | //______________________________________________________________________ |
9f026db8 | 178 | TGraphErrors* AliITSOnlineSDDInjectors::GetDriftSpeedGraph() const{ |
348f80b7 | 179 | // |
348f80b7 | 180 | Int_t ipt=0; |
181 | TGraphErrors *g=new TGraphErrors(0); | |
9f026db8 | 182 | for(Int_t i=0;i<kInjPads;i++){ |
183 | if(fDriftSpeed[i]>0){ | |
184 | g->SetPoint(ipt,GetAnodeNumber(i),fDriftSpeed[i]); | |
185 | g->SetPointError(ipt,0,fDriftSpeedErr[i]); | |
348f80b7 | 186 | ipt++; |
187 | } | |
188 | } | |
189 | return g; | |
190 | } | |
191 | //______________________________________________________________________ | |
84df0230 | 192 | TGraphErrors* AliITSOnlineSDDInjectors::GetSelectedDriftSpeedGraph(Int_t minAcceptStatus) const{ |
193 | // TGraphErrors with only pads with status of injector >= minAcceptStatus | |
194 | Int_t ipt=0; | |
195 | TGraphErrors *g=new TGraphErrors(0); | |
196 | for(Int_t i=0;i<kInjPads;i++){ | |
197 | Int_t padStatus = GetInjPadStatus(i); | |
198 | if(fDriftSpeed[i]>0 && padStatus >= minAcceptStatus ){ | |
199 | g->SetPoint(ipt,GetAnodeNumber(i),fDriftSpeed[i]); | |
200 | g->SetPointError(ipt,0,fDriftSpeedErr[i]); | |
201 | ipt++; | |
202 | } | |
203 | } | |
204 | return g; | |
205 | } | |
206 | //______________________________________________________________________ | |
348f80b7 | 207 | void AliITSOnlineSDDInjectors::CalcTimeBinZero(){ |
784a52ed | 208 | // Get time zero from trigger signal |
2ca27861 | 209 | Double_t tzero=0.,intCont=0.,rmsPeak=0.; |
784a52ed | 210 | Bool_t isTbUsed[256]; |
211 | Int_t nTbUsed=0; | |
212 | for(Int_t i=0;i<256;i++) isTbUsed[i]=0; | |
348f80b7 | 213 | for(Int_t ian=0;ian<fgkNAnodes;ian++){ |
214 | for(Int_t itb=1;itb<fTbMin[0];itb++){ | |
2ca27861 | 215 | Double_t cont=fHisto->GetBinContent(itb,ian+1); |
216 | Double_t contm1=fHisto->GetBinContent(itb+1,ian+1); | |
217 | Double_t contp1=fHisto->GetBinContent(itb-1,ian+1); | |
9f026db8 | 218 | if(cont>fLowThreshold){ |
784a52ed | 219 | if(contm1>fHighThreshold || cont>fHighThreshold || contp1>fHighThreshold){ |
220 | tzero+=cont*float(itb); | |
221 | rmsPeak+=cont*float(itb)*float(itb); | |
222 | intCont+=cont; | |
223 | if(!isTbUsed[itb]){ | |
224 | isTbUsed[itb]=1; | |
225 | ++nTbUsed; | |
226 | } | |
227 | } | |
348f80b7 | 228 | } |
229 | } | |
230 | } | |
784a52ed | 231 | if(intCont>0){ |
232 | fTbZero=tzero/intCont; | |
233 | fRMSTbZero=TMath::Sqrt(rmsPeak/intCont-fTbZero*fTbZero); | |
234 | } | |
235 | if(nTbUsed==1) fRMSTbZero=0.5; | |
348f80b7 | 236 | } |
915c0469 | 237 | |
348f80b7 | 238 | //______________________________________________________________________ |
9f026db8 | 239 | void AliITSOnlineSDDInjectors::FitDriftSpeedVsAnode(){ |
251c7c7c | 240 | // fits the anode dependence of drift speed |
915c0469 | 241 | |
915c0469 | 242 | Float_t rangeForMax[2]={78.,178.}; |
251c7c7c | 243 | PolyFit(fPolDegree); |
244 | fActualPolDegree=fPolDegree; | |
245 | if(fPolDegree==3){ | |
246 | Double_t deltasq=fParam[2]*fParam[2]-3*fParam[1]*fParam[3]; | |
247 | Double_t zero1=-999.; | |
248 | Double_t zero2=-999.; | |
249 | if(deltasq>=0. && TMath::Abs(fParam[3])>0.){ | |
250 | Double_t delta=TMath::Sqrt(deltasq); | |
251 | zero1=(-fParam[2]+delta)/3./fParam[3]; | |
252 | zero2=(-fParam[2]-delta)/3./fParam[3]; | |
253 | } | |
254 | Bool_t twoZeroes=kFALSE; | |
255 | Bool_t oneZero=kFALSE; | |
256 | if(zero1>0. && zero1<256. && zero2>0. && zero2<256.) twoZeroes=kTRUE; | |
257 | if(zero1>rangeForMax[0] && zero1<rangeForMax[1]) oneZero=kTRUE; | |
258 | if(zero2>rangeForMax[0] && zero2<rangeForMax[1]) oneZero=kTRUE; | |
259 | if(!oneZero || twoZeroes){ | |
260 | PolyFit(2); | |
261 | Double_t xmax=-999.; | |
262 | if(fParam[2]<0.) xmax=-fParam[1]/2./fParam[2]; | |
263 | if(xmax>rangeForMax[0] && xmax<rangeForMax[1]){ | |
264 | fActualPolDegree=2; | |
265 | }else{ | |
266 | Double_t averSpeed=0.; | |
267 | Double_t sumWei=0.; | |
268 | Int_t nUsedPts=0; | |
269 | for(Int_t jpad=fFirstPadForFit; jpad<=fLastPadForFit; jpad++){ | |
270 | if(fDriftSpeed[jpad]>0 && GetInjPadStatus(jpad)>fPadStatusCutForFit){ | |
271 | Double_t wei=1./fDriftSpeedErr[jpad]/fDriftSpeedErr[jpad]; | |
272 | averSpeed+=wei*fDriftSpeed[jpad]; | |
273 | sumWei+=wei; | |
274 | nUsedPts++; | |
275 | } | |
915c0469 | 276 | } |
251c7c7c | 277 | if(sumWei>0.) averSpeed/=sumWei; |
278 | if(nUsedPts<fPolDegree+1) averSpeed=0; | |
279 | fParam[0]=averSpeed; | |
280 | for(Int_t i=1; i < fPolDegree+1; i++) fParam[i]=0.; | |
281 | fActualPolDegree=0; | |
915c0469 | 282 | } |
283 | } | |
284 | } | |
915c0469 | 285 | } |
286 | //______________________________________________________________________ | |
251c7c7c | 287 | void AliITSOnlineSDDInjectors::PolyFit(Int_t degree){ |
915c0469 | 288 | // fits the anode dependence of drift speed with a polynomial function |
251c7c7c | 289 | const Int_t kNn=degree+1; |
290 | const Int_t kDimens=fPolDegree+1; | |
291 | ||
2ca27861 | 292 | Double_t **mat = new Double_t*[kNn]; |
293 | for(Int_t i=0; i < kNn; i++) mat[i] = new Double_t[kNn]; | |
294 | Double_t *vect = new Double_t[kNn]; | |
9f026db8 | 295 | |
4ff6aa93 | 296 | for(Int_t k1=0;k1<kNn;k1++){ |
348f80b7 | 297 | vect[k1]=0; |
4ff6aa93 | 298 | for(Int_t k2=0;k2<kNn;k2++){ |
348f80b7 | 299 | mat[k1][k2]=0; |
348f80b7 | 300 | } |
301 | } | |
06bb3583 | 302 | Int_t npts = 0; |
4ff6aa93 | 303 | for(Int_t k1=0;k1<kNn;k1++){ |
9f026db8 | 304 | for(Int_t jpad=fFirstPadForFit; jpad<=fLastPadForFit; jpad++){ |
2ca27861 | 305 | Double_t x=(Double_t)GetAnodeNumber(jpad); |
9f026db8 | 306 | if(fDriftSpeed[jpad]>0 && GetInjPadStatus(jpad)>fPadStatusCutForFit){ |
307 | vect[k1]+=fDriftSpeed[jpad]*TMath::Power(x,k1)/TMath::Power(fDriftSpeedErr[jpad],2); | |
06bb3583 | 308 | if(k1==0) npts++; |
9f026db8 | 309 | for(Int_t k2=0;k2<kNn;k2++){ |
9f026db8 | 310 | mat[k1][k2]+=TMath::Power(x,k1+k2)/TMath::Power(fDriftSpeedErr[jpad],2); |
311 | } | |
312 | } | |
348f80b7 | 313 | } |
314 | } | |
915c0469 | 315 | if(npts<fPolDegree+1){ |
06bb3583 | 316 | if(fParam) delete [] fParam; |
251c7c7c | 317 | fParam=new Double_t[kDimens]; |
318 | for(Int_t i=0; i<kDimens;i++)fParam[i]=0; | |
06bb3583 | 319 | }else{ |
320 | Int_t *iPivot = new Int_t[kNn]; | |
321 | Int_t *indxR = new Int_t[kNn]; | |
322 | Int_t *indxC = new Int_t[kNn]; | |
323 | for(Int_t i=0;i<kNn;i++) iPivot[i]=0; | |
324 | Int_t iCol=-1,iRow=-1; | |
325 | for(Int_t i=0;i<kNn;i++){ | |
2ca27861 | 326 | Double_t big=0.; |
06bb3583 | 327 | for(Int_t j=0;j<kNn;j++){ |
328 | if(iPivot[j]!=1){ | |
329 | for(Int_t k=0;k<kNn;k++){ | |
330 | if(iPivot[k]==0){ | |
331 | if(TMath::Abs(mat[j][k])>=big){ | |
332 | big=TMath::Abs(mat[j][k]); | |
333 | iRow=j; | |
334 | iCol=k; | |
335 | } | |
336 | } | |
348f80b7 | 337 | } |
338 | } | |
339 | } | |
06bb3583 | 340 | iPivot[iCol]++; |
2ca27861 | 341 | Double_t aux; |
06bb3583 | 342 | if(iRow!=iCol){ |
343 | for(Int_t l=0;l<kNn;l++){ | |
344 | aux=mat[iRow][l]; | |
345 | mat[iRow][l]=mat[iCol][l]; | |
346 | mat[iCol][l]=aux; | |
347 | } | |
348 | aux=vect[iRow]; | |
349 | vect[iRow]=vect[iCol]; | |
350 | vect[iCol]=aux; | |
348f80b7 | 351 | } |
06bb3583 | 352 | indxR[i]=iRow; |
353 | indxC[i]=iCol; | |
354 | if(mat[iCol][iCol]==0) break; | |
2ca27861 | 355 | Double_t pivinv=1./mat[iCol][iCol]; |
06bb3583 | 356 | mat[iCol][iCol]=1; |
357 | for(Int_t l=0;l<kNn;l++) mat[iCol][l]*=pivinv; | |
358 | vect[iCol]*=pivinv; | |
359 | for(Int_t m=0;m<kNn;m++){ | |
360 | if(m!=iCol){ | |
361 | aux=mat[m][iCol]; | |
362 | mat[m][iCol]=0; | |
363 | for(Int_t n=0;n<kNn;n++) mat[m][n]-=mat[iCol][n]*aux; | |
364 | vect[m]-=vect[iCol]*aux; | |
365 | } | |
366 | } | |
348f80b7 | 367 | } |
06bb3583 | 368 | delete [] iPivot; |
369 | delete [] indxR; | |
370 | delete [] indxC; | |
371 | ||
372 | ||
373 | if(fParam) delete [] fParam; | |
251c7c7c | 374 | fParam=new Double_t[kDimens]; |
06bb3583 | 375 | for(Int_t i=0; i<kNn;i++)fParam[i]=vect[i]; |
251c7c7c | 376 | if(degree<fPolDegree) for(Int_t i=kNn; i<kDimens;i++)fParam[i]=0.; |
348f80b7 | 377 | } |
348f80b7 | 378 | |
4ff6aa93 | 379 | for(Int_t i=0; i < kNn; i++) delete [] mat[i]; |
348f80b7 | 380 | delete [] mat; |
381 | delete [] vect; | |
382 | } | |
383 | //______________________________________________________________________ | |
9f026db8 | 384 | void AliITSOnlineSDDInjectors::CalcDriftSpeed(Int_t jpad){ |
348f80b7 | 385 | // |
2ca27861 | 386 | Double_t sumY=0,sumX=0,sumXX=0,sumYY=0.,sumXY=0,sumWEI=0.; |
348f80b7 | 387 | Int_t npt=0; |
2ca27861 | 388 | Double_t y[kInjLines],ey[kInjLines]; |
389 | Double_t tzero=0,erry=0; | |
9f026db8 | 390 | for(Int_t i=0;i<kInjLines;i++){ |
391 | y[i]=fCentroid[jpad][i]; | |
392 | ey[i]=fRMSCentroid[jpad][i]; | |
348f80b7 | 393 | } |
9f026db8 | 394 | for(Int_t i=0;i<kInjLines;i++){ |
1397fe91 | 395 | if(!fUseLine[i]) continue; |
9f026db8 | 396 | if(fGoodInj[jpad][i] && ey[i]!=0){ |
348f80b7 | 397 | sumY+=y[i]/ey[i]/ey[i]; |
398 | sumX+=fPosition[i]/ey[i]/ey[i]; | |
399 | sumXX+=fPosition[i]*fPosition[i]/ey[i]/ey[i]; | |
400 | sumYY+=y[i]*y[i]/ey[i]/ey[i]; | |
401 | sumXY+=fPosition[i]*y[i]/ey[i]/ey[i]; | |
402 | sumWEI+=1./ey[i]/ey[i]; | |
403 | tzero=fTbZero/ey[i]/ey[i]; | |
784a52ed | 404 | erry=ey[i]/ey[i]/ey[i]; |
348f80b7 | 405 | npt++; |
406 | } | |
407 | } | |
2ca27861 | 408 | Double_t slope=0.,eslope=0.; |
784a52ed | 409 | if(npt==1){ |
410 | slope=(sumY-tzero)/sumX; | |
411 | eslope=erry/sumX; | |
412 | } | |
348f80b7 | 413 | if(npt>1){ |
784a52ed | 414 | if(fUseTimeZeroSignal){ |
415 | sumY+=fTbZero/fRMSTbZero/fRMSTbZero; | |
416 | sumX+=0.; | |
417 | sumXX+=0.; | |
418 | sumYY+=fTbZero*fTbZero/fRMSTbZero/fRMSTbZero; | |
419 | sumXY+=0.; | |
420 | sumWEI+=1./fRMSTbZero/fRMSTbZero; | |
53855521 | 421 | } |
784a52ed | 422 | slope=(sumWEI*sumXY-sumY*sumX)/(sumWEI*sumXX-sumX*sumX); |
423 | eslope=TMath::Sqrt(sumWEI/(sumWEI*sumXX-sumX*sumX)); | |
348f80b7 | 424 | } |
784a52ed | 425 | |
2ca27861 | 426 | Double_t vel=0,evel=0; |
784a52ed | 427 | if(slope!=0. && fTimeStep>0.){ |
428 | vel=1./slope*10000./fTimeStep;// micron/ns | |
429 | evel=eslope/slope/slope*10000./fTimeStep;// micron/ns | |
348f80b7 | 430 | } |
9f026db8 | 431 | if(vel>fMaxDriftSpeed||vel<fMinDriftSpeed || evel>fMaxDriftSpeedErr){ |
348f80b7 | 432 | vel=0.; |
433 | evel=0.; | |
434 | } | |
9f026db8 | 435 | fDriftSpeed[jpad]=vel; |
436 | fDriftSpeedErr[jpad]=evel; | |
348f80b7 | 437 | } |
438 | //______________________________________________________________________ | |
9f026db8 | 439 | Int_t AliITSOnlineSDDInjectors::GetAnodeNumber(Int_t iInjPad) const{ |
61606350 | 440 | // Injectors location along anodes: |
441 | // Side left (UP) - channel 0: injectors on anodes 0,7,15,...,247,255 | |
442 | // Side right (DOWN) - channel 1: injectors on anodes 0,8,16,...,248,255 | |
348f80b7 | 443 | Int_t ian=-1; |
9f026db8 | 444 | if(iInjPad>=kInjPads) return ian; |
61606350 | 445 | if(fSide==1){ // right side |
9f026db8 | 446 | ian=iInjPad*8; |
447 | if(iInjPad==32) ian--; | |
61606350 | 448 | }else{ // left side |
9f026db8 | 449 | ian=iInjPad*8-1; |
450 | if(iInjPad==0) ian=0; | |
348f80b7 | 451 | } |
452 | return ian; | |
453 | } | |
84c6e6c0 | 454 | //______________________________________________________________________ |
9f026db8 | 455 | Int_t AliITSOnlineSDDInjectors::GetInjPadNumberFromAnode(Int_t nAnode) const{ |
84c6e6c0 | 456 | // |
9f026db8 | 457 | Int_t iInjPad=-1; |
61606350 | 458 | if(fSide==1){ // right side |
9f026db8 | 459 | if(nAnode%8==0) iInjPad=nAnode/8; |
460 | if(nAnode==255) iInjPad=32; | |
61606350 | 461 | }else{ // left side |
9f026db8 | 462 | if(nAnode%8==7) iInjPad=1+nAnode/8; |
463 | if(nAnode==0) iInjPad=0; | |
84c6e6c0 | 464 | } |
9f026db8 | 465 | if(nAnode>=256) iInjPad=-1; |
466 | return iInjPad; | |
84c6e6c0 | 467 | } |
468 | //______________________________________________________________________ | |
9f026db8 | 469 | Int_t AliITSOnlineSDDInjectors::GetInjPadStatus(Int_t jpad) const{ |
470 | // returns an integer value with status of injector lines for given pad/anode | |
471 | // status=7 --> 111 all injector are good | |
472 | // status=6 --> 110 1st line (close to anodes) is bad, other two are good | |
473 | // .... | |
474 | // status=1 --> 001 only 1st line (close to anodes) good | |
475 | // status=0 --> 000 all lines are bad | |
84c6e6c0 | 476 | Int_t istatus=0; |
9f026db8 | 477 | if(jpad>=0 && jpad<kInjPads){ |
478 | for(Int_t jlin=0;jlin<kInjLines;jlin++) istatus+=fGoodInj[jpad][jlin]<<jlin; | |
84c6e6c0 | 479 | } |
480 | return istatus; | |
481 | } | |
348f80b7 | 482 | //______________________________________________________________________ |
483 | void AliITSOnlineSDDInjectors::FindGoodInjectors(){ | |
484 | // | |
9f026db8 | 485 | for(Int_t jpad=0;jpad<kInjPads;jpad++){ |
486 | Int_t ian=GetAnodeNumber(jpad); | |
487 | for(Int_t jlin=0;jlin<kInjLines;jlin++){ | |
488 | for(Int_t jjj=fTbMin[jlin];jjj<fTbMax[jlin];jjj++){ | |
348f80b7 | 489 | Float_t c1=fHisto->GetBinContent(jjj,ian+1); |
490 | Float_t c2=fHisto->GetBinContent(jjj+1,ian+1); | |
a7996467 | 491 | // Float_t c3=fHisto->GetBinContent(jjj+2,ian+1); |
492 | if(c1>fLowThreshold && c2>fLowThreshold){ | |
493 | if(c1>fHighThreshold || c2>fHighThreshold){ | |
494 | fGoodInj[jpad][jlin]=1; | |
495 | break; | |
496 | } | |
348f80b7 | 497 | } |
498 | } | |
348f80b7 | 499 | } |
500 | } | |
501 | } | |
502 | //______________________________________________________________________ | |
503 | void AliITSOnlineSDDInjectors::FindCentroids(){ | |
504 | // | |
9f026db8 | 505 | for(Int_t jpad=0;jpad<kInjPads;jpad++){ |
506 | Int_t ian=GetAnodeNumber(jpad); | |
507 | for(Int_t jlin=0;jlin<kInjLines;jlin++){ | |
508 | if(!fGoodInj[jpad][jlin]) continue; | |
2ca27861 | 509 | Double_t maxcont=0; |
348f80b7 | 510 | Int_t ilmax=-1; |
9f026db8 | 511 | for(Int_t jjj=fTbMin[jlin];jjj<fTbMax[jlin];jjj++){ |
2ca27861 | 512 | Double_t cont=fHisto->GetBinContent(jjj,ian+1); |
348f80b7 | 513 | if(cont>maxcont){ |
514 | maxcont=cont; | |
515 | ilmax=jjj; | |
516 | } | |
517 | } | |
2ca27861 | 518 | Double_t intCont=0; |
348f80b7 | 519 | Int_t jjj=ilmax; |
520 | while(1){ | |
2ca27861 | 521 | Double_t cont=fHisto->GetBinContent(jjj,ian+1); |
9f026db8 | 522 | if(cont<fLowThreshold) break; |
348f80b7 | 523 | if(cont<fgkSaturation){ |
2ca27861 | 524 | fCentroid[jpad][jlin]+=cont*(Double_t)jjj; |
525 | fRMSCentroid[jpad][jlin]+=cont*(Double_t)jjj*(Double_t)jjj; | |
348f80b7 | 526 | intCont+=cont; |
527 | } | |
528 | jjj--; | |
529 | } | |
530 | jjj=ilmax+1; | |
531 | while(1){ | |
2ca27861 | 532 | Double_t cont=fHisto->GetBinContent(jjj,ian+1); |
9f026db8 | 533 | if(cont<fLowThreshold) break; |
348f80b7 | 534 | if(cont<fgkSaturation){ |
9f026db8 | 535 | fCentroid[jpad][jlin]+=cont*float(jjj); |
2ca27861 | 536 | fRMSCentroid[jpad][jlin]+=cont*(Double_t)jjj*(Double_t)jjj; |
348f80b7 | 537 | intCont+=cont; |
538 | } | |
539 | jjj++; | |
540 | } | |
541 | if(intCont>0){ | |
9f026db8 | 542 | fCentroid[jpad][jlin]/=intCont; |
2ca27861 | 543 | fRMSCentroid[jpad][jlin]=TMath::Sqrt(fRMSCentroid[jpad][jlin]/intCont-fCentroid[jpad][jlin]*fCentroid[jpad][jlin])/TMath::Sqrt(intCont); |
348f80b7 | 544 | } |
545 | else{ | |
9f026db8 | 546 | fCentroid[jpad][jlin]=0.; |
547 | fRMSCentroid[jpad][jlin]=0.; | |
548 | fGoodInj[jpad][jlin]=0; | |
348f80b7 | 549 | } |
9f026db8 | 550 | if(fRMSCentroid[jpad][jlin]==0) fGoodInj[jpad][jlin]=0; |
348f80b7 | 551 | } |
552 | } | |
553 | } | |
554 | //______________________________________________________________________ | |
9f026db8 | 555 | void AliITSOnlineSDDInjectors::PrintInjectorStatus(){ |
348f80b7 | 556 | // |
9f026db8 | 557 | for(Int_t jpad=0;jpad<kInjPads;jpad++){ |
558 | printf("Line%d-Anode%d: %d %d %d\n",jpad,GetAnodeNumber(jpad),fGoodInj[jpad][0],fGoodInj[jpad][1],fGoodInj[jpad][2]); | |
348f80b7 | 559 | } |
560 | } | |
561 | //______________________________________________________________________ | |
562 | void AliITSOnlineSDDInjectors::PrintCentroids(){ | |
563 | // | |
9f026db8 | 564 | for(Int_t jpad=0;jpad<kInjPads;jpad++){ |
565 | printf("Line%d-Anode%d: %f+-%f %f+-%f %f+-%f\n",jpad,GetAnodeNumber(jpad),fCentroid[jpad][0],fRMSCentroid[jpad][0],fCentroid[jpad][1],fRMSCentroid[jpad][1],fCentroid[jpad][2],fRMSCentroid[jpad][2]); | |
348f80b7 | 566 | } |
567 | } | |
568 | //______________________________________________________________________ | |
4c82df4c | 569 | void AliITSOnlineSDDInjectors::WriteToASCII(Int_t evNumb, UInt_t timeStamp, Int_t optAppend){ |
348f80b7 | 570 | // |
571 | Char_t outfilnam[100]; | |
979b5a5f | 572 | sprintf(outfilnam,"SDDinj_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide); |
4c82df4c | 573 | FILE* outf; |
18da6e54 | 574 | if(optAppend==0){ |
575 | outf=fopen(outfilnam,"w"); | |
915c0469 | 576 | fprintf(outf,"%d\n",fActualPolDegree); |
18da6e54 | 577 | } |
4c82df4c | 578 | else outf=fopen(outfilnam,"a"); |
579 | fprintf(outf,"%d %d ",evNumb,timeStamp); | |
915c0469 | 580 | for(Int_t ic=0;ic<fPolDegree+1;ic++){ |
348f80b7 | 581 | fprintf(outf,"%G ",fParam[ic]); |
582 | } | |
583 | fprintf(outf,"\n"); | |
584 | fclose(outf); | |
585 | } | |
456ec396 | 586 | //______________________________________________________________________ |
e5b2f7f2 | 587 | TH1F* AliITSOnlineSDDInjectors::GetMeanDriftSpeedVsPadHisto() const{ |
588 | Char_t hisnam[20]; | |
589 | sprintf(hisnam,"hdrsp%02dc%02ds%d",fDDL,fCarlos,fSide); | |
590 | TH1F* h=new TH1F(hisnam,"",kInjPads,-0.5,kInjPads-0.5); | |
591 | if(fNEvents>0){ | |
592 | for(Int_t i=0;i<kInjPads;i++){ | |
593 | h->SetBinContent(i+1,GetMeanDriftSpeed(i)); | |
594 | Double_t rms=GetRMSDriftSpeed(i); | |
595 | Double_t err=0.; | |
596 | if(rms>0.) err=rms/TMath::Sqrt(fNEvents); | |
597 | h->SetBinError(i+1,err); | |
598 | } | |
599 | } | |
600 | return h; | |
601 | } | |
602 | //______________________________________________________________________ | |
456ec396 | 603 | Bool_t AliITSOnlineSDDInjectors::WriteToROOT(TFile *fil) const { |
604 | // | |
605 | if(fil==0){ | |
606 | AliWarning("Invalid pointer to ROOT file"); | |
607 | return kFALSE; | |
608 | } | |
609 | Char_t hisnam[20]; | |
610 | fil->cd(); | |
611 | sprintf(hisnam,"hdrsp%02dc%02ds%d",fDDL,fCarlos,fSide); | |
612 | TH1F hdsp(hisnam,"",kInjPads,-0.5,kInjPads-0.5); | |
613 | if(fNEvents==0){ | |
614 | AliWarning("Zero analyzed events"); | |
615 | return kFALSE; | |
616 | } | |
617 | ||
618 | for(Int_t i=0;i<kInjPads;i++){ | |
619 | hdsp.SetBinContent(i+1,GetMeanDriftSpeed(i)); | |
620 | Double_t rms=GetRMSDriftSpeed(i); | |
621 | Double_t err=0.; | |
622 | if(rms>0.) err=rms/TMath::Sqrt(fNEvents); | |
623 | hdsp.SetBinError(i+1,err); | |
624 | } | |
625 | hdsp.Write(); | |
626 | return kTRUE; | |
627 | } | |
50d25e98 | 628 | //______________________________________________________________________ |
629 | void AliITSOnlineSDDInjectors::WriteInjectorStatusToASCII(){ | |
630 | // dump status of injectors encoded into UInt_t | |
631 | // 5 bits (value 0-31) to store number of pads with given status | |
632 | Char_t outfilnam[100]; | |
633 | sprintf(outfilnam,"SDDinj_ddl%02dc%02d_sid%d.data",fDDL,fCarlos,fSide); | |
634 | FILE* outf=fopen(outfilnam,"a"); | |
635 | Int_t n[8]={0,0,0,0,0,0,0,0}; | |
636 | for(Int_t jpad=fFirstPadForFit; jpad<=fLastPadForFit; jpad++){ | |
637 | Int_t statusPad=GetInjPadStatus(jpad); | |
638 | ++n[statusPad]; | |
639 | } | |
640 | UInt_t statusInj=0; | |
641 | statusInj+=(n[7]&0x1F)<<25; // bits 25-29: n. of pads with status 7 | |
642 | statusInj+=(n[6]&0x1F)<<20; // bits 20-24: n. of pads with status 6 | |
643 | statusInj+=(n[5]&0x1F)<<15; // bits 15-19: n. of pads with status 5 | |
644 | statusInj+=(n[4]&0x1F)<<10; // bits 10-14: n. of pads with status 4 | |
645 | statusInj+=(n[3]&0x1F)<<5; // bits 5- 9: n. of pads with status 3 | |
646 | statusInj+=(n[2]&0x1F); // bits 0- 4: n. of pads with status 2 | |
647 | ||
648 | fprintf(outf,"-99 %u\n",statusInj); // -99 used in preprocessor to find line | |
649 | // with injector status info | |
650 | fclose(outf); | |
651 | ||
652 | } |