CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NuclearInteractionFinder.cc
Go to the documentation of this file.
4 
6 
9 
12 
14 
16 
18 
19 
21 maxHits(iConfig.getParameter<int>("maxHits")),
22 rescaleErrorFactor(iConfig.getParameter<double>("rescaleErrorFactor")),
23 checkCompletedTrack(iConfig.getParameter<bool>("checkCompletedTrack")),
24 navigationSchoolName(iConfig.getParameter<std::string>("NavigationSchool"))
25 {
26 
27  std::string measurementTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
28 
32  edm::ESHandle<MeasurementTracker> measurementTrackerHandle;
33  edm::ESHandle<GeometricSearchTracker> theGeomSearchTrackerHandle;
34  edm::ESHandle<TrackerGeometry> theTrackerGeom;
35 
36  es.get<TrackerDigiGeometryRecord> ().get (theTrackerGeom);
37  es.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",prop);
38  es.get<TrackingComponentsRecord>().get("Chi2",est);
39  es.get<CkfComponentsRecord>().get(measurementTrackerName, measurementTrackerHandle);
40  es.get<TrackerRecoGeometryRecord>().get(theGeomSearchTrackerHandle );
42 
46 
47  thePropagator = prop.product();
48  theEstimator = est.product();
49  theMeasurementTracker = measurementTrackerHandle.product();
51  theGeomSearchTracker = theGeomSearchTrackerHandle.product();
52 
53  LogDebug("NuclearSeedGenerator") << "New NuclearInteractionFinder instance with parameters : \n"
54  << "maxHits : " << maxHits << "\n"
55  << "rescaleErrorFactor : " << rescaleErrorFactor << "\n"
56  << "checkCompletedTrack : " << checkCompletedTrack << "\n";
57 
58  nuclTester = new NuclearTester(maxHits, theEstimator, theTrackerGeom.product() );
59 
60  currentSeed = new SeedFromNuclearInteraction(thePropagator, theTrackerGeom.product(), iConfig) ;
61 
63 }
64 //----------------------------------------------------------------------
66 {
68 }
69 
70 //----------------------------------------------------------------------
72  delete theLayerMeasurements;
73  delete nuclTester;
74  delete currentSeed;
75  delete thePrimaryHelix;
76 }
77 
78 //----------------------------------------------------------------------
80 
81  if(traj.empty() || !traj.isValid()) return false;
82 
83  LogDebug("NuclearSeedGenerator") << "Analyzis of a new trajectory with a number of valid hits = " << traj.foundHits();
84 
85  std::vector<TrajectoryMeasurement> measurements = traj.measurements();
86 
87  // initialization
88  nuclTester->reset( measurements.size() );
89  allSeeds.clear();
90 
91 
92  if(traj.direction()==alongMomentum) {
93  std::reverse(measurements.begin(), measurements.end());
94  }
95 
96  std::vector<TrajectoryMeasurement>::const_iterator it_meas = measurements.begin();
97 
98  std::vector<double> ncompatibleHits;
99  bool NIfound = false;
100 
101  // Loop on all the RecHits.
102  while(!NIfound)
103  {
104  if(it_meas == measurements.end()) break;
105 
106  // check only the maxHits outermost hits of the primary track
107  if(nuclTester->nHitsChecked() > maxHits) break;
108 
110 
111  LogDebug("NuclearSeedGenerator") << "Number of compatible meas:" << (nuclTester->back()).size() << "\n"
112  << "Mean distance between hits :" << nuclTester->meanHitDistance() << "\n"
113  << "Forward estimate :" << nuclTester->fwdEstimate() << "\n";
114 
115  // don't check tracks which reach the end of the tracker if checkCompletedTrack==false
116  if( checkCompletedTrack==false && (nuclTester->compatibleHits()).front()==0 ) break;
117 
118  if(nuclTester->isNuclearInteraction()) NIfound=true;
119 
120  ++it_meas;
121  }
122 
123  if(NIfound) {
124  LogDebug("NuclearSeedGenerator") << "NUCLEAR INTERACTION FOUND at index : " << nuclTester->nuclearIndex() << "\n";
125 
126  // Get correct parametrization of the helix of the primary track at the interaction point (to be used by improveCurrentSeed)
127  definePrimaryHelix(measurements.begin()+nuclTester->nuclearIndex()-1);
128 
129  this->fillSeeds( nuclTester->goodTMPair());
130 
131  return true;
132  }
133 
134  return false;
135 }
136 //----------------------------------------------------------------------
137 void NuclearInteractionFinder::definePrimaryHelix(std::vector<TrajectoryMeasurement>::const_iterator it_meas) {
138  // This method uses the 3 last TM after the interaction point to calculate the helix parameters
139 
140  GlobalPoint pt[3];
141  for(int i=0; i<3; i++) {
142  pt[i] = (it_meas->updatedState()).globalParameters().position();
143  it_meas++;
144  }
145  delete thePrimaryHelix;
146  thePrimaryHelix = new TangentHelix( pt[0], pt[1], pt[2] );
147 }
148 //----------------------------------------------------------------------
149 std::vector<TrajectoryMeasurement>
150 NuclearInteractionFinder::findCompatibleMeasurements(const TM& lastMeas, double rescale) const
151 {
152  TSOS currentState = lastMeas.updatedState();
153  LogDebug("NuclearSeedGenerator") << "currentState :" << currentState << "\n";
154 
155  TSOS newState = rescaleError(rescale, currentState);
156  return findMeasurementsFromTSOS(newState, lastMeas.recHit()->geographicalId());
157 }
158 //----------------------------------------------------------------------
159 std::vector<TrajectoryMeasurement>
161 
162  using namespace std;
163  int invalidHits = 0;
164  vector<TM> result;
165  const DetLayer* lastLayer = theGeomSearchTracker->detLayer( detid );
166  vector<const DetLayer*> nl;
167 
168  if(lastLayer) {
169  nl = lastLayer->nextLayers( *currentState.freeState(), alongMomentum);
170  }
171  else {
172  edm::LogError("NuclearInteractionFinder") << "In findCompatibleMeasurements : lastLayer not accessible";
173  return result;
174  }
175 
176  if (nl.empty()) {
177  LogDebug("NuclearSeedGenerator") << "In findCompatibleMeasurements : no compatible layer found";
178  return result;
179  }
180 
181  for (vector<const DetLayer*>::iterator il = nl.begin();
182  il != nl.end(); il++) {
183  vector<TM> tmp =
185  if ( !tmp.empty()) {
186  if ( result.empty()) result = tmp;
187  else {
188  // keep one dummy TM at the end, skip the others
189  result.insert( result.end()-invalidHits, tmp.begin(), tmp.end());
190  }
191  invalidHits++;
192  }
193  }
194 
195  // sort the final result, keep dummy measurements at the end
196  if ( result.size() > 1) {
197  sort( result.begin(), result.end()-invalidHits, TrajMeasLessEstim());
198  }
199  return result;
200 }
201 
202 //----------------------------------------------------------------------
203 void NuclearInteractionFinder::fillSeeds( const std::pair<TrajectoryMeasurement, std::vector<TrajectoryMeasurement> >& tmPairs ) {
204  // This method returns the seeds calculated by the class SeedsFromNuclearInteraction
205 
206  const TM& innerTM = tmPairs.first;
207  const std::vector<TM>& outerTMs = tmPairs.second;
208 
209  // Loop on all outer TM
210  for(std::vector<TM>::const_iterator outtm = outerTMs.begin(); outtm!=outerTMs.end(); outtm++) {
211  if((innerTM.recHit())->isValid() && (outtm->recHit())->isValid()) {
212  currentSeed->setMeasurements(innerTM.updatedState(), innerTM.recHit(), outtm->recHit());
213  allSeeds.push_back(*currentSeed);
214  }
215  else LogDebug("NuclearSeedGenerator") << "The initial hits for seeding are invalid" << "\n";
216  }
217  return;
218 }
219 //----------------------------------------------------------------------
220 std::auto_ptr<TrajectorySeedCollection> NuclearInteractionFinder::getPersistentSeeds() {
221  std::auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection);
222  for(std::vector<SeedFromNuclearInteraction>::const_iterator it_seed = allSeeds.begin(); it_seed != allSeeds.end(); it_seed++) {
223  if(it_seed->isValid()) {
224  output->push_back( it_seed->TrajSeed() );
225  }
226  else LogDebug("NuclearSeedGenerator") << "The seed is invalid" << "\n";
227  }
228  return output;
229 }
230 //----------------------------------------------------------------------
232  std::vector<SeedFromNuclearInteraction> newSeedCollection;
233 
234  // loop on all actual seeds
235  for(std::vector<SeedFromNuclearInteraction>::const_iterator it_seed = allSeeds.begin(); it_seed != allSeeds.end(); it_seed++) {
236 
237  if( !it_seed->isValid() ) continue;
238 
239  // find compatible TM in an outer layer
240  std::vector<TM> thirdTMs = findMeasurementsFromTSOS( it_seed->updatedTSOS() , it_seed->outerHitDetId() );
241 
242  // loop on those new TMs
243  for(std::vector<TM>::const_iterator tm = thirdTMs.begin(); tm!= thirdTMs.end(); tm++) {
244 
245  if( ! tm->recHit()->isValid() ) continue;
246 
247  // create new seeds collection using the circle equation
248  currentSeed->setMeasurements(*thePrimaryHelix, it_seed->initialTSOS(), it_seed->outerHit(), tm->recHit() );
249  newSeedCollection.push_back( *currentSeed );
250  }
251  }
252  allSeeds.clear();
253  allSeeds = newSeedCollection;
254 }
255 //----------------------------------------------------------------------
257 
261 
262  // we assume that the error on q/p is equal to 20% of q/p * rescale
263  mr(0,0) = (ltp.signedInverseMomentum()*0.2*rescale)*(ltp.signedInverseMomentum()*0.2*rescale);
264 
265  // the error on dx/z and dy/dz is fixed to 10% (* rescale)
266  mr(1,1) = 1E-2*rescale*rescale;
267  mr(2,2) = 1E-2*rescale*rescale;
268 
269  // the error on the local x and y positions are not modified.
270  mr(3,3) = m(3,3);
271  mr(4,4) = m(4,4);
272 
273  return TSOS(ltp, mr, state.surface(), &(state.globalParameters().magneticField()), state.surfaceSide());
274 }
#define LogDebug(id)
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:246
T getParameter(std::string const &) const
int foundHits() const
Definition: Trajectory.h:236
std::vector< TrajectoryMeasurement > measurements(const DetLayer &layer, const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est) const
int i
Definition: DBlmapReader.cc:9
void improveSeeds()
Improve the seeds with a third RecHit.
ConstRecHitPointer const & recHit() const
virtual void update(const edm::Event &) const =0
std::vector< int > compatibleHits() const
Definition: NuclearTester.h:61
const LocalTrajectoryParameters & localParameters() const
const TMContainer & back() const
Definition: NuclearTester.h:43
const NavigationSchool * nav() const
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void setMeasurements(const TSOS &tsosAtInteractionPoint, ConstRecHitPointer ihit, ConstRecHitPointer ohit)
Fill all data members from 2 TM&#39;s where the first one is supposed to be at the interaction point...
bool run(const Trajectory &traj)
Run the Finder.
double fwdEstimate(const std::vector< TrajectoryMeasurement > &vecTM) const
int nuclearIndex() const
Definition: NuclearTester.h:55
PropagationDirection const & direction() const
Definition: Trajectory.cc:196
bool isNuclearInteraction()
DataContainer const & measurements() const
Definition: Trajectory.h:215
std::vector< TrajectoryMeasurement > findCompatibleMeasurements(const TM &lastMeas, double rescaleFactor) const
Find compatible TM of a TM with error rescaled by rescaleFactor.
void push_back(const TM &init_tm, const TMContainer &vecTM)
Definition: NuclearTester.h:38
const SurfaceType & surface() const
std::vector< TrajectoryMeasurement > findMeasurementsFromTSOS(const TSOS &currentState, DetId detid) const
std::vector< TrajectorySeed > TrajectorySeedCollection
FreeTrajectoryState * freeState(bool withErrors=true) const
SurfaceSide surfaceSide() const
Position relative to material, defined relative to momentum vector.
double meanHitDistance(const std::vector< TrajectoryMeasurement > &vecTM) const
tuple result
Definition: query.py:137
std::vector< SeedFromNuclearInteraction > allSeeds
void reset(unsigned int nMeasurements)
Definition: NuclearTester.h:49
const MeasurementTracker * theMeasurementTracker
const DetLayer * detLayer(const DetId &id) const
obsolete method. Use idToLayer() instead.
const NavigationSchool * theNavigationSchool
const AlgebraicSymMatrix55 & matrix() const
const MeasurementEstimator * theEstimator
const LocalTrajectoryError & localError() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
Definition: DetId.h:20
bool isValid() const
Definition: Trajectory.h:271
const GlobalTrajectoryParameters & globalParameters() const
const T & get() const
Definition: EventSetup.h:55
edm::ESHandle< MagneticField > theMagField
T const * product() const
Definition: ESHandle.h:62
char state
Definition: procUtils.cc:75
const LayerMeasurements * theLayerMeasurements
const GeometricSearchTracker * theGeomSearchTracker
TrajectoryStateOnSurface TSOS
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::auto_ptr< TrajectorySeedCollection > getPersistentSeeds()
Fill &#39;output&#39; with persistent nuclear seeds.
void fillSeeds(const std::pair< TrajectoryMeasurement, std::vector< TrajectoryMeasurement > > &tmPairs)
get the seeds at the interaction point
Class used to test if a track has interacted nuclearly.
Definition: NuclearTester.h:16
const MagneticField & magneticField() const
TrajectoryStateOnSurface const & updatedState() const
unsigned int nHitsChecked() const
Definition: NuclearTester.h:59
void definePrimaryHelix(std::vector< TrajectoryMeasurement >::const_iterator it_meas)
Calculate the parameters of the circle representing the primary track at the interaction point...
TrajectoryStateOnSurface rescaleError(float rescale, const TSOS &state) const
double signedInverseMomentum() const
Signed inverse momentum q/p (zero for neutrals).
const TMPair & goodTMPair() const
Definition: NuclearTester.h:57
tuple size
Write out results.
std::vector< const DetLayer * > nextLayers(Args &&...args) const
Definition: DetLayer.h:60
void setEvent(const edm::Event &event) const
define the measurement (to be called for each event)
SeedFromNuclearInteraction * currentSeed