AliPhysics  556872f (556872f)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
helperMacrosRunByRunBC.C
Go to the documentation of this file.
1 
21 // --- ROOT system ---
22 #include <Riostream.h>
23 #include <TStyle.h>
24 #include <TCanvas.h>
25 #include <TROOT.h>
26 #include <TGaxis.h>
27 #include <TFile.h>
28 #include <TLatex.h>
29 #include <TLegend.h>
30 #include <TEnv.h>
31 #include <TSystem.h>
32 
33 
34 // --- ANALYSIS system ---
35 #include "AliEMCALGeometry.h" //include when compile
36 #include "AliCalorimeterUtils.h" //include when compile
37 #include "AliAODEvent.h" //include when compile
38 
39 //colors
40 const Int_t RainbowColors[]= {kRed, kRed-4, kRed-7, kRed-9, kRed-10, kYellow, kYellow-4, kYellow-7, kYellow-9, kYellow-10, kGreen, kGreen-4 , kGreen-7, kGreen-9, kGreen-10, kCyan, kCyan-4, kCyan-7, kCyan-9, kCyan-10, kBlue, kBlue-4, kBlue-7, kBlue-9, kBlue-10, kMagenta, kMagenta-4, kMagenta-7, kMagenta-9, kMagenta-10};
41 
42 //definition of methods
43 TH2F* CompressHistogram(TH2 *Histo,Int_t totalCells, Int_t badCells,std::vector<Int_t> runIdVec);
44 
45 void BuildMaxMinHisto(TH1D* inHisto, TH1D* minHist,TH1D* maxHist);
46 void PlotLowFractionCells(TString pdfName, std::vector<Int_t> cellVector,TH2F* badVsCell[],Int_t nRuns,TH2F* ampID[],TH1D* hCellGoodMean[]);
47 Bool_t IsItReallyBadRatio(TH1D* minHistoRatio,TH1D* maxHistoRatio,TH1D* meanHistoRatior,TString& crit);
48 
49 void PlotHorLineRange(Double_t y_val, Double_t xLow, Double_t xHigh, Int_t Line_Col);
50 void SetHisto(TH2 *Histo,TString Xtitel,TString Ytitel,Bool_t longhisto);
51 void SetHisto(TH1 *Histo,TString Xtitel,TString Ytitel,Bool_t longhisto);
52 Bool_t IsCellMaskedByHand(Int_t cell, std::vector<Int_t> cellVector);
53 void CreateCellCompPDF(TH2F* hAmpIDMasked, std::vector<Int_t> cellVector, TH1* goodCellsMerged, TH1* goodCellsRbR, TString pdfName);
54 void Plot2DCells(TString Block, Int_t runNo, std::vector<Int_t> cellVectorRbR, std::vector<Int_t> cellVectorMerge);
55 
59 //________________________________________________________________________
60 void SummarizeRunByRun(TString period = "LHC15o", TString train = "Train_641", TString trigger= "AnyINTnoBC", TString listName="runList",Int_t runsUsed=-1)
61 {
62  gROOT->ProcessLine("gErrorIgnoreLevel = kWarning;"); //..to supress a lot of standard output
63 
64  gStyle->SetOptTitle(0);
65  gStyle->SetOptStat(0);
66  //gStyle->SetPalette(53); //standard is 1
67  gStyle->SetCanvasColor(10);
68  TGaxis::SetMaxDigits(4);
69  gStyle->SetPadTopMargin(0.07);//0.05
70  gStyle->SetPadBottomMargin(0.18);//0.15
71  gStyle->SetPadRightMargin(0.10);
72  gStyle->SetPadLeftMargin(0.15);
73  gStyle->SetFrameFillColor(10);
74  gStyle->SetLabelSize(0.05,"X");
75  gStyle->SetLabelSize(0.05,"Y");
76  gStyle->SetTitleSize(5.0,"X");
77  gStyle->SetTitleSize(5.0,"Y");
78  gEnv->SetValue("Canvas.ShowEventStatus",1); //shows the status bar in the canvas
79 
80  //..............................................
81  //..manually disable cells
82  std::vector<Int_t> badcellsBlock1;
83  std::vector<Int_t> badcellsBlock2;
84  std::vector<Int_t> badcellsBlock3;
85  std::vector<Int_t> badcellsBlock4;
86  //badcellsBlock1.push_back(13483);
87  //badcellsBlock2.push_back(13483);
88  //badcellsBlock3.push_back(13483);
89  //badcellsBlock4.push_back(13483);
90 
91  //..select runs after which a new bad map is built
92  //..you get these numbers after you run this function and then the GetBestPeriodSplitting function
93  Int_t splitRuns1=34; //run bock is inclusive of this run
94  Int_t splitRuns2=66; //run bock is inclusive of this run
95  Int_t splitRuns3=74; //run bock is inclusive of this run
96  //..............................................
97  TString analysisInput = Form("AnalysisInput/%s",period.Data());
98  TString analysisOutput = Form("AnalysisOutput/%s/%s",period.Data(),train.Data());
99  TString runList = Form("./%s/%s/%s.txt", analysisInput.Data(), train.Data(),listName.Data());
100  gSystem->mkdir(TString::Format("%s/RunByRunSummary%i/", analysisOutput.Data(),runsUsed));
101 
102  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103  //..open the text file and save the run IDs into the RunId[] array
104  cout<<"o o o Open .txt file with run indices. Name = " << runList << endl;
105  FILE *pFile = fopen(runList.Data(), "r");
106  if(!pFile)
107  {
108  cout<<"couldn't open file "<<runList<<"!"<<endl;
109  return;
110  }
111  Int_t q;
112  Int_t ncols;
113  Int_t nlines = 0 ;
114  Int_t RunId[500] ;
115  std::vector<Int_t> RunIdVec;
116  while (1)
117  {
118  ncols = fscanf(pFile," %d ",&q);
119  if (ncols< 0) break;
120  RunId[nlines]=q;
121  RunIdVec.push_back(q);
122  nlines++;
123  }
124  fclose(pFile);
125  //..sort the vector by size to be shure to use the right order
126  std::sort (RunIdVec.begin(), RunIdVec.end());
127  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
128  //..Create different canvases for run-by-runcomparision
129  cout<<"o o o Found " << RunIdVec.size() <<" files in list"<< endl;
130  Int_t intRun;
131 
132  intRun= RunIdVec.size();
133  if(runsUsed>0 && runsUsed<intRun)intRun = runsUsed; //for test purposes
134  const Int_t nRun = intRun;
135  Int_t nRunsUsed = nRun;
136  //ELI for MartinInt_t totalperCv = 4;
137  Int_t totalperCv = 16;
138  Int_t nPad = TMath::Sqrt(totalperCv);
139  Int_t nCv = nRun/totalperCv+1;
140 
141 
142  if(nCv<1)nCv=1;
143 
144  //..canvases per run
145  TCanvas **cBad = new TCanvas*[nCv];
146  TCanvas **cGood = new TCanvas*[nCv];
147  TCanvas **cDead = new TCanvas*[nCv];
148  TCanvas **cAmp = new TCanvas*[nCv];
149 
150  for(Int_t ic = 0; ic<nCv; ic++)
151  {
152  cBad [ic] = new TCanvas(TString::Format("badcells%d", ic), TString::Format("I) badcells (%d/%d)", ic+1, nCv), 1000,750);
153  cGood[ic] = new TCanvas(TString::Format("goodcells%d", ic),TString::Format("I) goodcells (%d/%d)", ic+1, nCv),1000,750);
154  cDead[ic] = new TCanvas(TString::Format("deadcells%d", ic),TString::Format("I) deadcells (%d/%d)", ic+1, nCv),1000,750);
155  cAmp [ic] = new TCanvas(TString::Format("Amplitide%d", ic),TString::Format("I) Amplitide (%d/%d)", ic+1, nCv),1000,750);
156 
157  cBad [ic] ->Divide(nPad,nPad,0.001,0.001);
158  cGood[ic] ->Divide(nPad,nPad,0.001,0.001);
159  cDead[ic] ->Divide(nPad,nPad,0.001,0.001);
160  cAmp [ic] ->Divide(nPad,nPad,0.001,0.001);
161  }
162 
163  //..summary figures for all runs
164  Int_t nFlags = 3;
165  TH2F** hFlagvsRun = new TH2F*[nFlags];
166  TH2F* hFlagNew = 0x0;
167  TH2F* hFlagNewClean = 0x0;
168  TH2F** ampID = new TH2F*[nRun];
169  TH2F** ampIDCl = new TH2F*[nRun];
170  TH2F** ampIDCl3Block = new TH2F*[nRun];
171  TH2F** ampIDCl1Block = new TH2F*[nRun];
172  TH2F** ampIDDelete = new TH2F*[nRun];
173  TH1D** hCellGoodMean = new TH1D*[nRun];
174  TH1D** hNEvent = new TH1D*[nRun];
175  TH2F* hBadVsEvent = new TH2F("hBadVsEvent","hBadVsEvent",100,100000,25000000,60,700,1800);
176  TH2F* hDeadBadVsEvent = new TH2F("hDeadBadVsEvent","hDeadBadVsEvent",100,100000,25000000,60,700,1800);
177  TH1D* deadbadCellsVsRun;
178  TH1D* deadCellsVsRun;
179  TH1D* badCellsVsRun;
180  TH1D* deadCellsVsRunC;
181  TH1D* badCellsVsRunC;
182  TH1D* projSum;
183  TH1D* projSumC;
184  TH1D* projSumC3Blocks;
185  TH1D* projSumC3BlocksA;
186  TH1D* projSumC3BlocksB;
187  TH1D* projSumC3BlocksC;
188  TH1D* projSumC3BlocksD;
189  TH1D* projSumC1Block;
190  TH1D* nEventsVsRuns;
191  TH2F* Sum2DSingleMask;
192  TH2F* Sum2D3BlockMask;
193  TH2F* Sum2D3BlockMaskA;
194  TH2F* Sum2D3BlockMaskB;
195  TH2F* Sum2D3BlockMaskC;
196  TH2F* Sum2D3BlockMaskD;
197  TH2F* Sum2DOrig;
198  TH2F* Sum2DIdeal;
199  TH1D* hgoodMean;
200 
201  for(Int_t i = 0; i<nFlags; i++)
202  {
203  hFlagvsRun[i] = 0x0;
204  }
205  TCanvas *cFlagDeadBadI = new TCanvas("cFlagDeadBadI", "II) Flag dead or bad a", 1600, 1000);
206  TCanvas *cFlagDeadBadII = new TCanvas("cFlagDeadBadII", "II) Flag dead or bad b", 1600, 1000);
207  TCanvas *cFlagSumI = new TCanvas("cFlagSumI", "II) Flag dead&bad a", 1600, 1000);
208  TCanvas *cFlagSumII = new TCanvas("cFlagSumII", "II) Flag dead&bad b", 1600, 1000);
209  TCanvas *cFlagSumCleanedI = new TCanvas("cFlagSumCleanI", "III) cleanded Flag dead&bad a", 1600, 1000);
210  TCanvas *cFlagSumCleanedII = new TCanvas("cFlagSumCleanII", "III) cleanded Flag dead&bad b", 1600, 1000);
211  TCanvas *cFlagSumCompAllI = new TCanvas("cFlagSumCompAllI", "III) compressed Flag dead&bad a", 1600, 1000);
212  TCanvas *cFlagSumCompAllII = new TCanvas("cFlagSumCompAllII", "III) compressed Flag dead&bad b", 1600, 1000);
213  TCanvas *cFlagSumCompCleanI = new TCanvas("cFlagSumCompI", "III) compressed&cleaned Flag dead&bad a", 1600, 1000);
214  TCanvas *cFlagSumCompCleanII= new TCanvas("cFlagSumCompII", "III) compressed&cleaned Flag dead&bad b", 1600, 1000);
215 
216  TCanvas *cFlagNew = new TCanvas("cFlagNew", "IV) Frac dead&bad 2D", 1600, 800);
217  TCanvas *cellSummaryCan = new TCanvas("cellSummaryCan", "I) run overview", 1600, 800);
218  TCanvas *cellSummaryCan2 = new TCanvas("cellSummaryCan2","I) run overview II",1600,800);
219  TCanvas *cAmpSum = new TCanvas("SumOfAmplitudes","I) Sum of Amplitides over runs",1500,750);
220  TCanvas *cAmpSum2D = new TCanvas("SumOf2DAmplitudes","I) Sum of 2D Amplitides over runs",1500,750);
221  TCanvas *cAmpSum2D4Blocks = new TCanvas("cAmpSum2D4Blocks","I) Sum of 2D Amplitides in 4 run blocks",1500,750);
222  TCanvas *cAmpSum2D4BlocksRatio = new TCanvas("cAmpSum2D4BlocksRatio","I) Ratio of 2D Amplitides in 4 run blocks",1500,750);
223 
224  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
225  //..defining variables and histograms
226  TString rootFileName;
227  TString badChannelOutput;
228  /*TString badChannelOutput[4];
229  badChannelOutput[0]="AnalysisOutput/LHC16h/Version2/Train_622AnyINTnoBC_Histograms_V2.root";
230  badChannelOutput[1]="AnalysisOutput/LHC16i/Version2/Train_623AnyINTnoBC_Histograms_V2.root";
231  badChannelOutput[2]="AnalysisOutput/LHC16k/Version0/Train_658AnyINTnoBC_Histograms_V0.root";
232  badChannelOutput[3]="AnalysisOutput/LHC16o/Version3/Train_663AnyINTnoBC_Histograms_V3.root";
233  */
234  Int_t noOfCells=0;
235  Int_t usedRuns=0;
236  Bool_t iFirstRun=0;
237 
238  AliCalorimeterUtils *fCaloUtils = new AliCalorimeterUtils();
239  //..Create a dummy event for the CaloUtils
240  AliAODEvent* aod = new AliAODEvent();
241  fCaloUtils->SetRunNumber(RunIdVec.at(0));
242  fCaloUtils->AccessGeometry(aod);
243  noOfCells=fCaloUtils->GetEMCALGeometry()->GetNCells(); //..Very important number, never change after that point!
244 
245  hFlagvsRun[0] = new TH2F("hFlag1vsRun", "hFlag1vsRun (?); cell ID; Run number", noOfCells+10, 0, noOfCells+10, nRun, 0, nRun); // update this axis, need to have the run number
246  hFlagvsRun[1] = new TH2F("hFlag2vsRun", "hFlag2vsRun (?); cell ID; Run number", noOfCells+10, 0, noOfCells+10, nRun, 0, nRun);
247  hFlagvsRun[2] = new TH2F("hFlag3vsRun", "hFlag3vsRun (?); cell ID; Run number", noOfCells+10, 0, noOfCells+10, nRun, 0, nRun);
248  nEventsVsRuns = new TH1D("nEventVsRun", "number of events in run", nRun, 0, nRun);
249 
250  for(Int_t i=0;i<nRun;i++)
251  {
252  hFlagvsRun[0]->GetYaxis()->SetBinLabel(i+1,Form("%i",RunIdVec.at(i)));
253  hFlagvsRun[1]->GetYaxis()->SetBinLabel(i+1,Form("%i",RunIdVec.at(i)));
254  hFlagvsRun[2]->GetYaxis()->SetBinLabel(i+1,Form("%i",RunIdVec.at(i)));
255  }
256  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
257  //..Open the different .root files with help of the run numbers from the text file
258  //..loop over the amount of run numbers found in the previous text file.
259  for(Int_t i = 0 ; i < nRun ; i++) //Version%i" LHC16i_muon_caloLego_Histograms_V255539
260  {
261  rootFileName = Form("%s_Histograms_V%i.root", trigger.Data(), RunIdVec.at(i));
262  badChannelOutput = Form("%s/Version%i/%s", analysisOutput.Data(), RunIdVec.at(i),rootFileName.Data());
263 
264  //Martin cout<<"Open root file: "<<badChannelOutput[i]<<endl;
265  cout<<"Open root file No: "<<i+1<<" - "<<badChannelOutput<<" - "<<flush;
266  TFile *f = TFile::Open(badChannelOutput);
267  if(!f)
268  {
269  cout<<"Couldn't open/find .root file: "<<badChannelOutput<<endl;
270  cout<<endl;
271  break;
272  }
273 
274  //..you may introduce a cut here, selecting only
275  //..runs with a certain number of events
276  hNEvent[usedRuns] = (TH1D*)f->Get("hNEvents");
277  cout<<hNEvent[usedRuns]->Integral()<<" evt."<<endl;
278 // if(hNEvent[usedRuns]->Integral()>1000000)continue;
279 
280  TH2F *goodCells = (TH2F*)f->Get("2DChannelMap_Flag0");
281  TH2F *deadCells = (TH2F*)f->Get("2DChannelMap_Flag1");
282  TH2F *badCells = (TH2F*)f->Get("2DChannelMap_Flag2");
283  TH1F *hCellFlag = (TH1F*)f->Get("fhCellFlag");
284  ampID[usedRuns] = (TH2F*)f->Get("hCellAmplitude");
285  hCellGoodMean[usedRuns]= (TH1D*)f->Get("hgoodMean");
286 
287  if(!badCells || !goodCells || !deadCells || !ampID[usedRuns] || !hCellFlag)
288  {
289  if(!badCells) Printf("2DChannelMap_Flag2 not found");
290  if(!goodCells)Printf("2DChannelMap_Flag0 not found");
291  if(!deadCells)Printf("2DChannelMap_Flag1 not found");
292  if(!ampID[usedRuns]) Printf("hCellAmplitude not found");
293  if(!hCellFlag)Printf("fhCellFlag not found");
294  cout<<endl;
295  continue;
296  }
297 
298  nEventsVsRuns->SetBinContent(usedRuns+1,hNEvent[usedRuns]->Integral());
299  ampID[usedRuns] ->SetName(Form("hCellAmplitudeRun%i",usedRuns));
300  ampIDCl[usedRuns] = (TH2F*)ampID[usedRuns]->Clone(Form("hCellAmplitudeClRun%i",usedRuns));
301  ampIDCl3Block[usedRuns]= (TH2F*)ampID[usedRuns]->Clone(Form("hCellAmplitudeCl3RunBlock%i",usedRuns));
302  ampIDCl1Block[usedRuns]= (TH2F*)ampID[usedRuns]->Clone(Form("hCellAmplitudeCl1RunBlock%i",usedRuns));
303  ampIDDelete[usedRuns] = (TH2F*)ampID[usedRuns]->Clone(Form("hCellAmplitudeTest%i",usedRuns));
304 
305  hCellGoodMean[usedRuns]->SetLineColor(kGreen);
306  if(iFirstRun==0)
307  {
308  Sum2DOrig = (TH2F*)ampID[usedRuns]->Clone("Sum2DOrig");
309  Sum2DSingleMask= (TH2F*)ampID[usedRuns]->Clone("Sum2DSingleMask");
310  Sum2D3BlockMask= (TH2F*)ampID[usedRuns]->Clone("Sum2D3BlockMask");
311  Sum2DIdeal = (TH2F*)ampID[usedRuns]->Clone("Sum2DIdealDistr");
312  Sum2DOrig ->Reset();
313  Sum2DSingleMask->Reset();
314  Sum2D3BlockMask->Reset();
315  Sum2DIdeal ->Reset();
316  hgoodMean = (TH1D*)hCellGoodMean[usedRuns]->Clone("MeanSpectrumAllRuns");
317  hgoodMean ->Reset();
318  Sum2D3BlockMaskA =(TH2F*)Sum2D3BlockMask->Clone("Sum2D3BlockMaskA");
319  Sum2D3BlockMaskB =(TH2F*)Sum2D3BlockMask->Clone("Sum2D3BlockMaskB");
320  Sum2D3BlockMaskC =(TH2F*)Sum2D3BlockMask->Clone("Sum2D3BlockMaskC");
321  Sum2D3BlockMaskD =(TH2F*)Sum2D3BlockMask->Clone("Sum2D3BlockMaskD");
322  }
323  //if(i<30)hCellGoodMean[i]->SetLineColor(RainbowColors[i]);
324  hgoodMean->Add(hCellGoodMean[usedRuns]); //..add all good distributions to build a mean of all runs
325  hCellGoodMean[usedRuns]->SetLineWidth(3);
326 
327  //..fill the histo bad cell vs. run number
328  Int_t percBad=0;
329  for(Int_t icell = 0; icell < noOfCells; icell++)
330  {
331  Int_t flag = hCellFlag->GetBinContent(icell+1);
332  //..dead
333  if(flag == 1) hFlagvsRun[0]->Fill(icell, usedRuns, 1);
334  //..bad or warm
335  if(flag>1) hFlagvsRun[1]->Fill(icell, usedRuns, 1); //fill, use the x, y values
336  //..dead+bad
337  if(flag>0)
338  {
339  hFlagvsRun[2]->Fill(icell, usedRuns, 1);
340  percBad++;
341  }
342  }
343  if(1.0*percBad/noOfCells>0.3)cout<<"Problem in this run detected. Large number of bad+dead cells (>30%) - please double check!"<<endl;
344 
345  if(!hFlagNew)
346  {
347  hFlagNew = (TH2F*)goodCells->Clone(TString::Format("h2DChannelMapNew_FlagAll"));
348  hFlagNew->Reset();
349  hFlagNew->SetTitle("Selected flag greater than 0; cell column (#eta direction); cell raw (#phi direction)");
350  hFlagNewClean = (TH2F*)goodCells->Clone(TString::Format("h2DChannelMapNew_FlagAllClean"));
351  hFlagNewClean->Reset();
352  hFlagNewClean->SetTitle("Selected flag greater than 0; cell column (#eta direction); cell raw (#phi direction)");
353  }
354 
355  // Drawing histograms for each run
356  //....................................
357  cBad[usedRuns/totalperCv]->cd(usedRuns%totalperCv+1);
358  SetHisto(badCells,"","",0);
359  badCells->Draw("colz");
360  TLatex* text = new TLatex(0.2,0.85,Form("Bad Cells - Run %i",RunIdVec.at(i)));
361  text->SetTextSize(0.06);
362  text->SetNDC();
363  text->SetTextColor(1);
364  text->Draw();
365  //....................................
366  cGood[usedRuns/totalperCv]->cd(usedRuns%totalperCv+1);
367  SetHisto(goodCells,"","",0);
368  goodCells->Draw("colz");
369  TLatex* text1 = new TLatex(0.2,0.85,Form("Good Cells - Run %i",RunIdVec.at(i)));
370  text1->SetTextSize(0.06);
371  text1->SetNDC();
372  text1->SetTextColor(1);
373  text1->Draw();
374  //....................................
375  cDead[usedRuns/totalperCv]->cd(usedRuns%totalperCv+1);
376  SetHisto(deadCells,"","",0);
377  deadCells->Draw("colz");
378  TLatex* text2 = new TLatex(0.2,0.85,Form("Dead Cells - Run %i",RunIdVec.at(i)));
379  text2->SetTextSize(0.06);
380  text2->SetNDC();
381  text2->SetTextColor(1);
382  text2->Draw();
383  //....................................
384  cAmp[usedRuns/totalperCv]->cd(usedRuns%totalperCv+1)->SetLogy();
385  TH1D* proj = ampID[usedRuns]->ProjectionX(TString::Format("hampIDProj_Run%d",RunIdVec.at(i)));
386  SetHisto(proj,"","",0);
387  proj->SetLineColor(kCyan+2);
388  proj->GetYaxis()->SetRangeUser(0.0000001,100);
389  proj->Draw("hist");
390  TLatex* text3 = new TLatex(0.2,0.85,Form("Amplitudes - Run %i",RunIdVec.at(i)));
391  text3->SetTextSize(0.06);
392  text3->SetNDC();
393  text3->SetTextColor(1);
394  text3->Draw();
395  //..create a summ version
396  if(iFirstRun==0)projSum = ampID[usedRuns]->ProjectionX("hampIDProj_Sum");
397  if(iFirstRun>0) projSum->Add(proj);
398  Sum2DOrig->Add(ampID[usedRuns]);
399 
400  iFirstRun=1;
401  usedRuns++;
402  }
403  nRunsUsed=usedRuns; //why that?? I forgot
404  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
405  // Count number of cells that are bad in at least one run
406  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
407  Int_t nBadCells=0;
408  for(Int_t ic = 0; ic < noOfCells; ic++)
409  {
410  TH1D *htmpCell = hFlagvsRun[2]->ProjectionY(TString::Format("hIDProj_cell%d", ic), ic+1, ic+1);
411  Double_t sumRun = 0;
412  for(Int_t ir = 0; ir < nRunsUsed ; ir++)
413  {
414  sumRun += htmpCell->GetBinContent(ir+1);
415  if(htmpCell->GetBinContent(ir+1)==1)
416  {
417  //..mask the bad cells for this run
418  //..Direction of amplitude (Checks energies from 0-nBins GeV)
419  for (Int_t amp = 1; amp <= ampIDCl[ir]->GetNbinsX(); amp++)
420  {
421  ampIDCl[ir]->SetBinContent(amp,ic+1,0);
422  }
423  }
424  }
425  if(sumRun!=0)nBadCells++; //only count for the dead+bad case
426  }
427 
428  hgoodMean->Scale(1.0/nRunsUsed);
429 
430  //..create an ideal 2D energy distribution for a later division
431  //..helps to identify where cells have been unmasked and whether
432  //..this was a good or bad unmasking desicion (e.g. creating spikes)
433  for(Int_t eBin=0;eBin<Sum2DIdeal->GetNbinsX();eBin++)
434  {
435  Double_t binVal=hgoodMean->GetBinContent(eBin+1);
436  for(Int_t icell=0;icell<Sum2DIdeal->GetNbinsY();icell++)
437  {
438  Sum2DIdeal->SetBinContent(eBin+1,icell+1,binVal);
439  }
440  }
441  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
442  // Draw masked cell amplitude by masking cells that were identified bad or dead in this specific run
443  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
444  for(Int_t ir = 0; ir < nRunsUsed ; ir++)
445  {
446  cAmp[ir/totalperCv]->cd(ir%totalperCv+1)->SetLogy();
447  TH1D* proj = ampIDCl[ir]->ProjectionX(TString::Format("hampIDMaskedProj_Run%d",RunIdVec.at(ir)));
448  SetHisto(proj,"","",0);
449  proj->SetLineColor(kSpring-2);
450  proj->Draw("hist same");
451  //..create a sum version
452  if(ir==0)projSumC = ampIDCl[ir]->ProjectionX("hampIDProj_SumMasked");
453  if(ir>0) projSumC->Add(proj);
454  Sum2DSingleMask->Add(ampIDCl[ir]);
455  }
456  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
457  // Draw summary histogram with dead and bad cells vs run
458  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
459  deadCellsVsRun =hFlagvsRun[0]->ProjectionY("deadCellsVsRun");
460  badCellsVsRun =hFlagvsRun[1]->ProjectionY("badCellsVsRun");
461  deadbadCellsVsRun =hFlagvsRun[2]->ProjectionY("badDeadCellsVsRun");
462  cellSummaryCan->Divide(2);
463  cellSummaryCan->cd(1);
464  SetHisto(badCellsVsRun,"Run","No. of cells",0);
465  badCellsVsRun->GetYaxis()->SetTitleOffset(1.7);
466  badCellsVsRun->GetYaxis()->SetRangeUser(0,1300);
467  badCellsVsRun->SetLineColor(kCyan+2);
468  badCellsVsRun->SetLineWidth(2);
469  badCellsVsRun->DrawCopy("hist");
470  deadCellsVsRun->SetLineColor(kMagenta-2);
471  deadCellsVsRun->SetLineWidth(2);
472  deadCellsVsRun->DrawCopy("same");
473 
474  cellSummaryCan->cd(2);
475  SetHisto(nEventsVsRuns,"Run","No. of Events",0);
476  nEventsVsRuns->DrawCopy("hist");
477 
478  cellSummaryCan2->Divide(2);
479  for(Int_t iRun=0;iRun<nRunsUsed;iRun++)
480  {
481  hBadVsEvent ->Fill(nEventsVsRuns->GetBinContent(iRun+1),badCellsVsRun->GetBinContent(iRun+1));
482  hDeadBadVsEvent->Fill(nEventsVsRuns->GetBinContent(iRun+1),deadbadCellsVsRun->GetBinContent(iRun+1),1);
483  }
484  cellSummaryCan2->cd(1);
485  SetHisto(hBadVsEvent,"events in run","bad cells in run",0);
486  hBadVsEvent->DrawCopy("colz");
487  cellSummaryCan2->cd(2);
488  SetHisto(hDeadBadVsEvent,"events in run","bad+dead cells in run",0);
489  hDeadBadVsEvent->DrawCopy("colz");
490  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
491  //Draw bad & dead cells vs. ID
492  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
493  Color_t histCol=kCyan-8;
494  //..Draw summary for all runs
495  cFlagDeadBadI->cd()->SetLeftMargin(0.05);
496  cFlagDeadBadI->cd()->SetRightMargin(0.05);
497  cFlagDeadBadI->cd()->SetBottomMargin(0.06);
498  cFlagDeadBadI->cd()->SetTopMargin(0.02);
499  SetHisto(hFlagvsRun[0],"dead cell ID","Run No.",1); //ELI TT
500  hFlagvsRun[0]->SetFillColor(histCol);
501  hFlagvsRun[0]->Draw("BOX");
502  cFlagDeadBadII->cd()->SetLeftMargin(0.05);
503  cFlagDeadBadII->cd()->SetRightMargin(0.05);
504  cFlagDeadBadII->cd()->SetBottomMargin(0.05);
505  cFlagDeadBadII->cd()->SetTopMargin(0.02);
506  SetHisto(hFlagvsRun[1],"bad cell ID","Run No.",1);
507  hFlagvsRun[1]->SetFillColor(histCol);
508  hFlagvsRun[1]->Draw("BOX");
509 
510  cFlagSumI->cd()->SetLeftMargin(0.05);
511  cFlagSumI->cd()->SetRightMargin(0.05);
512  cFlagSumI->cd()->SetBottomMargin(0.05);
513  cFlagSumI->cd()->SetTopMargin(0.02);
514  SetHisto(hFlagvsRun[2],"dead+bad cell ID pt.1","Run No.",1);
515  hFlagvsRun[2]->SetFillColor(histCol);
516  hFlagvsRun[2]->GetXaxis()->SetRangeUser(0,8837);
517  hFlagvsRun[2]->DrawCopy("BOX");
518  cFlagSumII->cd()->SetLeftMargin(0.05);
519  cFlagSumII->cd()->SetRightMargin(0.05);
520  cFlagSumII->cd()->SetBottomMargin(0.05);
521  cFlagSumII->cd()->SetTopMargin(0.02);
522  SetHisto(hFlagvsRun[2],"dead+bad cell ID pt.2","Run No.",1);
523  hFlagvsRun[2]->GetXaxis()->SetRangeUser(8838,17674-2); //ELI why does that not work?
524  hFlagvsRun[2]->DrawCopy("BOX");
525 
526  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
527  //..compress the histogram for visibility since
528  //..90% of the space is filled by empty good cells
529  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
530  TH2F* CompressedAll = CompressHistogram(hFlagvsRun[2],noOfCells , nBadCells,RunIdVec);
531  cFlagSumCompAllI->cd()->SetLeftMargin(0.05);
532  cFlagSumCompAllI->cd()->SetRightMargin(0.05);
533  cFlagSumCompAllI->cd()->SetBottomMargin(0.05);
534  cFlagSumCompAllI->cd()->SetTopMargin(0.02);
535  SetHisto(CompressedAll,"certain dead+bad cell pt.1","Run No.",1);
536  CompressedAll->GetXaxis()->SetRangeUser(0,nBadCells/2);
537  CompressedAll->SetFillColor(histCol);
538  CompressedAll->DrawCopy("BOX");
539  cFlagSumCompAllII->cd()->SetLeftMargin(0.05);
540  cFlagSumCompAllII->cd()->SetRightMargin(0.05);
541  cFlagSumCompAllII->cd()->SetBottomMargin(0.05);
542  cFlagSumCompAllII->cd()->SetTopMargin(0.02);
543  SetHisto(CompressedAll,"certain dead+bad cell pt.2","Run No.",1);
544  CompressedAll->GetXaxis()->SetRangeUser(nBadCells/2,nBadCells+2);
545  CompressedAll->DrawCopy("BOX");
546 
547  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
548  //..................................................................
549  // Find cells that are bad in a low fraction of runs
550  //..................................................................
551  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
552  cout<<" o Summary: "<<nBadCells<<" bad cells of "<<noOfCells<<" total cells and "<<nRunsUsed<<" runs"<<endl;
553  cout<<" o 1 bad run out of "<<nRunsUsed<<" is "<<1.0/nRunsUsed<<endl;
554  Double_t percbad = 0.20; //..if a cell is only bad at 20% of the runs, test it again
555  Double_t setBadCompletley=0.8; //..If a cell is bad in >80% of the runs then set it bad completley
556  cout<<" o Cells with "<<percbad<<"% of bad runs are double checked. These are "<<nRunsUsed*percbad<<" runs"<<endl;
557  cout<<" o Cell id with low fraction of bad runs:"<<endl;
558 
559  std::vector<Int_t> cellVector; //Filled with cells that onl have a small fraction of bad runs
560  Double_t fracRun = 0, sumRun = 0;
561  for(Int_t ic = 0; ic < noOfCells; ic++)
562  {
563  TH1D *htmpCell = hFlagvsRun[2]->ProjectionY(TString::Format("hIDProj_cell%d", ic), ic+1, ic+1);
564  fracRun = 0, sumRun = 0;
565  for(Int_t ir = 0; ir < nRunsUsed ; ir++)
566  {
567  sumRun += htmpCell->GetBinContent(ir+1);
568  }
569  fracRun = sumRun/(Double_t)(nRunsUsed);
570 
571  //..loose selection criteria to remove the runs with zero entries
572  if(fracRun>0)
573  {
574  Int_t cellColumn=0, cellRow=0;
575  Int_t cellColumnAbs=0, cellRowAbs=0;
576  Int_t trash = 0 ;
577  fCaloUtils->GetModuleNumberCellIndexesAbsCaloMap(ic,0,cellColumn,cellRow,trash,cellColumnAbs,cellRowAbs);
578  hFlagNew->Fill(cellColumnAbs, cellRowAbs, fracRun*100);
579  //..If a cell is bad in >80% of the runs then set it bad completley
580  if(fracRun>setBadCompletley)
581  {
582  for(Int_t j = 0 ; j < nRunsUsed; j++)
583  {
584  hFlagvsRun[2]->SetBinContent(ic+1,j+1,1);
585  }
586  }
587  //..If a cell is bad in a low fraction of runs double check it
588  if(fracRun<percbad)
589  {
590  cout<<ic<<", "<<flush;
591  cellVector.push_back(ic);
592  }
593  }
594  }
595  cout<<endl;
596  cout<<" o In total "<<cellVector.size()<<" cells fall under this category"<<endl;
597  //..................................................................
598  // Plot cells with low fraction if bad runs
599  // Double checks if they are really bad and re-includes them
600  //..................................................................
601  TString pdfName = Form("%s/RunByRunSummary/%s_LowFractionCells",analysisOutput.Data(),listName.Data());
602  PlotLowFractionCells(pdfName,cellVector,hFlagvsRun,nRunsUsed,ampID,hCellGoodMean);
603 
604  //..................................................................
605  // Draw masked cell amplitude by masking cells that were identified bad or dead in a certain runblock
606  //..................................................................
607  for(Int_t ic = 0; ic < noOfCells; ic++)
608  {
609  TH1D *htmpCellAllRuns =hFlagvsRun[2]->ProjectionY(TString::Format("hIDProj_cell%d", ic), ic+1, ic+1);
610  Double_t integralBlock1 =htmpCellAllRuns->Integral(0,splitRuns1);
611  Double_t integralBlock2 =htmpCellAllRuns->Integral(splitRuns1+1,splitRuns2);
612  Double_t integralBlock3 =htmpCellAllRuns->Integral(splitRuns2+1,splitRuns3);
613  Double_t integralBlock4 =htmpCellAllRuns->Integral(splitRuns3+1,nRunsUsed);
614 
615  //..manually mask cells
616  if(badcellsBlock1.size()>0 && ic==badcellsBlock1.at(0))integralBlock1=1;
617  if(badcellsBlock2.size()>0 && ic==badcellsBlock2.at(0))integralBlock2=1;
618  if(badcellsBlock3.size()>0 && ic==badcellsBlock3.at(0))integralBlock3=1;
619  if(badcellsBlock4.size()>0 && ic==badcellsBlock4.at(0))integralBlock4=1;
620 
621  Double_t integralBlock3Sum=integralBlock1+integralBlock2+integralBlock3;
622  //..only if the cell is bad in 1 run we will start the
623  //..masking proceedure
624  if(integralBlock3Sum>0)
625  {
626  for(Int_t ir = 0; ir < nRunsUsed ; ir++)
627  {
628  if((integralBlock1>0 && ir<=splitRuns1) ||
629  (integralBlock2>0 && ir>splitRuns1 && ir<=splitRuns2) ||
630  (integralBlock3>0 && ir>splitRuns2 && ir<=splitRuns3) ||
631  (integralBlock4>0 && ir>splitRuns3))
632  {
633  for (Int_t amp = 1; amp <= ampIDCl3Block[ir]->GetNbinsX(); amp++)
634  {
635  //..mask the cell, if it is once bad in the specific block
636  ampIDCl3Block[ir]->SetBinContent(amp,ic+1,0);
637  }
638  }
639  //..mask the cell if it is bad in any run in the period
640  for (Int_t amp = 1; amp <= ampIDCl1Block[ir]->GetNbinsX(); amp++)
641  {
642  ampIDCl1Block[ir]->SetBinContent(amp,ic+1,0);
643  }
644  }
645  }
646  }
647  //..build projections of amplitudes
648  for(Int_t ir = 0; ir < nRunsUsed ; ir++)
649  {
650  cAmp[ir/totalperCv]->cd(ir%totalperCv+1)->SetLogy();
651  TH1D* proj = ampIDCl3Block[ir]->ProjectionX(TString::Format("hampIDMaskedCleanedProj_Run%d",RunIdVec.at(ir)));
652  TH1D* projBlock = ampIDCl1Block[ir]->ProjectionX(TString::Format("hampIDMaskedCleaned1blockProj_Run%d",RunIdVec.at(ir)));
653  SetHisto(proj,"","",0);
654  proj->SetLineColor(kBlue-1);
655  proj->Draw("hist same");
656  //..create a summ version
657  if(ir==0)
658  {
659  projSumC3Blocks = ampIDCl3Block[ir]->ProjectionX("hampIDProj_SumMaskedMultipleBlock");
660  projSumC3BlocksA= ampIDCl3Block[ir]->ProjectionX("hampIDProj_SumMaskedMultipleBlockA");
661  projSumC3BlocksB= ampIDCl3Block[ir]->ProjectionX("hampIDProj_SumMaskedMultipleBlockB");
662  projSumC3BlocksC= ampIDCl3Block[ir]->ProjectionX("hampIDProj_SumMaskedMultipleBlockC");
663  projSumC3BlocksD= ampIDCl3Block[ir]->ProjectionX("hampIDProj_SumMaskedMultipleBlockD");
664  projSumC3BlocksB->Reset();
665  projSumC3BlocksC->Reset();
666  projSumC3BlocksD->Reset();
667  projSumC1Block = ampIDCl1Block[ir]->ProjectionX("hampIDProj_SumMaskedOneBlock");
668  }
669  else
670  {
671  projSumC3Blocks->Add(proj);
672  if(ir<=splitRuns1) projSumC3BlocksA->Add(proj);
673  if(ir>splitRuns1 && ir<=splitRuns2) projSumC3BlocksB->Add(proj);
674  if(ir>splitRuns2 && ir<=splitRuns3) projSumC3BlocksC->Add(proj);
675  if(ir>splitRuns3) projSumC3BlocksD->Add(proj);
676  projSumC1Block ->Add(projBlock);
677  }
678  Sum2D3BlockMask->Add(ampIDCl3Block[ir]);
679  if(ir<=splitRuns1) Sum2D3BlockMaskA->Add(ampIDCl3Block[ir]);
680  if(ir>splitRuns1 && ir<=splitRuns2)Sum2D3BlockMaskB->Add(ampIDCl3Block[ir]);
681  if(ir>splitRuns2 && ir<=splitRuns3)Sum2D3BlockMaskC->Add(ampIDCl3Block[ir]);
682  if(ir>splitRuns3) Sum2D3BlockMaskD->Add(ampIDCl3Block[ir]);
683  }
684  //..................................................................
685  // Draw the cells masked in each respective run and summed amplitudes
686  //..................................................................
687  cAmpSum->Divide(2);
688  cAmpSum->cd(1)->SetLogy();
689  SetHisto(projSum,"","No. of hits/event",0);
690  projSum->GetYaxis()->SetRangeUser(0.0000001,1000);
691  projSum->SetLineColor(kCyan+3);
692  projSum->SetLineWidth(2);
693  projSum->Draw("hist");
694 
695  projSumC->SetLineColor(kSpring-2);
696  projSumC->SetLineWidth(2);
697  projSumC->DrawCopy("hist same");
698 
699  projSumC3Blocks->SetLineColor(kCyan-8);
700  projSumC3Blocks->SetLineWidth(2);
701  projSumC3Blocks->DrawCopy("hist same");
702  projSumC1Block->SetLineColor(2);
703  projSumC1Block->DrawCopy("hist same");
704  projSumC3BlocksA->SetLineColor(4);
705  projSumC3BlocksA->DrawCopy("hist same");
706  projSumC3BlocksB->SetLineColor(5);
707  projSumC3BlocksB->DrawCopy("hist same");
708  projSumC3BlocksC->SetLineColor(6);
709  projSumC3BlocksC->DrawCopy("hist same");
710  projSumC3BlocksD->SetLineColor(kRed-7);
711  projSumC3BlocksD->DrawCopy("hist same");
712  TLegend *legSum = new TLegend(0.35,0.70,0.55,0.85);
713  legSum->AddEntry(projSum,"Original engery distr.","l");
714  legSum->AddEntry(projSumC,"Cells masked in each run","l");
715  legSum->AddEntry(projSumC3Blocks,"Cells reincluded and masked in 3 blocks","l");
716  legSum->SetBorderSize(0);
717  legSum->SetTextSize(0.03);
718  legSum->Draw("same");
719 
720  cAmpSum->cd(2);
721  projSumC3Blocks->Divide(projSumC);
722  SetHisto(projSumC3Blocks,"","block masked/single masked",0);
723  projSumC3Blocks->SetLineColor(30);
724  projSumC3Blocks->DrawCopy("hist");
725  projSumC1Block->SetLineColor(4);
726  projSumC1Block->Divide(projSumC);
727  projSumC1Block->DrawCopy("same");
728 
729  projSumC1Block->SetLineStyle(3);
730  projSumC1Block->SetLineColor(6);
731  projSumC1Block->Divide(projSumC3Blocks);
732  projSumC1Block->DrawCopy("same");
733 
734  TLegend *legRatio = new TLegend(0.25,0.30,0.4,0.45);
735  legRatio->AddEntry(projSumC1Block,"re-incl & masked as one big block","l");
736  legRatio->AddEntry(projSumC3Blocks,"re-incl & masked in three blocks","l");
737  legRatio->AddEntry(projSumC1Block,"ratio 1Block/3Blocks","l");
738  legRatio->SetBorderSize(0);
739  legRatio->SetTextSize(0.03);
740  legRatio->Draw("same");
741 
742  //..................................................................
743  // Draw the Amp vs E histogram and the ratio to the masked 2D one
744  //..................................................................
745  cAmpSum2D->Divide(2);
746  cAmpSum2D->cd(1)->SetLogz();
747  SetHisto(Sum2D3BlockMask,"","",0);
748  Sum2D3BlockMask->GetZaxis()->SetRangeUser(10e-8,10);
749  Sum2D3BlockMask->DrawCopy("colz");
750 
751  cAmpSum2D->cd(2);
752  Sum2D3BlockMask->Divide(Sum2DIdeal);
753  SetHisto(Sum2D3BlockMask,"","",0);
754  Sum2D3BlockMask->SetTitle("Amplitude Vs. run / av. amp. vs. run");
755  //Sum2D3BlockMask->GetZaxis()->SetRangeUser(2,20);
756  Sum2D3BlockMask->DrawCopy("colz");
757 
758  //..................................................................
759  TLatex* textA = new TLatex(0.5,0.8,Form("Block over run %i-%i",0,splitRuns1));
760  textA->SetTextSize(0.04);
761  textA->SetTextColor(1);
762  textA->SetNDC();
763  TLatex* textB = new TLatex(0.5,0.8,Form("Block over run %i-%i",splitRuns1,splitRuns2));
764  textB->SetTextSize(0.04);
765  textB->SetTextColor(1);
766  textB->SetNDC();
767  TLatex* textC = new TLatex(0.5,0.8,Form("Block over run %i-%i",splitRuns2,splitRuns3));
768  textC->SetTextSize(0.04);
769  textC->SetTextColor(1);
770  textC->SetNDC();
771  TLatex* textD = new TLatex(0.5,0.8,Form("Block over run %i-%i",splitRuns3,nRunsUsed));
772  textD->SetTextSize(0.04);
773  textD->SetTextColor(1);
774  textD->SetNDC();
775 
776  cAmpSum2D4Blocks->Divide(2,2);
777  cAmpSum2D4Blocks->cd(1)->SetLogz();
778  SetHisto(Sum2D3BlockMaskA,"","",0);
779  Sum2D3BlockMaskA->GetZaxis()->SetRangeUser(10e-8,10);
780  Sum2D3BlockMaskA->DrawCopy("colz");
781  textA->Draw();
782  cAmpSum2D4Blocks->cd(2)->SetLogz();
783  SetHisto(Sum2D3BlockMaskB,"","",0);
784  Sum2D3BlockMaskB->GetZaxis()->SetRangeUser(10e-8,10);
785  Sum2D3BlockMaskB->DrawCopy("colz");
786  textB->Draw();
787  cAmpSum2D4Blocks->cd(3)->SetLogz();
788  SetHisto(Sum2D3BlockMaskC,"","",0);
789  Sum2D3BlockMaskC->GetZaxis()->SetRangeUser(10e-8,10);
790  Sum2D3BlockMaskC->DrawCopy("colz");
791  textC->Draw();
792  cAmpSum2D4Blocks->cd(4)->SetLogz();
793  SetHisto(Sum2D3BlockMaskD,"","",0);
794  Sum2D3BlockMaskD->GetZaxis()->SetRangeUser(10e-8,10);
795  Sum2D3BlockMaskD->DrawCopy("colz");
796  textD->Draw();
797 
798  cAmpSum2D4BlocksRatio->Divide(2,2);
799  cAmpSum2D4BlocksRatio->cd(1)->SetLogz();
800  Sum2D3BlockMaskA->Divide(Sum2DIdeal);
801  SetHisto(Sum2D3BlockMaskA,"","",0);
802  Sum2D3BlockMaskA->SetTitle("Amplitude Vs. run / av. amp. vs. run");
803  Sum2D3BlockMaskA->DrawCopy("colz");
804  textA->Draw();
805  cAmpSum2D4BlocksRatio->cd(2)->SetLogz();
806  Sum2D3BlockMaskB->Divide(Sum2DIdeal);
807  SetHisto(Sum2D3BlockMaskB,"","",0);
808  Sum2D3BlockMaskB->SetTitle("Amplitude Vs. run / av. amp. vs. run");
809  Sum2D3BlockMaskB->DrawCopy("colz");
810  textB->Draw();
811  cAmpSum2D4BlocksRatio->cd(3)->SetLogz();
812  Sum2D3BlockMaskC->Divide(Sum2DIdeal);
813  SetHisto(Sum2D3BlockMaskC,"","",0);
814  Sum2D3BlockMaskC->SetTitle("Amplitude Vs. run / av. amp. vs. run");
815  Sum2D3BlockMaskC->DrawCopy("colz");
816  textC->Draw();
817  cAmpSum2D4BlocksRatio->cd(4)->SetLogz();
818  Sum2D3BlockMaskD->Divide(Sum2DIdeal);
819  SetHisto(Sum2D3BlockMaskD,"","",0);
820  Sum2D3BlockMaskD->SetTitle("Amplitude Vs. run / av. amp. vs. run");
821  Sum2D3BlockMaskD->DrawCopy("colz");
822  textD->Draw();
823 
824  //..................................................................
825  //..Plot the cleaned up histogram again
826  //..................................................................
827  cFlagSumCleanedI->cd()->SetLeftMargin(0.05);
828  cFlagSumCleanedI->cd()->SetRightMargin(0.05);
829  cFlagSumCleanedI->cd()->SetBottomMargin(0.05);
830  cFlagSumCleanedI->cd()->SetTopMargin(0.02);
831  SetHisto(hFlagvsRun[2],"dead+bad cell ID (cleaned) pt.1","Run No.",1);
832  hFlagvsRun[2]->GetXaxis()->SetRangeUser(0,8837);
833  hFlagvsRun[2]->SetFillColor(histCol);
834  hFlagvsRun[2]->DrawCopy("BOX");
835  cFlagSumCleanedII->cd()->SetLeftMargin(0.05);
836  cFlagSumCleanedII->cd()->SetRightMargin(0.05);
837  cFlagSumCleanedII->cd()->SetBottomMargin(0.05);
838  cFlagSumCleanedII->cd()->SetTopMargin(0.02);
839  SetHisto(hFlagvsRun[2],"dead+bad cell ID (cleaned) pt.2","Run No.",1);
840  hFlagvsRun[2]->GetXaxis()->SetRangeUser(8837,17674);
841  hFlagvsRun[2]->DrawCopy("BOX");
842 
843  //..................................................................
844  // Draw summary histogram with dead and bad cells vs run
845  //..................................................................
846  badCellsVsRunC =hFlagvsRun[1]->ProjectionY("badCellsVsRunC");
847  cellSummaryCan->cd(1);
848  badCellsVsRunC->SetLineColor(kGreen-9);
849  badCellsVsRunC->SetLineWidth(2);
850  badCellsVsRunC->SetFillColorAlpha(10,0);
851  badCellsVsRunC->DrawCopy("same");
852 
853  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
854  //..compress the histogram for visibility since
855  //..90% of the space is filled by empty good cells
856  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
857  cout<<endl;
858  TH2F* CompressedClean = CompressHistogram(hFlagvsRun[2],noOfCells , nBadCells,RunIdVec);
859 
860  cFlagSumCompCleanI->cd()->SetLeftMargin(0.05);
861  cFlagSumCompCleanI->cd()->SetRightMargin(0.05);
862  cFlagSumCompCleanI->cd()->SetBottomMargin(0.05);
863  cFlagSumCompCleanI->cd()->SetTopMargin(0.02);
864  SetHisto(CompressedClean,"certain dead+bad cell (cleaned) pt.1","Run No.",1);
865  CompressedClean->GetXaxis()->SetRangeUser(0,nBadCells/2);
866  CompressedClean->SetFillColor(histCol);
867  CompressedClean->DrawCopy("BOX");
868  cFlagSumCompCleanII->cd()->SetLeftMargin(0.05);
869  cFlagSumCompCleanII->cd()->SetRightMargin(0.05);
870  cFlagSumCompCleanII->cd()->SetBottomMargin(0.05);
871  cFlagSumCompCleanII->cd()->SetTopMargin(0.02);
872  SetHisto(CompressedClean,"certain dead+bad cell (cleaned) pt.2","Run No.",1);
873  CompressedClean->GetXaxis()->SetRangeUser(nBadCells/2,nBadCells+2);
874  CompressedClean->DrawCopy("BOX");
875 
876  //..................................................................
877  //..build and draw a new 2D histogram after all the cleaning/resetting was done
878  //..................................................................
879  for(Int_t ic = 0; ic < noOfCells; ic++)
880  {
881  TH1D *htmpCell = hFlagvsRun[2]->ProjectionY(TString::Format("hIDProj_cell%d", ic), ic+1, ic+1);
882  fracRun = 0, sumRun = 0;
883  for(Int_t ir = 0; ir < nRunsUsed ; ir++)
884  {
885  sumRun += htmpCell->GetBinContent(ir+1);
886  }
887  fracRun = sumRun/(Double_t)(nRunsUsed);
888  if(fracRun>0)
889  {
890  Int_t cellColumn=0, cellRow=0;
891  Int_t cellColumnAbs=0, cellRowAbs=0;
892  Int_t trash = 0 ;
893  fCaloUtils->GetModuleNumberCellIndexesAbsCaloMap(ic,0,cellColumn,cellRow,trash,cellColumnAbs,cellRowAbs);
894  hFlagNewClean->Fill(cellColumnAbs, cellRowAbs, fracRun*100);
895  }
896  }
897  //..2D fraction
898  cFlagNew->Divide(2);
899  cFlagNew->cd(1);
900  SetHisto(hFlagNew,"","",0);
901  hFlagNew->Draw("colz");
902  cFlagNew->cd(2);
903  SetHisto(hFlagNewClean,"","",0);
904  hFlagNewClean->Draw("colz");
905 
906  //..................................................................
907  // Print out an overview of this run-by-run analysis
908  //..................................................................
909  Int_t bcBolckSum=0;
910 
911  TH1D *htmpCellSum = hFlagvsRun[2]->ProjectionX("countSum");
912  for(Int_t ic = 0; ic < noOfCells; ic++)
913  {
914  if(htmpCellSum->GetBinContent(ic+1)>0)bcBolckSum++;
915  }
916 
917  cout<<"...................................."<<endl;
918  cout<<"Summary: "<<nBadCells<<" bad cells of "<<noOfCells<<" total cells and "<<nRunsUsed<<" runs"<<endl;
919  cout<<"o All bad cells: "<<nBadCells<<endl;
920  cout<<"o low fraction bad cells: "<<cellVector.size()<<endl;
921  cout<<"o bad cells after reinclusion: "<<bcBolckSum<<endl;
922  cout<<"o rescued cells: "<<nBadCells-bcBolckSum<<endl;
923  if(cellVector.size()!=0)cout<<"o These are: "<<100*(nBadCells-bcBolckSum)/cellVector.size()<<"% of low frac cells"<<endl;
924  cout<<"...................................."<<endl;
925 
926  //_______________________________________________________________________
927  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
928  //. . Save histograms to file
929  //. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
930  //_______________________________________________________________________
931  TString fileName = Form("%s/RunByRunSummary%i/%s_Results.root",analysisOutput.Data(),runsUsed,listName.Data());
932  TFile* rootFile = new TFile(fileName,"recreate");
933 
934  for(Int_t ic = 0; ic<nCv; ic++)
935  {
936  rootFile->WriteObject(cBad [ic],cBad [ic]->GetName());
937  rootFile->WriteObject(cGood[ic],cGood[ic]->GetName());
938  rootFile->WriteObject(cDead[ic],cDead[ic]->GetName());
939  rootFile->WriteObject(cAmp [ic],cAmp [ic]->GetName());
940  }
941  rootFile->WriteObject(cellSummaryCan,cellSummaryCan->GetName());
942  rootFile->WriteObject(cAmpSum,cAmpSum->GetName());
943  rootFile->WriteObject(cFlagDeadBadI,cFlagDeadBadI->GetName());
944  rootFile->WriteObject(cFlagDeadBadII,cFlagDeadBadII->GetName());
945  rootFile->WriteObject(cFlagSumI,cFlagSumII->GetName());
946  rootFile->WriteObject(cFlagSumII,cFlagSumII->GetName());
947  rootFile->WriteObject(cFlagSumCleanedI,cFlagSumCleanedI->GetName());
948  rootFile->WriteObject(cFlagSumCleanedII,cFlagSumCleanedII->GetName());
949  rootFile->WriteObject(cFlagSumCompAllI,cFlagSumCompAllI->GetName());
950  rootFile->WriteObject(cFlagSumCompAllII,cFlagSumCompAllII->GetName());
951  rootFile->WriteObject(cFlagSumCompCleanI,cFlagSumCompCleanI->GetName());
952  rootFile->WriteObject(cFlagSumCompCleanII,cFlagSumCompCleanII->GetName());
953  rootFile->WriteObject(cFlagNew,cFlagNew->GetName());
954  rootFile->WriteObject(cAmpSum2D,cAmpSum2D->GetName());
955  rootFile->WriteObject(cAmpSum2D4Blocks,cAmpSum2D4Blocks->GetName());
956  rootFile->WriteObject(cAmpSum2D4BlocksRatio,cAmpSum2D4BlocksRatio->GetName());
957  //..histograms
958  rootFile->WriteObject(hFlagNew,hFlagNew->GetName());
959  rootFile->WriteObject(CompressedAll,CompressedAll->GetName());
960  rootFile->WriteObject(hFlagvsRun[2],hFlagvsRun[2]->GetName()); //..bad/dead vs. run number cleaned for low frac runs
961  rootFile->WriteObject(CompressedClean,CompressedClean->GetName()); //..bad/dead vs. run number cleaned&compressed
962  rootFile->WriteObject(projSum,projSum->GetName());
963  rootFile->WriteObject(projSumC,projSumC->GetName());
964  rootFile->WriteObject(projSumC3Blocks,projSumC3Blocks->GetName());
965  rootFile->WriteObject(nEventsVsRuns,nEventsVsRuns->GetName());
966  for(Int_t ir = 0; ir < nRunsUsed ; ir++)
967  {
968  rootFile->WriteObject(ampIDCl[ir],ampIDCl[ir]->GetName()); //..single run masked (original bad ch. analysis)
969  rootFile->WriteObject(ampID[ir],ampID[ir]->GetName()); //..original distribution - unmasked
970  rootFile->WriteObject(ampIDDelete[ir],ampIDDelete[ir]->GetName());
971  }
972 
973 
974  //..plot the canvases of cells into a .pdf file
975  TString badCanvasName =Form("%s/RunByRunSummary%i/%s_BadCells.pdf", analysisOutput.Data(),nRunsUsed,listName.Data());
976  TString goodCanvasName=Form("%s/RunByRunSummary%i/%s_GoodCells.pdf", analysisOutput.Data(),nRunsUsed,listName.Data());
977  TString deadCanvasName=Form("%s/RunByRunSummary%i/%s_DeadCells.pdf", analysisOutput.Data(),nRunsUsed,listName.Data());
978  TString ampCanvasName =Form("%s/RunByRunSummary%i/%s_Amplitudes.pdf", analysisOutput.Data(),nRunsUsed,listName.Data());
979  TString summaryPDF =Form("%s/RunByRunSummary%i/%s_FigureCollection.pdf", analysisOutput.Data(),nRunsUsed,listName.Data());
980 
981  for(Int_t ic = 0; ic<nCv; ic++)
982  {
983  if(ic==0 && nCv>1)
984  {
985  //..first pad
986  cBad [ic] ->Print(Form("%s(",badCanvasName.Data()));
987  cGood[ic] ->Print(Form("%s(",goodCanvasName.Data()));
988  cDead[ic] ->Print(Form("%s(",deadCanvasName.Data()));
989  cAmp [ic] ->Print(Form("%s(",ampCanvasName.Data()));
990  }
991  else if(ic==(nCv-1) && nCv>1)
992  {
993  //..last pad
994  cBad [ic] ->Print(Form("%s)",badCanvasName.Data()));
995  cGood[ic] ->Print(Form("%s)",goodCanvasName.Data()));
996  cDead[ic] ->Print(Form("%s)",deadCanvasName.Data()));
997  cAmp [ic] ->Print(Form("%s)",ampCanvasName.Data()));
998  }
999  else
1000  {
1001  //..all pads in between
1002  cBad [ic] ->Print(Form("%s",badCanvasName.Data()));
1003  cGood[ic] ->Print(Form("%s",goodCanvasName.Data()));
1004  cDead[ic] ->Print(Form("%s",deadCanvasName.Data()));
1005  cAmp [ic] ->Print(Form("%s",ampCanvasName.Data()));
1006  }
1007  }
1008 
1009  //..Add figures to the summary canvas
1010  cellSummaryCan ->Print(Form("%s(",summaryPDF.Data()));
1011  cellSummaryCan2 ->Print(Form("%s",summaryPDF.Data()));
1012  cAmpSum ->Print(Form("%s",summaryPDF.Data()));
1013  cAmpSum2D ->Print(Form("%s",summaryPDF.Data()));
1014  cAmpSum2D4Blocks ->Print(Form("%s",summaryPDF.Data()));
1015  cFlagNew ->Print(Form("%s",summaryPDF.Data()));
1016  cFlagDeadBadI ->Print(Form("%s",summaryPDF.Data()));
1017  cFlagDeadBadII ->Print(Form("%s",summaryPDF.Data()));
1018  cFlagSumI ->Print(Form("%s",summaryPDF.Data()));
1019  cFlagSumII ->Print(Form("%s",summaryPDF.Data()));
1020  cFlagSumCleanedI ->Print(Form("%s",summaryPDF.Data()));
1021  cFlagSumCleanedII->Print(Form("%s",summaryPDF.Data()));
1022  cFlagSumCompAllI ->Print(Form("%s",summaryPDF.Data()));
1023  cFlagSumCompAllII->Print(Form("%s",summaryPDF.Data()));
1024  cFlagSumCompCleanI->Print(Form("%s",summaryPDF.Data()));
1025  cFlagSumCompCleanII->Print(Form("%s)",summaryPDF.Data()));
1026 
1027 }
1031 //________________________________________________________________________
1032 void GetBestPeriodSplitting(TString period = "LHC15o", Int_t train = 771,Int_t Nruns=105, Int_t noOfSplits=4)
1033 {
1034  if(noOfSplits>4)cout<<"Error: so far only implemented for 1-4 splits"<<endl;
1035 
1036  gStyle->SetOptTitle(0);
1037  gStyle->SetOptStat(0);
1038  //gStyle->SetPalette(53); //standard is 1
1039  gStyle->SetCanvasColor(10);
1040  TGaxis::SetMaxDigits(4);
1041  gStyle->SetPadTopMargin(0.07);//0.05
1042  gStyle->SetPadBottomMargin(0.18);//0.15
1043  gStyle->SetPadRightMargin(0.04);
1044  gStyle->SetPadLeftMargin(0.06);
1045  gStyle->SetFrameFillColor(10);
1046  gStyle->SetLabelSize(0.05,"X");
1047  gStyle->SetLabelSize(0.05,"Y");
1048  gStyle->SetTitleSize(5.0,"X");
1049  gStyle->SetTitleSize(5.0,"Y");
1050  gEnv->SetValue("Canvas.ShowEventStatus",1); //shows the status bar in the canvas
1051 
1052  //.......................................
1053  //..Settings
1054  //.......................................
1055  //TString runList = "GloballyGood";
1056  TString runList = "GloballyGood10";
1057  Int_t runNumber=245145;
1058  Bool_t weightByNevt=1; //..weight the run period splitting by the number of events in the run
1059 
1060 
1061  //.......................................
1062  //..Get the Number of cells
1063  //.......................................
1064  AliCalorimeterUtils *fCaloUtils = new AliCalorimeterUtils();
1065  //..Create a dummy event for the CaloUtils
1066  AliAODEvent* aod = new AliAODEvent();
1067  fCaloUtils->SetRunNumber(runNumber);
1068  fCaloUtils->AccessGeometry(aod);
1069  Int_t noOfCells=fCaloUtils->GetEMCALGeometry()->GetNCells(); //..Very important number, never change after that point!
1070 
1071  //.......................................
1072  //..Get run-by-run analysis output
1073  //.......................................
1074  TString fileName = Form("AnalysisOutput/%s/Train_%i/RunByRunSummary%i/%s_Results.root",period.Data(),train,Nruns,runList.Data());
1075 
1076  cout<<"Open root file: "<<fileName<<endl;
1077  TFile *f = TFile::Open(fileName);
1078  if(!f)
1079  {
1080  cout<<"Couldn't open/find .root file: "<<fileName<<endl;
1081  }
1082  //..Get the histograms
1083  TH2F *hbadAndDeadvsRun = (TH2F*)f->Get("hFlag3vsRun_Comp");
1084  TH2F *hbadAndDeadvsRunw = (TH2F*)hbadAndDeadvsRun->Clone("hbadAndDeadvsRunWeight");
1085  if(!hbadAndDeadvsRun)cout<<"couldn't find histogram - hFlag3vsRun_Comp"<<endl;
1086  hbadAndDeadvsRun->GetXaxis()->UnZoom();
1087  hbadAndDeadvsRunw->GetXaxis()->UnZoom();
1088 
1089  TH1D* hEventsPerRun = (TH1D*)f->Get("nEventVsRun");
1090  if(!hEventsPerRun)cout<<"couldn't find histogram - nEventVsRun"<<endl;
1091 
1092  //TH1D *hEventsPerRunHI = (TH1D)hEventsPerRun->Clone("hEventsPerRunHI");
1093  // 2DPlot
1094  // flag vs run
1095 
1096  //.......................................
1097  //..Prepare the histogram for the splitting analysis
1098  //.......................................
1099  if(weightByNevt==1)
1100  {
1101  //..weight bad cells by numbers of events
1102  for(Int_t icell = 0; icell < noOfCells ; icell++)
1103  {
1104  for(Int_t iRun = 0; iRun < Nruns ; iRun++)
1105  {
1106  if(hbadAndDeadvsRun->GetBinContent(icell+1,iRun+1)==1)
1107  {
1108  hbadAndDeadvsRunw->SetBinContent(icell+1,iRun+1,hEventsPerRun->GetBinContent(iRun+1));
1109  }
1110  }
1111  }
1112  }
1113  //..Draw the histogram
1114  TCanvas *canEvt= new TCanvas("canEvt", "canEvt", 500, 500);
1115  canEvt->cd()->SetLeftMargin(0.08);
1116  SetHisto(hEventsPerRun,"Run","No of events",0);
1117  //hEventsPerRun->GetYaxis()->SetTitleOffset(0.35);
1118  hEventsPerRun->DrawCopy("hist"); //box
1119 
1120  TCanvas *can1= new TCanvas("compressedIDs1", "compressed cell ID's A)", 1600, 1000);
1121  can1->cd()->SetLeftMargin(0.05);
1122  can1->cd()->SetRightMargin(0.05);
1123  can1->cd()->SetBottomMargin(0.06);
1124  can1->cd()->SetTopMargin(0.02);
1125  SetHisto(hbadAndDeadvsRun,"","Run in List",1);
1126  hbadAndDeadvsRun->GetYaxis()->SetTitleOffset(0.35);
1127  hbadAndDeadvsRun->GetXaxis()->SetRangeUser(0,2300);
1128  hbadAndDeadvsRun->DrawCopy("colz"); //box
1129  TCanvas *can2= new TCanvas("compressedIDs2", "compressed cell ID's B)", 1600, 1000);
1130  can2->cd()->SetLeftMargin(0.05);
1131  can2->cd()->SetRightMargin(0.05);
1132  can2->cd()->SetBottomMargin(0.06);
1133  can2->cd()->SetTopMargin(0.02);
1134  SetHisto(hbadAndDeadvsRunw,"","Run in List",1);
1135  hbadAndDeadvsRunw->GetYaxis()->SetTitleOffset(0.35);
1136  hbadAndDeadvsRunw->GetXaxis()->SetRangeUser(0,2300);
1137  hbadAndDeadvsRunw->DrawCopy("colz");
1138 
1139  //.......................................
1140  //..Start analysis for getting the best possible splitting
1141  //.......................................
1142  //..Analyze the histogram
1143  //..split into three blocks and see what performs better
1144  Int_t splitRun1=0;
1145  Int_t splitRun2=0;
1146  Int_t splitRun3=0;
1147  Int_t splitRun1w=0;
1148  Int_t splitRun2w=0;
1149  Int_t splitRun3w=0;
1150  Int_t endBlock2;
1151  Int_t endBlock3;
1152  Double_t totalCellsBadRun=0;
1153  Double_t totalCellsBadEvt=0;
1154  Double_t nCellRunsBlock1=0;
1155  Double_t nCellRunsBlock2=0;
1156  Double_t nCellRunsBlock3=0;
1157  Double_t nCellRunsBlock4=0;
1158  Double_t nCellEvtBlock1=0;
1159  Double_t nCellEvtBlock2=0;
1160  Double_t nCellEvtBlock3=0;
1161  Double_t nCellEvtBlock4=0;
1162 
1163  Int_t sumRunBlockTotal=0;
1164  Int_t nBlockTotal=0;
1165  TH1D *hOneBigBlock = hbadAndDeadvsRunw->ProjectionX(TString::Format("%s_projSum",hbadAndDeadvsRunw->GetName()),0,Nruns);
1166 
1167  for(Int_t iRun=1; iRun<=Nruns; iRun++)
1168  {
1169  cout<<"Round "<<iRun<<" of "<<Nruns<<endl;
1170 
1171  if(noOfSplits<3)
1172  {
1173  endBlock2=Nruns-1;
1174  }
1175  else
1176  {
1177  endBlock2=iRun+1;
1178  }
1179  for(Int_t iRun2=endBlock2; iRun2<=Nruns; iRun2++)
1180  {
1181  if(noOfSplits<4)
1182  {
1183  endBlock3=Nruns-1;
1184  }
1185  else
1186  {
1187  endBlock3=iRun2+1;
1188  }
1189 
1190  for(Int_t iRun3=endBlock3; iRun3<=Nruns; iRun3++)
1191  {
1192  hbadAndDeadvsRun ->GetXaxis()->UnZoom();
1193  hbadAndDeadvsRunw->GetXaxis()->UnZoom();
1194  TH1D *htmpCell1;
1195  TH1D *htmpCell2;
1196  TH1D *htmpCell3;
1197  TH1D *htmpCell4;
1198 
1199  if(noOfSplits<3)iRun2=Nruns;
1200  if(noOfSplits<4)iRun3=Nruns;
1201 
1202  if(weightByNevt==1)
1203  {
1204  htmpCell1 = hbadAndDeadvsRunw->ProjectionX(TString::Format("%s_proj1",hbadAndDeadvsRunw->GetName()),0,iRun);
1205  htmpCell2 = hbadAndDeadvsRunw->ProjectionX(TString::Format("%s_proj2",hbadAndDeadvsRunw->GetName()),iRun+1,iRun2);
1206  if(noOfSplits>2)htmpCell3 = hbadAndDeadvsRunw->ProjectionX(TString::Format("%s_proj3",hbadAndDeadvsRunw->GetName()),iRun2+1,iRun3);
1207  if(noOfSplits>3)htmpCell4 = hbadAndDeadvsRunw->ProjectionX(TString::Format("%s_proj4",hbadAndDeadvsRunw->GetName()),iRun3+1,Nruns);
1208  }
1209  else
1210  {
1211  htmpCell1 = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj1",hbadAndDeadvsRun->GetName()),0,iRun);
1212  htmpCell2 = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj2",hbadAndDeadvsRun->GetName()),iRun+1,iRun2);
1213  if(noOfSplits>2)htmpCell3 = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj3",hbadAndDeadvsRun->GetName()),iRun2+1,iRun3);
1214  if(noOfSplits>3)htmpCell4 = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj4",hbadAndDeadvsRun->GetName()),iRun3+1,Nruns);
1215  }
1216 
1217  Double_t nEvtBlock1 = hEventsPerRun->Integral(0,iRun);
1218  Double_t nEvtBlock2 = hEventsPerRun->Integral(iRun+1,iRun2);
1219  Double_t nEvtBlock3 = hEventsPerRun->Integral(iRun2+1,iRun3);
1220  Double_t nEvtBlock4 = hEventsPerRun->Integral(iRun3+1,Nruns);
1221 
1222  sumRunBlockTotal=0;
1223  Int_t sumRunBlock1=0;
1224  Int_t sumRunBlock2=0;
1225  Int_t sumRunBlock3=0;
1226  Int_t sumRunBlock4=0;
1227  Int_t nBlock1=0;
1228  Int_t nBlock2=0;
1229  Int_t nBlock3=0;
1230  Int_t nBlock4=0;
1231  nBlockTotal=0;
1232 
1233  for(Int_t icell = 0; icell < htmpCell1->GetNbinsX(); icell++)
1234  {
1235  sumRunBlockTotal = hOneBigBlock->GetBinContent(icell+1);
1236  sumRunBlock1 = htmpCell1->GetBinContent(icell+1);
1237  sumRunBlock2 = htmpCell2->GetBinContent(icell+1);
1238  if(noOfSplits>2)sumRunBlock3 = htmpCell3->GetBinContent(icell+1);
1239  if(noOfSplits>3)sumRunBlock4 = htmpCell4->GetBinContent(icell+1);
1240 
1241  if(sumRunBlock1>0)nBlock1++;
1242  if(sumRunBlock2>0)nBlock2++;
1243  if(sumRunBlock3>0)nBlock3++;
1244  if(sumRunBlock4>0)nBlock4++;
1245  if(sumRunBlockTotal>0)nBlockTotal++;
1246  }
1247  //..bad cells in block
1248  nCellRunsBlock1=nBlock1*iRun;
1249  nCellRunsBlock2=nBlock2*(iRun2-iRun+1);
1250  nCellRunsBlock3=nBlock3*(iRun3-iRun2+1); //..is 0 for 2block splitting
1251  nCellRunsBlock4=nBlock4*(Nruns-iRun3+1); //..is 0 for 3block splitting
1252 
1253  //..bad cells in block weightet by nEvents in block
1254  nCellEvtBlock1 =nBlock1*nEvtBlock1;
1255  nCellEvtBlock2 =nBlock2*nEvtBlock2;
1256  nCellEvtBlock3 =nBlock3*nEvtBlock3;
1257  nCellEvtBlock4 =nBlock4*nEvtBlock4;
1258 
1259  //..not weighted by nuber of events in run
1260  if(totalCellsBadRun==0 || (nCellRunsBlock1+nCellRunsBlock2+nCellRunsBlock3+nCellRunsBlock4)<totalCellsBadRun)
1261  {
1262  totalCellsBadRun=nCellRunsBlock1+nCellRunsBlock2+nCellRunsBlock3+nCellRunsBlock4;
1263  splitRun1=iRun;
1264  splitRun2=iRun2;
1265  splitRun3=iRun3;
1266  }
1267  //..weighted by nuber of events in run
1268  if(totalCellsBadEvt==0 || (nCellEvtBlock1+nCellEvtBlock2+nCellEvtBlock3+nCellEvtBlock4)<totalCellsBadEvt)
1269  {
1270  totalCellsBadEvt=nCellEvtBlock1+nCellEvtBlock2+nCellEvtBlock3+nCellEvtBlock4;
1271  splitRun1w=iRun;
1272  splitRun2w=iRun2;
1273  splitRun3w=iRun3;
1274  }
1275  }
1276  }
1277  }
1278  hbadAndDeadvsRun->GetXaxis()->UnZoom();
1279  TH1D *htmpCell1p = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj1",hbadAndDeadvsRun->GetName()),0,splitRun1);
1280  TH1D *htmpCell2p = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj2",hbadAndDeadvsRun->GetName()),splitRun1+1,splitRun2);
1281  TH1D *htmpCell3p = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj3",hbadAndDeadvsRun->GetName()),splitRun2+1,splitRun3);
1282  TH1D *htmpCell4p = hbadAndDeadvsRun->ProjectionX(TString::Format("%s_proj4",hbadAndDeadvsRun->GetName()),splitRun3+1,Nruns);
1283 
1284  TCanvas *canSplit= new TCanvas("canSplit", "Split compressed cell ID's", 1600, 500);
1285  canSplit->Divide(2,2);
1286  canSplit->cd(1);
1287  SetHisto(htmpCell1p,"","nruns bad",1);
1288  htmpCell1p->GetYaxis()->SetTitleOffset(0.35);
1289  htmpCell1p->DrawCopy("hist");
1290  canSplit->cd(2);
1291  SetHisto(htmpCell2p,"","nruns bad",1);
1292  htmpCell2p->GetYaxis()->SetTitleOffset(0.35);
1293  htmpCell2p->DrawCopy("hist");
1294  canSplit->cd(3);
1295  SetHisto(htmpCell3p,"","nruns bad",1);
1296  htmpCell3p->GetYaxis()->SetTitleOffset(0.35);
1297  htmpCell3p->DrawCopy("hist");
1298  canSplit->cd(4);
1299  SetHisto(htmpCell4p,"","nruns bad",1);
1300  htmpCell4p->GetYaxis()->SetTitleOffset(0.35);
1301  htmpCell4p->DrawCopy("hist");
1302 
1303  //..Draw the split lines into the canvas
1304  can1->cd();
1305  PlotHorLineRange(splitRun1w,0,2000,9);
1306  PlotHorLineRange(splitRun2w,0,2000,9);
1307  PlotHorLineRange(splitRun3w,0,2000,9);
1308  can2->cd();
1309  PlotHorLineRange(splitRun1w,0,2000,1);
1310  PlotHorLineRange(splitRun2w,0,2000,1);
1311  PlotHorLineRange(splitRun3w,0,2000,1);
1312 
1313 
1314  cout<<"Best results are achieved by splitting into:"<<endl;
1315  cout<<"- - - - - - - - GENERAL - - - - - - - - -"<<endl;
1316  cout<<"Number of runs: "<<Nruns<<endl;
1317  cout<<"Number events: "<<hEventsPerRun->Integral(0,Nruns)<<endl;
1318  cout<<"Bad cells if masked as 1 block: "<<nBlockTotal<<endl;
1319  cout<<"Bad cells * runs: "<<nBlockTotal*Nruns<<endl;
1320  cout<<"Bad cells * evt: "<<nBlockTotal*hEventsPerRun->Integral(0,Nruns)<<endl;
1321  cout<<"- - - - - - - - UNWEIGHTED Splitting - - - - - - - - -"<<endl;
1322  cout<<"Run: 0-"<<splitRun1<<endl;
1323  cout<<"Run: "<<splitRun1+1<<"-"<<splitRun2<<endl;
1324  if(noOfSplits>2)cout<<"Run: "<<splitRun2+1<<"-"<<splitRun3<<endl;
1325  if(noOfSplits>3)cout<<"Run: "<<splitRun3+1<<"-"<<Nruns<<endl;
1326  cout<<"Number of bad cells*runs ="<<totalCellsBadRun<<endl;
1327  cout<<"- - - - - - - - WEIGHTED Splitting - - - - - - - - -"<<endl;
1328  cout<<"Run: 0-"<<splitRun1w<<endl;
1329  cout<<"Run: "<<splitRun1w+1<<"-"<<splitRun2w<<endl;
1330  if(noOfSplits>2)cout<<"Run: "<<splitRun2w+1<<"-"<<splitRun3w<<endl;
1331  if(noOfSplits>3)cout<<"Run: "<<splitRun3w+1<<"-"<<Nruns<<endl;
1332  cout<<"Number of bad cells*events ="<<totalCellsBadEvt<<endl;
1333 
1334  cout<<" events block1 : "<<hEventsPerRun->Integral(0,splitRun1)<<endl;
1335  cout<<" events block2 : "<<hEventsPerRun->Integral(splitRun1+1,splitRun2)<<endl;
1336  cout<<" events block3 : "<<hEventsPerRun->Integral(splitRun2+1,splitRun3)<<endl;
1337  cout<<" events block4 : "<<hEventsPerRun->Integral(splitRun3+1,Nruns)<<endl;
1338 
1339  //..With this splitting produce bad map lists and show how the masked blocks look like
1340  //
1341 }
1342 //
1343 // Compares masked amplidudes from two different versions of masking cells
1344 // Version A sum all runs in a certrain range up and analyse the channels all together
1345 // Version B do a run-by-run analsis and check wheather channels are masked in almost all runs and maks them then entirely
1346 //________________________________________________________________________
1347 void CompareTwoBCstrategies(TString period="LHC15n",Int_t trainNo=603,Int_t version=5)
1348 {
1349  //..this was originally used or LHC15o
1350  gROOT->ProcessLine("gErrorIgnoreLevel = kWarning;"); //..to supress a lot of standard output
1351  gStyle->SetOptStat(0); //..Do not plot stat boxes
1352  gStyle->SetPadLeftMargin(0.13);
1353  gStyle->SetPadRightMargin(0.1);
1354  gStyle->SetPadBottomMargin(0.13);
1355  gStyle->SetPadTopMargin(0.02);
1356 
1357  Int_t noOfCells=17674; //
1358  const Int_t nRunsUsed=105;
1359  //const Int_t nRunsUsed=10;
1360  //..select runs after which a new bad map is built
1361  Int_t splitRuns1=34; //run bock is inclusive of this run
1362  Int_t splitRuns2=66; //run bock is inclusive of this run
1363  Int_t splitRuns3=74; //run bock is inclusive of this run
1364  Int_t nBadCellMerged[4]={noOfCells,noOfCells,noOfCells,noOfCells};
1365  Int_t nBadCellRbR[4] ={noOfCells,noOfCells,noOfCells,noOfCells};
1366 
1367  //..............................................
1368  //..manually disable cells
1369  std::vector<Int_t> badcellsBlock1;
1370  std::vector<Int_t> badcellsBlock2;
1371  std::vector<Int_t> badcellsBlock3;
1372  std::vector<Int_t> badcellsBlock4;
1373 
1374  badcellsBlock1.insert(badcellsBlock1.end(),{14655,14622,14640,14728,14726});
1375 
1376  badcellsBlock2.insert(badcellsBlock2.end(),{6644,6655,10140,12036,12037,12038,12039,12040,12041,12926,13067,13066,13125});
1377  badcellsBlock2.insert(badcellsBlock2.end(),{13133,13483,13971,13978,14116,14118,14122,14411,14593,14599,14600,14606,14699});
1378  badcellsBlock2.insert(badcellsBlock2.end(),{14728,15158,15462,16309});
1379 
1380  badcellsBlock3.insert(badcellsBlock3.end(),{292,294,297,301,13483, 13975, 14116, 14320, 14326});
1381 
1382  badcellsBlock4.insert(badcellsBlock4.end(),{3472,3473,3474,3475,3476,3477,3478,3479,3480,3481,3482,3483,3484,3485,3486,3487});
1383  badcellsBlock4.insert(badcellsBlock4.end(),{3520,3521,3522,3523,3524,3525,3526,3527,3528,3529,3530,3531,3532,3533,3534,3535});
1384  badcellsBlock4.insert(badcellsBlock4.end(),{3665,3666,3667,3668,3669,3670,3671,3672,3673,3674,3675,3676,3677,3678,3679});
1385  badcellsBlock4.insert(badcellsBlock4.end(),{3712,3713,3714,3715,3716,3717,3718,3719,3720,3721,3722,3723,3724,3725,3726,3727});
1386  badcellsBlock4.insert(badcellsBlock4.end(),{8848,8849,8850,8851,8852,8853,8854,8855,8856,8857,8858,8859,8860,8861,8862,8863});
1387  badcellsBlock4.insert(badcellsBlock4.end(),{8896,8897,8898,8899,8900,8901,8902,8903,8904,8905,89106,8907,8908,8909,8910});
1388  badcellsBlock4.insert(badcellsBlock4.end(),{11906,11907,11908,11909,11910,11911,11912,11913,11914,11915,11916,11917,11918,11919});
1389  badcellsBlock4.insert(badcellsBlock4.end(),{12034,12035,12036,12037,12038,12039,12040,12041,12042,12043,12044,12045,13469,13483,16427,16430});
1390 
1391  std::vector<Int_t> vOnlyMaskedInMergedA;
1392  std::vector<Int_t> vOnlyMaskedInRunbRunA;
1393  std::vector<Int_t> vOnlyMaskedInMergedB;
1394  std::vector<Int_t> vOnlyMaskedInRunbRunB;
1395  std::vector<Int_t> vOnlyMaskedInMergedC;
1396  std::vector<Int_t> vOnlyMaskedInRunbRunC;
1397  std::vector<Int_t> vOnlyMaskedInMergedD;
1398  std::vector<Int_t> vOnlyMaskedInRunbRunD;
1399 
1400  cout<<"run splitting: "<<endl;
1401  cout<<0<<"-"<<splitRuns1<<" -> "<<splitRuns1<<" runs"<<endl;
1402  cout<<splitRuns1+1<<"-"<<splitRuns2<<" -> "<<splitRuns2-splitRuns1<<" runs"<<endl;
1403  cout<<splitRuns2+1<<"-"<<splitRuns3<<" -> "<<splitRuns3-splitRuns2<<" runs"<<endl;
1404  cout<<splitRuns3+1<<"-"<<nRunsUsed <<" -> "<<nRunsUsed-splitRuns3 <<" runs"<<endl;
1405 
1406  //......................................................
1407  //..Get the .root file from analyzing runs as 1 block together
1408  //......................................................
1409  cout<<"**Open files with merged runlist analysis: "<<endl;
1410  TString pathA = Form("./AnalysisOutput/%s/Train_%i/Version%i",period.Data(),trainNo,version);
1411  TString rootFileNameA= Form("INT7_Histograms_V%i.root",version);
1412  TFile* outputRootA = TFile::Open(Form("%s/%s",pathA.Data(),rootFileNameA.Data()));
1413  if(!outputRootA)cout<<"File "<<outputRootA->GetName()<<" does not exist"<<endl;
1414  else cout<<"file A: "<<outputRootA->GetName()<<endl;
1415  TString pathB = Form("./AnalysisOutput/%s/Train_%i/Version%i",period.Data(),trainNo,version+1);
1416  TString rootFileNameB= Form("INT7_Histograms_V%i.root",version+1);
1417  TFile* outputRootB = TFile::Open(Form("%s/%s",pathB.Data(),rootFileNameB.Data()));
1418  if(!outputRootB)cout<<"File "<<outputRootB->GetName()<<" does not exist"<<endl;
1419  else cout<<"file B: "<<outputRootB->GetName()<<endl;
1420  TString pathC = Form("./AnalysisOutput/%s/Train_%i/Version%i",period.Data(),trainNo,version+2);
1421  TString rootFileNameC= Form("INT7_Histograms_V%i.root",version+2);
1422  TFile* outputRootC = TFile::Open(Form("%s/%s",pathC.Data(),rootFileNameC.Data()));
1423  if(!outputRootC)cout<<"File "<<outputRootC->GetName()<<" does not exist"<<endl;
1424  else cout<<"file C: "<<outputRootC->GetName()<<endl;
1425  TString pathD = Form("./AnalysisOutput/%s/Train_%i/Version%i",period.Data(),trainNo,version+3);
1426  TString rootFileNameD= Form("INT7_Histograms_V%i.root",version+3);
1427  TFile* outputRootD = TFile::Open(Form("%s/%s",pathD.Data(),rootFileNameD.Data()));
1428  if(!outputRootD)cout<<"File "<<outputRootD->GetName()<<" does not exist"<<endl;
1429  else cout<<"file D: "<<outputRootD->GetName()<<endl;
1430 
1431  //..get the necessary histograms
1432  TH2F* hCellAmplitudeA =(TH2F*)outputRootA->Get("hCellAmplitude");
1433  TH1F* hnEventsA =(TH1F*)outputRootA->Get("hNEvents");
1434  hCellAmplitudeA->Scale(hnEventsA->GetBinContent(1));
1435  TH2F* hCellAmplitudeBlockMaskA=(TH2F*)hCellAmplitudeA->Clone("hCellAmplitudeMask");
1436  TH1F* hCellFlagA =(TH1F*)outputRootA->Get("fhCellFlag");
1437 
1438  TH2F* hCellAmplitudeB =(TH2F*)outputRootB->Get("hCellAmplitude");
1439  TH1F* hnEventsB =(TH1F*)outputRootB->Get("hNEvents");
1440  hCellAmplitudeB->Scale(hnEventsB->GetBinContent(1));
1441  TH2F* hCellAmplitudeBlockMaskB=(TH2F*)hCellAmplitudeB->Clone("hCellAmplitudeMask");
1442  TH1F* hCellFlagB =(TH1F*)outputRootB->Get("fhCellFlag");
1443 
1444  TH2F* hCellAmplitudeC =(TH2F*)outputRootC->Get("hCellAmplitude");
1445  TH1F* hnEventsC =(TH1F*)outputRootC->Get("hNEvents");
1446  hCellAmplitudeC->Scale(hnEventsC->GetBinContent(1));
1447  TH2F* hCellAmplitudeBlockMaskC=(TH2F*)hCellAmplitudeC->Clone("hCellAmplitudeMask");
1448  TH1F* hCellFlagC =(TH1F*)outputRootC->Get("fhCellFlag");
1449 
1450  TH2F* hCellAmplitudeD =(TH2F*)outputRootD->Get("hCellAmplitude");
1451  TH1F* hnEventsD =(TH1F*)outputRootD->Get("hNEvents");
1452  hCellAmplitudeD->Scale(hnEventsD->GetBinContent(1));
1453  TH2F* hCellAmplitudeBlockMaskD=(TH2F*)hCellAmplitudeD->Clone("hCellAmplitudeMask");
1454  TH1F* hCellFlagD =(TH1F*)outputRootD->Get("fhCellFlag");
1455 
1456  //......................................................
1457  //..Get the .root file with run-by-run bad channel mask
1458  //......................................................
1459  cout<<"**Open file with masking based on run-by-run info within a block: "<<endl;
1460  TString pathRbR = Form("./AnalysisOutput/%s/Train_%i/RunByRunSummary105",period.Data(),trainNo);
1461  TString rootFileNameRbR = Form("GloballyGood_Results.root");
1462  TFile* outputRootRbR = TFile::Open(Form("%s/%s",pathRbR .Data(),rootFileNameRbR .Data()));
1463  if(!outputRootRbR )cout<<"File "<<outputRootRbR ->GetName()<<" does not exist"<<endl;
1464  else cout<<"file R-b-R: "<<outputRootRbR ->GetName()<<endl;
1465 
1466  TH2F* BadCellsVsRun =(TH2F*)outputRootRbR ->Get("hFlag3vsRun"); //..that is the original bad map - cleaned and filled up for channels with>80% bad runs
1467  TH1F* hEvtVsRun =(TH1F*)outputRootRbR ->Get("nEventVsRun");
1468  TH2F* AmpVsID[nRunsUsed];
1469  for(Int_t nRun=0;nRun<nRunsUsed;nRun++)
1470  {
1471  AmpVsID[nRun] = (TH2F*)outputRootRbR ->Get(Form("hCellAmplitudeRun%i",nRun));
1472  AmpVsID[nRun]->Scale(hEvtVsRun->GetBinContent(nRun+1));
1473  }
1474  //..build the 3/4 blocks
1475  TH2F* AmpVsIDrBrBlockA = (TH2F*)AmpVsID[0]->Clone("AmpVsIDrBrBlockA");
1476  TH2F* AmpVsIDrBrBlockB = (TH2F*)AmpVsID[0]->Clone("AmpVsIDrBrBlockB");
1477  TH2F* AmpVsIDrBrBlockC = (TH2F*)AmpVsID[0]->Clone("AmpVsIDrBrBlockC");
1478  TH2F* AmpVsIDrBrBlockD = (TH2F*)AmpVsID[0]->Clone("AmpVsIDrBrBlockD");
1479 
1480  //..use only the histogram properties not the content
1481  AmpVsIDrBrBlockA->Reset();
1482  AmpVsIDrBrBlockB->Reset();
1483  AmpVsIDrBrBlockC->Reset();
1484  AmpVsIDrBrBlockD->Reset();
1485 
1486  for(Int_t nRun=0;nRun<nRunsUsed;nRun++)
1487  {
1488  if(nRun<=splitRuns1) AmpVsIDrBrBlockA->Add(AmpVsID[nRun]);
1489  if(nRun>splitRuns1 && nRun<=splitRuns2)AmpVsIDrBrBlockB->Add(AmpVsID[nRun]);
1490  if(nRun>splitRuns2 && nRun<=splitRuns3)AmpVsIDrBrBlockC->Add(AmpVsID[nRun]);
1491  if(nRun>splitRuns3) AmpVsIDrBrBlockD->Add(AmpVsID[nRun]);
1492  }
1493 
1494  //--------------------------------------------------
1495  //..unfortunatley this part is necessary. The amplidude vs. ID figures
1496  //..are scaled at the end of the bad channel analysis and alathough
1497  //..we can undo the scaling here by multiplying with nEvents it does
1498  //..not look the same. It does when one comments the scaling in the bad
1499  //..channel analysis. So to avaoid intoducing artificial differences
1500  //..we use the exact same amplidute vs. ID figure.
1501  AmpVsIDrBrBlockA->Reset();
1502  AmpVsIDrBrBlockA=(TH2F*)hCellAmplitudeA->Clone("AmpVsIDrBrBlockA");
1503  AmpVsIDrBrBlockB->Reset();
1504  AmpVsIDrBrBlockB=(TH2F*)hCellAmplitudeB->Clone("AmpVsIDrBrBlockB");
1505  AmpVsIDrBrBlockC->Reset();
1506  AmpVsIDrBrBlockC=(TH2F*)hCellAmplitudeC->Clone("AmpVsIDrBrBlockC");
1507  AmpVsIDrBrBlockD->Reset();
1508  AmpVsIDrBrBlockD=(TH2F*)hCellAmplitudeD->Clone("AmpVsIDrBrBlockD");
1509  //--------------------------------------------------
1510 
1511  //......................................................
1512  //..mask the bad cells according to both versions
1513  //......................................................
1514  Int_t maskA=0;
1515  Int_t maskB=0;
1516  Int_t maskC=0;
1517  Int_t maskD=0;
1518 
1519  for(Int_t ic = 0; ic < noOfCells; ic++)
1520  {
1521  //......................................................
1522  //..Part A - analyzed as one merged runblock
1523  //......................................................
1524  maskA=0;
1525  maskB=0;
1526  maskC=0;
1527  maskD=0;
1528  maskA=IsCellMaskedByHand(ic,badcellsBlock1);
1529  maskB=IsCellMaskedByHand(ic,badcellsBlock2);
1530  maskC=IsCellMaskedByHand(ic,badcellsBlock3);
1531  maskD=IsCellMaskedByHand(ic,badcellsBlock4);
1532 
1533  //..mask the bad cells
1534  for (Int_t amp = 1; amp <= hCellAmplitudeBlockMaskA->GetNbinsX(); amp++)
1535  {
1536  if(hCellFlagA->GetBinContent(ic+1)>0 || maskA==1)
1537  {
1538  hCellAmplitudeBlockMaskA->SetBinContent(amp,ic+1,0);
1539  if(amp==1)nBadCellMerged[0]--;
1540  }
1541  if(hCellFlagB->GetBinContent(ic+1)>0 || maskB==1)
1542  {
1543  hCellAmplitudeBlockMaskB->SetBinContent(amp,ic+1,0);
1544  if(amp==1)nBadCellMerged[1]--;
1545  }
1546  if(hCellFlagC->GetBinContent(ic+1)>0 || maskC==1)
1547  {
1548  hCellAmplitudeBlockMaskC->SetBinContent(amp,ic+1,0);
1549  if(amp==1)nBadCellMerged[2]--;
1550  }
1551  if(hCellFlagD->GetBinContent(ic+1)>0 || maskD==1)
1552  {
1553  hCellAmplitudeBlockMaskD->SetBinContent(amp,ic+1,0);
1554  if(amp==1)nBadCellMerged[3]--;
1555  }
1556  }
1557 
1558  //......................................................
1559  //..Part B - analyzed run-by-run, corrected and masked in block
1560  //......................................................
1561 
1562  TH1D *htmpCellAllRuns =BadCellsVsRun->ProjectionY(TString::Format("hIDProj_cell%d", ic), ic+1, ic+1);
1563  Double_t integralBlock1 =htmpCellAllRuns->Integral(0,splitRuns1);
1564  Double_t integralBlock2 =htmpCellAllRuns->Integral(splitRuns1+1,splitRuns2);
1565  Double_t integralBlock3 =htmpCellAllRuns->Integral(splitRuns2+1,splitRuns3);
1566  Double_t integralBlock4 =htmpCellAllRuns->Integral(splitRuns3+1,nRunsUsed);
1567 
1568  //..manually mask cells
1569  integralBlock1+=IsCellMaskedByHand(ic,badcellsBlock1);
1570  integralBlock2+=IsCellMaskedByHand(ic,badcellsBlock2);
1571  integralBlock3+=IsCellMaskedByHand(ic,badcellsBlock3);
1572  integralBlock4+=IsCellMaskedByHand(ic,badcellsBlock4);
1573 
1574  for(Int_t amp = 1; amp <= AmpVsIDrBrBlockA->GetNbinsX(); amp++)
1575  {
1576  if(integralBlock1>0)
1577  {
1578  AmpVsIDrBrBlockA->SetBinContent(amp,ic+1,0);
1579  if(amp==1)nBadCellRbR[0]--;
1580  }
1581  if(integralBlock2>0)
1582  {
1583  AmpVsIDrBrBlockB->SetBinContent(amp,ic+1,0);
1584  if(amp==1)nBadCellRbR[1]--;
1585  }
1586  if(integralBlock3>0)
1587  {
1588  AmpVsIDrBrBlockC->SetBinContent(amp,ic+1,0);
1589  if(amp==1)nBadCellRbR[2]--;
1590  }
1591  if(integralBlock4>0)
1592  {
1593  AmpVsIDrBrBlockD->SetBinContent(amp,ic+1,0);
1594  if(amp==1)nBadCellRbR[3]--;
1595  }
1596  }
1597 
1598  //......................................................
1599  //..Compare the different channels that are marked in the two versions
1600  //......................................................
1601  if(!IsCellMaskedByHand(ic,badcellsBlock1))
1602  {
1603  if(hCellFlagA->GetBinContent(ic+1)>0 && integralBlock1==0)vOnlyMaskedInMergedA.push_back(ic);
1604  if(hCellFlagA->GetBinContent(ic+1)==0 && integralBlock1>0) vOnlyMaskedInRunbRunA.push_back(ic);
1605  }
1606  if(!IsCellMaskedByHand(ic,badcellsBlock2))
1607  {
1608  if(hCellFlagB->GetBinContent(ic+1)>0 && integralBlock2==0)vOnlyMaskedInMergedB.push_back(ic);
1609  if(hCellFlagB->GetBinContent(ic+1)==0 && integralBlock2>0) vOnlyMaskedInRunbRunB.push_back(ic);
1610  }
1611  if(!IsCellMaskedByHand(ic,badcellsBlock3))
1612  {
1613  if(hCellFlagC->GetBinContent(ic+1)>0 && integralBlock3==0)vOnlyMaskedInMergedC.push_back(ic);
1614  if(hCellFlagC->GetBinContent(ic+1)==0 && integralBlock3>0) vOnlyMaskedInRunbRunC.push_back(ic);
1615  }
1616  if(!IsCellMaskedByHand(ic,badcellsBlock4))
1617  {
1618  if(hCellFlagD->GetBinContent(ic+1)>0 && integralBlock4==0)vOnlyMaskedInMergedD.push_back(ic);
1619  if(hCellFlagD->GetBinContent(ic+1)==0 && integralBlock4>0) vOnlyMaskedInRunbRunD.push_back(ic);
1620  }
1621 
1622  }
1623  //..merged runblock
1624  TH1* projMaskedCellsA = hCellAmplitudeBlockMaskA->ProjectionX("MaskedCellsMergedBlockA");
1625  TH1* projMaskedCellsB = hCellAmplitudeBlockMaskB->ProjectionX("MaskedCellsMergedBlockB");
1626  TH1* projMaskedCellsC = hCellAmplitudeBlockMaskC->ProjectionX("MaskedCellsMergedBlockC");
1627  TH1* projMaskedCellsD = hCellAmplitudeBlockMaskD->ProjectionX("MaskedCellsMergedBlockD");
1628 
1629  //..RbR mask
1630  TH1* projMaskedCellsBlockA = AmpVsIDrBrBlockA->ProjectionX("MaskedCellsRbRBlockA");
1631  TH1* projMaskedCellsBlockB = AmpVsIDrBrBlockB->ProjectionX("MaskedCellsRbRBlockB");
1632  TH1* projMaskedCellsBlockC = AmpVsIDrBrBlockC->ProjectionX("MaskedCellsRbRBlockC");
1633  TH1* projMaskedCellsBlockD = AmpVsIDrBrBlockD->ProjectionX("MaskedCellsRbRBlockD");
1634 
1635  //......................................................
1636  //..Plot results
1637  //......................................................
1638  TCanvas* C1 = new TCanvas("-1-","Bock A and B",900,900);
1639  C1->Divide(2,2);
1640  C1->cd(1)->SetLogy();
1641  SetHisto(projMaskedCellsA,"","hits/event",0);
1642  projMaskedCellsA->DrawCopy("hist");
1643  projMaskedCellsBlockA->SetLineColor(8);
1644  projMaskedCellsBlockA->DrawCopy("same hist");
1645  C1->cd(2);
1646  projMaskedCellsA->Divide(projMaskedCellsBlockA);
1647  SetHisto(projMaskedCellsA,"","Merged block/Run-by-Run block",0);
1648  projMaskedCellsA->DrawCopy("hist");
1649  projMaskedCellsA->Multiply(projMaskedCellsBlockA);
1650 
1651  C1->cd(3)->SetLogy();
1652  SetHisto(projMaskedCellsB,"","hits/event",0);
1653  projMaskedCellsB->DrawCopy("hist");
1654  projMaskedCellsBlockB->SetLineColor(8);
1655  projMaskedCellsBlockB->DrawCopy("same hist");
1656  C1->cd(4);
1657  projMaskedCellsB->Divide(projMaskedCellsBlockB);
1658  SetHisto(projMaskedCellsB,"","Merged block/Run-by-Run block",0);
1659  projMaskedCellsB->DrawCopy("hist");
1660  projMaskedCellsB->Multiply(projMaskedCellsBlockB);
1661 
1662  TCanvas* C2 = new TCanvas("-2-","Block C and D",900,900);
1663  C2->Divide(2,2);
1664  C2->cd(1)->SetLogy();
1665  SetHisto(projMaskedCellsC,"","hits/event",0);
1666  projMaskedCellsC->DrawCopy("hist");
1667  projMaskedCellsBlockC->SetLineColor(8);
1668  projMaskedCellsBlockC->DrawCopy("same hist");
1669  C2->cd(2);
1670  projMaskedCellsC->Divide(projMaskedCellsBlockC);
1671  SetHisto(projMaskedCellsC,"","Merged block/Run-by-Run block",0);
1672  projMaskedCellsC->DrawCopy("hist");
1673  projMaskedCellsC->Multiply(projMaskedCellsBlockC);
1674 
1675  C2->cd(3)->SetLogy();
1676  SetHisto(projMaskedCellsD,"","hits/event",0);
1677  projMaskedCellsD->DrawCopy("hist");
1678  projMaskedCellsBlockD->SetLineColor(8);
1679  projMaskedCellsBlockD->DrawCopy("same hist");
1680  C2->cd(4);
1681  projMaskedCellsD->Divide(projMaskedCellsBlockD);
1682  SetHisto(projMaskedCellsD,"","Merged block/Run-by-Run block",0);
1683  projMaskedCellsD->DrawCopy("hist");
1684  projMaskedCellsD->Multiply(projMaskedCellsBlockD);
1685 
1686  TCanvas* C3 = new TCanvas("-3-","Merge A, B, C, and D",900,900);
1687  C3->Divide(2,2);
1688  C3->cd(1)->SetLogz();
1689  SetHisto(hCellAmplitudeBlockMaskA,"","cell ID",0);
1690  hCellAmplitudeBlockMaskA->DrawCopy("colz");
1691  C3->cd(2)->SetLogz();
1692  SetHisto(hCellAmplitudeBlockMaskB,"","cell ID",0);
1693  hCellAmplitudeBlockMaskB->DrawCopy("colz");
1694  C3->cd(3)->SetLogz();
1695  SetHisto(hCellAmplitudeBlockMaskC,"","cell ID",0);
1696  hCellAmplitudeBlockMaskC->DrawCopy("colz");
1697  C3->cd(4)->SetLogz();
1698  SetHisto(hCellAmplitudeBlockMaskD,"","cell ID",0);
1699  hCellAmplitudeBlockMaskD->DrawCopy("colz");
1700 
1701  TCanvas* C4 = new TCanvas("-4-","Run-by-Run A, B, C, and D",900,900);
1702  C4->Divide(2,2);
1703  C4->cd(1)->SetLogz();
1704  SetHisto(AmpVsIDrBrBlockA,"","cell ID",0);
1705  AmpVsIDrBrBlockA->DrawCopy("colz");
1706  C4->cd(2)->SetLogz();
1707  SetHisto(AmpVsIDrBrBlockB,"","cell ID",0);
1708  AmpVsIDrBrBlockB->DrawCopy("colz");
1709  C4->cd(3)->SetLogz();
1710  SetHisto(AmpVsIDrBrBlockC,"","cell ID",0);
1711  AmpVsIDrBrBlockC->DrawCopy("colz");
1712  C4->cd(4)->SetLogz();
1713  SetHisto(AmpVsIDrBrBlockD,"","cell ID",0);
1714  AmpVsIDrBrBlockD->DrawCopy("colz");
1715 
1716  //......................................................
1717  //..Print out compared cells and plot the spectra
1718  //......................................................
1719  projMaskedCellsA->Scale(1.0/nBadCellMerged[0]);
1720  projMaskedCellsB->Scale(1.0/nBadCellMerged[1]);
1721  projMaskedCellsC->Scale(1.0/nBadCellMerged[2]);
1722  projMaskedCellsD->Scale(1.0/nBadCellMerged[3]);
1723  projMaskedCellsBlockA->Scale(1.0/nBadCellRbR[0]);
1724  projMaskedCellsBlockB->Scale(1.0/nBadCellRbR[1]);
1725  projMaskedCellsBlockC->Scale(1.0/nBadCellRbR[2]);
1726  projMaskedCellsBlockD->Scale(1.0/nBadCellRbR[3]);
1727 
1728  cout<<0<<"-"<<splitRuns1<<" -> "<<splitRuns1<<" runs"<<endl;
1729  cout<<splitRuns1+1<<"-"<<splitRuns2<<" -> "<<splitRuns2-splitRuns1<<" runs"<<endl;
1730  cout<<splitRuns2+1<<"-"<<splitRuns3<<" -> "<<splitRuns3-splitRuns2<<" runs"<<endl;
1731  cout<<splitRuns3+1<<"-"<<nRunsUsed<<" -> "<<nRunsUsed-splitRuns3<<" runs"<<endl;
1732 
1733  cout<<"o Run block A ("<<"0-"<<splitRuns1<<")"<<endl;
1734  cout<<" Cells masked in Merged version and not in Run-b-run version ("<<vOnlyMaskedInMergedA.size()<<"):"<<endl;
1735  for(Int_t i=0; i<(Int_t)vOnlyMaskedInMergedA.size();i++)
1736  {
1737  cout<<vOnlyMaskedInMergedA.at(i)<<","<<flush;
1738  }
1739  cout<<endl;
1740  CreateCellCompPDF(AmpVsIDrBrBlockA,vOnlyMaskedInMergedA,projMaskedCellsA,projMaskedCellsBlockA,"./cOnlyMergedBlockA.pdf");
1741  cout<<" Cells masked in Run-b-run version and not in Merged version ("<<vOnlyMaskedInRunbRunA.size()<<"):"<<endl;
1742  for(Int_t i=0; i<(Int_t)vOnlyMaskedInRunbRunA.size();i++)
1743  {
1744  cout<<vOnlyMaskedInRunbRunA.at(i)<<","<<flush;
1745  }
1746  cout<<endl;
1747  CreateCellCompPDF(hCellAmplitudeBlockMaskA,vOnlyMaskedInRunbRunA,projMaskedCellsA,projMaskedCellsBlockA,"./cOnlyRbRBlockA.pdf");
1748 
1749  cout<<"o Run block B ("<<splitRuns1+1<<"-"<<splitRuns2<<")"<<endl;
1750  cout<<" Cells masked in Merged version and not in Run-b-run version ("<<vOnlyMaskedInMergedB.size()<<"):"<<endl;
1751  for(Int_t i=0; i<(Int_t)vOnlyMaskedInMergedB.size();i++)
1752  {
1753  cout<<vOnlyMaskedInMergedB.at(i)<<","<<flush;
1754  }
1755  cout<<endl;
1756  CreateCellCompPDF(AmpVsIDrBrBlockB,vOnlyMaskedInMergedB,projMaskedCellsB,projMaskedCellsBlockB,"./cOnlyMergedBlockB.pdf");
1757  cout<<" Cells masked in Run-b-run version and not in Merged version ("<<vOnlyMaskedInRunbRunB.size()<<"):"<<endl;
1758  for(Int_t i=0; i<(Int_t)vOnlyMaskedInRunbRunB.size();i++)
1759  {
1760  cout<<vOnlyMaskedInRunbRunB.at(i)<<","<<flush;
1761  }
1762  cout<<endl;
1763  CreateCellCompPDF(hCellAmplitudeBlockMaskB,vOnlyMaskedInRunbRunB,projMaskedCellsB,projMaskedCellsBlockB,"./cOnlyRbRBlockB.pdf");
1764 
1765  cout<<"o Run block C ("<<splitRuns2+1<<"-"<<splitRuns3<<")"<<endl;
1766  cout<<" Cells masked in Merged version and not in Run-b-run version ("<<vOnlyMaskedInMergedC.size()<<"):"<<endl;
1767  for(Int_t i=0; i<(Int_t)vOnlyMaskedInMergedC.size();i++)
1768  {
1769  cout<<vOnlyMaskedInMergedC.at(i)<<","<<flush;
1770  }
1771  cout<<endl;
1772  CreateCellCompPDF(AmpVsIDrBrBlockC,vOnlyMaskedInMergedC,projMaskedCellsC,projMaskedCellsBlockC,"./cOnlyMergedBlockC.pdf");
1773  cout<<" Cells masked in Run-b-run version and not in Merged version ("<<vOnlyMaskedInRunbRunC.size()<<"):"<<endl;
1774  for(Int_t i=0; i<(Int_t)vOnlyMaskedInRunbRunC.size();i++)
1775  {
1776  cout<<vOnlyMaskedInRunbRunC.at(i)<<","<<flush;
1777  }
1778  cout<<endl;
1779  CreateCellCompPDF(hCellAmplitudeBlockMaskC,vOnlyMaskedInRunbRunC,projMaskedCellsC,projMaskedCellsBlockC,"./cOnlyRbRBlockC.pdf");
1780 
1781  cout<<"o Run block D ("<<splitRuns3+1<<"-"<<nRunsUsed<<")"<<endl;
1782  cout<<" Cells masked in Merged version and not in Run-b-run version ("<<vOnlyMaskedInMergedD.size()<<"):"<<endl;
1783  for(Int_t i=0; i<(Int_t)vOnlyMaskedInMergedD.size();i++)
1784  {
1785  cout<<vOnlyMaskedInMergedD.at(i)<<","<<flush;
1786  }
1787  cout<<endl;
1788  CreateCellCompPDF(AmpVsIDrBrBlockD,vOnlyMaskedInMergedD,projMaskedCellsD,projMaskedCellsBlockD,"./cOnlyMergedBlockD.pdf");
1789  cout<<" Cells masked in Run-b-run version and not in Merged version ("<<vOnlyMaskedInRunbRunD.size()<<"):"<<endl;
1790  for(Int_t i=0; i<(Int_t)vOnlyMaskedInRunbRunD.size();i++)
1791  {
1792  cout<<vOnlyMaskedInRunbRunD.at(i)<<","<<flush;
1793  }
1794  cout<<endl;
1795  CreateCellCompPDF(hCellAmplitudeBlockMaskD,vOnlyMaskedInRunbRunD,projMaskedCellsD,projMaskedCellsBlockD,"./cOnlyRbRBlockD.pdf");
1796 
1797  //......................................................
1798  //..build two dimensional histogram with cells rejected from
1799  //..the one or the other method
1800  //......................................................
1801  Plot2DCells("A",244917,vOnlyMaskedInRunbRunA,vOnlyMaskedInMergedA);
1802  Plot2DCells("B",244917,vOnlyMaskedInRunbRunB,vOnlyMaskedInMergedB);
1803  Plot2DCells("C",244917,vOnlyMaskedInRunbRunC,vOnlyMaskedInMergedC);
1804  Plot2DCells("D",244917,vOnlyMaskedInRunbRunD,vOnlyMaskedInMergedD);
1805 
1806  vOnlyMaskedInRunbRunA.insert( vOnlyMaskedInRunbRunA.end(), vOnlyMaskedInRunbRunB.begin(), vOnlyMaskedInRunbRunB.end() );
1807  vOnlyMaskedInRunbRunA.insert( vOnlyMaskedInRunbRunA.end(), vOnlyMaskedInRunbRunC.begin(), vOnlyMaskedInRunbRunC.end() );
1808  vOnlyMaskedInRunbRunA.insert( vOnlyMaskedInRunbRunA.end(), vOnlyMaskedInRunbRunD.begin(), vOnlyMaskedInRunbRunD.end() );
1809  vOnlyMaskedInMergedA.insert( vOnlyMaskedInMergedA.end(), vOnlyMaskedInMergedB.begin(), vOnlyMaskedInMergedB.end() );
1810  vOnlyMaskedInMergedA.insert( vOnlyMaskedInMergedA.end(), vOnlyMaskedInMergedC.begin(), vOnlyMaskedInMergedC.end() );
1811  vOnlyMaskedInMergedA.insert( vOnlyMaskedInMergedA.end(), vOnlyMaskedInMergedD.begin(), vOnlyMaskedInMergedD.end() );
1812  Plot2DCells("sum",244917,vOnlyMaskedInRunbRunA,vOnlyMaskedInMergedA);
1813 
1814 }
1815 //
1816 //
1817 //
1818 //
1819 void Plot2DCells(TString Block, Int_t runNo, std::vector<Int_t> cellVectorRbR, std::vector<Int_t> cellVectorMerge)
1820 {
1821  //......................................................
1822  //..Initialize EMCal/DCal geometry
1823  AliCalorimeterUtils* fCaloUtils = new AliCalorimeterUtils();
1824  //..Create a dummy event for the CaloUtils
1825  AliAODEvent* aod = new AliAODEvent();
1826  fCaloUtils->SetRunNumber(runNo);
1827  fCaloUtils->AccessGeometry(aod);
1828  //......................................................
1829  //..setings for the 2D histogram
1830  Int_t nModules=fCaloUtils->GetEMCALGeometry()->GetNumberOfSuperModules();
1831  Int_t fNMaxColsAbs = 2*48;
1832  Int_t fNMaxRowsAbs = Int_t (nModules/2)*24; //multiply by number of supermodules
1833 
1834  TH2F *plot2D_RbR = new TH2F(Form("Block%s_MaskedRbR",Block.Data()),Form("Block%s_MaskedRbR",Block.Data()),fNMaxColsAbs+1,-0.5,fNMaxColsAbs+0.5, fNMaxRowsAbs+1,-0.5,fNMaxRowsAbs+0.5);
1835  plot2D_RbR->GetXaxis()->SetTitle("cell column (#eta direction)");
1836  plot2D_RbR->GetYaxis()->SetTitle("cell row (#phi direction)");
1837  TH2F *plot2D_Merge = new TH2F(Form("Block%s_MaskedMerge",Block.Data()),Form("Block%s_MaskedMerge",Block.Data()),fNMaxColsAbs+1,-0.5,fNMaxColsAbs+0.5, fNMaxRowsAbs+1,-0.5,fNMaxRowsAbs+0.5);
1838  plot2D_Merge->GetXaxis()->SetTitle("cell column (#eta direction)");
1839  plot2D_Merge->GetYaxis()->SetTitle("cell row (#phi direction)");
1840 
1841  Int_t cellColumn=0,cellRow=0;
1842  Int_t cellColumnAbs=0,cellRowAbs=0;
1843  Int_t trash;
1844 
1845  for(Int_t i = 0; i < (Int_t)cellVectorRbR.size(); i++)
1846  {
1847  Int_t cell=cellVectorRbR.at(i);
1848  //..Do that only for cell ids also accepted by the code
1849  if(!fCaloUtils->GetEMCALGeometry()->CheckAbsCellId(cell))continue;
1850 
1851  //..Get Row and Collumn for cell ID c
1852  fCaloUtils->GetModuleNumberCellIndexesAbsCaloMap(cell,0,cellColumn,cellRow,trash,cellColumnAbs,cellRowAbs);
1853  if(cellColumnAbs> fNMaxColsAbs || cellRowAbs>fNMaxRowsAbs)
1854  {
1855  cout<<"Problem! wrong calculated number of max col and max rows"<<endl;
1856  cout<<"current col: "<<cellColumnAbs<<", max col"<<fNMaxColsAbs<<endl;
1857  cout<<"current row: "<<cellRowAbs<<", max row"<<fNMaxRowsAbs<<endl;
1858  }
1859  plot2D_RbR->Fill(cellColumnAbs,cellRowAbs);
1860  }
1861  for(Int_t i = 0; i < (Int_t)cellVectorMerge.size(); i++)
1862  {
1863  Int_t cell=cellVectorMerge.at(i);
1864  //..Do that only for cell ids also accepted by the code
1865  if(!fCaloUtils->GetEMCALGeometry()->CheckAbsCellId(cell))continue;
1866 
1867  //..Get Row and Collumn for cell ID c
1868  fCaloUtils->GetModuleNumberCellIndexesAbsCaloMap(cell,0,cellColumn,cellRow,trash,cellColumnAbs,cellRowAbs);
1869  if(cellColumnAbs> fNMaxColsAbs || cellRowAbs>fNMaxRowsAbs)
1870  {
1871  cout<<"Problem! wrong calculated number of max col and max rows"<<endl;
1872  cout<<"current col: "<<cellColumnAbs<<", max col"<<fNMaxColsAbs<<endl;
1873  cout<<"current row: "<<cellRowAbs<<", max row"<<fNMaxRowsAbs<<endl;
1874  }
1875  plot2D_Merge->Fill(cellColumnAbs,cellRowAbs,1);
1876  }
1877  //. . . . . . . . . . . . . . . . . . . .
1878  TCanvas *c1 = new TCanvas(Form("2DMapForBlock%s",Block.Data()),Form("2DMapForBlock%s",Block.Data()),900,500);
1879  c1->ToggleEventStatus();
1880  c1->Divide(2);
1881  c1->cd(1);
1882  plot2D_RbR->Draw("colz");
1883  c1->cd(2);
1884  plot2D_Merge->Draw("colz");
1885 }
1886 //
1887 //________________________________________________________________________
1888 void BuildMaxMinHisto(TH1D* inHisto, TH1D* minHist,TH1D* maxHist)
1889 {
1890  Double_t ref;
1891  Double_t min;
1892  Double_t max;
1893  for(Int_t bin=0;bin<50;bin++)
1894  {
1895  ref = inHisto->GetBinContent(bin);
1896  max = maxHist->GetBinContent(bin);
1897  min = minHist->GetBinContent(bin);
1898  if((ref!=0 && ref<min) || min==0)minHist->SetBinContent(bin,ref);
1899  if(ref>max)maxHist->SetBinContent(bin,ref);
1900  }
1901 }
1902 //
1903 //________________________________________________________________________
1904 Bool_t IsItReallyBadRatio(TH1D* minHistoRatio,TH1D* maxHistoRatio,TH1D* meanHistoRatio, TString& crit)
1905 {
1906  //minHistoRatio ->Smooth();
1907  //maxHistoRatio ->Smooth();
1908  //meanHistoRatio ->Smooth();
1909 
1910  //..do the check only until 1 GeV because
1911  //..then we are running out of statistic
1912  /*Int_t OneGeVBin =minHistoRatio->FindBin(1.47); //=30bins
1913  Int_t HalfGeVBin =minHistoRatio->FindBin(0.73); //=15bins
1914  Int_t ThirdGeVBinA =minHistoRatio->FindBin(0.35);
1915  Int_t ThirdGeVBinB =minHistoRatio->FindBin(0.7);
1916  Int_t ThirdGeVBinC =minHistoRatio->FindBin(1.05);
1917  */
1918  Double_t mBlock1=0,mBlock2=0,mBlock3=0,mBlock4=0,mBlock5=0;
1919  Double_t zBlock1=0,zBlock2=0,zBlock3=0,zBlock4=0,zBlock5=0;
1920 
1921  Double_t minMean=0, maxMean=0, meanMean=0;
1922  Double_t zminMean=0, zmaxMean=0, zmeanMean=0;
1923 /* Double_t meanMean1=0, meanMean2=0;
1924  Double_t meanMeanA3=0, meanMeanB3=0, meanMeanC3=0;
1925  Int_t zeroBinsHalf1=0, zeroBinsHalf2=0;
1926  Int_t zeroBinsThird1=0, zeroBinsThird2=0, zeroBinsThird3=0;
1927 */
1928  //for(Int_t bin=0;bin<30;bin++)
1929  for(Int_t bin=3;bin<53;bin++)
1930  {
1931  if(bin<33)
1932  {
1933  minMean += minHistoRatio ->GetBinContent(bin);
1934  maxMean += maxHistoRatio ->GetBinContent(bin);
1935  meanMean += meanHistoRatio->GetBinContent(bin);
1936  if(minHistoRatio->GetBinContent(bin)==0)zminMean++;
1937  if(maxHistoRatio->GetBinContent(bin)==0)zmaxMean++;
1938  if(meanHistoRatio->GetBinContent(bin)==0)zmeanMean++;
1939  }
1940 
1941 /* if(bin<18) meanMean1+=meanHistoRatio->GetBinContent(bin);
1942  else if(bin<33) meanMean2+=meanHistoRatio->GetBinContent(bin);
1943 
1944 */
1945  /* if(bin<10) meanMeanA3+=meanHistoRatio->GetBinContent(bin+1);
1946  else if(bin<20)meanMeanB3+=meanHistoRatio->GetBinContent(bin+1);
1947  else meanMeanC3+=meanHistoRatio->GetBinContent(bin+1);
1948  */
1949  if(bin<13) mBlock1+=meanHistoRatio->GetBinContent(bin);
1950  else if(bin<23) mBlock2+=meanHistoRatio->GetBinContent(bin);
1951  else if(bin<33) mBlock3+=meanHistoRatio->GetBinContent(bin);
1952  else if(bin<43) mBlock4+=meanHistoRatio->GetBinContent(bin);
1953  else if(bin<53) mBlock5+=meanHistoRatio->GetBinContent(bin);
1954  //..count zero bins
1955  if(meanHistoRatio->GetBinContent(bin)==0)
1956  {
1957  if(bin<13) zBlock1++;
1958  else if(bin<23) zBlock2++;
1959  else if(bin<33) zBlock3++;
1960  else if(bin<43) zBlock4++;
1961  else if(bin<53) zBlock5++;
1962  }
1963  /* //..correct for zero bins
1964  if(meanHistoRatio->GetBinContent(bin+1)==0 && bin<15) zeroBinsHalf1++;
1965  else if(meanHistoRatio->GetBinContent(bin+1)==0) zeroBinsHalf2++;
1966 
1967  if(meanHistoRatio->GetBinContent(bin+1)==0 && bin<10) zeroBinsThird1++;
1968  else if(meanHistoRatio->GetBinContent(bin+1)==0 && bin<20)zeroBinsThird2++;
1969  else if(meanHistoRatio->GetBinContent(bin+1)==0) zeroBinsThird3++;
1970  */}
1971  //.......................................
1972  //..correct for zero bins
1973  //.......................................
1974 /*
1975  if(zeroBinsHalf1!=0)meanMean1=meanMean1/(1.0-1.0*zeroBinsHalf1/15);
1976  if(zeroBinsHalf2!=0)meanMean2=meanMean2/(1.0-1.0*zeroBinsHalf2/15);
1977 
1978  if(zeroBinsThird1!=0)meanMeanA3=meanMeanA3/(1.0-1.0*zeroBinsThird1/10);
1979  if(zeroBinsThird2!=0)meanMeanB3=meanMeanB3/(1.0-1.0*zeroBinsThird2/10);
1980  if(zeroBinsThird3!=0)meanMeanC3=meanMeanC3/(1.0-1.0*zeroBinsThird3/10);
1981 */
1982  if(zBlock1<10 && zBlock1!=0)mBlock1=mBlock1/(1.0-1.0*zBlock1/10);
1983  if(zBlock2<10 && zBlock2!=0)mBlock2=mBlock2/(1.0-1.0*zBlock2/10);
1984  if(zBlock3<10 && zBlock3!=0)mBlock3=mBlock3/(1.0-1.0*zBlock3/10);
1985  if(zBlock4<10 && zBlock4!=0)mBlock4=mBlock4/(1.0-1.0*zBlock4/10);
1986  if(zBlock5<10 && zBlock5!=0)mBlock5=mBlock5/(1.0-1.0*zBlock5/10);
1987 
1988  if(zminMean!=0)minMean =minMean/(1.0-1.0*zminMean/30);
1989  if(zmaxMean!=0)maxMean =maxMean/(1.0-1.0*zmaxMean/30);
1990  if(zmeanMean!=0)meanMean=meanMean/(1.0-1.0*zmeanMean/30);
1991 
1992  //..if more than half of the bins in the block were 0 exclude block
1993  if(zBlock1>5)mBlock1=0;
1994  if(zBlock2>5)mBlock2=0;
1995  if(zBlock3>5)mBlock3=0;
1996  if(zBlock4>5)mBlock4=0;
1997  if(zBlock5>5)mBlock5=0;
1998  //.......................................
1999  //..check criteria
2000  //.......................................
2001 
2002  //..bad channel is 5times lower than max distr.
2003  crit = "spectr. too low";
2004  if(meanMean/30.0>5) return 1;
2005  if(minMean/30.0 >5) return 1; //5 times lower than the lowest run
2006  //..bad channel is 5times higher than max distr.
2007  crit = "spectr. too high";
2008  if(meanMean/30.0<0.2) return 1;
2009  if(maxMean/30.0 <0.2) return 1; //5 times higher than the highest run
2010 
2011  //..if there is a slope down (should be more than 10% decrease)
2012  crit = "slope down";
2013  Int_t down=0;
2014  if(mBlock1!=0 && mBlock2!=0 && mBlock1>mBlock2 && mBlock1>1.4*mBlock2)down++;
2015  if(mBlock2!=0 && mBlock3!=0 && mBlock2>mBlock3 && mBlock2>1.4*mBlock3)down++;
2016  if(mBlock3!=0 && mBlock4!=0 && mBlock3>mBlock4 && mBlock3>1.4*mBlock4)down++;
2017  if(mBlock4!=0 && mBlock5!=0 && mBlock4>mBlock5 && mBlock4>1.4*mBlock5)down++;
2018  if(down>=2)return 1; //..means at least three blocks have to be staggered
2019 
2020  crit = "slope up";
2021  Int_t up=0;
2022  if(mBlock1!=0 && mBlock2 !=0 && mBlock1<mBlock2 && 1.4*mBlock1<mBlock2)up++;
2023  if(mBlock2!=0 && mBlock3 !=0 && mBlock2<mBlock3 && 1.4*mBlock2<mBlock3)up++;
2024  if(mBlock3!=0 && mBlock4 !=0 && mBlock3<mBlock4 && 1.4*mBlock3<mBlock4)up++;
2025  if(mBlock4!=0 && mBlock5 !=0 && mBlock4<mBlock5 && 1.4*mBlock4<mBlock5)up++;
2026  if(up>=2)return 1; //..means at least three blocks have to be staggered
2027 
2028  //..if there is a step at 2.1 GeV
2029  crit = "step 2.1 GeV";
2030  if(mBlock4!=0 && mBlock5!=0 && mBlock4>mBlock5 && mBlock4>20*mBlock5) return 1;
2031 
2032  //..if there is a steep step at 1.1 GeV (can only be performed if this is not dominated by "zero" bins)
2033 // crit = "step 1.1";
2034 // if(zeroBinsThird3<5 && meanMeanB3>meanMeanC3 && meanMeanB3>3.5*meanMeanC3) return 1;
2035  //..is good
2036  crit = "";
2037  return 0;
2038 }
2039 //
2040 //________________________________________________________________________
2041 void PlotLowFractionCells(TString pdfName, std::vector<Int_t> cellVector,TH2F* badVsCell[],Int_t nRuns,TH2F* ampID[],TH1D* hCellGoodMean[])
2042 {
2043  gROOT->ProcessLine("gErrorIgnoreLevel = kWarning;"); //..to supress a lot of standard output
2044 
2045  Int_t nRescuableChannels=cellVector.size();
2046  Int_t totalperCv = 16;
2047  Int_t nPad = TMath::Sqrt(totalperCv);
2048  Int_t nCv = nRescuableChannels/totalperCv+1;
2049  Int_t lastGood=0;
2050 
2051  TLatex* text = new TLatex(0.45,0.6,"*Indeed bad*");//..
2052  text->SetTextSize(0.07);
2053  text->SetTextColor(kAzure-8);
2054  text->SetNDC();
2055 
2056  TH1D *maxHisto = ampID[0]->ProjectionX("hMaxCells", 1, 1);
2057  TH1D *minHisto = ampID[0]->ProjectionX("hMinCells", 1, 1);
2058  TH1D* hgoodMean = ampID[0]->ProjectionX("hMeanofRuns", 1, 1);
2059  if(nCv<1)nCv=1;
2060 
2061  cout<<" o create: "<<nCv<<" Canvases with "<<nPad*nPad<<" pads"<<endl;
2062  //..to compare specific cells over the runs
2063  TCanvas **cComp = new TCanvas*[nCv];
2064  TCanvas **cCompDiv = new TCanvas*[nCv];
2065  for(Int_t i=0;i<nCv;i++)
2066  {
2067  cComp[i] = new TCanvas(TString::Format("CompareGood%d", i), TString::Format("V) Candidates (%d/%d)", i+1, nCv), 1000,750);
2068  cComp[i] ->Divide(nPad,nPad,0.001,0.001);
2069  cCompDiv[i] = new TCanvas(TString::Format("CompareGood Ratio%d", i), TString::Format("V) Candidates Ratio (%d/%d)", i+1, nCv), 1000,750);
2070  cCompDiv[i] ->Divide(nPad,nPad,0.001,0.001);
2071  }
2072 
2073  Int_t notBadCounter=0;
2074  //TH1F** hCellSpectr = new TH1F*[nRescuableChannels];
2075  for(Int_t cell=0;cell< (Int_t)cellVector.size();cell++)
2076  {
2077  if(cell%400==0)cout<<"cell No."<<cell<<endl;
2078  if(cell%20==0) cout<<"."<<flush;
2079  maxHisto->Reset();
2080  minHisto->Reset();
2081  hgoodMean->Reset();
2082  TH1D* declaredBad;
2083  std::vector<TH1D*> badHistVector;
2084  Int_t badRun=-1;
2085  for(Int_t i = 0 ; i < nRuns ; i++)
2086  {
2087  TH1D *htmpCell = ampID[i]->ProjectionX(TString::Format("hIDProj_cell%dRun%i", cellVector.at(cell),i), cellVector.at(cell)+1, cellVector.at(cell)+1);
2088  htmpCell->SetLineColor(kGray+1);
2089  if(badVsCell[2]->GetBinContent(cellVector.at(cell)+1,i+1)==1)
2090  {
2091  htmpCell->SetLineColor(2);
2092  htmpCell->SetFillColor(2);
2093  htmpCell->SetFillStyle(3002);
2094  declaredBad = (TH1D*)htmpCell->Clone("saveForLater");
2095  badHistVector.push_back(htmpCell);
2096  badRun=i;
2097  if(htmpCell->Integral()==0)cout<<"cell "<<cell<<" is dead for run: "<<i<<endl;
2098  }
2099  else
2100  {
2101  BuildMaxMinHisto(htmpCell,minHisto,maxHisto);
2102  hgoodMean->Add(htmpCell);
2103  }
2104  //..go to the last pad and draw the mean of all good cell distribution
2105  //..for all the tested runs
2106  if(i==0)
2107  {
2108  cComp[nCv-1] ->cd(nPad*nPad)->SetLogy();
2109  SetHisto(hCellGoodMean[i],"","Number of Hits",0);
2110  hCellGoodMean[i]->GetXaxis()->SetRangeUser(0,3);
2111  hCellGoodMean[i]->Draw("hist");
2112  }
2113  else
2114  {
2115  cComp[nCv-1] ->cd(nPad*nPad)->SetLogy();
2116  hCellGoodMean[i]->Draw("same hist");
2117  }
2118  //..go to pads and draw cell in all runs
2119  lastGood=(cell-notBadCounter)/totalperCv;//..you can overwrite good canvases to lessen the amount of canvases
2120  if(i==0)
2121  {
2122  cComp[(cell-notBadCounter)/totalperCv]->cd(((cell-notBadCounter)%totalperCv)+1)->SetLogy();
2123  SetHisto(htmpCell,Form("Energy of cell %i",cellVector.at(cell)),"Number of Hits",0);
2124  htmpCell->GetXaxis()->SetRangeUser(0,3);
2125  htmpCell->Draw("hist");
2126  }
2127  else
2128  {
2129  cComp[(cell-notBadCounter)/totalperCv]->cd(((cell-notBadCounter)%totalperCv)+1)->SetLogy();
2130  htmpCell->DrawCopy("same hist");
2131  }
2132  }//..end of loop over runs
2133  hgoodMean->Scale(1.0/nRuns);
2134 
2135  hCellGoodMean[badRun]->DrawCopy("same hist"); //..draw the mean of all good cells for the run where the cell was bad
2136  minHisto->SetLineColor(1);
2137  maxHisto->SetLineColor(1);
2138  minHisto->DrawCopy("same"); //..draw the combined minimum of that cell for all the runs
2139  maxHisto->DrawCopy("same"); //..draw the combined maximum of that cell for all the runs
2140 
2141  //..Draw bad again
2142  for(Int_t j=0;j< (Int_t)badHistVector.size();j++)
2143  {
2144  badHistVector[j]->SetLineColor(2);
2145  badHistVector[j]->DrawCopy("same");
2146  }
2147 
2148  TLegend *leg = new TLegend(0.35,0.65,0.75,0.85);
2149  leg->AddEntry(hCellGoodMean[badRun],"mean of good cells","l");
2150  leg->AddEntry(declaredBad,"Cell in the ''bad'' run","l");
2151  leg->AddEntry(maxHisto,"max and min values","l");
2152  leg->SetBorderSize(0);
2153  leg->SetTextSize(0.07);
2154  leg->Draw("same");
2155 
2156  //. . . . . . . . . . . . . . . . . . . . . . . . .
2157  //..Fill the ratio canvas
2158  cCompDiv[(cell-notBadCounter)/totalperCv]->cd(((cell-notBadCounter)%totalperCv)+1);
2159 
2160  //..Draw bad again
2161  Int_t runTry=0;
2162  Bool_t badRatio=0;
2163  TString failCrit;
2164  for(Int_t j=0;j< (Int_t)badHistVector.size();j++)
2165  {
2166  TH1D* minHistoCopy =(TH1D*)minHisto->Clone("minHistoCopy");
2167  TH1D* maxHistoCopy =(TH1D*)maxHisto->Clone("maxHistoCopy");
2168  TH1D* meanHistoCopy=(TH1D*)hgoodMean->Clone("meanHistoCopy");
2169  minHistoCopy ->Divide(badHistVector[j]);
2170  maxHistoCopy ->Divide(badHistVector[j]);
2171  meanHistoCopy->Divide(badHistVector[j]);
2172 
2173  SetHisto(maxHistoCopy,Form("Energy of cell %i",cellVector.at(cell)),"max,min,mean / bad cell",0);
2174  maxHistoCopy->GetXaxis()->SetRangeUser(0,3);
2175  maxHistoCopy->DrawCopy("hist");
2176  minHistoCopy->DrawCopy("same hist");
2177  meanHistoCopy->SetLineColor(kBlue-8);
2178  meanHistoCopy->DrawCopy("same hist");
2179  //cout<<"cell: "<<cell<<endl;
2180  badRatio = IsItReallyBadRatio(minHistoCopy,maxHistoCopy,meanHistoCopy,failCrit);
2181  runTry=j;
2182  if(badRatio==1)break; //if its bad for one of the runs its enough
2183  }
2184  if(badRatio==1)
2185  {
2186  gPad->SetFrameFillColor(kRed-10);
2187  text->DrawLatexNDC(0.45,0.8,Form("#splitline{(%i)Excluded: }{%s}",runTry,(const char*)failCrit));;
2188  }
2189  else
2190  {
2191  //de-mask cells not declared as bad. (re-inclusion)
2192  for(Int_t j = 0 ; j < nRuns ; j++)
2193  {
2194  badVsCell[0]->SetBinContent(cellVector.at(cell)+1,j+1,0);
2195  badVsCell[1]->SetBinContent(cellVector.at(cell)+1,j+1,0);
2196  badVsCell[2]->SetBinContent(cellVector.at(cell)+1,j+1,0);
2197  }
2198  }
2199  if(cell==(Int_t)cellVector.size()-1)text->SetText(0.45,0.8,"test");
2200 
2201  }
2202  cout<<endl;
2203 
2204  //..plot the canvases of cells into a .pdf file
2205  for(Int_t can=0;can<nCv;can++)
2206  {
2207  TString internal_pdfName1=pdfName+"Low.pdf";
2208  TString internal_pdfName2=pdfName+"High.pdf";
2209  TString internal_pdfName3=pdfName+"Ratio.pdf";
2210  if(can==0)
2211  {
2212  //..first pad
2213  internal_pdfName1 +="(";
2214  internal_pdfName2 +="(";
2215  internal_pdfName3 +="(";
2216  cComp[can] ->Print(internal_pdfName1.Data());
2217  cCompDiv[can] ->Print(internal_pdfName3.Data());
2218  }
2219  else if(can==(nCv-1))
2220  {
2221  //..last pad
2222  internal_pdfName1 +=")";
2223  internal_pdfName2 +=")";
2224  internal_pdfName3 +=")";
2225  cComp[can] ->Print(internal_pdfName1.Data());
2226  cCompDiv[can] ->Print(internal_pdfName3.Data());
2227  }
2228  else
2229  {
2230  //..all pads in between
2231  cComp[can] ->Print(internal_pdfName1.Data());
2232  cCompDiv[can] ->Print(internal_pdfName3.Data());
2233  }
2234  }
2235  for(Int_t i=lastGood+1;i<nCv-1;i++)
2236  {
2237  cout<<"last good "<<lastGood<<endl;
2238  cout<<"nCv "<<nCv<<endl;
2239  cout<<"round "<<i<<endl;
2240  delete cComp[i];
2241  }
2242  cout<<endl;
2243 
2244 }
2248 //________________________________________________________________________
2249 TH2F* CompressHistogram(TH2 *Histo,Int_t totalCells, Int_t badCells,std::vector<Int_t> runIdVec)
2250 {
2251  TH2F* cpmpressed = new TH2F(Form("%s_Comp",Histo->GetName()),Form("%s_Comp",Histo->GetName()),badCells+2, 0,badCells+2,runIdVec.size(),0,runIdVec.size());
2252 
2253  Histo->GetXaxis()->UnZoom();
2254  TH1D *htmpCell = Histo->ProjectionX(TString::Format("%s_proj",Histo->GetName()),0,runIdVec.size());
2255  Int_t sumRun=0,newHistoBin=0;
2256  for(Int_t icell = 0; icell < totalCells ; icell++)
2257  {
2258  sumRun = htmpCell->GetBinContent(icell+1);
2259  //cout<<"enties cell("<<icell<<"): "<<sumRun<<endl;
2260  //..Fill non zero entries into the new histogram
2261  if(sumRun>0)
2262  {
2263  newHistoBin++;
2264  if(newHistoBin>badCells)cout<<"PROBLEM"<<endl;
2265  for(Int_t iRun = 0; iRun < (Int_t)runIdVec.size() ; iRun++)
2266  {
2267  cpmpressed->Fill(newHistoBin,iRun,Histo->GetBinContent(icell+1,iRun+1));
2268  //cout<<"fill bin "<<newHistoBin<<" with value: 2"<<endl;
2269  }
2270  }
2271  }
2272  for(Int_t i=0;i<(Int_t)runIdVec.size();i++)
2273  {
2274  cpmpressed->GetYaxis()->SetBinLabel(i+1,Form("%i",runIdVec.at(i)));
2275  }
2276  return cpmpressed;
2277 }
2281 //________________________________________________________________________
2282 void PlotHorLineRange(Double_t y_val, Double_t xLow, Double_t xHigh, Int_t Line_Col)
2283 {
2284  TLine* Zero_line = new TLine();
2285  Zero_line -> SetY1(y_val);
2286  Zero_line -> SetY2(y_val);
2287  Zero_line -> SetX1(xLow);
2288  Zero_line -> SetX2(xHigh);
2289  //cout << "x_val = " << x_val << ", Bin = " << Histo->FindBin(x_val) << ", Y2 = " << Histo->GetBinContent(Histo->FindBin(x_val)) << endl;
2290  Zero_line -> SetLineWidth(2);
2291  Zero_line -> SetLineStyle(9);
2292  Zero_line -> SetLineColor(Line_Col);
2293  Zero_line -> Draw();
2294  //delete Zero_line;
2295 }
2299 //________________________________________________________________________
2300 void SetHisto(TH2 *Histo,TString Xtitel,TString Ytitel,Bool_t longhisto)
2301 {
2302  //ELI
2303  Histo->SetStats(0);
2304  Histo->SetTitle("");
2305  if(longhisto==0)
2306  {
2307  Histo->GetYaxis()->SetTitleOffset(1.4);
2308  Histo->GetXaxis()->SetTitleOffset(1.4);
2309  Histo->GetXaxis()->SetLabelSize(0.05);
2310  Histo->GetYaxis()->SetLabelSize(0.05);
2311  Histo->GetXaxis()->SetTitleSize(0.045);
2312  Histo->GetYaxis()->SetTitleSize(0.045);
2313  }
2314  //..these are the run number vs. ID
2315  if(longhisto==1)
2316  {
2317  Histo->GetYaxis()->SetTitleOffset(0.6);
2318  Histo->GetXaxis()->SetTitleOffset(0.8);
2319  Histo->GetYaxis()->SetLabelOffset(0.002);
2320 // Histo->GetXaxis()->SetLabelSize(0.07);
2321 // Histo->GetYaxis()->SetLabelSize(0.07);
2322  Histo->GetXaxis()->SetLabelSize(0.025);
2323  Histo->GetYaxis()->SetLabelSize(0.015);
2324  Histo->GetXaxis()->SetTitleSize(0.03);
2325  Histo->GetYaxis()->SetTitleSize(0.04);
2326  Histo->GetYaxis()->SetTickLength(0.02);
2327  }
2328  //Histo->GetXaxis()->CenterTitle();
2329  //Histo->GetYaxis()->CenterTitle();
2330 
2331  if(longhisto==1)
2332  {
2333  Histo->GetXaxis()->SetNdivisions(520);
2334  //Histo->GetYaxis()->SetNdivisions(10);
2335  }
2336  else
2337  {
2338  Histo->GetXaxis()->SetNdivisions(505);
2339  Histo->GetYaxis()->SetNdivisions(505);
2340  }
2341 
2342  //..make nice font
2343  Histo->GetXaxis()->SetLabelFont(42);
2344  Histo->GetYaxis()->SetLabelFont(42);
2345  Histo->GetXaxis()->SetTitleFont(42);
2346  Histo->GetYaxis()->SetTitleFont(42);
2347  if(Xtitel!="")Histo->GetXaxis()->SetTitle(Xtitel);
2348  if(Ytitel!="")Histo->GetYaxis()->SetTitle(Ytitel);
2349  Histo->SetLineColor(1);
2350  Histo->SetMarkerColor(1);
2351  Histo->SetMarkerStyle(20);
2352  Histo->SetMarkerSize(0.5);
2353 }
2357 //________________________________________________________________________
2358 void SetHisto(TH1 *Histo,TString Xtitel,TString Ytitel,Bool_t longhisto)
2359 {
2360  Histo->SetStats(0);
2361  Histo->SetTitle("");
2362  if(longhisto==0)
2363  {
2364  Histo->GetYaxis()->SetTitleOffset(1.4);
2365  Histo->GetXaxis()->SetTitleOffset(1.4);
2366  Histo->GetXaxis()->SetLabelSize(0.05);
2367  Histo->GetYaxis()->SetLabelSize(0.05);
2368  Histo->GetXaxis()->SetTitleSize(0.045);
2369  Histo->GetYaxis()->SetTitleSize(0.045);
2370  Histo->GetXaxis()->SetNdivisions(505);
2371  Histo->GetYaxis()->SetNdivisions(505);
2372  }
2373 
2374  if(longhisto==1)
2375  {
2376  Histo->GetYaxis()->SetTitleOffset(0.2);
2377  Histo->GetXaxis()->SetTitleOffset(1.0);
2378  //if(big==1) Histo->GetYaxis()->SetLabelOffset(0.015);
2379  //if(big==1) Histo->GetXaxis()->SetLabelOffset(0.015);
2380  Histo->GetXaxis()->SetLabelSize(0.07);
2381  Histo->GetYaxis()->SetLabelSize(0.07);
2382  Histo->GetXaxis()->SetTitleSize(0.08);
2383  Histo->GetYaxis()->SetTitleSize(0.08);
2384  //Histo->GetXaxis()->CenterTitle();
2385  //Histo->GetYaxis()->CenterTitle();
2386  Histo->GetXaxis()->SetNdivisions(520);
2387  Histo->GetYaxis()->SetNdivisions(10);
2388  }
2389 
2390  Histo->GetXaxis()->SetLabelFont(42);
2391  Histo->GetYaxis()->SetLabelFont(42);
2392  Histo->GetXaxis()->SetTitleFont(42);
2393  Histo->GetYaxis()->SetTitleFont(42);
2394  if(Xtitel!="")Histo->GetXaxis()->SetTitle(Xtitel);
2395  if(Ytitel!="")Histo->GetYaxis()->SetTitle(Ytitel);
2396 
2397  Histo->SetLineColor(1);
2398  Histo->SetMarkerColor(1);
2399  Histo->SetMarkerStyle(20);
2400  Histo->SetMarkerSize(0.5);
2401 }
2402 //
2403 //
2404 // checks if the cell is part of manually masked cells
2405 //
2406 Bool_t IsCellMaskedByHand(Int_t cell, std::vector<Int_t> cellVector)
2407 {
2408  Bool_t bad=0;
2409  for(Int_t i=0; i<(Int_t)cellVector.size();i++)
2410  {
2411  if(cell==cellVector.at(i))bad=1;
2412  }
2413 
2414  return bad;
2415 }
2416 void CreateCellCompPDF(TH2F* hAmpIDMasked, std::vector<Int_t> cellVector,TH1* goodCellsMerged, TH1* goodCellsRbR, TString pdfName)
2417 {
2418  Int_t NoOfCells=cellVector.size();
2419  Bool_t firstCanvas=0;
2420  TString name;
2421  /*TLatex* textA = new TLatex(0.2,0.8,"*test*");
2422  textA->SetTextSize(0.08);
2423  textA->SetTextColor(1);
2424  textA->SetNDC();
2425  */
2426  for(Int_t cell=0;cell<NoOfCells;cell++)
2427  {
2428  TString internal_pdfName=pdfName;
2429  TCanvas *c1;
2430  if(cell%9==0)
2431  {
2432  c1 = new TCanvas(Form("badcells%i",cell),"badcells",1000,750);
2433  if(cellVector.size() > 6) c1->Divide(3,3);
2434  else if (cellVector.size() > 3) c1->Divide(3,2);
2435  else c1->Divide(3,1);
2436  }
2437  TH1 *hCell = hAmpIDMasked->ProjectionX(Form("Cell %d",cellVector.at(cell)),cellVector.at(cell)+1,cellVector.at(cell)+1);
2438  TH1 *hCell2 = (TH1*)hCell->Clone("hCell2");
2439 
2440  c1->cd(cell%9 + 1);
2441  hCell->Divide(goodCellsRbR);
2442  hCell2->Divide(goodCellsMerged);
2443 
2444  hCell->SetLineColor(kBlue-8);
2445  hCell2->SetLineColor(kRed-9);
2446  hCell->GetXaxis()->SetTitle("E (GeV)");
2447  hCell->GetYaxis()->SetTitle("cell/mean of good");
2448  hCell->GetXaxis()->SetRangeUser(0.,10.);
2449  hCell->SetLineWidth(1) ;
2450  hCell->SetTitle(Form("Cell No. %d",cellVector.at(cell)));
2451  hCell->Draw("hist");
2452  hCell2->DrawCopy("same hist");
2453 
2454  //textA->SetTitle(Form("Cell No. %d",cellVector.at(cell)));
2455  //textA->Draw();
2456 
2457  //..page is full or end of loop
2458  if(cell%9==8 ||cell == NoOfCells-1)
2459  {
2460  if(cell == NoOfCells-1)
2461  {
2462  //internal_pdfName +=")";
2463  c1->Print(Form("%s)",pdfName.Data()));
2464  }
2465  else if(firstCanvas==0)
2466  {
2467  internal_pdfName +="(";
2468  c1->Print(internal_pdfName.Data());
2469  firstCanvas=1;
2470  }
2471  else
2472  {
2473  c1->Print(internal_pdfName.Data());
2474  }
2475  delete c1;
2476  }
2477  }
2478 
2479 }
void PlotHorLineRange(Double_t y_val, Double_t xLow, Double_t xHigh, Int_t Line_Col)
double Double_t
Definition: External.C:58
void Draw(const char *filename, const char *title="", const char *others="ALL", const char *options="DEFAULT", const char *outFlg="ALL", UShort_t rebin=5, Float_t eff=0, const char *base="")
Definition: DrawdNdeta.C:3603
void SetRunNumber(Int_t run)
Definition: External.C:236
TString fileName
TSystem * gSystem
void PlotLowFractionCells(TString pdfName, std::vector< Int_t > cellVector, TH2F *badVsCell[], Int_t nRuns, TH2F *ampID[], TH1D *hCellGoodMean[])
Bool_t IsItReallyBadRatio(TH1D *minHistoRatio, TH1D *maxHistoRatio, TH1D *meanHistoRatior, TString &crit)
void Plot2DCells(TString Block, Int_t runNo, std::vector< Int_t > cellVectorRbR, std::vector< Int_t > cellVectorMerge)
AliEMCALGeometry * GetEMCALGeometry() const
int Int_t
Definition: External.C:63
Definition: External.C:212
const char * pdfName
Definition: DrawAnaELoss.C:30
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)
Bool_t IsCellMaskedByHand(Int_t cell, std::vector< Int_t > cellVector)
TH2F * CompressHistogram(TH2 *Histo, Int_t totalCells, Int_t badCells, std::vector< Int_t > runIdVec)
void GetBestPeriodSplitting(TString period="LHC15o", Int_t train=771, Int_t Nruns=105, Int_t noOfSplits=4)
const Int_t RainbowColors[]
Definition: External.C:220
void SummarizeRunByRun(TString period="LHC15o", TString train="Train_641", TString trigger="AnyINTnoBC", TString listName="runList", Int_t runsUsed=-1)
void CompareTwoBCstrategies(TString period="LHC15n", Int_t trainNo=603, Int_t version=5)
void BuildMaxMinHisto(TH1D *inHisto, TH1D *minHist, TH1D *maxHist)
void SetHisto(TH2 *Histo, TString Xtitel, TString Ytitel, Bool_t longhisto)
bool Bool_t
Definition: External.C:53
Class with utils specific to calorimeter clusters/cells.
void AccessGeometry(AliVEvent *inputEvent)
Definition: External.C:196
void CreateCellCompPDF(TH2F *hAmpIDMasked, std::vector< Int_t > cellVector, TH1 *goodCellsMerged, TH1 *goodCellsRbR, TString pdfName)
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