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