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