| 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 |
|
|---|
| 51 | ClassImp(MSimMMCS);
|
|---|
| 52 |
|
|---|
| 53 | using namespace std;
|
|---|
| 54 |
|
|---|
| 55 | // --------------------------------------------------------------------------
|
|---|
| 56 | //
|
|---|
| 57 | // Default Constructor.
|
|---|
| 58 | //
|
|---|
| 59 | MSimMMCS::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 | //
|
|---|
| 67 | Int_t MSimMMCS::PreProcess(MParList *plist)
|
|---|
| 68 | {
|
|---|
| 69 | fMcRunHeader = (MMcRunHeader*)plist->FindCreateObj("MMcRunHeader");
|
|---|
| 70 | if (!fMcRunHeader)
|
|---|
| 71 | return kFALSE;
|
|---|
| 72 |
|
|---|
| 73 | if (!plist->FindCreateObj("MMcCorsikaRunHeader"))
|
|---|
| 74 | return kFALSE;
|
|---|
| 75 |
|
|---|
| 76 | if (!plist->FindCreateObj("MRawRunHeader"))
|
|---|
| 77 | return kFALSE;
|
|---|
| 78 |
|
|---|
| 79 | fMcEvtBasic = (MMcEvtBasic*)plist->FindCreateObj("MMcEvtBasic");
|
|---|
| 80 | if (!fMcEvtBasic)
|
|---|
| 81 | return kFALSE;
|
|---|
| 82 |
|
|---|
| 83 | fMcEvt = (MMcEvt*)plist->FindCreateObj("MMcEvt");
|
|---|
| 84 | if (!fMcEvt)
|
|---|
| 85 | return kFALSE;
|
|---|
| 86 |
|
|---|
| 87 | fPointingTel = (MPointingPos*)plist->FindObject("MPointingPos");
|
|---|
| 88 | if (!fPointingTel)
|
|---|
| 89 | {
|
|---|
| 90 | *fLog << err << "MPointingPos not found... aborting." << endl;
|
|---|
| 91 | return kFALSE;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | fEvtHeader = (MCorsikaEvtHeader*)plist->FindObject("MCorsikaEvtHeader");
|
|---|
| 95 | if (!fEvtHeader)
|
|---|
| 96 | {
|
|---|
| 97 | *fLog << err << "MCorsikaEvtHeader not found... aborting." << endl;
|
|---|
| 98 | return kFALSE;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | fRunHeader = (MCorsikaRunHeader*)plist->FindObject("MCorsikaRunHeader");
|
|---|
| 102 | if (!fRunHeader)
|
|---|
| 103 | {
|
|---|
| 104 | *fLog << err << "MCorsikaRunHeader not found... aborting." << endl;
|
|---|
| 105 | return kFALSE;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | return kTRUE;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | // --------------------------------------------------------------------------
|
|---|
| 112 | //
|
|---|
| 113 | Bool_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 | // fNumPheFromDNSB MMcPedestalNSBAdd // Number of phe/ns from diffuse NSB
|
|---|
| 129 |
|
|---|
| 130 | // FIXME: Is there a way to write them as LAST entry in the file?
|
|---|
| 131 | fMcRunHeader->SetNumSimulatedShowers(fRunHeader->GetNumEvents());
|
|---|
| 132 | fMcRunHeader->SetCorsikaVersion(TMath::Nint(fRunHeader->GetProgramVersion()*100));
|
|---|
| 133 |
|
|---|
| 134 | if (fRunHeader->GetImpactMax()>0)
|
|---|
| 135 | fMcRunHeader->SetImpactMax(fRunHeader->GetImpactMax());
|
|---|
| 136 |
|
|---|
| 137 | // ----------------------------------------------------
|
|---|
| 138 |
|
|---|
| 139 | MRawRunHeader *rh = (MRawRunHeader*)plist->FindObject("MRawRunHeader");
|
|---|
| 140 | if (!rh)
|
|---|
| 141 | {
|
|---|
| 142 | *fLog << err << "MRawRunHeader not found... aborting." << endl;
|
|---|
| 143 | return kFALSE;
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | const UInt_t id = fRunHeader->GetParticleID();
|
|---|
| 147 |
|
|---|
| 148 | // FIXME: Is there a way to write them as LAST entry in the file?
|
|---|
| 149 | rh->SetRunInfo(1, fRunHeader->GetRunNumber(), 0);
|
|---|
| 150 | rh->SetSourceInfo(MMcEvtBasic::GetParticleName(id));
|
|---|
| 151 | rh->SetReadyToSave();
|
|---|
| 152 |
|
|---|
| 153 | // ----------------------------------------------------
|
|---|
| 154 |
|
|---|
| 155 | fMcEvtBasic->SetPartId(MMcEvtBasic::ParticleId_t(id));
|
|---|
| 156 |
|
|---|
| 157 | return kTRUE;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | // --------------------------------------------------------------------------
|
|---|
| 161 | //
|
|---|
| 162 | Int_t MSimMMCS::Process()
|
|---|
| 163 | {
|
|---|
| 164 | fMcEvtBasic->SetEnergy(fEvtHeader->GetTotalEnergy());
|
|---|
| 165 | fMcEvtBasic->SetImpact(fEvtHeader->GetImpact());
|
|---|
| 166 |
|
|---|
| 167 | fMcEvtBasic->SetTelescopeTheta(fPointingTel->GetZdRad());
|
|---|
| 168 | fMcEvtBasic->SetTelescopePhi(fPointingTel->GetAzRad());
|
|---|
| 169 |
|
|---|
| 170 | fMcEvtBasic->SetReadyToSave();
|
|---|
| 171 |
|
|---|
| 172 | static_cast<MMcEvtBasic&>(*fMcEvt) = *fMcEvtBasic;
|
|---|
| 173 |
|
|---|
| 174 | // Convert from corsika frame to telescope frame, taking
|
|---|
| 175 | // the magnetic field into account: tel = corsika+offset
|
|---|
| 176 | if (fRunHeader->HasViewCone())
|
|---|
| 177 | {
|
|---|
| 178 | fMcEvt->SetTheta(fPointingTel->GetZdRad());
|
|---|
| 179 | fMcEvt->SetPhi(fPointingTel->GetAzRad());
|
|---|
| 180 | }
|
|---|
| 181 | else
|
|---|
| 182 | {
|
|---|
| 183 | fMcEvt->SetTheta(fEvtHeader->GetZd());
|
|---|
| 184 | fMcEvt->SetPhi(fEvtHeader->GetAz()+fRunHeader->GetMagneticFieldAz());
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | fMcEvt->SetEvtNumber(fEvtHeader->GetEvtNumber());
|
|---|
| 188 | fMcEvt->SetPhotElfromShower(0);
|
|---|
| 189 |
|
|---|
| 190 | if (fRunHeader->GetImpactMax()<0 &&
|
|---|
| 191 | fEvtHeader->GetImpact()>fMcRunHeader->GetImpactMax())
|
|---|
| 192 | fMcRunHeader->SetImpactMax(fEvtHeader->GetImpact());
|
|---|
| 193 |
|
|---|
| 194 | return kTRUE;
|
|---|
| 195 | }
|
|---|