Debian Codegraph @

src/pwiz/utility/findmf/base/resample/masscomparefunctors.hpp

raw
1 //
2 // $Id$
3 //
4 //
5 // Original author: Witold Wolski <[email protected]>
6 //
7 // Copyright : ETH Zurich
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21
22
23 #ifndef MASSCOMPAREFUNCTORS_H
24 #define MASSCOMPAREFUNCTORS_H
25
26 #include <stdlib.h>
27 #include <cstdio>
28 #include <complex>
29 /*! \file MassCompareFunctors.h
30 Defines function objects which are used by SortedMatcher and UnsortedMatcher.
31
32 */
33 namespace ralab
34 {
35
36 namespace base
37 {
38 namespace resample
39 {
40
41
42 inline double resolution2ppm(double resolution){
43 return 1/resolution * 1e6;
44 }
45
46
47 ///TODO Do checking on TReal thats a real
48 template<typename TReal>
49 struct PPMCompFunctor
50 {
51 typedef TReal value_type;
52 value_type window_;
53 value_type ppm_;
54
55 PPMCompFunctor(value_type window //!< in ppm
56 ):window_(window),ppm_(1e-6)
57 {}
58
59 /// returns window at mass
60 inline value_type operator()(value_type val)
61 {
62 return((window_ * val)*ppm_);
63 }
64
65 /// if dist pval cval smaller then window returns true
66 inline bool operator()(value_type pval, value_type cval)
67 {
68 return( std::abs(pval - cval) < operator()(pval) );
69 }
70 };
71
72 /// Da Comparator - constant mass error
73 template<typename TReal>
74 struct DaCompFunctor
75 {
76 typedef TReal value_type;
77 value_type window_;
78 DaCompFunctor(value_type window) : window_(window)
79 {
80 }
81
82 /// window at mass
83 inline value_type operator()(value_type /*val*/)
84 {
85 return( window_ );
86 }
87
88 /** if dist pval cval smaller then window returns true */
89 inline bool operator()(value_type pval, value_type cval)
90 {
91 return( std::abs(pval - cval) < operator()(pval) );
92 }
93 };
94
95 /// FTMS Comparator
96 template<typename TReal>
97 struct FTMSCompFunctor
98 {
99 typedef TReal value_type;
100 value_type window_;
101
102 value_type mass_;
103 value_type invR_;//FTMS resolution
104
105 /// brief window at mass, i.e. 0.1 Da at 400Da
106 FTMSCompFunctor( value_type window , value_type mass ) : window_(window) , mass_(mass)
107 {
108 invR_ = sqrt(window_)/mass_;
109 }
110
111 /// brief returns size of windows for this mass
112 inline value_type operator()(value_type val)
113 {
114 value_type pR = (val*invR_);
115 return( pR*pR );
116 }
117 /// brief compares two masses, returns true if they match false otherwise
118 inline bool operator()(value_type pval, value_type cval)
119 {
120 return( std::abs( pval - cval ) < operator()(pval) );
121 }
122 };
123
124 }//end resample
125 }//end MSALGO
126 }//end ralab
127
128
129 #endif // MASSCOMPAREFUNCTORS_H