Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CalibTracker/SiStripLorentzAngle/interface/LA_Filler_Fitter.h"
0002 #include "CalibTracker/SiStripCommon/interface/TTREE_FOREACH_ENTRY.hh"
0003 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0004 
0005 #include <cmath>
0006 
0007 void LA_Filler_Fitter::fill(TTree* tree, Book& book) const {
0008   TTREE_FOREACH_ENTRY(tree) {
0009     TFE_MAX(maxEvents_);
0010     TFE_PRINTSTATUS;
0011     std::vector<unsigned> PLEAF(tsostrackmulti, tree);
0012     std::vector<unsigned> PLEAF(clusterdetid, tree);
0013     std::vector<unsigned> PLEAF(clusterwidth, tree);
0014     std::vector<float> PLEAF(clustervariance, tree);
0015     std::vector<float> PLEAF(tsosdriftx, tree);
0016     std::vector<float> PLEAF(tsosdriftz, tree);
0017     std::vector<float> PLEAF(tsoslocaltheta, tree);
0018     std::vector<float> PLEAF(tsoslocalphi, tree);
0019     std::vector<float> PLEAF(tsosglobalZofunitlocalY, tree);
0020 
0021     const unsigned N(clusterdetid.size());
0022     std::vector<float> BdotY(N, 0);
0023     if (!ensembleBins_) {
0024       std::vector<float> PLEAF(tsosBdotY, tree);
0025       swap(BdotY, tsosBdotY);
0026     }
0027     std::vector<float> localy(N, 0);
0028     if (localYbin_) {
0029       std::vector<float> PLEAF(tsoslocaly, tree);
0030       swap(localy, tsoslocaly);
0031     }
0032     std::vector<unsigned> seedstrip(N, 0);
0033     if (stripsPerBin_) {
0034       std::vector<unsigned> PLEAF(clusterseedstrip, tree);
0035       swap(seedstrip, clusterseedstrip);
0036     }
0037 
0038     for (unsigned i = 0; i < N; i++) {
0039       const SiStripDetId detid(clusterdetid[i]);
0040       if (tsostrackmulti[i] != 1 ||
0041           (detid.subDetector() != SiStripDetId::TIB && detid.subDetector() != SiStripDetId::TOB))
0042         continue;
0043 
0044       const int sign = tsosglobalZofunitlocalY[i] < 0 ? -1 : 1;
0045       const float tthetaL = sign * tsosdriftx[i] / tsosdriftz[i];
0046       const float tthetaT = sign * tan(tsoslocaltheta[i]) * cos(tsoslocalphi[i]);
0047 
0048       fill_one_cluster(book,
0049                        granularity(detid, tthetaL, TFE_index, localy[i], seedstrip[i] % 128),
0050                        clusterwidth[i],
0051                        clustervariance[i],
0052                        tthetaL,
0053                        tthetaT,
0054                        fabs(BdotY[i]));
0055     }
0056   }
0057 }
0058 
0059 void LA_Filler_Fitter::fill_one_cluster(Book& book,
0060                                         const poly<std::string>& gran,
0061                                         const unsigned width,
0062                                         const float variance,
0063                                         const float tthetaL,
0064                                         const float tthetaT,
0065                                         const float BdotY) const {
0066   book.fill(tthetaL, gran + "_reconstruction", 360, -1.0, 1.0);
0067   book.fill(tthetaT - tthetaL, gran + allAndOne(width), 360, -1.0, 1.0);
0068   book.fill(tthetaT - tthetaL, variance, gran + varWidth(width), 360, -1.0, 1.0);
0069   if (methods_ & WIDTH)
0070     book.fill(tthetaT, width, gran + method(WIDTH), 81, -0.6, 0.6);
0071   if (!ensembleBins_) {
0072     book.fill(BdotY, gran + "_field", 101, 1, 5);
0073     book.fill(width, gran + "_width", 10, 0, 10);
0074   }
0075 }
0076 
0077 poly<std::string> LA_Filler_Fitter::allAndOne(const unsigned width) const {
0078   poly<std::string> a1("_all");
0079   if (width == 1)
0080     a1 *= "_w1";
0081   return a1;
0082 }
0083 
0084 poly<std::string> LA_Filler_Fitter::varWidth(const unsigned width) const {
0085   poly<std::string> vw;
0086   vw++;
0087   if (width == 2 && methods_ & (AVGV2 | RMSV2))
0088     vw *= method(AVGV2, false);
0089   if (width == 3 && methods_ & (AVGV3 | RMSV3))
0090     vw *= method(AVGV3, false);
0091   return vw;
0092 }
0093 
0094 poly<std::string> LA_Filler_Fitter::granularity(const SiStripDetId detid,
0095                                                 const float tthetaL,
0096                                                 const Long64_t TFE_index,
0097                                                 const float localy,
0098                                                 const unsigned apvstrip) const {
0099   poly<std::string> gran;
0100   gran += subdetLabel(detid);
0101   if (byLayer_)
0102     gran *= layerLabel(detid);
0103   if (byModule_)
0104     gran *= moduleLabel(detid);
0105   if (localYbin_)
0106     gran += (localy < 0 ? "_yM" : "_yP") + std::to_string(abs((int)(localy / localYbin_ + (localy < 0 ? -1 : 0))));
0107   if (stripsPerBin_)
0108     gran += "_strip" +
0109             std::to_string(
0110                 (unsigned)((0.5 + ((apvstrip / 64) ? (127 - apvstrip) : apvstrip) / stripsPerBin_) * stripsPerBin_));
0111   if (ensembleBins_) {
0112     gran +=
0113         "_ensembleBin" + std::to_string((int)(ensembleBins_ * (tthetaL - ensembleLow_) / (ensembleUp_ - ensembleLow_)));
0114     gran += "";
0115     if (ensembleSize_)
0116       gran *= "_sample" + std::to_string(TFE_index % ensembleSize_);
0117   }
0118   return gran;
0119 }
0120 
0121 std::string LA_Filler_Fitter::subdetLabel(const SiStripDetId detid) {
0122   return detid.subDetector() == SiStripDetId::TOB ? "TOB" : "TIB";
0123 }
0124 std::string LA_Filler_Fitter::moduleLabel(const SiStripDetId detid) {
0125   return subdetLabel(detid) + "_module" + std::to_string(detid());
0126 }
0127 std::string LA_Filler_Fitter::layerLabel(const SiStripDetId detid) const {
0128   const bool isTIB = detid.subdetId() == StripSubdetector::TIB;
0129   unsigned layer = isTIB ? tTopo_->tibLayer(detid) : tTopo_->tobLayer(detid);
0130   bool stereo = isTIB ? tTopo_->tibStereo(detid) : tTopo_->tobStereo(detid);
0131 
0132   return subdetLabel(detid) + "_layer" + std::to_string(layer) + (stereo ? "s" : "a");
0133 }