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: 2009/06/26 15:18:25 $
7  * $Revision: 1.3 $
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  // The segment collections
61  iEvent.getByLabel(theDTSegmentLabel, dtSegments);
63  iEvent.getByLabel(theCSCSegmentLabel, cscSegments);
64  ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
65  iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
66 
67 
73 
74  //loop over recHit
75  for(trackingRecHit_iterator recHit = Track.recHitsBegin(); recHit != Track.recHitsEnd(); ++recHit){
76 
77  if(!(*recHit)->isValid()) continue;
78 
79 
80  numRecHit++;
81 
82  //get the detector Id
83  DetId idRivHit = (*recHit)->geographicalId();
84 
85 
86  // DT recHits
87  if (idRivHit.det() == DetId::Muon && idRivHit.subdetId() == MuonSubdetId::DT ) {
88 
89  // get the RecHit Local Position
90  LocalPoint posTrackRecHit = (*recHit)->localPosition();
91 
93  numRecHitDT++;
94 
95  // get the chamber Id
96  DTChamberId chamberId(idRivHit.rawId());
97  // get the segments of the chamber
98  range = dtSegments->get(chamberId);
99 
100  // loop over segments
101  for (segment = range.first; segment!=range.second; segment++){
102 
103  DetId id = segment->geographicalId();
104  const GeomDet* det = theTrackingGeometry->idToDet(id);
105  vector<const TrackingRecHit*> segments2D = (&(*segment))->recHits();
106  // container for 4D segment recHits
107  vector <const TrackingRecHit*> dtRecHits;
108 
109  for(vector<const TrackingRecHit*>::const_iterator segm2D = segments2D.begin();
110  segm2D != segments2D.end();
111  segm2D++) {
112 
113  vector <const TrackingRecHit*> rHits1D = (*segm2D)->recHits();
114  for (int hit=0; hit<int(rHits1D.size()); hit++){
115  dtRecHits.push_back(rHits1D[hit]);
116  }
117 
118  }
119 
120  // loop over the recHit checking if there's the recHit of the track
121  for (unsigned int hit = 0; hit < dtRecHits.size(); hit++) {
122 
123  DetId idRivHitSeg = (*dtRecHits[hit]).geographicalId();
124  LocalPoint posDTSegment= segment->localPosition();
125  LocalPoint posSegDTRecHit = (*dtRecHits[hit]).localPosition();
126 
127  double rDT=sqrt(pow((posSegDTRecHit.x()-posTrackRecHit.x()),2) +pow((posSegDTRecHit.y()-posTrackRecHit.y()),2) + pow((posSegDTRecHit.z()-posTrackRecHit.z()),2));
128 
129  if (idRivHit == idRivHitSeg && rDT<0.0001){
130 
131  if (selectedDtSegments.empty()){
132  selectedDtSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det,&*segment));
133  LogTrace(metname) <<"First selected segment (from DT). Position : "<<posDTSegment<<" Chamber : "<<segment->chamberId();
134  }
135  else{
136  int check=0;
137  for(int segm=0; segm < int(selectedDtSegments.size()); ++segm) {
138  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));
139  if(dist>30) check++;
140  }
141 
142  if(check==int(selectedDtSegments.size())){
143  selectedDtSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det,&*segment));
144  LogTrace(metname) <<"New DT selected segment. Position : "<<posDTSegment<<" Chamber : "<<segment->chamberId();
145  }
146  }
147  } // check to tag the segment as "selected"
148 
149  } // loop over segment recHits
150 
151  } // loop over DT segments
152  }
153 
154 
155  // CSC recHits
156  if (idRivHit.det() == DetId::Muon && idRivHit.subdetId() == MuonSubdetId::CSC ) {
157 
158  // get the RecHit Local Position
159  LocalPoint posTrackRecHit = (*recHit)->localPosition();
160 
162  numRecHitCSC++;
163 
164  // get the chamber Id
165  CSCDetId tempchamberId(idRivHit.rawId());
166 
167  int ring = tempchamberId.ring();
168  int station = tempchamberId.station();
169  int endcap = tempchamberId.endcap();
170  int chamber = tempchamberId.chamber();
171  CSCDetId chamberId(endcap, station, ring, chamber, 0);
172 
173  // get the segments of the chamber
174  range = cscSegments->get(chamberId);
175  // loop over segments
176  for(segment2 = range.first; segment2!=range.second; segment2++){
177 
178  DetId id2 = segment2->geographicalId();
179  const GeomDet* det2 = theTrackingGeometry->idToDet(id2);
180 
181  // container for CSC segment recHits
182  vector<const TrackingRecHit*> cscRecHits = (&(*segment2))->recHits();
183 
184  // loop over the recHit checking if there's the recHit of the track
185  for (unsigned int hit = 0; hit < cscRecHits.size(); hit++) {
186 
187  DetId idRivHitSeg = (*cscRecHits[hit]).geographicalId();
188  LocalPoint posSegCSCRecHit = (*cscRecHits[hit]).localPosition();
189  LocalPoint posCSCSegment= segment2->localPosition();
190 
191  double rCSC=sqrt(pow((posSegCSCRecHit.x()-posTrackRecHit.x()),2) +pow((posSegCSCRecHit.y()-posTrackRecHit.y()),2) + pow((posSegCSCRecHit.z()-posTrackRecHit.z()),2));
192 
193  if (idRivHit==idRivHitSeg && rCSC < 0.0001){
194 
195  if (selectedCscSegments.empty()){
196  selectedCscSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det2,&*segment2));
197  LogTrace(metname) <<"First selected segment (from CSC). Position: "<<posCSCSegment;
198  }
199  else{
200  int check=0;
201  for(int n=0; n< int(selectedCscSegments.size()); n++){
202  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));
203  if(dist>30) check++;
204  }
205  if(check==int(selectedCscSegments.size())){
206  selectedCscSegments.push_back(MuonTransientTrackingRecHit::specificBuild(det2,&*segment2));
207  LogTrace(metname) <<"New CSC segment selected. Position : "<<posCSCSegment;
208  }
209  }
210 
211  } // check to tag the segment as "selected"
212 
213  } // loop over segment recHits
214 
215  } // loop over DT segments
216  }
217 
218  } // loop over track recHits
219 
220  LogTrace(metname) <<"N recHit:"<<numRecHit;
221  numRecHit=0;
222  LogTrace(metname) <<"N recHit DT:"<<numRecHitDT;
223  numRecHitDT=0;
224  LogTrace(metname) <<"N recHit CSC:"<<numRecHitCSC;
225  numRecHitCSC=0;
226 
227  copy(selectedDtSegments.begin(), selectedDtSegments.end(), back_inserter(selectedSegments));
228  LogTrace(metname) <<"N selected Dt segments:"<<selectedDtSegments.size();
229  copy(selectedCscSegments.begin(), selectedCscSegments.end(), back_inserter(selectedSegments));
230  LogTrace(metname) <<"N selected Csc segments:"<<selectedCscSegments.size();
231  LogTrace(metname) <<"N selected segments:"<<selectedSegments.size();
232 
233  return selectedSegments;
234 
235 }
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
T y() const
Definition: PV3DBase.h:62
double double double 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:46
T z() const
Definition: PV3DBase.h:63
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:356
#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:61
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