source: trunk/MagicSoft/Mars/msim/MSimMMCS.cc@ 9341

Last change on this file since 9341 was 9336, checked in by tbretz, 16 years ago
*** empty log message ***
File size: 5.5 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of CheObs, the Modular 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 appears 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): Thomas Bretz, 2/2009 <mailto:tbretz@astro.uni-wuerzburg.de>
19!
20! Copyright: CheObs Software Development, 2000-2009
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MSimMMCS
28//
29// Task to copy the Mars CheObs MC headers to the old Mars style
30//
31//////////////////////////////////////////////////////////////////////////////
32#include "MSimMMCS.h"
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38
39#include "MMcEvt.hxx"
40
41#include "MRawRunHeader.h"
42
43#include "MCorsikaRunHeader.h"
44#include "MCorsikaEvtHeader.h"
45
46#include "MMcRunHeader.hxx"
47#include "MMcCorsikaRunHeader.h"
48
49#include "MPointingPos.h"
50
51ClassImp(MSimMMCS);
52
53using namespace std;
54
55// --------------------------------------------------------------------------
56//
57// Default Constructor.
58//
59MSimMMCS::MSimMMCS(const char* name, const char *title)
60{
61 fName = name ? name : "MSimMMCS";
62 fTitle = title ? title : "Task to copy the Mars CheObs MC headers to the old Mars style";
63}
64
65// --------------------------------------------------------------------------
66//
67Int_t MSimMMCS::PreProcess(MParList *plist)
68{
69 if (!plist->FindCreateObj("MMcRunHeader"))
70 return kFALSE;
71
72 if (!plist->FindCreateObj("MMcCorsikaRunHeader"))
73 return kFALSE;
74
75 if (!plist->FindCreateObj("MRawRunHeader"))
76 return kFALSE;
77
78 fMcEvtBasic = (MMcEvtBasic*)plist->FindCreateObj("MMcEvtBasic");
79 if (!fMcEvtBasic)
80 return kFALSE;
81
82 fMcEvt = (MMcEvt*)plist->FindCreateObj("MMcEvt");
83 if (!fMcEvt)
84 return kFALSE;
85
86 fPointingTel = (MPointingPos*)plist->FindObject("MPointingPos");
87 if (!fPointingTel)
88 {
89 *fLog << err << "MPointingPos not found... aborting." << endl;
90 return kFALSE;
91 }
92
93 fEvtHeader = (MCorsikaEvtHeader*)plist->FindObject("MCorsikaEvtHeader");
94 if (!fEvtHeader)
95 {
96 *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
97 return kFALSE;
98 }
99
100 fRunHeader = (MCorsikaRunHeader*)plist->FindObject("MCorsikaRunHeader");
101 if (!fRunHeader)
102 {
103 *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
104 return kFALSE;
105 }
106
107
108 return kTRUE;
109}
110
111// --------------------------------------------------------------------------
112//
113Bool_t MSimMMCS::ReInit(MParList *plist)
114{
115 MMcCorsikaRunHeader *mch = (MMcCorsikaRunHeader*)plist->FindObject("MMcCorsikaRunHeader");
116 if (!mch)
117 {
118 *fLog << err << "MMcCorsikaRunHeader not found... aborting." << endl;
119 return kFALSE;
120 }
121
122 mch->SetSpectrum(fRunHeader->GetSlopeSpectrum(),
123 fRunHeader->GetEnergyMin(), fRunHeader->GetEnergyMax());
124 mch->SetReadyToSave();
125
126 // ----------------------------------------------------
127
128 MMcRunHeader *mrh = (MMcRunHeader*)plist->FindObject("MMcRunHeader");
129 if (!mrh)
130 {
131 *fLog << err << "MMcRunHeader not found... aborting." << endl;
132 return kFALSE;
133 }
134
135 // fNumPheFromDNSB MMcPedestalNSBAdd // Number of phe/ns from diffuse NSB
136
137 // FIXME: Is there a way to write them as LAST entry in the file?
138 mrh->SetNumSimulatedShowers(fRunHeader->GetNumEvents());
139 mrh->SetImpactMax(fRunHeader->GetImpactMax());
140 mrh->SetCorsikaVersion(TMath::Nint(fRunHeader->GetProgramVersion()*100));
141
142 // ----------------------------------------------------
143
144 MRawRunHeader *rh = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
145 if (!rh)
146 {
147 *fLog << err << "MRawRunHeader not found... aborting." << endl;
148 return kFALSE;
149 }
150
151 const UInt_t id = fRunHeader->GetParticleID();
152
153 // FIXME: Is there a way to write them as LAST entry in the file?
154 rh->SetRunInfo(1, fRunHeader->GetRunNumber(), 0);
155 rh->SetSourceInfo(MMcEvtBasic::GetParticleName(id));
156 rh->SetReadyToSave();
157
158 // ----------------------------------------------------
159
160 fMcEvtBasic->SetPartId(MMcEvtBasic::ParticleId_t(id));
161
162 return kTRUE;
163}
164
165// --------------------------------------------------------------------------
166//
167Int_t MSimMMCS::Process()
168{
169 fMcEvtBasic->SetEnergy(fEvtHeader->GetTotalEnergy());
170 fMcEvtBasic->SetImpact(fEvtHeader->GetImpact());
171
172 fMcEvtBasic->SetTelescopeTheta(fPointingTel->GetZdRad());
173 fMcEvtBasic->SetTelescopePhi(fPointingTel->GetAzRad());
174
175 fMcEvtBasic->SetReadyToSave();
176
177 static_cast<MMcEvtBasic&>(*fMcEvt) = *fMcEvtBasic;
178
179 // Convert from corsika franme to telescope frame, taking
180 // the magnetic field into account: tel = corsika+offset
181 fMcEvt->SetTheta(fEvtHeader->GetZd());
182 fMcEvt->SetPhi(fEvtHeader->GetAz()+fRunHeader->GetMagneticFieldAz());
183
184 fMcEvt->SetEvtNumber(fEvtHeader->GetEvtNumber());
185 fMcEvt->SetPhotElfromShower(0);
186
187 return kTRUE;
188}
Note: See TracBrowser for help on using the repository browser.