CMS 3D CMS Logo

CtfSpecialSeedGenerator.cc
Go to the documentation of this file.
6 
12 
15 
16 using namespace ctfseeding;
17 
19  : conf_(conf),
20  theMFToken(esConsumes<edm::Transition::BeginRun>()),
21  theBuilderToken(
22  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conf_.getParameter<std::string>("TTRHBuilder")))),
23  theTrackerToken(esConsumes<edm::Transition::BeginRun>()),
24  thePropAlongToken(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "PropagatorWithMaterial"))),
25  thePropOppositeToken(
26  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "PropagatorWithMaterialOpposite"))),
27  theTopoToken(esConsumes()),
28  requireBOFF(conf.getParameter<bool>("requireBOFF")),
29  theMaxSeeds(conf.getParameter<int32_t>("maxSeeds")),
30  check(conf, consumesCollector())
31 
32 {
33  useScintillatorsConstraint = conf_.getParameter<bool>("UseScintillatorsConstraint");
34  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Constructing CtfSpecialSeedGenerator";
35  produces<TrajectorySeedCollection>();
36 
37  edm::ParameterSet regfactoryPSet = conf_.getParameter<edm::ParameterSet>("RegionFactoryPSet");
38  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
39  theRegionProducer = std::unique_ptr<TrackingRegionProducer>{
40  TrackingRegionProducerFactory::get()->create(regfactoryName, regfactoryPSet, consumesCollector())};
41 
42  std::vector<edm::ParameterSet> pSets = conf_.getParameter<std::vector<edm::ParameterSet>>("OrderedHitsFactoryPSets");
43  std::vector<edm::ParameterSet>::const_iterator iPSet;
44  edm::ConsumesCollector iC = consumesCollector();
45  for (iPSet = pSets.begin(); iPSet != pSets.end(); iPSet++) {
46  std::string hitsfactoryName = iPSet->getParameter<std::string>("ComponentName");
47  theGenerators.emplace_back(OrderedHitsGeneratorFactory::get()->create(hitsfactoryName, *iPSet, iC));
48  }
49 }
50 
52 
54 
59 
60  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Initializing...";
62  edm::ParameterSet upperScintPar = conf_.getParameter<edm::ParameterSet>("UpperScintillatorParameters");
63  edm::ParameterSet lowerScintPar = conf_.getParameter<edm::ParameterSet>("LowerScintillatorParameters");
64  RectangularPlaneBounds upperBounds(
65  upperScintPar.getParameter<double>("WidthInX"), upperScintPar.getParameter<double>("LenghtInZ"), 1);
66  GlobalPoint upperPosition(upperScintPar.getParameter<double>("GlobalX"),
67  upperScintPar.getParameter<double>("GlobalY"),
68  upperScintPar.getParameter<double>("GlobalZ"));
69  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Upper Scintillator position x, y, z " << upperPosition.x() << ", "
70  << upperPosition.y() << ", " << upperPosition.z();
71  RectangularPlaneBounds lowerBounds(
72  lowerScintPar.getParameter<double>("WidthInX"), lowerScintPar.getParameter<double>("LenghtInZ"), 1);
73  GlobalPoint lowerPosition(lowerScintPar.getParameter<double>("GlobalX"),
74  lowerScintPar.getParameter<double>("GlobalY"),
75  lowerScintPar.getParameter<double>("GlobalZ"));
76  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Lower Scintillator position x, y, z " << lowerPosition.x() << ", "
77  << lowerPosition.y() << ", " << lowerPosition.z();
78  TkRotation<float> rot(1, 0, 0, 0, 0, 1, 0, 1, 0);
79  upperScintillator = BoundPlane::build(upperPosition, rot, &upperBounds);
80  lowerScintillator = BoundPlane::build(lowerPosition, rot, &lowerBounds);
81  }
82 
83  edm::ESHandle<Propagator> propagatorAlongHandle = iSetup.getHandle(thePropAlongToken);
84  edm::ESHandle<Propagator> propagatorOppositeHandle = iSetup.getHandle(thePropOppositeToken);
85 
86  std::vector<edm::ParameterSet> pSets = conf_.getParameter<std::vector<edm::ParameterSet>>("OrderedHitsFactoryPSets");
87  std::vector<edm::ParameterSet>::const_iterator iPSet;
88  for (iPSet = pSets.begin(); iPSet != pSets.end(); iPSet++) {
89  std::string propagationDirection = iPSet->getParameter<std::string>("PropagationDirection");
90  if (propagationDirection == "alongMomentum")
91  thePropDirs.push_back(alongMomentum);
92  else
94  std::string navigationDirection = iPSet->getParameter<std::string>("NavigationDirection");
95  if (navigationDirection == "insideOut")
96  theNavDirs.push_back(insideOut);
97  else
98  theNavDirs.push_back(outsideIn);
99  edm::LogVerbatim("CtfSpecialSeedGenerator") << "hitsGenerator done";
100  }
101  bool setMomentum = conf_.getParameter<bool>("SetMomentum");
102  std::vector<int> charges;
103  if (setMomentum) {
104  charges = conf_.getParameter<std::vector<int>>("Charges");
105  }
106  theSeedBuilder = std::make_unique<SeedFromGenericPairOrTriplet>(theMagfield.product(),
109  propagatorAlongHandle.product(),
110  propagatorOppositeHandle.product(),
111  charges,
112  setMomentum,
113  conf_.getParameter<double>("ErrorRescaling"));
114  double p = 1;
115  if (setMomentum) {
116  p = conf_.getParameter<double>("SeedMomentum");
117  theSeedBuilder->setMomentumTo(p);
118  }
119 }
120 
122  // get Inputs
123  auto output = std::make_unique<TrajectorySeedCollection>();
124 
125  //check on the number of clusters
126  if (!requireBOFF || (theMagfield->inTesla(GlobalPoint(0, 0, 0)).mag() == 0.00)) {
127  size_t clustsOrZero = check.tooManyClusters(e);
128  if (!clustsOrZero) {
129  bool ok = run(iSetup, e, *output);
130  if (!ok) {
131  } // nothing to do
132  } else
133  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
134  }
135 
136  edm::LogVerbatim("CtfSpecialSeedGenerator") << " number of seeds = " << output->size();
137  e.put(std::move(output));
138 }
139 
141  const edm::Event& e,
143  std::vector<std::unique_ptr<TrackingRegion>> regions = theRegionProducer->regions(e, iSetup);
144  bool ok = true;
145  for (auto iReg = regions.begin(); iReg != regions.end(); iReg++) {
146  if (!theSeedBuilder->momentumFromPSet())
147  theSeedBuilder->setMomentumTo((*iReg)->ptMin());
148  int i = 0;
149  for (auto iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++) {
150  ok = buildSeeds(iSetup, e, (*iGen)->run(**iReg, e, iSetup), theNavDirs[i], thePropDirs[i], output);
151  i++;
152  if (!ok)
153  break;
154  }
155  if (!ok)
156  break;
157  }
158  return ok;
159 }
160 
162  const edm::Event& e,
163  const OrderedSeedingHits& osh,
164  const NavigationDirection& navdir,
165  const PropagationDirection& dir,
167  //SeedFromGenericPairOrTriplet seedBuilder(conf_, magfield.product(), tracker.product(), theBuilder.product());
168  edm::LogInfo("CtfSpecialSeedGenerator") << "osh.size() " << osh.size();
169  for (unsigned int i = 0; i < osh.size(); i++) {
170  const SeedingHitSet& shs = osh[i];
171  if (preliminaryCheck(shs, iSetup)) {
172  std::vector<TrajectorySeed*> seeds = theSeedBuilder->seed(shs, dir, navdir, iSetup);
173  for (std::vector<TrajectorySeed*>::const_iterator iSeed = seeds.begin(); iSeed != seeds.end(); iSeed++) {
174  if (!*iSeed) {
175  edm::LogError("CtfSpecialSeedGenerator") << "a seed pointer is null. skipping.";
176  continue;
177  }
178  if (postCheck(**iSeed)) {
179  output.push_back(**iSeed);
180  }
181  delete *iSeed;
182  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Seed built";
183  }
184  }
185  }
186  if ((theMaxSeeds > 0) && (output.size() > size_t(theMaxSeeds))) {
187  edm::LogWarning("TooManySeeds") << "Too many seeds (" << output.size() << "), bailing out.\n";
188  output.clear();
189  return false;
190  }
191  return true;
192 }
193 //checks the hits are on diffrent layers
196 
197  std::vector<std::pair<unsigned int, unsigned int>> vSubdetLayer;
198  //std::vector<std::string> vSeedLayerNames;
199  bool checkHitsAtPositiveY = conf_.getParameter<bool>("SeedsFromPositiveY");
200  //***top-bottom
201  bool checkHitsAtNegativeY = conf_.getParameter<bool>("SeedsFromNegativeY");
202  //***
203  bool checkHitsOnDifferentLayers = conf_.getParameter<bool>("CheckHitsAreOnDifferentLayers");
204  unsigned int nHits = shs.size();
205  for (unsigned int iHit = 0; iHit < nHits; ++iHit) {
206  //hits for the seeds must be at positive y
207  auto trh = shs[iHit];
208  auto recHit = trh;
209  GlobalPoint hitPos = recHit->globalPosition();
210  //GlobalPoint point =
211  // theTracker->idToDet(iHits->geographicalId() )->surface().toGlobal(iHits->localPosition());
212  if (checkHitsAtPositiveY) {
213  if (hitPos.y() < 0)
214  return false;
215  }
216  //***top-bottom
217  if (checkHitsAtNegativeY) {
218  if (hitPos.y() > 0)
219  return false;
220  }
221  //***
222  //std::string name = iHits->seedinglayer().name();
223  //hits for the seeds must be in different layers
224  unsigned int subid = (*trh).geographicalId().subdetId();
225  unsigned int layer = tTopo->layer((*trh).geographicalId());
226  std::vector<std::pair<unsigned int, unsigned int>>::const_iterator iter;
227  //std::vector<std::string>::const_iterator iNames;
228  if (checkHitsOnDifferentLayers) {
229  for (iter = vSubdetLayer.begin(); iter != vSubdetLayer.end(); iter++) {
230  if (iter->first == subid && iter->second == layer)
231  return false;
232  }
233  /*
234  for (iNames = vSeedLayerNames.begin(); iNames != vSeedLayerNames.end(); iNames++){
235  if (*iNames == name) return false;
236  }
237  */
238  }
239  //vSeedLayerNames.push_back(iHits->seedinglayer().name());
240  vSubdetLayer.push_back(std::make_pair(subid, layer));
241  }
242  return true;
243 }
244 
247  return true;
248 
249  PTrajectoryStateOnDet pstate = seed.startingState();
251  pstate, &(theTracker->idToDet(DetId(pstate.detId()))->surface()), &(*theMagfield));
252  const FreeTrajectoryState* state = theTSOS.freeState();
253  StraightLinePlaneCrossing planeCrossingLower(
255  StraightLinePlaneCrossing planeCrossingUpper(
257  std::pair<bool, StraightLinePlaneCrossing::PositionType> positionUpper =
258  planeCrossingUpper.position(*upperScintillator);
259  std::pair<bool, StraightLinePlaneCrossing::PositionType> positionLower =
260  planeCrossingLower.position(*lowerScintillator);
261  if (!(positionUpper.first && positionLower.first)) {
262  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection") << "Scintillator plane not crossed";
263  return false;
264  }
265  LocalPoint positionUpperLocal = upperScintillator->toLocal((GlobalPoint)(positionUpper.second));
266  LocalPoint positionLowerLocal = lowerScintillator->toLocal((GlobalPoint)(positionLower.second));
267  if (upperScintillator->bounds().inside(positionUpperLocal) &&
268  lowerScintillator->bounds().inside(positionLowerLocal)) {
269  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
270  << "position on Upper scintillator " << positionUpper.second;
271  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
272  << "position on Lower scintillator " << positionLower.second;
273 
274  return true;
275  }
276  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
277  << "scintillator not crossed in bounds: position on Upper scintillator " << positionUpper.second
278  << " position on Lower scintillator " << positionLower.second;
279  return false;
280 }
Log< level::Info, true > LogVerbatim
std::unique_ptr< SeedFromGenericPairOrTriplet > theSeedBuilder
std::unique_ptr< TrackingRegionProducer > theRegionProducer
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
size_t tooManyClusters(const edm::Event &e) const
def create(alignables, pedeDump, additionalData, outputFile, config)
T z() const
Definition: PV3DBase.h:61
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
BoundPlane::BoundPlanePointer lowerScintillator
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > theBuilderToken
virtual unsigned int size() const =0
bool run(const edm::EventSetup &c, const edm::Event &e, TrajectorySeedCollection &output)
PropagationDirection
Log< level::Error, false > LogError
bool buildSeeds(const edm::EventSetup &iSetup, const edm::Event &e, const OrderedSeedingHits &osh, const NavigationDirection &navdir, const PropagationDirection &dir, TrajectorySeedCollection &output)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropOppositeToken
CtfSpecialSeedGenerator(const edm::ParameterSet &conf)
unsigned int detId() const
unsigned int layer(const DetId &id) const
constexpr std::array< uint8_t, layerIndexSize< TrackerTraits > > layer
BoundPlane::BoundPlanePointer upperScintillator
T x() const
Definition: PV3DBase.h:59
T y() const
Definition: PV3DBase.h:60
T const * product() const
Definition: ESHandle.h:86
std::vector< TrajectorySeed > TrajectorySeedCollection
T mag() const
Definition: PV3DBase.h:64
unsigned int size() const
Definition: SeedingHitSet.h:52
Transition
Definition: Transition.h:12
PositionType position(float s) const
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
const TrackerGeomDet * idToDet(DetId) const override
Log< level::Info, false > LogInfo
bool preliminaryCheck(const SeedingHitSet &shs, const edm::EventSetup &es)
Definition: DetId.h:17
~CtfSpecialSeedGenerator() override
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
bool postCheck(const TrajectorySeed &seed)
const edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropAlongToken
void produce(edm::Event &e, const edm::EventSetup &c) override
void beginRun(edm::Run const &, edm::EventSetup const &) override
edm::ESHandle< MagneticField > theMagfield
const edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > theTrackerToken
HLT enums.
edm::ESHandle< TrackerGeometry > theTracker
FreeTrajectoryState const * freeState(bool withErrors=true) const
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
Definition: output.py:1
charges
only generated particles of these IDs are considered
#define get
Log< level::Warning, false > LogWarning
TupleMultiplicity< TrackerTraits > const *__restrict__ uint32_t nHits
void endRun(edm::Run const &, edm::EventSetup const &) override
std::vector< NavigationDirection > theNavDirs
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > theTopoToken
std::vector< std::unique_ptr< OrderedHitsGenerator > > theGenerators
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > theMFToken
std::vector< PropagationDirection > thePropDirs
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45