CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
CtfSpecialSeedGenerator.cc
Go to the documentation of this file.
13 
14 using namespace ctfseeding;
15 
17  : conf_(conf),
18  theMFToken(esConsumes<edm::Transition::BeginRun>()),
19  theBuilderToken(
20  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", conf_.getParameter<std::string>("TTRHBuilder")))),
21  theTrackerToken(esConsumes<edm::Transition::BeginRun>()),
22  thePropAlongToken(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "PropagatorWithMaterial"))),
23  thePropOppositeToken(
24  esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "PropagatorWithMaterialOpposite"))),
25  theTopoToken(esConsumes()),
26  requireBOFF(conf.getParameter<bool>("requireBOFF")),
27  theMaxSeeds(conf.getParameter<int32_t>("maxSeeds")),
28  check(conf, consumesCollector())
29 
30 {
31  useScintillatorsConstraint = conf_.getParameter<bool>("UseScintillatorsConstraint");
32  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Constructing CtfSpecialSeedGenerator";
33  produces<TrajectorySeedCollection>();
34 
35  edm::ParameterSet regfactoryPSet = conf_.getParameter<edm::ParameterSet>("RegionFactoryPSet");
36  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
37  theRegionProducer = std::unique_ptr<TrackingRegionProducer>{
38  TrackingRegionProducerFactory::get()->create(regfactoryName, regfactoryPSet, consumesCollector())};
39 
40  std::vector<edm::ParameterSet> pSets = conf_.getParameter<std::vector<edm::ParameterSet>>("OrderedHitsFactoryPSets");
41  std::vector<edm::ParameterSet>::const_iterator iPSet;
42  edm::ConsumesCollector iC = consumesCollector();
43  for (iPSet = pSets.begin(); iPSet != pSets.end(); iPSet++) {
44  std::string hitsfactoryName = iPSet->getParameter<std::string>("ComponentName");
45  theGenerators.emplace_back(OrderedHitsGeneratorFactory::get()->create(hitsfactoryName, *iPSet, iC));
46  }
47 }
48 
50 
55 
56  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Initializing...";
58  edm::ParameterSet upperScintPar = conf_.getParameter<edm::ParameterSet>("UpperScintillatorParameters");
59  edm::ParameterSet lowerScintPar = conf_.getParameter<edm::ParameterSet>("LowerScintillatorParameters");
60  RectangularPlaneBounds upperBounds(
61  upperScintPar.getParameter<double>("WidthInX"), upperScintPar.getParameter<double>("LenghtInZ"), 1);
62  GlobalPoint upperPosition(upperScintPar.getParameter<double>("GlobalX"),
63  upperScintPar.getParameter<double>("GlobalY"),
64  upperScintPar.getParameter<double>("GlobalZ"));
65  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Upper Scintillator position x, y, z " << upperPosition.x() << ", "
66  << upperPosition.y() << ", " << upperPosition.z();
67  RectangularPlaneBounds lowerBounds(
68  lowerScintPar.getParameter<double>("WidthInX"), lowerScintPar.getParameter<double>("LenghtInZ"), 1);
69  GlobalPoint lowerPosition(lowerScintPar.getParameter<double>("GlobalX"),
70  lowerScintPar.getParameter<double>("GlobalY"),
71  lowerScintPar.getParameter<double>("GlobalZ"));
72  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Lower Scintillator position x, y, z " << lowerPosition.x() << ", "
73  << lowerPosition.y() << ", " << lowerPosition.z();
74  TkRotation<float> rot(1, 0, 0, 0, 0, 1, 0, 1, 0);
75  upperScintillator = BoundPlane::build(upperPosition, rot, &upperBounds);
76  lowerScintillator = BoundPlane::build(lowerPosition, rot, &lowerBounds);
77  }
78 
79  edm::ESHandle<Propagator> propagatorAlongHandle = iSetup.getHandle(thePropAlongToken);
80  edm::ESHandle<Propagator> propagatorOppositeHandle = iSetup.getHandle(thePropOppositeToken);
81 
82  std::vector<edm::ParameterSet> pSets = conf_.getParameter<std::vector<edm::ParameterSet>>("OrderedHitsFactoryPSets");
83  std::vector<edm::ParameterSet>::const_iterator iPSet;
84  for (iPSet = pSets.begin(); iPSet != pSets.end(); iPSet++) {
85  std::string propagationDirection = iPSet->getParameter<std::string>("PropagationDirection");
86  if (propagationDirection == "alongMomentum")
87  thePropDirs.push_back(alongMomentum);
88  else
90  std::string navigationDirection = iPSet->getParameter<std::string>("NavigationDirection");
91  if (navigationDirection == "insideOut")
92  theNavDirs.push_back(insideOut);
93  else
94  theNavDirs.push_back(outsideIn);
95  edm::LogVerbatim("CtfSpecialSeedGenerator") << "hitsGenerator done";
96  }
97  bool setMomentum = conf_.getParameter<bool>("SetMomentum");
98  std::vector<int> charges;
99  if (setMomentum) {
100  charges = conf_.getParameter<std::vector<int>>("Charges");
101  }
102  theSeedBuilder = std::make_unique<SeedFromGenericPairOrTriplet>(theMagfield.product(),
105  propagatorAlongHandle.product(),
106  propagatorOppositeHandle.product(),
107  charges,
108  setMomentum,
109  conf_.getParameter<double>("ErrorRescaling"));
110  double p = 1;
111  if (setMomentum) {
112  p = conf_.getParameter<double>("SeedMomentum");
113  theSeedBuilder->setMomentumTo(p);
114  }
115 }
116 
118  // get Inputs
119  auto output = std::make_unique<TrajectorySeedCollection>();
120 
121  //check on the number of clusters
122  if (!requireBOFF || (theMagfield->inTesla(GlobalPoint(0, 0, 0)).mag() == 0.00)) {
123  size_t clustsOrZero = check.tooManyClusters(e);
124  if (!clustsOrZero) {
125  bool ok = run(iSetup, e, *output);
126  if (!ok) {
127  } // nothing to do
128  } else
129  edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
130  }
131 
132  edm::LogVerbatim("CtfSpecialSeedGenerator") << " number of seeds = " << output->size();
133  e.put(std::move(output));
134 }
135 
137  const edm::Event& e,
139  std::vector<std::unique_ptr<TrackingRegion>> regions = theRegionProducer->regions(e, iSetup);
140  bool ok = true;
141  for (auto iReg = regions.begin(); iReg != regions.end(); iReg++) {
142  if (!theSeedBuilder->momentumFromPSet())
143  theSeedBuilder->setMomentumTo((*iReg)->ptMin());
144  int i = 0;
145  for (auto iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++) {
146  ok = buildSeeds(iSetup, e, (*iGen)->run(**iReg, e, iSetup), theNavDirs[i], thePropDirs[i], output);
147  i++;
148  if (!ok)
149  break;
150  }
151  if (!ok)
152  break;
153  }
154  return ok;
155 }
156 
158  const edm::Event& e,
159  const OrderedSeedingHits& osh,
160  const NavigationDirection& navdir,
161  const PropagationDirection& dir,
163  //SeedFromGenericPairOrTriplet seedBuilder(conf_, magfield.product(), tracker.product(), theBuilder.product());
164  edm::LogInfo("CtfSpecialSeedGenerator") << "osh.size() " << osh.size();
165  for (unsigned int i = 0; i < osh.size(); i++) {
166  const SeedingHitSet& shs = osh[i];
167  if (preliminaryCheck(shs, iSetup)) {
168  std::vector<TrajectorySeed*> seeds = theSeedBuilder->seed(shs, dir, navdir, iSetup);
169  for (std::vector<TrajectorySeed*>::const_iterator iSeed = seeds.begin(); iSeed != seeds.end(); iSeed++) {
170  if (!*iSeed) {
171  edm::LogError("CtfSpecialSeedGenerator") << "a seed pointer is null. skipping.";
172  continue;
173  }
174  if (postCheck(**iSeed)) {
175  output.push_back(**iSeed);
176  }
177  delete *iSeed;
178  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Seed built";
179  }
180  }
181  }
182  if ((theMaxSeeds > 0) && (output.size() > size_t(theMaxSeeds))) {
183  edm::LogWarning("TooManySeeds") << "Too many seeds (" << output.size() << "), bailing out.\n";
184  output.clear();
185  return false;
186  }
187  return true;
188 }
189 //checks the hits are on diffrent layers
192 
193  std::vector<std::pair<unsigned int, unsigned int>> vSubdetLayer;
194  //std::vector<std::string> vSeedLayerNames;
195  bool checkHitsAtPositiveY = conf_.getParameter<bool>("SeedsFromPositiveY");
196  //***top-bottom
197  bool checkHitsAtNegativeY = conf_.getParameter<bool>("SeedsFromNegativeY");
198  //***
199  bool checkHitsOnDifferentLayers = conf_.getParameter<bool>("CheckHitsAreOnDifferentLayers");
200  unsigned int nHits = shs.size();
201  for (unsigned int iHit = 0; iHit < nHits; ++iHit) {
202  //hits for the seeds must be at positive y
203  auto trh = shs[iHit];
204  auto recHit = trh;
205  GlobalPoint hitPos = recHit->globalPosition();
206  //GlobalPoint point =
207  // theTracker->idToDet(iHits->geographicalId() )->surface().toGlobal(iHits->localPosition());
208  if (checkHitsAtPositiveY) {
209  if (hitPos.y() < 0)
210  return false;
211  }
212  //***top-bottom
213  if (checkHitsAtNegativeY) {
214  if (hitPos.y() > 0)
215  return false;
216  }
217  //***
218  //std::string name = iHits->seedinglayer().name();
219  //hits for the seeds must be in different layers
220  unsigned int subid = (*trh).geographicalId().subdetId();
221  unsigned int layer = tTopo->layer((*trh).geographicalId());
222  std::vector<std::pair<unsigned int, unsigned int>>::const_iterator iter;
223  //std::vector<std::string>::const_iterator iNames;
224  if (checkHitsOnDifferentLayers) {
225  for (iter = vSubdetLayer.begin(); iter != vSubdetLayer.end(); iter++) {
226  if (iter->first == subid && iter->second == layer)
227  return false;
228  }
229  /*
230  for (iNames = vSeedLayerNames.begin(); iNames != vSeedLayerNames.end(); iNames++){
231  if (*iNames == name) return false;
232  }
233  */
234  }
235  //vSeedLayerNames.push_back(iHits->seedinglayer().name());
236  vSubdetLayer.push_back(std::make_pair(subid, layer));
237  }
238  return true;
239 }
240 
243  return true;
244 
245  PTrajectoryStateOnDet pstate = seed.startingState();
247  pstate, &(theTracker->idToDet(DetId(pstate.detId()))->surface()), &(*theMagfield));
248  const FreeTrajectoryState* state = theTSOS.freeState();
249  StraightLinePlaneCrossing planeCrossingLower(
251  StraightLinePlaneCrossing planeCrossingUpper(
253  std::pair<bool, StraightLinePlaneCrossing::PositionType> positionUpper =
254  planeCrossingUpper.position(*upperScintillator);
255  std::pair<bool, StraightLinePlaneCrossing::PositionType> positionLower =
256  planeCrossingLower.position(*lowerScintillator);
257  if (!(positionUpper.first && positionLower.first)) {
258  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection") << "Scintillator plane not crossed";
259  return false;
260  }
261  LocalPoint positionUpperLocal = upperScintillator->toLocal((GlobalPoint)(positionUpper.second));
262  LocalPoint positionLowerLocal = lowerScintillator->toLocal((GlobalPoint)(positionLower.second));
263  if (upperScintillator->bounds().inside(positionUpperLocal) &&
264  lowerScintillator->bounds().inside(positionLowerLocal)) {
265  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
266  << "position on Upper scintillator " << positionUpper.second;
267  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
268  << "position on Lower scintillator " << positionLower.second;
269 
270  return true;
271  }
272  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
273  << "scintillator not crossed in bounds: position on Upper scintillator " << positionUpper.second
274  << " position on Lower scintillator " << positionLower.second;
275  return false;
276 }
277 
280 
281  // Top-level parameters
282  desc.add<double>("SeedMomentum", 5.0);
283  desc.add<double>("ErrorRescaling", 50.0);
284  desc.add<bool>("UseScintillatorsConstraint", true);
285  desc.add<std::string>("TTRHBuilder", "WithTrackAngle");
286  desc.add<bool>("SeedsFromPositiveY", true);
287  desc.add<bool>("SeedsFromNegativeY", false);
288  desc.add<bool>("CheckHitsAreOnDifferentLayers", false);
289  desc.add<bool>("SetMomentum", true);
290  desc.add<bool>("requireBOFF", false);
291  desc.add<int32_t>("maxSeeds", 10000);
292 
293  // call the cluster checker to insert directly the configuration
295 
296  // Vector parameters
297  desc.add<std::vector<int>>("Charges", {-1});
298 
299  // RegionFactoryPSet (nested PSet)
300  {
301  edm::ParameterSetDescription ps_RegionFactoryPSet;
302  ps_RegionFactoryPSet.add<std::string>("ComponentName", "GlobalRegionProducer");
303 
304  edm::ParameterSetDescription ps_RegionPSet;
305  ps_RegionPSet.setAllowAnything();
306  ps_RegionFactoryPSet.add("RegionPSet", ps_RegionPSet)->setComment("");
307  desc.add<edm::ParameterSetDescription>("RegionFactoryPSet", ps_RegionFactoryPSet);
308  }
309 
310  // UpperScintillatorParameters (nested PSet)
311  {
312  edm::ParameterSetDescription ps_UpperScintillatorParameters;
313  ps_UpperScintillatorParameters.add<double>("LenghtInZ", 100.0);
314  ps_UpperScintillatorParameters.add<double>("GlobalX", 0.0);
315  ps_UpperScintillatorParameters.add<double>("GlobalY", 300.0);
316  ps_UpperScintillatorParameters.add<double>("GlobalZ", 50.0);
317  ps_UpperScintillatorParameters.add<double>("WidthInX", 100.0);
318  desc.add<edm::ParameterSetDescription>("UpperScintillatorParameters", ps_UpperScintillatorParameters);
319  }
320 
321  // LowerScintillatorParameters (nested PSet)
322  {
323  edm::ParameterSetDescription ps_LowerScintillatorParameters;
324  ps_LowerScintillatorParameters.add<double>("LenghtInZ", 100.0);
325  ps_LowerScintillatorParameters.add<double>("GlobalX", 0.0);
326  ps_LowerScintillatorParameters.add<double>("GlobalY", -100.0);
327  ps_LowerScintillatorParameters.add<double>("GlobalZ", 50.0);
328  ps_LowerScintillatorParameters.add<double>("WidthInX", 100.0);
329  desc.add<edm::ParameterSetDescription>("LowerScintillatorParameters", ps_LowerScintillatorParameters);
330  }
331 
332  // OrderedHitsFactoryPSets (VPSet)
333  {
334  edm::ParameterSetDescription ps_OrderedHitsFactoryPSet;
335  ps_OrderedHitsFactoryPSet.setAllowAnything();
336  std::vector<edm::ParameterSet> default_OrderedHitsFactoryPSet(1);
337 
338  // Add the VPSet (OrderedHitsFactoryPSets) to the top-level description
339  desc.addVPSet("OrderedHitsFactoryPSets", ps_OrderedHitsFactoryPSet, default_OrderedHitsFactoryPSet);
340  }
341 
342  // Add the top-level description to the descriptions
343  descriptions.addWithDefaultLabel(desc);
344 }
Log< level::Info, true > LogVerbatim
void setComment(std::string const &value)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
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:307
size_t tooManyClusters(const edm::Event &e) const
def create(alignables, pedeDump, additionalData, outputFile, config)
T z() const
Definition: PV3DBase.h:61
void setAllowAnything()
allow any parameter label/value pairs
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)
static void fillDescriptions(edm::ParameterSetDescription &description)
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
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
ParameterDescriptionBase * add(U const &iLabel, T const &value)
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
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.
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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