Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:20:44

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