AliPhysics  d497547 (d497547)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helperMacrosOADBBC.C
Go to the documentation of this file.
1 
19 
20 
21 // --- ROOT system ---
22 #include <Riostream.h>
23 #include <TH2D.h>
24 #include <TFile.h>
25 #include <TCanvas.h>
26 #include <TLatex.h>
27 #include <TStyle.h>
28 
29 // --- ANALYSIS system ---
30 #include "AliEMCALGeometry.h" //include when compile
31 #include "AliCalorimeterUtils.h" //include when compile
32 #include "AliAODEvent.h" //include when compile
33 #include "AliOADBContainer.h" //include when compile
34 
35 
40 void Sort_RunNumbers(TString period="LHC15n",Int_t trainNo=603,TString runList="")
41 {
42  //......................................................
43  //..open the text file and save the run IDs into the RunId[] array
44  cout<<"o o o Open .txt file with run indices. Name = " << runList << endl;
45  TString RunPath1 = Form("./AnalysisInput/%s/Train_%i/%s",period.Data(),trainNo,runList.Data());
46  cout<<"o o o Open .txt file with run indices = " << RunPath1 << endl;
47  FILE *pFile1 = fopen(RunPath1.Data(), "r");
48  if(!pFile1)
49  {
50  cout<<"couldn't open file "<<RunPath1<<"!"<<endl;
51  return;
52  }
53  Int_t q1;
54  Int_t ncols1;
55  Int_t nlines1 = 0 ;
56  std::vector<Int_t> RunIdVec1;
57  while (1)
58  {
59  ncols1 = fscanf(pFile1," %d ",&q1);
60  if (ncols1< 0) break;
61  RunIdVec1.push_back(q1);
62  nlines1++;
63  }
64  fclose(pFile1);
65  std::sort (RunIdVec1.begin(), RunIdVec1.end());
66  //.......................................................
67  cout<<"Runs in Order: "<<endl;
68  for(Int_t iRun = 0; iRun < (Int_t)RunIdVec1.size(); iRun++)
69  {
70  cout<<RunIdVec1.at(iRun)<<", "<<flush;
71  }
72  cout<<endl;
73 }
80 void Test_OADB(TString period="LHC15n",Int_t trainNo=603,Int_t version=5,TString runList="")
81 {
82  gStyle->SetOptStat(0); //..Do not plot stat boxes
83  //......................................................
84  // Test if the file committed to OADB is correct
85  //......................................................
86  Int_t nSM = 20;
87  TH1C *h[20];
88  Int_t cellColumnAbs,cellRowAbs,trash,cellID;
89  TString summaryPDF=Form("./AnalysisOutput/%s/Train_%i/OADB_Summary.pdf",period.Data(),trainNo);
90 
91  //......................................................
92  //..open the text file and save the run IDs into the RunId[] array
93  cout<<"o o o Open .txt file with run indices. Name = " << runList << endl;
94  TString RunPath = Form("./AnalysisInput/%s/Train_%i/%s",period.Data(),trainNo,runList.Data());
95  cout<<"o o o Open .txt file with run indices = " << RunPath << endl;
96  FILE *pFile = fopen(RunPath.Data(), "r");
97  if(!pFile)
98  {
99  cout<<"couldn't open file "<<RunPath<<"!"<<endl;
100  return;
101  }
102  Int_t q;
103  Int_t ncols;
104  Int_t nlines = 0 ;
105  Int_t RunId[500] ;
106  std::vector<Int_t> RunIdVec;
107  while (1)
108  {
109  ncols = fscanf(pFile," %d ",&q);
110  if (ncols< 0) break;
111  RunId[nlines]=q;
112  RunIdVec.push_back(q);
113  nlines++;
114  }
115  fclose(pFile);
116  //..sort the vector by size to be shure to use the right order
117  std::sort (RunIdVec.begin(), RunIdVec.end());
118  Int_t nRuns=RunIdVec.size();
119  //......................................................
120  //..Get the OADB information
121  //TString fBasePath="/Users/Eliane/Software/alice/sw/osx_x86-64/AliPhysics/latest-ali-master/OADB/EMCAL";
122  TString fBasePath="/Users/Eliane/Software/BadChannelAnalysis";
123 
124  AliOADBContainer *cont=new AliOADBContainer("");
125  cont->InitFromFile(Form("%s/EMCALBadChannels.root",fBasePath.Data()),"AliEMCALBadChannels");
126  //......................................................
127  //..Get the .root file with the original histogram to compare if they coincide
128  //TString path = Form("/Users/Eliane/Software/BadChannelAnalysis/AnalysisOutput/%s/Train_%i/VersionINT7Glob",period.Data(),trainNo);
129  //TString path = Form("/Users/Eliane/Software/BadChannelAnalysis/AnalysisOutput/%s/Train_%i/Version4ManMasked",period.Data(),trainNo);
130  TString path = Form("/Users/Eliane/Software/BadChannelAnalysis/AnalysisOutput/%s/Train_%i/Version%i",period.Data(),trainNo,version);
131  TString rootFileName= Form("%s_INT7_Histograms_V%i.root",period.Data(),version);
132  TFile* outputRoot = TFile::Open(Form("%s/%s",path.Data(),rootFileName.Data()));
133 
134  if(!outputRoot)cout<<"File "<<outputRoot->GetName()<<" does not exist"<<endl;
135  TH2F* h2DChannelMap_FlagBad =(TH2F*)outputRoot->Get("2DChannelMap_Flag2");
136  TH2F* h2DChannelMap_FlagDead=(TH2F*)outputRoot->Get("2DChannelMap_Flag1");
137 
138  //......................................................
139  //..Initialize EMCal/DCal geometry
140  AliCalorimeterUtils* fCaloUtils = new AliCalorimeterUtils();
141  //..Create a dummy event for the CaloUtils
142  AliAODEvent* aod = new AliAODEvent();
143  fCaloUtils->SetRunNumber(RunIdVec.at(0));
144  fCaloUtils->AccessGeometry(aod);
145  AliEMCALGeometry * geom = fCaloUtils->GetEMCALGeometry();
146 
147  //.......................................................
148  //..build two dimensional histogram with values row vs. column
149  //..with info from OADB
150  Int_t fNMaxCols = 48; //eta direction
151  Int_t fNMaxRows = 24; //phi direction
152 
153  Int_t fNMaxColsAbs = 2*fNMaxCols;
154  Int_t fNMaxRowsAbs = Int_t (nSM/2)*fNMaxRows; //multiply by number of supermodules
155  TString histoName;
156  histoName = Form("2DChannelMap_Flag_Bad");
157  TH2F *plot2D_Bad_OADB = new TH2F(histoName,histoName,fNMaxColsAbs+1,-0.5,fNMaxColsAbs+0.5, fNMaxRowsAbs+1,-0.5,fNMaxRowsAbs+0.5);
158  //*OADB looks like Marcels figures*/ TH2F *plot2D_Bad_OADB = new TH2F(histoName,histoName,fNMaxColsAbs,0,fNMaxColsAbs, fNMaxRowsAbs,0,fNMaxRowsAbs);
159  plot2D_Bad_OADB->GetXaxis()->SetTitle("cell column (#eta direction)");
160  plot2D_Bad_OADB->GetYaxis()->SetTitle("cell row (#phi direction)");
161  histoName = Form("2DChannelMap_Flag_Dead");
162  TH2F *plot2D_Dead_OADB = new TH2F(histoName,histoName,fNMaxColsAbs+1,-0.5,fNMaxColsAbs+0.5, fNMaxRowsAbs+1,-0.5,fNMaxRowsAbs+0.5);
163  //*OADB looks like Marcels figures*/ TH2F *plot2D_Dead_OADB = new TH2F(histoName,histoName,fNMaxColsAbs,0,fNMaxColsAbs, fNMaxRowsAbs,0,fNMaxRowsAbs);
164  plot2D_Dead_OADB->GetXaxis()->SetTitle("cell column (#eta direction)");
165  plot2D_Dead_OADB->GetYaxis()->SetTitle("cell row (#phi direction)");
166 
167  //.......................................................
168  //.. Read the Bad Channel map from OADB
169  TCanvas* C2 = new TCanvas("CompareCanvas","Compare OADB to LocalFile",900,900);
170  C2->Divide(2,2);
171  TCanvas* C4 = new TCanvas("Subtraction of OADB-Orig.","Subtraction of OADB-Orig.",900,900);
172  C4->Divide(2,2);
173  TLatex* textA = new TLatex(0.5,0.8,"If empty -> good!");
174  textA->SetTextSize(0.04);
175  textA->SetTextColor(1);
176  textA->SetNDC();
177 
178  cout<<"Checking "<<nRuns<<" runs: "<<endl;
179  for(Int_t iRun = 0; iRun < nRuns; iRun++)
180  {
181  //cout<<"------ run "<<RunIdVec.at(iRun)<<endl;
182  if(iRun%5==0)cout<<"."<<flush;
183  if(iRun%20==0)cout<<"Run No."<<iRun<<endl;
184  TObjArray *recal=(TObjArray*)cont->GetObject(RunIdVec.at(iRun));
185  if(!recal)cout<<"Error - No bad map for run Number "<<RunIdVec.at(iRun)<<" online!!"<<endl;
186 
187  plot2D_Bad_OADB ->Reset();
188  plot2D_Dead_OADB->Reset();
189  for(Int_t iSM = 0; iSM < nSM; iSM++)
190  {
191  //..Bad map fore each module
192  h[iSM]=(TH1C *)recal->FindObject(Form("EMCALBadChannelMap_Mod%d",iSM));
193  //..Loop though the SM to set which cells are bad
194  for(Int_t column=0;column<48;column++)
195  {
196  for(Int_t row=0;row<24;row++)
197  {
198  Int_t inRow=row;
199  Int_t inCol=column;
200  cellID=geom->GetAbsCellIdFromCellIndexes(iSM,inRow,inCol);
201  fCaloUtils->GetModuleNumberCellIndexesAbsCaloMap(cellID,0,inCol,inRow,trash,cellColumnAbs,cellRowAbs);
202  if(h[iSM]->GetBinContent(column,row)>1)//..bad and warm
203  {
204  plot2D_Bad_OADB->SetBinContent(cellColumnAbs,cellRowAbs,1);
205  }
206  if(h[iSM]->GetBinContent(column,row)==1)//..dead
207  {
208  plot2D_Dead_OADB->SetBinContent(cellColumnAbs,cellRowAbs,1);
209  }
210  }
211  }
212  }
213  //..................................................................
214  TLatex* text=new TLatex(0.15,0.85,Form("Run Number %i",RunIdVec.at(iRun)));
215  text->SetTextSize(0.05);
216  text->SetNDC();
217  text->SetTextColor(1);
218  text->SetTextAngle(0);
219 
220  C2->cd(1);
221  plot2D_Bad_OADB->SetTitle("Bad Cells OADB");
222  plot2D_Bad_OADB->DrawCopy("colz");
223  text->Draw();
224  C2->cd(2);
225  plot2D_Dead_OADB->SetTitle("Dead Cells OADB");
226  plot2D_Dead_OADB->DrawCopy("colz");
227  C2->cd(3);
228  h2DChannelMap_FlagBad->SetTitle("Bad Cells LocalFile");
229  h2DChannelMap_FlagBad->DrawCopy("colz");
230  C2->cd(4);
231  h2DChannelMap_FlagDead->SetTitle("Dead Cells LocalFile");
232  h2DChannelMap_FlagDead->DrawCopy("colz");
233 
234  //..................................................................
235  C4->cd(1);
236  plot2D_Bad_OADB->SetTitle("OADB-Local File (Bad)");
237  plot2D_Bad_OADB->Add(h2DChannelMap_FlagBad,-1);
238  plot2D_Bad_OADB->DrawCopy("colz");
239  plot2D_Bad_OADB->Add(h2DChannelMap_FlagBad,+1);
240  textA->Draw();
241  text->Draw();
242  C4->cd(2);
243  plot2D_Dead_OADB->SetTitle("OADB-Local File (Dead)");
244  plot2D_Dead_OADB->Add(h2DChannelMap_FlagDead,-1);
245  plot2D_Dead_OADB->DrawCopy("colz");
246  plot2D_Dead_OADB->Add(h2DChannelMap_FlagDead,+1);
247  textA->Draw();
248  C4->cd(3);
249  plot2D_Bad_OADB->SetTitle("OADB/Local File (Bad)");
250  plot2D_Bad_OADB->Divide(h2DChannelMap_FlagBad);
251  plot2D_Bad_OADB->DrawCopy("colz");
252  C4->cd(4);
253  plot2D_Dead_OADB->SetTitle("OADB/Local File (Dead)");
254  plot2D_Dead_OADB->Divide(h2DChannelMap_FlagDead);
255  plot2D_Dead_OADB->DrawCopy("colz");
256 
257  //..................................................................
258  //..Save to PDF
259  //..Add figures to the summary canvas
260  if(iRun==0)C2 ->Print(Form("%s(",summaryPDF.Data()));
261  else C2 ->Print(Form("%s(",summaryPDF.Data()));
262  if(iRun==nRuns-1)C4 ->Print(Form("%s)",summaryPDF.Data()));
263  else C4 ->Print(Form("%s",summaryPDF.Data()));
264  }//end of run loop
265 }
void SetRunNumber(Int_t run)
Definition: External.C:236
void Test_OADB(TString period="LHC15n", Int_t trainNo=603, Int_t version=5, TString runList="")
AliEMCALGeometry * GetEMCALGeometry() const
int Int_t
Definition: External.C:63
void Sort_RunNumbers(TString period="LHC15n", Int_t trainNo=603, TString runList="")
Class with utils specific to calorimeter clusters/cells.
void AccessGeometry(AliVEvent *inputEvent)
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