-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.cpp
More file actions
205 lines (149 loc) · 7.14 KB
/
Copy pathsimulation.cpp
File metadata and controls
205 lines (149 loc) · 7.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <iostream>
#include <cmath>
#include <ctime>
#include <string>
#include "Generator.h"
#include "Detector.h"
#include "ScatteringDet.h"
#include "EnergyLossDet.h"
#include "TLorentzVector.h"
#include "TMath.h"
#include "TH1D.h"
#include "TCanvas.h"
#include "TROOT.h"
#include "TRandom.h"
//#define pmax 3.5 //da configurare a mano
//#define thmax 0.01 //da configurare a mano
#define par1 0.1
#define par2 0.02
#define NScatDet 3
#define m0 5.3
#define pz 4
#define m1 0.5
#define m2 0.13
#define nevent 10000
Double_t InvMass(TLorentzVector* v1, TLorentzVector* v2){
TLorentzVector temp(0,0,0,0);
temp=*v1+*v2;
return (temp.M());
}
void Process(Double_t pmax, Double_t thmax, Double_t* dataVec,TRandom* rnd){
Generator* g1= new Generator(rnd);
Double_t beta,E,Ei1,Ei2;
bool debug=false;
//lab frame
E=TMath::Sqrt(pz*pz+m0*m0);
beta=pz/E;
g1->GeneratePrimary(m0,pz);
if(debug) std::cout<< "PRIMARY PARTICLE GENERATED LAB FRAME"<<std::endl;
if(debug) std::cout<<g1->GetV0()->Px()<<" "<<g1->GetV0()->Py() << " " << g1->GetV0()->Pz() << " "<< g1->GetV0()->E()<<std::endl;
if(debug) std::cout<<std::endl;
g1->GetV0()->Boost(0,0,-beta); //boost to the Center of mass frame
if(debug) std::cout<< "PRIMARY PARTICLE GENERATED C.O.M. FRAME"<<std::endl;
if(debug) std::cout<<g1->GetV0()->Px()<<" "<<g1->GetV0()->Py() << " " << g1->GetV0()->Pz() << " "<< g1->GetV0()->E()<<std::endl;
if(debug) std::cout<<std::endl;
g1->DecaySim(m0,m1,m2);
g1->GetV1()->Boost(0,0,beta); //return on lab frame
g1->GetV2()->Boost(0,0,beta); //return on lab frame
Ei1=g1->GetV1()->E();
Ei2=g1->GetV2()->E();
if(debug) std::cout<< "LAB FRAME AFTER DECAY P1,P2" << std::endl;
if(debug) std::cout<<g1->GetV1()->Px()<<" "<<g1->GetV1()->Py() << " " << g1->GetV1()->Pz() << " "<< g1->GetV1()->E()<<" "<<g1->GetV1()->M()<<std::endl;
if(debug) std::cout<<g1->GetV2()->Px()<<" "<<g1->GetV2()->Py() << " " << g1->GetV2()->Pz() << " "<< g1->GetV2()->E()<<" "<<g1->GetV2()->M()<<std::endl;
if(debug) std::cout<<std::endl;
//The two particle are in Lab frame
//Simulation of detector interaction
ScatteringDet* Sdet1= new ScatteringDet();
Sdet1->SetMean(0);
Sdet1->SetStdev(pmax*thmax/g1->GetV1()->P());
Sdet1->SetGen(rnd);
ScatteringDet* Sdet2= new ScatteringDet();
Sdet2->SetMean(0);
Sdet2->SetStdev(pmax*thmax/g1->GetV2()->P());
Sdet2->SetGen(rnd);
EnergyLossDet* Edet1= new EnergyLossDet();
Edet1->SetMean(par1*g1->GetV1()->P());
Edet1->SetStdev(par2*g1->GetV1()->P());
Edet1->SetGen(rnd);
EnergyLossDet* Edet2= new EnergyLossDet();
Edet2->SetMean(par1*g1->GetV2()->P());
Edet2->SetStdev(par2*g1->GetV2()->P());
Edet2->SetGen(rnd);
// if(g1->GetV1()->Pz()>0 && g1->GetV2()->Pz()>0 ){
if(debug) std::cout<< "SCATTERING PROCESS..." << std::endl;
for(int i=0;i<NScatDet;i++){
Sdet1->ActionScat(g1->GetV1());
Sdet2->ActionScat(g1->GetV2());
dataVec[i]=InvMass(g1->GetV1(),g1->GetV2());
if(debug) std::cout<<g1->GetV1()->Px()<<" "<<g1->GetV1()->Py() << " " << g1->GetV1()->Pz() << " "<< g1->GetV1()->E()<<" "<<g1->GetV1()->M()<<std::endl;
if(debug) std::cout<<g1->GetV2()->Px()<<" "<<g1->GetV2()->Py() << " " << g1->GetV2()->Pz() << " "<< g1->GetV2()->E()<<" "<<g1->GetV2()->M()<<std::endl;
if(debug) std::cout<<std::endl;
}//chiudo for
//}else{if(debug) std::cout << "BAD PRODUCTION" << std::endl;}//chiudo if
if(debug) std::cout<< "ENERGY LOSS PROCESS..." << std::endl;
if(debug) std::cout<< "BEFORE" << std::endl;
if(debug) std::cout<<g1->GetV1()->Px()<<" "<<g1->GetV1()->Py() << " " << g1->GetV1()->Pz() << " "<< g1->GetV1()->E()<<" "<<g1->GetV1()->M()<<std::endl;
if(debug) std::cout<<g1->GetV1()->Px()/g1->GetV1()->P()<<" "<<g1->GetV1()->Py()/g1->GetV1()->P() << " " << g1->GetV1()->Pz()/g1->GetV1()->P() << " "<< g1->GetV1()->E()<<" "<<g1->GetV1()->M()<<std::endl;
if(debug) std::cout<<g1->GetV2()->Px()<<" "<<g1->GetV2()->Py() << " " << g1->GetV2()->Pz() << " "<< g1->GetV2()->E()<<" "<<g1->GetV2()->M()<<std::endl;
if(debug) std::cout<<g1->GetV2()->Px()/g1->GetV2()->P()<<" "<<g1->GetV2()->Py()/g1->GetV2()->P() << " " << g1->GetV2()->Pz()/g1->GetV2()->P() << " "<< g1->GetV2()->E()<<" "<<g1->GetV2()->M()<<std::endl;
if(debug) std::cout<<std::endl;
Edet1->EnergyLoss(g1->GetV1());
Edet2->EnergyLoss(g1->GetV2());
dataVec[3]=InvMass(g1->GetV1(),g1->GetV2());
if(debug) std::cout<< "AFTER" << std::endl;
if(debug) std::cout<<g1->GetV1()->Px()<<" "<<g1->GetV1()->Py() << " " << g1->GetV1()->Pz() << " "<< g1->GetV1()->E()<<" "<<g1->GetV1()->M()<<std::endl;
if(debug) std::cout<<g1->GetV1()->Px()/g1->GetV1()->P()<<" "<<g1->GetV1()->Py()/g1->GetV1()->P() << " " << g1->GetV1()->Pz()/g1->GetV1()->P() << " "<< g1->GetV1()->E()<<" "<<g1->GetV1()->M()<<std::endl;
if(debug) std::cout<<g1->GetV2()->Px()<<" "<<g1->GetV2()->Py() << " " << g1->GetV2()->Pz() << " "<< g1->GetV2()->E()<<" "<<g1->GetV2()->M()<<std::endl;
if(debug) std::cout<<g1->GetV2()->Px()/g1->GetV2()->P()<<" "<<g1->GetV2()->Py()/g1->GetV2()->P() << " " << g1->GetV2()->Pz()/g1->GetV2()->P() << " "<< g1->GetV2()->E()<<" "<<g1->GetV2()->M()<<std::endl;
if(debug) std::cout<<std::endl;
dataVec[4]= g1->GetV1()->E()/Ei1 ;
dataVec[5]= g1->GetV2()->E()/Ei2;
//delete g1,Sdet1,Sdet2,Edet1,Edet2;
}
int main(int argc, char *argv[]){
//gROOT->SetBatch(kTRUE);
TRandom* rnd=new TRandom(time(0));
Double_t pmax,thmax;
Double_t Nrms=7;
Double_t data[6]={0}; //0...3 invariant mass after detector, 4,5 response for m1 and m2
int i;
if (argc<3){
std::cout << "enter -> " << argv[0] <<" PMax ThetaMax" << std::endl;
return 0;
}
pmax = atof(argv[1]);
thmax = atof(argv[2]);
TH1D* HistoInvMass[4];
TH1D* HistoResp[2];
for (i=0;i<4;i++){
if(i<2) HistoResp[i]=new TH1D(("Response M"+std::to_string(i+1)).c_str(),("Response M"+std::to_string(i+1)).c_str(),150,0.6,1);
HistoInvMass[i]= new TH1D(("InvmassDet"+std::to_string(i+1)).c_str(),("InvmassDet"+std::to_string(i+1)).c_str(),300,4,6);
}
for(i=0;i<nevent;i++){
Process(pmax,thmax,data,rnd);
HistoInvMass[0]->Fill(data[0]);
HistoInvMass[1]->Fill(data[1]);
HistoInvMass[2]->Fill(data[2]);
HistoInvMass[3]->Fill(data[3]);
HistoResp[0]->Fill(data[4]);
HistoResp[1]->Fill(data[5]);
//std::cout<< data[0]<<" "<< data[1]<<" "<<data[2] << " " << data[3]<<" "<< data[4] <<std::endl;
}
TCanvas* CanvInvMass = new TCanvas("canv1","InvMass",1200,800);
TCanvas* CanvResp = new TCanvas("canv2","Response",1200,800);
CanvInvMass->Divide(2,2);
CanvResp->Divide(2,1);
for(i=0;i<4;i++){
if(i<2){
CanvResp->cd(i+1);
HistoResp[i]->GetXaxis()->SetRangeUser(HistoResp[i]->GetMean()-5*HistoResp[i]->GetRMS(),HistoResp[i]->GetMean()+5*HistoResp[i]->GetRMS());
HistoResp[i]->Draw("HISTO");
}
CanvInvMass->cd(i+1);
HistoInvMass[i]->GetXaxis()->SetRangeUser(HistoInvMass[i]->GetMean()-5.5*HistoInvMass[i]->GetRMS(),HistoInvMass[i]->GetMean()+5*HistoInvMass[i]->GetRMS());
HistoInvMass[i]->Draw("HISTO");
}
CanvInvMass->SaveAs("invmass.pdf");
CanvResp->SaveAs("response.pdf");
return 0;
}