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