test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StripCompactDigiSimLinksProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
10 
12 
16 
17 #include <boost/foreach.hpp>
18 #define foreach BOOST_FOREACH
19 
20 #ifdef SCDSL_DEBUG
21  #define DEBUG(X) X
22 #else
23  #define DEBUG(X)
24 #endif
25 
27  public:
30 
31  virtual void produce(edm::Event&, const edm::EventSetup&) override;
32 
33  private:
35  uint32_t maxHoleSize_;
36 };
37 
39  src_(iConfig.getParameter<edm::InputTag>("src")),
40  maxHoleSize_(iConfig.getParameter<uint32_t>("maxHoleSize"))
41 {
42  produces<StripCompactDigiSimLinks>();
43 }
44 
46 {
47 }
48 
49 void
51 {
52  using namespace edm;
54  iEvent.getByLabel(src_, src);
55 
57 
58  int previousStrip; // previous strip with at least one link (might not be the strip of the previous link there are overlapping clusters)
59  int previousLinkStrip; // strip of the previous link (can be the same as the one of this link if there are overlapping clusters)
60  std::vector<StripCompactDigiSimLinks::key_type> thisStripSignals; // particles on this strip
61  std::vector<StripCompactDigiSimLinks::key_type> previousStripSignals; // particles on the previous strip
62 
63  foreach(const DetSet<StripDigiSimLink> &det, *src) {
64  DEBUG(std::cerr << "\n\nProcessing detset " << det.detId() << ", size = " << det.size() << std::endl;)
65  previousStrip = -2; // previous strip with at least one link (might not be the strip of the previous link there are overlapping clusters)
66  previousLinkStrip = -2; // strip of the previous link (can be the same as the one of this link if there are overlapping clusters)
67  thisStripSignals.clear();
68  previousStripSignals.clear();
69  for (DetSet<StripDigiSimLink>::const_iterator it = det.begin(), ed = det.end(); it != ed; ++it) {
70  DEBUG(std::cerr << " processing digiSimLink on strip " << it->channel() << " left by particle " << it->SimTrackId() << ", event " << it->eventId().rawId() << std::endl;)
71  if (int(it->channel()) != previousLinkStrip) {
72  previousStrip = previousLinkStrip;
73  DEBUG(std::cerr << " strip changed!" << std::endl;)
74  swap(thisStripSignals, previousStripSignals);
75  thisStripSignals.clear();
76  }
77  DEBUG(std::cerr << " previous strip " << previousStrip << ", previous link strip " << previousLinkStrip << std::endl;)
78  //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;)
79  //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;)
80  StripCompactDigiSimLinks::key_type key(it->eventId(), it->SimTrackId());
81  bool alreadyClusterized = false;
82  if (int(it->channel()) == previousStrip+1) {
83  DEBUG(std::cerr << " on next strip" << std::endl;)
84  if (std::find(previousStripSignals.begin(), previousStripSignals.end(), key) != previousStripSignals.end()) {
85  alreadyClusterized = true;
86  DEBUG(std::cerr << " and part of previous cluster" << std::endl;)
87  }
88  }
89  if (!alreadyClusterized) {
90  DEBUG(std::cerr << " clusterize!" << std::endl;)
91  unsigned int size = 1;
92  int myLastStrip = it->channel(); // last known strip with signals from this particle
93  for (DetSet<StripDigiSimLink>::const_iterator it2 = it+1; it2 < ed; ++it2) {
94  DEBUG(std::cerr << " digiSimLink on strip " << it2->channel() << " left by particle " << it2->SimTrackId() << ", event " << it2->eventId().rawId() << std::endl;)
95  if ((it2->channel() - myLastStrip) > maxHoleSize_+1) {
96  DEBUG(std::cerr << " found hole of size " << (it2->channel() - myLastStrip) << ", stopping." << std::endl;)
97  break;
98  }
99  if ((it2->eventId() == key.first) && (it2->SimTrackId() == key.second)) {
100  size++;
101  DEBUG(std::cerr << " extending cluster, now size = " << size << std::endl;)
102  myLastStrip = it2->channel();
103  }
104  }
105  output.insert(key, StripCompactDigiSimLinks::HitRecord(det.detId(), it->channel(), size));
106  }
107  if (int(it->channel()) != previousLinkStrip) {
108  previousLinkStrip = it->channel();
109  }
110  thisStripSignals.push_back(key);
111  DEBUG(std::cerr << " ending state " << previousStrip << ", previous link strip " << previousLinkStrip << std::endl;)
112  //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;)
113  //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;)
114  DEBUG(std::cerr << std::endl;)
115  }
116  }
117 
118  std::auto_ptr< StripCompactDigiSimLinks > ptr(new StripCompactDigiSimLinks(output));
119  iEvent.put(ptr);
120 }
121 
iterator end()
Definition: DetSet.h:60
void swap(ora::Record &rh, ora::Record &lh)
Definition: Record.h:70
det_id_type detId() const
Definition: DetSet.h:72
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
size_type size() const
Definition: DetSet.h:63
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:120
StripCompactDigiSimLinksProducer(const edm::ParameterSet &iConfig)
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:420
iterator begin()
Definition: DetSet.h:59
virtual void produce(edm::Event &, const edm::EventSetup &) override
tuple size
Write out results.