Hi. I’m picking up a new project that is taking its first steps and would like to start writing analysis tools in the form of a set of classes like EvtLoader, PulseIdentifier, PeakFinder, etc. I’m clueless as to how to organize all of this code for the project, and even more so for how to integrate all of it together. I’d like to be able to use the classes in two ways:
- Write root macros like the following that can be executed with a “root MyMacroAnalysis.C+”:
#include "PulseArray.hh"
#include "EvtLoader.hh"
{
EvtLoader* evtloader = new EvtLoader("data20101009.evt");
evtloader->LoadAll();
PulseArray* pulse_array = evtloader->GetPulses();
// More analysis...
}
2) Interactively at the interpreter.
I would like to get method 1) set up first so let’s ignore 2). In my short tests where I’ve attempted this with toy classes I’ve not succeeded. Let’s use the following as an example:
pmt.h
[code]#ifndef PMT_H
#define PMT_H 1
class PMT {
double gain, voltage;
public:
PMT();
double GetGain();
double GetVoltage();
void SetGain(double g);
void SetVoltage(double v);
// Put in here for root testing to import the class.
ClassDef(PMT,1);
};
#endif
[/code]
pmt.C
[code]#include “pmt.h”
ClassImp(PMT)
using namespace std;
double PMT::GetGain() {return gain;}
double PMT::GetVoltage() {return voltage;}
void PMT::SetGain(double g) {gain=g;}
void PMT::SetVoltage(double v) {voltage=v;}
[/code]
test_pmt_class.C
[code]#include
#include “pmt.h”
PMT *pmt = new PMT;
pmt->SetVoltage(900);
pmt->SetGain(2e6);
double voltage = pmt->GetVoltage();
double gain= pmt->GetGain();
cout << "The voltage is " << voltage
<< " and the gain is " << gain << “.” <<endl;
}
[/code]
Running with “root test_pmt_class.C+” returns:
root [0]
Processing test_pmt_class.C+...
root [1]
The namespace is empty, nothing was printed, I don’t have access to my PMT class, and I clearly don’t understand how this kind of structure can be used to put together an analysis! What am I missing (conceptually) and what do I need to change to make a class-based analysis toolset work for me? Thanks a lot for your help.