|
| 1 | +#ifndef Phase2L1Trigger_DTTrigger_ShowerBuilder_h |
| 2 | +#define Phase2L1Trigger_DTTrigger_ShowerBuilder_h |
| 3 | + |
| 4 | +#include "FWCore/Framework/interface/Event.h" |
| 5 | +#include "FWCore/Framework/interface/Frameworkfwd.h" |
| 6 | +#include "FWCore/Framework/interface/EventSetup.h" |
| 7 | +#include "FWCore/Framework/interface/Run.h" |
| 8 | +#include "FWCore/MessageLogger/interface/MessageLogger.h" |
| 9 | + |
| 10 | +#include "DataFormats/DTDigi/interface/DTDigiCollection.h" |
| 11 | +#include "L1Trigger/DTTriggerPhase2/interface/ShowerCandidate.h" |
| 12 | +#include "L1Trigger/DTTriggerPhase2/interface/constants.h" |
| 13 | + |
| 14 | +#include "Geometry/Records/interface/MuonGeometryRecord.h" |
| 15 | +#include "Geometry/DTGeometry/interface/DTGeometry.h" |
| 16 | +#include "Geometry/DTGeometry/interface/DTLayer.h" |
| 17 | + |
| 18 | +#include <iostream> |
| 19 | +#include <fstream> |
| 20 | + |
| 21 | +// =============================================================================== |
| 22 | +// Previous definitions and declarations |
| 23 | +// =============================================================================== |
| 24 | + |
| 25 | +namespace showerb { |
| 26 | + typedef std::pair<int, DTPrimitive> DTPrimPlusBx; |
| 27 | + typedef std::deque<DTPrimPlusBx> ShowerBuffer; |
| 28 | + |
| 29 | + bool hitWireSort_shower(const DTPrimitive& hit1, const DTPrimitive& hit2){ |
| 30 | + int wi1 = hit1.channelId(); |
| 31 | + int wi2 = hit2.channelId(); |
| 32 | + |
| 33 | + if (wi1 < wi2) return true; |
| 34 | + else return false; |
| 35 | + } |
| 36 | + |
| 37 | + bool hitLayerSort_shower(const DTPrimitive& hit1, const DTPrimitive& hit2) { |
| 38 | + int lay1 = hit1.layerId(); |
| 39 | + int lay2 = hit2.layerId(); |
| 40 | + |
| 41 | + if (lay1 < lay2) return true; |
| 42 | + else if (lay1 > lay2) return false; |
| 43 | + else return hitWireSort_shower(hit1, hit2); |
| 44 | + } |
| 45 | + |
| 46 | + bool hitTimeSort_shower(const DTPrimitive& hit1, const DTPrimitive& hit2) { |
| 47 | + int tdc1 = hit1.tdcTimeStamp(); |
| 48 | + int tdc2 = hit2.tdcTimeStamp(); |
| 49 | + |
| 50 | + if (tdc1 < tdc2) return true; |
| 51 | + else return false; |
| 52 | + // else if (tdc1 > tdc2) return false; |
| 53 | + // else return hitLayerSort_shower(hit1, hit2); --> ignoring those sortings for now |
| 54 | + } |
| 55 | + |
| 56 | + float compute_avg_pos(DTPrimitives& hits) { |
| 57 | + int nhits_ = hits.size(); |
| 58 | + |
| 59 | + if (nhits_ == 0) return -1.0; |
| 60 | + |
| 61 | + float aux_avgPos_ = 0; |
| 62 | + |
| 63 | + for (auto& hit : hits) { |
| 64 | + aux_avgPos_ += hit.wireHorizPos(); |
| 65 | + } |
| 66 | + |
| 67 | + return aux_avgPos_ / nhits_; |
| 68 | + } |
| 69 | + |
| 70 | + float compute_avg_time(DTPrimitives& hits) { |
| 71 | + int nhits_ = hits.size(); |
| 72 | + |
| 73 | + if (nhits_ == 0) return -1.0; |
| 74 | + |
| 75 | + float aux_avgTime_ = 0; |
| 76 | + |
| 77 | + for (auto& hit : hits) { |
| 78 | + aux_avgTime_ += hit.tdcTimeStamp(); |
| 79 | + } |
| 80 | + return aux_avgTime_ / nhits_; |
| 81 | + } |
| 82 | + |
| 83 | + void set_wires_profile(std::vector<int>& wires_profile, DTPrimitives& hits) { |
| 84 | + for (auto& hit : hits) { |
| 85 | + wires_profile[hit.channelId()-1]++; |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + bool buffer_contains(const ShowerBuffer& buffer, const DTPrimitive& hit) { |
| 90 | + for (const auto& item : buffer) { |
| 91 | + if (item.second.channelId() == hit.channelId()) return true; |
| 92 | + } |
| 93 | + return false; |
| 94 | + } |
| 95 | + |
| 96 | + void buffer_get_hits(const ShowerBuffer& buffer, DTPrimitives& hits) { |
| 97 | + for (const auto& item : buffer) { |
| 98 | + hits.push_back(item.second); |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + void buffer_clear_olds(ShowerBuffer& buffer, const int _current_bx, const int persistence_bx_units) { |
| 103 | + while (!buffer.empty() && (_current_bx - buffer.front().first) > persistence_bx_units) { |
| 104 | + buffer.pop_front(); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + void buffer_reset(ShowerBuffer& buffer) { |
| 109 | + buffer.clear(); |
| 110 | + } |
| 111 | +} |
| 112 | + |
| 113 | +// =============================================================================== |
| 114 | +// Class declarations |
| 115 | +// =============================================================================== |
| 116 | + |
| 117 | +class ShowerBuilder { |
| 118 | + |
| 119 | +public: |
| 120 | + // Constructors and destructor |
| 121 | + ShowerBuilder(const edm::ParameterSet& pset, edm::ConsumesCollector& iC); |
| 122 | + virtual ~ShowerBuilder(); |
| 123 | + |
| 124 | + // Main methods |
| 125 | + virtual void initialise(const edm::EventSetup& iEventSetup); |
| 126 | + virtual void run(edm::Event& iEvent, |
| 127 | + const edm::EventSetup& iEventSetup, |
| 128 | + const DTDigiCollection& digis, |
| 129 | + ShowerCandidatePtr &showerCandidate_SL1, |
| 130 | + ShowerCandidatePtr &showerCandidate_SL3); |
| 131 | + virtual void finish(); |
| 132 | + |
| 133 | +private: |
| 134 | + // Private auxiliary methods |
| 135 | + void clear(); |
| 136 | + void setInChannels(const DTDigiCollection* digi); |
| 137 | + void processHits_standAlone(std::map<int, ShowerCandidatePtr> &showerCands); |
| 138 | + void processHitsFirmwareEmulation(std::map<int, ShowerCandidatePtr> &showerCands); |
| 139 | + |
| 140 | + bool triggerShower(const showerb::ShowerBuffer& buffer); |
| 141 | + void set_shower_properties( |
| 142 | + ShowerCandidatePtr &showerCand, |
| 143 | + showerb::ShowerBuffer& buffer, |
| 144 | + int nhits = -1, |
| 145 | + int bx = -1, |
| 146 | + int min_wire = -1, |
| 147 | + int max_wire = -1, |
| 148 | + float avg_pos = -1., |
| 149 | + float avg_time = -1. |
| 150 | + ); |
| 151 | + void groupHits_byBx(); |
| 152 | + void fill_obdt(const int bx); |
| 153 | + void fill_bmtl1_buffers(); |
| 154 | + void bxStep(const int _current_bx); |
| 155 | + |
| 156 | + // Private attributes |
| 157 | + const int showerTaggingAlgo_; |
| 158 | + const int threshold_for_shower_; |
| 159 | + const int nHits_per_bx_; |
| 160 | + const int obdt_hits_bxpersistence_; |
| 161 | + const int obdt_wire_relaxing_time_; |
| 162 | + const int bmtl1_hits_bxpersistence_; |
| 163 | + const bool debug_; |
| 164 | + const int scenario_; |
| 165 | + |
| 166 | + // auxiliary variables |
| 167 | + DTPrimitives all_hits; |
| 168 | + std::map<int, DTPrimitives, std::less<int>> all_hits_perBx; |
| 169 | + showerb::ShowerBuffer obdt_buffer; // Buffer to emulate the OBDT behavior |
| 170 | + showerb::ShowerBuffer hot_wires_buffer; // Buffer to emulate the hot wires behavior |
| 171 | + showerb::ShowerBuffer bmtl1_sl1_buffer; // Buffer to emulate the BMTL1 shower buffer for SL1 |
| 172 | + showerb::ShowerBuffer bmtl1_sl3_buffer; // Buffer to emulate the BMTL1 shower buffer for SL3 |
| 173 | +}; |
| 174 | + |
| 175 | +#endif |
0 commit comments