Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:03

0001 #ifndef SimGeneral_MixingModule_Adjuster_h
0002 #define SimGeneral_MixingModule_Adjuster_h
0003 
0004 #include "DataFormats/Common/interface/Wrapper.h"
0005 #include "FWCore/Framework/interface/ConsumesCollector.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/EventPrincipal.h"
0008 #include "FWCore/Utilities/interface/EDGetToken.h"
0009 #include "FWCore/Utilities/interface/InputTag.h"
0010 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
0011 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0012 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0013 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
0014 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
0015 
0016 #include <memory>
0017 #include <vector>
0018 #include <string>
0019 #include <iostream>
0020 
0021 class FastTrackerRecHit;
0022 
0023 namespace edm {
0024   class ModuleCallingContext;
0025 
0026   class AdjusterBase {
0027   public:
0028     virtual ~AdjusterBase() {}
0029     virtual void doOffset(int bunchspace,
0030                           int bcr,
0031                           const edm::EventPrincipal&,
0032                           ModuleCallingContext const*,
0033                           unsigned int EventNr,
0034                           int vertexOffset) = 0;
0035     virtual bool checkSignal(edm::Event const& event) = 0;
0036   };
0037 
0038   template <typename T>
0039   class Adjuster : public AdjusterBase {
0040   public:
0041     Adjuster(InputTag const& tag, edm::ConsumesCollector&& iC, bool wrap);
0042 
0043     ~Adjuster() override {}
0044 
0045     void doOffset(int bunchspace,
0046                   int bcr,
0047                   const edm::EventPrincipal&,
0048                   ModuleCallingContext const*,
0049                   unsigned int EventNr,
0050                   int vertexOffset) override;
0051 
0052     bool checkSignal(edm::Event const& event) override {
0053       bool got = false;
0054       edm::Handle<T> result_t;
0055       got = event.getByToken(token_, result_t);
0056       return got;
0057     }
0058 
0059   private:
0060     InputTag tag_;
0061     bool WrapT_ = false;
0062     EDGetTokenT<T> token_;
0063   };
0064 
0065   //==============================================================================
0066   //                              implementations
0067   //==============================================================================
0068 
0069   namespace detail {
0070     void doTheOffset(int bunchspace,
0071                      int bcr,
0072                      std::vector<SimTrack>& product,
0073                      unsigned int eventNr,
0074                      int vertexOffset,
0075                      bool wraptimes);
0076     void doTheOffset(int bunchspace,
0077                      int bcr,
0078                      std::vector<SimVertex>& product,
0079                      unsigned int eventNr,
0080                      int vertexOffset,
0081                      bool wraptimes);
0082     void doTheOffset(int bunchspace,
0083                      int bcr,
0084                      std::vector<PCaloHit>& product,
0085                      unsigned int eventNr,
0086                      int vertexOffset,
0087                      bool wraptimes);
0088     void doTheOffset(
0089         int bunchspace, int bcr, std::vector<PSimHit>& product, unsigned int eventNr, int vertexOffset, bool wraptimes);
0090     void doTheOffset(int bunchspace,
0091                      int bcr,
0092                      TrackingRecHitCollection& product,
0093                      unsigned int eventNr,
0094                      int vertexOffset,
0095                      bool wraptimes);
0096   }  // namespace detail
0097 
0098   template <typename T>
0099   void Adjuster<T>::doOffset(int bunchspace,
0100                              int bcr,
0101                              const EventPrincipal& ep,
0102                              ModuleCallingContext const* mcc,
0103                              unsigned int eventNr,
0104                              int vertexOffset) {
0105     std::shared_ptr<Wrapper<T> const> shPtr = getProductByTag<T>(ep, tag_, mcc);
0106     if (shPtr) {
0107       T& product = const_cast<T&>(*shPtr->product());
0108       detail::doTheOffset(bunchspace, bcr, product, eventNr, vertexOffset, WrapT_);
0109     }
0110   }
0111 
0112   template <typename T>
0113   Adjuster<T>::Adjuster(InputTag const& tag, ConsumesCollector&& iC, bool wrapLongTimes)
0114       : tag_(tag), token_(iC.consumes<T>(tag)) {
0115     if (wrapLongTimes) {
0116       std::string Musearch = tag_.instance();
0117       if (Musearch.find("Muon") == 0)
0118         WrapT_ = true;  // wrap time for neutrons in Muon system subdetectors
0119     }
0120   }
0121 }  // namespace edm
0122 
0123 #endif