source: trunk/Mars/mmc/MMcEvtBasic.cc@ 19344

Last change on this file since 19344 was 18571, checked in by tbretz, 8 years ago
Implemented a sanity check in SetupFits for the container name.
File size: 7.6 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): Abelardo Moralejo, 02/2005 <mailto:moralejo@pd.infn.it>
19!
20! Copyright: MAGIC Software Development, 2000-2005
21!
22!
23\* ======================================================================== */
24
25/////////////////////////////////////////////////////////////////////////////
26//
27// MMcEvtBasic
28//
29// This class contains the most basic MonteCarlo information
30// with which an event has been generated
31//
32// Note: The azimuth fTelescopePhi angle in this and other MC classes
33// follow the convention in the Corsika program (see Corsika manual and
34// TDAS 02-11). There, phi is the azimuth of the momentum vector of
35// particles, and is measured from the north direction, anticlockwise
36// (i.e, west is phi=90 degrees). When it refers to the telescope
37// orientation, it is the azimuth of a vector along the telescope axis,
38// going from the camera to the mirror. So, fTelescopeTheta=90,
39// fTelescopePhi = 0 means the telescope is pointing horizontally towards
40// South.
41//
42//
43// Version 1:
44// New container to keep the very basic informations on the
45// original MC events produced by Corsika
46//
47// Version 2:
48// - added typedef for ParticleId_t from MMcEvt
49// - replaced MMcEvt::ParticleId_t by ParticleId_t
50//
51// Version 3:
52// - moved fPhi from MMcEvt
53// - moved fTheta from MmcEvt
54//
55/////////////////////////////////////////////////////////////////////////////
56#include "MMcEvtBasic.h"
57
58#include "fits.h"
59
60#include "MString.h"
61
62#include "MLog.h"
63#include "MLogManip.h"
64
65ClassImp(MMcEvtBasic);
66
67using namespace std;
68
69// --------------------------------------------------------------------------
70//
71// Default constructor. Calls Clear()
72//
73MMcEvtBasic::MMcEvtBasic()
74{
75 fName = "MMcEvtBasic";
76 fTitle = "Basic event info from Monte Carlo";
77
78 Clear();
79}
80
81// --------------------------------------------------------------------------
82//
83// Constructor. Use this to set all data members
84//
85// THIS FUNCTION IS FOR THE SIMULATION OLNY.
86// DON'T USE THIS MEMBERFUNCTION IN THE ANALYSIS.
87//
88MMcEvtBasic::MMcEvtBasic(ParticleId_t usPId, Float_t fEner,
89 Float_t fImpa, Float_t fTPhii, Float_t fTThet)
90 : fPartId(usPId), fEnergy(fEner), fImpact(fImpa),
91 fTelescopePhi(fTPhii), fTelescopeTheta(fTThet), fTheta(0), fPhi(0)
92{
93 fName = "MMcEvtBasic";
94 fTitle = "Basic event info from Monte Carlo";
95}
96
97// --------------------------------------------------------------------------
98//
99// Copy operator. Copy all data members
100//
101void MMcEvtBasic::operator=(const MMcEvtBasic &evt)
102{
103 fPartId = evt.fPartId;
104 fEnergy = evt.fEnergy;
105 fImpact = evt.fImpact;
106 fTelescopePhi = evt.fTelescopePhi;
107 fTelescopeTheta = evt.fTelescopeTheta;
108 fPhi = evt.fPhi;
109 fTheta = evt.fTheta;
110}
111
112// --------------------------------------------------------------------------
113//
114// Reset all values.
115//
116void MMcEvtBasic::Clear(Option_t *opt)
117{
118 fPartId = kUNDEFINED;
119
120 fEnergy = -1;
121 fImpact = -1;
122
123 fTelescopePhi = 0;
124 fTelescopeTheta = 0;
125
126 fTheta = 0;
127 fPhi = 0;
128}
129
130// --------------------------------------------------------------------------
131//
132// Fill all data members
133//
134void MMcEvtBasic::Fill(ParticleId_t usPId, Float_t fEner,
135 Float_t fImpa, Float_t fTPhii, Float_t fTThet)
136{
137 fPartId = usPId;
138
139 fEnergy = fEner;
140 fImpact = fImpa;
141
142 fTelescopePhi = fTPhii;
143 fTelescopeTheta = fTThet;
144}
145
146TString MMcEvtBasic::GetParticleName(Int_t id)
147{
148 switch (id)
149 {
150 case kUNDEFINED: return "Undefined";
151 case kGAMMA: return "Gamma";
152 case kPOSITRON: return "Positron";
153 case kELECTRON: return "Electron";
154 case kANTIMUON: return "Anti-Muon";
155 case kMUON: return "Muon";
156 case kPI0: return "Pi-0";
157 case kNEUTRON: return "Neutron";
158 case kPROTON: return "Proton";
159 case kHELIUM: return "Helium";
160 case kOXYGEN: return "Oxygen";
161 case kIRON: return "Iron";
162 case kArtificial: return "Artificial";
163 case kNightSky: return "NightSky";
164 }
165
166 return MString::Format("Id:%d", id);
167}
168
169TString MMcEvtBasic::GetParticleSymbol(Int_t id)
170{
171 switch (id)
172 {
173 case kUNDEFINED:return "N/A";
174 case kGAMMA: return "\\gamma";
175 case kPOSITRON: return "e^{+}";
176 case kELECTRON: return "e^{-}";
177 case kANTIMUON: return "\\mu^{+}";
178 case kMUON: return "\\mu^{-}";
179 case kPI0: return "\\pi^{0}";
180 case kNEUTRON: return "n";
181 case kPROTON: return "p";
182 case kHELIUM: return "He";
183 case kOXYGEN: return "O";
184 case kIRON: return "Fe";
185 case kNightSky: return "\\gamma_{NSB}";
186 }
187
188 return MString::Format("Id:%d", id);
189}
190
191TString MMcEvtBasic::GetEnergyStr(Float_t e)
192{
193 if (e>=1000)
194 return MString::Format("%.1fTeV", e/1000);
195
196 if (e>=10)
197 return MString::Format("%dGeV", (Int_t)(e+.5));
198
199 if (e>=1)
200 return MString::Format("%.1fGeV", e);
201
202 return MString::Format("%dMeV", (Int_t)(e*1000+.5));
203}
204
205
206// --------------------------------------------------------------------------
207//
208// Print the contents of the container.
209//
210// if you specify an option only the requested data members are printed:
211// allowed options are: id, energy, impact
212//
213void MMcEvtBasic::Print(Option_t *opt) const
214{
215 //
216 // print out the data member on screen
217 //
218 TString str(opt);
219 if (str.IsNull())
220 {
221 *fLog << all << endl;
222 *fLog << "Monte Carlo output:" << endl;
223 *fLog << " Particle Id: " << GetParticleName() << endl;
224 *fLog << " Energy: " << fEnergy << "GeV" << endl;
225 *fLog << " Impactparam.: " << fImpact/100 << "m" << endl;
226 *fLog << endl;
227 return;
228 }
229 if (str.Contains("id", TString::kIgnoreCase))
230 *fLog << "Particle: " << GetParticleName() << endl;
231 if (str.Contains("energy", TString::kIgnoreCase))
232 *fLog << "Energy: " << fEnergy << "GeV" << endl;
233 if (str.Contains("impact", TString::kIgnoreCase))
234 *fLog << "Impact: " << fImpact << "cm" << endl;
235}
236
237Bool_t MMcEvtBasic::SetupFits(fits &fin)
238{
239 if (ClassName()==TString("MMcEvtBasic") && fName!="MMcEvtBasic")
240 {
241 *fLog << err << "ERROR - SetupFits only supported if name equals MMcEvtBasic." << endl;
242 return kFALSE;
243 }
244
245 //if (!fin.SetRefAddress("MMcEvtBasic.fPartId", fPartId )) return kFALSE;
246 if (!fin.SetRefAddress("MMcEvtBasic.fEnergy", fEnergy )) return kFALSE;
247 if (!fin.SetRefAddress("MMcEvtBasic.fImpact", fImpact )) return kFALSE;
248 if (!fin.SetRefAddress("MMcEvtBasic.fTelescopePhi", fTelescopePhi )) return kFALSE;
249 if (!fin.SetRefAddress("MMcEvtBasic.fTelescopeTheta", fTelescopeTheta)) return kFALSE;
250 if (!fin.SetRefAddress("MMcEvtBasic.fTheta", fTheta )) return kFALSE;
251 if (!fin.SetRefAddress("MMcEvtBasic.fPhi", fPhi )) return kFALSE;
252
253 return kTRUE;
254}
Note: See TracBrowser for help on using the repository browser.