AliPhysics  cc1c0ba (cc1c0ba)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helperMacrosOADBBC.C
Go to the documentation of this file.
1 
20 
21 
22 // --- ROOT system ---
23 #include <Riostream.h>
24 #include <TH2D.h>
25 #include <TFile.h>
26 #include <TCanvas.h>
27 #include <TLatex.h>
28 #include <TStyle.h>
29 
30 // --- ANALYSIS system ---
31 #include "AliEMCALGeometry.h" //include when compile
32 #include "AliCalorimeterUtils.h" //include when compile
33 #include "AliAODEvent.h" //include when compile
34 #include "AliOADBContainer.h" //include when compile
35 
36 
41 void Sort_RunNumbers(TString period="LHC15n",Int_t trainNo=603,TString runList="")
42 {
43  //......................................................
44  //..open the text file and save the run IDs into the RunId[] array
45  cout<<"o o o Open .txt file with run indices. Name = " << runList << endl;
46  TString RunPath1 = Form("./AnalysisInput/%s/Train_%i/%s",period.Data(),trainNo,runList.Data());
47  cout<<"o o o Open .txt file with run indices = " << RunPath1 << endl;
48  FILE *pFile1 = fopen(RunPath1.Data(), "r");
49  if(!pFile1)
50  {
51  cout<<"couldn't open file "<<RunPath1<<"!"<<endl;
52  return;
53  }
54  Int_t q1;
55  Int_t ncols1;
56  Int_t nlines1 = 0 ;
57  std::vector<Int_t> RunIdVec1;
58  while (1)
59  {
60  ncols1 = fscanf(pFile1," %d ",&q1);
61  if (ncols1< 0) break;
62  RunIdVec1.push_back(q1);
63  nlines1++;
64  }
65  fclose(pFile1);
66  std::sort (RunIdVec1.begin(), RunIdVec1.end());
67  //.......................................................
68  cout<<"Runs in Order: "<<endl;
69  for(Int_t iRun = 0; iRun < (Int_t)RunIdVec1.size(); iRun++)
70  {
71  cout<<RunIdVec1.at(iRun)<<", "<<flush;
72  }
73  cout<<endl;
74 }
81 void Test_OADB(TString period="LHC15n",Int_t trainNo=603,TString version="INT7Emc",TString runList="")
82 {
83  gStyle->SetOptStat(0); //..Do not plot stat boxes
84  //......................................................
85  // Test if the file committed to OADB is correct
86  //......................................................
87  Int_t nSM = 20;
88  TH1C *h[20];
89  Int_t cellColumnAbs,cellRowAbs,trash,cellID;
90  TString summaryPDF=Form("./AnalysisOutput/%s/Train_%i/OADB_Summary.pdf",period.Data(),trainNo);
91 
92  //......................................................
93  //..open the text file and save the run IDs into the RunId[] array
94  cout<<"o o o Open .txt file with run indices. Name = " << runList << endl;
95  TString RunPath = Form("./AnalysisInput/%s/Train_%i/%s",period.Data(),trainNo,runList.Data());
96  cout<<"o o o Open .txt file with run indices = " << RunPath << endl;
97  FILE *pFile = fopen(RunPath.Data(), "r");
98  if(!pFile)
99  {
100  cout<<"couldn't open file "<<RunPath<<"!"<<endl;
101  return;
102  }
103  Int_t q;
104  Int_t ncols;
105  Int_t nlines = 0 ;
106  Int_t RunId[500] ;
107  std::vector<Int_t> RunIdVec;
108  while (1)
109  {
110  ncols = fscanf(pFile," %d ",&q);
111  if (ncols< 0) break;
112  RunId[nlines]=q;
113  RunIdVec.push_back(q);
114  nlines++;
115  }
116  fclose(pFile);
117  //..sort the vector by size to be shure to use the right order
118  std::sort (RunIdVec.begin(), RunIdVec.end());
119  Int_t nRuns=RunIdVec.size();
120  //......................................................
121  //..Get the OADB information
122  //TString fBasePath="/Users/Eliane/Software/alice/sw/osx_x86-64/AliPhysics/latest-ali-master/OADB/EMCAL"; //..from AliPhysics
123  TString fBasePath="/Users/Eliane/Software/BadChannelAnalysis"; //..locally from OADB commit/e-mail to test quickly
124 
125  AliOADBContainer *cont=new AliOADBContainer("");
126  cont->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
127  //......................................................
128  //..Get the .root file with the original histogram to compare if they coincide
129  //TString path = Form("/Users/Eliane/Software/BadChannelAnalysis/AnalysisOutput/%s/Train_%i/VersionINT7Glob",period.Data(),trainNo);
130  //TString path = Form("/Users/Eliane/Software/BadChannelAnalysis/AnalysisOutput/%s/Train_%i/Version4ManMasked",period.Data(),trainNo);
131  TString path = Form("/Users/Eliane/Software/BadChannelAnalysis/AnalysisOutput/%s/Train_%i/Version%s",period.Data(),trainNo,version.Data());
132  TString rootFileName= Form("%s_INT7_Histograms_V%s.root",period.Data(),version.Data());
133  TFile* outputRoot = TFile::Open(Form("%s/%s",path.Data(),rootFileName.Data()));
134 
135  if(!outputRoot)cout<<"File "<<outputRoot->GetName()<<" does not exist"<<endl;
136  TH2F* h2DChannelMap_FlagBad =(TH2F*)outputRoot->Get("2DChannelMap_Flag2");
137  TH2F* h2DChannelMap_FlagDead=(TH2F*)outputRoot->Get("2DChannelMap_Flag1");
138 
139  //......................................................
140  //..Initialize EMCal/DCal geometry
141  AliCalorimeterUtils* fCaloUtils = new AliCalorimeterUtils();
142  //..Create a dummy event for the CaloUtils
143  AliAODEvent* aod = new AliAODEvent();
144  fCaloUtils->SetRunNumber(RunIdVec.at(0));
145  fCaloUtils->AccessGeometry(aod);
146  AliEMCALGeometry * geom = fCaloUtils->GetEMCALGeometry();
147 
148  //.......................................................
149  //..build two dimensional histogram with values row vs. column
150  //..with info from OADB
151  Int_t fNMaxCols = 48; //eta direction
152  Int_t fNMaxRows = 24; //phi direction
153 
154  Int_t fNMaxColsAbs = 2*fNMaxCols;
155  Int_t fNMaxRowsAbs = Int_t (nSM/2)*fNMaxRows; //multiply by number of supermodules
156  TString histoName;
157  histoName = Form("2DChannelMap_Flag_Bad");
158  TH2F *plot2D_Bad_OADB = new TH2F(histoName,histoName,fNMaxColsAbs+1,-0.5,fNMaxColsAbs+0.5, fNMaxRowsAbs+1,-0.5,fNMaxRowsAbs+0.5);
159  //*OADB looks like Marcels figures*/ TH2F *plot2D_Bad_OADB = new TH2F(histoName,histoName,fNMaxColsAbs,0,fNMaxColsAbs, fNMaxRowsAbs,0,fNMaxRowsAbs);
160  plot2D_Bad_OADB->GetXaxis()->SetTitle("cell column (#eta direction)");
161  plot2D_Bad_OADB->GetYaxis()->SetTitle("cell row (#phi direction)");
162  histoName = Form("2DChannelMap_Flag_Dead");
163  TH2F *plot2D_Dead_OADB = new TH2F(histoName,histoName,fNMaxColsAbs+1,-0.5,fNMaxColsAbs+0.5, fNMaxRowsAbs+1,-0.5,fNMaxRowsAbs+0.5);
164  //*OADB looks like Marcels figures*/ TH2F *plot2D_Dead_OADB = new TH2F(histoName,histoName,fNMaxColsAbs,0,fNMaxColsAbs, fNMaxRowsAbs,0,fNMaxRowsAbs);
165  plot2D_Dead_OADB->GetXaxis()->SetTitle("cell column (#eta direction)");
166  plot2D_Dead_OADB->GetYaxis()->SetTitle("cell row (#phi direction)");
167 
168  //.......................................................
169  //.. Read the Bad Channel map from OADB
170  TCanvas* C2 = new TCanvas("CompareCanvas","Compare OADB to LocalFile",900,900);
171  C2->Divide(2,2);
172  TCanvas* C4 = new TCanvas("Subtraction of OADB-Orig.","Subtraction of OADB-Orig.",900,900);
173  C4->Divide(2,2);
174  TLatex* textA = new TLatex(0.5,0.8,"If empty -> good!");
175  textA->SetTextSize(0.04);
176  textA->SetTextColor(1);
177  textA->SetNDC();
178 
179  cout<<"Checking "<<nRuns<<" runs: "<<endl;
180  std::vector<Int_t> RunsWithoutMap;
181  std::vector<Int_t> RunsWithMap;
182 
183  for(Int_t iRun = 0; iRun < nRuns; iRun++)
184  {
185  //cout<<"------ run "<<RunIdVec.at(iRun)<<endl;
186  if(iRun%5==0)cout<<"."<<flush;
187  if(iRun%20==0)cout<<"Run No."<<iRun<<endl;
188  TObjArray *recal=(TObjArray*)cont->GetObject(RunIdVec.at(iRun));
189  if(!recal)
190  {
191  cout<<"Error - No bad map for run Number "<<RunIdVec.at(iRun)<<" online!!"<<endl;
192  RunsWithoutMap.push_back(RunIdVec.at(iRun));
193  continue;
194  }
195  RunsWithMap.push_back(RunIdVec.at(iRun));
196 
197  plot2D_Bad_OADB ->Reset();
198  plot2D_Dead_OADB->Reset();
199  for(Int_t iSM = 0; iSM < nSM; iSM++)
200  {
201  //..Bad map fore each module
202  h[iSM]=(TH1C *)recal->FindObject(Form("EMCALBadChannelMap_Mod%d",iSM));
203  //..Loop though the SM to set which cells are bad
204  for(Int_t column=0;column<48;column++)
205  {
206  for(Int_t row=0;row<24;row++)
207  {
208  Int_t inRow=row;
209  Int_t inCol=column;
210  cellID=geom->GetAbsCellIdFromCellIndexes(iSM,inRow,inCol);
211  fCaloUtils->GetModuleNumberCellIndexesAbsCaloMap(cellID,0,inCol,inRow,trash,cellColumnAbs,cellRowAbs);
212  if(h[iSM]->GetBinContent(column,row)>1)//..bad and warm
213  {
214  plot2D_Bad_OADB->SetBinContent(cellColumnAbs,cellRowAbs,1);
215  }
216  if(h[iSM]->GetBinContent(column,row)==1)//..dead
217  {
218  plot2D_Dead_OADB->SetBinContent(cellColumnAbs,cellRowAbs,1);
219  }
220  }
221  }
222  }
223  //..................................................................
224  TLatex* text=new TLatex(0.15,0.85,Form("Run Number %i",RunIdVec.at(iRun)));
225  text->SetTextSize(0.05);
226  text->SetNDC();
227  text->SetTextColor(1);
228  text->SetTextAngle(0);
229 
230  C2->cd(1);
231  plot2D_Bad_OADB->SetTitle("Bad Cells OADB");
232  plot2D_Bad_OADB->DrawCopy("colz");
233  text->Draw();
234  C2->cd(2);
235  plot2D_Dead_OADB->SetTitle("Dead Cells OADB");
236  plot2D_Dead_OADB->DrawCopy("colz");
237  C2->cd(3);
238  h2DChannelMap_FlagBad->SetTitle("Bad Cells LocalFile");
239  h2DChannelMap_FlagBad->DrawCopy("colz");
240  C2->cd(4);
241  h2DChannelMap_FlagDead->SetTitle("Dead Cells LocalFile");
242  h2DChannelMap_FlagDead->DrawCopy("colz");
243 
244  //..................................................................
245  C4->cd(1);
246  plot2D_Bad_OADB->SetTitle("OADB-Local File (Bad)");
247  plot2D_Bad_OADB->Add(h2DChannelMap_FlagBad,-1);
248  plot2D_Bad_OADB->DrawCopy("colz");
249  plot2D_Bad_OADB->Add(h2DChannelMap_FlagBad,+1);
250  textA->Draw();
251  text->Draw();
252  C4->cd(2);
253  plot2D_Dead_OADB->SetTitle("OADB-Local File (Dead)");
254  plot2D_Dead_OADB->Add(h2DChannelMap_FlagDead,-1);
255  plot2D_Dead_OADB->DrawCopy("colz");
256  plot2D_Dead_OADB->Add(h2DChannelMap_FlagDead,+1);
257  textA->Draw();
258  C4->cd(3);
259  plot2D_Bad_OADB->SetTitle("OADB/Local File (Bad)");
260  plot2D_Bad_OADB->Divide(h2DChannelMap_FlagBad);
261  plot2D_Bad_OADB->DrawCopy("colz");
262  C4->cd(4);
263  plot2D_Dead_OADB->SetTitle("OADB/Local File (Dead)");
264  plot2D_Dead_OADB->Divide(h2DChannelMap_FlagDead);
265  plot2D_Dead_OADB->DrawCopy("colz");
266 
267  //..................................................................
268  //..Save to PDF
269  //..Add figures to the summary canvas
270  if(iRun==0)C2 ->Print(Form("%s(",summaryPDF.Data()));
271  else C2 ->Print(Form("%s(",summaryPDF.Data()));
272  if(iRun==nRuns-1)C4 ->Print(Form("%s)",summaryPDF.Data()));
273  else C4 ->Print(Form("%s",summaryPDF.Data()));
274  }//end of run loop
275  cout<<"==Total Summary=="<<endl;
276  //..print runs without a correct map.
277  cout<<"Runs with a bad map ("<<RunsWithMap.size()<<"): "<<flush;
278  for(Int_t i=0;i<(Int_t)RunsWithMap.size();i++)
279  {
280  cout<<RunsWithMap.at(i)<<","<<flush;
281  }
282  cout<<endl;
283  cout<<"Runs without a bad map ("<<RunsWithoutMap.size()<<"): "<<flush;
284  for(Int_t i=0;i<(Int_t)RunsWithoutMap.size();i++)
285  {
286  cout<<RunsWithoutMap.at(i)<<","<<flush;
287  }
288  cout<<endl;
289 }
295 void Plot_CellList(TString period="LHC15n",Int_t trainNo=603,TString version="5",TString cellList="")
296 {
297  //......................................................
298  //..open the text file and save the run IDs into the RunId[] array
299  cout<<"o o o Open .txt file with run indices. Name = " << cellList << endl;
300  FILE *pFile = fopen(cellList.Data(), "r");
301  if(!pFile)
302  {
303  cout<<"couldn't open file "<<cellList<<"!"<<endl;
304  return;
305  }
306  Int_t q;
307  Int_t ncols;
308  Int_t nlines = 0 ;
309  Int_t cellId[500] ;
310  std::vector<Int_t> cellIdVec;
311  while (1)
312  {
313  ncols = fscanf(pFile," %d ",&q);
314  if (ncols< 0) break;
315  cellId[nlines]=q;
316  cellIdVec.push_back(q);
317  nlines++;
318  }
319  fclose(pFile);
320  //..sort the vector by size to be shure to use the right order
321  std::sort (cellIdVec.begin(), cellIdVec.end());
322  Int_t nCells=cellIdVec.size();
323 
324  //......................................................
325  //..Get the .root file with the original histogram to compare if they coincide
326  TString path = Form("/Users/Eliane/Software/BadChannelAnalysis/AnalysisOutput/%s/Train_%i/Version%s",period.Data(),trainNo,version.Data());
327  TString rootFileName= Form("%s_INT7_Histograms_V%s.root",period.Data(),version.Data());
328  TFile* outputRoot = TFile::Open(Form("%s/%s",path.Data(),rootFileName.Data()));
329  if(!outputRoot)cout<<"File "<<outputRoot->GetName()<<" does not exist"<<endl;
330  TH2F* h2DAmp =(TH2F*)outputRoot->Get("hCellAmplitude");
331  TH2F* h2DRatio =(TH2F*)outputRoot->Get("ratio2DAmp");
332 
333  TCanvas *c1 = new TCanvas(1);
334  c1->Divide(2);
335  c1->cd(1);
336  h2DAmp->Draw("colz");
337  c1->cd(2);
338  h2DRatio->Draw("colz");
339 
340 
341 
342  Int_t totalperCv = 16;
343  Int_t nPad = TMath::Sqrt(totalperCv);
344  Int_t nCv = nCells/totalperCv+1;
345  if(nCv<1)nCv=1;
346 
347  cout<<" o create: "<<nCv<<" Canvases with "<<nPad*nPad<<" pads"<<endl;
348  //..to compare specific cells over the runs
349  TCanvas **cComp = new TCanvas*[nCv];
350  TCanvas **cCompR = new TCanvas*[nCv];
351  for(Int_t i=0;i<nCv;i++)
352  {
353  cComp[i] = new TCanvas(TString::Format("CompareGood%d", i), TString::Format("V) Candidates (%d/%d)", i+1, nCv), 1000,750);
354  cComp[i] ->Divide(nPad,nPad,0.001,0.001);
355  cCompR[i] = new TCanvas(TString::Format("CompareGoodR%d", i), TString::Format("V) Ratio (%d/%d)", i+1, nCv), 1000,750);
356  cCompR[i] ->Divide(nPad,nPad,0.001,0.001);
357  }
358  cout<<" o Fill Canvases with bad cells canvases"<<endl;
359 
360  for(Int_t icell = 0; icell < nCells; icell++)
361  {
362  TH1D *htmpCellAllRuns =h2DAmp->ProjectionX(TString::Format("hIDProj_cell%d", icell), icell+1, icell+1);
363  cout<<"cell number:"<<cellIdVec.at(icell)<<endl;
364  cComp[(icell)/totalperCv]->cd(((icell)%totalperCv)+1)->SetLogy();
365  //SetHisto(htmpCellAllRuns,Form("Energy of cell %i",cellIdVec.at(icell)),"Number of Hits",0);
366  //htmpCellAllRuns->GetXaxis()->SetRangeUser(0,3);
367  htmpCellAllRuns->Draw("hist");
368 
369 
370  TH1D *htmpCellRatioAllRuns =h2DRatio->ProjectionX(TString::Format("hIDRatioProj_cell%d", icell), icell+1, icell+1);
371  cout<<"cell number:"<<cellIdVec.at(icell)<<endl;
372  cCompR[(icell)/totalperCv]->cd(((icell)%totalperCv)+1)->SetLogy();
373  //SetHisto(htmpCellAllRuns,Form("Energy of cell %i",cellIdVec.at(icell)),"Number of Hits",0);
374  //htmpCellAllRuns->GetXaxis()->SetRangeUser(0,3);
375  htmpCellRatioAllRuns->Draw("hist");
376 }
377 
378  TString pdfName="MoreBadCellsCandidates.pdf";
379  //..plot the canvases of cells into a .pdf file
380  for(Int_t can=0;can<nCv;can++)
381  {
382  //TString internal_pdfName1=pdfName+"Low.pdf";
383  if(can==0)
384  {
385  //..first pad
386  //internal_pdfName1 +="(";
387  cComp[can] ->Print(Form("%s(",pdfName.Data()));
388  }
389  else if(can==(nCv-1))
390  {
391  //..last pad
392  //internal_pdfName1 +=")";
393  cComp[can] ->Print(Form("%s)",pdfName.Data()));
394  }
395  else
396  {
397  //..all pads in between
398  cComp[can] ->Print(Form("%s",pdfName.Data()));
399  }
400  }
401 
402 
403 
404 }
405 
406 
void SetRunNumber(Int_t run)
Definition: External.C:236
TLatex * text[5]
option to what and if export to output file
void Test_OADB(TString period="LHC15n", Int_t trainNo=603, TString version="INT7Emc", TString runList="")
AliEMCALGeometry * GetEMCALGeometry() const
int Int_t
Definition: External.C:63
void Sort_RunNumbers(TString period="LHC15n", Int_t trainNo=603, TString runList="")
Definition: External.C:212
const char * pdfName
Definition: DrawAnaELoss.C:30
Class with utils specific to calorimeter clusters/cells.
void AccessGeometry(AliVEvent *inputEvent)
void Plot_CellList(TString period="LHC15n", Int_t trainNo=603, TString version="5", TString cellList="")
Int_t GetModuleNumberCellIndexesAbsCaloMap(Int_t absId, Int_t calo, Int_t &icol, Int_t &irow, Int_t &iRCU, Int_t &icolAbs, Int_t &irowAbs) const