32 #include "TDirectory.h"
58 if(theDataType.label() !=
"RealData" && theDataType.label() !=
"SimData")
59 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Error in Data Type!!";
66 theMuonSimHitNumberPerEvent = 0;
78 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Begin Job";
88 dirName+=algo.
label()+
"_";
91 if (dirName.find(
"Tracks")<dirName.length()){
92 dirName.replace(dirName.find(
"Tracks"),6,
"");
98 hDPtRef =
dbe_->
book1D(
"DeltaPtRef",
"P^{in}_{t}-P^{in ref}",10000,-20,20);
106 hSimHitsPerTrack =
dbe_->
book1D(
"SimHitsPerTrack",
"Number of sim hits per track",55,0,55);
107 hSimHitsPerTrackVsEta =
dbe_->
book2D(
"SimHitsPerTrackVsEta",
"Number of sim hits per track VS #eta",120,-3.,3.,55,0,55);
108 hDeltaPtVsEtaSim =
dbe_->
book2D(
"DeltaPtVsEtaSim",
"#Delta P_{t} vs #eta gen, sim quantity",120,-3.,3.,500,-250.,250.);
109 hDeltaPtVsEtaSim2 =
dbe_->
book2D(
"DeltaPtVsEtaSim2",
"#Delta P_{t} vs #eta gen, sim quantity",120,-3.,3.,500,-250.,250.);
118 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Analyze";
121 theService->update(eventSetup);
123 theMuonSimHitNumberPerEvent = 0;
127 event.getByLabel(dtSimHitLabel.instance(),dtSimHitLabel.label(), dtSimHits);
130 event.getByLabel(cscSimHitLabel.instance(),cscSimHitLabel.label(), cscSimHits);
133 event.getByLabel(rpcSimHitLabel.instance(),rpcSimHitLabel.label(), rpcSimHits);
140 map<DetId, const PSimHit* > muonSimHitsPerId =
141 mapMuSimHitsPerId(dtSimHits,cscSimHits,rpcSimHits);
143 hSimHitsPerTrack->Fill(theMuonSimHitNumberPerEvent);
147 if(theDataType.label() ==
"SimData"){
150 event.getByLabel(theDataType.instance(),simTracks);
153 SimTrackContainer::const_iterator simTrack;
155 for (simTrack = simTracks->begin(); simTrack != simTracks->end(); ++simTrack)
156 if (
abs((*simTrack).type()) == 13){
157 hSimHitsPerTrackVsEta->Fill((*simTrack).momentum().eta(),theMuonSimHitNumberPerEvent);
158 etaSim = (*simTrack).momentum().eta();
159 theSimTkId = (*simTrack).trackId();
167 event.getByLabel(theMuonTrackLabel, muonTracks);
169 reco::TrackCollection::const_iterator muonTrack;
172 for (muonTrack = muonTracks->begin(); muonTrack != muonTracks->end(); ++muonTrack) {
174 reco::TransientTrack track(*muonTrack,&*theService->magneticField(),theService->trackingGeometry());
182 double momAtEntry = -150., momAtExit = -150.;
184 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")<<
"Inner SimHit: "<<theSimHitContainer.front()->particleType()
193 <<
" Pt: "<<theSimHitContainer.front()->momentumAtEntry().perp()
194 <<
" E: "<<theSimHitContainer.front()->momentumAtEntry().perp()
195 <<
" R: "<<distA<<endl;
196 LogTrace(
"MuonTrackResidualAnalyzer")<<
"Outer SimHit: "<<theSimHitContainer.back()->particleType()
197 <<
" Pt: "<<theSimHitContainer.back()->momentumAtEntry().perp()
198 <<
" E: "<<theSimHitContainer.front()->momentumAtEntry().perp()
199 <<
" 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);
246 LogDebug(
"MuonTrackResidualAnalyzer")<<
"NO SimTrack'eta";
258 return (
abs(eta) <= 2.4 ) ?
true :
false;
260 return (
abs(eta) < 1.1 ) ?
true :
false;
262 return (
abs(eta) >= 1.1 &&
abs(eta) <= 2.4 ) ?
true :
false;
264 {
LogDebug(
"MuonTrackResidualAnalyzer")<<
"No correct Eta range selected!! ";
return false;}
269 map<DetId,const PSimHit*>
276 map<DetId,const PSimHit*> hitIdMap;
277 theSimHitContainer.clear();
279 mapMuSimHitsPerId(dtSimhits,hitIdMap);
280 mapMuSimHitsPerId(cscSimhits,hitIdMap);
281 mapMuSimHitsPerId(rpcSimhits,hitIdMap);
283 if(theSimHitContainer.size() >1)
284 stable_sort(theSimHitContainer.begin(),theSimHitContainer.end(),
RadiusComparatorInOut(theService->trackingGeometry()));
286 LogDebug(
"MuonTrackResidualAnalyzer")<<
"Sim Hit list";
288 for(vector<const PSimHit*>::const_iterator it = theSimHitContainer.begin();
289 it != theSimHitContainer.end(); ++it){
290 LogTrace(
"MuonTrackResidualAnalyzer")<<count
292 <<
" Process Type: " << (*it)->processType()
302 map<DetId,const PSimHit*> &hitIdMap){
304 for(PSimHitContainer::const_iterator simhit = simhits->begin();
305 simhit != simhits->end(); ++simhit) {
307 if (
abs(simhit->particleType()) != 13 && theSimTkId != simhit->trackId())
continue;
309 theSimHitContainer.push_back(&*simhit);
317 map<DetId,const PSimHit*>::const_iterator it = hitIdMap.find(
id);
319 if (it == hitIdMap.end() )
320 hitIdMap[
id] = &*simhit;
322 LogDebug(
"MuonTrackResidualAnalyzer")<<
"TWO muons in the same sensible volume!!";
324 ++theMuonSimHitNumberPerEvent;
330 map<DetId,const PSimHit*> &hitIdMap,
335 for(Trajectory::DataContainer::const_iterator datum = data.begin();
336 datum != data.end(); ++datum){
338 GlobalPoint fitPoint = datum->updatedState().globalPosition();
345 double errX = datum->updatedState().localError().matrix()(3,3);
346 double errY = datum->updatedState().localError().matrix()(4,4);
349 map<DetId,const PSimHit*>::const_iterator it = hitIdMap.find(datum->recHit()->geographicalId());
352 if (it == hitIdMap.end() )
continue;
354 const PSimHit* simhit = it->second;
365 cout <<
"SimHit position "<< simHitPoint << endl;
366 cout <<
"Fit position "<< fitLocalPoint << endl;
367 cout <<
"Fit position2 "<< datum->updatedState().localPosition() << endl;
368 cout <<
"Errors on the fit position: (" << errX <<
"," << errY <<
"," << errZ <<
")"<<endl;
369 cout <<
"Resolution on x: " << diff.
x()/
abs(simHitPoint.x()) << endl;
370 cout <<
"Resolution on y: " << diff.
y()/
abs(simHitPoint.y()) << endl;
371 cout <<
"Resolution on z: " << diff.
z()/
abs(simHitPoint.z()) << endl;
373 cout <<
"Eta direction: "<< simhit->
momentumAtEntry().
eta() <<
" eta position: " << simHitPoint.eta() << endl;
377 histos->
Fill( simHitPoint.x(), simHitPoint.y(), simHitPoint.z(),
378 diff.
x(), diff.
y(), diff.
z(),
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::map< DetId, const PSimHit * > mapMuSimHitsPerId(edm::Handle< edm::PSimHitContainer > dtSimhits, edm::Handle< edm::PSimHitContainer > cscSimhits, edm::Handle< edm::PSimHitContainer > rpcSimhits)
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
LocalVector momentumAtEntry() const
The momentum of the track that produced the hit, at entry point.
bool isInTheAcceptance(double eta)
void cd(void)
go to top directory (ie. root)
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.
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Geom::Phi< T > phi() const
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
MuonTrackResidualAnalyzer(const edm::ParameterSet &pset)
Constructor.
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
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
tuple Chi2MeasurementEstimator
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
std::vector< ConstRecHitPointer > ConstRecHitContainer
char data[epos_bytes_allocation]
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 showDirStructure(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
void computeResolution(Trajectory &trajectory, std::map< DetId, const PSimHit * > &hitIdMap, HResolution1DRecHit *histos)
void setCurrentFolder(const std::string &fullpath)
unsigned int detUnitId() const