CMS 3D CMS Logo

SiStripLorentzAngleCalibrationHelpers.h
Go to the documentation of this file.
1 #ifndef CalibTracker_SiStripLorentzAngle_SiStripLorentzAngleCalibrationHelper_h
2 #define CalibTracker_SiStripLorentzAngle_SiStripLorentzAngleCalibrationHelper_h
3 
4 // user includes
9 
10 // system includes
11 #include <string>
12 
13 // for ROOT
14 #include "TString.h"
15 #include "TFitResult.h"
16 #include "TF1.h"
17 
19 
32  //_____________________________________________________________________
33  inline std::string moduleLocationType(const uint32_t& mod, const TrackerTopology* tTopo) {
34  const SiStripDetId detid(mod);
35  std::string subdet = "";
36  unsigned int layer = 0;
37  if (detid.subDetector() == SiStripDetId::TIB) {
38  subdet = "TIB";
39  layer = tTopo->layer(mod);
40  } else if (detid.subDetector() == SiStripDetId::TOB) {
41  subdet = "TOB";
42  layer = tTopo->layer(mod);
43  }
44 
45  if (layer == 0)
46  return subdet;
47 
48  std::string type = (detid.stereo() ? "s" : "a");
49  std::string d_l_t = Form("%s_L%d%s", subdet.c_str(), layer, type.c_str());
50  return d_l_t;
51  }
52 
71  //_____________________________________________________________________
72  inline std::pair<int, int> locationTypeIndex(const std::string& locType) {
73  // Assuming input format is "subdet_LlayerType"
74  // Example: "TIB_L3a"
75 
76  std::string subdet, layerType;
77  int layer;
78 
79  // Parse the input string
80  if (sscanf(locType.c_str(), "%3s_L%d%1[a-zA-Z]", &subdet[0], &layer, &layerType[0]) == 3) {
81  // Process subdet and layerType to compute the values
82  LogTrace("locationTypeIndex") << "subdet " << &subdet[0] << ") layer " << layer << " type " << layerType[0]
83  << std::endl;
84 
85  int firstElement = (layerType[0] == 'a') ? 1 : 2;
86  int secondElement = (std::string(&subdet[0]) == "TIB") ? layer : (layer + 4);
87 
88  return std::make_pair(firstElement, secondElement);
89  } else {
90  // Handle invalid input format
91  // FIXME use MessageLogger
92  std::cerr << "Invalid input format: " << locType << std::endl;
93  return std::make_pair(-1, -1); // Indicates error
94  }
95  }
96 
97  // SiStripLatency::singleReadOutMode() returns
98  // 1: all in peak, 0: all in deco, -1: mixed state
99  enum { k_DeconvolutionMode = 0, k_PeakMode = 1 };
100 
101  //_____________________________________________________________________
102  inline const std::string fieldAsString(const float& inputField) {
103  std::string theMagFieldStr = std::to_string(inputField);
104  size_t dotPosition = theMagFieldStr.find('.');
105  if (dotPosition != std::string::npos) {
106  theMagFieldStr = theMagFieldStr.substr(0, dotPosition + 2); // +2 to include one decimal place
107  }
108  return theMagFieldStr;
109  }
110 
111  //_____________________________________________________________________
113  if (latency) {
114  switch (latency->singleReadOutMode()) {
115  case k_PeakMode:
116  return "PEAK"; // peak mode
117  case k_DeconvolutionMode:
118  return "DECO"; // deco mode
119  default:
120  return "UNDEF"; // undefined
121  }
122  } else {
123  return "UNDEF";
124  }
125  }
126 
127  //_____________________________________________________________________
128  inline double fitFunction(double* x, double* par) {
129  double a = par[0];
130  double thetaL = par[1];
131  double b = par[2];
132 
133  double tanThetaL = std::tan(thetaL);
134  double value = a * std::abs(std::tan(x[0]) - tanThetaL) + b;
135 
136  //TF1::RejectPoint(); // Reject points outside the fit range
137  return value;
138  }
139 } // namespace siStripLACalibration
140 #endif
double fitFunction(double *x, double *par)
SubDetector subDetector() const
Definition: SiStripDetId.h:105
std::pair< int, int > locationTypeIndex(const std::string &locType)
static std::string to_string(const XMLCh *ch)
unsigned int layer(const DetId &id) const
#define LogTrace(id)
uint32_t stereo() const
Definition: SiStripDetId.h:168
const std::string fieldAsString(const float &inputField)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
Definition: value.py:1
const std::string apvModeAsString(const SiStripLatency *latency)
static constexpr auto TOB
Definition: SiStripDetId.h:39
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
double b
Definition: hdecay.h:120
static constexpr auto TIB
Definition: SiStripDetId.h:37
double a
Definition: hdecay.h:121
float x
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
std::string moduleLocationType(const uint32_t &mod, const TrackerTopology *tTopo)
Generates a module location type string based on the detector ID and topology information.