Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NoiseSimulator.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file NoiseSimulator.C
2 TH1D* BlobSigma;
4 TH1D* BlobPos;
5 TH1D* BlobCharge;
6 TF1* BlobFit;
7 TF1* NORMGAUSS;
8 
12 
16 
20 
21 void NoiseSimulator(int Nevent = 10000, double NOISE = 9)
22 {
23  gSystem->Load("libgroot");
24 
25  groot* Tree = groot::instance();
26 
27  double Minphi = 9999;
28  double Maxphi = -9999;
29  for (int i=0; i<128; i++)
30  {
31  if (Tree->ZigzagMap2[0][i])
32  {
33  double phi = Tree->ZigzagMap2[0][i]->PCenter();
34  if (phi < Minphi) Minphi = phi;
35  if (phi > Maxphi) Maxphi = phi;
36  }
37  }
38  double dPhi = fabs( Tree->ZigzagMap2[0][90]->PCenter() - Tree->ZigzagMap2[0][91]->PCenter() );
39  cout << dPhi << endl;
40  int NBINS = int( (Maxphi - Minphi)/dPhi + 1.5 );
41  cout << NBINS << endl;
42  double left = Minphi - 0.5*dPhi;
43  double right = Maxphi + 0.5*dPhi;
44  BlobFit = new TF1("BlobFit", "[0]*exp(-(x-[1])*(x-[1])/(2*[2]*[2]))", left, right);
45  BlobPos = new TH1D("BlobPos", "BlobPos", NBINS, left, right);
46  BlobSigma = new TH1D("BlobSigma", "BlobSigma", 250, 0.0, 8.0E-3);
47  BlobSigmaGen = new TH1D("BlobSigmaGen", "BlobSigmaGen", 250, 0.0, 8.0E-3);
48 
49  BlobPosition = new TH1D("BlobPosition", "BlobPosition", NBINS*10, left, right);
50  BlobCharge = new TH1D("BlobCharge", "BlobCharge", 256, 0, 2000);
51 
52  ChargeQuality = new TH2D("ChargeQuality", "ChargeQuality", 256, 0, 2000, 256, 0, 2000);
53  MeanQuality = new TH2D("MeanQuality", "MeanQuality", NBINS*10, left, right, NBINS*10, left, right);
54  SigmaQuality = new TH2D("SigmaQuality", "SigmaQuality", 250, 0.0, 8.0E-3, 250, 0.0, 8.0E-3);
55 
56  ChargeDiffBeforeNoise = new TH1D("ChargeDiffBeforeNoise", "ChargeDiffBeforeNoise", 300, -10, 10);
57  MeanDiffBeforeNoise = new TH1D("MeanDiffBeforeNoise", "MeanDiffBeforeNoise", 300, -dPhi, dPhi);
58  SigmaDiffBeforeNoise = new TH1D("SigmaDiffBeforeNoise", "SigmaDiffBeforeNoise", 300, -1e-4, 1e-4);
59 
60  ChargeDiffAfterNoise = new TH1D("ChargeDiffAfterNoise", "ChargeDiffAfterNoise", 300, -100, 100);
61  MeanDiffAfterNoise = new TH1D("MeanDiffAfterNoise", "MeanDiffAfterNoise", 300, -3e-4, 3e-4);
62  SigmaDiffAfterNoise = new TH1D("SigmaDiffAfterNoise", "SigmaDiffAfterNoise", 300, -3e-4, 3e-4);
63 
64  double sqrt2pi = 2.506628275;
65  NORMGAUSS = new TF1("NORMGAUSS", "[0]*0.00396825/([2]*2.506628275)*exp(-(x-[1])*(x-[1])/(2*[2]*[2]))", left, right);
66 
67  TRandom randy;
68 
69  double R5 = 467900.0; // microns
70 
71  // These are values at 17.5 inches...
72  //double BlobSigmaMean = 33.5e-4; // radians
73  //double BlobSigmaSigma = 4.1e-4*4.1/4.66; // radians
74 
75  // These are values at 14.0 inches...
76  //double BlobSigmaMean = 31.7e-4; // radians
77  //double BlobSigmaSigma = 3.5e-4*4.1/4.66; // radians
78 
79  // These are values at 10.0 inches...
80  //double BlobSigmaMean = 29.4e-4; // radians
81  //double BlobSigmaSigma = 3.0e-4*4.1/4.66; // radians
82 
83  // These are values at 4.0 inches...
84  double BlobSigmaMean = 25.1e-4; // radians
85  double BlobSigmaSigma = 2.0e-4*4.1/4.66; // radians
86 
87  double BlobLandauMPV = 326.8;
88  double BlobLandauSigma = 135.1;
89 
90  for (int i=0; i<Nevent; i++)
91  {
92  double MEAN = (left + 0.1*(right-left)) + 0.8*(right-left)*randy.Rndm();
93  BlobPosition->Fill(MEAN);
94 
95  double SIGMA = randy.Gaus(BlobSigmaMean, BlobSigmaSigma);
96  BlobSigmaGen->Fill(SIGMA); // radians
97 
98  double CHARGE = randy.Landau(BlobLandauMPV, BlobLandauSigma);
99  BlobCharge->Fill(CHARGE);
100 
101  NORMGAUSS->SetParameter(0,CHARGE);
102  NORMGAUSS->SetParameter(1,MEAN);
103  NORMGAUSS->SetParameter(2,SIGMA);
104 
105  for (int j=1; j<BlobPos->GetNbinsX()+1; j++)
106  {
107  double x = BlobPos->GetBinCenter(j);
108  double height = NORMGAUSS->Eval(x);
109  BlobPos->SetBinContent(j,height);
110  BlobPos->SetBinError(j,9.0);
111  }
112 
113  double max = BlobPos->GetMaximum();
114  double mean = BlobPos->GetBinCenter(BlobPos->GetMaximumBin());
115  double sigma = 0.003;
116  if (sigma < dPhi/3.0) sigma = dPhi/3.0;
117  if (sigma > 5.0*dPhi) sigma = 5.0*dPhi;
118 
119  BlobFit->SetParameter(0,max);
120  BlobFit->SetParameter(1,mean);
121  BlobFit->SetParameter(2,sigma);
122 
123  BlobFit->SetParLimits(0, max/2.0, 3.0*max);
124  BlobFit->SetParLimits(1, mean-1.0*dPhi, mean+1.0*dPhi);
125  BlobFit->SetParLimits(2, 0.0007, 0.0055);
126 
127  BlobPos->Fit(BlobFit,"Q0");
128 
129  double FITTEDCHARGE = BlobFit->GetParameter(0)*BlobFit->GetParameter(2)*sqrt2pi/dPhi;
130  double FITTEDMEAN = BlobFit->GetParameter(1);
131  double FITTEDSIGMA = BlobFit->GetParameter(2);
132 
133  ChargeQuality->Fill(CHARGE,FITTEDCHARGE);
134  MeanQuality->Fill(MEAN,FITTEDMEAN);
135  SigmaQuality->Fill(SIGMA,FITTEDSIGMA);
136 
137  ChargeDiffBeforeNoise->Fill(CHARGE-FITTEDCHARGE);
138  MeanDiffBeforeNoise->Fill(MEAN-FITTEDMEAN);
139  SigmaDiffBeforeNoise->Fill(SIGMA-FITTEDSIGMA);
140 
141  for (int j=1; j<BlobPos->GetNbinsX()+1; j++)
142  {
143  double oldheight = BlobPos->GetBinContent(j);
144  double newheight = oldheight + randy.Gaus(0,NOISE);
145  BlobPos->SetBinContent(j,newheight);
146  }
147 
148  max = BlobPos->GetMaximum();
149  mean = BlobPos->GetBinCenter(BlobPos->GetMaximumBin());
150  sigma = 0.003;
151  if (sigma < dPhi/3.0) sigma = dPhi/3.0;
152  if (sigma > 5.0*dPhi) sigma = 5.0*dPhi;
153 
154  BlobFit->SetParameter(0,max);
155  BlobFit->SetParameter(1,mean);
156  BlobFit->SetParameter(2,sigma);
157 
158  BlobFit->SetParLimits(0, max/2.0, 3.0*max);
159  BlobFit->SetParLimits(1, mean-1.0*dPhi, mean+1.0*dPhi);
160  BlobFit->SetParLimits(2, 0.0007, 0.0055);
161 
162  BlobPos->Fit(BlobFit,"Q0");
163 
164  double REFITTEDCHARGE = BlobFit->GetParameter(0)*BlobFit->GetParameter(2)*sqrt2pi;
165  double REFITTEDMEAN = BlobFit->GetParameter(1);
166  double REFITTEDSIGMA = BlobFit->GetParameter(2);
167 
168  ChargeDiffAfterNoise->Fill(CHARGE-REFITTEDCHARGE);
169  MeanDiffAfterNoise->Fill(MEAN-REFITTEDMEAN);
170  SigmaDiffAfterNoise->Fill(SIGMA-REFITTEDSIGMA);
171 
172  BlobSigma->Fill(REFITTEDSIGMA);
173 
174  }
175 
176 }