Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DNL_CorrectionArray.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DNL_CorrectionArray.C
1 /* This is a decent routine to fix differential non-linearity (DNL)
2  and more rapidly get at the actual resolution. We assume the following:
3  Since the FTBF tracks are "nearly" horizontal, the "phi" coordinate causes
4  all of sets of triple-layers to smoothly vary across the DNL parameter.
5  In this case, the residual will have a deterministic dependence on phi.
6  We'll use a profile histogram from the #Residual_vsPhi result to extract a
7  correction function. This will be turned into a "shift". Then we will copy
8  the #Residual_vsPhi into a new histogram while applying the appropriate shifts.
9 
10  2018-10-30 TKH & Vlad */
11 
12 
13 // PC = PhiCut (efficiency/track attempt before Hough) 2018-12-05 Vlad
14 
15 // New pointers need to be created and assigned to the original histograms in the code
16 char name[100];
19 
20 // Histograming ALL Radii through an array
23 
24 void TripleFit(TH2*);
25 
26 void DNL_CorrectionArray(int REBIN=1)
27 {
28 
29  // Assign the array of pointers.
30  for( int i=0; i<16; i++)
31  {
32  sprintf(name, "BH_Residual_vsPhi_%d", i);
33  _file0->GetObject(name, BH_Residual_vsPhi_[i]);
34 
35  sprintf(name, "BH_Residual_vsPhi_PC_%d", i);
36  _file0->GetObject(name, BH_Residual_vsPhi_PC_[i]);
37  }
38 
39  // Clone these into the "correct ones"
40  for (int i=1; i<15; i++) // 0 & 15 currently aren't "new'ed" in FillBlobHist.C
41  {
42  BH_Residual_vsPhi_[i]->Rebin2D(1, REBIN);
43  BH_Residual_vsPhi_PC_[i]->Rebin2D(1, REBIN);
44 
45  sprintf(name, "BH_Residual_vsPhi_Corrected_%d", i);
48 
49  sprintf(name, "BH_Residual_vsPhi_PC_Corrected_%d", i);
52  }
53 
54  // Fill the "corrected" histograms
55  for (int k=1; k<15; k++)
56  {
57  cout << "Calculating corrections for layer " << k << endl;
58  for (int i=1; i<BH_Residual_vsPhi_[k]->GetNbinsX()+1; i++)
59  {
60  double correction = BH_Residual_vsPhi_[k]->ProfileX()->GetBinContent(i); // This ultimately gives a y-value
61  double correction_PC = BH_Residual_vsPhi_PC_[k]->ProfileX()->GetBinContent(i);
62 
63  double xValue = BH_Residual_vsPhi_[k]->GetXaxis()->GetBinCenter(i);
64  double xValue_PC = BH_Residual_vsPhi_PC_[k]->GetXaxis()->GetBinCenter(i);
65 
66  for (int j=1; j< BH_Residual_vsPhi_[k]->GetNbinsY()+1; j++)
67  {
68  int getBin;
69  double content, yValue;
70 
71  getBin = BH_Residual_vsPhi_[k]->GetBin(i,j);
72  content = BH_Residual_vsPhi_[k]->GetBinContent(getBin);
73  yValue = BH_Residual_vsPhi_[k]->GetYaxis()->GetBinCenter(j);
74  BH_Residual_vsPhi_Corrected_[k]->Fill(xValue, yValue-correction, content); // "content" in this 2D histogram is the weight
75 
76  getBin = BH_Residual_vsPhi_PC_[k]->GetBin(i,j);
77  content = BH_Residual_vsPhi_PC_[k]->GetBinContent(getBin);
78  yValue = BH_Residual_vsPhi_PC_[k]->GetYaxis()->GetBinCenter(j);
79  BH_Residual_vsPhi_PC_Corrected_[k]->Fill(xValue_PC, yValue-correction_PC, content);
80  }
81  }
82  }
83 
84  for (int i=1; i<15; i++)
85  {
88  }
89 }
90 
91 TF1* GAUSS = 0;
92 
93 void TripleFit(TH2* hist)
94 {
95 
96  if (hist->Integral()<1000) { return; }
97 
98  TH1D* ProjectionY = hist->ProjectionY(); // Sums (cause that's what histograms do) all x-values along that particular y-value
99  double min = ProjectionY->GetBinCenter(1); // first bin is minimum (in Gauss tail)
100  double max = ProjectionY->GetBinCenter(ProjectionY->GetNbinsX()); // last bin is maximum (in Gauss tail)
101 
102  double amp = ProjectionY->GetBinContent(ProjectionY->GetMaximumBin());
103  double mean = ProjectionY->GetMean();
104  double sigma = ProjectionY->GetRMS();
105 
106  if (!GAUSS) { GAUSS = new TF1("GAUSS", "[0]*exp(-(x-[1])*(x-[1])/(2.0*[2]*[2]))", min, max); }
107 
108  for (int j=0; j<3; j++)
109  {
110  GAUSS->SetParameter(0,amp);
111  GAUSS->SetParameter(1,mean);
112  GAUSS->SetParameter(2,sigma);
113 
114  ProjectionY->Fit(GAUSS, "Q0", "", min, max);
115 
116  amp = ProjectionY->GetFunction("GAUSS")->GetParameter(0);
117  mean = ProjectionY->GetFunction("GAUSS")->GetParameter(1);
118  sigma = ProjectionY->GetFunction("GAUSS")->GetParameter(2);
119 
120  min = mean - 2.0*sigma;
121  max = mean + 2.0*sigma;
122  }
123 
124 
125  cout << "Name: " << hist->GetName();
126  cout << "\t Amp:" << amp;
127  cout << "\t Mean:" << mean;
128  cout << "\t Sigma:" << sigma;
129  cout << endl;
130 }
131