CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/SimTracker/TrackAssociation/plugins/StripCompactDigiSimLinksProducer.cc

Go to the documentation of this file.
00001 // system include files
00002 #include <memory>
00003 
00004 // user include files
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDProducer.h"
00007 
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/MakerMacros.h"
00010 
00011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00012 
00013 #include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
00014 #include "DataFormats/Common/interface/DetSetVector.h"
00015 #include "SimDataFormats/TrackerDigiSimLink/interface/StripCompactDigiSimLinks.h"
00016 
00017 #include <boost/foreach.hpp>
00018 #define foreach BOOST_FOREACH
00019 
00020 #ifdef SCDSL_DEBUG
00021   #define DEBUG(X) X
00022 #else
00023   #define DEBUG(X)
00024 #endif
00025 
00026 class StripCompactDigiSimLinksProducer : public edm::EDProducer {
00027     public:
00028         StripCompactDigiSimLinksProducer(const edm::ParameterSet &iConfig) ;
00029         ~StripCompactDigiSimLinksProducer();
00030 
00031         virtual void produce(edm::Event&, const edm::EventSetup&);
00032 
00033     private:
00034         edm::InputTag src_;
00035         uint32_t      maxHoleSize_;
00036 };
00037 
00038 StripCompactDigiSimLinksProducer::StripCompactDigiSimLinksProducer(const edm::ParameterSet &iConfig) :
00039     src_(iConfig.getParameter<edm::InputTag>("src")),
00040     maxHoleSize_(iConfig.getParameter<uint32_t>("maxHoleSize"))
00041 {
00042     produces<StripCompactDigiSimLinks>();
00043 }
00044 
00045 StripCompactDigiSimLinksProducer::~StripCompactDigiSimLinksProducer()
00046 {
00047 }
00048 
00049 void
00050 StripCompactDigiSimLinksProducer::produce(edm::Event & iEvent, const edm::EventSetup&) 
00051 {
00052     using namespace edm;
00053     Handle<DetSetVector<StripDigiSimLink> > src;
00054     iEvent.getByLabel(src_, src);
00055 
00056     StripCompactDigiSimLinks::Filler output;
00057 
00058     int previousStrip;     // previous strip with at least one link (might not be the strip of the previous link there are overlapping clusters)
00059     int previousLinkStrip; // strip of the previous link (can be the same as the one of this link if there are overlapping clusters)
00060     std::vector<StripCompactDigiSimLinks::key_type> thisStripSignals;      // particles on this strip
00061     std::vector<StripCompactDigiSimLinks::key_type> previousStripSignals;  // particles on the previous strip
00062 
00063     foreach(const DetSet<StripDigiSimLink> &det, *src) {
00064         DEBUG(std::cerr << "\n\nProcessing detset " << det.detId() << ", size = " << det.size() << std::endl;)
00065         previousStrip     = -2; // previous strip with at least one link (might not be the strip of the previous link there are overlapping clusters)
00066         previousLinkStrip = -2; // strip of the previous link (can be the same as the one of this link if there are overlapping clusters)
00067         thisStripSignals.clear();
00068         previousStripSignals.clear();
00069         for (DetSet<StripDigiSimLink>::const_iterator it = det.begin(), ed = det.end(); it != ed; ++it) {
00070             DEBUG(std::cerr << "  processing digiSimLink on strip " << it->channel() << " left by particle " << it->SimTrackId() << ", event " << it->eventId().rawId() << std::endl;)
00071             if (int(it->channel()) != previousLinkStrip) { 
00072                 previousStrip = previousLinkStrip;
00073                 DEBUG(std::cerr << "   strip changed!" << std::endl;)
00074                 swap(thisStripSignals, previousStripSignals); 
00075                 thisStripSignals.clear();
00076             }
00077             DEBUG(std::cerr << "    previous strip " << previousStrip << ", previous link strip " << previousLinkStrip << std::endl;)
00078             //DEBUG(std::cerr << "    on previous strip: "; foreach(StripCompactDigiSimLinks::key_type k, previousStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
00079             //DEBUG(std::cerr << "    on this strip: ";     foreach(StripCompactDigiSimLinks::key_type k,     thisStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
00080             StripCompactDigiSimLinks::key_type key(it->eventId(), it->SimTrackId());
00081             bool alreadyClusterized = false;
00082             if (int(it->channel()) == previousStrip+1) {
00083                 DEBUG(std::cerr << "  on next strip" << std::endl;)
00084                 if (std::find(previousStripSignals.begin(), previousStripSignals.end(), key) != previousStripSignals.end()) {
00085                     alreadyClusterized = true;
00086                     DEBUG(std::cerr << "    and part of previous cluster" << std::endl;)
00087                 }
00088             }
00089             if (!alreadyClusterized) {
00090                 DEBUG(std::cerr << "   clusterize!" << std::endl;)
00091                 unsigned int size = 1;
00092                 int myLastStrip = it->channel(); // last known strip with signals from this particle
00093                 for (DetSet<StripDigiSimLink>::const_iterator it2 = it+1; it2 < ed; ++it2) {
00094                     DEBUG(std::cerr << "     digiSimLink on strip " << it2->channel() << " left by particle " << it2->SimTrackId() << ", event " << it2->eventId().rawId() << std::endl;)
00095                     if ((it2->channel() - myLastStrip) > maxHoleSize_+1) {
00096                         DEBUG(std::cerr << "        found hole of size " << (it2->channel() - myLastStrip) << ", stopping." << std::endl;)
00097                         break;
00098                     }
00099                     if ((it2->eventId() == key.first) && (it2->SimTrackId() == key.second)) {
00100                         size++;
00101                         DEBUG(std::cerr << "        extending cluster, now size = " << size << std::endl;)
00102                         myLastStrip = it2->channel();
00103                     }
00104                 }
00105                 output.insert(key, StripCompactDigiSimLinks::HitRecord(det.detId(), it->channel(), size));
00106             }
00107             if (int(it->channel()) != previousLinkStrip) {
00108                 previousLinkStrip = it->channel();
00109             }
00110             thisStripSignals.push_back(key);
00111             DEBUG(std::cerr << "    ending state " << previousStrip << ", previous link strip " << previousLinkStrip << std::endl;)
00112             //DEBUG(std::cerr << "    on previous strip: "; foreach(StripCompactDigiSimLinks::key_type k, previousStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
00113             //DEBUG(std::cerr << "    on this strip: ";     foreach(StripCompactDigiSimLinks::key_type k,     thisStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
00114             DEBUG(std::cerr << std::endl;)
00115         }
00116     }
00117    
00118     std::auto_ptr< StripCompactDigiSimLinks > ptr(new StripCompactDigiSimLinks(output));
00119     iEvent.put(ptr);
00120 }
00121 
00122 DEFINE_FWK_MODULE(StripCompactDigiSimLinksProducer);