59 const std::vector<DTRecHit1DPair>& pairs){
62 vector<DTHitPairForFit*> hitsForFit =
initHits(sl, pairs);
64 vector<DTSegmentCand*> candidates =
buildSegments(sl, hitsForFit);
66 vector<DTSegmentCand*>::const_iterator cand=candidates.begin();
67 while (cand<candidates.end()) {
74 cout<<
"Reconstructed 2D segments "<<*segment<<endl;
80 for (vector<DTHitPairForFit*>::iterator it = hitsForFit.begin(), ed = hitsForFit.end();
81 it != ed; ++it)
delete *it;
92 vector<DTHitPairForFit*>
94 const std::vector<DTRecHit1DPair>& hits){
96 vector<DTHitPairForFit*>
result;
97 for (vector<DTRecHit1DPair>::const_iterator
hit=hits.begin();
104 vector<DTSegmentCand*>
106 const std::vector<DTHitPairForFit*>& hits){
108 typedef vector<DTHitPairForFit*> hitCont;
109 typedef hitCont::const_iterator hitIter;
110 vector<DTSegmentCand*>
result;
114 cout <<
"buildSegments: " << sl->
id() <<
" nHits " << hits.size() << endl;
115 for (hitIter
hit=hits.begin();
hit!=hits.end(); ++
hit)
cout << **
hit<<
" wire: " << (*hit)->
id() <<
" DigiTime: " << (*hit)->digiTime() << endl;
123 cout <<
"Warning: this SuperLayer " << sl->
id() <<
" has too many hits : "
125 cout <<
"Skipping segment reconstruction... " << endl;
132 if ((sl->
id()).superlayer()==2)
137 vector<AssPoint> usedHits;
141 for (hitCont::const_iterator firstHit=hits.begin(); firstHit!=hits.end();
143 for (hitCont::const_reverse_iterator lastHit=hits.rbegin();
144 (*lastHit)!=(*firstHit); ++lastHit) {
147 if (!
geometryFilter((*firstHit)->id(),(*lastHit)->id()))
continue;
151 for (hitCont::const_iterator tmpHit=firstHit+1; (*tmpHit)!=(*lastHit); tmpHit++)
153 && (
geometryFilter((*tmpHit)->id(),(*firstHit)->id()))) hitsForFit.push_back(*tmpHit);
155 for (
int firstLR=0; firstLR<2; ++firstLR) {
156 for (
int lastLR=0; lastLR<2; ++lastLR) {
166 float DAlpha=fabs(gvec.
theta()-gvecIP.
theta());
167 if (DAlpha>DAlphaMax)
continue;
170 cout <<
"Selected hit pair:" << endl;
171 cout <<
" First " << *(*firstHit) <<
" Layer Id: " << (*firstHit)->id().layerId() <<
" Side: " << firstLR <<
" DigiTime: " << (*firstHit)->digiTime() << endl;
172 cout <<
" Last " << *(*lastHit) <<
" Layer Id: " << (*lastHit)->id().layerId() <<
" Side: " << lastLR <<
" DigiTime: " << (*lastHit)->digiTime() << endl;
175 vector<AssPoint> assHits;
177 assHits.push_back(
AssPoint(*firstHit,codes[firstLR]));
178 assHits.push_back(
AssPoint(*lastHit,codes[lastLR]));
182 addHits(sl,assHits,hitsForFit,result, usedHits);
190 cout <<
"Result (before cleaning): " << result.size() << endl;
191 for (vector<DTSegmentCand*>::const_iterator seg=result.begin(); seg!=result.end(); ++seg)
192 cout << *(*seg) << endl;
196 cout <<
"Result (after cleaning): " << result.size() << endl;
197 for (vector<DTSegmentCand*>::const_iterator seg=result.begin();
198 seg!=result.end(); ++seg)
199 cout << *(*seg) << endl;
209 vector<DTSegmentCand*> &
result, vector<AssPoint>& usedHits) {
211 typedef vector<DTHitPairForFit*> hitCont;
212 double chi2l,chi2r,t0_corrl,t0_corrr;
213 bool foundSomething =
false;
216 cout <<
"DTMeantimerPatternReco::addHit " << endl <<
" Picked " << assHits.size() <<
" hits, " << hits.size() <<
" left." << endl;
218 if (assHits.size()+hits.size()<
maxfound)
return;
221 for (hitCont::const_iterator
hit=hits.begin();
hit!=hits.end(); ++
hit) {
223 cout <<
" Trying B: " << **
hit<<
" wire: " << (*hit)->
id() << endl;
226 bool left_ok=
fitWithT0(assHits, chi2l, t0_corrl,0);
230 bool right_ok=
fitWithT0(assHits, chi2r, t0_corrr,0);
234 int nHits=assHits.size()+1;
235 cout <<
" Left: t0_corr = " << t0_corrl <<
"ns chi2/nHits = " << chi2l <<
"/" << nHits <<
" ok: " << left_ok << endl;
236 cout <<
" Right: t0_corr = " << t0_corrr <<
"ns chi2/nHits = " << chi2r <<
"/" << nHits <<
" ok: " << right_ok << endl;
239 if (!left_ok && !right_ok)
continue;
241 foundSomething =
true;
245 for (hitCont::const_iterator tmpHit=
hit+1; tmpHit!=hits.end(); tmpHit++)
246 if (
geometryFilter((*tmpHit)->id(),(*hit)->id())) hitsForFit.push_back(*tmpHit);
248 reverse(hitsForFit.begin(),hitsForFit.end());
251 if (assHits.size()>3 && left_ok && right_ok) {
252 if (chi2l<chi2r-0.1) right_ok=
false;
else
253 if (chi2r<chi2l-0.1) left_ok=
false;
257 addHits(sl,assHits,hitsForFit,result,usedHits);
262 addHits(sl,assHits,hitsForFit,result,usedHits);
267 if (foundSomething)
return;
270 if (assHits.size()<
maxfound)
return;
278 pointsSet.insert(assHits.begin(),assHits.end());
283 for (vector<AssPoint>::const_iterator hiti = assHits.begin()+1; hiti != assHits.end()-1; hiti++)
284 usedHits.push_back(*hiti);
288 if (
debug)
cout <<
"Segment built: " << *seg<< endl;
290 result.push_back(seg);
291 if (
debug)
cout <<
" Result is now " << result.size() << endl;
293 if (
debug)
cout <<
" Exists - skipping" << endl;
305 const int layerLowerCut[4]={0,-1,-2,-2};
306 const int layerUpperCut[4]={0, 2, 2, 3};
317 if (!deltaLayer)
return false;
321 cout <<
"*** WARNING! DT Layer numbers differ by more than 3! for hits: " << endl;
322 cout <<
" " << first << endl;
323 cout <<
" " << second << endl;
328 int deltaWire=first.
wire()-second.
wire();
329 if (second.
layerId().
layer()%2==0) deltaWire=-deltaWire;
330 if ((deltaWire<=layerLowerCut[deltaLayer]) || (deltaWire>=layerUpperCut[deltaLayer]))
return false;
339 typedef vector < pair<double,double> > hitCoord;
340 double a,
b,coordError,
x,
y;
341 double sx=0,sy=0,sxy=0,sxx=0,ssx=0,ssy=0,
s=0,ss=0;
342 int leftHits=0,rightHits=0;
344 if (assHits.size()<3)
return false;
347 coordError=((*(assHits.begin())).first)->localPositionError().xx();
349 for (vector<AssPoint>::const_iterator assHit=assHits.begin(); assHit!=assHits.end(); ++assHit) {
350 if (coordError!=((*(assHits.begin())).first)->localPositionError().xx())
351 cout <<
" DTMeantimerPatternReco: Warning! Hit errors different within one segment!" << endl;
353 x=((*assHit).first)->localPosition((*assHit).second).z();
354 y=((*assHit).first)->localPosition((*assHit).second).x();
375 if (fitdebug &&
debug)
376 cout <<
" DTMeantimerPatternReco::fitWithT0 Left hits: " << leftHits <<
" Right hits: " << rightHits << endl;
378 if (leftHits && rightHits) {
380 double delta = ss*ss*sxx+
s*sx*sx+
s*ssx*ssx-
s*
s*sxx-2*ss*sx*ssx;
384 a=(ssy*
s*ssx+sxy*ss*ss+sy*sx*
s-sy*ss*ssx-ssy*sx*ss-sxy*
s*
s)/delta;
385 b=(ssx*sy*ssx+sxx*ssy*ss+sx*sxy*
s-sxx*sy*
s-ssx*sxy*ss-sx*ssy*ssx)/delta;
386 t0_corr=(ssx*
s*sxy+sxx*ss*sy+sx*sx*ssy-sxx*
s*ssy-sx*ss*sxy-ssx*sx*sy)/delta;
389 double d =
s*sxx - sx*sx;
390 b = (sxx*sy- sx*sxy)/ d;
391 a = (
s*sxy - sx*sy) / d;
397 double chi,chi2_not0;
401 for (vector<AssPoint>::const_iterator assHit=assHits.begin(); assHit!=assHits.end(); ++assHit) {
402 x=((*assHit).first)->localPosition((*assHit).second).z();
403 y=((*assHit).first)->localPosition((*assHit).second).x();
406 chi2_not0+=chi*chi/coordError;
411 chi2+=chi*chi/coordError;
415 if (assHits.size()<4) {
418 if (chi2<200.)
return true;
424 if (
debug && fitdebug)
426 cout <<
" t0_corr = " << t0_corr <<
"ns chi2/nHits = " << chi2 <<
"/" << assHits.size() << endl;
428 if (((chi2/(assHits.size()-2)<
theMaxChi2) && (t0_corr<theMaxT0) && (t0_corr>
theMinT0)) || (assHits.size()==4)) {
429 cout <<
" a = " << a <<
" b = " << b << endl;
430 for (vector<AssPoint>::const_iterator assHit=assHits.begin(); assHit!=assHits.end(); ++assHit) {
431 x=((*assHit).first)->localPosition((*assHit).second).z();
432 y=((*assHit).first)->localPosition((*assHit).second).x();
433 cout <<
" z= " << x <<
" x= " <<
y;
435 else cout <<
" x_corr= " << y-t0_corr*0.00543;
436 cout <<
" seg= " << a*x+b << endl;
441 if ((chi2/(assHits.size()-2)<
theMaxChi2) && (t0_corr<theMaxT0) && (t0_corr>
theMinT0))
return true;
448 double s=0,sx=0,sy=0,
x,
y;
452 if (hits.size()==0)
return;
454 if (hits.size()==1) {
455 b=(*(hits.begin())).second;
457 for (
unsigned int i = 0;
i != hits.size();
i++) {
468 double d = s*sxx - sx*sx;
469 b = (sxx*sy- sx*sxy)/ d;
470 a = (s*sxy - sx*sy) / d;
477 for (vector<DTSegmentCand*>::iterator cand=cands.begin();
478 cand!=cands.end(); ++cand) {
479 if (*(*cand)==*seg)
return false;
480 if (((*cand)->nHits()>=seg->
nHits()) && ((*cand)->chi2ndof()<seg->
chi2ndof()))
481 if ((*cand)->nSharedHitPairs(*seg)>int(seg->
nHits()-2))
return false;
T getParameter(std::string const &) const
std::pair< DTHitPairForFit *, DTEnums::DTCellSide > AssPoint
T getUntrackedParameter(std::string const &, T const &) const
void update(DTRecSegment4D *seg, const bool calcT0=false) const
recompute hits position and refit the segment4D
virtual double chi2ndof() const
the chi2/NDOF of the fit
bool checkDoubleCandidates(std::vector< DTSegmentCand * > &segs, DTSegmentCand *seg)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
DTCellSide
Which side of the DT cell.
virtual void setChi2(double &chi2)
set chi2
virtual ~DTMeantimerPatternReco()
Destructor.
int layer() const
Return the layer number.
std::vector< DTSegmentCand * > clean(const std::vector< DTSegmentCand * > &inputCands) const
do the cleaning
DTSuperLayerId superlayerId() const
Return the corresponding SuperLayerId.
DTSegmentCleaner * theCleaner
Geom::Theta< T > theta() const
U second(std::pair< T, U > const &p)
DTSuperLayerId id() const
Return the DetId of this SL.
virtual void setES(const edm::EventSetup &setup)
void setES(const edm::EventSetup &setup)
set the setup
unsigned int theMaxAllowedHits
std::vector< DTHitPairForFit * > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
Abs< T >::type abs(const T &t)
int superLayer() const
Return the superlayer number.
bool fit(DTSegmentCand *seg) const
bool fitWithT0(const std::vector< AssPoint > &assHits, double &chi2, double &t0_corr, const bool fitdebug)
int wire() const
Return the wire number.
std::set< AssPoint, AssPointLessZ > AssPointCont
void rawFit(double &a, double &b, const std::vector< std::pair< double, double > > &hits)
virtual unsigned int nHits() const
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< DTHitPairForFit * > &hits)
bool geometryFilter(const DTWireId first, const DTWireId second) const
virtual edm::OwnVector< DTSLRecSegment2D > reconstruct(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
this function is called in the producer
void addHits(const DTSuperLayer *sl, std::vector< AssPoint > &assHits, const std::vector< DTHitPairForFit * > &hits, std::vector< DTSegmentCand * > &result, std::vector< AssPoint > &usedHits)
DTLayerId layerId() const
Return the corresponding LayerId.
DTMeantimerPatternReco(const edm::ParameterSet &pset)
Constructor.
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
edm::ESHandle< DTGeometry > theDTGeometry
DTSegmentUpdator * theUpdator