CMS 3D CMS Logo

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 #ifdef SCDSL_DEBUG
18  #define DEBUG(X) X
19 #else
20  #define DEBUG(X)
21 #endif
22 
24  public:
27 
28  void produce(edm::Event&, const edm::EventSetup&) override;
29 
30  private:
32  uint32_t maxHoleSize_;
33 };
34 
36  src_(iConfig.getParameter<edm::InputTag>("src")),
37  maxHoleSize_(iConfig.getParameter<uint32_t>("maxHoleSize"))
38 {
39  produces<StripCompactDigiSimLinks>();
40 }
41 
43 {
44 }
45 
46 void
48 {
49  using namespace edm;
51  iEvent.getByLabel(src_, src);
52 
54 
55  int previousStrip; // previous strip with at least one link (might not be the strip of the previous link there are overlapping clusters)
56  int previousLinkStrip; // strip of the previous link (can be the same as the one of this link if there are overlapping clusters)
57  std::vector<StripCompactDigiSimLinks::key_type> thisStripSignals; // particles on this strip
58  std::vector<StripCompactDigiSimLinks::key_type> previousStripSignals; // particles on the previous strip
59 
60  for(auto const& det : *src) {
61  DEBUG(std::cerr << "\n\nProcessing detset " << det.detId() << ", size = " << det.size() << std::endl;)
62  previousStrip = -2; // previous strip with at least one link (might not be the strip of the previous link there are overlapping clusters)
63  previousLinkStrip = -2; // strip of the previous link (can be the same as the one of this link if there are overlapping clusters)
64  thisStripSignals.clear();
65  previousStripSignals.clear();
66  for (DetSet<StripDigiSimLink>::const_iterator it = det.begin(), ed = det.end(); it != ed; ++it) {
67  DEBUG(std::cerr << " processing digiSimLink on strip " << it->channel() << " left by particle " << it->SimTrackId() << ", event " << it->eventId().rawId() << std::endl;)
68  if (int(it->channel()) != previousLinkStrip) {
69  previousStrip = previousLinkStrip;
70  DEBUG(std::cerr << " strip changed!" << std::endl;)
71  swap(thisStripSignals, previousStripSignals);
72  thisStripSignals.clear();
73  }
74  DEBUG(std::cerr << " previous strip " << previousStrip << ", previous link strip " << previousLinkStrip << std::endl;)
75  //DEBUG(std::cerr << " on previous strip: "; for(auto const& k : previousStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
76  //DEBUG(std::cerr << " on this strip: "; for(auto const& k : thisStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
77  StripCompactDigiSimLinks::key_type key(it->eventId(), it->SimTrackId());
78  bool alreadyClusterized = false;
79  if (int(it->channel()) == previousStrip+1) {
80  DEBUG(std::cerr << " on next strip" << std::endl;)
81  if (std::find(previousStripSignals.begin(), previousStripSignals.end(), key) != previousStripSignals.end()) {
82  alreadyClusterized = true;
83  DEBUG(std::cerr << " and part of previous cluster" << std::endl;)
84  }
85  }
86  if (!alreadyClusterized) {
87  DEBUG(std::cerr << " clusterize!" << std::endl;)
88  unsigned int size = 1;
89  int myLastStrip = it->channel(); // last known strip with signals from this particle
90  for (DetSet<StripDigiSimLink>::const_iterator it2 = it+1; it2 < ed; ++it2) {
91  DEBUG(std::cerr << " digiSimLink on strip " << it2->channel() << " left by particle " << it2->SimTrackId() << ", event " << it2->eventId().rawId() << std::endl;)
92  if ((it2->channel() - myLastStrip) > maxHoleSize_+1) {
93  DEBUG(std::cerr << " found hole of size " << (it2->channel() - myLastStrip) << ", stopping." << std::endl;)
94  break;
95  }
96  if ((it2->eventId() == key.first) && (it2->SimTrackId() == key.second)) {
97  size++;
98  DEBUG(std::cerr << " extending cluster, now size = " << size << std::endl;)
99  myLastStrip = it2->channel();
100  }
101  }
102  output.insert(key, StripCompactDigiSimLinks::HitRecord(det.detId(), it->channel(), size));
103  }
104  if (int(it->channel()) != previousLinkStrip) {
105  previousLinkStrip = it->channel();
106  }
107  thisStripSignals.push_back(key);
108  DEBUG(std::cerr << " ending state " << previousStrip << ", previous link strip " << previousLinkStrip << std::endl;)
109  //DEBUG(std::cerr << " on previous strip: "; for(auto const& k : previousStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
110  //DEBUG(std::cerr << " on this strip: "; for(auto const& k : thisStripSignals) { std::cerr << "(ev " << k.first.rawId() << ", id " << k.second << ") "; } std::cerr << std::endl;)
111  DEBUG(std::cerr << std::endl;)
112  }
113  }
114 
115  std::unique_ptr< StripCompactDigiSimLinks > ptr(new StripCompactDigiSimLinks(output));
116  iEvent.put(std::move(ptr));
117 }
118 
size
Write out results.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
#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:20
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
int iEvent
Definition: GenABIO.cc:230
StripCompactDigiSimLinksProducer(const edm::ParameterSet &iConfig)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:535
iterator begin()
Definition: DetSet.h:59
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
def move(src, dest)
Definition: eostools.py:511