00001 #include <TH2.h>
00002 #include <TStyle.h>
00003 #include <TCanvas.h>
00004 #include <TF1.h>
00005 #include <TSystem.h>
00006 #include <TLatex.h>
00007 #include <iostream>
00008 #include <fstream>
00009 #include <TGraph.h>
00010 #include <TGraphErrors.h>
00011 #include <TMath.h>
00012 #include <TLine.h>
00013 #include <TChain.h>
00014 #include <TClonesArray.h>
00015 #include <TFile.h>
00016 #include <TPostScript.h>
00017 #include <TNtuple.h>
00018 #include <TString.h>
00019 #include <TRandom.h>
00020 #include <TRandom2.h>
00021
00022 void
00023 frankSimu(float rotAngle=0., long nEvents = 1000) {
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 double eLoss[10000];
00056 ifstream inFile("BichselELossProbHighBG.dat");
00057 double cl1, cl2, cl3, cl4, cl5, cl6, cl7;
00058 for (int i = 0; i < 10000; i++) {
00059 inFile >> cl1 >> cl2 >> cl3 >> cl4 >> cl5 >> cl6>> cl7;
00060 eLoss[i] = cl4;
00061 }
00062
00063 float angle = TMath::Pi() * rotAngle / 180.;
00064
00065 double pathLength = 3.2 / TMath::Cos(angle);
00066 double pairsPerMM = 4.;
00067
00068
00069 TRandom2* tR = new TRandom2();
00070 tR->SetSeed(0);
00071
00072 TH1F* hMean = new TH1F("hMean", "hMean", 100, -1, 1);
00073 TH1F* hNP = new TH1F("hNP", "hNP", 35, -0.5, 34.5);
00074 hNP->SetXTitle("Number of Primary Pairs");
00075 TH1F* hElectron = new TH1F("hElectron", "hElectron", 250, -0.5, 249.5);
00076 TH1F* hEnergy = new TH1F("hEnergy", "hEnergy", 250, 0, 5.);
00077 hEnergy->SetXTitle("Energy Loss [keV]");
00078 TH1F* hEPerColl = new TH1F("hEPerColl", "hEPerColl", 100, 0, 100);
00079 hEPerColl->SetXTitle("Energy Loss per collision [eV]");
00080
00081 TF1* fElectronDist = new TF1("fElectronDist", "1/(x*x*x)", 0, 100);
00082 float pos[1000];
00083 Double_t weight[1000];
00084 int totalElectrons = 0;
00085 float totalEnergy = 0;
00086 double dist = 0;
00087
00088 for (int i = 0; i < nEvents; i++) {
00089
00090 int np = 0;
00091 totalElectrons = 0;
00092 totalEnergy = 0;
00093 dist = 0;
00094 while (1) {
00095
00096 double stepLength = - TMath::Log(tR->Uniform()) / pairsPerMM;
00097 dist += stepLength;
00098 if (dist > pathLength) break;
00099 np++;
00100 pos[np-1] = dist/pathLength -0.5;
00101
00102 int rndBin = ((int) (10000.0 * tR->Uniform()));
00103 double eL = eLoss[rndBin];
00104
00105 int ns = 1 + ((int) ((eL-15.4)/26.));
00106 totalEnergy += eL;
00107 hEPerColl->Fill(eL);
00108 if (ns < 0) ns = 0;
00109 weight[np-1] = ns;
00110 totalElectrons += weight[np-1];
00111 }
00112 float mpos = TMath::Mean(np, pos, weight);
00113 mpos = mpos * 3.2 * TMath::Sin(angle);
00114 hMean->Fill(mpos);
00115 hNP->Fill(np);
00116 hElectron->Fill(totalElectrons);
00117 totalEnergy = totalEnergy / 1000.;
00118 hEnergy->Fill(totalEnergy);
00119 }
00120
00121 TCanvas* c1 = new TCanvas("SimuMean", "SimuMean", 600, 450);
00122 hMean->Draw();
00123 TCanvas* c2 = new TCanvas("NumberOfPairs", "NumberOfPairs", 600, 800);
00124 c2->Divide(1, 2);
00125 c2->cd(1);
00126 hNP->Draw();
00127 c2->cd(2);
00128 hEPerColl->Draw();
00129 TCanvas* c3 = new TCanvas("NumberOfElectrons", "NumberOfElectrons", 600, 800);
00130 c3->Divide(1, 2);
00131 c3->cd(1);
00132 hElectron->Draw();
00133 c3->cd(2);
00134 hEnergy->Draw();
00135
00136 }