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 
35 
39 
40 //
41 // constructors and destructor
42 //
44 {
45  // Load parameters for the DTTimingExtractor
46  edm::ParameterSet dtTimingParameters = iConfig.getParameter<edm::ParameterSet>("DTTimingParameters");
47  theDTTimingExtractor_ = new DTTimingExtractor(dtTimingParameters,iC);
48 
49  // Load parameters for the CSCTimingExtractor
50  edm::ParameterSet cscTimingParameters = iConfig.getParameter<edm::ParameterSet>("CSCTimingParameters");
51  theCSCTimingExtractor_ = new CSCTimingExtractor(cscTimingParameters,iC);
52 
53  errorEB_ = iConfig.getParameter<double>("ErrorEB");
54  errorEE_ = iConfig.getParameter<double>("ErrorEE");
55  ecalEcut_ = iConfig.getParameter<double>("EcalEnergyCut");
56 
57  useDT_ = iConfig.getParameter<bool>("UseDT");
58  useCSC_ = iConfig.getParameter<bool>("UseCSC");
59  useECAL_ = iConfig.getParameter<bool>("UseECAL");
60 
61 }
62 
63 
65 {
68 }
69 
70 
71 //
72 // member functions
73 //
74 
75 void
77 {
78  TimeMeasurementSequence dtTmSeq,cscTmSeq;
79 
80  if ( !(muon.combinedMuon().isNull()) ) {
81  theDTTimingExtractor_->fillTiming(dtTmSeq, muon.combinedMuon(), iEvent, iSetup);
82  theCSCTimingExtractor_->fillTiming(cscTmSeq, muon.combinedMuon(), iEvent, iSetup);
83  } else
84  if ( !(muon.standAloneMuon().isNull()) ) {
85  theDTTimingExtractor_->fillTiming(dtTmSeq, muon.standAloneMuon(), iEvent, iSetup);
86  theCSCTimingExtractor_->fillTiming(cscTmSeq, muon.standAloneMuon(), iEvent, iSetup);
87  }
88 
89  // Fill DT-specific timing information block
90  fillTimeFromMeasurements(dtTmSeq, dtTime);
91 
92  // Fill CSC-specific timing information block
93  fillTimeFromMeasurements(cscTmSeq, cscTime);
94 
95  // Combine the TimeMeasurementSequences from all subdetectors
96  TimeMeasurementSequence combinedTmSeq;
97  combineTMSequences(muon,dtTmSeq,cscTmSeq,combinedTmSeq);
98  // add ECAL info
99  if (useECAL_) addEcalTime(muon,combinedTmSeq);
100 
101  // Fill the master timing block
102  fillTimeFromMeasurements(combinedTmSeq, combinedTime);
103 
104  LogTrace("MuonTime") << "Global 1/beta: " << combinedTime.inverseBeta() << " +/- " << combinedTime.inverseBetaErr()<<std::endl;
105  LogTrace("MuonTime") << " Free 1/beta: " << combinedTime.freeInverseBeta() << " +/- " << combinedTime.freeInverseBetaErr()<<std::endl;
106  LogTrace("MuonTime") << " Vertex time (in-out): " << combinedTime.timeAtIpInOut() << " +/- " << combinedTime.timeAtIpInOutErr()
107  << " # of points: " << combinedTime.nDof() <<std::endl;
108  LogTrace("MuonTime") << " Vertex time (out-in): " << combinedTime.timeAtIpOutIn() << " +/- " << combinedTime.timeAtIpOutInErr()<<std::endl;
109  LogTrace("MuonTime") << " direction: " << combinedTime.direction() << std::endl;
110 
111 }
112 
113 
114 void
116 
117  std::vector <double> x,y;
118  double invbeta=0, invbetaerr=0;
119  double vertexTime=0, vertexTimeErr=0, vertexTimeR=0, vertexTimeRErr=0;
120  double freeBeta, freeBetaErr, freeTime, freeTimeErr;
121 
122  if (tmSeq.dstnc.size()<=1) return;
123 
124  for (unsigned int i=0;i<tmSeq.dstnc.size();i++) {
125  invbeta+=(1.+tmSeq.local_t0.at(i)/tmSeq.dstnc.at(i)*30.)*tmSeq.weightInvbeta.at(i)/tmSeq.totalWeightInvbeta;
126  x.push_back(tmSeq.dstnc.at(i)/30.);
127  y.push_back(tmSeq.local_t0.at(i)+tmSeq.dstnc.at(i)/30.);
128  vertexTime+=tmSeq.local_t0.at(i)*tmSeq.weightVertex.at(i)/tmSeq.totalWeightVertex;
129  vertexTimeR+=(tmSeq.local_t0.at(i)+2*tmSeq.dstnc.at(i)/30.)*tmSeq.weightVertex.at(i)/tmSeq.totalWeightVertex;
130  }
131 
132  double diff;
133  for (unsigned int i=0;i<tmSeq.dstnc.size();i++) {
134  diff=(1.+tmSeq.local_t0.at(i)/tmSeq.dstnc.at(i)*30.)-invbeta;
135  invbetaerr+=diff*diff*tmSeq.weightInvbeta.at(i);
136  diff=tmSeq.local_t0.at(i)-vertexTime;
137  vertexTimeErr+=diff*diff*tmSeq.weightVertex.at(i);
138  diff=tmSeq.local_t0.at(i)+2*tmSeq.dstnc.at(i)/30.-vertexTimeR;
139  vertexTimeRErr+=diff*diff*tmSeq.weightVertex.at(i);
140  }
141 
142  double cf = 1./(tmSeq.dstnc.size()-1);
143  invbetaerr=sqrt(invbetaerr/tmSeq.totalWeightInvbeta*cf);
144  vertexTimeErr=sqrt(vertexTimeErr/tmSeq.totalWeightVertex*cf);
145  vertexTimeRErr=sqrt(vertexTimeRErr/tmSeq.totalWeightVertex*cf);
146 
147  muTime.setInverseBeta(invbeta);
148  muTime.setInverseBetaErr(invbetaerr);
149  muTime.setTimeAtIpInOut(vertexTime);
150  muTime.setTimeAtIpInOutErr(vertexTimeErr);
151  muTime.setTimeAtIpOutIn(vertexTimeR);
152  muTime.setTimeAtIpOutInErr(vertexTimeRErr);
153 
154  rawFit(freeBeta, freeBetaErr, freeTime, freeTimeErr, x, y);
155 
156  muTime.setFreeInverseBeta(freeBeta);
157  muTime.setFreeInverseBetaErr(freeBetaErr);
158 
159  muTime.setNDof(tmSeq.dstnc.size());
160 }
161 
162 void
164  const TimeMeasurementSequence& dtSeq,
165  const TimeMeasurementSequence& cscSeq,
166  TimeMeasurementSequence &cmbSeq ) {
167 
168  if (useDT_) for (unsigned int i=0;i<dtSeq.dstnc.size();i++) {
169  cmbSeq.dstnc.push_back(dtSeq.dstnc.at(i));
170  cmbSeq.local_t0.push_back(dtSeq.local_t0.at(i));
171  cmbSeq.weightVertex.push_back(dtSeq.weightVertex.at(i));
172  cmbSeq.weightInvbeta.push_back(dtSeq.weightInvbeta.at(i));
173 
174  cmbSeq.totalWeightVertex+=dtSeq.weightVertex.at(i);
175  cmbSeq.totalWeightInvbeta+=dtSeq.weightInvbeta.at(i);
176  }
177 
178  if (useCSC_) for (unsigned int i=0;i<cscSeq.dstnc.size();i++) {
179  cmbSeq.dstnc.push_back(cscSeq.dstnc.at(i));
180  cmbSeq.local_t0.push_back(cscSeq.local_t0.at(i));
181  cmbSeq.weightVertex.push_back(cscSeq.weightVertex.at(i));
182  cmbSeq.weightInvbeta.push_back(cscSeq.weightInvbeta.at(i));
183 
184  cmbSeq.totalWeightVertex+=cscSeq.weightVertex.at(i);
185  cmbSeq.totalWeightInvbeta+=cscSeq.weightInvbeta.at(i);
186  }
187 }
188 
189 
190 void
192  TimeMeasurementSequence &cmbSeq ) {
193 
194  reco::MuonEnergy muonE;
195  if (muon.isEnergyValid())
196  muonE = muon.calEnergy();
197 
198  // Cut on the crystal energy and restrict to the ECAL barrel for now
199 // if (muonE.emMax<ecalEcut_ || fabs(muon.eta())>1.5) return;
200  if (muonE.emMax<ecalEcut_) return;
201 
202  // A simple parametrization of the error on the ECAL time measurement
203  double emErr;
204  if (muonE.ecal_id.subdetId()==EcalBarrel) emErr= errorEB_/muonE.emMax; else
205  emErr=errorEE_/muonE.emMax;
206  double hitWeight = 1/(emErr*emErr);
207  double hitDist=muonE.ecal_position.r();
208 
209  cmbSeq.local_t0.push_back(muonE.ecal_time);
210  cmbSeq.weightVertex.push_back(hitWeight);
211  cmbSeq.weightInvbeta.push_back(hitDist*hitDist*hitWeight/(30.*30.));
212 
213  cmbSeq.dstnc.push_back(hitDist);
214 
215  cmbSeq.totalWeightVertex+=hitWeight;
216  cmbSeq.totalWeightInvbeta+=hitDist*hitDist*hitWeight/(30.*30.);
217 
218 }
219 
220 
221 
222 void
223 MuonTimingFiller::rawFit(double &a, double &da, double &b, double &db, const std::vector<double>& hitsx, const std::vector<double>& hitsy) {
224 
225  double s=0,sx=0,sy=0,x,y;
226  double sxx=0,sxy=0;
227 
228  a=b=0;
229  if (hitsx.size()==0) return;
230  if (hitsx.size()==1) {
231  b=hitsy[0];
232  } else {
233  for (unsigned int i = 0; i != hitsx.size(); i++) {
234  x=hitsx[i];
235  y=hitsy[i];
236  sy += y;
237  sxy+= x*y;
238  s += 1.;
239  sx += x;
240  sxx += x*x;
241  }
242 
243  double d = s*sxx - sx*sx;
244  b = (sxx*sy- sx*sxy)/ d;
245  a = (s*sxy - sx*sy) / d;
246  da = sqrt(sxx/d);
247  db = sqrt(s/d);
248  }
249 }
250 
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
void combineTMSequences(const reco::Muon &muon, const TimeMeasurementSequence &dtSeq, const TimeMeasurementSequence &cscSeq, TimeMeasurementSequence &cmbSeq)
std::vector< double > local_t0
float inverseBeta() const
Definition: MuonTimeExtra.h:27
Direction direction() const
direction estimation based on time dispersion
Definition: MuonTimeExtra.h:54
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
void fillTiming(TimeMeasurementSequence &tmSequence, reco::TrackRef muonTrack, const edm::Event &iEvent, const edm::EventSetup &iSetup)
MuonTimingFiller(const edm::ParameterSet &, edm::ConsumesCollector &&iC)
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:48
void rawFit(double &a, double &da, double &b, double &db, const std::vector< double > &hitsx, const std::vector< double > &hitsy)
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
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
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: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
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:38
std::vector< double > weightVertex
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