StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
findMinChi2.C
1 //#include "/star/u/syang/Macro/headers.h"
2 //#include "/star/u/syang/Macro/function.C"
3 
4 //find the minimum Chi2 among all the root files, then print out the root file full name
5 //the name of the root file will tell what parameter settings give the minimum chi2
6 
7 void findMinChi2(const Char_t* inputFileList = "minChi2_file.list")
8 {
9  ifstream fin(inputFileList);
10  if(!fin){
11  Error("Error, inputfile", "can't open %s", inputFileList);
12  return;
13  }
14 
15  Double_t minChi2 = 1.e9;
16  TString minName = "";
17 
18  ofstream outData("minChi2_rootfile_fullname.dat");
19 
20  TString name("");
21 
22  while( fin >> name )
23  {
24  TFile* file = TFile::Open(name);
25  if(!file || !file->IsOpen() || !file->GetNkeys())
26  {
27  Error("check chi2", "can't open %s", name.Data());
28  continue;
29  }
30  //cout << "OPEN " << file->GetName() << endl;
31 
32  TH3* hchi2 = (TH3D*) file->Get("hChi2");
33 
34  for(Int_t i=0; i<hchi2->GetNbinsX(); i++)//parameter n_{pp}
35  {
36  for(Int_t j=0; j<hchi2->GetNbinsY(); j++)//parameter k
37  {
38  for(Int_t k=0; k<hchi2->GetNbinsZ(); k++)//parameter x
39  {
40  Double_t chi2 = hchi2->GetBinContent(i+1, j+1, k+1);
41 
42  if(chi2<minChi2)
43  {
44  minChi2 = chi2;
45  minName = name;
46 
47  //if(minChi2<10)
48  //{
49  // outData<<"minChi2: "<<minChi2<<" fileName: "<<minName<<endl;
50  // cout<<"minChi2: "<<minChi2<<" fileName: "<<minName<<endl;
51  //}
52  }
53  }
54  }
55  }
56 
57  file->Close();
58  }
59 
60  outData<<"The minimum Chi2 are found: "<<minChi2<<endl;
61  outData<<"the corresponding root fileName: "<<endl;
62  outData<<minName<<endl;
63  outData.close();
64 
65  cout<<endl;
66  cout<<"The minimum Chi2: "<<minChi2<<" fileName: "<<minName<<endl;
67 }
Definition: FJcore.h:367