CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
MultiTrajectoryStateAssembler Class Reference

#include <MultiTrajectoryStateAssembler.h>

Public Member Functions

void addInvalidState (const double)
 Adds (the weight of an) invalid state to the list. More...
 
void addState (const TrajectoryStateOnSurface)
 
TrajectoryStateOnSurface combinedState ()
 
TrajectoryStateOnSurface combinedState (const float weight)
 
 MultiTrajectoryStateAssembler ()
 

Private Types

typedef std::vector< TrajectoryStateOnSurfaceMultiTSOS
 
typedef TrajectoryStateOnSurface TSOS
 

Private Member Functions

void addStateVector (const MultiTSOS &)
 
bool invalidCombinedState () const
 Checks status of combined state. More...
 
bool prepareCombinedState ()
 Preparation of combined state (cleaning & sorting) More...
 
void removeSmallWeights ()
 
void removeWrongPz ()
 Removes states with local p_z != average p_z. More...
 
TrajectoryStateOnSurface reweightedCombinedState (const double) const
 

Private Attributes

bool combinationDone
 
float minFractionalWeight
 
float minValidFraction
 
bool sortStates
 
double theInvalidWeightSum
 
bool thePzError
 
MultiTSOS theStates
 
double theValidWeightSum
 

Detailed Description

Collects trajectory states and returns a MultiTrajectoryState.

Definition at line 13 of file MultiTrajectoryStateAssembler.h.

Member Typedef Documentation

Definition at line 17 of file MultiTrajectoryStateAssembler.h.

Definition at line 16 of file MultiTrajectoryStateAssembler.h.

Constructor & Destructor Documentation

MultiTrajectoryStateAssembler::MultiTrajectoryStateAssembler ( )

Member Function Documentation

void MultiTrajectoryStateAssembler::addInvalidState ( const double  weight)

Adds (the weight of an) invalid state to the list.

Definition at line 75 of file MultiTrajectoryStateAssembler.cc.

References theInvalidWeightSum, and mps_merge::weight.

Referenced by FullConvolutionWithMaterial::operator()().

75  {
76  //
77  // change status of combination (contains at least one invalid state)
78  //
80 }
void MultiTrajectoryStateAssembler::addState ( const TrajectoryStateOnSurface  tsos)

Adds a new TrajectoryStateOnSurface to the list of components

Definition at line 22 of file MultiTrajectoryStateAssembler.cc.

References addStateVector(), combinationDone, makeMuonMisalignmentScenario::components, Exception, and TrajectoryStateOnSurface::isValid().

Referenced by FullConvolutionWithMaterial::operator()(), GsfMultiStateUpdator::update(), and GsfMaterialEffectsUpdator::updateState().

22  {
23  //
24  // refuse to add states after combination has been done
25  //
26  if ( combinationDone )
27  throw cms::Exception("LogicError")
28  << "MultiTrajectoryStateAssembler: trying to add states after combination";
29  //
30  // Verify validity of state to be added
31  //
32  if ( !tsos.isValid() )
33  throw cms::Exception("LogicError") << "MultiTrajectoryStateAssembler: trying to add invalid state";
34  //
35  // Add components (i.e. state to be added can be single or multi state)
36  //
37  GetComponents comps(tsos);
38  MultiTSOS components(comps());
40 }
std::vector< TrajectoryStateOnSurface > MultiTSOS
void MultiTrajectoryStateAssembler::addStateVector ( const MultiTSOS states)
private

Adds a vector of trajectory states to the list of components

Definition at line 42 of file MultiTrajectoryStateAssembler.cc.

References combinationDone, Exception, mps_fire::i, thePzError, theStates, and theValidWeightSum.

Referenced by addState().

43 {
44  //
45  // refuse to add states after combination has been done
46  //
47  if ( combinationDone )
48  throw cms::Exception("LogicError")
49  << "MultiTrajectoryStateAssembler: trying to add states after combination";
50  //
51  // sum up weights (all components are supposed to be valid!!!) and
52  // check for consistent pz
53  //
54  double sum(0.);
55  double pzFirst = theStates.empty() ? 0. : theStates.front().localParameters().pzSign();
56  for ( MultiTSOS::const_iterator i=states.begin();
57  i!=states.end(); i++ ) {
58  if ( !(i->isValid()) )
59  throw cms::Exception("LogicError")
60  << "MultiTrajectoryStateAssembler: trying to add invalid state";
61  // weights
62  sum += i->weight();
63  // check on p_z
64  if ( !theStates.empty() &&
65  pzFirst*i->localParameters().pzSign()<0. ) thePzError = true;
66  }
67  theValidWeightSum += sum;
68  //
69  // add to vector of states
70  //
71  theStates.insert(theStates.end(),states.begin(),states.end());
72 }
TrajectoryStateOnSurface MultiTrajectoryStateAssembler::combinedState ( )

Returns the resulting MultiTrajectoryState with weight = sum of all valid components.

Definition at line 82 of file MultiTrajectoryStateAssembler.cc.

References prepareCombinedState(), reweightedCombinedState(), theInvalidWeightSum, theStates, and theValidWeightSum.

Referenced by FullConvolutionWithMaterial::operator()(), GsfMultiStateUpdator::update(), and GsfMaterialEffectsUpdator::updateState().

82  {
83  //
84  // Prepare resulting state vector
85  //
86  if ( !prepareCombinedState() ) return TSOS();
87  //
88  // If invalid states in input: use reweighting
89  //
90  if ( theInvalidWeightSum>0. )
92  //
93  // Return new multi state without reweighting
94  //
96 }
TrajectoryStateOnSurface reweightedCombinedState(const double) const
bool prepareCombinedState()
Preparation of combined state (cleaning & sorting)
TrajectoryStateOnSurface MultiTrajectoryStateAssembler::combinedState ( const float  weight)

Returns the resulting MultiTrajectoryState renormalised to specified weight.

Definition at line 98 of file MultiTrajectoryStateAssembler.cc.

References prepareCombinedState(), and reweightedCombinedState().

98  {
99  //
100  // Prepare resulting state vector
101  //
102  if ( !prepareCombinedState() ) return TSOS();
103  //
104  // return reweighted state
105  //
106  return reweightedCombinedState(newWeight);
107 }
TrajectoryStateOnSurface reweightedCombinedState(const double) const
bool prepareCombinedState()
Preparation of combined state (cleaning & sorting)
bool MultiTrajectoryStateAssembler::invalidCombinedState ( ) const
inlineprivate

Checks status of combined state.

Definition at line 49 of file MultiTrajectoryStateAssembler.h.

References prepareCombinedState(), removeSmallWeights(), removeWrongPz(), reweightedCombinedState(), and theStates.

Referenced by prepareCombinedState(), and reweightedCombinedState().

50  {
51  //
52  // Protect against empty combination (no valid input state)
53  //
54  return theStates.empty();
55  }
bool MultiTrajectoryStateAssembler::prepareCombinedState ( )
private

Preparation of combined state (cleaning & sorting)

Definition at line 110 of file MultiTrajectoryStateAssembler.cc.

References combinationDone, invalidCombinedState(), minValidFraction, removeSmallWeights(), removeWrongPz(), jetUpdater_cfi::sort, sortStates, theInvalidWeightSum, thePzError, theStates, and theValidWeightSum.

Referenced by combinedState(), and invalidCombinedState().

110  {
111  //
112  // Protect against empty combination (no valid input state)
113  //
114  if ( invalidCombinedState() ) return false;
115  //
116  // Check for states with wrong pz
117  //
118  if ( thePzError ) removeWrongPz();
119  //
120  // Check for minimum fraction of valid states
121  //
122  double allWeights(theValidWeightSum+theInvalidWeightSum);
123  if ( theInvalidWeightSum>0. && theValidWeightSum <minValidFraction*allWeights ) return false;
124  //
125  // remaining part to be done only once
126  //
127  if ( combinationDone ) return true;
128  combinationDone = true;
129  //
130  // Remove states with negligible weights
131  //
133  if ( invalidCombinedState() ) return false;
134  //
135  // Sort output by weights?
136  //
137  if ( sortStates )
139 
140  return true;
141 }
void removeWrongPz()
Removes states with local p_z != average p_z.
bool invalidCombinedState() const
Checks status of combined state.
void MultiTrajectoryStateAssembler::removeSmallWeights ( )
private

Removes states with negligible weight (no renormalisation of total weight!).

Definition at line 172 of file MultiTrajectoryStateAssembler.cc.

References minFractionalWeight, alignCSCRings::s, theInvalidWeightSum, theStates, and theValidWeightSum.

Referenced by invalidCombinedState(), and prepareCombinedState().

173 {
174  //
175  // check total weight
176  //
177  auto totalWeight(theInvalidWeightSum+theValidWeightSum);
178  if ( totalWeight == 0. ) {
179  theStates.clear();
180  return;
181  }
182  theStates.erase(std::remove_if(theStates.begin(),theStates.end(),
183  [&](MultiTSOS::value_type const & s){ return s.weight() < minFractionalWeight*totalWeight;}),
184  theStates.end());
185 }
void MultiTrajectoryStateAssembler::removeWrongPz ( )
private

Removes states with local p_z != average p_z.

Definition at line 188 of file MultiTrajectoryStateAssembler.cc.

References LogDebug, eostools::move(), theInvalidWeightSum, theStates, and theValidWeightSum.

Referenced by invalidCombinedState(), and prepareCombinedState().

188  {
189  LogDebug("GsfTrackFitters")
190  << "MultiTrajectoryStateAssembler: found at least one state with inconsistent pz\n"
191  << " #state / weights before cleaning = " << theStates.size()
192  << " / " << theValidWeightSum
193  << " / " << theInvalidWeightSum;
194  //
195  // Calculate average pz
196  //
197  double meanPz(0.);
198  for (auto const & is : theStates)
199  meanPz += is.weight()*is.localParameters().pzSign();
200  meanPz /= theValidWeightSum;
201  //
202  // Now keep only states compatible with the average pz
203  //
204  theValidWeightSum = 0.;
205  MultiTSOS oldStates(theStates);
206  theStates.clear();
207  for (auto const & is :oldStates) {
208  if ( meanPz*is.localParameters().pzSign()>=0. ) {
209  theValidWeightSum += is.weight();
210  theStates.push_back(std::move(is));
211  }
212  else {
213  theInvalidWeightSum += is.weight();
214  LogDebug("GsfTrackFitters")
215  << "removing weight / pz / global position = " << is.weight()
216  << " " << is.localParameters().pzSign()
217  << " " << is.globalPosition();
218 
219  }
220  }
221  LogDebug("GsfTrackFitters")
222  << " #state / weights after cleaning = " << theStates.size()
223  << " / " << theValidWeightSum
224  << " / " << theInvalidWeightSum;
225 }
#define LogDebug(id)
std::vector< TrajectoryStateOnSurface > MultiTSOS
def move(src, dest)
Definition: eostools.py:511
TrajectoryStateOnSurface MultiTrajectoryStateAssembler::reweightedCombinedState ( const double  newWeight) const
private

Returns the resulting MultiTrajectoryState with user-supplied total weight.

Definition at line 144 of file MultiTrajectoryStateAssembler.cc.

References invalidCombinedState(), theStates, and theValidWeightSum.

Referenced by combinedState(), and invalidCombinedState().

144  {
145  //
146  // check status
147  //
148  if ( invalidCombinedState() ) return TSOS();
149  //
150  // scaling factor
151  //
152  double factor = theValidWeightSum>0. ? newWeight/theValidWeightSum : 1;
153  //
154  // create new vector of states & combined state
155  //
156  MultiTSOS reweightedStates;
157  reweightedStates.reserve(theStates.size());
158  for (auto const & is : theStates) {
159  auto oldWeight = is.weight();
160  reweightedStates.emplace_back(factor*oldWeight,
161  is.localParameters(),
162  is.localError(),
163  is.surface(),
164  &(is.globalParameters().magneticField()),
165  is.surfaceSide()
166  );
167  }
168  return TSOS((BasicTrajectoryState *)(new BasicMultiTrajectoryState(reweightedStates)));
169 }
std::vector< TrajectoryStateOnSurface > MultiTSOS
bool invalidCombinedState() const
Checks status of combined state.

Member Data Documentation

bool MultiTrajectoryStateAssembler::combinationDone
private

Definition at line 74 of file MultiTrajectoryStateAssembler.h.

Referenced by addState(), addStateVector(), and prepareCombinedState().

float MultiTrajectoryStateAssembler::minFractionalWeight
private
float MultiTrajectoryStateAssembler::minValidFraction
private
bool MultiTrajectoryStateAssembler::sortStates
private
double MultiTrajectoryStateAssembler::theInvalidWeightSum
private
bool MultiTrajectoryStateAssembler::thePzError
private

Definition at line 75 of file MultiTrajectoryStateAssembler.h.

Referenced by addStateVector(), and prepareCombinedState().

MultiTSOS MultiTrajectoryStateAssembler::theStates
private
double MultiTrajectoryStateAssembler::theValidWeightSum
private