Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_PRODUCTMODEL_H
00037 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_PRODUCTMODEL_H
00038
00039 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/BaseModel.h>
00040 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/ModelDescription.h>
00041 #include <OpenMS/KERNEL/Peak2D.h>
00042 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/IsotopeModel.h>
00043 #include <OpenMS/CHEMISTRY/EmpiricalFormula.h>
00044
00045 namespace OpenMS
00046 {
00047
00060 template <UInt D>
00061 class ProductModel;
00062
00064 template <>
00065 class OPENMS_DLLAPI ProductModel<2>:
00066 public BaseModel<2>
00067 {
00068 public:
00069
00071 enum {D = 2};
00072
00073 typedef DoubleReal IntensityType;
00074 typedef DPosition<D> PositionType;
00075 typedef BaseModel<D>::SamplesType SamplesType;
00076
00078 ProductModel() :
00079 BaseModel<D>(),
00080 distributions_(D, 0)
00081 {
00082 this->setName(this->getProductName());
00083
00084
00085 for (UInt dim = 0; dim < D; ++dim)
00086 {
00087 String name = Peak2D::shortDimensionName(dim);
00088 this->subsections_.push_back(name);
00089 this->defaults_.setValue(name, "GaussModel", "Name of the model used for this dimension");
00090 }
00091
00092
00093 this->defaults_.setValue("intensity_scaling", 1.0, "Scaling factor used to adjust the model distribution to the intensities of the data");
00094 this->defaultsToParam_();
00095 }
00096
00098 ProductModel(const ProductModel & source) :
00099 BaseModel<D>(source),
00100 distributions_(D, 0),
00101 scale_(source.scale_)
00102 {
00103 for (UInt dim = 0; dim < D; ++dim)
00104 {
00105
00106 if (source.distributions_[dim])
00107 {
00108 ModelDescription<1> desc(source.distributions_[dim]);
00109 setModel(dim, desc.createModel());
00110 }
00111 }
00112 updateMembers_();
00113 }
00114
00116 virtual ~ProductModel()
00117 {
00118 for (Size dim = 0; dim < D; ++dim)
00119 {
00120 delete distributions_[dim];
00121 }
00122 }
00123
00125 virtual ProductModel & operator=(const ProductModel & source)
00126 {
00127 if (&source == this) return *this;
00128
00129 BaseModel<D>::operator=(source);
00130 scale_ = source.scale_;
00131
00132 for (UInt dim = 0; dim < D; ++dim)
00133 {
00134 if (source.distributions_[dim])
00135 {
00136
00137 ModelDescription<1> desc(source.distributions_[dim]);
00138 setModel(dim, desc.createModel());
00139 }
00140 else
00141 {
00142 distributions_[dim] = 0;
00143 }
00144 }
00145 updateMembers_();
00146
00147 return *this;
00148 }
00149
00151 IntensityType getIntensity(const PositionType & pos) const
00152 {
00153 IntensityType intens(scale_);
00154 for (UInt dim = 0; dim < D; ++dim)
00155 {
00156 if (distributions_[dim] == 0)
00157 {
00158 throw Exception::BaseException(__FILE__, __LINE__, __PRETTY_FUNCTION__, String("ProductModel: model for dimension ") + dim + " not set.", "");
00159 }
00160 intens *= distributions_[dim]->getIntensity(pos[dim]);
00161 }
00162 return intens;
00163 }
00164
00166 static BaseModel<D> * create()
00167 {
00168 return new ProductModel<D>();
00169 }
00170
00172 static const String getProductName()
00173 {
00174 return String("ProductModel") + D + "D";
00175 }
00176
00184 ProductModel & setModel(UInt dim, BaseModel<1> * dist)
00185 {
00186 OPENMS_PRECONDITION(dim < D, "ProductModel<D>:getModel(Position): index overflow!");
00187 if (dist == 0 || dist == distributions_[dim])
00188 {
00189 return *this;
00190 }
00191
00192 delete distributions_[dim];
00193 distributions_[dim] = dist;
00194
00195
00196 String name = Peak2D::shortDimensionName(dim);
00197 this->param_.removeAll(name + ':');
00198 this->param_.insert(name + ':', distributions_[dim]->getParameters());
00199 this->param_.setValue(name, distributions_[dim]->getName());
00200
00201 return *this;
00202 }
00203
00204 BaseModel<1> * getModel(UInt dim) const
00205 {
00206 OPENMS_PRECONDITION(dim < D, "ProductModel<D>:getModel(Position): index overflow!");
00207 return distributions_[dim];
00208 }
00209
00211 IntensityType getScale() const
00212 {
00213 return scale_;
00214 }
00215
00217 void setScale(IntensityType scale)
00218 {
00219 this->setCutOff(this->getCutOff() / scale_);
00220 scale_ = scale;
00221 this->param_.setValue("intensity_scaling", scale);
00222 this->setCutOff(this->getCutOff() * scale_);
00223 }
00224
00226 void getSamples(SamplesType & cont) const
00227 {
00228 cont.clear();
00229 typedef BaseModel<1>::SamplesType Samples1D;
00230 std::vector<Samples1D> samples(D);
00231
00232 for (Size dim = 0; dim < D; ++dim)
00233 {
00234 distributions_[dim]->getSamples(samples[dim]);
00235 }
00236
00237 BaseModel<D>::PeakType peak;
00238 std::vector<UInt> i(D, 0);
00239
00240 while (i[D - 1] < samples[D - 1].size())
00241 {
00242 for (UInt dim = 0; dim < D; ++dim)
00243 {
00244 peak.getPosition()[dim] = samples[dim][i[dim]].getPosition()[0];
00245 }
00246 fillIntensity(peak);
00247 cont.push_back(peak);
00248
00249 ++i[0];
00250 for (Size dim = 0; dim < D - 1; ++dim)
00251 {
00252 if (i[dim] >= samples[dim].size())
00253 {
00254 i[dim] = 0;
00255 ++i[dim + 1];
00256 }
00257 }
00258 }
00259 return;
00260 }
00261
00262 protected:
00263 void updateMembers_()
00264 {
00265 BaseModel<D>::updateMembers_();
00266 scale_ = (double)(this->param_.getValue("intensity_scaling"));
00267 for (UInt dim = 0; dim < D; ++dim)
00268 {
00269 String name = Peak2D::shortDimensionName(dim);
00270 if (this->param_.exists(name))
00271 {
00272 delete distributions_[dim];
00273 distributions_[dim] = Factory<BaseModel<1> >::create(this->param_.getValue(name));
00274 Param copy = this->param_.copy(name + ":", true);
00275 distributions_[dim]->setParameters(copy);
00276 if (distributions_[dim]->getName().hasSubstring("IsotopeModel"))
00277 {
00278 static_cast<IsotopeModel *>(distributions_[dim])->setSamples(static_cast<IsotopeModel *>(distributions_[dim])->getFormula());
00279 }
00280 }
00281 }
00282 }
00283
00284 std::vector<BaseModel<1> *> distributions_;
00285 IntensityType scale_;
00286 };
00287 }
00288
00289 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_PRODUCTMODEL_H