CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
L2MuonSeedGenerator.cc
Go to the documentation of this file.
1 //-------------------------------------------------
2 //
17 //
18 //--------------------------------------------------
19 
20 // Class Header
22 
23 // Data Formats
36 
37 #include "CLHEP/Vector/ThreeVector.h"
38 
40 
41 // Framework
46 
54 
57 
58 using namespace std;
59 using namespace edm;
60 using namespace l1extra;
61 
62 // constructors
64  theSource(iConfig.getParameter<InputTag>("InputObjects")),
65  theL1GMTReadoutCollection(iConfig.getParameter<InputTag>("GMTReadoutCollection")),
66  thePropagatorName(iConfig.getParameter<string>("Propagator")),
67  theL1MinPt(iConfig.getParameter<double>("L1MinPt")),
68  theL1MaxEta(iConfig.getParameter<double>("L1MaxEta")),
69  theL1MinQuality(iConfig.getParameter<unsigned int>("L1MinQuality")){
70 
71  // service parameters
72  ParameterSet serviceParameters = iConfig.getParameter<ParameterSet>("ServiceParameters");
73 
74  // the services
75  theService = new MuonServiceProxy(serviceParameters);
76 
77  // the estimator
79 
80  produces<L2MuonTrajectorySeedCollection>();
81 }
82 
83 // destructor
85  if (theService) delete theService;
86  if (theEstimator) delete theEstimator;
87 }
88 
90 {
91  const std::string metname = "Muon|RecoMuon|L2MuonSeedGenerator";
93 
94  auto_ptr<L2MuonTrajectorySeedCollection> output(new L2MuonTrajectorySeedCollection());
95 
96  // Muon particles and GMT readout collection
98  iEvent.getByLabel(theL1GMTReadoutCollection,gmtrc_handle);
99  L1MuGMTReadoutRecord const& gmtrr = gmtrc_handle.product()->getRecord(0);
100 
102  iEvent.getByLabel(theSource, muColl);
103  LogTrace(metname) << "Number of muons " << muColl->size() << endl;
104 
105  L1MuonParticleCollection::const_iterator it;
106  L1MuonParticleRef::key_type l1ParticleIndex = 0;
107 
108  for(it = muColl->begin(); it != muColl->end(); ++it,++l1ParticleIndex) {
109 
110  const L1MuGMTExtendedCand muonCand = (*it).gmtMuonCand();
111  unsigned int quality = 0;
112  bool valid_charge = false;;
113 
114  if ( muonCand.empty() ) {
115  LogWarning(metname) << "L2MuonSeedGenerator: WARNING, no L1MuGMTCand! " << endl;
116  LogWarning(metname) << "L2MuonSeedGenerator: this should make sense only within MC tests" << endl;
117  // FIXME! Temporary to handle the MC input
118  quality = 7;
119  valid_charge = true;
120  }
121  else {
122  quality = muonCand.quality();
123  valid_charge = muonCand.charge_valid();
124  }
125 
126  float pt = (*it).pt();
127  float eta = (*it).eta();
128  float theta = 2*atan(exp(-eta));
129  float phi = (*it).phi();
130  int charge = (*it).charge();
131  // Set charge=0 for the time being if the valid charge bit is zero
132  if (!valid_charge) charge = 0;
133  bool barrel = !(*it).isForward();
134 
135  // Get a better eta and charge from regional information
136  // Phi has the same resolution in GMT than regionally, is not it?
137  if ( !(muonCand.empty()) ) {
138  int idx = -1;
139  vector<L1MuRegionalCand> rmc;
140  if ( !muonCand.isRPC() ) {
141  idx = muonCand.getDTCSCIndex();
142  if (muonCand.isFwd()) rmc = gmtrr.getCSCCands();
143  else rmc = gmtrr.getDTBXCands();
144  } else {
145  idx = muonCand.getRPCIndex();
146  if (muonCand.isFwd()) rmc = gmtrr.getFwdRPCCands();
147  else rmc = gmtrr.getBrlRPCCands();
148  }
149  if (idx>=0) {
150  eta = rmc[idx].etaValue();
151  //phi = rmc[idx].phiValue();
152  // Use this charge if the valid charge bit is zero
153  if (!valid_charge) charge = rmc[idx].chargeValue();
154  }
155  }
156 
157  if ( pt < theL1MinPt || fabs(eta) > theL1MaxEta ) continue;
158 
159  LogTrace(metname) << "New L2 Muon Seed";
160  LogTrace(metname) << "Pt = " << pt << " GeV/c";
161  LogTrace(metname) << "eta = " << eta;
162  LogTrace(metname) << "theta = " << theta << " rad";
163  LogTrace(metname) << "phi = " << phi << " rad";
164  LogTrace(metname) << "charge = "<< charge;
165  LogTrace(metname) << "In Barrel? = "<< barrel;
166 
167  if ( quality <= theL1MinQuality ) continue;
168  LogTrace(metname) << "quality = "<< quality;
169 
170  // Update the services
171  theService->update(iSetup);
172 
173  const DetLayer *detLayer = 0;
174  float radius = 0.;
175 
176  CLHEP::Hep3Vector vec(0.,1.,0.);
177  vec.setTheta(theta);
178  vec.setPhi(phi);
179 
180  // Get the det layer on which the state should be put
181  if ( barrel ){
182  LogTrace(metname) << "The seed is in the barrel";
183 
184  // MB2
185  DetId id = DTChamberId(0,2,0);
186  detLayer = theService->detLayerGeometry()->idToLayer(id);
187  LogTrace(metname) << "L2 Layer: " << debug.dumpLayer(detLayer);
188 
189  const BoundSurface* sur = &(detLayer->surface());
190  const BoundCylinder* bc = dynamic_cast<const BoundCylinder*>(sur);
191 
192  radius = fabs(bc->radius()/sin(theta));
193 
194  LogTrace(metname) << "radius "<<radius;
195 
196  if ( pt < 3.5 ) pt = 3.5;
197  }
198  else {
199  LogTrace(metname) << "The seed is in the endcap";
200 
201  DetId id;
202  // ME2
203  if ( theta < Geom::pi()/2. )
204  id = CSCDetId(1,2,0,0,0);
205  else
206  id = CSCDetId(2,2,0,0,0);
207 
208  detLayer = theService->detLayerGeometry()->idToLayer(id);
209  LogTrace(metname) << "L2 Layer: " << debug.dumpLayer(detLayer);
210 
211  radius = fabs(detLayer->position().z()/cos(theta));
212 
213  if( pt < 1.0) pt = 1.0;
214  }
215 
216  vec.setMag(radius);
217 
218  GlobalPoint pos(vec.x(),vec.y(),vec.z());
219 
220  GlobalVector mom(pt*cos(phi), pt*sin(phi), pt*cos(theta)/sin(theta));
221 
222  GlobalTrajectoryParameters param(pos,mom,charge,&*theService->magneticField());
223  AlgebraicSymMatrix mat(5,0);
224 
225  mat[0][0] = (0.25/pt)*(0.25/pt); // sigma^2(charge/abs_momentum)
226  if ( !barrel ) mat[0][0] = (0.4/pt)*(0.4/pt);
227 
228  //Assign q/pt = 0 +- 1/pt if charge has been declared invalid
229  if (!valid_charge) mat[0][0] = (1./pt)*(1./pt);
230 
231  mat[1][1] = 0.05*0.05; // sigma^2(lambda)
232  mat[2][2] = 0.2*0.2; // sigma^2(phi)
233  mat[3][3] = 20.*20.; // sigma^2(x_transverse))
234  mat[4][4] = 20.*20.; // sigma^2(y_transverse))
235 
237 
238  const FreeTrajectoryState state(param,error);
239 
240  LogTrace(metname) << "Free trajectory State from the parameters";
241  LogTrace(metname) << debug.dumpFTS(state);
242 
243  // Propagate the state on the MB2/ME2 surface
244  TrajectoryStateOnSurface tsos = theService->propagator(thePropagatorName)->propagate(state, detLayer->surface());
245 
246  LogTrace(metname) << "State after the propagation on the layer";
247  LogTrace(metname) << debug.dumpLayer(detLayer);
248  LogTrace(metname) << debug.dumpFTS(state);
249 
250  if (tsos.isValid()) {
251  // Get the compatible dets on the layer
252  std::vector< pair<const GeomDet*,TrajectoryStateOnSurface> >
253  detsWithStates = detLayer->compatibleDets(tsos,
254  *theService->propagator(thePropagatorName),
255  *theEstimator);
256  if (detsWithStates.size()){
257  TrajectoryStateTransform tsTransform;
258 
259  TrajectoryStateOnSurface newTSOS = detsWithStates.front().second;
260  const GeomDet *newTSOSDet = detsWithStates.front().first;
261 
262  LogTrace(metname) << "Most compatible det";
263  LogTrace(metname) << debug.dumpMuonId(newTSOSDet->geographicalId());
264 
265  if (newTSOS.isValid()){
266 
267  LogTrace(metname) << "State on it";
268  LogTrace(metname) << debug.dumpTSOS(newTSOS);
269 
270  // convert the TSOS into a PTSOD
271  PTrajectoryStateOnDet *seedTSOS = tsTransform.persistentState( newTSOS,newTSOSDet->geographicalId().rawId());
272 
274 
275  output->push_back(L2MuonTrajectorySeed(*seedTSOS,container,alongMomentum,
276  L1MuonParticleRef(muColl,l1ParticleIndex)));
277  }
278  }
279  }
280 
281  }
282 
283  iEvent.put(output);
284 }
285 
T getParameter(std::string const &) const
virtual const BoundSurface & surface() const =0
The surface of the GeometricSearchDet.
edm::InputTag theL1GMTReadoutCollection
std::string dumpLayer(const DetLayer *layer) const
const std::string metname
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
Geom::Theta< T > theta() const
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
T eta() const
std::vector< L1MuRegionalCand > getBrlRPCCands() const
get barrel RPC candidates vector
double charge(const std::vector< uint8_t > &Ampls)
virtual std::vector< DetWithState > compatibleDets(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
~L2MuonSeedGenerator()
Destructor.
std::string dumpMuonId(const DetId &id) const
std::string dumpFTS(const FreeTrajectoryState &fts) const
std::vector< L1MuRegionalCand > getFwdRPCCands() const
get forward RPC candidates vector
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
const unsigned theL1MinQuality
std::string dumpTSOS(const TrajectoryStateOnSurface &tsos) const
std::vector< L1MuRegionalCand > getCSCCands() const
get CSC candidates vector
void push_back(D *&d)
Definition: OwnVector.h:290
virtual void produce(edm::Event &, const edm::EventSetup &)
bool empty() const
is it an empty muon candidate?
Definition: L1MuGMTCand.h:66
int iEvent
Definition: GenABIO.cc:243
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:55
bool isRPC() const
get RPC bit (true=RPC, false = DT/CSC or matched)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
std::vector< L2MuonTrajectorySeed > L2MuonTrajectorySeedCollection
bool charge_valid() const
is the charge valid ?
Definition: L1MuGMTCand.h:140
T z() const
Definition: PV3DBase.h:58
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
unsigned getRPCIndex() const
get index of contributing RPC muon
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:74
PTrajectoryStateOnDet * persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid) const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
#define LogTrace(id)
unsigned int quality() const
get quality
Definition: L1MuGMTCand.h:95
Definition: DetId.h:20
unsigned getDTCSCIndex() const
get index of contributing DT/CSC muon
MeasurementEstimator * theEstimator
virtual const Surface::PositionType & position() const
Returns position of the surface.
std::vector< L1MuRegionalCand > getDTBXCands() const
get DT candidates vector
T const * product() const
Definition: Handle.h:74
edm::Ref< L1MuonParticleCollection > L1MuonParticleRef
char state
Definition: procUtils.cc:75
MuonServiceProxy * theService
the event setup proxy, it takes care the services update
double pi()
Definition: Pi.h:31
CLHEP::HepSymMatrix AlgebraicSymMatrix
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:169
L2MuonSeedGenerator(const edm::ParameterSet &)
Constructor.
#define debug
Definition: MEtoEDMFormat.h:34
bool isFwd() const
get forward bit (true=forward, false=barrel)
Definition: DDAxes.h:10