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 maxHits(iConfig.getParameter<int>("maxHits")),
19 rescaleErrorFactor(iConfig.getParameter<double>("rescaleErrorFactor")),
20 checkCompletedTrack(iConfig.getParameter<bool>("checkCompletedTrack")),
21 navigationSchoolName(iConfig.getParameter<std::string>("NavigationSchool"))
22 {
23 
24  std::string measurementTrackerName = iConfig.getParameter<std::string>("MeasurementTrackerName");
25 
29  edm::ESHandle<MeasurementTracker> measurementTrackerHandle;
30  edm::ESHandle<GeometricSearchTracker> theGeomSearchTrackerHandle;
31  edm::ESHandle<TrackerGeometry> theTrackerGeom;
32 
33  es.get<TrackerDigiGeometryRecord> ().get (theTrackerGeom);
34  es.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",prop);
35  es.get<TrackingComponentsRecord>().get("Chi2",est);
36  es.get<CkfComponentsRecord>().get(measurementTrackerName, measurementTrackerHandle);
37  es.get<TrackerRecoGeometryRecord>().get(theGeomSearchTrackerHandle );
39 
43 
44  thePropagator = prop.product();
45  theEstimator = est.product();
46  theMeasurementTracker = measurementTrackerHandle.product();
48  theGeomSearchTracker = theGeomSearchTrackerHandle.product();
49 
50  LogDebug("NuclearSeedGenerator") << "New NuclearInteractionFinder instance with parameters : \n"
51  << "maxHits : " << maxHits << "\n"
52  << "rescaleErrorFactor : " << rescaleErrorFactor << "\n"
53  << "checkCompletedTrack : " << checkCompletedTrack << "\n";
54 
55  nuclTester = new NuclearTester(maxHits, theEstimator, theTrackerGeom.product() );
56 
57  currentSeed = new SeedFromNuclearInteraction(thePropagator, theTrackerGeom.product(), iConfig) ;
58 
60 }
61 //----------------------------------------------------------------------
63 {
65 }
66 
67 //----------------------------------------------------------------------
69  delete theLayerMeasurements;
70  delete nuclTester;
71  delete currentSeed;
72  delete thePrimaryHelix;
73 }
74 
75 //----------------------------------------------------------------------
77 
78  if(traj.empty() || !traj.isValid()) return false;
79 
80  LogDebug("NuclearSeedGenerator") << "Analyzis of a new trajectory with a number of valid hits = " << traj.foundHits();
81 
82  std::vector<TrajectoryMeasurement> measurements = traj.measurements();
83 
84  // initialization
85  nuclTester->reset( measurements.size() );
86  allSeeds.clear();
87 
88 
89  if(traj.direction()==alongMomentum) {
90  std::reverse(measurements.begin(), measurements.end());
91  }
92 
93  std::vector<TrajectoryMeasurement>::const_iterator it_meas = measurements.begin();
94 
95  std::vector<double> ncompatibleHits;
96  bool NIfound = false;
97 
98  // Loop on all the RecHits.
99  while(!NIfound)
100  {
101  if(it_meas == measurements.end()) break;
102 
103  // check only the maxHits outermost hits of the primary track
104  if(nuclTester->nHitsChecked() > maxHits) break;
105 
107 
108  LogDebug("NuclearSeedGenerator") << "Number of compatible meas:" << (nuclTester->back()).size() << "\n"
109  << "Mean distance between hits :" << nuclTester->meanHitDistance() << "\n"
110  << "Forward estimate :" << nuclTester->fwdEstimate() << "\n";
111 
112  // don't check tracks which reach the end of the tracker if checkCompletedTrack==false
113  if( checkCompletedTrack==false && (nuclTester->compatibleHits()).front()==0 ) break;
114 
115  if(nuclTester->isNuclearInteraction()) NIfound=true;
116 
117  ++it_meas;
118  }
119 
120  if(NIfound) {
121  LogDebug("NuclearSeedGenerator") << "NUCLEAR INTERACTION FOUND at index : " << nuclTester->nuclearIndex() << "\n";
122 
123  // Get correct parametrization of the helix of the primary track at the interaction point (to be used by improveCurrentSeed)
124  definePrimaryHelix(measurements.begin()+nuclTester->nuclearIndex()-1);
125 
126  this->fillSeeds( nuclTester->goodTMPair());
127 
128  return true;
129  }
130 
131  return false;
132 }
133 //----------------------------------------------------------------------
134 void NuclearInteractionFinder::definePrimaryHelix(std::vector<TrajectoryMeasurement>::const_iterator it_meas) {
135  // This method uses the 3 last TM after the interaction point to calculate the helix parameters
136 
137  GlobalPoint pt[3];
138  for(int i=0; i<3; i++) {
139  pt[i] = (it_meas->updatedState()).globalParameters().position();
140  it_meas++;
141  }
142  delete thePrimaryHelix;
143  thePrimaryHelix = new TangentHelix( pt[0], pt[1], pt[2] );
144 }
145 //----------------------------------------------------------------------
146 std::vector<TrajectoryMeasurement>
147 NuclearInteractionFinder::findCompatibleMeasurements(const TM& lastMeas, double rescale) const
148 {
149  TSOS currentState = lastMeas.updatedState();
150  LogDebug("NuclearSeedGenerator") << "currentState :" << currentState << "\n";
151 
152  TSOS newState = rescaleError(rescale, currentState);
153  return findMeasurementsFromTSOS(newState, lastMeas.recHit()->geographicalId());
154 }
155 //----------------------------------------------------------------------
156 std::vector<TrajectoryMeasurement>
158 
159  using namespace std;
160  int invalidHits = 0;
161  vector<TM> result;
162  const DetLayer* lastLayer = theGeomSearchTracker->detLayer( detid );
163  vector<const DetLayer*> nl;
164 
165  if(lastLayer) {
166  nl = lastLayer->nextLayers( *currentState.freeState(), alongMomentum);
167  }
168  else {
169  edm::LogError("NuclearInteractionFinder") << "In findCompatibleMeasurements : lastLayer not accessible";
170  return result;
171  }
172 
173  if (nl.empty()) {
174  LogDebug("NuclearSeedGenerator") << "In findCompatibleMeasurements : no compatible layer found";
175  return result;
176  }
177 
178  for (vector<const DetLayer*>::iterator il = nl.begin();
179  il != nl.end(); il++) {
180  vector<TM> tmp =
182  if ( !tmp.empty()) {
183  if ( result.empty()) result = tmp;
184  else {
185  // keep one dummy TM at the end, skip the others
186  result.insert( result.end()-invalidHits, tmp.begin(), tmp.end());
187  }
188  invalidHits++;
189  }
190  }
191 
192  // sort the final result, keep dummy measurements at the end
193  if ( result.size() > 1) {
194  sort( result.begin(), result.end()-invalidHits, TrajMeasLessEstim());
195  }
196  return result;
197 }
198 
199 //----------------------------------------------------------------------
200 void NuclearInteractionFinder::fillSeeds( const std::pair<TrajectoryMeasurement, std::vector<TrajectoryMeasurement> >& tmPairs ) {
201  // This method returns the seeds calculated by the class SeedsFromNuclearInteraction
202 
203  const TM& innerTM = tmPairs.first;
204  const std::vector<TM>& outerTMs = tmPairs.second;
205 
206  // Loop on all outer TM
207  for(std::vector<TM>::const_iterator outtm = outerTMs.begin(); outtm!=outerTMs.end(); outtm++) {
208  if((innerTM.recHit())->isValid() && (outtm->recHit())->isValid()) {
209  currentSeed->setMeasurements(innerTM.updatedState(), innerTM.recHit(), outtm->recHit());
210  allSeeds.push_back(*currentSeed);
211  }
212  else LogDebug("NuclearSeedGenerator") << "The initial hits for seeding are invalid" << "\n";
213  }
214  return;
215 }
216 //----------------------------------------------------------------------
217 std::auto_ptr<TrajectorySeedCollection> NuclearInteractionFinder::getPersistentSeeds() {
218  std::auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection);
219  for(std::vector<SeedFromNuclearInteraction>::const_iterator it_seed = allSeeds.begin(); it_seed != allSeeds.end(); it_seed++) {
220  if(it_seed->isValid()) {
221  output->push_back( it_seed->TrajSeed() );
222  }
223  else LogDebug("NuclearSeedGenerator") << "The seed is invalid" << "\n";
224  }
225  return output;
226 }
227 //----------------------------------------------------------------------
229  std::vector<SeedFromNuclearInteraction> newSeedCollection;
230 
231  // loop on all actual seeds
232  for(std::vector<SeedFromNuclearInteraction>::const_iterator it_seed = allSeeds.begin(); it_seed != allSeeds.end(); it_seed++) {
233 
234  if( !it_seed->isValid() ) continue;
235 
236  // find compatible TM in an outer layer
237  std::vector<TM> thirdTMs = findMeasurementsFromTSOS( it_seed->updatedTSOS() , it_seed->outerHitDetId() );
238 
239  // loop on those new TMs
240  for(std::vector<TM>::const_iterator tm = thirdTMs.begin(); tm!= thirdTMs.end(); tm++) {
241 
242  if( ! tm->recHit()->isValid() ) continue;
243 
244  // create new seeds collection using the circle equation
245  currentSeed->setMeasurements(*thePrimaryHelix, it_seed->initialTSOS(), it_seed->outerHit(), tm->recHit() );
246  newSeedCollection.push_back( *currentSeed );
247  }
248  }
249  allSeeds.clear();
250  allSeeds = newSeedCollection;
251 }
252 //----------------------------------------------------------------------
254 
258 
259  // we assume that the error on q/p is equal to 20% of q/p * rescale
260  mr(0,0) = (ltp.signedInverseMomentum()*0.2*rescale)*(ltp.signedInverseMomentum()*0.2*rescale);
261 
262  // the error on dx/z and dy/dz is fixed to 10% (* rescale)
263  mr(1,1) = 1E-2*rescale*rescale;
264  mr(2,2) = 1E-2*rescale*rescale;
265 
266  // the error on the local x and y positions are not modified.
267  mr(3,3) = m(3,3);
268  mr(4,4) = m(4,4);
269 
270  return TSOS(ltp, mr, state.surface(), &(state.globalParameters().magneticField()), state.surfaceSide());
271 }
#define LogDebug(id)
bool empty() const
True if trajectory has no measurements.
Definition: Trajectory.h:200
T getParameter(std::string const &) const
int foundHits() const
Definition: Trajectory.h:190
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.
std::vector< int > compatibleHits() const
Definition: NuclearTester.h:61
const LocalTrajectoryParameters & localParameters() const
const TMContainer & back() const
Definition: NuclearTester.h:43
virtual void update(const edm::Event &) const
virtual std::vector< const DetLayer * > nextLayers(NavigationDirection direction) const
Definition: DetLayer.cc:35
ConstRecHitPointer recHit() const
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:195
bool isNuclearInteraction()
DataContainer const & measurements() const
Definition: Trajectory.h:169
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
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
TrajectoryStateOnSurface updatedState() const
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:225
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.
const Surface & surface() const
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
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.
void setEvent(const edm::Event &event) const
define the measurement (to be called for each event)
SeedFromNuclearInteraction * currentSeed