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"
13 
18 
20 
22 
23 using namespace ctfseeding;
24 
26  conf_(conf),
27  requireBOFF(conf.getParameter<bool>("requireBOFF")),
28  theMaxSeeds(conf.getParameter<int32_t>("maxSeeds"))
29 {
30  useScintillatorsConstraint = conf_.getParameter<bool>("UseScintillatorsConstraint");
31  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Constructing CtfSpecialSeedGenerator";
32  produces<TrajectorySeedCollection>();
33  theSeedBuilder =0;
35 }
36 
38 }
39 
41  if (theSeedBuilder) { delete theSeedBuilder; theSeedBuilder = 0; }
43  std::vector<OrderedHitsGenerator*>::iterator iGen;
44  for (iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++){
45  delete (*iGen);
46  }
47  theGenerators.clear();
48 }
49 
51  std::string builderName = conf_.getParameter<std::string>("TTRHBuilder");
52  iSetup.get<TransientRecHitRecord>().get(builderName,theBuilder);
53 
56 
57  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Initializing...";
59  edm::ParameterSet upperScintPar = conf_.getParameter<edm::ParameterSet>("UpperScintillatorParameters");
60  edm::ParameterSet lowerScintPar = conf_.getParameter<edm::ParameterSet>("LowerScintillatorParameters");
61  RectangularPlaneBounds upperBounds(upperScintPar.getParameter<double>("WidthInX"),
62  upperScintPar.getParameter<double>("LenghtInZ"),
63  1);
64  GlobalPoint upperPosition(upperScintPar.getParameter<double>("GlobalX"),
65  upperScintPar.getParameter<double>("GlobalY"),
66  upperScintPar.getParameter<double>("GlobalZ"));
67  edm::LogVerbatim("CtfSpecialSeedGenerator")
68  << "Upper Scintillator position x, y, z " << upperPosition.x()
69  << ", " << upperPosition.y() << ", " << upperPosition.z();
70  RectangularPlaneBounds lowerBounds(lowerScintPar.getParameter<double>("WidthInX"),
71  lowerScintPar.getParameter<double>("LenghtInZ"),
72  1);
73  GlobalPoint lowerPosition(lowerScintPar.getParameter<double>("GlobalX"),
74  lowerScintPar.getParameter<double>("GlobalY"),
75  lowerScintPar.getParameter<double>("GlobalZ"));
76  edm::LogVerbatim("CtfSpecialSeedGenerator")
77  << "Lower Scintillator position x, y, z " << lowerPosition.x()
78  << ", " << lowerPosition.y() << ", " << lowerPosition.z() ;
79  TkRotation<float> rot(1,0,0,0,0,1,0,1,0);
80  upperScintillator = BoundPlane::build(upperPosition, rot, &upperBounds);
81  lowerScintillator = BoundPlane::build(lowerPosition, rot, &lowerBounds);
82  }
83  edm::ParameterSet regfactoryPSet = conf_.getParameter<edm::ParameterSet>("RegionFactoryPSet");
84  std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
85  theRegionProducer = TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet);
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 hitsfactoryName = iPSet->getParameter<std::string>("ComponentName");
117  theGenerators.push_back(OrderedHitsGeneratorFactory::get()->create( hitsfactoryName, *iPSet));
118  std::string propagationDirection = iPSet->getParameter<std::string>("PropagationDirection");
119  if (propagationDirection == "alongMomentum") thePropDirs.push_back(alongMomentum);
120  else thePropDirs.push_back(oppositeToMomentum);
121  std::string navigationDirection = iPSet->getParameter<std::string>("NavigationDirection");
122  if (navigationDirection == "insideOut") theNavDirs.push_back(insideOut);
123  else theNavDirs.push_back(outsideIn);
124  edm::LogVerbatim("CtfSpecialSeedGenerator") << "hitsGenerator done";
125  }
126  bool setMomentum = conf_.getParameter<bool>("SetMomentum");
127  std::vector<int> charges;
128  if (setMomentum){
129  charges = conf_.getParameter<std::vector<int> >("Charges");
130  }
132  theTracker.product(),
134  propagatorAlongHandle.product(),
135  propagatorOppositeHandle.product(),
136  charges,
137  setMomentum,
138  conf_.getParameter<double>("ErrorRescaling"));
139  double p = 1;
140  if (setMomentum) {
141  p = conf_.getParameter<double>("SeedMomentum");
143  }
144 
145 }
146 
148 {
149  // get Inputs
150  std::auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection);
151 
152  //check on the number of clusters
154  if ( !requireBOFF || (theMagfield->inTesla(GlobalPoint(0,0,0)).mag() == 0.00) ) {
155  size_t clustsOrZero = check.tooManyClusters(e);
156  if (!clustsOrZero){
157  bool ok = run(iSetup, e, *output);
158  if (!ok) { ; } // nothing to do
159  } else edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
160  }
161 
162 
163  edm::LogVerbatim("CtfSpecialSeedGenerator") << " number of seeds = "<< output->size();
164  e.put(output);
165 }
166 
168  const edm::Event& e,
170  std::vector<TrackingRegion*> regions = theRegionProducer->regions(e, iSetup);
171  std::vector<TrackingRegion*>::const_iterator iReg;
172  bool ok = true;
173  for (iReg = regions.begin(); iReg != regions.end(); iReg++){
174  if(!theSeedBuilder->momentumFromPSet()) theSeedBuilder->setMomentumTo((*iReg)->ptMin());
175  std::vector<OrderedHitsGenerator*>::const_iterator iGen;
176  int i = 0;
177  for (iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++){
178  ok = buildSeeds(iSetup,
179  e,
180  (*iGen)->run(**iReg, e, iSetup),
181  theNavDirs[i],
182  thePropDirs[i],
183  output);
184  i++;
185  if (!ok) break;
186  }
187  if (!ok) break;
188  }
189  //clear memory
190  for (std::vector<TrackingRegion*>::iterator iReg = regions.begin(); iReg != regions.end(); iReg++){
191  delete *iReg;
192  }
193  return ok;
194 }
195 
197  const edm::Event& e,
198  const OrderedSeedingHits& osh,
199  const NavigationDirection& navdir,
200  const PropagationDirection& dir,
202  //SeedFromGenericPairOrTriplet seedBuilder(conf_, magfield.product(), tracker.product(), theBuilder.product());
203  edm::LogInfo("CtfSpecialSeedGenerator")<<"osh.size() " << osh.size();
204  for (unsigned int i = 0; i < osh.size(); i++){
205  SeedingHitSet shs = osh[i];
206  if (preliminaryCheck(shs)){
207  std::vector<TrajectorySeed*> seeds = theSeedBuilder->seed(shs,
208  dir,
209  navdir,
210  iSetup);
211  for (std::vector<TrajectorySeed*>::const_iterator iSeed = seeds.begin(); iSeed != seeds.end(); iSeed++){
212  if (!*iSeed) {edm::LogError("CtfSpecialSeedGenerator")<<"a seed pointer is null. skipping.";continue;}
213  if (postCheck(**iSeed)){
214  output.push_back(**iSeed);
215  }
216  delete *iSeed;
217  edm::LogVerbatim("CtfSpecialSeedGenerator") << "Seed built";
218  }
219  }
220  }
221  if ((theMaxSeeds > 0) && (output.size() > size_t(theMaxSeeds))) {
222  edm::LogWarning("TooManySeeds") << "Too many seeds ("<< output.size() <<"), bailing out.\n";
223  output.clear();
224  return false;
225  }
226  return true;
227 }
228 //checks the hits are on diffrent layers
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 = 0;
253  if (subid == StripSubdetector::TIB){
254  TIBDetId tibId((*trh).geographicalId());
255  layer = tibId.layer();
256  } else if (subid == StripSubdetector::TID){
257  TIDDetId tidId((*trh).geographicalId());
258  layer = tidId.wheel();
259  } else if (subid == StripSubdetector::TOB){
260  TOBDetId tobId((*trh).geographicalId());
261  layer = tobId.layer();
262  } else if (subid == StripSubdetector::TEC){
263  TECDetId tecId((*trh).geographicalId());
264  layer = tecId.wheel();
265  }
266  std::vector<std::pair<unsigned int, unsigned int> >::const_iterator iter;
267  //std::vector<std::string>::const_iterator iNames;
268  if (checkHitsOnDifferentLayers){
269 
270  for (iter = vSubdetLayer.begin(); iter != vSubdetLayer.end(); iter++){
271  if (iter->first == subid && iter->second == layer) return false;
272  }
273  /*
274  for (iNames = vSeedLayerNames.begin(); iNames != vSeedLayerNames.end(); iNames++){
275  if (*iNames == name) return false;
276  }
277  */
278  }
279  //vSeedLayerNames.push_back(iHits->seedinglayer().name());
280  vSubdetLayer.push_back(std::make_pair(subid, layer));
281  }
282  return true;
283 }
284 
285 
287  if (!useScintillatorsConstraint) return true;
288  TrajectoryStateTransform transformer;
289  PTrajectoryStateOnDet pstate = seed.startingState();
290  TrajectoryStateOnSurface theTSOS = transformer.transientState(pstate,
291  &(theTracker->idToDet(DetId(pstate.detId()))->surface()),
292  &(*theMagfield));
293  FreeTrajectoryState* state = theTSOS.freeState();
294  StraightLinePlaneCrossing planeCrossingLower( Basic3DVector<float>(state->position()),
295  Basic3DVector<float>(state->momentum()),
296  alongMomentum);
297  StraightLinePlaneCrossing planeCrossingUpper( Basic3DVector<float>(state->position()),
298  Basic3DVector<float>(state->momentum()),
300  std::pair<bool,StraightLinePlaneCrossing::PositionType> positionUpper =
301  planeCrossingUpper.position(*upperScintillator);
302  std::pair<bool,StraightLinePlaneCrossing::PositionType> positionLower =
303  planeCrossingLower.position(*lowerScintillator);
304  if (!(positionUpper.first && positionLower.first)) {
305  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
306  << "Scintillator plane not crossed";
307  return false;
308  }
309  LocalPoint positionUpperLocal = upperScintillator->toLocal((GlobalPoint)(positionUpper.second));
310  LocalPoint positionLowerLocal = lowerScintillator->toLocal((GlobalPoint)(positionLower.second));
311  if (upperScintillator->bounds().inside(positionUpperLocal) &&
312  lowerScintillator->bounds().inside(positionLowerLocal)) {
313  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
314  << "position on Upper scintillator "
315  << positionUpper.second;
316  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
317  << "position on Lower scintillator "
318  << positionLower.second;
319 
320  return true;
321  }
322  edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
323  << "scintillator not crossed in bounds: position on Upper scintillator "
324  << positionUpper.second << " position on Lower scintillator " << positionLower.second;
325  return false;
326 }
327 
328 
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:31
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