111 vector<double> vec_dedx(0);
113 t->SetBranchAddress(
"dedx_hit", &m_dedx);
114 for(
int i=0; i<
t->GetEntries(); i++){
116 vec_dedx.push_back(m_dedx);
118 sort(vec_dedx.begin(), vec_dedx.end());
120 int step =
t->GetEntries()/100;
121 int rad =
t->GetEntries()%100;
124 points[0] = vec_dedx.front();
125 if(
m_debug) cout <<
"points[0] " << points[0] << endl;
126 for(
unsigned int i=0; i<vec_dedx.size(); i++){
129 points[sum] = (vec_dedx[i]+vec_dedx[i+1])/2;
133 if(
m_debug) cout <<
"i= " << i <<
" rad " <<
rad <<
" step " << step <<
" count " <<
count <<
" sum " << sum-1 <<
" point " << points[sum-1] << endl;
136 points[100] = vec_dedx.back();
138 double points_mod[111];
139 for(
int j=0; j<111; j++){
140 if(j<11) points_mod[j] = points[1]/11.*j;
141 else points_mod[j] = points[j-10];
142 if(
m_debug) cout <<
"j= " << j <<
" modified point " << points_mod[j] << endl;
144 h->SetBins(110, points_mod);
145 t->Project(h->GetName(),
"dedx_hit");
149void histgen(
string filename,
int type, TObjArray& hist, vector<double>&
bg){
153 double bg_min, bg_max, bg_step;
155 TFile*
f =
new TFile(filename.c_str());
156 TTree* trk = (TTree*)
f->Get(
"n103");
157 trk->SetBranchAddress(
"dEdx_meas", &
dEdx_meas);
158 trk->SetBranchAddress(
"bg", &bgg);
159 trk->SetBranchAddress(
"costheta", &
costheta);
160 trk->SetBranchAddress(
"charge", &
charge);
161 trk->SetBranchAddress(
"dEdx_hit", exraw);
162 trk->SetBranchAddress(
"nhits", &ndedxhit);
182 std::cout <<
"Error: no such sample type!" << std::endl;
187 TH1F** h =
new TH1F*[nbin * 2 *
na];
188 TTree**
t =
new TTree*[nbin * 2 *
na];
189 stringstream ss, sst;
191 for (
int i = 0; i < nbin * 2 *
na; i++){
192 ss.str(
""); sst.str(
"");
193 ss <<
"h" << histNum + i; sst <<
"t" << histNum + i;
194 h[i] =
new TH1F(ss.str().c_str(), ss.str().c_str(), 1, 0, 1);
196 t[i] =
new TTree(sst.str().c_str(), sst.str().c_str());
197 t[i]->Branch(
"dedx_hit", &m_dedx_hit,
"dedx_hit/D");
199 histNum += nbin*2*
na;
202 int bgidx(-1), angleidx(-1), chargeidx(-1), treeidx(-1);
204 for (
int i = 0; i < trk->GetEntries(); i++){
206 if(bgg<bg_min || bgg>bg_max)
continue;
210 bg_step = (bg_max-bg_min)/nbin;
211 bgidx =
find_bgidx(type, bgg, bg_min, bg_step, nbin);
212 if(bgidx<0 || bgidx>=nbin)
continue;
216 if(angleidx<0 || angleidx>=
na)
continue;
219 if (
charge == 0)
continue;
220 else chargeidx = (
charge > 0) ? 0 : 1;
225 for (
int j = 0; j <ndedxhit; j++) {
227 treeidx = bgidx*
na*2 + angleidx*2 + chargeidx;
228 m_dedx_hit = exraw[j];
230 if(m_dedx_hit>0 && m_dedx_hit<500000)
t[treeidx]->Fill();
236 for (
int i = 0; i < nbin *
na *
nc; i++){
237 if(
t[i]->GetEntries()<1000) cout <<
"i " << i <<
" no." <<
t[i]->GetEntries() << endl;
241 for (
int i = 0; i < nbin; i++){
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)