CMS 3D CMS Logo

SegmentsTrackAssociator.cc
Go to the documentation of this file.
1 
2 
3 /*
4  * See header file for a description of this class.
5  *
6  * \author C. Botta, G. Mila - INFN Torino
7  */
8 
9 
11 
22 
26 
32 
33 #include <vector>
34 
35 using namespace edm;
36 using namespace std;
37 
38 
39 
41 {
42  theDTSegmentLabel = iConfig.getUntrackedParameter<InputTag>("segmentsDt");
43  theCSCSegmentLabel = iConfig.getUntrackedParameter<InputTag>("segmentsCSC");
44  theSegmentContainerName = iConfig.getUntrackedParameter<InputTag>("SelectedSegments");
45 
46  numRecHit=0;
47  numRecHitDT=0;
48  numRecHitCSC=0;
49  metname = "SegmentsTrackAssociator";
50 
51  dtSegmentsToken = iC.consumes<DTRecSegment4DCollection>(theDTSegmentLabel) ;
52  cscSegmentsToken = iC.consumes<CSCSegmentCollection>(theCSCSegmentLabel) ;
53 
54 
55 }
56 
57 
59 
60 
62 
63  // The segment collections
65  iEvent.getByToken(dtSegmentsToken, dtSegments);
67  iEvent.getByToken(cscSegmentsToken, cscSegments);
68  ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
69  iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
70 
71 
77 
78  //loop over recHit
79  for(trackingRecHit_iterator recHit = Track.recHitsBegin(); recHit != Track.recHitsEnd(); ++recHit){
80 
81  if(!(*recHit)->isValid()) continue;
82 
83 
84  numRecHit++;
85 
86  //get the detector Id
87  DetId idRivHit = (*recHit)->geographicalId();
88 
89 
90  // DT recHits
91  if (idRivHit.det() == DetId::Muon && idRivHit.subdetId() == MuonSubdetId::DT ) {
92 
93  // get the RecHit Local Position
94  LocalPoint posTrackRecHit = (*recHit)->localPosition();
95 
97  numRecHitDT++;
98 
99  // get the chamber Id
100  DTChamberId chamberId(idRivHit.rawId());
101  // get the segments of the chamber
102  range = dtSegments->get(chamberId);
103 
104  // loop over segments
105  for (segment = range.first; segment!=range.second; segment++){
106 
107  DetId id = segment->geographicalId();
108  const GeomDet* det = theTrackingGeometry->idToDet(id);
109  vector<const TrackingRecHit*> segments2D = (&(*segment))->recHits();
110  // container for 4D segment recHits
111  vector <const TrackingRecHit*> dtRecHits;
112 
113  for(vector<const TrackingRecHit*>::const_iterator segm2D = segments2D.begin();
114  segm2D != segments2D.end();
115  segm2D++) {
116 
117  vector <const TrackingRecHit*> rHits1D = (*segm2D)->recHits();
118  for (int hit=0; hit<int(rHits1D.size()); hit++){
119  dtRecHits.push_back(rHits1D[hit]);
120  }
121 
122  }
123 
124  // loop over the recHit checking if there's the recHit of the track
125  for (unsigned int hit = 0; hit < dtRecHits.size(); hit++) {
126 
127  DetId idRivHitSeg = (*dtRecHits[hit]).geographicalId();
128  LocalPoint posDTSegment= segment->localPosition();
129  LocalPoint posSegDTRecHit = (*dtRecHits[hit]).localPosition();
130 
131  double rDT=sqrt(pow((posSegDTRecHit.x()-posTrackRecHit.x()),2) +pow((posSegDTRecHit.y()-posTrackRecHit.y()),2) + pow((posSegDTRecHit.z()-posTrackRecHit.z()),2));
132 
133  if (idRivHit == idRivHitSeg && rDT<0.0001){
134 
135  if (selectedDtSegments.empty()){
136  selectedDtSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det,&*segment));
137  LogTrace(metname) <<"First selected segment (from DT). Position : "<<posDTSegment<<" Chamber : "<<segment->chamberId();
138  }
139  else{
140  int check=0;
141  for(int segm=0; segm < int(selectedDtSegments.size()); ++segm) {
142  double dist=sqrt(pow((((*(selectedDtSegments[segm])).localPosition()).x()-posDTSegment.x()),2) +pow((((*(selectedDtSegments[segm])).localPosition()).y()-posDTSegment.y()),2) + pow((((*(selectedDtSegments[segm])).localPosition()).z()-posDTSegment.z()),2));
143  if(dist>30) check++;
144  }
145 
146  if(check==int(selectedDtSegments.size())){
147  selectedDtSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det,&*segment));
148  LogTrace(metname) <<"New DT selected segment. Position : "<<posDTSegment<<" Chamber : "<<segment->chamberId();
149  }
150  }
151  } // check to tag the segment as "selected"
152 
153  } // loop over segment recHits
154 
155  } // loop over DT segments
156  }
157 
158 
159  // CSC recHits
160  if (idRivHit.det() == DetId::Muon && idRivHit.subdetId() == MuonSubdetId::CSC ) {
161 
162  // get the RecHit Local Position
163  LocalPoint posTrackRecHit = (*recHit)->localPosition();
164 
166  numRecHitCSC++;
167 
168  // get the chamber Id
169  CSCDetId tempchamberId(idRivHit.rawId());
170 
171  int ring = tempchamberId.ring();
172  int station = tempchamberId.station();
173  int endcap = tempchamberId.endcap();
174  int chamber = tempchamberId.chamber();
175  CSCDetId chamberId(endcap, station, ring, chamber, 0);
176 
177  // get the segments of the chamber
178  range = cscSegments->get(chamberId);
179  // loop over segments
180  for(segment2 = range.first; segment2!=range.second; segment2++){
181 
182  DetId id2 = segment2->geographicalId();
183  const GeomDet* det2 = theTrackingGeometry->idToDet(id2);
184 
185  // container for CSC segment recHits
186  vector<const TrackingRecHit*> cscRecHits = (&(*segment2))->recHits();
187 
188  // loop over the recHit checking if there's the recHit of the track
189  for (unsigned int hit = 0; hit < cscRecHits.size(); hit++) {
190 
191  DetId idRivHitSeg = (*cscRecHits[hit]).geographicalId();
192  LocalPoint posSegCSCRecHit = (*cscRecHits[hit]).localPosition();
193  LocalPoint posCSCSegment= segment2->localPosition();
194 
195  double rCSC=sqrt(pow((posSegCSCRecHit.x()-posTrackRecHit.x()),2) +pow((posSegCSCRecHit.y()-posTrackRecHit.y()),2) + pow((posSegCSCRecHit.z()-posTrackRecHit.z()),2));
196 
197  if (idRivHit==idRivHitSeg && rCSC < 0.0001){
198 
199  if (selectedCscSegments.empty()){
200  selectedCscSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det2,&*segment2));
201  LogTrace(metname) <<"First selected segment (from CSC). Position: "<<posCSCSegment;
202  }
203  else{
204  int check=0;
205  for(int n=0; n< int(selectedCscSegments.size()); n++){
206  double dist = sqrt(pow(((*(selectedCscSegments[n])).localPosition().x()-posCSCSegment.x()),2) +pow(((*(selectedCscSegments[n])).localPosition().y()-posCSCSegment.y()),2) + pow(((*(selectedCscSegments[n])).localPosition().z()-posCSCSegment.z()),2));
207  if(dist>30) check++;
208  }
209  if(check==int(selectedCscSegments.size())){
210  selectedCscSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det2,&*segment2));
211  LogTrace(metname) <<"New CSC segment selected. Position : "<<posCSCSegment;
212  }
213  }
214 
215  } // check to tag the segment as "selected"
216 
217  } // loop over segment recHits
218 
219  } // loop over DT segments
220  }
221 
222  } // loop over track recHits
223 
224  LogTrace(metname) <<"N recHit:"<<numRecHit;
225  numRecHit=0;
226  LogTrace(metname) <<"N recHit DT:"<<numRecHitDT;
227  numRecHitDT=0;
228  LogTrace(metname) <<"N recHit CSC:"<<numRecHitCSC;
229  numRecHitCSC=0;
230 
231  copy(selectedDtSegments.begin(), selectedDtSegments.end(), back_inserter(selectedSegments));
232  LogTrace(metname) <<"N selected Dt segments:"<<selectedDtSegments.size();
233  copy(selectedCscSegments.begin(), selectedCscSegments.end(), back_inserter(selectedSegments));
234  LogTrace(metname) <<"N selected Csc segments:"<<selectedCscSegments.size();
235  LogTrace(metname) <<"N selected segments:"<<selectedSegments.size();
236 
237  return selectedSegments;
238 
239 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getUntrackedParameter(std::string const &, T const &) const
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:50
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
const std::string metname
virtual ~SegmentsTrackAssociator()
Destructor.
T y() const
Definition: PV3DBase.h:63
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
SegmentsTrackAssociator(const edm::ParameterSet &, edm::ConsumesCollector &iC)
Constructor.
int iEvent
Definition: GenABIO.cc:230
static const int CSC
Definition: MuonSubdetId.h:13
T sqrt(T t)
Definition: SSEVec.h:18
T z() const
Definition: PV3DBase.h:64
MuonTransientTrackingRecHit::MuonRecHitContainer associate(const edm::Event &, const edm::EventSetup &, const reco::Track &)
Get the analysis.
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define LogTrace(id)
Definition: DetId.h:18
const T & get() const
Definition: EventSetup.h:55
HLT enums.
const GeomDet * idToDet(DetId) const override
static const int DT
Definition: MuonSubdetId.h:12
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
T x() const
Definition: PV3DBase.h:62
static MuonRecHitPointer specificBuild(const GeomDet *geom, const TrackingRecHit *rh)
std::vector< MuonRecHitPointer > MuonRecHitContainer
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
static void check(T const &p, std::string const &id, SelectedProducts const &iProducts)
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109