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