MINT2
Utils.h
Go to the documentation of this file.
1 #ifndef UHTILS_HH
2 #define UHTILS_HH
3 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
4 // status: Mon 9 Feb 2009 19:17:57 GMT
5 
6 #include <iostream>
7 #include "TLorentzVector.h"
8 #include <sstream>
9 #include <string>
10 #include <map>
11 #include <vector>
12 #include "TMatrixT.h"
13 #include "TMatrixTSym.h"
14 
15 namespace MINT{
16 
18 
19 template <typename Key, typename Val>
20  const Val & keyFinder( const Key& k
21  , const std::map< Key, Val > & m
22  , const Val& dummy
23  , bool& successFlag
24  ){
25  typename std::map< Key , Val >::const_iterator it = m.find(k);
26  if(it == m.end()){
27  successFlag = false;
28  return dummy;
29  }else{
30  successFlag = true;
31  return it->second;
32  }
33 }
34 
35 template <typename Key, typename Val>
36  const Val & keyFinder( const Key& k
37  , const std::map< Key, Val > & m
38  , const Val& dummy
39  ){
40  bool successFlag;
41  return keyFinder<Key, Val>(k, m, dummy, successFlag);
42 }
43 
44 template<typename T>
45 TMatrixTSym<T> makeTMatrixTSym(const TMatrixT<T>& m){
46  TMatrixTSym<T> ms(m.GetNcols());
47  for(int i=0; i < ms.GetNcols(); i++){
48  for(int j=i; j < ms.GetNcols(); j++){
49  ms(i,j) = ms(j,i) = m(i,j);
50  }
51  }
52  return ms;
53 }
54 
55 template<typename T>
56 void stringToAnything(const std::string& str, T& anything){
57  std::stringstream strm(str);
58  strm >> anything;
59 }
60 
61 template<typename T>
62 std::string anythingToString(const T& anything){
63  std::stringstream strm;
64  strm << anything;
65  std::string ing;
66  strm >> ing;
67  return ing;
68 }
69 
70 template<typename T>
71 std::string anyVectorToString(const std::vector<T>& anyV){
72  std::stringstream strm;
73  for(unsigned int i=0; i<anyV.size(); i++){
74  strm << anyV[i];
75  }
76  std::string ing;
77  strm >> ing;
78  return ing;
79 }
80 
81 std::string stringtime(double dt);
82 
83 int nearestInt(double f);
84 
85 bool A_is_in_B(const std::string& a, const std::string& b);
86 
87 // need to move these to Dalitz Fitter
88 int LeviCita(int a, int b);
89 int LeviCita(int a, int b, int c);
90 int LeviCita(int a, int b, int c, int d);
91 int LeviCita(int a, int b, int c, int d, int e);
92 int LeviCita(const std::vector<int>& v);
93 
94 } // namespace MINT
95 
96 std::ostream& operator<<(std::ostream& os, const TLorentzVector& v);
97 
98 template<typename T>
99 std::ostream& operator<<(std::ostream& os, const std::vector<T>& v){
100  os << "(";
101  for(unsigned int i=0; i<v.size(); i++){
102  os << v[i];
103  if(i + 1 < v.size()) os << ", ";
104  }
105  os << ")";
106  return os;
107 }
108 
109 #endif
110 //
void stringToAnything(const std::string &str, T &anything)
Definition: Utils.h:56
std::ostream & operator<<(std::ostream &os, const TLorentzVector &v)
Definition: Utils.cpp:7
int LeviCita(int a, int b)
Definition: Utils.cpp:41
TMatrixTSym< T > makeTMatrixTSym(const TMatrixT< T > &m)
Definition: Utils.h:45
int nearestInt(double f)
Definition: Utils.cpp:26
bool A_is_in_B(const std::string &a, const std::string &b)
Definition: Utils.cpp:34
const Val & keyFinder(const Key &k, const std::map< Key, Val > &m, const Val &dummy, bool &successFlag)
Definition: Utils.h:20
static const double m
OWNERSHIP
Definition: Utils.h:17
std::string anyVectorToString(const std::vector< T > &anyV)
Definition: Utils.h:71
std::string anythingToString(const T &anything)
Definition: Utils.h:62
std::string stringtime(double dt)
Definition: Utils.cpp:14
static const double ms