ROOT34, 產(chǎn)生數(shù)據(jù)的腳本
// signal detected by detector 1
double detector1( double time, double offset=0.5 ){
?if( time < offset ){ return (gRandom->Uniform()-0.5)*0.06; ?}
?else{ return -0.3*exp( -(time-offset)/0.05 ) ? (gRandom->Uniform()-0.5)*0.06; ?}
}
// signal detected by detector 2
double detector2( double time, double offset=0.5 ){
?if( time < offset ){ return (gRandom->Uniform()-0.5)*0.06; ?}
?else{ return -0.3*exp( -(time-offset)/0.05 ) ? (gRandom->Uniform()-0.5)*0.06; ?}
}
// generate wave, assign values of D1 and D2 to array
const int N = 200;
const double offset1 = 0.5;
double offset2 = 0.5;
void generateWFM( double* time, double* ch1, double* ch2, bool flag_coin=true ?){
?if( flag_coin==true ){ ?offset2 = 0.5 ? ?(gRandom->Uniform()-0.5)*0.05;}
?else{ offset2 = offset2 = (gRandom->Uniform()); }
?for( int i=0; i<N; i ? ){
time[i] = (double)i*0.005;
? ?ch1[i] = detector1( time[i], offset1 );
? ?ch2[i] = detector2( time[i], offset2 );
?} ?
}
// plot the wave form
int gd(){
?double timeStamp1 = 1;
?double timeStamp2 = 1;
?timeStamp1 = gRandom->Exp( 2.2 );
?timeStamp2 = gRandom->Uniform()*10;
?double time[N], ch1[N], ch2[N];
?generateWFM( time, ch1, ch2, true );
?
?TCanvas *c1 = new TCanvas( "c1", "on and off", 1200, 500 );
?c1->Divide( 2, 1 );
?c1->cd(1);
?TGraph *g1c1 = new TGraph( N, time, ch1);
?TGraph *g1c2 = new TGraph( N, time, ch2);
?g1c2->SetLineColor( kRed );
?g1c1->SetTitle( Form("Coincident Event, TimeStamp = %f", timeStamp1) );
?g1c1->GetXaxis()->SetTitle( "Time [ns]" );
?g1c1->GetYaxis()->SetTitle( "Wave Form" );
?g1c1->GetYaxis()->SetRangeUser(-0.4, 0.1);
?g1c1->Draw("ALP");
?g1c2->Draw("same");
?
?TLegend *leg1 = new TLegend();
?leg1->AddEntry( g1c1, "Channel 1 (trigger)" );
?leg1->AddEntry( g1c2, "Channel 2" );
?leg1->Draw( "same" );
?
?
?c1->cd(2);
?generateWFM( time, ch1, ch2, false );
?TGraph *g2c1 = new TGraph( N, time, ch1);
?TGraph *g2c2 = new TGraph( N, time, ch2);
?g2c1->SetTitle( Form("Anti-Coincident Event, TimeStamp = %f", timeStamp2 ) ?);
?g2c2->SetLineColor( kRed );
?g2c1->GetXaxis()->SetTitle( "Time [ns]" );
?g2c1->GetYaxis()->SetTitle( "Wave Form" );
?g2c1->GetYaxis()->SetRangeUser(-0.4, 0.1);
?g2c1->Draw("ALP");
?g2c2->Draw("same");
?TLegend *leg2 = new TLegend();
?leg2->AddEntry( g2c1, "Channel 1 (trigger)" );
?leg2->AddEntry( g2c2, "Channel 2" );
?leg2->Draw( "same" );
?// create 10000 ?WFMXXXX.txt file
?cout << "Start create data" << endl;
?std::ofstream write;
?for( int j=1; j<10000 1; j ? ){
if( gRandom->Uniform()<0.5 ){
generateWFM( time, ch1, ch2, true );
? ? ?timeStamp1 = gRandom->Exp( 2.2 );
? ? ?cout << "True" << endl;
? ?}else{
? ? ?generateWFM( time, ch1, ch2, false );
? ? ?timeStamp1 = gRandom->Uniform(0, 10);
? ? ?cout << "False" << endl;
? ?}
? ?write.open( Form("WFM%05d.txt", j) );
? ?write << timeStamp1 << "\n";
? ?for( int i=0; i<N; i ? ){
write << time[i] << "\t" << ch1[i] << "\t" << ch2[i] << endl;
? ?}
? ?write.close();
?}
?cout << "Data are created" << endl;
?
?return 1;
}