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
00024 int chosenAlgo = ps.getParameter<int>("algo_type") - 1;
00025
00026
00027 std::vector<edm::ParameterSet> algoPSets = ps.getParameter<std::vector<edm::ParameterSet> >("algo_psets");
00028
00029
00030
00031 std::string algoName = algoPSets[chosenAlgo].getParameter<std::string>("algo_name");
00032
00033 LogDebug("CSCSegment|CSC")<< "CSCSegmentBuilder algorithm name: " << algoName;
00034
00035
00036 std::vector<edm::ParameterSet> segAlgoPSet = algoPSets[chosenAlgo].getParameter<std::vector<edm::ParameterSet> >("algo_psets");
00037
00038
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
00043 std::vector<int> algoToType = algoPSets[chosenAlgo].getParameter<std::vector<int> >("parameters_per_chamber_type");
00044
00045
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
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
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
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
00113 oc.put((*chIt), segv.begin(), segv.end());
00114 }
00115 }
00116
00117 void CSCSegmentBuilder::setGeometry(const CSCGeometry* geom) {
00118 geom_ = geom;
00119 }
00120