Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:40

0001 /****************************************************************************
0002  *
0003  * This is a part of CTPPS offline software.
0004  * Authors:
0005  *   Laurent Forthomme (laurent.forthomme@cern.ch)
0006  *   Nicola Minafra (nicola.minafra@cern.ch)
0007  *   Mateusz Szpyrka (mateusz.szpyrka@cern.ch)
0008  *   Christopher Misan (krzysztof.misan@cern.ch)
0009  *
0010  ****************************************************************************/
0011 
0012 #include <memory>
0013 #include <utility>
0014 
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/stream/EDProducer.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/MakerMacros.h"
0019 
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/Utilities/interface/StreamID.h"
0022 
0023 #include "DataFormats/Common/interface/DetSetVector.h"
0024 
0025 #include "DataFormats/CTPPSDetId/interface/CTPPSDiamondDetId.h"
0026 #include "DataFormats/CTPPSDetId/interface/TotemTimingDetId.h"
0027 #include "DataFormats/CTPPSReco/interface/TotemTimingRecHit.h"
0028 #include "DataFormats/CTPPSReco/interface/TotemTimingLocalTrack.h"
0029 
0030 #include "RecoPPS/Local/interface/TotemTimingTrackRecognition.h"
0031 template <typename T>
0032 class TotemTimingLocalTrackFitter : public edm::stream::EDProducer<> {
0033 public:
0034   explicit TotemTimingLocalTrackFitter(const edm::ParameterSet&);
0035 
0036   static void fillDescriptions(edm::ConfigurationDescriptions&);
0037 
0038 private:
0039   static edm::ParameterSetDescription fillDescriptionsShared(edm::ConfigurationDescriptions&);
0040   void produce(edm::Event&, const edm::EventSetup&) override;
0041 
0042   const edm::EDGetTokenT<edm::DetSetVector<TotemTimingRecHit> > recHitsToken_;
0043   const int maxPlaneActiveChannels_;
0044   const edm::ParameterSet trk_algo_params_;
0045   std::map<CTPPSDetId, TotemTimingTrackRecognition> trk_algo_map_;
0046 };
0047 template <typename T>
0048 TotemTimingLocalTrackFitter<T>::TotemTimingLocalTrackFitter(const edm::ParameterSet& iConfig)
0049     : recHitsToken_(consumes<edm::DetSetVector<TotemTimingRecHit> >(iConfig.getParameter<edm::InputTag>("recHitsTag"))),
0050       maxPlaneActiveChannels_(iConfig.getParameter<int>("maxPlaneActiveChannels")),
0051       trk_algo_params_(iConfig.getParameter<edm::ParameterSet>("trackingAlgorithmParams")) {
0052   produces<edm::DetSetVector<TotemTimingLocalTrack> >();
0053 }
0054 template <typename T>
0055 void TotemTimingLocalTrackFitter<T>::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0056   auto pOut = std::make_unique<edm::DetSetVector<TotemTimingLocalTrack> >();
0057 
0058   edm::Handle<edm::DetSetVector<TotemTimingRecHit> > recHits;
0059   iEvent.getByToken(recHitsToken_, recHits);
0060 
0061   std::map<T, int> planeActivityMap;
0062 
0063   auto motherId = [](const edm::det_id_type& detid) {
0064     T out(detid);
0065     out.setChannel(0);
0066     return out;
0067   };
0068 
0069   for (const auto& vec : *recHits)
0070     planeActivityMap[motherId(vec.detId())] += vec.size();
0071 
0072   // feed hits to the track producers
0073   for (const auto& vec : *recHits) {
0074     const CTPPSDetId raw_detid(vec.detId());
0075     T detid(raw_detid.arm(), raw_detid.station(), raw_detid.rp());
0076     // if algorithm is not found, build it
0077     if (trk_algo_map_.count(detid) == 0)
0078       trk_algo_map_.insert(std::make_pair(detid, trk_algo_params_));
0079 
0080     auto detId = motherId(vec.detId());
0081     if (planeActivityMap[detId] > maxPlaneActiveChannels_)
0082       continue;
0083 
0084     detId.setPlane(0);
0085     for (const auto& hit : vec) {
0086       if (trk_algo_map_.find(detId) == trk_algo_map_.end())
0087         throw cms::Exception("TotemTimingLocalTrackFitter")
0088             << "Invalid detId for rechit: arm=" << detId.arm() << ", rp=" << detId.rp();
0089       trk_algo_map_.find(detId)->second.addHit(hit);
0090     }
0091   }
0092 
0093   // retrieves tracks for all hit sets
0094   for (auto& trk_algo_entry : trk_algo_map_) {
0095     pOut->find_or_insert(trk_algo_entry.first);
0096     trk_algo_entry.second.produceTracks(pOut->operator[](trk_algo_entry.first));
0097   }
0098 
0099   iEvent.put(std::move(pOut));
0100 
0101   // remove all hits from the track producers to prepare for the next event
0102   for (auto& trk_algo_entry : trk_algo_map_)
0103     trk_algo_entry.second.clear();
0104 }
0105 template <typename T>
0106 edm::ParameterSetDescription TotemTimingLocalTrackFitter<T>::fillDescriptionsShared(
0107     edm::ConfigurationDescriptions& descr) {
0108   edm::ParameterSetDescription desc;
0109   desc.add<edm::InputTag>("recHitsTag", edm::InputTag("totemTimingRecHits"))
0110       ->setComment("input rechits collection to retrieve");
0111   desc.add<int>("maxPlaneActiveChannels", 2)->setComment("threshold for discriminating noisy planes");
0112 
0113   edm::ParameterSetDescription trackingAlgoParams;
0114   trackingAlgoParams.add<double>("threshold", 1.5)
0115       ->setComment("minimal number of rechits to be observed before launching the track recognition algorithm");
0116   trackingAlgoParams.add<double>("thresholdFromMaximum", 0.5)
0117       ->setComment("threshold relative to hit profile function local maximum for determining the width of the track");
0118   trackingAlgoParams.add<double>("resolution", 0.01 /* mm */)
0119       ->setComment("spatial resolution on the horizontal coordinate (in mm)");
0120   trackingAlgoParams.add<double>("sigma", 0.)
0121       ->setComment("pixel efficiency function parameter determining the smoothness of the step");
0122   trackingAlgoParams.add<double>("tolerance", 0.1 /* mm */)
0123       ->setComment("tolerance used for checking if the track contains certain hit");
0124 
0125   trackingAlgoParams.add<std::string>("pixelEfficiencyFunction", "(x>[0]-0.5*[1]-0.05)*(x<[0]+0.5*[1]-0.05)+0*[2]")
0126       ->setComment(
0127           "efficiency function for single pixel\n"
0128           "can be defined as:\n"
0129           " * Precise: "
0130           "(TMath::Erf((x-[0]+0.5*([1]-0.05))/([2]/4)+2)+1)*TMath::Erfc((x-[0]-0.5*([1]-0.05))/([2]/4)-2)/4\n"
0131           " * Fast: "
0132           "(x>[0]-0.5*([1]-0.05))*(x<[0]+0.5*([1]-0.05))+((x-[0]+0.5*([1]-0.05)+[2])/"
0133           "[2])*(x>[0]-0.5*([1]-0.05)-[2])*(x<[0]-0.5*([1]-0.05))+(2-(x-[0]-0.5*([1]-0.05)+[2])/"
0134           "[2])*(x>[0]+0.5*([1]-0.05))*(x<[0]+0.5*([1]-0.05)+[2])\n"
0135           " * Legacy: (1/(1+exp(-(x-[0]+0.5*([1]-0.05))/[2])))*(1/(1+exp((x-[0]-0.5*([1]-0.05))/[2])))\n"
0136           " * Default (sigma ignored): (x>[0]-0.5*[1]-0.05)*(x<[0]+0.5*[1]-0.05)+0*[2]\n"
0137           "with:\n"
0138           "  [0]: centre of pad\n"
0139           "  [1]: width of pad\n"
0140           "  [2]: sigma: distance between efficiency ~100 -> 0 outside width");
0141 
0142   trackingAlgoParams.add<double>("yPosition", 0.0)->setComment("vertical offset of the outcoming track centre");
0143   trackingAlgoParams.add<double>("yWidth", 0.0)->setComment("vertical track width");
0144   desc.add<edm::ParameterSetDescription>("trackingAlgorithmParams", trackingAlgoParams)
0145       ->setComment("list of parameters associated to the track recognition algorithm");
0146   return desc;
0147 }
0148 template <>
0149 void TotemTimingLocalTrackFitter<TotemTimingDetId>::fillDescriptions(edm::ConfigurationDescriptions& descr) {
0150   auto desc = fillDescriptionsShared(descr);
0151   descr.add("totemTimingLocalTracks", desc);
0152 }
0153 
0154 template <>
0155 void TotemTimingLocalTrackFitter<CTPPSDiamondDetId>::fillDescriptions(edm::ConfigurationDescriptions& descr) {
0156   auto desc = fillDescriptionsShared(descr);
0157   descr.add("diamondSampicLocalTracks", desc);
0158 }
0159 template class TotemTimingLocalTrackFitter<CTPPSDiamondDetId>;
0160 template class TotemTimingLocalTrackFitter<TotemTimingDetId>;
0161 DEFINE_FWK_MODULE(TotemTimingLocalTrackFitter<TotemTimingDetId>);
0162 DEFINE_FWK_MODULE(TotemTimingLocalTrackFitter<CTPPSDiamondDetId>);