CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.cc

Go to the documentation of this file.
00001 
00008 #include "RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco4D.h"
00009 
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 
00013 #include "RecoLocalMuon/DTSegment/src/DTSegmentUpdator.h"
00014 // For the 2D reco I use thei reconstructor!
00015 #include "RecoLocalMuon/DTSegment/src/DTMeantimerPatternReco.h"
00016 #include "RecoLocalMuon/DTSegment/src/DTSegmentCand.h"
00017 
00018 #include "DataFormats/Common/interface/OwnVector.h"
00019 #include "DataFormats/DTRecHit/interface/DTRangeMapAccessor.h"
00020 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00021 #include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h"
00022 #include "DataFormats/DTRecHit/interface/DTSLRecSegment2D.h"
00023 #include "DataFormats/DTRecHit/interface/DTChamberRecSegment2D.h"
00024 
00025 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00026 
00027 using namespace std;
00028 using namespace edm;
00029 
00030 // TODO
00031 // Throw an exception if a theta segment container is requested and in the event
00032 // there isn't it. (Or launch a "lazy" reco on demand)
00033 
00034 DTMeantimerPatternReco4D::DTMeantimerPatternReco4D(const ParameterSet& pset):
00035   DTRecSegment4DBaseAlgo(pset), theAlgoName("DTMeantimerPatternReco4D"){
00036 
00037     // debug parameter
00038     debug = pset.getUntrackedParameter<bool>("debug");
00039 
00040     // the updator
00041     theUpdator = new DTSegmentUpdator(pset);
00042 
00043     // the input type. 
00044     // If true the instructions in setDTRecSegment2DContainer will be schipped and the 
00045     // theta segment will be recomputed from the 1D rechits
00046     // If false the theta segment will be taken from the Event. Caveat: in this case the
00047     // event must contain the 2D segments!
00048     allDTRecHits = pset.getParameter<bool>("AllDTRecHits");
00049 
00050     // Get the concrete 2D-segments reconstruction algo from the factory
00051     // For the 2D reco I use this reconstructor!
00052     the2DAlgo = new DTMeantimerPatternReco(pset.getParameter<ParameterSet>("Reco2DAlgoConfig"));
00053   }
00054 
00055 
00056 DTMeantimerPatternReco4D::~DTMeantimerPatternReco4D(){
00057   delete the2DAlgo;
00058   delete theUpdator;
00059 }
00060 
00061 void DTMeantimerPatternReco4D::setES(const EventSetup& setup){
00062   setup.get<MuonGeometryRecord>().get(theDTGeometry);
00063   the2DAlgo->setES(setup);
00064   theUpdator->setES(setup);
00065 }
00066 
00067 void DTMeantimerPatternReco4D::setChamber(const DTChamberId &chId){
00068   // Set the chamber
00069   theChamber = theDTGeometry->chamber(chId); 
00070 }
00071 
00072 void DTMeantimerPatternReco4D::setDTRecHit1DContainer(Handle<DTRecHitCollection> all1DHits){
00073   theHitsFromPhi1.clear();
00074   theHitsFromPhi2.clear();
00075   theHitsFromTheta.clear();
00076 
00077   DTRecHitCollection::range rangeHitsFromPhi1 = 
00078     all1DHits->get(DTRangeMapAccessor::layersBySuperLayer( DTSuperLayerId(theChamber->id(),1) ) );
00079   DTRecHitCollection::range rangeHitsFromPhi2 = 
00080     all1DHits->get(DTRangeMapAccessor::layersBySuperLayer( DTSuperLayerId(theChamber->id(),3) ) );
00081 
00082   vector<DTRecHit1DPair> hitsFromPhi1(rangeHitsFromPhi1.first,rangeHitsFromPhi1.second);
00083   vector<DTRecHit1DPair> hitsFromPhi2(rangeHitsFromPhi2.first,rangeHitsFromPhi2.second);
00084   if(debug)
00085     cout<< "Number of DTRecHit1DPair in the SL 1 (Phi 1): " << hitsFromPhi1.size()<<endl
00086                                                                << "Number of DTRecHit1DPair in the SL 3 (Phi 2): " << hitsFromPhi2.size()<<endl;
00087 
00088   theHitsFromPhi1 = hitsFromPhi1;
00089   theHitsFromPhi2 = hitsFromPhi2;
00090 
00091   if(allDTRecHits){
00092     DTRecHitCollection::range rangeHitsFromTheta = 
00093       all1DHits->get(DTRangeMapAccessor::layersBySuperLayer( DTSuperLayerId(theChamber->id(),2) ) );
00094 
00095     vector<DTRecHit1DPair> hitsFromTheta(rangeHitsFromTheta.first,rangeHitsFromTheta.second);
00096     if(debug)
00097       cout<< "Number of DTRecHit1DPair in the SL 2 (Theta): " << hitsFromTheta.size()<<endl;
00098     theHitsFromTheta = hitsFromTheta;
00099   }
00100 
00101 }
00102 
00103 void DTMeantimerPatternReco4D::setDTRecSegment2DContainer(Handle<DTRecSegment2DCollection> all2DSegments){
00104   theSegments2DTheta.clear();
00105 
00106   if(!allDTRecHits){
00107 
00108     //Extract the DTRecSegment2DCollection range for the theta SL
00109     DTRecSegment2DCollection::range rangeTheta = 
00110       all2DSegments->get(DTSuperLayerId(theChamber->id(),2));
00111 
00112     // Fill the DTRecSegment2D container for the theta SL
00113     vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first,rangeTheta.second);
00114 
00115     if(debug)
00116       cout << "Number of 2D-segments in the second SL (Theta): " << segments2DTheta.size() << endl;
00117     theSegments2DTheta = segments2DTheta;
00118   }
00119 
00120 }
00121 
00122 
00123 OwnVector<DTRecSegment4D>
00124 DTMeantimerPatternReco4D::reconstruct(){
00125 
00126   OwnVector<DTRecSegment4D> result;
00127 
00128   if (debug){ 
00129     cout << "Segments in " << theChamber->id() << endl;
00130     cout << "Reconstructing Phi segments"<<endl;
00131   }
00132   vector<DTSegmentCand*> resultPhi = buildPhiSuperSegmentsCandidates();
00133 
00134   if (debug) cout << "There are " << resultPhi.size() << " Phi cand" << endl;
00135 
00136   if (allDTRecHits){
00137     // take the theta SL of this chamber
00138     const DTSuperLayer* sl = theChamber->superLayer(2);
00139     // sl points to 0 if the theta SL was not found
00140     if(sl){
00141       // reconstruct the theta segments
00142       if(debug) cout << "Reconstructing Theta segments"<<endl;
00143       OwnVector<DTSLRecSegment2D> thetaSegs = the2DAlgo->reconstruct(sl, theHitsFromTheta);
00144       vector<DTSLRecSegment2D> segments2DTheta(thetaSegs.begin(),thetaSegs.end());
00145       theSegments2DTheta = segments2DTheta;
00146     }
00147   }
00148 
00149   bool hasZed=false;
00150 
00151   // has this chamber the Z-superlayer?
00152   if (theSegments2DTheta.size()){
00153     hasZed = theSegments2DTheta.size()>0;
00154     if (debug) cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
00155   } else {
00156     if (debug) cout << "No Theta SL" << endl;
00157   }
00158 
00159   // Now I want to build the concrete DTRecSegment4D.
00160   if(debug) cout<<"Building the concrete DTRecSegment4D"<<endl;
00161   if (resultPhi.size()) {
00162     for (vector<DTSegmentCand*>::const_iterator phi=resultPhi.begin();
00163          phi!=resultPhi.end(); ++phi) {
00164 
00165       DTChamberRecSegment2D* superPhi = (**phi);
00166 
00167       theUpdator->update(superPhi);
00168 
00169       if (hasZed) {
00170 
00171         // Create all the 4D-segment combining the Z view with the Phi one
00172         // loop over the Z segments
00173         for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
00174             zed != theSegments2DTheta.end(); ++zed){
00175 
00176           // Important!!
00177           DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
00178 
00179           // Put the theta segment poistion in its 3D place.
00180           // note: (superPhi is in the CHAMBER local frame)
00181           const DTSuperLayer* zSL = theChamber->superLayer(ZedSegSLId);
00182 
00183           // FIXME: should rather extrapolate for Y!
00184           LocalPoint zPos(zed->localPosition().x(), 
00185                          (zSL->toLocal(theChamber->toGlobal(superPhi->localPosition()))).y(),
00186                          0.);
00187 
00188           const LocalPoint posZInCh  = theChamber->toLocal( zSL->toGlobal(zPos));
00189           // FIXME: zed->localDirection() is in 2D. Should add the phi direction in the orthogonal plane as well!!
00190           const LocalVector dirZInCh = theChamber->toLocal( zSL->toGlobal(zed->localDirection()));
00191 
00192           DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi,*zed,posZInCh,dirZInCh);
00193           //<<
00194 
00196           theUpdator->update(newSeg);
00197           if (debug) cout << "Created a 4D seg " << *newSeg << endl;
00198           result.push_back(newSeg);
00199         }
00200       } else {
00201         // Only phi
00202         DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi);
00203 
00204         if (debug) cout << "Created a 4D segment using only the 2D Phi segment" << endl;
00205         result.push_back(newSeg);
00206       }
00207     }
00208   } else { 
00209     // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
00210     if (hasZed) {
00211       for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
00212           zed != theSegments2DTheta.end(); ++zed){
00213 
00214         // Important!!
00215         DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
00216 
00217         const LocalPoint posZInCh  = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
00218         const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
00219 
00220         DTRecSegment4D* newSeg = new DTRecSegment4D( *zed,posZInCh,dirZInCh);
00221         // <<
00222 
00223         if (debug) cout << "Created a 4D segment using only the 2D Theta segment" << endl;
00224         result.push_back(newSeg);
00225       }
00226     }
00227   }
00228   // finally delete the candidates!
00229   for (vector<DTSegmentCand*>::iterator phi=resultPhi.begin();
00230        phi!=resultPhi.end(); ++phi) delete *phi;
00231 
00232   return result;
00233 }
00234 
00235 
00236 
00237 vector<DTSegmentCand*> DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates(){
00238 
00239   DTSuperLayerId slId;
00240 
00241   if(theHitsFromPhi1.size())
00242     slId = theHitsFromPhi1.front().wireId().superlayerId();
00243   else
00244     if(theHitsFromPhi2.size())
00245       slId = theHitsFromPhi2.front().wireId().superlayerId();
00246     else{
00247       if(debug) cout<<"DTMeantimerPatternReco4D::buildPhiSuperSegmentsCandidates: "
00248         <<"No Hits in the two Phi SL"<<endl;
00249       return vector<DTSegmentCand*>();
00250     }
00251 
00252   const DTSuperLayer *sl = theDTGeometry->superLayer(slId);
00253 
00254   vector<DTHitPairForFit*> pairPhi1 = the2DAlgo->initHits(sl,theHitsFromPhi1);
00255   // same sl!! Since the fit will be in the sl phi 1!
00256   vector<DTHitPairForFit*> pairPhi2 = the2DAlgo->initHits(sl,theHitsFromPhi2);
00257   // copy the pairPhi2 in the pairPhi1 vector 
00258   copy(pairPhi2.begin(),pairPhi2.end(),back_inserter(pairPhi1));
00259 
00260   // Build the segment candidate
00261   return the2DAlgo->buildSegments(sl,pairPhi1);
00262 }