BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
ElectronWidget/ElectronCorrection.cc
Go to the documentation of this file.
2
4 m_constfilename("dEdxConstants.root"),
5 m_filename(""),
6 m_removeLowest(0.05),
7 m_removeHighest(0.25)
8{
10}
11
12
13ElectronCorrection::ElectronCorrection( TString constfilename, TString infilename, double removeLowest, double removeHighest ) :
14 m_constfilename(constfilename),
15 m_filename(infilename),
16 m_removeLowest(removeLowest),
17 m_removeHighest(removeHighest)
18{
20}
21
22
23void ElectronCorrection::process(TFile* outFile)
24{
25
26 TFile* dedxInput = new TFile(m_filename);
27 TTree* track = (TTree*)dedxInput->Get("track");
28
29 // --------------------------------------------------
30 // INITIALIZE CONTAINERS
31 // --------------------------------------------------
32
33 double dedxpub; // dE/dx without electron saturation correction
34 double dedx; // dE/dx truncated mean with electron saturation correction
35 double dedxerr; // dE/dx error with electron saturation correction
36 double mean; // dE/dx mean with electron saturation correction
37 double p; // track momentum
38 double bg; // track beta-gamma
39 double costh; // cosine of track polar angle
40 int nhits; // number of hits on this track
41
42 const int maxhits = 100;
43 int wire[maxhits]; // wire number of this hit
44 double dedxhit[maxhits]; // dE/dx for this hit
45
46 track->SetBranchAddress("mean", &mean);
47 track->SetBranchAddress("dedx", &dedxpub);
48 track->SetBranchAddress("dedxsat", &dedx);
49 track->SetBranchAddress("dedxerr", &dedxerr);
50 track->SetBranchAddress("pF", &p);
51 track->SetBranchAddress("costh", &costh);
52 track->SetBranchAddress("numGoodLayerHits", &nhits);
53 track->SetBranchAddress("wire", wire);
54 track->SetBranchAddress("dedxhit", dedxhit);
55
56 outFile->cd();
57 TTree* newtrack = track->CloneTree(0);
58
59 // --------------------------------------------------
60 // LOOP OVER EACH DEDX MEASUREMENT (TRACK LEVEL)
61 // --------------------------------------------------
62
63 for( unsigned int i = 0; i < track->GetEntries(); ++i ){
64 track->GetEvent(i);
65
66 if( nhits <= 0 ){
67 std::cout << "No good hits on this track...";
68 continue;
69 }
70
71
72 // --------------------------------------------------
73 // LOOP OVER EACH DEDX MEASUREMENT (HIT LEVEL)
74 // --------------------------------------------------
75
76 for (int j = 0; j < nhits; ++j) {
77 double newdedx = StandardCorrection(wire[j], costh, dedxhit[j]);
78 dedxhit[j] = newdedx;
79 } // end loop over hits
80
81 // recalculate means -> mean, dedx, and dedxerr will be replaced
82 std::cout << "MEANS = " << dedx << "\t";
83 calculateMeans(mean, dedx, dedxerr, dedxhit, nhits);
84 std::cout << dedx << std::endl << std::endl;
85
86 newtrack->Fill();
87 } // end loop over tracks
88
89 outFile->cd();
90 newtrack->AutoSave();
91 outFile->Close();
92 dedxInput->Close();
93}
94
95
97{
98
99 std::cout << "ElectronCorrection: initializing calibration constants..." << std::endl;
100
101 // For now just initialize the parameters to an arbitrary values for
102 // debugging. Eventually, this should get the constants from the
103 // calibration database.
104 m_runGain = 1.0;
105 for (int i = 0; i < c_NCDCWires; ++i) {
106 m_wireGain[i] = 1.0;
107 m_valid[i] = 1.0;
108 }
109
110 // get the hadron saturation parameters
111 // if the parameters do not exist, use the values in the default constructor
112 double hadpar[5];
113 std::ifstream parfile("sat-pars.txt");
114 if( !parfile.fail() ){
115 for( int i = 0; i < 5; ++i ){
116 parfile >> hadpar[i];
117 }
118 parfile.close();
119 m_hadsat.setParameters(hadpar);
120 }
121}
122
123
125{
126
127 if (m_runGain != 0) {
128 double newDedx = dedx / m_runGain;
129 return newDedx;
130 } else
131 return dedx;
132}
133
134double ElectronCorrection::WireGainCorrection(int wireID, double& dedx) const
135{
136
137 if (m_valid[wireID] && m_wireGain[wireID] != 0) {
138 double newDedx = dedx / m_wireGain[wireID];
139 return newDedx;
140 } else
141 return dedx;
142}
143
144
145double ElectronCorrection::HadronCorrection(double costheta, double dedx) const
146{
147
148 double newDedx = m_hadsat.D2I(costheta,m_hadsat.I2D(costheta,1.0)*dedx);
149 return newDedx;
150}
151
152
153double ElectronCorrection::StandardCorrection(int wireID, double costheta, double dedx) const
154{
155
156 double temp = dedx;
157
158 temp = RunGainCorrection(temp);
159
160 temp = WireGainCorrection(wireID, temp);
161
162 // temp = HadronCorrection(costheta, temp);
163
164 return temp;
165}
166
167
168void ElectronCorrection::calculateMeans(double &mean, double &truncatedMean, double &truncatedMeanErr,
169 double dedx[], int size) const
170{
171 // Calculate the truncated average by skipping the lowest & highest
172 // events in the array of dE/dx values
173 std::vector<double> sortedDedx;
174 for( int i = 0; i < size; ++i )
175 sortedDedx.push_back(dedx[i]);
176 std::sort(sortedDedx.begin(), sortedDedx.end());
177
178 double truncatedMeanTmp = 0.0;
179 double meanTmp = 0.0;
180 double sum_of_squares = 0.0;
181 int numValuesTrunc = 0;
182 const int numDedx = sortedDedx.size();
183 const int lowEdgeTrunc = int(numDedx * m_removeLowest);
184 const int highEdgeTrunc = int(numDedx * (1 - m_removeHighest));
185 for (int i = 0; i < numDedx; i++) {
186 std::cout << sortedDedx[i] << "+\t";
187 meanTmp += sortedDedx[i];
188 if (i >= lowEdgeTrunc and i < highEdgeTrunc) {
189 truncatedMeanTmp += sortedDedx[i];
190 sum_of_squares += sortedDedx[i] * sortedDedx[i];
191 numValuesTrunc++;
192 }
193 }
194 std::cout << std::endl;
195
196 if (numDedx != 0) {
197 meanTmp /= numDedx;
198 }
199 if (numValuesTrunc != 0) {
200 truncatedMeanTmp /= numValuesTrunc;
201 } else {
202 truncatedMeanTmp = meanTmp;
203 }
204
205 mean = meanTmp;
206 truncatedMean = truncatedMeanTmp;
207
208 if (numValuesTrunc > 1) {
209 truncatedMeanErr = sqrt(sum_of_squares / double(numValuesTrunc) - truncatedMeanTmp * truncatedMeanTmp) / double(numValuesTrunc - 1);
210 } else {
211 truncatedMeanErr = 0;
212 }
213}
214
215
216void ElectronCorrection::calculateMeans(double &mean, double &truncatedMean, double &truncatedMeanErr,
217 std::vector<double> dedx, int size) const
218{
219 // Calculate the truncated average by skipping the lowest & highest
220 // events in the array of dE/dx values
221 std::vector<double> sortedDedx = dedx;
222 std::sort(sortedDedx.begin(), sortedDedx.end());
223
224 double truncatedMeanTmp = 0.0;
225 double meanTmp = 0.0;
226 double sum_of_squares = 0.0;
227 int numValuesTrunc = 0;
228 const int numDedx = sortedDedx.size();
229 const int lowEdgeTrunc = int(numDedx * m_removeLowest);
230 const int highEdgeTrunc = int(numDedx * (1 - m_removeHighest));
231 for (int i = 0; i < numDedx; i++) {
232 std::cout << sortedDedx[i] << "+\t";
233 meanTmp += sortedDedx[i];
234 if (i >= lowEdgeTrunc and i < highEdgeTrunc) {
235 truncatedMeanTmp += sortedDedx[i];
236 sum_of_squares += sortedDedx[i] * sortedDedx[i];
237 numValuesTrunc++;
238 }
239 }
240 std::cout << std::endl;
241
242 if (numDedx != 0) {
243 meanTmp /= numDedx;
244 }
245 if (numValuesTrunc != 0) {
246 truncatedMeanTmp /= numValuesTrunc;
247 } else {
248 truncatedMeanTmp = meanTmp;
249 }
250
251 mean = meanTmp;
252 truncatedMean = truncatedMeanTmp;
253
254 if (numValuesTrunc > 1) {
255 truncatedMeanErr = sqrt(sum_of_squares / double(numValuesTrunc) - truncatedMeanTmp * truncatedMeanTmp) / double(numValuesTrunc - 1);
256 } else {
257 truncatedMeanErr = 0;
258 }
259}
const int c_NCDCWires
void calculateMeans(double &mean, double &truncatedMean, double &truncatedMeanErr, double dedx[], int size) const
double RunGainCorrection(double &dedx) const
double StandardCorrection(int wireID, double costheta, double dedx) const
double WireGainCorrection(int wireID, double &dedx) const
double HadronCorrection(double costheta, double dedx) const
double I2D(double cosTheta, double I, double alpha, double gamma, double delta, double power, double ratio) const
double D2I(double cosTheta, double D, double alpha, double gamma, double delta, double power, double ratio) const
void setParameters(double par[])
int nhits
float costheta
float bg