Ignore:
Timestamp:
02/13/09 17:46:02 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/msimreflector
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/msimreflector/MMirror.cc

    r9312 r9332  
    126126    psf /= 2;                        // The factor two because of the doubleing of the angle in the reflection
    127127    psf /= F;                        // Scale the Gauss to the size of the PSF
    128     psf *= n.Z();                    // Normalize the addon vector to the normal vector
    129     //psf *= n.Mag();                // Alternative! (Gaussian projected on the surface of a sphere)
     128    //psf *= n.Z();                  //
     129    psf *= n.Mag();                  // This means that the PSF is measured in the focal distance
    130130
    131131    TVector3 dn(gx*psf, gy*psf, 0);  // Instead of psf/F also atan(psf/F) might make sense
     
    136136}
    137137
     138// --------------------------------------------------------------------------
     139//
    138140void MMirror::Print(Option_t *o) const
    139141{
     
    141143    gLog << fNorm.X() << " " << fNorm.Y() << " " << fNorm.Z() << " ";
    142144    gLog << fFocalLength << " ";
     145    if (fSigmaPSF>0)
     146        gLog << fSigmaPSF << " ";
    143147
    144148    const TString n = ClassName();
  • trunk/MagicSoft/Mars/msimreflector/MMirror.h

    r9312 r9332  
    3636    TVector2 operator-(const MMirror &m) const;// { return TVector2(X()-m.X(), Y()-m.Y()); }
    3737
     38    void SetSigmaPSF(Double_t psf) { fSigmaPSF = psf; }
     39    void SetFocalLength(Double_t f) { fFocalLength = f; }
    3840    void SetPosition(const TVector3 &v) { fPos = v; }
    3941    void SetNorm(const TVector3 &n) {
     
    5456    const TVector3 &GetNorm() const { return fNorm; }
    5557
     58    Double_t GetFocalLength() const { return fFocalLength; }
     59    Double_t GetSigmaPSF() const { return fSigmaPSF; }
     60
    5661    Double_t GetDist() const { return fPos.Perp(); }
    5762
     
    6368
    6469    // ----- Basic function for parabolic mirror -----
    65     void SetFocalLength(Double_t f) { fFocalLength = f; }
    66     Double_t GetFocalLength() const { return fFocalLength; }
    67 
    6870    Bool_t ExecuteReflection(MQuaternion &p, MQuaternion &u) const;
    6971
  • trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.cc

    r9322 r9332  
    144144Int_t MMirrorDisk::ReadM(const TObjArray &tok)
    145145{
    146     if (tok.GetSize()<9)
     146    if (tok.GetEntries()!=1)
    147147        return -1;
    148148
    149     Double_t r = atof(tok[8]->GetName());
     149    Double_t r = atof(tok[0]->GetName());
    150150
    151151    if (r<=0)
  • trunk/MagicSoft/Mars/msimreflector/MMirrorHex.cc

    r9324 r9332  
    163163Int_t MMirrorHex::ReadM(const TObjArray &tok)
    164164{
    165     if (tok.GetSize()<9)
     165    if (tok.GetEntries()!=1)
    166166        return -1;
    167167
    168     const Double_t d = atof(tok[8]->GetName());
     168    const Double_t d = atof(tok[0]->GetName());
    169169
    170170    if (d<=0)
  • trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.cc

    r9322 r9332  
    160160Int_t MMirrorSquare::ReadM(const TObjArray &tok)
    161161{
    162     if (tok.GetSize()<9)
     162    if (tok.GetEntries()!=1)
    163163        return -1;
    164164
    165     Double_t l = atof(tok[8]->GetName());
     165    Double_t l = atof(tok[0]->GetName());
    166166
    167167    if (l<=0)
  • trunk/MagicSoft/Mars/msimreflector/MReflector.cc

    r9313 r9332  
    6565// --------------------------------------------------------------------------
    6666//
     67// Set the SigmaPSF of all mirrors currently stored.
     68//
     69void MReflector::SetSigmaPSF(Double_t psf)
     70{
     71    fMirrors.ForEach(MMirror, SetSigmaPSF)(psf);
     72}
     73
     74// --------------------------------------------------------------------------
     75//
    6776// Calculate the maximum radius of th ereflector. This is not meant as
    6877// a precise number but as a rough estimate e.g. to bin a histogram.
     
    118127// --------------------------------------------------------------------------
    119128//
     129// I/O helper for ReadFile to avoid calling "delete arr" before every return
     130//
     131MMirror *MReflector::EvalTokens(TObjArray &arr, Double_t defpsf) const
     132{
     133    if (arr.GetEntries()<9)
     134    {
     135        *fLog << err << "ERROR - Not enough arguments..." << endl;
     136        return 0;
     137    }
     138
     139    const TVector3 pos(atof(arr[0]->GetName()),
     140                       atof(arr[1]->GetName()),
     141                       atof(arr[2]->GetName()));
     142
     143    const TVector3 norm(atof(arr[3]->GetName()),
     144                        atof(arr[4]->GetName()),
     145                        atof(arr[5]->GetName()));
     146
     147    const Double_t F = atof(arr[6]->GetName());
     148
     149    const TString val = arr[7]->GetName();
     150
     151    const Double_t psf = val.IsFloat() ? val.Atof() : -1;
     152
     153    const UInt_t n = val.IsFloat() ? 9 : 8;
     154
     155    TString type = arr[n-1]->GetName();
     156    type.Prepend("MMirror");
     157
     158    for (UInt_t i=0; i<n; i++)
     159        delete arr.RemoveAt(i);
     160    arr.Compress();
     161
     162    TString msg;
     163    TClass *cls = MParContainer::GetClass(type);
     164    if (!cls)
     165    {
     166        *fLog << err << "ERROR - Class " << type << " not in dictionary." << endl;
     167        return 0;
     168    }
     169
     170    if (!cls->InheritsFrom(MMirror::Class()))
     171    {
     172        *fLog << err << "ERROR - Cannot create new instance of class " << type << ": " << endl;
     173        *fLog << "Class doesn't inherit from MMirror." << endl;
     174        return 0;
     175    }
     176
     177    MMirror *m = static_cast<MMirror*>(cls->New());
     178    if (!m)
     179    {
     180        *fLog << err << "ERROR - Cannot create new instance of class " << type << ": " << endl;
     181        *fLog << " - Class has no default constructor." << endl;
     182        *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
     183        return 0;
     184    }
     185
     186    m->SetFocalLength(F);
     187    m->SetPosition(pos);
     188    m->SetNorm(norm);
     189    m->SetSigmaPSF(psf>=0 ? psf : defpsf);
     190
     191    if (m->ReadM(arr)>=0)
     192        return m;
     193
     194    *fLog << err << "ERROR - " << type << "::ReadM failed." << endl;
     195
     196    delete m;
     197    return 0;
     198}
     199
     200// --------------------------------------------------------------------------
     201//
    120202// Read a reflector setup from a file. This needs improvemtn.
    121 // FIXME: Documentation missing!
    122 //
    123 Bool_t MReflector::ReadFile(TString fname)
     203//
     204// The file structur is like:
     205//
     206//     x y z nx ny nz F [psf] Type ...
     207//
     208//  x:      x-coordinate of the mirror's center
     209//  y:      y-coordinate of the mirror's center
     210//  z:      z-coordinate of the mirror's center
     211//  nx:     x-component of the normal vecor in the mirror center
     212//  ny:     y-component of the normal vecor in the mirror center
     213//  nz:     z-component of the normal vecor in the mirror center
     214//  F:      Focal distance of a spherical mirror
     215//  [psf]:  This number is the psf given in the units of x,y,z and
     216//          defined at the focal distance F. It can be used to overwrite
     217//          the second argument given in ReadFile for individual mirrors.
     218//  Type:   A instance of a mirrot of the class Type MMirrorType is created
     219//          (Type can be, for example, Hex for for MMirrorHex).
     220//  ...:    Additional arguments as defined in MMirrorType::ReadM
     221//
     222//
     223// Coordinate System:
     224//  The coordinate system is local in the reflectors frame.
     225//  It is defined viewing from the back side of the reflector
     226//  towards the camera. (x "right", y "up", z from reflector to camera)
     227//  Note, that it is left-handed!
     228//
     229Bool_t MReflector::ReadFile(TString fname, Double_t defpsf)
    124230{
    125231    SetTitle(fname);
     
    145251    */
    146252
     253    Int_t cnt = 0;
     254
    147255    while (1)
    148256    {
     
    152260            break;
    153261
     262        // Count lines
     263        cnt++;
     264
     265        // Skip comments
    154266        if (line.BeginsWith("#"))
    155         {
    156             //cout << line << endl;
    157267            continue;
    158         }
    159 
     268
     269        // Remove leading and trailing whitespaces
    160270        line=line.Strip(TString::kBoth);
    161271
     272        // Skip empty lines
    162273        if (line.IsNull())
    163274            continue;
    164275
     276        // Tokenize line
    165277        TObjArray *arr = line.Tokenize(' ');
    166278
    167         if (arr->GetSize()<8)
     279        // Evaluate tokens
     280        MMirror *m = EvalTokens(*arr, defpsf);
     281
     282        // Delete now obsolete array
     283        delete arr;
     284
     285        // Check if a new mirror could be created successfully
     286        if (!m)
    168287        {
    169             cout << "Skip3: " <<line << endl;
    170             delete arr;
    171             continue;
    172         }
    173 
    174         const TVector3 pos(atof((*arr)[0]->GetName()),
    175                            atof((*arr)[1]->GetName()),
    176                            atof((*arr)[2]->GetName()));
    177 
    178         const TVector3 norm(atof((*arr)[3]->GetName()),
    179                             atof((*arr)[4]->GetName()),
    180                             atof((*arr)[5]->GetName()));
    181 
    182         const Double_t F = atof((*arr)[6]->GetName());
    183 
    184         TString type = (*arr)[7]->GetName();
    185         type.Prepend("MMirror");
    186 
    187         TString msg;
    188         TClass *cls = MParContainer::GetClass(type);
    189         if (!cls)
    190         {
    191             *fLog << err << dbginf << "ERROR - Class " << type << " not in dictionary." << endl;
     288            *fLog << err << "Error in line " << cnt << ": " << line << endl;
    192289            return kFALSE;
    193290        }
    194291
    195         if (!cls->InheritsFrom(MMirror::Class()))
    196         {
    197             *fLog << err << dbginf << "Cannot create new instance of class " << type << ": " << endl;
    198             *fLog << "Class doesn't inherit from MMirror." << endl;
    199             return kFALSE;
    200         }
    201 
    202         MMirror *m = (MMirror*)cls->New();
    203         if (!m)
    204         {
    205             *fLog << err << dbginf << "Cannot create new instance of class " << type << ": " << endl;
    206             *fLog << " - Class has no default constructor." << endl;
    207             *fLog << " - An abstract member functions of a base class is not overwritten." << endl;
    208             return kFALSE;
    209         }
    210 
    211         m->SetFocalLength(F);
    212         m->SetPosition(pos);
    213         m->SetNorm(norm);
    214 
    215         Int_t n = m->ReadM(*arr);
    216         if (n<=0)
    217         {
    218             *fLog << err << dbginf << "ERROR - ReadM failed." << endl;
    219             return kFALSE;
    220         }
    221 
     292        // Add new mirror to array
    222293        fMirrors.Add(m);
    223 
    224         //maxr = TMath::Max(maxr, TMath::Hypot(pos[i].X()+24.75, pos[i].Y()+24.75));
    225         //maxr = TMath::Max(maxr, TMath::Hypot(pos.X()+24.75, pos.Y()+24.75));
    226 
    227         delete arr;
    228294    }
    229295
     
    285351// --------------------------------------------------------------------------
    286352//
     353// SigmaPSF: -1
    287354// FileName: reflector.txt
    288355//
     356// SigmaPSF can be used to set a default for the psf of the mirrors
     357// read from the file. Note, that this can be overwritten for individual
     358// mirrors in the file.
     359//
     360// For details on the file structure see MReflector::ReadFile
     361//
    289362Int_t MReflector::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
    290363{
    291364    Bool_t rc = kFALSE;
     365
     366    Double_t psf = -1;
     367    if (IsEnvDefined(env, prefix, "SetSigmaPSF", print))
     368    {
     369        rc = kTRUE;
     370        psf = GetEnvValue(env, prefix, "SetSigmaPSF", -1);
     371    }
     372
    292373    if (IsEnvDefined(env, prefix, "FileName", print))
    293374    {
    294375        rc = kTRUE;
    295         if (!ReadFile(GetEnvValue(env, prefix, "FileName", "")))
     376        if (!ReadFile(GetEnvValue(env, prefix, "FileName", ""), psf))
    296377            return kERROR;
    297378    }
  • trunk/MagicSoft/Mars/msimreflector/MReflector.h

    r9312 r9332  
    2828    void InitMaxR();
    2929
     30    // Helper for I/O
     31    MMirror *EvalTokens(TObjArray &arr, Double_t defpsf) const;
     32
    3033    // MParContainer
    3134    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
     
    3942    const MMirror *GetMirror(UInt_t idx) const { return idx>=GetNumMirrors()?0:*(GetFirstPtr()+idx); }
    4043
    41     Bool_t ReadFile(TString fname);
     44    Bool_t ReadFile(TString fname, Double_t defpsf=-1);
    4245
    4346    Double_t GetMaxR() const { return fMaxR; }
     
    4649
    4750    Int_t ExecuteReflector(MQuaternion &p, MQuaternion &u) const;
     51
     52    void SetSigmaPSF(Double_t psf);
    4853
    4954    // TObject
Note: See TracChangeset for help on using the changeset viewer.