Belle II Software  release-08-01-10
SVDStripNoiseMap.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #include <svd/online/SVDStripNoiseMap.h>
10 #include <framework/logging/Logger.h>
11 
12 #include <cstdlib>
13 #include <fstream>
14 
15 using namespace Belle2;
16 using namespace std;
17 
19  m_onl2offl_map_ptr(onl2offl_map_ptr)
20 {
21 
22  memset(m_pedestalMap, 0, sizeof(m_pedestalMap));
23  memset(m_noiseMap, 0, sizeof(m_noiseMap));
24  memset(m_thresholdMap, 0, sizeof(m_thresholdMap));
25  memset(m_goodStripMap, 0, sizeof(m_goodStripMap));
26 
27 }
28 
30  const string& noisefilename):
31  m_onl2offl_map_ptr(onl2offl_map_ptr)
32 {
33  this->initializeMap(noisefilename);
34 }
35 
36 int SVDStripNoiseMap::initializeMap(const string& noisefilename)
37 {
38 
39  B2INFO("initializeMap()");
40 
41  if (noisefilename == "") {
42  B2INFO("CAUTION:: Pedestal and noise values are not changed, because noise file is not specified.");
43  return 0;
44  }
45 
46  if (m_onl2offl_map_ptr == nullptr) {
47  B2ERROR("SVDOnlineToOfflineMap is not assigned correctly.");
48  return -1;
49  }
50 
51  memset(m_pedestalMap, 0, sizeof(m_pedestalMap));
52  memset(m_noiseMap, 0, sizeof(m_noiseMap));
53  memset(m_thresholdMap, 0, sizeof(m_thresholdMap));
54  memset(m_goodStripMap, 0, sizeof(m_goodStripMap));
55 
56  ifstream noisefile(noisefilename.c_str());
57  if (!noisefile.is_open()) {
58  B2ERROR("Cannot open noise file: " << noisefilename);
59  return -1;
60  }
61 
62  int module, apv, strip, fadc, fadc_ch, good;
63  float pedestal, gaus_noise, noise, rms, cmc;
64 
65  short file_section = 0;
66  string line;
67  while (getline(noisefile, line)) {
68 
69  if (line.substr(0, 1) == "#") continue;
70 
71  size_t space_pos;
72  while ((space_pos = line.find(" ")) != string::npos) {
73  line.erase(space_pos, 1);
74  }
75 
76  if (line.empty()) continue;
77 
78  //B2INFO(line);
79 
80  if (line.substr(0, 1) == "[" && line.substr(line.size() - 1, 1) == "]") {
81  if (line == "[noi]") file_section = 1;
82  else if (line == "[fit]") file_section = 2;
83  else file_section = 3;
84  }//if(line.substr(0,1)=="["&&line.substr(line.size()-1,1)=="]"){
85  else if (file_section == 1) {
86  sscanf(line.c_str(), "str=%d,%d,%d,%d,%d,%d,%f,%f,%f,%f,%f",
87  &module, &apv, &strip, &fadc, &fadc_ch, &good,
88  &pedestal, &gaus_noise, &noise, &rms, &cmc);
89 
90  //**************************************************
91  //*** This fadc_id definition is workround solution
92  //*** for DESY beam data analysis.
93  //*** It must be removed in future. (Katsuro)
94  //**************************************************
95  short fadc_id = 0;
96  if (fadc == 0) fadc_id = 1; //0x01 (p-side)
97  else if (fadc == 1) fadc_id = 129; //0x81 (n-side)
98  else fadc_id = 1; //0x01
99  //**************************************************
100 
101  //*** module value starts from 1 ***//
102  unsigned short apv_base = 0;
103  switch (module) {
104  case 1 : apv_base = 0; break;
105  case 2 : apv_base = 6; break;
106  case 3 : apv_base = 24; break;
107  case 4 : apv_base = 30; break;
108  case 8 : apv_base = 0; break;
109  case 9 : apv_base = 6; break;
110  case 10 : apv_base = 24; break;
111  case 11 : apv_base = 30; break;
112  default : apv_base = 0; break;
113  }
114  unsigned short apv_id = apv_base + apv;
115  VxdID vxd_id =
116  (m_onl2offl_map_ptr->getSensorInfo(fadc_id, apv_id)).m_sensorID;
117  //bool is_u = (((fadc_id>>7)&0x1)==0x0) ? true : false;
118  bool is_u =
119  (m_onl2offl_map_ptr->getSensorInfo(fadc_id, apv_id)).m_uSide;
120  short svd_sensor_id = SVDPar::getSVDSensorID(vxd_id, is_u);
121  if (svd_sensor_id < 0) {
122  B2ERROR("Invalid SVDSensorID: " << LogVar("SVDSensorID", svd_sensor_id) << " (FADC ID: " << fadc_id << ", APV: " << apv << ")");
123  return -1;
124  }
125 
126  B2INFO("Sensor ID: " << svd_sensor_id << " Module: " << module << " VxdID: " << vxd_id.getID() << " (FADC ID: " << fadc_id <<
127  ", APV: " << apv << ", STRIP: " << strip << ") " << ((good == 0) ? "BAD" : " ") << " ped: " << pedestal << ", noi: " << noise);
128 
129  m_pedestalMap [svd_sensor_id][strip] = pedestal;
130  m_noiseMap [svd_sensor_id][strip] = gaus_noise;
131  m_thresholdMap[svd_sensor_id][strip] = 5 * gaus_noise;
132  m_goodStripMap[svd_sensor_id][strip] = (good == 0) ? false : true;
133 
134  }//else if(file_section==1){
135 
136  }//while(getline(noisefile,line)){
137 
138  return 0;
139 }
140 
141 float SVDStripNoiseMap::getPedestal(VxdID id, bool is_u, short strip)
142 {
143 
144  if (strip < 0 || SVDPar::maxStrip <= strip) {
145  B2ERROR("Invalid strip number: " << strip);
146  return -9999.0;
147  }
148 
149  short sensor_id = SVDPar::getSVDSensorID(id, is_u);
150  if (sensor_id < 0 || SVDPar::nSensorID <= sensor_id) {
151  B2ERROR("Invalid SVDSensorID: " << LogVar("SVDSensorID", sensor_id));
152  return -9999.0;
153  }
154 
155  return m_pedestalMap[sensor_id][strip];
156 }
157 
158 float SVDStripNoiseMap::getNoise(VxdID id, bool is_u, short strip)
159 {
160 
161  if (strip < 0 || SVDPar::maxStrip <= strip) {
162  B2ERROR("Invalid strip number: " << LogVar("strip number", strip));
163  return -9999.0;
164  }
165 
166  short sensor_id = SVDPar::getSVDSensorID(id, is_u);
167  if (sensor_id < 0 || SVDPar::nSensorID <= sensor_id) {
168  B2ERROR("Invalid SVDSensorID: " << LogVar("SVDSensorID", sensor_id));
169  return -9999.0;
170  }
171 
172  return m_noiseMap[sensor_id][strip];
173 }
174 
175 float SVDStripNoiseMap::getThreshold(VxdID id, bool is_u, short strip)
176 {
177 
178  if (strip < 0 || SVDPar::maxStrip <= strip) {
179  B2ERROR("Invalid strip number: " << LogVar("strip number", strip));
180  return -9999.0;
181  }
182 
183  short sensor_id = SVDPar::getSVDSensorID(id, is_u);
184  if (sensor_id < 0 || SVDPar::nSensorID <= sensor_id) {
185  B2ERROR("Invalid SVDSensorID: " << LogVar("SVDSensorID", sensor_id));
186  return -9999.0;
187  }
188 
189  return m_thresholdMap[sensor_id][strip];
190 }
191 
192 bool SVDStripNoiseMap::isGood(VxdID id, bool is_u, short strip)
193 {
194 
195  if (strip < 0 || SVDPar::maxStrip <= strip) {
196  B2ERROR("Invalid strip number: " << LogVar("strip number", strip));
197  return false;
198  }
199 
200  short sensor_id = SVDPar::getSVDSensorID(id, is_u);
201  if (sensor_id < 0 || SVDPar::nSensorID <= sensor_id) {
202  B2ERROR("Invalid SVDSensorID: " << LogVar("SVDSensorID", sensor_id));
203  return false;
204  }
205 
206  return m_goodStripMap[sensor_id][strip];
207 }
This class implements the methods to map raw SVD hits to basf2 SVD hits.
const SensorInfo & getSensorInfo(unsigned char FADC, unsigned char APV25)
Get SensorInfo for a given FADC/APV combination.
SVDStripNoiseMap(SVDOnlineToOfflineMap *onl2offl_map_ptr=nullptr)
Constructor.
bool isGood(VxdID id, bool is_u, short strip)
Check whether the strip is available or not.
float getThreshold(VxdID id, bool is_u, short strip)
Get pedestal, noise, and threshold values.
float getPedestal(VxdID id, bool is_u, short strip)
Get pedestal, noise, and threshold values.
int initializeMap(const std::string &noisefilename="")
Initialize maps with input noisefile.
SVDOnlineToOfflineMap * m_onl2offl_map_ptr
Pointer to SVDOnlineToOfflineMap.
bool m_goodStripMap[SVDPar::nSensorID][SVDPar::maxStrip]
Good strip map.
float m_pedestalMap[SVDPar::nSensorID][SVDPar::maxStrip]
Pedestal map for all strips in ladders.
float m_thresholdMap[SVDPar::nSensorID][SVDPar::maxStrip]
threshold map for all strips in ladders.
float m_noiseMap[SVDPar::nSensorID][SVDPar::maxStrip]
noise map for all strips in ladders.
float getNoise(VxdID id, bool is_u, short strip)
Get pedestal, noise, and threshold values.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getID() const
Get the unique id.
Definition: VxdID.h:94
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.