13 int kA[mxSS]={ka,kb,kc,kd};
18 void genWalgoYields(
int nEve=6e2,
double pol1=0.5,
double pol2=0.99 ,
double lumiSpread=0.1){
19 gROOT->LoadMacro(
"setWALmodel.C");
20 TString outF=
"run12toySetB";
27 TH1F * hLumi=newSpin4Histo(
"AEta8spinY1",
"relative lums from toy MC");
29 TH1F * hWyield[mxQ][mxEta];
30 for (
int iq=0;iq<mxQ;iq++) {
31 TString Q=
"P";
if (iq) Q=
"N";
32 for(
int k=0;k<mxEta;k++) {
34 TString cEta=Form(
"Eta%d",k+1);
35 hWyield[iq][k]=newSpin4Histo(
"A"+cEta+
"spinY2_"+Q,
"charge="+Q+
", thrown W+BG events from toy MC, starEtaBin="+cEta);
41 double lumi4[mxSS], prob4[mxSS];
42 for(
int is=0; is<mxSS; is++) {
43 float val=1.+rnd->Uniform(lumiSpread);
45 hLumi->SetBinContent(kA[is]+1,val);
48 TString bgName=
"8.15.12/bkgdBetaModel_"+core+
".hist.root";
49 TFile *fdBG=
new TFile(bgName); assert(fdBG->IsOpen());
50 TFile *fdWAL=
new TFile(
"WALModel.hist.root"); assert(fdWAL->IsOpen());
52 printf(
" generate W algo yields, nEve=%d year=%s pol1=%.2f, pol2=%.2f lumiSpread=%.2f\n",nEve,core.Data(), pol1, pol2,lumiSpread);
56 for(
int iq=0; iq<mxQ; iq++) {
57 TString Q=
"P";
if (iq) Q=
"N";
61 TH1F *hWAL=fdWAL->Get(
"modW_AL_"+Q); assert(hWAL);
62 TH1F *hWALL=fdWAL->Get(
"modW_ALL_"+Q); assert(hWALL);
65 TH1F *hBeta=fdBG->Get(
"beta"+Q+
"_"+core); assert(hBeta);
68 for(
int starPhysEtaBin=1; starPhysEtaBin<=6; starPhysEtaBin++) {
69 int nThrow=nEve/6 *(1.-iq*0.3);
70 if (starPhysEtaBin>=5) nThrow/=5;
71 printf(
"\n\n........ processing Q=%s ..... starEtaBin=%d ....nThrow=%d\n",Q.Data(),starPhysEtaBin,nThrow);
74 int polBeam1EtaBin=12+starPhysEtaBin;
75 int polBeam2EtaBin=17-starPhysEtaBin;
76 printf(
"starPhysEtaBin=%d --> polBeam1=%d polBeam2=%d\n",starPhysEtaBin,polBeam1EtaBin,polBeam2EtaBin);
79 double WAL1=hWAL->GetBinContent(polBeam1EtaBin);
80 double WAL2=hWAL->GetBinContent(polBeam2EtaBin);
81 double WALL=hWALL->GetBinContent(polBeam1EtaBin);
85 double beta=hBeta->GetBinContent(starPhysEtaBin);
88 double alpha1=0, alpha2=0;
92 getProbOneEta( pol1, pol2,WAL1, WAL2, WALL, alpha1,alpha2, beta, lumi4, prob4);
95 for(
int ieve=0; ieve<nThrow; ieve++) {
96 int spin4=throwSpin4( prob4 );
97 int kBin=starPhysEtaBin-1;
99 hWyield[iq][kBin]->Fill(spin4);
106 hWyield[iq][7-1]->Add( hWyield[iq][6-1]);
107 hWyield[iq][7-1]->Add( hWyield[iq][5-1]);
108 for(
int jj=0;jj<4;jj++)
109 hWyield[iq][8-1]->Add( hWyield[iq][jj]);
113 TFile *fdOut=
new TFile(outF+
".wana.hist.root",
"recreate"); assert(fdOut->IsOpen());
114 printf(
"saving histo w/ events to %s\n",fdOut->GetName());
116 for(
int k=0;k<mxEta;k++) {
117 TString cEta=Form(
"Eta%d",k+1);
120 for (
int iq=0;iq<mxQ;iq++) hWyield[iq][k]->Write();
135 int throwSpin4(
double *prob4) {
136 double x=rnd->Uniform();
137 for(
int is=0; is<mxSS; is++)
138 if(x<prob4[is])
break;
145 void getProbOneEta(
double P1,
double P2,
double WAL1,
double WAL2,
double WALL,
146 double alpha1,
double alpha2,
double beta,
double *lumi,
148 printf(
"getProbOneEta INPUT: pol1=%.2f, pol2=%.2f, W: AL1=%g AL2=%g ALL=%g \n",P1,P2,WAL1,WAL2,WALL);
149 printf(
"input lumis: ");
for(
int is=0;is<mxSS; is++) printf(
"%8.3f ", lumi[is]);printf(
"\n");
150 if(beta<0.1) {printf(
"changed beta WARN\n"); beta=0.9;}
151 printf(
"input BG: beta=%.3f alpha1=%.3f alpha2=%.3f\n",beta,alpha1, alpha2);
153 double ppW , pnW, npW, nnW ;
155 ppW=lumi[0]*(1. +(WAL1*beta +alpha1)*P1 +( WAL2*beta +alpha2)*P2 +WALL*beta*P1*P2 );
156 pnW=lumi[1]*(1. +(WAL1*beta +alpha1)*P1 -( WAL2*beta +alpha2)*P2 -WALL*beta*P1*P2 );
157 npW=lumi[2]*(1. -(WAL1*beta +alpha1)*P1 +( WAL2*beta +alpha2)*P2 -WALL*beta*P1*P2 );
158 nnW=lumi[3]*(1. -(WAL1*beta +alpha1)*P1 -( WAL2*beta +alpha2)*P2 +WALL*beta*P1*P2 );
166 for(
int is=0;is<mxSS; is++) prob[is]/=prob[3];
168 printf(
"computed probs:%8.3f ", prob[0]);
for(
int is=1;is<mxSS; is++) printf(
"%8.3f ", prob[is]-prob[is-1]); printf(
"\n");