Changeset 8728


Ignore:
Timestamp:
09/03/07 13:07:35 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mpointing
Files:
2 edited

Legend:

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

    r8641 r8728  
    1818!   Author(s): Thomas Bretz, 07/2005 <mailto:tbretz@astro.uni-wuerzburg.de>
    1919!
    20 !   Copyright: MAGIC Software Development, 2000-2005
     20!   Copyright: MAGIC Software Development, 2000-2007
    2121!
    2222!
     
    3131// There are some quality parameters to steer which are the valid
    3232// starguider data points:
     33//
    3334//  * MPointingDevCalc.NumMinStars: 8
    3435//    Minimum number of identified stars required to accep the data
     36//
    3537//  * MPointingDevCalc.NsbLevel:    3.0
    36 //    Minimum deviation (in rms) from the the mean allowed for the measured
    37 //    NSB (noise in the ccd camera)
     38//    Minimum deviation (in rms) from the the mean allowed for the
     39//    measured NSB (noise in the ccd camera)
     40//
    3841//  * MPointingDevCalc.NsbMin:      30
    3942//    - minimum NSB to be used in mean/rms calculation
     43//
    4044//  * MPointingDevCalc.NsbMax:      60
    4145//    - maximum NSB to be used in mean/rms calculation
     46//
    4247//  * MPointingDevCalc.MaxAbsDev:   15
    4348//    - Maximum absolute deviation which is consideres as valid (arcmin)
     
    4954// The calculation of NSB mean and rms is reset for each file (ReInit)
    5055//
     56// If your starguider data doesn't fullfill this requirement the latest
     57// value which could be correctly calculated is used instead. If the time
     58// for which no valid value can be calculated exceeds one minute
     59// the return value is reset to 0/0. The maximum time allowed without
     60// a valid value can be setup using:
     61//
     62//  * MPointingDevCalc.MaxAge:   1
     63//    Maximum time before the starguider is reset to 0/0 in minutes
     64//
     65// Note, that the starguider itself is not well calibrated. Therefore
     66// it is necessary to do a starguider calibration in our software.
     67//
     68// There are two options:
     69//
     70//  * Simple starguider calibration using offsets in the camera plane
     71//
     72//    The starguider is calibrated by taking its values (dZd/dAz)
     73//    adding them to the source position, calculating the source position
     74//    in the camera plane and adding the offsets. To switch off the
     75//    full starguider calibration do:
     76//
     77//      * MPointingDevCalc.PointingModels:
     78//
     79//    To set the offsets (in units of degree) use
     80//
     81//      * MPointingDevCalc.Dx: -0.001
     82//      * MPointingDevCalc.Dy: -0.004
     83//
     84//   * A starguider calibration using a pointing model calculated
     85//     from calibration data, so called TPoints
     86//
     87//     Because the pointing model can change from time to time
     88//     you can give the run-number from which on a new pointing
     89//     model is valid. The run itself is included, e.g.:
     90//
     91//      * MPointingDevCalc.PointingModels: 85240 89180
     92//      * MPointingDevCalc.FilePrefix:     resources/starguider
     93//
     94//     mean that for all runs<85240 the simple offset correction is used.
     95//     For runs >=85240 and <89180 the file resources/starguider0085240.txt
     96//     and for runs >=89180 the file resources/starguider0089180.txt is
     97//     used. To setup a default file for all runs before 85240 setup
     98//     a low number (eg. 0 or 1)
     99//
     100//     In the case a pointing model is used additional offsets in
     101//     the x/y-camera plane (in units of deg) can be set using the DX
     102//     and DY parameters of the pointing model. The fDx and fDy data
     103//     members of this class are ignored. To overwrite the starguider
     104//     calibrated offset in either Az or Zd with a constant, you
     105//     can use the PX/PY directive in the pointing model. (To enable
     106//     the overwrite set the third column, the error, to a value
     107//     greater than zero)
     108//
     109//
     110// At the PostProcessing step a table with statistics is print if the
     111// debug level is greater or equal 3 (in most applications it is switched
     112// on by -v3)
     113//
     114//
     115// Pointing Models:
     116// ----------------
     117//
     118//  What we know so far about (maybe) important changes in cosy:
     119//
     120//   18.03.2006: The camera holding has been repaired and the camera got
     121//               shifted a little bit.
     122//
     123//   16.04.2006: Around this date a roque lamp focussing hass been done
     124//
     125//   25.04.2006: A missalignment intrduced with the roque adjust has been
     126//               corrected
     127//
     128//   The starguider pointing model for the time before 18.3.2006 and after
     129//   April 2006 (in fact there are no TPoints until 07/2006 to check it)
     130//   and for the period 07/2006 to (at least) 06/2007 are very similar.
     131//
     132//   The pointing model for the time between 18.3.2006 and 04/2006 is
     133//   clearly different, mainly giving different Azimuth values between
     134//   Zenith and roughly ~25deg, and a slight offset on both axes.
     135//
     136//   10.5.2006:  pos1 -= pos0 commented  (What was the mentioned fix?)
     137//   29.6.2006:  repaired
     138//
     139//   23.3.2006:  new starguider algorithm
     140//
     141//   17.3.2005:  Fixed units of "nompos" in MDriveCom
     142//
     143//
     144// New pointing models have been installed (if the pointing model
     145// is different, than the previous one it might mean, that also
     146// the starguider calibration is different.)
     147//
     148//   29. Apr. 2004    ~25800
     149//    5. Aug. 2004    ~32000
     150//   19. Aug. 2004    ~33530
     151//    7. Jun. 2005    ~57650
     152//    8. Jun. 2005
     153//    9. Jun. 2005    ~57860
     154//   12. Sep. 2005    ~68338
     155//   24. Nov. 2005    ~75562
     156//   17. Oct. 2006   ~103130
     157//   17. Jun. 2007   ~248193
     158//
     159//
     160// ToDo:
     161// -----
     162//
     163//   * Is 0/0 the best assumption if the starguider partly fails?
     164//
    51165//
    52166// Input Container:
     167//   MRawRunHeader
    53168//   MReportStarguider
    54169//
     
    74189using namespace std;
    75190
    76 const TString MPointingDevCalc::fgFileName="resources/starguider.txt";
     191const TString MPointingDevCalc::fgFilePrefix="resources/starguider";
     192
     193// --------------------------------------------------------------------------
     194//
     195// Destructor. Call Clear() and delete fPointingModels if any.
     196//
     197MPointingDevCalc::~MPointingDevCalc()
     198{
     199    Clear();
     200}
    77201
    78202// --------------------------------------------------------------------------
     
    90214// --------------------------------------------------------------------------
    91215//
     216// Sort the entries in fPoinitngModels
     217//
     218void MPointingDevCalc::SortPointingModels()
     219{
     220    const int n = fPointingModels.GetSize();
     221
     222    TArrayI idx(n);
     223
     224    TMath::Sort(n, fPointingModels.GetArray(), idx.GetArray(), kFALSE);
     225
     226    const TArrayI arr(fPointingModels);
     227
     228    for (int i=0; i<n; i++)
     229        fPointingModels[i] = arr[idx[i]];
     230}
     231
     232// --------------------------------------------------------------------------
     233//
     234// Set new pointing models
     235//
     236void MPointingDevCalc::SetPointingModels(const TString &models)
     237{
     238    fPointingModels.Set(0);
     239
     240    if (models.IsNull())
     241        return;
     242
     243    TObjArray *arr = models.Tokenize(" ");
     244
     245    const int n = arr->GetEntries();
     246    fPointingModels.Set(n);
     247
     248    for (int i=0; i<n; i++)
     249        fPointingModels[i] = atoi((*arr)[i]->GetName());
     250
     251    delete arr;
     252
     253    SortPointingModels();
     254}
     255
     256// --------------------------------------------------------------------------
     257//
     258// Return a string with the pointing models, seperated by a space.
     259//
     260TString MPointingDevCalc::GetPointingModels() const
     261{
     262    TString rc;
     263    for (int i=0; i<fPointingModels.GetSize(); i++)
     264        rc += Form ("%d ", fPointingModels[i]);
     265
     266    return rc;
     267}
     268
     269// --------------------------------------------------------------------------
     270//
     271// Add a number to the pointing models
     272//
     273void MPointingDevCalc::AddPointingModel(UInt_t runnum)
     274{
     275    const int n = fPointingModels.GetSize();
     276    for (int i=0; i<n; i++)
     277        if ((UInt_t)fPointingModels[i]==runnum)
     278        {
     279            *fLog << warn << "WARNING - Pointing model " << runnum << " already in list... ignored." << endl;
     280            return;
     281        }
     282
     283    fPointingModels.Set(n+1);
     284    fPointingModels[n] = runnum;
     285
     286    SortPointingModels();
     287}
     288
     289// --------------------------------------------------------------------------
     290//
     291// Find the highest number in the array which is lower or equal num.
     292//
     293UInt_t MPointingDevCalc::FindPointingModel(UInt_t num)
     294{
     295    const int n = fPointingModels.GetSize();
     296    if (n==0)
     297        return (UInt_t)-1;
     298
     299    // Loop over all pointing models
     300    for (int i=0; i<n; i++)
     301    {
     302        // The number stored in the array did not yet overtake the runnumber
     303        if ((UInt_t)fPointingModels[i]<num)
     304            continue;
     305
     306        // The first pointing model is later than this run: use a default
     307        if (i==0)
     308            return (UInt_t)-1;
     309
     310        // The last entry in the array is the right one.
     311        return fPointingModels[i-1];
     312    }
     313
     314    // Runnumber is after last entry of pointing models. Use the last one.
     315    return fPointingModels[n-1];
     316}
     317
     318// --------------------------------------------------------------------------
     319//
    92320// Clear the pointing model. If run-number >= 87751 read the new
    93 // pointing model with fFileName
     321// pointing model with fFilePrefix
    94322//
    95323Bool_t MPointingDevCalc::ReadPointingModel(const MRawRunHeader &run)
    96324{
    97     if (run.GetRunNumber()<85240)
     325    const UInt_t num = FindPointingModel(run.GetRunNumber());
     326
     327    // No poinitng models are defined. Use simple dx/dy-calibration
     328    if (num==(UInt_t)-1)
    98329    {
    99330        Clear();
     
    101332    }
    102333
     334    // compile the name for the starguider files
     335    // The file with the number 00000000 is the default file
     336    TString fname = Form("%s%08d.txt", fFilePrefix.Data(), num);
     337
    103338    if (!fPointing)
    104339        fPointing = new MPointing;
    105340
    106     if (fFileName==fPointing->GetName())
    107     {
    108         *fLog << inf << fFileName << " already loaded." << endl;
     341    if (fname==fPointing->GetName())
     342    {
     343        *fLog << inf << fname << " already loaded." << endl;
    109344        return kTRUE;
    110345    }
    111346
    112     return fPointing->Load(fFileName);
     347    return fPointing->Load(fname);
    113348}
    114349
     
    210445        // For calibration add MDriveReport::GetErrorZd/Az !
    211446        fDeviation->SetDevXY(fDx, fDy); // 1arcmin ~ 5mm
    212         //devzd -= 2.686/60;   
    213         //devaz -= 2.840/60;
    214447
    215448        return;
    216449    }
    217 
    218     // def?: 20.105, 773
    219     // 0/0 : 20.119, 763
    220     // -/- : 19.417  726
    221     // +mis: 19.80,  756
    222450
    223451    // Get the nominal position the star is at the sky
     
    229457    // calculate as follows:
    230458    //
    231     // Position at which the starguider camera is pointing in real:
    232     //       pointing position = nominal position - mis
    233     ZdAz mis(devzd, devaz);
    234     mis *= TMath::DegToRad();
    235 
    236     // The pointing mode is the conversion from the real pointing
     459    // The mispointing measured by the starguider:
     460    //    ZdAz mis(devzd, devaz);
     461    //    mis *= TMath::DegToRad();
     462
     463    // The pointing model is the conversion from the real pointing
    237464    // position of the telescope into the pointing position measured
    238465    // by the starguider.
    239466    //
    240     //  --> To get the real poiting position of the telescope we have
    241     //      to convert the measured position back;
    242     //
     467    // To keep as close to the fitted model we use the forward correction.
    243468
    244469    // Position at which the starguider camera is pointing in real:
     
    247472    // The position measured as the starguider's pointing position
    248473    ZdAz pos(nom);        // cpos = sao - dev
    249     pos -= mis;
     474    pos -= ZdAz(devzd, devaz)*TMath::DegToRad();
    250475
    251476    // Now we convert the starguider's pointing position into the
     
    253478    // the telescope pointing position into the starguider pointing
    254479    // position)
    255     ZdAz point = fPointing->CorrectBack(pos);
     480    ZdAz point = fPointing->CorrectBack(pos);  //FWD!!!
    256481
    257482    // MSrcPosCalc uses the following condition to calculate the
    258483    // source position in the camera:
    259484    //    real pointing pos = nominal pointing pos - dev
    260     //
     485    //      --> dev = nominal - real
    261486    // Therefor we calculate dev as follows:
    262487    ZdAz dev(nom);
     
    264489    dev *= TMath::RadToDeg();
    265490
    266     // Set Measured mispointing and additional offset
    267     fDeviation->SetDevZdAz(dev.Zd(), dev.Az());
    268     fDeviation->SetDevXY(0, 0);
     491    /*
     492     // We chose the other way. It is less accurate because is is the
     493     // other was than the poinitng model was fittet, but it is more
     494     // accurate because the nominal (i.e. real) pointing position
     495     // is less accurately known than the position returned by the
     496     // starguider.
     497     //
     498     // Calculate the deviation which would be measured by the starguider
     499     // if applied to a perfectly pointing telescope.
     500     ZdAz dev = fPointing->Correct(nom);
     501     dev -= nom;
     502
     503     // Now add these offsets and the starguider measured offsets to
     504     // the real pointing deviation of the telescope (note, that
     505     // signs here are just conventions)
     506     dev += ZdAz(devzd, devaz)*TMath::DegToRad(); // --> nom-mis
     507     dev *= TMath::RadToDeg();
     508     */
     509
     510    // Check if the starguider pointing model requests overwriting
     511    // of the values with constants (e.g. 0)
     512    devaz = fPointing->IsPxValid() ? fPointing->GetPx() : dev.Az();
     513    devzd = fPointing->IsPyValid() ? fPointing->GetPy() : dev.Zd();
     514
     515    fDeviation->SetDevZdAz(devzd, devaz);
     516    fDeviation->SetDevXY(fPointing->GetDxy());
    269517}
    270518
    271519Int_t MPointingDevCalc::ProcessStarguiderReport()
    272520{
    273     /************* CHECK STATUS!!! ******************/
    274 
    275521    Double_t devzd = fReport->GetDevZd(); // [arcmin]
    276522    Double_t devaz = fReport->GetDevAz(); // [arcmin]
     
    393639// MPointingDevCalc.MaxAbsDev:   15
    394640// MPointingDevCalc.MaxAge:      1.0
     641// MPointingDevCalc.Dx:         -0.001
     642// MPointingDevCalc.Dy:         -0.004
     643//
     644// For a detailed description see the class reference.
    395645//
    396646Int_t MPointingDevCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
     
    437687        rc = kTRUE;
    438688    }
     689    if (IsEnvDefined(env, prefix, "FilePrefix", print))
     690    {
     691        fFilePrefix = GetEnvValue(env, prefix, "FilePrefix", fFilePrefix);
     692        rc = kTRUE;
     693    }
     694    if (IsEnvDefined(env, prefix, "PointingModels", print))
     695    {
     696        SetPointingModels(GetEnvValue(env, prefix, "PointingModels", GetPointingModels()));
     697        rc = kTRUE;
     698    }
    439699
    440700    return rc;
  • trunk/MagicSoft/Mars/mpointing/MPointingDevCalc.h

    r8601 r8728  
    1818{
    1919private:
    20     static const TString fgFileName; //! default file name of pointing model
     20    static const TString fgFilePrefix; //! default file name of pointing model
    2121
    2222    MReportStarguider *fReport;    //! MReportStarguider to get mispointing
     
    3333    Double_t fLastMjd;             //! Time of last processed report
    3434
    35     TString fFileName;             // File name of pointing model
     35    TString fFilePrefix;           // File name of pointing model
     36    TArrayI fPointingModels;       // List with pointing models
    3637
    37     UInt_t  fNumMinStars;          // Minimum number of identified stars
     38    UInt_t  fNumMinStars;          // [num] Minimum number of identified stars
    3839    Float_t fNsbLevel;             // Minimum deviation from mean in sigma
    39     Float_t fNsbMin;               // Minimum NSB to calc mean and rms
    40     Float_t fNsbMax;               // Maximum NSB to calc mean and rms
     40    Float_t fNsbMin;               // [au] Minimum NSB to calc mean and rms
     41    Float_t fNsbMax;               // [au] Maximum NSB to calc mean and rms
    4142    Float_t fMaxAbsDev;            // [arcmin] Maximum considered absolute deviation
    4243    Float_t fMaxAge;               // [min] Maximum age of reports to be used without an update
    4344
    44     Float_t fDx;                   // Starguider calibration dx
    45     Float_t fDy;                   // Starguider calibration dy
     45    Float_t fDx;                   // [deg] Starguider calibration dx
     46    Float_t fDy;                   // [deg] Starguider calibration dy
    4647
    4748    // MPointingDevCalc
     
    4950
    5051    Bool_t ReadPointingModel(const MRawRunHeader &run);
     52    UInt_t FindPointingModel(UInt_t num);
     53    void   SortPointingModels();
    5154
    5255    Int_t ProcessStarguiderReport();
     
    6467public:
    6568    MPointingDevCalc() : fReport(0), fDeviation(0), fPointing(0),
    66         fSkip(7), fFileName(fgFileName), fNumMinStars(8),
     69        fSkip(7), fFilePrefix(fgFilePrefix), fNumMinStars(8),
    6770        fNsbLevel(3), fNsbMin(30), fNsbMax(60), fMaxAbsDev(15),
    68         fMaxAge(1), fDx(-7), fDy(16)
     71        fMaxAge(1), fDx(-0.001), fDy(-0.004)
    6972    {
    7073        fName  = "MPointingDevCalc";
    71         fTitle = "Task calculating the pointing deviation";
     74        fTitle = "Task calculating the starguider correction";
    7275
    7376        AddToBranchList("MReportStarguider.*");
    7477    }
    75     ~MPointingDevCalc()
    76     {
    77         Clear();
    78     }
     78    ~MPointingDevCalc();
    7979
     80    // Tobject
    8081    void Clear(Option_t *o="");
    8182
     83    // Setter
    8284    void SetNumMinStars(UInt_t n)  { fNumMinStars=n; }
    8385    void SetNsbLevel(Float_t lvl)  { fNsbLevel=lvl;  }
     
    8991    void SetMaxAge(Float_t age)    { fMaxAge=age; }
    9092
    91     ClassDef(MPointingDevCalc, 0) //Task calculating the pointing deviation
     93    void SetFilePrefix(const char *n) { fFilePrefix=n; }
     94
     95    // Handle pointing models
     96    void    SetPointingModels(const TString &models);
     97    void    AddPointingModel(UInt_t runnum);
     98    TString GetPointingModels() const;
     99
     100    ClassDef(MPointingDevCalc, 0) //Task calculating the starguider correction
    92101};
    93102
Note: See TracChangeset for help on using the changeset viewer.