ROOTPWA
getThresholds.cc
Go to the documentation of this file.
1 
2 //
3 // Copyright 2009 Sebastian Neubert
4 //
5 // This file is part of rootpwa
6 //
7 // rootpwa is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // rootpwa is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with rootpwa. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #include <fstream>
23 #include <iostream>
24 #include <vector>
25 #include <list>
26 #include <map>
27 #include <algorithm>
28 #include <exception>
29 #include <string>
30 
31 #include "TString.h"
32 #include "TGraph.h"
33 #include "TMultiGraph.h"
34 #include "TFile.h"
35 #include "integral.h"
36 #include "TH1D.h"
37 
38 
39 using namespace std;
40 
41 
42 bool SameJPCEPS(TString s1, TString s2){
43  TString ss1=s1(2,5);
44  TString ss2=s2(2,5);
45  //cout << ss1 << " " << ss2 << endl;
46  return ss1==ss2;
47 }
48 
49 
50 int
51 main(int argc, char** argv){
52 
53  // read in config file
54  ifstream config(argv[1]);
55  vector<integral> integrals;
56  vector<double> masses;
57 
58  while(config.good() && !config.eof()){
59  double mass;
60  TString normfilename;
61  config >> mass >> normfilename;
62  ifstream file(normfilename.Data());
63  integrals.push_back(integral());
64  integrals.back().scan(file);
65  masses.push_back(mass);
66  cerr << mass << endl;
67  //getline(0);
68  config.ignore(255,'\n');
69  }
70  //double weights[masses.size()];
71  //for(unsigned int i=0;i<masses.size();++i)
72  // weights[i]=1;
73 
74 
75  list<string> waves=integrals[0].files();
76  //unsigned int nwaves=waves.size();
77  list<string>::iterator it=waves.begin();
78  // wavemap: contains one entry per wave
79  // each entry records mass and maximum integral value
80  map<TString,pair<double,double> > wavemap;
81  map<TString,TGraph*> graphs;
82  map<TString,TGraph*> diaggraphs_re;
83  map<TString,TGraph*> diaggraphs_im;
84 
85 
86  TMultiGraph* mg=new TMultiGraph();
87  TMultiGraph* mg_re=new TMultiGraph();
88  TMultiGraph* mg_im=new TMultiGraph();
89 
90  while(it!=waves.end()){
91  wavemap[*it]=pair<double,double>(0,0);
92  graphs[*it]=new TGraph(masses.size());
93  graphs[*it]->SetName(it->c_str());
94  mg->Add(graphs[*it]);
95  list<string>::iterator itb=it;
96  ++itb;
97  while(itb!=waves.end()){
98  TString s=(*it);
99  s+=(*itb);
100 
101  diaggraphs_re[s]=new TGraph(masses.size());
102  diaggraphs_im[s]=new TGraph(masses.size());
103  mg_re->Add(diaggraphs_re[s]);
104  mg_im->Add(diaggraphs_im[s]);
105 
106  ++itb;
107  }
108  ++it;
109  }
110 
111  map<TString,TGraph*> jpcgraphs;
112  TMultiGraph* mg2=new TMultiGraph();
113  //jpcgraphs["0-+0+"]=new TGraph(1000);
114  //jpcgraphs["0-+0+"]->SetName("g0-+0+");
115  //mg2->Add(jpcgraphs["0-+0+"]);
116 
117 
118  map<TString,pair<double,double> >::iterator it2=wavemap.begin();
119  map<TString,pair<double,double> >::iterator it3=wavemap.begin();
120 
121  // loop over mass bins
122  // unsigned int k=0;
123  for(unsigned int i=0; i<masses.size(); ++i){
124  cerr << "Processing mass bin "<< masses[i] << endl;
125  it2=wavemap.begin();
126  while(it2!=wavemap.end()){
127  it3=it2;
128  while(it3!=wavemap.end()){
129  try{
130  std::complex<double> c=integrals[i].val(it2->first.Data(),it3->first.Data());
131  //double n1=sqrt(integrals[i].val(it2->first.Data(),it2->first.Data()).real());
132  //double n2=sqrt(integrals[i].val(it3->first.Data(),it3->first.Data()).real());
133  //double norm=n1*n2;
134  //double re=c.real();///norm;
135  double im=c.imag();
136  double val=integrals[i].val(it2->first.Data(),it3->first.Data()).real();
137  if(it2!=it3){
138  TString s=(it2->first);
139  s+=it3->first;
140  if(diaggraphs_re[s]!=NULL){
141  diaggraphs_re[s]->SetPoint(i,masses[i],arg(c));
142  diaggraphs_re[s]->SetName(s);
143  diaggraphs_im[s]->SetPoint(i,masses[i],im);
144  diaggraphs_im[s]->SetName(s);
145  }
146  }
147  else if(it2==it3){
148  graphs[it2->first]->SetPoint(i,masses[i],val);
149  if(it2->second.second<val){
150  it2->second=pair<double,double>(masses[i],val);
151  }
152  }
153  else if(SameJPCEPS(it2->first,it3->first)){
154  TString name("g");
155  name.Append(it2->first);
156  name.Append(it3->first);
157  if(jpcgraphs[name]==0){
158  jpcgraphs[name]=new TGraph(masses.size());
159  jpcgraphs[name]->SetName(name);
160  mg2->Add(jpcgraphs[name]);
161  }
162  jpcgraphs[name]->SetPoint(i,masses[i],val);
163 
164  }
165  }
166  catch(char const*){
167  cerr<< "Cought exception" << endl;
168  }
169  ++it3;
170  }
171  ++it2;
172  }
173  }
174 
175 
176  // print results:
177  it2=wavemap.begin();
178  while(it2!=wavemap.end()){
179  cout << it2->first << " " << it2->second.first*0.8 << endl;
180  ++it2;
181  }
182 
183  TFile* file=TFile::Open("normgraphs.root","RECREATE");
184  // create histos
185  map<TString,TGraph*>::iterator git=diaggraphs_re.begin();
186  while(1 && git!=diaggraphs_re.end()){
187  TGraph* g=git->second;
188  g->Write();
189  double max=-1E6;
190  double min=1E6;
191  double mean=0;
192  //double val[masses.size()];
193  for(unsigned int i=1; i<masses.size(); ++i){
194  double x,y;
195  g->GetPoint(i,x,y);
196  if(max<y)max=y;
197  if(min>y)min=y;
198  mean+=y;
199  //val[i]=y;
200  }
201  mean/=(double)masses.size();
202  //double range=(max-min)*0.2;
203  //min/
204  //double var=0;
205  // for(unsigned int i=1; i<masses.size(); ++i){
206 // val[i]=(mean-val[i])/mean;
207 // var+=val[i]*val[i];
208 // }
209 // var=sqrt(var);
210 
211  //cerr << min << " " << max << endl;
212  TString name=g->GetName();
213  name.Prepend("h");
214  //TH1D* histo=new TH1D(name,name,20,min-range,max+range);
215  //histo->FillN(masses.size(),val,weights);
216  //histo->Write();
217  ++git;
218  }
219 
220  map<TString,TGraph*>::iterator grit=graphs.begin();
221  while(grit!=graphs.end()){
222  grit->second->Write();
223  ++grit;
224  }
225 
226 
227  mg->Write("graphs");
228  mg2->Write("jpcgraphs");
229  mg_re->Write("greal");
230  mg_im->Write("gimag");
231  file->Close();
232 
233  return 0;
234 }