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

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 2008-2010, 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             : 
      18             : ////////////////////////////////////////////////////////////
      19             : // Author: A. Mastroserio                                 //
      20             : // This class is used in the detector algorithm framework //
      21             : // to process the data stored in special container files  //
      22             : // (see AliITSOnlineSPDfo). The "good" set of DAC values  //
      23             : // is extracted.                                          //
      24             : ////////////////////////////////////////////////////////////
      25             : 
      26             : #include <TFile.h>
      27             : #include <TMath.h>
      28             : #include <TString.h>
      29             : #include <TStyle.h>
      30             : #include <TF1.h>
      31             : #include <TH1D.h>
      32             : #include <TH2D.h>
      33             : #include <TArrayI.h>
      34             : #include <TCanvas.h>
      35             : #include <THnSparse.h>
      36             : #include <TKey.h>
      37             : #include <iostream>
      38             : #include <fstream>
      39             : #include "AliITSOnlineSPDfoChipConfig.h"
      40             : #include "AliITSOnlineSPDfoChip.h"
      41             : #include "AliITSOnlineSPDfoInfo.h"
      42             : #include "AliITSOnlineSPDfo.h"
      43             : #include "AliITSOnlineSPDfoAnalyzer.h"
      44             : #include "AliLog.h"
      45             : 
      46             : using std::ifstream;
      47             : 
      48             : AliITSOnlineSPDfoAnalyzer::AliITSOnlineSPDfoAnalyzer(const TString fileName, Bool_t readFromGridFile) :
      49           0 :   fFileName(0),
      50           0 :   fNdims(0),
      51           0 :   fNbins(0x0),
      52           0 :   fXmin(0x0),
      53           0 :   fXmax(0x0),
      54           0 :   fFOHandler(0x0),
      55           0 :   fHighOccupancyCheck(kTRUE)
      56           0 : {
      57             :   // constructor
      58           0 :   fFileName = fileName;
      59           0 :   for(Int_t iqual =0; iqual<kNqualityFlags; iqual++) fGeneralThresholds[iqual]=0;
      60             :   
      61           0 :   for (UInt_t chipNr=0; chipNr<10; chipNr++) {
      62           0 :     for (UInt_t hs=0; hs<6; hs++) {
      63           0 :       for(Int_t i =0; i< kNqualityFlags; i++) fNh[i][hs][chipNr]=NULL;
      64             :     }
      65             :   }
      66             :   
      67           0 :   Init(readFromGridFile); 
      68           0 : }
      69             : //-------------------------------------------------------------------
      70             : AliITSOnlineSPDfoAnalyzer::AliITSOnlineSPDfoAnalyzer(const AliITSOnlineSPDfoAnalyzer& foan) :
      71           0 :   fFileName(foan.fFileName),
      72           0 :   fNdims(foan.fNdims),
      73           0 :   fNbins(foan.fNbins),
      74           0 :   fXmin(foan.fXmin),
      75           0 :   fXmax(foan.fXmax),
      76           0 :   fFOHandler(foan.fFOHandler),
      77           0 :   fHighOccupancyCheck(foan.fHighOccupancyCheck)
      78           0 : {
      79             :   //
      80             :   // copy constructor, only copies the filename and params (not the processed data
      81             :   //
      82             :   
      83           0 :   for(Int_t iqual =0; iqual<3; iqual++) fGeneralThresholds[iqual] =foan.fGeneralThresholds[iqual];
      84           0 :   for (UInt_t chipNr=0; chipNr<10; chipNr++) {
      85           0 :     for (UInt_t hs=0; hs<6; hs++) {
      86           0 :       for(Int_t i=0; i<kNqualityFlags;i++) fNh[i][hs][chipNr]=NULL;
      87             :     }
      88             :   }
      89             :   
      90           0 :   Init();
      91           0 : }
      92             : //-------------------------------------------------------------------
      93             : AliITSOnlineSPDfoAnalyzer::~AliITSOnlineSPDfoAnalyzer() 
      94           0 : {
      95             :   //
      96             :   // destructor
      97             :   // 
      98             :   
      99           0 :   for (UInt_t hs=0; hs<6; hs++) {
     100           0 :     for (UInt_t chipNr=0; chipNr<10; chipNr++) {
     101           0 :       for(Int_t i=0; i<kNqualityFlags ; i++ ) if(fNh[i][hs][chipNr]!=NULL) delete fNh[i][hs][chipNr];          
     102             :     }
     103             :   }
     104           0 :   delete fFOHandler;
     105           0 : }
     106             : //-------------------------------------------------------------------
     107             : AliITSOnlineSPDfoAnalyzer& AliITSOnlineSPDfoAnalyzer::operator=(const AliITSOnlineSPDfoAnalyzer& foan) 
     108             : {
     109             :   // assignment operator, only copies the filename and params (not the processed data)
     110           0 :   if (this!=&foan) {
     111           0 :     for (UInt_t hs=0; hs<6; hs++) {
     112           0 :       for (UInt_t chipNr=0; chipNr<10; chipNr++) {
     113           0 :         for(Int_t i=0; i<kNqualityFlags ; i++ ) if(fNh[i][hs][chipNr]!=NULL) delete fNh[i][hs][chipNr];
     114             :       }
     115             :     }
     116             :     
     117           0 :     fFileName=foan.fFileName;
     118           0 :     fHighOccupancyCheck=foan.fHighOccupancyCheck;
     119           0 :     Init();    
     120           0 :   }
     121           0 :   return *this;
     122             : }
     123             : //-------------------------------------------------------------------
     124             : void AliITSOnlineSPDfoAnalyzer::Init(Bool_t readFromGridFile) 
     125             : {
     126             :   //
     127             :   // first checks type of container and then initializes container obj
     128             :   //
     129           0 :   if (!readFromGridFile) {
     130           0 :     TFile* p0 = TFile::Open(fFileName.Data());
     131           0 :     if (p0 == NULL) {
     132           0 :       printf("no file open!"); 
     133           0 :       return;
     134             :     }
     135             :     else { 
     136           0 :       fFOHandler = new AliITSOnlineSPDfo();
     137           0 :       fFOHandler->SetFile(fFileName);
     138             :     }
     139           0 :     p0->Close();   
     140           0 :   }
     141           0 : }
     142             : //-------------------------------------------------------------------
     143             : void AliITSOnlineSPDfoAnalyzer::SetGeneralThresholds(Float_t thre[3])
     144             : {
     145             :   // here the settings for the 3 quality flags are defined
     146           0 :   for(Int_t i=0; i< 3; i++) fGeneralThresholds[i]=thre[i];  
     147           0 : }
     148             : //-------------------------------------------------------------------
     149             : void AliITSOnlineSPDfoAnalyzer::SetNdimensions()
     150             : {
     151             :   //
     152             :   // here the axis of the N-dim histograms are setted 
     153             :   // 
     154           0 :   if(!fFOHandler) {
     155           0 :     printf("no fo object. Exiting...\n"); 
     156           0 :     return;
     157             :   }
     158             :   
     159           0 :   TArrayI array = fFOHandler->GetDACscanParams();
     160           0 :   fNdims = array.GetSize()/3;
     161           0 :   fNbins = new Int_t[fNdims];
     162           0 :   fXmin = new Double_t[fNdims];
     163           0 :   fXmax = new Double_t[fNdims];
     164           0 :   for(Int_t i=0; i< fNdims; i++){
     165           0 :     fXmin[i] = array.At(3*i)-0.25;
     166           0 :     fXmax[i] = array.At(3*i+1)+0.25;
     167           0 :     fNbins[i] = (Int_t)((fXmax[i]-fXmin[i])/0.5)+1;//to avoid Int->Double conversion problems when checking results. 
     168             :   } 
     169           0 : }
     170             : //-------------------------------------------------------------------
     171             : void AliITSOnlineSPDfoAnalyzer::BuildTHnSparse(Int_t ihs, Int_t ichip)
     172             : {
     173             :   //
     174             :   // here the N-dim histogram is booked per chip in one HS 
     175             :   //
     176             :   
     177           0 :   if(!fNdims) SetNdimensions();
     178             :   
     179           0 :   for(Int_t iqual =0; iqual < 3; iqual++) fNh[iqual][ihs][ichip] = new THnSparseI(Form("h%i_HS%i_C%i",iqual,ihs,ichip), Form("h%i_HS%i_C%i",iqual,ihs,ichip), fNdims, fNbins, fXmin, fXmax);
     180           0 : }
     181             : //-------------------------------------------------------------------
     182             : Int_t AliITSOnlineSPDfoAnalyzer::Select(const AliITSOnlineSPDfoChip *chip) const
     183             : {
     184             :   //
     185             :   // Selects the DAC values if in the chip: the I configuration corresponds to
     186             :   // 0% efficiency ( no FO response case). All the others shoud be within the 
     187             :   // predefined thresholds
     188             :   
     189           0 :   if(!fFOHandler->GetFOscanInfo()) {
     190           0 :     printf("no general information object in the file. Exiting...\n");
     191           0 :     return -1;
     192             :   }
     193             :   
     194           0 :   Double_t npulses = (fFOHandler->GetFOscanInfo())->GetNumTriggers();
     195             :   
     196           0 :   if(npulses == 0. ) {
     197           0 :     Info("AliITSOnlineSPDfoAnalyzer::Select","no trigger pulses set. Exiting...");
     198           0 :     return -999;
     199             :   } 
     200             :   
     201           0 :   TObjArray *array = chip->GetChipConfigInfo();
     202           0 :   if(!array) {
     203           0 :     printf("No measurement array found in the chip!!\n");
     204           0 :     return 0;
     205             :   }
     206             :   
     207             :   Int_t quality = -1;
     208             :   
     209             :   Float_t counts = 0;
     210             :   
     211           0 :   Int_t processedconfigurations = chip->GetNumberOfChipConfigs();
     212             :   
     213             :  
     214             :   
     215             :   
     216           0 :   for(Int_t isteps =0; isteps < processedconfigurations; isteps++){ 
     217             :     
     218           0 :     Int_t matrixId = ((AliITSOnlineSPDfoChipConfig*)array->At(isteps))->GetChipConfigMatrixId();
     219           0 :     counts = (Float_t)(((AliITSOnlineSPDfoChipConfig*)array->At(isteps))->GetChipConfigCounter());
     220           0 :     if(matrixId==0 && counts > 0) return -1;
     221           0 :     if(fHighOccupancyCheck &&  matrixId ==6) continue;
     222             :     
     223           0 :     Float_t efficiency = counts/npulses;
     224             :     
     225           0 :     if(matrixId > 0){
     226           0 :       Int_t response = IsSelected(efficiency);
     227           0 :       if( response >=0) {
     228           0 :         if(quality < response) quality = response;
     229             :       }
     230           0 :       else return -1; 
     231           0 :     }
     232           0 :   }
     233           0 :   return quality;
     234           0 : }
     235             : //-----------------------------------------------------
     236             : Int_t AliITSOnlineSPDfoAnalyzer::IsSelected(Float_t eff) const
     237             : {
     238             :   //
     239             :   // returns the quality of the selection 
     240             :   //
     241             :   
     242           0 :   for(Int_t i=0; i<3; i++){  
     243           0 :     if(eff <= 1.+ fGeneralThresholds[i] && eff >= 1. - fGeneralThresholds[i]  ) return i;
     244             :   }
     245           0 :   return -1;
     246           0 : }
     247             : //----------------------------------------------------
     248             : void AliITSOnlineSPDfoAnalyzer::Process()
     249             : { 
     250             :   //
     251             :   // The procedure is the following:
     252             :   // - DAC 4-tuples are checked  
     253             :   // - if the 4-tuple survives the selection, the chip-related histograms are filled.
     254             :   // (- Per each histogram the mean values of each axis are taken)
     255             :   //
     256             :   
     257           0 :   if(!fFOHandler) { 
     258           0 :     Warning("AliITSOnlineSPDfoAnalyzer::Process","no fo object. Exiting.. \n");
     259           0 :     return;
     260             :   } 
     261             :   
     262             :   TKey *key;
     263           0 :   TIter iter((fFOHandler->GetFile())->GetListOfKeys());  
     264           0 :   while ((key = (TKey*)(iter.Next()))) {
     265           0 :     TString classname = key->GetClassName();
     266           0 :     if(classname.Contains("OnlineSPD")) break;
     267             :     
     268           0 :     TObjArray *array = (TObjArray*)(fFOHandler->GetFile())->Get(key->GetName()); // array of chips corresponding to the DACS (size 1-60)
     269           0 :     if(!array){
     270           0 :       printf("no array found! Exiting...\n");
     271           0 :       break; 
     272             :     }
     273             :     
     274           0 :     Double_t *dacvalues = fFOHandler->GetDACvaluesD(key->GetName(), GetFOHandler()->GetFOscanInfo()->GetNumDACindex());
     275             :     
     276           0 :     for(Int_t i=0; i< array->GetSize(); i++){
     277           0 :       AliITSOnlineSPDfoChip *chip = (AliITSOnlineSPDfoChip *)array->At(i); 
     278             :           
     279           0 :       if(!chip) continue;
     280           0 :       Int_t hs = chip->GetActiveHS();
     281           0 :       Int_t chipid = chip->GetChipId();     
     282           0 :       Int_t quality = Select(chip);
     283           0 :       if(quality<0) continue; 
     284           0 :       if(!fNh[quality][hs][chipid]) BuildTHnSparse(hs,chipid);
     285           0 :       fNh[quality][hs][chipid]->Fill(dacvalues);       
     286           0 :     } 
     287             : 
     288           0 :     if(dacvalues) delete [] dacvalues;
     289           0 :   } 
     290           0 : }
     291             : //---------------------------------------------
     292             : void AliITSOnlineSPDfoAnalyzer::WriteToFile(TString outputfile)
     293             : {
     294             :   //
     295             :   // The 4-dim histograms are stored into a file
     296             :   //
     297             :   
     298           0 :   TFile * f = TFile::Open(outputfile.Data(),"recreate");
     299           0 :   for(Int_t ihs =0; ihs < 6; ihs++) {
     300           0 :     for(Int_t ichip =0; ichip < 10; ichip++){
     301           0 :       for(Int_t i=0; i<kNqualityFlags ; i++ ) {
     302           0 :       if(fNh[i][ihs][ichip]) f->WriteObjectAny(fNh[i][ihs][ichip],"THnSparse",Form("h%i_hs%i_chip%i",i,ihs,ichip));
     303             :       }
     304             :       
     305             :     }
     306             :   }
     307           0 :   f->Close();
     308           0 : }
     309             : //---------------------------------------------
     310             : void AliITSOnlineSPDfoAnalyzer::CheckResults(TString filename, Int_t hs, Int_t ichip, Int_t iqual) const
     311             : {
     312             :   //  
     313             :   //The chip related 4-dim histograms are produced and stored into eps files
     314             :   //    
     315             :   
     316           0 :   TFile *f = TFile::Open(filename.Data());
     317           0 :   if(!f) {
     318           0 :     Info("AliITSOnlineSPDfoAnalyzer::CehckResults","no file open!. Exiting...\n");
     319           0 :     return; 
     320             :   }
     321             :   
     322             :   THnSparse *hn;
     323             :   TObject *obj;
     324             :   
     325           0 :   TIter iter(f->GetListOfKeys());
     326           0 :   while((obj=iter.Next())){
     327           0 :     TString name = obj->GetName();
     328           0 :     hn=(THnSparse*)f->Get(name.Data()); 
     329           0 :     if(name.Contains(Form("hs%i",hs)) && name.Contains(Form("chip%i",ichip)) && name.Contains(Form("h%i",iqual))) GetCanvases(hn,hs,ichip,iqual);
     330           0 :   } 
     331           0 : }
     332             : //-----------------------------------------------------------------------------------------------
     333             : void AliITSOnlineSPDfoAnalyzer::GetCanvases(const THnSparse *hn,Int_t hs, Int_t chip, Int_t iqual) const
     334             : {
     335             :   //
     336             :   // 1-Dim and 2 Dim Projections of 4-dim histograms are visualized in canvases per quality selection
     337             :   //
     338             :   //
     339             :   
     340           0 :   if(!hn) {printf("no thnsparse...exiting!\n"); return;} 
     341             :   
     342           0 :   gStyle->SetPalette(1);
     343             :   
     344           0 :   TString dacname[4];
     345             :   
     346           0 :   if(  (fFOHandler->GetFOscanInfo())->GetDACindex(0) == 20 ) dacname[0] = "FOPOL";
     347           0 :   else dacname[0] = "possible DAC-name/ DAC-register-number mismatch";  
     348           0 :   if(  (fFOHandler->GetFOscanInfo())->GetDACindex(1) == 17 ) dacname[1] = "CONVPOL";
     349           0 :   else dacname[1] = "possible DAC-name/ DAC-register-number mismatch";
     350           0 :   if(  (fFOHandler->GetFOscanInfo())->GetDACindex(2) == 16 ) dacname[2] = "COMPREF";
     351           0 :   else dacname[2] = "possible DAC-name/ DAC-register-number mismatch";
     352           0 :   if(  (fFOHandler->GetFOscanInfo())->GetDACindex(3) == 39 ) dacname[3] = "pre_VTH";
     353           0 :   else dacname[3] = "possible DAC-name/ DAC-register-number mismatch";
     354             :   
     355           0 :   TString titles = Form("|eff-1| <= %f   for CHIP %i  in HS  %i",fGeneralThresholds[iqual],hs,chip);
     356           0 :   TCanvas *c[3];
     357             :   
     358           0 :   for(Int_t i=0; i<2; i++) {
     359           0 :     c[i] = new TCanvas(Form("c%i",i+1),Form(" %i DIM plots. %s ",i+1,titles.Data()),1200,800); 
     360           0 :     c[i]->Divide(2,2);
     361             :   }
     362             :   
     363             :   
     364           0 :   for(Int_t idim =0; idim<2; idim++){
     365           0 :     for(Int_t k=1; k<5; k++){
     366           0 :       c[idim]->cd(k);
     367             :       
     368             :       TH1D *h1 =0x0;
     369             :       TH2D *h2=0x0;       
     370           0 :       if(idim == 0) {
     371           0 :         h1 = hn->Projection(k-1);
     372           0 :         if(!h1) {
     373           0 :          printf("no histogram!!...\n\n\n");
     374             :         } else {
     375           0 :         h1->SetXTitle(Form("DAC %i  ( %s )",k-1,dacname[k-1].Data()));
     376           0 :         h1->SetYTitle("entries (eff within thresholds)");
     377           0 :         h1->Draw();
     378             :         }
     379             :       } 
     380             :       
     381           0 :       if(idim==1) {      
     382           0 :         if(k<4){
     383           0 :           h2  = hn->Projection(k-1,k);
     384           0 :           h2->SetXTitle(Form("DAC %i ( %s )",k,dacname[k].Data())); h2->SetYTitle(Form("DAC %i  ( %s )",k-1,dacname[k-1].Data()));
     385           0 :           h2->SetTitleOffset(2,"Y"); h2->SetTitleOffset(1.5,"X");
     386             :         } else {
     387           0 :           h2 = hn->Projection(0,3);
     388           0 :           h2->SetXTitle(Form("DAC %i ( %s )",3,dacname[3].Data())); h2->SetYTitle(Form("DAC %i  ( %s )",0, dacname[0].Data()));
     389           0 :           h2->SetTitleOffset(2,"Y"); h2->SetTitleOffset(1.5,"X"); 
     390             :         }    
     391             :         
     392           0 :         h2->Draw("lego2");
     393             :       }  
     394             :     }// k loop
     395             :     
     396           0 :     c[idim]->SaveAs(Form("c%iDIM_%i_%i_%i.eps",idim,iqual,hs,chip));   
     397             :   }// idim loop  
     398           0 : }
     399             : //-----------------------------------------------------
     400             : TArrayI AliITSOnlineSPDfoAnalyzer::ChooseDACValues(Int_t hs, Int_t chip) const
     401             : {
     402             :   //
     403             :   // here the "best" 4 dacs are chosen. The most present are taken. 
     404             :   // If the n-tuple does not correspond to a meaningful entry, the
     405             :   // closest value to the mean point in the n-dimensional histogram
     406             :   // is taken.
     407             :   
     408           0 :   TH1D *tmp[5];
     409           0 :   for(Int_t jj=0;jj<5;jj++)tmp[jj]=NULL;
     410           0 :   if(fNdims > 5) printf("AliITSOnlineSPDfoAnalyzer::ChooseDACValues -> N. of dimensions are more than expected! Break! \n");
     411           0 :   TArrayI dacs(fNdims+1);
     412             :   
     413           0 :   for(Int_t i=0; i<fNdims+1; i++) dacs.AddAt(-1,i);
     414             :   
     415           0 :   for(Int_t iqual =0; iqual < kNqualityFlags; iqual++){
     416           0 :     if(!fNh[iqual][hs][chip]) continue;    
     417           0 :     if(fNh[iqual][hs][chip]->GetEntries()==0) continue;
     418           0 :     for(Int_t idim =0; idim<fNdims; idim++){
     419           0 :       if(dacs.At(idim)>=0) continue;
     420           0 :       tmp[idim] = fNh[iqual][hs][chip]->Projection(idim);
     421           0 :       dacs.AddAt((Int_t)tmp[idim]->GetBinLowEdge(tmp[idim]->GetMaximumBin()+1),idim);
     422           0 :       Int_t bin=-1;
     423           0 :       if(fFOHandler->GetFOscanInfo()->GetDACindex(idim)==fFOHandler->kIdPreVTH && CorrectPreVTHChioce(tmp[idim],bin)) {
     424           0 :        dacs.AddAt((Int_t)tmp[idim]->GetBinLowEdge(bin+1),idim);
     425             :       }
     426           0 :       dacs.AddAt(iqual,fNdims);
     427           0 :     }//idim
     428           0 :   }//iqual
     429             :   
     430           0 :   if(!IsExisting(dacs,hs,chip)  && dacs.At(fNdims)>-1) {   
     431           0 :    TArrayI centraldacs = GetCentralDACS(dacs.At(fNdims),hs,chip,tmp);
     432           0 :     dacs = centraldacs;
     433           0 :   }
     434             :   return dacs; 
     435           0 : }
     436             : //_____________________________________________________
     437             : Bool_t AliITSOnlineSPDfoAnalyzer::IsExisting(TArrayI dacs,Int_t hs, Int_t chip) const
     438             : {
     439             :   //
     440             :   // check the N-tuple corresponds to a real one
     441             :   //  
     442             :   
     443           0 :   if(dacs.At(fNdims)<0) return kFALSE;
     444             :   Bool_t isOk = kFALSE;
     445             :   
     446           0 :   Int_t size = dacs.GetSize()-1;
     447           0 :   Double_t *entry = new Double_t[size];
     448           0 :   for(Int_t i=0; i<size; i++) entry[i] = dacs.At(i);
     449           0 :   Int_t checkbin = fNh[dacs.At(dacs.GetSize()-1)][hs][chip]->GetBin(entry,kFALSE); // kFALSE does not allocate another bin
     450           0 :   if(checkbin > -1) isOk = kTRUE;
     451           0 :   delete [] entry;
     452           0 :   return isOk; 
     453           0 : }
     454             : //-----------------------------------------------------------
     455             : TArrayI AliITSOnlineSPDfoAnalyzer::GetCentralDACS(Int_t qualityflag, Int_t hs, Int_t chip, TH1D **hd) const
     456             : {
     457             :   //
     458             :   // This method gets the DAC values which are closest to the mean point in the N-dim histogram
     459             :   // It is called when the most probable DAC set does not correspond to a real entry in the N-dim
     460             :   // histogram.
     461             :   //
     462             :  
     463           0 :   TArrayI dacs(fNdims+1);
     464             :    
     465           0 :   Double_t *mean=new Double_t[fNdims];
     466           0 :   Int_t *goodbins=new Int_t[fNdims];
     467             :   Double_t distance = 9999999;
     468           0 :     for(Int_t i=0; i<fNdims ;i++){ 
     469           0 :     mean[i]=hd[i]->GetMean();
     470           0 :     goodbins[i]=0;
     471           0 :     dacs.AddAt(-1,i);
     472             :   }
     473             :   
     474           0 :   Int_t *bins = new Int_t[fNdims];
     475           0 :   Double_t *val=new Double_t[fNdims];
     476             :   
     477           0 :   for(Int_t in=0; in< fNh[qualityflag][hs][chip]->GetNbins() ; in++){
     478             :     
     479           0 :     fNh[qualityflag][hs][chip]->GetBinContent(in,bins);
     480             :     Double_t r2 = 0;  
     481           0 :     for(Int_t j=0; j<fNdims; j++) {
     482           0 :      val[j] = hd[j]->GetBinCenter(bins[j]);
     483           0 :       r2+=TMath::Power(val[j]-mean[j],2);
     484             :     }
     485             :     
     486           0 :     if(r2<distance) {
     487             :       distance = r2;
     488           0 :       fNh[qualityflag][hs][chip]->GetBinContent(in,goodbins);
     489             :     }    
     490             :   }
     491             :   
     492             :   
     493           0 :   for(Int_t k=0; k<fNdims; k++) {  
     494           0 :    dacs.AddAt((Int_t)(hd[k]->GetBinCenter(goodbins[k]) + 0.5*hd[k]->GetBinWidth(goodbins[k])),k);
     495             :   }
     496             :  
     497           0 :   dacs.AddAt(qualityflag,fNdims);
     498             :   
     499             :   
     500           0 :   delete [] mean;
     501           0 :   delete [] goodbins;
     502           0 :   delete [] bins;
     503           0 :   delete [] val;
     504             :   return dacs;
     505           0 : }
     506             : //-------------------------------------------------------
     507             : void AliITSOnlineSPDfoAnalyzer::ReadParamsFromLocation(const Char_t *dirName) 
     508             : {
     509             :   //
     510             :   // opens file (default name) in dir dirName and reads parameters from it
     511             :   // The file should be in database
     512             :   //
     513             :   
     514           0 :   TString paramsFileName = Form("./%s/focalib_params.txt",dirName);
     515             :   
     516           0 :   ifstream paramsFile;
     517           0 :   paramsFile.open(paramsFileName, ifstream::in);
     518           0 :   if (paramsFile.fail()) {
     519           0 :     printf("No config file (%s) present. Using default tuning parameters.\n",paramsFileName.Data());
     520             :   }
     521             :   else {
     522             :     while(1) {
     523           0 :       Char_t paramN[50];
     524           0 :       Char_t paramV[50];
     525           0 :       paramsFile >> paramN;
     526           0 :       if (paramsFile.eof()) break;
     527           0 :       paramsFile >> paramV;
     528           0 :       SetParam(paramN,paramV);
     529           0 :       if (paramsFile.eof()) break;
     530           0 :     }
     531           0 :     paramsFile.close();
     532             :   }
     533           0 : }
     534             : //---------------------------------------------------------
     535             : void AliITSOnlineSPDfoAnalyzer::SetParam(const Char_t *pname, const Char_t *pval) 
     536             : {
     537             :   //
     538             :   // sets a single parameter when reading from a file in the database
     539             :   //
     540             :   
     541           0 :   TString name = pname;
     542           0 :   TString val = pval;
     543             :   
     544             :   
     545           0 :   if (name.CompareTo("fGeneralThresholds0")==0) {
     546           0 :     fGeneralThresholds[0] = val.Atof();
     547           0 :   }
     548           0 :   else if (name.CompareTo("fGeneralThresholds1")==0) {
     549           0 :     fGeneralThresholds[1] = val.Atof();
     550           0 :   }
     551           0 :   else if (name.CompareTo("fGeneralThresholds2")==0) {
     552           0 :     fGeneralThresholds[2] = val.Atof();
     553           0 :   }
     554             :   else {
     555           0 :     Error("AliITSOnlineSPDscanAnalyzer::SetParam","Parameter %s in configuration file unknown.",name.Data());
     556             :   }
     557           0 : }
     558             : //--------------------------------------------------------
     559             : Bool_t AliITSOnlineSPDfoAnalyzer::CorrectPreVTHChioce(const TH1D *h,Int_t &bin) const
     560             : {
     561             :   //
     562             :   // Checks if more maxima of the same height are present in the pre_VTH case
     563             :   //
     564             :   
     565             :   
     566           0 :   Int_t maxbin = (Int_t)h->GetMaximumBin();
     567           0 :   Double_t maxentries = h->GetBinContent(maxbin);
     568             :   
     569             :   Int_t binindex = -1;
     570             :   Bool_t check=kFALSE;
     571             : 
     572           0 :   for(Int_t i=0; i< h->GetNbinsX(); i++){    
     573           0 :      if(h->GetBinContent(i) == maxentries){
     574           0 :       if(binindex <= i) binindex =i;
     575             :     }
     576             :   }
     577             :   
     578             :   
     579           0 :   if(binindex>-1) {
     580           0 :     bin=binindex;
     581             :     check = kTRUE; 
     582           0 :   }
     583             :   
     584             :   
     585           0 :   return check; 
     586             : }

Generated by: LCOV version 1.11