Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:30:37

0001 // -*- C++ -*-
0002 //
0003 // Package:    SecSourceAnalyzer
0004 // Class:      SecSourceAnalyzer
0005 //
0006 /**\class SecSourceAnalyzer SecSourceAnalyzer.cc SecSource/SecSourceAnalyzer/src/SecSourceAnalyzer.cc
0007 
0008  Description: Get the data from the secondary source file using the getProductByTag method
0009 
0010  Implementation:
0011    
0012 */
0013 //
0014 // Original Author:  Emilia Lubenova Becheva
0015 //         Created:  Wed Apr 22 16:54:31 CEST 2009
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <functional>
0022 
0023 // user include files
0024 #include "FWCore/Framework/interface/Frameworkfwd.h"
0025 
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028 #include "FWCore/Framework/interface/ModuleContextSentry.h"
0029 
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0032 #include "SimDataFormats/CrossingFrame/interface/PCrossingFrame.h"
0033 
0034 #include "FWCore/Framework/interface/InputSourceDescription.h"
0035 #include "FWCore/ServiceRegistry/interface/InternalContext.h"
0036 #include "FWCore/ServiceRegistry/interface/ModuleCallingContext.h"
0037 #include "FWCore/ServiceRegistry/interface/ParentContext.h"
0038 #include "FWCore/Sources/interface/VectorInputSourceFactory.h"
0039 
0040 #include "FWCore/Sources/interface/VectorInputSource.h"
0041 
0042 #include "Mixing/Base/interface/PileUp.h"
0043 
0044 #include "SecSourceAnalyzer.h"
0045 
0046 #include "TH1F.h"
0047 
0048 //
0049 // constructors and destructor
0050 //
0051 namespace edm {
0052   SecSourceAnalyzer::SecSourceAnalyzer(const edm::ParameterSet& iConfig)
0053       : minBunch_(0), maxBunch_(0), tag_(InputTag()) {
0054     //    int minb = minBunch_;
0055     //    int maxb = maxBunch_;
0056     int averageNumber = 1;
0057     std::string histoFileName = " ";
0058     std::unique_ptr<TH1F> histoName(new TH1F("h", "", 10, 0, 10));
0059     bool playback = false;
0060 
0061     auto conf = std::make_shared<PileUpConfig>("input", averageNumber, histoName, playback);
0062     input_ = std::make_unique<edm::PileUp>(
0063         iConfig.getParameter<edm::ParameterSet>("input"), conf, consumesCollector(), false);
0064 
0065     dataStep2_ = iConfig.getParameter<bool>("dataStep2");
0066 
0067     if (dataStep2_)
0068       // The data file contain the PCrossingFrame<SimTrack>
0069       label_ = iConfig.getParameter<edm::InputTag>("collPCF");
0070     else
0071       // The data file contain the SimTrack
0072       label_ = iConfig.getParameter<edm::InputTag>("collSimTrack");
0073   }
0074 
0075   SecSourceAnalyzer::~SecSourceAnalyzer() {}
0076 
0077   //
0078   // member functions
0079   //
0080 
0081   // ------------ method called for each event  ------------
0082   void SecSourceAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0083     using namespace std::placeholders;
0084     vectorEventIDs_.resize(maxBunch_ - minBunch_ + 1);
0085 
0086     int nevt = 0;
0087     for (int ibx = minBunch_; ibx <= maxBunch_; ++ibx) {
0088       if (ibx == 0) {
0089         input_->readPileUp(iEvent.id(),
0090                            vectorEventIDs_[ibx - minBunch_],
0091                            std::bind(&SecSourceAnalyzer::getBranches, this, _1, iEvent.moduleCallingContext()),
0092                            ibx,
0093                            iEvent.streamID());
0094       } else {
0095         input_->readPileUp(iEvent.id(),
0096                            vectorEventIDs_[ibx - minBunch_],
0097                            std::bind(&SecSourceAnalyzer::dummyFunction, this, _1),
0098                            ibx,
0099                            iEvent.streamID());
0100       }
0101 
0102       nevt += vectorEventIDs_[ibx - minBunch_].size();
0103     }
0104 
0105     std::cout << "-> The std::vector<EventPrincipalVector> of the secondary source 'input' has been filled with "
0106               << nevt << " element corresponding to " << maxBunch_ - minBunch_ + 1 << " bunch." << std::endl;
0107   }
0108 
0109   bool SecSourceAnalyzer::getBranches(EventPrincipal const& ep, ModuleCallingContext const* mcc) {
0110     InternalContext internalContext(ep.id(), mcc);
0111     ParentContext parentContext(&internalContext);
0112     ModuleCallingContext moduleCallingContext(&moduleDescription());
0113     ModuleContextSentry moduleContextSentry(&moduleCallingContext, parentContext);
0114 
0115     std::cout << "-> Get the event:  id " << ep.id() << std::endl;
0116     std::cout << "-> dataStep2_ = " << dataStep2_ << std::endl;
0117     tag_ = InputTag(label_);
0118 
0119     std::cout << "-> Will try to get the branch with the tag : " << tag_ << std::endl;
0120     std::cout << " and the EventPrincipal ep with a size = " << ep.size() << std::endl;
0121 
0122     if (!dataStep2_) {
0123       // Get the SimTrack collection
0124 
0125       // default version changed to transmit vertexoffset
0126       std::shared_ptr<Wrapper<std::vector<SimTrack> > const> shPtr =
0127           getProductByTag<std::vector<SimTrack> >(ep, tag_, &moduleCallingContext);
0128 
0129       if (shPtr)
0130         std::cout << "-> Could get SimTrack !" << std::endl;
0131       else
0132         std::cout << "-> Could not get SimTrack !" << std::endl;
0133 
0134     } else {
0135       // Get the PCrossingFrame collection given as signal
0136 
0137       // default version changed to transmit vertexoffset
0138       tag_ = InputTag("CFwriter", "g4SimHits");
0139       std::shared_ptr<Wrapper<PCrossingFrame<SimTrack> > const> shPtr =
0140           getProductByTag<PCrossingFrame<SimTrack> >(ep, tag_, &moduleCallingContext);
0141 
0142       if (shPtr)
0143         std::cout << "-> Could get PCrossingFrame<SimTrack> !" << std::endl;
0144       else
0145         std::cout << "-> Could not get PCrossingFrame<SimTrack> !" << std::endl;
0146     }
0147 
0148     return true;
0149   }
0150 
0151   // ------------ method called once each job just before starting event loop  ------------
0152   void SecSourceAnalyzer::beginJob() {}
0153 
0154   // ------------ method called once each job just after ending the event loop  ------------
0155   void SecSourceAnalyzer::endJob() {
0156     if (input_)
0157       input_->endStream();
0158   }
0159 
0160 }  // namespace edm