18 std::cout <<
"WidgetGenerator: generating " << m_nevents <<
" particles of mass " << genmass << std::endl;
19 std::cout << m_upperbg <<
"\t" << m_lowerbg << std::endl;
33 double dedx_cur, dedx_res;
36 TFile* genfile =
new TFile(filename,
"CREATE");
37 TTree* gentree =
new TTree(
"track",
"Fake track sample");
39 gentree->Branch(
"dedx",&dedxpub,
"dedx/D");
40 gentree->Branch(
"dedxcur",&dedx_cur,
"dedxcur/D");
41 gentree->Branch(
"dedxres",&dedx_res,
"dedxres/D");
42 gentree->Branch(
"dedxsat",&dedx,
"dedxsat/D");
43 gentree->Branch(
"pF",&p,
"pF/D");
44 gentree->Branch(
"bg",&
bg,
"bg/D");
45 gentree->Branch(
"costh",&costh,
"costh/D");
46 gentree->Branch(
"db",&db,
"db/D");
47 gentree->Branch(
"dz",&dz,
"dz/D");
48 gentree->Branch(
"chiPi",&chiPi,
"chiPi/D");
49 gentree->Branch(
"numGoodHits",&nhit,
"numGoodHits/D");
50 gentree->Branch(
"eopst",&eop,
"eopst/D");
52 TH2F* dedx_costh =
new TH2F(
"dedx_costh",
"dE/dx vs. cos(#theta);cos(#theta);dE/dx",
53 100,-1.0,1.0,100,0.0,10.0);
54 TH2F* dedx_bg =
new TH2F(
"dedx_bg",
"dE/dx vs. #beta#gamma;#beta#gamma;dE/dx",
55 100,m_lowerbg,m_upperbg,100,0.0,10.0);
60 TRandom *r0 =
new TRandom();
65 std::cout <<
"WidgetGenerator::ERROR - please input non-zero particle mass" << std::endl;
69 double mass = genmass;
71 massvec[0] = Widget::mpion;
72 massvec[1] = Widget::mkaon;
73 massvec[2] = Widget::mproton;
74 massvec[3] = Widget::mmuon;
75 massvec[4] = Widget::melectron;
78 for(
int i = 0; i < m_nevents; ++i ){
80 bg = r0->Rndm(i)*(m_upperbg+m_lowerbg)+m_lowerbg;
81 while( bg < m_lowerbg || bg > m_upperbg )
82 bg = r0->Rndm(i)*(m_upperbg+m_lowerbg)+m_lowerbg;
85 costh = 2*(r0->Rndm(i))-1;
86 while( costh < -1.0 || costh > 1.0 )
87 costh = 2*(r0->Rndm(i))-1;
91 chiPi = r0->Gaus(1.0);
95 if(
mass == Widget::melectron ||
mass == Widget::mmuon ) dedx_res = 0.05;
98 dedx = r0->Gaus(hadsat.
I2D(costh,dedx_cur)/hadsat.
I2D(costh,1.0),dedx_res/3.0);
106 dedx_costh->Fill(costh,dedx);
107 dedx_bg->Fill(
bg,dedx);
123 TFile* infile =
new TFile(infilename);
124 TTree* intree = (TTree*)infile->Get(
"track");
126 double dedx,
bg, costh, p;
127 intree->SetBranchAddress(
"p",&p);
128 intree->SetBranchAddress(
"costh",&costh);
131 TFile* outfile =
new TFile(outfilename,
"CREATE");
132 TTree* tracks =
new TTree(
"track",
"Fake track sample");
133 tracks->Branch(
"dedxsat",&dedx,
"dedxsat/D");
134 tracks->Branch(
"p",&p,
"p/D");
135 tracks->Branch(
"costh",&costh,
"costh/D");
137 TH2F* dedx_costh =
new TH2F(
"dedx_costh",
"dE/dx vs. cos(#theta);cos(#theta);dE/dx",
138 100,-1.0,1.0,100,0.0,10.0);
139 TH2F* dedx_bg =
new TH2F(
"dedx_bg",
"dE/dx vs. #beta#gamma;#beta#gamma;dE/dx",
140 100,m_lowerbg,m_upperbg,100,0.0,10.0);
144 TRandom *r0 =
new TRandom();
148 double mass = genmass;
150 massvec[0] = Widget::mpion;
151 massvec[1] = Widget::mkaon;
152 massvec[2] = Widget::mproton;
153 massvec[3] = Widget::mmuon;
154 massvec[4] = Widget::melectron;
157 for(
int i = 0; i < intree->GetEntries(); ++i ){
161 std::cout <<
"Event " << i <<
": p = " << p <<
", cos(theta) = " << costh << std::endl;
163 if( genmass == 0 )
mass = massvec[i%5];
167 dedx = r0->Gaus(hadsat.
I2D(costh,0.8)/hadsat.
I2D(costh,1.0),0.05);
169 dedx = r0->Gaus(hadsat.
I2D(costh,0.8)/hadsat.
I2D(costh,1.0),0.05);
171 dedx_costh->Fill(costh,dedx);
172 dedx_bg->Fill(
bg,dedx);
188 TFile* infile =
new TFile(infilename);
189 TTree* intree = (TTree*)infile->Get(
"track");
192 double dedxhit[100], adcraw[100], path[100];
193 intree->SetBranchAddress(
"dedxhit",dedxhit);
194 intree->SetBranchAddress(
"adcraw",adcraw);
195 intree->SetBranchAddress(
"path",path);
197 double layer[100], layerdedx[100], layerdx[100];
198 intree->SetBranchAddress(
"layer",layer);
199 intree->SetBranchAddress(
"layerdx",layerdx);
200 intree->SetBranchAddress(
"layerdedx",layerdedx);
202 double mean, dedx, dedxerr, costh;
203 intree->SetBranchAddress(
"numLayerHits",&
nhits);
204 intree->SetBranchAddress(
"mean",&mean);
205 intree->SetBranchAddress(
"dedx",&dedx);
206 intree->SetBranchAddress(
"dedxerr",&dedxerr);
207 intree->SetBranchAddress(
"costh",&costh);
210 TFile* outfile =
new TFile(outfilename,
"CREATE");
211 TTree* tracks = intree->CloneTree(0);
213 double newdedxhit[100];
214 double newmean, newdedx, newerr;
215 tracks->Branch(
"newmean",&newmean,
"newmean/D");
216 tracks->Branch(
"newdedx",&newdedx,
"newdedx/D");
217 tracks->Branch(
"newerr",&newerr,
"newerr/D");
219 for(
int i = 0; i < intree->GetEntries(); ++i ){
223 newmean = 0; newdedx = 0; newerr = 0;
226 std::vector<double> sortedDedx;
227 for(
int j = 0; j <
nhits; ++j ){
228 sortedDedx.push_back(layerdedx[j]);
230 std::sort(sortedDedx.begin(), sortedDedx.end());
233 int lb = int(
nhits * 0.05 + 0.5);
234 int ub = int(
nhits * 0.75 + 0.5);
236 for(
int j = 0; j <
nhits; ++j ){
237 newmean += sortedDedx[j];
238 if( j >= lb && j < ub ){
239 newdedx += sortedDedx[j];
240 newerr += sortedDedx[j]*sortedDedx[j];
246 if( ntrunc != 0 ) newdedx /= ntrunc;
247 else newdedx = newmean;
249 if( ntrunc > 1 ) newerr = sqrt(newerr/ntrunc - newdedx*newdedx)/(ntrunc-1);
double I2D(double cosTheta, double I, double alpha, double gamma, double delta, double power, double ratio) const