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