CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/SimGeneral/MixingModule/plugins/SecSourceAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SecSourceAnalyzer
00004 // Class:      SecSourceAnalyzer
00005 // 
00013 //
00014 // Original Author:  Emilia Lubenova Becheva
00015 //         Created:  Wed Apr 22 16:54:31 CEST 2009
00016 // $Id: SecSourceAnalyzer.cc,v 1.8 2012/01/30 18:23:36 fwyzard Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 #include <boost/bind.hpp>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/Frameworkfwd.h"
00027 #include "FWCore/Framework/interface/EDAnalyzer.h"
00028 
00029 #include "FWCore/Framework/interface/Event.h"
00030 #include "FWCore/Framework/interface/MakerMacros.h"
00031 
00032 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00033 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
00034 #include "SimDataFormats/CrossingFrame/interface/PCrossingFrame.h"
00035 
00036 #include "FWCore/Framework/interface/InputSourceDescription.h"
00037 #include "FWCore/Sources/interface/VectorInputSourceFactory.h"
00038 
00039 #include "FWCore/Sources/interface/VectorInputSource.h"
00040 
00041 #include "Mixing/Base/interface/PileUp.h"
00042 
00043 #include "SecSourceAnalyzer.h"
00044 
00045 #include "TH1F.h"
00046 
00047 //
00048 // constructors and destructor
00049 //
00050 namespace edm
00051 {
00052 SecSourceAnalyzer::SecSourceAnalyzer(const edm::ParameterSet& iConfig)
00053   :minBunch_(0),
00054    maxBunch_(0),
00055    tag_(InputTag())
00056 {
00057 //    int minb = minBunch_;
00058 //    int maxb = maxBunch_;
00059    int averageNumber = 1;
00060    std::string histoFileName = " ";
00061    TH1F * histoName = new TH1F("h","",10,0,10); 
00062    bool playback = false;
00063    
00064    input_.reset(new edm::PileUp(iConfig.getParameter<edm::ParameterSet>("input"),
00065                                 averageNumber,histoName,playback));
00066       
00067    dataStep2_ = iConfig.getParameter<bool>("dataStep2");
00068    
00069    
00070    if (dataStep2_)
00071      // The data file contain the PCrossingFrame<SimTrack>
00072      label_   = iConfig.getParameter<edm::InputTag>("collPCF");
00073    else
00074      // The data file contain the SimTrack
00075      label_   = iConfig.getParameter<edm::InputTag>("collSimTrack");
00076 
00077 }
00078 
00079 
00080 SecSourceAnalyzer::~SecSourceAnalyzer()
00081 {
00082 }
00083 
00084 
00085 //
00086 // member functions
00087 //
00088 
00089 // ------------ method called for each event  ------------
00090 void
00091 SecSourceAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00092 {
00093    vectorEventIDs_.resize(maxBunch_-minBunch_+1);
00094 
00095    int nevt = 0 ;
00096    for( int ibx = minBunch_ ; ibx <= maxBunch_ ; ++ibx )
00097      {
00098        if( ibx == 0 )
00099          {
00100            input_->readPileUp( iEvent.id(),
00101                                vectorEventIDs_[ ibx-minBunch_ ],
00102                                boost::bind(&SecSourceAnalyzer::getBranches, 
00103                                            this, _1), ibx
00104                                );
00105          }
00106        else
00107          {
00108            input_->readPileUp( iEvent.id(),
00109                                vectorEventIDs_[ ibx-minBunch_ ],
00110                                boost::bind(&SecSourceAnalyzer::dummyFunction, 
00111                                            this, _1), ibx
00112                                );
00113          }
00114 
00115        nevt += vectorEventIDs_[ ibx-minBunch_ ].size() ;
00116      }
00117 
00118    std::cout << "-> The std::vector<EventPrincipalVector> of the secondary source 'input' has been filled with " 
00119              << nevt << " element corresponding to " << maxBunch_-minBunch_+1 
00120              << " bunch." << std::endl;
00121 }
00122 
00123 void  SecSourceAnalyzer::getBranches(EventPrincipal const &ep)
00124   { 
00125     std::cout <<"-> Get the event:  id " << ep.id() << std::endl;
00126     std::cout << "-> dataStep2_ = " << dataStep2_ << std::endl;
00127     tag_ = InputTag(label_);
00128     
00129     std::cout << "-> Will try to get the branch with the tag : " << tag_ << std::endl;    
00130     std::cout << " and the EventPrincipal ep with a size = " << ep.size() << std::endl;
00131     
00132     if (!dataStep2_){
00133         // Get the SimTrack collection
00134         
00135         // default version changed to transmit vertexoffset
00136         boost::shared_ptr<Wrapper<std::vector<SimTrack> > const> shPtr =
00137         getProductByTag<std::vector<SimTrack> >(ep, tag_);
00138     
00139         if (shPtr) 
00140                 std::cout << "-> Could get SimTrack !" << std::endl;
00141         else 
00142                 std::cout << "-> Could not get SimTrack !" << std::endl;
00143 
00144     }
00145     else{
00146         // Get the PCrossingFrame collection given as signal
00147     
00148         // default version changed to transmit vertexoffset
00149         tag_ = InputTag("CFwriter","g4SimHits");
00150         boost::shared_ptr<Wrapper<PCrossingFrame<SimTrack> > const> shPtr =
00151         getProductByTag<PCrossingFrame<SimTrack> >(ep, tag_);
00152         
00153         if (shPtr) 
00154                 std::cout << "-> Could get PCrossingFrame<SimTrack> !" << std::endl;
00155         else 
00156                 std::cout << "-> Could not get PCrossingFrame<SimTrack> !" << std::endl;
00157         
00158     }
00159  
00160   }
00161 
00162 
00163 // ------------ method called once each job just before starting event loop  ------------
00164 void 
00165 SecSourceAnalyzer::beginJob()
00166 {
00167 }
00168 
00169 // ------------ method called once each job just after ending the event loop  ------------
00170 void 
00171 SecSourceAnalyzer::endJob() {
00172   if (input_) input_->endJob();
00173 }
00174 
00175 }//edm