Pluto v6.3.0
Loading...
Searching...
No Matches
make_demo_pfilter.C
Go to the documentation of this file.
1//TITLE <b>Virtual detectors and batch packs</b> This macro makes a demo filter root file
2
3{
4 //Let us create a "virtual detector"
5
6 //First, we create dummy root files
7 //For a real detector, they can be derived e.g.
8 //from a full GEANT simulation and re-opened
9 //here from a ROOT file
10
11 //Our dummy detector should have an acceptance
12 //for electrons in forward directions
13 //between 18 - 95 degrees. The efficiency
14 //of electrons should be 80%,
15 //in a momentum range below 100 MeV only 50,
16 //and below 50 MeV no acceptance
17
18 //Protons should have a flat acceptance of 90%
19 //using a forward detector (a plane) in
20 //a distance of 2m downstream with 3x3m
21
22 //Other particles are rejected
23
24 //Remember, this is NOT HADES
25
26 //This filter should come in 2 modi operandi:
27 //1. For inclusive measurements (e+e-)
28 //2. For exclusive measurements (ppe+e-)
29
30
31 //Make a pseudo-Monto-Carlo simulation:
32 //Generate particles between:
33 //mom = 0 ... 3000 MeV (x)
34 //cos(theta) = -1 ... 1 (y)
35 //phi = 0 ... 360 deg (z)
36
37 //On purpose, we do not use the Pluto convention
38 //to demonstrate the convertion inside the command list
39
40 //In addition, we apply a 1% momentum resolution...
41 //...just fixed, to keep it easy. Of course it is possible
42 //to use matrices as well
43 //This is controlled via "filter_smear_factor"
44
45 //Create the efficiency matrices:
46 TH3F *gen =
47 new TH3F ("gen", "Generated events", 30, 0, 1500, 20, -1, 1, 20, 0, 360);
48 TH3F *eff_elec =
49 new TH3F ("eff_elec", "Efficiency matrix electrons", 30, 0, 1500, 20, -1, 1, 20, 0, 360);
50 TH3F *eff_protons =
51 new TH3F ("eff_protons", "Efficiency matrix protons", 30, 0, 1500, 20, -1, 1, 20, 0, 360);
52
53 //Start the Monte-Carlo
54 int nev = 1000000;
55 for (int i=0; i<nev; i++) {
56 Double_t mom = PUtils::sampleFlat()*3000;
57 Double_t costheta = PUtils::sampleFlat()*2 - 1;
58 Double_t phi = PUtils::sampleFlat()*360;
59
60 gen->Fill(mom, costheta, phi);
61
62 Double_t theta = acos(costheta)*180/TMath::Pi();
63
64 //electrons
65 if ((theta > 18) && (theta < 95)) {
66 Double_t rnd = PUtils::sampleFlat();
67 if ((mom > 100) && (rnd < 0.8))
68 eff_elec->Fill(mom, costheta, phi);
69 else if ((mom > 50) && (rnd < 0.5))
70 eff_elec->Fill(mom, costheta, phi);
71 }
72
73 //protons
74 Double_t x = tan(acos(costheta)) * 2 * cos(phi*TMath::Pi()/180);
75 Double_t y = tan(acos(costheta)) * 2 * sin(phi*TMath::Pi()/180);
76
77 if ((fabs(x) < 1.5) && (fabs(y) < 1.5)) {
78 Double_t rnd = PUtils::sampleFlat();
79 if (rnd < 0.90)
80 eff_protons->Fill(mom,costheta,phi);
81 }
82 }
83
84 eff_elec->Divide(gen);
85 eff_protons->Divide(gen);
86
87
88 //Now we create the filter file
89 TFile *f = new TFile("pluto_demo_filter.root", "RECREATE");
90
91 //Commands with the keyword "_main" are called when the filter is attached
92 PCommandList *p = new PCommandList("_main", "echo **** This is our demo filter, v1");
93
94 //A little bit of hello information:
95 p->AddCommand("echo ********************************************************************************");
96 p->AddCommand("echo Usage: This filter works in 2 modi:");
97 p->AddCommand("echo Usage: 1.) inclusive:");
98 p->AddCommand("echo Usage: default");
99 p->AddCommand("echo Usage: 2.) exclusive measurement:");
100 p->AddCommand("echo Usage: Add in your macro after filter attachment:");
101 p->AddCommand("echo Usage: makeDistributionManager()->Startup(\"_filter_exclusive=1\");");
102 p->AddCommand("echo ********************************************************************************");
103 p->AddCommand("echo Usage: Momentum smearing is applied, you can change:");
104 p->AddCommand("echo Usage: makeDistributionManager()->Startup(\"_filter_smear_factor=....\");");
105 p->AddCommand("echo ********************************************************************************");
106 p->AddCommand("echo Debug mode: makeDistributionManager()->Startup(\"_filter_debug=1\");");
107 p->AddCommand("echo ********************************************************************************");
108 //Generate variables
109 p->AddCommand("_filter_debug=0");
110 p->AddCommand("_filter_exclusive=0");
111 p->AddCommand("_filter_smear_factor=1.");
112
113 p->Write();
114
115 //Commands with the keyword "_startup" are called when event loop is started
116 //Here, it is used to add another warning
118 new PCommandList("_startup",
119 "echo ********************************************************************************");
120
121 s->AddCommand("echo This event loop uses the demo filter ");
122 s->AddCommand("echo ********************************************************************************");
123 s->Write();
124
125 //Commands with the keyword "_loop" are called within event loop
126 //Labels should be unique. Avoid common names
127 PCommandList *l = new PCommandList("_loop");
128
129 //The first thing we have to do is to calculate for each particle under test the axes values
130
131 l->AddCommand("if (_filter_debug); echo **** New event called"); //do not forget the ";" after the if-statement
132 l->AddCommand("_start: removed=0"); //labels with colon
133 l->AddCommand("_x = [e+]->P() * 1000.; "); //Conversion of units
134 l->AddCommand("_y = [e+]->CosTheta(); ");
135 l->AddCommand("_z = (([e+]->Phi()) *180/TMath::Pi()); if (_z<0); _z = _z + 360");
136 l->AddCommand(eff_elec,"eff_ep = Eval(); rnd = sampleFlat(); if (rnd>eff_ep); [e+]->SetInActive(); removed=1");
137 l->AddCommand("mom = [e+]->P(); newmom = sampleGaus(mom,0.01*mom*_filter_smear_factor);[e+]->SetMom(newmom)");
138 l->AddCommand("if (_filter_debug && removed); echo e+: $_x, $_y, $_z eff: $eff_ep <removed>");
139 l->AddCommand("if (_filter_debug && !removed); echo e+: $_x, $_y, $_z eff: $eff_ep");
140
141 l->AddCommand("formore e+; goto _start"); // added 2 separate gotos for e+ and e- following a hint by V. Hejny
142
143 l->AddCommand("_start2: removed=0");
144 l->AddCommand("_x = [e-]->P() * 1000.;");
145 l->AddCommand("_y = [e-]->CosTheta(); ");
146 l->AddCommand("_z = (([e-]->Phi()) *180/TMath::Pi()); if (_z<0); _z = _z + 360;");
147 l->AddCommand(eff_elec,"eff_em = Eval(); rnd = sampleFlat(); if (rnd>eff_em); [e-]->SetInActive(); removed=1");
148 l->AddCommand("mom = [e-]->P(); newmom = sampleGaus(mom,0.01*mom*_filter_smear_factor);[e-]->SetMom(newmom)");
149 l->AddCommand("if (_filter_debug && removed); echo e-: $_x, $_y, $_z eff: $eff_em <removed>");
150 l->AddCommand("if (_filter_debug && !removed); echo e-: $_x, $_y, $_z eff: $eff_em");
151
152 l->AddCommand("formore e-; goto _start2");
153
154 l->AddCommand("if (!_filter_exclusive); goto _end;");
155
156 l->AddCommand("_start_proton_loop: removed=0");
157
158 l->AddCommand("_x = [p]->P() * 1000.; ");
159 l->AddCommand("_y = [p]->CosTheta(); ");
160 l->AddCommand("_z = (([p]->Phi()) *180/TMath::Pi()); if (_z<0); _z = _z + 360;");
161 //l->AddCommand("[p]->Print();");
162 l->AddCommand(eff_protons,"eff_p = Eval(); rnd = sampleFlat(); if (rnd>eff_p); [p]->SetInActive(); removed=1");
163 l->AddCommand("mom = [p]->P(); newmom = sampleGaus(mom,0.01*mom*_filter_smear_factor);[p]->SetMom(newmom)");
164 // l->AddCommand("echo $mom , $newmom");
165 //l->AddCommand("[p]->Print();");
166 l->AddCommand("if (_filter_debug && removed); echo p: $_x, $_y, $_z eff: $eff_p <removed>");
167 l->AddCommand("if (_filter_debug && !removed); echo p: $_x, $_y, $_z eff: $eff_p");
168
169 l->AddCommand("formore p; goto _start_proton_loop");
170
171 l->AddCommand("_end:");
172
173 l->Write();
174 eff_elec->Write();
175 eff_protons->Write();
176
177 f->Write();
178}
TFile * f
Definition analyze_g12C.C:8
static Double_t sampleFlat()
Definition PUtils.h:121
PParticle * p
Definition dp_mult.C:24
PParticle * s
Definition dp_mult.C:25
int nev
TH3F * eff_protons
TH3F * eff_elec
PCommandList * l