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

◆ MultiTSOS

Definition at line 16 of file MultiTrajectoryStateAssembler.h.

◆ TSOS

Definition at line 15 of file MultiTrajectoryStateAssembler.h.

Constructor & Destructor Documentation

◆ MultiTrajectoryStateAssembler()

MultiTrajectoryStateAssembler::MultiTrajectoryStateAssembler ( )

Member Function Documentation

◆ addInvalidState()

void MultiTrajectoryStateAssembler::addInvalidState ( const double  weight)

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

Definition at line 65 of file MultiTrajectoryStateAssembler.cc.

References theInvalidWeightSum, and mps_merge::weight.

65  {
66  //
67  // change status of combination (contains at least one invalid state)
68  //
70 }

◆ addState()

void MultiTrajectoryStateAssembler::addState ( const TrajectoryStateOnSurface  tsos)

Adds a new TrajectoryStateOnSurface to the list of components

Definition at line 18 of file MultiTrajectoryStateAssembler.cc.

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

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

◆ addStateVector()

void MultiTrajectoryStateAssembler::addStateVector ( const MultiTSOS states)
private

Adds a vector of trajectory states to the list of components

Definition at line 37 of file MultiTrajectoryStateAssembler.cc.

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

Referenced by addState().

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

◆ combinedState() [1/2]

TrajectoryStateOnSurface MultiTrajectoryStateAssembler::combinedState ( )

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

Definition at line 72 of file MultiTrajectoryStateAssembler.cc.

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

72  {
73  //
74  // Prepare resulting state vector
75  //
76  if (!prepareCombinedState())
77  return TSOS();
78  //
79  // If invalid states in input: use reweighting
80  //
81  if (theInvalidWeightSum > 0.)
83  //
84  // Return new multi state without reweighting
85  //
87 }
TrajectoryStateOnSurface reweightedCombinedState(const double) const
bool prepareCombinedState()
Preparation of combined state (cleaning & sorting)

◆ combinedState() [2/2]

TrajectoryStateOnSurface MultiTrajectoryStateAssembler::combinedState ( const float  weight)

Returns the resulting MultiTrajectoryState renormalised to specified weight.

Definition at line 89 of file MultiTrajectoryStateAssembler.cc.

References prepareCombinedState(), and reweightedCombinedState().

89  {
90  //
91  // Prepare resulting state vector
92  //
93  if (!prepareCombinedState())
94  return TSOS();
95  //
96  // return reweighted state
97  //
98  return reweightedCombinedState(newWeight);
99 }
TrajectoryStateOnSurface reweightedCombinedState(const double) const
bool prepareCombinedState()
Preparation of combined state (cleaning & sorting)

◆ invalidCombinedState()

bool MultiTrajectoryStateAssembler::invalidCombinedState ( ) const
inlineprivate

Checks status of combined state.

Definition at line 47 of file MultiTrajectoryStateAssembler.h.

References theStates.

Referenced by prepareCombinedState(), and reweightedCombinedState().

47  {
48  //
49  // Protect against empty combination (no valid input state)
50  //
51  return theStates.empty();
52  }

◆ prepareCombinedState()

bool MultiTrajectoryStateAssembler::prepareCombinedState ( )
private

Preparation of combined state (cleaning & sorting)

Definition at line 101 of file MultiTrajectoryStateAssembler.cc.

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

Referenced by combinedState().

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

◆ removeSmallWeights()

void MultiTrajectoryStateAssembler::removeSmallWeights ( )
private

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

Definition at line 166 of file MultiTrajectoryStateAssembler.cc.

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

Referenced by prepareCombinedState().

166  {
167  //
168  // check total weight
169  //
171  if (totalWeight == 0.) {
172  theStates.clear();
173  return;
174  }
175  theStates.erase(
176  std::remove_if(theStates.begin(),
177  theStates.end(),
178  [&](MultiTSOS::value_type const &s) { return s.weight() < minFractionalWeight * totalWeight; }),
179  theStates.end());
180 }

◆ removeWrongPz()

void MultiTrajectoryStateAssembler::removeWrongPz ( )
private

Removes states with local p_z != average p_z.

Definition at line 182 of file MultiTrajectoryStateAssembler.cc.

References LogDebug, theInvalidWeightSum, theStates, and theValidWeightSum.

Referenced by prepareCombinedState().

182  {
183  LogDebug("GsfTrackFitters") << "MultiTrajectoryStateAssembler: found at least one state with inconsistent pz\n"
184  << " #state / weights before cleaning = " << theStates.size() << " / "
185  << theValidWeightSum << " / " << theInvalidWeightSum;
186  //
187  // Calculate average pz
188  //
189  double meanPz(0.);
190  for (auto const &is : theStates)
191  meanPz += is.weight() * is.localParameters().pzSign();
192  meanPz /= theValidWeightSum;
193  //
194  // Now keep only states compatible with the average pz
195  //
196  theValidWeightSum = 0.;
197  MultiTSOS oldStates(theStates);
198  theStates.clear();
199  for (auto const &is : oldStates) {
200  if (meanPz * is.localParameters().pzSign() >= 0.) {
201  theValidWeightSum += is.weight();
202  theStates.push_back(is);
203  } else {
204  theInvalidWeightSum += is.weight();
205  LogDebug("GsfTrackFitters") << "removing weight / pz / global position = " << is.weight() << " "
206  << is.localParameters().pzSign() << " " << is.globalPosition();
207  }
208  }
209  LogDebug("GsfTrackFitters") << " #state / weights after cleaning = " << theStates.size() << " / "
210  << theValidWeightSum << " / " << theInvalidWeightSum;
211 }
std::vector< TrajectoryStateOnSurface > MultiTSOS
#define LogDebug(id)

◆ reweightedCombinedState()

TrajectoryStateOnSurface MultiTrajectoryStateAssembler::reweightedCombinedState ( const double  newWeight) const
private

Returns the resulting MultiTrajectoryState with user-supplied total weight.

Definition at line 139 of file MultiTrajectoryStateAssembler.cc.

References DQMScaleToClient_cfi::factor, invalidCombinedState(), theStates, and theValidWeightSum.

Referenced by combinedState().

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

Member Data Documentation

◆ combinationDone

bool MultiTrajectoryStateAssembler::combinationDone
private

Definition at line 71 of file MultiTrajectoryStateAssembler.h.

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

◆ minFractionalWeight

float MultiTrajectoryStateAssembler::minFractionalWeight
private

◆ minValidFraction

float MultiTrajectoryStateAssembler::minValidFraction
private

◆ sortStates

bool MultiTrajectoryStateAssembler::sortStates
private

◆ theInvalidWeightSum

double MultiTrajectoryStateAssembler::theInvalidWeightSum
private

◆ thePzError

bool MultiTrajectoryStateAssembler::thePzError
private

Definition at line 72 of file MultiTrajectoryStateAssembler.h.

Referenced by addStateVector(), and prepareCombinedState().

◆ theStates

MultiTSOS MultiTrajectoryStateAssembler::theStates
private

◆ theValidWeightSum

double MultiTrajectoryStateAssembler::theValidWeightSum
private