00001 #include <time.h>
00002
00003 TH1F* makeToySpin(int nEvents=10000,
00004 float AL=-.25, float P1=0.35, float P2=0.25,
00005 float AN=0., float dQ1=0.0,float dQ2=0.0,
00006 float ALL=-0.4)
00007 {
00008
00009 float n[4];
00010 n[0]=1 +AL*P1 +AL*P2 +AN*dQ1 -AN*dQ2 +ALL*P1*P2;
00011 n[1]=1 +AL*P1 -AL*P2 +AN*dQ1 +AN*dQ2 -ALL*P1*P2;
00012 n[2]=1 -AL*P1 +AL*P2 -AN*dQ1 -AN*dQ2 -ALL*P1*P2;
00013 n[3]=1 -AL*P1 -AL*P2 -AN*dQ1 +AN*dQ2 +ALL*P1*P2;
00014
00015
00016 float prob[4], total_prob, cumulative_prob[4];
00017 for (int i=0;i<4;i++)
00018 {
00019 prob[i]=n[i]/(n[0]+n[1]+n[2]+n[3]);
00020 total_prob+=prob[i];
00021 printf("i=%d prob=%f\n",i, prob[i]);
00022 cumulative_prob[i]=total_prob;
00023 }
00024
00025 for (int i=0,;i<4;i++)
00026 assert(prob[i]>0);
00027
00028 time_t t;
00029 time(&t);
00030 TRandom3 *rand=new TRandom3(t);
00031
00032 char tit[1000];
00033 sprintf(tit,"toy spin4 : AL=%.2f P1=%.2f P2=%.2f AN=%.2f dQ1=%.2f dQ2=%.2f ALL=%.2f;spin4 state;counts",AL,P1,P2,AN,dQ1,dQ2,ALL);
00034
00035 TH1F* toySpin=new TH1F("toySpin4",tit,16,-0.5,15.5);
00036
00037 for (int i=0;i<nEvents;i++)
00038 {
00039 float rnd=rand->Rndm();
00040 if (rnd<cumulative_prob[0]) toySpin->Fill(10);
00041 else if (rnd<cumulative_prob[1]) toySpin->Fill(9);
00042 else if (rnd<cumulative_prob[2]) toySpin->Fill(6);
00043 else if (rnd<cumulative_prob[3]) toySpin->Fill(5);
00044 }
00045
00046 toySpin->Draw();
00047
00048 TFile *output=new TFile ("toySpin.hist.root","RECREATE");
00049 toySpin->Write();
00050 output->Close();
00051 return toySpin;
00052 }