CMS 3D CMS Logo

DTCombinatorialPatternReco4D.cc

Go to the documentation of this file.
00001 
00008 #include "RecoLocalMuon/DTSegment/src/DTCombinatorialPatternReco4D.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/DTCombinatorialPatternReco.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 DTCombinatorialPatternReco4D::DTCombinatorialPatternReco4D(const ParameterSet& pset):
00035   DTRecSegment4DBaseAlgo(pset), theAlgoName("DTCombinatorialPatternReco4D"){
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 DTCombinatorialPatternReco(pset.getParameter<ParameterSet>("Reco2DAlgoConfig"));
00053 }
00054 
00055 DTCombinatorialPatternReco4D::~DTCombinatorialPatternReco4D(){
00056   delete the2DAlgo;
00057   delete theUpdator;
00058 }
00059 
00060 void DTCombinatorialPatternReco4D::setES(const EventSetup& setup){
00061   setup.get<MuonGeometryRecord>().get(theDTGeometry);
00062   the2DAlgo->setES(setup);
00063   theUpdator->setES(setup);
00064 }
00065 
00066 void DTCombinatorialPatternReco4D::setChamber(const DTChamberId &chId){
00067   // Set the chamber
00068   theChamber = theDTGeometry->chamber(chId); 
00069 }
00070 
00071 void DTCombinatorialPatternReco4D::setDTRecHit1DContainer(Handle<DTRecHitCollection> all1DHits){
00072   theHitsFromPhi1.clear();
00073   theHitsFromPhi2.clear();
00074   theHitsFromTheta.clear();
00075 
00076   DTRecHitCollection::range rangeHitsFromPhi1 = 
00077     all1DHits->get(DTRangeMapAccessor::layersBySuperLayer( DTSuperLayerId(theChamber->id(),1) ) );
00078   DTRecHitCollection::range rangeHitsFromPhi2 = 
00079     all1DHits->get(DTRangeMapAccessor::layersBySuperLayer( DTSuperLayerId(theChamber->id(),3) ) );
00080 
00081   vector<DTRecHit1DPair> hitsFromPhi1(rangeHitsFromPhi1.first,rangeHitsFromPhi1.second);
00082   vector<DTRecHit1DPair> hitsFromPhi2(rangeHitsFromPhi2.first,rangeHitsFromPhi2.second);
00083   if(debug)
00084     cout<< "Number of DTRecHit1DPair in the SL 1 (Phi 1): " << hitsFromPhi1.size()<<endl
00085         << "Number of DTRecHit1DPair in the SL 3 (Phi 2): " << hitsFromPhi2.size()<<endl;
00086   
00087   theHitsFromPhi1 = hitsFromPhi1;
00088   theHitsFromPhi2 = hitsFromPhi2;
00089 
00090   if(allDTRecHits){
00091     DTRecHitCollection::range rangeHitsFromTheta = 
00092       all1DHits->get(DTRangeMapAccessor::layersBySuperLayer( DTSuperLayerId(theChamber->id(),2) ) );
00093     
00094     vector<DTRecHit1DPair> hitsFromTheta(rangeHitsFromTheta.first,rangeHitsFromTheta.second);
00095     if(debug)
00096       cout<< "Number of DTRecHit1DPair in the SL 2 (Theta): " << hitsFromTheta.size()<<endl;
00097     theHitsFromTheta = hitsFromTheta;
00098   }
00099 
00100 }
00101 
00102 void DTCombinatorialPatternReco4D::setDTRecSegment2DContainer(Handle<DTRecSegment2DCollection> all2DSegments){
00103   theSegments2DTheta.clear();
00104 
00105   if(!allDTRecHits){
00106 
00107     //Extract the DTRecSegment2DCollection range for the theta SL
00108     DTRecSegment2DCollection::range rangeTheta = 
00109       all2DSegments->get(DTSuperLayerId(theChamber->id(),2));
00110     
00111     // Fill the DTRecSegment2D container for the theta SL
00112     vector<DTSLRecSegment2D> segments2DTheta(rangeTheta.first,rangeTheta.second);
00113     
00114     if(debug)
00115       cout << "Number of 2D-segments in the second SL (Theta): " << segments2DTheta.size() << endl;
00116     theSegments2DTheta = segments2DTheta;
00117   }
00118 
00119 }
00120 
00121   
00122 OwnVector<DTRecSegment4D>
00123 DTCombinatorialPatternReco4D::reconstruct(){
00124 
00125   OwnVector<DTRecSegment4D> result;
00126   
00127   if (debug){ 
00128     cout << "Segments in " << theChamber->id() << endl;
00129     cout<<"Reconstructing of the Phi segments"<<endl;
00130   }
00131 
00132   vector<DTHitPairForFit*> pairPhiOwned;
00133   vector<DTSegmentCand*> resultPhi = buildPhiSuperSegmentsCandidates(pairPhiOwned);
00134   
00135   if (debug) cout << "There are " << resultPhi.size() << " Phi cand" << endl;
00136   
00137   if (allDTRecHits){
00138     // take the theta SL of this chamber
00139     const DTSuperLayer* sl = theChamber->superLayer(2);
00140     // sl points to 0 if the theta SL was not found
00141     if(sl){
00142       // reconstruct the theta segments
00143       if(debug) cout<<"Reconstructing of the Theta segments"<<endl;
00144       OwnVector<DTSLRecSegment2D> thetaSegs = the2DAlgo->reconstruct(sl, theHitsFromTheta);
00145       vector<DTSLRecSegment2D> segments2DTheta(thetaSegs.begin(),thetaSegs.end());
00146       theSegments2DTheta = segments2DTheta;
00147     }
00148   }
00149   
00150   bool hasZed=false;
00151   
00152   // has this chamber the Z-superlayer?
00153   if (theSegments2DTheta.size()){
00154     hasZed = theSegments2DTheta.size()>0;
00155     if (debug) cout << "There are " << theSegments2DTheta.size() << " Theta cand" << endl;
00156   } else {
00157     if (debug) cout << "No Theta SL" << endl;
00158   }
00159 
00160   // Now I want to build the concrete DTRecSegment4D.
00161   if(debug) cout<<"Building of the concrete DTRecSegment4D"<<endl;
00162   if (resultPhi.size()) {
00163     for (vector<DTSegmentCand*>::const_iterator phi=resultPhi.begin();
00164          phi!=resultPhi.end(); ++phi) {
00165       
00166       std::auto_ptr<DTChamberRecSegment2D> superPhi(**phi);
00167       
00168       theUpdator->update(superPhi.get());
00169       
00170       if (hasZed) {
00171 
00172         // Create all the 4D-segment combining the Z view with the Phi one
00173         // loop over the Z segments
00174         for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
00175             zed != theSegments2DTheta.end(); ++zed){
00176           
00177           // Important!!
00178           DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
00179           
00180           const LocalPoint posZInCh  = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
00181           const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
00182         
00183           DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi,*zed,posZInCh,dirZInCh);
00184           //<<
00185   
00187           theUpdator->update(newSeg);
00188           if (debug) cout << "Created a 4D seg " << endl;
00189           result.push_back(newSeg);
00190         }
00191       } else {
00192         // Only phi
00193         DTRecSegment4D* newSeg = new DTRecSegment4D(*superPhi);
00194         
00195         if (debug) cout << "Created a 4D segment using only the 2D Phi segment" << endl;
00196         result.push_back(newSeg);
00197       }
00198     }
00199   } else { 
00200     // DTRecSegment4D from zed projection only (unlikely, not so useful, but...)
00201     if (hasZed) {
00202       for(vector<DTSLRecSegment2D>::const_iterator zed = theSegments2DTheta.begin();
00203           zed != theSegments2DTheta.end(); ++zed){
00204         
00205         // Important!!
00206         DTSuperLayerId ZedSegSLId(zed->geographicalId().rawId());
00207           
00208         const LocalPoint posZInCh  = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localPosition() )) ;
00209         const LocalVector dirZInCh = theChamber->toLocal( theChamber->superLayer(ZedSegSLId)->toGlobal(zed->localDirection() )) ;
00210         
00211         DTRecSegment4D* newSeg = new DTRecSegment4D( *zed,posZInCh,dirZInCh);
00212         // <<
00213         
00214         if (debug) cout << "Created a 4D segment using only the 2D Theta segment" << endl;
00215         result.push_back(newSeg);
00216       }
00217     }
00218   }
00219   // finally delete the candidates!
00220   for (vector<DTSegmentCand*>::iterator phi=resultPhi.begin();
00221        phi!=resultPhi.end(); ++phi) delete *phi;
00222   for (vector<DTHitPairForFit*>::iterator phiPair = pairPhiOwned.begin();
00223        phiPair!=pairPhiOwned.end(); ++phiPair) delete *phiPair;
00224   return result;
00225 }
00226 
00227 
00228 
00229 vector<DTSegmentCand*> DTCombinatorialPatternReco4D::buildPhiSuperSegmentsCandidates(vector<DTHitPairForFit*> &pairPhiOwned){
00230   
00231   DTSuperLayerId slId;
00232 
00233   if(theHitsFromPhi1.size())
00234     slId = theHitsFromPhi1.front().wireId().superlayerId();
00235   else
00236     if(theHitsFromPhi2.size())
00237       slId = theHitsFromPhi2.front().wireId().superlayerId();
00238     else{
00239       if(debug) cout<<"DTCombinatorialPatternReco4D::buildPhiSuperSegmentsCandidates: "
00240                     <<"No Hits in the two Phi SL"<<endl;
00241       return vector<DTSegmentCand*>();
00242     }
00243 
00244   const DTSuperLayer *sl = theDTGeometry->superLayer(slId);
00245   
00246   vector<DTHitPairForFit*> pairPhi1 = the2DAlgo->initHits(sl,theHitsFromPhi1);
00247   // same sl!! Since the fit will be in the sl phi 1!
00248   vector<DTHitPairForFit*> pairPhi2 = the2DAlgo->initHits(sl,theHitsFromPhi2);
00249   // copy the pairPhi2 in the pairPhi1 vector 
00250   copy(pairPhi2.begin(),pairPhi2.end(),back_inserter(pairPhi1));
00251 
00252   pairPhiOwned.swap(pairPhi1);
00253   // Build the segment candidate
00254   return the2DAlgo->buildSegments(sl,pairPhiOwned);
00255 }

Generated on Tue Jun 9 17:43:53 2009 for CMSSW by  doxygen 1.5.4