diff --git a/Validation/MuonHits/BuildFile.xml b/Validation/MuonHits/BuildFile.xml
index 8896987508d9c..9dd05125a275c 100644
--- a/Validation/MuonHits/BuildFile.xml
+++ b/Validation/MuonHits/BuildFile.xml
@@ -10,7 +10,12 @@
+
+
+
-
+
+
+
diff --git a/Validation/MuonHits/interface/CSCSimHitMatcher.h b/Validation/MuonHits/interface/CSCSimHitMatcher.h
new file mode 100644
index 0000000000000..f8d9c59458a61
--- /dev/null
+++ b/Validation/MuonHits/interface/CSCSimHitMatcher.h
@@ -0,0 +1,79 @@
+#ifndef Validation_MuonHits_CSCSimHitMatcher_h
+#define Validation_MuonHits_CSCSimHitMatcher_h
+
+/**\class CSCSimHitMatcher
+
+ Description: Matching of CSC SimHit to SimTrack
+
+ Author: Sven Dildick (TAMU), Tao Huang (TAMU)
+*/
+
+#include "Geometry/CSCGeometry/interface/CSCGeometry.h"
+#include "Validation/MuonHits/interface/MuonSimHitMatcher.h"
+
+class CSCSimHitMatcher : public MuonSimHitMatcher {
+ public:
+ // constructor
+ CSCSimHitMatcher(const edm::ParameterSet& iPS, edm::ConsumesCollector&& iC);
+
+ // destructor
+ ~CSCSimHitMatcher() {}
+
+ // initialize the event
+ void init(const edm::Event& e, const edm::EventSetup& eventSetup);
+
+ // do the matching
+ void match(const SimTrack& t, const SimVertex& v);
+
+ // partitions' detIds with SimHits
+ std::set detIds(int type = MuonHitHelper::CSC_ALL) const;
+
+ // chamber detIds with SimHits
+ std::set chamberIds(int type = MuonHitHelper::CSC_ALL) const;
+
+ // CSC station detIds with SimHits
+ std::set chamberIdsStation(int station) const;
+
+ // was there a hit in a particular CSC station?
+ bool hitStation(int, int) const;
+
+ // number of stations with hits in at least X layers
+ int nStations(int nl = 4) const;
+
+ // #layers with hits
+ int nLayersWithHitsInChamber(unsigned int) const;
+
+ // How many CSC chambers with minimum number of layer with simhits did this
+ // simtrack get?
+ int nCoincidenceChambers(int min_n_layers = 4) const;
+
+ // calculated the fitted position in a given layer for CSC simhits in a
+ // chamber
+ GlobalPoint simHitPositionKeyLayer(unsigned int chamberid) const;
+
+ // local bending in a CSC chamber
+ float LocalBendingInChamber(unsigned int detid) const;
+
+ // calculate average strip number for a provided collection of simhits
+ float simHitsMeanStrip(const edm::PSimHitContainer& sim_hits) const;
+
+ // calculate average wg number for a provided collection of simhits (for CSC)
+ float simHitsMeanWG(const edm::PSimHitContainer& sim_hits) const;
+
+ void chamberIdsToString(const std::set& set) const;
+
+ // calculate the average position at the second station
+ GlobalPoint simHitsMeanPositionStation(int n) const;
+
+ std::set hitStripsInDetId(unsigned int, int margin_n_strips = 0) const;
+ std::set hitWiregroupsInDetId(unsigned int, int margin_n_wg = 0) const;
+
+ void camberIdsToString(const std::set&) const;
+
+ private:
+ void matchSimHitsToSimTrack();
+
+ edm::ESHandle csc_geom_;
+};
+
+#endif
diff --git a/Validation/MuonHits/interface/DTSimHitMatcher.h b/Validation/MuonHits/interface/DTSimHitMatcher.h
new file mode 100644
index 0000000000000..98895b6b0a515
--- /dev/null
+++ b/Validation/MuonHits/interface/DTSimHitMatcher.h
@@ -0,0 +1,82 @@
+#ifndef Validation_MuonHits_DTSimHitMatcher_h
+#define Validation_MuonHits_DTSimHitMatcher_h
+
+/**\class DTSimHitMatcher
+
+ Description: Matching of DT SimHit to SimTrack
+
+ Author: Sven Dildick (TAMU), Tao Huang (TAMU)
+*/
+
+#include "Geometry/DTGeometry/interface/DTGeometry.h"
+#include "Validation/MuonHits/interface/MuonSimHitMatcher.h"
+
+class DTSimHitMatcher : public MuonSimHitMatcher {
+ public:
+ // constructor
+ DTSimHitMatcher(const edm::ParameterSet& iPS, edm::ConsumesCollector&& iC);
+
+ // destructor
+ ~DTSimHitMatcher() {}
+
+ // initialize the event
+ void init(const edm::Event& e, const edm::EventSetup& eventSetup);
+
+ // do the matching
+ void match(const SimTrack& t, const SimVertex& v);
+
+ // partitions' detIds with SimHits
+ std::set detIds(int type = MuonHitHelper::DT_ALL) const;
+
+ // chamber detIds with SimHits
+ std::set chamberIds(int type = MuonHitHelper::DT_ALL) const;
+
+ // DT station detIds with SimHits
+ std::set chamberIdsStation(int station) const;
+
+ // DT layer detIds with SimHits
+ std::set layerIds() const;
+
+ // DT super layer detIds with SimHits
+ std::set superlayerIds() const;
+
+ // was there a hit in a particular DT/CSC station?
+ bool hitStation(int, int, int) const;
+
+ // number of stations with hits in at least X layers
+ int nStations(int nsl = 1, int nl = 3) const;
+
+ // access to DT hits
+ int nCellsWithHitsInLayer(unsigned int) const;
+ int nLayersWithHitsInSuperLayer(unsigned int) const;
+ int nSuperLayersWithHitsInChamber(unsigned int) const;
+ int nLayersWithHitsInChamber(unsigned int) const;
+ const edm::PSimHitContainer& hitsInLayer(unsigned int) const;
+ const edm::PSimHitContainer& hitsInSuperLayer(unsigned int) const;
+ const edm::PSimHitContainer& hitsInChamber(unsigned int) const;
+
+ // calculate average wg number for a provided collection of simhits
+ float simHitsMeanWire(const edm::PSimHitContainer& sim_hits) const;
+
+ // calculate the average position at the second station
+ GlobalPoint simHitsMeanPositionStation(int n) const;
+
+ std::set hitWiresInDTLayerId(
+ unsigned int, int margin_n_wires = 0) const; // DT
+ std::set hitWiresInDTSuperLayerId(
+ unsigned int, int margin_n_wires = 0) const; // DT
+ std::set hitWiresInDTChamberId(
+ unsigned int, int margin_n_wires = 0) const; // DT
+
+ void dtChamberIdsToString(const std::set&) const;
+
+ private:
+ void matchSimHitsToSimTrack();
+
+ std::map layer_to_hits_;
+ std::map superlayer_to_hits_;
+
+ edm::ESHandle dt_geom_;
+};
+
+#endif
diff --git a/Validation/MuonHits/interface/GEMSimHitMatcher.h b/Validation/MuonHits/interface/GEMSimHitMatcher.h
new file mode 100644
index 0000000000000..eda6fe813bbbd
--- /dev/null
+++ b/Validation/MuonHits/interface/GEMSimHitMatcher.h
@@ -0,0 +1,90 @@
+#ifndef Validation_MuonHits_GEMSimHitMatcher_h
+#define Validation_MuonHits_GEMSimHitMatcher_h
+
+/**\class GEMSimHitMatcher
+
+ Description: Matching of GEM SimHit to SimTrack
+
+ Author: Sven Dildick (TAMU), Tao Huang (TAMU)
+*/
+
+#include "Geometry/GEMGeometry/interface/GEMGeometry.h"
+#include "Validation/MuonHits/interface/MuonSimHitMatcher.h"
+
+class GEMSimHitMatcher : public MuonSimHitMatcher {
+ public:
+ // constructor
+ GEMSimHitMatcher(const edm::ParameterSet& iPS, edm::ConsumesCollector&& iC);
+
+ // destructor
+ ~GEMSimHitMatcher() {}
+
+ // initialize the event
+ void init(const edm::Event& e, const edm::EventSetup& eventSetup);
+
+ // do the matching
+ void match(const SimTrack& t, const SimVertex& v);
+
+ // partitions' detIds with SimHits
+ std::set detIds(int gem_type = MuonHitHelper::GEM_ALL) const;
+
+ // chamber detIds with SimHits
+ std::set chamberIds(
+ int gem_type = MuonHitHelper::GEM_ALL) const;
+
+ // GEM detid's with hits in 2 layers of coincidence pads
+ // those are layer==1 only detid's
+ std::set detIdsCoincidences() const;
+
+ // GEM superchamber detIds with SimHits
+ std::set superChamberIds() const;
+
+ // GEM superchamber detIds with SimHits 2 layers of coincidence pads
+ std::set superChamberIdsCoincidences() const;
+
+ // simhits from a particular superchamber
+ const edm::PSimHitContainer& hitsInSuperChamber(unsigned int) const;
+
+ // was there a hit in a particular station?
+ bool hitStation(int, int) const;
+
+ // number of stations with hits in at least X layers
+ int nStations(int nl = 2) const;
+
+ // #layers with hits
+ int nLayersWithHitsInSuperChamber(unsigned int) const;
+
+ // How many pads with simhits in GEM did this simtrack get?
+ int nPadsWithHits() const;
+
+ // How many coincidence pads with simhits in GEM did this simtrack get?
+ int nCoincidencePadsWithHits() const;
+
+ // transverse position in GEM
+ float simHitsGEMCentralPosition(const edm::PSimHitContainer& sim_hits) const;
+
+ // calculate average strip number for a provided collection of simhits
+ float simHitsMeanStrip(const edm::PSimHitContainer& sim_hits) const;
+
+ std::set hitStripsInDetId(unsigned int, int margin_n_strips = 0) const;
+ std::set hitPadsInDetId(unsigned int) const;
+ std::set hitCoPadsInDetId(unsigned int) const;
+
+ // what unique partitions numbers were hit by this simtrack?
+ std::set hitPartitions() const;
+
+ private:
+ void matchSimHitsToSimTrack();
+
+ edm::ESHandle gem_geom_;
+
+ std::map superchamber_to_hits_;
+
+ // detids with hits in pads
+ std::map > detids_to_pads_;
+
+ // detids with hits in 2-layer pad coincidences
+ std::map > detids_to_copads_;
+};
+
+#endif
diff --git a/Validation/MuonHits/interface/ME0SimHitMatcher.h b/Validation/MuonHits/interface/ME0SimHitMatcher.h
new file mode 100644
index 0000000000000..38b433a65b1e9
--- /dev/null
+++ b/Validation/MuonHits/interface/ME0SimHitMatcher.h
@@ -0,0 +1,77 @@
+#ifndef Validation_MuonHits_ME0SimHitMatcher_h
+#define Validation_MuonHits_ME0SimHitMatcher_h
+
+/**\class ME0SimHitMatcher
+
+ Description: Matching of ME0 SimHit to SimTrack
+
+ Author: Sven Dildick (TAMU), Tao Huang (TAMU)
+*/
+
+#include "Geometry/GEMGeometry/interface/ME0Geometry.h"
+#include "Validation/MuonHits/interface/MuonSimHitMatcher.h"
+
+class ME0SimHitMatcher : public MuonSimHitMatcher {
+ public:
+ // constructor
+ ME0SimHitMatcher(const edm::ParameterSet& iPS, edm::ConsumesCollector&& iC);
+
+ // destructor
+ ~ME0SimHitMatcher() {}
+
+ // initialize the event
+ void init(const edm::Event& e, const edm::EventSetup& eventSetup);
+
+ // do the matching
+ void match(const SimTrack& t, const SimVertex& v);
+
+ // partitions' detIds with SimHits
+ std::set detIds() const;
+
+ // chamber detIds with SimHits
+ std::set chamberIds() const;
+
+ // ME0 superchamber detIds with SimHits
+ std::set superChamberIds() const;
+
+ // simhits from a particular partition, chamber
+ const edm::PSimHitContainer& hitsInSuperChamber(unsigned int) const;
+
+ // #layers with hits
+ int nLayersWithHitsInSuperChamber(unsigned int) const;
+
+ // ME0 superchamber detIds with SimHits >=4 layers of coincidence pads
+ std::set superChamberIdsCoincidences(
+ int min_n_layers = 4) const;
+
+ // How many ME0 chambers with minimum number of layer with simhits did this
+ // simtrack get?
+ int nCoincidenceChambers(int min_n_layers = 4) const;
+
+ // calculate average strip for a provided collection of simhits
+ float simHitsMeanStrip(const edm::PSimHitContainer& sim_hits) const;
+
+ std::set hitStripsInDetId(unsigned int, int margin_n_strips = 0) const;
+ std::set hitPadsInDetId(unsigned int) const;
+
+ // what unique partitions numbers were hit by this simtrack?
+ std::set hitPartitions() const;
+
+ // How many pads with simhits in ME0 did this simtrack get?
+ int nPadsWithHits() const;
+
+ private:
+ void matchSimHitsToSimTrack();
+
+ edm::ESHandle me0_geom_;
+
+ // detids with hits in pads
+ std::map > detids_to_pads_;
+
+ // detids with hits in 2-layer pad coincidences
+ std::map > detids_to_copads_;
+
+ std::map superChamber_to_hits_;
+};
+
+#endif
diff --git a/Validation/MuonHits/interface/MuonHitHelper.h b/Validation/MuonHits/interface/MuonHitHelper.h
new file mode 100644
index 0000000000000..fd97dfd9645c8
--- /dev/null
+++ b/Validation/MuonHits/interface/MuonHitHelper.h
@@ -0,0 +1,109 @@
+#ifndef Validation_MuonHits_MuonHitHelper_h
+#define Validation_MuonHits_MuonHitHelper_h
+
+#include "DataFormats/MuonDetId/interface/CSCDetId.h"
+#include "DataFormats/MuonDetId/interface/CSCTriggerNumbering.h"
+#include "DataFormats/MuonDetId/interface/DTWireId.h"
+#include "DataFormats/MuonDetId/interface/GEMDetId.h"
+#include "DataFormats/MuonDetId/interface/ME0DetId.h"
+#include "DataFormats/MuonDetId/interface/RPCDetId.h"
+
+class MuonHitHelper {
+ public:
+ /// CSC chamber types, according to CSCDetId::iChamberType()
+ enum CSCType {
+ CSC_ALL = 0,
+ CSC_ME11,
+ CSC_ME1a,
+ CSC_ME1b,
+ CSC_ME12,
+ CSC_ME13,
+ CSC_ME21,
+ CSC_ME22,
+ CSC_ME31,
+ CSC_ME32,
+ CSC_ME41,
+ CSC_ME42
+ };
+
+ /// GEM chamber types
+ enum GEMType { GEM_ALL = 0, GEM_ME11, GEM_ME21 };
+
+ /// RPC endcap chamber types
+ enum RPCType {
+ RPC_ALL = 0,
+ RPC_ME12,
+ RPC_ME13,
+ RPC_ME22,
+ RPC_ME23,
+ RPC_ME31,
+ RPC_ME32,
+ RPC_ME33,
+ RPC_ME41,
+ RPC_ME42,
+ RPC_ME43,
+ RPC_MB01,
+ RPC_MB02,
+ RPC_MB03,
+ RPC_MB04,
+ RPC_MB11p,
+ RPC_MB12p,
+ RPC_MB13p,
+ RPC_MB14p,
+ RPC_MB21p,
+ RPC_MB22p,
+ RPC_MB23p,
+ RPC_MB24p,
+ RPC_MB11n,
+ RPC_MB12n,
+ RPC_MB13n,
+ RPC_MB14n,
+ RPC_MB21n,
+ RPC_MB22n,
+ RPC_MB23n,
+ RPC_MB24n
+ };
+
+ /// DT chamber types
+ enum DTType {
+ DT_ALL = 0,
+ DT_MB01,
+ DT_MB02,
+ DT_MB03,
+ DT_MB04,
+ DT_MB11p,
+ DT_MB12p,
+ DT_MB13p,
+ DT_MB14p,
+ DT_MB21p,
+ DT_MB22p,
+ DT_MB23p,
+ DT_MB24p,
+ DT_MB11n,
+ DT_MB12n,
+ DT_MB13n,
+ DT_MB14n,
+ DT_MB21n,
+ DT_MB22n,
+ DT_MB23n,
+ DT_MB24n
+ };
+
+ /// check detid type
+ static bool isDT(unsigned int detId);
+ static bool isGEM(unsigned int detId);
+ static bool isCSC(unsigned int detId);
+ static bool isRPC(unsigned int detId);
+ static bool isME0(unsigned int detId);
+
+ // return MuonType for a particular DetId
+ static int toGEMType(int st, int ri);
+ static int toRPCType(int re, int st, int ri);
+ static int toDTType(int wh, int st);
+ static int toCSCType(int st, int ri);
+
+ // get chamber number
+ static int chamber(const DetId& id);
+};
+
+#endif
diff --git a/Validation/MuonHits/interface/MuonSimHitMatcher.h b/Validation/MuonHits/interface/MuonSimHitMatcher.h
new file mode 100644
index 0000000000000..eb99675850064
--- /dev/null
+++ b/Validation/MuonHits/interface/MuonSimHitMatcher.h
@@ -0,0 +1,109 @@
+#ifndef Validation_MuonHits_MuonSimHitMatcher_h
+#define Validation_MuonHits_MuonSimHitMatcher_h
+
+/**\class MuonSimHitMatcher
+
+ Description: Matching of muon SimHit to SimTrack
+
+ Author: Sven Dildick (TAMU), Tao Huang (TAMU)
+*/
+
+#include "DataFormats/GeometryVector/interface/GlobalPoint.h"
+#include "DataFormats/Math/interface/deltaPhi.h"
+#include "FWCore/Framework/interface/ConsumesCollector.h"
+#include "FWCore/Framework/interface/ESHandle.h"
+#include "FWCore/Framework/interface/Event.h"
+#include "FWCore/Framework/interface/EventSetup.h"
+#include "FWCore/Framework/interface/Frameworkfwd.h"
+#include "FWCore/MessageLogger/interface/MessageLogger.h"
+#include "FWCore/ParameterSet/interface/ParameterSet.h"
+#include "FWCore/Utilities/interface/InputTag.h"
+#include "Geometry/CommonDetUnit/interface/TrackingGeometry.h"
+#include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
+#include "Geometry/Records/interface/MuonGeometryRecord.h"
+#include "SimDataFormats/Track/interface/SimTrackContainer.h"
+#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
+#include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
+#include "Validation/MuonHits/interface/MuonHitHelper.h"
+
+#include