CMS 3D CMS Logo

CTPPSDiamondTrackRecognition.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of CTPPS offline software.
4  * Authors:
5  * Laurent Forthomme (laurent.forthomme@cern.ch)
6  * Nicola Minafra (nicola.minafra@cern.ch)
7  *
8  ****************************************************************************/
9 
11 
12 #include <cmath>
13 #include <cstdio>
14 #include <algorithm>
15 
16 //----------------------------------------------------------------------------------------------------
17 
18 const std::string CTPPSDiamondTrackRecognition::pixelEfficiencyDefaultFunction_ = "(x>[0]-0.5*[1])*(x<[0]+0.5*[1])";
19 
21  threshold_ ( iConfig.getParameter<double>( "threshold" ) ),
22  thresholdFromMaximum_( iConfig.getParameter<double>( "thresholdFromMaximum" ) ),
23  resolution_ ( iConfig.getParameter<double>( "resolution" ) ),
24  sigma_ ( iConfig.getParameter<double>( "sigma" ) ),
25  startFromX_ ( iConfig.getParameter<double>( "startFromX" ) ),
26  stopAtX_ ( iConfig.getParameter<double>( "stopAtX" ) ),
27  yPositionInitial_ ( iConfig.getParameter<double>( "yPosition" ) ),
28  yWidthInitial_ ( iConfig.getParameter<double>( "yWidth" ) ),
29  hit_f_( "hit_TF1_CTPPS", iConfig.getParameter<std::string>( "pixelEfficiencyFunction" ).c_str(), startFromX_, stopAtX_ )
30 {
31  if (sigma_==0.0) {
32  hit_f_ = TF1( "hit_TF1_CTPPS", pixelEfficiencyDefaultFunction_.c_str(), startFromX_, stopAtX_ ); // simple step function
33  }
34 }
35 
36 //----------------------------------------------------------------------------------------------------
37 
39 {}
40 
41 //----------------------------------------------------------------------------------------------------
42 
43 void
45 {
47  mhMap_.clear();
50 }
51 
52 //----------------------------------------------------------------------------------------------------
53 
54 void
56 {
57  // store hit parameters
58  hitParametersVectorMap_[recHit.getOOTIndex()].emplace_back( recHit.getX(), recHit.getXWidth() );
59 
60  // Check vertical coordinates
62  yPosition_ = recHit.getY();
63  yWidth_ = recHit.getYWidth();
64  }
65 
66  //Multiple hits in the RP
67  if ( recHit.getMultipleHits() ) {
68  if ( mhMap_.find( recHit.getOOTIndex() ) == mhMap_.end() ) {
69  mhMap_[recHit.getOOTIndex()] = 1;
70  }
71  else {
72  ++( mhMap_[recHit.getOOTIndex()] );
73  }
74  }
75 }
76 
77 //----------------------------------------------------------------------------------------------------
78 
79 int
81 {
82  int number_of_tracks = 0;
83  for ( auto const& oot : hitParametersVectorMap_ ) {
84  std::vector<float> hit_profile( ( stopAtX_-startFromX_ )/resolution_, 0. );
85  for ( auto const& param : oot.second ) {
86  hit_f_.SetParameters( param.center, param.width, sigma_ );
87  for ( unsigned int i=0; i<hit_profile.size(); ++i ) {
88  hit_profile[i] += hit_f_.Eval( startFromX_ + i*resolution_ );
89  }
90  }
91 
92  float maximum = 0.;
93  bool below = true; // start below the threshold
94  int track_start_n = 0;
95 
96  for ( unsigned int i=0; i<hit_profile.size(); ++i ) {
97  if ( below && hit_profile[i] >= threshold_ ) { // going above the threshold
98  track_start_n = i;
99  maximum=0;
100  below = false;
101  }
102  if ( !below ) {
103  if ( hit_profile[i] > maximum ) {
104  maximum = hit_profile[i];
105  }
106  if ( hit_profile[i] < threshold_ ) { // going back below the threshold
107  below = true;
108 
109  // go back and use new threshold
110  const float threshold = maximum - thresholdFromMaximum_;
111  for ( unsigned int j=track_start_n; j<=i; ++j ) {
112  if ( below && hit_profile[j] >= threshold ) { // going above the threshold
113  track_start_n = j;
114  below = false;
115  }
116  if ( !below && hit_profile[j] < threshold ) { // going back below the threshold
117  below = true;
118 
119  //store track
120  math::XYZPoint pos0_sigma( ( j-track_start_n )*resolution_*0.5, yWidth_ * 0.5, 0. );
121  math::XYZPoint pos0( startFromX_ + track_start_n*resolution_ + pos0_sigma.X(), yPosition_, 0. );
122  int mult_hits = 0;
123  if ( mhMap_.find( oot.first ) != mhMap_.end() ) mult_hits = mhMap_[oot.first];
124 
125  CTPPSDiamondLocalTrack track( pos0, pos0_sigma, 0., 0., 0., oot.first, mult_hits );
126  track.setValid( true );
127  tracks.push_back( track );
128  ++number_of_tracks;
129  }
130  }
131  }
132  }
133  }
134  }
135 
136  return number_of_tracks;
137 }
float getXWidth() const
static const std::string pixelEfficiencyDefaultFunction_
Default hit function accounting for the pad spatial efficiency.
void push_back(const T &t)
Definition: DetSet.h:68
void clear()
Reset the list of hits.
Reconstructed hit in diamond detectors.
int getOOTIndex() const
HitParametersVectorMap hitParametersVectorMap_
float getYWidth() const
CTPPSDiamondTrackRecognition(const edm::ParameterSet &)
TF1 hit_f_
Function for pad efficiency.
void addHit(const CTPPSDiamondRecHit &recHit)
Feed a new hit to the tracks recognition algorithm.
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool getMultipleHits() const
int produceTracks(edm::DetSet< CTPPSDiamondLocalTrack > &tracks)
Produce a collection of tracks for the current station, given its hits collection.
std::unordered_map< int, int > mhMap_