CMS 3D CMS Logo

SETMuonSeedProducer.cc
Go to the documentation of this file.
1 
6 
13 
16 
18 
25 #include "TMath.h"
26 
27 using namespace edm;
28 using namespace std;
29 
31 : theSeedFinder(parameterSet),
32  theBeamSpotTag(parameterSet.getParameter<edm::InputTag>("beamSpotTag"))
33 {
34 
35  edm::ConsumesCollector iC = consumesCollector();
36  thePatternRecognition = new SETPatternRecognition(parameterSet,iC);
37 
38  const string metname = "Muon|RecoMuon|SETMuonSeedSeed";
39  //std::cout<<" The SET SEED producer started."<<std::endl;
40 
41  ParameterSet serviceParameters = parameterSet.getParameter<ParameterSet>("ServiceParameters");
42  theService = new MuonServiceProxy(serviceParameters);
44  theSeedFinder.setServiceProxy(theService);
45  // Parameter set for the Builder
46  ParameterSet trajectoryBuilderParameters = parameterSet.getParameter<ParameterSet>("SETTrajBuilderParameters");
47 
48  LogTrace(metname) << "constructor called" << endl;
49 
50  apply_prePruning = trajectoryBuilderParameters.getParameter<bool>("Apply_prePruning");
51 
52  useSegmentsInTrajectory = trajectoryBuilderParameters.getParameter<bool>("UseSegmentsInTrajectory");
53 
54  // The inward-outward fitter (starts from seed state)
55  ParameterSet filterPSet = trajectoryBuilderParameters.getParameter<ParameterSet>("FilterParameters");
56  filterPSet.addUntrackedParameter("UseSegmentsInTrajectory", useSegmentsInTrajectory);
57  theFilter = new SETFilter(filterPSet,theService);
58 
59  //----
60 
61 
62  beamspotToken = consumes<reco::BeamSpot>(theBeamSpotTag);
63  produces<TrajectorySeedCollection>();
64 
65 }
66 
68 
69  LogTrace("Muon|RecoMuon|SETMuonSeedProducer")
70  << "SETMuonSeedProducer destructor called" << endl;
71 
72  if(theFilter) delete theFilter;
73  if (theService) delete theService;
75 
76 }
77 
79  //std::cout<<" start producing..."<<std::endl;
80  const string metname = "Muon|RecoMuon|SETMuonSeedSeed";
81 
83 
84  //Get the CSC Geometry :
85  theService->update(eventSetup);
86 
87  auto output = std::make_unique<TrajectorySeedCollection>();
88 
90 
91  setEvent(event);
92 
94  edm::Handle<reco::BeamSpot> beamSpotHandle;
95  event.getByToken(beamspotToken, beamSpotHandle);
96  if ( beamSpotHandle.isValid() )
97  {
98  beamSpot = *beamSpotHandle;
99 
100  } else
101  {
102  edm::LogInfo("MuonSeedGenerator")
103  << "No beam spot available from EventSetup \n";
104  }
105 
106  // make it a vector so we can subtract it from position vectors
107  GlobalVector gv(beamSpot.x0(), beamSpot.y0(), beamSpot.z0());
109 
110  bool fwFitFailed = true;
111 
112  std::vector <SeedCandidate> seedCandidates_AllChosen;
113  std::vector< MuonRecHitContainer > MuonRecHitContainer_clusters;
114  //---- this is "clustering"; later a trajectory can not use hits from different clusters
115  thePatternRecognition->produce(event, eventSetup, MuonRecHitContainer_clusters);
116 
117  //std::cout<<"We have formed "<<MuonRecHitContainer_clusters.size()<<" clusters"<<std::endl;
118  //---- for each cluster,
119  for(unsigned int cluster = 0; cluster < MuonRecHitContainer_clusters.size(); ++cluster) {
120  //std::cout<<" This is cluster number : "<<cluster<<std::endl;
121  std::vector <SeedCandidate> seedCandidates_inCluster;
122  //---- group hits in detector layers (if in same layer); the idea is that
123  //---- some hits could not belong to a track simultaneously - these will be in a
124  //---- group; two hits from one and the same group will not go to the same track
125  std::vector< MuonRecHitContainer > MuonRecHitContainer_perLayer = theSeedFinder.sortByLayer(MuonRecHitContainer_clusters[cluster]);
126  //---- Add protection against huge memory consumption
127  //---- Delete busy layers if needed (due to combinatorics)
128  theSeedFinder.limitCombinatorics(MuonRecHitContainer_perLayer);
129  //---- build all possible combinations (valid sets)
130  std::vector <MuonRecHitContainer> allValidSets = theSeedFinder.findAllValidSets(MuonRecHitContainer_perLayer);
131  if(apply_prePruning){
132  //---- remove "wild" segments from the combination
133  theSeedFinder.validSetsPrePruning(allValidSets);
134  }
135 
136  //---- build the appropriate output: seedCandidates_inCluster
137  //---- if too many (?) valid sets in a cluster - skip it
138  if(allValidSets.size()<500){// hardcoded - remove it
139  seedCandidates_inCluster = theSeedFinder.fillSeedCandidates(allValidSets);
140  }
141  //---- find the best valid combinations using simple (no propagation errors) chi2-fit
142  //std::cout<<" Found "<<seedCandidates_inCluster.size()<<" valid sets in the current cluster."<<std::endl;
143  if(!seedCandidates_inCluster.empty()){
144  //---- this is the forward fitter (segments); choose which of the SETs in a cluster to be considered further
145  std::vector < SeedCandidate> bestSets_inCluster;
146  fwFitFailed = !(filter()->fwfit_SET(seedCandidates_inCluster, bestSets_inCluster));
147 
148  //---- has the fit failed? continue to the next cluster instead of returning the empty trajectoryContainer and stop the loop IBL 080903
149  if(fwFitFailed){
150  //std::cout<<" fwfit_SET failed!"<<std::endl;
151  continue;
152  }
153  for(unsigned int iSet = 0; iSet<bestSets_inCluster.size();++iSet){
154  seedCandidates_AllChosen.push_back(bestSets_inCluster[iSet]);
155  }
156  }
157  }
158  //---- loop over all the SETs candidates
159  for(unsigned int iMuon = 0;iMuon<seedCandidates_AllChosen.size();++iMuon){
160  //std::cout<<" chosen iMuon = "<<iMuon<<std::endl;
161  Trajectory::DataContainer finalCandidate;
162  SeedCandidate * aFinalSet = &(seedCandidates_AllChosen[iMuon]);
163  fwFitFailed = !(filter()->buildTrajectoryMeasurements(aFinalSet, finalCandidate));
164  if(fwFitFailed ){
165  //std::cout<<" buildTrajectoryMeasurements failed!"<<std::endl;
166  continue;
167  }
168  //---- are there measurements (or detLayers) used at all?
169  if( !filter()->layers().empty() )
170  LogTrace(metname) << debug.dumpLayer( filter()->lastDetLayer());
171  else {
172  continue;
173  }
174  //std::cout<<" chambers used - all : "<<filter()->getTotalChamberUsed()<<", DT : "<<filter()->getDTChamberUsed()<<
175  //", CSC : "<<filter()->getCSCChamberUsed()<<", RPC : "<<filter()->getRPCChamberUsed()<<std::endl;
176  //---- ask for some "reasonable" conditions to build a STA muon;
177  //---- (totalChambers >= 2, dtChambers + cscChambers >0)
178  if (filter()->goodState()) {
180  TrajectoryStateOnSurface firstTSOS;
181  bool conversionPassed = false;
183  //---- transforms set of segment measurements to a set of rechit measurements
184  conversionPassed = filter()->transform(finalCandidate, hitContainer, firstTSOS);
185  }
186  else{
187  //---- transforms set of segment measurements to a set of segment measurements
188  conversionPassed = filter()->transformLight(finalCandidate, hitContainer, firstTSOS);
189  }
190  if ( conversionPassed && !finalCandidate.empty() && !hitContainer.empty()) {
191  //---- doesn't work...
192  //output->push_back( theSeedFinder.makeSeed(firstTSOS, hitContainer) );
193 
194  edm::OwnVector<TrackingRecHit> recHitsContainer;
195  for(unsigned int iHit = 0;iHit < hitContainer.size();++iHit){
196  recHitsContainer.push_back(hitContainer.at(iHit)->hit()->clone());
197  }
200  dir = alongMomentum;// why forward (for rechits) later?
201  }
202 
203  PTrajectoryStateOnDet seedTSOS =
204  trajectoryStateTransform::persistentState( firstTSOS, hitContainer.at(0)->geographicalId().rawId());
205  TrajectorySeed seed(seedTSOS,recHitsContainer,dir);
206 
207  //MuonPatternRecoDumper debug;
208  //std::cout<<" firstTSOS (not IP) = "<<debug.dumpTSOS(firstTSOS)<<std::endl;
209  //std::cout<<" hits(from range) = "<<range.second-range.first<<" hits (from size) = "<<hitContainer.size()<<std::endl;
210  //for(unsigned int iRH=0;iRH<hitContainer.size();++iRH){
211  //std::cout<<" RH = "<<iRH+1<<" globPos = "<<hitContainer.at(iRH)->globalPosition()<<std::endl;
212  //}
213  output->push_back(seed);
214  }
215  else{
216  //std::cout<<" Transformation from TrajectoryMeasurements to RecHitContainer faild - skip "<<std::endl;
217  continue;
218  }
219  }else{
220  //std::cout<<" Not enough (as defined) measurements to build trajectory - skip"<<std::endl;
221  continue;
222  }
223  }
224  event.put(std::move(output));
225  theFilter->reset();
226 }
227 
228 //
230  theFilter->setEvent(event);
231 }
void setServiceProxy(MuonServiceProxy *service)
Definition: SETSeedFinder.h:32
SETSeedFinder theSeedFinder
void setBeamSpot(const GlobalVector &gv)
bool transform(Trajectory::DataContainer &measurements_segments, TransientTrackingRecHit::ConstRecHitContainer &hitContainer, TrajectoryStateOnSurface &firstTSOS)
transforms "segment trajectory" to "rechit container"
Definition: SETFilter.cc:169
T getParameter(std::string const &) const
double z0() const
z coordinate
Definition: BeamSpot.h:68
bool transformLight(Trajectory::DataContainer &measurements_segments, TransientTrackingRecHit::ConstRecHitContainer &hitContainer, TrajectoryStateOnSurface &firstTSOS)
transforms "segment trajectory" to "segment container"
Definition: SETFilter.cc:217
edm::EDGetTokenT< reco::BeamSpot > beamspotToken
std::string dumpLayer(const DetLayer *layer) const
const std::string metname
void reset()
Definition: SETFilter.cc:71
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
bool buildTrajectoryMeasurements(SeedCandidate *validSegmentsSet, Trajectory::DataContainer &finalCandidate)
from SeedCandidate to DataContainer only
Definition: SETFilter.cc:135
PropagationDirection
std::vector< MuonRecHitContainer > sortByLayer(MuonRecHitContainer &cluster) const
SETMuonSeedProducer(const edm::ParameterSet &)
Constructor with Parameter set.
std::vector< const DetLayer * > layers() const
return the layer used for the refit
Definition: SETFilter.h:104
void push_back(D *&d)
Definition: OwnVector.h:290
~SETMuonSeedProducer() override
Destructor.
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:44
bool fwfit_SET(std::vector< SeedCandidate > &validSegmentsSet_in, std::vector< SeedCandidate > &validSegmentsSet_out)
Perform the SET inner-outward fitting.
Definition: SETFilter.cc:100
edm::InputTag theBeamSpotTag
SETPatternRecognition * thePatternRecognition
void setServiceProxy(MuonServiceProxy *service)
bool isValid() const
Definition: HandleBase.h:74
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
void limitCombinatorics(std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
#define debug
Definition: HDRShower.cc:19
void setEvent(const edm::Event &)
void addUntrackedParameter(std::string const &name, T const &value)
Definition: ParameterSet.h:207
std::vector< MuonRecHitContainer > findAllValidSets(const std::vector< MuonRecHitContainer > &MuonRecHitContainer_perLayer)
MuonServiceProxy * theService
HLT enums.
void validSetsPrePruning(std::vector< MuonRecHitContainer > &allValidSets)
double y0() const
y coordinate
Definition: BeamSpot.h:66
dbl *** dir
Definition: mlp_gen.cc:35
std::vector< SeedCandidate > fillSeedCandidates(std::vector< MuonRecHitContainer > &allValidSets)
SETFilter * filter() const
pre-filter
void produce(edm::Event &, const edm::EventSetup &) override
void produce(const edm::Event &event, const edm::EventSetup &eSetup, std::vector< MuonRecHitContainer > &result) override
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
def move(src, dest)
Definition: eostools.py:511
virtual void setEvent(const edm::Event &event)
Pass the Event to the algo at each event.
Definition: SETFilter.cc:68
Definition: event.py:1
double x0() const
x coordinate
Definition: BeamSpot.h:64