CMS 3D CMS Logo

NuclearInteractionEDProducer.cc
Go to the documentation of this file.
3 
5 
8 
9 
11 
12 namespace {
13  void print(std::ostringstream& str, const reco::NuclearInteraction& nucl, const NuclearVertexBuilder& builder);
14 }
15 
16 
18 conf_(iConfig)
19 {
20  token_primaryTrack = consumes<reco::TrackCollection>(iConfig.getParameter<std::string>("primaryProducer"));
21  token_secondaryTrack = consumes<reco::TrackCollection>(iConfig.getParameter<std::string>("secondaryProducer"));
22  token_additionalSecTracks = consumes<reco::TrackCollection>(iConfig.getParameter<std::string>("additionalSecondaryProducer"));
23  token_primaryTrajectory = consumes<TrajectoryCollection>(iConfig.getParameter<std::string>("primaryProducer"));
24  token_refMapH = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<std::string>("primaryProducer"));
25  token_nuclMapH = consumes<TrajectoryToSeedsMap>(iConfig.getParameter<std::string>("seedsProducer"));
26 
27  produces<reco::NuclearInteractionCollection>();
28 }
29 
31 {
32 }
33 
34 //
35 // member functions
36 //
37 
38 // ------------ method called to produce the data ------------
39 void
41 {
42  if ( magFieldWatcher_.check(iSetup) || transientTrackWatcher_.check(iSetup) ) {
45  iSetup.get<IdealMagneticFieldRecord>().get(magField);
46 
48  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",builder);
49 
50  vertexBuilder = std::make_unique< NuclearVertexBuilder >(magField.product(), builder.product(), conf_);
51  likelihoodCalculator = std::make_unique< NuclearLikelihood >();
52  }
53 
55  edm::Handle<reco::TrackCollection> primaryTrackCollection;
56  iEvent.getByToken(token_primaryTrack, primaryTrackCollection);
57 
59  edm::Handle< TrajectoryCollection > primaryTrajectoryCollection;
60  iEvent.getByToken(token_primaryTrajectory, primaryTrajectoryCollection);
61 
64  iEvent.getByToken(token_refMapH, refMapH);
65  const TrajTrackAssociationCollection& refMap = *(refMapH.product());
66 
69  iEvent.getByToken(token_nuclMapH, nuclMapH);
70  const TrajectoryToSeedsMap& nuclMap = *(nuclMapH.product());
71 
73  edm::Handle<reco::TrackCollection> secondaryTrackCollection;
74  iEvent.getByToken(token_secondaryTrack, secondaryTrackCollection);
75 
76  // Get eventual additional secondary tracks
77  edm::Handle<reco::TrackCollection> additionalSecTracks;
78  iEvent.getByToken(token_additionalSecTracks, additionalSecTracks);
79 
81  auto theNuclearInteractions = std::make_unique<reco::NuclearInteractionCollection>();
82 
83  typedef edm::Ref<TrajectoryCollection> TrajectoryRef;
84 
86  for(unsigned int i = 0; i < primaryTrajectoryCollection->size() ; i++) {
87 
88  TrajectoryRef trajRef( primaryTrajectoryCollection, i );
89 
91  TrajTrackAssociationCollection::const_iterator itPrimTrack = refMap.find( trajRef );
92  if( itPrimTrack == refMap.end() || (itPrimTrack->val).isNull() ) continue;
93  const reco::TrackRef& primary_track = itPrimTrack->val;
94 
96  TrajectoryToSeedsMap::const_iterator itSeeds = nuclMap.find( trajRef );
97  if( itSeeds == nuclMap.end() || (itSeeds->val).isNull()) continue;
98  const TrajectorySeedRefVector& seeds = itSeeds->val;
99 
101  std::vector<reco::TrackRef> secondary_tracks;
102  for( unsigned int k=0; k < secondaryTrackCollection->size(); k++) {
103  reco::TrackRef currentTrk(secondaryTrackCollection, k);
104  if( isInside( currentTrk, seeds ) ) secondary_tracks.push_back(currentTrk);
105  }
106 
108  vertexBuilder->build(primary_track, secondary_tracks);
109  likelihoodCalculator->calculate( vertexBuilder->getVertex() );
110 
112  reco::NuclearInteraction nuclInter(seeds, vertexBuilder->getVertex(), likelihoodCalculator->result() );
113 
116  if( additionalSecTracks.isValid() )
117  findAdditionalSecondaryTracks(nuclInter, additionalSecTracks);
118 
119  theNuclearInteractions->push_back( nuclInter );
120 
121  std::ostringstream str;
122  print(str, nuclInter, *vertexBuilder);
123  edm::LogInfo("NuclearInteractionMaker") << str.str();
124 
125  }
126 
127 
128  LogDebug("NuclearInteractionMaker") << "End of NuclearInteractionMaker - Number of nuclear interactions found :" << theNuclearInteractions->size();
129  iEvent.put(std::move(theNuclearInteractions));
130 }
131 
132 // ------ method used to check whether the seed of a track belong to the vector of seeds --
134  unsigned int seedKey = track->seedRef().key();
135  for (unsigned int i=0; i< seeds.size(); i++) { if( seeds[i].key() == seedKey ) return true; }
136  return false;
137 }
138 
140  const edm::Handle<reco::TrackCollection>& additionalSecTracks) const {
141 
142  LogDebug("NuclearInteractionMaker") << "Check if one of the " << additionalSecTracks->size()
143  << " additional secondary track is compatible";
144  reco::TrackRefVector allSecondary;
145  for(unsigned int i=0; i< additionalSecTracks->size(); i++) {
146  reco::TrackRef sec(additionalSecTracks, i);
147  if( vertexBuilder->isCompatible( sec ) ) {
148  // check if sec is already a secondary track (with id = tkId)
149  // else add this new track
150  vertexBuilder->addSecondaryTrack( sec );
151  }
152  }
153  likelihoodCalculator->calculate( vertexBuilder->getVertex() );
154 
155  nucl = reco::NuclearInteraction(nucl.seeds(), vertexBuilder->getVertex(), likelihoodCalculator->result() );
156 }
157 
158 // -- print out
159 namespace {
160 void print(std::ostringstream& out, const reco::NuclearInteraction& nucl, const NuclearVertexBuilder& builder) {
161  out<<"Nuclear Interaction with vertex position : (";
162  out<< nucl.vertex().position().x() << " , "
163  << nucl.vertex().position().y() << " , "
164  << nucl.vertex().position().z() << ")";
165  reco::TrackRef primTrack = (nucl.primaryTrack()).castTo<reco::TrackRef>();
166  out<<"\tLikelihood : " << nucl.likelihood() << std::endl;
167  out<<"\tPrimary Track : Pt = " << primTrack->pt() << " - Nhits = "
168  << primTrack->numberOfValidHits() << std::endl;
169  out << "\tNumber of seeds : " << nucl.seedsSize() << std::endl;
170  out << "\tNumber of secondary Tracks : " << nucl.secondaryTracksSize() << std::endl;
171  int it=0;
172  for( reco::NuclearInteraction::trackRef_iterator itr_=nucl.secondaryTracks_begin(); itr_ != nucl.secondaryTracks_end(); itr_++, it++) {
173  reco::TrackRef secTrack = (*itr_).castTo<reco::TrackRef>();
174  ClosestApproachInRPhi* theApproach = builder.closestApproach(primTrack, secTrack);
175  out << "\t\t Secondary track " << it << " : Pt = " << (*itr_)->pt()
176  << " - Nhits = " << (*itr_)->numberOfValidHits()
177  << " - Dist = " << theApproach->distance()
178  << " - chi2 = " << (*itr_)->normalizedChi2() << std::endl;
179  delete theApproach;
180  }
181  out << "----------------" << std::endl;
182 }
183 }
#define LogDebug(id)
T getParameter(std::string const &) const
std::unique_ptr< NuclearLikelihood > likelihoodCalculator
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
static 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 &)
edm::EDGetTokenT< reco::TrackCollection > token_additionalSecTracks
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
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:10
const_iterator find(const key_type &k) const
find element with specified reference key
virtual void produce(edm::Event &, const edm::EventSetup &) override
key_type key() const
Accessor for product key.
Definition: Ref.h:265
const Point & position() const
position
Definition: Vertex.h:109
int secondaryTracksSize() const
return the number of secondary tracks
const TrajectorySeedRefVector & seeds()
return the seeds
ClosestApproachInRPhi * closestApproach(const reco::TrackRef &primTrack, const reco::TrackRef &secTrack) const
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< TrajTrackAssociationCollection > token_refMapH
std::unique_ptr< NuclearVertexBuilder > vertexBuilder
reco::Vertex::trackRef_iterator trackRef_iterator
edm::EDGetTokenT< TrajectoryCollection > token_primaryTrajectory
void findAdditionalSecondaryTracks(reco::NuclearInteraction &nucl, const edm::Handle< reco::TrackCollection > &additionalSecTracks) const
int seedsSize() const
return the number of seeds
bool isValid() const
Definition: HandleBase.h:74
double likelihood() const
return the likelihood ~ probability that the vertex is a real nuclear interaction ...
int k[5][pyjets_maxn]
T const * product() const
Definition: Handle.h:81
const T & get() const
Definition: EventSetup.h:55
edm::ESWatcher< IdealMagneticFieldRecord > magFieldWatcher_
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
edm::EDGetTokenT< reco::TrackCollection > token_secondaryTrack
const reco::Vertex & vertex() const
return the vertex
size_type size() const
Size of the RefVector.
Definition: RefVector.h:107
edm::EDGetTokenT< reco::TrackCollection > token_primaryTrack
edm::EDGetTokenT< TrajectoryToSeedsMap > token_nuclMapH
virtual float distance() const
trackRef_iterator secondaryTracks_end() const
last iterator over secondary tracks
T const * product() const
Definition: ESHandle.h:86
def move(src, dest)
Definition: eostools.py:510