ROOTPWA
evt2tree.cc
Go to the documentation of this file.
1 
3 //
4 // Copyright 2009 Sebastian Neubert
5 //
6 // This file is part of rootpwa
7 //
8 // rootpwa is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // rootpwa is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
20 //
22 
23 
24 #include <complex>
25 #include <iostream>
26 #include <string>
27 #include <vector>
28 #include <iomanip>
29 #include <cstdlib>
30 #include <unistd.h>
31 #include <assert.h>
32 #include "event.h"
33 #include "particle.h"
34 #include "lorentz.h"
35 #include "Vec.h"
36 
37 #include "TFile.h"
38 #include "TTree.h"
39 #include "TLorentzVector.h"
40 #include "TClonesArray.h"
41 
42 using namespace std;
43 
44 
45 void printUsage(char* prog) {
46  cerr << "Converts pwa2000 evt format to ROOT tree" << endl;
47  cerr << "usage:" << endl;
48  cerr << "cat myevents.evt | " << prog << " myevents.root " << endl;
49 
50 }
51 
52 int main(int argc, char** argv) {
53 
54  if(argc<2){
55  printUsage(argv[0]);
56  return 1;
57  }
58 
59  threeVec evtbeam;
60  list<particle> f_mesons;
61 
62  string outfilename(argv[1]);
63 
64  TFile* outfile=TFile::Open(outfilename.c_str(),"RECREATE");
65  if(outfile==NULL){
66  cerr << "Could not open output file '"<<outfilename << "'. Aborting." << endl;
67  return 1;
68  }
69  TTree* outtree=new TTree("events","events");
70  TClonesArray* p=new TClonesArray("TLorentzVector");
71  TLorentzVector beam;
72  int qbeam;
73  std::vector<int> q; // array of charges
74 
75  outtree->Branch("p",&p);
76  outtree->Branch("beam",&beam);
77  outtree->Branch("q",&q);
78  outtree->Branch("qbeam",&qbeam,"qbeam/I");
79 
80 
81  while(cin.good() && !cin.eof()) { // begin event loop
82  event e;
83  cin>>e;
84  if(!e.isValid()){
85  cerr << "EVENT NOT VALID (NO BEAM AND/OR NO FINAL STATE)!!! SKIPPING" << endl;
86  continue;
87  }
88  //cerr << e;
89  p->Delete(); // clear output arrays
90  q.clear();
91  f_mesons=e.f_mesons();
92  fourVec pX;
93  list<particle>::iterator it = f_mesons.begin();
94  while (it != f_mesons.end() ) {
95  pX=it->get4P();
96  new ((*p)[p->GetEntries()]) TLorentzVector(pX.x(),pX.y(),pX.z(),pX.t());
97  q.push_back(it->Charge());
98  ++it;
99  }
100  fourVec evtbeam=e.beam().get4P();
101  beam.SetPxPyPzE(evtbeam.x(),evtbeam.y(),evtbeam.z(),evtbeam.t());
102  qbeam=e.beam().Charge();
103  outtree->Fill();
104  }
105 
106  outtree->Write();
107  outfile->Close();
108  return 0;
109 }