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