AliPhysics  2c6b7ad (2c6b7ad)
HVrecalculation_EMCALthirds.C
Go to the documentation of this file.
1 #include <signal.h>
2 //#include <sys/time.h>
3 #include <stdio.h>
4 #include <vector>
5 #include <iostream>
6 #include <fstream>
7 #include <string>
8 #include <iosfwd>
9 #include <iostream>
10 #include <numeric>
11 #include <queue>
12 #include <set>
13 #include <sstream>
14 
15 #include <map>
16 #include <utility>
17 #include <iterator>
18 
19 
20 #include <TSystem.h> //To have gSystem known at compilation time
21 #include <TApplication.h>
22 #include <TChain.h>
23 #include <TF1.h>
24 #include <TH1F.h>
25 #include <TH2F.h>
26 #include <TFile.h>
27 #include <TCanvas.h>
28 #include <TFrame.h>
29 #include <TPostScript.h>
30 #include <TLine.h>
31 #include <TGaxis.h>
32 #include <TStyle.h>
33 #include <TGraphErrors.h>
34 #include <TMath.h>
35 #include <TMatrixF.h>
36 #include <TText.h>
37 
38 
39 //#include "/cebaf/faivre/recherche/utilities/defineMyPalette2011.C"
40 
41 
42 namespace std {} using namespace std;
43 
44 
45 const double kMaxHV = 395.; // default max voltage limit; could possibly be relaxed in future
46 const double kMinHV = 210.; // Hexa encoding limit
47 const double coefFactorWanted=0.0162;
48 
49 
50 // voir http://dsilverm.web.cern.ch/dsilverm/fee/addrP2.html
51  char SMP2Name[][100]={"SMA0","SMC0","SMA1","SMC1","SMA2","SMC2","SMA3","SMC3","SMA4","SMC4","SMA5","SMC5","SMA9","SMC9","SMA10","SMC10","SMA11","SMC11","SMA12","SMC12"};
52  char SMcalibName[][100]={"US2","US1","EU2","EU1","US3","US5","US4","EU3","US7","US6","US8C0","US8C2","DCN1","DJP1","DUS2","DUS1","DJP2","DUS3","CN1A","CN1C"};
53  char SMnumber[][100]={"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19"};
54 
57  char detTypeString[][100]={"EMCAL","EMCALthird","DCAL","DCALthird"};
59  const int kNbColEMCAL=48;
60  const int kNbRowEMCAL=24;
61  const int kNbSMEMCAL=10;
63  const int kNbRowEMCALthird=(int)(kNbRowEMCAL/3);
64  const int kNbSMEMCALthird=2;
65  const int kNbColDCAL=32;
67  const int kNbSMDCAL=6;
70  const int kNbSMDCALthird=2;
71  const int kNbSMtot=kNbSMEMCAL+kNbSMEMCALthird+kNbSMDCAL+kNbSMDCALthird;
72  const int kTabNbCol[4]={kNbColEMCAL,kNbColEMCALthird,kNbColDCAL,kNbColDCALthird};
73  const int kTabNbRow[4]={kNbRowEMCAL,kNbRowEMCALthird,kNbRowDCAL,kNbRowDCALthird};
74  const int kTabNbSM[4]={kNbSMEMCAL,kNbSMEMCALthird,kNbSMDCAL,kNbSMDCALthird};
78 
79  int lastSM;
80 
81 
82 
83 
129 
130 
134 void CalcNewHVperSM(TString hvFileName,TString paramFileName,int smNb,char *fchNameBase,FILE *outFile,FILE *badGainFileOut,double coeffOCDB[kNbSMtot][kNbColMax][kNbRowMax],double coeffCalib[kNbSMtot][kNbColMax][kNbRowMax],double forcedGainChange[kNbSMtot][kNbColMax][kNbRowMax],double forcedOCDBcoeff[kNbSMtot][kNbColMax][kNbRowMax],int flag[kNbSMtot][kNbColMax][kNbRowMax],TPostScript *ps,TCanvas *c1)
135 {int nbTowersAbove395,nbTowersBelowMin,nbTowersLargeModif,nbTowersBadHVscan,nbTowersProblem;
136  int icol,irow,expectSameE;
137  double hv,p0,p1,p2,gainChange,newHV,tmpNewHV;
138  double HVtab[kNbColMax][kNbRowMax]={{0.}};
139  double p0tab[kNbColMax][kNbRowMax]={{0.}};
140  double p1tab[kNbColMax][kNbRowMax]={{0.}};
141  double p2tab[kNbColMax][kNbRowMax]={{0.}};
142  double ampliIn,Eout1,Eout2,Ediff,initialGain,newGain;
143  //CUSTOMIZE customize every year :
144  double kMaxDeltaGainLook=2.0; //Will printf the tower above this.
145  double kMaxDeltaGainAuthorize=3.0; //Will suggest that number to any tower beyond that.
146  double kMaxDeltaHVgraph=50.;
147  //CUSTOMIZE customize every pass :
148  //Pass 0, 1, 2 :
149  double kMaxDeltaHVcut=10.;
150 
151  double kMaxEmismatchCut=0.01; //0.001 is OK but with flag -3 it's too hard. Put 0.01 instead (that's in %).
152 
153  printf("----- Calculating HV's for SM %d (%s)",smNb,detTypeString[SMdetType[smNb]]);
154  fprintf(outFile,"\n-------------- Calculating HV's for SM %d (%s)",smNb,detTypeString[SMdetType[smNb]]);
155  if ((smNb%2) == 0)
156  {printf(" (side A)\n");
157  fprintf(outFile," (side A) -----\n\n");
158  }
159  else
160  {printf(" (side C)\n");
161  fprintf(outFile," (side C) -----\n\n");
162  }
163 
164  // Check file existence and load the table of HV's :
165  FILE *inFile,*outHVFile,*outParamFile;
166  inFile=fopen(hvFileName.Data(),"r");
167  if(!inFile) {printf("File %s can not be found\n",hvFileName.Data());exit(-1);}
168  while (fscanf(inFile,"%d %d %lf\n",&icol,&irow,&hv)>0)
169  {if (smNb == 10) HVtab[icol][irow]=hv;
170  else HVtab[icol][irow-16]=hv;
171  }
172  fclose(inFile);
173 
174  inFile=fopen(paramFileName.Data(),"r");
175  if(!inFile) {printf("File %s can not be found\n",paramFileName.Data());exit(-1);}
176  while(fscanf(inFile,"%d %d %lf %lf %lf\n",&icol,&irow,&p0,&p1,&p2)>0)
177  {if (smNb == 10)
178  {p0tab[icol][irow]=p0;
179  p1tab[icol][irow]=p1;
180  p2tab[icol][irow]=p2;
181  }
182  else
183  {p0tab[icol][irow-16]=p0;
184  p1tab[icol][irow-16]=p1;
185  p2tab[icol][irow-16]=p2;
186  }
187  }
188  fclose(inFile);
189 
190  // Create some histograms :
191  TH1F *hEChange = new TH1F(Form("hEChange%d",smNb),Form("hEChange%d",smNb),80,-50.,50.);
192  hEChange->SetXTitle("(E_{2}-E_{1})/E_{1} (%)");
193  hEChange->SetYTitle("Counts");
194  hEChange->SetStats(0);
195  TH1F *hEChangeLogP = new TH1F(Form("hEChangeLogP%d",smNb),Form("hEChangeLogP%d",smNb),80,-3.,3.);
196  hEChangeLogP->SetXTitle("log [(E_{2}-E_{1})/E_{1} (%)]");
197  hEChangeLogP->SetYTitle("Counts");
198  hEChangeLogP->SetStats(0);
199  TH1F *hEChangeLogN = new TH1F(Form("hEChangeLogN%d",smNb),Form("hEChangeLogN%d",smNb),80,-3.,3.);
200  hEChangeLogN->SetXTitle("log [(E_{2}-E_{1})/E_{1} (%)]");
201  hEChangeLogN->SetYTitle("Counts");
202  hEChangeLogN->SetStats(0);
203  TH2F *h2HVdiffVsOCDB = new TH2F(Form("h2HVdiffVsOCDB%d",smNb),Form("h2HVdiffVsOCDB%d",smNb),80,0.,5.,80,-kMaxDeltaHVgraph,kMaxDeltaHVgraph);
204  h2HVdiffVsOCDB->SetXTitle("OCDB factor / 0.0162");
205  h2HVdiffVsOCDB->SetYTitle("NewHV - OldHV (V)");
206  h2HVdiffVsOCDB->SetStats(0);
207  h2HVdiffVsOCDB->SetContour(30);
208  TH2F *h2HVdiffVsOCDBZm = new TH2F(Form("h2HVdiffVsOCDBZm%d",smNb),Form("h2HVdiffVsOCDBZm%d",smNb),80,0.5,2.,80,-30.,30.);
209  h2HVdiffVsOCDBZm->SetXTitle("OCDB factor / 0.0162");
210  h2HVdiffVsOCDBZm->SetYTitle("NewHV - OldHV (V)");
211  h2HVdiffVsOCDBZm->SetStats(0);
212  h2HVdiffVsOCDBZm->SetContour(30);
213  TH2F *hSpaceHVbefore = new TH2F(Form("hSpaceHVbefore%d",smNb),Form("hSpaceHVbefore%d",smNb),kNbColMax,-0.5,kNbColMax-0.5,kNbRowMax,-0.5,kNbRowMax-0.5);
214  hSpaceHVbefore->SetXTitle("Column");
215  hSpaceHVbefore->SetYTitle("Row");
216  hSpaceHVbefore->SetStats(0);
217  hSpaceHVbefore->SetContour(30);
218  TH2F *hSpaceHVafter = new TH2F(Form("hSpaceHVafter%d",smNb),Form("hSpaceHVafter%d",smNb),kNbColMax,-0.5,kNbColMax-0.5,kNbRowMax,-0.5,kNbRowMax-0.5);
219  hSpaceHVafter->SetXTitle("Column");
220  hSpaceHVafter->SetYTitle("Row");
221  hSpaceHVafter->SetStats(0);
222  hSpaceHVafter->SetContour(30);
223  TH2F *hSpaceOCDBbefore = new TH2F(Form("hSpaceOCDBbefore%d",smNb),Form("hSpaceOCDBbefore%d",smNb),kNbColMax,-0.5,kNbColMax-0.5,kNbRowMax,-0.5,kNbRowMax-0.5);
224  hSpaceOCDBbefore->SetXTitle("Column");
225  hSpaceOCDBbefore->SetYTitle("Row");
226  hSpaceOCDBbefore->SetStats(0);
227  hSpaceOCDBbefore->SetContour(30);
228  TH2F *hSpaceOCDBafter = new TH2F(Form("hSpaceOCDBafter%d",smNb),Form("hSpaceOCDBafter%d",smNb),kNbColMax,-0.5,kNbColMax-0.5,kNbRowMax,-0.5,kNbRowMax-0.5);
229  hSpaceOCDBafter->SetXTitle("Column");
230  hSpaceOCDBafter->SetYTitle("Row");
231  hSpaceOCDBafter->SetStats(0);
232  hSpaceOCDBafter->SetContour(30);
233  TH2F *hSpaceAboveBefore = new TH2F(Form("hSpaceAboveBefore%d",smNb),Form("hSpaceAboveBefore%d",smNb),kNbColMax,-0.5,kNbColMax-0.5,kNbRowMax,-0.5,kNbRowMax-0.5);
234  hSpaceAboveBefore->SetXTitle("Column");
235  hSpaceAboveBefore->SetYTitle("Row");
236  hSpaceAboveBefore->SetStats(0);
237  hSpaceAboveBefore->SetContour(30);
238  TH2F *hSpaceAboveAfter = new TH2F(Form("hSpaceAboveAfter%d",smNb),Form("hSpaceAboveAfter%d",smNb),kNbColMax,-0.5,kNbColMax-0.5,kNbRowMax,-0.5,kNbRowMax-0.5);
239  hSpaceAboveAfter->SetXTitle("Column");
240  hSpaceAboveAfter->SetYTitle("Row");
241  hSpaceAboveAfter->SetStats(0);
242  hSpaceAboveAfter->SetContour(30);
243 
244  // Setup a few counters :
245  ampliIn=1.; //Nb of "photoelectrons" (arbitrary unit)
246  nbTowersAbove395=0;
247  nbTowersBelowMin=0;
248  nbTowersLargeModif=0;
249  nbTowersBadHVscan=0;
250  nbTowersProblem=0;
251 
252  // Loop over the towers to calculate the new HV's :
253  for(icol=0;icol<kTabNbCol[SMdetType[smNb]];icol++)
254  {for(irow=0;irow<kTabNbRow[SMdetType[smNb]];irow++)
255  //for(icol=4;icol<5;icol++)
256  // {for(irow=3;irow<4;irow++)
257  {hv=HVtab[icol][irow];
258  p0=p0tab[icol][irow];
259  p1=p1tab[icol][irow];
260  p2=p2tab[icol][irow];
261 //printf("%d %d %d HV %f coeff %f %f\n",smNb,icol,irow,hv,coeffCalib[smNb][icol][irow],0.0162/coeffOCDB[smNb][icol][irow]);
262  expectSameE=1;
263  hSpaceHVbefore->Fill(icol,irow,hv);
264  hSpaceOCDBbefore->Fill(icol,irow,coeffOCDB[smNb][icol][irow]/coefFactorWanted);
265  if (hv == kMaxHV) hSpaceAboveBefore->Fill(icol,irow,coeffOCDB[smNb][icol][irow]/coefFactorWanted);
266 
267  gainChange=coeffOCDB[smNb][icol][irow]/coefFactorWanted;
268  // Suggest discarding the towers with calib coeff = 1 (half of the time dead towers) :
269  if ((coeffCalib[smNb][icol][irow] == 1.0) && (flag[smNb][icol][irow] == 5)) //Don't escape again if tower has already seen at previous pass !
270  {fprintf(outFile,"######## Tower with calib coeff 1.0 (%d,%d,%d) ### do nothing.\n",smNb,icol,irow);
271  fprintf(badGainFileOut,"%d %2d %2d XXX2 %f %4.2f %f %f\n",smNb,icol,irow,gainChange,1.,forcedGainChange[smNb][icol][irow],forcedOCDBcoeff[smNb][icol][irow]);
272  nbTowersProblem++;
273  continue;
274  }
275 
276  // Check that the p0, p1, p2 parameters look OK (raw check) :
277  if ((p1==0.) && (p2==0.)) // LED HV-scan not good.
278  {//fprintf(outFile,"######## Bad HV scan for tower (%d,%d,%d), HV %7.3f ### do nothing.\n",smNb,icol,irow,hv);
279  //For 1/3-EMCAL-SMs : only this error appears with the HV scans. Calculate new HV with default parameters :
280  fprintf(outFile,"######## Bad HV scan for tower (%d,%d,%d), HV %7.3f ### use default parameters.\n",smNb,icol,irow,hv);
281  fprintf(outFile,"######## CAUTION : EMCAL thirds 2015 only !!!!!!\n");
282  p0=0.;
283  p1=1.;
284  p2=0.02;
285  nbTowersBadHVscan++;
286  nbTowersProblem++;
287  //continue;
288  }
289  if ((p1<=0.) || (p2<=0.))
290  {fprintf(outFile,"######## Bad HV scan parameters for tower (%d,%d,%d), HV %7.3f (params : %f %e %f) ### do nothing.\n",smNb,icol,irow,hv,p0,p1,p2);
291  nbTowersBadHVscan++;
292  nbTowersProblem++;
293  continue;
294  }
295  if ( (p0 + p1 * exp(p2*(hv-kMaxDeltaHVcut-10.))) < 0. )
296  {fprintf(outFile,"######## Bad HV scan value for tower (%d,%d,%d), HV %7.3f (params : %f %e %f) ### do nothing.\n",smNb,icol,irow,hv,p0,p1,p2);
297  nbTowersBadHVscan++;
298  nbTowersProblem++;
299  continue;
300  }
301 
302  // Check for a chosen, forced value.
303  // If there isn't, check that the required gain change isn't too far from 1.0.
304  if (flag[smNb][icol][irow] == 0) //Undecided tower (shouldn't be found...), copy as is.
305  {fprintf(badGainFileOut,"%d %2d %2d XXX %f %4.2f %f %f\n",smNb,icol,irow,gainChange,1.,forcedGainChange[smNb][icol][irow],forcedOCDBcoeff[smNb][icol][irow]);
306  nbTowersProblem++;
307  continue;
308  }
309  if (flag[smNb][icol][irow] == -3) //HV change was too large, forced gain and OCDB value.
310  {fprintf(badGainFileOut,"%d %2d %2d -3 %f %4.2f %f %f\n",smNb,icol,irow,gainChange,1.,forcedGainChange[smNb][icol][irow],forcedOCDBcoeff[smNb][icol][irow]);
311  gainChange=forcedGainChange[smNb][icol][irow];
312  initialGain = p0 + p1 * exp(p2*hv);
313  newGain = initialGain * gainChange;
314  Eout1=ampliIn*initialGain*coeffOCDB[smNb][icol][irow];
315  //expectSameE=0; //If the "-3" results from a too large HV change (most of the cases), the energies must be equal ! Some outliers may be caught by the printf.
316  if ((newGain-p0) > 0)
317  {newHV = log ( (newGain - p0)/p1 ) / p2;
318  HVtab[icol][irow]=newHV;
319  coeffOCDB[smNb][icol][irow]=forcedOCDBcoeff[smNb][icol][irow];
320  Eout2=ampliIn*(p0 + p1 * exp(p2*newHV))*coeffOCDB[smNb][icol][irow];
321  h2HVdiffVsOCDB->Fill(gainChange,newHV-hv);
322  h2HVdiffVsOCDBZm->Fill(gainChange,newHV-hv);
323  Ediff=100.*(Eout2-Eout1)/Eout1;
324  if (expectSameE == 1)
325  {hEChange->Fill(Ediff);
326  if (Eout2 > Eout1) hEChangeLogP->Fill(TMath::Log10(TMath::Abs(Ediff)));
327  if (Eout2 < Eout1) hEChangeLogN->Fill(TMath::Log10(TMath::Abs(Ediff)));
328  if (TMath::Abs(Ediff) > kMaxEmismatchCut)
329  {printf("##### E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
330  fprintf(outFile,"E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
331  }
332  }
333  continue;
334  }
335  else // LED HV-scan not good (can happen if changed HV scan between an execution and the next one) : tell it and move to the next tower.
336  {fprintf(outFile,"######## Negative in log for forced tower (%d,%d,%d), HV %7.3f and gain %5.3f (params : %f %e %f) ### do nothing.\n",smNb,icol,irow,hv,gainChange,p0,p1,p2);
337  continue;
338  }
339  }
340  if (forcedGainChange[smNb][icol][irow] != 0.)
341  {if ((flag[smNb][icol][irow] > 9) || (flag[smNb][icol][irow] == -4)) fprintf(badGainFileOut,"%d %2d %2d %d %f %4.2f %f %f\n",smNb,icol,irow,flag[smNb][icol][irow],gainChange,1.,forcedGainChange[smNb][icol][irow],forcedOCDBcoeff[smNb][icol][irow]); //Can't put these lines later because the older "gainChange" must be known. That causes this line to be issued a 2nd time (with different values) in badGainFileOut when deltaHV is too large. The latter line overwrites the previous anyway when the file is read back => that's OK even if the user doesn't cancel it manually. The line automatically disappears from the "bad gain" file at the next pass.
342  else fprintf(badGainFileOut,"%d %2d %2d %d %f %4.2f %f %f\n",smNb,icol,irow,flag[smNb][icol][irow]+10,gainChange,1.,forcedGainChange[smNb][icol][irow],forcedOCDBcoeff[smNb][icol][irow]);
343  gainChange=forcedGainChange[smNb][icol][irow];
344  }
345  else
346  {if (gainChange < 1./kMaxDeltaGainAuthorize)
347  {fprintf(outFile,"######## Gain change < factor 1/%4.2f for tower (%d,%d,%d), HV %7.3f and gain %5.3f ### do nothing.\n",kMaxDeltaGainAuthorize,smNb,icol,irow,hv,gainChange);
348  fprintf(badGainFileOut,"%d %2d %2d XXX-4 %f %4.2f %f %f\n",smNb,icol,irow,gainChange,1.,1./kMaxDeltaGainAuthorize,coefFactorWanted*1./kMaxDeltaGainAuthorize); //Have to setup both the gain change and the OCDB factor, as *that* OCDB factor is still the desired change (not yet the factor that will be written to file).
349  nbTowersLargeModif++;
350  nbTowersProblem++;
351  continue;
352  }
353  if (gainChange > kMaxDeltaGainAuthorize)
354  {fprintf(outFile,"######## Gain change > factor %4.2f for tower (%d,%d,%d), HV %7.3f and gain %5.3f ### do nothing.\n",kMaxDeltaGainAuthorize,smNb,icol,irow,hv,gainChange);
355  fprintf(badGainFileOut,"%d %2d %2d XXX-4 %f %4.2f %f %f\n",smNb,icol,irow,gainChange,1.,kMaxDeltaGainAuthorize,coefFactorWanted*kMaxDeltaGainAuthorize); //Have to setup both the gain change and the OCDB factor, as *that* OCDB factor is still the desired change (not yet the factor that will be written to file).
356  nbTowersLargeModif++;
357  nbTowersProblem++;
358  continue;
359  }
360  if ((gainChange < 1./kMaxDeltaGainLook) || (gainChange > kMaxDeltaGainLook))
361  {fprintf(outFile,"######## Gain change > factor %4.2f for tower (%d,%d,%d), HV %7.3f and gain %5.3f ### do nothing.\n",kMaxDeltaGainLook,smNb,icol,irow,hv,gainChange);
362  fprintf(badGainFileOut,"%d %2d %2d XXX1 %f %4.2f %4.2f %4.2f\n",smNb,icol,irow,gainChange,1.,0.,0.);
363  nbTowersLargeModif++;
364  nbTowersProblem++;
365  continue;
366  }
367  }
368  if ((flag[smNb][icol][irow] == 2) || (flag[smNb][icol][irow] == 12) || (flag[smNb][icol][irow] == 3) || (flag[smNb][icol][irow] == 13)) expectSameE=0;
369 
370  // Calculate the new HV :
371  newHV=hv;
372  initialGain = p0 + p1 * exp(p2*hv);
373  newGain = initialGain * gainChange;
374  Eout1=ampliIn*initialGain*coeffOCDB[smNb][icol][irow];
375  if ((newGain-p0) <= 0) // LED HV-scan not good.
376  {fprintf(outFile,"######## Negative in log for tower (%d,%d,%d), HV %7.3f and gain %5.3f (params : %f %e %f) ### do nothing.\n",smNb,icol,irow,hv,gainChange,p0,p1,p2);
377  nbTowersBadHVscan++;
378  nbTowersProblem++;
379  continue;
380  }
381  else
382  newHV = log ( (newGain - p0)/p1 ) / p2;
383  if (flag[smNb][icol][irow] == -4) coeffOCDB[smNb][icol][irow]=forcedOCDBcoeff[smNb][icol][irow]; //GainChange has been levelled off at kMaxDeltaGainAuthorize
384 
385  // Check the calculated newHV :
386  if (newHV < 0) // conversion failed: let's just keep the old custom value then
387  {fprintf(outFile,"######## Neg HV returned for tower (%d,%d,%d), HV %7.3f and gain %5.3f (params : %f %e %f) ### keeping previous value.\n",smNb,icol,irow,hv,gainChange,p0,p1,p2);
388  nbTowersProblem++;
389  continue;
390  }
391  if (TMath::Abs(newHV-hv) > kMaxDeltaHVcut)
392  {fprintf(outFile,"######## Too large HV change for tower (%d,%d,%d), HV %7.3f -> %7.3f with gain %5.3f (params : %f %e %f) ### do nothing, ",smNb,icol,irow,hv,newHV,gainChange,p0,p1,p2);
393  fprintf(badGainFileOut,"%d %2d %2d XXX-3 %f %4.2f ",smNb,icol,irow,gainChange,1.);
394  if (newHV > hv) tmpNewHV=TMath::Min(kMaxHV,hv+(kMaxDeltaHVcut-0.01)); //Use val-0.01 instead of val so that we're sure it doesn't get trapped again after correcting the gain.
395  else tmpNewHV=TMath::Max(kMinHV,hv-(kMaxDeltaHVcut-0.01));
396  newGain= p0 + p1 * exp(p2*tmpNewHV);
397  gainChange=newGain/initialGain;
398  fprintf(outFile,"suggest gain %f w/ OCDBcoeff %f\n",gainChange,coeffOCDB[smNb][icol][irow]/gainChange);
399  fprintf(badGainFileOut,"%f %f\n",gainChange,coeffOCDB[smNb][icol][irow]/gainChange);
400  nbTowersProblem++;
401  continue;
402  }
403  if (newHV < kMinHV)
404  {fprintf(outFile,"HV below min voltage for tower (%d,%d,%d), HV %7.3f -> %7.3f with gain %5.3f -- set to supply voltage %7.3f.\n",smNb,icol,irow,hv,newHV,gainChange,kMinHV);
405  nbTowersBelowMin++;
406  nbTowersProblem++;
407  newGain= p0 + p1 * exp(p2*kMinHV);
408  gainChange=newGain/initialGain;
409  coeffOCDB[smNb][icol][irow]=coeffOCDB[smNb][icol][irow]/gainChange;
410  HVtab[icol][irow]=kMinHV;
411  Eout2=ampliIn*newGain*coeffOCDB[smNb][icol][irow];
412  Ediff=100.*(Eout2-Eout1)/Eout1;
413  if (expectSameE == 1) //Energies are not equal when we force the gain change to be different from the calculated OCDB coeff.
414  {hEChange->Fill(Ediff);
415  if (Eout2 > Eout1) hEChangeLogP->Fill(TMath::Log10(TMath::Abs(Ediff)));
416  if (Eout2 < Eout1) hEChangeLogN->Fill(TMath::Log10(TMath::Abs(Ediff)));
417  if (TMath::Abs(Ediff) > kMaxEmismatchCut)
418  {printf("##### E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
419  fprintf(outFile,"E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
420  }
421  }
422  continue;
423  }
424  if (newHV>kMaxHV) // we reached a too high voltage: let's keep the max then
425  {fprintf(outFile,"HV above supply voltage for tower (%d,%d,%d), HV %7.3f -> %7.3f with gain %5.3f -- set to supply voltage %7.3f.\n",smNb,icol,irow,hv,newHV,gainChange,kMaxHV);
426  nbTowersAbove395++;
427  nbTowersProblem++;
428  newGain= p0 + p1 * exp(p2*kMaxHV);
429  gainChange=newGain/initialGain;
430  coeffOCDB[smNb][icol][irow]=coeffOCDB[smNb][icol][irow]/gainChange;
431  HVtab[icol][irow]=kMaxHV;
432  Eout2=ampliIn*newGain*coeffOCDB[smNb][icol][irow];
433  Ediff=100.*(Eout2-Eout1)/Eout1;
434  if (expectSameE == 1) //Energies are not equal when we force the gain change to be different from the calculated OCDB coeff.
435  {hEChange->Fill(Ediff);
436  if (Eout2 > Eout1) hEChangeLogP->Fill(TMath::Log10(TMath::Abs(Ediff)));
437  if (Eout2 < Eout1) hEChangeLogN->Fill(TMath::Log10(TMath::Abs(Ediff)));
438  if (TMath::Abs(Ediff) > kMaxEmismatchCut)
439  {printf("##### E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
440  fprintf(outFile,"E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
441  }
442  }
443  continue;
444  }
445  //everything ok
446  HVtab[icol][irow]=newHV;
447  coeffOCDB[smNb][icol][irow]=coefFactorWanted;
448  Eout2=ampliIn*(p0 + p1 * exp(p2*newHV))*coeffOCDB[smNb][icol][irow];
449 //if ((gainChange < 0.95) && (newHV-hv > -1)) printf("##### BAAAAD tower (%d,%d,%d) HV's %f %f, gainChange %f, p's %e %e %e\n",smNb,icol,irow,hv,newHV,gainChange,p0,p1,p2); /////////
450  h2HVdiffVsOCDB->Fill(gainChange,newHV-hv);
451  h2HVdiffVsOCDBZm->Fill(gainChange,newHV-hv);
452  Ediff=100.*(Eout2-Eout1)/Eout1;
453  if (expectSameE == 1) //Energies are not equal when we force the gain change to be different from the calculated OCDB coeff.
454  {hEChange->Fill(Ediff);
455  if (Eout2 > Eout1) hEChangeLogP->Fill(TMath::Log10(TMath::Abs(Ediff)));
456  if (Eout2 < Eout1) hEChangeLogN->Fill(TMath::Log10(TMath::Abs(Ediff)));
457  if (TMath::Abs(Ediff) > kMaxEmismatchCut)
458  {printf("##### E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
459  fprintf(outFile,"E mismatch tower (%d,%d,%d) : Eout1 = %f, Eout2 = %f HV %7.3f -> %7.3f => %7.3f w/ OCDB %f flag %d\n",smNb,icol,irow,Eout1,Eout2,hv,newHV,HVtab[icol][irow],coeffOCDB[smNb][icol][irow],flag[smNb][icol][irow]);
460  }
461  }
462  }
463  }
464 
465  // Write to file the new HV values and the new OCDB parameters :
466  outHVFile=fopen(Form("%s/%s/NewBias.txt",fchNameBase,SMP2Name[smNb]),"w");
467  outParamFile=fopen(Form("%s/%s/NewParamFactor.txt",fchNameBase,SMP2Name[smNb]),"w");
468  for(icol=0;icol<kTabNbCol[SMdetType[smNb]];icol++)
469  {for(irow=0;irow<kTabNbRow[SMdetType[smNb]];irow++)
470  {fprintf(outHVFile,"%d %d %f\n",icol,irow,HVtab[icol][irow]);
471  //Flip OCDB params from Grenoble/electonic mapping to Alice-offline mapping. HVs are kept in Grenoble/electonic mapping.
472  if ((smNb%2) == 0) fprintf(outParamFile,"%d %d %d %f\n",smNb,icol,irow,coeffOCDB[smNb][icol][irow]); //Side A.
473  else fprintf(outParamFile,"%d %d %d %f\n",smNb,(kTabNbCol[SMdetType[smNb]]-1)-icol,(kTabNbRow[SMdetType[smNb]]-1)-irow,coeffOCDB[smNb][icol][irow]); //Side C.
474  hSpaceHVafter->Fill(icol,irow,HVtab[icol][irow]);
475  hSpaceOCDBafter->Fill(icol,irow,coeffOCDB[smNb][icol][irow]/coefFactorWanted);
476  if (HVtab[icol][irow] == kMaxHV) hSpaceAboveAfter->Fill(icol,irow,coeffOCDB[smNb][icol][irow]/coefFactorWanted);
477  }
478  }
479  fclose(outHVFile);
480  fclose(outParamFile);
481 
482  fprintf(outFile,"\n\nNb towers above 395 V : %d\n",nbTowersAbove395);
483  fprintf(outFile,"Nb towers below min voltage : %d\n",nbTowersBelowMin);
484  fprintf(outFile,"Nb towers w/ too large gain : %d <--\n",nbTowersLargeModif);
485  fprintf(outFile,"Nb towers w/ bad HV scan : %d <--\n",nbTowersBadHVscan);
486  fprintf(outFile,"Nb other towers to look at : %d <--\n",nbTowersProblem-nbTowersAbove395-nbTowersBelowMin-nbTowersLargeModif-nbTowersBadHVscan);
487  fprintf(outFile,"Tot nb towers w/ problem : %d\n",nbTowersProblem);
488  fprintf(outFile,"\n");
489 
490  // Draw a few plots :
491  TLine *lineH = new TLine(h2HVdiffVsOCDBZm->GetXaxis()->GetXmin(),0.,h2HVdiffVsOCDBZm->GetXaxis()->GetXmax(),0.);
492  TLine *lineV = new TLine(1.,h2HVdiffVsOCDBZm->GetYaxis()->GetXmin(),1.,h2HVdiffVsOCDBZm->GetYaxis()->GetXmax());
493  ps->NewPage();
494  c1->Clear();
495  c1->Divide(2,3);
496  c1->cd(1);
497  hEChange->Draw();
498  gPad->SetLogy();
499  hEChange->Write();
500  c1->cd(3);
501  hEChangeLogP->Draw();
502  gPad->SetLogy();
503  hEChangeLogP->Write();
504  c1->cd(5);
505  hEChangeLogN->Draw();
506  gPad->SetLogy();
507  hEChangeLogN->Write();
508  c1->cd(2);
509  h2HVdiffVsOCDB->Draw("COLZ");
510  h2HVdiffVsOCDB->Write();
511  lineH->Draw();
512  lineV->Draw();
513  c1->cd(4);
514  h2HVdiffVsOCDBZm->Draw("COLZ");
515  h2HVdiffVsOCDBZm->Write();
516  lineH->Draw();
517  lineV->Draw();
518  c1->Update();
519 
520  ps->NewPage();
521  c1->Clear();
522  c1->Divide(2,3);
523  c1->cd(1);
524  hSpaceHVbefore->SetMinimum(kMinHV);
525  hSpaceHVbefore->SetMaximum(kMaxHV+5.);
526  hSpaceHVbefore->Draw("COLZ");
527  hSpaceHVbefore->Write();
528  c1->cd(2);
529  hSpaceHVafter->SetMinimum(kMinHV);
530  hSpaceHVafter->SetMaximum(kMaxHV+5.);
531  hSpaceHVafter->Draw("COLZ");
532  hSpaceHVafter->Write();
533  c1->cd(3);
534  hSpaceOCDBbefore->Draw("COLZ");
535  hSpaceOCDBbefore->Write();
536  c1->cd(4);
537  hSpaceOCDBafter->Draw("COLZ");
538  hSpaceOCDBafter->Write();
539  c1->cd(5);
540  hSpaceAboveBefore->Draw("COLZ");
541  hSpaceAboveBefore->Write();
542  c1->cd(6);
543  hSpaceAboveAfter->Draw("COLZ");
544  hSpaceAboveAfter->Write();
545  c1->Update();
546 
547  if (smNb < (lastSM-1)) //Otherwise, the plots on the last page don't show up. Not sure why.
548  {delete hEChange;
549  delete hEChangeLogP;
550  delete hEChangeLogN;
551  delete h2HVdiffVsOCDB;
552  delete h2HVdiffVsOCDBZm;
553  delete hSpaceHVbefore;
554  delete hSpaceHVafter;
555  delete hSpaceOCDBbefore;
556  delete hSpaceOCDBafter;
557  delete hSpaceAboveBefore;
558  delete hSpaceAboveAfter;
559  }
560 
561  return;
562  }
563 
564 
565 
566 
567 
580 void HVrecalculation_EMCALthirds(TString ident,int choiceArg=0b0010)
581 {int i,ism,icol,irow,choice,oldFlag;
582  int tabChoiceCalos[4],tmpChoice;
583  double paramFactor;
584  double val1,val2,val3,ocdbCoeff;
585 
586  //defineMyPalette2011(30,5);
587 
588  for (i=4-1;i>=0;i--)
589  {tmpChoice=choiceArg>>i;
590  tabChoiceCalos[i]=tmpChoice;
591  choiceArg-=tmpChoice*pow(2,i);
592  }
593  printf("\n\n---------------------------------\n| Running for :");
594  for (i=0;i<4;i++)
595  {if (tabChoiceCalos[i] == 1) printf(" %s",detTypeString[i]);
596  }
597  printf("\n");
598  if (tabChoiceCalos[0] == 1) lastSM=kNbSMEMCAL;
599  if (tabChoiceCalos[1] == 1) lastSM=kNbSMEMCAL+kNbSMEMCALthird;
600  if (tabChoiceCalos[2] == 1) lastSM=kNbSMEMCAL+kNbSMEMCALthird+kNbSMDCAL;
601  if (tabChoiceCalos[3] == 1) lastSM=kNbSMtot;
602 
603  // Setup filenames, including :
604  // - new directory created to store everything,
605  // - name of the file with the OCDB parameters,
606  // - name of the file (to be created) with the "bad [large] gain towers",
607  // - name of the file (**to provide**) with the wanted gain for towers with initially "bad [large] gain".
608  char fchNameBase[250],fchNameRoot[250],fchNamePs[250],fchNameOut[250],fchNameBadGainIn[250],fchNameBadGainOut[250];
609  FILE *inFile,*outFile,*badGainFileIn,*badGainFileOut,*OCDBcoeffsFile,*calibCoeffsFile;
610  sprintf(fchNameBase,"output_HVrecalculation_EMCALthirds_%s",ident.Data());
611  sprintf(fchNameRoot,"%s/%s.root",fchNameBase,fchNameBase);
612  sprintf(fchNamePs,"%s/%s.ps",fchNameBase,fchNameBase);
613  sprintf(fchNameOut,"%s/%s.out",fchNameBase,fchNameBase);
614  sprintf(fchNameBadGainOut,"%s/%s_badGain.txt",fchNameBase,fchNameBase);
615  gSystem->Exec(Form("mkdir %s",fchNameBase));
616  for (ism=0;ism<kNbSMtot;ism++) gSystem->Exec(Form("mkdir %s/%s",fchNameBase,SMP2Name[ism]));
617  outFile=fopen(fchNameOut,"w");
618 
619  inFile=fopen(fchNameBadGainOut,"r");
620  if (inFile)
621  {printf("File %s already exists, exiting.\n",fchNameBadGainOut);
622  fclose(inFile); //Must be inside the if-loop, otherwise breaks (tries to close a file that it didn't open because it didn't exist).
623  return;
624  }
625 
626  TFile *rootFileOut = new TFile(fchNameRoot,"RECREATE");
627  const int cWidth=500;
628  const int cHeight=(int)(500*(29./21.));
629  TCanvas *c1 = new TCanvas("c1","EMCal cosmics analysis",cWidth,cHeight);
630  TPostScript *ps = new TPostScript(fchNamePs,111);
631 
632  //CUSTOMIZE customize every year (OCDB coeffs + calib coeffs) :
633  const char fchNameOCDBcoeffsFile[] = "/cebaf/cebaf/EMCAL/calibPi0_run2/recalculateHV_4_with2015data/OCDBparamsAfterCalib2015.txt";
634  const char fchNameCalibCoeffsFile[] = "/cebaf/cebaf/EMCAL/calibPi0_run2/calibPi0_4_with2015data/output/pass2_DCALandThirdSMsVeryHighTowers/output_calibPi0_coeffs_clean_finalFile4HVcalculation_setUntrustedToOne.txt"; //This is used only to check which towers are dead (calib coeff = 1).
635 
636  //CUSTOMIZE customize at every pass :
637  //***** To be set by the user at every execution : *****//
638  //For pass0 :
639  //sprintf(fchNameBadGainIn,"000.txt");
640  //For pass1 :
641  //sprintf(fchNameBadGainIn,"/cebaf/cebaf/EMCAL/calibPi0_run2/recalculateHV_4_with2015data/output_HVrecalculation_EMCALthirds_pass0/output_HVrecalculation_EMCALthirds_pass0_badGain_Custom.txt");
642  //For pass2 :
643  sprintf(fchNameBadGainIn,"/cebaf/cebaf/EMCAL/calibPi0_run2/recalculateHV_4_with2015data/output_HVrecalculation_EMCALthirds_pass1/output_HVrecalculation_EMCALthirds_pass1_badGain.txt"); //Nothing to customize, all the lines were OK.
644 
645  printf("\n***** Will be using 'bad gain' correction file %s. PLEASE CHECK.\n",fchNameBadGainIn);
646  fprintf(outFile,"\nUse 'bad gain' correction file %s.\n",fchNameBadGainIn);
647  printf("Number of lines with 'XXX' :\n");
648  fprintf(outFile,"Number of lines with 'XXX' :\n");
649  gSystem->Exec(Form("grep -c XXX %s",fchNameBadGainIn));
650  gSystem->Exec(Form("grep -c XXX %s >> %s",fchNameBadGainIn,fchNameOut));
651  printf("\n\n");
652  fprintf(outFile,"\n\n");
653  fprintf(outFile,"Tower numbers are given in Grenoble/electronic convention.\n\n");
654 
655  // Load the calibration parameters from the OCDB text file :
656  double coeffOCDB[kNbSMtot][kNbColMax][kNbRowMax]={{{0.}}};
657  double coeffCalib[kNbSMtot][kNbColMax][kNbRowMax]={{{0.}}};
658  OCDBcoeffsFile = fopen(fchNameOCDBcoeffsFile,"r");
659  if(!OCDBcoeffsFile) {printf("File %s can not be found\n",fchNameOCDBcoeffsFile);exit(-1);}
660  while (fscanf(OCDBcoeffsFile,"%d %d %d %lf",&ism,&icol,&irow,&paramFactor)>0) //Flip from Alice-offline mapping to Grenoble/electronic mapping.
661  {if ((ism%2) == 0) coeffOCDB[ism][icol][irow]=paramFactor; //Side A.
662  else coeffOCDB[ism][(kTabNbCol[SMdetType[ism]]-1)-icol][(kTabNbRow[SMdetType[ism]]-1)-irow]=paramFactor; //Side C.
663  }
664  fclose(OCDBcoeffsFile);
665  // Load the calib coefficients used to produce the OCDB file :
666  calibCoeffsFile = fopen(fchNameCalibCoeffsFile,"r");
667  if(!calibCoeffsFile) {printf("File %s can not be found\n",fchNameCalibCoeffsFile);exit(-1);}
668  while (fscanf(calibCoeffsFile,"%d %d %d %d %lf",&oldFlag,&ism,&icol,&irow,&paramFactor)>0) //Flip from Alice-offline mapping to Grenoble/electronic mapping.
669  {if ((ism%2) == 0) coeffCalib[ism][icol][irow]=paramFactor; //Side A.
670  else coeffCalib[ism][(kTabNbCol[SMdetType[ism]]-1)-icol][(kTabNbRow[SMdetType[ism]]-1)-irow]=paramFactor; //Side C.
671  }
672  fclose(calibCoeffsFile);
673 
674  // Read bad gain correction file and store the desired gains :
675  printf("\n\nRead 'bad gain' correction file.\n");
676  double forcedGainChange[kNbSMtot][kNbColMax][kNbRowMax]={{{0.}}};
677  double forcedOCDBcoeff[kNbSMtot][kNbColMax][kNbRowMax]={{{0.}}};
678  int flag[kNbSMtot][kNbColMax][kNbRowMax]={{{0}}};
679  //Need to initialize by hand because {{{5}}} doesn't put "5" everywhere ; it's still initialized to 0 !
680  for (ism=0;ism<kNbSMtot;ism++)
681  {for (icol=0;icol<kNbColMax;icol++)
682  {for (irow=0;irow<kNbRowMax;irow++) flag[ism][icol][irow]=5;
683  }
684  }
685  //In table "flag" :
686  // -3 -> force gain *and* OCDB coeff,
687  // 0 -> 'bad gain' tower but not customized yet,
688  // 1 -> calculated OCDB coeff OK,
689  // 2 -> don't change HV,
690  // 3 -> apply hand-calculated HV change,
691  // 4 [obsolete] -> 'bad gain' tower already looked at in a previous pass,
692  // 11,12,13 -> 'bad gain' tower already looked at in a previous pass, with flag resp. 1, 2, 3.
693  // 5 -> not a 'bad gain' tower.
694  badGainFileIn=fopen(fchNameBadGainIn,"r");
695  if (!badGainFileIn)
696  {printf("##### 'Bad gain' correction file %s can not be found.\n##### CAUTION : is this the 1st pass ? #####\n\n",fchNameBadGainIn);
697  fprintf(outFile,"##### 'Bad gain' correction file %s can not be found.\n##### CAUTION : is this the 1st pass ? #####\n\n",fchNameBadGainIn);
698  }
699  else
700  {while (fscanf(badGainFileIn,"%d %d %d %d %lf %lf %lf %lf",&ism,&icol,&irow,&choice,&val1,&val2,&val3,&ocdbCoeff)>0) //Caution, do use %lf with doubles, not %f.
701  {switch (TMath::Abs(choice))
702  {case 1 : if (val3 != 0.0) printf("#### Check 'bad gain' correction file (%d,%d,%d) : choice %d while val3 %f (should be 0.)\n",ism,icol,irow,choice,val3);
703  case 11 : forcedGainChange[ism][icol][irow]=val1;
704  if (val2 != 1.0) printf("#### Check 'bad gain' correction file (%d,%d,%d) : choice %d while val2 %f (should be 1.)\n",ism,icol,irow,choice,val2);
705  if (ocdbCoeff != 0.0) printf("#### Check 'bad gain' correction file (%d,%d,%d) : choice %d while OCDB coeff %f (should be 0.)\n",ism,icol,irow,choice,ocdbCoeff);
706  break;
707  case 2 :
708  case 12 : forcedGainChange[ism][icol][irow]=val2;
709  break;
710  case 0 :
711  case 3 :
712  case 4 :
713  case 13 : forcedGainChange[ism][icol][irow]=val3;
714  if ((choice == -3) && (ocdbCoeff == 0.)) printf("#### Check 'bad gain' correction file (%d,%d,%d) : choice %d while OCDB coeff %f.\n",ism,icol,irow,choice,ocdbCoeff);
715  if (val3 == 0.) printf("#### Check 'bad gain' correction file (%d,%d,%d) : choice %d while val3 %f.\n",ism,icol,irow,choice,val3);
716  break;
717  default : printf("*** Unknown choice %d for (SM,col,row) (%d,%d,%d)\n",choice,ism,icol,irow);
718  fprintf(outFile,"*** Unknown choice %d for (SM,col,row) (%d,%d,%d)\n",choice,ism,icol,irow);
719  }
720  forcedOCDBcoeff[ism][icol][irow]=ocdbCoeff;
721  flag[ism][icol][irow]=choice;
722  }
723  fclose(badGainFileIn);
724  }
725  printf("\n");
726 
727  // Launch subroutine to calculate new HV's and new OCDB params for every SM :
728  badGainFileOut=fopen(fchNameBadGainOut,"w");
729  //CUSTOMIZE customize every year (HV files + LED scans) :
730  //Merging of HV scans LED 2013, 2012 and 2011 :
731  for (ism=0;ism<kNbSMtot;ism++)
732  //for (ism=0;ism<1;ism++)
733  {if (tabChoiceCalos[SMdetType[ism]] == 0) continue;
734  //CalcNewHVperSM(Form("/cebaf/faivre/recherche/calibPi0/biasSentByDavidMay2015/bias/%s/NewBias.txt",SMP2Name[ism]),Form("/cebaf/faivre/recherche/calibPi0/recalculateDCAL_HV_July2015/HVscanParametersGrenobleDCAL/HVscanParamsGrenobleDCAL/HvscanSM%s_%s_%s/parameters.txt",SMnumber[ism],SMcalibName[ism],SMP2Name[ism]),ism,fchNameBase,outFile,badGainFileOut,coeffOCDB,coeffCalib,forcedGainChange,forcedOCDBcoeff,flag,ps,c1); //This is WRONG.
735  CalcNewHVperSM(Form("/cebaf/faivre/recherche/calibPi0/recalculateDCAL_HV_July2015/output_HVrecalculationDCAL2015July_mergedWithEMCalHV_lowerTemperature_createBias/%s/NewBias.txt",SMP2Name[ism]),Form("/cebaf/faivre/recherche/calibPi0/recalculateDCAL_HV_July2015/HVscanParametersGrenobleDCAL/HVscanParamsGrenobleDCAL/HvscanSM%s_%s_%s/parameters.txt",SMnumber[ism],SMcalibName[ism],SMP2Name[ism]),ism,fchNameBase,outFile,badGainFileOut,coeffOCDB,coeffCalib,forcedGainChange,forcedOCDBcoeff,flag,ps,c1);
736  }
737 
738  fclose(badGainFileOut);
739 
740  // Close what has been opened :
741  ps->Close();
742  rootFileOut->Close();
743  fclose(outFile);
744 
745  return;
746  }
747 
748 
749 
750 
751 
752 
753 
754 
const int kTabNbCol[4]
Definition: External.C:236
TSystem * gSystem
char detTypeString[][100]
const int kNbRowDCAL
const double coefFactorWanted
void HVrecalculation_EMCALthirds(TString ident, int choiceArg=0b0010)
char SMcalibName[][100]
const int kTabNbSM[4]
const int kTabNbRow[4]
const int kNbColDCALthird
char SMP2Name[][100]
const int kNbColEMCAL
const int kNbSMDCALthird
const int kNbSMEMCAL
const int kNbSMDCAL
const int kNbRowEMCAL
const int kNbColMax
const int kNbColEMCALthird
const int kNbRowEMCALthird
int detTypeType[]
void CalcNewHVperSM(TString hvFileName, TString paramFileName, int smNb, char *fchNameBase, FILE *outFile, FILE *badGainFileOut, double coeffOCDB[kNbSMtot][kNbColMax][kNbRowMax], double coeffCalib[kNbSMtot][kNbColMax][kNbRowMax], double forcedGainChange[kNbSMtot][kNbColMax][kNbRowMax], double forcedOCDBcoeff[kNbSMtot][kNbColMax][kNbRowMax], int flag[kNbSMtot][kNbColMax][kNbRowMax], TPostScript *ps, TCanvas *c1)
const double kMaxHV
const int kNbRowDCALthird
const int kNbColDCAL
char SMnumber[][100]
const int kNbSMEMCALthird
const double kMinHV
const int kNbSMtot
const int kNbRowMax
const int kNbColOffsetDCAL