31 #include "TDirectory.h" 45 theMuonTrackLabel =
pset.getParameter<
InputTag>(
"MuonTrack");
46 theMuonTrackToken = consumes<reco::TrackCollection>(theMuonTrackLabel);
48 cscSimHitLabel =
pset.getParameter<
InputTag>(
"CSCSimHit");
50 rpcSimHitLabel =
pset.getParameter<
InputTag>(
"RPCSimHit");
51 theCSCSimHitToken = consumes<std::vector<PSimHit> >(cscSimHitLabel);
52 theDTSimHitToken = consumes<std::vector<PSimHit> >(dtSimHitLabel);
53 theRPCSimHitToken = consumes<std::vector<PSimHit> >(rpcSimHitLabel);
56 out =
pset.getUntrackedParameter<
string>(
"rootFileName");
58 subsystemname_ =
pset.getUntrackedParameter<
std::string>(
"subSystemFolder",
"YourSubsystem");
62 if (theDataType.label() !=
"RealData" && theDataType.label() !=
"SimData")
63 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Error in Data Type!!";
64 theDataTypeToken = consumes<edm::SimTrackContainer>(theDataType);
66 theEtaRange = (
EtaRange)
pset.getParameter<
int>(
"EtaRange");
71 theMuonSimHitNumberPerEvent = 0;
84 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Begin Run";
89 if (!
algo.process().empty())
91 if (!
algo.label().empty())
93 if (!
algo.instance().empty())
101 hDPtRef = ibooker.
book1D(
"DeltaPtRef",
"P^{in}_{t}-P^{in ref}", 10000, -20, 20);
109 hSimHitsPerTrack = ibooker.
book1D(
"SimHitsPerTrack",
"Number of sim hits per track", 55, 0, 55);
110 hSimHitsPerTrackVsEta =
111 ibooker.
book2D(
"SimHitsPerTrackVsEta",
"Number of sim hits per track VS #eta", 120, -3., 3., 55, 0, 55);
113 ibooker.
book2D(
"DeltaPtVsEtaSim",
"#Delta P_{t} vs #eta gen, sim quantity", 120, -3., 3., 500, -250., 250.);
115 ibooker.
book2D(
"DeltaPtVsEtaSim2",
"#Delta P_{t} vs #eta gen, sim quantity", 120, -3., 3., 500, -250., 250.);
123 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Analyze";
128 theMuonSimHitNumberPerEvent = 0;
132 event.getByToken(theDTSimHitToken, dtSimHits);
135 event.getByToken(theCSCSimHitToken, cscSimHits);
138 event.getByToken(theRPCSimHitToken, rpcSimHits);
145 map<DetId, const PSimHit *> muonSimHitsPerId = mapMuSimHitsPerId(dtSimHits, cscSimHits, rpcSimHits);
147 hSimHitsPerTrack->Fill(theMuonSimHitNumberPerEvent);
151 if (theDataType.label() ==
"SimData") {
153 event.getByToken(theDataTypeToken,
simTracks);
156 SimTrackContainer::const_iterator
simTrack;
159 if (
abs((*simTrack).type()) == 13) {
160 hSimHitsPerTrackVsEta->Fill((*simTrack).momentum().eta(), theMuonSimHitNumberPerEvent);
161 etaSim = (*simTrack).momentum().eta();
162 theSimTkId = (*simTrack).trackId();
168 event.getByToken(theMuonTrackToken,
muonTracks);
170 reco::TrackCollection::const_iterator muonTrack;
182 double momAtEntry = -150., momAtExit = -150.;
184 if (theSimHitContainer.size() > 1) {
185 const GeomDet *geomDetA = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.front()->detUnitId()));
186 double distA = geomDetA->
toGlobal(theSimHitContainer.front()->localPosition()).
mag();
188 const GeomDet *geomDetB = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.back()->detUnitId()));
189 double distB = geomDetB->
toGlobal(theSimHitContainer.back()->localPosition()).
mag();
191 LogTrace(
"MuonTrackResidualAnalyzer")
192 <<
"Inner SimHit: " << theSimHitContainer.front()->particleType()
193 <<
" Pt: " << theSimHitContainer.front()->momentumAtEntry().perp()
194 <<
" E: " << theSimHitContainer.front()->momentumAtEntry().perp() <<
" R: " << distA << endl;
195 LogTrace(
"MuonTrackResidualAnalyzer")
196 <<
"Outer SimHit: " << theSimHitContainer.back()->particleType()
197 <<
" Pt: " << theSimHitContainer.back()->momentumAtEntry().perp()
198 <<
" E: " << theSimHitContainer.front()->momentumAtEntry().perp() <<
" R: " << distB << endl;
200 momAtEntry = theSimHitContainer.front()->momentumAtEntry().perp();
201 momAtExit = theSimHitContainer.back()->momentumAtEntry().perp();
206 map<DetId, const PSimHit *>::const_iterator itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
207 map<DetId, const PSimHit *>::const_iterator itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
209 double momAtEntry2 = -150, momAtExit2 = -150.;
210 if (itFirst != muonSimHitsPerId.end())
211 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
213 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No first sim hit found";
215 itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
216 if (itFirst != muonSimHitsPerId.end())
217 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
219 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No second sim hit found";
224 if (itLast != muonSimHitsPerId.end())
225 momAtExit2 = itLast->second->momentumAtEntry().perp();
227 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No last sim hit found";
229 itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
230 if (itLast != muonSimHitsPerId.end())
231 momAtExit2 = itLast->second->momentumAtEntry().perp();
233 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No last but one sim hit found";
239 if (momAtEntry >= 0 && momAtExit >= 0)
240 hDeltaPtVsEtaSim->Fill(etaSim, momAtEntry - momAtExit);
241 if (momAtEntry2 >= 0 && momAtExit2 >= 0)
242 hDeltaPtVsEtaSim2->Fill(etaSim, momAtEntry2 - momAtExit2);
244 LogDebug(
"MuonTrackResidualAnalyzer") <<
"NO SimTrack'eta";
253 switch (theEtaRange) {
261 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No correct Eta range selected!! ";
273 map<DetId, const PSimHit *> hitIdMap;
274 theSimHitContainer.clear();
276 mapMuSimHitsPerId(dtSimhits, hitIdMap);
277 mapMuSimHitsPerId(cscSimhits, hitIdMap);
278 mapMuSimHitsPerId(rpcSimhits, hitIdMap);
280 if (theSimHitContainer.size() > 1)
282 theSimHitContainer.begin(), theSimHitContainer.end(),
RadiusComparatorInOut(theService->trackingGeometry()));
284 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Sim Hit list";
286 for (vector<const PSimHit *>::const_iterator it = theSimHitContainer.begin(); it != theSimHitContainer.end(); ++it) {
287 LogTrace(
"MuonTrackResidualAnalyzer")
289 <<
" Process Type: " << (*it)->processType() <<
" " <<
debug.dumpMuonId(
DetId((*it)->detUnitId())) << endl;
296 map<DetId, const PSimHit *> &hitIdMap) {
297 for (PSimHitContainer::const_iterator simhit =
simhits->begin(); simhit !=
simhits->end(); ++simhit) {
298 if (
abs(simhit->particleType()) != 13 && theSimTkId != simhit->trackId())
301 theSimHitContainer.push_back(&*simhit);
309 map<DetId, const PSimHit *>::const_iterator it = hitIdMap.find(
id);
311 if (it == hitIdMap.end())
312 hitIdMap[
id] = &*simhit;
314 LogDebug(
"MuonTrackResidualAnalyzer") <<
"TWO muons in the same sensible volume!!";
316 ++theMuonSimHitNumberPerEvent;
321 map<DetId, const PSimHit *> &hitIdMap,
325 for (Trajectory::DataContainer::const_iterator datum =
data.begin(); datum !=
data.end(); ++datum) {
326 GlobalPoint fitPoint = datum->updatedState().globalPosition();
333 double errX = datum->updatedState().localError().matrix()(3, 3);
334 double errY = datum->updatedState().localError().matrix()(4, 4);
337 map<DetId, const PSimHit *>::const_iterator it = hitIdMap.find(datum->recHit()->geographicalId());
339 if (it == hitIdMap.end())
342 const PSimHit *simhit = it->second;
352 cout <<
"SimHit position " << simHitPoint << endl;
353 cout <<
"Fit position " << fitLocalPoint << endl;
354 cout <<
"Fit position2 " << datum->updatedState().localPosition() << endl;
355 cout <<
"Errors on the fit position: (" <<
errX <<
"," <<
errY <<
"," <<
errZ <<
")" << endl;
356 cout <<
"Resolution on x: " <<
diff.x() /
abs(simHitPoint.x()) << endl;
357 cout <<
"Resolution on y: " <<
diff.y() /
abs(simHitPoint.y()) << endl;
358 cout <<
"Resolution on z: " <<
diff.z() /
abs(simHitPoint.z()) << endl;
360 cout <<
"Eta direction: " << simhit->
momentumAtEntry().
eta() <<
" eta position: " << simHitPoint.eta() << endl;
363 histos->Fill(simHitPoint.x(),
~MuonTrackResidualAnalyzer() override
Destructor.
std::map< DetId, const PSimHit * > mapMuSimHitsPerId(edm::Handle< edm::PSimHitContainer > dtSimhits, edm::Handle< edm::PSimHitContainer > cscSimhits, edm::Handle< edm::PSimHitContainer > rpcSimhits)
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
unsigned int detUnitId() const
virtual void setCurrentFolder(std::string const &fullpath)
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
bool isInTheAcceptance(double eta)
Geom::Phi< T > phi() const
dqm::legacy::DQMStore * dbe_
def replace(string, replacements)
void dqmEndRun(edm::Run const &, edm::EventSetup const &) override
DataContainer const & measurements() const
std::vector< TrajectoryMeasurement > DataContainer
void computeResolution(Trajectory &trajectory, std::map< DetId, const PSimHit *> &hitIdMap, HResolution1DRecHit *histos)
Abs< T >::type abs(const T &t)
MuonTrackResidualAnalyzer(const edm::ParameterSet &ps)
Constructor.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
std::vector< ConstRecHitPointer > ConstRecHitContainer
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
constexpr uint32_t rawId() const
get the raw id
Local3DPoint localPosition() const
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
DQM_DEPRECATED void save(std::string const &filename, std::string const &path="")
char data[epos_bytes_allocation]
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.