{
c1=new TCanvas("c1","c1",0,0,700,500);
double pion_energy=2.;  // pion energy(GeV)
double const m_pion=0.13957;    // pion mass (GeV)
double const tau_pion=2.6E-8;   // pion lifetime (sec)
double const c=2.998E8;         // light velocity (m/sec)
// variable gamm cause error.
pion = new TH1F("pion","pion flight length",130, 0.,130.0);
double gammaPi = pion_energy / m_pion;
for (int i=0; i<10000; i++) {
  double decay = -log(gRandom->Rndm()) * gammaPi * c * tau_pion;
  for( double x = 0.0 ; x<decay ; x+=1.0) {
    if(x>130.) break;
    pion->Fill(x); 
  }
}
pion->SetXTitle("flight length (m)");
pion->SetYTitle("survived pions");
pion->SetMinimum(0.);
pion->Draw("L");
t=new TText(70,4100,"2 GeV"); 
t->Draw();
//
c1->Print("pion_flight.png");
}


