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