ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/TreeFiller/src/FillerConversions.cc
Revision: 1.24
Committed: Fri Dec 28 17:27:21 2012 UTC (12 years, 4 months ago) by pharris
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_032, Mit_031, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, HEAD
Changes since 1.23: +6 -5 lines
Log Message:
Added Embedded and PFAOD functionality

File Contents

# User Rev Content
1 pharris 1.24 // $Id: FillerConversions.cc,v 1.23 2012/05/05 16:49:59 paus Exp $
2 bendavid 1.1
3 loizides 1.2 #include "MitProd/TreeFiller/interface/FillerConversions.h"
4 bendavid 1.10 #include "DataFormats/Common/interface/RefToPtr.h"
5 bendavid 1.22 #include "MitEdm/DataFormats/interface/RefToBaseToPtr.h"
6 loizides 1.15 #include "MitAna/DataTree/interface/ConversionCol.h"
7 bendavid 1.1 #include "MitAna/DataTree/interface/Names.h"
8 loizides 1.15 #include "MitProd/ObjectService/interface/ObjectService.h"
9 bendavid 1.1
10     using namespace std;
11     using namespace edm;
12     using namespace mithep;
13    
14 loizides 1.2 //--------------------------------------------------------------------------------------------------
15 loizides 1.12 FillerConversions::FillerConversions(const ParameterSet &cfg, const char *name, bool active) :
16 paus 1.23 BaseFiller (cfg,name,active),
17     edmName_ (Conf().getUntrackedParameter<string>("edmName","conversions")),
18     mitName_ (Conf().getUntrackedParameter<string>("mitName","Conversions")),
19 pharris 1.24 checkTrackRef_ (Conf().getUntrackedParameter<bool> ("checkTrackRef" ,true )),
20 bendavid 1.16 stablePartMapNames_(Conf().exists("stablePartMaps") ?
21 paus 1.23 Conf().getUntrackedParameter<vector<string> >("stablePartMaps") :
22     vector<string>()),
23     conversionMapName_ (Conf().getUntrackedParameter<string>("conversionMapName",
24     Form("%sMapName",mitName_.c_str()))),
25     conversions_ (new mithep::ConversionArr(16)),
26     conversionMap_ (new mithep::ConversionMap)
27 bendavid 1.1 {
28 loizides 1.2 // Constructor.
29 bendavid 1.1 }
30    
31 loizides 1.2 //--------------------------------------------------------------------------------------------------
32 bendavid 1.1 FillerConversions::~FillerConversions()
33     {
34 loizides 1.2 // Destructor.
35    
36 loizides 1.4 delete conversions_;
37 loizides 1.2 delete conversionMap_;
38 bendavid 1.1 }
39    
40 loizides 1.2 //--------------------------------------------------------------------------------------------------
41 bendavid 1.20 void FillerConversions::BookDataBlock(TreeWriter &tws)
42 bendavid 1.1 {
43 loizides 1.8 // Add conversions to tree. Publish and get our objects.
44 loizides 1.2
45 loizides 1.13 tws.AddBranch(mitName_,&conversions_);
46     OS()->add<mithep::ConversionArr>(conversions_,mitName_);
47 loizides 1.8
48 paus 1.23 if (!conversionMapName_.empty()) {
49 loizides 1.13 conversionMap_->SetBrName(mitName_);
50     OS()->add(conversionMap_,conversionMapName_);
51     }
52    
53 bendavid 1.16 for (std::vector<std::string>::const_iterator bmapName = stablePartMapNames_.begin();
54     bmapName!=stablePartMapNames_.end(); ++bmapName) {
55     if (!bmapName->empty()) {
56     const TrackPartMap *map = OS()->get<TrackPartMap>(*bmapName);
57     if (map) {
58     stablePartMaps_.push_back(map);
59     AddBranchDep(mitName_,map->GetBrName());
60     }
61     }
62 loizides 1.13 }
63 bendavid 1.1 }
64    
65 loizides 1.2 //--------------------------------------------------------------------------------------------------
66 bendavid 1.1 void FillerConversions::FillDataBlock(const edm::Event &event,
67     const edm::EventSetup &setup)
68     {
69 loizides 1.5 // Fill conversions data structure and maps.
70 bendavid 1.1
71 bendavid 1.11 conversions_->Delete();
72 bendavid 1.1 conversionMap_->Reset();
73 loizides 1.5
74     Handle<reco::ConversionCollection> hConversionProduct;
75     GetProduct(edmName_, hConversionProduct, event);
76    
77     conversionMap_->SetEdmProductId(hConversionProduct.id().id());
78 bendavid 1.1
79 loizides 1.5 const reco::ConversionCollection inConversions = *(hConversionProduct.product());
80 bendavid 1.1
81     for (reco::ConversionCollection::const_iterator inConversion = inConversions.begin();
82     inConversion != inConversions.end(); ++inConversion) {
83    
84 loizides 1.14 mithep::Vertex vertex(inConversion->conversionVertex().x(),
85     inConversion->conversionVertex().y(),
86     inConversion->conversionVertex().z(),
87     inConversion->conversionVertex().xError(),
88     inConversion->conversionVertex().yError(),
89     inConversion->conversionVertex().zError());
90     vertex.SetChi2(inConversion->conversionVertex().chi2());
91 bendavid 1.21 vertex.SetNdof(inConversion->conversionVertex().ndof());
92 bendavid 1.19 vertex.SetNTracksFit(inConversion->conversionVertex().tracksSize());
93    
94 loizides 1.6 mithep::Conversion *outConversion = conversions_->Allocate();
95 loizides 1.14 new (outConversion) mithep::Conversion(vertex);
96 loizides 1.5 outConversion->SetDCotTheta(inConversion->pairCotThetaSeparation());
97     outConversion->SetEOverP(inConversion->EoverP());
98     outConversion->SetPairMass(inConversion->pairInvariantMass());
99     outConversion->SetPairMomentum(inConversion->pairMomentum().x(),
100     inConversion->pairMomentum().y(),
101     inConversion->pairMomentum().z());
102 bendavid 1.1
103 bendavid 1.16 if (stablePartMaps_.size()) {
104 bendavid 1.22 std::vector<reco::TrackBaseRef> trackRefs = inConversion->tracks();
105     for (std::vector<reco::TrackBaseRef>::const_iterator trackRef = trackRefs.begin();
106 loizides 1.5 trackRef != trackRefs.end(); ++trackRef) {
107 pharris 1.24 if(GetMitParticle(mitedm::refToBaseToPtr(*trackRef))) outConversion->AddDaughter(GetMitParticle(mitedm::refToBaseToPtr(*trackRef)));
108 loizides 1.5 }
109     }
110    
111     reco::ConversionRef theRef(hConversionProduct, inConversion-inConversions.begin());
112     conversionMap_->Add(theRef, outConversion);
113 bendavid 1.1 }
114     conversions_->Trim();
115     }
116 bendavid 1.16
117     //--------------------------------------------------------------------------------------------------
118 loizides 1.17 mithep::Particle *FillerConversions::GetMitParticle(edm::Ptr<reco::Track> ptr) const
119 bendavid 1.16 {
120     // Return our particle referenced by the edm pointer.
121    
122     mithep::Particle *mitPart = 0;
123     for (std::vector<const mithep::TrackPartMap*>::const_iterator bmap = stablePartMaps_.begin();
124     bmap!=stablePartMaps_.end(); ++bmap) {
125     const mithep::TrackPartMap *theMap = *bmap;
126     if (theMap->HasMit(ptr)) {
127     mitPart = theMap->GetMit(ptr);
128     return mitPart;
129     }
130     }
131    
132 pharris 1.24 if (!mitPart && checkTrackRef_ )
133 bendavid 1.16 throw edm::Exception(edm::errors::Configuration, "FillerConversions::FillDataBlock()\n")
134 pharris 1.24 << "Error! MITHEP Object "
135     << "not found in AssociationMaps (" << typeid(*this).name() << ")." << std::endl;
136 bendavid 1.16
137     return mitPart;
138     }