]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSCalibrationDB.cxx
Fatal if no magnetic field set for the reconstruction (Y.Belikov)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSCalibrationDB.cxx
CommitLineData
f74edaba 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//_________________________________________________________________________
19// Short description
20//
21//*-- Author : D.Peressounko (RRC KI & SUBATECH)
22//////////////////////////////////////////////////////////////////////////////
23
24// --- ROOT system ---
25#include "TFile.h"
26// --- Standard library ---
27#include <iostream.h>
28#include <fstream>
29
30// --- AliRoot header files ---
31#include "AliPHOSConTableDB.h"
32#include "AliPHOSCalibrationDB.h"
33#include "AliPHOSGeometry.h"
34ClassImp(AliPHOSCalibrationDB)
35
36
37//____________________________________________________________________________
38 AliPHOSCalibrationDB::AliPHOSCalibrationDB():TNamed()
39{
40 fPedestals = 0 ;
41 fSlopes = 0;
42 fNChannels = 0 ;
43 fctdb = 0 ;
44}
45//____________________________________________________________________________
46AliPHOSCalibrationDB::AliPHOSCalibrationDB(const char* filename ,const char * database):
47 TNamed("AliPHOSCalibrationDB",database){
48 //Creates the containers: we prepare places for all channels in PHOS
49
50 AliPHOSGeometry * geom = AliPHOSGeometry::GetInstance("GPS2","") ;
51 fNChannels = geom->GetNModules()*geom->GetNPhi()*geom->GetNZ()+
52 geom->GetNumberOfCPVPadsZ()*geom->GetNumberOfCPVPadsPhi()*geom->GetNModules() ;
53 //Note, that to avoid shifting AbsId each time we access data, we do not use
54 //first slot and index runs from 1 to fNChannels inclusively
55 fPedestals = new TArrayF(fNChannels+1) ;
56 fSlopes = new TArrayF(fNChannels+1) ;
57 fctdb = 0 ;
58}
59//____________________________________________________________________________
60 AliPHOSCalibrationDB::~AliPHOSCalibrationDB()
61{
62 if(fPedestals)
63 delete fPedestals ;
64 if(fSlopes)
65 delete fSlopes ;
66}
67//____________________________________________________________________________
68Float_t AliPHOSCalibrationDB::Calibrate(Int_t amp, Int_t absId)const
69{
70 //if absID is known, return calibrated energy, else - zero
71 if(absId <=0 || absId > fNChannels)
72 return 0.0000001 ;
73
74 Float_t ret = (amp - fPedestals->At(absId))*fSlopes->At(absId);
75 if(ret > 0)
76 return ret ;
77 else
78 return 0.0000001 ; //Should not be zero - to avoid FPE
79}
80//____________________________________________________________________________
81void AliPHOSCalibrationDB::SetAll(Float_t pedestal, Float_t slope){
82 //Set all calibration parameters to the same value
83 if(fPedestals)
84 for(Int_t i=0;i<fNChannels;i++){
85 fPedestals->AddAt(pedestal,i) ;
86 fSlopes->AddAt(slope,i);
87 }
88 else
89 cout << "Please, create me with non-default constructor!" << endl;
90}
91//____________________________________________________________________________
92void AliPHOSCalibrationDB::ReadCalibrationParameters(const char * filename, Option_t* opt){
93 //reads calibration parameters from ascii file
94
95 if(strcmp(opt,"gains")==0){ //read gains
96 if(!fctdb){
97 cout << "Specify Connections Table Database first" << endl ;
98 return ;
99 }
100 ifstream gainfile(filename) ;
101 for(Int_t i = 1; i<=64; i++){
102 Float_t slope ;
103 gainfile >> slope ;
104 fSlopes->AddAt(slope,fctdb->Raw2AbsId(i));
105 }
106 gainfile.close();
107 }
108 else
109 if(strstr(opt,"pedest")){ //read pedestals
110 if(!fctdb){
111 cout << "Specify Connections Table Database first" << endl ;
112 return ;
113 }
114 ifstream pfile(filename) ;
115 for(Int_t i = 1; i<=64; i++){
116 Float_t pedestal ;
117 pfile >> pedestal ;
118 fPedestals->AddAt(pedestal,fctdb->Raw2AbsId(i));
119 }
120 pfile.close();
121 }
122 else{
123 cout << "Available options are " << endl ;
124 cout << " `gains' : to read gains " << endl ;
125 cout << " `pedestals : to read pedestals " << endl ;
126 }
127}
128//____________________________________________________________________________
129AliPHOSCalibrationDB& AliPHOSCalibrationDB::operator=(AliPHOSCalibrationDB const & cdb)
130{
131 //
132 fNChannels = cdb.fNChannels;
133 fFileName = cdb.fFileName;
134 fPedestals=cdb.fPedestals ;
135 fSlopes = cdb.fSlopes;
136 return *this ;
137}