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