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.8 2010/03/09 08:19:03 ptraczyk 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  errorDT_ = iConfig.getParameter<double>("ErrorDT");
55  errorCSC_ = iConfig.getParameter<double>("ErrorCSC");
56  errorEB_ = iConfig.getParameter<double>("ErrorEB");
57  errorEE_ = iConfig.getParameter<double>("ErrorEE");
58  ecalEcut_ = iConfig.getParameter<double>("EcalEnergyCut");
59 
60  useDT_ = iConfig.getParameter<bool>("UseDT");
61  useCSC_ = iConfig.getParameter<bool>("UseCSC");
62  useECAL_ = iConfig.getParameter<bool>("UseECAL");
63 
64 }
65 
66 
68 {
71 }
72 
73 
74 //
75 // member functions
76 //
77 
78 void
80 {
81  TimeMeasurementSequence dtTmSeq,cscTmSeq;
82 
83  if ( !(muon.standAloneMuon().isNull()) ) {
84  theDTTimingExtractor_->fillTiming(dtTmSeq, muon.standAloneMuon(), iEvent, iSetup);
85  theCSCTimingExtractor_->fillTiming(cscTmSeq, muon.standAloneMuon(), iEvent, iSetup);
86  }
87 
88  // Fill DT-specific timing information block
89  fillTimeFromMeasurements(dtTmSeq, dtTime);
90 
91  // Fill CSC-specific timing information block
92  fillTimeFromMeasurements(cscTmSeq, cscTime);
93 
94  // Combine the TimeMeasurementSequences from all subdetectors
95  TimeMeasurementSequence combinedTmSeq;
96  combineTMSequences(muon,dtTmSeq,cscTmSeq,combinedTmSeq);
97  // add ECAL info
98  if (useECAL_) addEcalTime(muon,combinedTmSeq);
99 
100  // Fill the master timing block
101  fillTimeFromMeasurements(combinedTmSeq, combinedTime);
102 
103  LogTrace("MuonTime") << "Global 1/beta: " << combinedTime.inverseBeta() << " +/- " << combinedTime.inverseBetaErr()<<std::endl;
104  LogTrace("MuonTime") << " Free 1/beta: " << combinedTime.freeInverseBeta() << " +/- " << combinedTime.freeInverseBetaErr()<<std::endl;
105  LogTrace("MuonTime") << " Vertex time (in-out): " << combinedTime.timeAtIpInOut() << " +/- " << combinedTime.timeAtIpInOutErr()
106  << " # of points: " << combinedTime.nDof() <<std::endl;
107  LogTrace("MuonTime") << " Vertex time (out-in): " << combinedTime.timeAtIpOutIn() << " +/- " << combinedTime.timeAtIpOutInErr()<<std::endl;
108  LogTrace("MuonTime") << " direction: " << combinedTime.direction() << std::endl;
109 
110 }
111 
112 
113 void
115 
116  std::vector <double> x,y;
117  double invbeta=0, invbetaerr=0;
118  double vertexTime=0, vertexTimeErr=0, vertexTimeR=0, vertexTimeRErr=0;
119  double freeBeta, freeBetaErr, freeTime, freeTimeErr;
120 
121  if (tmSeq.dstnc.size()<=1) return;
122 
123  for (unsigned int i=0;i<tmSeq.dstnc.size();i++) {
124  invbeta+=(1.+tmSeq.local_t0.at(i)/tmSeq.dstnc.at(i)*30.)*tmSeq.weight.at(i)/tmSeq.totalWeight;
125  x.push_back(tmSeq.dstnc.at(i)/30.);
126  y.push_back(tmSeq.local_t0.at(i)+tmSeq.dstnc.at(i)/30.);
127  vertexTime+=tmSeq.local_t0.at(i)*tmSeq.weight.at(i)/tmSeq.totalWeight;
128  vertexTimeR+=(tmSeq.local_t0.at(i)+2*tmSeq.dstnc.at(i)/30.)*tmSeq.weight.at(i)/tmSeq.totalWeight;
129  }
130 
131  double diff;
132  for (unsigned int i=0;i<tmSeq.dstnc.size();i++) {
133  diff=(1.+tmSeq.local_t0.at(i)/tmSeq.dstnc.at(i)*30.)-invbeta;
134  invbetaerr+=diff*diff*tmSeq.weight.at(i);
135  diff=tmSeq.local_t0.at(i)-vertexTime;
136  vertexTimeErr+=diff*diff*tmSeq.weight.at(i);
137  diff=tmSeq.local_t0.at(i)+2*tmSeq.dstnc.at(i)/30.-vertexTimeR;
138  vertexTimeRErr+=diff*diff*tmSeq.weight.at(i);
139  }
140 
141  double cf = 1./(tmSeq.dstnc.size()-1);
142  invbetaerr=sqrt(invbetaerr/tmSeq.totalWeight*cf);
143  vertexTimeErr=sqrt(vertexTimeErr/tmSeq.totalWeight*cf);
144  vertexTimeRErr=sqrt(vertexTimeRErr/tmSeq.totalWeight*cf);
145 
146  muTime.setInverseBeta(invbeta);
147  muTime.setInverseBetaErr(invbetaerr);
148  muTime.setTimeAtIpInOut(vertexTime);
149  muTime.setTimeAtIpInOutErr(vertexTimeErr);
150  muTime.setTimeAtIpOutIn(vertexTimeR);
151  muTime.setTimeAtIpOutInErr(vertexTimeRErr);
152 
153  rawFit(freeBeta, freeBetaErr, freeTime, freeTimeErr, x, y);
154 
155  muTime.setFreeInverseBeta(freeBeta);
156  muTime.setFreeInverseBetaErr(freeBetaErr);
157 
158  muTime.setNDof(tmSeq.dstnc.size());
159 }
160 
161 void
164  TimeMeasurementSequence cscSeq,
165  TimeMeasurementSequence &cmbSeq ) {
166  double hitWeight;
167 
168  if (useDT_) for (unsigned int i=0;i<dtSeq.dstnc.size();i++) {
169  hitWeight=dtSeq.weight.at(i) / (errorDT_*errorDT_);
170 
171  cmbSeq.dstnc.push_back(dtSeq.dstnc.at(i));
172  cmbSeq.local_t0.push_back(dtSeq.local_t0.at(i));
173  cmbSeq.weight.push_back(hitWeight);
174 
175  cmbSeq.totalWeight+=hitWeight;
176  }
177 
178  if (useCSC_) for (unsigned int i=0;i<cscSeq.dstnc.size();i++) {
179  hitWeight=1./(errorCSC_*errorCSC_);
180 
181  cmbSeq.dstnc.push_back(cscSeq.dstnc.at(i));
182  cmbSeq.local_t0.push_back(cscSeq.local_t0.at(i));
183  cmbSeq.weight.push_back(hitWeight);
184 
185  cmbSeq.totalWeight+=hitWeight;
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 
208  cmbSeq.local_t0.push_back(muonE.ecal_time);
209  cmbSeq.weight.push_back(hitWeight);
210 
211  cmbSeq.dstnc.push_back(muonE.ecal_position.r());
212 
213  cmbSeq.totalWeight+=hitWeight;
214 
215 }
216 
217 
218 
219 void
220 MuonTimingFiller::rawFit(double &a, double &da, double &b, double &db, const std::vector<double> hitsx, const std::vector<double> hitsy) {
221 
222  double s=0,sx=0,sy=0,x,y;
223  double sxx=0,sxy=0;
224 
225  a=b=0;
226  if (hitsx.size()==0) return;
227  if (hitsx.size()==1) {
228  b=hitsy[0];
229  } else {
230  for (unsigned int i = 0; i != hitsx.size(); i++) {
231  x=hitsx[i];
232  y=hitsy[i];
233  sy += y;
234  sxy+= x*y;
235  s += 1.;
236  sx += x;
237  sxx += x*x;
238  }
239 
240  double d = s*sxx - sx*sx;
241  b = (sxx*sy- sx*sxy)/ d;
242  a = (s*sxy - sx*sy) / d;
243  da = sqrt(sxx/d);
244  db = sqrt(s/d);
245  }
246 }
247 
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)
std::vector< double > weight
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:244
MuonTimingFiller(const edm::ParameterSet &)
T sqrt(T t)
Definition: SSEVec.h:28
float timeAtIpInOutErr() const
Definition: MuonTimeExtra.h:45
void setNDof(const int nDof)
Definition: MuonTimeExtra.h:24
math::XYZPoint ecal_position
Trajectory position at the calorimeter.
Definition: MuonEnergy.h:43
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:60
MuonEnergy calEnergy() const
get energy deposition information
Definition: Muon.h:62
float emMax
maximal energy of ECAL crystal in the 5x5 shape
Definition: MuonEnergy.h:22
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
string s
Definition: asciidump.py:422
float timeAtIpOutIn() const
b) particle is moving from outside in
Definition: MuonTimeExtra.h:49
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)
void setFreeInverseBeta(const float iBeta)
Definition: MuonTimeExtra.h:39
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:42
void setInverseBeta(const float iBeta)
Definition: MuonTimeExtra.h:30