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;
91 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Begin Run";
101 dirName+=algo.
label()+
"_";
104 if (dirName.find(
"Tracks")<dirName.length()){
105 dirName.replace(dirName.find(
"Tracks"),6,
"");
111 hDPtRef = ibooker.
book1D(
"DeltaPtRef",
"P^{in}_{t}-P^{in ref}",10000,-20,20);
119 hSimHitsPerTrack = ibooker.
book1D(
"SimHitsPerTrack",
"Number of sim hits per track",55,0,55);
120 hSimHitsPerTrackVsEta = ibooker.
book2D(
"SimHitsPerTrackVsEta",
"Number of sim hits per track VS #eta",120,-3.,3.,55,0,55);
121 hDeltaPtVsEtaSim = ibooker.
book2D(
"DeltaPtVsEtaSim",
"#Delta P_{t} vs #eta gen, sim quantity",120,-3.,3.,500,-250.,250.);
122 hDeltaPtVsEtaSim2 = ibooker.
book2D(
"DeltaPtVsEtaSim2",
"#Delta P_{t} vs #eta gen, sim quantity",120,-3.,3.,500,-250.,250.);
129 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Analyze";
132 theService->update(eventSetup);
134 theMuonSimHitNumberPerEvent = 0;
138 event.getByToken(theDTSimHitToken, dtSimHits);
141 event.getByToken(theCSCSimHitToken, cscSimHits);
144 event.getByToken(theRPCSimHitToken, rpcSimHits);
151 map<DetId, const PSimHit* > muonSimHitsPerId =
152 mapMuSimHitsPerId(dtSimHits,cscSimHits,rpcSimHits);
154 hSimHitsPerTrack->Fill(theMuonSimHitNumberPerEvent);
158 if(theDataType.label() ==
"SimData"){
161 event.getByToken(theDataTypeToken,simTracks);
164 SimTrackContainer::const_iterator simTrack;
166 for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack)
167 if (
abs((*simTrack).type()) == 13){
168 hSimHitsPerTrackVsEta->Fill((*simTrack).momentum().eta(),theMuonSimHitNumberPerEvent);
169 etaSim = (*simTrack).momentum().eta();
170 theSimTkId = (*simTrack).trackId();
178 event.getByToken(theMuonTrackToken, muonTracks);
180 reco::TrackCollection::const_iterator muonTrack;
183 for (muonTrack = muonTracks->begin(); muonTrack != muonTracks->end(); ++muonTrack) {
185 reco::TransientTrack track(*muonTrack,&*theService->magneticField(),theService->trackingGeometry());
193 double momAtEntry = -150., momAtExit = -150.;
195 if(theSimHitContainer.size()>1){
197 const GeomDet *geomDetA = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.front()->detUnitId()));
198 double distA = geomDetA->
toGlobal(theSimHitContainer.front()->localPosition()).
mag();
200 const GeomDet *geomDetB = theService->trackingGeometry()->idToDet(
DetId(theSimHitContainer.back()->detUnitId()));
201 double distB = geomDetB->
toGlobal(theSimHitContainer.back()->localPosition()).
mag();
203 LogTrace(
"MuonTrackResidualAnalyzer")<<
"Inner SimHit: "<<theSimHitContainer.front()->particleType()
204 <<
" Pt: "<<theSimHitContainer.front()->momentumAtEntry().perp()
205 <<
" E: "<<theSimHitContainer.front()->momentumAtEntry().perp()
206 <<
" R: "<<distA<<endl;
207 LogTrace(
"MuonTrackResidualAnalyzer")<<
"Outer SimHit: "<<theSimHitContainer.back()->particleType()
208 <<
" Pt: "<<theSimHitContainer.back()->momentumAtEntry().perp()
209 <<
" E: "<<theSimHitContainer.front()->momentumAtEntry().perp()
210 <<
" R: "<<distB<<endl;
212 momAtEntry = theSimHitContainer.front()->momentumAtEntry().perp();
213 momAtExit = theSimHitContainer.back()->momentumAtEntry().perp();
218 map<DetId,const PSimHit*>::const_iterator itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
219 map<DetId,const PSimHit*>::const_iterator itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
221 double momAtEntry2 = -150, momAtExit2 = -150.;
222 if (itFirst != muonSimHitsPerId.end() )
223 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
225 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No first sim hit found";
227 itFirst = muonSimHitsPerId.find((*rhFirst)->geographicalId());
228 if (itFirst != muonSimHitsPerId.end() )
229 momAtEntry2 = itFirst->second->momentumAtEntry().perp();
231 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No second sim hit found";
236 if (itLast != muonSimHitsPerId.end() )
237 momAtExit2 = itLast->second->momentumAtEntry().perp();
239 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No last sim hit found";
241 itLast = muonSimHitsPerId.find((*rhLast)->geographicalId());
242 if (itLast != muonSimHitsPerId.end() )
243 momAtExit2 = itLast->second->momentumAtEntry().perp();
245 LogDebug(
"MuonTrackResidualAnalyzer")<<
"No last but one sim hit found";
251 if(momAtEntry >=0 && momAtExit >= 0)
252 hDeltaPtVsEtaSim->Fill(etaSim,momAtEntry-momAtExit);
253 if(momAtEntry2 >=0 && momAtExit2 >= 0)
254 hDeltaPtVsEtaSim2->Fill(etaSim,momAtEntry2-momAtExit2);
257 LogDebug(
"MuonTrackResidualAnalyzer")<<
"NO SimTrack'eta";
269 return (
abs(eta) <= 2.4 ) ?
true :
false;
271 return (
abs(eta) < 1.1 ) ?
true :
false;
273 return (
abs(eta) >= 1.1 &&
abs(eta) <= 2.4 ) ?
true :
false;
275 {
LogDebug(
"MuonTrackResidualAnalyzer")<<
"No correct Eta range selected!! ";
return false;}
280 map<DetId,const PSimHit*>
287 map<DetId,const PSimHit*> hitIdMap;
288 theSimHitContainer.clear();
290 mapMuSimHitsPerId(dtSimhits,hitIdMap);
291 mapMuSimHitsPerId(cscSimhits,hitIdMap);
292 mapMuSimHitsPerId(rpcSimhits,hitIdMap);
294 if(theSimHitContainer.size() >1)
295 stable_sort(theSimHitContainer.begin(),theSimHitContainer.end(),
RadiusComparatorInOut(theService->trackingGeometry()));
297 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Sim Hit list";
299 for(vector<const PSimHit*>::const_iterator it = theSimHitContainer.begin();
300 it != theSimHitContainer.end(); ++it){
301 LogTrace(
"MuonTrackResidualAnalyzer")<<count
303 <<
" Process Type: " << (*it)->processType()
313 map<DetId,const PSimHit*> &hitIdMap){
315 for(PSimHitContainer::const_iterator simhit = simhits->begin();
316 simhit != simhits->end(); ++simhit) {
318 if (
abs(simhit->particleType()) != 13 && theSimTkId != simhit->trackId())
continue;
320 theSimHitContainer.push_back(&*simhit);
328 map<DetId,const PSimHit*>::const_iterator it = hitIdMap.find(
id);
330 if (it == hitIdMap.end() )
331 hitIdMap[
id] = &*simhit;
333 LogDebug(
"MuonTrackResidualAnalyzer")<<
"TWO muons in the same sensible volume!!";
335 ++theMuonSimHitNumberPerEvent;
341 map<DetId,const PSimHit*> &hitIdMap,
346 for(Trajectory::DataContainer::const_iterator datum = data.begin();
347 datum != data.end(); ++datum){
349 GlobalPoint fitPoint = datum->updatedState().globalPosition();
356 double errX = datum->updatedState().localError().matrix()(3,3);
357 double errY = datum->updatedState().localError().matrix()(4,4);
360 map<DetId,const PSimHit*>::const_iterator it = hitIdMap.find(datum->recHit()->geographicalId());
363 if (it == hitIdMap.end() )
continue;
365 const PSimHit* simhit = it->second;
376 cout <<
"SimHit position "<< simHitPoint << endl;
377 cout <<
"Fit position "<< fitLocalPoint << endl;
378 cout <<
"Fit position2 "<< datum->updatedState().localPosition() << endl;
379 cout <<
"Errors on the fit position: (" << errX <<
"," << errY <<
"," << errZ <<
")"<<endl;
380 cout <<
"Resolution on x: " << diff.
x()/
abs(simHitPoint.x()) << endl;
381 cout <<
"Resolution on y: " << diff.
y()/
abs(simHitPoint.y()) << endl;
382 cout <<
"Resolution on z: " << diff.
z()/
abs(simHitPoint.z()) << endl;
384 cout <<
"Eta direction: "<< simhit->
momentumAtEntry().
eta() <<
" eta position: " << simHitPoint.eta() << endl;
388 histos->
Fill( simHitPoint.x(), simHitPoint.y(), simHitPoint.z(),
389 diff.
x(), diff.
y(), diff.
z(),
std::map< DetId, const PSimHit * > mapMuSimHitsPerId(edm::Handle< edm::PSimHitContainer > dtSimhits, edm::Handle< edm::PSimHitContainer > cscSimhits, edm::Handle< edm::PSimHitContainer > rpcSimhits)
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
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
std::string dumpMuonId(const DetId &id) const
uint32_t rawId() const
get the raw id
DataContainer const & measurements() const
std::vector< TrajectoryMeasurement > DataContainer
Local3DPoint localPosition() const
MonitorElement * book1D(Args &&...args)
Abs< T >::type abs(const T &t)
MuonTrackResidualAnalyzer(const edm::ParameterSet &ps)
Constructor.
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
std::vector< ConstRecHitPointer > ConstRecHitContainer
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
void setCurrentFolder(const std::string &fullpath)
MonitorElement * book2D(Args &&...args)
virtual ~MuonTrackResidualAnalyzer()
Destructor.
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
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection