00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedGenerator.h"
00013 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedHits.h"
00014 #include "RecoMuon/MuonSeedGenerator/src/RPCSeedFinder.h"
00015
00016
00017 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00018 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00019
00020 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00021
00022
00023 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00024 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00025 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00026 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00027
00028 #include "RecoMuon/MeasurementDet/interface/MuonDetLayerMeasurements.h"
00029 #include "RecoMuon/DetLayers/interface/MuonDetLayerGeometry.h"
00030 #include "RecoMuon/Records/interface/MuonRecoGeometryRecord.h"
00031 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00032
00033
00034 #include "FWCore/Framework/interface/EventSetup.h"
00035 #include "FWCore/Framework/interface/Event.h"
00036 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00037 #include "FWCore/Framework/interface/ESHandle.h"
00038 #include "DataFormats/Common/interface/Handle.h"
00039 #include "FWCore/Framework/interface/MakerMacros.h"
00040 #include "FWCore/Framework/interface/Frameworkfwd.h"
00041
00042 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00043
00044 #include "math.h"
00045
00046
00047 #include <vector>
00048
00049 using namespace std;
00050 using namespace edm;
00051
00052 typedef MuonTransientTrackingRecHit::MuonRecHitPointer MuonRecHitPointer;
00053 typedef MuonTransientTrackingRecHit::ConstMuonRecHitPointer ConstMuonRecHitPointer;
00054 typedef MuonTransientTrackingRecHit::MuonRecHitContainer MuonRecHitContainer;
00055
00056 double RB1X, RB1Y, RB1Z, RB2X, RB2Y, RB2Z, RB3X, RB3Y, RB3Z, RB4X, RB4Y, RB4Z;
00057 double theta,L,s,r;
00058
00059
00060 RPCSeedGenerator::RPCSeedGenerator(const edm::ParameterSet& pset){
00061 produces<TrajectorySeedCollection>();
00062
00063 theRPCRecHits = pset.getParameter<edm::InputTag>("RPCRecHitsLabel");
00064 cout << endl << "[RPCSeedGenerator] --> Constructor called" << endl;
00065 }
00066
00067
00068
00069 RPCSeedGenerator::~RPCSeedGenerator(){
00070 cout << "[RPCSeedGenerator] --> Destructor called" << endl;
00071 }
00072
00073
00074 void RPCSeedGenerator::produce(edm::Event& event, const edm::EventSetup& eSetup){
00075
00076 theSeeds.clear();
00077
00078
00079 auto_ptr<TrajectorySeedCollection> output(new TrajectorySeedCollection());
00080
00081
00082 edm::ESHandle<MuonDetLayerGeometry> muonLayers;
00083 eSetup.get<MuonRecoGeometryRecord>().get(muonLayers);
00084
00085
00086 vector<DetLayer*> RPCBarrelLayers = muonLayers->barrelRPCLayers();
00087 const DetLayer* RB4L = RPCBarrelLayers[5];
00088 const DetLayer* RB3L = RPCBarrelLayers[4];
00089 const DetLayer* RB22L = RPCBarrelLayers[3];
00090 const DetLayer* RB21L = RPCBarrelLayers[2];
00091 const DetLayer* RB12L = RPCBarrelLayers[1];
00092 const DetLayer* RB11L = RPCBarrelLayers[0];
00093
00094
00095 MuonDetLayerMeasurements muonMeasurements(edm::InputTag(),edm::InputTag(), theRPCRecHits,
00096 false, false, true);
00097
00098
00099 MuonRecHitContainer list11 = muonMeasurements.recHits(RB11L,event);
00100 MuonRecHitContainer list12 = muonMeasurements.recHits(RB12L,event);
00101 MuonRecHitContainer list21 = muonMeasurements.recHits(RB21L,event);
00102 MuonRecHitContainer list22 = muonMeasurements.recHits(RB22L,event);
00103 MuonRecHitContainer list3 = muonMeasurements.recHits(RB3L,event);
00104 MuonRecHitContainer list4 = muonMeasurements.recHits(RB4L,event);
00105
00106
00107 if (list11.size() == 1 && list21.size() == 1 && list3.size() == 1 && list4.size() == 1) {
00108
00109
00110 cout << "list11 = " << list11.size() << endl;
00111 cout << "list21 = " << list21.size() << endl;
00112 cout << "list3 = " << list3.size() << endl;
00113 cout << "list4 = " << list4.size() << endl;
00114
00115
00116 unsigned int counter;
00117
00118 bool* RB11 = 0;
00119 if (list11.size()) {
00120 RB11 = new bool[list11.size()];
00121 for ( size_t i=0; i<list11.size(); i++ ) RB11[i]=false;
00122 }
00123
00124 bool* RB21 = 0;
00125 if (list21.size()) {
00126 RB21 = new bool[list21.size()];
00127 for ( size_t i=0; i<list21.size(); i++ ) RB21[i]=false;
00128 }
00129
00130
00131 bool* RB3 = 0;
00132 if (list3.size()) {
00133 RB3 = new bool[list3.size()];
00134 for ( size_t i=0; i<list3.size(); i++ ) RB3[i]=false;
00135 }
00136
00137
00138 for (MuonRecHitContainer::iterator iter=list4.begin(); iter!=list4.end(); iter++ ){
00139 RPCSeedFinder theSeed;
00140 theSeed.add(*iter);
00141 complete(theSeed, list3, RB3);
00142 complete(theSeed, list21, RB21);
00143 complete(theSeed, list11, RB11);
00144 checkAndFill(theSeed, eSetup);
00145 }
00146
00147 for ( counter = 0; counter<list3.size(); counter++ ){
00148 if ( !RB3[counter] ) {
00149 RPCSeedFinder theSeed;
00150 theSeed.add(list3[counter]);
00151 complete(theSeed, list21, RB21);
00152 complete(theSeed, list11, RB11);
00153 complete(theSeed, list4);
00154 checkAndFill(theSeed,eSetup);
00155 }
00156 }
00157
00158 for ( counter = 0; counter<list21.size(); counter++ ){
00159 if ( !RB21[counter] ) {
00160 RPCSeedFinder theSeed;
00161 theSeed.add(list21[counter]);
00162 complete(theSeed, list11, RB11);
00163 complete(theSeed, list4);
00164 complete(theSeed, list3, RB3);
00165 if (theSeed.nrhit()>1 || (theSeed.nrhit()==1 &&
00166 theSeed.firstRecHit()->dimension()==4) ) {
00167 checkAndFill(theSeed,eSetup);
00168 }
00169 }
00170 }
00171
00172 for ( counter = 0; counter<list11.size(); counter++ ){
00173 if ( !RB11[counter] ) {
00174 RPCSeedFinder theSeed;
00175 theSeed.add(list11[counter]);
00176 complete(theSeed, list4);
00177 complete(theSeed, list3, RB3);
00178 complete(theSeed, list21, RB21);
00179 if (theSeed.nrhit()>1 || (theSeed.nrhit()==1 &&
00180 theSeed.firstRecHit()->dimension()==4) ) {
00181 checkAndFill(theSeed,eSetup);
00182 }
00183 }
00184 }
00185
00186 if ( RB3 ) delete [] RB3;
00187 if ( RB21 ) delete [] RB21;
00188 if ( RB11 ) delete [] RB11;
00189
00190 if(theSeeds.size() == 1) output->push_back(theSeeds.front());
00191
00192 else{
00193 for(vector<TrajectorySeed>::iterator seed = theSeeds.begin();
00194 seed != theSeeds.end(); ++seed){
00195 int counter =0;
00196 for(vector<TrajectorySeed>::iterator seed2 = seed;
00197 seed2 != theSeeds.end(); ++seed2)
00198 if( seed->startingState().parameters().vector() ==
00199 seed2->startingState().parameters().vector() )
00200 ++counter;
00201
00202 if( counter > 1 ) theSeeds.erase(seed--);
00203 else output->push_back(*seed);
00204 }
00205 }
00206
00207 event.put(output);
00208
00209 }
00210
00211 }
00212
00213
00214 void RPCSeedGenerator::complete(RPCSeedFinder& seed,
00215 MuonRecHitContainer &recHits, bool* used) const {
00216
00217 MuonRecHitContainer good_rhit;
00218
00219 ConstMuonRecHitPointer first = seed.firstRecHit();
00220
00221 GlobalPoint ptg2 = first->globalPosition();
00222
00223 int nr=0;
00224
00225 for (MuonRecHitContainer::iterator iter=recHits.begin(); iter!=recHits.end(); iter++){
00226
00227 GlobalPoint ptg1 = (*iter)->globalPosition();
00228
00229 if ( fabs (ptg1.eta()-ptg2.eta()) > .2 || fabs (ptg1.phi()-ptg2.phi()) > .1 ) {
00230 nr++;
00231 continue;
00232 }
00233
00234 if( fabs ( ptg2.eta() ) < 1.0 ) {
00235
00236 good_rhit.push_back(*iter);
00237
00238 }
00239
00240 nr++;
00241
00242 }
00243
00244 MuonRecHitPointer best=0;
00245
00246 if( fabs ( ptg2.eta() ) < 1.0 ) {
00247
00248 float best_dphi = M_PI;
00249
00250 for (MuonRecHitContainer::iterator iter=good_rhit.begin(); iter!=good_rhit.end(); iter++){
00251
00252 GlobalVector dir1 = (*iter)->globalDirection();
00253
00254 GlobalVector dir2 = first->globalDirection();
00255
00256 float dphi = dir1.phi()-dir2.phi();
00257
00258 if (dphi < 0.) dphi = -dphi;
00259 if (dphi > M_PI) dphi = 2.*M_PI - dphi;
00260
00261 if ( dphi < best_dphi ) {
00262
00263 best_dphi = dphi;
00264 best = (*iter);
00265 }
00266
00267 }
00268
00269 }
00270
00271
00272 if(best)
00273 if ( best->isValid() ) seed.add(best);
00274
00275 }
00276
00277
00278 void RPCSeedGenerator::checkAndFill(RPCSeedFinder& theSeed, const edm::EventSetup& eSetup){
00279
00280 if (theSeed.nrhit()>1 ) {
00281 vector<TrajectorySeed> the_seeds = theSeed.seeds(eSetup);
00282 for (vector<TrajectorySeed>::const_iterator
00283 the_seed=the_seeds.begin(); the_seed!=the_seeds.end(); ++the_seed) {
00284 theSeeds.push_back(*the_seed);
00285 }
00286 }
00287 }