ROOT logo
#ifndef ALIEMCALCALIBMAPAPD_H
#define ALIEMCALCALIBMAPAPD_H

/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
 * See cxx source for full Copyright notice                               */

/* $Id: $ */

#include <TObject.h>
#include <TObjArray.h>
#include "AliEMCALGeoParams.h"
#include <cmath>
class TString;
class TTree;

/*
  Objects of this class contain info on APD calibration and map info,
  such as V30 and other parameters from the tests in Catania/Houston,
  as well as info on which APD is located where.  
*/

// ******* internal class definition *************
// values per single APD
class AliEMCALCalibMapAPDVal : public TObject {

 public:
  AliEMCALCalibMapAPDVal() : TObject(), // just init values
    fHardWareId(0),
    fAPDNum(0),
    fV30(0),
    fBreakDown(0),
    fDarkCurrent(0) 
    {
      Init();
    }
  
  void Init() {
    fHardWareId = 0;
    fAPDNum = 0;
    fV30 = 0;
    fBreakDown = 0;
    fDarkCurrent = 0; 
    for (int i=0; i<3; i++) {
      fPar[i] = 0;
      fParErr[i] = 0;
    }
    return;
  }
  
 public:
  void SetHardWareId(Int_t i) { fHardWareId = i; }; //
  Int_t GetHardWareId() const { return fHardWareId; }; //
  void SetAPDNum(Int_t i) { fAPDNum = i; }; //
  Int_t GetAPDNum() const { return fAPDNum; }; //
  void SetV30(Float_t f) { fV30 = f; }; //
  Float_t GetV30() const { return fV30; }; // 
  void SetPar(int ip, Float_t f) { fPar[ip] = f; }; //
  Float_t GetPar(int ip) const { return fPar[ip]; }; // 
  void SetParErr(int ip, Float_t f) { fParErr[ip] = f; }; //
  Float_t GetParErr(int ip) const { return fParErr[ip]; }; // 
  void SetBreakDown(Int_t i) { fBreakDown = i; }; //
  Int_t GetBreakDown() const { return fBreakDown; }; //
  void SetDarkCurrent(Float_t f) { fDarkCurrent = f; }; //
  Float_t GetDarkCurrent() const { return fDarkCurrent; }; // 

 private:
  Int_t fHardWareId; // HardWareIndex
  // info from APD calibrations
  Int_t fAPDNum;    // assigned APD-PA number; Catania 10000-, Houston: 20000-
  Float_t fV30;      // Catania/Houston Voltage V30 (V) at T = 25 deg C
  Float_t fPar[3];   // fit parameters, p0,p1,p2 - for ADC vs bias measurement
  Float_t fParErr[3]; // error on fit parameters	
  
  Int_t fBreakDown; // Hamamatsu Breakdown Voltage (V)	
  Float_t fDarkCurrent; // Hamamatsu Dark Current (A)	
  
  ClassDef(AliEMCALCalibMapAPDVal, 2) // help class
}; // AliEMCALCalibAPDVal

// 1 SuperModule's worth of info: info on where the different APDs are
class AliEMCALSuperModuleCalibMapAPD : public TObject {
 public:
  AliEMCALSuperModuleCalibMapAPD(const int smNum=0) : TObject(), // just init values
    fSuperModuleNum(smNum)
    {
      for (int icol=0; icol<AliEMCALGeoParams::fgkEMCALCols; icol++) {
	for (int irow=0; irow<AliEMCALGeoParams::fgkEMCALRows; irow++) {
	  fAPDVal[icol][irow].Init();
	}
      }
    }
  
 public:
  void SetSuperModuleNum(Int_t i) { fSuperModuleNum = i;}; // 
  Int_t GetSuperModuleNum() const { return fSuperModuleNum;}; // 
  AliEMCALCalibMapAPDVal * GetAPDVal(int icol, int irow) 
    { return &fAPDVal[icol][irow]; };

 private:
  Int_t fSuperModuleNum; // SuperModule index
  AliEMCALCalibMapAPDVal fAPDVal[AliEMCALGeoParams::fgkEMCALCols][AliEMCALGeoParams::fgkEMCALRows]; // APD calibration info
  
  ClassDef(AliEMCALSuperModuleCalibMapAPD, 2) // help class
};
// ******* end of internal class definition *************    
    
class AliEMCALCalibMapAPD : public TObject {

public:

  enum kValType {kCalibTemp=25};// 25 deg C used for all APD calibrations

  AliEMCALCalibMapAPD(const int nSM = AliEMCALGeoParams::fgkEMCALModules);

  // Read and Write txt I/O methods are normally not used, but are useful for 
  // filling the object before it is saved in OCDB 
  void ReadTextCalibMapAPDInfo(Int_t nSM, const TString &txtFileName, Bool_t swapSides=kFALSE); // info file is for nSm=1 to fgkEMCALModules
  void WriteTextCalibMapAPDInfo(const TString &txtFileName, Bool_t swapSides=kFALSE); // info file is for nSm=1 to fgkEMCALModules
  void ReadRootCalibMapAPDInfo(const TString &rootFileName, Bool_t swapSides=kFALSE); // info file is for nSm=1 to fgkEMCALModules
  void ReadTreeCalibMapAPDInfo(TTree *tree, Bool_t swapSides=kFALSE); // info file is for nSm=1 to fgkEMCALModules
  void WriteRootCalibMapAPDInfo(const TString &rootFileName, Bool_t swapSides=kFALSE); // info file is for nSm=1 to fgkEMCALModules

  virtual ~AliEMCALCalibMapAPD();

  // pointer to stored info.
  Int_t GetNSuperModule() const { return fNSuperModule; }; 

  // on a SuperModule level
  virtual AliEMCALSuperModuleCalibMapAPD * GetSuperModuleCalibMapAPDId(Int_t smIndex) const
    { return (AliEMCALSuperModuleCalibMapAPD*) fSuperModuleData[smIndex]; }; // - via the index in the stored array:

  virtual AliEMCALSuperModuleCalibMapAPD * GetSuperModuleCalibMapAPDNum(Int_t smNum) const;   // - or via the actual SM number
  
  // method to calculate gain M from fit parameters, and HV value
  Float_t GetGain(Float_t fitPar[3], Float_t HV) const 
    { return (fitPar[0] + fitPar[1] * exp(fitPar[2]*HV)); };
  Float_t GetGain(Float_t fitPar0, Float_t fitPar1, Float_t fitPar2, Float_t HV) const 
    { return (fitPar0 + fitPar1 * exp(fitPar2*HV)); };

protected:

  Int_t 	  fNSuperModule; // Number of supermodules.
  TObjArray fSuperModuleData; // SuperModule data

private:

  AliEMCALCalibMapAPD(const AliEMCALCalibMapAPD &);
  AliEMCALCalibMapAPD &operator = (const AliEMCALCalibMapAPD &);

  ClassDef(AliEMCALCalibMapAPD, 3) //CalibMapAPD data info
};

#endif
 AliEMCALCalibMapAPD.h:1
 AliEMCALCalibMapAPD.h:2
 AliEMCALCalibMapAPD.h:3
 AliEMCALCalibMapAPD.h:4
 AliEMCALCalibMapAPD.h:5
 AliEMCALCalibMapAPD.h:6
 AliEMCALCalibMapAPD.h:7
 AliEMCALCalibMapAPD.h:8
 AliEMCALCalibMapAPD.h:9
 AliEMCALCalibMapAPD.h:10
 AliEMCALCalibMapAPD.h:11
 AliEMCALCalibMapAPD.h:12
 AliEMCALCalibMapAPD.h:13
 AliEMCALCalibMapAPD.h:14
 AliEMCALCalibMapAPD.h:15
 AliEMCALCalibMapAPD.h:16
 AliEMCALCalibMapAPD.h:17
 AliEMCALCalibMapAPD.h:18
 AliEMCALCalibMapAPD.h:19
 AliEMCALCalibMapAPD.h:20
 AliEMCALCalibMapAPD.h:21
 AliEMCALCalibMapAPD.h:22
 AliEMCALCalibMapAPD.h:23
 AliEMCALCalibMapAPD.h:24
 AliEMCALCalibMapAPD.h:25
 AliEMCALCalibMapAPD.h:26
 AliEMCALCalibMapAPD.h:27
 AliEMCALCalibMapAPD.h:28
 AliEMCALCalibMapAPD.h:29
 AliEMCALCalibMapAPD.h:30
 AliEMCALCalibMapAPD.h:31
 AliEMCALCalibMapAPD.h:32
 AliEMCALCalibMapAPD.h:33
 AliEMCALCalibMapAPD.h:34
 AliEMCALCalibMapAPD.h:35
 AliEMCALCalibMapAPD.h:36
 AliEMCALCalibMapAPD.h:37
 AliEMCALCalibMapAPD.h:38
 AliEMCALCalibMapAPD.h:39
 AliEMCALCalibMapAPD.h:40
 AliEMCALCalibMapAPD.h:41
 AliEMCALCalibMapAPD.h:42
 AliEMCALCalibMapAPD.h:43
 AliEMCALCalibMapAPD.h:44
 AliEMCALCalibMapAPD.h:45
 AliEMCALCalibMapAPD.h:46
 AliEMCALCalibMapAPD.h:47
 AliEMCALCalibMapAPD.h:48
 AliEMCALCalibMapAPD.h:49
 AliEMCALCalibMapAPD.h:50
 AliEMCALCalibMapAPD.h:51
 AliEMCALCalibMapAPD.h:52
 AliEMCALCalibMapAPD.h:53
 AliEMCALCalibMapAPD.h:54
 AliEMCALCalibMapAPD.h:55
 AliEMCALCalibMapAPD.h:56
 AliEMCALCalibMapAPD.h:57
 AliEMCALCalibMapAPD.h:58
 AliEMCALCalibMapAPD.h:59
 AliEMCALCalibMapAPD.h:60
 AliEMCALCalibMapAPD.h:61
 AliEMCALCalibMapAPD.h:62
 AliEMCALCalibMapAPD.h:63
 AliEMCALCalibMapAPD.h:64
 AliEMCALCalibMapAPD.h:65
 AliEMCALCalibMapAPD.h:66
 AliEMCALCalibMapAPD.h:67
 AliEMCALCalibMapAPD.h:68
 AliEMCALCalibMapAPD.h:69
 AliEMCALCalibMapAPD.h:70
 AliEMCALCalibMapAPD.h:71
 AliEMCALCalibMapAPD.h:72
 AliEMCALCalibMapAPD.h:73
 AliEMCALCalibMapAPD.h:74
 AliEMCALCalibMapAPD.h:75
 AliEMCALCalibMapAPD.h:76
 AliEMCALCalibMapAPD.h:77
 AliEMCALCalibMapAPD.h:78
 AliEMCALCalibMapAPD.h:79
 AliEMCALCalibMapAPD.h:80
 AliEMCALCalibMapAPD.h:81
 AliEMCALCalibMapAPD.h:82
 AliEMCALCalibMapAPD.h:83
 AliEMCALCalibMapAPD.h:84
 AliEMCALCalibMapAPD.h:85
 AliEMCALCalibMapAPD.h:86
 AliEMCALCalibMapAPD.h:87
 AliEMCALCalibMapAPD.h:88
 AliEMCALCalibMapAPD.h:89
 AliEMCALCalibMapAPD.h:90
 AliEMCALCalibMapAPD.h:91
 AliEMCALCalibMapAPD.h:92
 AliEMCALCalibMapAPD.h:93
 AliEMCALCalibMapAPD.h:94
 AliEMCALCalibMapAPD.h:95
 AliEMCALCalibMapAPD.h:96
 AliEMCALCalibMapAPD.h:97
 AliEMCALCalibMapAPD.h:98
 AliEMCALCalibMapAPD.h:99
 AliEMCALCalibMapAPD.h:100
 AliEMCALCalibMapAPD.h:101
 AliEMCALCalibMapAPD.h:102
 AliEMCALCalibMapAPD.h:103
 AliEMCALCalibMapAPD.h:104
 AliEMCALCalibMapAPD.h:105
 AliEMCALCalibMapAPD.h:106
 AliEMCALCalibMapAPD.h:107
 AliEMCALCalibMapAPD.h:108
 AliEMCALCalibMapAPD.h:109
 AliEMCALCalibMapAPD.h:110
 AliEMCALCalibMapAPD.h:111
 AliEMCALCalibMapAPD.h:112
 AliEMCALCalibMapAPD.h:113
 AliEMCALCalibMapAPD.h:114
 AliEMCALCalibMapAPD.h:115
 AliEMCALCalibMapAPD.h:116
 AliEMCALCalibMapAPD.h:117
 AliEMCALCalibMapAPD.h:118
 AliEMCALCalibMapAPD.h:119
 AliEMCALCalibMapAPD.h:120
 AliEMCALCalibMapAPD.h:121
 AliEMCALCalibMapAPD.h:122
 AliEMCALCalibMapAPD.h:123
 AliEMCALCalibMapAPD.h:124
 AliEMCALCalibMapAPD.h:125
 AliEMCALCalibMapAPD.h:126
 AliEMCALCalibMapAPD.h:127
 AliEMCALCalibMapAPD.h:128
 AliEMCALCalibMapAPD.h:129
 AliEMCALCalibMapAPD.h:130
 AliEMCALCalibMapAPD.h:131
 AliEMCALCalibMapAPD.h:132
 AliEMCALCalibMapAPD.h:133
 AliEMCALCalibMapAPD.h:134
 AliEMCALCalibMapAPD.h:135
 AliEMCALCalibMapAPD.h:136
 AliEMCALCalibMapAPD.h:137
 AliEMCALCalibMapAPD.h:138
 AliEMCALCalibMapAPD.h:139
 AliEMCALCalibMapAPD.h:140
 AliEMCALCalibMapAPD.h:141
 AliEMCALCalibMapAPD.h:142
 AliEMCALCalibMapAPD.h:143
 AliEMCALCalibMapAPD.h:144
 AliEMCALCalibMapAPD.h:145
 AliEMCALCalibMapAPD.h:146
 AliEMCALCalibMapAPD.h:147
 AliEMCALCalibMapAPD.h:148
 AliEMCALCalibMapAPD.h:149
 AliEMCALCalibMapAPD.h:150
 AliEMCALCalibMapAPD.h:151
 AliEMCALCalibMapAPD.h:152
 AliEMCALCalibMapAPD.h:153