Changeset 9425 for trunk/MagicSoft/Mars/msim
- Timestamp:
- 04/16/09 12:04:29 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/msim
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msim/MSimAbsorption.cc
r9348 r9425 30 30 // 31 31 // Input Containers: 32 // fParName [MParSpline] 32 33 // MPhotonEvent 33 34 // MCorsikaEvtHeader … … 43 44 44 45 #include <TRandom.h> 45 #include <TSpline.h>46 46 47 47 #include "MLog.h" … … 50 50 #include "MParList.h" 51 51 52 #include "MBinning.h" 53 #include "MArrayD.h" 54 55 #include "MSpline3.h" 52 #include "MParSpline.h" 56 53 57 54 #include "MCorsikaEvtHeader.h" … … 69 66 // 70 67 MSimAbsorption::MSimAbsorption(const char* name, const char *title) 71 : fEvt(0), fHeader(0), fSpline(0), f UseTheta(kFALSE)68 : fEvt(0), fHeader(0), fSpline(0), fParName("MParSpline"), fUseTheta(kFALSE) 72 69 { 73 70 fName = name ? name : "MSimAbsorption"; 74 71 fTitle = title ? title : "Task to calculate wavelength dependent absorption"; 75 }76 77 // --------------------------------------------------------------------------78 //79 // Calls Clear()80 //81 MSimAbsorption::~MSimAbsorption()82 {83 Clear();84 }85 86 // --------------------------------------------------------------------------87 //88 // Delete fSpline and set to 0.89 //90 void MSimAbsorption::Clear(Option_t *)91 {92 if (fSpline)93 delete fSpline;94 fSpline=0;95 }96 97 // --------------------------------------------------------------------------98 //99 // Read a TGraph from a file and return a newly allocated MSpline3.100 //101 MSpline3 *MSimAbsorption::ReadSpline(const char *fname)102 {103 *fLog << inf << "Reading spline from " << fname << endl;104 105 TGraph g(fname);106 if (g.GetN()==0)107 {108 *fLog << err << "ERROR - No data points from " << fname << "." << endl;109 return 0;110 }111 112 // option: b1/e1 b2/e2 (first second derivative?)113 // option: valbeg/valend (first second derivative?)114 115 return new MSpline3(g);116 }117 118 // --------------------------------------------------------------------------119 //120 // Initializes a spline from min to max with n points with 1.121 //122 void MSimAbsorption::InitUnity(UInt_t n, Float_t min, Float_t max)123 {124 // Delete the existing spline125 Clear();126 127 // We need at least two points (the edges)128 if (n<2)129 return;130 131 // Initialize an array with the x-values132 const MBinning bins(n-1, min, max);133 134 // Initialize an array with all one135 MArrayD y(n);136 y.Reset(1);137 138 // Set the spline139 fSpline = new MSpline3(bins.GetEdges(), y.GetArray(), n);140 }141 142 // --------------------------------------------------------------------------143 //144 // Takes the existing fSpline and multiplies it with the given spline.145 // As x-points the values from fSpline are used.146 //147 void MSimAbsorption::Multiply(const TSpline3 &spline)148 {149 if (!fSpline)150 {151 Clear();152 // WARNING WARNING WARNING: This is a very dangerous cast!153 fSpline = (MSpline3*)spline.Clone();154 return;155 }156 157 // Initialize a TGraph with the number of knots from a TSpline158 TGraph g(fSpline->GetNp());159 160 // Loop over all knots161 for (int i=0; i<fSpline->GetNp(); i++)162 {163 // Get th i-th knot164 Double_t x, y;165 fSpline->GetKnot(i, x, y);166 167 // Multiply y by the value from the given spline168 y *= spline.Eval(x);169 170 // push the point "back"171 g.SetPoint(i, x, y);172 }173 174 // Clear the spline and initialize a new one from the updated TGraph175 Clear();176 fSpline = new MSpline3(g);177 }178 179 // --------------------------------------------------------------------------180 //181 // Initializes a TSpline3 with n knots x and y. Call Multiply for it.182 //183 void MSimAbsorption::Multiply(UInt_t n, const Double_t *x, const Double_t *y)184 {185 const TSpline3 spline("Spline", const_cast<Double_t*>(x), const_cast<Double_t*>(y), n);186 Multiply(spline);187 }188 189 // --------------------------------------------------------------------------190 //191 // Read a Spline from a file using ReadSpline.192 // Call Multiply for it.193 //194 void MSimAbsorption::Multiply(const char *fname)195 {196 const MSpline3 *spline = ReadSpline(fname);197 if (!spline)198 return;199 200 fFileName = "";201 202 Multiply(*spline);203 204 delete spline;205 }206 207 // --------------------------------------------------------------------------208 //209 // Read a spline from a file and set fSpline accfordingly.210 //211 Bool_t MSimAbsorption::ReadFile(const char *fname)212 {213 if (fname)214 fFileName = fname;215 216 MSpline3 *spline = ReadSpline(fFileName);217 if (!spline)218 return kFALSE;219 220 221 // option: b1/e1 b2/e2 (first second derivative?)222 // option: valbeg/valend (first second derivative?)223 224 Clear();225 fSpline = spline;226 227 return kTRUE;228 72 } 229 73 … … 235 79 Int_t MSimAbsorption::PreProcess(MParList *pList) 236 80 { 237 if (fFileName.IsNull())238 {239 *fLog << inf << "No file given... skipping." << endl;240 return kSKIP;241 }242 243 81 fEvt = (MPhotonEvent*)pList->FindObject("MPhotonEvent"); 244 82 if (!fEvt) 245 83 { 246 84 *fLog << err << "MPhotonEvent not found... aborting." << endl; 85 return kFALSE; 86 } 87 88 fSpline = (MParSpline*)pList->FindObject(fParName, "MParSpline"); 89 if (!fSpline) 90 { 91 *fLog << err << fParName << " [MParSpline] not found... aborting." << endl; 92 return kFALSE; 93 } 94 95 if (!fSpline->IsValid()) 96 { 97 *fLog << err << "Spline in " << fParName << " is inavlid... aborting." << endl; 247 98 return kFALSE; 248 99 } … … 257 108 *fLog << inf << "Using " << (fUseTheta?"Theta":"Wavelength") << " for absorption." << endl; 258 109 259 return ReadFile();110 return kTRUE; 260 111 } 261 112 … … 331 182 { 332 183 Bool_t rc = kFALSE; 333 if (IsEnvDefined(env, prefix, " FileName", print))184 if (IsEnvDefined(env, prefix, "ParName", print)) 334 185 { 335 186 rc = kTRUE; 336 Set FileName(GetEnvValue(env, prefix, "FileName", fFileName));187 SetParName(GetEnvValue(env, prefix, "ParName", fParName)); 337 188 } 338 189 -
trunk/MagicSoft/Mars/msim/MSimAbsorption.h
r9232 r9425 6 6 #endif 7 7 8 class TSpline3;9 10 8 class MParList; 11 class M Spline3;9 class MParSpline; 12 10 class MPhotonEvent; 13 11 class MCorsikaEvtHeader; … … 19 17 MCorsikaEvtHeader *fHeader; //! Header storing event information 20 18 21 M Spline3*fSpline; //! Spline to interpolate wavelength or incident angle19 MParSpline *fSpline; //! Spline to interpolate wavelength or incident angle 22 20 23 TString f FileName; // FileName of the file containing the curve21 TString fParName; // Container name of the spline containing the curve 24 22 Bool_t fUseTheta; // Switches between using wavelength or incident angle 25 23 … … 32 30 Int_t Process(); 33 31 34 // MSimAbsorption35 MSpline3 *ReadSpline(const char *fname);36 37 32 public: 38 33 MSimAbsorption(const char *name=NULL, const char *title=NULL); 39 ~MSimAbsorption();40 34 41 35 // MSimAbsorption 42 Bool_t ReadFile(const char *fname=0); 43 void SetFileName(const char *fname) { fFileName=fname; } 36 void SetParName(const char *name) { fParName=name; } 44 37 45 38 void SetUseTheta(Bool_t b=kTRUE) { fUseTheta = b; } 46 47 void InitUnity(UInt_t n, Float_t min, Float_t max);48 49 void Multiply(const char *fname);50 void Multiply(const TSpline3 &spline);51 void Multiply(UInt_t n, const Double_t *x, const Double_t *y);52 53 // TObject54 void Clear(Option_t *o="");55 39 56 40 ClassDef(MSimAbsorption, 0) // Task to calculate wavelength or incident angle dependent absorption
Note:
See TracChangeset
for help on using the changeset viewer.