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;
87 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Begin Run";
96 if(!algo.
label().empty())
97 dirName+=algo.
label()+
"_";
100 if (dirName.find(
"Tracks")<dirName.length()){
101 dirName.replace(dirName.find(
"Tracks"),6,
"");
107 hDPtRef = ibooker.
book1D(
"DeltaPtRef",
"P^{in}_{t}-P^{in ref}",10000,-20,20);
115 hSimHitsPerTrack = ibooker.
book1D(
"SimHitsPerTrack",
"Number of sim hits per track",55,0,55);
116 hSimHitsPerTrackVsEta = ibooker.
book2D(
"SimHitsPerTrackVsEta",
"Number of sim hits per track VS #eta",120,-3.,3.,55,0,55);
117 hDeltaPtVsEtaSim = ibooker.
book2D(
"DeltaPtVsEtaSim",
"#Delta P_{t} vs #eta gen, sim quantity",120,-3.,3.,500,-250.,250.);
118 hDeltaPtVsEtaSim2 = ibooker.
book2D(
"DeltaPtVsEtaSim2",
"#Delta P_{t} vs #eta gen, sim quantity",120,-3.,3.,500,-250.,250.);
125 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Analyze";
128 theService->update(eventSetup);
130 theMuonSimHitNumberPerEvent = 0;
134 event.getByToken(theDTSimHitToken, dtSimHits);
137 event.getByToken(theCSCSimHitToken, cscSimHits);
140 event.getByToken(theRPCSimHitToken, rpcSimHits);
147 map<DetId, const PSimHit* > muonSimHitsPerId =
148 mapMuSimHitsPerId(dtSimHits,cscSimHits,rpcSimHits);
150 hSimHitsPerTrack->Fill(theMuonSimHitNumberPerEvent);
154 if(theDataType.label() ==
"SimData"){
157 event.getByToken(theDataTypeToken,simTracks);
160 SimTrackContainer::const_iterator
simTrack;
162 for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++
simTrack)
163 if (
abs((*simTrack).type()) == 13){
164 hSimHitsPerTrackVsEta->Fill((*simTrack).momentum().eta(),theMuonSimHitNumberPerEvent);
165 etaSim = (*simTrack).momentum().eta();
166 theSimTkId = (*simTrack).trackId();
174 event.getByToken(theMuonTrackToken, muonTracks);
176 reco::TrackCollection::const_iterator muonTrack;
179 for (muonTrack = muonTracks->begin(); muonTrack != muonTracks->end(); ++muonTrack) {
189 double momAtEntry = -150., momAtExit = -150.;
191 if(theSimHitContainer.size()>1){
193 const GeomDet *geomDetA = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.front()->detUnitId()));
194 double distA = geomDetA->
toGlobal(theSimHitContainer.front()->localPosition()).
mag();
196 const GeomDet *geomDetB = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.back()->detUnitId()));
197 double distB = geomDetB->
toGlobal(theSimHitContainer.back()->localPosition()).
mag();
199 LogTrace(
"MuonTrackResidualAnalyzer")<<
"Inner SimHit: "<<theSimHitContainer.front()->particleType()
200 <<
" Pt: "<<theSimHitContainer.front()->momentumAtEntry().perp()
201 <<
" E: "<<theSimHitContainer.front()->momentumAtEntry().perp()
202 <<
" R: "<<distA<<endl;
203 LogTrace(
"MuonTrackResidualAnalyzer")<<
"Outer SimHit: "<<theSimHitContainer.back()->particleType()
204 <<
" Pt: "<<theSimHitContainer.back()->momentumAtEntry().perp()
205 <<
" E: "<<theSimHitContainer.front()->momentumAtEntry().perp()
206 <<
" R: "<<distB<<endl;
208 momAtEntry = theSimHitContainer.front()->momentumAtEntry().perp();
209 momAtExit = theSimHitContainer.back()->momentumAtEntry().perp();
214 map<DetId,const PSimHit*>::const_iterator itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
215 map<DetId,const PSimHit*>::const_iterator itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
217 double momAtEntry2 = -150, momAtExit2 = -150.;
218 if (itFirst != muonSimHitsPerId.end() )
219 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
221 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No first sim hit found";
223 itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
224 if (itFirst != muonSimHitsPerId.end() )
225 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
227 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No second sim hit found";
232 if (itLast != muonSimHitsPerId.end() )
233 momAtExit2 = itLast->second->momentumAtEntry().perp();
235 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No last sim hit found";
237 itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
238 if (itLast != muonSimHitsPerId.end() )
239 momAtExit2 = itLast->second->momentumAtEntry().perp();
241 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No last but one sim hit found";
247 if(momAtEntry >=0 && momAtExit >= 0)
248 hDeltaPtVsEtaSim->Fill(etaSim,momAtEntry-momAtExit);
249 if(momAtEntry2 >=0 && momAtExit2 >= 0)
250 hDeltaPtVsEtaSim2->Fill(etaSim,momAtEntry2-momAtExit2);
253 LogDebug(
"MuonTrackResidualAnalyzer")<<
"NO SimTrack'eta";
265 return (
abs(eta) <= 2.4 ) ?
true :
false;
267 return (
abs(eta) < 1.1 ) ?
true :
false;
269 return (
abs(eta) >= 1.1 &&
abs(eta) <= 2.4 ) ?
true :
false;
271 {
LogDebug(
"MuonTrackResidualAnalyzer")<<
"No correct Eta range selected!! ";
return false;}
276 map<DetId,const PSimHit*>
283 map<DetId,const PSimHit*> hitIdMap;
284 theSimHitContainer.clear();
286 mapMuSimHitsPerId(dtSimhits,hitIdMap);
287 mapMuSimHitsPerId(cscSimhits,hitIdMap);
288 mapMuSimHitsPerId(rpcSimhits,hitIdMap);
290 if(theSimHitContainer.size() >1)
291 stable_sort(theSimHitContainer.begin(),theSimHitContainer.end(),
RadiusComparatorInOut(theService->trackingGeometry()));
293 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Sim Hit list";
295 for(vector<const PSimHit*>::const_iterator it = theSimHitContainer.begin();
296 it != theSimHitContainer.end(); ++it){
297 LogTrace(
"MuonTrackResidualAnalyzer")<<count
299 <<
" Process Type: " << (*it)->processType()
309 map<DetId,const PSimHit*> &hitIdMap){
311 for(PSimHitContainer::const_iterator simhit = simhits->begin();
312 simhit != simhits->end(); ++simhit) {
314 if (
abs(simhit->particleType()) != 13 && theSimTkId != simhit->trackId())
continue;
316 theSimHitContainer.push_back(&*simhit);
324 map<DetId,const PSimHit*>::const_iterator it = hitIdMap.find(
id);
326 if (it == hitIdMap.end() )
327 hitIdMap[
id] = &*simhit;
329 LogDebug(
"MuonTrackResidualAnalyzer")<<
"TWO muons in the same sensible volume!!";
331 ++theMuonSimHitNumberPerEvent;
337 map<DetId,const PSimHit*> &hitIdMap,
342 for(Trajectory::DataContainer::const_iterator datum = data.begin();
343 datum != data.end(); ++datum){
345 GlobalPoint fitPoint = datum->updatedState().globalPosition();
352 double errX = datum->updatedState().localError().matrix()(3,3);
353 double errY = datum->updatedState().localError().matrix()(4,4);
356 map<DetId,const PSimHit*>::const_iterator it = hitIdMap.find(datum->recHit()->geographicalId());
359 if (it == hitIdMap.end() )
continue;
361 const PSimHit* simhit = it->second;
372 cout <<
"SimHit position "<< simHitPoint << endl;
373 cout <<
"Fit position "<< fitLocalPoint << endl;
374 cout <<
"Fit position2 "<< datum->updatedState().localPosition() << endl;
375 cout <<
"Errors on the fit position: (" << errX <<
"," << errY <<
"," << errZ <<
")"<<endl;
376 cout <<
"Resolution on x: " << diff.
x()/
abs(simHitPoint.x()) << endl;
377 cout <<
"Resolution on y: " << diff.
y()/
abs(simHitPoint.y()) << endl;
378 cout <<
"Resolution on z: " << diff.
z()/
abs(simHitPoint.z()) << endl;
380 cout <<
"Eta direction: "<< simhit->
momentumAtEntry().
eta() <<
" eta position: " << simHitPoint.eta() << endl;
384 histos->
Fill( simHitPoint.x(), simHitPoint.y(), simHitPoint.z(),
385 diff.
x(), diff.
y(), diff.
z(),
~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())
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
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 endRun(edm::Run const &, edm::EventSetup const &) override
std::string dumpMuonId(const DetId &id) const
DataContainer const & measurements() const
std::vector< TrajectoryMeasurement > DataContainer
void setCurrentFolder(std::string const &fullpath)
Local3DPoint localPosition() const
MonitorElement * book1D(Args &&...args)
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
MonitorElement * book2D(Args &&...args)
char data[epos_bytes_allocation]
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)
unsigned int detUnitId() const