Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:17

0001 /** \class DirectMuonTrajectoryBuilder
0002  *  Class which takes a trajectory seed and fit its hits, returning a Trajectory container
0003  *
0004  *  \author
0005  */
0006 
0007 #include "RecoMuon/TrackingTools/interface/DirectMuonTrajectoryBuilder.h"
0008 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0009 
0010 #include "TrackingTools/TrackRefitter/interface/SeedTransformer.h"
0011 
0012 #include "FWCore/Framework/interface/ConsumesCollector.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 
0016 using namespace edm;
0017 using namespace std;
0018 
0019 DirectMuonTrajectoryBuilder::DirectMuonTrajectoryBuilder(const ParameterSet& par,
0020                                                          const MuonServiceProxy* service,
0021                                                          ConsumesCollector iC)
0022     : theService(service) {
0023   // The seed transformer (used to refit the seed and get the seed transient state)
0024   //  ParameterSet seedTransformerPSet = par.getParameter<ParameterSet>("SeedTransformerParameters");
0025   ParameterSet seedTransformerParameters = par.getParameter<ParameterSet>("SeedTransformerParameters");
0026   theSeedTransformer = new SeedTransformer(seedTransformerParameters, iC);
0027 }
0028 
0029 DirectMuonTrajectoryBuilder::~DirectMuonTrajectoryBuilder() {
0030   LogTrace("Muon|RecoMuon|DirectMuonTrajectoryBuilder") << "DirectMuonTrajectoryBuilder destructor called" << endl;
0031 
0032   if (theSeedTransformer)
0033     delete theSeedTransformer;
0034 }
0035 
0036 MuonTrajectoryBuilder::TrajectoryContainer DirectMuonTrajectoryBuilder::trajectories(const TrajectorySeed& seed) {
0037   // Set the services for the seed transformer
0038   theSeedTransformer->setServices(theService->eventSetup());
0039 
0040   const string metname = "Muon|RecoMuon|DirectMuonTrajectoryBuilder";
0041 
0042   MuonTrajectoryBuilder::TrajectoryContainer trajectoryContainer;
0043 
0044   vector<Trajectory> seedTrajectories = theSeedTransformer->seedTransform(seed);
0045 
0046   if (!seedTrajectories.empty())
0047     for (vector<Trajectory>::const_iterator trajectory = seedTrajectories.begin(); trajectory != seedTrajectories.end();
0048          ++trajectory)
0049       trajectoryContainer.push_back(std::make_unique<Trajectory>(*trajectory));
0050   else
0051     LogTrace(metname) << "Seed not refitted";
0052 
0053   return trajectoryContainer;
0054 
0055   // std::pair<bool, Trajectory>
0056   // SETFilter::bwfit_SET(const TrajectorySeed &trajectorySeed  ,
0057   //                  const TransientTrackingRecHit::ConstRecHitContainer & trajRH,
0058   //                  const TrajectoryStateOnSurface & firstTsos) {
0059   //   // get the actual fitter - Kalman fit
0060   //   theService->eventSetup().get<TrajectoryFitter::Record>().get(theBWLightFitterName, theBWLightFitter);
0061   //   vector<Trajectory> refitted;
0062   //   Trajectory trajectory;
0063   //   // the actual Kalman Fit
0064   //   refitted = theBWLightFitter->fit(trajectorySeed, trajRH, firstTsos);
0065   //   if(!refitted.empty()){
0066   //     // under tests...
0067   //     bool applyPruning = false;
0068   //     if(applyPruning){
0069   //       double previousTheta = trajRH[0]->globalPosition().theta();
0070   //       double previousWeight = 0.;
0071   //       std::vector <double> weights(trajRH.size());
0072   //       std::vector <double> weight_diff(trajRH.size());
0073   //       for(unsigned int iRH = 0; iRH<trajRH.size();++iRH){
0074   //    double weight = trajRH[iRH]->globalPosition().theta() - previousTheta;
0075   //    weights.at(iRH)= weight;
0076   //    double weightDiff = weight + previousWeight;
0077   //    weight_diff.at(iRH) = weightDiff;
0078   //    std::cout<<" iRH = "<<iRH<<" globPos"<< trajRH[iRH]->globalPosition()<<" weight = "<<weight<<" weightDiff = "<<weightDiff<<std::endl;
0079   //    previousTheta = trajRH[iRH]->globalPosition().theta();
0080   //    previousWeight = weight;
0081 
0082   //       }
0083   //       Trajectory::DataContainer measurements_segments = refitted.front().measurements();
0084   //       if(measurements_segments.size() != trajRH.size()){
0085   //    std::cout<<" measurements_segments.size() = "<<measurements_segments.size()<<
0086   //      " trajRH.size() = "<<trajRH.size()<<std::endl;
0087   //    std::cout<<" THIS IS NOT SUPPOSED TO HAPPEN! CHECK THE CODE (pruning)"<<std::endl;
0088   //       }
0089   //       std::vector <int> badHits;
0090   //       TransientTrackingRecHit::ConstRecHitContainer trajRH_pruned;
0091   //       for(unsigned int iMeas = 0; iMeas<measurements_segments.size();++iMeas){
0092   //    // we have to apply pruning on the base of intermed. chi2 of measurements
0093   //    // and then refit again!
0094   //    std::cout<<" after refitter : iMeas = "<<iMeas<<"  estimate() = "<< measurements_segments[iMeas].estimate()<<
0095   //      " globPos = "<< measurements_segments[iMeas].recHit()->globalPosition()<<std::endl;
0096   //    //const TransientTrackingRecHit::ConstRecHitContainer trajRH_pruned;
0097   //    bool pruningCondition = fabs(weights[iMeas])>0.0011 && fabs(weight_diff[iMeas])>0.0011;
0098   //    std::cout<<" weights[iMeas] = "<<weights[iMeas]<<" weight_diff[iMeas] = "<<weight_diff[iMeas]<<" pruningCondition = "<<pruningCondition<<std::endl;
0099   //    //bool pruningCondition = (measurements_segments[iMeas].estimate()>50);
0100   //    if(iMeas && pruningCondition && measurements_segments.size() == trajRH.size()){// first is kept for technical reasons (for now)
0101   //      badHits.push_back(iMeas);
0102   //    }
0103   //    else{
0104   //      trajRH_pruned.push_back(trajRH[iMeas]);
0105   //    }
0106   //       }
0107   //       if(float(measurements_segments.size())/float(badHits.size()) >0.5 &&
0108   //     measurements_segments.size() - badHits.size() > 6){
0109   //    std::cout<<" this is pruning ; badHits.size() = "<<badHits.size()<<std::endl;
0110   //    refitted = theBWLightFitter->fit(trajectorySeed, trajRH_pruned, firstTsos);
0111   //       }
0112   //     }
0113   //     std::pair<bool, Trajectory> refitResult = make_pair(true,refitted.front());
0114   //     //return RefitResult(true,refitted.front());
0115   //     return refitResult;
0116   //   }
0117   //   else{
0118   //     //    std::cout<<" refitted.empty() = "<<refitted.empty()<<std::endl;
0119   //     std::pair<bool, Trajectory> refitResult = make_pair(false,trajectory);
0120   //     //return RefitResult(false,trajectory);
0121   //     return refitResult;
0122   //   }
0123 }
0124 
0125 MuonTrajectoryBuilder::CandidateContainer DirectMuonTrajectoryBuilder::trajectories(const TrackCand&) {
0126   return MuonTrajectoryBuilder::CandidateContainer();
0127 }
0128 
0129 void DirectMuonTrajectoryBuilder::setEvent(const edm::Event& event) {}