LCOV - code coverage report
Current view: top level - MUON/MUONcalib - AliMUONCalibParamND.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 38 102 37.3 %
Date: 2016-06-14 17:26:59 Functions: 14 27 51.9 %

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

Generated by: LCOV version 1.11