LCOV - code coverage report
Current view: top level - ITS/ITSrec - AliITSOnlineSPDphysAnalyzer.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 386 0.0 %
Date: 2016-06-14 17:26:59 Functions: 0 27 0.0 %

          Line data    Source code
       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             : ////////////////////////////////////////////////////////////
      17             : // Author: Henrik Tydesjo                                 //
      18             : // This class is used in the detector algorithm framework //
      19             : // to process the data stored in special container files  //
      20             : // (see AliITSOnlineSPDphys).                             //
      21             : ////////////////////////////////////////////////////////////
      22             : 
      23             : #include "AliITSOnlineSPDphysAnalyzer.h"
      24             : #include "AliITSOnlineSPDphys.h"
      25             : #include "AliITSOnlineCalibrationSPDhandler.h"
      26             : #include "AliITSRawStreamSPD.h"
      27             : #include "AliITSIntMap.h"
      28             : #include <TStyle.h>
      29             : #include <TMath.h>
      30             : #include <TF1.h>
      31             : #include <TGraph.h>
      32             : #include <TH2F.h>
      33             : #include <TError.h>
      34             : #include <iostream>
      35             : #include <fstream>
      36             : 
      37             : using std::ifstream;
      38             : 
      39             : AliITSOnlineSPDphysAnalyzer::AliITSOnlineSPDphysAnalyzer(const Char_t *fileName, AliITSOnlineCalibrationSPDhandler* handler, Bool_t readFromGridFile) :
      40           0 :         fFileName(fileName),fPhysObj(NULL),fHandler(handler),
      41           0 :         fNrEnoughStatChips(0),fNrDeadChips(0),fNrInefficientChips(0),
      42           0 :         fNrEqHits(0),fbDeadProcessed(kFALSE),
      43           0 :         fThreshNoisy(1e-9),fThreshDead(1e-9),
      44           0 :         fMinEventsForNoisy(10000),fMinEventsForDead(10000),
      45           0 :         fDefinitelyNoisyRatio(0.3),
      46           0 :         fMinNrEqHitsForDeadChips(60000),fRatioToMeanForInefficientChip(0.1)
      47           0 : {
      48             :         // constructor  
      49           0 :         Init(readFromGridFile);
      50           0 : }
      51             : 
      52             : AliITSOnlineSPDphysAnalyzer::AliITSOnlineSPDphysAnalyzer(AliITSOnlineSPDphys* physObj, AliITSOnlineCalibrationSPDhandler* handler) :
      53           0 :         fFileName("test.root"),fPhysObj(NULL),fHandler(handler),
      54           0 :         fNrEnoughStatChips(0),fNrDeadChips(0),fNrInefficientChips(0),
      55           0 :         fNrEqHits(0),fbDeadProcessed(kFALSE),
      56           0 :         fThreshNoisy(1e-9),fThreshDead(1e-9),
      57           0 :         fMinEventsForNoisy(10000),fMinEventsForDead(10000),
      58           0 :         fDefinitelyNoisyRatio(0.3),
      59           0 :         fMinNrEqHitsForDeadChips(60000),fRatioToMeanForInefficientChip(0.1)
      60           0 : {
      61             :         // alt constructor
      62           0 :         fPhysObj = physObj;
      63           0 : }
      64             : 
      65             : AliITSOnlineSPDphysAnalyzer::AliITSOnlineSPDphysAnalyzer(const AliITSOnlineSPDphysAnalyzer& handle) :
      66           0 :         fFileName("test.root"),fPhysObj(NULL),fHandler(NULL),
      67           0 :         fNrEnoughStatChips(0),fNrDeadChips(0),fNrInefficientChips(0),
      68           0 :         fNrEqHits(0),fbDeadProcessed(kFALSE),
      69           0 :         fThreshNoisy(1e-9),fThreshDead(1e-9),
      70           0 :         fMinEventsForNoisy(10000),fMinEventsForDead(10000),
      71           0 :         fDefinitelyNoisyRatio(0.3),
      72           0 :         fMinNrEqHitsForDeadChips(60000),fRatioToMeanForInefficientChip(0.1)
      73           0 : {
      74             :         // copy constructor, only copies the filename and params (not the processed data)
      75           0 :         fFileName=handle.fFileName;
      76           0 :         fThreshNoisy = handle.fThreshNoisy;
      77           0 :         fThreshDead = handle.fThreshDead;
      78           0 :         fMinEventsForNoisy = handle.fMinEventsForNoisy;
      79           0 :         fMinEventsForDead = handle.fMinEventsForDead;
      80           0 :         fDefinitelyNoisyRatio = handle.fDefinitelyNoisyRatio;
      81           0 :         fMinNrEqHitsForDeadChips = handle.fMinNrEqHitsForDeadChips;
      82           0 :         fRatioToMeanForInefficientChip = handle.fRatioToMeanForInefficientChip;
      83             : 
      84           0 :         Init();
      85           0 : }
      86             : 
      87           0 : AliITSOnlineSPDphysAnalyzer::~AliITSOnlineSPDphysAnalyzer() {
      88             :         // destructor
      89           0 :         if (fPhysObj!=NULL) delete fPhysObj;
      90           0 : }
      91             : 
      92             : AliITSOnlineSPDphysAnalyzer& AliITSOnlineSPDphysAnalyzer::operator=(const AliITSOnlineSPDphysAnalyzer& handle) {
      93             :         // assignment operator, only copies the filename and params (not the processed data)
      94           0 :         if (this!=&handle) {
      95           0 :                 if (fPhysObj!=NULL) delete fPhysObj;
      96             : 
      97           0 :                 fFileName=handle.fFileName;
      98           0 :                 fThreshNoisy = handle.fThreshNoisy;
      99           0 :                 fThreshDead = handle.fThreshDead;
     100           0 :                 fMinEventsForNoisy = handle.fMinEventsForNoisy;
     101           0 :                 fMinEventsForDead = handle.fMinEventsForDead;
     102           0 :                 fDefinitelyNoisyRatio = handle.fDefinitelyNoisyRatio;
     103           0 :                 fMinNrEqHitsForDeadChips = handle.fMinNrEqHitsForDeadChips;
     104           0 :                 fRatioToMeanForInefficientChip = handle.fRatioToMeanForInefficientChip;
     105             : 
     106           0 :                 fPhysObj = NULL;
     107           0 :                 fHandler = NULL;
     108           0 :                 fNrEnoughStatChips = 0;
     109           0 :                 fNrDeadChips = 0;
     110           0 :                 fNrInefficientChips = 0;
     111           0 :                 fNrEqHits = 0;
     112           0 :                 fbDeadProcessed = kFALSE;
     113             : 
     114           0 :                 Init();    
     115           0 :         }
     116           0 :         return *this;
     117             : }
     118             : 
     119             : void AliITSOnlineSPDphysAnalyzer::Init(Bool_t readFromGridFile) {
     120             :         // initialize container obj
     121           0 :         if (!readFromGridFile) {
     122           0 :                 FILE* fp0 = fopen(fFileName.Data(), "r");
     123           0 :                 if (fp0 == NULL) {
     124           0 :                         return;
     125             :                 }
     126             :                 else {
     127           0 :                         fclose(fp0);
     128             :                 }
     129           0 :         }
     130           0 :         fPhysObj = new AliITSOnlineSPDphys(fFileName.Data(), readFromGridFile);
     131           0 : }
     132             : 
     133             : void AliITSOnlineSPDphysAnalyzer::SetParam(const Char_t *pname, const Char_t *pval) {
     134             :         // set a parameter
     135           0 :         TString name = pname;
     136           0 :         TString val = pval;
     137             :         //  printf("Setting Param %s  to %s\n",name.Data(),val.Data());
     138           0 :         if (name.CompareTo("MistakeProbabilityNoisy")==0) {
     139           0 :                 Double_t mistakeProbabilityNoisy = val.Atof();
     140           0 :                 fThreshNoisy = mistakeProbabilityNoisy/(20*6*10*32*256);
     141           0 :         }
     142           0 :         else if (name.CompareTo("MistakeProbabilityDead")==0) {
     143           0 :                 Double_t mistakeProbabilityDead = val.Atof();
     144           0 :                 fThreshDead = mistakeProbabilityDead/(20*6*10*32*256);
     145           0 :         }
     146           0 :         else if (name.CompareTo("fMinEventsForNoisy")==0) {
     147           0 :                 fMinEventsForNoisy = val.Atoi();
     148           0 :         }
     149           0 :         else if (name.CompareTo("fMinEventsForDead")==0) {
     150           0 :                 fMinEventsForDead = val.Atoi();
     151           0 :         }
     152           0 :         else if (name.CompareTo("fDefinitelyNoisyRatio")==0) {
     153           0 :                 fDefinitelyNoisyRatio = val.Atof();
     154           0 :         }
     155           0 :         else if (name.CompareTo("fMinNrEqHitsForDeadChips")==0) {
     156           0 :                 fMinNrEqHitsForDeadChips = val.Atof();
     157           0 :         }
     158           0 :         else if (name.CompareTo("fRatioToMeanForInefficientChip")==0) {
     159           0 :                 fRatioToMeanForInefficientChip = val.Atof();
     160           0 :         }
     161             :         else {
     162           0 :                 Error("AliITSOnlineSPDphysAnalyzer::SetParam","Parameter %s in configuration file unknown.",name.Data());
     163             :         }
     164           0 : }
     165             : 
     166             : void AliITSOnlineSPDphysAnalyzer::ReadParamsFromLocation(const Char_t *dirName) {
     167             :         // opens file (default name) in dir dirName and reads parameters from it
     168           0 :         TString paramsFileName = Form("%s/physics_params.txt",dirName);
     169           0 :         ifstream paramsFile;
     170           0 :         paramsFile.open(paramsFileName, ifstream::in);
     171           0 :         if (paramsFile.fail()) {
     172           0 :                 printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
     173             :         }
     174             :         else {
     175             :                 while(1) {
     176           0 :                         Char_t paramN[50];
     177           0 :                         Char_t paramV[50];
     178           0 :                         paramsFile >> paramN;
     179           0 :                         if (paramsFile.eof()) break;
     180           0 :                         paramsFile >> paramV;
     181           0 :                         SetParam(paramN,paramV);
     182           0 :                         if (paramsFile.eof()) break;
     183           0 :                 }
     184           0 :                 paramsFile.close();
     185             :         }
     186           0 : }
     187             : 
     188             : 
     189             : UInt_t AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels() {
     190             :         // process noisy pixel data , returns number of chips with enough statistics
     191           0 :         if (fPhysObj==NULL) {
     192           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","No data!");
     193           0 :                 return 0;
     194             :         }
     195             :         // do we have enough events to even try the algorithm?
     196           0 :         if (GetNrEvents() < fMinEventsForNoisy) {
     197           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Nr events (%d) < fMinEventsForNoisy (%d)!",GetNrEvents(),fMinEventsForNoisy);
     198           0 :                 return 0;
     199             :         }
     200             :         // handler should be initialized
     201           0 :         if (fHandler==NULL) {
     202           0 :                 Error("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Calibration handler is not initialized!");
     203           0 :                 return 0;
     204             :         }
     205             : 
     206             :         UInt_t nrEnoughStatChips = 0;
     207           0 :         UInt_t nrEvts = GetNrEvents();
     208           0 :         UInt_t eq = GetEqNr();
     209           0 :         UInt_t minHitsNoisy = fDefinitelyNoisyRatio*GetNrEvents();
     210             :         //UInt_t minHitsNoisy = 0.0005*GetNrEvents();
     211           0 :         for (UInt_t hs=0; hs<6; hs++) {
     212           0 :                 if(fPhysObj->GetAverageMultiplicityTot(hs)<1e-6) continue;
     213           0 :                 for (UInt_t chip=0; chip<10; chip++) {
     214             : 
     215             :                         UInt_t nrPixels = 0;
     216             :                         UInt_t nrChipHits = 0;
     217             :                         UInt_t nrMostHits = 0;
     218           0 :                         for (UInt_t col=0; col<32; col++) {
     219           0 :                                 for (UInt_t row=0; row<256; row++) {
     220           0 :                                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     221           0 :                                         nrChipHits += nrHits;
     222             :                                         //        if (nrHits>0) nrPixels++; // don't include pixels that might be dead
     223           0 :                                         nrPixels++;
     224           0 :                                         if (nrHits>minHitsNoisy) {
     225           0 :                                                 fHandler->SetNoisyPixel(eq,hs,chip,col,row);
     226             :                                                 nrPixels--;
     227             :                                                 nrChipHits-=nrHits;
     228           0 :                                         }
     229             :                                         else {
     230           0 :                                                 if (nrMostHits<nrHits) nrMostHits=nrHits;
     231             :                                         }
     232             :                                 }
     233             :                         }
     234             :                         /*
     235             :                            if (nrChipHits>0) { // otherwise there are for sure no noisy
     236             : // Binomial with n events and probability p for pixel hit
     237             : UInt_t n = nrEvts;
     238             : if (nrPixels>0 && n>0) {
     239             : 
     240             : Double_t p = (Double_t)nrChipHits/nrPixels/n;
     241             : 
     242             : // Bin(n,k=0):
     243             : Double_t bin = pow((Double_t)(1-p),(Double_t)n);
     244             : // Bin(n,k)
     245             : UInt_t k=1;
     246             : while ((bin>fThreshNoisy || k<n*p) && k<=n) {
     247             : k++;
     248             : bin = bin*(n-k+1)/k*p/(1-p);
     249             : }
     250             : 
     251             : // can we find noisy pixels...?
     252             : if (k<=n) {
     253             :                         //          printf("eq %d , hs %d , chip %d : Noisy level = %d\n",GetEqNr(),hs,chip,k);
     254             :                         nrEnoughStatChips++;
     255             :                         // add noisy pixels to handler
     256             :                         UInt_t noiseLimit=k;
     257             :                         if (nrMostHits>=noiseLimit) {
     258             :                         for (UInt_t col=0; col<32; col++) {
     259             :                         for (UInt_t row=0; row<256; row++) {
     260             :                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     261             :                         if (nrHits >= noiseLimit) {
     262             :                         fHandler->SetNoisyPixel(eq,hs,chip,col,row);
     263             :                         }
     264             :                         }
     265             :                         }
     266             :                         }
     267             :                         }
     268             :                         }
     269             : 
     270             :                         }
     271             :                         */
     272             : } // for chip
     273           0 : } // for hs
     274             : 
     275             : return nrEnoughStatChips;
     276           0 : }
     277             : 
     278             : //____________________________________________________________________________________
     279             : 
     280             : UInt_t AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixelsFast() {
     281             :         // process noisy pixel data , returns number of chips with enough statistics
     282           0 :         if (fPhysObj==NULL) {
     283           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","No data!");
     284           0 :                 return 0;
     285             :         }
     286             :         // do we have enough events to even try the algorithm?
     287           0 :         if (GetNrEvents() < fMinEventsForNoisy) {
     288           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Nr events (%d) < fMinEventsForNoisy (%d)!",GetNrEvents(),fMinEventsForNoisy);
     289           0 :                 return 0;
     290             :         }
     291             :         // handler should be initialized
     292           0 :         if (fHandler==NULL) {
     293           0 :                 Error("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Calibration handler is not initialized!");
     294           0 :                 return 0;
     295             :         }
     296             : 
     297             :         UInt_t nrNoisyPixels = 0;
     298           0 :         UInt_t nrEvts = GetNrEvents();
     299           0 :         UInt_t eq = GetEqNr();
     300           0 :         UInt_t minHitsNoisy = fDefinitelyNoisyRatio*nrEvts;
     301             :         //UInt_t minHitsNoisy = 0.0005*GetNrEvents();
     302           0 :         for (UInt_t hs=0; hs<6; hs++) {
     303           0 :                 if(fPhysObj->GetAverageMultiplicityTot(hs)<1e-6) continue;
     304           0 :                 for (UInt_t chip=0; chip<10; chip++) {
     305             : 
     306             :                         UInt_t nrChipHits = 0;
     307           0 :                         for (UInt_t col=0; col<32; col++) {
     308           0 :                                 for (UInt_t row=0; row<256; row++) {
     309           0 :                                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     310           0 :                                         nrChipHits += nrHits;
     311             :                                         //        if (nrHits>0) nrPixels++; // don't include pixels that might be dead         
     312           0 :                                         if (nrHits>minHitsNoisy) {
     313           0 :                                         fHandler->SetNoisyPixel(eq,hs,chip,col,row);
     314           0 :                                         nrNoisyPixels++;
     315           0 :                                         }
     316             :                                 }
     317             :                         }
     318             :                 }
     319           0 :         }
     320             : return nrNoisyPixels;
     321             : 
     322           0 : }
     323             : 
     324             : //_____________________________________________________________________________________
     325             : 
     326             : UInt_t AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels(UInt_t eq, UInt_t nrEvts) {
     327             :         // process noisy pixel data , returns number of chips with enough statistics
     328           0 :         if (fPhysObj==NULL) {
     329           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","No data!");
     330           0 :                 return 0;
     331             :         }
     332             :         // do we have enough events to even try the algorithm?
     333           0 :         if (nrEvts < fMinEventsForNoisy) {
     334           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Nr events (%d) < fMinEventsForNoisy (%d)!",nrEvts,fMinEventsForNoisy);
     335           0 :                 return 0;
     336             :         }
     337             :         // handler should be initialized
     338           0 :         if (fHandler==NULL) {
     339           0 :                 Error("AliITSOnlineSPDphysAnalyzer::ProcessNoisyPixels","Calibration handler is not initialized!");
     340           0 :                 return 0;
     341             :         }
     342             : 
     343             :         UInt_t nrEnoughStatChips = 0;
     344             : 
     345           0 :         for (UInt_t hs=0; hs<6; hs++) {
     346           0 :                 for (UInt_t chip=0; chip<10; chip++) {
     347             : 
     348             :                         UInt_t nrPixels = 0;
     349             :                         UInt_t nrChipHits = 0;
     350             :                         UInt_t nrMostHits = 0;
     351           0 :                         for (UInt_t col=0; col<32; col++) {
     352           0 :                                 for (UInt_t row=0; row<256; row++) {
     353           0 :                                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     354           0 :                                         nrChipHits += nrHits;
     355             :                                         //        if (nrHits>0) nrPixels++; // don't include pixels that might be dead
     356           0 :                                         nrPixels++;
     357           0 :                                         if (nrHits>fDefinitelyNoisyRatio*nrEvts) {
     358           0 :                                                 fHandler->SetNoisyPixel(eq,hs,chip,col,row);
     359             :                                                 nrPixels--;
     360             :                                                 nrChipHits-=nrHits;
     361           0 :                                         }
     362             :                                         else {
     363           0 :                                                 if (nrMostHits<nrHits) nrMostHits=nrHits;
     364             :                                         }
     365             :                                 }
     366             :                         }
     367             : 
     368           0 :                         if (nrChipHits>0) { // otherwise there are for sure no noisy
     369             :                                 // Binomial with n events and probability p for pixel hit
     370             :                                 UInt_t n = nrEvts;
     371           0 :                                 if (nrPixels>0 && n>0) {
     372             : 
     373           0 :                                         Double_t p = (Double_t)nrChipHits/nrPixels/n;
     374             : 
     375             :                                         // Bin(n,k=0):
     376           0 :                                         Double_t bin = pow((Double_t)(1-p),(Double_t)n);
     377             :                                         // Bin(n,k)
     378             :                                         UInt_t k=1;
     379           0 :                                         while ((bin>fThreshNoisy || k<n*p) && k<=n) {
     380           0 :                                                 k++;
     381           0 :                                                 bin = bin*(n-k+1)/k*p/(1-p);
     382             :                                         }
     383             : 
     384             :                                         // can we find noisy pixels...?
     385           0 :                                         if (k<=n) {
     386             :                                                 //          printf("eq %d , hs %d , chip %d : Noisy level = %d\n",GetEqNr(),hs,chip,k);
     387           0 :                                                 nrEnoughStatChips++;
     388             :                                                 // add noisy pixels to handler
     389             :                                                 UInt_t noiseLimit=k;
     390           0 :                                                 if (nrMostHits>=noiseLimit) {
     391           0 :                                                         for (UInt_t col=0; col<32; col++) {
     392           0 :                                                                 for (UInt_t row=0; row<256; row++) {
     393           0 :                                                                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     394           0 :                                                                         if (nrHits >= noiseLimit) {
     395           0 :                                                                                 fHandler->SetNoisyPixel(eq,hs,chip,col,row);
     396           0 :                                                                         }
     397             :                                                                 }
     398             :                                                         }
     399           0 :                                                 }
     400           0 :                                         }
     401           0 :                                 }
     402             : 
     403           0 :                         }
     404             : 
     405             :                 } // for chip
     406             :         } // for hs
     407             : 
     408             :         return nrEnoughStatChips;
     409           0 : }
     410             : //_______________________________________________________________________________
     411             : 
     412             : UInt_t AliITSOnlineSPDphysAnalyzer::ProcessDead() {
     413             : 
     414           0 :         Printf("AliITSOnlineSPDphysAnalyzer::ProcessDead()");
     415             :         // process dead pixel data , returns number of dead pixels
     416           0 :         if (fPhysObj==NULL) {
     417           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","No data!");
     418           0 :                 return 0;
     419             :         }
     420             : 
     421             :         // do we have enough events to even try the algorithm?
     422             :         //if (GetNrEvents() < fMinEventsForDead) {
     423           0 :         if (GetNrEvents() < 150000){
     424           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","Nr events (%d) < fMinEventsForDead (%d)!",GetNrEvents(),fMinEventsForDead);
     425           0 :                 return 0;
     426             :         }
     427             :         // handler should be initialized
     428           0 :         if (fHandler==NULL) {
     429           0 :                 Error("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","Calibration handler is not initialized!");
     430           0 :                 return 0;
     431             :         }
     432             : 
     433           0 :         fNrDeadChips = 0;
     434             :         UInt_t nrDeadPixels =0; 
     435             : 
     436           0 :         for(Int_t hs=0; hs<6; hs++){
     437           0 :                 if(!fHandler->IsActiveHS(GetEqNr(),hs)){
     438           0 :                         fNrDeadChips+=10;
     439           0 :                         nrDeadPixels+=81920;
     440             :                         //Printf("Eq %d HS %d dead",GetEqNr(),hs);
     441           0 :                 }
     442             :                 else{
     443           0 :                         for (UInt_t chip=0; chip<10; chip++) {
     444           0 :                                 if (!fHandler->IsActiveChip(GetEqNr(),hs,chip)) {
     445           0 :                                         fNrDeadChips++;
     446           0 :                                         nrDeadPixels+=8192;
     447           0 :                                 }
     448             :                                 else{
     449           0 :                                         for (UInt_t col=0; col<32; col++) {
     450           0 :                                                 for (UInt_t row=0; row<256; row++) {
     451           0 :                                                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     452           0 :                                                         if (nrHits==0) {
     453           0 :                                                                 fHandler->SetDeadPixel(GetEqNr(),hs,chip,col,row);
     454           0 :                                                                 nrDeadPixels+=1;
     455           0 :                                                         }
     456           0 :                                                         else fHandler->UnSetDeadPixel(GetEqNr(),hs,chip,col,row);
     457             :                                                 }//end loop on row
     458             :                                         }//end loop on col 
     459             :                                 }
     460             :                         }//end loop on chips
     461             :                 }//end HS active
     462             :         } //end loop on HS
     463             : 
     464           0 :         fbDeadProcessed = kTRUE;
     465             : 
     466             :         return nrDeadPixels;
     467             : 
     468           0 : }
     469             : 
     470             : UInt_t AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels() {
     471             :         // process dead pixel data , returns number of chips with enough statistics
     472           0 :         if (fPhysObj==NULL) {
     473           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","No data!");
     474           0 :                 return 0;
     475             :         }
     476             : 
     477             :         // do we have enough events to even try the algorithm?
     478             :         //if (GetNrEvents() < fMinEventsForDead) {
     479           0 :         if(GetNrEvents()<150000){    
     480           0 :                 Warning("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","Nr events (%d) < fMinEventsForDead (%d)!",GetNrEvents(),fMinEventsForDead);
     481           0 :                 return 0;
     482             :         }
     483             :         // handler should be initialized
     484           0 :         if (fHandler==NULL) {
     485           0 :                 Error("AliITSOnlineSPDphysAnalyzer::ProcessDeadPixels","Calibration handler is not initialized!");
     486           0 :                 return 0;
     487             :         }
     488             : 
     489           0 :         AliITSIntMap* possiblyDead  = new AliITSIntMap();
     490           0 :         AliITSIntMap* possiblyIneff = new AliITSIntMap();
     491             : 
     492           0 :         fNrEnoughStatChips = 0;
     493           0 :         fNrDeadChips = 0;
     494           0 :         fNrInefficientChips = 0;
     495             :         UInt_t nrPossiblyDeadChips = 0;
     496           0 :         fNrEqHits = 0;
     497             : 
     498             : 
     499           0 :         for (UInt_t hs=0; hs<6; hs++) {
     500           0 :                 if (!fHandler->IsActiveHS(GetEqNr(),hs)) {
     501           0 :                         fNrDeadChips+=10;
     502           0 :                 }
     503             :                 else {
     504           0 :                         for (UInt_t chip=0; chip<10; chip++) {
     505           0 :                                 if (!fHandler->IsActiveChip(GetEqNr(),hs,chip)) {
     506           0 :                                         fNrDeadChips++;
     507           0 :                                 }
     508             :                                 else {
     509             :                                         // perform search for individual dead pixels...
     510             :                                         Bool_t good=kFALSE;
     511             : 
     512             :                                         UInt_t nrPossiblyDeadPixels = 0;
     513             :                                         UInt_t nrPixels = 0;
     514             :                                         UInt_t nrChipHits = 0;
     515           0 :                                         for (UInt_t col=0; col<32; col++) {
     516           0 :                                                 for (UInt_t row=0; row<256; row++) {
     517           0 :                                                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     518           0 :                                                         nrChipHits += nrHits;
     519           0 :                                                         if (!fHandler->IsPixelNoisy(GetEqNr(),hs,chip,col,row)) {
     520             :                                                                 // don't include noisy pixels
     521           0 :                                                                 nrPixels++;
     522           0 :                                                                 if (nrHits==0) {
     523           0 :                                                                         nrPossiblyDeadPixels++;
     524           0 :                                                                 }
     525             :                                                                 else {
     526           0 :                                                                         fHandler->UnSetDeadPixel(GetEqNr(),hs,chip,col,row); // unset (no action unless dead before)
     527             :                                                                 }
     528             :                                                         }
     529             :                                                         else {
     530             :                                                                 nrChipHits -= nrHits; // this is needed when running offline (online nrHits should be 0 already)
     531             :                                                         }
     532             :                                                 }
     533             :                                         }
     534           0 :                                         fNrEqHits+=nrChipHits;
     535             : 
     536           0 :                                         if (nrChipHits>0) {
     537             :                                                 // make sure the chip is not flagged as dead
     538           0 :                                                 fHandler->SetDeadChip(GetEqNr(),hs,chip,kFALSE);
     539           0 :                                         }
     540             : 
     541           0 :                                         if (nrPossiblyDeadPixels==0) {
     542             :                                                 // no need to see if we have enough statistics...
     543           0 :                                                 fNrEnoughStatChips++;
     544             :                                                 good=kTRUE;
     545             :                                                 //      printf("%3d",good);
     546             :                                                 //      if (chip==9) printf("\n");
     547           0 :                                                 continue;
     548             :                                         }
     549             : 
     550           0 :                                         if (nrChipHits==0) {
     551           0 :                                                 nrPossiblyDeadChips++;
     552           0 :                                                 possiblyDead->Insert(hs,chip);
     553             :                                                 good=kFALSE;
     554             :                                                 //      printf("%3d",good);
     555             :                                                 //      if (chip==9) printf("\n");
     556           0 :                                                 continue;
     557             :                                         }
     558             : 
     559             :                                         // Binomial with n events and probability p for pixel hit
     560           0 :                                         UInt_t n = GetNrEvents();
     561           0 :                                         if (nrPixels>0 && n>0) {
     562             : 
     563           0 :                                                 Double_t p = (Double_t)nrChipHits/nrPixels/n;
     564             : 
     565             :                                                 // probability of falsely assigning a dead pixel
     566           0 :                                                 Double_t falselyDeadProb = pow((Double_t)(1-p),(Double_t)n);
     567             :                                                 //          printf("falselyprob=%e\n",falselyDeadProb);
     568             : 
     569             :                                                 // can we find dead pixels...?
     570           0 :                                                 if (falselyDeadProb<fThreshDead) {
     571           0 :                                                         fNrEnoughStatChips++;
     572             :                                                         good=kTRUE;
     573             :                                                         // add dead pixels to handler
     574           0 :                                                         for (UInt_t col=0; col<32; col++) {
     575           0 :                                                                 for (UInt_t row=0; row<256; row++) {
     576           0 :                                                                         UInt_t nrHits = fPhysObj->GetHits(hs,chip,col,row);
     577           0 :                                                                         if (nrHits==0) {
     578           0 :                                                                                 if (!fHandler->IsPixelNoisy(GetEqNr(),hs,chip,col,row)) {
     579             :                                                                                         // don't include noisy pixels
     580           0 :                                                                                         fHandler->SetDeadPixel(GetEqNr(),hs,chip,col,row);
     581           0 :                                                                                 }
     582             :                                                                         }
     583             :                                                                 }
     584             :                                                         }
     585           0 :                                                 }
     586           0 :                                                 if (!good) {
     587             :                                                         // this might be an inefficient chip
     588           0 :                                                         possiblyIneff->Insert(hs*10+chip,nrChipHits);
     589           0 :                                                 }
     590             : 
     591           0 :                                         }
     592             :                                         else {
     593           0 :                                                 if (n>0) {
     594             :                                                         // this is a completely noisy chip... put in category enough stat
     595           0 :                                                         fNrEnoughStatChips++;
     596             :                                                         good=kTRUE;
     597           0 :                                                 }
     598             :                                         }
     599             : 
     600             :                                         //      printf("%3d",good);
     601             :                                         //      if (chip==9) printf("\n");
     602             : 
     603           0 :                                 }
     604             :                         } // for chip
     605             :                 }
     606             :         } // for hs
     607             : 
     608             : 
     609           0 :         Int_t key,val;
     610             : 
     611             :         // dead chips?
     612           0 :         if (fNrEqHits>fMinNrEqHitsForDeadChips) {
     613           0 :                 while (possiblyDead->Pop(key,val)) {
     614           0 :                         fHandler->SetDeadChip(GetEqNr(),key,val,kFALSE);
     615             :                 }
     616           0 :                 fNrDeadChips+=nrPossiblyDeadChips;
     617           0 :         }
     618           0 :         delete possiblyDead;
     619             : 
     620             :         // inefficient chips?
     621           0 :         while (possiblyIneff->Pop(key,val)) {
     622           0 :                 if (val<fNrEqHits/60*fRatioToMeanForInefficientChip) {
     623           0 :                         fNrInefficientChips++;
     624           0 :                 }
     625             :         }
     626           0 :         delete possiblyIneff;
     627             : 
     628             : 
     629           0 :         fbDeadProcessed = kTRUE;
     630             : 
     631           0 :         return fNrEnoughStatChips;
     632           0 : }
     633             : 
     634             : 
     635             : UInt_t AliITSOnlineSPDphysAnalyzer::GetNrEnoughStatChips() {
     636             :         // returns nr of enough stat chips
     637           0 :         if (!fbDeadProcessed) ProcessDeadPixels();
     638           0 :         return fNrEnoughStatChips;
     639             : }
     640             : UInt_t AliITSOnlineSPDphysAnalyzer::GetNrDeadChips() {
     641             :         // returns nr of dead chips
     642           0 :         if (!fbDeadProcessed) ProcessDeadPixels();
     643           0 :         return fNrDeadChips;
     644             : }
     645             : UInt_t AliITSOnlineSPDphysAnalyzer::GetNrInefficientChips() {
     646             :         // returns nr of inefficient chips
     647           0 :         if (!fbDeadProcessed) ProcessDeadPixels();
     648           0 :         return fNrInefficientChips;
     649             : }
     650             : UInt_t AliITSOnlineSPDphysAnalyzer::GetNrNeedsMoreStatChips() {
     651             :         // returns nr of needs more stat chips
     652           0 :         if (!fbDeadProcessed) ProcessDeadPixels();
     653           0 :         return 60-fNrEnoughStatChips-fNrDeadChips-fNrInefficientChips;
     654             : }
     655             : 
     656             : UInt_t AliITSOnlineSPDphysAnalyzer::GetEqNr() const {
     657             :         // returns the eq nr of phys obj
     658           0 :         if (fPhysObj!=NULL) return fPhysObj->GetEqNr(); 
     659           0 :         else return 999;
     660           0 : }
     661             : 
     662             : UInt_t AliITSOnlineSPDphysAnalyzer::GetNrEvents() const {
     663             :         // returns the nr of events of phys obj
     664           0 :         if (fPhysObj!=NULL) return fPhysObj->GetNrEvents(); 
     665           0 :         else return 0;
     666           0 : }
     667             : 
     668             : void AliITSOnlineSPDphysAnalyzer::Exponent(Double_t &val, Int_t &valExp) const {
     669             :         // put double in format with val and exp so that 1<val<10 - The actual value is val*10e(valExp)
     670           0 :         while (val>10) {
     671           0 :                 val/=10;
     672           0 :                 valExp++;
     673             :         }
     674           0 :         while (val<1) {
     675           0 :                 val*=10;
     676           0 :                 valExp--;
     677             :         }
     678           0 : }
     679             : //____________________________________________________________________________________________________
     680             : TH2F* AliITSOnlineSPDphysAnalyzer::GetPhysicalHitMapTot() {
     681             :         // creates and returns a pointer to a hitmap histo (equipment opened up)
     682             :         // physical representation of the half stave hitmap.
     683             : 
     684           0 :         if (fPhysObj==NULL) {
     685           0 :                 Error("AliITSOnlineSPDphysAnalyzer::GetPhysicalHitMapTot","No data!");
     686           0 :                 return NULL;
     687             :         }
     688           0 :         TString histoname = Form("Eq %d",GetEqNr());
     689           0 :         TH2F* hPhysicalHitMapTot = new TH2F(histoname.Data(),histoname.Data(),32*10,-0.5,32*10-0.5,256*6,-0.5,256*6-0.5);
     690           0 :         hPhysicalHitMapTot->SetNdivisions(-10,"X");
     691           0 :         hPhysicalHitMapTot->SetNdivisions(-006,"Y");
     692           0 :         hPhysicalHitMapTot->SetTickLength(0,"X");
     693           0 :         hPhysicalHitMapTot->SetTickLength(0,"Y");
     694           0 :         hPhysicalHitMapTot->GetXaxis()->SetLabelColor(gStyle->GetCanvasColor());
     695           0 :         hPhysicalHitMapTot->GetYaxis()->SetLabelColor(gStyle->GetCanvasColor());
     696             :         Int_t correctChip=-1;
     697           0 :         for (UInt_t hs=0; hs<6; hs++) {
     698           0 :                 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
     699           0 :                         if(GetEqNr()<10) correctChip=9-chipNr;
     700             :                         else correctChip=chipNr;
     701           0 :                         for (UInt_t col=0; col<32; col++) {
     702           0 :                                 for (UInt_t row=0; row<256; row++) {
     703           0 :                                         if(hs>1) hPhysicalHitMapTot->Fill(correctChip*32+(31-col),(5-hs)*256+row,fPhysObj->GetHits(hs,chipNr,col,row));
     704           0 :                                         else hPhysicalHitMapTot->Fill(correctChip*32+col,(5-hs)*256+row,fPhysObj->GetHits(hs,chipNr,col,row));
     705             :                                 }
     706             :                         }
     707             :                 }
     708             :         }
     709             :         return hPhysicalHitMapTot;
     710           0 : }
     711             : //_____________________________________________________________________________________________________
     712             : TH2F* AliITSOnlineSPDphysAnalyzer::GetHitMapTot() {
     713             :         // creates and returns a pointer to a hitmap histo (half sector style a la spdmood)
     714             :         // This histogram  shown the read out numbering pattern, it is not the physical one.
     715           0 :         if (fPhysObj==NULL) {
     716           0 :                 Error("AliITSOnlineSPDphysAnalyzer::GetHitMapTot","No data!");
     717           0 :                 return NULL;
     718             :         }
     719           0 :         TString histoname = Form("Eq %d",GetEqNr());
     720           0 :         TH2F* fHitMapTot = new TH2F(histoname.Data(),histoname.Data(),32*10,-0.5,32*10-0.5,256*6,-0.5,256*6-0.5);
     721           0 :         fHitMapTot->SetNdivisions(-10,"X");
     722           0 :         fHitMapTot->SetNdivisions(-006,"Y");
     723           0 :         fHitMapTot->SetTickLength(0,"X");
     724           0 :         fHitMapTot->SetTickLength(0,"Y");
     725           0 :         fHitMapTot->GetXaxis()->SetLabelColor(gStyle->GetCanvasColor());
     726           0 :         fHitMapTot->GetYaxis()->SetLabelColor(gStyle->GetCanvasColor());
     727           0 :         for (UInt_t hs=0; hs<6; hs++) {
     728           0 :                 for (UInt_t chipNr=0; chipNr<10; chipNr++) {
     729           0 :                         for (UInt_t col=0; col<32; col++) {
     730           0 :                                 for (UInt_t row=0; row<256; row++) {
     731           0 :                                         fHitMapTot->Fill(chipNr*32+col,(5-hs)*256+row,fPhysObj->GetHits(hs,chipNr,col,row));
     732             :                                 }
     733             :                         }
     734             :                 }
     735             :         }
     736             :         return fHitMapTot;
     737           0 : }
     738             : //________________________________________________________________________________________________________
     739             : TH2F* AliITSOnlineSPDphysAnalyzer::GetHitMapChip(UInt_t hs, UInt_t chip) {
     740             :         // creates and returns a pointer to a hitmap histo (chip style a la spdmood)
     741           0 :         if (fPhysObj==NULL) {
     742           0 :                 Error("AliITSOnlineSPDphysAnalyzer::GetHitMapChip","No data!");
     743           0 :                 return NULL;
     744             :         }
     745             : 
     746           0 :         TString histoName;
     747           0 :         TString histoTitle;
     748           0 :         histoName = Form("fChipHisto_%d_%d_%d", GetEqNr(), hs, chip);
     749           0 :         histoTitle = Form("Eq ID %d, Half Stave %d, Chip %d", GetEqNr(), hs, chip);
     750             : 
     751           0 :         TH2F *returnHisto = new TH2F(histoName.Data(), histoTitle.Data(), 32, -0.5, 31.5, 256, -0.5, 255.5);
     752           0 :         returnHisto->SetMinimum(0);
     753           0 :         for (UInt_t col=0; col<32; col++) {
     754           0 :                 for (UInt_t row=0; row<256; row++) {
     755           0 :                         if(hs<2) returnHisto->Fill(31-col,row,fPhysObj->GetHits(hs,chip,col,row));
     756           0 :                         else returnHisto->Fill(col,row,fPhysObj->GetHits(hs,chip,col,row));
     757             :                 }
     758             :         }
     759             : 
     760             :         return returnHisto;
     761           0 : }

Generated by: LCOV version 1.11