Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-13 03:16:19

0001 /** \file GlobalHitsProdHist.cc
0002  *
0003  *  See header file for description of class
0004  *
0005  *  \author M. Strang SUNY-Buffalo
0006  */
0007 
0008 #include "Geometry/HcalTowerAlgo/interface/HcalGeometry.h"
0009 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0010 #include "Validation/GlobalHits/interface/GlobalHitsProdHist.h"
0011 
0012 GlobalHitsProdHist::GlobalHitsProdHist(const edm::ParameterSet &iPSet)
0013     : fName(""),
0014       verbosity(0),
0015       frequency(0),
0016       vtxunit(0),
0017       getAllProvenances(false),
0018       printProvenanceInfo(false),
0019       G4VtxSrc_Token_(consumes<edm::SimVertexContainer>((iPSet.getParameter<edm::InputTag>("G4VtxSrc")))),
0020       G4TrkSrc_Token_(consumes<edm::SimTrackContainer>(iPSet.getParameter<edm::InputTag>("G4TrkSrc"))),
0021       tGeomToken_(esConsumes()),
0022       cscGeomToken_(esConsumes()),
0023       dtGeomToken_(esConsumes()),
0024       rpcGeomToken_(esConsumes()),
0025       caloGeomToken_(esConsumes()),
0026       count(0) {
0027   std::string MsgLoggerCat = "GlobalHitsProdHist_GlobalHitsProdHist";
0028 
0029   // get information from parameter set
0030   fName = iPSet.getUntrackedParameter<std::string>("Name");
0031   verbosity = iPSet.getUntrackedParameter<int>("Verbosity");
0032   frequency = iPSet.getUntrackedParameter<int>("Frequency");
0033   vtxunit = iPSet.getUntrackedParameter<int>("VtxUnit");
0034   edm::ParameterSet m_Prov = iPSet.getParameter<edm::ParameterSet>("ProvenanceLookup");
0035   getAllProvenances = m_Prov.getUntrackedParameter<bool>("GetAllProvenances");
0036   printProvenanceInfo = m_Prov.getUntrackedParameter<bool>("PrintProvenanceInfo");
0037 
0038   // get Labels to use to extract information
0039   PxlBrlLowSrc_ = iPSet.getParameter<edm::InputTag>("PxlBrlLowSrc");
0040   PxlBrlHighSrc_ = iPSet.getParameter<edm::InputTag>("PxlBrlHighSrc");
0041   PxlFwdLowSrc_ = iPSet.getParameter<edm::InputTag>("PxlFwdLowSrc");
0042   PxlFwdHighSrc_ = iPSet.getParameter<edm::InputTag>("PxlFwdHighSrc");
0043 
0044   SiTIBLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTIBLowSrc");
0045   SiTIBHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTIBHighSrc");
0046   SiTOBLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTOBLowSrc");
0047   SiTOBHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTOBHighSrc");
0048   SiTIDLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTIDLowSrc");
0049   SiTIDHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTIDHighSrc");
0050   SiTECLowSrc_ = iPSet.getParameter<edm::InputTag>("SiTECLowSrc");
0051   SiTECHighSrc_ = iPSet.getParameter<edm::InputTag>("SiTECHighSrc");
0052 
0053   MuonCscSrc_ = iPSet.getParameter<edm::InputTag>("MuonCscSrc");
0054   MuonDtSrc_ = iPSet.getParameter<edm::InputTag>("MuonDtSrc");
0055   MuonRpcSrc_ = iPSet.getParameter<edm::InputTag>("MuonRpcSrc");
0056 
0057   ECalEBSrc_ = iPSet.getParameter<edm::InputTag>("ECalEBSrc");
0058   ECalEESrc_ = iPSet.getParameter<edm::InputTag>("ECalEESrc");
0059   ECalESSrc_ = iPSet.getParameter<edm::InputTag>("ECalESSrc");
0060 
0061   HCalSrc_ = iPSet.getParameter<edm::InputTag>("HCalSrc");
0062 
0063   // use value of first digit to determine default output level (inclusive)
0064   // 0 is none, 1 is basic, 2 is fill output, 3 is gather output
0065   verbosity %= 10;
0066 
0067   // print out Parameter Set information being used
0068   if (verbosity >= 0) {
0069     edm::LogInfo(MsgLoggerCat)
0070         << "\n===============================\n"
0071         << "Initialized as EDProducer with parameter values:\n"
0072         << "    Name          = " << fName << "\n"
0073         << "    Verbosity     = " << verbosity << "\n"
0074         << "    Frequency     = " << frequency << "\n"
0075         << "    VtxUnit       = " << vtxunit << "\n"
0076         << "    GetProv       = " << getAllProvenances << "\n"
0077         << "    PrintProv     = " << printProvenanceInfo << "\n"
0078         << "    PxlBrlLowSrc  = " << PxlBrlLowSrc_.label() << ":" << PxlBrlLowSrc_.instance() << "\n"
0079         << "    PxlBrlHighSrc = " << PxlBrlHighSrc_.label() << ":" << PxlBrlHighSrc_.instance() << "\n"
0080         << "    PxlFwdLowSrc  = " << PxlFwdLowSrc_.label() << ":" << PxlBrlLowSrc_.instance() << "\n"
0081         << "    PxlFwdHighSrc = " << PxlFwdHighSrc_.label() << ":" << PxlBrlHighSrc_.instance() << "\n"
0082         << "    SiTIBLowSrc   = " << SiTIBLowSrc_.label() << ":" << SiTIBLowSrc_.instance() << "\n"
0083         << "    SiTIBHighSrc  = " << SiTIBHighSrc_.label() << ":" << SiTIBHighSrc_.instance() << "\n"
0084         << "    SiTOBLowSrc   = " << SiTOBLowSrc_.label() << ":" << SiTOBLowSrc_.instance() << "\n"
0085         << "    SiTOBHighSrc  = " << SiTOBHighSrc_.label() << ":" << SiTOBHighSrc_.instance() << "\n"
0086         << "    SiTIDLowSrc   = " << SiTIDLowSrc_.label() << ":" << SiTIDLowSrc_.instance() << "\n"
0087         << "    SiTIDHighSrc  = " << SiTIDHighSrc_.label() << ":" << SiTIDHighSrc_.instance() << "\n"
0088         << "    SiTECLowSrc   = " << SiTECLowSrc_.label() << ":" << SiTECLowSrc_.instance() << "\n"
0089         << "    SiTECHighSrc  = " << SiTECHighSrc_.label() << ":" << SiTECHighSrc_.instance() << "\n"
0090         << "    MuonCscSrc    = " << MuonCscSrc_.label() << ":" << MuonCscSrc_.instance() << "\n"
0091         << "    MuonDtSrc     = " << MuonDtSrc_.label() << ":" << MuonDtSrc_.instance() << "\n"
0092         << "    MuonRpcSrc    = " << MuonRpcSrc_.label() << ":" << MuonRpcSrc_.instance() << "\n"
0093         << "    ECalEBSrc     = " << ECalEBSrc_.label() << ":" << ECalEBSrc_.instance() << "\n"
0094         << "    ECalEESrc     = " << ECalEESrc_.label() << ":" << ECalEESrc_.instance() << "\n"
0095         << "    ECalESSrc     = " << ECalESSrc_.label() << ":" << ECalESSrc_.instance() << "\n"
0096         << "    HCalSrc       = " << HCalSrc_.label() << ":" << HCalSrc_.instance() << "\n"
0097         << "===============================\n";
0098   }
0099 
0100   // create histograms
0101   Char_t hname[200];
0102   Char_t htitle[200];
0103 
0104   // MCGeant
0105   sprintf(hname, "hMCRGP1");
0106   histName_.push_back(hname);
0107   sprintf(htitle, "RawGenParticles");
0108   hMCRGP[0] = new TH1F(hname, htitle, 100, 0., 5000.);
0109   sprintf(hname, "hMCRGP2");
0110   histName_.push_back(hname);
0111   hMCRGP[1] = new TH1F(hname, htitle, 100, 0., 500.);
0112   for (Int_t i = 0; i < 2; ++i) {
0113     hMCRGP[i]->GetXaxis()->SetTitle("Number of Raw Generated Particles");
0114     hMCRGP[i]->GetYaxis()->SetTitle("Count");
0115     histMap_[hMCRGP[i]->GetName()] = hMCRGP[i];
0116   }
0117 
0118   sprintf(hname, "hMCG4Vtx1");
0119   histName_.push_back(hname);
0120   sprintf(htitle, "G4 Vertices");
0121   hMCG4Vtx[0] = new TH1F(hname, htitle, 100, 0., 50000.);
0122   sprintf(hname, "hMCG4Vtx2");
0123   histName_.push_back(hname);
0124   hMCG4Vtx[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0125   for (Int_t i = 0; i < 2; ++i) {
0126     hMCG4Vtx[i]->GetXaxis()->SetTitle("Number of Vertices");
0127     hMCG4Vtx[i]->GetYaxis()->SetTitle("Count");
0128     histMap_[hMCG4Vtx[i]->GetName()] = hMCG4Vtx[i];
0129   }
0130 
0131   sprintf(hname, "hMCG4Trk1");
0132   histName_.push_back(hname);
0133   sprintf(htitle, "G4 Tracks");
0134   hMCG4Trk[0] = new TH1F(hname, htitle, 150, 0., 15000.);
0135   sprintf(hname, "hMCG4Trk2");
0136   histName_.push_back(hname);
0137   hMCG4Trk[1] = new TH1F(hname, htitle, 150, -0.5, 99.5);
0138   for (Int_t i = 0; i < 2; ++i) {
0139     hMCG4Trk[i]->GetXaxis()->SetTitle("Number of Tracks");
0140     hMCG4Trk[i]->GetYaxis()->SetTitle("Count");
0141     histMap_[hMCG4Trk[i]->GetName()] = hMCG4Trk[i];
0142   }
0143 
0144   sprintf(hname, "hGeantVtxX1");
0145   histName_.push_back(hname);
0146   sprintf(htitle, "Geant vertex x/micrometer");
0147   hGeantVtxX[0] = new TH1F(hname, htitle, 100, -8000000., 8000000.);
0148   sprintf(hname, "hGeantVtxX2");
0149   histName_.push_back(hname);
0150   hGeantVtxX[1] = new TH1F(hname, htitle, 100, -50., 50.);
0151   for (Int_t i = 0; i < 2; ++i) {
0152     hGeantVtxX[i]->GetXaxis()->SetTitle("x of Vertex (um)");
0153     hGeantVtxX[i]->GetYaxis()->SetTitle("Count");
0154     histMap_[hGeantVtxX[i]->GetName()] = hGeantVtxX[i];
0155   }
0156 
0157   sprintf(hname, "hGeantVtxY1");
0158   histName_.push_back(hname);
0159   sprintf(htitle, "Geant vertex y/micrometer");
0160   hGeantVtxY[0] = new TH1F(hname, htitle, 100, -8000000, 8000000.);
0161   sprintf(hname, "hGeantVtxY2");
0162   histName_.push_back(hname);
0163   hGeantVtxY[1] = new TH1F(hname, htitle, 100, -50., 50.);
0164   for (Int_t i = 0; i < 2; ++i) {
0165     hGeantVtxY[i]->GetXaxis()->SetTitle("y of Vertex (um)");
0166     hGeantVtxY[i]->GetYaxis()->SetTitle("Count");
0167     histMap_[hGeantVtxY[i]->GetName()] = hGeantVtxY[i];
0168   }
0169 
0170   sprintf(hname, "hGeantVtxZ1");
0171   histName_.push_back(hname);
0172   sprintf(htitle, "Geant vertex z/millimeter");
0173   hGeantVtxZ[0] = new TH1F(hname, htitle, 100, -11000., 11000.);
0174   sprintf(hname, "hGeantVtxZ2");
0175   histName_.push_back(hname);
0176   hGeantVtxZ[1] = new TH1F(hname, htitle, 100, -250., 250.);
0177   for (Int_t i = 0; i < 2; ++i) {
0178     hGeantVtxZ[i]->GetXaxis()->SetTitle("z of Vertex (mm)");
0179     hGeantVtxZ[i]->GetYaxis()->SetTitle("Count");
0180     histMap_[hGeantVtxZ[i]->GetName()] = hGeantVtxZ[i];
0181   }
0182 
0183   sprintf(hname, "hGeantTrkPt");
0184   histName_.push_back(hname);
0185   sprintf(htitle, "Geant track pt/GeV");
0186   hGeantTrkPt = new TH1F(hname, htitle, 100, 0., 200.);
0187   hGeantTrkPt->GetXaxis()->SetTitle("pT of Track (GeV)");
0188   hGeantTrkPt->GetYaxis()->SetTitle("Count");
0189   histMap_[hGeantTrkPt->GetName()] = hGeantTrkPt;
0190 
0191   sprintf(hname, "hGeantTrkE");
0192   histName_.push_back(hname);
0193   sprintf(htitle, "Geant track E/GeV");
0194   hGeantTrkE = new TH1F(hname, htitle, 100, 0., 5000.);
0195   hGeantTrkE->GetXaxis()->SetTitle("E of Track (GeV)");
0196   hGeantTrkE->GetYaxis()->SetTitle("Count");
0197   histMap_[hGeantTrkE->GetName()] = hGeantTrkE;
0198 
0199   // ECal
0200   sprintf(hname, "hCaloEcal1");
0201   histName_.push_back(hname);
0202   sprintf(htitle, "Ecal hits");
0203   hCaloEcal[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0204   sprintf(hname, "hCaloEcal2");
0205   histName_.push_back(hname);
0206   hCaloEcal[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0207 
0208   sprintf(hname, "hCaloEcalE1");
0209   histName_.push_back(hname);
0210   sprintf(htitle, "Ecal hits, energy/GeV");
0211   hCaloEcalE[0] = new TH1F(hname, htitle, 100, 0., 10.);
0212   sprintf(hname, "hCaloEcalE2");
0213   histName_.push_back(hname);
0214   hCaloEcalE[1] = new TH1F(hname, htitle, 100, 0., 0.1);
0215 
0216   sprintf(hname, "hCaloEcalToF1");
0217   histName_.push_back(hname);
0218   sprintf(htitle, "Ecal hits, ToF/ns");
0219   hCaloEcalToF[0] = new TH1F(hname, htitle, 100, 0., 1000.);
0220   sprintf(hname, "hCaloEcalToF2");
0221   histName_.push_back(hname);
0222   hCaloEcalToF[1] = new TH1F(hname, htitle, 100, 0., 100.);
0223 
0224   for (Int_t i = 0; i < 2; ++i) {
0225     hCaloEcal[i]->GetXaxis()->SetTitle("Number of Hits");
0226     hCaloEcal[i]->GetYaxis()->SetTitle("Count");
0227     histMap_[hCaloEcal[i]->GetName()] = hCaloEcal[i];
0228     hCaloEcalE[i]->GetXaxis()->SetTitle("Energy of Hits (GeV)");
0229     hCaloEcalE[i]->GetYaxis()->SetTitle("Count");
0230     histMap_[hCaloEcalE[i]->GetName()] = hCaloEcalE[i];
0231     hCaloEcalToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0232     hCaloEcalToF[i]->GetYaxis()->SetTitle("Count");
0233     histMap_[hCaloEcalToF[i]->GetName()] = hCaloEcalToF[i];
0234   }
0235 
0236   sprintf(hname, "hCaloEcalPhi");
0237   histName_.push_back(hname);
0238   sprintf(htitle, "Ecal hits, phi/rad");
0239   hCaloEcalPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0240   hCaloEcalPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0241   hCaloEcalPhi->GetYaxis()->SetTitle("Count");
0242   histMap_[hCaloEcalPhi->GetName()] = hCaloEcalPhi;
0243 
0244   sprintf(hname, "hCaloEcalEta");
0245   histName_.push_back(hname);
0246   sprintf(htitle, "Ecal hits, eta");
0247   hCaloEcalEta = new TH1F(hname, htitle, 100, -5.5, 5.5);
0248   hCaloEcalEta->GetXaxis()->SetTitle("Eta of Hits");
0249   hCaloEcalEta->GetYaxis()->SetTitle("Count");
0250   histMap_[hCaloEcalEta->GetName()] = hCaloEcalEta;
0251 
0252   sprintf(hname, "hCaloPreSh1");
0253   histName_.push_back(hname);
0254   sprintf(htitle, "PreSh hits");
0255   hCaloPreSh[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0256   sprintf(hname, "hCaloPreSh2");
0257   histName_.push_back(hname);
0258   hCaloPreSh[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0259 
0260   sprintf(hname, "hCaloPreShE1");
0261   histName_.push_back(hname);
0262   sprintf(htitle, "PreSh hits, energy/GeV");
0263   hCaloPreShE[0] = new TH1F(hname, htitle, 100, 0., 10.);
0264   sprintf(hname, "hCaloPreShE2");
0265   histName_.push_back(hname);
0266   hCaloPreShE[1] = new TH1F(hname, htitle, 100, 0., 0.1);
0267 
0268   sprintf(hname, "hCaloPreShToF1");
0269   histName_.push_back(hname);
0270   sprintf(htitle, "PreSh hits, ToF/ns");
0271   hCaloPreShToF[0] = new TH1F(hname, htitle, 100, 0., 1000.);
0272   sprintf(hname, "hCaloPreShToF2");
0273   histName_.push_back(hname);
0274   hCaloPreShToF[1] = new TH1F(hname, htitle, 100, 0., 100.);
0275 
0276   for (Int_t i = 0; i < 2; ++i) {
0277     hCaloPreSh[i]->GetXaxis()->SetTitle("Number of Hits");
0278     hCaloPreSh[i]->GetYaxis()->SetTitle("Count");
0279     histMap_[hCaloPreSh[i]->GetName()] = hCaloPreSh[i];
0280     hCaloPreShE[i]->GetXaxis()->SetTitle("Energy of Hits (GeV)");
0281     hCaloPreShE[i]->GetYaxis()->SetTitle("Count");
0282     histMap_[hCaloPreShE[i]->GetName()] = hCaloPreShE[i];
0283     hCaloPreShToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0284     hCaloPreShToF[i]->GetYaxis()->SetTitle("Count");
0285     histMap_[hCaloPreShToF[i]->GetName()] = hCaloPreShToF[i];
0286   }
0287 
0288   sprintf(hname, "hCaloPreShPhi");
0289   histName_.push_back(hname);
0290   sprintf(htitle, "PreSh hits, phi/rad");
0291   hCaloPreShPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0292   hCaloPreShPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0293   hCaloPreShPhi->GetYaxis()->SetTitle("Count");
0294   histMap_[hCaloPreShPhi->GetName()] = hCaloPreShPhi;
0295 
0296   sprintf(hname, "hCaloPreShEta");
0297   histName_.push_back(hname);
0298   sprintf(htitle, "PreSh hits, eta");
0299   hCaloPreShEta = new TH1F(hname, htitle, 100, -5.5, 5.5);
0300   hCaloPreShEta->GetXaxis()->SetTitle("Eta of Hits");
0301   hCaloPreShEta->GetYaxis()->SetTitle("Count");
0302   histMap_[hCaloPreShEta->GetName()] = hCaloPreShEta;
0303 
0304   // Hcal
0305   sprintf(hname, "hCaloHcal1");
0306   histName_.push_back(hname);
0307   sprintf(htitle, "Hcal hits");
0308   hCaloHcal[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0309   sprintf(hname, "hCaloHcal2");
0310   histName_.push_back(hname);
0311   hCaloHcal[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0312 
0313   sprintf(hname, "hCaloHcalE1");
0314   histName_.push_back(hname);
0315   sprintf(htitle, "Hcal hits, energy/GeV");
0316   hCaloHcalE[0] = new TH1F(hname, htitle, 100, 0., 10.);
0317   sprintf(hname, "hCaloHcalE2");
0318   histName_.push_back(hname);
0319   hCaloHcalE[1] = new TH1F(hname, htitle, 100, 0., 0.1);
0320 
0321   sprintf(hname, "hCaloHcalToF1");
0322   histName_.push_back(hname);
0323   sprintf(htitle, "Hcal hits, ToF/ns");
0324   hCaloHcalToF[0] = new TH1F(hname, htitle, 100, 0., 1000.);
0325   sprintf(hname, "hCaloHcalToF2");
0326   histName_.push_back(hname);
0327   hCaloHcalToF[1] = new TH1F(hname, htitle, 100, 0., 100.);
0328 
0329   for (Int_t i = 0; i < 2; ++i) {
0330     hCaloHcal[i]->GetXaxis()->SetTitle("Number of Hits");
0331     hCaloHcal[i]->GetYaxis()->SetTitle("Count");
0332     histMap_[hCaloHcal[i]->GetName()] = hCaloHcal[i];
0333     hCaloHcalE[i]->GetXaxis()->SetTitle("Energy of Hits (GeV)");
0334     hCaloHcalE[i]->GetYaxis()->SetTitle("Count");
0335     histMap_[hCaloHcalE[i]->GetName()] = hCaloHcalE[i];
0336     hCaloHcalToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0337     hCaloHcalToF[i]->GetYaxis()->SetTitle("Count");
0338     histMap_[hCaloHcalToF[i]->GetName()] = hCaloHcalToF[i];
0339   }
0340 
0341   sprintf(hname, "hCaloHcalPhi");
0342   histName_.push_back(hname);
0343   sprintf(htitle, "Hcal hits, phi/rad");
0344   hCaloHcalPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0345   hCaloHcalPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0346   hCaloHcalPhi->GetYaxis()->SetTitle("Count");
0347   histMap_[hCaloHcalPhi->GetName()] = hCaloHcalPhi;
0348 
0349   sprintf(hname, "hCaloHcalEta");
0350   histName_.push_back(hname);
0351   sprintf(htitle, "Hcal hits, eta");
0352   hCaloHcalEta = new TH1F(hname, htitle, 100, -5.5, 5.5);
0353   hCaloHcalEta->GetXaxis()->SetTitle("Eta of Hits");
0354   hCaloHcalEta->GetYaxis()->SetTitle("Count");
0355   histMap_[hCaloHcalEta->GetName()] = hCaloHcalEta;
0356 
0357   // tracker
0358   sprintf(hname, "hTrackerPx1");
0359   histName_.push_back(hname);
0360   sprintf(htitle, "Pixel hits");
0361   hTrackerPx[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0362   sprintf(hname, "hTrackerPx2");
0363   histName_.push_back(hname);
0364   hTrackerPx[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0365   for (Int_t i = 0; i < 2; ++i) {
0366     hTrackerPx[i]->GetXaxis()->SetTitle("Number of Pixel Hits");
0367     hTrackerPx[i]->GetYaxis()->SetTitle("Count");
0368     histMap_[hTrackerPx[i]->GetName()] = hTrackerPx[i];
0369   }
0370 
0371   sprintf(hname, "hTrackerPxPhi");
0372   histName_.push_back(hname);
0373   sprintf(htitle, "Pixel hits phi/rad");
0374   hTrackerPxPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0375   hTrackerPxPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0376   hTrackerPxPhi->GetYaxis()->SetTitle("Count");
0377   histMap_[hTrackerPxPhi->GetName()] = hTrackerPxPhi;
0378 
0379   sprintf(hname, "hTrackerPxEta");
0380   histName_.push_back(hname);
0381   sprintf(htitle, "Pixel hits eta");
0382   hTrackerPxEta = new TH1F(hname, htitle, 100, -3.5, 3.5);
0383   hTrackerPxEta->GetXaxis()->SetTitle("Eta of Hits");
0384   hTrackerPxEta->GetYaxis()->SetTitle("Count");
0385   histMap_[hTrackerPxEta->GetName()] = hTrackerPxEta;
0386 
0387   sprintf(hname, "hTrackerPxBToF");
0388   histName_.push_back(hname);
0389   sprintf(htitle, "Pixel barrel hits, ToF/ns");
0390   hTrackerPxBToF = new TH1F(hname, htitle, 100, 0., 40.);
0391   hTrackerPxBToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0392   hTrackerPxBToF->GetYaxis()->SetTitle("Count");
0393   histMap_[hTrackerPxBToF->GetName()] = hTrackerPxBToF;
0394 
0395   sprintf(hname, "hTrackerPxBR");
0396   histName_.push_back(hname);
0397   sprintf(htitle, "Pixel barrel hits, R/cm");
0398   hTrackerPxBR = new TH1F(hname, htitle, 100, 0., 50.);
0399   hTrackerPxBR->GetXaxis()->SetTitle("R of Hits (cm)");
0400   hTrackerPxBR->GetYaxis()->SetTitle("Count");
0401   histMap_[hTrackerPxBR->GetName()] = hTrackerPxBR;
0402 
0403   sprintf(hname, "hTrackerPxFToF");
0404   histName_.push_back(hname);
0405   sprintf(htitle, "Pixel forward hits, ToF/ns");
0406   hTrackerPxFToF = new TH1F(hname, htitle, 100, 0., 50.);
0407   hTrackerPxFToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0408   hTrackerPxFToF->GetYaxis()->SetTitle("Count");
0409   histMap_[hTrackerPxFToF->GetName()] = hTrackerPxFToF;
0410 
0411   sprintf(hname, "hTrackerPxFZ");
0412   histName_.push_back(hname);
0413   sprintf(htitle, "Pixel forward hits, Z/cm");
0414   hTrackerPxFZ = new TH1F(hname, htitle, 200, -100., 100.);
0415   hTrackerPxFZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0416   hTrackerPxFZ->GetYaxis()->SetTitle("Count");
0417   histMap_[hTrackerPxFZ->GetName()] = hTrackerPxFZ;
0418 
0419   sprintf(hname, "hTrackerSi1");
0420   histName_.push_back(hname);
0421   sprintf(htitle, "Silicon hits");
0422   hTrackerSi[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0423   sprintf(hname, "hTrackerSi2");
0424   histName_.push_back(hname);
0425   hTrackerSi[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0426   for (Int_t i = 0; i < 2; ++i) {
0427     hTrackerSi[i]->GetXaxis()->SetTitle("Number of Silicon Hits");
0428     hTrackerSi[i]->GetYaxis()->SetTitle("Count");
0429     histMap_[hTrackerSi[i]->GetName()] = hTrackerSi[i];
0430   }
0431 
0432   sprintf(hname, "hTrackerSiPhi");
0433   histName_.push_back(hname);
0434   sprintf(htitle, "Silicon hits phi/rad");
0435   hTrackerSiPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0436   hTrackerSiPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0437   hTrackerSiPhi->GetYaxis()->SetTitle("Count");
0438   histMap_[hTrackerSiPhi->GetName()] = hTrackerSiPhi;
0439 
0440   sprintf(hname, "hTrackerSiEta");
0441   histName_.push_back(hname);
0442   sprintf(htitle, "Silicon hits eta");
0443   hTrackerSiEta = new TH1F(hname, htitle, 100, -3.5, 3.5);
0444   hTrackerSiEta->GetXaxis()->SetTitle("Eta of Hits");
0445   hTrackerSiEta->GetYaxis()->SetTitle("Count");
0446   histMap_[hTrackerSiEta->GetName()] = hTrackerSiEta;
0447 
0448   sprintf(hname, "hTrackerSiBToF");
0449   histName_.push_back(hname);
0450   sprintf(htitle, "Silicon barrel hits, ToF/ns");
0451   hTrackerSiBToF = new TH1F(hname, htitle, 100, 0., 50.);
0452   hTrackerSiBToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0453   hTrackerSiBToF->GetYaxis()->SetTitle("Count");
0454   histMap_[hTrackerSiBToF->GetName()] = hTrackerSiBToF;
0455 
0456   sprintf(hname, "hTrackerSiBR");
0457   histName_.push_back(hname);
0458   sprintf(htitle, "Silicon barrel hits, R/cm");
0459   hTrackerSiBR = new TH1F(hname, htitle, 100, 0., 200.);
0460   hTrackerSiBR->GetXaxis()->SetTitle("R of Hits (cm)");
0461   hTrackerSiBR->GetYaxis()->SetTitle("Count");
0462   histMap_[hTrackerSiBR->GetName()] = hTrackerSiBR;
0463 
0464   sprintf(hname, "hTrackerSiFToF");
0465   histName_.push_back(hname);
0466   sprintf(htitle, "Silicon forward hits, ToF/ns");
0467   hTrackerSiFToF = new TH1F(hname, htitle, 100, 0., 75.);
0468   hTrackerSiFToF->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0469   hTrackerSiFToF->GetYaxis()->SetTitle("Count");
0470   histMap_[hTrackerSiFToF->GetName()] = hTrackerSiFToF;
0471 
0472   sprintf(hname, "hTrackerSiFZ");
0473   histName_.push_back(hname);
0474   sprintf(htitle, "Silicon forward hits, Z/cm");
0475   hTrackerSiFZ = new TH1F(hname, htitle, 200, -300., 300.);
0476   hTrackerSiFZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0477   hTrackerSiFZ->GetYaxis()->SetTitle("Count");
0478   histMap_[hTrackerSiFZ->GetName()] = hTrackerSiFZ;
0479 
0480   // muon
0481   sprintf(hname, "hMuon1");
0482   histName_.push_back(hname);
0483   sprintf(htitle, "Muon hits");
0484   hMuon[0] = new TH1F(hname, htitle, 100, 0., 10000.);
0485   sprintf(hname, "hMuon2");
0486   histName_.push_back(hname);
0487   hMuon[1] = new TH1F(hname, htitle, 100, -0.5, 99.5);
0488   for (Int_t i = 0; i < 2; ++i) {
0489     hMuon[i]->GetXaxis()->SetTitle("Number of Muon Hits");
0490     hMuon[i]->GetYaxis()->SetTitle("Count");
0491     histMap_[hMuon[i]->GetName()] = hMuon[i];
0492   }
0493 
0494   sprintf(hname, "hMuonPhi");
0495   histName_.push_back(hname);
0496   sprintf(htitle, "Muon hits phi/rad");
0497   hMuonPhi = new TH1F(hname, htitle, 100, -3.2, 3.2);
0498   hMuonPhi->GetXaxis()->SetTitle("Phi of Hits (rad)");
0499   hMuonPhi->GetYaxis()->SetTitle("Count");
0500   histMap_[hMuonPhi->GetName()] = hMuonPhi;
0501 
0502   sprintf(hname, "hMuonEta");
0503   histName_.push_back(hname);
0504   sprintf(htitle, "Muon hits eta");
0505   hMuonEta = new TH1F(hname, htitle, 100, -3.5, 3.5);
0506   hMuonEta->GetXaxis()->SetTitle("Eta of Hits");
0507   hMuonEta->GetYaxis()->SetTitle("Count");
0508   histMap_[hMuonEta->GetName()] = hMuonEta;
0509 
0510   sprintf(hname, "hMuonCscToF1");
0511   histName_.push_back(hname);
0512   sprintf(htitle, "Muon CSC hits, ToF/ns");
0513   hMuonCscToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0514   sprintf(hname, "hMuonCscToF2");
0515   histName_.push_back(hname);
0516   hMuonCscToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0517   for (Int_t i = 0; i < 2; ++i) {
0518     hMuonCscToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0519     hMuonCscToF[i]->GetYaxis()->SetTitle("Count");
0520     histMap_[hMuonCscToF[i]->GetName()] = hMuonCscToF[i];
0521   }
0522 
0523   sprintf(hname, "hMuonCscZ");
0524   histName_.push_back(hname);
0525   sprintf(htitle, "Muon CSC hits, Z/cm");
0526   hMuonCscZ = new TH1F(hname, htitle, 200, -1500., 1500.);
0527   hMuonCscZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0528   hMuonCscZ->GetYaxis()->SetTitle("Count");
0529   histMap_[hMuonCscZ->GetName()] = hMuonCscZ;
0530 
0531   sprintf(hname, "hMuonDtToF1");
0532   histName_.push_back(hname);
0533   sprintf(htitle, "Muon DT hits, ToF/ns");
0534   hMuonDtToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0535   sprintf(hname, "hMuonDtToF2");
0536   histName_.push_back(hname);
0537   hMuonDtToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0538   for (Int_t i = 0; i < 2; ++i) {
0539     hMuonDtToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0540     hMuonDtToF[i]->GetYaxis()->SetTitle("Count");
0541     histMap_[hMuonDtToF[i]->GetName()] = hMuonDtToF[i];
0542   }
0543 
0544   sprintf(hname, "hMuonDtR");
0545   histName_.push_back(hname);
0546   sprintf(htitle, "Muon DT hits, R/cm");
0547   hMuonDtR = new TH1F(hname, htitle, 100, 0., 1500.);
0548   hMuonDtR->GetXaxis()->SetTitle("R of Hits (cm)");
0549   hMuonDtR->GetYaxis()->SetTitle("Count");
0550   histMap_[hMuonDtR->GetName()] = hMuonDtR;
0551 
0552   sprintf(hname, "hMuonRpcFToF1");
0553   histName_.push_back(hname);
0554   sprintf(htitle, "Muon RPC forward hits, ToF/ns");
0555   hMuonRpcFToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0556   sprintf(hname, "hMuonRpcFToF2");
0557   histName_.push_back(hname);
0558   hMuonRpcFToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0559   for (Int_t i = 0; i < 2; ++i) {
0560     hMuonRpcFToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0561     hMuonRpcFToF[i]->GetYaxis()->SetTitle("Count");
0562     histMap_[hMuonRpcFToF[i]->GetName()] = hMuonRpcFToF[i];
0563   }
0564 
0565   sprintf(hname, "hMuonRpcFZ");
0566   histName_.push_back(hname);
0567   sprintf(htitle, "Muon RPC forward hits, Z/cm");
0568   hMuonRpcFZ = new TH1F(hname, htitle, 201, -1500., 1500.);
0569   hMuonRpcFZ->GetXaxis()->SetTitle("Z of Hits (cm)");
0570   hMuonRpcFZ->GetYaxis()->SetTitle("Count");
0571   histMap_[hMuonRpcFZ->GetName()] = hMuonRpcFZ;
0572 
0573   sprintf(hname, "hMuonRpcBToF1");
0574   histName_.push_back(hname);
0575   sprintf(htitle, "Muon RPC barrel hits, ToF/ns");
0576   hMuonRpcBToF[0] = new TH1F(hname, htitle, 100, 0., 250.);
0577   sprintf(hname, "hMuonRpcBToF2");
0578   histName_.push_back(hname);
0579   hMuonRpcBToF[1] = new TH1F(hname, htitle, 100, 0., 50.);
0580   for (Int_t i = 0; i < 2; ++i) {
0581     hMuonRpcBToF[i]->GetXaxis()->SetTitle("Time of Flight of Hits (ns)");
0582     hMuonRpcBToF[i]->GetYaxis()->SetTitle("Count");
0583     histMap_[hMuonRpcBToF[i]->GetName()] = hMuonRpcBToF[i];
0584   }
0585 
0586   sprintf(hname, "hMuonRpcBR");
0587   histName_.push_back(hname);
0588   sprintf(htitle, "Muon RPC barrel hits, R/cm");
0589   hMuonRpcBR = new TH1F(hname, htitle, 100, 0., 1500.);
0590   hMuonRpcBR->GetXaxis()->SetTitle("R of Hits (cm)");
0591   hMuonRpcBR->GetYaxis()->SetTitle("Count");
0592   histMap_[hMuonRpcBR->GetName()] = hMuonRpcBR;
0593 
0594   // create persistent objects
0595   for (std::size_t i = 0; i < histName_.size(); ++i) {
0596     produces<TH1F, edm::Transition::EndRun>(histName_[i]).setBranchAlias(histName_[i]);
0597   }
0598 }
0599 
0600 GlobalHitsProdHist::~GlobalHitsProdHist() {}
0601 
0602 void GlobalHitsProdHist::beginJob() { return; }
0603 
0604 void GlobalHitsProdHist::endJob() {
0605   std::string MsgLoggerCat = "GlobalHitsProdHist_endJob";
0606   if (verbosity >= 0)
0607     edm::LogInfo(MsgLoggerCat) << "Terminating having processed " << count << " events.";
0608   return;
0609 }
0610 
0611 void GlobalHitsProdHist::produce(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0612   std::string MsgLoggerCat = "GlobalHitsProdHist_produce";
0613 
0614   // keep track of number of events processed
0615   ++count;
0616 
0617   // get event id information
0618   edm::RunNumber_t nrun = iEvent.id().run();
0619   edm::EventNumber_t nevt = iEvent.id().event();
0620 
0621   if (verbosity > 0) {
0622     edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << ", event " << nevt << " (" << count << " events total)";
0623   } else if (verbosity == 0) {
0624     if (nevt % frequency == 0 || nevt == 1) {
0625       edm::LogInfo(MsgLoggerCat) << "Processing run " << nrun << ", event " << nevt << " (" << count
0626                                  << " events total)";
0627     }
0628   }
0629 
0630   // look at information available in the event
0631   if (getAllProvenances) {
0632     std::vector<const edm::StableProvenance *> AllProv;
0633     iEvent.getAllStableProvenance(AllProv);
0634 
0635     if (verbosity >= 0)
0636       edm::LogInfo(MsgLoggerCat) << "Number of Provenances = " << AllProv.size();
0637 
0638     if (printProvenanceInfo && (verbosity >= 0)) {
0639       TString eventout("\nProvenance info:\n");
0640 
0641       for (unsigned int i = 0; i < AllProv.size(); ++i) {
0642         eventout += "\n       ******************************";
0643         eventout += "\n       Module       : ";
0644         eventout += AllProv[i]->moduleLabel();
0645         eventout += "\n       ProductID    : ";
0646         eventout += AllProv[i]->productID().id();
0647         eventout += "\n       ClassName    : ";
0648         eventout += AllProv[i]->className();
0649         eventout += "\n       InstanceName : ";
0650         eventout += AllProv[i]->productInstanceName();
0651         eventout += "\n       BranchName   : ";
0652         eventout += AllProv[i]->branchName();
0653       }
0654       eventout += "\n       ******************************\n";
0655       edm::LogInfo(MsgLoggerCat) << eventout << "\n";
0656       printProvenanceInfo = false;
0657     }
0658     getAllProvenances = false;
0659   }
0660 
0661   // call fill functions
0662   // gather G4MC information from event
0663   fillG4MC(iEvent);
0664   // gather Tracker information from event
0665   fillTrk(iEvent, iSetup);
0666   // gather muon information from event
0667   fillMuon(iEvent, iSetup);
0668   // gather Ecal information from event
0669   fillECal(iEvent, iSetup);
0670   // gather Hcal information from event
0671   fillHCal(iEvent, iSetup);
0672 
0673   if (verbosity > 0)
0674     edm::LogInfo(MsgLoggerCat) << "Done gathering data from event.";
0675 
0676   return;
0677 }
0678 
0679 void GlobalHitsProdHist::endRunProduce(edm::Run &iRun, const edm::EventSetup &iSetup) {
0680   std::string MsgLoggerCat = "GlobalHitsProdHist_endRun";
0681 
0682   TString eventout;
0683   TString eventoutw;
0684   bool warning = false;
0685 
0686   if (verbosity > 0)
0687     edm::LogInfo(MsgLoggerCat) << "\nStoring histograms.";
0688 
0689   // store persistent objects
0690   std::map<std::string, TH1F *>::iterator iter;
0691   for (std::size_t i = 0; i < histName_.size(); ++i) {
0692     iter = histMap_.find(histName_[i]);
0693     if (iter != histMap_.end()) {
0694       std::unique_ptr<TH1F> hist1D(iter->second);
0695       eventout += "\n Storing histogram " + histName_[i];
0696       iRun.put(std::move(hist1D), histName_[i]);
0697     } else {
0698       warning = true;
0699       eventoutw += "\n Unable to find histogram with name " + histName_[i];
0700     }
0701   }
0702 
0703   if (verbosity > 0) {
0704     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
0705     if (warning)
0706       edm::LogWarning(MsgLoggerCat) << eventoutw << "\n";
0707   }
0708   return;
0709 }
0710 
0711 //==================fill and store functions================================
0712 void GlobalHitsProdHist::fillG4MC(edm::Event &iEvent) {
0713   std::string MsgLoggerCat = "GlobalHitsProdHist_fillG4MC";
0714 
0715   TString eventout;
0716   if (verbosity > 0)
0717     eventout = "\nGathering info:";
0718 
0719   //////////////////////
0720   // get MC information
0721   /////////////////////
0722   edm::Handle<edm::HepMCProduct> HepMCEvt;
0723   std::vector<edm::Handle<edm::HepMCProduct>> AllHepMCEvt;
0724   iEvent.getManyByType(AllHepMCEvt);
0725 
0726   // loop through products and extract VtxSmearing if available. Any of them
0727   // should have the information needed
0728   for (unsigned int i = 0; i < AllHepMCEvt.size(); ++i) {
0729     HepMCEvt = AllHepMCEvt[i];
0730     if ((HepMCEvt.provenance()->branchDescription()).moduleLabel() == "generatorSmeared")
0731       break;
0732   }
0733 
0734   if (!HepMCEvt.isValid()) {
0735     edm::LogWarning(MsgLoggerCat) << "Unable to find HepMCProduct in event!";
0736     return;
0737   } else {
0738     eventout += "\n          Using HepMCProduct: ";
0739     eventout += (HepMCEvt.provenance()->branchDescription()).moduleLabel();
0740   }
0741   const HepMC::GenEvent *MCEvt = HepMCEvt->GetEvent();
0742   nRawGenPart = MCEvt->particles_size();
0743 
0744   if (verbosity > 1) {
0745     eventout += "\n          Number of Raw Particles collected:......... ";
0746     eventout += nRawGenPart;
0747   }
0748 
0749   if (hMCRGP[0])
0750     hMCRGP[0]->Fill((float)nRawGenPart);
0751   if (hMCRGP[1])
0752     hMCRGP[1]->Fill((float)nRawGenPart);
0753 
0754   ////////////////////////////
0755   // get G4Vertex information
0756   ////////////////////////////
0757   // convert unit stored in SimVertex to mm
0758   float unit = 0.;
0759   if (vtxunit == 0)
0760     unit = 1.;  // already in mm
0761   if (vtxunit == 1)
0762     unit = 10.;  // stored in cm, convert to mm
0763 
0764   edm::Handle<edm::SimVertexContainer> G4VtxContainer;
0765   iEvent.getByToken(G4VtxSrc_Token_, G4VtxContainer);
0766   if (!G4VtxContainer.isValid()) {
0767     edm::LogWarning(MsgLoggerCat) << "Unable to find SimVertex in event!";
0768     return;
0769   }
0770   int i = 0;
0771   edm::SimVertexContainer::const_iterator itVtx;
0772   for (itVtx = G4VtxContainer->begin(); itVtx != G4VtxContainer->end(); ++itVtx) {
0773     ++i;
0774 
0775     const math::XYZTLorentzVector G4Vtx1(
0776         itVtx->position().x(), itVtx->position().y(), itVtx->position().z(), itVtx->position().e());
0777 
0778     double G4Vtx[4];
0779     G4Vtx1.GetCoordinates(G4Vtx);
0780 
0781     if (hGeantVtxX[0])
0782       hGeantVtxX[0]->Fill((G4Vtx[0] * unit) / micrometer);
0783     if (hGeantVtxX[1])
0784       hGeantVtxX[1]->Fill((G4Vtx[0] * unit) / micrometer);
0785 
0786     if (hGeantVtxY[0])
0787       hGeantVtxY[0]->Fill((G4Vtx[1] * unit) / micrometer);
0788     if (hGeantVtxY[1])
0789       hGeantVtxY[1]->Fill((G4Vtx[1] * unit) / micrometer);
0790 
0791     if (hGeantVtxZ[0])
0792       hGeantVtxZ[0]->Fill((G4Vtx[2] * unit) / millimeter);
0793     if (hGeantVtxZ[1])
0794       hGeantVtxZ[1]->Fill((G4Vtx[2] * unit) / millimeter);
0795   }
0796 
0797   if (verbosity > 1) {
0798     eventout += "\n          Number of G4Vertices collected:............ ";
0799     eventout += i;
0800   }
0801 
0802   if (hMCG4Vtx[0])
0803     hMCG4Vtx[0]->Fill((float)i);
0804   if (hMCG4Vtx[1])
0805     hMCG4Vtx[1]->Fill((float)i);
0806 
0807   ///////////////////////////
0808   // get G4Track information
0809   ///////////////////////////
0810   edm::Handle<edm::SimTrackContainer> G4TrkContainer;
0811   iEvent.getByToken(G4TrkSrc_Token_, G4TrkContainer);
0812   if (!G4TrkContainer.isValid()) {
0813     edm::LogWarning(MsgLoggerCat) << "Unable to find SimTrack in event!";
0814     return;
0815   }
0816   i = 0;
0817   edm::SimTrackContainer::const_iterator itTrk;
0818   for (itTrk = G4TrkContainer->begin(); itTrk != G4TrkContainer->end(); ++itTrk) {
0819     ++i;
0820 
0821     const math::XYZTLorentzVector G4Trk1(
0822         itTrk->momentum().x(), itTrk->momentum().y(), itTrk->momentum().z(), itTrk->momentum().e());
0823     double G4Trk[4];
0824     G4Trk1.GetCoordinates(G4Trk);
0825 
0826     if (hGeantTrkPt)
0827       hGeantTrkPt->Fill(sqrt(G4Trk[0] * G4Trk[0] + G4Trk[1] * G4Trk[1]));
0828     if (hGeantTrkE)
0829       hGeantTrkE->Fill(G4Trk[3]);
0830   }
0831 
0832   if (verbosity > 1) {
0833     eventout += "\n          Number of G4Tracks collected:.............. ";
0834     eventout += i;
0835   }
0836 
0837   if (hMCG4Trk[0])
0838     hMCG4Trk[0]->Fill((float)i);
0839   if (hMCG4Trk[1])
0840     hMCG4Trk[1]->Fill((float)i);
0841 
0842   if (verbosity > 0)
0843     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
0844 
0845   return;
0846 }
0847 
0848 void GlobalHitsProdHist::fillTrk(edm::Event &iEvent, const edm::EventSetup &iSetup) {
0849   nPxlHits = 0;
0850   std::string MsgLoggerCat = "GlobalHitsProdHist_fillTrk";
0851 
0852   TString eventout;
0853   if (verbosity > 0)
0854     eventout = "\nGathering info:";
0855 
0856   // access the tracker geometry
0857   const auto &theTrackerGeometry = iSetup.getHandle(tGeomToken_);
0858   if (!theTrackerGeometry.isValid()) {
0859     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerDigiGeometryRecord in event!";
0860     return;
0861   }
0862   const TrackerGeometry &theTracker(*theTrackerGeometry);
0863 
0864   // iterator to access containers
0865   edm::PSimHitContainer::const_iterator itHit;
0866 
0867   ///////////////////////////////
0868   // get Pixel Barrel information
0869   ///////////////////////////////
0870   edm::PSimHitContainer thePxlBrlHits;
0871   // extract low container
0872   edm::Handle<edm::PSimHitContainer> PxlBrlLowContainer;
0873   iEvent.getByToken(PxlBrlLowSrc_Token_, PxlBrlLowContainer);
0874   if (!PxlBrlLowContainer.isValid()) {
0875     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsPixelBarrelLowTof in event!";
0876     return;
0877   }
0878   // extract high container
0879   edm::Handle<edm::PSimHitContainer> PxlBrlHighContainer;
0880   iEvent.getByToken(PxlBrlHighSrc_Token_, PxlBrlHighContainer);
0881   if (!PxlBrlHighContainer.isValid()) {
0882     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsPixelBarrelHighTof in event!";
0883     return;
0884   }
0885   // place both containers into new container
0886   thePxlBrlHits.insert(thePxlBrlHits.end(), PxlBrlLowContainer->begin(), PxlBrlLowContainer->end());
0887   thePxlBrlHits.insert(thePxlBrlHits.end(), PxlBrlHighContainer->begin(), PxlBrlHighContainer->end());
0888 
0889   // cycle through new container
0890   int i = 0, j = 0;
0891   for (itHit = thePxlBrlHits.begin(); itHit != thePxlBrlHits.end(); ++itHit) {
0892     ++i;
0893 
0894     // create a DetId from the detUnitId
0895     DetId theDetUnitId(itHit->detUnitId());
0896     int detector = theDetUnitId.det();
0897     int subdetector = theDetUnitId.subdetId();
0898 
0899     // check that expected detector is returned
0900     if ((detector == dTrk) && (subdetector == sdPxlBrl)) {
0901       // get the GeomDetUnit from the geometry using theDetUnitID
0902       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
0903 
0904       if (!theDet) {
0905         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from PxlBrlHits for Hit " << i;
0906         continue;
0907       }
0908 
0909       ++j;
0910 
0911       // get the Surface of the hit (knows how to go from local <-> global)
0912       const BoundPlane &bSurface = theDet->surface();
0913 
0914       if (hTrackerPxBToF)
0915         hTrackerPxBToF->Fill(itHit->tof());
0916       if (hTrackerPxBR)
0917         hTrackerPxBR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
0918       if (hTrackerPxPhi)
0919         hTrackerPxPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
0920       if (hTrackerPxEta)
0921         hTrackerPxEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
0922 
0923     } else {
0924       edm::LogWarning(MsgLoggerCat) << "PxlBrl PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
0925                                     << sdPxlBrl << "); value returned is: (" << detector << "," << subdetector << ")";
0926       continue;
0927     }  // end detector type check
0928   }    // end loop through PxlBrl Hits
0929 
0930   if (verbosity > 1) {
0931     eventout += "\n          Number of Pixel Barrel Hits collected:..... ";
0932     eventout += j;
0933   }
0934 
0935   nPxlHits += j;
0936 
0937   /////////////////////////////////
0938   // get Pixel Forward information
0939   ////////////////////////////////
0940   edm::PSimHitContainer thePxlFwdHits;
0941   // extract low container
0942   edm::Handle<edm::PSimHitContainer> PxlFwdLowContainer;
0943   iEvent.getByToken(PxlFwdLowSrc_Token_, PxlFwdLowContainer);
0944   if (!PxlFwdLowContainer.isValid()) {
0945     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsPixelEndcapLowTof in event!";
0946     return;
0947   }
0948   // extract high container
0949   edm::Handle<edm::PSimHitContainer> PxlFwdHighContainer;
0950   iEvent.getByToken(PxlFwdHighSrc_Token_, PxlFwdHighContainer);
0951   if (!PxlFwdHighContainer.isValid()) {
0952     edm::LogWarning("GlobalHitsProdHist_fillTrk") << "Unable to find TrackerHitsPixelEndcapHighTof in event!";
0953     return;
0954   }
0955   // place both containers into new container
0956   thePxlFwdHits.insert(thePxlFwdHits.end(), PxlFwdLowContainer->begin(), PxlFwdLowContainer->end());
0957   thePxlFwdHits.insert(thePxlFwdHits.end(), PxlFwdHighContainer->begin(), PxlFwdHighContainer->end());
0958 
0959   // cycle through new container
0960   i = 0;
0961   j = 0;
0962   for (itHit = thePxlFwdHits.begin(); itHit != thePxlFwdHits.end(); ++itHit) {
0963     ++i;
0964 
0965     // create a DetId from the detUnitId
0966     DetId theDetUnitId(itHit->detUnitId());
0967     int detector = theDetUnitId.det();
0968     int subdetector = theDetUnitId.subdetId();
0969 
0970     // check that expected detector is returned
0971     if ((detector == dTrk) && (subdetector == sdPxlFwd)) {
0972       // get the GeomDetUnit from the geometry using theDetUnitID
0973       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
0974 
0975       if (!theDet) {
0976         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from PxlFwdHits for Hit " << i;
0977         ;
0978         continue;
0979       }
0980 
0981       ++j;
0982 
0983       // get the Surface of the hit (knows how to go from local <-> global)
0984       const BoundPlane &bSurface = theDet->surface();
0985 
0986       if (hTrackerPxFToF)
0987         hTrackerPxFToF->Fill(itHit->tof());
0988       if (hTrackerPxFZ)
0989         hTrackerPxFZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
0990       if (hTrackerPxPhi)
0991         hTrackerPxPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
0992       if (hTrackerPxEta)
0993         hTrackerPxEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
0994 
0995     } else {
0996       edm::LogWarning(MsgLoggerCat) << "PxlFwd PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
0997                                     << sdPxlFwd << "); value returned is: (" << detector << "," << subdetector << ")";
0998       continue;
0999     }  // end detector type check
1000   }    // end loop through PxlFwd Hits
1001 
1002   if (verbosity > 1) {
1003     eventout += "\n          Number of Pixel Forward Hits collected:.... ";
1004     eventout += j;
1005   }
1006 
1007   nPxlHits += j;
1008 
1009   if (hTrackerPx[0])
1010     hTrackerPx[0]->Fill((float)nPxlHits);
1011   if (hTrackerPx[1])
1012     hTrackerPx[1]->Fill((float)nPxlHits);
1013 
1014   ///////////////////////////////////
1015   // get Silicon Barrel information
1016   //////////////////////////////////
1017   nSiHits = 0;
1018   edm::PSimHitContainer theSiBrlHits;
1019   // extract TIB low container
1020   edm::Handle<edm::PSimHitContainer> SiTIBLowContainer;
1021   iEvent.getByToken(SiTIBLowSrc_Token_, SiTIBLowContainer);
1022   if (!SiTIBLowContainer.isValid()) {
1023     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTIBLowTof in event!";
1024     return;
1025   }
1026   // extract TIB high container
1027   edm::Handle<edm::PSimHitContainer> SiTIBHighContainer;
1028   iEvent.getByToken(SiTIBHighSrc_Token_, SiTIBHighContainer);
1029   if (!SiTIBHighContainer.isValid()) {
1030     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTIBHighTof in event!";
1031     return;
1032   }
1033   // extract TOB low container
1034   edm::Handle<edm::PSimHitContainer> SiTOBLowContainer;
1035   iEvent.getByToken(SiTOBLowSrc_Token_, SiTOBLowContainer);
1036   if (!SiTOBLowContainer.isValid()) {
1037     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTOBLowTof in event!";
1038     return;
1039   }
1040   // extract TOB high container
1041   edm::Handle<edm::PSimHitContainer> SiTOBHighContainer;
1042   iEvent.getByToken(SiTOBHighSrc_Token_, SiTOBHighContainer);
1043   if (!SiTOBHighContainer.isValid()) {
1044     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTOBHighTof in event!";
1045     return;
1046   }
1047   // place all containers into new container
1048   theSiBrlHits.insert(theSiBrlHits.end(), SiTIBLowContainer->begin(), SiTIBLowContainer->end());
1049   theSiBrlHits.insert(theSiBrlHits.end(), SiTIBHighContainer->begin(), SiTIBHighContainer->end());
1050   theSiBrlHits.insert(theSiBrlHits.end(), SiTOBLowContainer->begin(), SiTOBLowContainer->end());
1051   theSiBrlHits.insert(theSiBrlHits.end(), SiTOBHighContainer->begin(), SiTOBHighContainer->end());
1052 
1053   // cycle through new container
1054   i = 0;
1055   j = 0;
1056   for (itHit = theSiBrlHits.begin(); itHit != theSiBrlHits.end(); ++itHit) {
1057     ++i;
1058 
1059     // create a DetId from the detUnitId
1060     DetId theDetUnitId(itHit->detUnitId());
1061     int detector = theDetUnitId.det();
1062     int subdetector = theDetUnitId.subdetId();
1063 
1064     // check that expected detector is returned
1065     if ((detector == dTrk) && ((subdetector == sdSiTIB) || (subdetector == sdSiTOB))) {
1066       // get the GeomDetUnit from the geometry using theDetUnitID
1067       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
1068 
1069       if (!theDet) {
1070         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from SiBrlHits for Hit " << i;
1071         continue;
1072       }
1073 
1074       ++j;
1075 
1076       // get the Surface of the hit (knows how to go from local <-> global)
1077       const BoundPlane &bSurface = theDet->surface();
1078 
1079       if (hTrackerSiBToF)
1080         hTrackerSiBToF->Fill(itHit->tof());
1081       if (hTrackerSiBR)
1082         hTrackerSiBR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
1083       if (hTrackerSiPhi)
1084         hTrackerSiPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1085       if (hTrackerSiEta)
1086         hTrackerSiEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1087 
1088     } else {
1089       edm::LogWarning(MsgLoggerCat) << "SiBrl PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
1090                                     << sdSiTIB << " || " << sdSiTOB << "); value returned is: (" << detector << ","
1091                                     << subdetector << ")";
1092       continue;
1093     }  // end detector type check
1094   }    // end loop through SiBrl Hits
1095 
1096   if (verbosity > 1) {
1097     eventout += "\n          Number of Silicon Barrel Hits collected:... ";
1098     eventout += j;
1099   }
1100 
1101   nSiHits += j;
1102 
1103   ///////////////////////////////////
1104   // get Silicon Forward information
1105   ///////////////////////////////////
1106   edm::PSimHitContainer theSiFwdHits;
1107   // extract TID low container
1108   edm::Handle<edm::PSimHitContainer> SiTIDLowContainer;
1109   iEvent.getByToken(SiTIDLowSrc_Token_, SiTIDLowContainer);
1110   if (!SiTIDLowContainer.isValid()) {
1111     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTIDLowTof in event!";
1112     return;
1113   }
1114   // extract TID high container
1115   edm::Handle<edm::PSimHitContainer> SiTIDHighContainer;
1116   iEvent.getByToken(SiTIDHighSrc_Token_, SiTIDHighContainer);
1117   if (!SiTIDHighContainer.isValid()) {
1118     edm::LogWarning("GlobalHitsProdHist_fillTrk") << "Unable to find TrackerHitsTIDHighTof in event!";
1119     return;
1120   }
1121   // extract TEC low container
1122   edm::Handle<edm::PSimHitContainer> SiTECLowContainer;
1123   iEvent.getByToken(SiTECLowSrc_Token_, SiTECLowContainer);
1124   if (!SiTECLowContainer.isValid()) {
1125     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTECLowTof in event!";
1126     return;
1127   }
1128   // extract TEC high container
1129   edm::Handle<edm::PSimHitContainer> SiTECHighContainer;
1130   iEvent.getByToken(SiTECHighSrc_Token_, SiTECHighContainer);
1131   if (!SiTECHighContainer.isValid()) {
1132     edm::LogWarning(MsgLoggerCat) << "Unable to find TrackerHitsTECHighTof in event!";
1133     return;
1134   }
1135   // place all containers into new container
1136   theSiFwdHits.insert(theSiFwdHits.end(), SiTIDLowContainer->begin(), SiTIDLowContainer->end());
1137   theSiFwdHits.insert(theSiFwdHits.end(), SiTIDHighContainer->begin(), SiTIDHighContainer->end());
1138   theSiFwdHits.insert(theSiFwdHits.end(), SiTECLowContainer->begin(), SiTECLowContainer->end());
1139   theSiFwdHits.insert(theSiFwdHits.end(), SiTECHighContainer->begin(), SiTECHighContainer->end());
1140 
1141   // cycle through container
1142   i = 0;
1143   j = 0;
1144   for (itHit = theSiFwdHits.begin(); itHit != theSiFwdHits.end(); ++itHit) {
1145     ++i;
1146 
1147     // create a DetId from the detUnitId
1148     DetId theDetUnitId(itHit->detUnitId());
1149     int detector = theDetUnitId.det();
1150     int subdetector = theDetUnitId.subdetId();
1151 
1152     // check that expected detector is returned
1153     if ((detector == dTrk) && ((subdetector == sdSiTID) || (subdetector == sdSiTEC))) {
1154       // get the GeomDetUnit from the geometry using theDetUnitID
1155       const GeomDetUnit *theDet = theTracker.idToDetUnit(theDetUnitId);
1156 
1157       if (!theDet) {
1158         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from SiFwdHits Hit " << i;
1159         return;
1160       }
1161 
1162       ++j;
1163 
1164       // get the Surface of the hit (knows how to go from local <-> global)
1165       const BoundPlane &bSurface = theDet->surface();
1166 
1167       if (hTrackerSiFToF)
1168         hTrackerSiFToF->Fill(itHit->tof());
1169       if (hTrackerSiFZ)
1170         hTrackerSiFZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
1171       if (hTrackerSiPhi)
1172         hTrackerSiPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1173       if (hTrackerSiEta)
1174         hTrackerSiEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1175 
1176     } else {
1177       edm::LogWarning(MsgLoggerCat) << "SiFwd PSimHit " << i << " is expected to be (det,subdet) = (" << dTrk << ","
1178                                     << sdSiTOB << " || " << sdSiTEC << "); value returned is: (" << detector << ","
1179                                     << subdetector << ")";
1180       continue;
1181     }  // end check detector type
1182   }    // end loop through SiFwd Hits
1183 
1184   if (verbosity > 1) {
1185     eventout += "\n          Number of Silicon Forward Hits collected:.. ";
1186     eventout += j;
1187   }
1188 
1189   nSiHits += j;
1190 
1191   if (hTrackerSi[0])
1192     hTrackerSi[0]->Fill((float)nSiHits);
1193   if (hTrackerSi[1])
1194     hTrackerSi[1]->Fill((float)nSiHits);
1195 
1196   if (verbosity > 0)
1197     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1198 
1199   return;
1200 }
1201 
1202 void GlobalHitsProdHist::fillMuon(edm::Event &iEvent, const edm::EventSetup &iSetup) {
1203   nMuonHits = 0;
1204   std::string MsgLoggerCat = "GlobalHitsProdHist_fillMuon";
1205 
1206   TString eventout;
1207   if (verbosity > 0)
1208     eventout = "\nGathering info:";
1209 
1210   // iterator to access containers
1211   edm::PSimHitContainer::const_iterator itHit;
1212 
1213   ///////////////////////
1214   // access the CSC Muon
1215   ///////////////////////
1216   // access the CSC Muon geometry
1217   const auto &theCSCGeometry = iSetup.getHandle(cscGeomToken_);
1218   if (!theCSCGeometry.isValid()) {
1219     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonGeometryRecord for the CSCGeometry in event!";
1220     return;
1221   }
1222   const CSCGeometry &theCSCMuon(*theCSCGeometry);
1223 
1224   // get Muon CSC information
1225   edm::Handle<edm::PSimHitContainer> MuonCSCContainer;
1226   iEvent.getByToken(MuonCscSrc_Token_, MuonCSCContainer);
1227   if (!MuonCSCContainer.isValid()) {
1228     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonCSCHits in event!";
1229     return;
1230   }
1231 
1232   // cycle through container
1233   int i = 0, j = 0;
1234   for (itHit = MuonCSCContainer->begin(); itHit != MuonCSCContainer->end(); ++itHit) {
1235     ++i;
1236 
1237     // create a DetId from the detUnitId
1238     DetId theDetUnitId(itHit->detUnitId());
1239     int detector = theDetUnitId.det();
1240     int subdetector = theDetUnitId.subdetId();
1241 
1242     // check that expected detector is returned
1243     if ((detector == dMuon) && (subdetector == sdMuonCSC)) {
1244       // get the GeomDetUnit from the geometry using theDetUnitID
1245       const GeomDetUnit *theDet = theCSCMuon.idToDetUnit(theDetUnitId);
1246 
1247       if (!theDet) {
1248         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from theCSCMuon for hit " << i;
1249         continue;
1250       }
1251 
1252       ++j;
1253 
1254       // get the Surface of the hit (knows how to go from local <-> global)
1255       const BoundPlane &bSurface = theDet->surface();
1256 
1257       if (hMuonCscToF[0])
1258         hMuonCscToF[0]->Fill(itHit->tof());
1259       if (hMuonCscToF[1])
1260         hMuonCscToF[1]->Fill(itHit->tof());
1261       if (hMuonCscZ)
1262         hMuonCscZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
1263       if (hMuonPhi)
1264         hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1265       if (hMuonEta)
1266         hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1267 
1268     } else {
1269       edm::LogWarning(MsgLoggerCat) << "MuonCsc PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << ","
1270                                     << sdMuonCSC << "); value returned is: (" << detector << "," << subdetector << ")";
1271       continue;
1272     }  // end detector type check
1273   }    // end loop through CSC Hits
1274 
1275   if (verbosity > 1) {
1276     eventout += "\n          Number of CSC muon Hits collected:......... ";
1277     eventout += j;
1278   }
1279 
1280   nMuonHits += j;
1281 
1282   /////////////////////
1283   // access the DT Muon
1284   /////////////////////
1285   // access the DT Muon geometry
1286   const auto &theDTGeometry = iSetup.getHandle(dtGeomToken_);
1287   if (!theDTGeometry.isValid()) {
1288     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonGeometryRecord for the DTGeometry in event!";
1289     return;
1290   }
1291   const DTGeometry &theDTMuon(*theDTGeometry);
1292 
1293   // get Muon DT information
1294   edm::Handle<edm::PSimHitContainer> MuonDtContainer;
1295   iEvent.getByToken(MuonDtSrc_Token_, MuonDtContainer);
1296   if (!MuonDtContainer.isValid()) {
1297     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonDTHits in event!";
1298     return;
1299   }
1300 
1301   // cycle through container
1302   i = 0, j = 0;
1303   for (itHit = MuonDtContainer->begin(); itHit != MuonDtContainer->end(); ++itHit) {
1304     ++i;
1305 
1306     // create a DetId from the detUnitId
1307     DetId theDetUnitId(itHit->detUnitId());
1308     int detector = theDetUnitId.det();
1309     int subdetector = theDetUnitId.subdetId();
1310 
1311     // check that expected detector is returned
1312     if ((detector == dMuon) && (subdetector == sdMuonDT)) {
1313       // CSC uses wires and layers rather than the full detID
1314       // get the wireId
1315       DTWireId wireId(itHit->detUnitId());
1316 
1317       // get the DTLayer from the geometry using the wireID
1318       const DTLayer *theDet = theDTMuon.layer(wireId.layerId());
1319 
1320       if (!theDet) {
1321         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from theDtMuon for hit " << i;
1322         continue;
1323       }
1324 
1325       ++j;
1326 
1327       // get the Surface of the hit (knows how to go from local <-> global)
1328       const BoundPlane &bSurface = theDet->surface();
1329 
1330       if (hMuonDtToF[0])
1331         hMuonDtToF[0]->Fill(itHit->tof());
1332       if (hMuonDtToF[1])
1333         hMuonDtToF[1]->Fill(itHit->tof());
1334       if (hMuonDtR)
1335         hMuonDtR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
1336       if (hMuonPhi)
1337         hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1338       if (hMuonEta)
1339         hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1340 
1341     } else {
1342       edm::LogWarning(MsgLoggerCat) << "MuonDt PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << ","
1343                                     << sdMuonDT << "); value returned is: (" << detector << "," << subdetector << ")";
1344       continue;
1345     }  // end detector type check
1346   }    // end loop through DT Hits
1347 
1348   if (verbosity > 1) {
1349     eventout += "\n          Number of DT muon Hits collected:.......... ";
1350     eventout += j;
1351   }
1352 
1353   nMuonHits += j;
1354 
1355   // int RPCBrl = 0, RPCFwd = 0;
1356   ///////////////////////
1357   // access the RPC Muon
1358   ///////////////////////
1359   // access the RPC Muon geometry
1360   const auto &theRPCGeometry = iSetup.getHandle(rpcGeomToken_);
1361   if (!theRPCGeometry.isValid()) {
1362     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonGeometryRecord for the RPCGeometry in event!";
1363     return;
1364   }
1365   const RPCGeometry &theRPCMuon(*theRPCGeometry);
1366 
1367   // get Muon RPC information
1368   edm::Handle<edm::PSimHitContainer> MuonRPCContainer;
1369   iEvent.getByToken(MuonRpcSrc_Token_, MuonRPCContainer);
1370   if (!MuonRPCContainer.isValid()) {
1371     edm::LogWarning(MsgLoggerCat) << "Unable to find MuonRPCHits in event!";
1372     return;
1373   }
1374 
1375   // cycle through container
1376   i = 0, j = 0;
1377   int RPCBrl = 0, RPCFwd = 0;
1378   for (itHit = MuonRPCContainer->begin(); itHit != MuonRPCContainer->end(); ++itHit) {
1379     ++i;
1380 
1381     // create a DetID from the detUnitId
1382     DetId theDetUnitId(itHit->detUnitId());
1383     int detector = theDetUnitId.det();
1384     int subdetector = theDetUnitId.subdetId();
1385 
1386     // check that expected detector is returned
1387     if ((detector == dMuon) && (subdetector == sdMuonRPC)) {
1388       // get an RPCDetID from the detUnitID
1389       RPCDetId RPCId(itHit->detUnitId());
1390 
1391       // find the region of the RPC hit
1392       int region = RPCId.region();
1393 
1394       // get the GeomDetUnit from the geometry using the RPCDetId
1395       const GeomDetUnit *theDet = theRPCMuon.idToDetUnit(theDetUnitId);
1396 
1397       if (!theDet) {
1398         edm::LogWarning(MsgLoggerCat) << "Unable to get GeomDetUnit from theRPCMuon for hit " << i;
1399         continue;
1400       }
1401 
1402       ++j;
1403 
1404       // get the Surface of the hit (knows how to go from local <-> global)
1405       const BoundPlane &bSurface = theDet->surface();
1406 
1407       // gather necessary information
1408       if ((region == sdMuonRPCRgnFwdp) || (region == sdMuonRPCRgnFwdn)) {
1409         ++RPCFwd;
1410 
1411         if (hMuonRpcFToF[0])
1412           hMuonRpcFToF[0]->Fill(itHit->tof());
1413         if (hMuonRpcFToF[1])
1414           hMuonRpcFToF[1]->Fill(itHit->tof());
1415         if (hMuonRpcFZ)
1416           hMuonRpcFZ->Fill(bSurface.toGlobal(itHit->localPosition()).z());
1417         if (hMuonPhi)
1418           hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1419         if (hMuonEta)
1420           hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1421 
1422       } else if (region == sdMuonRPCRgnBrl) {
1423         ++RPCBrl;
1424 
1425         if (hMuonRpcBToF[0])
1426           hMuonRpcBToF[0]->Fill(itHit->tof());
1427         if (hMuonRpcBToF[1])
1428           hMuonRpcBToF[1]->Fill(itHit->tof());
1429         if (hMuonRpcBR)
1430           hMuonRpcBR->Fill(bSurface.toGlobal(itHit->localPosition()).perp());
1431         if (hMuonPhi)
1432           hMuonPhi->Fill(bSurface.toGlobal(itHit->localPosition()).phi());
1433         if (hMuonEta)
1434           hMuonEta->Fill(bSurface.toGlobal(itHit->localPosition()).eta());
1435 
1436       } else {
1437         edm::LogWarning(MsgLoggerCat) << "Invalid region for RPC Muon hit" << i;
1438         continue;
1439       }  // end check of region
1440     } else {
1441       edm::LogWarning(MsgLoggerCat) << "MuonRpc PSimHit " << i << " is expected to be (det,subdet) = (" << dMuon << ","
1442                                     << sdMuonRPC << "); value returned is: (" << detector << "," << subdetector << ")";
1443       continue;
1444     }  // end detector type check
1445   }    // end loop through RPC Hits
1446 
1447   if (verbosity > 1) {
1448     eventout += "\n          Number of RPC muon Hits collected:......... ";
1449     eventout += j;
1450     eventout += "\n                    RPC Barrel muon Hits:............ ";
1451     eventout += RPCBrl;
1452     eventout += "\n                    RPC Forward muon Hits:........... ";
1453     eventout += RPCFwd;
1454   }
1455 
1456   nMuonHits += j;
1457 
1458   if (hMuon[0])
1459     hMuon[0]->Fill((float)nMuonHits);
1460   if (hMuon[1])
1461     hMuon[1]->Fill((float)nMuonHits);
1462 
1463   if (verbosity > 0)
1464     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1465 
1466   return;
1467 }
1468 
1469 void GlobalHitsProdHist::fillECal(edm::Event &iEvent, const edm::EventSetup &iSetup) {
1470   std::string MsgLoggerCat = "GlobalHitsProdHist_fillECal";
1471 
1472   TString eventout;
1473   if (verbosity > 0)
1474     eventout = "\nGathering info:";
1475 
1476   // access the calorimeter geometry
1477   const auto &theCaloGeometry = iSetup.getHandle(caloGeomToken_);
1478   if (!theCaloGeometry.isValid()) {
1479     edm::LogWarning(MsgLoggerCat) << "Unable to find CaloGeometryRecord in event!";
1480     return;
1481   }
1482   const CaloGeometry &theCalo(*theCaloGeometry);
1483 
1484   // iterator to access containers
1485   edm::PCaloHitContainer::const_iterator itHit;
1486 
1487   ///////////////////////////////
1488   // get  ECal information
1489   ///////////////////////////////
1490   edm::PCaloHitContainer theECalHits;
1491   // extract EB container
1492   edm::Handle<edm::PCaloHitContainer> EBContainer;
1493   iEvent.getByToken(ECalEBSrc_Token_, EBContainer);
1494   if (!EBContainer.isValid()) {
1495     edm::LogWarning(MsgLoggerCat) << "Unable to find EcalHitsEB in event!";
1496     return;
1497   }
1498   // extract EE container
1499   edm::Handle<edm::PCaloHitContainer> EEContainer;
1500   iEvent.getByToken(ECalEESrc_Token_, EEContainer);
1501   if (!EEContainer.isValid()) {
1502     edm::LogWarning(MsgLoggerCat) << "Unable to find EcalHitsEE in event!";
1503     return;
1504   }
1505   // place both containers into new container
1506   theECalHits.insert(theECalHits.end(), EBContainer->begin(), EBContainer->end());
1507   theECalHits.insert(theECalHits.end(), EEContainer->begin(), EEContainer->end());
1508 
1509   // cycle through new container
1510   int i = 0, j = 0;
1511   for (itHit = theECalHits.begin(); itHit != theECalHits.end(); ++itHit) {
1512     ++i;
1513 
1514     // create a DetId from the detUnitId
1515     DetId theDetUnitId(itHit->id());
1516     int detector = theDetUnitId.det();
1517     int subdetector = theDetUnitId.subdetId();
1518 
1519     // check that expected detector is returned
1520     if ((detector == dEcal) && ((subdetector == sdEcalBrl) || (subdetector == sdEcalFwd))) {
1521       // get the Cell geometry
1522       auto theDet = (theCalo.getSubdetectorGeometry(theDetUnitId))->getGeometry(theDetUnitId);
1523 
1524       if (!theDet) {
1525         edm::LogWarning(MsgLoggerCat) << "Unable to get CaloCellGeometry from ECalHits for Hit " << i;
1526         continue;
1527       }
1528 
1529       ++j;
1530 
1531       // get the global position of the cell
1532       const GlobalPoint &globalposition = theDet->getPosition();
1533 
1534       if (hCaloEcalE[0])
1535         hCaloEcalE[0]->Fill(itHit->energy());
1536       if (hCaloEcalE[1])
1537         hCaloEcalE[1]->Fill(itHit->energy());
1538       if (hCaloEcalToF[0])
1539         hCaloEcalToF[0]->Fill(itHit->time());
1540       if (hCaloEcalToF[1])
1541         hCaloEcalToF[1]->Fill(itHit->time());
1542       if (hCaloEcalPhi)
1543         hCaloEcalPhi->Fill(globalposition.phi());
1544       if (hCaloEcalEta)
1545         hCaloEcalEta->Fill(globalposition.eta());
1546 
1547     } else {
1548       edm::LogWarning(MsgLoggerCat) << "ECal PCaloHit " << i << " is expected to be (det,subdet) = (" << dEcal << ","
1549                                     << sdEcalBrl << " || " << sdEcalFwd << "); value returned is: (" << detector << ","
1550                                     << subdetector << ")";
1551       continue;
1552     }  // end detector type check
1553   }    // end loop through ECal Hits
1554 
1555   if (verbosity > 1) {
1556     eventout += "\n          Number of ECal Hits collected:............. ";
1557     eventout += j;
1558   }
1559 
1560   if (hCaloEcal[0])
1561     hCaloEcal[0]->Fill((float)j);
1562   if (hCaloEcal[1])
1563     hCaloEcal[1]->Fill((float)j);
1564 
1565   ////////////////////////////
1566   // Get Preshower information
1567   ////////////////////////////
1568   // extract PreShower container
1569   edm::Handle<edm::PCaloHitContainer> PreShContainer;
1570   iEvent.getByToken(ECalESSrc_Token_, PreShContainer);
1571   if (!PreShContainer.isValid()) {
1572     edm::LogWarning(MsgLoggerCat) << "Unable to find EcalHitsES in event!";
1573     return;
1574   }
1575 
1576   // cycle through container
1577   i = 0, j = 0;
1578   for (itHit = PreShContainer->begin(); itHit != PreShContainer->end(); ++itHit) {
1579     ++i;
1580 
1581     // create a DetId from the detUnitId
1582     DetId theDetUnitId(itHit->id());
1583     int detector = theDetUnitId.det();
1584     int subdetector = theDetUnitId.subdetId();
1585 
1586     // check that expected detector is returned
1587     if ((detector == dEcal) && (subdetector == sdEcalPS)) {
1588       // get the Cell geometry
1589       auto theDet = (theCalo.getSubdetectorGeometry(theDetUnitId))->getGeometry(theDetUnitId);
1590 
1591       if (!theDet) {
1592         edm::LogWarning(MsgLoggerCat) << "Unable to get CaloCellGeometry from PreShContainer for Hit " << i;
1593         continue;
1594       }
1595 
1596       ++j;
1597 
1598       // get the global position of the cell
1599       const GlobalPoint &globalposition = theDet->getPosition();
1600 
1601       if (hCaloPreShE[0])
1602         hCaloPreShE[0]->Fill(itHit->energy());
1603       if (hCaloPreShE[1])
1604         hCaloPreShE[1]->Fill(itHit->energy());
1605       if (hCaloPreShToF[0])
1606         hCaloPreShToF[0]->Fill(itHit->time());
1607       if (hCaloPreShToF[1])
1608         hCaloPreShToF[1]->Fill(itHit->time());
1609       if (hCaloPreShPhi)
1610         hCaloPreShPhi->Fill(globalposition.phi());
1611       if (hCaloPreShEta)
1612         hCaloPreShEta->Fill(globalposition.eta());
1613 
1614     } else {
1615       edm::LogWarning(MsgLoggerCat) << "PreSh PCaloHit " << i << " is expected to be (det,subdet) = (" << dEcal << ","
1616                                     << sdEcalPS << "); value returned is: (" << detector << "," << subdetector << ")";
1617       continue;
1618     }  // end detector type check
1619   }    // end loop through PreShower Hits
1620 
1621   if (verbosity > 1) {
1622     eventout += "\n          Number of PreSh Hits collected:............ ";
1623     eventout += j;
1624   }
1625 
1626   if (hCaloPreSh[0])
1627     hCaloPreSh[0]->Fill((float)j);
1628   if (hCaloPreSh[1])
1629     hCaloPreSh[1]->Fill((float)j);
1630 
1631   if (verbosity > 0)
1632     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1633 
1634   return;
1635 }
1636 
1637 void GlobalHitsProdHist::fillHCal(edm::Event &iEvent, const edm::EventSetup &iSetup) {
1638   std::string MsgLoggerCat = "GlobalHitsProdHist_fillHCal";
1639 
1640   TString eventout;
1641   if (verbosity > 0)
1642     eventout = "\nGathering info:";
1643 
1644   // access the calorimeter geometry
1645   const auto &theCaloGeometry = iSetup.getHandle(caloGeomToken_);
1646   if (!theCaloGeometry.isValid()) {
1647     edm::LogWarning(MsgLoggerCat) << "Unable to find CaloGeometryRecord in event!";
1648     return;
1649   }
1650   const CaloGeometry &theCalo(*theCaloGeometry);
1651 
1652   // iterator to access containers
1653   edm::PCaloHitContainer::const_iterator itHit;
1654 
1655   ///////////////////////////////
1656   // get  HCal information
1657   ///////////////////////////////
1658   // extract HCal container
1659   edm::Handle<edm::PCaloHitContainer> HCalContainer;
1660   iEvent.getByToken(HCalSrc_Token_, HCalContainer);
1661   if (!HCalContainer.isValid()) {
1662     edm::LogWarning(MsgLoggerCat) << "Unable to find HCalHits in event!";
1663     return;
1664   }
1665 
1666   // cycle through container
1667   int i = 0, j = 0;
1668   for (itHit = HCalContainer->begin(); itHit != HCalContainer->end(); ++itHit) {
1669     ++i;
1670 
1671     // create a DetId from the detUnitId
1672     DetId theDetUnitId(itHit->id());
1673     int detector = theDetUnitId.det();
1674     int subdetector = theDetUnitId.subdetId();
1675 
1676     // check that expected detector is returned
1677     if ((detector == dHcal) && ((subdetector == sdHcalBrl) || (subdetector == sdHcalEC) || (subdetector == sdHcalOut) ||
1678                                 (subdetector == sdHcalFwd))) {
1679       // get the Cell geometry
1680       const HcalGeometry *theDet = dynamic_cast<const HcalGeometry *>(theCalo.getSubdetectorGeometry(theDetUnitId));
1681 
1682       if (!theDet) {
1683         edm::LogWarning(MsgLoggerCat) << "Unable to get HcalGeometry from HCalContainer for Hit " << i;
1684         continue;
1685       }
1686 
1687       ++j;
1688 
1689       // get the global position of the cell
1690       const GlobalPoint &globalposition = theDet->getPosition(theDetUnitId);
1691 
1692       if (hCaloHcalE[0])
1693         hCaloHcalE[0]->Fill(itHit->energy());
1694       if (hCaloHcalE[1])
1695         hCaloHcalE[1]->Fill(itHit->energy());
1696       if (hCaloHcalToF[0])
1697         hCaloHcalToF[0]->Fill(itHit->time());
1698       if (hCaloHcalToF[1])
1699         hCaloHcalToF[1]->Fill(itHit->time());
1700       if (hCaloHcalPhi)
1701         hCaloHcalPhi->Fill(globalposition.phi());
1702       if (hCaloHcalEta)
1703         hCaloHcalEta->Fill(globalposition.eta());
1704 
1705     } else {
1706       edm::LogWarning(MsgLoggerCat) << "HCal PCaloHit " << i << " is expected to be (det,subdet) = (" << dHcal << ","
1707                                     << sdHcalBrl << " || " << sdHcalEC << " || " << sdHcalOut << " || " << sdHcalFwd
1708                                     << "); value returned is: (" << detector << "," << subdetector << ")";
1709       continue;
1710     }  // end detector type check
1711   }    // end loop through HCal Hits
1712 
1713   if (verbosity > 1) {
1714     eventout += "\n          Number of HCal Hits collected:............. ";
1715     eventout += j;
1716   }
1717 
1718   if (hCaloHcal[0])
1719     hCaloHcal[0]->Fill((float)j);
1720   if (hCaloHcal[1])
1721     hCaloHcal[1]->Fill((float)j);
1722 
1723   if (verbosity > 0)
1724     edm::LogInfo(MsgLoggerCat) << eventout << "\n";
1725 
1726   return;
1727 }