CMS 3D CMS Logo

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