Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-20 11:34:00

0001 #include <iostream>
0002 #include <string>
0003 #include <vector>
0004 
0005 #include "TTree.h"
0006 
0007 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0008 #include "FWCore/Framework/interface/Frameworkfwd.h"
0009 #include "FWCore/Framework/interface/stream/EDAnalyzer.h"
0010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0011 #include "FWCore/ServiceRegistry/interface/Service.h"
0012 
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/ESTransientHandle.h"
0015 #include "FWCore/Framework/interface/Event.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Framework/interface/MakerMacros.h"
0018 
0019 #include "DataFormats/ForwardDetId/interface/ForwardSubdetector.h"
0020 #include "DataFormats/ForwardDetId/interface/HFNoseTriggerDetId.h"
0021 #include "DataFormats/ForwardDetId/interface/HGCalDetId.h"
0022 #include "DataFormats/ForwardDetId/interface/HGCalTriggerDetId.h"
0023 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0024 
0025 #include "DataFormats/ForwardDetId/interface/HGCScintillatorDetId.h"
0026 #include "DataFormats/ForwardDetId/interface/HGCSiliconDetId.h"
0027 #include "Geometry/HGCalCommonData/interface/HGCalGeometryMode.h"
0028 #include "Geometry/HGCalGeometry/interface/HGCalGeometry.h"
0029 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0030 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0031 
0032 #include "L1Trigger/L1THGCal/interface/HGCalTriggerGeometryBase.h"
0033 #include "DataFormats/ForwardDetId/interface/HGCalTriggerModuleDetId.h"
0034 #include "DataFormats/ForwardDetId/interface/HGCalTriggerBackendDetId.h"
0035 
0036 #include <cstdlib>
0037 
0038 namespace {
0039   template <typename T>
0040   struct array_deleter {
0041     void operator()(T* arr) { delete[] arr; }
0042   };
0043 }  // namespace
0044 
0045 class HGCalTriggerGeomTesterV9Imp3 : public edm::stream::EDAnalyzer<> {
0046 public:
0047   explicit HGCalTriggerGeomTesterV9Imp3(const edm::ParameterSet&);
0048   ~HGCalTriggerGeomTesterV9Imp3() override = default;
0049 
0050   void beginRun(const edm::Run&, const edm::EventSetup&) override;
0051   void endRun(const edm::Run&, const edm::EventSetup&) override {}
0052   void analyze(const edm::Event&, const edm::EventSetup&) override;
0053 
0054 private:
0055   void fillTriggerGeometry();
0056   bool checkMappingConsistency();
0057   void setTreeModuleSize(const size_t n);
0058   void setTreeModuleCellSize(const size_t n);
0059   void setTreeTriggerCellSize(const size_t n);
0060   void setTreeCellCornerSize(const size_t n);
0061   void setTreeTriggerCellNeighborSize(const size_t n);
0062 
0063   const edm::ESGetToken<HGCalTriggerGeometryBase, CaloGeometryRecord> triggerGeomToken_;
0064   edm::ESHandle<HGCalTriggerGeometryBase> triggerGeometry_;
0065   bool no_trigger_;
0066   bool no_neighbors_;
0067   TTree* treeModules_;
0068   TTree* treeTriggerCells_;
0069   TTree* treeCells_;
0070   TTree* treeCellsBH_;
0071   TTree* treeCellsNose_;
0072   TTree* treeModuleErrors_;
0073   // tree variables
0074   int moduleId_ = 0;
0075   int moduleSide_ = 0;
0076   int moduleSubdet_ = 0;
0077   int moduleLayer_ = 0;
0078   int moduleIEta_ = 0;
0079   int moduleIPhi_ = 0;
0080   int module_ = 0;
0081   float moduleX_ = 0;
0082   float moduleY_ = 0;
0083   float moduleZ_ = 0;
0084   float moduleEta_ = 0;
0085   float modulePhi_ = 0;
0086   int moduleTC_N_ = 0;
0087   int moduleLinks_ = 0;
0088   std::shared_ptr<int> moduleTC_id_;
0089   std::shared_ptr<int> moduleTC_zside_;
0090   std::shared_ptr<int> moduleTC_subdet_;
0091   std::shared_ptr<int> moduleTC_layer_;
0092   std::shared_ptr<int> moduleTC_waferU_;
0093   std::shared_ptr<int> moduleTC_waferV_;
0094   std::shared_ptr<int> moduleTC_cellU_;
0095   std::shared_ptr<int> moduleTC_cellV_;
0096   std::shared_ptr<int> moduleTC_ieta_;
0097   std::shared_ptr<int> moduleTC_iphi_;
0098   std::shared_ptr<float> moduleTC_x_;
0099   std::shared_ptr<float> moduleTC_y_;
0100   std::shared_ptr<float> moduleTC_z_;
0101   std::shared_ptr<float> moduleTC_eta_;
0102   std::shared_ptr<float> moduleTC_phi_;
0103   int moduleCell_N_ = 0;
0104   std::shared_ptr<int> moduleCell_id_;
0105   std::shared_ptr<int> moduleCell_zside_;
0106   std::shared_ptr<int> moduleCell_subdet_;
0107   std::shared_ptr<int> moduleCell_layer_;
0108   std::shared_ptr<int> moduleCell_waferU_;
0109   std::shared_ptr<int> moduleCell_waferV_;
0110   std::shared_ptr<int> moduleCell_cellU_;
0111   std::shared_ptr<int> moduleCell_cellV_;
0112   std::shared_ptr<int> moduleCell_ieta_;
0113   std::shared_ptr<int> moduleCell_iphi_;
0114   std::shared_ptr<float> moduleCell_x_;
0115   std::shared_ptr<float> moduleCell_y_;
0116   std::shared_ptr<float> moduleCell_z_;
0117   std::shared_ptr<float> moduleCell_eta_;
0118   std::shared_ptr<float> moduleCell_phi_;
0119   int triggerCellId_ = 0;
0120   int triggerCellSide_ = 0;
0121   int triggerCellSubdet_ = 0;
0122   int triggerCellLayer_ = 0;
0123   int triggerCellWaferU_ = 0;
0124   int triggerCellWaferV_ = 0;
0125   int triggerCellU_ = 0;
0126   int triggerCellV_ = 0;
0127   int triggerCellIEta_ = 0;
0128   int triggerCellIPhi_ = 0;
0129   float triggerCellX_ = 0;
0130   float triggerCellY_ = 0;
0131   float triggerCellZ_ = 0;
0132   float triggerCellEta_ = 0;
0133   float triggerCellPhi_ = 0;
0134   int triggerCellNeighbor_N_ = 0;
0135   std::shared_ptr<int> triggerCellNeighbor_id_;
0136   std::shared_ptr<int> triggerCellNeighbor_zside_;
0137   std::shared_ptr<int> triggerCellNeighbor_subdet_;
0138   std::shared_ptr<int> triggerCellNeighbor_layer_;
0139   std::shared_ptr<int> triggerCellNeighbor_waferU_;
0140   std::shared_ptr<int> triggerCellNeighbor_waferV_;
0141   std::shared_ptr<int> triggerCellNeighbor_cellU_;
0142   std::shared_ptr<int> triggerCellNeighbor_cellV_;
0143   std::shared_ptr<int> triggerCellNeighbor_cellIEta_;
0144   std::shared_ptr<int> triggerCellNeighbor_cellIPhi_;
0145   std::shared_ptr<float> triggerCellNeighbor_distance_;
0146   int triggerCellCell_N_ = 0;
0147   std::shared_ptr<int> triggerCellCell_id_;
0148   std::shared_ptr<int> triggerCellCell_zside_;
0149   std::shared_ptr<int> triggerCellCell_subdet_;
0150   std::shared_ptr<int> triggerCellCell_layer_;
0151   std::shared_ptr<int> triggerCellCell_waferU_;
0152   std::shared_ptr<int> triggerCellCell_waferV_;
0153   std::shared_ptr<int> triggerCellCell_cellU_;
0154   std::shared_ptr<int> triggerCellCell_cellV_;
0155   std::shared_ptr<int> triggerCellCell_ieta_;
0156   std::shared_ptr<int> triggerCellCell_iphi_;
0157   std::shared_ptr<float> triggerCellCell_x_;
0158   std::shared_ptr<float> triggerCellCell_y_;
0159   std::shared_ptr<float> triggerCellCell_z_;
0160   std::shared_ptr<float> triggerCellCell_eta_;
0161   std::shared_ptr<float> triggerCellCell_phi_;
0162   int cellId_ = 0;
0163   int cellSide_ = 0;
0164   int cellSubdet_ = 0;
0165   int cellLayer_ = 0;
0166   int cellWaferU_ = 0;
0167   int cellWaferV_ = 0;
0168   int cellWaferType_ = 0;
0169   int cellWaferRow_ = 0;
0170   int cellWaferColumn_ = 0;
0171   int cellU_ = 0;
0172   int cellV_ = 0;
0173   float cellX_ = 0;
0174   float cellY_ = 0;
0175   float cellZ_ = 0;
0176   float cellEta_ = 0;
0177   float cellPhi_ = 0;
0178   int cellCornersN_ = 0;
0179   std::shared_ptr<float> cellCornersX_;
0180   std::shared_ptr<float> cellCornersY_;
0181   std::shared_ptr<float> cellCornersZ_;
0182   int cellBHId_ = 0;
0183   int cellBHType_ = 0;
0184   int cellBHSide_ = 0;
0185   int cellBHSubdet_ = 0;
0186   int cellBHLayer_ = 0;
0187   int cellBHIEta_ = 0;
0188   int cellBHIPhi_ = 0;
0189   float cellBHEta_ = 0;
0190   float cellBHPhi_ = 0;
0191   float cellBHX_ = 0;
0192   float cellBHY_ = 0;
0193   float cellBHZ_ = 0;
0194   float cellBHX1_ = 0;
0195   float cellBHY1_ = 0;
0196   float cellBHX2_ = 0;
0197   float cellBHY2_ = 0;
0198   float cellBHX3_ = 0;
0199   float cellBHY3_ = 0;
0200   float cellBHX4_ = 0;
0201   float cellBHY4_ = 0;
0202   //
0203   int moduleErrorSubdet_ = 0;
0204   int moduleErrorLayer_ = 0;
0205   int moduleErrorWaferU_ = 0;
0206   int moduleErrorWaferV_ = 0;
0207 
0208 private:
0209   typedef std::unordered_map<uint32_t, std::unordered_set<uint32_t>> trigger_map_set;
0210 };
0211 
0212 /*****************************************************************/
0213 HGCalTriggerGeomTesterV9Imp3::HGCalTriggerGeomTesterV9Imp3(const edm::ParameterSet& conf)
0214     : triggerGeomToken_(esConsumes<HGCalTriggerGeometryBase, CaloGeometryRecord, edm::Transition::BeginRun>()),
0215       no_trigger_(false),
0216       no_neighbors_(true)
0217 /*****************************************************************/
0218 {
0219   edm::Service<TFileService> fs;
0220   // initialize output trees
0221   treeModules_ = fs->make<TTree>("TreeModules", "Tree of all HGC modules");
0222   treeModules_->Branch("id", &moduleId_, "id/I");
0223   treeModules_->Branch("zside", &moduleSide_, "zside/I");
0224   treeModules_->Branch("subdet", &moduleSubdet_, "subdet/I");
0225   treeModules_->Branch("layer", &moduleLayer_, "layer/I");
0226   treeModules_->Branch("ieta", &moduleIEta_, "ieta/I");
0227   treeModules_->Branch("iphi", &moduleIPhi_, "iphi/I");
0228   treeModules_->Branch("module", &module_, "module/I");
0229   treeModules_->Branch("links", &moduleLinks_, "links/I");
0230   treeModules_->Branch("x", &moduleX_, "x/F");
0231   treeModules_->Branch("y", &moduleY_, "y/F");
0232   treeModules_->Branch("z", &moduleZ_, "z/F");
0233   treeModules_->Branch("eta", &moduleEta_, "eta/F");
0234   treeModules_->Branch("phi", &modulePhi_, "phi/F");
0235   treeModules_->Branch("tc_n", &moduleTC_N_, "tc_n/I");
0236   moduleTC_id_.reset(new int[1], array_deleter<int>());
0237   moduleTC_zside_.reset(new int[1], array_deleter<int>());
0238   moduleTC_subdet_.reset(new int[1], array_deleter<int>());
0239   moduleTC_layer_.reset(new int[1], array_deleter<int>());
0240   moduleTC_waferU_.reset(new int[1], array_deleter<int>());
0241   moduleTC_waferV_.reset(new int[1], array_deleter<int>());
0242   moduleTC_cellU_.reset(new int[1], array_deleter<int>());
0243   moduleTC_cellV_.reset(new int[1], array_deleter<int>());
0244   moduleTC_x_.reset(new float[1], array_deleter<float>());
0245   moduleTC_y_.reset(new float[1], array_deleter<float>());
0246   moduleTC_z_.reset(new float[1], array_deleter<float>());
0247   moduleTC_eta_.reset(new float[1], array_deleter<float>());
0248   moduleTC_phi_.reset(new float[1], array_deleter<float>());
0249   treeModules_->Branch("tc_id", moduleTC_id_.get(), "tc_id[tc_n]/I");
0250   treeModules_->Branch("tc_zside", moduleTC_zside_.get(), "tc_zside[tc_n]/I");
0251   treeModules_->Branch("tc_subdet", moduleTC_subdet_.get(), "tc_subdet[tc_n]/I");
0252   treeModules_->Branch("tc_layer", moduleTC_layer_.get(), "tc_layer[tc_n]/I");
0253   treeModules_->Branch("tc_waferu", moduleTC_waferU_.get(), "tc_waferu[tc_n]/I");
0254   treeModules_->Branch("tc_waferv", moduleTC_waferV_.get(), "tc_waferv[tc_n]/I");
0255   treeModules_->Branch("tc_cellu", moduleTC_cellU_.get(), "tc_cellu[tc_n]/I");
0256   treeModules_->Branch("tc_cellv", moduleTC_cellV_.get(), "tc_cellv[tc_n]/I");
0257   treeModules_->Branch("tc_ieta", moduleTC_ieta_.get(), "tc_ieta[tc_n]/I");
0258   treeModules_->Branch("tc_iphi", moduleTC_iphi_.get(), "tc_iphi[tc_n]/I");
0259   treeModules_->Branch("tc_x", moduleTC_x_.get(), "tc_x[tc_n]/F");
0260   treeModules_->Branch("tc_y", moduleTC_y_.get(), "tc_y[tc_n]/F");
0261   treeModules_->Branch("tc_z", moduleTC_z_.get(), "tc_z[tc_n]/F");
0262   treeModules_->Branch("tc_eta", moduleTC_eta_.get(), "tc_eta[tc_n]/F");
0263   treeModules_->Branch("tc_phi", moduleTC_phi_.get(), "tc_phi[tc_n]/F");
0264   treeModules_->Branch("c_n", &moduleCell_N_, "c_n/I");
0265   moduleCell_id_.reset(new int[1], array_deleter<int>());
0266   moduleCell_zside_.reset(new int[1], array_deleter<int>());
0267   moduleCell_subdet_.reset(new int[1], array_deleter<int>());
0268   moduleCell_layer_.reset(new int[1], array_deleter<int>());
0269   moduleCell_waferU_.reset(new int[1], array_deleter<int>());
0270   moduleCell_waferV_.reset(new int[1], array_deleter<int>());
0271   moduleCell_cellU_.reset(new int[1], array_deleter<int>());
0272   moduleCell_cellV_.reset(new int[1], array_deleter<int>());
0273   moduleCell_ieta_.reset(new int[1], array_deleter<int>());
0274   moduleCell_iphi_.reset(new int[1], array_deleter<int>());
0275   moduleCell_x_.reset(new float[1], array_deleter<float>());
0276   moduleCell_y_.reset(new float[1], array_deleter<float>());
0277   moduleCell_z_.reset(new float[1], array_deleter<float>());
0278   moduleCell_eta_.reset(new float[1], array_deleter<float>());
0279   moduleCell_phi_.reset(new float[1], array_deleter<float>());
0280   treeModules_->Branch("c_id", moduleCell_id_.get(), "c_id[c_n]/I");
0281   treeModules_->Branch("c_zside", moduleCell_zside_.get(), "c_zside[c_n]/I");
0282   treeModules_->Branch("c_subdet", moduleCell_subdet_.get(), "c_subdet[c_n]/I");
0283   treeModules_->Branch("c_layer", moduleCell_layer_.get(), "c_layer[c_n]/I");
0284   treeModules_->Branch("c_waferu", moduleCell_waferU_.get(), "c_waferu[c_n]/I");
0285   treeModules_->Branch("c_waferv", moduleCell_waferV_.get(), "c_waferv[c_n]/I");
0286   treeModules_->Branch("c_cellu", moduleCell_cellU_.get(), "c_cellu[c_n]/I");
0287   treeModules_->Branch("c_cellv", moduleCell_cellV_.get(), "c_cellv[c_n]/I");
0288   treeModules_->Branch("c_ieta", moduleCell_ieta_.get(), "c_ieta[c_n]/I");
0289   treeModules_->Branch("c_iphi", moduleCell_iphi_.get(), "c_iphi[c_n]/I");
0290   treeModules_->Branch("c_x", moduleCell_x_.get(), "c_x[c_n]/F");
0291   treeModules_->Branch("c_y", moduleCell_y_.get(), "c_y[c_n]/F");
0292   treeModules_->Branch("c_z", moduleCell_z_.get(), "c_z[c_n]/F");
0293   treeModules_->Branch("c_eta", moduleCell_eta_.get(), "c_eta[c_n]/F");
0294   treeModules_->Branch("c_phi", moduleCell_phi_.get(), "c_phi[c_n]/F");
0295   //
0296   treeTriggerCells_ = fs->make<TTree>("TreeTriggerCells", "Tree of all HGC trigger cells");
0297   treeTriggerCells_->Branch("id", &triggerCellId_, "id/I");
0298   treeTriggerCells_->Branch("zside", &triggerCellSide_, "zside/I");
0299   treeTriggerCells_->Branch("subdet", &triggerCellSubdet_, "subdet/I");
0300   treeTriggerCells_->Branch("layer", &triggerCellLayer_, "layer/I");
0301   treeTriggerCells_->Branch("waferu", &triggerCellWaferU_, "waferu/I");
0302   treeTriggerCells_->Branch("waferv", &triggerCellWaferV_, "waferv/I");
0303   treeTriggerCells_->Branch("triggercellu", &triggerCellU_, "triggercellu/I");
0304   treeTriggerCells_->Branch("triggercellv", &triggerCellV_, "triggercellv/I");
0305   treeTriggerCells_->Branch("triggercellieta", &triggerCellIEta_, "triggercellieta/I");
0306   treeTriggerCells_->Branch("triggercelliphi", &triggerCellIPhi_, "triggercelliphi/I");
0307   treeTriggerCells_->Branch("x", &triggerCellX_, "x/F");
0308   treeTriggerCells_->Branch("y", &triggerCellY_, "y/F");
0309   treeTriggerCells_->Branch("z", &triggerCellZ_, "z/F");
0310   treeTriggerCells_->Branch("eta", &triggerCellEta_, "eta/F");
0311   treeTriggerCells_->Branch("phi", &triggerCellPhi_, "phi/F");
0312   treeTriggerCells_->Branch("neighbor_n", &triggerCellNeighbor_N_, "neighbor_n/I");
0313   triggerCellNeighbor_id_.reset(new int[1], array_deleter<int>());
0314   triggerCellNeighbor_zside_.reset(new int[1], array_deleter<int>());
0315   triggerCellNeighbor_subdet_.reset(new int[1], array_deleter<int>());
0316   triggerCellNeighbor_layer_.reset(new int[1], array_deleter<int>());
0317   triggerCellNeighbor_waferU_.reset(new int[1], array_deleter<int>());
0318   triggerCellNeighbor_waferV_.reset(new int[1], array_deleter<int>());
0319   triggerCellNeighbor_cellU_.reset(new int[1], array_deleter<int>());
0320   triggerCellNeighbor_cellV_.reset(new int[1], array_deleter<int>());
0321   triggerCellNeighbor_distance_.reset(new float[1], array_deleter<float>());
0322   treeTriggerCells_->Branch("neighbor_id", triggerCellNeighbor_id_.get(), "neighbor_id[neighbor_n]/I");
0323   treeTriggerCells_->Branch("neighbor_zside", triggerCellNeighbor_zside_.get(), "neighbor_zside[neighbor_n]/I");
0324   treeTriggerCells_->Branch("neighbor_subdet", triggerCellNeighbor_subdet_.get(), "neighbor_subdet[neighbor_n]/I");
0325   treeTriggerCells_->Branch("neighbor_layer", triggerCellNeighbor_layer_.get(), "neighbor_layer[neighbor_n]/I");
0326   treeTriggerCells_->Branch("neighbor_waferu", triggerCellNeighbor_waferU_.get(), "neighbor_waferu[neighbor_n]/I");
0327   treeTriggerCells_->Branch("neighbor_waferv", triggerCellNeighbor_waferV_.get(), "neighbor_waferv[neighbor_n]/I");
0328   treeTriggerCells_->Branch("neighbor_cellu", triggerCellNeighbor_cellU_.get(), "neighbor_cellu[neighbor_n]/I");
0329   treeTriggerCells_->Branch("neighbor_cellv", triggerCellNeighbor_cellV_.get(), "neighbor_cellv[neighbor_n]/I");
0330   treeTriggerCells_->Branch(
0331       "neighbor_distance", triggerCellNeighbor_distance_.get(), "neighbor_distance[neighbor_n]/F");
0332   treeTriggerCells_->Branch("c_n", &triggerCellCell_N_, "c_n/I");
0333   triggerCellCell_id_.reset(new int[1], array_deleter<int>());
0334   triggerCellCell_zside_.reset(new int[1], array_deleter<int>());
0335   triggerCellCell_subdet_.reset(new int[1], array_deleter<int>());
0336   triggerCellCell_layer_.reset(new int[1], array_deleter<int>());
0337   triggerCellCell_waferU_.reset(new int[1], array_deleter<int>());
0338   triggerCellCell_waferV_.reset(new int[1], array_deleter<int>());
0339   triggerCellCell_cellU_.reset(new int[1], array_deleter<int>());
0340   triggerCellCell_cellV_.reset(new int[1], array_deleter<int>());
0341   triggerCellCell_ieta_.reset(new int[1], array_deleter<int>());
0342   triggerCellCell_iphi_.reset(new int[1], array_deleter<int>());
0343   triggerCellCell_x_.reset(new float[1], array_deleter<float>());
0344   triggerCellCell_y_.reset(new float[1], array_deleter<float>());
0345   triggerCellCell_z_.reset(new float[1], array_deleter<float>());
0346   triggerCellCell_eta_.reset(new float[1], array_deleter<float>());
0347   triggerCellCell_phi_.reset(new float[1], array_deleter<float>());
0348   treeTriggerCells_->Branch("c_id", triggerCellCell_id_.get(), "c_id[c_n]/I");
0349   treeTriggerCells_->Branch("c_zside", triggerCellCell_zside_.get(), "c_zside[c_n]/I");
0350   treeTriggerCells_->Branch("c_subdet", triggerCellCell_subdet_.get(), "c_subdet[c_n]/I");
0351   treeTriggerCells_->Branch("c_layer", triggerCellCell_layer_.get(), "c_layer[c_n]/I");
0352   treeTriggerCells_->Branch("c_waferu", triggerCellCell_waferU_.get(), "c_waferu[c_n]/I");
0353   treeTriggerCells_->Branch("c_waferv", triggerCellCell_waferV_.get(), "c_waferv[c_n]/I");
0354   treeTriggerCells_->Branch("c_cellu", triggerCellCell_cellU_.get(), "c_cellu[c_n]/I");
0355   treeTriggerCells_->Branch("c_cellv", triggerCellCell_cellV_.get(), "c_cellv[c_n]/I");
0356   treeTriggerCells_->Branch("c_ieta", triggerCellCell_ieta_.get(), "c_cell[c_n]/I");
0357   treeTriggerCells_->Branch("c_iphi", triggerCellCell_iphi_.get(), "c_cell[c_n]/I");
0358   treeTriggerCells_->Branch("c_x", triggerCellCell_x_.get(), "c_x[c_n]/F");
0359   treeTriggerCells_->Branch("c_y", triggerCellCell_y_.get(), "c_y[c_n]/F");
0360   treeTriggerCells_->Branch("c_z", triggerCellCell_z_.get(), "c_z[c_n]/F");
0361   treeTriggerCells_->Branch("c_eta", triggerCellCell_eta_.get(), "c_eta[c_n]/F");
0362   treeTriggerCells_->Branch("c_phi", triggerCellCell_phi_.get(), "c_phi[c_n]/F");
0363   //
0364   treeCells_ = fs->make<TTree>("TreeCells", "Tree of all HGC cells");
0365   treeCells_->Branch("id", &cellId_, "id/I");
0366   treeCells_->Branch("zside", &cellSide_, "zside/I");
0367   treeCells_->Branch("subdet", &cellSubdet_, "subdet/I");
0368   treeCells_->Branch("layer", &cellLayer_, "layer/I");
0369   treeCells_->Branch("waferu", &cellWaferU_, "waferu/I");
0370   treeCells_->Branch("waferv", &cellWaferV_, "waferv/I");
0371   treeCells_->Branch("wafertype", &cellWaferType_, "wafertype/I");
0372   treeCells_->Branch("waferrow", &cellWaferRow_, "waferrow/I");
0373   treeCells_->Branch("wafercolumn", &cellWaferColumn_, "wafercolumn/I");
0374   treeCells_->Branch("cellu", &cellU_, "cellu/I");
0375   treeCells_->Branch("cellv", &cellV_, "cellv/I");
0376   treeCells_->Branch("x", &cellX_, "x/F");
0377   treeCells_->Branch("y", &cellY_, "y/F");
0378   treeCells_->Branch("z", &cellZ_, "z/F");
0379   treeCells_->Branch("eta", &cellEta_, "eta/F");
0380   treeCells_->Branch("phi", &cellPhi_, "phi/F");
0381   treeCells_->Branch("corner_n", &cellCornersN_, "corner_n/I");
0382   treeCells_->Branch("corner_x", cellCornersX_.get(), "corner_x[corner_n]/F");
0383   treeCells_->Branch("corner_y", cellCornersY_.get(), "corner_y[corner_n]/F");
0384   treeCells_->Branch("corner_z", cellCornersZ_.get(), "corner_z[corner_n]/F");
0385   //
0386   treeCellsBH_ = fs->make<TTree>("TreeCellsBH", "Tree of all BH cells");
0387   treeCellsBH_->Branch("id", &cellBHId_, "id/I");
0388   treeCellsBH_->Branch("type", &cellBHType_, "type/I");
0389   treeCellsBH_->Branch("zside", &cellBHSide_, "zside/I");
0390   treeCellsBH_->Branch("subdet", &cellBHSubdet_, "subdet/I");
0391   treeCellsBH_->Branch("layer", &cellBHLayer_, "layer/I");
0392   treeCellsBH_->Branch("ieta", &cellBHIEta_, "ieta/I");
0393   treeCellsBH_->Branch("iphi", &cellBHIPhi_, "iphi/I");
0394   treeCellsBH_->Branch("eta", &cellBHEta_, "eta/F");
0395   treeCellsBH_->Branch("phi", &cellBHPhi_, "phi/F");
0396   treeCellsBH_->Branch("x", &cellBHX_, "x/F");
0397   treeCellsBH_->Branch("y", &cellBHY_, "y/F");
0398   treeCellsBH_->Branch("z", &cellBHZ_, "z/F");
0399   treeCellsBH_->Branch("x1", &cellBHX1_, "x1/F");
0400   treeCellsBH_->Branch("y1", &cellBHY1_, "y1/F");
0401   treeCellsBH_->Branch("x2", &cellBHX2_, "x2/F");
0402   treeCellsBH_->Branch("y2", &cellBHY2_, "y2/F");
0403   treeCellsBH_->Branch("x3", &cellBHX3_, "x3/F");
0404   treeCellsBH_->Branch("y3", &cellBHY3_, "y3/F");
0405   treeCellsBH_->Branch("x4", &cellBHX4_, "x4/F");
0406   treeCellsBH_->Branch("y4", &cellBHY4_, "y4/F");
0407   //
0408   treeCellsNose_ = fs->make<TTree>("TreeCellsNose", "Tree of all HGCnose cells");
0409   treeCellsNose_->Branch("id", &cellId_, "id/I");
0410   treeCellsNose_->Branch("zside", &cellSide_, "zside/I");
0411   treeCellsNose_->Branch("subdet", &cellSubdet_, "subdet/I");
0412   treeCellsNose_->Branch("layer", &cellLayer_, "layer/I");
0413   treeCellsNose_->Branch("waferu", &cellWaferU_, "waferu/I");
0414   treeCellsNose_->Branch("waferv", &cellWaferV_, "waferv/I");
0415   treeCellsNose_->Branch("wafertype", &cellWaferType_, "wafertype/I");
0416   treeCellsNose_->Branch("waferrow", &cellWaferRow_, "waferrow/I");
0417   treeCellsNose_->Branch("wafercolumn", &cellWaferColumn_, "wafercolumn/I");
0418   treeCellsNose_->Branch("cellu", &cellU_, "cellu/I");
0419   treeCellsNose_->Branch("cellv", &cellV_, "cellv/I");
0420   treeCellsNose_->Branch("x", &cellX_, "x/F");
0421   treeCellsNose_->Branch("y", &cellY_, "y/F");
0422   treeCellsNose_->Branch("z", &cellZ_, "z/F");
0423   treeCellsNose_->Branch("eta", &cellEta_, "eta/F");
0424   treeCellsNose_->Branch("phi", &cellPhi_, "phi/F");
0425   treeCellsNose_->Branch("corner_n", &cellCornersN_, "corner_n/I");
0426   treeCellsNose_->Branch("corner_x", cellCornersX_.get(), "corner_x[corner_n]/F");
0427   treeCellsNose_->Branch("corner_y", cellCornersY_.get(), "corner_y[corner_n]/F");
0428   treeCellsNose_->Branch("corner_z", cellCornersZ_.get(), "corner_z[corner_n]/F");
0429   //
0430   treeModuleErrors_ = fs->make<TTree>("TreeModuleErrors", "Tree of module mapping errors");
0431   treeModuleErrors_->Branch("subdet", &moduleErrorSubdet_, "subdet/I");
0432   treeModuleErrors_->Branch("layer", &moduleErrorLayer_, "layer/I");
0433   treeModuleErrors_->Branch("waferu", &moduleErrorWaferU_, "waferu/I");
0434   treeModuleErrors_->Branch("waferv", &moduleErrorWaferV_, "waferv/I");
0435 }
0436 
0437 /*****************************************************************/
0438 void HGCalTriggerGeomTesterV9Imp3::beginRun(const edm::Run& /*run*/, const edm::EventSetup& es)
0439 /*****************************************************************/
0440 {
0441   triggerGeometry_ = es.getHandle(triggerGeomToken_);
0442 
0443   no_trigger_ = !checkMappingConsistency();
0444 
0445   fillTriggerGeometry();
0446 }
0447 
0448 bool HGCalTriggerGeomTesterV9Imp3::checkMappingConsistency() {
0449   try {
0450     // Set of (subdet,layer,waferU,waferV) with module mapping errors
0451     std::set<std::tuple<unsigned, unsigned, int, int>> module_errors;
0452     trigger_map_set modules_to_triggercells;
0453     trigger_map_set modules_to_cells;
0454     trigger_map_set triggercells_to_cells;
0455     // EE
0456     for (const auto& id : triggerGeometry_->eeGeometry()->getValidDetIds()) {
0457       HGCSiliconDetId detid(id);
0458       if (!triggerGeometry_->eeTopology().valid(id))
0459         continue;
0460       // fill trigger cells
0461       uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0462       auto itr_insert = triggercells_to_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0463       itr_insert.first->second.emplace(id);
0464       // fill modules
0465       uint32_t module = 0;
0466       try {
0467         module = triggerGeometry_->getModuleFromCell(id);
0468         triggerGeometry_->getLinksInModule(module);
0469       } catch (const std::exception& e) {
0470         module_errors.emplace(std::make_tuple(HGCalTriggerModuleDetId(module).triggerSubdetId(),
0471                                               HGCalTriggerModuleDetId(module).layer(),
0472                                               HGCalTriggerModuleDetId(module).moduleU(),
0473                                               HGCalTriggerModuleDetId(module).moduleV()));
0474         continue;
0475       }
0476       itr_insert = modules_to_cells.emplace(module, std::unordered_set<uint32_t>());
0477       itr_insert.first->second.emplace(id);
0478     }
0479 
0480     // HSi
0481     for (const auto& id : triggerGeometry_->hsiGeometry()->getValidDetIds()) {
0482       if (!triggerGeometry_->hsiTopology().valid(id))
0483         continue;
0484       // fill trigger cells
0485       uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0486       auto itr_insert = triggercells_to_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0487       itr_insert.first->second.emplace(id);
0488       // fill modules
0489       uint32_t module = 0;
0490       try {
0491         module = triggerGeometry_->getModuleFromCell(id);
0492         triggerGeometry_->getLinksInModule(module);
0493       } catch (const std::exception& e) {
0494         module_errors.emplace(std::make_tuple(HGCalTriggerModuleDetId(module).triggerSubdetId(),
0495                                               HGCalTriggerModuleDetId(module).layer(),
0496                                               HGCalTriggerModuleDetId(module).moduleU(),
0497                                               HGCalTriggerModuleDetId(module).moduleV()));
0498         continue;
0499       }
0500       itr_insert = modules_to_cells.emplace(module, std::unordered_set<uint32_t>());
0501       itr_insert.first->second.emplace(id);
0502     }
0503 
0504     // HSc
0505     for (const auto& id : triggerGeometry_->hscGeometry()->getValidDetIds()) {
0506       // fill trigger cells
0507       unsigned layer = HGCScintillatorDetId(id).layer();
0508       if (HGCScintillatorDetId(id).type() != triggerGeometry_->hscTopology().dddConstants().getTypeTrap(layer)) {
0509         std::cout << "Sci cell type = " << HGCScintillatorDetId(id).type()
0510                   << " != " << triggerGeometry_->hscTopology().dddConstants().getTypeTrap(layer) << "\n";
0511       }
0512       uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0513       auto itr_insert = triggercells_to_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0514       itr_insert.first->second.emplace(id);
0515       // fill modules
0516       uint32_t module = triggerGeometry_->getModuleFromCell(id);
0517       if (module != 0) {
0518         itr_insert = modules_to_cells.emplace(module, std::unordered_set<uint32_t>());
0519         itr_insert.first->second.emplace(id);
0520       }
0521     }
0522 
0523     // NOSE
0524     if (triggerGeometry_->isWithNoseGeometry()) {
0525       for (const auto& id : triggerGeometry_->noseGeometry()->getValidDetIds()) {
0526         if (!triggerGeometry_->noseTopology().valid(id))
0527           continue;
0528         // fill trigger cells
0529         uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0530         auto itr_insert = triggercells_to_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0531         itr_insert.first->second.emplace(id);
0532         // fill modules
0533         uint32_t module = triggerGeometry_->getModuleFromCell(id);
0534         if (module != 0) {
0535           itr_insert = modules_to_cells.emplace(module, std::unordered_set<uint32_t>());
0536           itr_insert.first->second.emplace(id);
0537         }
0538       }
0539     }
0540 
0541     if (module_errors.size() > 0) {
0542       for (const auto& module : module_errors) {
0543         moduleErrorSubdet_ = std::get<0>(module);
0544         moduleErrorLayer_ = std::get<1>(module);
0545         moduleErrorWaferU_ = std::get<2>(module);
0546         moduleErrorWaferV_ = std::get<3>(module);
0547         treeModuleErrors_->Fill();
0548       }
0549       throw cms::Exception("BadGeometry") << "HGCalTriggerGeometry: Found  module mapping problems. Check the produced "
0550                                              "tree to see the list of problematic wafers";
0551     }
0552 
0553     edm::LogPrint("TriggerCellCheck") << "Checking cell -> trigger cell -> cell consistency";
0554     // Loop over trigger cells
0555     for (const auto& triggercell_cells : triggercells_to_cells) {
0556       DetId id(triggercell_cells.first);
0557 
0558       // fill modules
0559       uint32_t module = triggerGeometry_->getModuleFromTriggerCell(id);
0560       if (module != 0) {
0561         auto itr_insert = modules_to_triggercells.emplace(module, std::unordered_set<uint32_t>());
0562         itr_insert.first->second.emplace(id);
0563       }
0564 
0565       // Check consistency of cells included in trigger cell
0566       HGCalTriggerGeometryBase::geom_set cells_geom = triggerGeometry_->getCellsFromTriggerCell(id);
0567       const auto& cells = triggercell_cells.second;
0568       for (auto cell : cells) {
0569         if (cells_geom.find(cell) == cells_geom.end()) {
0570           if (id.det() == DetId::HGCalHSc) {
0571             edm::LogProblem("BadTriggerCell")
0572                 << "Error: \n Cell " << cell << "(" << HGCScintillatorDetId(cell)
0573                 << ")\n has not been found in \n trigger cell " << HGCScintillatorDetId(id);
0574             std::stringstream output;
0575             output << " Available cells are:\n";
0576             for (auto cell_geom : cells_geom)
0577               output << "     " << HGCScintillatorDetId(cell_geom) << "\n";
0578             edm::LogProblem("BadTriggerCell") << output.str();
0579           } else if (HFNoseTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0580             edm::LogProblem("BadTriggerCell")
0581                 << "Error: \n Cell " << cell << "(" << HFNoseDetId(cell) << ")\n has not been found in \n trigger cell "
0582                 << HFNoseTriggerDetId(triggercell_cells.first);
0583             std::stringstream output;
0584             output << " Available cells are:\n";
0585             for (auto cell_geom : cells_geom)
0586               output << "     " << HFNoseDetId(cell_geom) << "\n";
0587             edm::LogProblem("BadTriggerCell") << output.str();
0588           } else if (HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalEETrigger ||
0589                      HGCalTriggerDetId(id).subdet() == HGCalTriggerSubdetector::HGCalHSiTrigger) {
0590             edm::LogProblem("BadTriggerCell")
0591                 << "Error: \n Cell " << cell << "(" << HGCSiliconDetId(cell)
0592                 << ")\n has not been found in \n trigger cell " << HGCalTriggerDetId(triggercell_cells.first);
0593             std::stringstream output;
0594             output << " Available cells are:\n";
0595             for (auto cell_geom : cells_geom)
0596               output << "     " << HGCSiliconDetId(cell_geom) << "\n";
0597             edm::LogProblem("BadTriggerCell") << output.str();
0598           } else {
0599             edm::LogProblem("BadTriggerCell")
0600                 << "Unknown detector type " << id.det() << " " << id.subdetId() << " " << id.rawId() << "\n";
0601             edm::LogProblem("BadTriggerCell") << " cell " << std::hex << cell << std::dec << " "
0602                                               << "\n";
0603             edm::LogProblem("BadTriggerCell")
0604                 << "Cell ID " << HGCSiliconDetId(cell) << " or " << HFNoseDetId(cell) << "\n";
0605           }
0606           throw cms::Exception("BadGeometry")
0607               << "HGCalTriggerGeometry: Found inconsistency in cell <-> trigger cell mapping";
0608         }
0609       }
0610     }
0611     edm::LogPrint("ModuleCheck") << "Checking trigger cell -> module -> trigger cell consistency";
0612     // Loop over modules
0613     for (const auto& module_triggercells : modules_to_triggercells) {
0614       HGCalTriggerModuleDetId id(module_triggercells.first);
0615       // Check consistency of trigger cells included in module
0616       HGCalTriggerGeometryBase::geom_set triggercells_geom = triggerGeometry_->getTriggerCellsFromModule(id);
0617       const auto& triggercells = module_triggercells.second;
0618       for (auto cell : triggercells) {
0619         if (triggercells_geom.find(cell) == triggercells_geom.end()) {
0620           if (id.triggerSubdetId() == HGCalTriggerSubdetector::HGCalHScTrigger) {
0621             HGCScintillatorDetId cellid(cell);
0622             edm::LogProblem("BadModule") << "Error: \n Trigger cell " << cell << "(" << cellid
0623                                          << ")\n has not been found in \n module " << HGCalTriggerModuleDetId(id);
0624             std::stringstream output;
0625             output << " Available trigger cells are:\n";
0626             for (auto cell_geom : triggercells_geom) {
0627               output << "     " << HGCScintillatorDetId(cell_geom) << "\n";
0628             }
0629             edm::LogProblem("BadModule") << output.str();
0630             throw cms::Exception("BadGeometry")
0631                 << "HGCalTriggerGeometry: Found inconsistency in trigger cell <->  module mapping";
0632           } else if (id.triggerSubdetId() == HGCalTriggerSubdetector::HFNoseTrigger) {
0633             HFNoseTriggerDetId cellid(cell);
0634             edm::LogProblem("BadModule") << "Error : \n Trigger cell " << cell << "(" << cellid
0635                                          << ")\n has not been found in \n module " << HGCalTriggerModuleDetId(id);
0636             std::stringstream output;
0637             output << " Available trigger cells are:\n";
0638             for (auto cell_geom : triggercells_geom) {
0639               output << "     " << HFNoseTriggerDetId(cell_geom) << "\n";
0640             }
0641             edm::LogProblem("BadModule") << output.str();
0642             throw cms::Exception("BadGeometry")
0643                 << "HGCalTriggerGeometry: Found inconsistency in trigger cell <->  module mapping";
0644           } else {
0645             HGCalTriggerDetId cellid(cell);
0646             edm::LogProblem("BadModule") << "Error : \n Trigger cell " << cell << "(" << cellid
0647                                          << ")\n has not been found in \n module " << HGCalTriggerModuleDetId(id);
0648             std::stringstream output;
0649             output << " Available trigger cells are:\n";
0650             for (auto cell_geom : triggercells_geom) {
0651               output << "     " << HGCalTriggerDetId(cell_geom) << "\n";
0652             }
0653             edm::LogProblem("BadModule") << output.str();
0654             throw cms::Exception("BadGeometry")
0655                 << "HGCalTriggerGeometry: Found inconsistency in trigger cell <->  module mapping";
0656           }
0657         }
0658       }
0659     }
0660     edm::LogPrint("ModuleCheck") << "Checking cell -> module -> cell consistency";
0661     for (const auto& module_cells : modules_to_cells) {
0662       HGCalTriggerModuleDetId id(module_cells.first);
0663       // Check consistency of cells included in module
0664       HGCalTriggerGeometryBase::geom_set cells_geom = triggerGeometry_->getCellsFromModule(id);
0665       const auto& cells = module_cells.second;
0666       for (auto cell : cells) {
0667         if (cells_geom.find(cell) == cells_geom.end()) {
0668           if (id.triggerSubdetId() == HGCalTriggerSubdetector::HGCalHScTrigger) {
0669             edm::LogProblem("BadModule") << "Error: \n Cell " << cell << "(" << HGCScintillatorDetId(cell)
0670                                          << ")\n has not been found in \n module " << HGCalTriggerModuleDetId(id);
0671           } else if (id.triggerSubdetId() == HGCalTriggerSubdetector::HFNoseTrigger) {
0672             edm::LogProblem("BadModule") << "Error: \n Cell " << cell << "(" << HFNoseDetId(cell)
0673                                          << ")\n has not been found in \n module " << HGCalTriggerModuleDetId(id);
0674           } else {
0675             edm::LogProblem("BadModule") << "Error: \n Cell " << cell << "(" << HGCSiliconDetId(cell)
0676                                          << ")\n has not been found in \n module " << HGCalTriggerModuleDetId(id);
0677           }
0678           std::stringstream output;
0679           output << " Available cells are:\n";
0680           for (auto cell_geom : cells_geom) {
0681             output << cell_geom << " ";
0682           }
0683           edm::LogProblem("BadModule") << output.str();
0684           throw cms::Exception("BadGeometry") << "HGCalTriggerGeometry: Found inconsistency in cell <-> module mapping";
0685         }
0686       }
0687     }
0688 
0689     // Filling Stage 1 FPGA -> modules
0690 
0691     edm::LogPrint("ModuleCheck") << "Checking module -> stage-1 -> module consistency";
0692     trigger_map_set stage1_to_modules;
0693     for (const auto& module_tc : modules_to_triggercells) {
0694       HGCalTriggerModuleDetId id(module_tc.first);
0695       HGCalTriggerGeometryBase::geom_set lpgbts = triggerGeometry_->getLpgbtsFromModule(id);
0696       if (lpgbts.size() == 0)
0697         continue;  //Module is not connected to an lpGBT and therefore not to a Stage 1 FPGA
0698       uint32_t stage1 = 0;
0699       for (const auto& lpgbt : lpgbts) {
0700         uint32_t stage1_tmp = triggerGeometry_->getStage1FpgaFromLpgbt(lpgbt);
0701         if (stage1 != 0 && stage1_tmp != stage1) {
0702           throw cms::Exception("BadGeometry") << "HGCalTriggerGeometry: Module " << HGCalTriggerModuleDetId(id)
0703                                               << " is split is split into more than one Stage-1 FPGA";
0704         }
0705         stage1 = stage1_tmp;
0706       }
0707       auto itr_insert = stage1_to_modules.emplace(stage1, std::unordered_set<uint32_t>());
0708       itr_insert.first->second.emplace(id);
0709     }
0710     // checking S1 -> module consistency
0711 
0712     for (const auto& stage1_modules : stage1_to_modules) {
0713       HGCalTriggerBackendDetId stage1(stage1_modules.first);
0714       HGCalTriggerGeometryBase::geom_set modules_geom;
0715       // Check consistency of modules going to Stage-1 FPGA
0716       HGCalTriggerGeometryBase::geom_set lpgbts = triggerGeometry_->getLpgbtsFromStage1Fpga(stage1);
0717       for (const auto& lpgbt : lpgbts) {
0718         HGCalTriggerGeometryBase::geom_set modules = triggerGeometry_->getModulesFromLpgbt(lpgbt);
0719         modules_geom.insert(modules.begin(), modules.end());
0720       }
0721       const auto& modules = stage1_modules.second;
0722       for (auto module : modules) {
0723         if (modules_geom.find(module) == modules_geom.end()) {
0724           edm::LogProblem("BadStage1") << "Error: \n Module " << module << "(" << HGCalTriggerModuleDetId(module)
0725                                        << ")\n has not been found in \n stage-1 " << HGCalTriggerBackendDetId(stage1);
0726           std::stringstream output;
0727           output << "   Available modules are:\n";
0728           for (auto module_geom : modules_geom) {
0729             output << module_geom << " ";
0730           }
0731           output << "   Connected lpgbts are:\n";
0732           for (auto lpgbt : lpgbts) {
0733             output << lpgbt << " ";
0734           }
0735           edm::LogProblem("BadStage1") << output.str();
0736           throw cms::Exception("BadGeometry")
0737               << "HGCalTriggerGeometry: Found inconsistency in Stage1 <-> module mapping";
0738         }
0739       }
0740     }
0741 
0742     // Filling Stage 2 FPGA -> Stage 1 FPGA
0743 
0744     edm::LogPrint("ModuleCheck") << "Checking Stage 1 -> Stage 2 -> Stage 1 consistency";
0745     trigger_map_set stage2_to_stage1;
0746     for (const auto& stage1 : stage1_to_modules) {
0747       HGCalTriggerBackendDetId id(stage1.first);
0748       HGCalTriggerGeometryBase::geom_set stage2FPGAs = triggerGeometry_->getStage2FpgasFromStage1Fpga(id);
0749       for (const auto& stage2 : stage2FPGAs) {
0750         auto itr_insert = stage2_to_stage1.emplace(stage2, std::unordered_set<uint32_t>());
0751         itr_insert.first->second.emplace(id);
0752       }
0753     }
0754     // checking S1 -> S2 consistency
0755 
0756     for (const auto& stage2_modules : stage2_to_stage1) {
0757       HGCalTriggerBackendDetId stage2(stage2_modules.first);
0758 
0759       // Check consistency of Stage-1 FPGA going to Stage 2 FPGA
0760       HGCalTriggerGeometryBase::geom_set stage1FPGAs = triggerGeometry_->getStage1FpgasFromStage2Fpga(stage2);
0761 
0762       const auto& stage1fpgas = stage2_modules.second;
0763 
0764       for (auto stage1fpga : stage1fpgas) {
0765         if (stage1FPGAs.find(stage1fpga) == stage1FPGAs.end()) {
0766           edm::LogProblem("BadStage2") << "Error: \n Stage-1 FPGA " << stage1fpga << "("
0767                                        << HGCalTriggerBackendDetId(stage1fpga)
0768                                        << ")\n has not been found in \n Stage-2 " << HGCalTriggerBackendDetId(stage2);
0769           std::stringstream output;
0770           output << "\n   Available Stage-1 FPGAs are:\n";
0771           for (auto stage1FPGA : stage1FPGAs) {
0772             output << HGCalTriggerBackendDetId(stage1FPGA) << "\n";
0773           }
0774           edm::LogProblem("BadStage2") << output.str();
0775           throw cms::Exception("BadGeometry")
0776               << "HGCalTriggerGeometry: Found inconsistency in Stage2 <-> Stage1 mapping";
0777         }
0778       }
0779     }
0780 
0781   } catch (const cms::Exception& e) {
0782     edm::LogWarning("HGCalTriggerGeometryTester")
0783         << "Problem with the trigger geometry detected. Only the basic cells tree will be filled\n";
0784     edm::LogWarning("HGCalTriggerGeometryTester") << e.message() << "\n";
0785     return false;
0786   }
0787   return true;
0788 }
0789 
0790 /*****************************************************************/
0791 void HGCalTriggerGeomTesterV9Imp3::fillTriggerGeometry()
0792 /*****************************************************************/
0793 {
0794   trigger_map_set modules;
0795   trigger_map_set trigger_cells;
0796 
0797   // Loop over cells
0798   edm::LogPrint("TreeFilling") << "Filling cells tree";
0799   // EE
0800   std::cout << "Filling EE geometry\n";
0801   for (const auto& id : triggerGeometry_->eeGeometry()->getValidDetIds()) {
0802     HGCSiliconDetId detid(id);
0803     if (!triggerGeometry_->eeTopology().valid(id))
0804       continue;
0805     cellId_ = detid.rawId();
0806     cellSide_ = detid.zside();
0807     cellSubdet_ = detid.subdet();
0808     cellLayer_ = detid.layer();
0809     cellWaferU_ = detid.waferU();
0810     cellWaferV_ = detid.waferV();
0811     cellU_ = detid.cellU();
0812     cellV_ = detid.cellV();
0813     int type1 = detid.type();
0814     int type2 = triggerGeometry_->eeTopology().dddConstants().getTypeHex(cellLayer_, cellWaferU_, cellWaferV_);
0815     if (type1 != type2) {
0816       std::cout << "Found incompatible wafer types:\n  " << detid << "\n";
0817     }
0818     //
0819     GlobalPoint center = triggerGeometry_->eeGeometry()->getPosition(id);
0820     cellX_ = center.x();
0821     cellY_ = center.y();
0822     cellZ_ = center.z();
0823     cellEta_ = center.eta();
0824     cellPhi_ = center.phi();
0825     std::vector<GlobalPoint> corners = triggerGeometry_->eeGeometry()->getCorners(id);
0826     cellCornersN_ = corners.size();
0827     setTreeCellCornerSize(cellCornersN_);
0828     for (unsigned i = 0; i < corners.size(); i++) {
0829       cellCornersX_.get()[i] = corners[i].x();
0830       cellCornersY_.get()[i] = corners[i].y();
0831       cellCornersZ_.get()[i] = corners[i].z();
0832     }
0833     treeCells_->Fill();
0834     // fill trigger cells
0835     if (!no_trigger_) {
0836       uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0837       // Skip trigger cells in module 0
0838       // uint32_t module = triggerGeometry_->getModuleFromTriggerCell(trigger_cell);
0839       //if (HGCalDetId(module).wafer() == 0)
0840       //  continue;
0841       auto itr_insert = trigger_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0842       itr_insert.first->second.emplace(id);
0843     }
0844   }
0845   std::cout << "Filling HSi geometry\n";
0846   for (const auto& id : triggerGeometry_->hsiGeometry()->getValidDetIds()) {
0847     HGCSiliconDetId detid(id);
0848     if (!triggerGeometry_->hsiTopology().valid(id))
0849       continue;
0850     cellId_ = detid.rawId();
0851     cellSide_ = detid.zside();
0852     cellSubdet_ = detid.subdet();
0853     cellLayer_ = detid.layer();
0854     cellWaferU_ = detid.waferU();
0855     cellWaferV_ = detid.waferV();
0856     cellU_ = detid.cellU();
0857     cellV_ = detid.cellV();
0858     int type1 = detid.type();
0859     int type2 = triggerGeometry_->hsiTopology().dddConstants().getTypeHex(cellLayer_, cellWaferU_, cellWaferV_);
0860     if (type1 != type2) {
0861       std::cout << "Found incompatible wafer types:\n  " << detid << "\n";
0862     }
0863     //
0864     GlobalPoint center = triggerGeometry_->hsiGeometry()->getPosition(id);
0865     cellX_ = center.x();
0866     cellY_ = center.y();
0867     cellZ_ = center.z();
0868     cellEta_ = center.eta();
0869     cellPhi_ = center.phi();
0870     std::vector<GlobalPoint> corners = triggerGeometry_->hsiGeometry()->getCorners(id);
0871     cellCornersN_ = corners.size();
0872     setTreeCellCornerSize(cellCornersN_);
0873     for (unsigned i = 0; i < corners.size(); i++) {
0874       cellCornersX_.get()[i] = corners[i].x();
0875       cellCornersY_.get()[i] = corners[i].y();
0876       cellCornersZ_.get()[i] = corners[i].z();
0877     }
0878     treeCells_->Fill();
0879     // fill trigger cells
0880     if (!no_trigger_) {
0881       uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0882       // Skip trigger cells in module 0
0883       // uint32_t module = triggerGeometry_->getModuleFromTriggerCell(trigger_cell);
0884       //if (HGCalDetId(module).wafer() == 0)
0885       //  continue;
0886       auto itr_insert = trigger_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0887       itr_insert.first->second.emplace(id);
0888     }
0889   }
0890   std::cout << "Filling HSc geometry\n";
0891   for (const auto& id : triggerGeometry_->hscGeometry()->getValidDetIds()) {
0892     HGCScintillatorDetId cellid(id);
0893     cellBHId_ = cellid.rawId();
0894     cellBHType_ = cellid.type();
0895     cellBHSide_ = cellid.zside();
0896     cellBHSubdet_ = cellid.subdet();
0897     cellBHLayer_ = cellid.layer();
0898     cellBHIEta_ = cellid.ieta();
0899     cellBHIPhi_ = cellid.iphi();
0900     //
0901     GlobalPoint center = triggerGeometry_->hscGeometry()->getPosition(id);
0902     cellBHEta_ = center.eta();
0903     cellBHPhi_ = center.phi();
0904     cellBHX_ = center.x();
0905     cellBHY_ = center.y();
0906     cellBHZ_ = center.z();
0907     auto corners = triggerGeometry_->hscGeometry()->getCorners(id);
0908     if (corners.size() >= 4) {
0909       cellBHX1_ = corners[0].x();
0910       cellBHY1_ = corners[0].y();
0911       cellBHX2_ = corners[1].x();
0912       cellBHY2_ = corners[1].y();
0913       cellBHX3_ = corners[2].x();
0914       cellBHY3_ = corners[2].y();
0915       cellBHX4_ = corners[3].x();
0916       cellBHY4_ = corners[3].y();
0917     }
0918     treeCellsBH_->Fill();
0919     // fill trigger cells
0920     if (!no_trigger_) {
0921       uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0922       auto itr_insert = trigger_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0923       itr_insert.first->second.emplace(id);
0924     }
0925   }
0926 
0927   if (triggerGeometry_->isWithNoseGeometry()) {
0928     // NOSE
0929     std::cout << "Filling NOSE geometry\n";
0930     for (const auto& id : triggerGeometry_->noseGeometry()->getValidDetIds()) {
0931       HFNoseDetId detid(id);
0932       cellId_ = detid.rawId();
0933       cellSide_ = detid.zside();
0934       cellSubdet_ = detid.subdet();
0935       cellLayer_ = detid.layer();
0936       cellWaferU_ = detid.waferU();
0937       cellWaferV_ = detid.waferV();
0938       cellU_ = detid.cellU();
0939       cellV_ = detid.cellV();
0940       int type1 = detid.type();
0941       int type2 = triggerGeometry_->noseTopology().dddConstants().getTypeHex(cellLayer_, cellWaferU_, cellWaferV_);
0942       if (type1 != type2) {
0943         std::cout << "Found incompatible wafer types:\n  " << detid << "\n";
0944       }
0945       GlobalPoint center = triggerGeometry_->noseGeometry()->getPosition(id);
0946       cellX_ = center.x();
0947       cellY_ = center.y();
0948       cellZ_ = center.z();
0949       cellEta_ = center.eta();
0950       cellPhi_ = center.phi();
0951       std::vector<GlobalPoint> corners = triggerGeometry_->noseGeometry()->getCorners(id);
0952       cellCornersN_ = corners.size();
0953       setTreeCellCornerSize(cellCornersN_);
0954       for (unsigned i = 0; i < corners.size(); i++) {
0955         cellCornersX_.get()[i] = corners[i].x();
0956         cellCornersY_.get()[i] = corners[i].y();
0957         cellCornersZ_.get()[i] = corners[i].z();
0958       }
0959       treeCellsNose_->Fill();
0960       // fill trigger cells
0961       if (!no_trigger_) {
0962         uint32_t trigger_cell = triggerGeometry_->getTriggerCellFromCell(id);
0963         // Skip trigger cells in module 0
0964         // uint32_t module = triggerGeometry_->getModuleFromTriggerCell(trigger_cell);
0965         //if (HGCalDetId(module).wafer() == 0)
0966         //  continue;
0967         auto itr_insert = trigger_cells.emplace(trigger_cell, std::unordered_set<uint32_t>());
0968         itr_insert.first->second.emplace(id);
0969       }
0970     }
0971   }
0972 
0973   // if problem detected in the trigger geometry, don't produce trigger trees
0974   if (no_trigger_)
0975     return;
0976 
0977   // Loop over trigger cells
0978   edm::LogPrint("TreeFilling") << "Filling trigger cells tree";
0979   for (const auto& triggercell_cells : trigger_cells) {
0980     DetId id(triggercell_cells.first);
0981     GlobalPoint position = triggerGeometry_->getTriggerCellPosition(triggercell_cells.first);
0982     triggerCellId_ = id.rawId();
0983     if (id.det() == DetId::HGCalHSc) {
0984       HGCScintillatorDetId id_sc(triggercell_cells.first);
0985       triggerCellSide_ = id_sc.zside();
0986       triggerCellSubdet_ = id_sc.subdet();
0987       triggerCellLayer_ = id_sc.layer();
0988       triggerCellIEta_ = id_sc.ietaAbs();
0989       triggerCellIPhi_ = id_sc.iphi();
0990       triggerCellWaferU_ = 0;
0991       triggerCellWaferV_ = 0;
0992       triggerCellU_ = 0;
0993       triggerCellV_ = 0;
0994     } else if (HFNoseTriggerDetId(triggercell_cells.first).det() == DetId::HGCalTrigger &&
0995                HFNoseTriggerDetId(triggercell_cells.first).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
0996       HFNoseTriggerDetId id_nose_trig(triggercell_cells.first);
0997       triggerCellSide_ = id_nose_trig.zside();
0998       triggerCellSubdet_ = id_nose_trig.subdet();
0999       triggerCellLayer_ = id_nose_trig.layer();
1000       triggerCellIEta_ = 0;
1001       triggerCellIPhi_ = 0;
1002       triggerCellWaferU_ = id_nose_trig.waferU();
1003       triggerCellWaferV_ = id_nose_trig.waferV();
1004       triggerCellU_ = id_nose_trig.triggerCellU();
1005       triggerCellV_ = id_nose_trig.triggerCellV();
1006     } else {
1007       HGCalTriggerDetId id_si_trig(triggercell_cells.first);
1008       triggerCellSide_ = id_si_trig.zside();
1009       triggerCellSubdet_ = id_si_trig.subdet();
1010       triggerCellLayer_ = id_si_trig.layer();
1011       triggerCellIEta_ = 0;
1012       triggerCellIPhi_ = 0;
1013       triggerCellWaferU_ = id_si_trig.waferU();
1014       triggerCellWaferV_ = id_si_trig.waferV();
1015       triggerCellU_ = id_si_trig.triggerCellU();
1016       triggerCellV_ = id_si_trig.triggerCellV();
1017     }
1018     triggerCellX_ = position.x();
1019     triggerCellY_ = position.y();
1020     triggerCellZ_ = position.z();
1021     triggerCellEta_ = position.eta();
1022     triggerCellPhi_ = position.phi();
1023     triggerCellCell_N_ = triggercell_cells.second.size();
1024     //
1025     setTreeTriggerCellSize(triggerCellCell_N_);
1026     size_t ic = 0;
1027     for (const auto& c : triggercell_cells.second) {
1028       if (id.det() == DetId::HGCalHSc) {
1029         HGCScintillatorDetId cId(c);
1030         GlobalPoint cell_position = triggerGeometry_->hscGeometry()->getPosition(cId);
1031         triggerCellCell_id_.get()[ic] = c;
1032         triggerCellCell_zside_.get()[ic] = cId.zside();
1033         triggerCellCell_subdet_.get()[ic] = cId.subdetId();
1034         triggerCellCell_layer_.get()[ic] = cId.layer();
1035         triggerCellCell_waferU_.get()[ic] = 0;
1036         triggerCellCell_waferV_.get()[ic] = 0;
1037         triggerCellCell_cellU_.get()[ic] = 0;
1038         triggerCellCell_cellV_.get()[ic] = 0;
1039         triggerCellCell_ieta_.get()[ic] = cId.ietaAbs();
1040         triggerCellCell_iphi_.get()[ic] = cId.iphi();
1041         triggerCellCell_x_.get()[ic] = cell_position.x();
1042         triggerCellCell_y_.get()[ic] = cell_position.y();
1043         triggerCellCell_z_.get()[ic] = cell_position.z();
1044         triggerCellCell_eta_.get()[ic] = cell_position.eta();
1045         triggerCellCell_phi_.get()[ic] = cell_position.phi();
1046       } else if (HFNoseTriggerDetId(triggercell_cells.first).det() == DetId::HGCalTrigger &&
1047                  HFNoseTriggerDetId(triggercell_cells.first).subdet() == HGCalTriggerSubdetector::HFNoseTrigger) {
1048         HFNoseDetId cId(c);
1049         GlobalPoint cell_position = triggerGeometry_->noseGeometry()->getPosition(cId);
1050         triggerCellCell_id_.get()[ic] = c;
1051         triggerCellCell_zside_.get()[ic] = cId.zside();
1052         triggerCellCell_subdet_.get()[ic] = cId.subdet();
1053         triggerCellCell_layer_.get()[ic] = cId.layer();
1054         triggerCellCell_waferU_.get()[ic] = cId.waferU();
1055         triggerCellCell_waferV_.get()[ic] = cId.waferV();
1056         triggerCellCell_cellU_.get()[ic] = cId.cellU();
1057         triggerCellCell_cellV_.get()[ic] = cId.cellV();
1058         triggerCellCell_ieta_.get()[ic] = 0;
1059         triggerCellCell_iphi_.get()[ic] = 0;
1060         triggerCellCell_x_.get()[ic] = cell_position.x();
1061         triggerCellCell_y_.get()[ic] = cell_position.y();
1062         triggerCellCell_z_.get()[ic] = cell_position.z();
1063         triggerCellCell_eta_.get()[ic] = cell_position.eta();
1064         triggerCellCell_phi_.get()[ic] = cell_position.phi();
1065       } else {
1066         HGCSiliconDetId cId(c);
1067         GlobalPoint cell_position = (cId.det() == DetId::HGCalEE ? triggerGeometry_->eeGeometry()->getPosition(cId)
1068                                                                  : triggerGeometry_->hsiGeometry()->getPosition(cId));
1069         triggerCellCell_id_.get()[ic] = c;
1070         triggerCellCell_zside_.get()[ic] = cId.zside();
1071         triggerCellCell_subdet_.get()[ic] = cId.subdet();
1072         triggerCellCell_layer_.get()[ic] = cId.layer();
1073         triggerCellCell_waferU_.get()[ic] = cId.waferU();
1074         triggerCellCell_waferV_.get()[ic] = cId.waferV();
1075         triggerCellCell_cellU_.get()[ic] = cId.cellU();
1076         triggerCellCell_cellV_.get()[ic] = cId.cellV();
1077         triggerCellCell_ieta_.get()[ic] = 0;
1078         triggerCellCell_iphi_.get()[ic] = 0;
1079         triggerCellCell_x_.get()[ic] = cell_position.x();
1080         triggerCellCell_y_.get()[ic] = cell_position.y();
1081         triggerCellCell_z_.get()[ic] = cell_position.z();
1082         triggerCellCell_eta_.get()[ic] = cell_position.eta();
1083         triggerCellCell_phi_.get()[ic] = cell_position.phi();
1084       }
1085       ic++;
1086     }
1087 
1088     treeTriggerCells_->Fill();
1089 
1090     // fill modules
1091     uint32_t module = triggerGeometry_->getModuleFromTriggerCell(id);
1092     auto itr_insert = modules.emplace(module, std::unordered_set<uint32_t>());
1093     itr_insert.first->second.emplace(id);
1094   }
1095 
1096   // Loop over modules
1097   edm::LogPrint("TreeFilling") << "Filling modules tree";
1098 
1099   for (const auto& module_triggercells : modules) {
1100     HGCalTriggerModuleDetId id(module_triggercells.first);
1101     GlobalPoint position = triggerGeometry_->getModulePosition(id);
1102     moduleId_ = id.rawId();
1103     moduleX_ = position.x();
1104     moduleY_ = position.y();
1105     moduleZ_ = position.z();
1106     moduleEta_ = position.eta();
1107     modulePhi_ = position.phi();
1108 
1109     moduleSide_ = id.zside();
1110     moduleSubdet_ = id.triggerSubdetId();
1111     moduleLayer_ = id.layer();
1112     module_ = 0;
1113     if (moduleSubdet_ == HGCalTriggerSubdetector::HGCalHScTrigger) {
1114       moduleIEta_ = id.eta();
1115       moduleIPhi_ = id.phi();
1116     } else {
1117       moduleIEta_ = 0;
1118       moduleIPhi_ = 0;
1119     }
1120     moduleTC_N_ = module_triggercells.second.size();
1121     if (triggerGeometry_->disconnectedModule(id)) {
1122       moduleLinks_ = 0;
1123     } else {
1124       moduleLinks_ = triggerGeometry_->getLinksInModule(id);
1125     }
1126     //
1127     setTreeModuleSize(moduleTC_N_);
1128     size_t itc = 0;
1129     for (const auto& tc : module_triggercells.second) {
1130       moduleTC_id_.get()[itc] = tc;
1131       if (moduleSubdet_ == HGCalTriggerSubdetector::HGCalHScTrigger) {
1132         HGCScintillatorDetId tcId(tc);
1133         moduleTC_zside_.get()[itc] = tcId.zside();
1134         moduleTC_subdet_.get()[itc] = tcId.subdet();
1135         moduleTC_layer_.get()[itc] = tcId.layer();
1136         moduleTC_waferU_.get()[itc] = 0;
1137         moduleTC_waferV_.get()[itc] = 0;
1138         moduleTC_cellU_.get()[itc] = 0;
1139         moduleTC_cellV_.get()[itc] = 0;
1140         moduleTC_ieta_.get()[itc] = tcId.ietaAbs();
1141         moduleTC_iphi_.get()[itc] = tcId.iphi();
1142       } else if (moduleSubdet_ == HGCalTriggerSubdetector::HFNoseTrigger) {
1143         HFNoseTriggerDetId tcId(tc);
1144         moduleTC_zside_.get()[itc] = tcId.zside();
1145         moduleTC_subdet_.get()[itc] = tcId.subdet();
1146         moduleTC_layer_.get()[itc] = tcId.layer();
1147         moduleTC_waferU_.get()[itc] = tcId.waferU();
1148         moduleTC_waferV_.get()[itc] = tcId.waferV();
1149         moduleTC_cellU_.get()[itc] = tcId.triggerCellU();
1150         moduleTC_cellV_.get()[itc] = tcId.triggerCellV();
1151         moduleTC_ieta_.get()[itc] = 0;
1152         moduleTC_iphi_.get()[itc] = 0;
1153       } else {
1154         HGCalTriggerDetId tcId(tc);
1155         moduleTC_zside_.get()[itc] = tcId.zside();
1156         moduleTC_subdet_.get()[itc] = tcId.subdet();
1157         moduleTC_layer_.get()[itc] = tcId.layer();
1158         moduleTC_waferU_.get()[itc] = tcId.waferU();
1159         moduleTC_waferV_.get()[itc] = tcId.waferV();
1160         moduleTC_cellU_.get()[itc] = tcId.triggerCellU();
1161         moduleTC_cellV_.get()[itc] = tcId.triggerCellV();
1162         moduleTC_ieta_.get()[itc] = 0;
1163         moduleTC_iphi_.get()[itc] = 0;
1164       }
1165       GlobalPoint position = triggerGeometry_->getTriggerCellPosition(tc);
1166       moduleTC_x_.get()[itc] = position.x();
1167       moduleTC_y_.get()[itc] = position.y();
1168       moduleTC_z_.get()[itc] = position.z();
1169       moduleTC_eta_.get()[itc] = position.eta();
1170       moduleTC_phi_.get()[itc] = position.phi();
1171       itc++;
1172     }
1173     auto cells_in_module = triggerGeometry_->getCellsFromModule(id);
1174     moduleCell_N_ = cells_in_module.size();
1175     //
1176     setTreeModuleCellSize(moduleCell_N_);
1177     size_t ic = 0;
1178     for (const auto& c : cells_in_module) {
1179       if (moduleSubdet_ == HGCalTriggerSubdetector::HGCalHScTrigger) {
1180         HGCScintillatorDetId cId(c);
1181         GlobalPoint cell_position = triggerGeometry_->hscGeometry()->getPosition(cId);
1182         moduleCell_id_.get()[ic] = c;
1183         moduleCell_zside_.get()[ic] = cId.zside();
1184         moduleCell_subdet_.get()[ic] = cId.subdetId();
1185         moduleCell_layer_.get()[ic] = cId.layer();
1186         moduleCell_waferU_.get()[ic] = 0;
1187         moduleCell_waferV_.get()[ic] = 0;
1188         moduleCell_cellU_.get()[ic] = 0;
1189         moduleCell_cellV_.get()[ic] = 0;
1190         moduleCell_ieta_.get()[ic] = cId.ietaAbs();
1191         moduleCell_iphi_.get()[ic] = cId.iphi();
1192         moduleCell_x_.get()[ic] = cell_position.x();
1193         moduleCell_y_.get()[ic] = cell_position.y();
1194         moduleCell_z_.get()[ic] = cell_position.z();
1195         moduleCell_eta_.get()[ic] = cell_position.eta();
1196         moduleCell_phi_.get()[ic] = cell_position.phi();
1197       } else if (moduleSubdet_ == HGCalTriggerSubdetector::HFNoseTrigger) {
1198         HFNoseDetId cId(c);
1199         const GlobalPoint position = triggerGeometry_->noseGeometry()->getPosition(c);
1200         moduleCell_id_.get()[ic] = c;
1201         moduleCell_zside_.get()[ic] = cId.zside();
1202         moduleCell_subdet_.get()[ic] = cId.subdetId();
1203         moduleCell_layer_.get()[ic] = cId.layer();
1204         moduleCell_waferU_.get()[ic] = cId.waferU();
1205         moduleCell_waferV_.get()[ic] = cId.waferV();
1206         moduleCell_cellU_.get()[ic] = cId.cellU();
1207         moduleCell_cellV_.get()[ic] = cId.cellV();
1208         moduleCell_ieta_.get()[ic] = 0;
1209         moduleCell_iphi_.get()[ic] = 0;
1210         moduleCell_x_.get()[ic] = position.x();
1211         moduleCell_y_.get()[ic] = position.y();
1212         moduleCell_z_.get()[ic] = position.z();
1213         moduleCell_eta_.get()[ic] = position.eta();
1214         moduleCell_phi_.get()[ic] = position.phi();
1215       } else {
1216         HGCSiliconDetId cId(c);
1217         const GlobalPoint position = (cId.det() == DetId::HGCalEE ? triggerGeometry_->eeGeometry()->getPosition(cId)
1218                                                                   : triggerGeometry_->hsiGeometry()->getPosition(cId));
1219         moduleCell_id_.get()[ic] = c;
1220         moduleCell_zside_.get()[ic] = cId.zside();
1221         moduleCell_subdet_.get()[ic] = cId.subdetId();
1222         moduleCell_layer_.get()[ic] = cId.layer();
1223         moduleCell_waferU_.get()[ic] = cId.waferU();
1224         moduleCell_waferV_.get()[ic] = cId.waferV();
1225         moduleCell_cellU_.get()[ic] = cId.cellU();
1226         moduleCell_cellV_.get()[ic] = cId.cellV();
1227         moduleCell_ieta_.get()[ic] = 0;
1228         moduleCell_iphi_.get()[ic] = 0;
1229         moduleCell_x_.get()[ic] = position.x();
1230         moduleCell_y_.get()[ic] = position.y();
1231         moduleCell_z_.get()[ic] = position.z();
1232         moduleCell_eta_.get()[ic] = position.eta();
1233         moduleCell_phi_.get()[ic] = position.phi();
1234       }
1235       ic++;
1236     }
1237     treeModules_->Fill();
1238   }
1239 }
1240 
1241 /*****************************************************************/
1242 void HGCalTriggerGeomTesterV9Imp3::analyze(const edm::Event& e, const edm::EventSetup& es)
1243 /*****************************************************************/
1244 {}
1245 
1246 /*****************************************************************/
1247 void HGCalTriggerGeomTesterV9Imp3::setTreeModuleSize(const size_t n)
1248 /*****************************************************************/
1249 {
1250   moduleTC_id_.reset(new int[n], array_deleter<int>());
1251   moduleTC_zside_.reset(new int[n], array_deleter<int>());
1252   moduleTC_subdet_.reset(new int[n], array_deleter<int>());
1253   moduleTC_layer_.reset(new int[n], array_deleter<int>());
1254   moduleTC_waferU_.reset(new int[n], array_deleter<int>());
1255   moduleTC_waferV_.reset(new int[n], array_deleter<int>());
1256   moduleTC_cellU_.reset(new int[n], array_deleter<int>());
1257   moduleTC_cellV_.reset(new int[n], array_deleter<int>());
1258   moduleTC_ieta_.reset(new int[n], array_deleter<int>());
1259   moduleTC_iphi_.reset(new int[n], array_deleter<int>());
1260   moduleTC_x_.reset(new float[n], array_deleter<float>());
1261   moduleTC_y_.reset(new float[n], array_deleter<float>());
1262   moduleTC_z_.reset(new float[n], array_deleter<float>());
1263   moduleTC_eta_.reset(new float[n], array_deleter<float>());
1264   moduleTC_phi_.reset(new float[n], array_deleter<float>());
1265 
1266   treeModules_->GetBranch("tc_id")->SetAddress(moduleTC_id_.get());
1267   treeModules_->GetBranch("tc_zside")->SetAddress(moduleTC_zside_.get());
1268   treeModules_->GetBranch("tc_subdet")->SetAddress(moduleTC_subdet_.get());
1269   treeModules_->GetBranch("tc_layer")->SetAddress(moduleTC_layer_.get());
1270   treeModules_->GetBranch("tc_waferu")->SetAddress(moduleTC_waferU_.get());
1271   treeModules_->GetBranch("tc_waferv")->SetAddress(moduleTC_waferV_.get());
1272   treeModules_->GetBranch("tc_cellu")->SetAddress(moduleTC_cellU_.get());
1273   treeModules_->GetBranch("tc_cellv")->SetAddress(moduleTC_cellV_.get());
1274   treeModules_->GetBranch("tc_ieta")->SetAddress(moduleTC_ieta_.get());
1275   treeModules_->GetBranch("tc_iphi")->SetAddress(moduleTC_iphi_.get());
1276   treeModules_->GetBranch("tc_x")->SetAddress(moduleTC_x_.get());
1277   treeModules_->GetBranch("tc_y")->SetAddress(moduleTC_y_.get());
1278   treeModules_->GetBranch("tc_z")->SetAddress(moduleTC_z_.get());
1279   treeModules_->GetBranch("tc_eta")->SetAddress(moduleTC_eta_.get());
1280   treeModules_->GetBranch("tc_phi")->SetAddress(moduleTC_phi_.get());
1281 }
1282 
1283 /*****************************************************************/
1284 void HGCalTriggerGeomTesterV9Imp3::setTreeModuleCellSize(const size_t n)
1285 /*****************************************************************/
1286 {
1287   moduleCell_id_.reset(new int[n], array_deleter<int>());
1288   moduleCell_zside_.reset(new int[n], array_deleter<int>());
1289   moduleCell_subdet_.reset(new int[n], array_deleter<int>());
1290   moduleCell_layer_.reset(new int[n], array_deleter<int>());
1291   moduleCell_waferU_.reset(new int[n], array_deleter<int>());
1292   moduleCell_waferV_.reset(new int[n], array_deleter<int>());
1293   moduleCell_cellU_.reset(new int[n], array_deleter<int>());
1294   moduleCell_cellV_.reset(new int[n], array_deleter<int>());
1295   moduleCell_x_.reset(new float[n], array_deleter<float>());
1296   moduleCell_y_.reset(new float[n], array_deleter<float>());
1297   moduleCell_z_.reset(new float[n], array_deleter<float>());
1298   moduleCell_eta_.reset(new float[n], array_deleter<float>());
1299   moduleCell_phi_.reset(new float[n], array_deleter<float>());
1300 
1301   treeModules_->GetBranch("c_id")->SetAddress(moduleCell_id_.get());
1302   treeModules_->GetBranch("c_zside")->SetAddress(moduleCell_zside_.get());
1303   treeModules_->GetBranch("c_subdet")->SetAddress(moduleCell_subdet_.get());
1304   treeModules_->GetBranch("c_layer")->SetAddress(moduleCell_layer_.get());
1305   treeModules_->GetBranch("c_waferu")->SetAddress(moduleCell_waferU_.get());
1306   treeModules_->GetBranch("c_waferv")->SetAddress(moduleCell_waferV_.get());
1307   treeModules_->GetBranch("c_cellu")->SetAddress(moduleCell_cellU_.get());
1308   treeModules_->GetBranch("c_cellv")->SetAddress(moduleCell_cellV_.get());
1309   treeModules_->GetBranch("c_x")->SetAddress(moduleCell_x_.get());
1310   treeModules_->GetBranch("c_y")->SetAddress(moduleCell_y_.get());
1311   treeModules_->GetBranch("c_z")->SetAddress(moduleCell_z_.get());
1312   treeModules_->GetBranch("c_eta")->SetAddress(moduleCell_eta_.get());
1313   treeModules_->GetBranch("c_phi")->SetAddress(moduleCell_phi_.get());
1314 }
1315 
1316 /*****************************************************************/
1317 void HGCalTriggerGeomTesterV9Imp3::setTreeTriggerCellSize(const size_t n)
1318 /*****************************************************************/
1319 {
1320   triggerCellCell_id_.reset(new int[n], array_deleter<int>());
1321   triggerCellCell_zside_.reset(new int[n], array_deleter<int>());
1322   triggerCellCell_subdet_.reset(new int[n], array_deleter<int>());
1323   triggerCellCell_layer_.reset(new int[n], array_deleter<int>());
1324   triggerCellCell_waferU_.reset(new int[n], array_deleter<int>());
1325   triggerCellCell_waferV_.reset(new int[n], array_deleter<int>());
1326   triggerCellCell_cellU_.reset(new int[n], array_deleter<int>());
1327   triggerCellCell_cellV_.reset(new int[n], array_deleter<int>());
1328   triggerCellCell_ieta_.reset(new int[n], array_deleter<int>());
1329   triggerCellCell_iphi_.reset(new int[n], array_deleter<int>());
1330   triggerCellCell_x_.reset(new float[n], array_deleter<float>());
1331   triggerCellCell_y_.reset(new float[n], array_deleter<float>());
1332   triggerCellCell_z_.reset(new float[n], array_deleter<float>());
1333   triggerCellCell_eta_.reset(new float[n], array_deleter<float>());
1334   triggerCellCell_phi_.reset(new float[n], array_deleter<float>());
1335 
1336   treeTriggerCells_->GetBranch("c_id")->SetAddress(triggerCellCell_id_.get());
1337   treeTriggerCells_->GetBranch("c_zside")->SetAddress(triggerCellCell_zside_.get());
1338   treeTriggerCells_->GetBranch("c_subdet")->SetAddress(triggerCellCell_subdet_.get());
1339   treeTriggerCells_->GetBranch("c_layer")->SetAddress(triggerCellCell_layer_.get());
1340   treeTriggerCells_->GetBranch("c_waferu")->SetAddress(triggerCellCell_waferU_.get());
1341   treeTriggerCells_->GetBranch("c_waferv")->SetAddress(triggerCellCell_waferV_.get());
1342   treeTriggerCells_->GetBranch("c_cellu")->SetAddress(triggerCellCell_cellU_.get());
1343   treeTriggerCells_->GetBranch("c_cellv")->SetAddress(triggerCellCell_cellV_.get());
1344   treeTriggerCells_->GetBranch("c_ieta")->SetAddress(triggerCellCell_ieta_.get());
1345   treeTriggerCells_->GetBranch("c_iphi")->SetAddress(triggerCellCell_iphi_.get());
1346   treeTriggerCells_->GetBranch("c_x")->SetAddress(triggerCellCell_x_.get());
1347   treeTriggerCells_->GetBranch("c_y")->SetAddress(triggerCellCell_y_.get());
1348   treeTriggerCells_->GetBranch("c_z")->SetAddress(triggerCellCell_z_.get());
1349   treeTriggerCells_->GetBranch("c_eta")->SetAddress(triggerCellCell_eta_.get());
1350   treeTriggerCells_->GetBranch("c_phi")->SetAddress(triggerCellCell_phi_.get());
1351 }
1352 
1353 /*****************************************************************/
1354 void HGCalTriggerGeomTesterV9Imp3::setTreeCellCornerSize(const size_t n)
1355 /*****************************************************************/
1356 {
1357   cellCornersX_.reset(new float[n], array_deleter<float>());
1358   cellCornersY_.reset(new float[n], array_deleter<float>());
1359   cellCornersZ_.reset(new float[n], array_deleter<float>());
1360 
1361   treeCells_->GetBranch("corner_x")->SetAddress(cellCornersX_.get());
1362   treeCells_->GetBranch("corner_y")->SetAddress(cellCornersY_.get());
1363   treeCells_->GetBranch("corner_z")->SetAddress(cellCornersZ_.get());
1364 }
1365 
1366 /*****************************************************************/
1367 void HGCalTriggerGeomTesterV9Imp3::setTreeTriggerCellNeighborSize(const size_t n)
1368 /*****************************************************************/
1369 {
1370   triggerCellNeighbor_id_.reset(new int[n], array_deleter<int>());
1371   triggerCellNeighbor_zside_.reset(new int[n], array_deleter<int>());
1372   triggerCellNeighbor_subdet_.reset(new int[n], array_deleter<int>());
1373   triggerCellNeighbor_layer_.reset(new int[n], array_deleter<int>());
1374   triggerCellNeighbor_waferU_.reset(new int[n], array_deleter<int>());
1375   triggerCellNeighbor_waferV_.reset(new int[n], array_deleter<int>());
1376   triggerCellNeighbor_cellU_.reset(new int[n], array_deleter<int>());
1377   triggerCellNeighbor_cellV_.reset(new int[n], array_deleter<int>());
1378   triggerCellNeighbor_distance_.reset(new float[n], array_deleter<float>());
1379   treeTriggerCells_->GetBranch("neighbor_id")->SetAddress(triggerCellNeighbor_id_.get());
1380   treeTriggerCells_->GetBranch("neighbor_zside")->SetAddress(triggerCellNeighbor_zside_.get());
1381   treeTriggerCells_->GetBranch("neighbor_subdet")->SetAddress(triggerCellNeighbor_subdet_.get());
1382   treeTriggerCells_->GetBranch("neighbor_layer")->SetAddress(triggerCellNeighbor_layer_.get());
1383   treeTriggerCells_->GetBranch("neighbor_waferu")->SetAddress(triggerCellNeighbor_waferU_.get());
1384   treeTriggerCells_->GetBranch("neighbor_waferv")->SetAddress(triggerCellNeighbor_waferV_.get());
1385   treeTriggerCells_->GetBranch("neighbor_cellu")->SetAddress(triggerCellNeighbor_cellU_.get());
1386   treeTriggerCells_->GetBranch("neighbor_cellv")->SetAddress(triggerCellNeighbor_cellV_.get());
1387   treeTriggerCells_->GetBranch("neighbor_distance")->SetAddress(triggerCellNeighbor_distance_.get());
1388 }
1389 
1390 // define this as a plug-in
1391 DEFINE_FWK_MODULE(HGCalTriggerGeomTesterV9Imp3);