Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002  *
0003  * This is a part of TOTEM offline software.
0004  * Authors:
0005  *   Jan Kašpar (jan.kaspar@gmail.com)
0006  *   Laurent Forthomme
0007  *
0008  ****************************************************************************/
0009 
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/Framework/interface/EventSetup.h"
0012 #include "FWCore/Framework/interface/MakerMacros.h"
0013 #include "FWCore/Framework/interface/stream/EDProducer.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 
0016 #include "DataFormats/CTPPSReco/interface/CTPPSDiamondLocalTrack.h"
0017 #include "DataFormats/CTPPSReco/interface/CTPPSPixelLocalTrack.h"
0018 #include "DataFormats/CTPPSReco/interface/TotemRPLocalTrack.h"
0019 #include "DataFormats/Common/interface/DetSetVector.h"
0020 
0021 #include "DataFormats/CTPPSReco/interface/CTPPSLocalTrackLite.h"
0022 #include "DataFormats/CTPPSReco/interface/CTPPSLocalTrackLiteFwd.h"
0023 
0024 #include "DataFormats/Math/interface/libminifloat.h"
0025 
0026 //----------------------------------------------------------------------------------------------------
0027 
0028 /**
0029  * \brief Distills the essential track data from all RPs.
0030  **/
0031 class CTPPSLocalTrackLiteProducer : public edm::stream::EDProducer<> {
0032 public:
0033   explicit CTPPSLocalTrackLiteProducer(const edm::ParameterSet &);
0034 
0035   void produce(edm::Event &, const edm::EventSetup &) override;
0036   static void fillDescriptions(edm::ConfigurationDescriptions &);
0037 
0038 private:
0039   /// HPTDC time slice width, in ns
0040   static constexpr float HPTDC_TIME_SLICE_WIDTH = 25.;
0041 
0042   bool includeStrips_;
0043   edm::EDGetTokenT<edm::DetSetVector<TotemRPLocalTrack>> siStripTrackToken_;
0044 
0045   bool includeDiamonds_;
0046   edm::EDGetTokenT<edm::DetSetVector<CTPPSDiamondLocalTrack>> diamondTrackToken_;
0047 
0048   bool includePixels_;
0049   edm::EDGetTokenT<edm::DetSetVector<CTPPSPixelLocalTrack>> pixelTrackToken_;
0050 
0051   double pixelTrackTxMin_, pixelTrackTxMax_, pixelTrackTyMin_, pixelTrackTyMax_;
0052   double timingTrackTMin_, timingTrackTMax_;
0053 };
0054 
0055 //----------------------------------------------------------------------------------------------------
0056 
0057 CTPPSLocalTrackLiteProducer::CTPPSLocalTrackLiteProducer(const edm::ParameterSet &iConfig)
0058     : includeStrips_(iConfig.getParameter<bool>("includeStrips")),
0059       includeDiamonds_(iConfig.getParameter<bool>("includeDiamonds")),
0060       includePixels_(iConfig.getParameter<bool>("includePixels")),
0061       pixelTrackTxMin_(iConfig.getParameter<double>("pixelTrackTxMin")),
0062       pixelTrackTxMax_(iConfig.getParameter<double>("pixelTrackTxMax")),
0063       pixelTrackTyMin_(iConfig.getParameter<double>("pixelTrackTyMin")),
0064       pixelTrackTyMax_(iConfig.getParameter<double>("pixelTrackTyMax")),
0065       timingTrackTMin_(iConfig.getParameter<double>("timingTrackTMin")),
0066       timingTrackTMax_(iConfig.getParameter<double>("timingTrackTMax")) {
0067   auto tagSiStripTrack = iConfig.getParameter<edm::InputTag>("tagSiStripTrack");
0068   if (!tagSiStripTrack.label().empty())
0069     siStripTrackToken_ = consumes<edm::DetSetVector<TotemRPLocalTrack>>(tagSiStripTrack);
0070 
0071   auto tagDiamondTrack = iConfig.getParameter<edm::InputTag>("tagDiamondTrack");
0072   if (!tagDiamondTrack.label().empty())
0073     diamondTrackToken_ = consumes<edm::DetSetVector<CTPPSDiamondLocalTrack>>(tagDiamondTrack);
0074 
0075   auto tagPixelTrack = iConfig.getParameter<edm::InputTag>("tagPixelTrack");
0076   if (!tagPixelTrack.label().empty())
0077     pixelTrackToken_ = consumes<edm::DetSetVector<CTPPSPixelLocalTrack>>(tagPixelTrack);
0078 
0079   produces<CTPPSLocalTrackLiteCollection>();
0080 }
0081 
0082 //----------------------------------------------------------------------------------------------------
0083 
0084 void CTPPSLocalTrackLiteProducer::produce(edm::Event &iEvent, const edm::EventSetup &) {
0085   // prepare output
0086   auto pOut = std::make_unique<CTPPSLocalTrackLiteCollection>();
0087 
0088   //----- TOTEM strips
0089 
0090   // get input from Si strips
0091   if (includeStrips_) {
0092     edm::Handle<edm::DetSetVector<TotemRPLocalTrack>> inputSiStripTracks;
0093     iEvent.getByToken(siStripTrackToken_, inputSiStripTracks);
0094 
0095     // process tracks from Si strips
0096     for (const auto &rpv : *inputSiStripTracks) {
0097       const uint32_t rpId = rpv.detId();
0098       for (const auto &trk : rpv) {
0099         if (!trk.isValid())
0100           continue;
0101 
0102         float roundedX0 = MiniFloatConverter::reduceMantissaToNbitsRounding<14>(trk.x0());
0103         float roundedX0Sigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.x0Sigma());
0104         float roundedY0 = MiniFloatConverter::reduceMantissaToNbitsRounding<13>(trk.y0());
0105         float roundedY0Sigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.y0Sigma());
0106         float roundedTx = MiniFloatConverter::reduceMantissaToNbitsRounding<11>(trk.tx());
0107         float roundedTxSigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.txSigma());
0108         float roundedTy = MiniFloatConverter::reduceMantissaToNbitsRounding<11>(trk.ty());
0109         float roundedTySigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.tySigma());
0110         float roundedChiSquaredOverNDF = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.chiSquaredOverNDF());
0111 
0112         pOut->emplace_back(rpId,  // detector info
0113                                   // spatial info
0114                            roundedX0,
0115                            roundedX0Sigma,
0116                            roundedY0,
0117                            roundedY0Sigma,
0118                            // angular info
0119                            roundedTx,
0120                            roundedTxSigma,
0121                            roundedTy,
0122                            roundedTySigma,
0123                            // reconstruction info
0124                            roundedChiSquaredOverNDF,
0125                            CTPPSpixelLocalTrackReconstructionInfo::invalid,
0126                            trk.numberOfPointsUsedForFit(),
0127                            // timing info
0128                            0.,
0129                            0.);
0130       }
0131     }
0132   }
0133 
0134   //----- diamond detectors
0135 
0136   if (includeDiamonds_) {
0137     // get input from diamond detectors
0138     edm::Handle<edm::DetSetVector<CTPPSDiamondLocalTrack>> inputDiamondTracks;
0139     iEvent.getByToken(diamondTrackToken_, inputDiamondTracks);
0140 
0141     // process tracks from diamond detectors
0142     for (const auto &rpv : *inputDiamondTracks) {
0143       const unsigned int rpId = rpv.detId();
0144       for (const auto &trk : rpv) {
0145         if (!trk.isValid())
0146           continue;
0147 
0148         const float abs_time = trk.time() + trk.ootIndex() * HPTDC_TIME_SLICE_WIDTH;
0149         if (abs_time < timingTrackTMin_ || abs_time > timingTrackTMax_)
0150           continue;
0151 
0152         float roundedX0 = MiniFloatConverter::reduceMantissaToNbitsRounding<16>(trk.x0());
0153         float roundedX0Sigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.x0Sigma());
0154         float roundedY0 = MiniFloatConverter::reduceMantissaToNbitsRounding<13>(trk.y0());
0155         float roundedY0Sigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.y0Sigma());
0156         float roundedT = MiniFloatConverter::reduceMantissaToNbitsRounding<16>(abs_time);
0157         float roundedTSigma = MiniFloatConverter::reduceMantissaToNbitsRounding<13>(trk.timeSigma());
0158 
0159         pOut->emplace_back(rpId,  // detector info
0160                                   // spatial info
0161                            roundedX0,
0162                            roundedX0Sigma,
0163                            roundedY0,
0164                            roundedY0Sigma,
0165                            // angular info
0166                            0.,
0167                            0.,
0168                            0.,
0169                            0.,
0170                            // reconstruction info
0171                            0.,
0172                            CTPPSpixelLocalTrackReconstructionInfo::invalid,
0173                            trk.numberOfPlanes(),
0174                            // timing info
0175                            roundedT,
0176                            roundedTSigma);
0177       }
0178     }
0179   }
0180 
0181   //----- pixel detectors
0182 
0183   if (includePixels_) {
0184     edm::Handle<edm::DetSetVector<CTPPSPixelLocalTrack>> inputPixelTracks;
0185     if (!pixelTrackToken_.isUninitialized()) {
0186       iEvent.getByToken(pixelTrackToken_, inputPixelTracks);
0187 
0188       // process tracks from pixels
0189       for (const auto &rpv : *inputPixelTracks) {
0190         const uint32_t rpId = rpv.detId();
0191         for (const auto &trk : rpv) {
0192           if (!trk.isValid())
0193             continue;
0194           if (trk.tx() > pixelTrackTxMin_ && trk.tx() < pixelTrackTxMax_ && trk.ty() > pixelTrackTyMin_ &&
0195               trk.ty() < pixelTrackTyMax_) {
0196             float roundedX0 = MiniFloatConverter::reduceMantissaToNbitsRounding<16>(trk.x0());
0197             float roundedX0Sigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.x0Sigma());
0198             float roundedY0 = MiniFloatConverter::reduceMantissaToNbitsRounding<13>(trk.y0());
0199             float roundedY0Sigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.y0Sigma());
0200             float roundedTx = MiniFloatConverter::reduceMantissaToNbitsRounding<11>(trk.tx());
0201             float roundedTxSigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.txSigma());
0202             float roundedTy = MiniFloatConverter::reduceMantissaToNbitsRounding<11>(trk.ty());
0203             float roundedTySigma = MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.tySigma());
0204             float roundedChiSquaredOverNDF =
0205                 MiniFloatConverter::reduceMantissaToNbitsRounding<8>(trk.chiSquaredOverNDF());
0206 
0207             pOut->emplace_back(rpId,  // detector info
0208                                       // spatial info
0209                                roundedX0,
0210                                roundedX0Sigma,
0211                                roundedY0,
0212                                roundedY0Sigma,
0213                                // angular info
0214                                roundedTx,
0215                                roundedTxSigma,
0216                                roundedTy,
0217                                roundedTySigma,
0218                                // reconstruction info
0219                                roundedChiSquaredOverNDF,
0220                                trk.recoInfo(),
0221                                trk.numberOfPointsUsedForFit(),
0222                                // timing info
0223                                0.,
0224                                0.);
0225           }
0226         }
0227       }
0228     }
0229   }
0230 
0231   // save output to event
0232   iEvent.put(std::move(pOut));
0233 }
0234 
0235 //----------------------------------------------------------------------------------------------------
0236 
0237 void CTPPSLocalTrackLiteProducer::fillDescriptions(edm::ConfigurationDescriptions &descr) {
0238   edm::ParameterSetDescription desc;
0239 
0240   // By default: all includeXYZ flags set to false.
0241   // The includeXYZ are switched on when the "ctpps" era modifier is declared in
0242   // python config, see:
0243   // RecoPPS/Local/python/ctppsLocalTrackLiteProducer_cff.py
0244 
0245   desc.add<bool>("includeStrips", false)->setComment("whether tracks from Si strips should be included");
0246   desc.add<edm::InputTag>("tagSiStripTrack", edm::InputTag("totemRPLocalTrackFitter"))
0247       ->setComment("input TOTEM strips' local tracks collection to retrieve");
0248 
0249   desc.add<bool>("includeDiamonds", false)->setComment("whether tracks from diamonds strips should be included");
0250   desc.add<edm::InputTag>("tagDiamondTrack", edm::InputTag("ctppsDiamondLocalTracks"))
0251       ->setComment("input diamond detectors' local tracks collection to retrieve");
0252 
0253   desc.add<bool>("includePixels", false)->setComment("whether tracks from pixels should be included");
0254   desc.add<edm::InputTag>("tagPixelTrack", edm::InputTag("ctppsPixelLocalTracks"))
0255       ->setComment("input pixel detectors' local tracks collection to retrieve");
0256   desc.add<double>("timingTrackTMin", -12.5)->setComment("minimal track time selection for timing detectors, in ns");
0257   desc.add<double>("timingTrackTMax", +12.5)->setComment("maximal track time selection for timing detectors, in ns");
0258 
0259   desc.add<double>("pixelTrackTxMin", -10.0);
0260   desc.add<double>("pixelTrackTxMax", 10.0);
0261   desc.add<double>("pixelTrackTyMin", -10.0);
0262   desc.add<double>("pixelTrackTyMax", 10.0);
0263 
0264   descr.add("ctppsLocalTrackLiteDefaultProducer", desc);
0265 }
0266 
0267 //----------------------------------------------------------------------------------------------------
0268 
0269 DEFINE_FWK_MODULE(CTPPSLocalTrackLiteProducer);