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