Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-28 01:32:37

0001 /*
0002  * \file FakeTBEventHeaderProducer.cc
0003  *
0004  * Mimic the event header information
0005  * for the test beam simulation
0006  *
0007  */
0008 
0009 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0010 #include "DataFormats/Common/interface/Handle.h"
0011 
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/EventSetup.h"
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/Framework/interface/stream/EDProducer.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 #include "FWCore/PluginManager/interface/ModuleDef.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 
0020 #include "Geometry/EcalTestBeam/interface/EcalTBHodoscopeGeometry.h"
0021 #include "SimDataFormats/EcalTestBeam/interface/PEcalTBInfo.h"
0022 #include "TBDataFormats/EcalTBObjects/interface/EcalTBEventHeader.h"
0023 
0024 class FakeTBEventHeaderProducer : public edm::stream::EDProducer<> {
0025 public:
0026   /// Constructor
0027   explicit FakeTBEventHeaderProducer(const edm::ParameterSet &ps);
0028 
0029   /// Destructor
0030   ~FakeTBEventHeaderProducer() override = default;
0031 
0032   /// Produce digis out of raw data
0033   void produce(edm::Event &event, const edm::EventSetup &eventSetup) override;
0034 
0035 private:
0036   const edm::EDGetTokenT<PEcalTBInfo> ecalTBInfo_;
0037 };
0038 
0039 FakeTBEventHeaderProducer::FakeTBEventHeaderProducer(const edm::ParameterSet &ps)
0040     : ecalTBInfo_(consumes<PEcalTBInfo>(edm::InputTag("EcalTBInfoLabel", "SimEcalTBG4Object"))) {
0041   produces<EcalTBEventHeader>();
0042 }
0043 
0044 void FakeTBEventHeaderProducer::produce(edm::Event &event, const edm::EventSetup &eventSetup) {
0045   std::unique_ptr<EcalTBEventHeader> product(new EcalTBEventHeader());
0046 
0047   // get the vertex information from the event
0048 
0049   const PEcalTBInfo *theEcalTBInfo = nullptr;
0050   const edm::Handle<PEcalTBInfo> &EcalTBInfo = event.getHandle(ecalTBInfo_);
0051   if (EcalTBInfo.isValid()) {
0052     theEcalTBInfo = EcalTBInfo.product();
0053   } else {
0054     edm::LogError("FakeTBEventHeaderProducer") << "Error! can't get the product PEcalTBInfo";
0055   }
0056 
0057   if (!theEcalTBInfo) {
0058     return;
0059   }
0060 
0061   // 64 bits event ID in CMSSW converted to EcalTBEventHeader ID
0062   int evtid = (int)event.id().event();
0063   product->setEventNumber(evtid);
0064   product->setRunNumber(event.id().run());
0065   product->setBurstNumber(1);
0066   product->setTriggerMask(0x1);
0067   product->setCrystalInBeam(EBDetId(1, theEcalTBInfo->nCrystal(), EBDetId::SMCRYSTALMODE));
0068 
0069   LogDebug("FakeTBHeader") << (*product);
0070   LogDebug("FakeTBHeader") << (*product).eventType();
0071   LogDebug("FakeTBHeader") << (*product).crystalInBeam();
0072 
0073   event.put(std::move(product));
0074 }
0075 
0076 DEFINE_FWK_MODULE(FakeTBEventHeaderProducer);