StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
minimizeNegative.C
1 #include "../Support/StEStructMinimizeNegative.h"
3 static void minimizeNegative(int &npar, double *gin, double &f, double *par, int iflag) {
4  // We rely on following static variables to be set before minimization can be done.
5  // StEStructSupport *minData.mSupport;
6  // int minData.mChargeType; 0 for LS, 1 for US.
7  // int minData.mCorrType; 0 for SYtDYt, 1 for YtYt;
8  // double minData.mLambda; Lagrange multiplier to weight negative \Delta\rho. (normally 10)
9  float sf[2];
10  sf[0] = par[0];
11  sf[1] = par[0];
12  const char* spaceName[]={"SYtDYt","YtYt"};
13  TH2D **localHists = minData.mSupport->buildChargeTypes(spaceName[minData.mCorrType],5,sf);
14  if (!localHists) {
15  f = 2147483648;
16  return;
17  }
18 
19  double posVal=0.;
20  double negVal=0.;
21  double numNeg=0.;
22  double numPos=0.;
23 
24  if (0 == minData.mCorrType) { // SYtDYt space
25 
26  for(int ix=1;ix<=localHists[minData.mChargeType]->GetNbinsX();ix++){ // ix=13, sum_yt~3.4, yt~1.7
27  for(int iy=1;iy<=localHists[minData.mChargeType]->GetNbinsY();iy++){ // iy=13, delta_yt=0
28 /*
29  * Code checked to see if number of counts in \rho is >= 1.
30  * I don't know why checking for error in \Delta\rho/sqrt(\rho_{ref}) being
31  * non-zero isn't better. (Allows possibility that \rho is 0 while \rho_{ref}
32  * is non-zero, but why not include those bins?)
33  if (data->GetBinError(ix,iy)<=0) {
34  continue;
35  }
36  */
37  double testVal = (double) localHists[minData.mChargeType]->GetBinContent(ix,iy);
38  double testErr = fabs((double) localHists[minData.mChargeType]->GetBinError(ix,iy));
39  if (testErr==0.) {
40  continue;
41  }
42  double val = pow(testVal/testErr,2);
43  if (testVal<0.) {
44  negVal += val;
45  numNeg +=1.0;
46  } else {
47  posVal += val;
48  numPos +=1.0;
49  }
50  }
51  }
52 
53  } else if (1 ==minData.mCorrType) { //YtYt Space
54 
55  for(int ix=1;ix<=localHists[minData.mChargeType]->GetNbinsX();ix++){ // ix=5, yt~1.7
56  for(int iy=ix+1;iy<=localHists[minData.mChargeType]->GetNbinsY();iy++){ // iy>ix
57 /*
58  * See comment above.
59  if (data->GetBinContent(ix,iy)<1) {
60  continue;
61  }
62  */
63  double testVal = (double) localHists[minData.mChargeType]->GetBinContent(ix,iy);
64  double testErr = fabs((double) localHists[minData.mChargeType]->GetBinError(ix,iy));
65  if (testErr==0.) {
66  continue;
67  }
68  double val = pow(testVal/testErr,2);
69  if (testVal<0.) {
70  negVal += val;
71  numNeg += 1.0;
72  } else {
73  posVal += val;
74  numPos += 1.0;
75  }
76  }
77  }
78  }
79 
80  for (int iType=0;iType<4;iType++) {
81  delete localHists[iType];
82  }
83  delete [] localHists;
84 
85  if (numPos>0.) {
86  posVal = (posVal/numPos);
87  }
88  if (numNeg>0.) {
89  negVal = (1.+minData.mLambda)*(negVal/numNeg);
90  }
91 
92  f = posVal+negVal;
93 }