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 // $Id: MuonTimingFiller.cc,v 1.13 2011/02/24 15:41:53 farrell3 Exp $
16 //
17 //
18 
19 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
29 
31 
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  theDTTimingExtractor_ = new DTTimingExtractor(dtTimingParameters);
49 
50  // Load parameters for the CSCTimingExtractor
51  edm::ParameterSet cscTimingParameters = iConfig.getParameter<edm::ParameterSet>("CSCTimingParameters");
52  theCSCTimingExtractor_ = new CSCTimingExtractor(cscTimingParameters);
53 
54  errorEB_ = iConfig.getParameter<double>("ErrorEB");
55  errorEE_ = iConfig.getParameter<double>("ErrorEE");
56  ecalEcut_ = iConfig.getParameter<double>("EcalEnergyCut");
57 
58  useDT_ = iConfig.getParameter<bool>("UseDT");
59  useCSC_ = iConfig.getParameter<bool>("UseCSC");
60  useECAL_ = iConfig.getParameter<bool>("UseECAL");
61 
62 }
63 
64 
66 {
69 }
70 
71 
72 //
73 // member functions
74 //
75 
76 void
78 {
79  TimeMeasurementSequence dtTmSeq,cscTmSeq;
80 
81  if ( !(muon.combinedMuon().isNull()) ) {
82  theDTTimingExtractor_->fillTiming(dtTmSeq, muon.combinedMuon(), iEvent, iSetup);
83  theCSCTimingExtractor_->fillTiming(cscTmSeq, muon.combinedMuon(), iEvent, iSetup);
84  } else
85  if ( !(muon.standAloneMuon().isNull()) ) {
86  theDTTimingExtractor_->fillTiming(dtTmSeq, muon.standAloneMuon(), iEvent, iSetup);
87  theCSCTimingExtractor_->fillTiming(cscTmSeq, muon.standAloneMuon(), iEvent, iSetup);
88  }
89 
90  // Fill DT-specific timing information block
91  fillTimeFromMeasurements(dtTmSeq, dtTime);
92 
93  // Fill CSC-specific timing information block
94  fillTimeFromMeasurements(cscTmSeq, cscTime);
95 
96  // Combine the TimeMeasurementSequences from all subdetectors
97  TimeMeasurementSequence combinedTmSeq;
98  combineTMSequences(muon,dtTmSeq,cscTmSeq,combinedTmSeq);
99  // add ECAL info
100  if (useECAL_) addEcalTime(muon,combinedTmSeq);
101 
102  // Fill the master timing block
103  fillTimeFromMeasurements(combinedTmSeq, combinedTime);
104 
105  LogTrace("MuonTime") << "Global 1/beta: " << combinedTime.inverseBeta() << " +/- " << combinedTime.inverseBetaErr()<<std::endl;
106  LogTrace("MuonTime") << " Free 1/beta: " << combinedTime.freeInverseBeta() << " +/- " << combinedTime.freeInverseBetaErr()<<std::endl;
107  LogTrace("MuonTime") << " Vertex time (in-out): " << combinedTime.timeAtIpInOut() << " +/- " << combinedTime.timeAtIpInOutErr()
108  << " # of points: " << combinedTime.nDof() <<std::endl;
109  LogTrace("MuonTime") << " Vertex time (out-in): " << combinedTime.timeAtIpOutIn() << " +/- " << combinedTime.timeAtIpOutInErr()<<std::endl;
110  LogTrace("MuonTime") << " direction: " << combinedTime.direction() << std::endl;
111 
112 }
113 
114 
115 void
117 
118  std::vector <double> x,y;
119  double invbeta=0, invbetaerr=0;
120  double vertexTime=0, vertexTimeErr=0, vertexTimeR=0, vertexTimeRErr=0;
121  double freeBeta, freeBetaErr, freeTime, freeTimeErr;
122 
123  if (tmSeq.dstnc.size()<=1) return;
124 
125  for (unsigned int i=0;i<tmSeq.dstnc.size();i++) {
126  invbeta+=(1.+tmSeq.local_t0.at(i)/tmSeq.dstnc.at(i)*30.)*tmSeq.weightInvbeta.at(i)/tmSeq.totalWeightInvbeta;
127  x.push_back(tmSeq.dstnc.at(i)/30.);
128  y.push_back(tmSeq.local_t0.at(i)+tmSeq.dstnc.at(i)/30.);
129  vertexTime+=tmSeq.local_t0.at(i)*tmSeq.weightVertex.at(i)/tmSeq.totalWeightVertex;
130  vertexTimeR+=(tmSeq.local_t0.at(i)+2*tmSeq.dstnc.at(i)/30.)*tmSeq.weightVertex.at(i)/tmSeq.totalWeightVertex;
131  }
132 
133  double diff;
134  for (unsigned int i=0;i<tmSeq.dstnc.size();i++) {
135  diff=(1.+tmSeq.local_t0.at(i)/tmSeq.dstnc.at(i)*30.)-invbeta;
136  invbetaerr+=diff*diff*tmSeq.weightInvbeta.at(i);
137  diff=tmSeq.local_t0.at(i)-vertexTime;
138  vertexTimeErr+=diff*diff*tmSeq.weightVertex.at(i);
139  diff=tmSeq.local_t0.at(i)+2*tmSeq.dstnc.at(i)/30.-vertexTimeR;
140  vertexTimeRErr+=diff*diff*tmSeq.weightVertex.at(i);
141  }
142 
143  double cf = 1./(tmSeq.dstnc.size()-1);
144  invbetaerr=sqrt(invbetaerr/tmSeq.totalWeightInvbeta*cf);
145  vertexTimeErr=sqrt(vertexTimeErr/tmSeq.totalWeightVertex*cf);
146  vertexTimeRErr=sqrt(vertexTimeRErr/tmSeq.totalWeightVertex*cf);
147 
148  muTime.setInverseBeta(invbeta);
149  muTime.setInverseBetaErr(invbetaerr);
150  muTime.setTimeAtIpInOut(vertexTime);
151  muTime.setTimeAtIpInOutErr(vertexTimeErr);
152  muTime.setTimeAtIpOutIn(vertexTimeR);
153  muTime.setTimeAtIpOutInErr(vertexTimeRErr);
154 
155  rawFit(freeBeta, freeBetaErr, freeTime, freeTimeErr, x, y);
156 
157  muTime.setFreeInverseBeta(freeBeta);
158  muTime.setFreeInverseBetaErr(freeBetaErr);
159 
160  muTime.setNDof(tmSeq.dstnc.size());
161 }
162 
163 void
166  TimeMeasurementSequence cscSeq,
167  TimeMeasurementSequence &cmbSeq ) {
168 
169  if (useDT_) for (unsigned int i=0;i<dtSeq.dstnc.size();i++) {
170  cmbSeq.dstnc.push_back(dtSeq.dstnc.at(i));
171  cmbSeq.local_t0.push_back(dtSeq.local_t0.at(i));
172  cmbSeq.weightVertex.push_back(dtSeq.weightVertex.at(i));
173  cmbSeq.weightInvbeta.push_back(dtSeq.weightInvbeta.at(i));
174 
175  cmbSeq.totalWeightVertex+=dtSeq.weightVertex.at(i);
176  cmbSeq.totalWeightInvbeta+=dtSeq.weightInvbeta.at(i);
177  }
178 
179  if (useCSC_) for (unsigned int i=0;i<cscSeq.dstnc.size();i++) {
180  cmbSeq.dstnc.push_back(cscSeq.dstnc.at(i));
181  cmbSeq.local_t0.push_back(cscSeq.local_t0.at(i));
182  cmbSeq.weightVertex.push_back(cscSeq.weightVertex.at(i));
183  cmbSeq.weightInvbeta.push_back(cscSeq.weightInvbeta.at(i));
184 
185  cmbSeq.totalWeightVertex+=cscSeq.weightVertex.at(i);
186  cmbSeq.totalWeightInvbeta+=cscSeq.weightInvbeta.at(i);
187  }
188 }
189 
190 
191 void
193  TimeMeasurementSequence &cmbSeq ) {
194 
195  reco::MuonEnergy muonE;
196  if (muon.isEnergyValid())
197  muonE = muon.calEnergy();
198 
199  // Cut on the crystal energy and restrict to the ECAL barrel for now
200 // if (muonE.emMax<ecalEcut_ || fabs(muon.eta())>1.5) return;
201  if (muonE.emMax<ecalEcut_) return;
202 
203  // A simple parametrization of the error on the ECAL time measurement
204  double emErr;
205  if (muonE.ecal_id.subdetId()==EcalBarrel) emErr= errorEB_/muonE.emMax; else
206  emErr=errorEE_/muonE.emMax;
207  double hitWeight = 1/(emErr*emErr);
208  double hitDist=muonE.ecal_position.r();
209 
210  cmbSeq.local_t0.push_back(muonE.ecal_time);
211  cmbSeq.weightVertex.push_back(hitWeight);
212  cmbSeq.weightInvbeta.push_back(hitDist*hitDist*hitWeight/(30.*30.));
213 
214  cmbSeq.dstnc.push_back(hitDist);
215 
216  cmbSeq.totalWeightVertex+=hitWeight;
217  cmbSeq.totalWeightInvbeta+=hitDist*hitDist*hitWeight/(30.*30.);
218 
219 }
220 
221 
222 
223 void
224 MuonTimingFiller::rawFit(double &a, double &da, double &b, double &db, const std::vector<double> hitsx, const std::vector<double> hitsy) {
225 
226  double s=0,sx=0,sy=0,x,y;
227  double sxx=0,sxy=0;
228 
229  a=b=0;
230  if (hitsx.size()==0) return;
231  if (hitsx.size()==1) {
232  b=hitsy[0];
233  } else {
234  for (unsigned int i = 0; i != hitsx.size(); i++) {
235  x=hitsx[i];
236  y=hitsy[i];
237  sy += y;
238  sxy+= x*y;
239  s += 1.;
240  sx += x;
241  sxx += x*x;
242  }
243 
244  double d = s*sxx - sx*sx;
245  b = (sxx*sy- sx*sxy)/ d;
246  a = (s*sxy - sx*sy) / d;
247  da = sqrt(sxx/d);
248  db = sqrt(s/d);
249  }
250 }
251 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
void setTimeAtIpOutInErr(const float timeErr)
Definition: MuonTimeExtra.h:52
void addEcalTime(const reco::Muon &muon, TimeMeasurementSequence &cmbSeq)
float inverseBetaErr() const
Definition: MuonTimeExtra.h:29
std::vector< double > local_t0
float inverseBeta() const
Definition: MuonTimeExtra.h:28
void combineTMSequences(const reco::Muon &muon, TimeMeasurementSequence dtSeq, TimeMeasurementSequence cscSeq, TimeMeasurementSequence &cmbSeq)
Direction direction() const
direction estimation based on time dispersion
Definition: MuonTimeExtra.h:55
tuple db
Definition: EcalCondDB.py:151
float timeAtIpOutInErr() const
Definition: MuonTimeExtra.h:50
int nDof() const
number of measurements used in timing calculation
Definition: MuonTimeExtra.h:23
void fillTiming(TimeMeasurementSequence &tmSequence, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
void rawFit(double &a, double &da, double &b, double &db, const std::vector< double > hitsx, const std::vector< double > hitsy)
float ecal_time
Calorimeter timing.
Definition: MuonEnergy.h:37
void setTimeAtIpOutIn(const float timeIp)
Definition: MuonTimeExtra.h:51
int iEvent
Definition: GenABIO.cc:243
bool isNull() const
Checks for null.
Definition: Ref.h:247
MuonTimingFiller(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:46
float timeAtIpInOutErr() const
Definition: MuonTimeExtra.h:45
std::vector< double > weightInvbeta
void setNDof(const int nDof)
Definition: MuonTimeExtra.h:24
float freeInverseBetaErr() const
Definition: MuonTimeExtra.h:38
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
#define LogTrace(id)
bool isEnergyValid() const
Definition: Muon.h:110
MuonEnergy calEnergy() const
get energy deposition information
Definition: Muon.h:112
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:56
float timeAtIpInOut() const
Definition: MuonTimeExtra.h:44
void setInverseBetaErr(const float iBetaErr)
Definition: MuonTimeExtra.h:31
DTTimingExtractor * theDTTimingExtractor_
double b
Definition: hdecay.h:120
CSCTimingExtractor * theCSCTimingExtractor_
void fillTiming(TimeMeasurementSequence &tmSequence, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
DetId ecal_id
DetId of the central ECAL crystal.
Definition: MuonEnergy.h:47
float freeInverseBeta() const
Definition: MuonTimeExtra.h:37
double a
Definition: hdecay.h:121
void setFreeInverseBetaErr(const float iBetaErr)
Definition: MuonTimeExtra.h:40
float timeAtIpOutIn() const
b) particle is moving from outside in
Definition: MuonTimeExtra.h:49
std::vector< double > dstnc
x
Definition: VDTMath.h:216
void fillTiming(const reco::Muon &muon, reco::MuonTimeExtra &dtTime, reco::MuonTimeExtra &cscTime, reco::MuonTimeExtra &combinedTime, edm::Event &iEvent, const edm::EventSetup &iSetup)
math::XYZPointF ecal_position
Trajectory position at the calorimeter.
Definition: MuonEnergy.h:43
void setFreeInverseBeta(const float iBeta)
Definition: MuonTimeExtra.h:39
std::vector< double > weightVertex
void setTimeAtIpInOut(const float timeIp)
Definition: MuonTimeExtra.h:46
void setTimeAtIpInOutErr(const float timeErr)
Definition: MuonTimeExtra.h:47
void fillTimeFromMeasurements(TimeMeasurementSequence tmSeq, reco::MuonTimeExtra &muTime)
virtual TrackRef standAloneMuon() const
reference to a stand-alone muon Track
Definition: Muon.h:53
void setInverseBeta(const float iBeta)
Definition: MuonTimeExtra.h:30