37 selection_eff(iConfig.getUntrackedParameter<
bool>(
"selection_eff",
false)),
38 selection_fake(iConfig.getUntrackedParameter<
bool>(
"selection_fake",
true)),
39 ZmassSelection_(iConfig.getUntrackedParameter<
bool>(
"ZmassSelection",
false)),
40 simobject(iConfig.getUntrackedParameter<
std::
string>(
"simobject",
"g4SimHits")),
41 trackassociator(iConfig.getUntrackedParameter<
std::
string>(
"TrackAssociator",
"ByHits")),
47 rootfile_(iConfig.getUntrackedParameter<
std::
string>(
"rootfile",
"myroot.root")),
53 label, [
this](
const edm::InputTag& lab) {
return consumes<reco::TrackToTrackingParticleAssociator>(lab); })} {
55 mzmu = 0., recmzmu = 0., ptzmu = 0., recptzmu = 0., etazmu = 0., recetazmu = 0., thetazmu = 0., recthetazmu = 0.,
56 phizmu = 0., recphizmu = 0.;
57 recenezmu = 0., enezmu = 0., pLzmu = 0., recpLzmu = 0., yzmu = 0., recyzmu = 0., mxptmu = 0., recmxptmu = 0.,
58 minptmu = 0., recminptmu = 0.;
61 flag = 0, flagrec = 0,
count = 0, countrec = 0;
64 for (
int i = 0;
i < 2;
i++) {
67 for (
int j = 0;
j < 2;
j++) {
85 file_ =
new TFile(rootfile_.c_str(),
"RECREATE");
88 tree_eff =
new TTree(
"EffTracks",
"Efficiency Tracks Tree");
90 tree_eff->Branch(
"Run", &irun,
"irun/i");
91 tree_eff->Branch(
"Event", &ievt,
"ievt/i");
94 tree_eff->Branch(
"TrackID", &
trackType,
"trackType/i");
95 tree_eff->Branch(
"pt", &
pt,
"pt/F");
96 tree_eff->Branch(
"eta", &
eta,
"eta/F");
97 tree_eff->Branch(
"CotTheta", &cottheta,
"cottheta/F");
98 tree_eff->Branch(
"phi", &
phi,
"phi/F");
99 tree_eff->Branch(
"d0", &
d0,
"d0/F");
100 tree_eff->Branch(
"z0", &
z0,
"z0/F");
101 tree_eff->Branch(
"nhit", &nhit,
"nhit/i");
104 tree_eff->Branch(
"recpt", &recpt,
"recpt/F");
105 tree_eff->Branch(
"receta", &receta,
"receta/F");
106 tree_eff->Branch(
"CotRecTheta", &reccottheta,
"reccottheta/F");
107 tree_eff->Branch(
"recphi", &recphi,
"recphi/F");
108 tree_eff->Branch(
"recd0", &recd0,
"recd0/F");
109 tree_eff->Branch(
"recz0", &recz0,
"recz0/F");
110 tree_eff->Branch(
"nAssoc", &
nAssoc,
"nAssoc/i");
111 tree_eff->Branch(
"recnhit", &recnhit,
"recnhit/i");
112 tree_eff->Branch(
"CHISQ", &recchiq,
"recchiq/F");
114 tree_eff->Branch(
"reseta", &reseta,
"reseta/F");
115 tree_eff->Branch(
"respt", &respt,
"respt/F");
116 tree_eff->Branch(
"resd0", &resd0,
"resd0/F");
117 tree_eff->Branch(
"resz0", &resz0,
"resz0/F");
118 tree_eff->Branch(
"resphi", &resphi,
"resphi/F");
119 tree_eff->Branch(
"rescottheta", &rescottheta,
"rescottheta/F");
120 tree_eff->Branch(
"eff", &eff,
"eff/F");
123 tree_eff->Branch(
"mzmu", &mzmu,
"mzmu/F");
124 tree_eff->Branch(
"ptzmu", &ptzmu,
"ptzmu/F");
125 tree_eff->Branch(
"pLzmu", &pLzmu,
"pLzmu/F");
126 tree_eff->Branch(
"enezmu", &enezmu,
"enezmu/F");
127 tree_eff->Branch(
"etazmu", &etazmu,
"etazmu/F");
128 tree_eff->Branch(
"thetazmu", &thetazmu,
"thetazmu/F");
129 tree_eff->Branch(
"phizmu", &phizmu,
"phizmu/F");
130 tree_eff->Branch(
"yzmu", &yzmu,
"yzmu/F");
131 tree_eff->Branch(
"mxptmu", &mxptmu,
"mxptmu/F");
132 tree_eff->Branch(
"minptmu", &minptmu,
"minptmu/F");
134 tree_eff->Branch(
"recmzmu", &recmzmu,
"recmzmu/F");
135 tree_eff->Branch(
"recptzmu", &recptzmu,
"recptzmu/F");
136 tree_eff->Branch(
"recpLzmu", &recpLzmu,
"recpLzmu/F");
137 tree_eff->Branch(
"recenezmu", &recenezmu,
"recenezmu/F");
138 tree_eff->Branch(
"recetazmu", &recetazmu,
"recetazmu/F");
139 tree_eff->Branch(
"recthetazmu", &recthetazmu,
"recthetazmu/F");
140 tree_eff->Branch(
"recphizmu", &recphizmu,
"recphizmu/F");
141 tree_eff->Branch(
"recyzmu", &recyzmu,
"recyzmu/F");
142 tree_eff->Branch(
"recmxptmu", &recmxptmu,
"recmxptmu/F");
143 tree_eff->Branch(
"recminptmu", &recminptmu,
"recminptmu/F");
147 tree_eff->Branch(
"chi2Associator", &recchiq,
"recchiq/F");
151 tree_fake =
new TTree(
"FakeTracks",
"Fake Rate Tracks Tree");
153 tree_fake->Branch(
"Run", &irun,
"irun/i");
154 tree_fake->Branch(
"Event", &ievt,
"ievt/i");
157 tree_fake->Branch(
"fakeTrackID", &faketrackType,
"faketrackType/i");
158 tree_fake->Branch(
"fakept", &fakept,
"fakept/F");
159 tree_fake->Branch(
"fakeeta", &fakeeta,
"fakeeta/F");
160 tree_fake->Branch(
"fakeCotTheta", &fakecottheta,
"fakecottheta/F");
161 tree_fake->Branch(
"fakephi", &fakephi,
"fakephi/F");
162 tree_fake->Branch(
"faked0", &faked0,
"faked0/F");
163 tree_fake->Branch(
"fakez0", &fakez0,
"fakez0/F");
164 tree_fake->Branch(
"fakenhit", &fakenhit,
"fakenhit/i");
167 tree_fake->Branch(
"fakerecpt", &fakerecpt,
"fakerecpt/F");
168 tree_fake->Branch(
"fakereceta", &fakereceta,
"fakereceta/F");
169 tree_fake->Branch(
"fakeCotRecTheta", &fakereccottheta,
"fakereccottheta/F");
170 tree_fake->Branch(
"fakerecphi", &fakerecphi,
"fakerecphi/F");
171 tree_fake->Branch(
"fakerecd0", &fakerecd0,
"fakerecd0/F");
172 tree_fake->Branch(
"fakerecz0", &fakerecz0,
"fakerecz0/F");
173 tree_fake->Branch(
"fakenAssoc", &fakenAssoc,
"fakenAssoc/i");
174 tree_fake->Branch(
"fakerecnhit", &fakerecnhit,
"fakerecnhit/i");
175 tree_fake->Branch(
"fakeCHISQ", &fakerecchiq,
"fakerecchiq/F");
177 tree_fake->Branch(
"fakereseta", &fakereseta,
"fakereseta/F");
178 tree_fake->Branch(
"fakerespt", &fakerespt,
"fakerespt/F");
179 tree_fake->Branch(
"fakeresd0", &fakeresd0,
"fakeresd0/F");
180 tree_fake->Branch(
"fakeresz0", &fakeresz0,
"fakeresz0/F");
181 tree_fake->Branch(
"fakeresphi", &fakeresphi,
"fakeresphi/F");
182 tree_fake->Branch(
"fakerescottheta", &fakerescottheta,
"fakerescottheta/F");
183 tree_fake->Branch(
"fake", &fake,
"fake/F");
186 tree_fake->Branch(
"fakemzmu", &fakemzmu,
"fakemzmu/F");
187 tree_fake->Branch(
"fakeptzmu", &fakeptzmu,
"fakeptzmu/F");
188 tree_fake->Branch(
"fakepLzmu", &fakepLzmu,
"fakepLzmu/F");
189 tree_fake->Branch(
"fakeenezmu", &fakeenezmu,
"fakeenezmu/F");
190 tree_fake->Branch(
"fakeetazmu", &fakeetazmu,
"fakeetazmu/F");
191 tree_fake->Branch(
"fakethetazmu", &fakethetazmu,
"fakethetazmu/F");
192 tree_fake->Branch(
"fakephizmu", &fakephizmu,
"fakephizmu/F");
193 tree_fake->Branch(
"fakeyzmu", &fakeyzmu,
"fakeyzmu/F");
194 tree_fake->Branch(
"fakemxptmu", &fakemxptmu,
"fakemxptmu/F");
195 tree_fake->Branch(
"fakeminptmu", &fakeminptmu,
"fakeminptmu/F");
197 tree_fake->Branch(
"fakerecmzmu", &fakerecmzmu,
"fakerecmzmu/F");
198 tree_fake->Branch(
"fakerecptzmu", &fakerecptzmu,
"fakerecptzmu/F");
199 tree_fake->Branch(
"fakerecpLzmu", &fakerecpLzmu,
"fakerecpLzmu/F");
200 tree_fake->Branch(
"fakerecenezmu", &fakerecenezmu,
"fakerecenezmu/F");
201 tree_fake->Branch(
"fakerecetazmu", &fakerecetazmu,
"fakerecetazmu/F");
202 tree_fake->Branch(
"fakerecthetazmu", &fakerecthetazmu,
"fakerecthetazmu/F");
203 tree_fake->Branch(
"fakerecphizmu", &fakerecphizmu,
"fakerecphizmu/F");
204 tree_fake->Branch(
"fakerecyzmu", &fakerecyzmu,
"fakerecyzmu/F");
205 tree_fake->Branch(
"fakerecmxptmu", &fakerecmxptmu,
"fakerecmxptmu/F");
206 tree_fake->Branch(
"fakerecminptmu", &fakerecminptmu,
"fakerecminptmu/F");
208 tree_fake->Branch(
"fakechi2Associator", &fakerecchiq,
"fakerecchiq/F");
213 <<
"ValidationMisalignedTracker::endJob Processed " <<
eventCount_ <<
" events";
229 desc.add<std::vector<edm::InputTag> >(
"label", {});
232 desc.add<std::vector<std::string> >(
"associators", {});
233 desc.addUntracked<
bool>(
"selection_eff",
false);
234 desc.addUntracked<
bool>(
"selection_fake",
true);
235 desc.addUntracked<
bool>(
"ZmassSelection",
false);
239 descriptions.
add(
"validationMisAlignedTracker",
desc);
244 std::vector<const reco::TrackToTrackingParticleAssociator*> associatore;
249 associatore.push_back(theAssociator.
product());
253 edm::LogInfo(
"Tracker Misalignment Validation") <<
"\n Starting!";
257 std::vector<int> indmu;
261 bool accepted =
false;
262 bool foundmuons =
false;
265 for (HepMC::GenEvent::particle_iterator
p = myGenEvent->particles_begin();
p != myGenEvent->particles_end(); ++
p) {
266 if (!accepted && ((*p)->pdg_id() == 23) && (*p)->status() == 3) {
268 for (HepMC::GenVertex::particle_iterator aDaughter = (*p)->end_vertex()->particles_begin(HepMC::descendants);
269 aDaughter != (*p)->end_vertex()->particles_end(HepMC::descendants);
271 if (
abs((*aDaughter)->pdg_id()) == 13) {
273 if ((*aDaughter)->status() != 1) {
274 for (HepMC::GenVertex::particle_iterator byaDaughter =
275 (*aDaughter)->end_vertex()->particles_begin(HepMC::descendants);
276 byaDaughter != (*aDaughter)->end_vertex()->particles_end(HepMC::descendants);
278 if ((*byaDaughter)->status() == 1 &&
abs((*byaDaughter)->pdg_id()) == 13) {
279 indmu.push_back((*byaDaughter)->barcode());
281 <<
"Stable muon from Z with charge " << (*byaDaughter)->pdg_id() <<
" and index " 282 << (*byaDaughter)->barcode();
286 indmu.push_back((*aDaughter)->barcode());
288 <<
"Stable muon from Z with charge " << (*aDaughter)->pdg_id() <<
" and index " 289 << (*aDaughter)->barcode();
294 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
"No muons from Z ...skip event";
300 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
"No Z particles in the event ...skip event";
311 auto testGeomDet = trackerGeometry->
detsTOB().front();
324 for (
int i = 0;
i < 2;
i++) {
325 for (
int j = 0;
j < 2;
j++) {
355 LogTrace(
"TrackValidator") <<
"Calling associateRecoToSim method\n";
358 LogTrace(
"TrackValidator") <<
"Calling associateSimToReco method\n";
368 edm::LogVerbatim(
"TrackValidator") <<
"\n# of TrackingParticles (before cuts): " << tPCeff.size() <<
"\n";
384 if (
tp->charge() == 0)
391 const SimTrack* simulatedTrack = &(*
tp->g4Track_begin());
402 tscpBuilder(ftsAtProduction,
GlobalPoint(0, 0, 0));
409 double dxySim = (-
v.x() *
sin(
p.phi()) +
v.y() *
cos(
p.phi()));
410 double dszSim =
v.z() *
p.perp() /
p.mag() - (
v.x() *
p.x() +
v.y() *
p.y()) /
p.perp() *
p.z() /
p.mag();
415 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
" TRACCIA SIM DI MUONI ";
428 <<
"3) Before assoc: SimTrack of type = " << simulatedTrack->
type() <<
" ,at eta = " <<
eta 429 <<
" ,with pt at vertex = " << simulatedTrack->
momentum().pt() <<
" GeV/c" 430 <<
" ,d0 =" <<
d0 <<
" ,z0 =" <<
z0 <<
" ,nhit=" <<
nhit;
435 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
" TRACK sim of muons from Z ";
453 std::vector<std::pair<edm::RefToBase<reco::Track>,
double> >
rt;
454 if (simRecColl.
find(
tp) != simRecColl.
end()) {
466 edm::LogVerbatim(
"TrackValidator") <<
"TrackingParticle #" << st <<
" with pt=" <<
t->pt()
467 <<
" associated with quality:" <<
rt.begin()->second <<
"\n";
468 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
"Reconstructed Track:" <<
t->pt();
470 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
"\timpact parameter:d0: " <<
t->d0();
471 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
"\timpact parameter:z0: " <<
t->dz();
473 <<
"\tAzimuthal angle of point of closest approach:" <<
t->phi();
476 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
"\tnormalizedChi2: " <<
t->normalizedChi2();
492 <<
"5) After call to associator: the best match has " <<
recnhit <<
" hits, Chi2 = " <<
recchiq 493 <<
", pt at vertex = " <<
recpt <<
" GeV/c, " 494 <<
", recd0 = " <<
recd0 <<
", recz0= " <<
recz0;
505 <<
"6) Transverse momentum residual=" <<
respt <<
" ,d0 residual=" <<
resd0 506 <<
" ,z0 residual=" <<
resz0 <<
" with eff=" <<
eff;
510 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
" TRACCIA RECO DI MUONI ";
515 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
" TRACCIA RECO DI ELETTRONI ";
526 sqrt((
t->momentum().x() *
t->momentum().x()) + (
t->momentum().y() *
t->momentum().y()));
538 <<
"TrackingParticle #" << st <<
" with pt=" <<
sqrt(
tp->momentum().perp2())
539 <<
" NOT associated to any reco::Track" 568 (
py[0][0] +
py[0][1]) * (
py[0][0] +
py[0][1]) - (
pz[0][0] +
pz[0][1]) * (
pz[0][0] +
pz[0][1]));
682 <<
"\tAzimuthal angle of point of closest approach:" <<
track->phi();
687 std::vector<std::pair<TrackingParticleRef, double> >
tp;
694 <<
" associated with quality:" <<
tp.begin()->second <<
"\n";
697 const SimTrack* fakeassocTrack = &(*tpr->g4Track_begin());
701 GlobalPoint(tpr->vertex().x(), tpr->vertex().y(), tpr->vertex().z()),
708 tscpBuilder(ftsAtProduction,
GlobalPoint(0, 0, 0));
715 double dxySim = (-
v.x() *
sin(
p.phi()) +
v.y() *
cos(
p.phi()));
716 double dszSim =
v.z() *
p.perp() /
p.mag() - (
v.x() *
p.x() +
v.y() *
p.y()) /
p.perp() *
p.z() /
p.mag();
729 <<
"4) After call to associator: the best SimTrack match is of type" << fakeassocTrack->
type()
744 <<
"reco::Track #" << rT <<
" with pt=" <<
track->pt() <<
" NOT associated to any TrackingParticle" 773 edm::LogVerbatim(
"ValidationMisalignedTracker") <<
"\t Misalignment analysis completed \n";
Log< level::Info, true > LogVerbatim
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_
const std::vector< std::string > associators
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
example_stream int eventCount_
Sin< T >::type sin(const T &t)
T const * product() const
Global3DPoint GlobalPoint
const edm::EDGetTokenT< TrackingParticleCollection > tpeffToken_
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
void analyze(const edm::Event &, const edm::EventSetup &) override
const edm::EDGetTokenT< edm::View< reco::Track > > trackToken_
const math::XYZTLorentzVectorD & momentum() const
const_iterator find(const key_type &k) const
find element with specified reference key
const edm::EDGetTokenT< edm::HepMCProduct > evtToken_
const_iterator end() const
last iterator over the map (read only)
ValidationMisalignedTracker(const edm::ParameterSet &)
GlobalPoint position() const
int type() const
particle type (HEP PDT convension)
const edm::EDGetTokenT< TrackingParticleCollection > tpfakeToken_
const DetContainer & detsTOB() const
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > geomToken_
const std::vector< edm::EDGetTokenT< reco::TrackToTrackingParticleAssociator > > assocToken_
const std::vector< edm::InputTag > label
Cos< T >::type cos(const T &t)
Tan< T >::type tan(const T &t)
GlobalVector momentum() const
Abs< T >::type abs(const T &t)
#define DEFINE_FWK_MODULE(type)
const HepMC::GenEvent * GetEvent() const
Log< level::Info, false > LogInfo
const bool selection_fake
static constexpr float d0
const FreeTrajectoryState & theState() const
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
~ValidationMisalignedTracker() override
std::vector< TrackingParticle > TrackingParticleCollection
std::vector< float > ptused
const bool ZmassSelection_
Global3DVector GlobalVector
int genpartIndex() const
index of the corresponding Generator particle in the Event container (-1 if no Genpart) ...