49 theSimTracksToken = consumes<edm::SimTrackContainer>(theSimTracksLabel);
52 theTracksToken = consumes<reco::TrackCollection>(theTracksLabel);
53 doTracksAnalysis =
pset.getUntrackedParameter<
bool>(
"DoTracksAnalysis",
true);
55 doSeedsAnalysis =
pset.getUntrackedParameter<
bool>(
"DoSeedsAnalysis",
false);
56 if (doSeedsAnalysis) {
58 theSeedsToken = consumes<TrajectorySeedCollection>(theSeedsLabel);
60 theSeedPropagatorName = updatorPar.
getParameter<
string>(
"Propagator");
65 theCSCSimHitLabel =
pset.getParameter<
InputTag>(
"CSCSimHit");
66 theDTSimHitLabel =
pset.getParameter<
InputTag>(
"DTSimHit");
67 theRPCSimHitLabel =
pset.getParameter<
InputTag>(
"RPCSimHit");
68 theCSCSimHitToken = consumes<std::vector<PSimHit> >(theCSCSimHitLabel);
69 theDTSimHitToken = consumes<std::vector<PSimHit> >(theDTSimHitLabel);
70 theRPCSimHitToken = consumes<std::vector<PSimHit> >(theRPCSimHitLabel);
72 theEtaRange = (
EtaRange)
pset.getParameter<
int>(
"EtaRange");
75 numberOfSimTracks = 0;
77 numberOfRecTracks = 0;
80 out =
pset.getUntrackedParameter<
string>(
"rootFileName");
82 subsystemname_ =
pset.getUntrackedParameter<
std::string>(
"subSystemFolder",
"YourSubsystem");
99 dirName += algo.
process() +
"_";
100 if (!algo.
label().empty())
101 dirName += algo.
label() +
"_";
104 if (dirName.find(
"Tracks") < dirName.length()) {
105 dirName.replace(dirName.find(
"Tracks"), 6,
"");
112 simName +=
"/SimTracks";
121 if (doSeedsAnalysis) {
124 hRecoSeedInner =
new HTrack(ibooker, dirName,
"RecoSeed",
"Inner");
125 hRecoSeedPCA =
new HTrack(ibooker, dirName,
"RecoSeed",
"PCA");
128 if (doTracksAnalysis) {
131 hRecoTracksPCA =
new HTrack(ibooker, dirName,
"RecoTracks",
"PCA");
132 hRecoTracksInner =
new HTrack(ibooker, dirName,
"RecoTracks",
"Inner");
133 hRecoTracksOuter =
new HTrack(ibooker, dirName,
"RecoTracks",
"Outer");
140 hChi2 = ibooker.
book1D(
"chi2",
"#chi^2", 200, 0, 200);
141 hChi2VsEta = ibooker.
book2D(
"chi2VsEta",
"#chi^2 VS #eta", 120, -3., 3., 200, 0, 200);
143 hChi2Norm = ibooker.
book1D(
"chi2Norm",
"Normalized #chi^2", 400, 0, 100);
144 hChi2NormVsEta = ibooker.
book2D(
"chi2NormVsEta",
"Normalized #chi^2 VS #eta", 120, -3., 3., 400, 0, 100);
146 hHitsPerTrack = ibooker.
book1D(
"HitsPerTrack",
"Number of hits per track", 55, 0, 55);
148 ibooker.
book2D(
"HitsPerTrackVsEta",
"Number of hits per track VS #eta", 120, -3., 3., 55, 0, 55);
150 hDof = ibooker.
book1D(
"dof",
"Number of Degree of Freedom", 55, 0, 55);
151 hDofVsEta = ibooker.
book2D(
"dofVsEta",
"Number of Degree of Freedom VS #eta", 120, -3., 3., 55, 0, 55);
153 hChi2Prob = ibooker.
book1D(
"chi2Prob",
"#chi^2 probability", 200, 0, 1);
154 hChi2ProbVsEta = ibooker.
book2D(
"chi2ProbVsEta",
"#chi^2 probability VS #eta", 120, -3., 3., 200, 0, 1);
156 hNumberOfTracks = ibooker.
book1D(
"NumberOfTracks",
"Number of reconstructed tracks per event", 200, 0, 200);
157 hNumberOfTracksVsEta = ibooker.
book2D(
158 "NumberOfTracksVsEta",
"Number of reconstructed tracks per event VS #eta", 120, -3., 3., 10, 0, 10);
160 hChargeVsEta = ibooker.
book2D(
"ChargeVsEta",
"Charge vs #eta gen", 120, -3., 3., 4, -2., 2.);
161 hChargeVsPt = ibooker.
book2D(
"ChargeVsPt",
"Charge vs P_{T} gen", 250, 0, 200, 4, -2., 2.);
162 hPtRecVsPtGen = ibooker.
book2D(
"PtRecVsPtGen",
"P_{T} rec vs P_{T} gen", 250, 0, 200, 250, 0, 200);
164 hDeltaPtVsEta = ibooker.
book2D(
"DeltaPtVsEta",
"#Delta P_{t} vs #eta gen", 120, -3., 3., 500, -250., 250.);
165 hDeltaPt_In_Out_VsEta =
166 ibooker.
book2D(
"DeltaPt_In_Out_VsEta_",
"P^{in}_{t} - P^{out}_{t} vs #eta gen", 120, -3., 3., 500, -250., 250.);
171 LogDebug(
"MuonTrackAnalyzer") <<
"Run: " <<
event.id().run() <<
" Event: " <<
event.id().event();
174 theService->update(eventSetup);
177 event.getByToken(theSimTracksToken, simTracks);
178 fillPlots(event, simTracks);
180 if (doTracksAnalysis)
181 tracksAnalysis(event, eventSetup, simTracks);
184 seedsAnalysis(event, eventSetup, simTracks);
194 event.getByToken(theSeedsToken, seeds);
196 LogTrace(
"MuonTrackAnalyzer") <<
"Number of reconstructed seeds: " << seeds->size() << endl;
198 for (TrajectorySeedCollection::const_iterator
seed = seeds->begin();
seed != seeds->end(); ++
seed) {
200 pair<SimTrack, double>
sim = getSimTrack(seedTSOS, simTracks);
201 fillPlots(seedTSOS, sim.first, hRecoSeedInner, debug);
203 std::pair<bool, FreeTrajectoryState> propSeed = theUpdator->propagateToNominalLine(seedTSOS);
205 fillPlots(propSeed.second, sim.first, hRecoSeedPCA, debug);
207 LogTrace(
"MuonTrackAnalyzer") <<
"Error in seed propagation" << endl;
218 event.getByToken(theTracksToken, tracks);
220 LogTrace(
"MuonTrackAnalyzer") <<
"Reconstructed tracks: " << tracks->size() << endl;
221 hNumberOfTracks->Fill(tracks->size());
223 if (!tracks->empty())
227 for (reco::TrackCollection::const_iterator
t = tracks->begin();
t != tracks->end(); ++
t) {
234 pair<SimTrack, double>
sim = getSimTrack(pcaTSOS, simTracks);
236 hNumberOfTracksVsEta->Fill(simTrack.
momentum().eta(), tracks->size());
237 fillPlots(
track, simTrack);
239 LogTrace(
"MuonTrackAnalyzer") <<
"State at the outer surface: " << endl;
240 fillPlots(outerTSOS, simTrack, hRecoTracksOuter, debug);
242 LogTrace(
"MuonTrackAnalyzer") <<
"State at the inner surface: " << endl;
243 fillPlots(innerTSOS, simTrack, hRecoTracksInner, debug);
245 LogTrace(
"MuonTrackAnalyzer") <<
"State at PCA: " << endl;
246 fillPlots(pcaTSOS, simTrack, hRecoTracksPCA, debug);
248 double deltaPt_in_out = innerTSOS.
globalMomentum().
perp() - outerTSOS.globalMomentum().perp();
249 hDeltaPt_In_Out_VsEta->Fill(simTrack.
momentum().eta(), deltaPt_in_out);
252 hDeltaPtVsEta->Fill(simTrack.
momentum().eta(), deltaPt_pca_sim);
260 LogTrace(
"MuonTrackAnalyzer") <<
"--------------------------------------------" << endl;
264 if (!checkMuonSimHitPresence(event, simTracks))
268 SimTrackContainer::const_iterator
simTrack;
269 LogTrace(
"MuonTrackAnalyzer") <<
"Simulated tracks: " << simTracks->size() << endl;
271 for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++
simTrack)
272 if (
abs((*simTrack).type()) == 13) {
273 if (!isInTheAcceptance((*simTrack).momentum().eta()))
278 LogTrace(
"MuonTrackAnalyzer") <<
"Simualted muon:" << endl;
279 LogTrace(
"MuonTrackAnalyzer") <<
"Sim pT: " <<
sqrt((*simTrack).momentum().perp2()) << endl;
280 LogTrace(
"MuonTrackAnalyzer") <<
"Sim Eta: " << (*simTrack).momentum().eta() << endl;
282 hSimTracks->Fill((*simTrack).momentum().mag(),
283 sqrt((*simTrack).momentum().perp2()),
284 (*simTrack).momentum().eta(),
285 (*simTrack).momentum().phi(),
286 -(*simTrack).type() /
abs((*simTrack).type()));
287 LogTrace(
"MuonTrackAnalyzer") <<
"hSimTracks filled" << endl;
290 LogTrace(
"MuonTrackAnalyzer") << endl;
294 LogTrace(
"MuonTrackAnalyzer") <<
"Analizer: New track, chi2: " << track.
chi2() <<
" dof: " << track.
ndof() << endl;
295 hChi2->Fill(track.
chi2());
296 hDof->Fill(track.
ndof());
302 hChi2VsEta->Fill(simTrack.
momentum().eta(), track.
chi2());
306 hDofVsEta->Fill(simTrack.
momentum().eta(), track.
ndof());
314 histo->
Fill(recoTSOS);
329 histo->
Fill(recoFTS);
356 SimTrackContainer::const_iterator
simTrack;
360 double bestDeltaR = 10e5;
361 for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++
simTrack) {
362 if (
abs((*simTrack).type()) != 13)
368 double newDeltaR = deltaR<double>(vect.eta(), vect.phi(), simTrack->momentum().eta(), simTrack->momentum().phi());
370 if (newDeltaR < bestDeltaR) {
371 LogTrace(
"MuonTrackAnalyzer") <<
"Matching Track with DeltaR = " << newDeltaR << endl;
372 bestDeltaR = newDeltaR;
376 return pair<SimTrack, double>(
result, bestDeltaR);
380 switch (theEtaRange) {
382 return (
abs(eta) <= 2.4) ?
true :
false;
384 return (
abs(eta) < 1.1) ?
true :
false;
386 return (
abs(eta) >= 1.1 &&
abs(eta) <= 2.4) ?
true :
false;
388 LogTrace(
"MuonTrackAnalyzer") <<
"No correct Eta range selected!! " << endl;
397 event.getByToken(theDTSimHitToken, dtSimHits);
400 event.getByToken(theCSCSimHitToken, cscSimHits);
403 event.getByToken(theRPCSimHitToken, rpcSimHits);
405 map<unsigned int, vector<const PSimHit *> > mapOfMuonSimHits;
407 for (PSimHitContainer::const_iterator simhit = dtSimHits->begin(); simhit != dtSimHits->end(); ++simhit) {
408 if (
abs(simhit->particleType()) != 13)
410 mapOfMuonSimHits[simhit->trackId()].push_back(&*simhit);
413 for (PSimHitContainer::const_iterator simhit = cscSimHits->begin(); simhit != cscSimHits->end(); ++simhit) {
414 if (
abs(simhit->particleType()) != 13)
416 mapOfMuonSimHits[simhit->trackId()].push_back(&*simhit);
419 for (PSimHitContainer::const_iterator simhit = rpcSimHits->begin(); simhit != rpcSimHits->end(); ++simhit) {
420 if (
abs(simhit->particleType()) != 13)
422 mapOfMuonSimHits[simhit->trackId()].push_back(&*simhit);
425 bool presence =
false;
431 map<unsigned int, vector<const PSimHit *> >::const_iterator mapIterator =
432 mapOfMuonSimHits.find(
simTrack->trackId());
434 if (mapIterator != mapOfMuonSimHits.end())
449 const GeomDet *gdet = theService->trackingGeometry()->idToDet(seedDetId);
455 const DetLayer *initialLayer = theService->detLayerGeometry()->idToLayer(seedDetId);
460 vector<const DetLayer *> detLayers;
462 theService->muonNavigationSchool()->compatibleLayers(*initialLayer, *initialState.
freeState(), detLayerOrder);
465 if (!detLayers.empty()) {
466 const DetLayer *finalLayer = detLayers.back();
468 theService->propagator(theSeedPropagatorName)->propagate(initialState, finalLayer->
surface());
470 result = propagatedState;
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
void computeResolutionAndPull(TrajectoryStateOnSurface &vtx, SimTrack &simTrack)
TrackCharge charge() const
std::pair< SimTrack, double > getSimTrack(TrajectoryStateOnSurface &tsos, edm::Handle< edm::SimTrackContainer > simTracks)
virtual void setCurrentFolder(std::string const &fullpath)
bool checkMuonSimHitPresence(const edm::Event &event, edm::Handle< edm::SimTrackContainer > simTracks)
auto const & tracks
cannot be loose
size_t recHitsSize() const
number of RecHits
TrajectoryStateOnSurface getSeedTSOS(const TrajectorySeed &seed)
void seedsAnalysis(const edm::Event &event, const edm::EventSetup &eventSetup, edm::Handle< edm::SimTrackContainer > simTracks)
double chi2() const
chi-squared of the fit
MuonTrackAnalyzer(const edm::ParameterSet &pset)
Constructor.
std::string dumpFTS(const FreeTrajectoryState &fts) const
std::string dumpTSOS(const TrajectoryStateOnSurface &tsos) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > XYZVectorD
spatial vector with cartesian internal representation
bool isInTheAcceptance(double eta)
FreeTrajectoryState const * freeState(bool withErrors=true) const
tuple MuonUpdatorAtVertex
Abs< T >::type abs(const T &t)
float ChiSquaredProbability(double chiSquared, double nrDOF)
unsigned int detId() const
void Fill(TrajectoryStateOnSurface &)
GlobalVector momentum() const
PTrajectoryStateOnDet const & startingState() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
T getParameter(std::string const &) const
double normalizedChi2() const
chi-squared divided by n.d.o.f.
double ndof() const
number of degrees of freedom of the fit
void tracksAnalysis(const edm::Event &event, const edm::EventSetup &eventSetup, edm::Handle< edm::SimTrackContainer > simTracks)
GlobalVector globalMomentum() const
const math::XYZTLorentzVectorD & momentum() const
~MuonTrackAnalyzer() override
Destructor.
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
void fillPlots(const edm::Event &event, edm::Handle< edm::SimTrackContainer > &simTracks)