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.
2 //#include "RecoTracker/SpecialSeedGenerators/interface/CosmicLayerTriplets.h"
7 
13 
16 
17 using namespace ctfseeding;
18 
20  conf_(conf),
21  requireBOFF(conf.getParameter<bool>("requireBOFF")),
22  theMaxSeeds(conf.getParameter<int32_t>("maxSeeds")),
23  check(conf,consumesCollector())
24 
25 {
26  useScintillatorsConstraint = conf_.getParameter<bool>("UseScintillatorsConstraint");
27  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Constructing CtfSpecialSeedGenerator";
28  produces<TrajectorySeedCollection>();
29  theSeedBuilder =0;
31 
32  edm::ParameterSet regfactoryPSet = conf_.getParameter<edm::ParameterSet>("RegionFactoryPSet");
33  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
34  theRegionProducer = TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet, consumesCollector());
35 
36  std::vector<edm::ParameterSet> pSets = conf_.getParameter<std::vector<edm::ParameterSet> >("OrderedHitsFactoryPSets");
37  std::vector<edm::ParameterSet>::const_iterator iPSet;
39  for (iPSet = pSets.begin(); iPSet != pSets.end(); iPSet++){
40  std::string hitsfactoryName = iPSet->getParameter<std::string>("ComponentName");
41  theGenerators.emplace_back(OrderedHitsGeneratorFactory::get()->create( hitsfactoryName, *iPSet, iC));
42  }
43 }
44 
46 }
47 
49  if (theSeedBuilder) { delete theSeedBuilder; theSeedBuilder = 0; }
51 }
52 
54  std::string builderName = conf_.getParameter<std::string>("TTRHBuilder");
55  iSetup.get<TransientRecHitRecord>().get(builderName,theBuilder);
56 
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(upperScintPar.getParameter<double>("WidthInX"),
65  upperScintPar.getParameter<double>("LenghtInZ"),
66  1);
67  GlobalPoint upperPosition(upperScintPar.getParameter<double>("GlobalX"),
68  upperScintPar.getParameter<double>("GlobalY"),
69  upperScintPar.getParameter<double>("GlobalZ"));
70  edm::LogVerbatim("CtfSpecialSeedGenerator")
71  << "Upper Scintillator position x, y, z " << upperPosition.x()
72  << ", " << upperPosition.y() << ", " << upperPosition.z();
73  RectangularPlaneBounds lowerBounds(lowerScintPar.getParameter<double>("WidthInX"),
74  lowerScintPar.getParameter<double>("LenghtInZ"),
75  1);
76  GlobalPoint lowerPosition(lowerScintPar.getParameter<double>("GlobalX"),
77  lowerScintPar.getParameter<double>("GlobalY"),
78  lowerScintPar.getParameter<double>("GlobalZ"));
79  edm::LogVerbatim("CtfSpecialSeedGenerator")
80  << "Lower Scintillator position x, y, z " << lowerPosition.x()
81  << ", " << lowerPosition.y() << ", " << lowerPosition.z() ;
82  TkRotation<float> rot(1,0,0,0,0,1,0,1,0);
83  upperScintillator = BoundPlane::build(upperPosition, rot, &upperBounds);
84  lowerScintillator = BoundPlane::build(lowerPosition, rot, &lowerBounds);
85  }
86 
87  edm::ESHandle<Propagator> propagatorAlongHandle;
88  iSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",propagatorAlongHandle);
89  edm::ESHandle<Propagator> propagatorOppositeHandle;
90  iSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterialOpposite",propagatorOppositeHandle);
91 
92 /* edm::ParameterSet hitsfactoryOutInPSet = conf_.getParameter<edm::ParameterSet>("OrderedHitsFactoryOutInPSet");
93  std::string hitsfactoryOutInName = hitsfactoryOutInPSet.getParameter<std::string>("ComponentName");
94  hitsGeneratorOutIn = OrderedHitsGeneratorFactory::get()->create( hitsfactoryOutInName, hitsfactoryOutInPSet);
95  std::string propagationDirection = hitsfactoryOutInPSet.getUntrackedParameter<std::string>("PropagationDirection",
96  "alongMomentum");
97  if (propagationDirection == "alongMomentum") outInPropagationDirection = alongMomentum;
98  else outInPropagationDirection = oppositeToMomentum;
99  edm::LogVerbatim("CtfSpecialSeedGenerator") << "hitsGeneratorOutIn done";
100 
101  edm::ParameterSet hitsfactoryInOutPSet = conf_.getParameter<edm::ParameterSet>("OrderedHitsFactoryInOutPSet");
102  std::string hitsfactoryInOutName = hitsfactoryInOutPSet.getParameter<std::string>("ComponentName");
103  hitsGeneratorInOut = OrderedHitsGeneratorFactory::get()->create( hitsfactoryInOutName, hitsfactoryInOutPSet);
104 
105  propagationDirection = hitsfactoryInOutPSet.getUntrackedParameter<std::string>("PropagationDirection",
106  "alongMomentum");
107  if (propagationDirection == "alongMomentum") inOutPropagationDirection = alongMomentum;
108  else inOutPropagationDirection = oppositeToMomentum;
109  edm::LogVerbatim("CtfSpecialSeedGenerator") << "hitsGeneratorInOut done";
110  if (!hitsGeneratorOutIn || !hitsGeneratorInOut)
111  throw cms::Exception("CtfSpecialSeedGenerator") << "Only corcrete implementation GenericPairOrTripletGenerator of OrderedHitsGenerator is allowed ";
112 */
113  std::vector<edm::ParameterSet> pSets = conf_.getParameter<std::vector<edm::ParameterSet> >("OrderedHitsFactoryPSets");
114  std::vector<edm::ParameterSet>::const_iterator iPSet;
115  for (iPSet = pSets.begin(); iPSet != pSets.end(); iPSet++){
116  std::string propagationDirection = iPSet->getParameter<std::string>("PropagationDirection");
117  if (propagationDirection == "alongMomentum") thePropDirs.push_back(alongMomentum);
118  else thePropDirs.push_back(oppositeToMomentum);
119  std::string navigationDirection = iPSet->getParameter<std::string>("NavigationDirection");
120  if (navigationDirection == "insideOut") theNavDirs.push_back(insideOut);
121  else theNavDirs.push_back(outsideIn);
122  edm::LogVerbatim("CtfSpecialSeedGenerator") << "hitsGenerator done";
123  }
124  bool setMomentum = conf_.getParameter<bool>("SetMomentum");
125  std::vector<int> charges;
126  if (setMomentum){
127  charges = conf_.getParameter<std::vector<int> >("Charges");
128  }
130  theTracker.product(),
132  propagatorAlongHandle.product(),
133  propagatorOppositeHandle.product(),
134  charges,
135  setMomentum,
136  conf_.getParameter<double>("ErrorRescaling"));
137  double p = 1;
138  if (setMomentum) {
139  p = conf_.getParameter<double>("SeedMomentum");
141  }
142 
143 }
144 
146 {
147  // get Inputs
148  std::auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection);
149 
150  //check on the number of clusters
151  if ( !requireBOFF || (theMagfield->inTesla(GlobalPoint(0,0,0)).mag() == 0.00) ) {
152  size_t clustsOrZero = check.tooManyClusters(e);
153  if (!clustsOrZero){
154  bool ok = run(iSetup, e, *output);
155  if (!ok) { ; } // nothing to do
156  } else edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
157  }
158 
159 
160  edm::LogVerbatim("CtfSpecialSeedGenerator") << " number of seeds = "<< output->size();
161  e.put(output);
162 }
163 
165  const edm::Event& e,
167  std::vector<TrackingRegion*> regions = theRegionProducer->regions(e, iSetup);
168  std::vector<TrackingRegion*>::const_iterator iReg;
169  bool ok = true;
170  for (iReg = regions.begin(); iReg != regions.end(); iReg++){
171  if(!theSeedBuilder->momentumFromPSet()) theSeedBuilder->setMomentumTo((*iReg)->ptMin());
172  int i = 0;
173  for (auto iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++){
174  ok = buildSeeds(iSetup,
175  e,
176  (*iGen)->run(**iReg, e, iSetup),
177  theNavDirs[i],
178  thePropDirs[i],
179  output);
180  i++;
181  if (!ok) break;
182  }
183  if (!ok) break;
184  }
185  //clear memory
186  for (std::vector<TrackingRegion*>::iterator iReg = regions.begin(); iReg != regions.end(); iReg++){
187  delete *iReg;
188  }
189  return ok;
190 }
191 
193  const edm::Event& e,
194  const OrderedSeedingHits& osh,
195  const NavigationDirection& navdir,
196  const PropagationDirection& dir,
198  //SeedFromGenericPairOrTriplet seedBuilder(conf_, magfield.product(), tracker.product(), theBuilder.product());
199  edm::LogInfo("CtfSpecialSeedGenerator")<<"osh.size() " << osh.size();
200  for (unsigned int i = 0; i < osh.size(); i++){
201  SeedingHitSet shs = osh[i];
202  if (preliminaryCheck(shs,iSetup)){
203  std::vector<TrajectorySeed*> seeds = theSeedBuilder->seed(shs,
204  dir,
205  navdir,
206  iSetup);
207  for (std::vector<TrajectorySeed*>::const_iterator iSeed = seeds.begin(); iSeed != seeds.end(); iSeed++){
208  if (!*iSeed) {edm::LogError("CtfSpecialSeedGenerator")<<"a seed pointer is null. skipping.";continue;}
209  if (postCheck(**iSeed)){
210  output.push_back(**iSeed);
211  }
212  delete *iSeed;
213  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Seed built";
214  }
215  }
216  }
217  if ((theMaxSeeds > 0) && (output.size() > size_t(theMaxSeeds))) {
218  edm::LogWarning("TooManySeeds") << "Too many seeds ("<< output.size() <<"), bailing out.\n";
219  output.clear();
220  return false;
221  }
222  return true;
223 }
224 //checks the hits are on diffrent layers
226 
228  es.get<IdealGeometryRecord>().get(tTopo);
229 
230  std::vector<std::pair<unsigned int, unsigned int> > vSubdetLayer;
231  //std::vector<std::string> vSeedLayerNames;
232  bool checkHitsAtPositiveY = conf_.getParameter<bool>("SeedsFromPositiveY");
233  //***top-bottom
234  bool checkHitsAtNegativeY = conf_.getParameter<bool>("SeedsFromNegativeY");
235  //***
236  bool checkHitsOnDifferentLayers = conf_.getParameter<bool>("CheckHitsAreOnDifferentLayers");
237  unsigned int nHits = shs.size();
238  for (unsigned int iHit=0; iHit < nHits; ++iHit) {
239  //hits for the seeds must be at positive y
240  const TrackingRecHit * trh = shs[iHit]->hit();
242  GlobalPoint hitPos = recHit->globalPosition();
243  //GlobalPoint point =
244  // theTracker->idToDet(iHits->geographicalId() )->surface().toGlobal(iHits->localPosition());
245  if (checkHitsAtPositiveY){ if (hitPos.y() < 0) return false;}
246  //***top-bottom
247  if (checkHitsAtNegativeY){ if (hitPos.y() > 0) return false;}
248  //***
249  //std::string name = iHits->seedinglayer().name();
250  //hits for the seeds must be in different layers
251  unsigned int subid=(*trh).geographicalId().subdetId();
252  unsigned int layer = tTopo->layer( (*trh).geographicalId());
253  std::vector<std::pair<unsigned int, unsigned int> >::const_iterator iter;
254  //std::vector<std::string>::const_iterator iNames;
255  if (checkHitsOnDifferentLayers){
256 
257  for (iter = vSubdetLayer.begin(); iter != vSubdetLayer.end(); iter++){
258  if (iter->first == subid && iter->second == layer) return false;
259  }
260  /*
261  for (iNames = vSeedLayerNames.begin(); iNames != vSeedLayerNames.end(); iNames++){
262  if (*iNames == name) return false;
263  }
264  */
265  }
266  //vSeedLayerNames.push_back(iHits->seedinglayer().name());
267  vSubdetLayer.push_back(std::make_pair(subid, layer));
268  }
269  return true;
270 }
271 
272 
274  if (!useScintillatorsConstraint) return true;
275 
276  PTrajectoryStateOnDet pstate = seed.startingState();
278  &(theTracker->idToDet(DetId(pstate.detId()))->surface()),
279  &(*theMagfield));
280  const FreeTrajectoryState* state = theTSOS.freeState();
281  StraightLinePlaneCrossing planeCrossingLower( Basic3DVector<float>(state->position()),
282  Basic3DVector<float>(state->momentum()),
283  alongMomentum);
284  StraightLinePlaneCrossing planeCrossingUpper( Basic3DVector<float>(state->position()),
285  Basic3DVector<float>(state->momentum()),
287  std::pair<bool,StraightLinePlaneCrossing::PositionType> positionUpper =
288  planeCrossingUpper.position(*upperScintillator);
289  std::pair<bool,StraightLinePlaneCrossing::PositionType> positionLower =
290  planeCrossingLower.position(*lowerScintillator);
291  if (!(positionUpper.first && positionLower.first)) {
292  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
293  << "Scintillator plane not crossed";
294  return false;
295  }
296  LocalPoint positionUpperLocal = upperScintillator->toLocal((GlobalPoint)(positionUpper.second));
297  LocalPoint positionLowerLocal = lowerScintillator->toLocal((GlobalPoint)(positionLower.second));
298  if (upperScintillator->bounds().inside(positionUpperLocal) &&
299  lowerScintillator->bounds().inside(positionLowerLocal)) {
300  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
301  << "position on Upper scintillator "
302  << positionUpper.second;
303  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
304  << "position on Lower scintillator "
305  << positionLower.second;
306 
307  return true;
308  }
309  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
310  << "scintillator not crossed in bounds: position on Upper scintillator "
311  << positionUpper.second << " position on Lower scintillator " << positionLower.second;
312  return false;
313 }
314 
315 
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:116
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
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:88
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:62
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:41
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