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  //
109  return TSOS(new BasicMultiTrajectoryState(theStates));
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 188 of file MultiTrajectoryStateAssembler.cc.

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

Referenced by prepareCombinedState().

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

Removes states with local p_z != average p_z.

Definition at line 216 of file MultiTrajectoryStateAssembler.cc.

References theInvalidWeightSum, theStates, and theValidWeightSum.

Referenced by prepareCombinedState().

216  {
217  // edm::LogDebug("MultiTrajectoryStateAssembler")
218  // << "MultiTrajectoryStateAssembler: found at least one state with inconsistent pz\n"
219  // << " #state / weights before cleaning = " << theStates.size()
220  // << " / " << theValidWeightSum
221  // << " / " << theInvalidWeightSum;
222  //
223  // Calculate average pz
224  //
225  double meanPz(0.);
226  for ( MultiTSOS::const_iterator is=theStates.begin();
227  is!=theStates.end(); is++ ) {
228  meanPz += is->weight()*is->localParameters().pzSign();
229  // edm::LogDebug("MultiTrajectoryStateAssembler")
230  // << " weight / pz / global position = " << is->weight()
231  // << " " << is->localParameters().pzSign()
232  // << " " << is->globalPosition();
233  }
234  meanPz /= theValidWeightSum;
235  //
236  // Now keep only states compatible with the average pz
237  //
238  // double oldValidWeight(theValidWeightSum);
239  theValidWeightSum = 0.;
240  MultiTSOS oldStates(theStates);
241  theStates.clear();
242  for ( MultiTSOS::const_iterator is=oldStates.begin();
243  is!=oldStates.end(); is++ ) {
244  if ( meanPz*is->localParameters().pzSign()>=0. ) {
245  theValidWeightSum += is->weight();
246  theStates.push_back(*is);
247  }
248  else {
249  theInvalidWeightSum += is->weight();
250  }
251  }
252  // edm::LogDebug("MultiTrajectoryStateAssembler")
253  // << " #state / weights after cleaning = " << theStates.size()
254  // << " / " << theValidWeightSum
255  // << " / " << theInvalidWeightSum;
256 }
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(i->localParameters(),
178  i->localError(),
179  i->surface(),
180  &(i->globalParameters().magneticField()),
181  i->surfaceSide(),
182  factor*oldWeight));
183  }
184  return TSOS(new BasicMultiTrajectoryState(reweightedStates));
185 }
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