ATLAS Offline Software
Loading...
Searching...
No Matches
StorePIDinfo.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
6#include "GaudiKernel/MsgStream.h"
7#include <iostream>
8#include <utility>
9
10
11StorePIDinfo::StorePIDinfo(int nbins, float min, float max, const std::vector<float>& values){
12 update (nbins, min, max, values);
13}
14
15
16void StorePIDinfo::update( int nbins, float min, float max, const std::vector<float>& values){
17 m_nbins = nbins ;
18 m_min = min ;
19 m_max = max ;
20 if (values.size()!=m_nbins){
21 MsgStream log(Athena::getMessageSvc(),"StorePIDinfo");
22 log << MSG::ERROR << " Different Values of n_bins and vector size!!!" << endmsg;
23 }
24 m_values.clear();
25 for (float value : values){
26 m_values.push_back( value);
27 }
28}
29
30// THIS HAS TO BE CALLED in order!!!
31void StorePIDinfo::push_back( float value ){
32 // Just to read the DB
33 if (m_nbins==0) {
34 m_nbins = int(value) ;
35 m_min = -9999.9 ;
36 m_max = 10000000*2 ;
37 m_values.clear() ;
38 }
39 else if (m_min < -9999) m_min = value ;
40 else if (m_max > 10000000) m_max = value ;
41 else m_values.push_back(value);
42}
43
44StatusCode StorePIDinfo::check( int gas, int detpart) const{
45 MsgStream log(Athena::getMessageSvc(),"StorePIDinfo");
46 if ( m_nbins == 0)
47 {
48
49 log << MSG::ERROR << " StorePIDinfo: No bins in the DB!! Gas: " << gas << " detpart " << detpart << endmsg;
50 return StatusCode::FAILURE;
51 }
52 else if ( m_nbins != m_values.size() )
53 {
54 log << MSG::ERROR << " Different number of PID numbers!!!!! " << endmsg;
55 return StatusCode::FAILURE;
56 }
57 else if ( (m_max < m_min) || (m_max == m_min) )
58 {
59 log << MSG::ERROR << " Max is smaller or equal than min!!!" << endmsg;
60 return StatusCode::FAILURE;
61 }
62 return StatusCode::SUCCESS;
63}
64
65int StorePIDinfo::GetBin(float input) const
66{
67 if (input < m_min){
68 return 0;
69 }
70 else if (input >= m_max){
71 return m_nbins - 1;
72 }
73 float dr = (m_max - m_min) / m_nbins;
74 unsigned int bin = int((input - m_min) / dr);
75 return bin;
76}
#define endmsg
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
StorePIDinfo()=default
int GetBin(float input) const
unsigned int m_nbins
void push_back(float value)
void update(int nbins, float min, float max, const std::vector< float > &values)
StatusCode check(int gas, int detpart) const
std::vector< float > m_values
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)