1 |
// $Id: FillerStableParts.cc,v 1.16 2009/09/25 08:42:51 loizides Exp $
|
2 |
|
3 |
#include "MitProd/TreeFiller/interface/FillerStableParts.h"
|
4 |
#include "DataFormats/TrackReco/interface/Track.h"
|
5 |
#include "DataFormats/TrackReco/interface/TrackFwd.h"
|
6 |
#include "DataFormats/Common/interface/RefToPtr.h"
|
7 |
#include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
|
8 |
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
|
9 |
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
|
10 |
#include "MitAna/DataTree/interface/Names.h"
|
11 |
#include "MitAna/DataTree/interface/StableParticleCol.h"
|
12 |
#include "MitEdm/DataFormats/interface/Collections.h"
|
13 |
#include "MitProd/ObjectService/interface/ObjectService.h"
|
14 |
|
15 |
using namespace std;
|
16 |
using namespace edm;
|
17 |
using namespace mithep;
|
18 |
|
19 |
//--------------------------------------------------------------------------------------------------
|
20 |
FillerStableParts::FillerStableParts(const ParameterSet &cfg, const char *name, bool active) :
|
21 |
BaseFiller(cfg,name,active),
|
22 |
edmName_(Conf().getUntrackedParameter<string>("edmName","")),
|
23 |
mitName_(Conf().getUntrackedParameter<string>("mitName","")),
|
24 |
trackMapNames_(Conf().exists("trackMapNames") ?
|
25 |
Conf().getUntrackedParameter<vector<string> >("trackMapNames") :
|
26 |
vector<string>()),
|
27 |
basePartMapName_(Conf().getUntrackedParameter<string>("basePartMap",
|
28 |
Form("%sMapName",mitName_.c_str()))),
|
29 |
trackPartMapName_(Conf().getUntrackedParameter<string>("trackPartMap",
|
30 |
Form("%sTrackMapName",mitName_.c_str()))),
|
31 |
stables_(new mithep::StableParticleArr(250)),
|
32 |
basePartMap_(new mithep::BasePartMap),
|
33 |
trackPartMap_(new mithep::TrackPartMap)
|
34 |
{
|
35 |
// Constructor.
|
36 |
}
|
37 |
|
38 |
//--------------------------------------------------------------------------------------------------
|
39 |
FillerStableParts::~FillerStableParts()
|
40 |
{
|
41 |
// Destructor.
|
42 |
|
43 |
delete stables_;
|
44 |
delete basePartMap_;
|
45 |
delete trackPartMap_;
|
46 |
}
|
47 |
|
48 |
//--------------------------------------------------------------------------------------------------
|
49 |
void FillerStableParts::BookDataBlock(TreeWriter &tws)
|
50 |
{
|
51 |
// Add tracks branch to tree, get and publish our maps.
|
52 |
|
53 |
tws.AddBranch(mitName_,&stables_);
|
54 |
OS()->add<mithep::StableParticleArr>(stables_,mitName_);
|
55 |
|
56 |
if (!basePartMapName_.empty()) {
|
57 |
basePartMap_->SetBrName(mitName_);
|
58 |
OS()->add(basePartMap_,basePartMapName_);
|
59 |
}
|
60 |
if (!trackPartMapName_.empty()) {
|
61 |
trackPartMap_->SetBrName(mitName_);
|
62 |
OS()->add(trackPartMap_,trackPartMapName_);
|
63 |
}
|
64 |
|
65 |
for (std::vector<std::string>::const_iterator tmapName = trackMapNames_.begin();
|
66 |
tmapName!=trackMapNames_.end(); ++tmapName) {
|
67 |
if (!tmapName->empty()) {
|
68 |
const TrackMap *map = OS()->get<TrackMap>(*tmapName);
|
69 |
if (map) {
|
70 |
trackMaps_.push_back(map);
|
71 |
AddBranchDep(mitName_,map->GetBrName());
|
72 |
}
|
73 |
}
|
74 |
}
|
75 |
}
|
76 |
|
77 |
//--------------------------------------------------------------------------------------------------
|
78 |
void FillerStableParts::FillDataBlock(const edm::Event &evt,
|
79 |
const edm::EventSetup &setup)
|
80 |
{
|
81 |
// Fill our EDM StablePart collection into the MIT StableParticle collection.
|
82 |
|
83 |
stables_->Delete();
|
84 |
basePartMap_->Reset();
|
85 |
|
86 |
Handle<mitedm::StablePartCol> hParts;
|
87 |
GetProduct(edmName_, hParts, evt);
|
88 |
const mitedm::StablePartCol *iParts = hParts.product();
|
89 |
|
90 |
// loop through all StableParts and fill the information
|
91 |
for (UInt_t i=0; i<iParts->size(); ++i) {
|
92 |
const mitedm::StablePart &p = iParts->at(i);
|
93 |
mitedm::BasePartPtr thePtr(hParts,i);
|
94 |
mithep::StableParticle *d = stables_->Allocate();
|
95 |
new (d) mithep::StableParticle(p.pid());
|
96 |
basePartMap_->Add(thePtr,d);
|
97 |
trackPartMap_->Add(p.trackPtr(),d);
|
98 |
if (trackMaps_.size())
|
99 |
d->SetTrk(GetMitTrack(p.trackPtr()));
|
100 |
}
|
101 |
stables_->Trim();
|
102 |
}
|
103 |
|
104 |
//--------------------------------------------------------------------------------------------------
|
105 |
mithep::Track *FillerStableParts::GetMitTrack(const mitedm::TrackPtr &ptr) const
|
106 |
{
|
107 |
// Return our particle referenced by the edm pointer.
|
108 |
|
109 |
mithep::Track *mitTrack = 0;
|
110 |
for (std::vector<const mithep::TrackMap*>::const_iterator tmap = trackMaps_.begin();
|
111 |
tmap!=trackMaps_.end(); ++tmap) {
|
112 |
const mithep::TrackMap *theMap = *tmap;
|
113 |
if (theMap->HasMit(ptr)) {
|
114 |
mitTrack = theMap->GetMit(ptr);
|
115 |
return mitTrack;
|
116 |
}
|
117 |
}
|
118 |
|
119 |
if (!mitTrack)
|
120 |
throw edm::Exception(edm::errors::Configuration, "FillerStableParts::FillDataBlock()\n")
|
121 |
<< "Error! MITHEP Object "
|
122 |
<< "not found in AssociationMaps (" << typeid(*this).name() << ")." << std::endl;
|
123 |
|
124 |
return mitTrack;
|
125 |
}
|