CMS 3D CMS Logo

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