File: masscomparefunctors.hpp

package info (click to toggle)
libpwiz 3.0.18342-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,888 kB
  • sloc: cpp: 157,552; sh: 4,182; makefile: 317
file content (129 lines) | stat: -rw-r--r-- 3,338 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// $Id$
//
//
// Original author: Witold Wolski <wewolski@gmail.com>
//
// Copyright : ETH Zurich
//
// Licensed under the Apache License, Version 2.0 (the "License"); 
// you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at 
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software 
// distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and 
// limitations under the License.
//


#ifndef MASSCOMPAREFUNCTORS_H
#define MASSCOMPAREFUNCTORS_H

#include <stdlib.h>
#include <cstdio>
#include <complex>
/*! \file MassCompareFunctors.h
Defines function objects which are used by SortedMatcher and UnsortedMatcher.

*/
namespace ralab
{

  namespace base
  {
    namespace resample
    {


      inline double resolution2ppm(double resolution){
         return 1/resolution * 1e6;
      }

     
     ///TODO Do checking on TReal thats a real
      template<typename TReal>
      struct PPMCompFunctor
      {
        typedef TReal value_type;
        value_type window_;
        value_type ppm_;

        PPMCompFunctor(value_type window //!< in ppm
                       ):window_(window),ppm_(1e-6)
        {}

        /// returns window at mass
        inline value_type operator()(value_type val)
        {
          return((window_ * val)*ppm_);
        }

        /// if dist pval cval smaller then window returns true
        inline bool operator()(value_type pval, value_type cval)
        {
          return( std::abs(pval - cval) < operator()(pval) );
        }
      };

      /// Da Comparator - constant mass error
      template<typename TReal>
      struct DaCompFunctor
      {
        typedef TReal value_type;
        value_type window_;
        DaCompFunctor(value_type window) : window_(window)
        {
        }

        ///  window at mass
        inline value_type operator()(value_type /*val*/)
        {
          return( window_ );
        }

        /** if dist pval cval smaller then window returns true */
        inline bool operator()(value_type pval, value_type cval)
        {
          return( std::abs(pval - cval)   < operator()(pval) );
        }
      };

      /// FTMS Comparator
      template<typename TReal>
      struct FTMSCompFunctor
      {
        typedef TReal value_type;
        value_type window_;

        value_type mass_;
        value_type invR_;//FTMS resolution

        /// brief window at mass, i.e. 0.1 Da at 400Da
        FTMSCompFunctor( value_type window , value_type mass ) : window_(window) ,  mass_(mass)
        {
          invR_ = sqrt(window_)/mass_;
        }

        /// brief returns size of windows for this mass
        inline value_type operator()(value_type val)
        {
          value_type pR = (val*invR_);
          return( pR*pR );
        }
        /// brief compares two masses, returns true if they match false otherwise
        inline bool operator()(value_type pval, value_type cval)
        {
          return( std::abs( pval - cval )   <  operator()(pval) );
        }
      };

    }//end resample
  }//end MSALGO
}//end ralab


#endif // MASSCOMPAREFUNCTORS_H