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

Last change on this file since 2470 was 2449, checked in by marcos, 22 years ago
*** empty log message ***
File size: 3.4 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// This macro shows how to use the class MMcWeightEnergySpecCalc //
28// to convert the energy spectrum of the MC showers generated with Corsika, //
29// to a different one. //
30// //
31//////////////////////////////////////////////////////////////////////////////
32
33void weights(TString filename="/up1/data/Magic-MC/CameraAll/Gammas/zbin0/Gamma_zbin0_0_7_1000to1009_w0-4:4:2.root")
34{
35
36 //
37 // PartList
38 //
39 MParList parlist;
40 MTaskList tasklist;
41
42 MHMcEnergyImpact h1("h1");
43 MHMcEnergyImpact h2("h2");
44 parlist.AddToList(&h1);
45 parlist.AddToList(&h2);
46
47 MBinning binsenergy("BinningEnergy");
48 binsenergy.SetEdgesLog(100, 1, 1e5);
49 parlist.AddToList(&binsenergy);
50
51 MBinning binsimpact("BinningImpact");
52 binsimpact.SetEdges(100, 0, 450);
53 parlist.AddToList(&binsimpact);
54
55 parlist.AddToList(&tasklist);
56
57
58 //
59 // TaskList
60 //
61 MReadMarsFile reader("Events", filename);
62 reader.EnableBranch("fEnergy");
63 reader.EnableBranch("fImpact");
64
65 // ------------------
66 //
67 // Option 1. Just change the slope of the MC power law spectrum
68 //
69 //MMcWeightEnergySpecCalc wcalc(-2.0);
70 //
71 // Option 2. A completely differente specturm
72 // e.g. spectrum with exponential cutoff
73 //
74 TF1* spec = new TF1("spectrum","pow(x,[0])*exp(-x/[1])");
75 spec->SetParameter(0,-2.0); // Spectral index
76 spec->SetParameter(1,50); // Spectral index
77 MMcWeightEnergySpecCalc wcalc(spec);
78
79 MFillH hfill(&h1,"MMcEvt");
80 MFillH hfill2(&h2,"MMcEvt");
81 hfill2.SetWeight("MWeight");
82 //
83 //------------------
84
85 tasklist.AddToList(&reader);
86 tasklist.AddToList(&wcalc);
87 tasklist.AddToList(&hfill);
88 tasklist.AddToList(&hfill2);
89
90
91 //
92 // EventLoop
93 //
94 MEvtLoop magic;
95 magic.SetParList(&parlist);
96
97 if (!magic.Eventloop())
98 return;
99
100 tasklist.PrintStatistics();
101 parlist.Print();
102
103
104 //
105 // Draw the Results
106 //
107 TCanvas *c = new TCanvas();
108 c->SetLogy();
109 c->SetLogx();
110
111 TH1D* hist1 = (h1->GetHist())->ProjectionX();
112 TH1D* hist2 = (h2->GetHist())->ProjectionX();
113 hist2->SetLineColor(2);
114
115 hist1->DrawClone();
116 hist2->DrawClone("same");
117}
118
119
120
121
122
123
124
125
126
127
128
129
130
Note: See TracBrowser for help on using the repository browser.