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