Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:57

0001 #ifndef CalibTracker_SiStripLorentzAngle_SiStripLorentzAngleCalibrationHelper_h
0002 #define CalibTracker_SiStripLorentzAngle_SiStripLorentzAngleCalibrationHelper_h
0003 
0004 // user includes
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 // system includes
0011 #include <string>
0012 
0013 // for ROOT
0014 #include "TString.h"
0015 #include "TFitResult.h"
0016 #include "TF1.h"
0017 
0018 namespace siStripLACalibration {
0019 
0020   /**
0021    * @brief Generates a module location type string based on the detector ID and topology information.
0022    *
0023    * Given a module ID and the corresponding TrackerTopology, this function constructs a module
0024    * location type string in the format "subdet_LlayerType", where subdet is the subdetector name (TIB or TOB),
0025    * layer is the layer number, and Type is 'a' for axial or 's' for stereo.
0026    *
0027    * @param mod The module ID.
0028    * @param tTopo Pointer to the TrackerTopology object providing information about the detector.
0029    * @return A module location type string.
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    * @brief Process a string in the format "subdet_LlayerType" and compute values.
0055    *
0056    * This function takes a string in the format "subdet_LlayerType" and parses it to extract
0057    * information about the layer and type. It then computes and returns a std::pair<int, int> where
0058    * the first element is 1 if type is "a" and 2 if type is "s", 
0059    * and the second element is the processed value of layer if subdet is "TIB" or layer + 4 if subdet is "TOB".
0060    *
0061    * @param locType The input string in the format "subdet_LlayerType".
0062    * @return A std::pair<int, int> containing the processed values. If the input format is invalid,
0063    *         the pair (-1, -1) is returned.
0064    *
0065    * @example
0066    *   std::string d_l_t = "TIB_L3a";
0067    *   std::pair<int, int> result = processString(d_l_t);
0068    *   // The result will contain processed values based on the input.
0069    */
0070 
0071   //_____________________________________________________________________
0072   inline std::pair<int, int> locationTypeIndex(const std::string& locType) {
0073     // Assuming input format is "subdet_LlayerType"
0074     // Example: "TIB_L3a"
0075 
0076     std::string subdet, layerType;
0077     int layer;
0078 
0079     // Parse the input string
0080     if (sscanf(locType.c_str(), "%3s_L%d%1[a-zA-Z]", &subdet[0], &layer, &layerType[0]) == 3) {
0081       // Process subdet and layerType to compute the values
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       // Handle invalid input format
0091       // FIXME use MessageLogger
0092       std::cerr << "Invalid input format: " << locType << std::endl;
0093       return std::make_pair(-1, -1);  // Indicates error
0094     }
0095   }
0096 
0097   // SiStripLatency::singleReadOutMode() returns
0098   // 1: all in peak, 0: all in deco, -1: mixed state
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);  // +2 to include one decimal place
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";  // peak mode
0117         case k_DeconvolutionMode:
0118           return "DECO";  // deco mode
0119         default:
0120           return "UNDEF";  // undefined
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     //TF1::RejectPoint();  // Reject points outside the fit range
0137     return value;
0138   }
0139 }  // namespace siStripLACalibration
0140 #endif