30 #include "TDirectory.h" 44 theMuonTrackLabel =
pset.getParameter<
InputTag>(
"MuonTrack");
45 theMuonTrackToken = consumes<reco::TrackCollection>(theMuonTrackLabel);
47 cscSimHitLabel =
pset.getParameter<
InputTag>(
"CSCSimHit");
49 rpcSimHitLabel =
pset.getParameter<
InputTag>(
"RPCSimHit");
50 theCSCSimHitToken = consumes<std::vector<PSimHit> >(cscSimHitLabel);
51 theDTSimHitToken = consumes<std::vector<PSimHit> >(dtSimHitLabel);
52 theRPCSimHitToken = consumes<std::vector<PSimHit> >(rpcSimHitLabel);
55 out =
pset.getUntrackedParameter<
string>(
"rootFileName");
57 subsystemname_ =
pset.getUntrackedParameter<
std::string>(
"subSystemFolder",
"YourSubsystem");
61 if (theDataType.label() !=
"RealData" && theDataType.label() !=
"SimData")
62 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Error in Data Type!!";
63 theDataTypeToken = consumes<edm::SimTrackContainer>(theDataType);
65 theEtaRange = (
EtaRange)
pset.getParameter<
int>(
"EtaRange");
70 theMuonSimHitNumberPerEvent = 0;
83 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Begin Run";
91 dirName += algo.
process() +
"_";
92 if (!algo.
label().empty())
93 dirName += algo.
label() +
"_";
96 if (dirName.find(
"Tracks") < dirName.length()) {
97 dirName.replace(dirName.find(
"Tracks"), 6,
"");
102 hDPtRef = ibooker.
book1D(
"DeltaPtRef",
"P^{in}_{t}-P^{in ref}", 10000, -20, 20);
110 hSimHitsPerTrack = ibooker.
book1D(
"SimHitsPerTrack",
"Number of sim hits per track", 55, 0, 55);
111 hSimHitsPerTrackVsEta =
112 ibooker.
book2D(
"SimHitsPerTrackVsEta",
"Number of sim hits per track VS #eta", 120, -3., 3., 55, 0, 55);
114 ibooker.
book2D(
"DeltaPtVsEtaSim",
"#Delta P_{t} vs #eta gen, sim quantity", 120, -3., 3., 500, -250., 250.);
116 ibooker.
book2D(
"DeltaPtVsEtaSim2",
"#Delta P_{t} vs #eta gen, sim quantity", 120, -3., 3., 500, -250., 250.);
124 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Analyze";
127 theService->update(eventSetup);
129 theMuonSimHitNumberPerEvent = 0;
133 event.getByToken(theDTSimHitToken, dtSimHits);
136 event.getByToken(theCSCSimHitToken, cscSimHits);
139 event.getByToken(theRPCSimHitToken, rpcSimHits);
146 map<DetId, const PSimHit *> muonSimHitsPerId = mapMuSimHitsPerId(dtSimHits, cscSimHits, rpcSimHits);
148 hSimHitsPerTrack->Fill(theMuonSimHitNumberPerEvent);
152 if (theDataType.label() ==
"SimData") {
154 event.getByToken(theDataTypeToken, simTracks);
157 SimTrackContainer::const_iterator
simTrack;
159 for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++
simTrack)
160 if (
abs((*simTrack).type()) == 13) {
161 hSimHitsPerTrackVsEta->Fill((*simTrack).momentum().eta(), theMuonSimHitNumberPerEvent);
162 etaSim = (*simTrack).momentum().eta();
163 theSimTkId = (*simTrack).trackId();
169 event.getByToken(theMuonTrackToken, muonTracks);
171 reco::TrackCollection::const_iterator muonTrack;
174 for (muonTrack = muonTracks->begin(); muonTrack != muonTracks->end(); ++muonTrack) {
183 double momAtEntry = -150., momAtExit = -150.;
185 if (theSimHitContainer.size() > 1) {
186 const GeomDet *geomDetA = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.front()->detUnitId()));
187 double distA = geomDetA->
toGlobal(theSimHitContainer.front()->localPosition()).
mag();
189 const GeomDet *geomDetB = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.back()->detUnitId()));
190 double distB = geomDetB->
toGlobal(theSimHitContainer.back()->localPosition()).
mag();
192 LogTrace(
"MuonTrackResidualAnalyzer")
193 <<
"Inner SimHit: " << theSimHitContainer.front()->particleType()
194 <<
" Pt: " << theSimHitContainer.front()->momentumAtEntry().perp()
195 <<
" E: " << theSimHitContainer.front()->momentumAtEntry().perp() <<
" R: " << distA << endl;
196 LogTrace(
"MuonTrackResidualAnalyzer")
197 <<
"Outer SimHit: " << theSimHitContainer.back()->particleType()
198 <<
" Pt: " << theSimHitContainer.back()->momentumAtEntry().perp()
199 <<
" E: " << theSimHitContainer.front()->momentumAtEntry().perp() <<
" R: " << distB << endl;
201 momAtEntry = theSimHitContainer.front()->momentumAtEntry().perp();
202 momAtExit = theSimHitContainer.back()->momentumAtEntry().perp();
207 map<DetId, const PSimHit *>::const_iterator itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
208 map<DetId, const PSimHit *>::const_iterator itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
210 double momAtEntry2 = -150, momAtExit2 = -150.;
211 if (itFirst != muonSimHitsPerId.end())
212 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
214 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No first sim hit found";
216 itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
217 if (itFirst != muonSimHitsPerId.end())
218 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
220 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No second sim hit found";
225 if (itLast != muonSimHitsPerId.end())
226 momAtExit2 = itLast->second->momentumAtEntry().perp();
228 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No last sim hit found";
230 itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
231 if (itLast != muonSimHitsPerId.end())
232 momAtExit2 = itLast->second->momentumAtEntry().perp();
234 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No last but one sim hit found";
240 if (momAtEntry >= 0 && momAtExit >= 0)
241 hDeltaPtVsEtaSim->Fill(etaSim, momAtEntry - momAtExit);
242 if (momAtEntry2 >= 0 && momAtExit2 >= 0)
243 hDeltaPtVsEtaSim2->Fill(etaSim, momAtEntry2 - momAtExit2);
245 LogDebug(
"MuonTrackResidualAnalyzer") <<
"NO SimTrack'eta";
254 switch (theEtaRange) {
256 return (
abs(eta) <= 2.4) ?
true :
false;
258 return (
abs(eta) < 1.1) ?
true :
false;
260 return (
abs(eta) >= 1.1 &&
abs(eta) <= 2.4) ?
true :
false;
262 LogDebug(
"MuonTrackResidualAnalyzer") <<
"No correct Eta range selected!! ";
274 map<DetId, const PSimHit *> hitIdMap;
275 theSimHitContainer.clear();
277 mapMuSimHitsPerId(dtSimhits, hitIdMap);
278 mapMuSimHitsPerId(cscSimhits, hitIdMap);
279 mapMuSimHitsPerId(rpcSimhits, hitIdMap);
281 if (theSimHitContainer.size() > 1)
283 theSimHitContainer.begin(), theSimHitContainer.end(),
RadiusComparatorInOut(theService->trackingGeometry()));
285 LogDebug(
"MuonTrackResidualAnalyzer") <<
"Sim Hit list";
287 for (vector<const PSimHit *>::const_iterator it = theSimHitContainer.begin(); it != theSimHitContainer.end(); ++it) {
288 LogTrace(
"MuonTrackResidualAnalyzer")
290 <<
" Process Type: " << (*it)->processType() <<
" " << debug.
dumpMuonId(
DetId((*it)->detUnitId())) << endl;
297 map<DetId, const PSimHit *> &hitIdMap) {
298 for (PSimHitContainer::const_iterator simhit = simhits->begin(); simhit != simhits->end(); ++simhit) {
299 if (
abs(simhit->particleType()) != 13 && theSimTkId != simhit->trackId())
302 theSimHitContainer.push_back(&*simhit);
310 map<DetId, const PSimHit *>::const_iterator it = hitIdMap.find(
id);
312 if (it == hitIdMap.end())
313 hitIdMap[
id] = &*simhit;
315 LogDebug(
"MuonTrackResidualAnalyzer") <<
"TWO muons in the same sensible volume!!";
317 ++theMuonSimHitNumberPerEvent;
322 map<DetId, const PSimHit *> &hitIdMap,
326 for (Trajectory::DataContainer::const_iterator datum = data.begin(); datum != data.end(); ++datum) {
327 GlobalPoint fitPoint = datum->updatedState().globalPosition();
334 double errX = datum->updatedState().localError().matrix()(3, 3);
335 double errY = datum->updatedState().localError().matrix()(4, 4);
338 map<DetId, const PSimHit *>::const_iterator it = hitIdMap.find(datum->recHit()->geographicalId());
340 if (it == hitIdMap.end())
343 const PSimHit *simhit = it->second;
353 cout <<
"SimHit position " << simHitPoint << endl;
354 cout <<
"Fit position " << fitLocalPoint << endl;
355 cout <<
"Fit position2 " << datum->updatedState().localPosition() << endl;
356 cout <<
"Errors on the fit position: (" << errX <<
"," << errY <<
"," << errZ <<
")" << endl;
357 cout <<
"Resolution on x: " << diff.
x() /
abs(simHitPoint.x()) << endl;
358 cout <<
"Resolution on y: " << diff.
y() /
abs(simHitPoint.y()) << endl;
359 cout <<
"Resolution on z: " << diff.
z() /
abs(simHitPoint.z()) << endl;
361 cout <<
"Eta direction: " << simhit->
momentumAtEntry().
eta() <<
" eta position: " << simHitPoint.eta() << endl;
364 histos->
Fill(simHitPoint.x(),
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
~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
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.
bool isInTheAcceptance(double eta)
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
void setCurrentFolder(std::string const &fullpath)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
dqm::legacy::DQMStore * dbe_
Geom::Phi< T > phi() const
constexpr uint32_t rawId() const
get the raw id
def replace(string, replacements)
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
void dqmEndRun(edm::Run const &, edm::EventSetup const &) override
std::string dumpMuonId(const DetId &id) const
DataContainer const & measurements() const
std::vector< TrajectoryMeasurement > DataContainer
Local3DPoint localPosition() const
Abs< T >::type abs(const T &t)
MuonTrackResidualAnalyzer(const edm::ParameterSet &ps)
Constructor.
std::vector< ConstRecHitPointer > ConstRecHitContainer
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
char data[epos_bytes_allocation]
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
void Fill(double x, double y, double z, double dx, double dy, double dz, double errx, double erry, double errz, double eta, double phi)
void computeResolution(Trajectory &trajectory, std::map< DetId, const PSimHit * > &hitIdMap, HResolution1DRecHit *histos)
void save(std::string const &filename, std::string const &path="", std::string const &pattern="", std::string const &rewrite="", uint32_t run=0, uint32_t lumi=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, std::string const &fileupdate="RECREATE")
unsigned int detUnitId() const