CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
< TrajectoryStateOnSurface
MultiTSOS
 
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 ( )

Definition at line 8 of file MultiTrajectoryStateAssembler.cc.

References minFractionalWeight, minValidFraction, and sortStates.

8  :
9  combinationDone(false),
10  thePzError(false),
13 {
14  //
15  // parameters (could be configurable)
16  //
17  sortStates = false;
18  minValidFraction = 0.01;
19  minFractionalWeight = 1.e-6;
20  // //
21  // // Timers
22  // //
23  // if ( theTimerAdd==0 ) {
24  // theTimerAdd =
25  // &(*TimingReport::current())[string("MultiTrajectoryStateAssembler::addState")];
26  // theTimerAdd->switchCPU(false);
27  // theTimerComb =
28  // &(*TimingReport::current())[string("MultiTrajectoryStateAssembler::combinedState")];
29  // theTimerComb->switchCPU(false);
30  // }
31 }

Member Function Documentation

void MultiTrajectoryStateAssembler::addInvalidState ( const double  weight)

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

Definition at line 87 of file MultiTrajectoryStateAssembler.cc.

References theInvalidWeightSum, and histoStyle::weight.

87  {
88  //
89  // change status of combination (contains at least one invalid state)
90  //
92 }
int weight
Definition: histoStyle.py:50
void MultiTrajectoryStateAssembler::addState ( const TrajectoryStateOnSurface  tsos)

Adds a new TrajectoryStateOnSurface to the list of components

Definition at line 33 of file MultiTrajectoryStateAssembler.cc.

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

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

33  {
34  // // Timer
35  // TimeMe t(*theTimerAdd,false);
36  //
37  // refuse to add states after combination has been done
38  //
39  if ( combinationDone )
40  throw cms::Exception("LogicError")
41  << "MultiTrajectoryStateAssembler: trying to add states after combination";
42  //
43  // Verify validity of state to be added
44  //
45  if ( !tsos.isValid() )
46  throw cms::Exception("LogicError") << "MultiTrajectoryStateAssembler: trying to add invalid state";
47  //
48  // Add components (i.e. state to be added can be single or multi state)
49  //
52 }
std::vector< TrajectoryStateOnSurface > MultiTSOS
std::vector< TrajectoryStateOnSurface > components() const
void MultiTrajectoryStateAssembler::addStateVector ( const MultiTSOS states)
private

Adds a vector of trajectory states to the list of components

Definition at line 54 of file MultiTrajectoryStateAssembler.cc.

References combinationDone, edm::hlt::Exception, i, thePzError, theStates, and theValidWeightSum.

Referenced by addState().

55 {
56  //
57  // refuse to add states after combination has been done
58  //
59  if ( combinationDone )
60  throw cms::Exception("LogicError")
61  << "MultiTrajectoryStateAssembler: trying to add states after combination";
62  //
63  // sum up weights (all components are supposed to be valid!!!) and
64  // check for consistent pz
65  //
66  double sum(0.);
67  double pzFirst = theStates.empty() ? 0. : theStates.front().localParameters().pzSign();
68  for ( MultiTSOS::const_iterator i=states.begin();
69  i!=states.end(); i++ ) {
70  if ( !(i->isValid()) )
71  throw cms::Exception("LogicError")
72  << "MultiTrajectoryStateAssembler: trying to add invalid state";
73  // weights
74  sum += i->weight();
75  // check on p_z
76  if ( !theStates.empty() &&
77  pzFirst*i->localParameters().pzSign()<0. ) thePzError = true;
78  }
79  theValidWeightSum += sum;
80  //
81  // add to vector of states
82  //
83  theStates.insert(theStates.end(),states.begin(),states.end());
84 }
int i
Definition: DBlmapReader.cc:9
TrajectoryStateOnSurface MultiTrajectoryStateAssembler::combinedState ( )

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

Definition at line 94 of file MultiTrajectoryStateAssembler.cc.

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

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

94  {
95  // // Timer
96  // TimeMe t(*theTimerComb,false);
97  //
98  // Prepare resulting state vector
99  //
100  if ( !prepareCombinedState() ) return TSOS();
101  //
102  // If invalid states in input: use reweighting
103  //
104  if ( theInvalidWeightSum>0. )
106  //
107  // Return new multi state without reweighting
108  //
110 }
TrajectoryStateOnSurface reweightedCombinedState(const double) const
bool prepareCombinedState()
Preparation of combined state (cleaning &amp; sorting)
TrajectoryStateOnSurface MultiTrajectoryStateAssembler::combinedState ( const float  weight)

Returns the resulting MultiTrajectoryState renormalised to specified weight.

Definition at line 112 of file MultiTrajectoryStateAssembler.cc.

References prepareCombinedState(), and reweightedCombinedState().

112  {
113  // // Timer
114  // TimeMe t(*theTimerComb,false);
115  //
116  // Prepare resulting state vector
117  //
118  if ( !prepareCombinedState() ) return TSOS();
119  //
120  // return reweighted state
121  //
122  return reweightedCombinedState(newWeight);
123 }
TrajectoryStateOnSurface reweightedCombinedState(const double) const
bool prepareCombinedState()
Preparation of combined state (cleaning &amp; sorting)
bool MultiTrajectoryStateAssembler::invalidCombinedState ( ) const
inlineprivate

Checks status of combined state.

Definition at line 49 of file MultiTrajectoryStateAssembler.h.

References 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 126 of file MultiTrajectoryStateAssembler.cc.

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

Referenced by combinedState().

126  {
127  //
128  // Protect against empty combination (no valid input state)
129  //
130  if ( invalidCombinedState() ) return false;
131  //
132  // Check for states with wrong pz
133  //
134  if ( thePzError ) removeWrongPz();
135  //
136  // Check for minimum fraction of valid states
137  //
138  double allWeights(theValidWeightSum+theInvalidWeightSum);
139  if ( theInvalidWeightSum>0. && (theValidWeightSum/allWeights)<minValidFraction ) return false;
140  //
141  // remaining part to be done only once
142  //
143  if ( combinationDone ) return true;
144  else combinationDone = true;
145  //
146  // Remove states with negligible weights
147  //
149  if ( invalidCombinedState() ) return false;
150  //
151  // Sort output by weights?
152  //
153  if ( sortStates )
155 
156  return true;
157 }
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 189 of file MultiTrajectoryStateAssembler.cc.

References i, minFractionalWeight, theInvalidWeightSum, theStates, and theValidWeightSum.

Referenced by prepareCombinedState().

190 {
191  //
192  // check total weight
193  //
194  double totalWeight(theInvalidWeightSum+theValidWeightSum);
195  if ( totalWeight == 0. ) {
196  theStates.clear();
197  return;
198  }
199  //
200  // Loop until no more states are removed
201  //
202  bool redo;
203  do {
204  redo = false;
205  for ( MultiTSOS::iterator i=theStates.begin();
206  i!=theStates.end(); i++ ) {
207  if ( (*i).weight()/totalWeight < minFractionalWeight ) {
208  theStates.erase(i);
209  redo = true;
210  break;
211  }
212  }
213  } while (redo);
214 }
int i
Definition: DBlmapReader.cc:9
void MultiTrajectoryStateAssembler::removeWrongPz ( )
private

Removes states with local p_z != average p_z.

Definition at line 217 of file MultiTrajectoryStateAssembler.cc.

References theInvalidWeightSum, theStates, and theValidWeightSum.

Referenced by prepareCombinedState().

217  {
218  // edm::LogDebug("MultiTrajectoryStateAssembler")
219  // << "MultiTrajectoryStateAssembler: found at least one state with inconsistent pz\n"
220  // << " #state / weights before cleaning = " << theStates.size()
221  // << " / " << theValidWeightSum
222  // << " / " << theInvalidWeightSum;
223  //
224  // Calculate average pz
225  //
226  double meanPz(0.);
227  for ( MultiTSOS::const_iterator is=theStates.begin();
228  is!=theStates.end(); is++ ) {
229  meanPz += is->weight()*is->localParameters().pzSign();
230  // edm::LogDebug("MultiTrajectoryStateAssembler")
231  // << " weight / pz / global position = " << is->weight()
232  // << " " << is->localParameters().pzSign()
233  // << " " << is->globalPosition();
234  }
235  meanPz /= theValidWeightSum;
236  //
237  // Now keep only states compatible with the average pz
238  //
239  // double oldValidWeight(theValidWeightSum);
240  theValidWeightSum = 0.;
241  MultiTSOS oldStates(theStates);
242  theStates.clear();
243  for ( MultiTSOS::const_iterator is=oldStates.begin();
244  is!=oldStates.end(); is++ ) {
245  if ( meanPz*is->localParameters().pzSign()>=0. ) {
246  theValidWeightSum += is->weight();
247  theStates.push_back(*is);
248  }
249  else {
250  theInvalidWeightSum += is->weight();
251  }
252  }
253  // edm::LogDebug("MultiTrajectoryStateAssembler")
254  // << " #state / weights after cleaning = " << theStates.size()
255  // << " / " << theValidWeightSum
256  // << " / " << theInvalidWeightSum;
257 }
std::vector< TrajectoryStateOnSurface > MultiTSOS
TrajectoryStateOnSurface MultiTrajectoryStateAssembler::reweightedCombinedState ( const double  newWeight) const
private

Returns the resulting MultiTrajectoryState with user-supplied total weight.

Definition at line 160 of file MultiTrajectoryStateAssembler.cc.

References i, invalidCombinedState(), theStates, and theValidWeightSum.

Referenced by combinedState().

160  {
161  //
162  // check status
163  //
164  if ( invalidCombinedState() ) return TSOS();
165  //
166  // scaling factor
167  //
168  double factor = theValidWeightSum>0. ? newWeight/theValidWeightSum : 1;
169  //
170  // create new vector of states & combined state
171  //
172  MultiTSOS reweightedStates;
173  reweightedStates.reserve(theStates.size());
174  for ( MultiTSOS::const_iterator i=theStates.begin();
175  i!=theStates.end(); i++ ) {
176  double oldWeight = i->weight();
177  reweightedStates.push_back(TrajectoryStateOnSurface(factor*oldWeight,
178  i->localParameters(),
179  i->localError(),
180  i->surface(),
181  &(i->globalParameters().magneticField()),
182  i->surfaceSide()
183  ));
184  }
185  return TSOS((BasicTrajectoryState *)(new BasicMultiTrajectoryState(reweightedStates)));
186 }
int i
Definition: DBlmapReader.cc:9
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