5 #include "TLorentzVector.h"
6 #include "TClonesArray.h"
14 void readStarlightAscii(const char* inFileName = "slight.out",
15 const char* outFileName = "starlight.root")
17 const double daughterMass = 0.13957018; // charged pion [GeV]
20 TFile* outFile = new TFile(outFileName, "RECREATE");
22 cerr << " error: could not create output file '" << outFileName << "'" << endl;
25 TTree* outTree = new TTree("starlightTree", "starlightTree");
26 TLorentzVector* parentParticle = new TLorentzVector();
27 TClonesArray* daughterParticles = new TClonesArray("TLorentzVector");
28 outTree->Branch("parent", "TLorentzVector", &parentParticle, 32000, -1);
29 outTree->Branch("daughters", "TClonesArray", &daughterParticles, 32000, -1);
32 inFile.open(inFileName);
33 unsigned int countLines = 0;
34 while (inFile.good()) {
36 stringstream lineStream;
40 int eventNmb, nmbTracks;
41 if (!getline(inFile, line))
45 assert(lineStream >> label >> eventNmb >> nmbTracks);
46 if (!(label == "EVENT:"))
50 if (!getline(inFile, line))
54 assert(lineStream >> label);
55 assert(label == "VERTEX:");
57 *parentParticle = TLorentzVector(0, 0, 0, 0);
58 for (int i = 0; i < nmbTracks; ++i) {
62 if (!getline(inFile, line))
66 assert(lineStream >> label >> particleCode >> momentum[0] >> momentum[1] >> momentum[2]);
67 assert(label == "TRACK:");
68 const double E = sqrt( momentum[0] * momentum[0] + momentum[1] * momentum[1]
69 + momentum[2] * momentum[2] + daughterMass * daughterMass);
70 new ( (*daughterParticles)[i] ) TLorentzVector(momentum[0], momentum[1], momentum[2], E);
71 *parentParticle += *(static_cast<TLorentzVector*>(daughterParticles->At(i)));
74 daughterParticles->Compress();