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 ( )

Definition at line 8 of file MultiTrajectoryStateAssembler.cc.

10  //
11  // parameters (could be configurable)
12  //
13  sortStates = false;
14  minValidFraction = 0.01;
15  minFractionalWeight = 1.e-6; // 4;
16 }

References minFractionalWeight, minValidFraction, and sortStates.

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.

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

References theInvalidWeightSum, and mps_merge::weight.

◆ addState()

void MultiTrajectoryStateAssembler::addState ( const TrajectoryStateOnSurface  tsos)

Adds a new TrajectoryStateOnSurface to the list of components

Definition at line 18 of file MultiTrajectoryStateAssembler.cc.

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 }

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

◆ 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.

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 }

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

Referenced by addState().

◆ 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.

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 }

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

◆ 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.

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 }

References prepareCombinedState(), and reweightedCombinedState().

◆ invalidCombinedState()

bool MultiTrajectoryStateAssembler::invalidCombinedState ( ) const
inlineprivate

Checks status of combined state.

Definition at line 47 of file MultiTrajectoryStateAssembler.h.

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

References theStates.

Referenced by prepareCombinedState(), and reweightedCombinedState().

◆ prepareCombinedState()

bool MultiTrajectoryStateAssembler::prepareCombinedState ( )
private

Preparation of combined state (cleaning & sorting)

Definition at line 101 of file MultiTrajectoryStateAssembler.cc.

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)
134  sort(theStates.begin(), theStates.end(), TrajectoryStateLessWeight());
135 
136  return true;
137 }

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

Referenced by combinedState().

◆ removeSmallWeights()

void MultiTrajectoryStateAssembler::removeSmallWeights ( )
private

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

Definition at line 166 of file MultiTrajectoryStateAssembler.cc.

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 }

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

Referenced by prepareCombinedState().

◆ removeWrongPz()

void MultiTrajectoryStateAssembler::removeWrongPz ( )
private

Removes states with local p_z != average p_z.

Definition at line 182 of file MultiTrajectoryStateAssembler.cc.

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(std::move(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 }

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

Referenced by prepareCombinedState().

◆ 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.

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 }

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

Referenced by combinedState().

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
mps_fire.i
i
Definition: mps_fire.py:355
BasicMultiTrajectoryState
Definition: BasicMultiTrajectoryState.h:17
MultiTrajectoryStateAssembler::minValidFraction
float minValidFraction
Definition: MultiTrajectoryStateAssembler.h:68
mps_merge.weight
weight
Definition: mps_merge.py:88
generateEDF.totalWeight
totalWeight
Definition: generateEDF.py:688
MultiTrajectoryStateAssembler::reweightedCombinedState
TrajectoryStateOnSurface reweightedCombinedState(const double) const
Definition: MultiTrajectoryStateAssembler.cc:139
MultiTrajectoryStateAssembler::sortStates
bool sortStates
Definition: MultiTrajectoryStateAssembler.h:67
MultiTrajectoryStateAssembler::addStateVector
void addStateVector(const MultiTSOS &)
Definition: MultiTrajectoryStateAssembler.cc:37
MultiTrajectoryStateAssembler::theInvalidWeightSum
double theInvalidWeightSum
Definition: MultiTrajectoryStateAssembler.h:75
alignCSCRings.s
s
Definition: alignCSCRings.py:92
GetComponents
Definition: GetComponents.h:4
MultiTrajectoryStateAssembler::removeSmallWeights
void removeSmallWeights()
Definition: MultiTrajectoryStateAssembler.cc:166
TrajectoryStateLessWeight
Definition: TrajectoryStateLessWeight.h:10
MultiTrajectoryStateAssembler::invalidCombinedState
bool invalidCombinedState() const
Checks status of combined state.
Definition: MultiTrajectoryStateAssembler.h:47
MultiTrajectoryStateAssembler::removeWrongPz
void removeWrongPz()
Removes states with local p_z != average p_z.
Definition: MultiTrajectoryStateAssembler.cc:182
MultiTrajectoryStateAssembler::thePzError
bool thePzError
Definition: MultiTrajectoryStateAssembler.h:72
DQMScaleToClient_cfi.factor
factor
Definition: DQMScaleToClient_cfi.py:8
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
MultiTrajectoryStateAssembler::minFractionalWeight
float minFractionalWeight
Definition: MultiTrajectoryStateAssembler.h:69
MultiTrajectoryStateAssembler::theValidWeightSum
double theValidWeightSum
Definition: MultiTrajectoryStateAssembler.h:74
MultiTrajectoryStateAssembler::combinationDone
bool combinationDone
Definition: MultiTrajectoryStateAssembler.h:71
reco::JetExtendedAssociation::value_type
Container::value_type value_type
Definition: JetExtendedAssociation.h:30
BasicTrajectoryState
Definition: BasicTrajectoryState.h:66
MultiTrajectoryStateAssembler::theStates
MultiTSOS theStates
Definition: MultiTrajectoryStateAssembler.h:76
eostools.move
def move(src, dest)
Definition: eostools.py:511
makeMuonMisalignmentScenario.components
string components
Definition: makeMuonMisalignmentScenario.py:58
Exception
Definition: hltDiff.cc:246
MultiTrajectoryStateAssembler::TSOS
TrajectoryStateOnSurface TSOS
Definition: MultiTrajectoryStateAssembler.h:15
MultiTrajectoryStateAssembler::MultiTSOS
std::vector< TrajectoryStateOnSurface > MultiTSOS
Definition: MultiTrajectoryStateAssembler.h:16
MultiTrajectoryStateAssembler::prepareCombinedState
bool prepareCombinedState()
Preparation of combined state (cleaning & sorting)
Definition: MultiTrajectoryStateAssembler.cc:101
cms::Exception
Definition: Exception.h:70
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54