Dear rooters.
@pcanal I’m trying to store some event information in a TTree, where each event could contain information about several particles depositing energy in several detectors. I have a problem figuring out the most convenient format, and specifically I see that vector<string>
behaves in a different way than vector<double>
when I try to store them as members of a c++ class.
So far, I have come up with the following ‘Hit’-class:
class Hit : public TObject {
public:
char const *id; //Particle identity, i.e. alpha, proton ...
double e; //Reconstructed kinetic energy of particle.
vector<std::string> det; //List of detectors that were hit.
std::vector<double> edep; //Energy deposited in the individual detectors.
ClassDef(Hit,1);
};
and I store the hits in a TClonesArray. In ‘Minimal.C’ (Minimal.C (1.2 KB) ) I construct a TTree (attached in test.root (6.4 KB) ) with one event containing two hits, by running root -l Minimal.c
in the terminal. When I load the tree and do a Scan, I get the output:
root [1] data->Scan("id:e:det:edep")
***********************************************************************
* Row * Instance * id * e * det * edep *
***********************************************************************
* 0 * 0 * alpha * 12 * D1 * 3 *
* 0 * 1 * proton * 25 * D1 * 9 *
* 0 * 2 * * * * 8 *
* 0 * 3 * * * * 13 *
***********************************************************************
‘edep’ shows the wanted behaviour, i.e., there are two values associated with each hit, and I can draw ‘edep’-spectra gated on the particle type, like data->Draw("edep","id==\"alpha\"")
. The problem is that the Scan only shows ‘D1,D1’, whereas I would expect ‘D1,D2,D2,D3’. Also, I get wrong results when I try to draw the ‘edep’-spectrum gated on a particular detector, i.e. data->Draw("edep","det==\"D3\"")
produces an empty spectrum.
How do I get the ‘det’ member to behave in the same way as the ‘edep’ member? I should say that I’m completely open to suggestions of other event formats, as long as I get the possibility to draw spectra gated on particle ID and detector ID.
Cheers,
ROOT Version: 6.14/02
Platform: Ubuntu 16.04
Compiler: gcc 7.4.0