1 |
// $Id: FillerDecayParts.cc,v 1.17 2009/06/15 15:00:25 loizides Exp $
|
2 |
|
3 |
#include "MitProd/TreeFiller/interface/FillerDecayParts.h"
|
4 |
#include "DataFormats/TrackReco/interface/Track.h"
|
5 |
#include "DataFormats/TrackReco/interface/TrackFwd.h"
|
6 |
#include "DataFormats/TrackReco/interface/HitPattern.h"
|
7 |
#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
|
8 |
#include "DataFormats/RecoCandidate/interface/TrackAssociation.h"
|
9 |
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
|
10 |
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
|
11 |
#include "MitAna/DataTree/interface/StableDataCol.h"
|
12 |
#include "MitAna/DataTree/interface/DecayDataCol.h"
|
13 |
#include "MitAna/DataTree/interface/DecayParticleCol.h"
|
14 |
#include "MitAna/DataTree/interface/Names.h"
|
15 |
#include "MitEdm/DataFormats/interface/Collections.h"
|
16 |
#include "MitProd/ObjectService/interface/ObjectService.h"
|
17 |
|
18 |
using namespace std;
|
19 |
using namespace edm;
|
20 |
using namespace mithep;
|
21 |
|
22 |
//--------------------------------------------------------------------------------------------------
|
23 |
FillerDecayParts::FillerDecayParts(const ParameterSet &cfg, const char *name, bool active) :
|
24 |
BaseFiller(cfg,name,active),
|
25 |
edmName_(Conf().getUntrackedParameter<string>("edmName","")),
|
26 |
mitName_(Conf().getUntrackedParameter<string>("mitName","")),
|
27 |
stableDataName_(mitName_ + "_StableDatas"),
|
28 |
decayDataName_(mitName_ + "_DecayDatas"),
|
29 |
vertexMapName_(Conf().getUntrackedParameter<string>("vertexMap","")),
|
30 |
basePartMapNames_(Conf().exists("basePartMaps") ?
|
31 |
Conf().getUntrackedParameter<vector<string> >("basePartMaps") :
|
32 |
vector<string>()),
|
33 |
vertexMap_(0),
|
34 |
decays_(new mithep::DecayParticleArr(250)),
|
35 |
stableData_(new mithep::StableDataArr(500)),
|
36 |
decayData_(new mithep::DecayDataArr(500))
|
37 |
{
|
38 |
// Constructor.
|
39 |
}
|
40 |
|
41 |
//--------------------------------------------------------------------------------------------------
|
42 |
FillerDecayParts::~FillerDecayParts()
|
43 |
{
|
44 |
// Destructor.
|
45 |
|
46 |
delete decays_;
|
47 |
delete stableData_;
|
48 |
delete decayData_;
|
49 |
}
|
50 |
|
51 |
//--------------------------------------------------------------------------------------------------
|
52 |
void FillerDecayParts::BookDataBlock(TreeWriter &tws, const edm::EventSetup &es)
|
53 |
{
|
54 |
// Add our branches to tree and get our map.
|
55 |
|
56 |
tws.AddBranch(mitName_, &decays_);
|
57 |
OS()->add<mithep::DecayParticleArr>(decays_,mitName_);
|
58 |
tws.AddBranch(stableDataName_, &stableData_);
|
59 |
OS()->add<mithep::StableDataArr>(stableData_,stableDataName_);
|
60 |
tws.AddBranch(decayDataName_, &decayData_);
|
61 |
OS()->add<mithep::DecayDataArr>(decayData_,decayDataName_);
|
62 |
|
63 |
if (!vertexMapName_.empty()) {
|
64 |
vertexMap_ = OS()->get<VertexMap>(vertexMapName_);
|
65 |
if (vertexMap_)
|
66 |
AddBranchDep(mitName_,vertexMap_->GetBrName());
|
67 |
}
|
68 |
|
69 |
for (std::vector<std::string>::const_iterator bmapName = basePartMapNames_.begin();
|
70 |
bmapName!=basePartMapNames_.end(); ++bmapName) {
|
71 |
if (!bmapName->empty()) {
|
72 |
const BasePartMap *map = OS()->get<BasePartMap>(*bmapName);
|
73 |
if (map) {
|
74 |
basePartMaps_.push_back(map);
|
75 |
AddBranchDep(stableDataName_,map->GetBrName());
|
76 |
AddBranchDep(decayDataName_,map->GetBrName());
|
77 |
}
|
78 |
}
|
79 |
}
|
80 |
}
|
81 |
|
82 |
//--------------------------------------------------------------------------------------------------
|
83 |
void FillerDecayParts::FillDataBlock(const edm::Event &evt,
|
84 |
const edm::EventSetup &setup)
|
85 |
{
|
86 |
// Fill the EDM DecayPart collection into the MIT DecayParticle collection.
|
87 |
|
88 |
decays_->Delete();
|
89 |
stableData_->Delete();
|
90 |
decayData_->Delete();
|
91 |
|
92 |
Handle<mitedm::DecayPartCol> hParts;
|
93 |
GetProduct(edmName_, hParts, evt);
|
94 |
const mitedm::DecayPartCol *iParts = hParts.product();
|
95 |
|
96 |
// loop through all DecayParts and fill the information
|
97 |
for (UInt_t i=0; i<iParts->size(); ++i) {
|
98 |
const mitedm::DecayPart &p = iParts->at(i); // for convenience
|
99 |
mithep::DecayParticle *d = decays_->Allocate();
|
100 |
new (d) mithep::DecayParticle(p.pid());
|
101 |
|
102 |
d->SetMassError(p.fittedMassError());
|
103 |
d->SetLxy(p.lxyToPv());
|
104 |
d->SetLxyError(p.lxyToPvError());
|
105 |
d->SetDxy(p.dxyToPv());
|
106 |
d->SetDxyError(p.dxyToPvError());
|
107 |
d->SetLz(p.lzToPv());
|
108 |
d->SetLzError(p.lzToPvError());
|
109 |
d->SetMom(p.fourMomentum());
|
110 |
d->SetChi2(p.chi2());
|
111 |
d->SetNdof(p.ndof());
|
112 |
|
113 |
if (p.primaryVertex().isNonnull()) {
|
114 |
d->SetPriVertex(vertexMap_->GetMit(p.primaryVertex()));
|
115 |
}
|
116 |
|
117 |
if (basePartMaps_.size()) {
|
118 |
// loop through and add stable daughters
|
119 |
for (Int_t j=0; j<p.nStableChild(); ++j) {
|
120 |
const mitedm::StableData &stable = p.getStableData(j);
|
121 |
mitedm::BasePartPtr thePtr = stable.originalPtr();
|
122 |
mithep::Particle *daughter = getMitParticle(thePtr);
|
123 |
|
124 |
mithep::StableData *outStable = stableData_->Allocate();
|
125 |
new (outStable) mithep::StableData(daughter,
|
126 |
stable.p3().x(),stable.p3().y(),stable.p3().z());
|
127 |
|
128 |
// fill bad layer mask information using corrected HitPattern
|
129 |
const ChargedParticle *cDaughter = dynamic_cast<const ChargedParticle*>(daughter);
|
130 |
if (stable.HitsFilled() && cDaughter) {
|
131 |
const reco::HitPattern &hitPattern = stable.Hits();
|
132 |
BitMask48 crossedLayers;
|
133 |
UInt_t numCrossed=0;
|
134 |
// search for all good crossed layers (with or without hit)
|
135 |
for (Int_t hi=0; hi<hitPattern.numberOfHits(); hi++) {
|
136 |
uint32_t hit = hitPattern.getHitPattern(hi);
|
137 |
if (hitPattern.getHitType(hit)<=1) {
|
138 |
if (hitPattern.trackerHitFilter(hit)) {
|
139 |
numCrossed++;
|
140 |
crossedLayers.SetBit(hitReader_.Layer(hit));
|
141 |
}
|
142 |
}
|
143 |
}
|
144 |
|
145 |
BitMask48 badLayers = crossedLayers ^ cDaughter->Trk()->Hits();
|
146 |
outStable->SetBadLayers(badLayers);
|
147 |
|
148 |
if(verbose_>1) {
|
149 |
if (outStable->NWrongHits()) {
|
150 |
printf("numCrossed: %i\n",numCrossed);
|
151 |
printf("Hit Pattern Size: %i\n",hitPattern.numberOfHits());
|
152 |
printf("# of hits: %i\n",cDaughter->Trk()->NHits());
|
153 |
printf("# of crossed layers: %i\n",crossedLayers.NBitsSet());
|
154 |
printf("# of wrong/missing layers: %i\n",badLayers.NBitsSet());
|
155 |
printf("# of missed hits: %i\n",outStable->NMissedHits());
|
156 |
printf("# of wrong hits: %i\n",outStable->NWrongHits());
|
157 |
printf("Hits : ");
|
158 |
for (Int_t biti=63; biti >= 0; --biti) {
|
159 |
printf("%i",cDaughter->Trk()->Hits().TestBit(biti));
|
160 |
}
|
161 |
printf("\n");
|
162 |
printf("Crossed Layers : ");
|
163 |
for (Int_t biti=63; biti >= 0; --biti) {
|
164 |
printf("%i",crossedLayers.TestBit(biti));
|
165 |
}
|
166 |
printf("\n");
|
167 |
printf("WrongOrMissingHits: ");
|
168 |
for (Int_t biti=63; biti>=0; --biti) {
|
169 |
printf("%i",badLayers.TestBit(biti));
|
170 |
}
|
171 |
printf("\n");
|
172 |
}
|
173 |
}
|
174 |
}
|
175 |
|
176 |
d->AddDaughterData(outStable);
|
177 |
}
|
178 |
|
179 |
// loop through and add decay daughters
|
180 |
for (Int_t j=0; j<p.nDecayChild(); ++j) {
|
181 |
const mitedm::DecayData &decay = p.getDecayData(j);
|
182 |
mitedm::BasePartPtr thePtr = decay.originalPtr();
|
183 |
mithep::Particle *daughter = getMitParticle(thePtr);
|
184 |
|
185 |
mithep::DecayData *outDecay = decayData_->Allocate();
|
186 |
new (outDecay) mithep::DecayData(daughter,decay.p4());
|
187 |
outDecay->SetMassError(decay.massErr());
|
188 |
outDecay->SetLxy(decay.lxy());
|
189 |
outDecay->SetLxyError(decay.lxyErr());
|
190 |
outDecay->SetLz(decay.lz());
|
191 |
outDecay->SetLzError(decay.lzErr());
|
192 |
outDecay->SetDxy(decay.dxy());
|
193 |
outDecay->SetDxyError(decay.dxyErr());
|
194 |
|
195 |
d->AddDaughterData(outDecay);
|
196 |
}
|
197 |
}
|
198 |
}
|
199 |
decays_->Trim();
|
200 |
stableData_->Trim();
|
201 |
decayData_->Trim();
|
202 |
}
|
203 |
|
204 |
//--------------------------------------------------------------------------------------------------
|
205 |
mithep::Particle *FillerDecayParts::getMitParticle(mitedm::BasePartPtr ptr) const
|
206 |
{
|
207 |
// Return our particle referenced by the edm pointer.
|
208 |
|
209 |
mithep::Particle *mitPart = 0;
|
210 |
for (std::vector<const mithep::BasePartMap*>::const_iterator bmap = basePartMaps_.begin();
|
211 |
bmap!=basePartMaps_.end(); ++bmap) {
|
212 |
const mithep::BasePartMap *theMap = *bmap;
|
213 |
if (theMap->HasMit(ptr)) {
|
214 |
mitPart = theMap->GetMit(ptr);
|
215 |
return mitPart;
|
216 |
}
|
217 |
}
|
218 |
|
219 |
if (!mitPart)
|
220 |
throw edm::Exception(edm::errors::Configuration, "FillerDecayParts::FillDataBlock()\n")
|
221 |
<< "Error! MITHEP Object "
|
222 |
<< "not found in AssociationMaps (" << typeid(*this).name() << ")." << std::endl;
|
223 |
|
224 |
return mitPart;
|
225 |
}
|