ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerMCEventInfo.cc
Revision: 1.16
Committed: Thu Mar 18 20:21:00 2010 UTC (15 years, 1 month ago) by bendavid
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_025c_branch2, Mit_025c_branch1, Mit_025c_branch0, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a, Mit_025, Mit_025pre2, Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014e, Mit_014d, Mit_014c, Mit_014b, Mit_014a, Mit_014, Mit_014pre3, Mit_014pre2, Mit_014pre1, Mit_013d, Mit_013c, Mit_013b, Mit_013a, Mit_013
Branch point for: Mit_025c_branch
Changes since 1.15: +2 -2 lines
Log Message:
Fix beginrun,beginjob mess

File Contents

# Content
1 // $Id: FillerMCEventInfo.cc,v 1.15 2010/01/04 20:16:39 loizides Exp $
2
3 #include "MitProd/TreeFiller/interface/FillerMCEventInfo.h"
4 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
5 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
6 #include "MitAna/DataTree/interface/Names.h"
7 #include "MitAna/DataTree/interface/MCEventInfo.h"
8 #include "MitProd/ObjectService/interface/ObjectService.h"
9 #include "DataFormats/HepMCCandidate/interface/FlavorHistory.h"
10 #include "DataFormats/HepMCCandidate/interface/FlavorHistoryEvent.h"
11 #include "PhysicsTools/HepMCCandAlgos/interface/FlavorHistoryProducer.h"
12
13 using namespace std;
14 using namespace edm;
15 using namespace mithep;
16
17 //--------------------------------------------------------------------------------------------------
18 FillerMCEventInfo::FillerMCEventInfo(const ParameterSet &cfg, const char *name, bool active) :
19 BaseFiller(cfg,"MCEventInfo",active),
20 evtName_(Conf().getUntrackedParameter<string>("evtName",Names::gkMCEvtInfoBrn)),
21 genHepMCEvName_(Conf().getUntrackedParameter<string>("genHepMCEventEdmName","generator")),
22 genEvtInfoName_(Conf().getUntrackedParameter<string>("genEvtInfoEdmName","generator")),
23 flavorHistoryActive_(Conf().getUntrackedParameter<bool>("flavorHistoryActive",false)),
24 flavorHistName_(Conf().getUntrackedParameter<string>("flavorHistEdmName","flavorHistoryFilter")),
25 eventInfo_(new MCEventInfo())
26 {
27 // Constructor.
28 }
29
30 //--------------------------------------------------------------------------------------------------
31 FillerMCEventInfo::~FillerMCEventInfo()
32 {
33 // Destructor.
34
35 delete eventInfo_;
36 }
37
38 //--------------------------------------------------------------------------------------------------
39 void FillerMCEventInfo::BookDataBlock(TreeWriter &tws)
40 {
41 // Book our branch.
42
43 tws.AddBranch(evtName_,&eventInfo_);
44 OS()->add<mithep::MCEventInfo>(eventInfo_,evtName_);
45 }
46
47 //--------------------------------------------------------------------------------------------------
48 void FillerMCEventInfo::FillDataBlock(const edm::Event &event,
49 const edm::EventSetup &setup)
50 {
51 // Fill our data structures.
52
53 if (event.isRealData()) {
54 PrintErrorAndExit("Expected monte-carlo record, but did not get it. Aborting.");
55 }
56
57 Handle<GenEventInfoProduct> hEvtInfo;
58
59 if (genEvtInfoName_.empty() || !GetProductSafe(genEvtInfoName_, hEvtInfo, event)) {
60
61 // fall back to hepmc if requested
62 if (!genHepMCEvName_.empty()) {
63 Handle<edm::HepMCProduct> hHepMCProduct;
64 GetProduct(genHepMCEvName_, hHepMCProduct, event);
65 const HepMC::GenEvent *genEvt = hHepMCProduct->GetEvent();
66 eventInfo_->SetScale(genEvt->event_scale());
67 eventInfo_->SetProcessId(genEvt->signal_process_id());
68 HepMC::WeightContainer wc = genEvt->weights();
69 Double_t weight = 0;
70 for (int i = 0; i< wc.size(); ++i)
71 weight *= wc[i];
72 eventInfo_->SetWeight(weight);
73 const HepMC::PdfInfo *genPdfInfo = genEvt->pdf_info();
74 if (genPdfInfo) {
75 eventInfo_->SetId1(genPdfInfo->id1());
76 eventInfo_->SetId2(genPdfInfo->id2());
77 eventInfo_->SetPdf1(genPdfInfo->pdf1());
78 eventInfo_->SetPdf2(genPdfInfo->pdf2());
79 eventInfo_->SetScalePdf(genPdfInfo->scalePDF());
80 eventInfo_->SetX1(genPdfInfo->x1());
81 eventInfo_->SetX2(genPdfInfo->x2());
82 }
83 }
84
85 } else {
86
87 // use event info product
88 eventInfo_->SetScale(hEvtInfo->qScale());
89 eventInfo_->SetProcessId(hEvtInfo->signalProcessID());
90 eventInfo_->SetWeight(hEvtInfo->weight());
91 if (hEvtInfo->hasPDF()) {
92 const gen::PdfInfo *pdf = hEvtInfo->pdf();
93 eventInfo_->SetId1(pdf->id.first);
94 eventInfo_->SetId2(pdf->id.second);
95 eventInfo_->SetPdf1(pdf->xPDF.first);
96 eventInfo_->SetPdf2(pdf->xPDF.second);
97 eventInfo_->SetScalePdf(pdf->scalePDF);
98 eventInfo_->SetX1(pdf->x.first);
99 eventInfo_->SetX2(pdf->x.second);
100 }
101 }
102
103 // fill flavor history path if requested
104 if (flavorHistoryActive_) {
105 Handle<unsigned int> flavorHistoryPath;
106 GetProduct(flavorHistName_, flavorHistoryPath, event);
107 eventInfo_->SetFlavorHistoryPath(*flavorHistoryPath);
108 }
109 }