34 typedef std::vector<std::shared_ptr<DTHitPairForFit>>
hitCont;
42 theAlgoName(
"DTMeantimerPatternReco")
63 const std::vector<DTRecHit1DPair>& pairs){
66 std::vector<std::shared_ptr<DTHitPairForFit>> hitsForFit =
initHits(sl, pairs);
70 vector<DTSegmentCand*>::const_iterator cand=candidates.begin();
71 while (cand<candidates.end()) {
76 if (
debug)
cout<<
"Reconstructed 2D segments "<<*segment<<endl;
91 vector<std::shared_ptr<DTHitPairForFit>>
93 const std::vector<DTRecHit1DPair>& hits){
96 for (vector<DTRecHit1DPair>::const_iterator
hit=hits.begin();
98 result.push_back(std::make_shared<DTHitPairForFit>(*
hit, *sl,
theDTGeometry));
103 vector<DTSegmentCand*>
105 const std::vector<std::shared_ptr<DTHitPairForFit>>& hits){
107 vector<DTSegmentCand*>
result;
111 cout <<
"buildSegments: " << sl->
id() <<
" nHits " << hits.size() << endl;
112 for (
hitIter hit=hits.begin();
hit!=hits.end(); ++
hit)
cout << **
hit<<
" wire: " << (*hit)->
id() <<
" DigiTime: " << (*hit)->digiTime() << endl;
117 cout <<
"Warning: this SuperLayer " << sl->
id() <<
" has too many hits : "
119 cout <<
"Skipping segment reconstruction... " << endl;
126 if ((sl->
id()).superlayer()==2)
133 for (hitCont::const_iterator firstHit=hits.begin(); firstHit!=hits.end();
135 for (hitCont::const_reverse_iterator lastHit=hits.rbegin();
136 (*lastHit)!=(*firstHit); ++lastHit) {
139 if (!
geometryFilter((*firstHit)->id(),(*lastHit)->id()))
continue;
143 for (hitCont::const_iterator tmpHit=firstHit+1; (*tmpHit)!=(*lastHit); tmpHit++)
145 && (
geometryFilter((*tmpHit)->id(),(*firstHit)->id()))) hitsForFit.push_back(*tmpHit);
147 for (
int firstLR=0; firstLR<2; ++firstLR) {
148 for (
int lastLR=0; lastLR<2; ++lastLR) {
158 float DAlpha=fabs(gvec.
theta()-gvecIP.
theta());
159 if (DAlpha>DAlphaMax)
continue;
168 std::unique_ptr<DTSegmentCand> segCand(
new DTSegmentCand(pointSet,sl));
169 segCand->add(*firstHit,codes[firstLR]);
170 segCand->add(*lastHit,codes[lastLR]);
182 cout <<
"Result (before cleaning): " << result.size() << endl;
183 for (vector<DTSegmentCand*>::const_iterator seg=result.begin(); seg!=result.end(); ++seg)
cout << *(*seg) << endl;
189 cout <<
"Result (after cleaning): " << result.size() << endl;
190 for (vector<DTSegmentCand*>::const_iterator seg=result.begin(); seg!=result.end(); ++seg)
cout << *(*seg) << endl;
198 vector<DTSegmentCand*> &
result) {
200 double chi2l,chi2r,t0l,t0r;
201 bool foundSomething =
false;
204 cout <<
" DTMeantimerPatternReco::addHit " << endl <<
" Picked " << segCand->
nHits() <<
" hits, " << hits.size() <<
" left." << endl;
209 for (hitCont::const_iterator
hit=hits.begin();
hit!=hits.end(); ++
hit) {
220 bool left_ok=(
fitWithT0(segCand,0)?
true:
false);
221 chi2l=segCand->
chi2();
226 bool right_ok=(
fitWithT0(segCand,0)?
true:
false);
227 chi2r=segCand->
chi2();
232 int nHits=segCand->
nHits()+1;
233 cout <<
" Left: t0= " << t0l <<
" chi2/nHits= " << chi2l <<
"/" << nHits <<
" ok: " << left_ok << endl;
234 cout <<
" Right: t0= " << t0r <<
" chi2/nHits= " << chi2r <<
"/" << nHits <<
" ok: " << right_ok << endl;
237 if (!left_ok && !right_ok)
continue;
239 foundSomething =
true;
243 for (hitCont::const_iterator tmpHit=
hit+1; tmpHit!=hits.end(); tmpHit++)
244 if (
geometryFilter((*tmpHit)->id(),(*hit)->id())) hitsForFit.push_back(*tmpHit);
246 reverse(hitsForFit.begin(),hitsForFit.end());
249 if (segCand->
nHits()>3 && left_ok && right_ok) {
250 if (chi2l<chi2r-0.1) right_ok=
false;
else
251 if (chi2r<chi2l-0.1) left_ok=
false;
256 addHits(segCand,hitsForFit,result);
262 addHits(segCand,hitsForFit,result);
267 if (foundSomething)
return;
277 if (!segCand->
good()) {
283 if (
debug)
cout << endl <<
" Seg t0= " << segCand->
t0() << endl << *segCand << endl;
287 if (
debug)
cout <<
" Result is now " << result.size() << endl;
289 if (
debug)
cout <<
" Exists - skipping" << endl;
299 const int layerLowerCut[4]={0,-1,-2,-2};
300 const int layerUpperCut[4]={0, 2, 2, 3};
311 if (!deltaLayer)
return false;
315 cout <<
"*** WARNING! DT Layer numbers differ by more than 3! for hits: " << endl;
316 cout <<
" " << first << endl;
317 cout <<
" " << second << endl;
322 int deltaWire=first.
wire()-second.
wire();
323 if (second.
layerId().
layer()%2==0) deltaWire=-deltaWire;
324 if ((deltaWire<=layerLowerCut[deltaLayer]) || (deltaWire>=layerUpperCut[deltaLayer]))
return false;
340 if (chi2==-1.)
return nullptr;
343 if (seg->
nHits()==3)
return seg;
347 if (chi2<100.)
return seg;
361 for (vector<DTSegmentCand*>::iterator cand=cands.begin();
362 cand!=cands.end(); ++cand) {
363 if (*(*cand)==*seg)
return false;
364 if (((*cand)->nHits()>=seg->
nHits()) && ((*cand)->chi2ndof()<seg->
chi2ndof()))
365 if ((*cand)->nSharedHitPairs(*seg)>int(seg->
nHits()-2))
return false;
375 char mark[26]={
". . . . . . . . . . . . "};
376 int wire[12]={0,0,0,0,0,0,0,0,0,0,0,0};
378 for (vector<DTSegmentCand::AssPoint>::const_iterator assHit=assHits.begin(); assHit!=assHits.end(); ++assHit) {
379 int lay = (((*assHit).first)->
id().superlayerId().superLayer()-1)*4 + ((*assHit).first)->id().layerId().layer()-1;
380 wire[lay]= ((*assHit).first)->
id().wire();
381 if ((*assHit).second==
DTEnums::Left) mark[lay*2]=
'L';
else mark[lay*2]=
'R';
384 int lay = ((*hit).id().superlayerId().superLayer()-1)*4 + (*hit).id().layerId().layer() - 1;
385 wire[lay]= (*hit).id().wire();
388 cout <<
" " << mark << endl <<
" ";
389 for (
int i=0;
i<12;
i++)
if (wire[
i])
cout << setw(2) << wire[
i];
else cout <<
" ";
std::pair< std::shared_ptr< DTHitPairForFit >, DTEnums::DTCellSide > AssPoint
std::vector< std::shared_ptr< DTHitPairForFit > > initHits(const DTSuperLayer *sl, const std::vector< DTRecHit1DPair > &hits)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
virtual double chi2ndof() const
the chi2/NDOF of the fit
bool checkDoubleCandidates(std::vector< DTSegmentCand * > &segs, DTSegmentCand *seg)
void addHits(DTSegmentCand *segCand, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits, std::vector< DTSegmentCand * > &result)
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 ~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.
virtual bool good() const
std::vector< std::shared_ptr< DTHitPairForFit > > hitCont
DTSegmentCleaner * theCleaner
Geom::Theta< T > theta() const
U second(std::pair< T, U > const &p)
DTSuperLayerId id() const
Return the DetId of this SL.
DTSegmentCand * fitWithT0(DTSegmentCand *seg, const bool fitdebug)
std::vector< DTSegmentCand * > buildSegments(const DTSuperLayer *sl, const std::vector< std::shared_ptr< DTHitPairForFit >> &hits)
virtual void setES(const edm::EventSetup &setup)
void setES(const edm::EventSetup &setup)
set the setup
virtual void add(AssPoint newHit)
add hits to the hit list.
unsigned int theMaxAllowedHits
Abs< T >::type abs(const T &t)
int superLayer() const
Return the superlayer number.
virtual double chi2() const
the chi2 (NOT chi2/NDOF) of the fit
int wire() const
Return the wire number.
void printPattern(std::vector< DTSegmentCand::AssPoint > &assHits, const DTHitPairForFit *hit)
std::set< AssPoint, AssPointLessZ > AssPointCont
virtual unsigned int nHits() const
hitCont::const_iterator hitIter
virtual double t0() const
the t0 of the segment
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
DTLayerId layerId() const
Return the corresponding LayerId.
DTMeantimerPatternReco(const edm::ParameterSet &pset)
Constructor.
virtual void removeHit(AssPoint hit)
remove hit from the candidate
void update(DTRecSegment4D *seg, const bool calcT0, bool allow3par) const
recompute hits position and refit the segment4D
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
bool fit(DTSegmentCand *seg, bool allow3par, const bool fitdebug) const
edm::ESHandle< DTGeometry > theDTGeometry
DTSegmentUpdator * theUpdator