ROOT35. 波形分析分析代码
void ana(){
//1. create a TFile file
//2. create a TTree tree
//3. define (1) timestamp, (2) time, (3) ch1, (4) ch2, (5) flag_coin
//4. read the raw data
//5. save data to tree/file
const int N = 200;
double timestamp = 0.0;
bool flag_coincident;
vector<double> vtime;
vector<double> channel1;
vector<double> channel2;
double tempT, tempC1, tempC2;
TFile *ofile = new TFile( "WFM.root", "recreate" );
TTree *tree = new TTree( "WFM", "ep annihilation waveform" );
tree->Branch( "TimeStamp", ×tamp, "TimeStamp/D" );
tree->Branch("Time", &vtime);
tree->Branch("Channel1", &channel1);
tree->Branch("Channel2", &channel2);
tree->Branch("Flag_Coincident", &flag_coincident, "Flag_Coincident/B");
cout << "start reading" << endl;
string filename;
std::ifstream read;
// j is file id
for( int j=1; j<20001; j++ ){
filename = Form( "./waveforms/WFM%05d.txt", j );
read.open( filename.c_str() );
// assign value to branches
read >> timestamp;
for( int i=0; i<N; i++ ){
read >> tempT >> tempC1 >> tempC2;
vtime.push_back( tempT );
channel1.push_back( tempC1 );
channel2.push_back( tempC2 );
}
// check whether it is an annihilation event
auto c2minimum = std::min_element( channel2.begin(), channel2.end() );
int c2miniID = std::distance( channel2.begin(), c2minimum );
if ( 95<c2miniID && c2miniID <105 ){ flag_coincident = 1; }
else{ flag_coincident = 0; }
tree->Fill();
vtime.clear();
channel1.clear();
channel2.clear();
read.close();
}
tree->Write();
ofile->Close();
cout << "end reading" << endl;
}