File indexing completed on 2024-04-06 11:59:57
0001 #ifndef CalibTracker_SiStripLorentzAngle_SiStripLorentzAngleCalibrationHelper_h
0002 #define CalibTracker_SiStripLorentzAngle_SiStripLorentzAngleCalibrationHelper_h
0003
0004
0005 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
0006 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0007 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009
0010
0011 #include <string>
0012
0013
0014 #include "TString.h"
0015 #include "TFitResult.h"
0016 #include "TF1.h"
0017
0018 namespace siStripLACalibration {
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 inline std::string moduleLocationType(const uint32_t& mod, const TrackerTopology* tTopo) {
0034 const SiStripDetId detid(mod);
0035 std::string subdet = "";
0036 unsigned int layer = 0;
0037 if (detid.subDetector() == SiStripDetId::TIB) {
0038 subdet = "TIB";
0039 layer = tTopo->layer(mod);
0040 } else if (detid.subDetector() == SiStripDetId::TOB) {
0041 subdet = "TOB";
0042 layer = tTopo->layer(mod);
0043 }
0044
0045 if (layer == 0)
0046 return subdet;
0047
0048 std::string type = (detid.stereo() ? "s" : "a");
0049 std::string d_l_t = Form("%s_L%d%s", subdet.c_str(), layer, type.c_str());
0050 return d_l_t;
0051 }
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072 inline std::pair<int, int> locationTypeIndex(const std::string& locType) {
0073
0074
0075
0076 std::string subdet, layerType;
0077 int layer;
0078
0079
0080 if (sscanf(locType.c_str(), "%3s_L%d%1[a-zA-Z]", &subdet[0], &layer, &layerType[0]) == 3) {
0081
0082 LogTrace("locationTypeIndex") << "subdet " << &subdet[0] << ") layer " << layer << " type " << layerType[0]
0083 << std::endl;
0084
0085 int firstElement = (layerType[0] == 'a') ? 1 : 2;
0086 int secondElement = (std::string(&subdet[0]) == "TIB") ? layer : (layer + 4);
0087
0088 return std::make_pair(firstElement, secondElement);
0089 } else {
0090
0091
0092 std::cerr << "Invalid input format: " << locType << std::endl;
0093 return std::make_pair(-1, -1);
0094 }
0095 }
0096
0097
0098
0099 enum { k_DeconvolutionMode = 0, k_PeakMode = 1 };
0100
0101
0102 inline const std::string fieldAsString(const float& inputField) {
0103 std::string theMagFieldStr = std::to_string(inputField);
0104 size_t dotPosition = theMagFieldStr.find('.');
0105 if (dotPosition != std::string::npos) {
0106 theMagFieldStr = theMagFieldStr.substr(0, dotPosition + 2);
0107 }
0108 return theMagFieldStr;
0109 }
0110
0111
0112 inline const std::string apvModeAsString(const SiStripLatency* latency) {
0113 if (latency) {
0114 switch (latency->singleReadOutMode()) {
0115 case k_PeakMode:
0116 return "PEAK";
0117 case k_DeconvolutionMode:
0118 return "DECO";
0119 default:
0120 return "UNDEF";
0121 }
0122 } else {
0123 return "UNDEF";
0124 }
0125 }
0126
0127
0128 inline double fitFunction(double* x, double* par) {
0129 double a = par[0];
0130 double thetaL = par[1];
0131 double b = par[2];
0132
0133 double tanThetaL = std::tan(thetaL);
0134 double value = a * std::abs(std::tan(x[0]) - tanThetaL) + b;
0135
0136
0137 return value;
0138 }
0139 }
0140 #endif