]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/SMcalib/WriteNewBias.C
fix coverity 23059, fix indentation
[u/mrichter/AliRoot.git] / EMCAL / SMcalib / WriteNewBias.C
CommitLineData
a8827307 1/*
2*/
cdb5074a 3const int debug = 0; // 0=quiet; 1=print some parameter info
a8827307 4
cdb5074a 5const int kMaxHV = 395; // default max voltage limit; could possibly be relaxed in future
6const int kBreakDownMargin = 5; // at least 5 V away from breakDown voltage..
a8827307 7
8static const int fgkEmCalRows = 24; // number of rows per module for EMCAL
9static const int fgkEmCalCols = 48; // number of columns per module for EMCAL
10
cdb5074a 11Float_t previousVoltage[fgkEmCalCols][fgkEmCalRows];
a8827307 12Float_t gainFactor[fgkEmCalCols][fgkEmCalRows];
cdb5074a 13Float_t biasVoltage[fgkEmCalCols][fgkEmCalRows];
a8827307 14
15//____________________________________________________________________
16void WriteNewBias(const char * inputDBName, const char * inputMapName,
17 const char * previousVoltageFileName, const char * gainFactorFileName,
18 const char * outputFileName)
19{
20
21 ofstream outputFile(outputFileName);
22 ReadFiles(previousVoltageFileName, gainFactorFileName);
23
24 SetBiasVoltage(inputDBName, inputMapName);
25
26 for (int icol=0; icol<fgkEmCalCols; icol++) {
27 for (int irow=0; irow<fgkEmCalRows; irow++) {
28 outputFile << icol << " " << irow << " " << biasVoltage[icol][irow] << endl;
29 }
30 }
31
32 outputFile.close();
33}
34
35//____________________________________________________________________
36void ReadFiles(const char * previousVoltageFileName,
37 const char * gainFactorFileName)
38{
39 ifstream previousVoltageFile(previousVoltageFileName);
40 ifstream gainFactorFile(gainFactorFileName);
41
42 int icolp, irowp;
43 int icolg, irowg;
44 Float_t gFactor;
cdb5074a 45 Float_t pVoltage;
a8827307 46
47 for (int icol=0; icol<fgkEmCalCols; icol++) {
48 for (int irow=0; irow<fgkEmCalRows; irow++) {
49 previousVoltageFile >> icolp >> irowp >> pVoltage;
50 gainFactorFile >> icolg >> irowg >> gFactor;
51
52 previousVoltage[icolp][irowp] = pVoltage;
53 gainFactor[icolg][irowg] = gFactor;
54 }
55 }
56
57 previousVoltageFile.close();
58 gainFactorFile.close();
59
60 return;
61}
62
63//____________________________________________________________________
64void SetBiasVoltage(const char * inputDBName, const char * inputMapName)
65{
66 gSystem->Load("AliEMCALCalibAPD_cxx");
67 AliEMCALCalibAPD *calibAPD = new AliEMCALCalibAPD();
68
69 calibAPD->ReadCalibAPDInfo(10000, inputDBName);
70 int fNCalibAPD = calibAPD->GetNCalibAPD();
71 AliEMCALCalibAPD::AliEMCALCalibAPDData * fCalib = calibAPD->GetCalibAPDData();
72
73
74 gSystem->Load("AliEMCALMapAPD_cxx");
75 AliEMCALMapAPD *mapAPD = new AliEMCALMapAPD();
76
77 int nSM = 1;
78 mapAPD->ReadMapAPDInfo(nSM, inputMapName);
79 AliEMCALMapAPD::AliEMCALSuperModuleMapAPD * fMap = mapAPD->GetSuperModuleData();
80
81 int nFound = 0;
82 for (int icol=0; icol<fgkEmCalCols; icol++) {
83 for (int irow=0; irow<fgkEmCalRows; irow++) {
84
85 int apdMap = fMap[0].fAPDNum[icol][irow]; // 0 = nSM - 1
86 int i = 0;
87 int apdCalib = -1;
88 while (i<fNCalibAPD && apdMap!=apdCalib) {
89 apdCalib = fCalib[i].fAPDNum;
90 i++;
91 }
92
93 if (apdCalib == apdMap) { // found!
94 i--; // go back to what we dound
95
96 // estimate what the new/target HV should be
97 biasVoltage[icol][irow] = CalculateTargetHV(previousVoltage[icol][irow],
98 gainFactor[icol][irow],
99 fCalib[i].fPar[0],
100 fCalib[i].fPar[1],
cdb5074a 101 fCalib[i].fPar[2],
102 fCalib[i].fBreakDown);
a8827307 103 nFound++;
104 }
105 else { // no calib info, just use old settings
106 biasVoltage[icol][irow] = previousVoltage[icol][irow];
107 }
108
109 }
110 }
111
112 cout << " found " << nFound << " matches " << endl;
113 return;
114}
115
116//____________________________________________________________________
cdb5074a 117Float_t CalculateTargetHV(Float_t initialHV, Float_t gainChange,
118 Float_t par0, Float_t par1, Float_t par2, Int_t breakDown)
a8827307 119{
cdb5074a 120 if (debug) { printf("parameters p0:%g p1:%g p2:%g\n", par0, par1, par2); }
a8827307 121
122 // figure out what new HV should be,
123 // if we want to adjust the gain by some factor
a8827307 124 Float_t initialGain = par0 + par1 * exp(par2*initialHV);
125 Float_t newGain = initialGain * gainChange; // = par0 + par1 * exp(par2*newHV);
126
cdb5074a 127 if (debug) { printf("initialGain:%g newGain:%g\n", initialGain, newGain); }
a8827307 128
cdb5074a 129 Float_t newHV = -1;
a8827307 130 if ( par1>0 && par2>0 ) {
cdb5074a 131 newHV = log ( (newGain - par0)/par1 ) / par2;
a8827307 132 }
a8827307 133
134 // check results before returning..
cdb5074a 135 if (newHV < 0) {
a8827307 136 // conversion failed: let's just keep the old custom value then
e6906cac 137 newHV = initialHV;
a8827307 138 }
139 if (newHV>kMaxHV) {
140 // we reached a too high voltage: let's keep the max then
141 newHV = kMaxHV;
142 }
143
cdb5074a 144 // in case we increase the kMaxHV limit some time in the future we could
145 // also enter get close to the Hamamatsu breakdown limit - let's avoid that
146 if (newHV>breakDown) {
147 newHV = breakDown - kBreakDownMargin;
148 }
149
a8827307 150 return newHV;
151}