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