1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 // Objects of this class read txt file with APD number data
24 #include "AliEMCALCalibAPD.h"
26 const int kMaxLen = 1000; // maximum length of single line (# of characters)
27 // an OK line with complete info should have a certain number of characters
28 const int kMinLenAPDLine = 135;
29 const int kMaxLenAPDLine = 1000;
31 ClassImp(AliEMCALCalibAPD)
33 //____________________________________________________________________________
34 AliEMCALCalibAPD::AliEMCALCalibAPD() :
38 //Default constructor.
41 //____________________________________________________________________________
42 void AliEMCALCalibAPD::ReadCalibAPDInfo(Int_t nAPD, const TString &txtFileName)
44 //Read data from txt file. ; coordinates given on SuperModule basis
46 std::ifstream inputFile(txtFileName.Data());
48 printf("AliEMCALCalibAPD::ReadCalibAPDInfo - Cannot open the APD info file %s\n", txtFileName.Data());
53 if (fData) delete [] fData;
54 fData = new AliEMCALCalibAPDData[fNCalibAPD];
58 /* DS: header lines skipped when switched to white-spaced separeted dat files instead of csv:
59 conversion from spreadsheet can be done a la
60 sed 's/,/ /g' APD-database-Houston.csv | egrep ^2 | awk '{if (NF==19) {print $0}}' > APD-database-Houston.dat
61 - meaning "replace , with whitespace, only get the columns that start with the number 2 (Houston APDs),
62 and only get rows with the full 19 fields
65 inputFile.getline(line, kMaxLen);
66 // printf(" 1st header line character count %d\n", inputFile.gcount());
67 inputFile.getline(line, kMaxLen);
68 // printf(" 2nd header line character count %d\n", inputFile.gcount());
71 // variables for reading
73 float f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12;
76 int j = 0; // index for the ones that were read OK
77 for (Int_t i = 0; i < fNCalibAPD; i++) {
78 AliEMCALCalibAPDData &t = fData[j];
80 printf("AliEMCALCalibAPD::ReadCalibAPDInfo - Error while reading input file; likely EOF..\n");
81 fNCalibAPD = j; // that's how many we actually read succesfully
82 printf("AliEMCALCalibAPD::ReadCalibAPDInfo - read %d OK\n", fNCalibAPD);
86 // use some temporary/local values to perhaps help with the order when
87 // trying to read all the many fields in a line..
88 inputFile.getline(line, kMaxLen);
89 int nchar = inputFile.gcount();
90 //printf(" line %d ok %d - character count %d\n", i, j, nchar);
92 if (nchar>kMinLenAPDLine && nchar<kMaxLenAPDLine) {
93 // looks like the line has about the right number of characters, let's
94 // try to decode it now..
96 // printf("input: %s\n",line);
97 sscanf(line, "%d %u %s %s %d %d %f %f %f %f %f %f %f %f %f %d %f %f %f",
98 &i1, &i2, c1, c2, &i3, &i4, // header-type info
99 &f1, &f2, &f3, &f4, &f5, &f6, &f7, &f8, &f9, // measurements
100 &i5, &f10, &f11, &f12); // Hamamatsu
102 // printf("after scanf: %s\n",line);
104 printf("%d,%u,%s,%s,%d,%d,%g,%g,%g,%g,%g,%g,%g,%g,%g,%d,%g,%13.11f,%g\n",
105 i1, i2, c1, c2, i3, i4, // header-type info
106 f1, f2, f3, f4, f5, f6, f7, f8, f9, // measurements
107 i5, f10, f11, f12); // Hamamatsu
109 // assign the variables:
112 sprintf(t.fStatus,"%s",c1);
113 sprintf(t.fLocation,"%s",c2);
129 t.fDarkCurrent = f11;
132 j++; // increment our 'OK' counter..
133 } // line length appears OK
141 //____________________________________________________________________________
142 void AliEMCALCalibAPD::WriteCalibAPDInfo(const TString &txtFileName)
144 // write data to txt file. ; coordinates given on SuperModule basis
146 std::ofstream outputFile(txtFileName.Data());
148 printf("AliEMCALCalibAPD::WriteCalibAPDInfo - Cannot open the APD output file %s\n", txtFileName.Data());
154 for (Int_t i = 0; i < fNCalibAPD; i++) {
155 AliEMCALCalibAPDData &t = fData[i];
157 outputFile << t.fAPDNum << comma
158 << t.fSerialNum << comma // Serial Number; from Hamamatsu
159 << t.fStatus << comma //
160 << t.fLocation << comma //
161 << t.fRunNum << comma
162 << t.fTestPos << comma
163 << t.fV30 << comma // Catania/Houston Voltage V30 (V) at T = 25 deg C
165 << t.fVoltCoeff << comma // 1/M x dM/dV
166 << t.fPar[0] << comma // fit parameters, p0,p1,p2 - for ADC vs bias measurement
167 << t.fPar[1] << comma
168 << t.fPar[2] << comma
169 << t.fParErr[0] << comma // error on fit parameters
170 << t.fParErr[1] << comma
171 << t.fParErr[2] << comma
172 << t.fBreakDown << comma // Hamamatsu Breakdown Voltage (V)
173 << t.fHamV50 << comma; // Hamamatsu Voltage V50 (V)
174 // I wasn't able to quite reproduce the values as they appeared on the
175 // original file: e.g. dark current is not always 11-field - if last digit is zero..
176 // the other floats have 6 significant digits, but sometimes switch to
177 // scientific notation - don't know how to handle this for varying length of fields.. -leave it as is for now..
178 outputFile << t.fDarkCurrent << comma; // Hamamatsu Dark Current (A)
180 // some tweaking for the dark-current field to get the output the same
181 // as on the original CSV
182 outputFile.precision(11);
183 outputFile << fixed << t.fDarkCurrent << comma; // Hamamatsu Dark Current (A)
185 outputFile.precision(6); outputFile.unsetf(ios_base::floatfield);
188 outputFile << t.fTestTemp // Hamamatsu Testing Temperature (deg C)
198 //____________________________________________________________________________
199 AliEMCALCalibAPD::~AliEMCALCalibAPD()
204 //____________________________________________________________________________
205 AliEMCALCalibAPD::AliEMCALCalibAPDData AliEMCALCalibAPD::GetCalibAPDDataId(Int_t apdIndex)const
207 AliEMCALCalibAPDData t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
211 return fData[apdIndex];
214 //____________________________________________________________________________
215 AliEMCALCalibAPD::AliEMCALCalibAPDData AliEMCALCalibAPD::GetCalibAPDDataNum(Int_t apdNum)const
217 AliEMCALCalibAPDData t; // just to maybe prevent a crash, but we are returning something not-initialized so maybe not better really..
221 for (int i=0; i<fNCalibAPD; i++) {
222 if (fData[i].fAPDNum == apdNum) {
227 // if we made it to here, then no match was found - just return then