CMS 3D CMS Logo

MuonTimingFiller.cc
Go to the documentation of this file.
1 //
2 // Package: MuonTimingFiller
3 // Class: MuonTimingFiller
4 //
12 //
13 // Original Author: Piotr Traczyk, CERN
14 // Created: Mon Mar 16 12:27:22 CET 2009
15 //
16 //
17 
18 // system include files
19 #include <memory>
20 
21 // user include files
24 
27 
29 
35 
39 
40 //
41 // constructors and destructor
42 //
44  // Load parameters for the DTTimingExtractor
45  edm::ParameterSet dtTimingParameters = iConfig.getParameter<edm::ParameterSet>("DTTimingParameters");
46 
47  // Load parameters for the CSCTimingExtractor
48  edm::ParameterSet cscTimingParameters = iConfig.getParameter<edm::ParameterSet>("CSCTimingParameters");
49 
50  // Fallback mechanism for old configs (there the segment matcher was built inside the timing extractors)
51  edm::ParameterSet matchParameters;
52  if (iConfig.existsAs<edm::ParameterSet>("MatchParameters"))
53  matchParameters = iConfig.getParameter<edm::ParameterSet>("MatchParameters");
54  else
55  matchParameters = dtTimingParameters.getParameter<edm::ParameterSet>("MatchParameters");
56 
57  theMatcher_ = std::make_unique<MuonSegmentMatcher>(matchParameters, iC);
58  theDTTimingExtractor_ = std::make_unique<DTTimingExtractor>(dtTimingParameters, theMatcher_.get(), iC);
59  theCSCTimingExtractor_ = std::make_unique<CSCTimingExtractor>(cscTimingParameters, theMatcher_.get(), iC);
60 
61  errorEB_ = iConfig.getParameter<double>("ErrorEB");
62  errorEE_ = iConfig.getParameter<double>("ErrorEE");
63  ecalEcut_ = iConfig.getParameter<double>("EcalEnergyCut");
64 
65  useDT_ = iConfig.getParameter<bool>("UseDT");
66  useCSC_ = iConfig.getParameter<bool>("UseCSC");
67  useECAL_ = iConfig.getParameter<bool>("UseECAL");
68 }
69 
71 
72 //
73 // member functions
74 //
75 
77  reco::MuonTimeExtra& dtTime,
78  reco::MuonTimeExtra& cscTime,
79  reco::MuonTime& rpcTime,
80  reco::MuonTimeExtra& combinedTime,
82  const edm::EventSetup& iSetup) {
83  TimeMeasurementSequence dtTmSeq, cscTmSeq;
84 
85  if (!(muon.combinedMuon().isNull())) {
86  theDTTimingExtractor_->fillTiming(dtTmSeq, muon.combinedMuon(), iEvent, iSetup);
87  theCSCTimingExtractor_->fillTiming(cscTmSeq, muon.combinedMuon(), iEvent, iSetup);
88  } else {
89  if (!(muon.standAloneMuon().isNull())) {
90  theDTTimingExtractor_->fillTiming(dtTmSeq, muon.standAloneMuon(), iEvent, iSetup);
91  theCSCTimingExtractor_->fillTiming(cscTmSeq, muon.standAloneMuon(), iEvent, iSetup);
92  } else {
93  if (muon.isTrackerMuon()) {
94  std::vector<const DTRecSegment4D*> dtSegments;
95  std::vector<const CSCSegment*> cscSegments;
96  for (auto& chamber : muon.matches()) {
97  for (auto& segment : chamber.segmentMatches) {
98  // Use only the segments that passed arbitration to avoid mixing
99  // segments from in-time and out-of-time muons that may bias the result
100  // SegmentAndTrackArbitration
101  if (segment.isMask(reco::MuonSegmentMatch::BestInStationByDR) &&
103  if (!(segment.dtSegmentRef.isNull()))
104  dtSegments.push_back(segment.dtSegmentRef.get());
105  if (!(segment.cscSegmentRef.isNull()))
106  cscSegments.push_back(segment.cscSegmentRef.get());
107  }
108  }
109  }
110  theDTTimingExtractor_->fillTiming(dtTmSeq, dtSegments, muon.innerTrack(), iEvent, iSetup);
111  theCSCTimingExtractor_->fillTiming(cscTmSeq, cscSegments, muon.innerTrack(), iEvent, iSetup);
112  }
113  }
114  }
115 
116  // Fill DT-specific timing information block
117  fillTimeFromMeasurements(dtTmSeq, dtTime);
118 
119  // Fill CSC-specific timing information block
120  fillTimeFromMeasurements(cscTmSeq, cscTime);
121 
122  // Fill RPC-specific timing information block
123  fillRPCTime(muon, rpcTime, iEvent);
124 
125  // Combine the TimeMeasurementSequences from DT/CSC subdetectors
126  TimeMeasurementSequence combinedTmSeq;
127  combineTMSequences(muon, dtTmSeq, cscTmSeq, combinedTmSeq);
128  // add ECAL info
129  if (useECAL_)
130  addEcalTime(muon, combinedTmSeq);
131 
132  // Fill the master timing block
133  fillTimeFromMeasurements(combinedTmSeq, combinedTime);
134 
135  LogTrace("MuonTime") << "Global 1/beta: " << combinedTime.inverseBeta() << " +/- " << combinedTime.inverseBetaErr()
136  << std::endl;
137  LogTrace("MuonTime") << " Free 1/beta: " << combinedTime.freeInverseBeta() << " +/- "
138  << combinedTime.freeInverseBetaErr() << std::endl;
139  LogTrace("MuonTime") << " Vertex time (in-out): " << combinedTime.timeAtIpInOut() << " +/- "
140  << combinedTime.timeAtIpInOutErr() << " # of points: " << combinedTime.nDof() << std::endl;
141  LogTrace("MuonTime") << " Vertex time (out-in): " << combinedTime.timeAtIpOutIn() << " +/- "
142  << combinedTime.timeAtIpOutInErr() << std::endl;
143  LogTrace("MuonTime") << " direction: " << combinedTime.direction() << std::endl;
144 }
145 
147  std::vector<double> x, y;
148  double invbeta(0), invbetaerr(0);
149  double vertexTime(0), vertexTimeErr(0), vertexTimeR(0), vertexTimeRErr(0);
150  double freeBeta(0), freeBetaErr(0), freeTime(0), freeTimeErr(0);
151 
152  if (tmSeq.dstnc.size() <= 1)
153  return;
154 
155  for (unsigned int i = 0; i < tmSeq.dstnc.size(); i++) {
156  invbeta +=
157  (1. + tmSeq.local_t0.at(i) / tmSeq.dstnc.at(i) * 30.) * tmSeq.weightInvbeta.at(i) / tmSeq.totalWeightInvbeta;
158  x.push_back(tmSeq.dstnc.at(i) / 30.);
159  y.push_back(tmSeq.local_t0.at(i) + tmSeq.dstnc.at(i) / 30.);
160  vertexTime += tmSeq.local_t0.at(i) * tmSeq.weightTimeVtx.at(i) / tmSeq.totalWeightTimeVtx;
161  vertexTimeR +=
162  (tmSeq.local_t0.at(i) + 2 * tmSeq.dstnc.at(i) / 30.) * tmSeq.weightTimeVtx.at(i) / tmSeq.totalWeightTimeVtx;
163  }
164 
165  double diff;
166  for (unsigned int i = 0; i < tmSeq.dstnc.size(); i++) {
167  diff = (1. + tmSeq.local_t0.at(i) / tmSeq.dstnc.at(i) * 30.) - invbeta;
168  invbetaerr += diff * diff * tmSeq.weightInvbeta.at(i);
169  diff = tmSeq.local_t0.at(i) - vertexTime;
170  vertexTimeErr += diff * diff * tmSeq.weightTimeVtx.at(i);
171  diff = tmSeq.local_t0.at(i) + 2 * tmSeq.dstnc.at(i) / 30. - vertexTimeR;
172  vertexTimeRErr += diff * diff * tmSeq.weightTimeVtx.at(i);
173  }
174 
175  double cf = 1. / (tmSeq.dstnc.size() - 1);
176  invbetaerr = sqrt(invbetaerr / tmSeq.totalWeightInvbeta * cf);
177  vertexTimeErr = sqrt(vertexTimeErr / tmSeq.totalWeightTimeVtx * cf);
178  vertexTimeRErr = sqrt(vertexTimeRErr / tmSeq.totalWeightTimeVtx * cf);
179 
180  muTime.setInverseBeta(invbeta);
181  muTime.setInverseBetaErr(invbetaerr);
182  muTime.setTimeAtIpInOut(vertexTime);
183  muTime.setTimeAtIpInOutErr(vertexTimeErr);
184  muTime.setTimeAtIpOutIn(vertexTimeR);
185  muTime.setTimeAtIpOutInErr(vertexTimeRErr);
186 
187  rawFit(freeBeta, freeBetaErr, freeTime, freeTimeErr, x, y);
188 
189  muTime.setFreeInverseBeta(freeBeta);
190  muTime.setFreeInverseBetaErr(freeBetaErr);
191 
192  muTime.setNDof(tmSeq.dstnc.size());
193 }
194 
196  double trpc = 0, trpc2 = 0;
197 
198  reco::TrackRef staTrack = muon.standAloneMuon();
199  if (staTrack.isNull())
200  return;
201 
202  const std::vector<const RPCRecHit*> rpcHits = theMatcher_->matchRPC(*staTrack, iEvent);
203  const int nrpc = rpcHits.size();
204  for (const auto& hitRPC : rpcHits) {
205  const double time = hitRPC->timeError() < 0 ? hitRPC->BunchX() * 25. : hitRPC->time();
206  trpc += time;
207  trpc2 += time * time;
208  }
209 
210  if (nrpc == 0)
211  return;
212 
213  trpc2 = trpc2 / nrpc;
214  trpc = trpc / nrpc;
215  const double trpcerr = sqrt(std::max(0., trpc2 - trpc * trpc));
216 
217  rpcTime.timeAtIpInOut = trpc;
218  rpcTime.timeAtIpInOutErr = trpcerr;
219  rpcTime.nDof = nrpc;
220 
221  // currently unused
222  rpcTime.timeAtIpOutIn = 0.;
223  rpcTime.timeAtIpOutInErr = 0.;
224 }
225 
227  const TimeMeasurementSequence& dtSeq,
228  const TimeMeasurementSequence& cscSeq,
229  TimeMeasurementSequence& cmbSeq) {
230  if (useDT_)
231  for (unsigned int i = 0; i < dtSeq.dstnc.size(); i++) {
232  cmbSeq.dstnc.push_back(dtSeq.dstnc.at(i));
233  cmbSeq.local_t0.push_back(dtSeq.local_t0.at(i));
234  cmbSeq.weightTimeVtx.push_back(dtSeq.weightTimeVtx.at(i));
235  cmbSeq.weightInvbeta.push_back(dtSeq.weightInvbeta.at(i));
236 
237  cmbSeq.totalWeightTimeVtx += dtSeq.weightTimeVtx.at(i);
238  cmbSeq.totalWeightInvbeta += dtSeq.weightInvbeta.at(i);
239  }
240 
241  if (useCSC_)
242  for (unsigned int i = 0; i < cscSeq.dstnc.size(); i++) {
243  cmbSeq.dstnc.push_back(cscSeq.dstnc.at(i));
244  cmbSeq.local_t0.push_back(cscSeq.local_t0.at(i));
245  cmbSeq.weightTimeVtx.push_back(cscSeq.weightTimeVtx.at(i));
246  cmbSeq.weightInvbeta.push_back(cscSeq.weightInvbeta.at(i));
247 
248  cmbSeq.totalWeightTimeVtx += cscSeq.weightTimeVtx.at(i);
249  cmbSeq.totalWeightInvbeta += cscSeq.weightInvbeta.at(i);
250  }
251 }
252 
254  reco::MuonEnergy muonE;
255  if (muon.isEnergyValid())
256  muonE = muon.calEnergy();
257 
258  // Cut on the crystal energy and restrict to the ECAL barrel for now
259  // if (muonE.emMax<ecalEcut_ || fabs(muon.eta())>1.5) return;
260  if (muonE.emMax < ecalEcut_)
261  return;
262 
263  // A simple parametrization of the error on the ECAL time measurement
264  double emErr;
265  if (muonE.ecal_id.subdetId() == EcalBarrel)
266  emErr = errorEB_ / muonE.emMax;
267  else
268  emErr = errorEE_ / muonE.emMax;
269  double hitWeight = 1 / (emErr * emErr);
270  double hitDist = muonE.ecal_position.r();
271 
272  cmbSeq.local_t0.push_back(muonE.ecal_time);
273  cmbSeq.weightTimeVtx.push_back(hitWeight);
274  cmbSeq.weightInvbeta.push_back(hitDist * hitDist * hitWeight / (30. * 30.));
275 
276  cmbSeq.dstnc.push_back(hitDist);
277 
278  cmbSeq.totalWeightTimeVtx += hitWeight;
279  cmbSeq.totalWeightInvbeta += hitDist * hitDist * hitWeight / (30. * 30.);
280 }
281 
282 void MuonTimingFiller::rawFit(double& freeBeta,
283  double& freeBetaErr,
284  double& freeTime,
285  double& freeTimeErr,
286  const std::vector<double>& hitsx,
287  const std::vector<double>& hitsy) {
288  double s = 0, sx = 0, sy = 0, x, y;
289  double sxx = 0, sxy = 0;
290 
291  freeBeta = 0;
292  freeBetaErr = 0;
293  freeTime = 0;
294  freeTimeErr = 0;
295 
296  if (hitsx.empty())
297  return;
298  if (hitsx.size() == 1) {
299  freeTime = hitsy[0];
300  } else {
301  for (unsigned int i = 0; i != hitsx.size(); i++) {
302  x = hitsx[i];
303  y = hitsy[i];
304  sy += y;
305  sxy += x * y;
306  s += 1.;
307  sx += x;
308  sxx += x * x;
309  }
310 
311  double d = s * sxx - sx * sx;
312  freeTime = (sxx * sy - sx * sxy) / d;
313  freeBeta = (s * sxy - sx * sy) / d;
314  freeBetaErr = sqrt(sxx / d);
315  freeTimeErr = sqrt(s / d);
316  }
317 }
change_name.diff
diff
Definition: change_name.py:13
reco::MuonEnergy
Definition: MuonEnergy.h:17
MuonTimingFiller::MuonTimingFiller
MuonTimingFiller(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
Definition: MuonTimingFiller.cc:43
reco::MuonEnergy::ecal_time
float ecal_time
Calorimeter timing.
Definition: MuonEnergy.h:47
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:428
MuonTimingFiller::errorEE_
double errorEE_
Definition: MuonTimingFiller.h:68
Muon.h
MuonTimingFiller::theDTTimingExtractor_
std::unique_ptr< DTTimingExtractor > theDTTimingExtractor_
Definition: MuonTimingFiller.h:66
EDProducer.h
muon
Definition: MuonCocktails.h:17
MuonTimingFiller::addEcalTime
void addEcalTime(const reco::Muon &muon, TimeMeasurementSequence &cmbSeq)
Definition: MuonTimingFiller.cc:253
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
reco::MuonTimeExtra::timeAtIpInOutErr
float timeAtIpInOutErr() const
Definition: MuonTimeExtra.h:44
MuonTimingFiller::fillTiming
void fillTiming(const reco::Muon &muon, reco::MuonTimeExtra &dtTime, reco::MuonTimeExtra &cscTime, reco::MuonTime &rpcTime, reco::MuonTimeExtra &combinedTime, edm::Event &iEvent, const edm::EventSetup &iSetup)
Definition: MuonTimingFiller.cc:76
MuonTimingFiller::ecalEcut_
double ecalEcut_
Definition: MuonTimingFiller.h:68
reco::MuonTime::timeAtIpOutInErr
float timeAtIpOutInErr
Definition: MuonTime.h:17
reco::MuonTimeExtra::nDof
int nDof() const
number of measurements used in timing calculation
Definition: MuonTimeExtra.h:22
dtChamberEfficiency_cfi.cscSegments
cscSegments
Definition: dtChamberEfficiency_cfi.py:15
DDAxes::x
edm::ParameterSet::existsAs
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
MuonTimingFiller::combineTMSequences
void combineTMSequences(const reco::Muon &muon, const TimeMeasurementSequence &dtSeq, const TimeMeasurementSequence &cscSeq, TimeMeasurementSequence &cmbSeq)
Definition: MuonTimingFiller.cc:226
reco::MuonSegmentMatch::BelongsToTrackByDR
static const unsigned int BelongsToTrackByDR
Definition: MuonSegmentMatch.h:25
EcalBarrel
Definition: EcalSubdetector.h:10
reco::Muon
Definition: Muon.h:27
edm::Ref< TrackCollection >
reco::MuonTime
Definition: MuonTime.h:5
TimeMeasurementSequence::local_t0
std::vector< double > local_t0
Definition: TimeMeasurementSequence.h:18
reco::MuonTimeExtra::setTimeAtIpOutIn
void setTimeAtIpOutIn(const float timeIp)
Definition: MuonTimeExtra.h:50
MakerMacros.h
MuonTimeExtraMap.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
TimeMeasurementSequence::totalWeightTimeVtx
double totalWeightTimeVtx
Definition: TimeMeasurementSequence.h:23
reco::MuonTimeExtra
Definition: MuonTimeExtra.h:15
reco::MuonTimeExtra::setTimeAtIpInOutErr
void setTimeAtIpInOutErr(const float timeErr)
Definition: MuonTimeExtra.h:46
MuonFwd.h
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::MuonTimeExtra::inverseBetaErr
float inverseBetaErr() const
Definition: MuonTimeExtra.h:28
MuonTimeExtra.h
MuonTimingFiller::theMatcher_
std::unique_ptr< MuonSegmentMatcher > theMatcher_
Definition: MuonTimingFiller.h:65
MuonTimingFiller::fillTimeFromMeasurements
void fillTimeFromMeasurements(const TimeMeasurementSequence &tmSeq, reco::MuonTimeExtra &muTime)
Definition: MuonTimingFiller.cc:146
reco::MuonTimeExtra::inverseBeta
float inverseBeta() const
Definition: MuonTimeExtra.h:27
reco::MuonTimeExtra::freeInverseBetaErr
float freeInverseBetaErr() const
Definition: MuonTimeExtra.h:37
reco::MuonTimeExtra::setTimeAtIpInOut
void setTimeAtIpInOut(const float timeIp)
Definition: MuonTimeExtra.h:45
reco::MuonTime::nDof
int nDof
number of muon stations used
Definition: MuonTime.h:9
reco::MuonTimeExtra::timeAtIpOutIn
float timeAtIpOutIn() const
b) particle is moving from outside in
Definition: MuonTimeExtra.h:48
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EcalSubdetector.h
reco::MuonTimeExtra::setFreeInverseBetaErr
void setFreeInverseBetaErr(const float iBetaErr)
Definition: MuonTimeExtra.h:39
edm::ParameterSet
Definition: ParameterSet.h:47
reco::MuonTime::timeAtIpInOutErr
float timeAtIpInOutErr
Definition: MuonTime.h:14
Event.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
reco::MuonTime::timeAtIpOutIn
float timeAtIpOutIn
b) particle is moving from outside in
Definition: MuonTime.h:16
TimeMeasurementSequence::totalWeightInvbeta
double totalWeightInvbeta
Definition: TimeMeasurementSequence.h:22
MuonTimingFiller::useECAL_
bool useECAL_
Definition: MuonTimingFiller.h:69
iEvent
int iEvent
Definition: GenABIO.cc:224
TimeMeasurementSequence::weightTimeVtx
std::vector< double > weightTimeVtx
Definition: TimeMeasurementSequence.h:19
fftjetcommon_cfi.sy
sy
Definition: fftjetcommon_cfi.py:203
MuonTimingFiller::errorEB_
double errorEB_
Definition: MuonTimingFiller.h:68
MuonTimingFiller::rawFit
void rawFit(double &a, double &da, double &b, double &db, const std::vector< double > &hitsx, const std::vector< double > &hitsy)
Definition: MuonTimingFiller.cc:282
edm::EventSetup
Definition: EventSetup.h:57
reco::MuonTimeExtra::setTimeAtIpOutInErr
void setTimeAtIpOutInErr(const float timeErr)
Definition: MuonTimeExtra.h:51
TimeMeasurementSequence::weightInvbeta
std::vector< double > weightInvbeta
Definition: TimeMeasurementSequence.h:20
MuonTimingFiller::useCSC_
bool useCSC_
Definition: MuonTimingFiller.h:69
MuonTimingFiller.h
reco::MuonTimeExtra::timeAtIpOutInErr
float timeAtIpOutInErr() const
Definition: MuonTimeExtra.h:49
reco::MuonTimeExtra::direction
Direction direction() const
direction estimation based on time dispersion
Definition: MuonTimeExtra.h:54
reco::MuonEnergy::emMax
float emMax
maximal energy of ECAL crystal in the 5x5 shape
Definition: MuonEnergy.h:32
reco::MuonTimeExtra::setInverseBetaErr
void setInverseBetaErr(const float iBetaErr)
Definition: MuonTimeExtra.h:30
Frameworkfwd.h
RPCRecHit.h
relativeConstraints.chamber
chamber
Definition: relativeConstraints.py:53
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TimeMeasurementSequence.h
reco::MuonTimeExtra::setInverseBeta
void setInverseBeta(const float iBeta)
Definition: MuonTimeExtra.h:29
reco::MuonTimeExtra::freeInverseBeta
float freeInverseBeta() const
Definition: MuonTimeExtra.h:36
reco::MuonSegmentMatch::BestInStationByDR
static const unsigned int BestInStationByDR
Definition: MuonSegmentMatch.h:21
reco::MuonEnergy::ecal_position
math::XYZPointF ecal_position
Trajectory position at the calorimeter.
Definition: MuonEnergy.h:53
MuonTimingFiller::useDT_
bool useDT_
Definition: MuonTimingFiller.h:69
MuonTimingFiller::theCSCTimingExtractor_
std::unique_ptr< CSCTimingExtractor > theCSCTimingExtractor_
Definition: MuonTimingFiller.h:67
ztail.d
d
Definition: ztail.py:151
reco::MuonEnergy::ecal_id
DetId ecal_id
DetId of the central ECAL crystal.
Definition: MuonEnergy.h:57
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:224
ParameterSet.h
reco::MuonTime::timeAtIpInOut
float timeAtIpInOut
Definition: MuonTime.h:13
reco::MuonTimeExtra::timeAtIpInOut
float timeAtIpInOut() const
Definition: MuonTimeExtra.h:43
reco::MuonTimeExtra::setFreeInverseBeta
void setFreeInverseBeta(const float iBeta)
Definition: MuonTimeExtra.h:38
ntuplemaker.time
time
Definition: ntuplemaker.py:310
edm::Event
Definition: Event.h:73
TimeMeasurementSequence::dstnc
std::vector< double > dstnc
Definition: TimeMeasurementSequence.h:17
MuonTimingFiller::fillRPCTime
void fillRPCTime(const reco::Muon &muon, reco::MuonTime &muTime, edm::Event &iEvent)
Definition: MuonTimingFiller.cc:195
MuonTimingFiller::~MuonTimingFiller
~MuonTimingFiller()
Definition: MuonTimingFiller.cc:70
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
reco::MuonTimeExtra::setNDof
void setNDof(const int nDof)
Definition: MuonTimeExtra.h:23
TimeMeasurementSequence
Definition: TimeMeasurementSequence.h:15
fftjetcommon_cfi.sx
sx
Definition: fftjetcommon_cfi.py:202