00001 #include "RecoTracker/SpecialSeedGenerators/interface/CtfSpecialSeedGenerator.h"
00002
00003 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00004 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00005 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00006 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
00008 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
00009 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00010 #include "TrackingTools/GeomPropagators/interface/StraightLinePlaneCrossing.h"
00011 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00012 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00013
00014 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegionProducerFactory.h"
00015 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00016 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGeneratorFactory.h"
00017 #include "RecoTracker/TkSeedingLayers/interface/OrderedSeedingHits.h"
00018
00019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00020
00021 #include "RecoTracker/SpecialSeedGenerators/interface/ClusterChecker.h"
00022
00023 using namespace ctfseeding;
00024
00025 CtfSpecialSeedGenerator::CtfSpecialSeedGenerator(const edm::ParameterSet& conf):
00026 conf_(conf),
00027 requireBOFF(conf.getParameter<bool>("requireBOFF")),
00028 theMaxSeeds(conf.getParameter<int32_t>("maxSeeds"))
00029 {
00030 useScintillatorsConstraint = conf_.getParameter<bool>("UseScintillatorsConstraint");
00031 edm::LogVerbatim("CtfSpecialSeedGenerator") << "Constructing CtfSpecialSeedGenerator";
00032 produces<TrajectorySeedCollection>();
00033 theSeedBuilder =0;
00034 theRegionProducer =0;
00035 }
00036
00037 CtfSpecialSeedGenerator::~CtfSpecialSeedGenerator(){
00038 }
00039
00040 void CtfSpecialSeedGenerator::endRun(edm::Run &, edm::EventSetup const&){
00041 if (theSeedBuilder) { delete theSeedBuilder; theSeedBuilder = 0; }
00042 if (theRegionProducer) { delete theRegionProducer; theRegionProducer = 0; }
00043 std::vector<OrderedHitsGenerator*>::iterator iGen;
00044 for (iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++){
00045 delete (*iGen);
00046 }
00047 theGenerators.clear();
00048 }
00049
00050 void CtfSpecialSeedGenerator::beginRun(edm::Run &, const edm::EventSetup& iSetup){
00051 std::string builderName = conf_.getParameter<std::string>("TTRHBuilder");
00052 iSetup.get<TransientRecHitRecord>().get(builderName,theBuilder);
00053
00054 iSetup.get<IdealMagneticFieldRecord>().get(theMagfield);
00055 iSetup.get<TrackerDigiGeometryRecord>().get(theTracker);
00056
00057 edm::LogVerbatim("CtfSpecialSeedGenerator") << "Initializing...";
00058 if (useScintillatorsConstraint){
00059 edm::ParameterSet upperScintPar = conf_.getParameter<edm::ParameterSet>("UpperScintillatorParameters");
00060 edm::ParameterSet lowerScintPar = conf_.getParameter<edm::ParameterSet>("LowerScintillatorParameters");
00061 RectangularPlaneBounds upperBounds(upperScintPar.getParameter<double>("WidthInX"),
00062 upperScintPar.getParameter<double>("LenghtInZ"),
00063 1);
00064 GlobalPoint upperPosition(upperScintPar.getParameter<double>("GlobalX"),
00065 upperScintPar.getParameter<double>("GlobalY"),
00066 upperScintPar.getParameter<double>("GlobalZ"));
00067 edm::LogVerbatim("CtfSpecialSeedGenerator")
00068 << "Upper Scintillator position x, y, z " << upperPosition.x()
00069 << ", " << upperPosition.y() << ", " << upperPosition.z();
00070 RectangularPlaneBounds lowerBounds(lowerScintPar.getParameter<double>("WidthInX"),
00071 lowerScintPar.getParameter<double>("LenghtInZ"),
00072 1);
00073 GlobalPoint lowerPosition(lowerScintPar.getParameter<double>("GlobalX"),
00074 lowerScintPar.getParameter<double>("GlobalY"),
00075 lowerScintPar.getParameter<double>("GlobalZ"));
00076 edm::LogVerbatim("CtfSpecialSeedGenerator")
00077 << "Lower Scintillator position x, y, z " << lowerPosition.x()
00078 << ", " << lowerPosition.y() << ", " << lowerPosition.z() ;
00079 TkRotation<float> rot(1,0,0,0,0,1,0,1,0);
00080 upperScintillator = BoundPlane::build(upperPosition, rot, &upperBounds);
00081 lowerScintillator = BoundPlane::build(lowerPosition, rot, &lowerBounds);
00082 }
00083 edm::ParameterSet regfactoryPSet = conf_.getParameter<edm::ParameterSet>("RegionFactoryPSet");
00084 std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
00085 theRegionProducer = TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet);
00086
00087 edm::ESHandle<Propagator> propagatorAlongHandle;
00088 iSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterial",propagatorAlongHandle);
00089 edm::ESHandle<Propagator> propagatorOppositeHandle;
00090 iSetup.get<TrackingComponentsRecord>().get("PropagatorWithMaterialOpposite",propagatorOppositeHandle);
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 std::vector<edm::ParameterSet> pSets = conf_.getParameter<std::vector<edm::ParameterSet> >("OrderedHitsFactoryPSets");
00114 std::vector<edm::ParameterSet>::const_iterator iPSet;
00115 for (iPSet = pSets.begin(); iPSet != pSets.end(); iPSet++){
00116 std::string hitsfactoryName = iPSet->getParameter<std::string>("ComponentName");
00117 theGenerators.push_back(OrderedHitsGeneratorFactory::get()->create( hitsfactoryName, *iPSet));
00118 std::string propagationDirection = iPSet->getParameter<std::string>("PropagationDirection");
00119 if (propagationDirection == "alongMomentum") thePropDirs.push_back(alongMomentum);
00120 else thePropDirs.push_back(oppositeToMomentum);
00121 std::string navigationDirection = iPSet->getParameter<std::string>("NavigationDirection");
00122 if (navigationDirection == "insideOut") theNavDirs.push_back(insideOut);
00123 else theNavDirs.push_back(outsideIn);
00124 edm::LogVerbatim("CtfSpecialSeedGenerator") << "hitsGenerator done";
00125 }
00126 bool setMomentum = conf_.getParameter<bool>("SetMomentum");
00127 std::vector<int> charges;
00128 if (setMomentum){
00129 charges = conf_.getParameter<std::vector<int> >("Charges");
00130 }
00131 theSeedBuilder = new SeedFromGenericPairOrTriplet(theMagfield.product(),
00132 theTracker.product(),
00133 theBuilder.product(),
00134 propagatorAlongHandle.product(),
00135 propagatorOppositeHandle.product(),
00136 charges,
00137 setMomentum,
00138 conf_.getParameter<double>("ErrorRescaling"));
00139 double p = 1;
00140 if (setMomentum) {
00141 p = conf_.getParameter<double>("SeedMomentum");
00142 theSeedBuilder->setMomentumTo(p);
00143 }
00144
00145 }
00146
00147 void CtfSpecialSeedGenerator::produce(edm::Event& e, const edm::EventSetup& iSetup)
00148 {
00149
00150 std::auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection);
00151
00152
00153 ClusterChecker check(conf_);
00154 if ( !requireBOFF || (theMagfield->inTesla(GlobalPoint(0,0,0)).mag() == 0.00) ) {
00155 size_t clustsOrZero = check.tooManyClusters(e);
00156 if (!clustsOrZero){
00157 bool ok = run(iSetup, e, *output);
00158 if (!ok) { ; }
00159 } else edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
00160 }
00161
00162
00163 edm::LogVerbatim("CtfSpecialSeedGenerator") << " number of seeds = "<< output->size();
00164 e.put(output);
00165 }
00166
00167 bool CtfSpecialSeedGenerator::run(const edm::EventSetup& iSetup,
00168 const edm::Event& e,
00169 TrajectorySeedCollection& output){
00170 std::vector<TrackingRegion*> regions = theRegionProducer->regions(e, iSetup);
00171 std::vector<TrackingRegion*>::const_iterator iReg;
00172 bool ok = true;
00173 for (iReg = regions.begin(); iReg != regions.end(); iReg++){
00174 if(!theSeedBuilder->momentumFromPSet()) theSeedBuilder->setMomentumTo((*iReg)->ptMin());
00175 std::vector<OrderedHitsGenerator*>::const_iterator iGen;
00176 int i = 0;
00177 for (iGen = theGenerators.begin(); iGen != theGenerators.end(); iGen++){
00178 ok = buildSeeds(iSetup,
00179 e,
00180 (*iGen)->run(**iReg, e, iSetup),
00181 theNavDirs[i],
00182 thePropDirs[i],
00183 output);
00184 i++;
00185 if (!ok) break;
00186 }
00187 if (!ok) break;
00188 }
00189
00190 for (std::vector<TrackingRegion*>::iterator iReg = regions.begin(); iReg != regions.end(); iReg++){
00191 delete *iReg;
00192 }
00193 return ok;
00194 }
00195
00196 bool CtfSpecialSeedGenerator::buildSeeds(const edm::EventSetup& iSetup,
00197 const edm::Event& e,
00198 const OrderedSeedingHits& osh,
00199 const NavigationDirection& navdir,
00200 const PropagationDirection& dir,
00201 TrajectorySeedCollection& output){
00202
00203 edm::LogInfo("CtfSpecialSeedGenerator")<<"osh.size() " << osh.size();
00204 for (unsigned int i = 0; i < osh.size(); i++){
00205 SeedingHitSet shs = osh[i];
00206 if (preliminaryCheck(shs)){
00207 std::vector<TrajectorySeed*> seeds = theSeedBuilder->seed(shs,
00208 dir,
00209 navdir,
00210 iSetup);
00211 for (std::vector<TrajectorySeed*>::const_iterator iSeed = seeds.begin(); iSeed != seeds.end(); iSeed++){
00212 if (!*iSeed) {edm::LogError("CtfSpecialSeedGenerator")<<"a seed pointer is null. skipping.";continue;}
00213 if (postCheck(**iSeed)){
00214 output.push_back(**iSeed);
00215 }
00216 delete *iSeed;
00217 edm::LogVerbatim("CtfSpecialSeedGenerator") << "Seed built";
00218 }
00219 }
00220 }
00221 if ((theMaxSeeds > 0) && (output.size() > size_t(theMaxSeeds))) {
00222 edm::LogWarning("TooManySeeds") << "Too many seeds ("<< output.size() <<"), bailing out.\n";
00223 output.clear();
00224 return false;
00225 }
00226 return true;
00227 }
00228
00229 bool CtfSpecialSeedGenerator::preliminaryCheck(const SeedingHitSet& shs){
00230 std::vector<std::pair<unsigned int, unsigned int> > vSubdetLayer;
00231
00232 bool checkHitsAtPositiveY = conf_.getParameter<bool>("SeedsFromPositiveY");
00233
00234 bool checkHitsAtNegativeY = conf_.getParameter<bool>("SeedsFromNegativeY");
00235
00236 bool checkHitsOnDifferentLayers = conf_.getParameter<bool>("CheckHitsAreOnDifferentLayers");
00237 unsigned int nHits = shs.size();
00238 for (unsigned int iHit=0; iHit < nHits; ++iHit) {
00239
00240 const TrackingRecHit * trh = shs[iHit]->hit();
00241 TransientTrackingRecHit::RecHitPointer recHit = theBuilder->build(trh);
00242 GlobalPoint hitPos = recHit->globalPosition();
00243
00244
00245 if (checkHitsAtPositiveY){ if (hitPos.y() < 0) return false;}
00246
00247 if (checkHitsAtNegativeY){ if (hitPos.y() > 0) return false;}
00248
00249
00250
00251 unsigned int subid=(*trh).geographicalId().subdetId();
00252 unsigned int layer = 0;
00253 if (subid == StripSubdetector::TIB){
00254 TIBDetId tibId((*trh).geographicalId());
00255 layer = tibId.layer();
00256 } else if (subid == StripSubdetector::TID){
00257 TIDDetId tidId((*trh).geographicalId());
00258 layer = tidId.wheel();
00259 } else if (subid == StripSubdetector::TOB){
00260 TOBDetId tobId((*trh).geographicalId());
00261 layer = tobId.layer();
00262 } else if (subid == StripSubdetector::TEC){
00263 TECDetId tecId((*trh).geographicalId());
00264 layer = tecId.wheel();
00265 }
00266 std::vector<std::pair<unsigned int, unsigned int> >::const_iterator iter;
00267
00268 if (checkHitsOnDifferentLayers){
00269
00270 for (iter = vSubdetLayer.begin(); iter != vSubdetLayer.end(); iter++){
00271 if (iter->first == subid && iter->second == layer) return false;
00272 }
00273
00274
00275
00276
00277
00278 }
00279
00280 vSubdetLayer.push_back(std::make_pair(subid, layer));
00281 }
00282 return true;
00283 }
00284
00285
00286 bool CtfSpecialSeedGenerator::postCheck(const TrajectorySeed& seed){
00287 if (!useScintillatorsConstraint) return true;
00288 TrajectoryStateTransform transformer;
00289 PTrajectoryStateOnDet pstate = seed.startingState();
00290 TrajectoryStateOnSurface theTSOS = transformer.transientState(pstate,
00291 &(theTracker->idToDet(DetId(pstate.detId()))->surface()),
00292 &(*theMagfield));
00293 FreeTrajectoryState* state = theTSOS.freeState();
00294 StraightLinePlaneCrossing planeCrossingLower( Basic3DVector<float>(state->position()),
00295 Basic3DVector<float>(state->momentum()),
00296 alongMomentum);
00297 StraightLinePlaneCrossing planeCrossingUpper( Basic3DVector<float>(state->position()),
00298 Basic3DVector<float>(state->momentum()),
00299 oppositeToMomentum);
00300 std::pair<bool,StraightLinePlaneCrossing::PositionType> positionUpper =
00301 planeCrossingUpper.position(*upperScintillator);
00302 std::pair<bool,StraightLinePlaneCrossing::PositionType> positionLower =
00303 planeCrossingLower.position(*lowerScintillator);
00304 if (!(positionUpper.first && positionLower.first)) {
00305 edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
00306 << "Scintillator plane not crossed";
00307 return false;
00308 }
00309 LocalPoint positionUpperLocal = upperScintillator->toLocal((GlobalPoint)(positionUpper.second));
00310 LocalPoint positionLowerLocal = lowerScintillator->toLocal((GlobalPoint)(positionLower.second));
00311 if (upperScintillator->bounds().inside(positionUpperLocal) &&
00312 lowerScintillator->bounds().inside(positionLowerLocal)) {
00313 edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
00314 << "position on Upper scintillator "
00315 << positionUpper.second;
00316 edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
00317 << "position on Lower scintillator "
00318 << positionLower.second;
00319
00320 return true;
00321 }
00322 edm::LogVerbatim("CtfSpecialSeedGenerator::checkDirection")
00323 << "scintillator not crossed in bounds: position on Upper scintillator "
00324 << positionUpper.second << " position on Lower scintillator " << positionLower.second;
00325 return false;
00326 }
00327
00328