1 /**************************************************************************
2 * Copyright(c) 2007-2009, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////////////////////////////
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 //
23 // threshold values can be extracted. //
24 ////////////////////////////////////////////////////////////
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"
42 Double_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.)));
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.));
51 //_________________________________________________________________________
52 AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const Char_t *fileName, AliITSOnlineCalibrationSPDhandler *handler, Bool_t readFromGridFile) :
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),
54 fOverWrite(kFALSE),fNoiseThreshold(0.01),fNoiseMinimumEvents(100),
55 fMinNrStepsBeforeIncrease(5),fMinIncreaseFromBaseLine(2),fStepDownDacSafe(5),fMaxBaseLineLevel(10)
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;
64 for (UInt_t hs=0; hs<6; hs++) {
66 fDeadPixelChip[hs]=NULL;
67 fNoisyPixelChip[hs]=NULL;
70 for (UInt_t mod=0; mod<240; mod++) {
71 fbModuleScanned[mod]=kFALSE;
74 Init(readFromGridFile);
76 //_________________________________________________________________________
77 AliITSOnlineSPDscanAnalyzer::AliITSOnlineSPDscanAnalyzer(const AliITSOnlineSPDscanAnalyzer& handle) :
78 fType(99),fDacId(99),fFileName("."),fScanObj(NULL),fHandler(NULL),fTriggers(NULL),fTPeff(0),fTPeffHS(NULL),fDeadPixel(0),fDeadPixelHS(NULL),fNoisyPixel(0),fNoisyPixelHS(NULL),
79 fOverWrite(kFALSE),fNoiseThreshold(0.01),fNoiseMinimumEvents(100),
80 fMinNrStepsBeforeIncrease(5),fMinIncreaseFromBaseLine(2),fStepDownDacSafe(5),fMaxBaseLineLevel(10)
82 // copy constructor, only copies the filename and params (not the processed data)
83 fFileName=handle.fFileName;
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;
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;
98 for (UInt_t hs=0; hs<6; hs++) {
100 fDeadPixelChip[hs]=NULL;
101 fNoisyPixelChip[hs]=NULL;
104 for (UInt_t mod=0; mod<240; mod++) {
105 fbModuleScanned[mod]=kFALSE;
110 //_________________________________________________________________________
111 AliITSOnlineSPDscanAnalyzer::~AliITSOnlineSPDscanAnalyzer() {
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];
117 fMeanMultiplicity[hs][chipNr]=NULL;
119 if (fHitEventEfficiency[hs][chipNr]!=NULL) {
120 delete fHitEventEfficiency[hs][chipNr];
121 fHitEventEfficiency[hs][chipNr]=NULL;
126 if (fTriggers!=NULL) {
131 DeleteUniformityHistograms();
133 if (fScanObj!=NULL) {
138 //_________________________________________________________________________
139 AliITSOnlineSPDscanAnalyzer& AliITSOnlineSPDscanAnalyzer::operator=(const AliITSOnlineSPDscanAnalyzer& handle) {
140 // assignment operator, only copies the filename and params (not the processed data)
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];
147 if (fHitEventEfficiency[hs][chipNr]!=NULL) {
148 delete fHitEventEfficiency[hs][chipNr];
152 if (fTriggers!=NULL) {
157 DeleteUniformityHistograms();
159 if (fScanObj!=NULL) {
164 fFileName=handle.fFileName;
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;
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;
179 for (UInt_t mod=0; mod<240; mod++) {
180 fbModuleScanned[mod]=kFALSE;
192 //_________________________________________________________________________
193 void AliITSOnlineSPDscanAnalyzer::Init(Bool_t readFromGridFile) {
194 // first checks type of container and then initializes container obj
195 if (!readFromGridFile) {
196 FILE* fp0 = fopen(fFileName.Data(), "r");
205 fScanObj = new AliITSOnlineSPDscan(fFileName.Data(),readFromGridFile);
206 fType = fScanObj->GetType();
213 fScanObj = new AliITSOnlineSPDscanSingle(fFileName.Data(),readFromGridFile);
218 fScanObj = new AliITSOnlineSPDscanMultiple(fFileName.Data(),readFromGridFile);
219 fDacId = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacId();
222 fScanObj = new AliITSOnlineSPDscanMeanTh(fFileName.Data(),readFromGridFile);
223 fDacId = ((AliITSOnlineSPDscanMeanTh*)fScanObj)->GetDacId();
226 Error("AliITSOnlineSPDscanAnalyzer::Init","Type %d not defined!",fType);
233 //_________________________________________________________________________
234 void AliITSOnlineSPDscanAnalyzer::SetParam(const Char_t *pname, const Char_t *pval) {
236 TString name = pname;
238 if (name.CompareTo("fOverWrite")==0) {
239 if (val.CompareTo("YES")==0 || val.CompareTo("1")==0) {
242 else fOverWrite = kFALSE;
244 else if (name.CompareTo("fNoiseThreshold")==0) {
245 fNoiseThreshold = val.Atof();
247 else if (name.CompareTo("fNoiseMinimumEvents")==0) {
248 fNoiseMinimumEvents = val.Atoi();
250 else if (name.CompareTo("fMinNrStepsBeforeIncrease")==0) {
251 fMinNrStepsBeforeIncrease = val.Atoi();
253 else if (name.CompareTo("fMinIncreaseFromBaseLine")==0) {
254 fMinIncreaseFromBaseLine = val.Atof();
256 else if (name.CompareTo("fStepDownDacSafe")==0) {
257 fStepDownDacSafe = val.Atoi();
259 else if (name.CompareTo("fMaxBaseLineLevel")==0) {
260 fMaxBaseLineLevel = val.Atof();
263 Error("AliITSOnlineSPDscanAnalyzer::SetParam","Parameter %s in configuration file unknown.",name.Data());
266 //_________________________________________________________________________
267 void 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);
271 paramsFile.open(paramsFileName, ifstream::in);
272 if (paramsFile.fail()) {
273 printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
279 paramsFile >> paramN;
280 if (paramsFile.eof()) break;
281 paramsFile >> paramV;
282 SetParam(paramN,paramV);
283 if (paramsFile.eof()) break;
288 //_________________________________________________________________________
289 Bool_t AliITSOnlineSPDscanAnalyzer::IsChipPresent(UInt_t hs, UInt_t chipNr) {
290 // is the chip present?
291 if (fScanObj==NULL) {
292 Warning("AliITSOnlineSPDscanAnalyzer::IsChipPresent","No data!");
295 return fScanObj->GetChipPresent(hs,chipNr);
297 //_________________________________________________________________________
298 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels(/*Char_t *oldcalibDir*/) {
299 // process dead pixel data, for uniformity scan,
300 // NB: This will not be the general way of finding dead pixels.
301 if (fScanObj==NULL) {
302 Warning("AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels","No data!");
305 // should be type kUNIMA
307 Warning("AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels","Dead pixels only for scan type %d.",kUNIMA);
310 // handler should be initialized
311 if (fHandler==NULL) {
312 Error("AliITSOnlineSPDscanAnalyzer::ProcessDeadPixels","Calibration handler is not initialized!");
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!
322 if (fOverWrite) {fHandler->ResetDeadForChip(routerNr,hs,chipNr);}
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) {
327 fHandler->SetDeadPixel(routerNr,hs,chipNr,col,row);
337 //_________________________________________________________________________
338 Bool_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!");
344 // should be type kUNIMA
346 Warning("AliITSOnlineSPDscanAnalyzer::ProcessUniformity","Only for scan type %d.",kUNIMA);
350 CreateUniformityHistograms(); // create all histograms that will be filled here
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);
360 UInt_t numChipsActive=0;
362 for (UInt_t hs=0; hs<6; hs++) {
363 Float_t pixel100hs=0;
366 UInt_t numChipsActiveHS=0;
368 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
369 Float_t pixel100chip=0;
371 Float_t pixelNchip=0;
373 if (fScanObj->GetChipPresent(hs,chipNr)) { // check the status of the chippresent parameter in the mood header!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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!!!
381 if (fScanObj->GetHits(0,hs,chipNr,col,row)==NrTriggers) {
386 if (fScanObj->GetHits(0,hs,chipNr,col,row)==0) {
391 if (fScanObj->GetHits(0,hs,chipNr,col,row)>NrTriggers) {
400 Float_t TPeffChip=(pixel100chip/(28*(rowEnd-rowStart+1)))*100;
401 fTPeffChip[hs]->Fill(chipNr,TPeffChip);
403 Float_t DeadPixelChip=(zerichip/(28*(rowEnd-rowStart+1)))*100;
404 fDeadPixelChip[hs]->Fill(chipNr,DeadPixelChip);
406 Float_t NoisyPixelChip=(pixelNchip/(28*(rowEnd-rowStart+1)))*100;
407 fNoisyPixelChip[hs]->Fill(chipNr,NoisyPixelChip);
411 Float_t TPeffHS=(pixel100hs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
412 fTPeffHS->Fill(hs,TPeffHS);
414 Float_t DeadPixelHS=(zerihs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
415 fDeadPixelHS->Fill(hs,DeadPixelHS);
417 Float_t NoisyPixelHS=(pixelNhs/(28*numChipsActiveHS*(rowEnd-rowStart+1)))*100;
418 fNoisyPixelHS->Fill(hs,NoisyPixelHS);
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;
427 //_________________________________________________________________________
428 void 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();
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);
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);
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);
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);
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);
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);
479 //_________________________________________________________________________
480 void AliITSOnlineSPDscanAnalyzer::DeleteUniformityHistograms() {
481 // remove uniformity histograms if they are created
482 if (fTPeffHS!=NULL) {
486 if (fDeadPixelHS!=NULL) {
490 if (fNoisyPixelHS!=NULL) {
491 delete fNoisyPixelHS;
494 for (UInt_t hs=0; hs<6; hs++) {
495 if (fTPeffChip[hs]!=NULL) {
496 delete fTPeffChip[hs];
499 if (fDeadPixelChip[hs]!=NULL) {
500 delete fDeadPixelChip[hs];
501 fDeadPixelChip[hs]=NULL;
503 if (fNoisyPixelChip[hs]!=NULL) {
504 delete fNoisyPixelChip[hs];
505 fNoisyPixelChip[hs]=NULL;
509 //_________________________________________________________________________
510 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels(/*Char_t *oldcalibDir*/) {
511 // process noisy pixel data
512 if (fScanObj==NULL) {
513 Warning("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","No data!");
516 // should be type kNOISE
517 if (fType != kNOISE) {
518 Warning("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","Noisy pixels only for scan type %d.",kNOISE);
521 // handler should be initialized
522 if (fHandler==NULL) {
523 Error("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","Calibration handler is not initialized!");
526 // check if enough statistics
527 if (fScanObj->GetTriggers(0)<fNoiseMinimumEvents) {
528 Warning("AliITSOnlineSPDscanAnalyzer::ProcessNoisyPixels","Process noisy: Too few events.");
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!
536 if (fOverWrite) {fHandler->ResetNoisyForChip(routerNr,hs,chipNr);}
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) {
540 fHandler->SetNoisyPixel(routerNr,hs,chipNr,col,row);
549 //_________________________________________________________________________
550 Int_t AliITSOnlineSPDscanAnalyzer::GetDelay(UInt_t hs, UInt_t chipNr) {
552 if (hs>=6 || chipNr>10) return -1;
553 if (fScanObj==NULL) {
554 Warning("AliITSOnlineSPDscanAnalyzer::GetDelay","No data!");
557 // should be type kDELAY or kDAC with id 42 (delay_ctrl)
558 if (fType!=kDELAY && (fType!=kDAC || fDacId!=42)) {
559 Warning("AliITSOnlineSPDscanAnalyzer::GetDelay","Delay only for scan type %d or %d and dac_id 42.",kDELAY,kDAC);
562 if (fMeanMultiplicity[hs][chipNr]==NULL) {
563 if (!ProcessMeanMultiplicity()) {
570 for (UInt_t step=0; step<fScanObj->GetNSteps(); step++) {
573 fMeanMultiplicity[hs][chipNr]->GetPoint(step,thisDac,thisMult);
574 if (thisMult > maxVal) {
581 return ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(maxStep);
588 //_________________________________________________________________________
589 Int_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) {
593 Error("AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima","No data!");
596 // should be type kUNIMA
597 if (fType != kUNIMA) {
598 Error("AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima","Noisy pixels Unima only for scan type %d.",kUNIMA);
601 if (fScanObj->GetTriggers(0)!=25600) {
602 Error("AliITSOnlineSPDscanAnalyzer::GetNrNoisyUnima","Process noisy unima: Incorrect number of events (!=25600.");
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) {
621 //_________________________________________________________________________
622 Int_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()) {
630 Double_t firstVal, dummy1;
631 fMeanMultiplicity[hs][chipNr]->GetPoint(0,dummy1,firstVal);
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;
639 if (step==fScanObj->GetNSteps()-1) return -1;
640 return ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step);
643 Int_t AliITSOnlineSPDscanAnalyzer::FindClosestLowerStep(Float_t dacValueInput) {
644 // returns step closest (lower) to a dacvalue
646 while (step<fScanObj->GetNSteps()-1) {
647 Int_t dacVal = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step+1);
648 if (dacVal>=dacValueInput) break;
653 //_________________________________________________________________________
654 Float_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;
664 for (UInt_t st=1;st<2*step/3;st++) { // skip first point...
665 fMeanMultiplicity[hs][chipNr]->GetPoint(st,d,m);
667 baseS+=(m-baseLine)*(m-baseLine);
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;
675 Int_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) {
679 Error("AliITSOnlineSPDscanAnalyzer::GetMinTh","No data!");
682 // should be type kMINTH or kDAC with id 39 (pre_vth)
683 if (fType!=kMINTH && (fType!=kDAC || fDacId!=39)) {
684 Error("AliITSOnlineSPDscanAnalyzer::GetMinTh","MinTh only for scan type %d OR %d with dac_id 39.",kMINTH,kDAC);
687 if (fMeanMultiplicity[hs][chipNr]==NULL) {
688 if (!ProcessMeanMultiplicity()) {
693 Int_t lastDac = FindLastMinThDac(hs,chipNr);
695 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: Increase of Mean Multiplicity by %1.2f never reached.",hs,chipNr,fMinIncreaseFromBaseLine);
699 Int_t minDac = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(0);
700 TString funcName = Form("Fit minth func HS%d CHIP%d",hs,chipNr);
701 TF1 *minThFunc = new TF1(funcName.Data(),itsSpdErrorf,100,500,3);
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()) {
714 fMeanMultiplicity[hs][chipNr]->Fit(funcName,"Q0","",minDac,lastDac);
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);
721 if (baseLine>fMaxBaseLineLevel) {
722 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: BaseLine too large (%1.2f>%1.2f).",hs,chipNr,baseLine,fMaxBaseLineLevel);
725 UInt_t step=FindClosestLowerStep(lastDac);
726 Float_t compareLine = GetCompareLine(step,hs,chipNr,baseLine);
727 if (compareLine==-1) {
728 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: Not enough steps (%d<%d) before increase to get a compare line.",hs,chipNr,step,fMinNrStepsBeforeIncrease);
732 Double_t mult, dummy;
734 while (mult > compareLine && step>0) {
735 fMeanMultiplicity[hs][chipNr]->GetPoint(step,dummy,mult);
738 Int_t minth = ((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step+1)-fStepDownDacSafe;
744 Warning("AliITSOnlineSPDscanAnalyzer::GetMinTh","HS%d, Chip%d: Did not find a point below the compare line (%f).",hs,chipNr,compareLine);
748 //_________________________________________________________________________
749 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessMeanMultiplicity() {
750 // process mean multiplicity data
751 if (fScanObj==NULL) {
752 Error("AliITSOnlineSPDscanAnalyzer::ProcessMeanMultiplicity","No data!");
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!
760 if (fMeanMultiplicity[hs][chipNr]!=NULL) {
761 delete fMeanMultiplicity[hs][chipNr];
763 fMeanMultiplicity[hs][chipNr] = new TGraph();
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);
770 fMeanMultiplicity[hs][chipNr]->SetPoint(step,0,multiplMean);
778 //_________________________________________________________________________
779 TGraph* 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()) {
787 return fMeanMultiplicity[hs][chipNr];
789 //_________________________________________________________________________
790 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessHitEventEfficiency() {
791 // process hit event efficiency
792 if (fScanObj==NULL) {
793 Error("AliITSOnlineSPDscanAnalyzer::ProcessHitEventEfficiency","No data!");
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!!!!!!!!!!!!!!!!!!!!!!!!!!!!
801 if (fHitEventEfficiency[hs][chipNr]!=NULL) {
802 delete fHitEventEfficiency[hs][chipNr];
804 fHitEventEfficiency[hs][chipNr] = new TGraph();
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);
811 fHitEventEfficiency[hs][chipNr]->SetPoint(step,0,efficiency);
819 //_________________________________________________________________________
820 TGraph* 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()) {
828 return fHitEventEfficiency[hs][chipNr];
830 //_________________________________________________________________________
831 Bool_t AliITSOnlineSPDscanAnalyzer::ProcessNrTriggers() {
832 // process nr of triggers data
833 if (fScanObj==NULL) {
834 Error("AliITSOnlineSPDscanAnalyzer::ProcessNrTriggers","No data!");
837 for (UInt_t step=0; step<fScanObj->GetNSteps(); step++) {
839 if (fTriggers!=NULL) {
842 fTriggers = new TGraph();
844 if (fType==kMINTH || fType==kMEANTH || fType==kDAC || fType==kDELAY) {
845 fTriggers->SetPoint(step,((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step),fScanObj->GetTriggers(step));
848 fTriggers->SetPoint(step,0,fScanObj->GetTriggers(step));
853 //_________________________________________________________________________
854 TGraph* AliITSOnlineSPDscanAnalyzer::GetNrTriggersG() {
855 // returns nr of triggers graph
856 if (fTriggers==NULL) {
857 if (!ProcessNrTriggers()) {
863 //_________________________________________________________________________
864 Bool_t AliITSOnlineSPDscanAnalyzer::GetHalfStavePresent(UInt_t hs) {
865 // returns half stave present info
866 if (hs<6 && fScanObj!=NULL) {
868 for (Int_t chip=0; chip<10; chip++) {
869 chipstatus+=fScanObj->GetChipPresent(hs,chip);
871 if (chipstatus>0) return kTRUE;
875 //_________________________________________________________________________
876 UInt_t AliITSOnlineSPDscanAnalyzer::GetRouterNr() {
877 // returns the router nr of scan obj
878 if (fScanObj!=NULL) return fScanObj->GetRouterNr();
881 //_________________________________________________________________________
882 TH2F* 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) {
885 Error("AliITSOnlineSPDscanAnalyzer::GetHitMapTot","No data!");
889 if (fType==kMINTH || fType==kMEANTH || fType==kDAC) {
890 histoname = Form("Router %d , DAC %d",GetRouterNr(),((AliITSOnlineSPDscanMultiple*)fScanObj)->GetDacValue(step));
893 histoname = Form("Router %d ",GetRouterNr());
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);
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));
913 //_________________________________________________________________________
914 TH2F* 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!");
923 histoName = Form("fChipHisto_%d_%d_%d", GetRouterNr(), hs, chip);
924 histoTitle = Form("Eq ID %d, Half Stave %d, Chip %d", GetRouterNr(), hs, chip);
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));