ATLAS Offline Software
Contour.h
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
12 #ifndef CONTOUR_H
13 #define CONTOUR_H
14 
15 #include <iostream>
16 #include <vector>
17 #include <cstdlib>
18 #include <cstdio>
19 
21 
22 
23 template<typename T>
24 class Contour : public std::vector< std::pair<double, T*> > {
25 
26  typedef std::pair<double, T*> value_type;
27 
28 public:
29 
30  Contour(const std::string& s) : mname(s), mdir(s) { }
31 
32  virtual ~Contour() {
33  for ( unsigned i=this->size()-1 ; i-- ; ) if ( this->at(i).second ) delete this->at(i).second;
34  }
35 
36  void ranges( const std::vector<double>& d, T* t ) {
37  if ( d.empty() ) return;
38  ranges( &d[0], d.size(), t );
39  }
40 
41  void ranges( const double* d, unsigned N, T* t ) {
42  mdir.push();
43  for ( unsigned i=1 ; i<N ; i++ ) {
44  this->push_back( value_type( d[i-1], new T(*t) ) );
45  }
46  this->push_back( value_type( d[N-1], 0 ) );
47  mdir.pop();
48  }
49 
50  T* find( double d ) {
51  if ( this->empty() ) return 0;
52  for ( unsigned i=this->size()-1 ; i-- ; ) {
53  if ( d>=this->at(i).first && d<this->at(i+1).first ) return this->at(i).second;
54  }
55  return 0;
56  }
57 
58  std::string name() const { return mname; }
59 
60  void Write(const std::string& s="") {
61  mdir.push();
62  for ( unsigned i=this->size()-1 ; i-- ; ) {
63  if ( this->at(i).second ) {
64  char _name[64];
65  if ( s=="" ) std::sprintf( _name, "%s_%d", mname.c_str(), i-1 );
66  else std::sprintf( _name, "%s_%d", s.c_str(), i-1 );
67  this->at(i).second->Bayes()->Write(_name);
68  }
69  }
70  mdir.pop();
71  }
72 
73  TIDDirectory* dir() { return &mdir; }
74 
75 private:
76 
77  std::string mname;
78 
80 
81 };
82 
83 template<typename T>
84 inline std::ostream& operator<<( std::ostream& s, const Contour<T>& _c ) {
85  s << "Contour : " << _c.name() << "\n";
86  for ( unsigned i=0 ; i<_c.size() ; i++ ) s << "\t d " << _c[i].first << "\n";
87  return s;
88 }
89 
90 
91 #endif // CONTOUR_H
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
operator<<
std::ostream & operator<<(std::ostream &s, const Contour< T > &_c)
Definition: Contour.h:84
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Contour::Contour
Contour(const std::string &s)
Definition: Contour.h:30
TIDDirectory::pop
void pop()
Definition: TIDDirectory.h:79
Contour::mdir
TIDDirectory mdir
Definition: Contour.h:79
hist_file_dump.d
d
Definition: hist_file_dump.py:137
Contour::~Contour
virtual ~Contour()
Definition: Contour.h:32
Contour
Definition: Contour.h:24
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
TIDDirectory
Definition: TIDDirectory.h:25
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
TIDDirectory.h
class to keep a directory for each object in a root sort of way, but needed to keep the root objects ...
lumiFormat.i
int i
Definition: lumiFormat.py:85
Contour::mname
std::string mname
Definition: Contour.h:77
Contour::ranges
void ranges(const double *d, unsigned N, T *t)
Definition: Contour.h:41
Contour::value_type
std::pair< double, T * > value_type
Definition: Contour.h:26
Contour::find
T * find(double d)
Definition: Contour.h:50
TIDDirectory::push
void push()
Definition: TIDDirectory.h:78
Contour::Write
void Write(const std::string &s="")
Definition: Contour.h:60
DeMoScan.first
bool first
Definition: DeMoScan.py:536
Contour::ranges
void ranges(const std::vector< double > &d, T *t)
Definition: Contour.h:36
Contour::name
std::string name() const
Definition: Contour.h:58
Contour::dir
TIDDirectory * dir()
Definition: Contour.h:73
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35