Go to the documentation of this file.00001 #include "RecoVertex/NuclearInteractionProducer/interface/NuclearInteractionEDProducer.h"
00002 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00003 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005
00006 #include "DataFormats/VertexReco/interface/NuclearInteractionFwd.h"
00007
00008 #include "RecoVertex/NuclearInteractionProducer/interface/NuclearVertexBuilder.h"
00009 #include "RecoVertex/NuclearInteractionProducer/interface/NuclearLikelihood.h"
00010
00011
00012 #include "FWCore/Framework/interface/EventSetup.h"
00013
00014
00015 NuclearInteractionEDProducer::NuclearInteractionEDProducer(const edm::ParameterSet& iConfig) :
00016 conf_(iConfig),
00017 primaryProducer_(iConfig.getParameter<std::string>("primaryProducer")),
00018 seedsProducer_(iConfig.getParameter<std::string>("seedsProducer")),
00019 secondaryProducer_(iConfig.getParameter<std::string>("secondaryProducer")),
00020 additionalSecondaryProducer_(iConfig.getParameter<std::string>("additionalSecondaryProducer"))
00021 {
00022 produces<reco::NuclearInteractionCollection>();
00023 }
00024
00025 NuclearInteractionEDProducer::~NuclearInteractionEDProducer()
00026 {
00027 }
00028
00029
00030
00031
00032
00033
00034 void
00035 NuclearInteractionEDProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
00036 {
00037 if ( magFieldWatcher_.check(iSetup) || transientTrackWatcher_.check(iSetup) ) {
00039 edm::ESHandle<MagneticField> magField;
00040 iSetup.get<IdealMagneticFieldRecord>().get(magField);
00041
00042 edm::ESHandle<TransientTrackBuilder> builder;
00043 iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",builder);
00044
00045 vertexBuilder = std::auto_ptr< NuclearVertexBuilder >(new NuclearVertexBuilder( magField.product(), builder.product(), conf_) );
00046 likelihoodCalculator = std::auto_ptr< NuclearLikelihood >(new NuclearLikelihood);
00047 }
00048
00050 edm::Handle<reco::TrackCollection> primaryTrackCollection;
00051 iEvent.getByLabel( primaryProducer_, primaryTrackCollection );
00052
00054 edm::Handle< TrajectoryCollection > primaryTrajectoryCollection;
00055 iEvent.getByLabel( primaryProducer_, primaryTrajectoryCollection );
00056
00058 edm::Handle< TrajTrackAssociationCollection > refMapH;
00059 iEvent.getByLabel( primaryProducer_, refMapH );
00060 const TrajTrackAssociationCollection& refMap = *(refMapH.product());
00061
00063 edm::Handle<TrajectoryToSeedsMap> nuclMapH;
00064 iEvent.getByLabel(seedsProducer_, nuclMapH);
00065 const TrajectoryToSeedsMap& nuclMap = *(nuclMapH.product());
00066
00068 edm::Handle<reco::TrackCollection> secondaryTrackCollection;
00069 iEvent.getByLabel( secondaryProducer_, secondaryTrackCollection );
00070
00071
00072 edm::Handle<reco::TrackCollection> additionalSecTracks;
00073 iEvent.getByLabel( additionalSecondaryProducer_, additionalSecTracks);
00074
00076 std::auto_ptr<reco::NuclearInteractionCollection> theNuclearInteractions(new reco::NuclearInteractionCollection);
00077
00078 typedef edm::Ref<TrajectoryCollection> TrajectoryRef;
00079
00081 for(unsigned int i = 0; i < primaryTrajectoryCollection->size() ; i++) {
00082
00083 TrajectoryRef trajRef( primaryTrajectoryCollection, i );
00084
00086 TrajTrackAssociationCollection::const_iterator itPrimTrack = refMap.find( trajRef );
00087 if( itPrimTrack == refMap.end() || (itPrimTrack->val).isNull() ) continue;
00088 const reco::TrackRef& primary_track = itPrimTrack->val;
00089
00091 TrajectoryToSeedsMap::const_iterator itSeeds = nuclMap.find( trajRef );
00092 if( itSeeds == nuclMap.end() || (itSeeds->val).isNull()) continue;
00093 const TrajectorySeedRefVector& seeds = itSeeds->val;
00094
00096 std::vector<reco::TrackRef> secondary_tracks;
00097 for( unsigned int k=0; k < secondaryTrackCollection->size(); k++) {
00098 reco::TrackRef currentTrk(secondaryTrackCollection, k);
00099 if( isInside( currentTrk, seeds ) ) secondary_tracks.push_back(currentTrk);
00100 }
00101
00103 vertexBuilder->build(primary_track, secondary_tracks);
00104 likelihoodCalculator->calculate( vertexBuilder->getVertex() );
00105
00107 reco::NuclearInteraction nuclInter(seeds, vertexBuilder->getVertex(), likelihoodCalculator->result() );
00108
00111 if( additionalSecTracks.isValid() )
00112 findAdditionalSecondaryTracks(nuclInter, additionalSecTracks);
00113
00114 theNuclearInteractions->push_back( nuclInter );
00115
00116 std::ostringstream str;
00117 print(str, nuclInter, vertexBuilder);
00118 edm::LogInfo("NuclearInteractionMaker") << str.str();
00119
00120 }
00121
00122
00123 LogDebug("NuclearInteractionMaker") << "End of NuclearInteractionMaker - Number of nuclear interactions found :" << theNuclearInteractions->size();
00124 iEvent.put(theNuclearInteractions);
00125 }
00126
00127
00128 void
00129 NuclearInteractionEDProducer::beginJob()
00130 {
00131 }
00132
00133 void NuclearInteractionEDProducer::endJob() {}
00134
00135
00136 bool NuclearInteractionEDProducer::isInside( const reco::TrackRef& track, const TrajectorySeedRefVector& seeds) {
00137 unsigned int seedKey = track->seedRef().key();
00138 for (unsigned int i=0; i< seeds.size(); i++) { if( seeds[i].key() == seedKey ) return true; }
00139 return false;
00140 }
00141
00142 void NuclearInteractionEDProducer::findAdditionalSecondaryTracks( reco::NuclearInteraction& nucl,
00143 const edm::Handle<reco::TrackCollection>& additionalSecTracks) {
00144
00145 LogDebug("NuclearInteractionMaker") << "Check if one of the " << additionalSecTracks->size()
00146 << " additional secondary track is compatible";
00147 reco::TrackRefVector allSecondary;
00148 for(unsigned int i=0; i< additionalSecTracks->size(); i++) {
00149 reco::TrackRef sec(additionalSecTracks, i);
00150 if( vertexBuilder->isCompatible( sec ) ) {
00151
00152
00153 vertexBuilder->addSecondaryTrack( sec );
00154 }
00155 }
00156 likelihoodCalculator->calculate( vertexBuilder->getVertex() );
00157
00158 nucl = reco::NuclearInteraction(nucl.seeds(), vertexBuilder->getVertex(), likelihoodCalculator->result() );
00159 }
00160
00161
00162 void print(std::ostringstream& out, const reco::NuclearInteraction& nucl, const std::auto_ptr< NuclearVertexBuilder >& builder) {
00163 out<<"Nuclear Interaction with vertex position : (";
00164 out<< nucl.vertex().position().x() << " , "
00165 << nucl.vertex().position().y() << " , "
00166 << nucl.vertex().position().z() << ")";
00167 reco::TrackRef primTrack = (nucl.primaryTrack()).castTo<reco::TrackRef>();
00168 out<<"\tLikelihood : " << nucl.likelihood() << std::endl;
00169 out<<"\tPrimary Track : Pt = " << primTrack->pt() << " - Nhits = "
00170 << primTrack->numberOfValidHits() << std::endl;
00171 out << "\tNumber of seeds : " << nucl.seedsSize() << std::endl;
00172 out << "\tNumber of secondary Tracks : " << nucl.secondaryTracksSize() << std::endl;
00173 int it=0;
00174 for( reco::NuclearInteraction::trackRef_iterator itr_=nucl.secondaryTracks_begin(); itr_ != nucl.secondaryTracks_end(); itr_++, it++) {
00175 reco::TrackRef secTrack = (*itr_).castTo<reco::TrackRef>();
00176 ClosestApproachInRPhi* theApproach = builder->closestApproach(primTrack, secTrack);
00177 out << "\t\t Secondary track " << it << " : Pt = " << (*itr_)->pt()
00178 << " - Nhits = " << (*itr_)->numberOfValidHits()
00179 << " - Dist = " << theApproach->distance()
00180 << " - chi2 = " << (*itr_)->normalizedChi2() << std::endl;
00181 delete theApproach;
00182 }
00183 out << "----------------" << std::endl;
00184 }