Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ABlob.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ABlob.C
1 #include "ABlob.h"
2 #include "AZigzag.h"
3 #include <iostream>
4 
5 #include "groot.h"
6 
7 #include "TH1D.h"
8 #include "TF1.h"
9 
10 #include "TMarker.h"
11 
12 using namespace std;
13 
14 bool ABlob::RecalibrateCharge = true;
15 bool ABlob::GaussPosition = false;
16 TH1* ABlob::BlobPos = 0;
17 TH1* ABlob::BlobSigma = 0;
18 TF1* ABlob::BlobFit = 0;
19 
20 ABlob::ABlob(std::vector<AZigzag*> MANYZIGZAGS)
21 {
22  manyZigs = MANYZIGZAGS;
23 
24  correctedq = 0;
25  correctedcentroid = 0;
26 
27  if (RecalibrateCharge) FixTheCharges();
28 
29  Precalc_PHI = GetPHI();
30  Precalc_R = manyZigs[0]->RCenter();
31 }
32 
33 
34 double ABlob::CentroidX() { return Precalc_R * cos(Precalc_PHI); }
35 
36 double ABlob::CentroidY() { return Precalc_R * sin(Precalc_PHI); }
37 
38 double ABlob::CentroidR() { return Precalc_R; }
39 
40 double ABlob::CentroidP() { return Precalc_PHI; }
41 
42 double ABlob::maxT() { return manyZigs[0]->T(); } //time of zigzag with the max charge
43 
44 
45 double ABlob::Q()
46 {
47  double den = 0;
48  for(int i=0; i<manyZigs.size(); i++)
49  {
50  den += manyZigs[i]->Q();
51  }
52 
53  return den;
54 }
55 
57 {
58  if (Q() == 0)
59  {
60  cout << "ABlob:: Error: Blob has zero total charge...no Z centroid" << endl;
61  return -9999;
62  }
63 
64  double num = 0;
65  for(int i=0; i<manyZigs.size(); i++)
66  {
67  num += manyZigs[i]->Q() * manyZigs[i]->ZCenter();
68  }
69 
70  return num/Q();
71 }
72 
73 
74 double ABlob::GetPHI() //Angle Phi
75 {
76  if (Q() == 0)
77  {
78  cout << "ABlob:: Error: Blob has zero total charge...no Phi centroid" << endl;
79  return -9999;
80  }
81 
82  if (!GaussPosition)
83  {
84  double num = 0;
85  for(int i=0; i<manyZigs.size(); i++)
86  {
87  num += manyZigs[i]->Q() * manyZigs[i]->PCenter();
88  }
89 
90  return num/Q();
91  }
92  else
93  {
94  groot* Tree = groot::instance();
95  if (!BlobPos)
96  {
97  double Minphi = 9999;
98  double Maxphi = -9999;
99  for (int i=0; i<Nphi; i++)
100  {
101  if (Tree->ZigzagMap2[0][i])
102  {
103  double phi = Tree->ZigzagMap2[0][i]->PCenter();
104  if (phi < Minphi) Minphi = phi;
105  if (phi > Maxphi) Maxphi = phi;
106  }
107  }
108  double dPhi = abs( Tree->ZigzagMap2[0][90]->PCenter() - Tree->ZigzagMap2[0][91]->PCenter() );
109  int NBINS = int( (Maxphi - Minphi)/dPhi + 1.5 );
110  double left = Minphi - 0.5*dPhi;
111  double right = Maxphi + 0.5*dPhi;
112 
113  BlobPos = new TH1D("BlobPos", "BlobPos", NBINS, left, right);
114  BlobSigma = new TH1D("BlobSigma", "BlobSigma", 250, 0.0, 8.0E-3);
115  BlobFit = new TF1("BlobFit", "[0]*exp(-(x-[1])*(x-[1])/(2*[2]*[2]))", left, right);
116  Tree->theHistograms.push_back(BlobSigma);
117  }
118 
119  BlobPos->Reset();
120 
121  for(int i=0; i<manyZigs.size(); i++)
122  {
123  double phi = manyZigs[i]->PCenter();
124  double Q = manyZigs[i]->Q();
125  BlobPos->Fill(phi,Q);
126  }
127 
128  for (int i=1; i<=BlobPos->GetNbinsX(); i++)
129  {
130  BlobPos->SetBinError( i, 9.0 );
131  }
132 
133  double dPhi = abs( Tree->ZigzagMap2[0][90]->PCenter() - Tree->ZigzagMap2[0][91]->PCenter() );
134  double max = BlobPos->GetMaximum();
135  double mean = manyZigs[0]->PCenter();
136  double sigma = 0.003;
137  if (sigma < dPhi/3.0) sigma = dPhi/3.0;
138  if (sigma > 5.0*dPhi) sigma = 5.0*dPhi;
139 
140  BlobFit->SetParameter(0,max);
141  BlobFit->SetParameter(1,mean);
142  BlobFit->SetParameter(2,sigma);
143 
144  BlobFit->SetParLimits(0, max/2.0, 3.0*max);
145  BlobFit->SetParLimits(1, mean-1.0*dPhi, mean+1.0*dPhi);
146  BlobFit->SetParLimits(2, 0.0007, 0.0055);
147 
148  BlobPos->Fit(BlobFit,"Q0");
149 
150  BlobSigma->Fill(BlobFit->GetParameter(2));
151 
152  return BlobFit->GetParameter(1);;
153  }
154 }
155 
157 {
158  // color zigzag according to charge fraction of total deposited charge
159  int shape = 8;
160  double X = CentroidX();
161  double Y = CentroidY();
162 
163  TMarker* ablob = new TMarker(X,Y,shape);
164 
165  ablob->SetMarkerSize(1);
166  ablob->SetMarkerColor(6);
167 
168  ablob->Draw();
169 }
170 
172 {
173  //cout << "~~BLOB REPORT~~" << endl;
174  //cout << "Q:" << Q();
175  //cout << " \tX:" << CentroidX();
176  //cout << " \tY:" << CentroidY();
177  //cout << " \tZ:" << CentroidZ();
178  cout << " \tR:" << CentroidR();
179  cout << " \tP:" << CentroidP();
180  //cout << " \tT:" << maxT();
181  //cout << " \tsize:" << manyZigs.size();
182  cout << endl;
183 }
184 
186 {
187  // This routine is an attempt to improve the values of charge
188  // from the "edge" zigzags of the blob. It is premised upon the
189  // following assumptions:
190  //
191  // 1) When the charge hit is big, the Zigzag does a fine job
192  // of determining both Q and T.
193  // 2) When the charge hit is small, the fit can be drawn away
194  // from the correct Q by following a fluctuation at the wrong
195  // time.
196  // 3) Since every blob should have the same time for all zigzags,
197  // we can pull a trick for the outlying pads as follows:
198  // a: Determine a reference time by accessing the time from the
199  // pad with the most charge.
200  // b: Perform a NEW FIT of the charge on every pad by restricting
201  // the time fit range to be "near" to that of the reference time.
202  //
203  // In this way outlier pads will always use the "in time" charge instead
204  // of the "highest found" charge and hopefully improve the overall
205  // blob position resolution.
206  //
207  // TKH 10/10/2018
209 
210  double Reftime = maxT();
211  double Mintime = Reftime - 2.0;
212  double Maxtime = Reftime + 2.0;
213 
214  for(int i=0; i<manyZigs.size(); i++)
215  {
216  manyZigs[i]->DetermineQ(Mintime,Maxtime);
217  }
218 
219 }