// Header (interface) file for a simple Particle class // containing 'mass' and 'momentum' information //Without these lines, "Particle" will not be defined by the compiler #ifndef __Particle___ #define __Particle___ // to declare a class, use the C++ keyword 'class' class Particle { // the 'members' of this Particle class will be the variables for: mass and momentum (and charge) // we want them to be private, meaning they can only be accessed inside the class itself private: double fMass; double fP; //double fCharge; //... etc (could easily add other members) // note: I have put an 'f' at the start of the variable names // since this is generally the convention that ROOT uses to indicate variables // which are members of a class. // now we want to list the public parts of the class // here we will put the functions that we want to be able to use for the class public: Particle(); // the above function is very important - it is called the default constructor // for the class. All C++ classes must have a default instructor. // this is the function that is called when you try to create an object of the class, // without any arguments Particle(double mass, double p); // above is the normal constructor. It makes an object of the class with the given values for m and p (and c) // methods: // basic functions to get and set values of mass and momentum double GetMass(); double GetMomentum(); //double GetCharge(); void SetMass(double new_mass); void SetMomentum(double new_momentum); // void SetCharge(double new_charge); // function that calculates the particle energy from the mass and momentum double GetEnergy(); // the code that then implements all these functions can be found in the Particle.cc file }; // note this semicolon after defining the class! #endif