31static int histNum = 0;
33int find_bgidx(
int type,
double bgg,
double bg_min,
double bg_step,
int nbin);
34double find_boundary(
int type,
int idx,
double bg_min,
double bg_step);
36void histgen(
string,
int, TObjArray&, vector<double>&);
41TFile *
f_temp =
new TFile(
"temp.root",
"recreate");
44 std::cout <<
"in main()" << std::endl;
49 std::cout <<
"before histgen" << std::endl;
51 std::cout <<
"hadron hists has been generated" << std::endl;
54 std::cout <<
"muon hists has been generated" << std::endl;
57 std::cout <<
"electron hists has been generated" << std::endl;
60 string filename =
"DedxSampleHists.root";
61 TFile*
f =
new TFile(filename.c_str(),
"recreate");
63 int total = histCol.GetLast() + 1;
64 int bg_num =
bg.size();
65 if(
m_debug) cout <<
"total: " << total <<
" bg num = " << bg_num << endl;
66 double betagamma[3000];
67 for (
unsigned int i = 0; i <
bg.size(); i++) betagamma[i] =
bg[i];
69 TTree*
t =
new TTree(
"bin",
"bin information");
70 t->Branch(
"totalNum", &total,
"total/I");
71 t->Branch(
"betagammaBounds", &bg_num,
"bg_num/I");
72 t->Branch(
"betagamma", betagamma,
"betagamma[bg_num]/D");
76 std::cout <<
"begin write hists" << std::endl;
77 for (
int i=0; i<total; i++){
78 if(i%100==0) cout <<
"i: " << i <<
" histogram is written now" << endl;
79 ((TH1F*)histCol[i])->Write();
81 std::cout <<
"write hists finish" << std::endl;
92int find_bgidx(
int type,
double bgg,
double bg_min,
double bg_step,
int nbin){
94 for(
int i=0; i<=nbin; i++){
97 cout <<
"not found correct bgidx, something is wrong!" << endl;
100 else return((
int)(bgg-bg_min)/bg_step);
106 else return(bg_min + bg_step*idx);
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++){
249 TFile
f(name.c_str());
250 TTree*
t = (TTree*)
f.Get(
"bin");
252 t->SetBranchAddress(
"totalNum", &total);
253 t->SetBranchAddress(
"betagammaBounds", &bgb);
257 TCanvas c1(
"c1",
"canvas", 800, 600);
258 c1.Print((name +
".ps[").c_str());
259 for (Int_t i = 0; i < total; i++) {
260 if(i%100==0) cout <<
"i: " << i <<
" ps is written now" << endl;
263 h = (TH1F*)
f.Get(ss.str().c_str());
265 c1.Print((name +
".ps").c_str());
267 c1.Print((name +
".ps]").c_str());
273 TH1F *h1 =
new TH1F();
274 TTree *tree =
new TTree(
"TH1F_Col",
"TH1F_Col");
275 tree->Branch(
"TH1F_Col",
"TH1F", &h1, 3200, 0);
276 TFile*
f1 =
new TFile(
"DedxSampleHists.root",
"UPDATE");
277 TTree*
bin = (TTree*)
f1->Get(
"bin");
279 bin->SetBranchAddress(
"totalNum", &totNum);
282 for (Int_t i = 0; i < totNum; i++){
283 if(i >= 10000)
sprintf(hname,
"h%05d", i);
284 if(i >= 1000)
sprintf(hname,
"h%04d", i);
285 if(i >= 100)
sprintf(hname,
"h%03d", i);
286 if(i >= 10)
sprintf(hname,
"h%02d", i);
287 if(i < 10)
sprintf(hname,
"h%01d", i);
288 h1 = (TH1F*)
f1->Get(hname);
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)
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
*******INTEGER m_nBinMax INTEGER m_NdiMax !No of bins in histogram for cell exploration division $ !Last vertex $ !Last active cell $ !Last cell in buffer $ !No of sampling when dividing cell $ !No of function total $ !Flag for random ceel for $ !Flag for type of for WtMax $ !Flag which decides whether vertices are included in the sampling $ entire domain is hyp !Maximum effective eevents per bin
DOUBLE_PRECISION count[3]
double vec_bg_hadron[bg_hadron_bin+1]
void t_to_h(TTree *t, TH1F *h)
double find_boundary(int type, int idx, double bg_min, double bg_step)
const double electron_step
void histgen(string, int, TObjArray &, vector< double > &)
const bool ps_flag(false)
int find_bgidx(int type, double bgg, double bg_min, double bg_step, int nbin)