CMS 3D CMS Logo

HGCalTestScintHits.cc
Go to the documentation of this file.
3 
7 
14 
16 
20 
25 
26 #include <fstream>
27 #include <string>
28 #include <vector>
29 
31 public:
33  ~HGCalTestScintHits() override = default;
34  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
35 
36 protected:
37  void analyze(edm::Event const&, edm::EventSetup const&) override;
38  void beginJob() override {}
39  void endJob() override {}
40 
41 private:
45  std::vector<int> tiles_;
46 };
47 
49  : g4Label_(ps.getParameter<std::string>("moduleLabel")),
50  caloHitSource_(ps.getParameter<std::string>("caloHitSource")),
51  nameSense_(ps.getParameter<std::string>("nameSense")),
52  tileFileName_(ps.getParameter<std::string>("tileFileName")),
53  tok_calo_(consumes<edm::PCaloHitContainer>(edm::InputTag(g4Label_, caloHitSource_))),
55  edm::LogVerbatim("HGCalSim") << "Test Hit ID using SimHits for " << nameSense_ << " with module Label: " << g4Label_
56  << " Hits: " << caloHitSource_ << " Tile file " << tileFileName_;
57  if (!tileFileName_.empty()) {
58  edm::FileInPath filetmp("SimG4CMS/Calo/data/" + tileFileName_);
59  std::string fileName = filetmp.fullPath();
60  std::ifstream fInput(fileName.c_str());
61  if (!fInput.good()) {
62  edm::LogVerbatim("HGCalSim") << "Cannot open file " << fileName;
63  } else {
64  char buffer[80];
65  while (fInput.getline(buffer, 80)) {
66  std::vector<std::string> items = CaloSimUtils::splitString(std::string(buffer));
67  if (items.size() > 2) {
68  int layer = std::atoi(items[0].c_str());
69  int ring = std::atoi(items[1].c_str());
70  int phi = std::atoi(items[2].c_str());
72  }
73  }
74  edm::LogVerbatim("HGCalSim") << "Reads in " << tiles_.size() << " tile information from " << fileName;
75  fInput.close();
76  }
77  }
78 }
79 
82  desc.add<std::string>("moduleLabel", "g4SimHits");
83  desc.add<std::string>("caloHitSource", "HGCHitsHEback");
84  desc.add<std::string>("nameSense", "HGCalHEScintillatorSensitive");
85  desc.add<std::string>("tileFileName", "");
86  descriptions.add("hgcalHitScintillator", desc);
87 }
88 
90  // get hcalGeometry
91  const HGCalGeometry* geom = &iS.getData(geomToken_);
92  const HGCalDDDConstants& hgc = geom->topology().dddConstants();
93  int firstLayer = hgc.firstLayer() - 1;
94  // get the hit collection
95  const edm::Handle<edm::PCaloHitContainer>& hitsCalo = e.getHandle(tok_calo_);
96  bool getHits = (hitsCalo.isValid());
97  uint32_t nhits = (getHits) ? hitsCalo->size() : 0;
98  uint32_t good(0), all(0);
99  edm::LogVerbatim("HGCalSim") << "HGCalTestScintHits: Input flags Hits " << getHits << " with " << nhits
100  << " hits first Layer " << firstLayer;
101 
102  if (getHits) {
103  std::vector<PCaloHit> hits;
104  hits.insert(hits.end(), hitsCalo->begin(), hitsCalo->end());
105  if (!hits.empty()) {
106  // Loop over all hits
107  for (auto hit : hits) {
108  ++all;
109  DetId id(hit.id());
110  HGCScintillatorDetId hid(id);
111  std::pair<int, int> typm = hgc.tileType(hid.layer(), hid.ring(), 0);
112  if (typm.first >= 0) {
113  hid.setType(typm.first);
114  hid.setSiPM(typm.second);
115  id = static_cast<DetId>(hid);
116  }
117  bool toCheck(true);
118  if (!tiles_.empty()) {
119  int indx = HGCalTileIndex::tileIndex(firstLayer + hid.layer(), hid.ring(), hid.iphi());
120  if (std::find(tiles_.begin(), tiles_.end(), indx) != tiles_.end())
121  toCheck = true;
122  }
123  if (toCheck) {
124  ++good;
125  GlobalPoint pos = geom->getPosition(id);
126  bool valid1 = geom->topology().valid(id);
127  bool valid2 = hgc.isValidTrap(hid.zside(), hid.layer(), hid.ring(), hid.iphi());
128  edm::LogVerbatim("HGCalSim") << "Hit[" << all << ":" << good << "]" << hid << " at (" << pos.x() << ", "
129  << pos.y() << ", " << pos.z() << ") Validity " << valid1 << ":" << valid2
130  << " Energy " << hit.energy() << " Time " << hit.time();
131  }
132  }
133  }
134  }
135  edm::LogVerbatim("HGCalSim") << "Total hits = " << all << ":" << nhits << " Good DetIds = " << good;
136 }
137 
138 //define this as a plug-in
Log< level::Info, true > LogVerbatim
std::vector< int > tiles_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
std::vector< PCaloHit > PCaloHitContainer
void endJob() override
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
void analyze(edm::Event const &, edm::EventSetup const &) override
const std::string tileFileName_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
const edm::EDGetTokenT< edm::PCaloHitContainer > tok_calo_
int32_t tileIndex(int32_t layer, int32_t ring, int32_t phi)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string caloHitSource_
std::vector< std::string > splitString(const std::string &)
Definition: CaloSimUtils.cc:3
HGCalTestScintHits(const edm::ParameterSet &ps)
const edm::ESGetToken< HGCalGeometry, IdealGeometryRecord > geomToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
unsigned int id
~HGCalTestScintHits() override=default
Definition: DetId.h:17
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
const std::string nameSense_
void beginJob() override
const std::string g4Label_