Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-01 22:52:19

0001 #include "FWCore/Framework/interface/ModuleFactory.h"
0002 #include "FWCore/Framework/interface/ESProducer.h"
0003 
0004 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
0005 
0006 #include "RecoTracker/MkFit/interface/MkFitGeometry.h"
0007 
0008 // mkFit includes
0009 #include "RecoTracker/MkFitCore/interface/Track.h"
0010 #include "RecoTracker/MkFitCore/interface/TrackerInfo.h"
0011 #include "RecoTracker/MkFitCore/interface/HitStructures.h"
0012 #include "RecoTracker/MkFitCore/interface/IterationConfig.h"
0013 
0014 namespace {
0015   using namespace mkfit;
0016 
0017   [[maybe_unused]] void partitionSeeds0(const TrackerInfo &trk_info,
0018                                         const TrackVec &in_seeds,
0019                                         const EventOfHits &eoh,
0020                                         IterationSeedPartition &part) {
0021     const size_t size = in_seeds.size();
0022 
0023     for (size_t i = 0; i < size; ++i) {
0024       const Track &S = in_seeds[i];
0025 
0026       const bool z_dir_pos = S.pz() > 0;
0027 
0028       const auto &hot = S.getLastHitOnTrack();
0029       const float eta = eoh[hot.layer].refHit(hot.index).eta();
0030 
0031       // Region to be defined by propagation / intersection tests
0032       TrackerInfo::EtaRegion reg;
0033 
0034       const LayerInfo &outer_brl = trk_info.outer_barrel_layer();
0035 
0036       // Define first (mkFit) layer IDs for each strip subdetector.
0037       constexpr int tib1_id = 4;
0038       constexpr int tob1_id = 10;
0039       constexpr int tecp1_id = 27;
0040       constexpr int tecn1_id = 54;
0041 
0042       const LayerInfo &tib1 = trk_info.layer(tib1_id);
0043       const LayerInfo &tob1 = trk_info.layer(tob1_id);
0044 
0045       const LayerInfo &tecp1 = trk_info.layer(tecp1_id);
0046       const LayerInfo &tecn1 = trk_info.layer(tecn1_id);
0047 
0048       const LayerInfo &tec_first = z_dir_pos ? tecp1 : tecn1;
0049 
0050       const float maxR = S.maxReachRadius();
0051       float z_at_maxr;
0052 
0053       bool can_reach_outer_brl = S.canReachRadius(outer_brl.rout());
0054       float z_at_outer_brl;
0055       bool misses_first_tec;
0056       if (can_reach_outer_brl) {
0057         z_at_outer_brl = S.zAtR(outer_brl.rout());
0058         if (z_dir_pos)
0059           misses_first_tec = z_at_outer_brl < tec_first.zmin();
0060         else
0061           misses_first_tec = z_at_outer_brl > tec_first.zmax();
0062       } else {
0063         z_at_maxr = S.zAtR(maxR);
0064         if (z_dir_pos)
0065           misses_first_tec = z_at_maxr < tec_first.zmin();
0066         else
0067           misses_first_tec = z_at_maxr > tec_first.zmax();
0068       }
0069 
0070       if (misses_first_tec) {
0071         reg = TrackerInfo::Reg_Barrel;
0072       } else {
0073         if ((S.canReachRadius(tib1.rin()) && tib1.is_within_z_limits(S.zAtR(tib1.rin()))) ||
0074             (S.canReachRadius(tob1.rin()) && tob1.is_within_z_limits(S.zAtR(tob1.rin())))) {
0075           reg = z_dir_pos ? TrackerInfo::Reg_Transition_Pos : TrackerInfo::Reg_Transition_Neg;
0076         } else {
0077           reg = z_dir_pos ? TrackerInfo::Reg_Endcap_Pos : TrackerInfo::Reg_Endcap_Neg;
0078         }
0079       }
0080 
0081       part.m_region[i] = reg;
0082       if (part.m_phi_eta_foo)
0083         part.m_phi_eta_foo(eoh[hot.layer].refHit(hot.index).phi(), eta);
0084     }
0085   }
0086 
0087   [[maybe_unused]] void partitionSeeds1(const TrackerInfo &trk_info,
0088                                         const TrackVec &in_seeds,
0089                                         const EventOfHits &eoh,
0090                                         IterationSeedPartition &part) {
0091     // Define first (mkFit) layer IDs for each strip subdetector.
0092     constexpr int tib1_id = 4;
0093     constexpr int tob1_id = 10;
0094     constexpr int tidp1_id = 21;
0095     constexpr int tidn1_id = 48;
0096     constexpr int tecp1_id = 27;
0097     constexpr int tecn1_id = 54;
0098 
0099     const LayerInfo &tib1 = trk_info.layer(tib1_id);
0100     const LayerInfo &tob1 = trk_info.layer(tob1_id);
0101 
0102     const LayerInfo &tidp1 = trk_info.layer(tidp1_id);
0103     const LayerInfo &tidn1 = trk_info.layer(tidn1_id);
0104 
0105     const LayerInfo &tecp1 = trk_info.layer(tecp1_id);
0106     const LayerInfo &tecn1 = trk_info.layer(tecn1_id);
0107 
0108     // Merge first two layers to account for mono/stereo coverage.
0109     // TrackerInfo could hold joint limits for sub-detectors.
0110     const auto &L = trk_info;
0111     const float tidp_rin = std::min(L[tidp1_id].rin(), L[tidp1_id + 1].rin());
0112     const float tidp_rout = std::max(L[tidp1_id].rout(), L[tidp1_id + 1].rout());
0113     const float tecp_rin = std::min(L[tecp1_id].rin(), L[tecp1_id + 1].rin());
0114     const float tecp_rout = std::max(L[tecp1_id].rout(), L[tecp1_id + 1].rout());
0115     const float tidn_rin = std::min(L[tidn1_id].rin(), L[tidn1_id + 1].rin());
0116     const float tidn_rout = std::max(L[tidn1_id].rout(), L[tidn1_id + 1].rout());
0117     const float tecn_rin = std::min(L[tecn1_id].rin(), L[tecn1_id + 1].rin());
0118     const float tecn_rout = std::max(L[tecn1_id].rout(), L[tecn1_id + 1].rout());
0119 
0120     // Bias towards more aggressive transition-region assignemnts.
0121     // With current tunning it seems to make things a bit worse.
0122     const float tid_z_extra = 0.0f;  // 5.0f;
0123     const float tec_z_extra = 0.0f;  // 10.0f;
0124 
0125     const size_t size = in_seeds.size();
0126 
0127     auto barrel_pos_check = [](const Track &S, float maxR, float rin, float zmax) -> bool {
0128       bool inside = maxR > rin && S.zAtR(rin) < zmax;
0129       return inside;
0130     };
0131 
0132     auto barrel_neg_check = [](const Track &S, float maxR, float rin, float zmin) -> bool {
0133       bool inside = maxR > rin && S.zAtR(rin) > zmin;
0134       return inside;
0135     };
0136 
0137     auto endcap_pos_check = [](const Track &S, float maxR, float rout, float rin, float zmin) -> bool {
0138       bool inside = maxR > rout ? S.zAtR(rout) > zmin : (maxR > rin && S.zAtR(maxR) > zmin);
0139       return inside;
0140     };
0141 
0142     auto endcap_neg_check = [](const Track &S, float maxR, float rout, float rin, float zmax) -> bool {
0143       bool inside = maxR > rout ? S.zAtR(rout) < zmax : (maxR > rin && S.zAtR(maxR) < zmax);
0144       return inside;
0145     };
0146 
0147     for (size_t i = 0; i < size; ++i) {
0148       const Track &S = in_seeds[i];
0149 
0150       const auto &hot = S.getLastHitOnTrack();
0151       const float eta = eoh[hot.layer].refHit(hot.index).eta();
0152 
0153       // Region to be defined by propagation / intersection tests
0154       TrackerInfo::EtaRegion reg;
0155 
0156       const bool z_dir_pos = S.pz() > 0;
0157       const float maxR = S.maxReachRadius();
0158 
0159       if (z_dir_pos) {
0160         const bool in_tib = barrel_pos_check(S, maxR, tib1.rin(), tib1.zmax());
0161         const bool in_tob = barrel_pos_check(S, maxR, tob1.rin(), tob1.zmax());
0162 
0163         if (!in_tib && !in_tob) {
0164           reg = TrackerInfo::Reg_Endcap_Pos;
0165         } else {
0166           const bool in_tid = endcap_pos_check(S, maxR, tidp_rout, tidp_rin, tidp1.zmin() - tid_z_extra);
0167           const bool in_tec = endcap_pos_check(S, maxR, tecp_rout, tecp_rin, tecp1.zmin() - tec_z_extra);
0168 
0169           if (!in_tid && !in_tec) {
0170             reg = TrackerInfo::Reg_Barrel;
0171           } else {
0172             reg = TrackerInfo::Reg_Transition_Pos;
0173           }
0174         }
0175       } else {
0176         const bool in_tib = barrel_neg_check(S, maxR, tib1.rin(), tib1.zmin());
0177         const bool in_tob = barrel_neg_check(S, maxR, tob1.rin(), tob1.zmin());
0178 
0179         if (!in_tib && !in_tob) {
0180           reg = TrackerInfo::Reg_Endcap_Neg;
0181         } else {
0182           const bool in_tid = endcap_neg_check(S, maxR, tidn_rout, tidn_rin, tidn1.zmax() + tid_z_extra);
0183           const bool in_tec = endcap_neg_check(S, maxR, tecn_rout, tecn_rin, tecn1.zmax() + tec_z_extra);
0184 
0185           if (!in_tid && !in_tec) {
0186             reg = TrackerInfo::Reg_Barrel;
0187           } else {
0188             reg = TrackerInfo::Reg_Transition_Neg;
0189           }
0190         }
0191       }
0192 
0193       part.m_region[i] = reg;
0194       if (part.m_phi_eta_foo)
0195         part.m_phi_eta_foo(eoh[hot.layer].refHit(hot.index).phi(), eta);
0196     }
0197   }
0198 }  // namespace
0199 
0200 class MkFitIterationConfigESProducer : public edm::ESProducer {
0201 public:
0202   MkFitIterationConfigESProducer(const edm::ParameterSet &iConfig);
0203 
0204   static void fillDescriptions(edm::ConfigurationDescriptions &descriptions);
0205 
0206   std::unique_ptr<mkfit::IterationConfig> produce(const TrackerRecoGeometryRecord &iRecord);
0207 
0208 private:
0209   const edm::ESGetToken<MkFitGeometry, TrackerRecoGeometryRecord> geomToken_;
0210   const std::string configFile_;
0211   const float minPtCut_;
0212   const unsigned int maxClusterSize_;
0213 };
0214 
0215 MkFitIterationConfigESProducer::MkFitIterationConfigESProducer(const edm::ParameterSet &iConfig)
0216     : geomToken_{setWhatProduced(this, iConfig.getParameter<std::string>("ComponentName")).consumes()},
0217       configFile_{iConfig.getParameter<edm::FileInPath>("config").fullPath()},
0218       minPtCut_{(float)iConfig.getParameter<double>("minPt")},
0219       maxClusterSize_{iConfig.getParameter<unsigned int>("maxClusterSize")} {}
0220 
0221 void MkFitIterationConfigESProducer::fillDescriptions(edm::ConfigurationDescriptions &descriptions) {
0222   edm::ParameterSetDescription desc;
0223   desc.add<std::string>("ComponentName")->setComment("Product label");
0224   desc.add<edm::FileInPath>("config")->setComment("Path to the JSON file for the mkFit configuration parameters");
0225   desc.add<double>("minPt", 0.0)->setComment("min pT cut applied during track building");
0226   desc.add<unsigned int>("maxClusterSize", 8)->setComment("Max cluster size of SiStrip hits");
0227   descriptions.addWithDefaultLabel(desc);
0228 }
0229 
0230 std::unique_ptr<mkfit::IterationConfig> MkFitIterationConfigESProducer::produce(
0231     const TrackerRecoGeometryRecord &iRecord) {
0232   mkfit::ConfigJson cj;
0233   auto it_conf = cj.load_File(configFile_);
0234   it_conf->m_params.minPtCut = minPtCut_;
0235   it_conf->m_backward_params.minPtCut = minPtCut_;
0236   it_conf->m_partition_seeds = partitionSeeds1;
0237   it_conf->m_params.maxClusterSize = maxClusterSize_;
0238   it_conf->m_backward_params.maxClusterSize = maxClusterSize_;
0239   return it_conf;
0240 }
0241 
0242 DEFINE_FWK_EVENTSETUP_MODULE(MkFitIterationConfigESProducer);