LCOV - code coverage report
Current view: top level - TOF/TOFbase - AliTOFRunParams.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 17 149 11.4 %
Date: 2016-06-14 17:26:59 Functions: 4 18 22.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             : // *
      17             : // *
      18             : // *
      19             : // * this class defines the TOF object to be stored
      20             : // * in OCDB on a run-by-run basis in order to have the measurement
      21             : // * of the time evolution of T0 and of TOF resolution including
      22             : // * average T0 uncertainty
      23             : // *
      24             : // *
      25             : // *
      26             : 
      27             : #include "AliTOFRunParams.h"
      28             : #include "TGraph.h"
      29             : 
      30          26 : ClassImp(AliTOFRunParams)
      31             : 
      32             : //_________________________________________________________
      33             : 
      34             : AliTOFRunParams::AliTOFRunParams() :
      35           3 :   TObject(),
      36           3 :   fNPoints(0),
      37           3 :   fTimestamp(NULL),
      38           3 :   fT0(NULL),
      39           3 :   fTOFResolution(NULL),
      40           3 :   fT0Spread(NULL),
      41           3 :   fNRuns(0),
      42           3 :   fRunNb(NULL),
      43           3 :   fRunFirstPoint(NULL),
      44           3 :   fRunLastPoint(NULL),
      45           3 :   fUseLHCClockPhase(kFALSE)
      46          15 : {
      47             :   /*
      48             :    * default constructor
      49             :    */
      50           6 : }
      51             : 
      52             : //_________________________________________________________
      53             : 
      54             : AliTOFRunParams::AliTOFRunParams(Int_t nPoints, Int_t nRuns) :
      55           0 :   TObject(),
      56           0 :   fNPoints(nPoints),
      57           0 :   fTimestamp(new UInt_t[nPoints]),
      58           0 :   fT0(new Float_t[nPoints]),
      59           0 :   fTOFResolution(new Float_t[nPoints]),
      60           0 :   fT0Spread(new Float_t[nPoints]),
      61           0 :   fNRuns(nRuns),
      62           0 :   fRunNb(new UInt_t[nRuns]),
      63           0 :   fRunFirstPoint(new UInt_t[nRuns]),
      64           0 :   fRunLastPoint(new UInt_t[nRuns]),
      65           0 :   fUseLHCClockPhase(kFALSE)
      66           0 : {
      67             :   /*
      68             :    * standard constructor
      69             :    */
      70           0 : }
      71             : 
      72             : //_________________________________________________________
      73             : 
      74             : AliTOFRunParams::~AliTOFRunParams()
      75           0 : {
      76             :   /*
      77             :    * default destructor
      78             :    */
      79             : 
      80           0 :   if (fTimestamp) delete [] fTimestamp;
      81           0 :   if (fT0) delete [] fT0;
      82           0 :   if (fTOFResolution) delete [] fTOFResolution;
      83           0 :   if (fT0Spread) delete [] fT0Spread;
      84           0 :   if (fRunNb) delete [] fRunNb;
      85           0 :   if (fRunFirstPoint) delete [] fRunFirstPoint;
      86           0 :   if (fRunLastPoint) delete [] fRunLastPoint;
      87           0 : }
      88             : 
      89             : //_________________________________________________________
      90             : 
      91             : AliTOFRunParams::AliTOFRunParams(const AliTOFRunParams &source) :
      92           0 :   TObject(source),
      93           0 :   fNPoints(source.fNPoints),
      94           0 :   fTimestamp(new UInt_t[source.fNPoints]),
      95           0 :   fT0(new Float_t[source.fNPoints]),
      96           0 :   fTOFResolution(new Float_t[source.fNPoints]),
      97           0 :   fT0Spread(new Float_t[source.fNPoints]),
      98           0 :   fNRuns(source.fNRuns),
      99           0 :   fRunNb(new UInt_t[source.fNRuns]),
     100           0 :   fRunFirstPoint(new UInt_t[source.fNRuns]),
     101           0 :   fRunLastPoint(new UInt_t[source.fNRuns]),
     102           0 :   fUseLHCClockPhase(source.fUseLHCClockPhase)
     103           0 : {
     104             :   /*
     105             :    * copy constructor
     106             :    */
     107             : 
     108           0 :   for (Int_t i = 0; i < fNPoints; i++) {
     109           0 :     fTimestamp[i] = source.fTimestamp[i];
     110           0 :     fT0[i] = source.fT0[i];
     111           0 :     fTOFResolution[i] = source.fTOFResolution[i];
     112           0 :     fT0Spread[i] = source.fT0Spread[i];
     113             :   }
     114             : 
     115           0 :   for (Int_t i = 0; i < fNRuns; i++) {
     116           0 :     fRunNb[i] = source.fRunNb[i];
     117           0 :     fRunFirstPoint[i] = source.fRunFirstPoint[i];
     118           0 :     fRunLastPoint[i] = source.fRunLastPoint[i];
     119             :   }
     120             :   
     121           0 : }
     122             : 
     123             : //_________________________________________________________
     124             : 
     125             : AliTOFRunParams &
     126             : AliTOFRunParams::operator=(const AliTOFRunParams &source)
     127             : {
     128             :   /*
     129             :    * operator=
     130             :    */
     131             : 
     132           0 :   if (this == &source) return *this;
     133           0 :   TObject::operator=(source);
     134             :   
     135           0 :   if (fNPoints != source.fNPoints) {
     136           0 :     if (fTimestamp) delete [] fTimestamp;
     137           0 :     if (fT0) delete [] fT0;
     138           0 :     if (fTOFResolution) delete [] fTOFResolution;
     139           0 :     if (fT0Spread) delete [] fT0Spread;
     140           0 :     fNPoints = source.fNPoints;
     141           0 :     fTimestamp = new UInt_t[source.fNPoints];
     142           0 :     fT0 = new Float_t[source.fNPoints];
     143           0 :     fTOFResolution = new Float_t[source.fNPoints];
     144           0 :     fT0Spread = new Float_t[source.fNPoints];
     145           0 :   }
     146             : 
     147           0 :   for (Int_t i = 0; i < fNPoints; i++) {
     148           0 :     fTimestamp[i] = source.fTimestamp[i];
     149           0 :     fT0[i] = source.fT0[i];
     150           0 :     fTOFResolution[i] = source.fTOFResolution[i];
     151           0 :     fT0Spread[i] = source.fT0Spread[i];
     152             :   }
     153             : 
     154           0 :   if (fNRuns != source.fNRuns) {
     155           0 :     if (fRunNb) delete [] fRunNb;
     156           0 :     if (fRunFirstPoint) delete [] fRunFirstPoint;
     157           0 :     if (fRunLastPoint) delete [] fRunLastPoint;
     158           0 :     fNRuns = source.fNRuns;
     159           0 :     fRunNb = new UInt_t[source.fNRuns];
     160           0 :     fRunFirstPoint = new UInt_t[source.fNRuns];
     161           0 :     fRunLastPoint = new UInt_t[source.fNRuns];
     162           0 :   }
     163             : 
     164           0 :   for (Int_t i = 0; i < fNRuns; i++) {
     165           0 :     fRunNb[i] = source.fRunNb[i];
     166           0 :     fRunFirstPoint[i] = source.fRunFirstPoint[i];
     167           0 :     fRunLastPoint[i] = source.fRunLastPoint[i];
     168             :   }
     169             : 
     170           0 :   fUseLHCClockPhase = source.fUseLHCClockPhase;
     171             : 
     172           0 :   return *this;
     173           0 : }
     174             : 
     175             : //_________________________________________________________
     176             : 
     177             : Float_t
     178             : AliTOFRunParams::EvalT0(UInt_t timestamp)
     179             : {
     180             :   /*
     181             :    * eval T0
     182             :    */
     183             : 
     184             :   /* critical cases:
     185             :      1. no measurement -> 0.
     186             :      2. single measurement -> single value
     187             :      3. timestamp before first measurement -> first value
     188             :      4. timestamp after last measurement -> last value
     189             :   */
     190        1200 :   if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
     191         600 :   if (fNPoints == 1) return fT0[0];
     192           0 :   if (timestamp <= fTimestamp[0]) return fT0[0];
     193           0 :   if (timestamp >= fTimestamp[fNPoints - 1]) return fT0[fNPoints - 1];
     194             : 
     195             :   /* interpolate value */
     196             :   Int_t ipoint;
     197           0 :   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
     198           0 :     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
     199             :       break;
     200           0 :   Float_t coeff = (fT0[ipoint + 1] - fT0[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
     201           0 :   Float_t t0 = fT0[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
     202             :   
     203             :   return t0;
     204         300 : }
     205             : 
     206             : //_________________________________________________________
     207             : 
     208             : Float_t
     209             : AliTOFRunParams::EvalTOFResolution(UInt_t timestamp)
     210             : {
     211             :   /*
     212             :    * eval TOF resolution
     213             :    */
     214             : 
     215             :   /* critical cases:
     216             :      1. no measurement -> 0.
     217             :      2. single measurement -> single value
     218             :      3. timestamp before first measurement -> first value
     219             :      4. timestamp after last measurement -> last value
     220             :   */
     221           0 :   if (fNPoints <= 0 || !fTOFResolution || !fTimestamp) return 0.;
     222           0 :   if (fNPoints == 1) return fTOFResolution[0];
     223           0 :   if (timestamp <= fTimestamp[0]) return fTOFResolution[0];
     224           0 :   if (timestamp >= fTimestamp[fNPoints - 1]) return fTOFResolution[fNPoints - 1];
     225             : 
     226             :   /* interpolate value */
     227             :   Int_t ipoint;
     228           0 :   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
     229           0 :     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
     230             :       break;
     231           0 :   Float_t coeff = (fTOFResolution[ipoint + 1] - fTOFResolution[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
     232           0 :   Float_t reso = fTOFResolution[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
     233             :   
     234             :   return reso;
     235           0 : }
     236             : 
     237             : //_________________________________________________________
     238             : 
     239             : Float_t
     240             : AliTOFRunParams::EvalT0Spread(UInt_t timestamp)
     241             : {
     242             :   /*
     243             :    * eval T0 spread
     244             :    */
     245             : 
     246             :   /* critical cases:
     247             :      1. no measurement -> 0.
     248             :      2. single measurement -> single value
     249             :      3. timestamp before first measurement -> first value
     250             :      4. timestamp after last measurement -> last value
     251             :   */
     252           0 :   if (fNPoints <= 0 || !fT0Spread || !fTimestamp) return 0.;
     253           0 :   if (fNPoints == 1) return fT0Spread[0];
     254           0 :   if (timestamp <= fTimestamp[0]) return fT0Spread[0];
     255           0 :   if (timestamp >= fTimestamp[fNPoints - 1]) return fT0Spread[fNPoints - 1];
     256             : 
     257             :   /* interpolate value */
     258             :   Int_t ipoint;
     259           0 :   for (ipoint = 0; ipoint < fNPoints - 1; ipoint++)
     260           0 :     if (timestamp >= fTimestamp[ipoint] && timestamp < fTimestamp[ipoint + 1])
     261             :       break;
     262           0 :   Float_t coeff = (fT0Spread[ipoint + 1] - fT0Spread[ipoint]) / (Float_t)(fTimestamp[ipoint + 1] - fTimestamp[ipoint]);
     263           0 :   Float_t spread = fT0Spread[ipoint] + coeff * (timestamp - fTimestamp[ipoint]);
     264             :   
     265             :   return spread;
     266           0 : }
     267             : 
     268             : //_________________________________________________________
     269             : 
     270             : Float_t
     271             : AliTOFRunParams::Average(Float_t *data, Int_t first, Int_t last)
     272             : {
     273             :   /*
     274             :    * average
     275             :    */
     276             : 
     277           0 :   if (first < 0) first = 0;
     278           0 :   if (last >= fNPoints) last = fNPoints - 1;
     279             :   Float_t value = 0.;
     280             :   Int_t npt = 0;
     281           0 :   for (Int_t i = first; i <= last; i++) {
     282           0 :     value += data[i];
     283           0 :     npt++;
     284             :   }
     285           0 :   if (npt <= 0) return 0.;
     286           0 :   value /= npt;
     287           0 :   return value;
     288             : 
     289           0 : }
     290             : 
     291             : //_________________________________________________________
     292             : 
     293             : Float_t
     294             : AliTOFRunParams::Average(Float_t *data, UInt_t runNb)
     295             : {
     296             :   /*
     297             :    * average
     298             :    */
     299             : 
     300             :   /* critical cases:
     301             :      1. no measurement -> 0.
     302             :      2. no runNb structure -> average over all points
     303             :      3. runNb not found -> average over all points
     304             :   */
     305           0 :   if (fNPoints <= 0 || !fT0 || !fTimestamp) return 0.;
     306           0 :   if (fNRuns <= 0 || !fRunNb || !fRunFirstPoint || !fRunLastPoint) return Average(data, 0, fNPoints - 1);
     307             : 
     308             : 
     309             :   /* search for runNb */
     310             :   UInt_t runPoint = 0;
     311             :   Bool_t gotRunNb = kFALSE;
     312           0 :   for (Int_t irun = 0; irun < fNRuns; irun++) {
     313           0 :     if (fRunNb[irun] == runNb) {
     314             :       runPoint = irun;
     315             :       gotRunNb = kTRUE;
     316           0 :       break;
     317             :     }
     318             :   }
     319           0 :   if (!gotRunNb) return Average(data, 0, fNPoints - 1);
     320             : 
     321             :   /* average between first and last run points */
     322           0 :   UInt_t firstPoint = fRunFirstPoint[runPoint];
     323           0 :   UInt_t lastPoint = fRunLastPoint[runPoint];
     324           0 :   return Average(data, firstPoint, lastPoint);
     325             : 
     326           0 : }
     327             : 
     328             : //_________________________________________________________
     329             : 
     330             : TGraph *
     331             : AliTOFRunParams::DrawGraph(Float_t *data, Option_t* option)
     332             : {
     333             :   /*
     334             :    * draw
     335             :    */
     336             : 
     337           0 :   if (fNPoints == 0 || !data || !fTimestamp) return NULL;
     338             : 
     339           0 :   Float_t ts[1000000];
     340           0 :   for (Int_t i = 0; i < fNPoints; i++)
     341           0 :     ts[i] = fTimestamp[i];
     342             : 
     343           0 :   TGraph *graph = new TGraph(fNPoints, ts, data);
     344           0 :   graph->Draw(option);
     345             :   return graph;
     346           0 : }
     347             : 
     348             : //_________________________________________________________
     349             : 
     350             : TGraph *
     351             : AliTOFRunParams::DrawCorrelationGraph(Float_t *datax, Float_t *datay, Option_t* option)
     352             : {
     353             :   /*
     354             :    * draw
     355             :    */
     356             : 
     357           0 :   if (fNPoints == 0 || !datax || !datay) return NULL;
     358             : 
     359           0 :   TGraph *graph = new TGraph(fNPoints, datax, datay);
     360           0 :   graph->Draw(option);
     361             :   return graph;
     362           0 : }
     363             : 

Generated by: LCOV version 1.11