52 #include "TClonesArray.h"
57 #include "TStopwatch.h"
63 #include "Minuit2/Minuit2Minimizer.h"
65 using namespace ROOT::Minuit2;
71 int main(
int argc,
char** argv){
73 gRandom->SetSeed(
time(NULL));
79 unsigned int Nit=5000;
83 TString ofile_name=
"MCMCresult.root";
84 TString start_file_name;
86 string norm_file_name;
95 while ((c = getopt(argc, argv,
"l:u:i:w:o:s:S:n:r:qh")) != -1)
101 low_mass = atof(optarg);
104 high_mass = atof(optarg);
113 start_file_name= optarg;
116 norm_file_name = optarg;
119 wavefile_name = optarg;
129 cerr <<
"usage:" << endl;
130 cerr << progname <<
" -l # -u # [-i -h -q] [-n normfile -s start values -r rank] -w wavelist -o outfile " << endl;
131 cerr <<
" where:" << endl;
132 cerr <<
" -i #: iterations" << endl;
133 cerr <<
" -t #: maximal runtime in sec (default: 14000)" << endl;
134 cerr <<
" -l #: lower edge of bin" << endl;
135 cerr <<
" -u #: upper edge of bin" << endl;
136 cerr <<
" -w file: set wavelist file" << endl;
137 cerr <<
" -o file: set output file" << endl;
138 cerr <<
" -n file: set normalization file" << endl;
139 cerr <<
" -s #: set stepsize" <<endl;
140 cerr <<
" -r #: set rank" <<endl;
141 cerr <<
" -q: run quietly" << endl;
142 cerr <<
" -h: print help" << endl;
148 if(norm_file_name.length()<=1)norm_file_name=
"norm.int";
149 if(wavefile_name.length()<=1){
150 cerr <<
"No wavelist specified! Aborting!" << endl;
156 if(quiet)L.SetQuiet();
157 L.SetWavelist(wavefile_name);
159 cout<<L.
NDim()<<endl;
161 L.LoadIntegrals(norm_file_name,norm_file_name);
172 cout <<
"Installing parameters:" << endl;
173 unsigned int ndim=L.
NDim();
184 if(start_file_name.Length()>2){
185 TFile* file=TFile::Open(start_file_name,
"READ");
188 TTree* tree=(TTree*)file->Get(
"pwa");
190 cout <<
"pwa Tree not found for starting values." << endl;
193 tree->SetBranchAddress(
"fitbin",&start);
195 for(
int i=0;
i<tree->GetEntriesFast();++
i){
197 if(start->
mass()<=high_mass && start->
mass()>=low_mass){
198 cout <<
"Start values: found suiting mass bin: " << start->
mass() <<endl;
209 for(
unsigned int i=0;
i<L.
NDim();++
i){
210 if(!hasstart)X[
i]=0.1;
211 cout << L.parname(
i) <<
" " << X[
i] << endl;
212 R[
i]=gRandom->Gaus(0,1);
218 TFile* file=TFile::Open(ofile_name,
"RECREATE");
222 TTree* tree=
new TTree(
"MarkovChain",
"MarkovChain");
223 tree->Branch(
"N",&ndim,
"N/I");
224 tree->Branch(
"dL",&dL,
"dL[N]/D");
225 tree->Branch(
"X",&X,
"X[N]/D");
226 tree->Branch(
"L",&E,
"L/D");
227 tree->Branch(
"H",&H,
"H/D");
228 tree->Branch(
"R",&R,
"R[N]/D");
229 tree->Branch(
"Rlast",&Rlast,
"Rlast[N]/D");
234 unsigned int Nleap=5;
241 for(
unsigned int i=0;
i<L.
NDim();++
i){
250 L.getIntCMatrix(meta->
Norm,meta->
Norm);
251 meta->Write(
"MetaInfo");
260 for(
unsigned it=0;it<Nit;++it){
261 double tstart=watch.CpuTime();watch.Continue();
262 cout <<
"Iteration" << it << endl;
272 if(it==0)tree->Fill();
277 for(
unsigned int ip=0; ip<ndim;++ip){
285 for(
unsigned int ip=0; ip<ndim;++ip){
290 R[ip]=R[ip]-eps2*dL[ip];
293 unsigned int nl=gRandom->Integer(Nleap);
294 for(
unsigned il=0; il<nl;++il){
295 for(
unsigned int ip=0; ip<ndim;++ip){
296 X[ip]=X[ip]+eps/m*R[ip];
303 for(
unsigned int ip=0; ip<ndim;++ip){
304 R[ip]=R[ip]-eps*dL[ip];
308 for(
unsigned int ip=0; ip<ndim;++ip){
309 R[ip]=R[ip]-eps2*dL[ip];
318 for(
unsigned int ip=0; ip<ndim;++ip){
320 R[ip]=gRandom->Gaus(0,1);
324 double plength=gRandom->Gaus(0,1);
326 for(
unsigned int ip=0; ip<ndim;++ip)R[ip]*=plength;
332 cout <<
">>>> (Hlast-H)/H = " << (Hlast-H)/H << endl;
338 if(gRandom->Uniform()<TMath::Exp(H-Hlast)){
353 cout <<
"Acceptance Rate: " << (double)Nacc/(
double)(it+1) << endl;
354 double tend=watch.CpuTime();watch.Continue();
358 Tmean=Tacc/(double)(it+1);
361 cout <<
"Mean time per iteration: "<< Tmean <<
"sec"<<endl;
362 cout <<
"Max time left for this job: "
363 << Ttotal-Tacc <<
"sec ("<< Tacc/Ttotal*100 <<
"%)" << endl;
367 if(Tacc+5*Tmean>Ttotal)
break;
373 cout <<
"Acceptance Rate: " << (double)Nacc/(
double)Nit << endl;
462 int mnparm(
int,
string,
double,
double,
double,
double) {
463 cerr <<
"this is impossible" << endl;