ROOTPWA
binevt.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 "TSystem.h"
38 
39 using namespace std;
40 
41 
42 void printUsage(char* prog) {
43  cerr << "Bins evt data in mass bins" << endl;
44  cerr << "options:" << endl;
45  cerr << "-n number of bins" << endl;
46  cerr << "-s mass of start bin" << endl;
47  cerr << "-b bin width in mass" << endl;
48  cerr << "-o output path" << 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  TString path;
60  double mstart = 0;
61  double mbin = 0.04;
62  int nbins = 0;
63 
64  int c;
65  while ((c = getopt(argc, argv, "n:s:b:o:h")) != -1)
66  switch (c) {
67  case 'n':
68  nbins = atoi(optarg);
69  break;
70  case 's':
71  mstart = atof(optarg);
72  break;
73  case 'o':
74  path = optarg;
75  break;
76  case 'b':
77  mbin = atof(optarg);
78  break;
79  case 'h':
80  printUsage(argv[0]);
81  return 1;
82  }
83 
84 
85 
86  unsigned int nselected=0;
87  double m=mstart;
88 
89  vector<std::ofstream*> outfiles;// setup output file
90 
91  // open outfiles
92  for(int ibin=0;ibin<nbins;++ibin){
93 
94  double mmin=m;
95  double mmax=m+mbin;
96 
97  TString binS;
98  binS+=mmin*1000;
99  binS+=".";
100  binS+=mmax*1000;
101  // create directory
102  TString com;
103  com+=path;
104  com+=binS;
105  com.ReplaceAll(" ","");
106  if(!gSystem->mkdir(com.Data()))
107  std::cout<<"Directory "
108  <<com
109  <<" could not be created. Already existent?"<<std::endl;
110 
111  TString outfile=path;
112  outfile+=binS;
113  outfile+="/";
114  outfile+=binS;
115  outfile+=".evt";
116  outfile.ReplaceAll(" ","");
117  outfiles.push_back(new std::ofstream(outfile.Data()));
118  m=mmax; // step further in m
119  }
120 
121 
122 
123 
124  list<particle> f_mesons;
125  event e;
126  while(!(cin>>e).eof()) { // begin event loop
127  f_mesons=e.f_mesons();
128  fourVec pX;
129  fourVec p;
130  list<particle>::iterator it = f_mesons.begin();
131  while (it != f_mesons.end() ) {
132  pX=it->get4P();
133  p+=pX;
134  ++it;
135  }
136  // sort by mass
137  double m=p.len();
138  // select appropriate mass bin
139  unsigned int bin=(unsigned int)floor((m-mstart)/mbin);
140  if(bin<outfiles.size()){
141  std::ofstream* out=outfiles.at(bin);
142  ++nselected;
143  *out << e ;
144  }
145 
146 
147 
148  }
149 
150 
151  return 0;
152 }