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