CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NuclearInteractionEDProducer.cc
Go to the documentation of this file.
5 
7 
10 
11 
13 
14 
16 conf_(iConfig),
17 primaryProducer_(iConfig.getParameter<std::string>("primaryProducer")),
18 seedsProducer_(iConfig.getParameter<std::string>("seedsProducer")),
19 secondaryProducer_(iConfig.getParameter<std::string>("secondaryProducer")),
20 additionalSecondaryProducer_(iConfig.getParameter<std::string>("additionalSecondaryProducer"))
21 {
22  produces<reco::NuclearInteractionCollection>();
23 }
24 
26 {
27 }
28 
29 //
30 // member functions
31 //
32 
33 // ------------ method called to produce the data ------------
34 void
36 {
37  if ( magFieldWatcher_.check(iSetup) || transientTrackWatcher_.check(iSetup) ) {
40  iSetup.get<IdealMagneticFieldRecord>().get(magField);
41 
43  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",builder);
44 
45  vertexBuilder = std::auto_ptr< NuclearVertexBuilder >(new NuclearVertexBuilder( magField.product(), builder.product(), conf_) );
46  likelihoodCalculator = std::auto_ptr< NuclearLikelihood >(new NuclearLikelihood);
47  }
48 
50  edm::Handle<reco::TrackCollection> primaryTrackCollection;
51  iEvent.getByLabel( primaryProducer_, primaryTrackCollection );
52 
54  edm::Handle< TrajectoryCollection > primaryTrajectoryCollection;
55  iEvent.getByLabel( primaryProducer_, primaryTrajectoryCollection );
56 
59  iEvent.getByLabel( primaryProducer_, refMapH );
60  const TrajTrackAssociationCollection& refMap = *(refMapH.product());
61 
64  iEvent.getByLabel(seedsProducer_, nuclMapH);
65  const TrajectoryToSeedsMap& nuclMap = *(nuclMapH.product());
66 
68  edm::Handle<reco::TrackCollection> secondaryTrackCollection;
69  iEvent.getByLabel( secondaryProducer_, secondaryTrackCollection );
70 
71  // Get eventual additional secondary tracks
72  edm::Handle<reco::TrackCollection> additionalSecTracks;
73  iEvent.getByLabel( additionalSecondaryProducer_, additionalSecTracks);
74 
76  std::auto_ptr<reco::NuclearInteractionCollection> theNuclearInteractions(new reco::NuclearInteractionCollection);
77 
78  typedef edm::Ref<TrajectoryCollection> TrajectoryRef;
79 
81  for(unsigned int i = 0; i < primaryTrajectoryCollection->size() ; i++) {
82 
83  TrajectoryRef trajRef( primaryTrajectoryCollection, i );
84 
86  TrajTrackAssociationCollection::const_iterator itPrimTrack = refMap.find( trajRef );
87  if( itPrimTrack == refMap.end() || (itPrimTrack->val).isNull() ) continue;
88  const reco::TrackRef& primary_track = itPrimTrack->val;
89 
91  TrajectoryToSeedsMap::const_iterator itSeeds = nuclMap.find( trajRef );
92  if( itSeeds == nuclMap.end() || (itSeeds->val).isNull()) continue;
93  const TrajectorySeedRefVector& seeds = itSeeds->val;
94 
96  std::vector<reco::TrackRef> secondary_tracks;
97  for( unsigned int k=0; k < secondaryTrackCollection->size(); k++) {
98  reco::TrackRef currentTrk(secondaryTrackCollection, k);
99  if( isInside( currentTrk, seeds ) ) secondary_tracks.push_back(currentTrk);
100  }
101 
103  vertexBuilder->build(primary_track, secondary_tracks);
104  likelihoodCalculator->calculate( vertexBuilder->getVertex() );
105 
107  reco::NuclearInteraction nuclInter(seeds, vertexBuilder->getVertex(), likelihoodCalculator->result() );
108 
111  if( additionalSecTracks.isValid() )
112  findAdditionalSecondaryTracks(nuclInter, additionalSecTracks);
113 
114  theNuclearInteractions->push_back( nuclInter );
115 
116  std::ostringstream str;
117  print(str, nuclInter, vertexBuilder);
118  edm::LogInfo("NuclearInteractionMaker") << str.str();
119 
120  }
121 
122 
123  LogDebug("NuclearInteractionMaker") << "End of NuclearInteractionMaker - Number of nuclear interactions found :" << theNuclearInteractions->size();
124  iEvent.put(theNuclearInteractions);
125 }
126 
127 // ------------ method called once each job just before starting event loop ------------
128 void
130 {
131 }
132 
134 
135 // ------ method used to check whether the seed of a track belong to the vector of seeds --
137  unsigned int seedKey = track->seedRef().key();
138  for (unsigned int i=0; i< seeds.size(); i++) { if( seeds[i].key() == seedKey ) return true; }
139  return false;
140 }
141 
143  const edm::Handle<reco::TrackCollection>& additionalSecTracks) {
144 
145  LogDebug("NuclearInteractionMaker") << "Check if one of the " << additionalSecTracks->size()
146  << " additional secondary track is compatible";
147  reco::TrackRefVector allSecondary;
148  for(unsigned int i=0; i< additionalSecTracks->size(); i++) {
149  reco::TrackRef sec(additionalSecTracks, i);
150  if( vertexBuilder->isCompatible( sec ) ) {
151  // check if sec is already a secondary track (with id = tkId)
152  // else add this new track
153  vertexBuilder->addSecondaryTrack( sec );
154  }
155  }
156  likelihoodCalculator->calculate( vertexBuilder->getVertex() );
157 
158  nucl = reco::NuclearInteraction(nucl.seeds(), vertexBuilder->getVertex(), likelihoodCalculator->result() );
159 }
160 
161 // -- print out
162 void print(std::ostringstream& out, const reco::NuclearInteraction& nucl, const std::auto_ptr< NuclearVertexBuilder >& builder) {
163  out<<"Nuclear Interaction with vertex position : (";
164  out<< nucl.vertex().position().x() << " , "
165  << nucl.vertex().position().y() << " , "
166  << nucl.vertex().position().z() << ")";
167  reco::TrackRef primTrack = (nucl.primaryTrack()).castTo<reco::TrackRef>();
168  out<<"\tLikelihood : " << nucl.likelihood() << std::endl;
169  out<<"\tPrimary Track : Pt = " << primTrack->pt() << " - Nhits = "
170  << primTrack->numberOfValidHits() << std::endl;
171  out << "\tNumber of seeds : " << nucl.seedsSize() << std::endl;
172  out << "\tNumber of secondary Tracks : " << nucl.secondaryTracksSize() << std::endl;
173  int it=0;
174  for( reco::NuclearInteraction::trackRef_iterator itr_=nucl.secondaryTracks_begin(); itr_ != nucl.secondaryTracks_end(); itr_++, it++) {
175  reco::TrackRef secTrack = (*itr_).castTo<reco::TrackRef>();
176  ClosestApproachInRPhi* theApproach = builder->closestApproach(primTrack, secTrack);
177  out << "\t\t Secondary track " << it << " : Pt = " << (*itr_)->pt()
178  << " - Nhits = " << (*itr_)->numberOfValidHits()
179  << " - Dist = " << theApproach->distance()
180  << " - chi2 = " << (*itr_)->normalizedChi2() << std::endl;
181  delete theApproach;
182  }
183  out << "----------------" << std::endl;
184 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
virtual void produce(edm::Event &, const edm::EventSetup &)
bool isInside(const reco::TrackRef &track, const TrajectorySeedRefVector &seeds)
trackRef_iterator secondaryTracks_begin() const
first iterator over secondary tracks
edm::ESWatcher< TransientTrackRecord > transientTrackWatcher_
NuclearInteractionEDProducer(const edm::ParameterSet &)
const_iterator end() const
last iterator over the map (read only)
const edm::RefToBase< reco::Track > & primaryTrack() const
return the base reference to the primary track
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
const_iterator find(const key_type &k) const
find element with specified reference key
const Point & position() const
position
Definition: Vertex.h:93
int secondaryTracksSize() const
return the number of secondary tracks
const TrajectorySeedRefVector & seeds()
return the seeds
int iEvent
Definition: GenABIO.cc:243
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
std::vector< NuclearInteraction > NuclearInteractionCollection
collection of NuclearInteractions
reco::Vertex::trackRef_iterator trackRef_iterator
int seedsSize() const
return the number of seeds
bool isValid() const
Definition: HandleBase.h:76
double likelihood() const
return the likelihood ~ probability that the vertex is a real nuclear interaction ...
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
int k[5][pyjets_maxn]
tuple out
Definition: dbtoconf.py:99
void findAdditionalSecondaryTracks(reco::NuclearInteraction &nucl, const edm::Handle< reco::TrackCollection > &additionalSecTracks)
const T & get() const
Definition: EventSetup.h:55
key_type key() const
Accessor for product key.
Definition: Ref.h:266
T const * product() const
Definition: ESHandle.h:62
T const * product() const
Definition: Handle.h:74
edm::ESWatcher< IdealMagneticFieldRecord > magFieldWatcher_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:59
const reco::Vertex & vertex() const
return the vertex
list key
Definition: combine.py:13
std::auto_ptr< NuclearLikelihood > likelihoodCalculator
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
trackRef_iterator secondaryTracks_end() const
last iterator over secondary tracks
std::auto_ptr< NuclearVertexBuilder > vertexBuilder