Belle II Software  release-05-01-25
CDCBadWires.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: CDC group *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <map>
13 #include <algorithm>
14 #include <iostream>
15 #include <fstream>
16 #include <iomanip>
17 #include <TObject.h>
18 #include <cdc/dataobjects/WireID.h>
19 
20 namespace Belle2 {
29  class CDCBadWires: public TObject {
30  public:
31 
35  CDCBadWires() {}
36 
42  void setWire(const WireID& wid, double eff = 0)
43  {
44  m_wires.insert(std::pair(wid.getEWire(), eff));
45  }
46 
53  void setWire(unsigned short iCLayer, unsigned short iWire, double eff = 0)
54  {
55  m_wires.insert(std::pair(WireID(iCLayer, iWire).getEWire(), eff));
56  }
57 
61  unsigned short getEntries() const
62  {
63  return m_wires.size();
64  }
65 
69  std::map<unsigned short, float> getWires() const
70  {
71  return m_wires;
72  }
73 
79  bool isBadWire(const WireID& wid) const
80  {
81  std::map<unsigned short, float>::const_iterator it = m_wires.find(wid.getEWire());
82  if (it != m_wires.end() && it->second == 0.) {
83  return true;
84  } else {
85  return false;
86  }
87  }
88 
94  bool isDeadWire(const WireID& wid, double& eff) const
95  {
96  std::map<unsigned short, float>::const_iterator it = m_wires.find(wid.getEWire());
97  if (it != m_wires.end() && 0. <= it->second && it->second < 1.) {
98  eff = it->second;
99  return true;
100  } else {
101  return false;
102  }
103  }
104 
110  bool isHotWire(const WireID& wid) const
111  {
112  std::map<unsigned short, float>::const_iterator it = m_wires.find(wid.getEWire());
113  if (it != m_wires.end() && it->second > 1.) {
114  return true;
115  } else {
116  return false;
117  }
118  }
119 
123  void dump() const
124  {
125  std::cout << " " << std::endl;
126  std::cout << "Bad wire list" << std::endl;
127  std::cout << "#entries= " << m_wires.size() << std::endl;
128  std::cout << "in order of ICLayer and IWire and EWire" << std::endl;
129 
130  for (auto const ent : m_wires) {
131  std::cout << WireID(ent.first).getICLayer() << " " << WireID(ent.first).getIWire() << " " << ent.second << std::endl;
132  }
133  }
134 
138  void outputToFile(std::string fileName) const
139  {
140  std::ofstream fout(fileName);
141 
142  if (fout.bad()) {
143  B2ERROR("Specified output file could not be opened!");
144  } else {
145  for (auto const ent : m_wires) {
146  fout << std::setw(2) << std::right << WireID(ent.first).getICLayer() << " " << std::setw(3) << WireID(
147  ent.first).getIWire() << " " << ent.second << std::endl;
148  }
149  fout.close();
150  }
151  }
152 
153  private:
154  std::map<unsigned short, float> m_wires;
156  ClassDef(CDCBadWires, 2);
157  };
158 
160 } // end namespace Belle2
Belle2::CDCBadWires::CDCBadWires
CDCBadWires()
Default constructor.
Definition: CDCBadWires.h:43
Belle2::WireID
Class to identify a wire inside the CDC.
Definition: WireID.h:44
Belle2::CDCBadWires::getEntries
unsigned short getEntries() const
Get the no.
Definition: CDCBadWires.h:69
Belle2::CDCBadWires::m_wires
std::map< unsigned short, float > m_wires
badwire list
Definition: CDCBadWires.h:162
Belle2::WireID::getEWire
unsigned short getEWire() const
Getter for encoded wire number.
Definition: WireID.h:164
Belle2::CDCBadWires::dump
void dump() const
Print out contents.
Definition: CDCBadWires.h:131
Belle2::CDCBadWires::getWires
std::map< unsigned short, float > getWires() const
Get the whole list.
Definition: CDCBadWires.h:77
Belle2::CDCBadWires::isHotWire
bool isHotWire(const WireID &wid) const
Check if the wire is hot/noisy.
Definition: CDCBadWires.h:118
Belle2::CDCBadWires::ClassDef
ClassDef(CDCBadWires, 2)
ClassDef.
Belle2::CDCBadWires::outputToFile
void outputToFile(std::string fileName) const
Output the contents in text file format.
Definition: CDCBadWires.h:146
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCBadWires::setWire
void setWire(const WireID &wid, double eff=0)
Set the wire in the list.
Definition: CDCBadWires.h:50
Belle2::CDCBadWires::isDeadWire
bool isDeadWire(const WireID &wid, double &eff) const
Check if dead wire.
Definition: CDCBadWires.h:102
Belle2::CDCBadWires::isBadWire
bool isBadWire(const WireID &wid) const
Check if the wire is totally-dead (eff=0); to be replaced by isDeadWire() in future....
Definition: CDCBadWires.h:87
Belle2::WireID::getIWire
unsigned short getIWire() const
Getter for wire within the layer.
Definition: WireID.h:155
Belle2::WireID::getICLayer
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition: WireID.cc:26