StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
runChi2Min_SFEval.C
1 double chi2Eval(TH2D* h, TH2D* data, float beta, float sf, int rscale){
2 
3  double retVal=0.;
4  double posVal=0.;
5  double negVal=0.;
6  double numNeg=0.;
7  double numPos=0.;
8 
9  bool writeIt=true;
10  if(!rscale){ // SYtDYt space
11 
12  for(int ix=13;ix<=h->GetNbinsX();ix++){ // ix=13, sum_yt~3.4, yt~1.7
13  for(int iy=13;iy<=h->GetNbinsY();iy++){ // iy=13, delta_yt=0
14  if(data->GetBinContent(ix,iy)<1)continue;
15  double testVal=(double)h->GetBinContent(ix,iy);
16  double testErr=fabs((double)h->GetBinError(ix,iy));
17  if(testErr==0.)continue;
18  double val=testVal/testErr;
19  val*=val;
20  if(testVal<0.){
21  negVal += val;
22  numNeg+=1.0;
23  } else {
24  posVal += val;
25  numPos+=1.0;
26  }
27  }
28  }
29 
30  } else { //YtYt Space
31 
32  for(int ix=5;ix<=h->GetNbinsX();ix++){ // ix=5, yt~1.7
33  for(int iy=ix+1;iy<=h->GetNbinsY();iy++){ // iy>ix
34  if(data->GetBinContent(ix,iy)<1)continue;
35  double testVal=(double)h->GetBinContent(ix,iy);
36  double testErr=fabs((double)h->GetBinError(ix,iy));
37  if(testErr==0.)continue;
38  double val=testVal/testErr;
39  val*=val;
40  if(testVal<0.){
41  negVal += val;
42  numNeg+=1.0;
43  } else {
44  posVal += val;
45  numPos+=1.0;
46  }
47  }
48  }
49  }
50 
51  if(numPos>0.)posVal=(posVal/numPos);
52  if(numNeg>0.)negVal=(1.+beta)*(negVal/numNeg);
53 
54  retVal=posVal+negVal;
55  return retVal;
56 }
57 
58 //--------------------------------------------------------------------
59 float* runChi2Min_SFEval(const char* dirName, float beta, int itype, const char* cmult=NULL, int rscale=1){
60 
61  /* Notes from Jeff's 7/24 email to estruct
62  const char* dirName => input directory (excluding mult sub-dir)
63  float beta => lagrange multiplier (typically ~10)
64  int itype => side-index (all, awayside, sameside, ...)
65  const char* cmult => multiplicity subdir
66  int rscale => 0 do not apply, 1 apply radialScaling.C
67  */
68 
69  const char* spaceName[]={"NSYtDYt","NYtYt"};
70 
71  TString dirname(dirName);
72  if(cmult){
73  dirname+="/";
74  dirname+=cmult;
75  dirname+="/";
76  }
77 
78  gSystem->Load("StEStructPoolSupport.so");
79  gROOT->LoadMacro("radialScaling.C");
80 
81  double lsmin=999999.;
82  double usmin=999999.;
83 
84  float lsscale;
85  float usscale;
86 
87  const char* cname[]={"all","nearside","awayside"};
88 
89  TString fname(cname[itype]);
90 
91  TString infile(dirname.Data());
92  infile+=fname.Data();
93  infile+=".root";
94 
95  cout<<"Attempting fits from file = "<<infile.Data()<<" with beta="<<beta<<endl;
96  TFile* tf=new TFile(infile.Data());
97  tf->cd();
98  StEStructSupport ehelp(tf,1);
99 
100  TString ppName("Sibpp"); ppName+=spaceName[rscale];
101  TString mmName("Sibmm"); mmName+=spaceName[rscale];
102  TString mpName("Sibmp"); mpName+=spaceName[rscale];
103  TString pmName("Sibpm"); pmName+=spaceName[rscale];
104 
105  TH2D* ssdata=(TH2D*)(tf->Get(ppName.Data())->Clone());
106  TH2D* mmdata=(TH2D*)tf->Get(mmName.Data());
107  ssdata->Add(mmdata);
108 
109  TH2D* usdata=(TH2D*)tf->Get(mpName.Data());
110  TH2D* mpdata=(TH2D*)tf->Get(pmName.Data());
111  usdata->Add(mpdata);
112 
113  cout<<" Npairs:: LS="<<ssdata->Integral();
114  cout<<" US="<<usdata->Integral()<<endl;
115 
116  for(int is=0;is<20;is++){
117  float fnval=0.9+is*0.005;
118  float sf[2];//={1.00,1.00};
119  sf[0]=fnval;
120  sf[1]=fnval;
121 
122  TH2D** localHists=(TH2D**)ehelp.buildChargeTypes(spaceName[rscale],1,sf);
123  if(1==rscale){
124  radialScaling(localHists[0]);
125  radialScaling(localHists[1]);
126  }
127  double lval=chi2Eval(localHists[0],ssdata,beta,sf[0],rscale);
128  double uval=chi2Eval(localHists[1],usdata,beta,sf[1],rscale);
129 
130  if(lval<lsmin){
131  lsmin=lval;
132  lsscale=fnval;
133  }
134  if(uval<usmin){
135  usmin=uval;
136  usscale=fnval;
137  }
138 
139  }
140 
141  tf->Close();
142 
143  cout<<" found lsmin="<<lsscale<<" usscale="<<usscale<<endl;
144  float* retVal = new float[2];
145  retVal[0]=lsscale;
146  retVal[1]=usscale;
147 
148  return retVal;
149 }
150