-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSimulation.cc
95 lines (78 loc) · 3.67 KB
/
Simulation.cc
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
#include <cmath>
#include "Simulation.h"
void setupTrackByToyMC(SVector3& pos, SVector3& mom, SMatrixSym66& covtrk, std::vector<Hit>& hits, int& charge, float pt) {
unsigned int nTotHit = 10;
//assume beam spot width 1mm in xy and 1cm in z
pos=SVector3(0.1*g_gaus(g_gen), 0.1*g_gaus(g_gen), 1.0*g_gaus(g_gen));
if (charge==0) {
if (g_unif(g_gen) > 0.5) charge = -1;
else charge = 1;
}
float phi = 0.5*TMath::Pi()*g_unif(g_gen); // make an angle between 0 and pi/2
float px = pt * cos(phi);
float py = pt * sin(phi);
if (g_unif(g_gen)>0.5) px*=-1.;
if (g_unif(g_gen)>0.5) py*=-1.;
float pz = pt*(2.3*(g_unif(g_gen)-0.5));//so that we have -1<eta<1
mom=SVector3(px,py,pz);
covtrk=ROOT::Math::SMatrixIdentity();
//initial covariance can be tricky
for (unsigned int r=0;r<6;++r) {
for (unsigned int c=0;c<6;++c) {
if (r==c) {
if (r<3) covtrk(r,c)=pow(1.0*pos[r],2);//100% uncertainty on position
else covtrk(r,c)=pow(1.0*mom[r-3],2); //100% uncertainty on momentum
} else covtrk(r,c)=0.; //no covariance
}
}
//std::cout << "track with p=" << px << " " << py << " " << pz << " pt=" << sqrt(px*px+py*py) << " p=" << sqrt(px*px+py*py+pz*pz) << std::endl;
float hitposerrXY = 0.01;//assume 100mum uncertainty in xy coordinate
float hitposerrZ = 0.1;//assume 1mm uncertainty in z coordinate
TrackState initState;
initState.parameters=SVector6(pos[0],pos[1],pos[2],mom[0],mom[1],mom[2]);
initState.errors=covtrk;
initState.charge=charge;
TrackState tmpState = initState;
//do 4 cm in radius using propagation.h
for (unsigned int nhit=1;nhit<=nTotHit;++nhit) {
TrackState propState = propagateHelixToR(tmpState,4.*float(nhit));//radius of 4*nhit
float hitx = hitposerrXY*g_gaus(g_gen)+propState.parameters.At(0);
float hity = hitposerrXY*g_gaus(g_gen)+propState.parameters.At(1);
//float hity = sqrt((pos.At(0) + k*(px*sinAP-py*(1-cosAP)))*(pos.At(0) + k*(px*sinAP-py*(1-cosAP)))+
// (pos.At(1) + k*(py*sinAP+px*(1-cosAP)))*(pos.At(1) + k*(py*sinAP+px*(1-cosAP)))-
// hitx*hitx);//try to get the fixed radius
float hitz = hitposerrZ*g_gaus(g_gen)+propState.parameters.At(2);
//std::cout << "hit#" << nhit << " " << hitx << " " << hity << " " << hitz << std::endl;
SVector3 x1(hitx,hity,hitz);
SMatrixSym33 covx1 = ROOT::Math::SMatrixIdentity();
covx1(0,0)=hitposerrXY*hitposerrXY;
covx1(1,1)=hitposerrXY*hitposerrXY;
covx1(2,2)=hitposerrZ*hitposerrZ;
Hit hit1(x1,covx1);
hits.push_back(hit1);
tmpState = propState;
}
/*
//do 4 cm along path
for (unsigned int nhit=1;nhit<=nTotHit;++nhit) {
float distance = 4.*float(nhit);//~4 cm distance along curvature between each hit
float angPath = distance/curvature;
float cosAP=cos(angPath);
float sinAP=sin(angPath);
float hitx = gRandom->Gaus(0,hitposerr)+(pos.At(0) + k*(px*sinAP-py*(1-cosAP)));
float hity = gRandom->Gaus(0,hitposerr)+(pos.At(1) + k*(py*sinAP+px*(1-cosAP)));
//float hity = sqrt((pos.At(0) + k*(px*sinAP-py*(1-cosAP)))*(pos.At(0) + k*(px*sinAP-py*(1-cosAP)))+
// (pos.At(1) + k*(py*sinAP+px*(1-cosAP)))*(pos.At(1) + k*(py*sinAP+px*(1-cosAP)))-
// hitx*hitx);//try to get the fixed radius
float hitz = gRandom->Gaus(0,hitposerr)+(pos.At(2) + distance*ctgTheta);
//std::cout << "hit#" << nhit << " " << hitx << " " << hity << " " << hitz << std::endl;
SVector3 x1(hitx,hity,hitz);
SMatrixSym33 covx1 = ROOT::Math::SMatrixIdentity();
covx1(0,0)=hitposerr*hitposerr;
covx1(1,1)=hitposerr*hitposerr;
covx1(2,2)=hitposerr*hitposerr;
Hit hit1(x1,covx1);
hits.push_back(hit1);
}
*/
}