source: trunk/MagicSoft/Mars/macros/weights.C@ 2876

Last change on this file since 2876 was 2474, checked in by marcos, 21 years ago
*** empty log message ***
File size: 4.3 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC Analysis and Reconstruction
5! * Software. It is distributed to you in the hope that it can be a useful
6! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
7! * It is distributed WITHOUT ANY WARRANTY.
8! *
9! * Permission to use, copy, modify and distribute this software and its
10! * documentation for any purpose is hereby granted without fee,
11! * provided that the above copyright notice appear in all copies and
12! * that both that copyright notice and this permission notice appear
13! * in supporting documentation. It is provided "as is" without express
14! * or implied warranty.
15! *
16!
17!
18! Author(s): Marcos Lopez, 10/2003 <mailto:marcos@gae.ucm.es>
19!
20! Copyright: MAGIC Software Development, 2000-2003
21!
22!
23\* ======================================================================== */
24
25
26//////////////////////////////////////////////////////////////////////////////
27// //
28// This macro shows how to use the class MMcWeightEnergySpecCalc //
29// to convert the energy spectrum of the MC showers generated with Corsika, //
30// to a different one. //
31// //
32//////////////////////////////////////////////////////////////////////////////
33
34
35// --------------------------------------------------------------------------
36//
37//
38Double_t myfunction(Double_t *x, Double_t *par)
39{
40 Double_t xx = x[0];
41
42 return pow(xx,-2)*exp(-xx/20);
43}
44
45
46
47// --------------------------------------------------------------------------
48//
49//
50void weights(TString filename="/up1/data/Magic-MC/CameraAll/Gammas/zbin0/Gamma_zbin0_0_7_1000to1009_w0-4:4:2.root")
51{
52
53 //
54 // PartList
55 //
56 MParList parlist;
57 MTaskList tasklist;
58
59 MHMcEnergyImpact h1("h1");
60 MHMcEnergyImpact h2("h2");
61 parlist.AddToList(&h1);
62 parlist.AddToList(&h2);
63
64 MBinning binsenergy("BinningEnergy");
65 binsenergy.SetEdgesLog(100, 1, 1e5);
66 parlist.AddToList(&binsenergy);
67
68 MBinning binsimpact("BinningImpact");
69 binsimpact.SetEdges(100, 0, 450);
70 parlist.AddToList(&binsimpact);
71
72 parlist.AddToList(&tasklist);
73
74
75 //
76 // TaskList
77 //
78 MReadMarsFile reader("Events", filename);
79 reader.EnableBranch("fEnergy");
80 reader.EnableBranch("fImpact");
81
82
83 // -------------------------------------------------------------
84 //
85 // Option 1. Just change the slope of the MC power law spectrum
86 //
87 //MMcWeightEnergySpecCalc wcalc(-2.0); //<-- Uncomment me
88
89 //
90 // Option 2. A completely differente specturm pass as a TF1 function
91 // e.g. spectrum with exponential cutoff
92 //
93 //TF1 spec("spectrum","pow(x,[0])*exp(-x/[1])"); //<-- Uncomment me
94 //spec->SetParameter(0,-2.0); //<-- Uncomment me
95 //spec->SetParameter(1,50); //<-- Uncomment me
96 //MMcWeightEnergySpecCalc wcalc(spec); //<-- Uncomment me
97
98 //
99 // Option 3. A completely differente specturm pass as a cahr*
100 //
101 //char* func = "pow(x,-2)"; //<-- Uncomment me
102 //MMcWeightEnergySpecCalc wcalc(func); //<-- Uncomment me
103
104 //
105 // Option 4. A completely differente specturm pass as a c++ function
106 //
107 MMcWeightEnergySpecCalc wcalc((void*)myfunction); //<-- Uncomment me
108 //
109 //-------------------------------------------------------------
110
111
112 MFillH hfill(&h1,"MMcEvt");
113 MFillH hfill2(&h2,"MMcEvt");
114 hfill2.SetWeight("MWeight");
115
116 tasklist.AddToList(&reader);
117 tasklist.AddToList(&wcalc);
118 tasklist.AddToList(&hfill);
119 tasklist.AddToList(&hfill2);
120
121
122 //
123 // EventLoop
124 //
125 MEvtLoop magic;
126 magic.SetParList(&parlist);
127
128 if (!magic.Eventloop())
129 return;
130
131 tasklist.PrintStatistics();
132 parlist.Print();
133
134
135 //
136 // Draw the Results
137 //
138 TCanvas *c = new TCanvas();
139 c->SetLogy();
140 c->SetLogx();
141
142 TH1D* hist1 = (h1->GetHist())->ProjectionX();
143 TH1D* hist2 = (h2->GetHist())->ProjectionX();
144 hist2->SetLineColor(2);
145
146 hist1->DrawClone();
147 hist2->DrawClone("same");
148
149}
150
151
152
153
154
155
156
157
158
159
160
161
162
Note: See TracBrowser for help on using the repository browser.