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";
126 theService->update(eventSetup);
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;
173 for (muonTrack = muonTracks->begin(); muonTrack != muonTracks->end(); ++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(),