CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoMuon/MuonIdentification/plugins/MuonProducer.cc

Go to the documentation of this file.
00001 
00009 #include "RecoMuon/MuonIdentification/plugins/MuonProducer.h"
00010 
00011 #include "RecoMuon/MuonIsolation/interface/MuPFIsoHelper.h"
00012 
00013 #include "FWCore/Framework/interface/Event.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 #include "DataFormats/MuonReco/interface/Muon.h"
00019 #include "DataFormats/MuonReco/interface/MuonTrackLinks.h"
00020 #include "DataFormats/MuonReco/interface/MuonTimeExtraMap.h"
00021 #include "DataFormats/MuonReco/interface/MuonShower.h"
00022 #include "DataFormats/MuonReco/interface/MuonCosmicCompatibility.h"
00023 #include "DataFormats/MuonReco/interface/MuonToMuonMap.h"
00024 
00025 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00026 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00027 
00028 #include "DataFormats/Common/interface/ValueMap.h"
00029 #include "DataFormats/RecoCandidate/interface/IsoDepositFwd.h"
00030 #include "DataFormats/RecoCandidate/interface/IsoDeposit.h"
00031 
00032 #include <boost/foreach.hpp>
00033 #define foreach BOOST_FOREACH
00034 
00035 #ifndef dout
00036 #define dout if(debug_) std::cout
00037 #endif
00038 
00039 using std::endl;
00040 
00041 typedef std::map<reco::MuonRef, unsigned int> MuToPFMap;
00042 
00043 
00044 namespace reco {
00045   typedef edm::ValueMap<reco::MuonShower> MuonShowerMap;
00046 }
00047 
00048 
00050 MuonProducer::MuonProducer(const edm::ParameterSet& pSet):debug_(pSet.getUntrackedParameter<bool>("ActivateDebug",false)){
00051   
00052   setAlias(pSet.getParameter<std::string>("@module_label"));
00053   
00054   fastLabelling_ = pSet.getUntrackedParameter<bool>("FastLabelling",true);
00055 
00056   
00057   theMuonsCollectionLabel = pSet.getParameter<edm::InputTag>("InputMuons");
00058   thePFCandLabel = pSet.getParameter<edm::InputTag>("PFCandidates");
00059   
00060   
00061   // Variables to switch on-off the differnt parts
00062   fillSelectors_              = pSet.getParameter<bool>("FillSelectorMaps");
00063   fillCosmicsIdMap_           = pSet.getParameter<bool>("FillCosmicsIdMap");
00064   fillPFMomentum_             = pSet.getParameter<bool>("FillPFMomentumAndAssociation");
00065   fillPFIsolation_            = pSet.getParameter<bool>("FillPFIsolation");
00066   fillDetectorBasedIsolation_ = pSet.getParameter<bool>("FillDetectorBasedIsolation"); 
00067   fillShoweringInfo_          = pSet.getParameter<bool>("FillShoweringInfo");
00068   fillTimingInfo_             = pSet.getParameter<bool>("FillTimingInfo");
00069 
00070   produces<reco::MuonCollection>();
00071 
00072   if(fillTimingInfo_){
00073     produces<reco::MuonTimeExtraMap>("combined");
00074     produces<reco::MuonTimeExtraMap>("dt");
00075     produces<reco::MuonTimeExtraMap>("csc");
00076   }
00077   
00078   if (fillDetectorBasedIsolation_){
00079     theTrackDepositName = pSet.getParameter<edm::InputTag>("TrackIsoDeposits");
00080     produces<reco::IsoDepositMap>(labelOrInstance(theTrackDepositName));
00081     theJetDepositName = pSet.getParameter<edm::InputTag>("JetIsoDeposits");
00082     produces<reco::IsoDepositMap>(labelOrInstance(theJetDepositName));
00083     theEcalDepositName = pSet.getParameter<edm::InputTag>("EcalIsoDeposits");
00084     produces<reco::IsoDepositMap>(theEcalDepositName.instance());
00085     theHcalDepositName = pSet.getParameter<edm::InputTag>("HcalIsoDeposits");
00086     produces<reco::IsoDepositMap>(theHcalDepositName.instance());
00087     theHoDepositName = pSet.getParameter<edm::InputTag>("HoIsoDeposits");
00088     produces<reco::IsoDepositMap>(theHoDepositName.instance());
00089   }
00090   
00091   if(fillSelectors_){
00092     theSelectorMapNames = pSet.getParameter<InputTags>("SelectorMaps");
00093     
00094     for(InputTags::const_iterator tag = theSelectorMapNames.begin(); tag != theSelectorMapNames.end(); ++tag)
00095       produces<edm::ValueMap<bool> >(labelOrInstance(*tag));
00096   }
00097   
00098   if(fillShoweringInfo_){
00099     theShowerMapName = pSet.getParameter<edm::InputTag>("ShowerInfoMap");
00100     produces<edm::ValueMap<reco::MuonShower> >(labelOrInstance(theShowerMapName));
00101   }
00102   
00103   if(fillCosmicsIdMap_){
00104     theCosmicCompMapName = pSet.getParameter<edm::InputTag>("CosmicIdMap");
00105     produces<edm::ValueMap<reco::MuonCosmicCompatibility> >(labelOrInstance(theCosmicCompMapName));
00106     produces<edm::ValueMap<unsigned int> >(labelOrInstance(theCosmicCompMapName));
00107   }
00108   
00109   theMuToMuMapName = theMuonsCollectionLabel.label()+"2"+theAlias+"sMap";
00110   produces<edm::ValueMap<reco::MuonRef> >(theMuToMuMapName);
00111 
00112 
00113 
00114   
00115   if(fillPFIsolation_){
00116     
00117     edm::ParameterSet pfIsoPSet = pSet.getParameter<edm::ParameterSet >("PFIsolation");
00118 
00119     //Define a map between the isolation and the PSet for the PFHelper
00120     std::map<std::string,edm::ParameterSet> psetMap;
00121 
00122     //First declare what isolation you are going to read
00123     std::vector<std::string> isolationLabels;
00124     isolationLabels.push_back("pfIsolationR03");
00125     isolationLabels.push_back("pfIsoMeanDRProfileR03");
00126     isolationLabels.push_back("pfIsoSumDRProfileR03");
00127     isolationLabels.push_back("pfIsolationR04");
00128     isolationLabels.push_back("pfIsoMeanDRProfileR04");
00129     isolationLabels.push_back("pfIsoSumDRProfileR04");
00130 
00131     //Fill the label,pet map and initialize MuPFIsoHelper
00132     for( std::vector<std::string>::const_iterator label = isolationLabels.begin();label != isolationLabels.end();++label)
00133       psetMap[*label] =pfIsoPSet.getParameter<edm::ParameterSet >(*label); 
00134     thePFIsoHelper = new MuPFIsoHelper(psetMap);
00135 
00136     //Now loop on the mass read for each PSet the parameters and save them to the mapNames for later
00137 
00138     for(std::map<std::string,edm::ParameterSet>::const_iterator map = psetMap.begin();map!= psetMap.end();++map) {
00139       std::map<std::string,edm::InputTag> isoMap;
00140       isoMap["chargedParticle"]              = map->second.getParameter<edm::InputTag>("chargedParticle");
00141       isoMap["chargedHadron"]                = map->second.getParameter<edm::InputTag>("chargedHadron");
00142       isoMap["neutralHadron"]                = map->second.getParameter<edm::InputTag>("neutralHadron");
00143       isoMap["neutralHadronHighThreshold"]   = map->second.getParameter<edm::InputTag>("neutralHadronHighThreshold");
00144       isoMap["photon"]                       = map->second.getParameter<edm::InputTag>("photon");
00145       isoMap["photonHighThreshold"]          = map->second.getParameter<edm::InputTag>("photonHighThreshold");
00146       isoMap["pu"]                           = map->second.getParameter<edm::InputTag>("pu");
00147       pfIsoMapNames.push_back(isoMap);
00148     }
00149 
00150 
00151     for(unsigned int j=0;j<pfIsoMapNames.size();++j) {
00152       for(std::map<std::string,edm::InputTag>::const_iterator map = pfIsoMapNames.at(j).begin(); map != pfIsoMapNames.at(j).end(); ++map)
00153         produces<edm::ValueMap<double> >(labelOrInstance(map->second));
00154 
00155     }
00156     
00157   }
00158 }
00159 
00161 MuonProducer::~MuonProducer(){ 
00162   if (thePFIsoHelper && fillPFIsolation_) delete thePFIsoHelper;
00163 }
00164 
00165 
00167 void MuonProducer::produce(edm::Event& event, const edm::EventSetup& eventSetup){
00168 
00169    const std::string metname = "Muon|RecoMuon|MuonIdentification|MuonProducer";
00170 
00171    // the muon collection, it will be loaded in the event
00172    std::auto_ptr<reco::MuonCollection> outputMuons(new reco::MuonCollection());
00173    reco::MuonRefProd outputMuonsRefProd = event.getRefBeforePut<reco::MuonCollection>();
00174 
00175    edm::Handle<reco::MuonCollection> inputMuons; 
00176    event.getByLabel(theMuonsCollectionLabel, inputMuons);
00177    edm::OrphanHandle<reco::MuonCollection> inputMuonsOH(inputMuons.product(), inputMuons.id());
00178    
00179    edm::Handle<reco::PFCandidateCollection> pfCandidates; 
00180    event.getByLabel(thePFCandLabel, pfCandidates);
00181 
00182 
00183    // fetch collections for PFIso
00184    if(fillPFIsolation_) thePFIsoHelper->beginEvent(event);
00185 
00186    
00187    // Fill timing information
00188    edm::Handle<reco::MuonTimeExtraMap> timeMapCmb;
00189    edm::Handle<reco::MuonTimeExtraMap> timeMapDT;
00190    edm::Handle<reco::MuonTimeExtraMap> timeMapCSC;
00191    
00192    int nMuons=inputMuons->size();
00193 
00194    std::vector<reco::MuonTimeExtra> dtTimeColl(nMuons);
00195    std::vector<reco::MuonTimeExtra> cscTimeColl(nMuons);
00196    std::vector<reco::MuonTimeExtra> combinedTimeColl(nMuons);
00197 
00198    if(fillTimingInfo_){
00199      event.getByLabel(theMuonsCollectionLabel.label(),"combined",timeMapCmb);
00200      event.getByLabel(theMuonsCollectionLabel.label(),"dt",timeMapDT);
00201      event.getByLabel(theMuonsCollectionLabel.label(),"csc",timeMapCSC);
00202    }
00203 
00204    std::vector<reco::IsoDeposit> trackDepColl(nMuons);
00205    std::vector<reco::IsoDeposit> ecalDepColl(nMuons);
00206    std::vector<reco::IsoDeposit> hcalDepColl(nMuons);
00207    std::vector<reco::IsoDeposit> hoDepColl(nMuons);
00208    std::vector<reco::IsoDeposit> jetDepColl(nMuons);
00209 
00210 
00211    edm::Handle<reco::IsoDepositMap> trackIsoDepMap;
00212    edm::Handle<reco::IsoDepositMap> ecalIsoDepMap;
00213    edm::Handle<reco::IsoDepositMap> hcalIsoDepMap;
00214    edm::Handle<reco::IsoDepositMap> hoIsoDepMap;
00215    edm::Handle<reco::IsoDepositMap> jetIsoDepMap;
00216 
00217 
00218    if(fillDetectorBasedIsolation_){
00219      event.getByLabel(theTrackDepositName,trackIsoDepMap);
00220      event.getByLabel(theEcalDepositName,ecalIsoDepMap);
00221      event.getByLabel(theHcalDepositName,hcalIsoDepMap);
00222      event.getByLabel(theHoDepositName,hoIsoDepMap);
00223      event.getByLabel(theJetDepositName,jetIsoDepMap);
00224    }
00225 
00226    
00227 
00228    std::vector<std::map<std::string,edm::Handle<edm::ValueMap<double> > > > pfIsoMaps;
00229    std::vector<std::map<std::string,std::vector<double> > > pfIsoMapVals;
00230 
00231    if(fillPFIsolation_){
00232     for(unsigned int j=0;j<pfIsoMapNames.size();++j) {
00233         std::map<std::string,std::vector<double> > mapVals;
00234         std::map<std::string,edm::Handle<edm::ValueMap<double> > > maps;
00235         for(std::map<std::string,edm::InputTag>::const_iterator map = pfIsoMapNames.at(j).begin(); map != pfIsoMapNames.at(j).end(); ++map) {
00236           edm::Handle<edm::ValueMap<double> > handleTmp;
00237           event.getByLabel(map->second,handleTmp);
00238           maps[map->first]=handleTmp;
00239           mapVals[map->first].resize(nMuons);
00240         }
00241         pfIsoMapVals.push_back(mapVals);
00242         pfIsoMaps.push_back(maps);
00243 
00244     }
00245    }
00246 
00247 
00248    
00249    std::vector<edm::Handle<edm::ValueMap<bool> > >  selectorMaps(fillSelectors_ ? theSelectorMapNames.size() : 0); 
00250    std::vector<std::vector<bool> > selectorMapResults(fillSelectors_ ? theSelectorMapNames.size() : 0);
00251    if(fillSelectors_){
00252      unsigned int s=0;
00253      for(InputTags::const_iterator tag = theSelectorMapNames.begin(); tag != theSelectorMapNames.end(); ++tag, ++s){
00254        event.getByLabel(*tag,selectorMaps[s]);
00255        selectorMapResults[s].resize(nMuons);
00256      }
00257    }
00258 
00259    edm::Handle<reco::MuonShowerMap> showerInfoMap;
00260    if(fillShoweringInfo_) event.getByLabel(theShowerMapName,showerInfoMap);
00261 
00262    std::vector<reco::MuonShower> showerInfoColl(nMuons);
00263 
00264    edm::Handle<edm::ValueMap<unsigned int> > cosmicIdMap;
00265    if(fillCosmicsIdMap_) event.getByLabel(theCosmicCompMapName,cosmicIdMap);
00266    std::vector<unsigned int> cosmicIdColl(fillCosmicsIdMap_ ? nMuons : 0);
00267    
00268    edm::Handle<edm::ValueMap<reco::MuonCosmicCompatibility> > cosmicCompMap;
00269    if(fillCosmicsIdMap_) event.getByLabel(theCosmicCompMapName,cosmicCompMap);
00270    std::vector<reco::MuonCosmicCompatibility> cosmicCompColl(fillCosmicsIdMap_ ? nMuons : 0);
00271 
00272 
00273    std::vector<reco::MuonRef> muonRefColl(nMuons);
00274 
00275 
00276 
00277    if(inputMuons->empty()) {
00278      edm::OrphanHandle<reco::MuonCollection> muonHandle = event.put(outputMuons);
00279      
00280      if(fillTimingInfo_){
00281        fillMuonMap<reco::MuonTimeExtra>(event, muonHandle, combinedTimeColl,"combined");
00282        fillMuonMap<reco::MuonTimeExtra>(event, muonHandle, dtTimeColl,"dt");
00283        fillMuonMap<reco::MuonTimeExtra>(event, muonHandle, cscTimeColl,"csc");
00284      }
00285      
00286      if(fillDetectorBasedIsolation_){
00287        fillMuonMap<reco::IsoDeposit>(event, muonHandle, trackDepColl, labelOrInstance(theTrackDepositName));
00288        fillMuonMap<reco::IsoDeposit>(event, muonHandle, jetDepColl,   labelOrInstance(theJetDepositName));
00289        fillMuonMap<reco::IsoDeposit>(event, muonHandle, ecalDepColl,  theEcalDepositName.instance());
00290        fillMuonMap<reco::IsoDeposit>(event, muonHandle, hcalDepColl,  theHcalDepositName.instance());
00291        fillMuonMap<reco::IsoDeposit>(event, muonHandle, hoDepColl,    theHoDepositName.instance());
00292      }
00293 
00294      if(fillSelectors_){
00295        unsigned int s = 0;
00296        for(InputTags::const_iterator tag = theSelectorMapNames.begin(); 
00297            tag != theSelectorMapNames.end(); ++tag, ++s){
00298          fillMuonMap<bool>(event, muonHandle, selectorMapResults[s], labelOrInstance(*tag));
00299        }
00300      }
00301 
00302      if(fillShoweringInfo_) fillMuonMap<reco::MuonShower>(event, muonHandle, showerInfoColl, labelOrInstance(theShowerMapName));
00303 
00304      if(fillCosmicsIdMap_){
00305        fillMuonMap<unsigned int>(event, muonHandle, cosmicIdColl, labelOrInstance(theCosmicCompMapName));
00306        fillMuonMap<reco::MuonCosmicCompatibility>(event, muonHandle, cosmicCompColl, labelOrInstance(theCosmicCompMapName));
00307      }
00308 
00309      fillMuonMap<reco::MuonRef>(event,inputMuonsOH, muonRefColl, theMuToMuMapName);
00310 
00311      if(fillPFIsolation_){
00312        for(unsigned int j=0;j<pfIsoMapNames.size();++j) 
00313          for(std::map<std::string,edm::InputTag>::const_iterator map = pfIsoMapNames.at(j).begin(); map != pfIsoMapNames.at(j).end(); ++map) {
00314            fillMuonMap<double>(event, muonHandle, pfIsoMapVals.at(j)[map->first], labelOrInstance(map->second));
00315         }
00316      }
00317      return;
00318    }
00319    
00320    // FIXME: add the option to swith off the Muon-PF "info association".
00321    
00322 
00323    MuToPFMap muToPFMap;
00324 
00325    if(fillPFMomentum_){
00326      dout << "Number of PFCandidates: " << pfCandidates->size() << endl;
00327      for(unsigned int i=0;i< pfCandidates->size();++i)
00328        if(abs(pfCandidates->at(i).pdgId()) == 13){
00329          muToPFMap[pfCandidates->at(i).muonRef()] = i;
00330          dout << "MuonRef: " << pfCandidates->at(i).muonRef().id() << " " << pfCandidates->at(i).muonRef().key() << " PF p4: " << pfCandidates->at(i).p4() << endl;
00331        }
00332      dout << "Number of PFMuons: " << muToPFMap.size() << endl;
00333      dout << "Number of Muons in the original collection: " << inputMuons->size() << endl;
00334    }
00335 
00336    reco::MuonRef::key_type muIndex = 0;
00337    unsigned int i = 0;
00338    foreach(const reco::Muon &inMuon, *inputMuons){
00339      
00340      reco::MuonRef muRef(inputMuons, muIndex);
00341      muonRefColl[i] = reco::MuonRef(outputMuonsRefProd, muIndex++);
00342 
00343      // Copy the muon 
00344      reco::Muon outMuon = inMuon;
00345     
00346      if(fillPFMomentum_){ 
00347      // search for the corresponding pf candidate
00348        MuToPFMap::iterator iter =  muToPFMap.find(muRef);
00349        if(iter != muToPFMap.end()){
00350          outMuon.setPFP4(pfCandidates->at(iter->second).p4());
00351          outMuon.setP4(pfCandidates->at(iter->second).p4());//PF is the default
00352          outMuon.setBestTrack(pfCandidates->at(iter->second).bestMuonTrackType());
00353          muToPFMap.erase(iter);
00354          dout << "MuonRef: " << muRef.id() << " " << muRef.key() 
00355               << " Is it PF? " << outMuon.isPFMuon() 
00356               << " PF p4: " << outMuon.pfP4() << endl;
00357        }
00358        
00359        
00360        dout << "MuonRef: " << muRef.id() << " " << muRef.key() 
00361             << " Is it PF? " << outMuon.isPFMuon() << endl;
00362        
00363        dout << "GLB "  << outMuon.isGlobalMuon()
00364             << " TM "  << outMuon.isTrackerMuon()
00365             << " STA " << outMuon.isStandAloneMuon() 
00366             << " p4 "  << outMuon.p4() << endl;
00367      }
00368 
00369      // Add PF isolation info
00370      if(fillPFIsolation_){
00371        thePFIsoHelper->embedPFIsolation(outMuon,muRef);
00372 
00373        for(unsigned int j=0;j<pfIsoMapNames.size();++j) {
00374          for(std::map<std::string,edm::InputTag>::const_iterator map = pfIsoMapNames[j].begin(); map != pfIsoMapNames[j].end(); ++map){
00375            (pfIsoMapVals[j])[map->first][i] = (*pfIsoMaps[j][map->first])[muRef];
00376          }
00377        }
00378      }
00379      
00380      // Fill timing information   
00381      if(fillTimingInfo_){
00382        combinedTimeColl[i] = (*timeMapCmb)[muRef];
00383        dtTimeColl[i] = (*timeMapDT)[muRef];
00384        cscTimeColl[i] = (*timeMapCSC)[muRef];
00385      }
00386      
00387      if(fillDetectorBasedIsolation_){
00388        trackDepColl[i] = (*trackIsoDepMap)[muRef];
00389        ecalDepColl[i]  = (*ecalIsoDepMap)[muRef];
00390        hcalDepColl[i]  = (*hcalIsoDepMap)[muRef];
00391        hoDepColl[i]    = (*hoIsoDepMap)[muRef];
00392        jetDepColl[i]   = (*jetIsoDepMap)[muRef];;
00393      }
00394      
00395      if(fillSelectors_){
00396        unsigned int s = 0;
00397        for(InputTags::const_iterator tag = theSelectorMapNames.begin(); 
00398            tag != theSelectorMapNames.end(); ++tag, ++s)
00399          selectorMapResults[s][i] = (*selectorMaps[s])[muRef];
00400      }
00401 
00402      // Fill the Showering Info
00403      if(fillShoweringInfo_) showerInfoColl[i] = (*showerInfoMap)[muRef];
00404 
00405      if(fillCosmicsIdMap_){
00406        cosmicIdColl[i] = (*cosmicIdMap)[muRef];
00407        cosmicCompColl[i] = (*cosmicCompMap)[muRef];
00408      }
00409 
00410      outputMuons->push_back(outMuon); 
00411      ++i;
00412    }
00413    
00414    dout << "Number of Muons in the new muon collection: " << outputMuons->size() << endl;
00415    edm::OrphanHandle<reco::MuonCollection> muonHandle = event.put(outputMuons);
00416 
00417    if(fillTimingInfo_){
00418      fillMuonMap<reco::MuonTimeExtra>(event, muonHandle, combinedTimeColl,"combined");
00419      fillMuonMap<reco::MuonTimeExtra>(event, muonHandle, dtTimeColl,"dt");
00420      fillMuonMap<reco::MuonTimeExtra>(event, muonHandle, cscTimeColl,"csc");
00421    }
00422 
00423    if(fillDetectorBasedIsolation_){
00424      fillMuonMap<reco::IsoDeposit>(event, muonHandle, trackDepColl, labelOrInstance(theTrackDepositName));
00425      fillMuonMap<reco::IsoDeposit>(event, muonHandle, jetDepColl,   labelOrInstance(theJetDepositName));
00426      fillMuonMap<reco::IsoDeposit>(event, muonHandle, ecalDepColl,  theEcalDepositName.instance());
00427      fillMuonMap<reco::IsoDeposit>(event, muonHandle, hcalDepColl,  theHcalDepositName.instance());
00428      fillMuonMap<reco::IsoDeposit>(event, muonHandle, hoDepColl,    theHoDepositName.instance());
00429    }
00430    
00431    if(fillPFIsolation_){
00432 
00433      for(unsigned int j=0;j<pfIsoMapNames.size();++j) {
00434        for(std::map<std::string,edm::InputTag>::const_iterator map = pfIsoMapNames[j].begin(); map != pfIsoMapNames[j].end(); ++map) 
00435          fillMuonMap<double>(event, muonHandle, pfIsoMapVals[j][map->first], labelOrInstance(map->second));
00436      }
00437    }   
00438 
00439    if(fillSelectors_){
00440      unsigned int s = 0;
00441      for(InputTags::const_iterator tag = theSelectorMapNames.begin(); 
00442          tag != theSelectorMapNames.end(); ++tag, ++s)
00443        fillMuonMap<bool>(event, muonHandle, selectorMapResults[s], labelOrInstance(*tag));
00444    }
00445 
00446    if(fillShoweringInfo_) fillMuonMap<reco::MuonShower>(event, muonHandle, showerInfoColl, labelOrInstance(theShowerMapName));
00447 
00448    if(fillCosmicsIdMap_){
00449      fillMuonMap<unsigned int>(event, muonHandle, cosmicIdColl, labelOrInstance(theCosmicCompMapName));
00450      fillMuonMap<reco::MuonCosmicCompatibility>(event, muonHandle, cosmicCompColl, labelOrInstance(theCosmicCompMapName));
00451    }
00452 
00453    fillMuonMap<reco::MuonRef>(event,inputMuonsOH, muonRefColl, theMuToMuMapName);
00454    
00455  
00456 }
00457 
00458 
00459 
00460 template<typename TYPE>
00461 void MuonProducer::fillMuonMap(edm::Event& event,
00462                                const edm::OrphanHandle<reco::MuonCollection>& muonHandle,
00463                                const std::vector<TYPE>& muonExtra,
00464                                const std::string& label){
00465  
00466   typedef typename edm::ValueMap<TYPE>::Filler FILLER; 
00467 
00468   std::auto_ptr<edm::ValueMap<TYPE> > muonMap(new edm::ValueMap<TYPE>());
00469   if(!muonExtra.empty()){
00470     FILLER filler(*muonMap);
00471     filler.insert(muonHandle, muonExtra.begin(), muonExtra.end());
00472     filler.fill();
00473   }
00474   event.put(muonMap,label);
00475 }
00476 
00477 
00478 std::string MuonProducer::labelOrInstance(const edm::InputTag &input) const{
00479   if(fastLabelling_) return input.label();
00480 
00481   return input.label() != theMuonsCollectionLabel.label() ? input.label() : input.instance();
00482 }