LCOV - code coverage report
Current view: top level - MUON/MUONcalib - AliMUONCalibParamNF.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 32 101 31.7 %
Date: 2016-06-14 17:26:59 Functions: 12 23 52.2 %

          Line data    Source code
       1             : /**************************************************************************
       2             : * Copyright(c) 1998-1999, 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             : #include "AliMUONCalibParamNF.h"
      19             : 
      20             : #include "AliLog.h"
      21             : 
      22             : #include "Riostream.h"
      23             : #include "TMath.h"
      24             : #include "TString.h"
      25             : 
      26             : #include <limits.h>
      27             : 
      28             : //-----------------------------------------------------------------------------
      29             : /// \class AliMUONCalibParamNF
      30             : ///
      31             : /// Handle the case of N floating point parameters per channel.
      32             : ///
      33             : /// \author Laurent Aphecetche
      34             : //-----------------------------------------------------------------------------
      35             : 
      36             : using std::cout;
      37             : using std::endl;
      38             : /// \cond CLASSIMP
      39          18 : ClassImp(AliMUONCalibParamNF)
      40             : /// \endcond
      41             : 
      42             : //_____________________________________________________________________________
      43             : AliMUONCalibParamNF::AliMUONCalibParamNF() 
      44      151348 : : AliMUONVCalibParam(),
      45      151348 :   fDimension(0),
      46      151348 :   fSize(0),
      47      151348 :   fN(0),
      48      151348 :   fValues(0x0)
      49      756740 : {
      50             : /// Default constructor.
      51      302696 : }
      52             : 
      53             : //_____________________________________________________________________________
      54             : AliMUONCalibParamNF::AliMUONCalibParamNF(Int_t dimension, Int_t theSize, 
      55             :                                          Int_t id0, Int_t id1,
      56             :                                          Float_t fillWithValue) 
      57       33656 : : AliMUONVCalibParam(id0,id1),
      58       33656 :   fDimension(dimension),
      59       33656 :   fSize(theSize),
      60       33656 :   fN(fSize*fDimension),
      61       33656 :   fValues(0x0)
      62      168280 : {
      63             : /// Normal constructor, where theSize specifies the number of channels handled
      64             : /// by this object, and fillWithValue the default value assigned to each
      65             : /// channel.
      66             : 
      67       33656 :   if ( fN > 0 )
      68             :   {
      69       67312 :     fValues = new Float_t[fN];
      70     4375280 :     for ( Int_t i = 0; i < fN; ++i )
      71             :     {
      72     2153984 :       fValues[i] = fillWithValue;
      73             :     }
      74       33656 :   }
      75       67312 : }
      76             : 
      77             : 
      78             : //_____________________________________________________________________________
      79             : AliMUONCalibParamNF::AliMUONCalibParamNF(const AliMUONCalibParamNF& other) 
      80           0 : : AliMUONVCalibParam(),
      81           0 : fDimension(0),
      82           0 : fSize(0),
      83           0 : fN(0),
      84           0 : fValues(0x0)
      85           0 : {
      86             : /// Copy constructor.
      87             : 
      88           0 :   other.CopyTo(*this);
      89           0 : }
      90             : 
      91             : //_____________________________________________________________________________
      92             : AliMUONCalibParamNF&
      93             : AliMUONCalibParamNF::operator=(const AliMUONCalibParamNF& other) 
      94             : {
      95             : /// Assignment operator
      96             : 
      97           0 :   other.CopyTo(*this);
      98           0 :   return *this;
      99             : }
     100             : 
     101             : //_____________________________________________________________________________
     102             : AliMUONCalibParamNF::~AliMUONCalibParamNF()
     103      201936 : {
     104             : /// Destructor
     105             : 
     106       67312 :   delete[] fValues;
     107      100968 : }
     108             : 
     109             : //_____________________________________________________________________________
     110             : void
     111             : AliMUONCalibParamNF::CopyTo(AliMUONCalibParamNF& destination) const
     112             : {
     113             : /// Copy *this to destination
     114             : 
     115           0 :   TObject::Copy(destination);
     116             :   
     117           0 :   delete[] destination.fValues;
     118           0 :   destination.fN = fN;
     119           0 :   destination.fSize = fSize;
     120           0 :   destination.fDimension = fDimension;
     121             :   
     122           0 :   if ( fN > 0 )
     123             :   {
     124           0 :     destination.fValues = new Float_t[fN];
     125           0 :     for ( Int_t i = 0; i < fN; ++i )
     126             :     {
     127           0 :       destination.fValues[i] = fValues[i];
     128             :     }
     129           0 :   }
     130           0 : }
     131             : 
     132             : //_____________________________________________________________________________
     133             : Int_t
     134             : AliMUONCalibParamNF::Index(Int_t i, Int_t j) const
     135             : {
     136             : /// Compute the 1D index of the internal storage from the pair (i,j)
     137             : /// Returns -1 if the (i,j) pair is invalid
     138             : 
     139       25040 :   if ( i >= 0 && i < Size() && j >= 0 && j < Dimension() )
     140             :   {
     141        6260 :     return IndexFast(i,j);
     142             :   }
     143           0 :   return -1;
     144        6260 : }
     145             : 
     146             : //_____________________________________________________________________________
     147             : Int_t
     148             : AliMUONCalibParamNF::IndexFast(Int_t i, Int_t j) const
     149             : {
     150             :   /// Compute the 1D index of the internal storage from the pair (i,j)
     151             :   
     152     8628456 :   return i + Size()*j;
     153             : }
     154             : 
     155             : //_____________________________________________________________________________
     156             : void
     157             : AliMUONCalibParamNF::Print(Option_t* opt) const
     158             : {
     159             : /// Output this object to stdout.
     160             : /// If opt=="full", then all channels are printed, 
     161             : /// if opt=="mean#", only the mean and sigma value are printed for j-th dimension
     162             : /// otherwise only the general characteristics are printed.
     163             : 
     164           0 :   TString sopt(opt);
     165           0 :   sopt.ToUpper();
     166           0 :   cout << Form("AliMUONCalibParamNF Id=(%d,%d) Size=%d Dimension=%d",ID0(),
     167           0 :                ID1(),Size(),Dimension()) << endl;
     168           0 :   if ( sopt.Contains("FULL") )
     169             :   {
     170           0 :     for ( Int_t i = 0; i < Size(); ++i )
     171             :     {
     172           0 :       cout << Form("CH %3d",i);
     173           0 :       for ( Int_t j = 0; j < Dimension(); ++j )
     174             :       {
     175           0 :         cout << Form(" %e",ValueAsFloat(i,j));
     176             :       }
     177           0 :       cout << endl;
     178             :     }
     179           0 :   }  
     180           0 :   if ( sopt.Contains("MEAN") )
     181             :   {
     182           0 :     Int_t j(0);
     183           0 :     sscanf(sopt.Data(),"MEAN%d",&j);
     184             :     
     185             :     Float_t mean(0);
     186             :     Float_t v2(0);
     187             :     
     188           0 :     Int_t n = Size();
     189             :     
     190           0 :     for ( Int_t i = 0; i < Size(); ++i )
     191             :     {
     192           0 :       Float_t v = ValueAsFloat(i,j);
     193           0 :       mean += v;
     194           0 :       v2 += v*v;
     195             :     }
     196           0 :     mean /= n;
     197             :     float sigma = 0;
     198           0 :     if ( n > 1 ) sigma = TMath::Sqrt( (v2-n*mean*mean)/(n-1) );
     199           0 :     cout << Form(" Mean(j=%d)=%e Sigma(j=%d)=%e",j,mean,j,sigma) << endl;
     200           0 :   }
     201             :   
     202           0 : }
     203             : 
     204             : //_____________________________________________________________________________
     205             : void
     206             : AliMUONCalibParamNF::SetValueAsFloat(Int_t i, Int_t j, Float_t value)
     207             : {
     208             : /// Set one value as a float, after checking that the indices are correct.
     209             : 
     210           0 :   Int_t ix = Index(i,j);
     211             :   
     212           0 :   if ( ix < 0 )
     213             :   {
     214           0 :     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
     215             :                   i,j,Size()-1,Dimension()-1));
     216           0 :   }
     217             :   else
     218             :   {
     219           0 :     fValues[ix]=value;
     220             :   }
     221           0 : }
     222             : 
     223             : //_____________________________________________________________________________
     224             : void
     225             : AliMUONCalibParamNF::SetValueAsFloatFast(Int_t i, Int_t j, Float_t value)
     226             : {
     227             :   /// Set one value as a float, w/o checking that the indices are correct.
     228             :   
     229           0 :   fValues[IndexFast(i,j)] = value;
     230           0 : }
     231             : 
     232             : //_____________________________________________________________________________
     233             : void
     234             : AliMUONCalibParamNF::SetValueAsInt(Int_t i, Int_t j, Int_t value)
     235             : {
     236             : /// Set one value as an int.
     237             : 
     238           0 :   SetValueAsFloat(i,j,static_cast<Float_t>(value));
     239           0 : }
     240             : 
     241             : //_____________________________________________________________________________
     242             : void
     243             : AliMUONCalibParamNF::SetValueAsIntFast(Int_t i, Int_t j, Int_t value)
     244             : {
     245             :   /// Set one value as an int.
     246             :   
     247           0 :   SetValueAsFloatFast(i,j,static_cast<Float_t>(value));
     248           0 : }
     249             : 
     250             : //_____________________________________________________________________________
     251             : Float_t
     252             : AliMUONCalibParamNF::ValueAsFloat(Int_t i, Int_t j) const
     253             : {
     254             : /// Return the value as a float (which it is), after checking indices.
     255             : 
     256       12520 :   Int_t ix = Index(i,j);
     257             :   
     258        6260 :   if ( ix < 0 )
     259             :   {
     260           0 :     AliError(Form("Invalid (i,j)=(%d,%d) max allowed is (%d,%d)",
     261             :                   i,j,Size()-1,Dimension()-1));
     262           0 :     return 0.0;
     263             :   }
     264             :   else
     265             :   {
     266        6260 :     return fValues[ix];
     267             :   }
     268        6260 : }
     269             : 
     270             : //_____________________________________________________________________________
     271             : Float_t
     272             : AliMUONCalibParamNF::ValueAsFloatFast(Int_t i, Int_t j) const
     273             : {
     274             :   /// Return the value as a float (which it is), after checking indices.
     275             :   
     276     8615936 :   return fValues[IndexFast(i,j)];
     277             : }
     278             : 
     279             : //_____________________________________________________________________________
     280             : Int_t
     281             : AliMUONCalibParamNF::ValueAsInt(Int_t i, Int_t j) const
     282             : {
     283             : /// Return the value as an int, by rounding the internal float value.
     284             : 
     285           0 :   Float_t v = ValueAsFloat(i,j);
     286             :   
     287           0 :   if ( v >= Float_t(INT_MAX) ) {
     288           0 :     AliErrorStream() 
     289           0 :       << "Cannot convert value " << v << " to Int_t." << endl;
     290           0 :     return 0;
     291             :   }  
     292             :   
     293           0 :   return TMath::Nint(v);
     294           0 : }
     295             : 
     296             : //_____________________________________________________________________________
     297             : Int_t
     298             : AliMUONCalibParamNF::ValueAsIntFast(Int_t i, Int_t j) const
     299             : {
     300             :   /// Return the value as an int, by rounding the internal float value.
     301             :   
     302           0 :   Float_t v = ValueAsFloatFast(i,j);
     303           0 :   return TMath::Nint(v);
     304             : }

Generated by: LCOV version 1.11