| 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, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
|
|---|
| 19 | ! Author(s): Qi Zhe, 06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
|
|---|
| 20 | !
|
|---|
| 21 | ! Copyright: CheObs Software Development, 2000-2009
|
|---|
| 22 | !
|
|---|
| 23 | !
|
|---|
| 24 | \* ======================================================================== */
|
|---|
| 25 |
|
|---|
| 26 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 27 | //
|
|---|
| 28 | // MPhotonData
|
|---|
| 29 | //
|
|---|
| 30 | // Storage container to store Corsika events
|
|---|
| 31 | //
|
|---|
| 32 | // Version 1:
|
|---|
| 33 | // ----------
|
|---|
| 34 | // - First implementation
|
|---|
| 35 | //
|
|---|
| 36 | /////////////////////////////////////////////////////////////////////////////
|
|---|
| 37 | #include "MPhotonData.h"
|
|---|
| 38 |
|
|---|
| 39 | #include <fstream>
|
|---|
| 40 | #include <iostream>
|
|---|
| 41 |
|
|---|
| 42 | #include <TMath.h>
|
|---|
| 43 |
|
|---|
| 44 | #include "MLog.h"
|
|---|
| 45 | #include "MLogManip.h"
|
|---|
| 46 |
|
|---|
| 47 | ClassImp(MPhotonData);
|
|---|
| 48 |
|
|---|
| 49 | using namespace std;
|
|---|
| 50 |
|
|---|
| 51 | // --------------------------------------------------------------------------
|
|---|
| 52 | //
|
|---|
| 53 | // Default constructor.
|
|---|
| 54 | //
|
|---|
| 55 | MPhotonData::MPhotonData(/*const char *name, const char *title*/)
|
|---|
| 56 | : fPosX(0), fPosY(0), fCosU(0), fCosV(0), fTime(0), fWavelength(0),
|
|---|
| 57 | fNumPhotons(1), fProductionHeight(0), fPrimary(MMcEvtBasic::kUNDEFINED),
|
|---|
| 58 | fTag(-1), fWeight(1)
|
|---|
| 59 | {
|
|---|
| 60 | // fName = name ? name : "MPhotonData";
|
|---|
| 61 | // fTitle = title ? title : "Corsika Event Data Information";
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /*
|
|---|
| 65 | MPhotonData::MPhotonData(const MPhotonData &ph)
|
|---|
| 66 | : fPosX(ph.fPosX), fPosY(ph.fPosY), fCosU(ph.fCosU), fCosV(ph.fCosV),
|
|---|
| 67 | fTime(ph.fTime), fWavelength(ph.fWavelength), fNumPhotons(ph.fNumPhotons),
|
|---|
| 68 | fProductionHeight(ph.fProductionHeight), fPrimary(ph.fPrimary),
|
|---|
| 69 | fTag(ph.fTag), fWeight(ph.fWeight)
|
|---|
| 70 | {
|
|---|
| 71 | }
|
|---|
| 72 | */
|
|---|
| 73 |
|
|---|
| 74 | // --------------------------------------------------------------------------
|
|---|
| 75 | //
|
|---|
| 76 | // Copy function. Copy all data members into obj.
|
|---|
| 77 | //
|
|---|
| 78 | void MPhotonData::Copy(TObject &obj) const
|
|---|
| 79 | {
|
|---|
| 80 | MPhotonData &d = static_cast<MPhotonData&>(obj);
|
|---|
| 81 |
|
|---|
| 82 | d.fNumPhotons = fNumPhotons;
|
|---|
| 83 | d.fPosX = fPosX;
|
|---|
| 84 | d.fPosY = fPosY;
|
|---|
| 85 | d.fCosU = fCosU;
|
|---|
| 86 | d.fCosV = fCosV;
|
|---|
| 87 | d.fWavelength = fWavelength;
|
|---|
| 88 | d.fPrimary = fPrimary;
|
|---|
| 89 | d.fTime = fTime;
|
|---|
| 90 | d.fTag = fTag;
|
|---|
| 91 | d.fWeight = fWeight;
|
|---|
| 92 | d.fProductionHeight = fProductionHeight;
|
|---|
| 93 |
|
|---|
| 94 | TObject::Copy(obj);
|
|---|
| 95 | }
|
|---|
| 96 |
|
|---|
| 97 | // --------------------------------------------------------------------------
|
|---|
| 98 | //
|
|---|
| 99 | // return the cosine of the Theta-angle == sqrt(1-CosU^2-CosV^2)
|
|---|
| 100 | //
|
|---|
| 101 | Double_t MPhotonData::GetCosW() const
|
|---|
| 102 | {
|
|---|
| 103 | return TMath::Sqrt(1 - fCosU*fCosU - fCosV*fCosV);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | // --------------------------------------------------------------------------
|
|---|
| 107 | //
|
|---|
| 108 | // Return the theta angle in radians
|
|---|
| 109 | //
|
|---|
| 110 | Double_t MPhotonData::GetTheta() const
|
|---|
| 111 | {
|
|---|
| 112 | return TMath::ACos(GetCosW());
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | // --------------------------------------------------------------------------
|
|---|
| 116 | //
|
|---|
| 117 | // Return a TQuaternion with the first three components x, y, and z
|
|---|
| 118 | // and the fourth component the time.
|
|---|
| 119 | //
|
|---|
| 120 | TQuaternion MPhotonData::GetPosQ() const
|
|---|
| 121 | {
|
|---|
| 122 | return TQuaternion(GetPos3(), fTime);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | // --------------------------------------------------------------------------
|
|---|
| 126 | //
|
|---|
| 127 | // return a TQuaternion with the first three components the direction
|
|---|
| 128 | // moving in space (GetDir3()) and the fourth component is the
|
|---|
| 129 | // one devided by the speed of light (converted to cm/ns)
|
|---|
| 130 | //
|
|---|
| 131 | // FIXME: v in air!
|
|---|
| 132 | //
|
|---|
| 133 | TQuaternion MPhotonData::GetDirQ() const
|
|---|
| 134 | {
|
|---|
| 135 | return TQuaternion(GetDir3(), 1./(TMath::C()*100/1e9));
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | // --------------------------------------------------------------------------
|
|---|
| 139 | //
|
|---|
| 140 | // Set the data member according to the 8 floats read from a reflector-file.
|
|---|
| 141 | // This function MUST reset all data-members, no matter whether these are
|
|---|
| 142 | // contained in the input stream.
|
|---|
| 143 | //
|
|---|
| 144 | Int_t MPhotonData::FillRfl(Float_t f[8])
|
|---|
| 145 | {
|
|---|
| 146 | // Check coordinate system!!!!
|
|---|
| 147 | fWavelength = TMath::Nint(f[0]);
|
|---|
| 148 | fPosX = f[1]; // [cm]
|
|---|
| 149 | fPosY = f[2]; // [cm]
|
|---|
| 150 | fCosU = f[3]; // cos to x
|
|---|
| 151 | fCosV = f[4]; // cos to y
|
|---|
| 152 | fTime = f[5]; // [ns]
|
|---|
| 153 | fProductionHeight = f[6];
|
|---|
| 154 |
|
|---|
| 155 | // f[7]: Camera inclination angle
|
|---|
| 156 |
|
|---|
| 157 | fPrimary = MMcEvtBasic::kUNDEFINED;
|
|---|
| 158 | fNumPhotons = 1;
|
|---|
| 159 | fTag = -1;
|
|---|
| 160 | fWeight = 1;
|
|---|
| 161 |
|
|---|
| 162 | return kTRUE;
|
|---|
| 163 | }
|
|---|
| 164 |
|
|---|
| 165 | // --------------------------------------------------------------------------
|
|---|
| 166 | //
|
|---|
| 167 | // Set the data member according to the 7 floats read from a corsika-file.
|
|---|
| 168 | // This function MUST reset all data-members, no matter whether these are
|
|---|
| 169 | // contained in the input stream.
|
|---|
| 170 | //
|
|---|
| 171 | // Currently we exchange x and y and set y=-y to convert Corsikas coordinate
|
|---|
| 172 | // system intpo our own.
|
|---|
| 173 | //
|
|---|
| 174 | Int_t MPhotonData::FillCorsika(Float_t f[7])
|
|---|
| 175 | {
|
|---|
| 176 | const UInt_t n = TMath::Nint(f[0]);
|
|---|
| 177 | if (n==0)
|
|---|
| 178 | return kCONTINUE;
|
|---|
| 179 |
|
|---|
| 180 | // This seems to be special to mmcs
|
|---|
| 181 | fWavelength = n%1000;
|
|---|
| 182 | fPrimary = MMcEvtBasic::ParticleId_t(n/100000);
|
|---|
| 183 | fNumPhotons = (n/1000)%100; // Force this to be 1!
|
|---|
| 184 |
|
|---|
| 185 | if (fNumPhotons!=1)
|
|---|
| 186 | {
|
|---|
| 187 | // FIXME: Could be done in MPhotonEvent::ReadCorsikaEvent
|
|---|
| 188 | gLog << err << "ERROR - MPhotonData::FillCorsika: fNummPhotons not 1, but " << fNumPhotons << endl;
|
|---|
| 189 | gLog << " This is not yet supported." << endl;
|
|---|
| 190 | return kERROR;
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | // x=north, y=west
|
|---|
| 194 | //fPosX = f[1]; // [cm]
|
|---|
| 195 | //fPosY = f[2]; // [cm]
|
|---|
| 196 | //fCosU = f[3]; // cos to x
|
|---|
| 197 | //fCosV = f[4]; // cos to y
|
|---|
| 198 | // x=east, y=north
|
|---|
| 199 | fPosX = f[2]; // [cm]
|
|---|
| 200 | fPosY = -f[1]; // [cm]
|
|---|
| 201 |
|
|---|
| 202 | fCosU = f[4]; // cos to x
|
|---|
| 203 | fCosV = -f[3]; // cos to y
|
|---|
| 204 |
|
|---|
| 205 | fTime = f[5]; // [ns]
|
|---|
| 206 |
|
|---|
| 207 | fProductionHeight = f[6]; // [cm]
|
|---|
| 208 |
|
|---|
| 209 | // Now reset all data members which are not in the stream
|
|---|
| 210 | fTag = -1;
|
|---|
| 211 | fWeight = 1;
|
|---|
| 212 |
|
|---|
| 213 | return kTRUE;
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | // --------------------------------------------------------------------------
|
|---|
| 217 | //
|
|---|
| 218 | // Read seven floats from the stream and call FillCorsika for them.
|
|---|
| 219 | //
|
|---|
| 220 | Int_t MPhotonData::ReadCorsikaEvt(istream &fin)
|
|---|
| 221 | {
|
|---|
| 222 | Float_t f[7];
|
|---|
| 223 | fin.read((char*)&f, 7*4);
|
|---|
| 224 |
|
|---|
| 225 | const Int_t rc = FillCorsika(f);
|
|---|
| 226 |
|
|---|
| 227 | return rc==kTRUE ? !fin.eof() : rc;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | // --------------------------------------------------------------------------
|
|---|
| 231 | //
|
|---|
| 232 | // Read eight floats from the stream and call FillRfl for them.
|
|---|
| 233 | //
|
|---|
| 234 | Int_t MPhotonData::ReadRflEvt(istream &fin)
|
|---|
| 235 | {
|
|---|
| 236 | Float_t f[8];
|
|---|
| 237 | fin.read((char*)&f, 8*4);
|
|---|
| 238 |
|
|---|
| 239 | const Int_t rc = FillRfl(f);
|
|---|
| 240 |
|
|---|
| 241 | return rc==kTRUE ? !fin.eof() : rc;
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | // --------------------------------------------------------------------------
|
|---|
| 245 | //
|
|---|
| 246 | // Print contents. The tag and Weight are only printed if they are different
|
|---|
| 247 | // from the default.
|
|---|
| 248 | //
|
|---|
| 249 | void MPhotonData::Print(Option_t *) const
|
|---|
| 250 | {
|
|---|
| 251 | gLog << inf << endl;
|
|---|
| 252 | gLog << "Num Photons: " << fNumPhotons << " from " << MMcEvtBasic::GetParticleName(fPrimary) << endl;
|
|---|
| 253 | gLog << "Wavelength: " << fWavelength << "nm" << endl;
|
|---|
| 254 | gLog << "Pos X/Y Cos U/V: " << fPosX << "/" << fPosY << " " << fCosU << "/" << fCosV << endl;
|
|---|
| 255 | gLog << "Time/Prod.Height: " << fTime << "ns/" << fProductionHeight << "cm" << endl;
|
|---|
| 256 | if (fTag>=0)
|
|---|
| 257 | gLog << "Tag: " << fTag << endl;
|
|---|
| 258 | if (fWeight!=1)
|
|---|
| 259 | gLog << "Weight: " << fWeight << endl;
|
|---|
| 260 | }
|
|---|