MINT2
Utils.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:17:57 GMT
3 #include "Mint/Utils.h"
4 
5 using namespace MINT;
6 
7 std::ostream& operator<<(std::ostream& out, const TLorentzVector& v){
8  out << "(";
9  for(int i=0; i<3; i++) out << v[i] << ", ";
10  out << v[3] << ")";
11  return out;
12 }
13 
14 std::string MINT::stringtime(double ddt){
15  int dt = (int) ddt;
16  std::string str;
17  int sec = 1;
18  int min = sec*60;
19  int h = min*60;
20  if(dt >= h) str += MINT::anythingToString( (int) (dt/h) ) + " h ";
21  if(dt >= min) str += MINT::anythingToString( (int) (dt%h)/min ) + " min ";
22  str += MINT::anythingToString(dt%min) + " s";
23  return str;
24 }
25 
26 int MINT::nearestInt(double f){
27  if(f >= 0) return ((int)(f+0.5));
28 
29  f *= -1;
30 
31  return - ((int)(f+0.5));
32 }
33 
34 bool MINT::A_is_in_B(const std::string& a, const std::string& b){
35  unsigned int pos = b.find(a);
36  return pos < b.size();
37 }
38 
39 // need to move thise to Dalitz fitter:
40 
41 int MINT::LeviCita(int a, int b){
42  std::vector<int> v(2);
43  v[0]=a; v[1]=b;
44  return MINT::LeviCita(v);
45 }
46 int MINT::LeviCita(int a, int b, int c){
47  std::vector<int> v(3);
48  v[0]=a; v[1]=b; v[2]=c;
49  return MINT::LeviCita(v);
50 }
51 int MINT::LeviCita(int a, int b, int c, int d){
52  std::vector<int> v(4);
53  v[0]=a; v[1]=b; v[2]=c; v[3]=d;
54  return MINT::LeviCita(v);
55 }
56 int MINT::LeviCita(int a, int b, int c, int d, int e){
57  std::vector<int> v(5);
58  v[0]=a; v[1]=b; v[2]=c; v[3]=d; v[4]=e;
59  return MINT::LeviCita(v);
60 }
61 
62 int MINT::LeviCita(const std::vector<int>& v){
63  if(v.size() <=1) return 1;
64 
65  std::vector<int> checkMultiples(v.size(), 0);
66  int p=1;
67  for(unsigned int i=0; i<v.size(); i++){
68  if(v[i] < 0 || v[i] >= (int) v.size()) return 0;
69  if(++(checkMultiples[i]) > 1) return 0;
70  }
71  for(unsigned int i=0; i<v.size()-1; i++){
72  for(unsigned int j=i+1; j < v.size(); j++){
73  if(v[i] > v[j]) p*= -1;
74  }
75  }
76  return p;
77 }
78 
79 //
int LeviCita(int a, int b)
Definition: Utils.cpp:41
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
std::ostream & operator<<(std::ostream &out, const TLorentzVector &v)
Definition: Utils.cpp:7
std::string anythingToString(const T &anything)
Definition: Utils.h:62
std::string stringtime(double dt)
Definition: Utils.cpp:14