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"
9 
14 
16 
18 
19 using namespace ctfseeding;
20 
22  conf_(conf),
23  requireBOFF(conf.getParameter<bool>("requireBOFF")),
24  theMaxSeeds(conf.getParameter<int32_t>("maxSeeds"))
25 {
26  useScintillatorsConstraint = conf_.getParameter<bool>("UseScintillatorsConstraint");
27  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Constructing CtfSpecialSeedGenerator";
28  produces<TrajectorySeedCollection>();
29  theSeedBuilder =0;
31 }
32 
34 }
35 
37  if (theSeedBuilder) { delete theSeedBuilder; theSeedBuilder = 0; }
39  std::vector<OrderedHitsGenerator*>::iterator iGen;
40  for (iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++){
41  delete (*iGen);
42  }
43  theGenerators.clear();
44 }
45 
47  std::string builderName = conf_.getParameter<std::string>("TTRHBuilder");
48  iSetup.get<TransientRecHitRecord>().get(builderName,theBuilder);
49 
52 
53  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Initializing...";
55  edm::ParameterSet upperScintPar = conf_.getParameter<edm::ParameterSet>("UpperScintillatorParameters");
56  edm::ParameterSet lowerScintPar = conf_.getParameter<edm::ParameterSet>("LowerScintillatorParameters");
57  RectangularPlaneBounds upperBounds(upperScintPar.getParameter<double>("WidthInX"),
58  upperScintPar.getParameter<double>("LenghtInZ"),
59  1);
60  GlobalPoint upperPosition(upperScintPar.getParameter<double>("GlobalX"),
61  upperScintPar.getParameter<double>("GlobalY"),
62  upperScintPar.getParameter<double>("GlobalZ"));
63  edm::LogVerbatim("CtfSpecialSeedGenerator")
64  << "Upper Scintillator position x, y, z " << upperPosition.x()
65  << ", " << upperPosition.y() << ", " << upperPosition.z();
66  RectangularPlaneBounds lowerBounds(lowerScintPar.getParameter<double>("WidthInX"),
67  lowerScintPar.getParameter<double>("LenghtInZ"),
68  1);
69  GlobalPoint lowerPosition(lowerScintPar.getParameter<double>("GlobalX"),
70  lowerScintPar.getParameter<double>("GlobalY"),
71  lowerScintPar.getParameter<double>("GlobalZ"));
72  edm::LogVerbatim("CtfSpecialSeedGenerator")
73  << "Lower Scintillator position x, y, z " << lowerPosition.x()
74  << ", " << lowerPosition.y() << ", " << lowerPosition.z() ;
75  TkRotation<float> rot(1,0,0,0,0,1,0,1,0);
76  upperScintillator = BoundPlane::build(upperPosition, rot, &upperBounds);
77  lowerScintillator = BoundPlane::build(lowerPosition, rot, &lowerBounds);
78  }
79  edm::ParameterSet regfactoryPSet = conf_.getParameter<edm::ParameterSet>("RegionFactoryPSet");
80  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
81  theRegionProducer = TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet);
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
150  if ( !requireBOFF || (theMagfield->inTesla(GlobalPoint(0,0,0)).mag() == 0.00) ) {
151  size_t clustsOrZero = check.tooManyClusters(e);
152  if (!clustsOrZero){
153  bool ok = run(iSetup, e, *output);
154  if (!ok) { ; } // nothing to do
155  } else edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
156  }
157 
158 
159  edm::LogVerbatim("CtfSpecialSeedGenerator") << " number of seeds = "<< output->size();
160  e.put(output);
161 }
162 
164  const edm::Event& e,
166  std::vector<TrackingRegion*> regions = theRegionProducer->regions(e, iSetup);
167  std::vector<TrackingRegion*>::const_iterator iReg;
168  bool ok = true;
169  for (iReg = regions.begin(); iReg != regions.end(); iReg++){
170  if(!theSeedBuilder->momentumFromPSet()) theSeedBuilder->setMomentumTo((*iReg)->ptMin());
171  std::vector<OrderedHitsGenerator*>::const_iterator iGen;
172  int i = 0;
173  for (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)){
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  std::vector<std::pair<unsigned int, unsigned int> > vSubdetLayer;
227  //std::vector<std::string> vSeedLayerNames;
228  bool checkHitsAtPositiveY = conf_.getParameter<bool>("SeedsFromPositiveY");
229  //***top-bottom
230  bool checkHitsAtNegativeY = conf_.getParameter<bool>("SeedsFromNegativeY");
231  //***
232  bool checkHitsOnDifferentLayers = conf_.getParameter<bool>("CheckHitsAreOnDifferentLayers");
233  unsigned int nHits = shs.size();
234  for (unsigned int iHit=0; iHit < nHits; ++iHit) {
235  //hits for the seeds must be at positive y
236  const TrackingRecHit * trh = shs[iHit]->hit();
238  GlobalPoint hitPos = recHit->globalPosition();
239  //GlobalPoint point =
240  // theTracker->idToDet(iHits->geographicalId() )->surface().toGlobal(iHits->localPosition());
241  if (checkHitsAtPositiveY){ if (hitPos.y() < 0) return false;}
242  //***top-bottom
243  if (checkHitsAtNegativeY){ if (hitPos.y() > 0) return false;}
244  //***
245  //std::string name = iHits->seedinglayer().name();
246  //hits for the seeds must be in different layers
247  unsigned int subid=(*trh).geographicalId().subdetId();
248  unsigned int layer = 0;
249  if (subid == StripSubdetector::TIB){
250  TIBDetId tibId((*trh).geographicalId());
251  layer = tibId.layer();
252  } else if (subid == StripSubdetector::TID){
253  TIDDetId tidId((*trh).geographicalId());
254  layer = tidId.wheel();
255  } else if (subid == StripSubdetector::TOB){
256  TOBDetId tobId((*trh).geographicalId());
257  layer = tobId.layer();
258  } else if (subid == StripSubdetector::TEC){
259  TECDetId tecId((*trh).geographicalId());
260  layer = tecId.wheel();
261  }
262  std::vector<std::pair<unsigned int, unsigned int> >::const_iterator iter;
263  //std::vector<std::string>::const_iterator iNames;
264  if (checkHitsOnDifferentLayers){
265 
266  for (iter = vSubdetLayer.begin(); iter != vSubdetLayer.end(); iter++){
267  if (iter->first == subid && iter->second == layer) return false;
268  }
269  /*
270  for (iNames = vSeedLayerNames.begin(); iNames != vSeedLayerNames.end(); iNames++){
271  if (*iNames == name) return false;
272  }
273  */
274  }
275  //vSeedLayerNames.push_back(iHits->seedinglayer().name());
276  vSubdetLayer.push_back(std::make_pair(subid, layer));
277  }
278  return true;
279 }
280 
281 
283  if (!useScintillatorsConstraint) return true;
284  TrajectoryStateTransform transformer;
285  PTrajectoryStateOnDet pstate = seed.startingState();
286  TrajectoryStateOnSurface theTSOS = transformer.transientState(pstate,
287  &(theTracker->idToDet(DetId(pstate.detId()))->surface()),
288  &(*theMagfield));
289  FreeTrajectoryState* state = theTSOS.freeState();
290  StraightLinePlaneCrossing planeCrossingLower( Basic3DVector<float>(state->position()),
291  Basic3DVector<float>(state->momentum()),
292  alongMomentum);
293  StraightLinePlaneCrossing planeCrossingUpper( Basic3DVector<float>(state->position()),
294  Basic3DVector<float>(state->momentum()),
296  std::pair<bool,StraightLinePlaneCrossing::PositionType> positionUpper =
297  planeCrossingUpper.position(*upperScintillator);
298  std::pair<bool,StraightLinePlaneCrossing::PositionType> positionLower =
299  planeCrossingLower.position(*lowerScintillator);
300  if (!(positionUpper.first && positionLower.first)) {
301  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
302  << "Scintillator plane not crossed";
303  return false;
304  }
305  LocalPoint positionUpperLocal = upperScintillator->toLocal((GlobalPoint)(positionUpper.second));
306  LocalPoint positionLowerLocal = lowerScintillator->toLocal((GlobalPoint)(positionLower.second));
307  if (upperScintillator->bounds().inside(positionUpperLocal) &&
308  lowerScintillator->bounds().inside(positionLowerLocal)) {
309  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
310  << "position on Upper scintillator "
311  << positionUpper.second;
312  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
313  << "position on Lower scintillator "
314  << positionLower.second;
315 
316  return true;
317  }
318  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
319  << "scintillator not crossed in bounds: position on Upper scintillator "
320  << positionUpper.second << " position on Lower scintillator " << positionLower.second;
321  return false;
322 }
323 
324 
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
SeedFromGenericPairOrTriplet * theSeedBuilder
BoundPlane::BoundPlanePointer lowerScintillator
T y() const
Definition: PV3DBase.h:57
TrackingRegionProducer * theRegionProducer
virtual unsigned int size() const =0
bool run(const edm::EventSetup &c, const edm::Event &e, TrajectorySeedCollection &output)
virtual void produce(edm::Event &e, const edm::EventSetup &c)
PropagationDirection
static BoundPlanePointer build(const PositionType &pos, const RotationType &rot, const Bounds *bounds, MediumProperties *mp=0)
Definition: BoundPlane.h:26
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)
virtual void beginRun(edm::Run &, edm::EventSetup const &)
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:84
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
T z() const
Definition: PV3DBase.h:58
RunNumber_t run() const
Definition: Event.h:66
std::vector< OrderedHitsGenerator * > theGenerators
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field) const
GlobalVector momentum() const
tuple conf
Definition: dbtoconf.py:185
PositionType position(double s) const
size_t tooManyClusters(const edm::Event &e)
Definition: DetId.h:20
GlobalPoint position() const
std::vector< TrajectorySeed * > seed(const SeedingHitSet &hits, const PropagationDirection &dir, const NavigationDirection &seedDir, const edm::EventSetup &iSetup)
PTrajectoryStateOnDet const & startingState() const
virtual void endRun(edm::Run &, edm::EventSetup const &)
bool postCheck(const TrajectorySeed &seed)
const T & get() const
Definition: EventSetup.h:55
const unsigned int detId() const
T const * product() const
Definition: ESHandle.h:62
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
char state
Definition: procUtils.cc:75
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
edm::ESHandle< MagneticField > theMagfield
unsigned int size() const
Definition: SeedingHitSet.h:14
edm::ESHandle< TrackerGeometry > theTracker
edm::ESHandle< TransientTrackingRecHitBuilder > theBuilder
bool preliminaryCheck(const SeedingHitSet &shs)
dbl *** dir
Definition: mlp_gen.cc:35
std::vector< NavigationDirection > theNavDirs
T x() const
Definition: PV3DBase.h:56
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:32
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50
virtual std::vector< TrackingRegion * > regions(const edm::Event &ev, const edm::EventSetup &es) const =0