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