CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/SimMuon/MCTruth/src/TrackerMuonHitExtractor.cc

Go to the documentation of this file.
00001 //
00002 // modified & integrated by Giovanni Abbiendi
00003 // from code by Arun Luthra: UserCode/luthra/MuonTrackSelector/src/MuonTrackSelector.cc
00004 //
00005 #include "SimMuon/MCTruth/interface/TrackerMuonHitExtractor.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00008 #include "DataFormats/TrackReco/interface/Track.h"
00009 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00010 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00011 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00012 #include "DataFormats/MuonReco/interface/MuonSelectors.h"
00013 #include <sstream>
00014 
00015 TrackerMuonHitExtractor::TrackerMuonHitExtractor(const edm::ParameterSet& parset) :
00016   inputDTRecSegment4DCollection_(parset.getParameter<edm::InputTag>("inputDTRecSegment4DCollection")),
00017   inputCSCSegmentCollection_(parset.getParameter<edm::InputTag>("inputCSCSegmentCollection"))
00018 {
00019 }
00020 
00021 TrackerMuonHitExtractor::~TrackerMuonHitExtractor() {
00022 }
00023 
00024 void TrackerMuonHitExtractor::init(const edm::Event& iEvent, const edm::EventSetup& iSetup) 
00025 {
00026   iEvent.getByLabel(inputDTRecSegment4DCollection_, dtSegmentCollectionH_);
00027   iEvent.getByLabel(inputCSCSegmentCollection_, cscSegmentCollectionH_);
00028 
00029   edm::LogVerbatim("TrackerMuonHitExtractor") <<"\nThere are "<< dtSegmentCollectionH_->size()<<" DT segments.";
00030   unsigned int index_dt_segment = 0;
00031   for(DTRecSegment4DCollection::const_iterator segment = dtSegmentCollectionH_->begin();
00032       segment != dtSegmentCollectionH_->end(); ++segment , index_dt_segment++) {
00033     LocalPoint  segmentLocalPosition       = segment->localPosition();
00034     LocalVector segmentLocalDirection      = segment->localDirection();
00035     LocalError  segmentLocalPositionError  = segment->localPositionError();
00036     LocalError  segmentLocalDirectionError = segment->localDirectionError();
00037     DetId geoid = segment->geographicalId();
00038     DTChamberId dtdetid = DTChamberId(geoid);
00039     int wheel = dtdetid.wheel();
00040     int station = dtdetid.station();
00041     int sector = dtdetid.sector();
00042     
00043     float segmentX = segmentLocalPosition.x();
00044     float segmentY = segmentLocalPosition.y();
00045     float segmentdXdZ = segmentLocalDirection.x()/segmentLocalDirection.z();
00046     float segmentdYdZ = segmentLocalDirection.y()/segmentLocalDirection.z();
00047     float segmentXerr = sqrt(segmentLocalPositionError.xx());
00048     float segmentYerr = sqrt(segmentLocalPositionError.yy());
00049     float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
00050     float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
00051 
00052     edm::LogVerbatim("TrackerMuonHitExtractor") 
00053       <<"\nDT segment index :"<<index_dt_segment
00054       <<"\nchamber Wh:"<<wheel<<",St:"<<station<<",Se:"<<sector
00055       <<"\nLocal Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), " 
00056       <<"Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")"; 
00057   }
00058 
00059   edm::LogVerbatim("TrackerMuonHitExtractor") <<"\nThere are "<< cscSegmentCollectionH_->size()<<" CSC segments.";
00060   unsigned int index_csc_segment = 0;
00061   for(CSCSegmentCollection::const_iterator segment = cscSegmentCollectionH_->begin();
00062       segment != cscSegmentCollectionH_->end(); ++segment , index_csc_segment++) {
00063     LocalPoint  segmentLocalPosition       = segment->localPosition();
00064     LocalVector segmentLocalDirection      = segment->localDirection();
00065     LocalError  segmentLocalPositionError  = segment->localPositionError();
00066     LocalError  segmentLocalDirectionError = segment->localDirectionError();
00067 
00068     DetId geoid = segment->geographicalId();
00069     CSCDetId cscdetid = CSCDetId(geoid);
00070     int endcap = cscdetid.endcap();
00071     int station = cscdetid.station();
00072     int ring = cscdetid.ring();
00073     int chamber = cscdetid.chamber(); 
00074     
00075     float segmentX = segmentLocalPosition.x();
00076     float segmentY = segmentLocalPosition.y();
00077     float segmentdXdZ = segmentLocalDirection.x()/segmentLocalDirection.z();
00078     float segmentdYdZ = segmentLocalDirection.y()/segmentLocalDirection.z();
00079     float segmentXerr = sqrt(segmentLocalPositionError.xx());
00080     float segmentYerr = sqrt(segmentLocalPositionError.yy());
00081     float segmentdXdZerr = sqrt(segmentLocalDirectionError.xx());
00082     float segmentdYdZerr = sqrt(segmentLocalDirectionError.yy());
00083 
00084     edm::LogVerbatim("TrackerMuonHitExtractor") 
00085       <<"\nCSC segment index :"<<index_csc_segment
00086       <<"\nchamber Endcap:"<<endcap<<",St:"<<station<<",Ri:"<<ring<<",Ch:"<<chamber
00087       <<"\nLocal Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), " 
00088       <<"Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")"; 
00089   }
00090 
00091 }
00092 std::vector<const TrackingRecHit *>
00093 TrackerMuonHitExtractor::getMuonHits(const reco::Muon &mu) const {
00094         std::vector<const TrackingRecHit *> ret;
00095 
00096         int wheel, station, sector;
00097         int endcap, /*station, */ ring, chamber;
00098         
00099         edm::LogVerbatim("TrackerMuonHitExtractor") <<"Number of chambers: "<<mu.matches().size()
00100                                               <<", arbitrated: "<<mu.numberOfMatches(reco::Muon::SegmentAndTrackArbitration);
00101         unsigned int index_chamber = 0;
00102         
00103         for(std::vector<reco::MuonChamberMatch>::const_iterator chamberMatch = mu.matches().begin();
00104             chamberMatch != mu.matches().end(); ++chamberMatch, index_chamber++) {
00105           std::stringstream chamberStr;
00106           chamberStr <<"\nchamber index: "<<index_chamber; 
00107           
00108           int subdet = chamberMatch->detector();
00109           DetId did = chamberMatch->id;
00110           
00111           if (subdet == MuonSubdetId::DT) {
00112             DTChamberId dtdetid = DTChamberId(did);
00113             wheel = dtdetid.wheel();
00114             station = dtdetid.station();
00115             sector = dtdetid.sector();
00116             chamberStr << ", DT chamber Wh:"<<wheel<<",St:"<<station<<",Se:"<<sector;
00117           } 
00118           else if (subdet == MuonSubdetId::CSC) {
00119             CSCDetId cscdetid = CSCDetId(did);
00120             endcap = cscdetid.endcap();
00121             station = cscdetid.station();
00122             ring = cscdetid.ring();
00123             chamber = cscdetid.chamber();
00124             chamberStr << ", CSC chamber End:"<<endcap<<",St:"<<station<<",Ri:"<<ring<<",Ch:"<<chamber;
00125           }
00126           
00127           chamberStr << ", Number of segments: "<<chamberMatch->segmentMatches.size();
00128           edm::LogVerbatim("TrackerMuonHitExtractor") << chamberStr.str();
00129 
00130           unsigned int index_segment = 0;
00131           
00132           for(std::vector<reco::MuonSegmentMatch>::const_iterator segmentMatch = chamberMatch->segmentMatches.begin();
00133               segmentMatch != chamberMatch->segmentMatches.end(); ++segmentMatch, index_segment++) {
00134             
00135             float segmentX = segmentMatch->x;
00136             float segmentY = segmentMatch->y ;
00137             float segmentdXdZ = segmentMatch->dXdZ;
00138             float segmentdYdZ = segmentMatch->dYdZ;
00139             float segmentXerr = segmentMatch->xErr;
00140             float segmentYerr = segmentMatch->yErr;
00141             float segmentdXdZerr = segmentMatch->dXdZErr;
00142             float segmentdYdZerr = segmentMatch->dYdZErr;
00143             
00144             CSCSegmentRef segmentCSC = segmentMatch->cscSegmentRef;
00145             DTRecSegment4DRef segmentDT = segmentMatch->dtSegmentRef;
00146             
00147             bool segment_arbitrated_Ok = (segmentMatch->isMask(reco::MuonSegmentMatch::BestInChamberByDR) && 
00148                                           segmentMatch->isMask(reco::MuonSegmentMatch::BelongsToTrackByDR));
00149             
00150             std::string ARBITRATED(" ***Arbitrated Off*** ");
00151             if (segment_arbitrated_Ok) ARBITRATED = " ***ARBITRATED OK*** ";
00152 
00153             if (subdet == MuonSubdetId::DT) {         
00154               edm::LogVerbatim("TrackerMuonHitExtractor")
00155                 <<"\n\t segment index: "<<index_segment << ARBITRATED
00156                 <<"\n\t  Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), " 
00157                 <<"\n\t  Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")"; 
00158               
00159               if (!segment_arbitrated_Ok) continue;
00160 
00161               if (segmentDT.get() != 0) {
00162                 const DTRecSegment4D* segment = segmentDT.get();
00163                 
00164                 edm::LogVerbatim("TrackerMuonHitExtractor")<<"\t ===> MATCHING with DT segment with index = "<<segmentDT.key();
00165                 
00166                 if(segment->hasPhi()) {
00167                   const DTChamberRecSegment2D* phiSeg = segment->phiSegment();
00168                   std::vector<const TrackingRecHit*> phiHits = phiSeg->recHits();
00169                   for(std::vector<const TrackingRecHit*>::const_iterator ihit = phiHits.begin();
00170                       ihit != phiHits.end(); ++ihit) {
00171                     ret.push_back(*ihit);
00172                   }
00173                 }
00174                 
00175                 if(segment->hasZed()) {
00176                   const DTSLRecSegment2D* zSeg = (*segment).zSegment();
00177                   std::vector<const TrackingRecHit*> zedHits = zSeg->recHits();
00178                   for(std::vector<const TrackingRecHit*>::const_iterator ihit = zedHits.begin();
00179                       ihit != zedHits.end(); ++ihit) {
00180                     ret.push_back(*ihit);
00181                   }
00182                 }
00183               } else edm::LogWarning("TrackerMuonHitExtractor")<<"\n***WARNING: UNMATCHED DT segment ! \n";
00184             } // if (subdet == MuonSubdetId::DT)
00185             
00186             else if (subdet == MuonSubdetId::CSC) {
00187               edm::LogVerbatim("TrackerMuonHitExtractor")
00188                 <<"\n\t segment index: "<<index_segment << ARBITRATED
00189                 <<"\n\t  Local Position (X,Y)=("<<segmentX<<","<<segmentY<<") +/- ("<<segmentXerr<<","<<segmentYerr<<"), " 
00190                 <<"\n\t  Local Direction (dXdZ,dYdZ)=("<<segmentdXdZ<<","<<segmentdYdZ<<") +/- ("<<segmentdXdZerr<<","<<segmentdYdZerr<<")"; 
00191               
00192               if (!segment_arbitrated_Ok) continue;
00193 
00194               if (segmentCSC.get() != 0) {
00195                 const CSCSegment* segment = segmentCSC.get();
00196                 
00197                 edm::LogVerbatim("TrackerMuonHitExtractor")<<"\t ===> MATCHING with CSC segment with index = "<<segmentCSC.key();
00198                 
00199                 std::vector<const TrackingRecHit*> hits = segment->recHits();
00200                 for(std::vector<const TrackingRecHit*>::const_iterator ihit = hits.begin();
00201                     ihit != hits.end(); ++ihit) {
00202                   ret.push_back(*ihit);
00203                 }
00204               } else edm::LogWarning("TrackerMuonHitExtractor")<<"\n***WARNING: UNMATCHED CSC segment ! \n";
00205             }   // else if (subdet == MuonSubdetId::CSC)
00206             
00207           } // loop on vector<MuonSegmentMatch>   
00208         }  // loop on vector<MuonChamberMatch>  
00209 
00210         return ret;
00211 }
00212