CMS 3D CMS Logo

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