AliPhysics  eb0e5d9 (eb0e5d9)
MergeHVscanFilesVariousScans2.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 <TApplication.h>
21 #include <TChain.h>
22 #include <TF1.h>
23 #include <TH1F.h>
24 #include <TH2F.h>
25 #include <TFile.h>
26 #include <TCanvas.h>
27 #include <TFrame.h>
28 #include <TPostScript.h>
29 #include <TLine.h>
30 #include <TGaxis.h>
31 #include <TStyle.h>
32 #include <TGraphErrors.h>
33 #include <TMath.h>
34 #include <TMatrixF.h>
35 #include <TText.h>
36 
37 
38 //#include "/cebaf/faivre/recherche/utilities/defineMyPalette2011.C"
39 
40 
41 namespace std {} using namespace std;
42 
43 
44 // voir http://dsilverm.web.cern.ch/dsilverm/fee/addrP2.html
45 char SMP2Name[][100]={"SMA0","SMC0","SMA1","SMC1","SMA2","SMC2","SMA3","SMC3","SMA4","SMC4"};
46 char SMcalibName[][100]={"US2","US1","EU2","EU1","US3","US5","US4","EU3","US7","US6"};
47 char SMnumber[][100]={"0","1","2","3","4","5","6","7","8","9"};
48 
49 const int kNbCol=48;
50 const int kNbRow=24;
51 const int kNbSM=10;
52 
53 
54 
71 
76 {int ism,icol,irow,iScan,cmpt,cmptEye;
77 
78  double p0,p1,p2,p1Max,p2Max;
79  double p0tab[48][24]={{0.}};
80  double p1tab[48][24]={{0.}};
81  double p2tab[48][24]={{0.}};
82  double yearTab[48][24]={{0.}};
83  double monthTab[48][24]={{0.}};
84 
85  //defineMyPalette2011(30,5);
86 
87  //CUSTOMIZE customize :
88  const int kNbHVscans=3;
89  const int kNbMaxDiscardTowers=200;
90 
91  FILE *inFile,*outParamFile;
92  char paramFileName[200],baseName[200];
93  TString **HVscansPaths,**discardFiles;
94  HVscansPaths = new TString*[kNbHVscans];
95  discardFiles = new TString*[kNbHVscans];
96  int HVscansYears[kNbHVscans];
97  int HVscansMonths[kNbHVscans];
98  double discardScans[kNbHVscans][10][48][24]={{{{0.}}}};
99 
100  //CUSTOMIZE customize :
101  sprintf(baseName,"mergedHVscanParamsApr2013");
102  //CUSTOMIZE customize :
103  discardFiles[0] = new TString("000");
104  HVscansPaths[0] = new TString("/cebaf/Web/EMCALpub/biasScanP2/feb2011/Hvscan");
105  HVscansYears[0]=2011;
106  HVscansMonths[0]=2;
107  discardFiles[1] = new TString("000");
108  HVscansPaths[1] = new TString("/cebaf/Web/EMCALpub/biasScanP2/Mars2012/Hvscan");
109  HVscansYears[1]=2012;
110  HVscansMonths[1]=3;
111  discardFiles[2] = new TString("/cebaf/faivre/recherche/calibPi0/recalculateEMCAL_HV_Apr2013/HVscanMars2013/listBadScansByEye.txt");
112  HVscansPaths[2] = new TString("/cebaf/Web/EMCALpub/biasScanP2/Mars2013/Hvscan");
113  HVscansYears[2]=2013;
114  HVscansMonths[2]=3;
115 
116  p1Max=50.0;
117  p2Max=0.055;
118  TH1F *h0 = new TH1F("h0","h0",200,-150.,150.);
119  TH1F *h1 = new TH1F("h1","h1",200,0.,p1Max);
120  TH1F *h2 = new TH1F("h2","h2",200,0.,p2Max);
121  TH2F *h10 = new TH2F("h10","h10",100,-150.,150.,100,0.,p1Max);
122  TH2F *h20 = new TH2F("h20","h20",100,-150.,150.,100,0.,p2Max);
123  TH2F *h21 = new TH2F("h21","h21",100,0.,p1Max,100,0.,p2Max);
124  h0->SetStats(0);
125  h1->SetStats(0);
126  h2->SetStats(0);
127  h10->SetStats(0);
128  h20->SetStats(0);
129  h21->SetStats(0);
130  h10->SetContour(30);
131  h20->SetContour(30);
132  h21->SetContour(30);
133 
134  printf("\nTower numbers given in Grenoble/electronic mapping convention.\n\n");
135 
136  for (iScan=0;iScan<kNbHVscans;iScan++)
137  {inFile=fopen(discardFiles[iScan]->Data(),"r");
138  if (inFile)
139  {printf("Read discard file scan %d : %s\nFound towers : ",iScan,discardFiles[iScan]->Data());
140  while (fscanf(inFile," %d %d %d\n",&ism,&icol,&irow)>0)
141  {discardScans[iScan][ism][icol][irow]=1;
142  printf("(%d,%d,%d) ",ism,icol,irow);
143  }
144  fclose(inFile);
145  }
146  else printf("By-eye discarded LED HV-scan file %s not found (HV scan %d)\n",discardFiles[iScan]->Data(),iScan);
147  printf("\n");
148  }
149 
150  gSystem->Exec(Form("mkdir %s",baseName));
151 
152  for (ism=0;ism<kNbSM;ism++)
153  {printf("\n____________________________________\nDoing SM %d...\n",ism);
154  gSystem->Exec(Form("mkdir %s/HvscanSM%s_%s_%s",baseName,SMnumber[ism],SMcalibName[ism],SMP2Name[ism]));
155  for (icol=0;icol<kNbCol;icol++)
156  {for (irow=0;irow<kNbRow;irow++)
157  {p0tab[icol][irow]=0.;
158  p1tab[icol][irow]=0.;
159  p2tab[icol][irow]=0.;
160  }
161  }
162  for (iScan=kNbHVscans-1;iScan>=0;iScan--)
163  {if (iScan==kNbHVscans-1) printf("*** LED scan %d (%02d/%d)",iScan+1,HVscansMonths[iScan],HVscansYears[iScan]);
164  else printf("*** LED scan %d (%02d/%d)\n Check scan %d : ",iScan+1,HVscansMonths[iScan],HVscansYears[iScan],iScan+2);
165  sprintf(paramFileName,"%sSM%s_%s_%s/parameters.txt",HVscansPaths[iScan]->Data(),SMnumber[ism],SMcalibName[ism],SMP2Name[ism]);
166  inFile=fopen(paramFileName,"r");
167  cmpt=0;
168  cmptEye=0;
169  if (inFile)
170  {while (fscanf(inFile," %d %d %lf %lf %lf\n",&icol,&irow,&p0,&p1,&p2)>0)
171  {if (((p1tab[icol][irow]==0.) && (p2tab[icol][irow]==0.)) || ((p1tab[icol][irow]<=0.) || (p2tab[icol][irow]<=0.))) // Previous LED HV-scan flagged not good, or has bad parameters.
172  {if (iScan != (kNbHVscans-1)) printf("(%d,%d) ",icol,irow);
173  p0tab[icol][irow]=p0;
174  p1tab[icol][irow]=p1;
175  p2tab[icol][irow]=p2;
176  yearTab[icol][irow]=HVscansYears[iScan];
177  monthTab[icol][irow]=HVscansMonths[iScan];
178  cmpt++;
179  }
180  else
181  {if ((iScan < kNbHVscans-1) && (discardScans[iScan+1][ism][icol][irow] == 1)) // Previous LED HV-scan tagged as bad by eye-inspection.
182  {printf("eye(%d,%d) ",icol,irow);
183  p0tab[icol][irow]=p0;
184  p1tab[icol][irow]=p1;
185  p2tab[icol][irow]=p2;
186  yearTab[icol][irow]=HVscansYears[iScan];
187  monthTab[icol][irow]=HVscansMonths[iScan];
188  cmptEye++;
189  }
190  }
191  }
192  fclose(inFile);
193  }
194  else printf("File %s not found\n",paramFileName);
195  printf("\n");
196  if ((iScan != (kNbHVscans-1)) && (cmpt > 0)) printf(" %d towers found with missing info.\n",cmpt);
197  if ((iScan != (kNbHVscans-1)) && (cmptEye > 0)) printf(" %d towers tagged as bad by eye-inspection.\n",cmptEye);
198  }
199 
200  printf("*** Writing to file : ");
201  cmpt=0;
202  outParamFile=fopen(Form("%s/HvscanSM%s_%s_%s/parameters.txt",baseName,SMnumber[ism],SMcalibName[ism],SMP2Name[ism]),"w");
203  for(icol=0;icol<kNbCol;icol++)
204  {for(irow=0;irow<kNbRow;irow++)
205  {//fprintf(outParamFile,"%2d %2d %lf %lf %lf %d %d\n",icol,irow,p0tab[icol][irow],p1tab[icol][irow],p2tab[icol][irow],yearTab[icol][irow],monthTab[icol][irow]);
206  fprintf(outParamFile,"%2d %2d %lf %lf %lf\n",icol,irow,p0tab[icol][irow],p1tab[icol][irow],p2tab[icol][irow]);
207  if (((p1tab[icol][irow]==0.) && (p2tab[icol][irow]==0.)) || ((p1tab[icol][irow]<=0.) || (p2tab[icol][irow]<=0.))) // All LED HV-scans flagged not good, or had bad parameters.
208  {printf("(%d,%d) ",icol,irow);
209  cmpt++;
210  }
211  else
212  {h0->Fill(p0tab[icol][irow]);
213  h1->Fill(p1tab[icol][irow]);
214  h2->Fill(p2tab[icol][irow]);
215  h10->Fill(p0tab[icol][irow],p1tab[icol][irow]);
216  h20->Fill(p0tab[icol][irow],p2tab[icol][irow]);
217  h21->Fill(p1tab[icol][irow],p2tab[icol][irow]);
218  //if (p2tab[icol][irow] < 0.006) printf(">>>>>Check tower (%d %d %d), params (%f %f %f)\n",ism,icol,irow,p0tab[icol][irow],p1tab[icol][irow],p2tab[icol][irow]);
219  //if (p2tab[icol][irow] < 0.01*TMath::Exp(-0.06*p1tab[icol][irow])) printf(">>>>>Check tower (%d %d %d), params (%f %f %f)\n",ism,icol,irow,p0tab[icol][irow],p1tab[icol][irow],p2tab[icol][irow]);
220  }
221  }
222  }
223  fclose(outParamFile);
224  printf("\n %d towers remain with missing info.\n",cmpt);
225  }
226 
227  const int cWidth=500;
228  const int cHeight=(int)(500*(29./21.));
229  TCanvas *c1 = new TCanvas("c1","EMCal cosmics analysis",cWidth,cHeight);
230 
231  c1->Divide(2,3);
232  c1->cd(1);
233  gPad->SetLogy();
234  h0->Draw();
235  c1->cd(3);
236  gPad->SetLogy();
237  h1->Draw();
238  c1->cd(5);
239  gPad->SetLogy();
240  h2->Draw();
241  c1->cd(2);
242  gPad->SetLogz();
243  h10->Draw("COLZ");
244  c1->cd(4);
245  gPad->SetLogz();
246  h20->Draw("COLZ");
247  c1->cd(6);
248  gPad->SetLogz();
249  h21->Draw("COLZ");
250  c1->Update();
251 
252  return;
253  }
254 
255 
256 
257 
258 
259 
260 
261 
262 
263 
char SMcalibName[][100]
char SMP2Name[][100]
Definition: External.C:236
void MergeHVscanFilesVariousScans2(void)
TSystem * gSystem
char SMnumber[][100]
const int kNbSM
const int kNbRow
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
const int kNbCol