CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/RecoLocalMuon/RPCRecHit/src/RPCRecHitProducer.cc

Go to the documentation of this file.
00001 
00008 #include "RPCRecHitProducer.h"
00009 
00010 
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 
00015 #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
00016 
00017 #include "Geometry/RPCGeometry/interface/RPCRoll.h"
00018 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00020 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00021 #include "DataFormats/RPCRecHit/interface/RPCRecHit.h"
00022 
00023 #include "RecoLocalMuon/RPCRecHit/interface/RPCRecHitBaseAlgo.h"
00024 #include "RecoLocalMuon/RPCRecHit/interface/RPCRecHitAlgoFactory.h"
00025 #include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
00026 
00027 #include "CondFormats/RPCObjects/interface/RPCMaskedStrips.h"
00028 #include "CondFormats/DataRecord/interface/RPCMaskedStripsRcd.h"
00029 #include "CondFormats/RPCObjects/interface/RPCDeadStrips.h"
00030 #include "CondFormats/DataRecord/interface/RPCDeadStripsRcd.h"
00031 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00032 
00033 #include <string>
00034 
00035 
00036 using namespace edm;
00037 using namespace std;
00038 
00039 
00040 RPCRecHitProducer::RPCRecHitProducer(const ParameterSet& config){
00041 
00042   // Set verbose output
00043 
00044   produces<RPCRecHitCollection>();
00045 
00046   theRPCDigiLabel = config.getParameter<InputTag>("rpcDigiLabel");
00047   
00048   // Get the concrete reconstruction algo from the factory
00049 
00050   string theAlgoName = config.getParameter<string>("recAlgo");
00051   theAlgo = RPCRecHitAlgoFactory::get()->create(theAlgoName,
00052                                                 config.getParameter<ParameterSet>("recAlgoConfig"));
00053 
00054   // Get masked- and dead-strip information
00055 
00056   RPCMaskedStripsObj = new RPCMaskedStrips();
00057 
00058   RPCDeadStripsObj = new RPCDeadStrips();
00059 
00060   maskSource = config.getParameter<std::string>("maskSource");
00061 
00062   if (maskSource == "File") {
00063     edm::FileInPath fp = config.getParameter<edm::FileInPath>("maskvecfile");
00064     std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
00065     if ( !inputFile ) {
00066       std::cerr << "Masked Strips File cannot not be opened" << std::endl;
00067       exit(1);
00068     }
00069     while ( inputFile.good() ) {
00070       RPCMaskedStrips::MaskItem Item;
00071       inputFile >> Item.rawId >> Item.strip;
00072       if ( inputFile.good() ) MaskVec.push_back(Item);
00073     }
00074     inputFile.close();
00075   }
00076 
00077   deadSource = config.getParameter<std::string>("deadSource");
00078 
00079   if (deadSource == "File") {
00080     edm::FileInPath fp = config.getParameter<edm::FileInPath>("deadvecfile");
00081     std::ifstream inputFile(fp.fullPath().c_str(), std::ios::in);
00082     if ( !inputFile ) {
00083       std::cerr << "Dead Strips File cannot not be opened" << std::endl;
00084       exit(1);
00085     }
00086     while ( inputFile.good() ) {
00087       RPCDeadStrips::DeadItem Item;
00088       inputFile >> Item.rawId >> Item.strip;
00089       if ( inputFile.good() ) DeadVec.push_back(Item);
00090     }
00091     inputFile.close();
00092   }
00093 
00094 }
00095 
00096 
00097 RPCRecHitProducer::~RPCRecHitProducer(){
00098 
00099   delete theAlgo;
00100   delete RPCMaskedStripsObj;
00101   delete RPCDeadStripsObj;
00102 
00103 }
00104 
00105 
00106 
00107 void RPCRecHitProducer::beginRun(const edm::Run& r, const edm::EventSetup& setup){
00108 
00109   // Getting the masked-strip information
00110 
00111   if ( maskSource == "EventSetup" ) {
00112     edm::ESHandle<RPCMaskedStrips> readoutMaskedStrips;
00113     setup.get<RPCMaskedStripsRcd>().get(readoutMaskedStrips);
00114     const RPCMaskedStrips* tmp_obj = readoutMaskedStrips.product();
00115     RPCMaskedStripsObj->MaskVec = tmp_obj->MaskVec;
00116     delete tmp_obj;
00117   }
00118   else if ( maskSource == "File" ) {
00119     std::vector<RPCMaskedStrips::MaskItem>::iterator posVec;
00120     for ( posVec = MaskVec.begin(); posVec != MaskVec.end(); ++posVec ) {
00121       RPCMaskedStrips::MaskItem Item; 
00122       Item.rawId = (*posVec).rawId;
00123       Item.strip = (*posVec).strip;
00124       RPCMaskedStripsObj->MaskVec.push_back(Item);
00125     }
00126   }
00127 
00128   // Getting the dead-strip information
00129 
00130   if ( deadSource == "EventSetup" ) {
00131     edm::ESHandle<RPCDeadStrips> readoutDeadStrips;
00132     setup.get<RPCDeadStripsRcd>().get(readoutDeadStrips);
00133     const RPCDeadStrips* tmp_obj = readoutDeadStrips.product();
00134     RPCDeadStripsObj->DeadVec = tmp_obj->DeadVec;
00135     delete tmp_obj;
00136   }
00137   else if ( deadSource == "File" ) {
00138     std::vector<RPCDeadStrips::DeadItem>::iterator posVec;
00139     for ( posVec = DeadVec.begin(); posVec != DeadVec.end(); ++posVec ) {
00140       RPCDeadStrips::DeadItem Item;
00141       Item.rawId = (*posVec).rawId;
00142       Item.strip = (*posVec).strip;
00143       RPCDeadStripsObj->DeadVec.push_back(Item);
00144     }
00145   }
00146 
00147 }
00148 
00149 
00150 
00151 void RPCRecHitProducer::produce(Event& event, const EventSetup& setup) {
00152 
00153   // Get the RPC Geometry
00154 
00155   ESHandle<RPCGeometry> rpcGeom;
00156   setup.get<MuonGeometryRecord>().get(rpcGeom);
00157 
00158   // Get the digis from the event
00159 
00160   Handle<RPCDigiCollection> digis; 
00161   event.getByLabel(theRPCDigiLabel,digis);
00162 
00163   // Pass the EventSetup to the algo
00164 
00165   theAlgo->setES(setup);
00166 
00167   // Create the pointer to the collection which will store the rechits
00168 
00169   auto_ptr<RPCRecHitCollection> recHitCollection(new RPCRecHitCollection());
00170 
00171   // Iterate through all digi collections ordered by LayerId   
00172 
00173   RPCDigiCollection::DigiRangeIterator rpcdgIt;
00174   for (rpcdgIt = digis->begin(); rpcdgIt != digis->end();
00175        ++rpcdgIt){
00176        
00177     // The layerId
00178     const RPCDetId& rpcId = (*rpcdgIt).first;
00179 
00180     // Get the GeomDet from the setup
00181     const RPCRoll* roll = rpcGeom->roll(rpcId);
00182     if (roll == 0){
00183       edm::LogError("BadDigiInput")<<"Failed to find RPCRoll for ID "<<rpcId;
00184       continue;
00185     }
00186 
00187     // Get the iterators over the digis associated with this LayerId
00188     const RPCDigiCollection::Range& range = (*rpcdgIt).second;
00189 
00190 
00191     // Getting the roll mask, that includes dead strips, for the given RPCDet
00192 
00193     RollMask mask;
00194     int rawId = rpcId.rawId();
00195     int Size = RPCMaskedStripsObj->MaskVec.size();
00196     for (int i = 0; i < Size; i++ ) {
00197       if ( RPCMaskedStripsObj->MaskVec[i].rawId == rawId ) {
00198         int bit = RPCMaskedStripsObj->MaskVec[i].strip;
00199         mask.set(bit-1);
00200       }
00201     }
00202 
00203     Size = RPCDeadStripsObj->DeadVec.size();
00204     for (int i = 0; i < Size; i++ ) {
00205       if ( RPCDeadStripsObj->DeadVec[i].rawId == rawId ) {
00206         int bit = RPCDeadStripsObj->DeadVec[i].strip;
00207         mask.set(bit-1);
00208       }
00209     }
00210 
00211     // Call the reconstruction algorithm    
00212 
00213     OwnVector<RPCRecHit> recHits =
00214       theAlgo->reconstruct(*roll, rpcId, range, mask);
00215     
00216     if(recHits.size() > 0) //FIXME: is it really needed?
00217       recHitCollection->put(rpcId, recHits.begin(), recHits.end());
00218   }
00219 
00220   event.put(recHitCollection);
00221 
00222 }
00223