Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-11 16:23:16

0001 #include "RecoTracker/SpecialSeedGenerators/interface/CosmicSeedCreator.h"
0002 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0007 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0008 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitor.h"
0009 #include "RecoTracker/TkSeedingLayers/interface/SeedingHitSet.h"
0010 
0011 namespace {
0012   template <class T>
0013   inline T sqr(T t) {
0014     return t * t;
0015   }
0016 }  // namespace
0017 
0018 CosmicSeedCreator::CosmicSeedCreator(const edm::ParameterSet& extra, edm::ConsumesCollector&& iC)
0019     : magneticFieldESToken_(iC.esConsumes()), maxseeds_(extra.getParameter<int>("maxseeds")) {}
0020 
0021 void CosmicSeedCreator::init(const TrackingRegion& iregion, const edm::EventSetup& es, const SeedComparitor* ifilter) {
0022   region = &iregion;
0023   filter = ifilter;
0024   // mag field
0025   bfield = &es.getData(magneticFieldESToken_);
0026 }
0027 
0028 void CosmicSeedCreator::makeSeed(TrajectorySeedCollection& seedCollection, const SeedingHitSet& ordered) {
0029   //_________________________
0030   //
0031   //Get Parameters
0032   //________________________
0033 
0034   //hit package
0035   //+++++++++++
0036   const SeedingHitSet& hits = ordered;
0037   if (hits.size() < 2)
0038     return;
0039 
0040   //hits
0041   //++++
0042   SeedingHitSet::ConstRecHitPointer tth1 = hits[0];
0043   SeedingHitSet::ConstRecHitPointer tth2 = hits[1];
0044   assert(!trackerHitRTTI::isUndef(*tth1));
0045   assert(!trackerHitRTTI::isUndef(*tth2));
0046 
0047   SeedingHitSet::ConstRecHitPointer usedHit;
0048 
0049   //definition of position & momentum
0050   //++++++++++++++++++++++++++++++++++
0051   //direction of the trajectory seed given by the direction of the region
0052   GlobalVector initialMomentum(region->direction());
0053   //fix the momentum scale
0054   //initialMomentum = initialMomentum.basicVector.unitVector() * region->origin().direction().mag();
0055   //initialMomentum = region->origin().direction(); //alternative.
0056   LogDebug("CosmicSeedCreator") << "initial momentum = " << initialMomentum;
0057 
0058   //___________________________________________
0059   //
0060   //Direction of the trajectory seed
0061   //___________________________________________
0062 
0063   //radius
0064   //++++++
0065   bool reverseAll = false;
0066   if (fabs(tth1->globalPosition().perp()) < fabs(tth2->globalPosition().perp()))
0067   //comparison of the position of the 2 hits by checking/comparing their radius
0068   {
0069     usedHit = tth1;
0070     reverseAll = true;
0071   }
0072 
0073   else
0074     usedHit = tth2;
0075 
0076   //location in the barrel (up or bottom)
0077   //+++++++++++++++++++++++++++++++++++++
0078   //simple check, probably nees to be more precise FIXME
0079   bool bottomSeed = (usedHit->globalPosition().y() < 0);
0080 
0081   //apply corrections
0082   //+++++++++++++++++
0083   edm::OwnVector<TrackingRecHit> seedHits;
0084 
0085   if (reverseAll) {
0086     LogDebug("CosmicSeedCreator") << "Reverse all applied";
0087 
0088     seedHits.push_back(tth2->clone());
0089     seedHits.push_back(tth1->clone());
0090   }
0091 
0092   else {
0093     seedHits.push_back(tth1->clone());
0094     seedHits.push_back(tth2->clone());
0095   }
0096 
0097   //propagation
0098   //+++++++++++
0099 
0100   PropagationDirection seedDirection = alongMomentum;  //by default
0101 
0102   if (reverseAll)
0103     initialMomentum *= -1;
0104 
0105   if (bottomSeed) {
0106     //means that the seed parameters are inverse of what we want.
0107     //reverse the momentum again
0108     initialMomentum *= -1;
0109     //and change the direction of the seed
0110     seedDirection = oppositeToMomentum;
0111   }
0112 
0113   for (int charge = -1; charge <= 1; charge += 2) {
0114     //fixme, what hit do you want to use ?
0115 
0116     FreeTrajectoryState freeState(
0117         GlobalTrajectoryParameters(usedHit->globalPosition(), initialMomentum, charge, bfield),
0118         CurvilinearTrajectoryError(ROOT::Math::SMatrixIdentity()));
0119 
0120     LogDebug("CosmicSeedCreator") << "Position freeState: " << usedHit->globalPosition() << "\nCharge: " << charge
0121                                   << "\nInitial momentum :" << initialMomentum;
0122 
0123     TrajectoryStateOnSurface tsos(freeState, *usedHit->surface());
0124 
0125     PTrajectoryStateOnDet const& PTraj =
0126         trajectoryStateTransform::persistentState(tsos, usedHit->hit()->geographicalId().rawId());
0127     seedCollection.emplace_back(PTraj, seedHits, seedDirection);
0128 
0129   }  //end charge loop
0130 
0131   //________________
0132   //
0133   //Return seed
0134   //________________
0135 
0136   LogDebug("CosmicSeedCreator") << "Using SeedCreator---------->\n"
0137                                 << "seedCollections size = " << seedCollection.size();
0138 
0139   if (seedCollection.size() > maxseeds_) {
0140     edm::LogError("TooManySeeds") << "Found too many seeds (" << seedCollection.size() << " > " << maxseeds_
0141                                   << "), bailing out.\n";
0142     seedCollection.clear();
0143   }
0144 }