1 | /* |
---|
2 | To run this macro you should set the kDevelop mode in rootlogon.C and do: |
---|
3 | |
---|
4 | root [] .x CheckHoughTransform.C+ |
---|
5 | |
---|
6 | then answer to questions, |
---|
7 | to choose the kind of HoughTransform to use look in |
---|
8 | file config/Reco/HoughModule.cfg and change |
---|
9 | HoughModule.KindHough=linear or sinusoidal |
---|
10 | |
---|
11 | |
---|
12 | */ |
---|
13 | #include <vector> |
---|
14 | #include "EsafRandom.hh" |
---|
15 | #include "HoughFit.hh" |
---|
16 | |
---|
17 | #include <iostream> |
---|
18 | |
---|
19 | #include "TBrowser.h" |
---|
20 | #include "TH1.h" |
---|
21 | #include "TH2F.h" |
---|
22 | #include "TVector3.h" |
---|
23 | #include "TGraph.h" |
---|
24 | #include "TCanvas.h" |
---|
25 | |
---|
26 | using namespace std; |
---|
27 | void DoHoughTransform(Int_t dohough); |
---|
28 | |
---|
29 | //______________________________________________________________________________ |
---|
30 | void CheckHoughTransform() { |
---|
31 | Int_t dohough; |
---|
32 | cout<<"\nHoughFit of signal+background(1),signal(2),background(3)"<<endl; |
---|
33 | cout<<"Which do you want? "; |
---|
34 | cin>>dohough; |
---|
35 | if( dohough!=1 && dohough!=2 && dohough!=3 ){ |
---|
36 | cout<<"Not valid choice, return"<<endl; |
---|
37 | return; |
---|
38 | } |
---|
39 | DoHoughTransform(dohough); |
---|
40 | } |
---|
41 | |
---|
42 | //______________________________________________________________________________ |
---|
43 | void DoHoughTransform(Int_t dohough) { |
---|
44 | |
---|
45 | TRandom* rndm = EsafRandom::Get(); |
---|
46 | |
---|
47 | |
---|
48 | Double_t m=-1+2*rndm->Rndm(); |
---|
49 | Double_t frac=0; |
---|
50 | string nameroot; |
---|
51 | if(dohough==1 || dohough==2){ |
---|
52 | cout<<"Fraction of signal (between 0 and 1)= "; |
---|
53 | cin>>frac; |
---|
54 | if(dohough==1) nameroot="hfbkgsign.root"; |
---|
55 | if(dohough==2) nameroot="hfsign.root"; |
---|
56 | }else{ |
---|
57 | nameroot="hfbkg.root"; |
---|
58 | } |
---|
59 | TFile *f = TFile::Open(nameroot.c_str(), "RECREATE" ); |
---|
60 | |
---|
61 | Float_t ex=0.025;//error=1gtu |
---|
62 | Float_t ey=0.004;//error=4mm |
---|
63 | Double_t x1=0;//tempo se metto gtu*2.5*0.01 |
---|
64 | Double_t x2=2;//tempo se metto gtu*2.5*0.01 |
---|
65 | |
---|
66 | /* |
---|
67 | Float_t ex=0.004;//error=4mm |
---|
68 | Float_t ey=0.004;//error=4mm |
---|
69 | Double_t x1=-1;//m |
---|
70 | Double_t x2=1;//m |
---|
71 | */ |
---|
72 | Double_t y1=-1;//m |
---|
73 | Double_t y2=1;//m |
---|
74 | |
---|
75 | Double_t xs1=rndm->Rndm()+x1; |
---|
76 | Double_t xs2=xs1+1; |
---|
77 | Double_t ys1=y1+(rndm->Rndm())*(y2-y1); |
---|
78 | Double_t ys2=ys1+m*(xs2-xs1); |
---|
79 | Double_t q=ys1-m*xs1; |
---|
80 | |
---|
81 | Int_t bin=100; |
---|
82 | TH2F *hrndmbkgsign=new TH2F("hrndmbkgsign","hrndmbkgsign",bin,x1,x2,bin,y1,y2); |
---|
83 | |
---|
84 | vector<Double_t> xbkg; |
---|
85 | vector<Double_t> ybkg; |
---|
86 | vector<Int_t> cbkg; |
---|
87 | vector<Double_t> xsign; |
---|
88 | vector<Double_t> ysign; |
---|
89 | vector<Int_t> csign; |
---|
90 | vector<Double_t> xbkgsign; |
---|
91 | vector<Double_t> ybkgsign; |
---|
92 | vector<Int_t> cbkgsign; |
---|
93 | Double_t meangaussr=0.005; |
---|
94 | Double_t sigmagaussr=0.002; |
---|
95 | Double_t mu=0.3*2.5;//rate per pixel per gtu |
---|
96 | Double_t timelenght=10;//gtu |
---|
97 | TVector2 v1(xs1,ys1); |
---|
98 | TVector2 v2(xs2,ys2); |
---|
99 | TVector2 vmax(xs1+(xs2-xs1)*0.5,ys1+(ys2-ys1)*0.5); |
---|
100 | Double_t sigmadistv1v2=(v1-v2).Mod()*0.5; |
---|
101 | for(Int_t i=0;i<1000;i++){ |
---|
102 | Double_t xb=x1+(rndm->Rndm())*(x2-x1); |
---|
103 | Double_t yb=y1+(rndm->Rndm())*(y2-y1); |
---|
104 | Int_t cb=(Int_t)(rndm->Poisson(mu)*timelenght); |
---|
105 | xbkg.push_back(xb); |
---|
106 | ybkg.push_back(yb); |
---|
107 | cbkg.push_back(cb); |
---|
108 | xbkgsign.push_back(xb); |
---|
109 | ybkgsign.push_back(yb); |
---|
110 | cbkgsign.push_back(cb); |
---|
111 | if(rndm->Rndm()<frac){ |
---|
112 | Double_t xsexact=xs1+(rndm->Rndm())*(xs2-xs1); |
---|
113 | Double_t ysexact=(m*xsexact+q); |
---|
114 | TVector2 vcurr(xsexact,ysexact); |
---|
115 | Double_t distexact=(vcurr-vmax).Mod(); |
---|
116 | Double_t cs=10*TMath::Gaus(distexact,0,sigmadistv1v2,kFALSE); |
---|
117 | for(Int_t ci=0;ci<cs;ci++){ |
---|
118 | Double_t r=rndm->Gaus(meangaussr,sigmagaussr); |
---|
119 | Double_t phi=2*TMath::Pi()*rndm->Rndm(); |
---|
120 | Double_t xstep=r*cos(phi); |
---|
121 | Double_t ystep=r*sin(phi); |
---|
122 | TVector2 vstep(xstep,ystep); |
---|
123 | vcurr=vcurr+vstep; |
---|
124 | Double_t xs=vcurr.X(); |
---|
125 | Double_t ys=vcurr.Y(); |
---|
126 | xsign.push_back(xs); |
---|
127 | ysign.push_back(ys); |
---|
128 | csign.push_back(1); |
---|
129 | xbkgsign.push_back(xs); |
---|
130 | ybkgsign.push_back(ys); |
---|
131 | cbkgsign.push_back(1); |
---|
132 | hrndmbkgsign->Fill(xs,ys,1); |
---|
133 | } |
---|
134 | } |
---|
135 | hrndmbkgsign->Fill(xb,yb,cb); |
---|
136 | } |
---|
137 | |
---|
138 | TCanvas *b=new TCanvas("b","b",1); |
---|
139 | b->Divide(2,1); |
---|
140 | b->cd(1);hrndmbkgsign->Draw(); |
---|
141 | b->cd(2);hrndmbkgsign->Draw("LEGO"); |
---|
142 | b->Write(); |
---|
143 | delete b; |
---|
144 | delete hrndmbkgsign; |
---|
145 | |
---|
146 | vector<Double_t> x; |
---|
147 | vector<Double_t> y; |
---|
148 | vector<Int_t> c; |
---|
149 | if(dohough==1){ |
---|
150 | x=xbkgsign; y=ybkgsign; c=cbkgsign; |
---|
151 | }else{ |
---|
152 | if(dohough==2){ |
---|
153 | x=xsign; y=ysign; c=csign; |
---|
154 | }else{ |
---|
155 | x=xbkg; y=ybkg; c=cbkg; |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | HoughFit *hf = new HoughFit(x, y, c, 1, ex, ey); |
---|
160 | Double_t mh = hf->GetSlope(); |
---|
161 | Double_t qh = hf->GetOffset(); |
---|
162 | Float_t cmaxtocmedio = hf->GetMaxToMedium(); |
---|
163 | cout<<"\nfrom HoughFit: mh="<<mh<<" (m_sim="<<m<<")"<<endl; |
---|
164 | cout<<" qh="<<qh<<" (q_sim="<<q<<")"<<endl; |
---|
165 | cout<<" cmaxtocmedio="<<cmaxtocmedio<<endl; |
---|
166 | f->Close(); |
---|
167 | delete hf; |
---|
168 | |
---|
169 | |
---|
170 | cout<<"\nlook at the results in file --> "<<nameroot.c_str()<<"\n"<<endl; |
---|
171 | TBrowser* bro = new TBrowser(); |
---|
172 | |
---|
173 | } |
---|