Ignore:
Timestamp:
08/02/08 15:49:41 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mpointing/MSrcPosCalc.cc

    r8725 r9070  
    1717!
    1818!   Author(s): Thomas Bretz 3/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
    19 !   Author(s): Abelardo Moralejo 1/2005 <mailto:moralejo@pd.infn.it>
    2019!
    21 !   Copyright: MAGIC Software Development, 2000-2005
     20!   Copyright: MAGIC Software Development, 2000-2008
    2221!
    2322!
     
    4342// coordinates of the observatory from MObservatory.
    4443//
     44// If a reflector version >= 700 is detected the source position for
     45// Gammas (and _only_ gammas) is dynamically calculated from the
     46// telescope (e.g. MMcEvt::fTelescopePhi) and the shower (e.g. MMcEvt::fPhi)
     47// orientation. In off-mode it is fixed at the camera center.
     48//
    4549// FIXME: Add here some information about the more-cycle calculation
    4650//
     
    5054//   MGeomCam
    5155//   MTime
     56//   [MMcRunHeader]
     57//   [MMcCorsikaRunHeader]
    5258//   [MSourcePos] (of type MPointingPos)
    5359//
     
    5763// To be done:
    5864//   - a switch between using sky-coordinates and time or local-coordinates
    59 //     from MPointingPos for determine the rotation angle
    60 /////  NOTE, A. Moralejo: the above is not possible if MAstroSky2Local does not
    61 /////  account for precession and nutation.
     65//     from MPointingPos for determine the rotation angle. (Therefor a conversion
     66//     needs to be implemented inlcuding asrometric corrections)
    6267//
    6368//   - the center of rotation need not to be the camera center
     
    8287#include "MSrcPosCam.h"
    8388#include "MRawRunHeader.h"
     89
     90#include "MMcEvt.hxx"
     91#include "MMcRunHeader.hxx"
    8492#include "MMcCorsikaRunHeader.h"
    8593
     
    97105//
    98106MSrcPosCalc::MSrcPosCalc(const char *name, const char *title)
    99     : fObservatory(NULL), fPointPos(NULL), fSourcePos(NULL), fDeviation(NULL),
    100     fSrcPosCam(NULL), fSrcPosAnti(NULL), fGeom(NULL), fTime(NULL), fCallback(NULL),
    101     fMode(kDefault), fNumRandomOffPositions(0)
     107    : fObservatory(NULL), fPointPos(NULL), fDeviation(NULL), fMcEvt(NULL),
     108    fMcHeader(NULL), fGeom(NULL), fTime(NULL), fCallback(NULL),
     109    fSourcePos(NULL), fSrcPosCam(NULL), fSrcPosAnti(NULL), fMode(kDefault),
     110    fNumRandomOffPositions(0)
    102111{
    103112    fName  = name  ? name  : "MSrcPosCalc";
     
    105114
    106115    AddToBranchList("MTime.*");
     116    AddToBranchList("MMcEvt.*");
    107117    AddToBranchList("MPointingPos.*");
    108118}
     
    170180    if (!fSrcPosAnti)
    171181        return kFALSE;
     182
     183    fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
     184    if (!fGeom)
     185    {
     186        *fLog << err << "MGeomCam not found... aborting." << endl;
     187        return kFALSE;
     188    }
     189
     190    fPointPos = (MPointingPos*)pList->FindObject("MPointingPos");
     191    if (!fPointPos)
     192    {
     193        *fLog << err << "MPointingPos not found... aborting." << endl;
     194        return kFALSE;
     195    }
    172196
    173197    if (!fSourcePos)
     
    184208    }
    185209    // FIXME: Maybe we have to call FreeSourcePos in PostProcess()?
    186 
    187     fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
    188     if (!fGeom)
    189     {
    190         *fLog << err << "MGeomCam not found... aborting." << endl;
    191         return kFALSE;
    192     }
    193 
    194     fPointPos = (MPointingPos*)pList->FindObject("MPointingPos");
    195     if (!fPointPos)
    196     {
    197         *fLog << err << "MPointingPos not found... aborting." << endl;
    198         return kFALSE;
    199     }
    200210
    201211    fDeviation = (MPointingDev*)pList->FindObject("MPointingDev");
     
    262272}
    263273
     274void MSrcPosCalc::InitFixedPos() const
     275{
     276    // It is set here for the cases in which Process is not called at all
     277    fSrcPosCam->SetXY(fFixedPos/fGeom->GetConvMm2Deg());
     278
     279    // Informal message output
     280    *fLog << inf;
     281    *fLog << "Source position set to x=" << fFixedPos.X() << "deg ";
     282    *fLog << "y=" << fFixedPos.Y() << "deg" << endl;
     283}
     284
    264285// --------------------------------------------------------------------------
    265286//
     
    269290Bool_t MSrcPosCalc::ReInit(MParList *plist)
    270291{
     292    // In OffMode set fixed position to camera center
    271293    if (fMode==kOffData)
    272     {
    273         // Set fixed position to camera center
    274294        fFixedPos = TVector2();
    275295
     296    if (fMode==kOffData || fMode==kFixed)
     297    {
    276298        // It is set here for the cases in which Process is not called at all
    277         fSrcPosCam->SetXY(fFixedPos);
     299        InitFixedPos();
    278300        return kTRUE;
    279301    }
     
    302324            return kFALSE;
    303325        }
     326
    304327        return kTRUE;
    305328    }
    306329
    307     MMcCorsikaRunHeader *h = (MMcCorsikaRunHeader*)plist->FindObject("MMcCorsikaRunHeader");
     330    fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
     331    if (!fMcEvt)
     332    {
     333        *fLog << err << "MMcEvt not found... aborting." << endl;
     334        return kFALSE;
     335    }
     336
     337    fMcHeader = (const MMcRunHeader*)plist->FindObject("MMcRunHeader");
     338    if (!fMcHeader)
     339    {
     340        *fLog << err << "MMcRunHeader not found... aborting." << endl;
     341        return kFALSE;
     342    }
     343
     344    const MMcCorsikaRunHeader *h = (MMcCorsikaRunHeader*)plist->FindObject("MMcCorsikaRunHeader");
    308345    if (!h)
    309346    {
     
    311348        return kFALSE;
    312349    }
     350
     351    // We don't know here if these are gammas
     352    //if (fMcHeader->GetReflVersion()>600)
     353    //    *fLog << inf << "Source position will be calculated from shower and telescope orientation." << endl;
    313354
    314355    // Determine Monte Carlo position from Monte Carlo header
    315356    TVector2 v(0, 0);
    316357    if (h->GetWobbleMode()>0.5)
    317         v.Set(120., 0.);
     358        v.Set(120.*fGeom->GetConvMm2Deg(), 0.);
    318359    if (h->GetWobbleMode()<-0.5)
    319         v.Set(-120., 0.);
     360        v.Set(-120.*fGeom->GetConvMm2Deg(), 0.);
    320361
    321362    // Set fixed position
    322363    fFixedPos = v;
    323364
    324     // It is set here for the cases in which Process is not called at all
    325     fSrcPosCam->SetXY(fFixedPos);
    326 
    327     // Informal message output
    328     *fLog << inf;
    329     *fLog << "Source Position set to x=" << fFixedPos.X() << "mm ";
    330     *fLog << "y=" << fFixedPos.Y() << "mm" << endl;
     365    InitFixedPos();
    331366
    332367    return kTRUE;
    333368}
    334369
     370void MSrcPosCalc::CalcResult(const MVector3 &pos0, const MVector3 &pos)
     371{
     372    // Calculate source position in camera, and convert to mm:
     373    TVector2 v = MAstro::GetDistOnPlain(pos0, pos, -fGeom->GetCameraDist()*1000);
     374
     375    if (fDeviation)
     376        v -= fDeviation->GetDevXY()/fGeom->GetConvMm2Deg();
     377
     378    SetSrcPos(v);
     379}
     380
    335381// --------------------------------------------------------------------------
    336382//
     
    339385Int_t MSrcPosCalc::Process()
    340386{
    341     if (fRunType==MRawRunHeader::kRTMonteCarlo || !fSourcePos || !fTime || !fObservatory || fMode==kOffData)
    342     {
    343         SetSrcPos(fFixedPos);
     387    // In off-data mode the position is set to a fixed value
     388    // independent of the run type. In fixed-data mode the position
     389    // is set to the predefined position converted to mm.
     390    if (fMode==kOffData || fMode==kFixed)
     391    {
     392        SetSrcPos(fFixedPos/fGeom->GetConvMm2Deg());
     393        return kTRUE;
     394    }
     395
     396    // If it is a monte carlo run calculate source position from
     397    // Monte Carlo headers
     398    if (fRunType==MRawRunHeader::kRTMonteCarlo)
     399    {
     400        // If the reflector version is too old take source position
     401        // from the WobbleMode in the header
     402        if (fMcHeader->GetReflVersion()<=600)
     403        {
     404            SetSrcPos(fFixedPos/fGeom->GetConvMm2Deg());
     405            return kTRUE;
     406        }
     407
     408        // If the reflector version was new enough calculate the
     409        // source position from shower and telescope orientation
     410        // FIXME: Copy fMcEvt to fSourcePos!
     411        MVector3 pos0, pos;
     412        pos0.SetZdAz(fPointPos->GetZdRad(), fPointPos->GetAzRad());
     413        pos.SetZdAz(fMcEvt->GetTheta(), fMcEvt->GetPhi());
     414
     415        CalcResult(pos0, pos);
     416        return kTRUE;
     417    }
     418
     419    // If the user requested a fixed source position use this position
     420    if (!fSourcePos || !fTime || !fObservatory)
     421    {
     422        SetSrcPos(fFixedPos/fGeom->GetConvMm2Deg());
    344423        return kTRUE;
    345424    }
     
    352431    pos.SetRaDec(fSourcePos->GetRaRad(), fSourcePos->GetDecRad());
    353432
     433    // Set sky coordinates of camera center in pos0 (for details see below)
     434    MVector3 pos0;  // pos0: camera center
     435    pos0.SetRaDec(fPointPos->GetRaRad(), fPointPos->GetDecRad());
     436
     437    // Here we check that the source position which was given
     438    // by the drive system is not off by more than 1deg from the
     439    // source position given by the user. (Checking every individual
     440    // event is not the fastest, but the safest)
     441    if (pos.DeltaPhi(pos0)*TMath::RadToDeg()>1)
     442    {
     443        *fLog << err << "ERROR - Defined source position deviates from pointing-ra/dec by more than 1deg!" << endl;
     444        *fLog << "User defined source pos:  ";
     445        fSourcePos->Print();
     446        *fLog << "Pointing position of tel: ";
     447        fPointPos->Print();
     448
     449        return kFALSE;
     450    }
     451
    354452    // Convert sky coordinates of source to local coordinates. Warning! These are not the "true" local
    355453    // coordinates, since this transformation ignores precession and nutation effects.
     
    357455    pos *= conv;
    358456
    359     // Set sky coordinates of camera center in pos0, and then convert to
    360     // local. Same comment as above. These coordinates differ from the true
     457    // Convert sky coordinates of camera center convert to local.
     458    // Same comment as above. These coordinates differ from the true
    361459    // local coordinates of the camera center that one could get from
    362460    // "MPointingPos", calculated by the Drive: the reason is that the Drive
     
    369467    // would be wrong is to set in pos0 directly the local coordinates
    370468    // found in MPointingPos!
    371     MVector3 pos0;  // pos0: camera center
    372     pos0.SetRaDec(fPointPos->GetRaRad(), fPointPos->GetDecRad());
    373469    pos0 *= conv;
    374470
     
    384480    }
    385481
    386     // Calculate source position in camera, and convert to mm:
    387     TVector2 v = MAstro::GetDistOnPlain(pos0, pos, -fGeom->GetCameraDist()*1000);
    388 
    389     if (fDeviation)
    390         v -= fDeviation->GetDevXY()/fGeom->GetConvMm2Deg();
    391 
    392     SetSrcPos(v);
    393 
     482    CalcResult(pos0, pos);
    394483    return kTRUE;
    395484}
     
    440529Int_t MSrcPosCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
    441530{
     531    Bool_t rc = kFALSE;
     532
     533    if (IsEnvDefined(env, prefix, "FixedPos", print))
     534    {
     535        TString str = GetEnvValue(env, prefix, "FixedPos", "");
     536        str = str.Strip(TString::kBoth);
     537
     538        Double_t x, y;
     539        const Int_t n=sscanf(str.Data(), "%lf %lf", &x, &y);
     540        if (n!=2)
     541        {
     542            *fLog << warn << "WARNING - FixedPos requires two numbers." << endl;
     543            return kERROR;
     544        }
     545
     546        fFixedPos = TVector2(x, y);
     547        fMode = kFixed;
     548
     549        rc = kTRUE;
     550    }
     551
    442552    Double_t ra=0;
    443553    Double_t dec=0;
     
    461571
    462572        SetSourcePos(ra, dec);
    463         return kTRUE;
    464     }
    465 
    466     Bool_t rc = kFALSE;
     573        return rc;
     574    }
     575
     576    Bool_t rcsrc = kFALSE;
    467577    if (IsEnvDefined(env, prefix, "SourceRa", print))
    468578    {
     
    472582            return kERROR;
    473583
    474         rc = kTRUE;
     584        rcsrc = kTRUE;
    475585    }
    476586
     
    482592            return kERROR;
    483593
    484         rc = kTRUE;
    485     }
    486 
    487     if (!rc)
    488         return kFALSE;
    489 
    490     SetSourcePos(ra, dec);
    491     return kTRUE;
    492 }
     594        rcsrc = kTRUE;
     595    }
     596
     597    if (rcsrc)
     598        SetSourcePos(ra, dec);
     599
     600    return rcsrc || rc;
     601}
Note: See TracChangeset for help on using the changeset viewer.