CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  yPosition_ ( iConfig.getParameter<double>( "yPosition" ) ),
28  yWidth_ ( 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();
48 }
49 
50 //----------------------------------------------------------------------------------------------------
51 
52 void
54 {
55  // store hit parameters
56  hitParametersVectorMap_[recHit.getOOTIndex()].emplace_back( recHit.getX(), recHit.getXWidth() );
57 
58  // Check vertical coordinates
59  if ( yPosition_ == 0.0 and yWidth_ == 0.0 ) {
60  yPosition_ = recHit.getY();
61  yWidth_ = recHit.getYWidth();
62  }
63 
64  //Multiple hits in the RP
65  if ( recHit.getMultipleHits() ) {
66  if ( mhMap_.find( recHit.getOOTIndex() ) == mhMap_.end() ) {
67  mhMap_[recHit.getOOTIndex()] = 1;
68  }
69  else {
70  ++( mhMap_[recHit.getOOTIndex()] );
71  }
72  }
73 }
74 
75 //----------------------------------------------------------------------------------------------------
76 
77 int
79 {
80  int number_of_tracks = 0;
81  for ( auto const& oot : hitParametersVectorMap_ ) {
82  std::vector<float> hit_profile( ( stopAtX_-startFromX_ )/resolution_, 0. );
83  for ( auto const& param : oot.second ) {
84  hit_f_.SetParameters( param.center, param.width, sigma_ );
85  for ( unsigned int i=0; i<hit_profile.size(); ++i ) {
86  hit_profile[i] += hit_f_.Eval( startFromX_ + i*resolution_ );
87  }
88  }
89 
90  float maximum = 0.;
91  bool below = true; // start below the threshold
92  int track_start_n = 0;
93 
94  for ( unsigned int i=0; i<hit_profile.size(); ++i ) {
95  if ( below && hit_profile[i] >= threshold_ ) { // going above the threshold
96  track_start_n = i;
97  maximum=0;
98  below = false;
99  }
100  if ( !below ) {
101  if ( hit_profile[i] > maximum ) {
102  maximum = hit_profile[i];
103  }
104  if ( hit_profile[i] < threshold_ ) { // going back below the threshold
105  below = true;
106 
107  // go back and use new threshold
108  const float threshold = maximum - thresholdFromMaximum_;
109  for ( unsigned int j=track_start_n; j<=i; ++j ) {
110  if ( below && hit_profile[j] >= threshold ) { // going above the threshold
111  track_start_n = j;
112  below = false;
113  }
114  if ( !below && hit_profile[j] < threshold ) { // going back below the threshold
115  below = true;
116 
117  //store track
118  math::XYZPoint pos0_sigma( ( j-track_start_n )*resolution_*0.5, yWidth_ * 0.5, 0. );
119  math::XYZPoint pos0( startFromX_ + track_start_n*resolution_ + pos0_sigma.X(), yPosition_, 0. );
120  int mult_hits = 0;
121  if ( mhMap_.find( oot.first ) != mhMap_.end() ) mult_hits = mhMap_[oot.first];
122 
123  CTPPSDiamondLocalTrack track( pos0, pos0_sigma, 0., 0., 0., oot.first, mult_hits );
124  track.setValid( true );
125  tracks.push_back( track );
126  ++number_of_tracks;
127  }
128  }
129  }
130  }
131  }
132  }
133 
134  return number_of_tracks;
135 }
float getXWidth() const
int i
Definition: DBlmapReader.cc:9
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 &)
int j
Definition: DBlmapReader.cc:9
TF1 hit_f_
Function for pad efficiency.
void addHit(const CTPPSDiamondRecHit &recHit)
Feed a new hit to the tracks recognition algorithm.
tuple tracks
Definition: testEve_cfg.py:39
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_