Changes related to the extraction of the V0 finder into a separate class (A. Dainese...
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineSPDscanAnalyzer.cxx
CommitLineData
4ee23d3d 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 **************************************************************************/
15
16/* $Id$ */
17
f0aa5f6c 18////////////////////////////////////////////////////////////
19// Author: Henrik Tydesjo //
20// This class is used in the detector algorithm framework //
21// to process the data stored in special container files //
22// (see AliITSOnlineSPDscan). For instance, minimum //
6727e2db 23// threshold values can be extracted. //
f0aa5f6c 24////////////////////////////////////////////////////////////
25
26#include "AliITSOnlineSPDscanAnalyzer.h"
27#include "AliITSOnlineSPDscan.h"
28#include "AliITSOnlineSPDscanSingle.h"
29#include "AliITSOnlineSPDscanMultiple.h"
30#include "AliITSOnlineSPDscanMeanTh.h"
31#include "AliITSOnlineCalibrationSPDhandler.h"
32#include "AliITSRawStreamSPD.h"
33#include <TStyle.h>
34#include <TMath.h>
35#include <TF1.h>
36#include <TGraph.h>
37#include <TH2F.h>
53ae21ce 38#include <TError.h>
6727e2db 39#include <iostream>
40#include <fstream>
f0aa5f6c 41
42Double_t itsSpdErrorf(Double_t *x, Double_t *par){
43 if (par[2]<0) par[2]=0;
44 Double_t val = par[2]+(0.12*256*32-par[2])*(0.5+0.5*TMath::Erf((x[0]-par[0])/par[1]/sqrt(2.)));
45 return val;
46}
47//Double_t itsSpdErrorfOrig(Double_t *x, Double_t *par){
48// return 0.5+0.5*TMath::Erf((x[0]-par[0])/par[1]/sqrt(2.));
49//}
50
de12e454 51//_________________________________________________________________________
6ddf3d66 52AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const Char_t *fileName, AliITSOnlineCalibrationSPDhandler *handler, Bool_t readFromGridFile) :
de12e454 53 fType(99),fDacId(99),fFileName(fileName),fScanObj(NULL),fHandler(handler),fTriggers(NULL),fTPeff(0),fTPeffHS(NULL),fDeadPixel(0),fDeadPixelHS(NULL),fNoisyPixel(0),fNoisyPixelHS(NULL),
f0aa5f6c 54 fOverWrite(kFALSE),fNoiseThreshold(0.01),fNoiseMinimumEvents(100),
6727e2db 55 fMinNrStepsBeforeIncrease(5),fMinIncreaseFromBaseLine(2),fStepDownDacSafe(5),fMaxBaseLineLevel(10)
f0aa5f6c 56{
57 // constructor
f0aa5f6c 58 for (UInt_t chipNr=0; chipNr<11; chipNr++) {
59 for (UInt_t hs=0; hs<6; hs++) {
60 fMeanMultiplicity[hs][chipNr]=NULL;
61 fHitEventEfficiency[hs][chipNr]=NULL;
62 }
63 }
de12e454 64 for (UInt_t hs=0; hs<6; hs++) {
65 fTPeffChip[hs]=NULL;
66 fDeadPixelChip[hs]=NULL;
67 fNoisyPixelChip[hs]=NULL;
68 }
69
6727e2db 70 for (UInt_t mod=0; mod<240; mod++) {
71 fbModuleScanned[mod]=kFALSE;
f0aa5f6c 72 }
73
6ddf3d66 74 Init(readFromGridFile);
f0aa5f6c 75}
de12e454 76//_________________________________________________________________________
f0aa5f6c 77AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const AliITSOnlineSPDscanAnalyzer& handle) :
de12e454 78 fType(99),fDacId(99),fFileName("."),fScanObj(NULL),fHandler(NULL),fTriggers(NULL),fTPeff(0),fTPeffHS(NULL),fDeadPixel(0),fDeadPixelHS(NULL),fNoisyPixel(0),fNoisyPixelHS(NULL),
f0aa5f6c 79 fOverWrite(kFALSE),fNoiseThreshold(0.01),fNoiseMinimumEvents(100),
6727e2db 80 fMinNrStepsBeforeIncrease(5),fMinIncreaseFromBaseLine(2),fStepDownDacSafe(5),fMaxBaseLineLevel(10)
f0aa5f6c 81{
6727e2db 82 // copy constructor, only copies the filename and params (not the processed data)
53ae21ce 83 fFileName=handle.fFileName;
6727e2db 84 fOverWrite=handle.fOverWrite;
85 fNoiseThreshold=handle.fNoiseThreshold;
86 fNoiseMinimumEvents=handle.fNoiseMinimumEvents;
87 fMinNrStepsBeforeIncrease=handle.fMinNrStepsBeforeIncrease;
88 fMinIncreaseFromBaseLine=handle.fMinIncreaseFromBaseLine;
89 fStepDownDacSafe=handle.fStepDownDacSafe;
90 fMaxBaseLineLevel=handle.fMaxBaseLineLevel;
f0aa5f6c 91
f0aa5f6c 92 for (UInt_t chipNr=0; chipNr<11; chipNr++) {
93 for (UInt_t hs=0; hs<6; hs++) {
94 fMeanMultiplicity[hs][chipNr]=NULL;
95 fHitEventEfficiency[hs][chipNr]=NULL;
96 }
97 }
de12e454 98 for (UInt_t hs=0; hs<6; hs++) {
99 fTPeffChip[hs]=NULL;
100 fDeadPixelChip[hs]=NULL;
101 fNoisyPixelChip[hs]=NULL;
102 }
103
6727e2db 104 for (UInt_t mod=0; mod<240; mod++) {
105 fbModuleScanned[mod]=kFALSE;
f0aa5f6c 106 }
107
108 Init();
109}
de12e454 110//_________________________________________________________________________
f0aa5f6c 111AliITSOnlineSPDscanAnalyzer::~AliITSOnlineSPDscanAnalyzer() {
112 // destructor
113 for (UInt_t hs=0; hs<6; hs++) {
114 for (UInt_t chipNr=0; chipNr<11; chipNr++) {
115 if (fMeanMultiplicity[hs][chipNr]!=NULL) {
116 delete fMeanMultiplicity[hs][chipNr];
de12e454 117 fMeanMultiplicity[hs][chipNr]=NULL;
f0aa5f6c 118 }
119 if (fHitEventEfficiency[hs][chipNr]!=NULL) {
120 delete fHitEventEfficiency[hs][chipNr];
de12e454 121 fHitEventEfficiency[hs][chipNr]=NULL;
f0aa5f6c 122 }
123 }
124 }
f0aa5f6c 125
de12e454 126 if (fTriggers!=NULL) {
127 delete fTriggers;
128 fTriggers=NULL;
129 }
130
131 DeleteUniformityHistograms();
132
133 if (fScanObj!=NULL) {
134 delete fScanObj;
135 fScanObj=NULL;
136 }
137}
138//_________________________________________________________________________
f0aa5f6c 139AliITSOnlineSPDscanAnalyzer& AliITSOnlineSPDscanAnalyzer::operator=(const AliITSOnlineSPDscanAnalyzer& handle) {
6727e2db 140 // assignment operator, only copies the filename and params (not the processed data)
f0aa5f6c 141 if (this!=&handle) {
142 for (UInt_t hs=0; hs<6; hs++) {
143 for (UInt_t chipNr=0; chipNr<11; chipNr++) {
144 if (fMeanMultiplicity[hs][chipNr]!=NULL) {
145 delete fMeanMultiplicity[hs][chipNr];
146 }
147 if (fHitEventEfficiency[hs][chipNr]!=NULL) {
148 delete fHitEventEfficiency[hs][chipNr];
149 }
150 }
151 }
de12e454 152 if (fTriggers!=NULL) {
153 delete fTriggers;
154 fTriggers=NULL;
155 }
156
157 DeleteUniformityHistograms();
158
159 if (fScanObj!=NULL) {
160 delete fScanObj;
161 fScanObj=NULL;
162 }
f0aa5f6c 163
53ae21ce 164 fFileName=handle.fFileName;
6727e2db 165 fOverWrite=handle.fOverWrite;
166 fNoiseThreshold=handle.fNoiseThreshold;
167 fNoiseMinimumEvents=handle.fNoiseMinimumEvents;
168 fMinNrStepsBeforeIncrease=handle.fMinNrStepsBeforeIncrease;
169 fMinIncreaseFromBaseLine=handle.fMinIncreaseFromBaseLine;
170 fStepDownDacSafe=handle.fStepDownDacSafe;
171 fMaxBaseLineLevel=handle.fMaxBaseLineLevel;
f0aa5f6c 172
f0aa5f6c 173 for (UInt_t chipNr=0; chipNr<11; chipNr++) {
174 for (UInt_t hs=0; hs<6; hs++) {
175 fMeanMultiplicity[hs][chipNr]=NULL;
176 fHitEventEfficiency[hs][chipNr]=NULL;
177 }
178 }
6727e2db 179 for (UInt_t mod=0; mod<240; mod++) {
180 fbModuleScanned[mod]=kFALSE;
f0aa5f6c 181 }
de12e454 182
6727e2db 183 fHandler=NULL;
f0aa5f6c 184
6727e2db 185 fType=99;
186 fDacId=99;
187
f0aa5f6c 188 Init();
189 }
190 return *this;
191}
de12e454 192//_________________________________________________________________________
6ddf3d66 193void AliITSOnlineSPDscanAnalyzer::Init(Bool_t readFromGridFile) {
f0aa5f6c 194 // first checks type of container and then initializes container obj
6ddf3d66 195 if (!readFromGridFile) {
196 FILE* fp0 = fopen(fFileName.Data(), "r");
197 if (fp0 == NULL) {
198 return;
199 }
200 else {
201 fclose(fp0);
202 }
f0aa5f6c 203 }
6ddf3d66 204
205 fScanObj = new AliITSOnlineSPDscan(fFileName.Data(),readFromGridFile);
f0aa5f6c 206 fType = fScanObj->GetType();
207 delete fScanObj;
208
209 // init container
210 switch(fType) {
211 case kUNIMA:
212 case kNOISE:
6ddf3d66 213 fScanObj = new AliITSOnlineSPDscanSingle(fFileName.Data(),readFromGridFile);
f0aa5f6c 214 break;
215 case kMINTH:
216 case kDAC:
217 case kDELAY:
6ddf3d66 218 fScanObj = new AliITSOnlineSPDscanMultiple(fFileName.Data(),readFromGridFile);
f0aa5f6c 219 fDacId = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacId();
220 break;
221 case kMEANTH:
6ddf3d66 222 fScanObj = new AliITSOnlineSPDscanMeanTh(fFileName.Data(),readFromGridFile);
f0aa5f6c 223 fDacId = ((AliITSOnlineSPDscanMeanTh*)fScanObj)->GetDacId();
224 break;
225 default:
53ae21ce 226 Error("AliITSOnlineSPDscanAnalyzer::Init","Type %d not defined!",fType);
f0aa5f6c 227 fScanObj=NULL;
228 return;
229 break;
230 }
231
f0aa5f6c 232}
de12e454 233//_________________________________________________________________________
53ae21ce 234void AliITSOnlineSPDscanAnalyzer::SetParam(const Char_t *pname, const Char_t *pval) {
235 // set a parameter
236 TString name = pname;
237 TString val = pval;
238 if (name.CompareTo("fOverWrite")==0) {
6727e2db 239 if (val.CompareTo("YES")==0 || val.CompareTo("1")==0) {
53ae21ce 240 fOverWrite = kTRUE;
241 }
6727e2db 242 else fOverWrite = kFALSE;
53ae21ce 243 }
244 else if (name.CompareTo("fNoiseThreshold")==0) {
245 fNoiseThreshold = val.Atof();
246 }
247 else if (name.CompareTo("fNoiseMinimumEvents")==0) {
248 fNoiseMinimumEvents = val.Atoi();
249 }
250 else if (name.CompareTo("fMinNrStepsBeforeIncrease")==0) {
251 fMinNrStepsBeforeIncrease = val.Atoi();
252 }
253 else if (name.CompareTo("fMinIncreaseFromBaseLine")==0) {
254 fMinIncreaseFromBaseLine = val.Atof();
255 }
256 else if (name.CompareTo("fStepDownDacSafe")==0) {
257 fStepDownDacSafe = val.Atoi();
258 }
259 else if (name.CompareTo("fMaxBaseLineLevel")==0) {
260 fMaxBaseLineLevel = val.Atof();
261 }
262 else {
263 Error("AliITSOnlineSPDscanAnalyzer::SetParam","Parameter %s in configuration file unknown.",name.Data());
264 }
265}
de12e454 266//_________________________________________________________________________
6727e2db 267void AliITSOnlineSPDscanAnalyzer::ReadParamsFromLocation(const Char_t *dirName) {
268 // opens file (default name) in dir dirName and reads parameters from it
269 TString paramsFileName = Form("%s/standal_params.txt",dirName);
270 ifstream paramsFile;
271 paramsFile.open(paramsFileName, ifstream::in);
272 if (paramsFile.fail()) {
273 printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
274 }
275 else {
276 while(1) {
277 Char_t paramN[50];
278 Char_t paramV[50];
279 paramsFile >> paramN;
280 if (paramsFile.eof()) break;
281 paramsFile >> paramV;
282 SetParam(paramN,paramV);
283 if (paramsFile.eof()) break;
284 }
285 paramsFile.close();
286 }
287}
de12e454 288//_________________________________________________________________________
4f88491f 289Bool_t AliITSOnlineSPDscanAnalyzer::IsChipPresent(UInt_t hs, UInt_t chipNr) {
290 // is the chip present?
291 if (fScanObj==NULL) {
292 Warning("AliITSOnlineSPDscanAnalyzer::IsChipPresent","No data!");
293 return kFALSE;
6727e2db 294 }
4f88491f 295 return fScanObj->GetChipPresent(hs,chipNr);
6727e2db 296}
de12e454 297//_________________________________________________________________________
6727e2db 298Bool_t AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels(/*Char_t *oldcalibDir*/) {
53ae21ce 299 // process dead pixel data, for uniformity scan,
300 // NB: This will not be the general way of finding dead pixels.
f0aa5f6c 301 if (fScanObj==NULL) {
53ae21ce 302 Warning("AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels","No data!");
f0aa5f6c 303 return kFALSE;
304 }
305 // should be type kUNIMA
306 if (fType!=kUNIMA) {
53ae21ce 307 Warning("AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels","Dead pixels only for scan type %d.",kUNIMA);
f0aa5f6c 308 return kFALSE;
309 }
6727e2db 310 // handler should be initialized
311 if (fHandler==NULL) {
312 Error("AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels","Calibration handler is not initialized!");
313 return kFALSE;
314 }
f0aa5f6c 315
f0aa5f6c 316 UInt_t routerNr = fScanObj->GetRouterNr();
317 UInt_t rowStart = fScanObj->GetRowStart();
318 UInt_t rowEnd = fScanObj->GetRowEnd();
319 for (UInt_t hs=0; hs<6; hs++) {
320 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
321 if (fScanObj->GetChipPresent(hs,chipNr) && fScanObj->GetAverageMultiplicity(0,hs,chipNr)>0) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4f88491f 322 if (fOverWrite) {fHandler->ResetDeadForChip(routerNr,hs,chipNr);}
f0aa5f6c 323 for (UInt_t col=0; col<32; col++) {
324 for (UInt_t row=rowStart; row<=rowEnd; row++) {
325 if (col!=1 && col!=9 && col!=17 && col!=25) { //exclude test columns!!!
326 if (fScanObj->GetHits(0,hs,chipNr,col,row)==0) {
6727e2db 327 fHandler->SetDeadPixel(routerNr,hs,chipNr,col,row);
f0aa5f6c 328 }
329 }
330 }
331 }
332 }
333 }
334 }
335 return kTRUE;
336}
de12e454 337//_________________________________________________________________________
338Bool_t AliITSOnlineSPDscanAnalyzer::ProcessUniformity() {
339 // process uniformity scan data (thanks to Roberta Ferretti for providing this method)
340 if (fScanObj==NULL) {
341 Warning("AliITSOnlineSPDscanAnalyzer::ProcessUniformity","No data!");
342 return kFALSE;
343 }
344 // should be type kUNIMA
345 if (fType!=kUNIMA) {
346 Warning("AliITSOnlineSPDscanAnalyzer::ProcessUniformity","Only for scan type %d.",kUNIMA);
347 return kFALSE;
348 }
f0aa5f6c 349
de12e454 350 CreateUniformityHistograms(); // create all histograms that will be filled here
f0aa5f6c 351
de12e454 352 // UInt_t routerNr = fScanObj->GetRouterNr();
353 UInt_t rowStart = fScanObj->GetRowStart();
354 UInt_t rowEnd = fScanObj->GetRowEnd();
355 UInt_t NrTriggers = fScanObj->GetTriggers(0)/(rowEnd-rowStart+1);
356
357 Float_t pixel100=0;
358 Float_t zeri=0;
359 Float_t pixelN=0;
360 UInt_t numChipsActive=0;
361
362 for (UInt_t hs=0; hs<6; hs++) {
363 Float_t pixel100hs=0;
364 Float_t zerihs=0;
365 Float_t pixelNhs=0;
366 UInt_t numChipsActiveHS=0;
367
368 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
369 Float_t pixel100chip=0;
370 Float_t zerichip=0;
371 Float_t pixelNchip=0;
372
373 if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
374 numChipsActive++;
375 numChipsActiveHS++;
f0aa5f6c 376
de12e454 377 for (UInt_t col=0; col<32; col++) {
378 for (UInt_t row=rowStart; row<=rowEnd; row++) {
379 if (col!=1 && col!=9 && col!=17 && col!=25) { //exclude test columns!!!
380
381 if (fScanObj->GetHits(0,hs,chipNr,col,row)==NrTriggers) {
382 pixel100++;
383 pixel100hs++;
384 pixel100chip++;
385 }
386 if (fScanObj->GetHits(0,hs,chipNr,col,row)==0) {
387 zeri++;
388 zerihs++;
389 zerichip++;
390 }
391 if (fScanObj->GetHits(0,hs,chipNr,col,row)>NrTriggers) {
392 pixelN++;
393 pixelNhs++;
394 pixelNchip++;
395 }
396 }
397 }
398 }
399
400 Float_t TPeffChip=(pixel100chip/(28*(rowEnd-rowStart+1)))*100;
401 fTPeffChip[hs]->Fill(chipNr,TPeffChip);
402
403 Float_t DeadPixelChip=(zerichip/(28*(rowEnd-rowStart+1)))*100;
404 fDeadPixelChip[hs]->Fill(chipNr,DeadPixelChip);
405
406 Float_t NoisyPixelChip=(pixelNchip/(28*(rowEnd-rowStart+1)))*100;
407 fNoisyPixelChip[hs]->Fill(chipNr,NoisyPixelChip);
408 }
409 }
410
411 Float_t TPeffHS=(pixel100hs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
412 fTPeffHS->Fill(hs,TPeffHS);
413
414 Float_t DeadPixelHS=(zerihs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
415 fDeadPixelHS->Fill(hs,DeadPixelHS);
416
417 Float_t NoisyPixelHS=(pixelNhs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
418 fNoisyPixelHS->Fill(hs,NoisyPixelHS);
419 }
420
421 fTPeff=(pixel100/(28*numChipsActive*(rowEnd-rowStart+1)))*100;
422 fDeadPixel=(zeri/(28*numChipsActive*(rowEnd-rowStart+1)))*100;
423 fNoisyPixel=(pixelN/(28*numChipsActive*(rowEnd-rowStart+1)))*100;
424
425 return kTRUE;
426}
427//_________________________________________________________________________
428void AliITSOnlineSPDscanAnalyzer::CreateUniformityHistograms() {
429 // create uniformity histograms to be filled by "ProcessUniformity" method
430 DeleteUniformityHistograms(); // make sure no old histograms are lying around...
431 UInt_t eq = GetRouterNr();
432 TString label;
433
434 label = Form("Ratio of 'Good' Pixels Per HS (eq %d)",eq);
435 fTPeffHS = new TH1F(label.Data(),label.Data(),6,-0.5,5.5);
436 fTPeffHS->SetXTitle("hs");
437 fTPeffHS->SetYTitle("ratio [%]");
438 fTPeffHS->SetFillColor(kBlue);
439 fTPeffHS->SetStats(0);
440
441 label = Form("Ratio of 'Dead' Pixels Per HS (eq %d)",eq);
442 fDeadPixelHS = new TH1F(label.Data(),label.Data(),6,-0.5,5.5);
443 fDeadPixelHS->SetXTitle("hs");
444 fDeadPixelHS->SetYTitle("ratio [%]");
445 fDeadPixelHS->SetFillColor(kBlue);
446 fDeadPixelHS->SetStats(0);
447
448 label = Form("Ratio of 'Noisy' Pixels Per HS (eq %d)",eq);
449 fNoisyPixelHS = new TH1F(label.Data(),label.Data(),6,-0.5,5.5);
450 fNoisyPixelHS->SetXTitle("hs");
451 fNoisyPixelHS->SetYTitle("ratio [%]");
452 fNoisyPixelHS->SetFillColor(kBlue);
453 fNoisyPixelHS->SetStats(0);
454
455 for (UInt_t hs=0; hs<6; hs++) {
456 label = Form("Ratio of 'Good' Pixels Per Chip (eq %d, hs %d)",eq,hs);
457 fTPeffChip[hs] = new TH1F(label.Data(),label.Data(),10,-0.5,9.5);
458 fTPeffChip[hs]->SetXTitle("chip");
459 fTPeffChip[hs]->SetYTitle("ratio [%]");
460 fTPeffChip[hs]->SetFillColor(kBlue);
461 fTPeffChip[hs]->SetStats(0);
462
463 label = Form("Ratio of 'Dead' Pixels Per Chip (eq %d, hs %d)",eq,hs);
464 fDeadPixelChip[hs] = new TH1F(label.Data(),label.Data(),10,-0.5,9.5);
465 fDeadPixelChip[hs]->SetXTitle("chip");
466 fDeadPixelChip[hs]->SetYTitle("ratio [%]");
467 fDeadPixelChip[hs]->SetFillColor(kBlue);
468 fDeadPixelChip[hs]->SetStats(0);
469
470 label = Form("Ratio of 'Noisy' Pixels Per Chip (eq %d, hs %d)",eq,hs);
471 fNoisyPixelChip[hs] = new TH1F(label.Data(),label.Data(),10,-0.5,9.5);
472 fNoisyPixelChip[hs]->SetXTitle("chip");
473 fNoisyPixelChip[hs]->SetYTitle("ratio [%]");
474 fNoisyPixelChip[hs]->SetFillColor(kBlue);
475 fNoisyPixelChip[hs]->SetStats(0);
476 }
477
478}
479//_________________________________________________________________________
480void AliITSOnlineSPDscanAnalyzer::DeleteUniformityHistograms() {
481 // remove uniformity histograms if they are created
482 if (fTPeffHS!=NULL) {
483 delete fTPeffHS;
484 fTPeffHS=NULL;
485 }
486 if (fDeadPixelHS!=NULL) {
487 delete fDeadPixelHS;
488 fDeadPixelHS=NULL;
489 }
490 if (fNoisyPixelHS!=NULL) {
491 delete fNoisyPixelHS;
492 fNoisyPixelHS=NULL;
493 }
494 for (UInt_t hs=0; hs<6; hs++) {
495 if (fTPeffChip[hs]!=NULL) {
496 delete fTPeffChip[hs];
497 fTPeffChip[hs]=NULL;
498 }
499 if (fDeadPixelChip[hs]!=NULL) {
500 delete fDeadPixelChip[hs];
501 fDeadPixelChip[hs]=NULL;
502 }
503 if (fNoisyPixelChip[hs]!=NULL) {
504 delete fNoisyPixelChip[hs];
505 fNoisyPixelChip[hs]=NULL;
506 }
507 }
508}
509//_________________________________________________________________________
6727e2db 510Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels(/*Char_t *oldcalibDir*/) {
f0aa5f6c 511 // process noisy pixel data
512 if (fScanObj==NULL) {
53ae21ce 513 Warning("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","No data!");
f0aa5f6c 514 return kFALSE;
515 }
516 // should be type kNOISE
517 if (fType != kNOISE) {
53ae21ce 518 Warning("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","Noisy pixels only for scan type %d.",kNOISE);
f0aa5f6c 519 return kFALSE;
520 }
6727e2db 521 // handler should be initialized
522 if (fHandler==NULL) {
523 Error("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","Calibration handler is not initialized!");
524 return kFALSE;
525 }
526 // check if enough statistics
f0aa5f6c 527 if (fScanObj->GetTriggers(0)<fNoiseMinimumEvents) {
53ae21ce 528 Warning("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","Process noisy: Too few events.");
f0aa5f6c 529 return kFALSE;
530 }
6727e2db 531
f0aa5f6c 532 UInt_t routerNr = fScanObj->GetRouterNr();
533 for (UInt_t hs=0; hs<6; hs++) {
534 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
535 if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4f88491f 536 if (fOverWrite) {fHandler->ResetNoisyForChip(routerNr,hs,chipNr);}
f0aa5f6c 537 for (UInt_t col=0; col<32; col++) {
538 for (UInt_t row=0; row<256; row++) {
539 if (fScanObj->GetHitsEfficiency(0,hs,chipNr,col,row)>fNoiseThreshold) {
6727e2db 540 fHandler->SetNoisyPixel(routerNr,hs,chipNr,col,row);
f0aa5f6c 541 }
542 }
543 }
544 }
545 }
546 }
547 return kTRUE;
548}
de12e454 549//_________________________________________________________________________
f0aa5f6c 550Int_t AliITSOnlineSPDscanAnalyzer::GetDelay(UInt_t hs, UInt_t chipNr) {
551 // get delay
552 if (hs>=6 || chipNr>10) return -1;
553 if (fScanObj==NULL) {
53ae21ce 554 Warning("AliITSOnlineSPDscanAnalyzer::GetDelay","No data!");
f0aa5f6c 555 return -1;
556 }
557 // should be type kDELAY or kDAC with id 42 (delay_ctrl)
558 if (fType!=kDELAY && (fType!=kDAC || fDacId!=42)) {
53ae21ce 559 Warning("AliITSOnlineSPDscanAnalyzer::GetDelay","Delay only for scan type %d or %d and dac_id 42.",kDELAY,kDAC);
f0aa5f6c 560 return -1;
561 }
562 if (fMeanMultiplicity[hs][chipNr]==NULL) {
563 if (!ProcessMeanMultiplicity()) {
564 return -1;
565 }
566 }
567
1fd93b67 568 UInt_t maxStep=0;
569 Float_t maxVal=0;
570 for (UInt_t step=0; step<fScanObj->GetNSteps(); step++) {
571 Double_t thisDac;
572 Double_t thisMult;
573 fMeanMultiplicity[hs][chipNr]->GetPoint(step,thisDac,thisMult);
574 if (thisMult > maxVal) {
575 maxVal = thisMult;
576 maxStep = step;
577 }
578 }
579
580 if (maxVal>0) {
581 return ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(maxStep);
f0aa5f6c 582 }
583 else {
584 return -1;
585 }
1fd93b67 586
f0aa5f6c 587}
de12e454 588//_________________________________________________________________________
f0aa5f6c 589Int_t AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima(UInt_t hs, UInt_t chipNr) {
590 // in case of a uniformity scan, returns the nr of noisy pixels, (here > 200 hits)
591 if (hs>=6 || chipNr>10) return -1;
592 if (fScanObj==NULL) {
53ae21ce 593 Error("AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima","No data!");
f0aa5f6c 594 return kFALSE;
595 }
596 // should be type kUNIMA
597 if (fType != kUNIMA) {
53ae21ce 598 Error("AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima","Noisy pixels Unima only for scan type %d.",kUNIMA);
f0aa5f6c 599 return kFALSE;
600 }
601 if (fScanObj->GetTriggers(0)!=25600) {
53ae21ce 602 Error("AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima","Process noisy unima: Incorrect number of events (!=25600.");
f0aa5f6c 603 return kFALSE;
604 }
605
606 Int_t nrNoisy=0;
607 if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
608 for (UInt_t col=0; col<32; col++) {
609 for (UInt_t row=0; row<256; row++) {
610 if (fScanObj->GetHits(0,hs,chipNr,col,row)>200) {
611 nrNoisy++;
612 }
613 }
614 }
615 }
616 else {
617 return -1;
618 }
619 return nrNoisy;
620}
de12e454 621//_________________________________________________________________________
f0aa5f6c 622Int_t AliITSOnlineSPDscanAnalyzer::FindLastMinThDac(UInt_t hs, UInt_t chipNr) {
623 // returns dac value where fMinIncreaseFromBaseLine reached
624 if (hs>=6 || chipNr>10) return -1;
625 if (fMeanMultiplicity[hs][chipNr]==NULL) {
626 if (!ProcessMeanMultiplicity()) {
627 return -1;
628 }
629 }
630 Double_t firstVal, dummy1;
631 fMeanMultiplicity[hs][chipNr]->GetPoint(0,dummy1,firstVal);
632 UInt_t step=0;
633 while (step<fScanObj->GetNSteps()-1) {
634 Double_t graphVal, dummy2;
635 fMeanMultiplicity[hs][chipNr]->GetPoint(step+1,dummy2,graphVal);
636 if (graphVal>firstVal+fMinIncreaseFromBaseLine) break;
637 step++;
638 }
639 if (step==fScanObj->GetNSteps()-1) return -1;
640 return ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step);
641}
642
643Int_t AliITSOnlineSPDscanAnalyzer::FindClosestLowerStep(Float_t dacValueInput) {
644 // returns step closest (lower) to a dacvalue
645 UInt_t step=0;
646 while (step<fScanObj->GetNSteps()-1) {
647 Int_t dacVal = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step+1);
648 if (dacVal>=dacValueInput) break;
649 step++;
650 }
651 return step;
652}
de12e454 653//_________________________________________________________________________
f0aa5f6c 654Float_t AliITSOnlineSPDscanAnalyzer::GetCompareLine(UInt_t step, UInt_t hs, UInt_t chipNr, Float_t basePar2) {
655 // returns value to compare mean mult with (when finding min th)
656 if (hs>=6 || chipNr>10) return -1;
657 if (step<fMinNrStepsBeforeIncrease) return -1;
658 Float_t baseLine = basePar2;
659 if (baseLine<0) baseLine=0;
660 Float_t baseAdd;
661 Double_t baseM=0;
662 Double_t baseS=0;
663 Double_t d,m;
664 for (UInt_t st=1;st<2*step/3;st++) { // skip first point...
665 fMeanMultiplicity[hs][chipNr]->GetPoint(st,d,m);
666 baseM+=m-baseLine;
667 baseS+=(m-baseLine)*(m-baseLine);
668 }
669 baseAdd=2*sqrt( baseS/(2*step/3-1) - (baseM/(2*step/3-1))*(baseM/(2*step/3-1)) );
670 baseAdd+=0.03; // magic number
671 if (baseAdd>fMinIncreaseFromBaseLine) baseAdd=fMinIncreaseFromBaseLine;
672 return baseLine + baseAdd;
673}
674
675Int_t AliITSOnlineSPDscanAnalyzer::GetMinTh(UInt_t hs, UInt_t chipNr) {
676 // calculates and returns the minimum threshold
677 if (hs>=6 || chipNr>10) return -1;
678 if (fScanObj==NULL) {
53ae21ce 679 Error("AliITSOnlineSPDscanAnalyzer::GetMinTh","No data!");
f0aa5f6c 680 return -1;
681 }
682 // should be type kMINTH or kDAC with id 39 (pre_vth)
683 if (fType!=kMINTH && (fType!=kDAC || fDacId!=39)) {
53ae21ce 684 Error("AliITSOnlineSPDscanAnalyzer::GetMinTh","MinTh only for scan type %d OR %d with dac_id 39.",kMINTH,kDAC);
f0aa5f6c 685 return -1;
686 }
687 if (fMeanMultiplicity[hs][chipNr]==NULL) {
688 if (!ProcessMeanMultiplicity()) {
689 return -1;
690 }
691 }
692
693 Int_t lastDac = FindLastMinThDac(hs,chipNr);
694 if (lastDac==-1) {
53ae21ce 695 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: Increase of Mean Multiplicity by %1.2f never reached.",hs,chipNr,fMinIncreaseFromBaseLine);
f0aa5f6c 696 return -1;
697 }
698
699 Int_t minDac = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(0);
53ae21ce 700 TString funcName = Form("Fit minth func HS%d CHIP%d",hs,chipNr);
701 TF1 *minThFunc = new TF1(funcName.Data(),itsSpdErrorf,100,500,3);
f0aa5f6c 702 minThFunc->SetParameter(0,lastDac+10);
703 minThFunc->SetParameter(1,2);
704 minThFunc->SetParameter(2,0);
705 minThFunc->SetParName(0,"Mean");
706 minThFunc->SetParName(1,"Sigma");
707 minThFunc->SetParName(2,"BaseLine");
708 minThFunc->SetLineWidth(1);
709 if (fMeanMultiplicity[hs][chipNr]==NULL) {
710 if (!ProcessMeanMultiplicity()) {
711 return -1;
712 }
713 }
714 fMeanMultiplicity[hs][chipNr]->Fit(funcName,"Q0","",minDac,lastDac);
715
716 // Double_t mean = fMinThFunc[hs][chipNr]->GetParameter(0);
717 // Double_t sigma = fMinThFunc[hs][chipNr]->GetParameter(1);
718 Double_t baseLine = minThFunc->GetParameter(2);
719 delete minThFunc;
720
721 if (baseLine>fMaxBaseLineLevel) {
53ae21ce 722 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: BaseLine too large (%1.2f>%1.2f).",hs,chipNr,baseLine,fMaxBaseLineLevel);
f0aa5f6c 723 return -1;
724 }
725 UInt_t step=FindClosestLowerStep(lastDac);
726 Float_t compareLine = GetCompareLine(step,hs,chipNr,baseLine);
727 if (compareLine==-1) {
53ae21ce 728 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: Not enough steps (%d<%d) before increase to get a compare line.",hs,chipNr,step,fMinNrStepsBeforeIncrease);
f0aa5f6c 729 return -1;
730 }
731
732 Double_t mult, dummy;
733 mult=1000;
734 while (mult > compareLine && step>0) {
735 fMeanMultiplicity[hs][chipNr]->GetPoint(step,dummy,mult);
736 step--;
737 }
738 Int_t minth = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step+1)-fStepDownDacSafe;
739
740 if (step>0) {
741 return minth;
742 }
743 else {
53ae21ce 744 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: Did not find a point below the compare line (%f).",hs,chipNr,compareLine);
f0aa5f6c 745 return -1;
746 }
747}
de12e454 748//_________________________________________________________________________
f0aa5f6c 749Bool_t AliITSOnlineSPDscanAnalyzer::ProcessMeanMultiplicity() {
750 // process mean multiplicity data
751 if (fScanObj==NULL) {
53ae21ce 752 Error("AliITSOnlineSPDscanAnalyzer::ProcessMeanMultiplicity","No data!");
f0aa5f6c 753 return kFALSE;
754 }
755 for (UInt_t step=0; step<fScanObj->GetNSteps(); step++) {
756 for (UInt_t hs=0; hs<6; hs++) {
757 for (UInt_t chipNr=0; chipNr<11; chipNr++) {
758 // if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
759 if (step==0) {
760 if (fMeanMultiplicity[hs][chipNr]!=NULL) {
761 delete fMeanMultiplicity[hs][chipNr];
762 }
763 fMeanMultiplicity[hs][chipNr] = new TGraph();
764 }
765 Float_t multiplMean=fScanObj->GetAverageMultiplicity(step,hs,chipNr);
766 if (fType==kMINTH || fType==kMEANTH || fType==kDAC || fType==kDELAY) {
767 fMeanMultiplicity[hs][chipNr]->SetPoint(step,((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step),multiplMean);
768 }
769 else {
770 fMeanMultiplicity[hs][chipNr]->SetPoint(step,0,multiplMean);
771 }
772 }
773 // }
774 }
775 }
776 return kTRUE;
777}
de12e454 778//_________________________________________________________________________
f0aa5f6c 779TGraph* AliITSOnlineSPDscanAnalyzer::GetMeanMultiplicityG(UInt_t hs, UInt_t chipNr) {
780 // returns mean multiplicity graph
781 if (hs>=6 || chipNr>10) return NULL;
782 if (fMeanMultiplicity[hs][chipNr]==NULL) {
783 if (!ProcessMeanMultiplicity()) {
784 return NULL;
785 }
786 }
787 return fMeanMultiplicity[hs][chipNr];
788}
de12e454 789//_________________________________________________________________________
f0aa5f6c 790Bool_t AliITSOnlineSPDscanAnalyzer::ProcessHitEventEfficiency() {
791 // process hit event efficiency
792 if (fScanObj==NULL) {
53ae21ce 793 Error("AliITSOnlineSPDscanAnalyzer::ProcessHitEventEfficiency","No data!");
f0aa5f6c 794 return kFALSE;
795 }
796 for (UInt_t step=0; step<fScanObj->GetNSteps(); step++) {
797 for (UInt_t hs=0; hs<6; hs++) {
798 for (UInt_t chipNr=0; chipNr<11; chipNr++) {
799 // if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
800 if (step==0) {
801 if (fHitEventEfficiency[hs][chipNr]!=NULL) {
802 delete fHitEventEfficiency[hs][chipNr];
803 }
804 fHitEventEfficiency[hs][chipNr] = new TGraph();
805 }
806 Float_t efficiency=fScanObj->GetHitEventsEfficiency(step,hs,chipNr);
807 if (fType==kMINTH || fType==kMEANTH || fType==kDAC || fType==kDELAY) {
808 fHitEventEfficiency[hs][chipNr]->SetPoint(step,((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step),efficiency);
809 }
810 else {
811 fHitEventEfficiency[hs][chipNr]->SetPoint(step,0,efficiency);
812 }
813 }
814 // }
815 }
816 }
817 return kTRUE;
818}
de12e454 819//_________________________________________________________________________
f0aa5f6c 820TGraph* AliITSOnlineSPDscanAnalyzer::GetHitEventEfficiencyG(UInt_t hs, UInt_t chipNr) {
821 // returns hit event efficiency graph
822 if (hs>=6 || chipNr>10) return NULL;
823 if (fHitEventEfficiency[hs][chipNr]==NULL) {
824 if (!ProcessHitEventEfficiency()) {
825 return NULL;
826 }
827 }
828 return fHitEventEfficiency[hs][chipNr];
829}
de12e454 830//_________________________________________________________________________
f0aa5f6c 831Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNrTriggers() {
832 // process nr of triggers data
833 if (fScanObj==NULL) {
53ae21ce 834 Error("AliITSOnlineSPDscanAnalyzer::ProcessNrTriggers","No data!");
f0aa5f6c 835 return kFALSE;
836 }
837 for (UInt_t step=0; step<fScanObj->GetNSteps(); step++) {
838 if (step==0) {
839 if (fTriggers!=NULL) {
840 delete fTriggers;
841 }
842 fTriggers = new TGraph();
843 }
844 if (fType==kMINTH || fType==kMEANTH || fType==kDAC || fType==kDELAY) {
845 fTriggers->SetPoint(step,((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step),fScanObj->GetTriggers(step));
846 }
847 else {
848 fTriggers->SetPoint(step,0,fScanObj->GetTriggers(step));
849 }
850 }
851 return kTRUE;
852}
de12e454 853//_________________________________________________________________________
f0aa5f6c 854TGraph* AliITSOnlineSPDscanAnalyzer::GetNrTriggersG() {
855 // returns nr of triggers graph
856 if (fTriggers==NULL) {
857 if (!ProcessNrTriggers()) {
858 return NULL;
859 }
860 }
861 return fTriggers;
862}
de12e454 863//_________________________________________________________________________
f0aa5f6c 864Bool_t AliITSOnlineSPDscanAnalyzer::GetHalfStavePresent(UInt_t hs) {
865 // returns half stave present info
866 if (hs<6 && fScanObj!=NULL) {
867 Int_t chipstatus=0;
868 for (Int_t chip=0; chip<10; chip++) {
869 chipstatus+=fScanObj->GetChipPresent(hs,chip);
870 }
871 if (chipstatus>0) return kTRUE;
872 }
873 return kFALSE;
874}
de12e454 875//_________________________________________________________________________
f0aa5f6c 876UInt_t AliITSOnlineSPDscanAnalyzer::GetRouterNr() {
877 // returns the router nr of scan obj
878 if (fScanObj!=NULL) return fScanObj->GetRouterNr();
879 else return 99;
880}
de12e454 881//_________________________________________________________________________
f0aa5f6c 882TH2F* AliITSOnlineSPDscanAnalyzer::GetHitMapTot(UInt_t step) {
883 // creates and returns a pointer to a hitmap histo (half sector style a la spdmood)
884 if (fScanObj==NULL) {
53ae21ce 885 Error("AliITSOnlineSPDscanAnalyzer::GetHitMapTot","No data!");
f0aa5f6c 886 return NULL;
887 }
53ae21ce 888 TString histoname;
f0aa5f6c 889 if (fType==kMINTH || fType==kMEANTH || fType==kDAC) {
53ae21ce 890 histoname = Form("Router %d , DAC %d",GetRouterNr(),((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step));
f0aa5f6c 891 }
892 else {
53ae21ce 893 histoname = Form("Router %d ",GetRouterNr());
f0aa5f6c 894 }
53ae21ce 895 TH2F* fHitMapTot = new TH2F(histoname.Data(),histoname.Data(),32*10,-0.5,32*10-0.5,256*6,-0.5,256*6-0.5);
f0aa5f6c 896 fHitMapTot->SetNdivisions(-10,"X");
897 fHitMapTot->SetNdivisions(-006,"Y");
898 fHitMapTot->SetTickLength(0,"X");
899 fHitMapTot->SetTickLength(0,"Y");
900 fHitMapTot->GetXaxis()->SetLabelColor(gStyle->GetCanvasColor());
901 fHitMapTot->GetYaxis()->SetLabelColor(gStyle->GetCanvasColor());
902 for (UInt_t hs=0; hs<6; hs++) {
903 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
904 for (UInt_t col=0; col<32; col++) {
905 for (UInt_t row=0; row<256; row++) {
906 fHitMapTot->Fill(chipNr*32+col,(5-hs)*256+row,fScanObj->GetHits(step,hs,chipNr,col,row));
907 }
908 }
909 }
910 }
911 return fHitMapTot;
912}
de12e454 913//_________________________________________________________________________
6727e2db 914TH2F* AliITSOnlineSPDscanAnalyzer::GetHitMapChip(UInt_t step, UInt_t hs, UInt_t chip) {
915 // creates and returns a pointer to a hitmap histo (chip style a la spdmood)
916 if (fScanObj==NULL) {
917 Error("AliITSOnlineSPDscanAnalyzer::GetHitMapChip","No data!");
918 return NULL;
919 }
920
921 TString histoName;
922 TString histoTitle;
923 histoName = Form("fChipHisto_%d_%d_%d", GetRouterNr(), hs, chip);
924 histoTitle = Form("Eq ID %d, Half Stave %d, Chip %d", GetRouterNr(), hs, chip);
925
926 TH2F *returnHisto = new TH2F(histoName.Data(), histoTitle.Data(), 32, -0.5, 31.5, 256, -0.5, 255.5);
927 returnHisto->SetMinimum(0);
928 for (UInt_t col=0; col<32; col++) {
929 for (UInt_t row=0; row<256; row++) {
930 returnHisto->Fill(col,row,fScanObj->GetHits(step,hs,chip,col,row));
931 }
932 }
933
934 return returnHisto;
935}
de12e454 936