00001
00002
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/MakerMacros.h"
00005 #include "FWCore/Framework/interface/EventSetup.h"
00006
00007 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00008 #include "SimDataFormats/CaloHit/interface/PCaloHitContainer.h"
00009 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00010
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00013 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00014
00015 #include "FastSimulation/EventProducer/interface/FamosProducer.h"
00016 #include "FastSimulation/EventProducer/interface/FamosManager.h"
00017 #include "FastSimulation/Event/interface/FSimEvent.h"
00018 #include "FastSimulation/Event/interface/KineParticleFilter.h"
00019 #include "FastSimulation/Event/interface/PrimaryVertexGenerator.h"
00020 #include "FastSimulation/Calorimetry/interface/CalorimetryManager.h"
00021 #include "FastSimulation/TrajectoryManager/interface/TrajectoryManager.h"
00022
00023 #include "HepMC/GenEvent.h"
00024 #include "HepMC/GenVertex.h"
00025
00026
00027 #include <iostream>
00028 #include <memory>
00029 #include <vector>
00030
00031 FamosProducer::FamosProducer(edm::ParameterSet const & p)
00032 {
00033
00034 std::cout << " FamosProducer initializing " << std::endl;
00035
00036 produces<edm::SimTrackContainer>();
00037 produces<edm::SimVertexContainer>();
00038 produces<edm::PSimHitContainer>("TrackerHits");
00039 produces<edm::PCaloHitContainer>("EcalHitsEB");
00040 produces<edm::PCaloHitContainer>("EcalHitsEE");
00041 produces<edm::PCaloHitContainer>("EcalHitsES");
00042 produces<edm::PCaloHitContainer>("HcalHits");
00043
00044 simulateMuons = p.getParameter<bool>("SimulateMuons");
00045 if ( simulateMuons ) produces<edm::SimTrackContainer>("MuonSimTracks");
00046
00047
00048 theSourceLabel = p.getParameter<edm::InputTag>("SourceLabel");
00049 theGenParticleLabel = p.getParameter<edm::InputTag>("GenParticleLabel");
00050 theBeamSpotLabel = p.getParameter<edm::InputTag>("BeamSpotLabel");
00051
00052 famosManager_ = new FamosManager(p);
00053
00054 }
00055
00056 FamosProducer::~FamosProducer()
00057 { if ( famosManager_ ) delete famosManager_; }
00058
00059 void
00060 FamosProducer::beginRun(edm::Run & run, const edm::EventSetup & es) {
00061 famosManager_->setupGeometryAndField(run,es);
00062 }
00063
00064 void FamosProducer::endJob()
00065 {
00066 std::cout << " FamosProducer terminating " << std::endl;
00067 }
00068
00069 void FamosProducer::produce(edm::Event & iEvent, const edm::EventSetup & es)
00070 {
00071 using namespace edm;
00072
00073
00074 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
00075 iEvent.getByLabel(theBeamSpotLabel,recoBeamSpotHandle);
00076 math::XYZPoint BSPosition_ = recoBeamSpotHandle->position();
00077
00078
00079
00080
00081
00082
00083 Handle<HepMCProduct> theHepMCProduct;
00084
00085 const HepMC::GenEvent* myGenEvent = 0;
00086 FSimEvent* fevt = famosManager_->simEvent();
00087 fevt->setBeamSpot(BSPosition_);
00088 PrimaryVertexGenerator* theVertexGenerator = fevt->thePrimaryVertexGenerator();
00089
00090
00091 bool source = iEvent.getByLabel(theSourceLabel,theHepMCProduct);
00092 if ( source ) {
00093 myGenEvent = theHepMCProduct->GetEvent();
00094
00095 if ( theVertexGenerator ) {
00096 TMatrixD* boost = theVertexGenerator->boost();
00097 if ( boost ) theHepMCProduct->boostToLab(boost,"momentum");
00098 }
00099 myGenEvent = theHepMCProduct->GetEvent();
00100 }
00101
00102
00103 bool genPart = false;
00104 const reco::GenParticleCollection* myGenParticles = 0;
00105 if ( !myGenEvent ) {
00106
00107 Handle<reco::GenParticleCollection> genEvt;
00108 genPart = iEvent.getByLabel(theGenParticleLabel,genEvt);
00109 if ( genPart ) myGenParticles = &(*genEvt);
00110 }
00111
00112 if ( !myGenEvent && !genPart )
00113 std::cout << "There is no generator input for this event, under "
00114 << "any form (HepMCProduct, genParticles)" << std::endl
00115 << "Please check SourceLabel or GenParticleLabel" << std::endl;
00116
00117
00118
00119
00120 Handle<HepMCProduct> thePileUpEvents;
00121 bool isPileUp = iEvent.getByLabel("famosPileUp","PileUpEvents",thePileUpEvents);
00122 const HepMC::GenEvent* thePUEvents = isPileUp ? thePileUpEvents->GetEvent() : 0;
00123
00124
00125 if ( myGenEvent || myGenParticles )
00126 famosManager_->reconstruct(myGenEvent,myGenParticles,thePUEvents);
00127
00128
00129 if ( myGenEvent ) {
00130 if ( theVertexGenerator ) {
00131 HepMC::FourVector theVertex(
00132 (theVertexGenerator->X()-theVertexGenerator->beamSpot().X()+BSPosition_.X())*10.,
00133 (theVertexGenerator->Y()-theVertexGenerator->beamSpot().Y()+BSPosition_.Y())*10.,
00134 (theVertexGenerator->Z()-theVertexGenerator->beamSpot().Z()+BSPosition_.Z())*10.,
00135 0.);
00136 if ( fabs(theVertexGenerator->Z()) > 1E-10 ) theHepMCProduct->applyVtxGen( &theVertex );
00137 }
00138 }
00139
00140 CalorimetryManager * calo = famosManager_->calorimetryManager();
00141 TrajectoryManager * tracker = famosManager_->trackerManager();
00142
00143
00144 std::auto_ptr<edm::SimTrackContainer> p1(new edm::SimTrackContainer);
00145 std::auto_ptr<edm::SimTrackContainer> m1(new edm::SimTrackContainer);
00146 std::auto_ptr<edm::SimVertexContainer> p2(new edm::SimVertexContainer);
00147 std::auto_ptr<edm::PSimHitContainer> p3(new edm::PSimHitContainer);
00148 std::auto_ptr<edm::PCaloHitContainer> p4(new edm::PCaloHitContainer);
00149 std::auto_ptr<edm::PCaloHitContainer> p5(new edm::PCaloHitContainer);
00150 std::auto_ptr<edm::PCaloHitContainer> p6(new edm::PCaloHitContainer);
00151 std::auto_ptr<edm::PCaloHitContainer> p7(new edm::PCaloHitContainer);
00152
00153 fevt->load(*p1,*m1);
00154 fevt->load(*p2);
00155
00156 tracker->loadSimHits(*p3);
00157
00158 if ( calo ) {
00159 calo->loadFromEcalBarrel(*p4);
00160 calo->loadFromEcalEndcap(*p5);
00161 calo->loadFromPreshower(*p6);
00162 calo->loadFromHcal(*p7);
00163 }
00164
00165
00166 if ( simulateMuons ) iEvent.put(m1,"MuonSimTracks");
00167 iEvent.put(p1);
00168 iEvent.put(p2);
00169 iEvent.put(p3,"TrackerHits");
00170 iEvent.put(p4,"EcalHitsEB");
00171 iEvent.put(p5,"EcalHitsEE");
00172 iEvent.put(p6,"EcalHitsES");
00173 iEvent.put(p7,"HcalHits");
00174
00175 }
00176
00177 DEFINE_FWK_MODULE(FamosProducer);