Changeset 9332 for trunk/MagicSoft/Mars/msimreflector
- Timestamp:
- 02/13/09 17:46:02 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/msimreflector
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msimreflector/MMirror.cc
r9312 r9332 126 126 psf /= 2; // The factor two because of the doubleing of the angle in the reflection 127 127 psf /= F; // Scale the Gauss to the size of the PSF 128 psf *= n.Z(); // Normalize the addon vector to the normal vector129 //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 130 130 131 131 TVector3 dn(gx*psf, gy*psf, 0); // Instead of psf/F also atan(psf/F) might make sense … … 136 136 } 137 137 138 // -------------------------------------------------------------------------- 139 // 138 140 void MMirror::Print(Option_t *o) const 139 141 { … … 141 143 gLog << fNorm.X() << " " << fNorm.Y() << " " << fNorm.Z() << " "; 142 144 gLog << fFocalLength << " "; 145 if (fSigmaPSF>0) 146 gLog << fSigmaPSF << " "; 143 147 144 148 const TString n = ClassName(); -
trunk/MagicSoft/Mars/msimreflector/MMirror.h
r9312 r9332 36 36 TVector2 operator-(const MMirror &m) const;// { return TVector2(X()-m.X(), Y()-m.Y()); } 37 37 38 void SetSigmaPSF(Double_t psf) { fSigmaPSF = psf; } 39 void SetFocalLength(Double_t f) { fFocalLength = f; } 38 40 void SetPosition(const TVector3 &v) { fPos = v; } 39 41 void SetNorm(const TVector3 &n) { … … 54 56 const TVector3 &GetNorm() const { return fNorm; } 55 57 58 Double_t GetFocalLength() const { return fFocalLength; } 59 Double_t GetSigmaPSF() const { return fSigmaPSF; } 60 56 61 Double_t GetDist() const { return fPos.Perp(); } 57 62 … … 63 68 64 69 // ----- Basic function for parabolic mirror ----- 65 void SetFocalLength(Double_t f) { fFocalLength = f; }66 Double_t GetFocalLength() const { return fFocalLength; }67 68 70 Bool_t ExecuteReflection(MQuaternion &p, MQuaternion &u) const; 69 71 -
trunk/MagicSoft/Mars/msimreflector/MMirrorDisk.cc
r9322 r9332 144 144 Int_t MMirrorDisk::ReadM(const TObjArray &tok) 145 145 { 146 if (tok.Get Size()<9)146 if (tok.GetEntries()!=1) 147 147 return -1; 148 148 149 Double_t r = atof(tok[ 8]->GetName());149 Double_t r = atof(tok[0]->GetName()); 150 150 151 151 if (r<=0) -
trunk/MagicSoft/Mars/msimreflector/MMirrorHex.cc
r9324 r9332 163 163 Int_t MMirrorHex::ReadM(const TObjArray &tok) 164 164 { 165 if (tok.Get Size()<9)165 if (tok.GetEntries()!=1) 166 166 return -1; 167 167 168 const Double_t d = atof(tok[ 8]->GetName());168 const Double_t d = atof(tok[0]->GetName()); 169 169 170 170 if (d<=0) -
trunk/MagicSoft/Mars/msimreflector/MMirrorSquare.cc
r9322 r9332 160 160 Int_t MMirrorSquare::ReadM(const TObjArray &tok) 161 161 { 162 if (tok.Get Size()<9)162 if (tok.GetEntries()!=1) 163 163 return -1; 164 164 165 Double_t l = atof(tok[ 8]->GetName());165 Double_t l = atof(tok[0]->GetName()); 166 166 167 167 if (l<=0) -
trunk/MagicSoft/Mars/msimreflector/MReflector.cc
r9313 r9332 65 65 // -------------------------------------------------------------------------- 66 66 // 67 // Set the SigmaPSF of all mirrors currently stored. 68 // 69 void MReflector::SetSigmaPSF(Double_t psf) 70 { 71 fMirrors.ForEach(MMirror, SetSigmaPSF)(psf); 72 } 73 74 // -------------------------------------------------------------------------- 75 // 67 76 // Calculate the maximum radius of th ereflector. This is not meant as 68 77 // a precise number but as a rough estimate e.g. to bin a histogram. … … 118 127 // -------------------------------------------------------------------------- 119 128 // 129 // I/O helper for ReadFile to avoid calling "delete arr" before every return 130 // 131 MMirror *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 // 120 202 // 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 // 229 Bool_t MReflector::ReadFile(TString fname, Double_t defpsf) 124 230 { 125 231 SetTitle(fname); … … 145 251 */ 146 252 253 Int_t cnt = 0; 254 147 255 while (1) 148 256 { … … 152 260 break; 153 261 262 // Count lines 263 cnt++; 264 265 // Skip comments 154 266 if (line.BeginsWith("#")) 155 {156 //cout << line << endl;157 267 continue; 158 } 159 268 269 // Remove leading and trailing whitespaces 160 270 line=line.Strip(TString::kBoth); 161 271 272 // Skip empty lines 162 273 if (line.IsNull()) 163 274 continue; 164 275 276 // Tokenize line 165 277 TObjArray *arr = line.Tokenize(' '); 166 278 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) 168 287 { 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; 192 289 return kFALSE; 193 290 } 194 291 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 222 293 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;228 294 } 229 295 … … 285 351 // -------------------------------------------------------------------------- 286 352 // 353 // SigmaPSF: -1 287 354 // FileName: reflector.txt 288 355 // 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 // 289 362 Int_t MReflector::ReadEnv(const TEnv &env, TString prefix, Bool_t print) 290 363 { 291 364 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 292 373 if (IsEnvDefined(env, prefix, "FileName", print)) 293 374 { 294 375 rc = kTRUE; 295 if (!ReadFile(GetEnvValue(env, prefix, "FileName", "") ))376 if (!ReadFile(GetEnvValue(env, prefix, "FileName", ""), psf)) 296 377 return kERROR; 297 378 } -
trunk/MagicSoft/Mars/msimreflector/MReflector.h
r9312 r9332 28 28 void InitMaxR(); 29 29 30 // Helper for I/O 31 MMirror *EvalTokens(TObjArray &arr, Double_t defpsf) const; 32 30 33 // MParContainer 31 34 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print); … … 39 42 const MMirror *GetMirror(UInt_t idx) const { return idx>=GetNumMirrors()?0:*(GetFirstPtr()+idx); } 40 43 41 Bool_t ReadFile(TString fname );44 Bool_t ReadFile(TString fname, Double_t defpsf=-1); 42 45 43 46 Double_t GetMaxR() const { return fMaxR; } … … 46 49 47 50 Int_t ExecuteReflector(MQuaternion &p, MQuaternion &u) const; 51 52 void SetSigmaPSF(Double_t psf); 48 53 49 54 // TObject
Note:
See TracChangeset
for help on using the changeset viewer.