CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10/src/RecoLocalMuon/CSCSegment/src/CSCSegmentBuilder.cc

Go to the documentation of this file.
00001 
00007 #include <RecoLocalMuon/CSCSegment/src/CSCSegmentBuilder.h>
00008 #include <Geometry/CSCGeometry/interface/CSCChamberSpecs.h>
00009 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
00010 #include <Geometry/CSCGeometry/interface/CSCGeometry.h>
00011 #include <DataFormats/MuonDetId/interface/CSCDetId.h>
00012 #include <DataFormats/CSCRecHit/interface/CSCRecHit2D.h>
00013 #include <DataFormats/CSCRecHit/interface/CSCRangeMapAccessor.h>
00014 
00015 #include <RecoLocalMuon/CSCSegment/src/CSCSegmentAlgorithm.h>
00016 #include <RecoLocalMuon/CSCSegment/src/CSCSegmentBuilderPluginFactory.h>
00017 
00018 #include <FWCore/Utilities/interface/Exception.h>
00019 #include <FWCore/MessageLogger/interface/MessageLogger.h> 
00020 
00021 CSCSegmentBuilder::CSCSegmentBuilder(const edm::ParameterSet& ps) : geom_(0) {
00022     
00023     // The algo chosen for the segment building
00024     int chosenAlgo = ps.getParameter<int>("algo_type") - 1;
00025     
00026     // Find appropriate ParameterSets for each algo type
00027     std::vector<edm::ParameterSet> algoPSets = ps.getParameter<std::vector<edm::ParameterSet> >("algo_psets");
00028 
00029     // Now load the right parameter set
00030     // Algo name
00031     std::string algoName = algoPSets[chosenAlgo].getParameter<std::string>("algo_name");
00032         
00033     LogDebug("CSCSegment|CSC")<< "CSCSegmentBuilder algorithm name: " << algoName;
00034 
00035     // SegAlgo parameter set
00036     std::vector<edm::ParameterSet> segAlgoPSet = algoPSets[chosenAlgo].getParameter<std::vector<edm::ParameterSet> >("algo_psets");
00037 
00038     // Chamber types to handle
00039     std::vector<std::string> chType = algoPSets[chosenAlgo].getParameter<std::vector<std::string> >("chamber_types");
00040     LogDebug("CSCSegment|CSC")<< "No. of chamber types to handle: " << chType.size();
00041 
00042     // Algo to chamber type 
00043     std::vector<int> algoToType = algoPSets[chosenAlgo].getParameter<std::vector<int> >("parameters_per_chamber_type");
00044 
00045     // Trap if we don't have enough parameter sets or haven't assigned an algo to every type   
00046     if (algoToType.size() !=  chType.size()) {
00047         throw cms::Exception("ParameterSetError") << 
00048           "#dim algosToType=" << algoToType.size() << ", #dim chType=" << chType.size() << std::endl;
00049     }
00050 
00051     // Ask factory to build this algorithm, giving it appropriate ParameterSet
00052             
00053     for (size_t j=0; j<chType.size(); ++j) {
00054         algoMap[chType[j]] = CSCSegmentBuilderPluginFactory::get()->
00055                 create(algoName, segAlgoPSet[algoToType[j]-1]);
00056         LogDebug("CSCSegment|CSC")<< "using algorithm #" << algoToType[j] << " for chamber type " << chType[j];
00057     }
00058 }
00059 
00060 CSCSegmentBuilder::~CSCSegmentBuilder() {
00061   //
00062   // loop on algomap and delete them
00063   //
00064   for (std::map<std::string, CSCSegmentAlgorithm*>::iterator it = algoMap.begin();it != algoMap.end(); it++){
00065     delete ((*it).second);
00066   }
00067 }
00068 
00069 void CSCSegmentBuilder::build(const CSCRecHit2DCollection* recHits, CSCSegmentCollection& oc) {
00070         
00071   LogDebug("CSCSegment|CSC")<< "Total number of rechits in this event: " << recHits->size();
00072 
00073     std::vector<CSCDetId> chambers;
00074     std::vector<CSCDetId>::const_iterator chIt;
00075     
00076     for(CSCRecHit2DCollection::const_iterator it2 = recHits->begin(); it2 != recHits->end(); it2++) {
00077         
00078         bool insert = true;
00079         for(chIt=chambers.begin(); chIt != chambers.end(); ++chIt) 
00080             if (((*it2).cscDetId().chamber() == (*chIt).chamber()) &&
00081                 ((*it2).cscDetId().station() == (*chIt).station()) &&
00082                 ((*it2).cscDetId().ring() == (*chIt).ring()) &&
00083                 ((*it2).cscDetId().endcap() == (*chIt).endcap()))
00084                 insert = false;
00085         
00086         if (insert)
00087             chambers.push_back((*it2).cscDetId().chamberId());
00088     }
00089 
00090     for(chIt=chambers.begin(); chIt != chambers.end(); ++chIt) {
00091 
00092         std::vector<const CSCRecHit2D*> cscRecHits;
00093         const CSCChamber* chamber = geom_->chamber(*chIt);
00094         
00095         CSCRangeMapAccessor acc;
00096         CSCRecHit2DCollection::range range = recHits->get(acc.cscChamber(*chIt));
00097         
00098         std::vector<int> hitPerLayer(6);
00099         for(CSCRecHit2DCollection::const_iterator rechit = range.first; rechit != range.second; rechit++) {
00100             
00101             hitPerLayer[(*rechit).cscDetId().layer()-1]++;
00102             cscRecHits.push_back(&(*rechit));
00103         }    
00104         
00105         LogDebug("CSCSegment|CSC") << "found " << cscRecHits.size() << " rechits in chamber " << *chIt;
00106             
00107         // given the chamber select the appropriate algo... and run it
00108         std::vector<CSCSegment> segv = algoMap[chamber->specs()->chamberTypeName()]->run(chamber, cscRecHits);
00109 
00110         LogDebug("CSCSegment|CSC") << "found " << segv.size() << " segments in chamber " << *chIt;
00111 
00112         // Add the segments to master collection
00113         oc.put((*chIt), segv.begin(), segv.end());
00114     }
00115 }
00116 
00117 void CSCSegmentBuilder::setGeometry(const CSCGeometry* geom) {
00118         geom_ = geom;
00119 }
00120