BOSS 7.0.5
BESIII Offline Software System
Loading...
Searching...
No Matches
prepare_data.cxx
Go to the documentation of this file.
1/* 1) This program is to collect all types of particles in an uniform style (dE/dx, angle, beta-gamma)
2 Output the data to a preliminary.root file
3 2) Also do a coarse region devision, the results should be output to a preliminary.txt file
4 with other additional information
5*/
6#include "TCanvas.h"
7#include "TFile.h"
8//#include "TKey.h"
9#include "TTree.h"
10#include "TH1F.h"
11//#include <TROOT.h>
12#include <sstream>
13#include <iostream>
14#include <string>
15#include <cstring>
16#include <vector>
17#include <cmath>
18#include "TCut.h"
19
20using namespace std;
21
22#define mass_e 0.511e-3
23#define mass_mu 105.658e-3
24#define mass_pi 139.570e-3
25#define mass_k 493.677e-3
26#define mass_p 938.272e-3
27
28float ptrk, dEdx_meas, costheta, charge, bg, mass; // bg means beta-gamma
30float dEdx_hit[100];
31void collect(TString filename, int type, TTree *tree);
32void setregion();
33
34int main(){
35 TFile *f = new TFile("pre_data.root","recreate");
36 TTree *t = new TTree("n103","predata");
37 t->Branch("dEdx_meas", &dEdx_meas, "dEdx_meas/f");
38 t->Branch("costheta", &costheta, "costheta/f");
39 t->Branch("charge", &charge, "charge/f");
40 t->Branch("bg", &bg, "bg/f");
41 t->Branch("nhits", &nhits, "nhits/I");
42 t->Branch("dEdx_hit", dEdx_hit, "dEdx_hit[nhits]/f");
43
44 // collect all data here
45 cout << "begin to collect data" << endl;
46 collect("../hadron_track/proton/proton.root", 0, t);
47 cout << "proton collected" << endl;
48 collect("../hadron_track/kaon/kaon.root", 1, t);
49 cout << "kaon collected" << endl;
50 collect("../hadron_track/pion/pion.root", 2, t);
51 cout << "pion collected" << endl;
52 collect("../hadron_track/muon/muon.root", 3, t);
53 cout << "muon collected" << endl;
54 collect("../hadron_track/electron/electron.root", 4, t);
55 cout << "electron collected" << endl;
56
57 f->cd();
58 t->Write();
59 f->Close();
60
61 // setregion();
62
63 return 0;
64}
65
66void collect(TString filename, int type, TTree *t){
67 TFile *ff = new TFile(filename);
68 TTree* trk = (TTree*)ff->Get("n103");
69 trk->SetBranchAddress("dEdx_meas", &dEdx_meas);
70 trk->SetBranchAddress("ptrk", &ptrk);
71 trk->SetBranchAddress("costheta", &costheta);
72 trk->SetBranchAddress("charge", &charge);
73 trk->SetBranchAddress("ndedxhit", &nhits);
74 trk->SetBranchAddress("dEdx_hit", dEdx_hit);
75
76 //initialize variables
77 switch (type) {
78 case 0:
79 mass = mass_p;
80 break;
81 case 1:
82 mass = mass_k;
83 break;
84 case 2:
85 mass = mass_pi;
86 break;
87 case 3:
88 mass = mass_mu;
89 break;
90 case 4:
91 mass = mass_e;
92 break;
93 default:
94 cout << "Error: no such sample type!" << endl;
95 }
96
97 int m_ntot = trk->GetEntries();
98 // if(m_ntot>500000) m_ntot = 500000;
99 for (int i = 0; i < m_ntot; i++){
100 trk->GetEntry(i);
101 if (type == 0 && dEdx_meas < 500) continue; // type 0 is proton!
102 if (type == 4 && dEdx_meas > 1200) continue; // type 4 is electron!
103 if(ptrk <= 0 || ptrk > 2.3) continue;
104 if(fabs(costheta) >= 0.93) continue;
105 bg = ptrk/mass;
106 t->Fill();
107 }
108 ff->Close();
109}// end of collect()
110
111void setregion(){ // use greedy algorithm, step by step to check
112 TFile *f = new TFile("pre_data.root");
113 TTree *t = (TTree*)f->Get("n103");
114 bool small_flag(true);
115 double step(0.1); // for beta-gamma
116 double current(0.0); // current position in beta-gamma
117 int accu(0); // accumulated events
118 double stop(4600);
119 int threshold(1000);
120 while(current<stop){
121 cout << "now: " << current << endl;
122 if(small_flag){
123 accu = t->GetEntries(Form("bg>=%f && bg<%f", current, current+step));
124 current += step;
125 if(accu > threshold){
126 cout << "point: " << current << " events: " << accu << endl;
127 small_flag = false;
128 }
129 }// end of if(small_flag)
130 else{
131 accu = t->GetEntries(Form("bg>=%f && bg<%f", current, current+step));
132 current += step;
133 if(accu < threshold){
134 cout << "point: " << current << " events: " << accu << endl;
135 small_flag = true;
136 }
137 }// end of else(small_flag)
138 }// end of while
139 f->Close();
140}
********INTEGER modcns REAL m_twom24 INTEGER m_ntot
Definition: PseuMar.h:14
TTree * t
Definition: binning.cxx:23
TFile f("ana_bhabha660a_dqa_mcPat_zy_old.root")
int nhits
float costheta
float charge
#define mass_mu
#define mass_e
float mass
void setregion()
#define mass_p
float dEdx_meas
#define mass_k
float bg
void collect(TString filename, int type, TTree *tree)
#define mass_pi
int main()
float ptrk
float dEdx_hit[100]