ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HFmon2012/macros/toy.C
(Generate patch)

Comparing UserCode/HFmon2012/macros/toy.C (file contents):
Revision 1.1 by yilmaz, Tue Feb 28 12:48:29 2012 UTC vs.
Revision 1.3 by gaydin, Tue Aug 14 13:32:35 2012 UTC

# Line 1 | Line 1
1 + #include <string>
2 + #include <vector>
3 + #include <iostream>
4 + #include <map>
5 + #include <utility>
6 +
7 + //#include "HistogramManager.h"
8 + //#include "Map.h"
9 +
10 + #include "TNtuple.h"
11 + #include "TRandom.h"
12 +
13 + #include "TTree.h"
14 + #include "TFile.h"
15 + #include "TH1I.h"
16 + #include "TH1F.h"
17 + #include "TH2F.h"
18 + #include "TProfile.h"
19 + #include "TString.h"
20 + #include "TMath.h"
21 + #include "TF1.h"
22 + #include "TString.h"
23 + #include <fstream>
24 + #include <vector>
25 + #include <iomanip>
26 + #include <iostream>
27 +
28 + using namespace std;
29 +
30 +
31 + class Laser{
32 + public:
33 +  Laser(double rin = 0.5){
34 +    r = rin;
35 +    s1 = 100.;
36 +    s2 = r*s1;
37 +
38 +    w = 0.1;
39 +
40 +    f1 = new TF1("f1","gaus",-10,20);
41 +    f2 = new TF1("f2","gaus",-10,20);
42  
43 +    f1->SetParameter(0,s1);
44 +    f2->SetParameter(0,s2);
45  
46 +    f1->SetParameter(1,0);
47 +    f2->SetParameter(1,1);
48 +
49 +    f1->SetParameter(2,w);
50 +    f2->SetParameter(2,w);
51 +
52 +  }
53 +
54 +  void fillHit(TH1* h, double phase = 0){
55 +
56 +    h->Reset();
57 +    for(int i = 0; i < h->GetNbinsX(); ++i){
58 +      double low = h->GetBinLowEdge(i);
59 +      double high = h->GetBinLowEdge(i+1);
60 +      double mid = (low+high)/2.;
61 +
62 +      low = low + phase - 4;
63 +      high = high + phase - 4;
64 +
65 +      double adc = f1->Integral(low,high)+f2->Integral(low,high);
66 +
67 +      h->Fill(mid,adc);
68 +    }
69 +
70 +    h->Draw();
71 +
72 +  };
73 +
74 +
75 +
76 +  double s1,s2,r,w;
77 +  TF1* f1, *f2;
78  
79  
5 void toy(double pp = 0){
80  
81 + };
82  
83  
84  
10  TF1* f0 = new TF1("f0","gaus",0,10);
85  
12  TF1* f1 = new TF1("f1","gaus",-10,10);
13  TF1* f2 = new TF1("f2","gaus",-10,10);
86  
15  f1->SetParameter(0,1);
16  f1->SetParameter(1,0);
17  f1->SetParameter(2,0.27);
18  f2->SetParameter(0,1);
19  f2->SetParameter(1,0);
20  f2->SetParameter(2,0.27);
87  
88 + void simulate(double inputR = 0.5){
89 +
90 +  Laser *laz = new Laser(inputR);
91 +
92 +
93 +  TF1* f0 = new TF1("f0","pol0",-1,3);
94    f0->SetParameter(0,1);
95 <  f0->SetParameter(1,4);
96 <  f0->SetParameter(2,1);
95 >  //  f0->SetParameter(1,4);
96 >  //  f0->SetParameter(2,1);
97  
98 <  TNtuple* nt = new TNtuple("nt","","s1:s2:r:p");
98 >  TNtuple* nt = new TNtuple(Form("nt%d",(int)(100.*inputR)),"","s1:s2:r:p");
99  
100    TH1D* hit = new TH1D("hit","",10,0,10);
101  
102 <  for(int iev = 0; iev < 1000; iev++){
102 >  double noiseFactor = 10;
103 >
104 >  int Nev = 10000;
105 >
106 >  for(int iev = 0; iev < Nev; iev++){
107  
108      hit->Reset();
109  
110      double p = f0->GetRandom();
111 < //    p = pp;
111 >    laz->fillHit(hit,p);
112  
113      for(int i = 0; i < 10; ++i){
114 <      hit->Fill(10*gRandom->Uniform(),0.1*(gRandom->Uniform()-0.5));
39 <    }
40 <
41 <    for(int i = 0; i < 100; ++i){
42 <      hit->Fill(f1->GetRandom()+p,1);
43 <      hit->Fill(f2->GetRandom()+1+p,0.9);
44 <
114 >      hit->Fill(i+0.5,noiseFactor*(gRandom->Uniform()-0.5));
115      }
116  
117      double s1 = hit->GetBinContent(4);
# Line 54 | Line 124 | void toy(double pp = 0){
124    }
125  
126  
127 <  nt->Draw("r:p","r < 5","");
127 >  nt->Draw("r:p","r > -0.2 &&r < 1.2","colz");
128 >  nt->Draw("r:p","r > -0.2 &&r < 1.2","prof same");
129  
130    //  hit->Draw();
131  
132   }
133  
134 +
135 + void toy(){
136 +
137 +  simulate();
138 +
139 + }
140 +
141 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines