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