I am not a professional programmer. I have heard the concept of procedural and object-oriented programming, and that ROOT is an object-oriented framework for physics analysis. I naively thought my analysis codes based on ROOT should be programmed using OO style.
So I wrote my program with 3 base classes: “Detector”, “Event” and “Analyzer”. There are 3 main functions in the “Analyzer”:
Analyzer::SetEvent(Event *evt); Analyzer::SetDetector(Detector *det); Analyzer::Process();
The idea behind this setup is simple: an analysis can be performed given the hardware information saved in the “Detector” and an “Event” from data.
The problem of this setup is that there are many getters/setters in the “Detector” and “Event” classes. Getters are used in function “Analyzer::Process()” to get individual piece of information from the detector and an event. This means that I basically have a procedural program taking the form of an object-oriented program. The “Detector” and “Event” classes behave like global variables in a procedural program, while the “Analyzer” class is just a collection of functions in a procedural program.
I can let the “Analyzer” inherits from the “Detector” to remove function “Analyzer::SetDetector” and all getters in the “Detector”. But I still have many getters in “Event”. I cannot find a way to go around it.
So I started to ask myself, is a physics analysis better to be programmed in a procedural style or OO style? We take data, and pass the data to a serious of analyses. It seems natural to mimic this process in programming, meaning that procedural programming is a natural choice for physics data analysis.
I feel like that ROOT defines many objects used in an analysis, for example, TVector3, TClonesArray, etc. One can utilize OO to realize those objects. But once they are established, they should be used in an specific analysis realized in procedural programming style.
And it seems to me that the use of TTree forces one to program in procedural style. He gets all variables saved in a tree by calling TTree::GetEntry(ievt) at the beginning of the main event loop, processes these variables in a serious of functions, and finally saves selected events in the end of the loop. The tree is essentially a place to hold the global variables for procedural programming.
To summarize my understanding, ROOT can be written by OO, but an specific analysis should be programmed in the traditional procedural style. Can somebody with more experience help me to understand this issue better?