CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTClusterer.cc
Go to the documentation of this file.
1 /******* \class DTClusterer *******
2  *
3  * Description:
4  *
5  * detailed description
6  *
7  * \author : Stefano Lacaprara - INFN LNL <stefano.lacaprara@pd.infn.it>
8  * $date : 17/04/2008 14:55:53 CEST $
9  *
10  * Modification:
11  *
12  *********************************/
13 
14 /* This Class Header */
16 
17 /* Collaborating Class Header */
21 using namespace edm;
22 
27 
32 
33 /* C++ Headers */
34 #include <iostream>
35 using namespace std;
36 
37 /* ====================================================================== */
38 
39 /* Constructor */
41  // Set verbose output
42  debug = pset.getUntrackedParameter<bool>("debug");
43 
44  // the name of the 1D rec hits collection
45  theRecHits1DLabel = pset.getParameter<InputTag>("recHits1DLabel");
46  // min number of hits to build a cluster
47  theMinHits = pset.getParameter<unsigned int>("minHits");
48  // min number of hits to build a cluster
49  theMinLayers = pset.getParameter<unsigned int>("minLayers");
50 
51  if(debug)
52  cout << "[DTClusterer] Constructor called" << endl;
53 
54  produces<DTRecClusterCollection>();
55 }
56 
57 /* Destructor */
59 }
60 
61 /* Operations */
63  if(debug)
64  cout << "[DTClusterer] produce called" << endl;
65  // Get the DT Geometry
66  ESHandle<DTGeometry> dtGeom;
67  setup.get<MuonGeometryRecord>().get(dtGeom);
68 
69  // Get the 1D rechits from the event
71  event.getByLabel(theRecHits1DLabel, allHits);
72 
73  // Create the pointer to the collection which will store the rechits
74  auto_ptr<DTRecClusterCollection> clusters(new DTRecClusterCollection());
75 
76  // Iterate through all hit collections ordered by LayerId
78  DTSuperLayerId oldSlId;
79  for (dtLayerIt = allHits->id_begin(); dtLayerIt != allHits->id_end(); ++dtLayerIt){
80  // The layerId
81  DTLayerId layerId = (*dtLayerIt);
82  const DTSuperLayerId SLId = layerId.superlayerId();
83  if (SLId==oldSlId) continue; // I'm on the same SL as before
84  oldSlId = SLId;
85 
86  if(debug) cout <<"Reconstructing the clusters in "<< SLId << endl;
87 
88  const DTSuperLayer* sl = dtGeom->superLayer(SLId);
89 
90  // Get all the rec hit in the same superLayer in which layerId relies
92  allHits->get(DTRangeMapAccessor::layersBySuperLayer(SLId));
93 
94  // Fill the vector with the 1D RecHit
95  vector<DTRecHit1DPair> pairs(range.first,range.second);
96  if(debug) cout << "Number of 1D-RecHit pairs " << pairs.size() << endl;
97  vector<DTSLRecCluster> clus=buildClusters(sl, pairs);
98  if(debug) cout << "Number of clusters build " << clus.size() << endl;
99  if (clus.size() > 0 )
100  clusters->put(sl->id(), clus.begin(), clus.end());
101  }
102  event.put(clusters);
103 }
104 
105 vector<DTSLRecCluster> DTClusterer::buildClusters(const DTSuperLayer* sl,
106  vector<DTRecHit1DPair>& pairs) {
107  // create a vector of hits with wire position in SL frame
108  vector<pair<float, DTRecHit1DPair> > hits = initHits(sl, pairs);
109 
110  vector<DTSLRecCluster> result;
111  // loop over pairs
112  vector<DTRecHit1DPair> adiacentPairs;
113  float lastPos=hits.front().first;
114  const float cellWidth=4.2; // cm
115  float sum=0.;
116  float sum2=0.;
117 
118  for (vector<pair<float, DTRecHit1DPair> >::const_iterator hit=hits.begin(); hit!=hits.end();
119  ++hit) {
120  if(debug) cout << "Hit: " << (*hit).first << " lastPos: " << lastPos << endl;
121  // start from first hits
122  // two cells are adiacente if their position is closer than cell width
123  if(abs((*hit).first-lastPos)>cellWidth ) {
124  if (adiacentPairs.size() >= theMinHits && differentLayers(adiacentPairs)>=theMinLayers) {
125  // if not, build the cluster with so far collection hits and go on
126  float mean=sum/adiacentPairs.size();
127  float err2=sum2/adiacentPairs.size()-mean*mean;
128  DTSLRecCluster cluster(sl->id(),
129  LocalPoint(mean,0.,0.),
130  LocalError(err2,0.,0.),
131  adiacentPairs);
132  if(debug) cout << "Cluster " << cluster << endl;
133  result.push_back(cluster);
134  }
135  // clean the vector
136  adiacentPairs.clear();
137  sum=0.;
138  sum2=0.;
139  }
140  // if adiacente, add them to a vector
141  adiacentPairs.push_back((*hit).second);
142  if(debug) cout << "adiacentPairs " << adiacentPairs.size() << endl;
143  sum+=(*hit).first;
144  sum2+=(*hit).first*(*hit).first;
145 
146  lastPos=(*hit).first;
147  }
148  // build the last cluster
149  if (adiacentPairs.size() >= theMinHits && differentLayers(adiacentPairs)>=theMinLayers) {
150  float mean=sum/adiacentPairs.size();
151  float err2=sum2/adiacentPairs.size()-mean*mean;
152  DTSLRecCluster cluster(sl->id(),
153  LocalPoint(mean,0.,0.),
154  LocalError(err2,0.,0.),
155  adiacentPairs);
156  if(debug) cout << "Cluster " << cluster << endl;
157  result.push_back(cluster);
158  }
159 
160  return result;
161 }
162 
163 vector<pair<float, DTRecHit1DPair> > DTClusterer::initHits(const DTSuperLayer* sl,
164  vector<DTRecHit1DPair>& pairs) {
165  vector<pair<float, DTRecHit1DPair> > result;
166  for (vector<DTRecHit1DPair>::const_iterator pair=pairs.begin();
167  pair!=pairs.end(); ++pair ) {
168 
169  // get wire
170  DTWireId wid = (*pair).wireId();
171  // get Layer
172  const DTLayer* lay= sl->layer(wid.layer());
173  // get wire position in SL (only x)
174  LocalPoint
175  posInLayer(lay->specificTopology().wirePosition(wid.wire()),0.,0.);
176  LocalPoint posInSL = sl->toLocal(lay->toGlobal(posInLayer));
177  // put the pair into result
178  result.push_back(make_pair(posInSL.x(), *pair));
179  }
180  // sorted by x
181  sort(result.begin(), result.end(), sortClusterByX());
182 
183  return result;
184 }
185 
186 unsigned int DTClusterer::differentLayers(vector<DTRecHit1DPair>& hits) {
187 // Count the number of different layers
188  int layers=0;
189  unsigned int result=0;
190  for (vector<DTRecHit1DPair>::const_iterator hit=hits.begin(); hit!=hits.end();
191  ++hit) {
192  int pos = (1 << ((*hit).wireId().layer() -1 ));
193  if (! (pos & layers)) {
194  result++;
195  layers |= pos;
196  }
197  }
198  return result;
199 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
float wirePosition(int wireNumber) const
Returns the x position in the layer of a given wire number.
Definition: DTTopology.cc:73
unsigned int differentLayers(std::vector< DTRecHit1DPair > &hits)
Definition: DTClusterer.cc:186
std::pair< const_iterator, const_iterator > range
iterator range
Definition: RangeMap.h:52
virtual void produce(edm::Event &event, const edm::EventSetup &setup)
Definition: DTClusterer.cc:62
edm::RangeMap< DTSuperLayerId, edm::OwnVector< DTSLRecCluster > > DTRecClusterCollection
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
static std::pair< DTLayerId, DTSuperLayerIdComparator > layersBySuperLayer(DTSuperLayerId slId)
Access by SL objects written into a RangeMap by layer.
#define abs(x)
Definition: mlp_lapack.h:159
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:64
identifier iterator
Definition: RangeMap.h:138
int layer() const
Return the layer number.
Definition: DTLayerId.h:55
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
Definition: DTLayerId.h:61
DTSuperLayerId id() const
Return the DetId of this SL.
Definition: DTSuperLayer.cc:38
const DTTopology & specificTopology() const
Definition: DTLayer.cc:44
tuple result
Definition: query.py:137
tuple pset
Definition: CrabTask.py:85
virtual ~DTClusterer()
Definition: DTClusterer.cc:58
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
std::vector< DTSLRecCluster > buildClusters(const DTSuperLayer *sl, std::vector< DTRecHit1DPair > &pairs)
Definition: DTClusterer.cc:105
const DTLayer * layer(DTLayerId id) const
Return the layer corresponding to the given id.
Definition: DTSuperLayer.cc:70
int wire() const
Return the wire number.
Definition: DTWireId.h:58
DTClusterer(const edm::ParameterSet &)
Definition: DTClusterer.cc:40
const T & get() const
Definition: EventSetup.h:55
Local3DPoint LocalPoint
Definition: LocalPoint.h:11
std::vector< std::pair< float, DTRecHit1DPair > > initHits(const DTSuperLayer *sl, std::vector< DTRecHit1DPair > &pairs)
Definition: DTClusterer.cc:163
tuple cout
Definition: gather_cfg.py:41
#define debug
Definition: MEtoEDMFormat.h:34
T x() const
Definition: PV3DBase.h:56