Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:00:05

0001 // -*- C++ -*-
0002 //
0003 // Class:      EcalTPGAnalyzer
0004 //
0005 //
0006 // Original Author:  Pascal Paganini
0007 //
0008 //
0009 
0010 // system include files
0011 #include <memory>
0012 #include <utility>
0013 
0014 // user include files
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 
0017 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
0018 
0019 #include "EcalTPGAnalyzer.h"
0020 
0021 #include <TMath.h>
0022 #include <sstream>
0023 
0024 using namespace edm;
0025 class CaloSubdetectorGeometry;
0026 
0027 EcalTPGAnalyzer::EcalTPGAnalyzer(const edm::ParameterSet& iConfig)
0028     : tpCollection_(iConfig.getParameter<edm::InputTag>("TPCollection")),
0029       tpEmulatorCollection_(iConfig.getParameter<edm::InputTag>("TPEmulatorCollection")),
0030       digiCollectionEB_(iConfig.getParameter<edm::InputTag>("DigiCollectionEB")),
0031       digiCollectionEE_(iConfig.getParameter<edm::InputTag>("DigiCollectionEE")),
0032       gtRecordCollectionTag_(iConfig.getParameter<std::string>("GTRecordCollection")),
0033       l1GtReadoutRecordToken_(consumes<L1GlobalTriggerReadoutRecord>(edm::InputTag(gtRecordCollectionTag_))),
0034       tpToken_(consumes<EcalTrigPrimDigiCollection>(tpCollection_)),
0035       tpEmulToken_(consumes<EcalTrigPrimDigiCollection>(tpEmulatorCollection_)),
0036       ebDigiToken_(consumes<EBDigiCollection>(digiCollectionEB_)),
0037       eeDigiToken_(consumes<EEDigiCollection>(digiCollectionEE_)),
0038       eTTMapToken_(esConsumes<edm::Transition::BeginRun>()),
0039       ebGeometryToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "EcalBarrel"))),
0040       eeGeometryToken_(esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "EcalEndcap"))),
0041       l1GtMaskToken_(esConsumes()),
0042       allowTP_(iConfig.getParameter<bool>("ReadTriggerPrimitives")),
0043       useEE_(iConfig.getParameter<bool>("UseEndCap")),
0044       print_(iConfig.getParameter<bool>("Print")) {
0045   // file
0046   file_ = new TFile("ECALTPGtree.root", "RECREATE");
0047   file_->cd();
0048 
0049   // tree
0050   tree_ = new TTree("EcalTPGAnalysis", "EcalTPGAnalysis");
0051 
0052   tree_->Branch("runNb", &treeVariables_.runNb, "runNb/i");                                                //
0053   tree_->Branch("evtNb", &treeVariables_.evtNb, "evtNb/i");                                                //
0054   tree_->Branch("bxNb", &treeVariables_.bxNb, "bxNb/i");                                                   //
0055   tree_->Branch("orbitNb", &treeVariables_.orbitNb, "orbitNb/i");                                          //
0056   tree_->Branch("nbOfActiveTriggers", &treeVariables_.nbOfActiveTriggers, "nbOfActiveTriggers/i");         //
0057   tree_->Branch("activeTriggers", treeVariables_.activeTriggers, "activeTriggers[nbOfActiveTriggers]/I");  //
0058 
0059   tree_->Branch("nbOfTowers", &treeVariables_.nbOfTowers, "nbOfTowers/i");             //
0060   tree_->Branch("ieta", treeVariables_.ieta, "ieta[nbOfTowers]/I");                    //
0061   tree_->Branch("iphi", treeVariables_.iphi, "iphi[nbOfTowers]/I");                    //
0062   tree_->Branch("nbOfXtals", treeVariables_.nbOfXtals, "nbOfXtals[nbOfTowers]/I");     //
0063   tree_->Branch("rawTPData", treeVariables_.rawTPData, "rawTPData[nbOfTowers]/I");     //
0064   tree_->Branch("rawTPEmul1", treeVariables_.rawTPEmul1, "rawTPEmul1[nbOfTowers]/I");  //
0065   tree_->Branch("rawTPEmul2", treeVariables_.rawTPEmul2, "rawTPEmul2[nbOfTowers]/I");  //
0066   tree_->Branch("rawTPEmul3", treeVariables_.rawTPEmul3, "rawTPEmul3[nbOfTowers]/I");  //
0067   tree_->Branch("rawTPEmul4", treeVariables_.rawTPEmul4, "rawTPEmul4[nbOfTowers]/I");  //
0068   tree_->Branch("rawTPEmul5", treeVariables_.rawTPEmul5, "rawTPEmul5[nbOfTowers]/I");  //
0069   tree_->Branch("eRec", treeVariables_.eRec, "eRec[nbOfTowers]/F");                    //
0070 }
0071 
0072 EcalTPGAnalyzer::~EcalTPGAnalyzer() {
0073   file_->cd();
0074   tree_->Write();
0075   file_->Close();
0076 }
0077 
0078 void EcalTPGAnalyzer::beginRun(edm::Run const&, edm::EventSetup const& evtSetup) {
0079   // geometry
0080   eTTmap_ = &evtSetup.getData(eTTMapToken_);
0081   theBarrelGeometry_ = &evtSetup.getData(ebGeometryToken_);
0082   theEndcapGeometry_ = &evtSetup.getData(eeGeometryToken_);
0083 }
0084 
0085 void EcalTPGAnalyzer::endRun(edm::Run const&, edm::EventSetup const& evtSetup) {}
0086 
0087 void EcalTPGAnalyzer::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0088   using namespace edm;
0089   using namespace std;
0090 
0091   if (print_)
0092     std::cout << "===========" << iEvent.id() << std::endl;
0093 
0094   map<EcalTrigTowerDetId, towerEner> mapTower;
0095   map<EcalTrigTowerDetId, towerEner>::iterator itTT;
0096 
0097   ///////////////////////////
0098   // get Evts info
0099   ///////////////////////////
0100 
0101   treeVariables_.runNb = iEvent.id().run();
0102   treeVariables_.evtNb = iEvent.id().event();
0103   treeVariables_.bxNb = iEvent.bunchCrossing();
0104   treeVariables_.orbitNb = iEvent.orbitNumber();
0105 
0106   ///////////////////////////
0107   // get L1 info
0108   ///////////////////////////
0109 
0110   edm::Handle<L1GlobalTriggerReadoutRecord> gtRecord;
0111   iEvent.getByToken(l1GtReadoutRecordToken_, gtRecord);
0112   DecisionWord dWord = gtRecord->decisionWord();  // this will get the decision word *before* masking disabled bits
0113 
0114   const auto& l1GtTmAlgo = iSetup.getData(l1GtMaskToken_);
0115   std::vector<unsigned int> triggerMaskAlgoTrig = l1GtTmAlgo.gtTriggerMask();
0116 
0117   // apply masks on algo
0118   int iDaq = 0;
0119   int iBit = -1;
0120   treeVariables_.nbOfActiveTriggers = 0;
0121   for (std::vector<bool>::iterator itBit = dWord.begin(); itBit != dWord.end(); ++itBit) {
0122     iBit++;
0123     int maskBit = triggerMaskAlgoTrig[iBit] & (1 << iDaq);
0124     if (maskBit)
0125       *itBit = false;
0126     if (*itBit) {
0127       treeVariables_.activeTriggers[treeVariables_.nbOfActiveTriggers] = iBit;
0128       treeVariables_.nbOfActiveTriggers++;
0129     }
0130   }
0131 
0132   ///////////////////////////
0133   // Get TP data
0134   ///////////////////////////
0135 
0136   edm::Handle<EcalTrigPrimDigiCollection> tp;
0137   iEvent.getByToken(tpToken_, tp);
0138   if (print_)
0139     std::cout << "TP collection size=" << tp.product()->size() << std::endl;
0140 
0141   for (unsigned int i = 0; i < tp.product()->size(); i++) {
0142     EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
0143     const EcalTrigTowerDetId TPtowid = d.id();
0144     towerEner tE;
0145     tE.iphi_ = TPtowid.iphi();
0146     tE.ieta_ = TPtowid.ieta();
0147     tE.tpgADC_ = d[0].raw();
0148     mapTower[TPtowid] = tE;
0149   }
0150 
0151   ///////////////////////////
0152   // Get Emulators TP
0153   ///////////////////////////
0154 
0155   edm::Handle<EcalTrigPrimDigiCollection> tpEmul;
0156   iEvent.getByToken(tpEmulToken_, tpEmul);
0157   if (print_)
0158     std::cout << "TPEmulator collection size=" << tpEmul.product()->size() << std::endl;
0159 
0160   for (unsigned int i = 0; i < tpEmul.product()->size(); i++) {
0161     EcalTriggerPrimitiveDigi d = (*(tpEmul.product()))[i];
0162     const EcalTrigTowerDetId TPtowid = d.id();
0163     itTT = mapTower.find(TPtowid);
0164     if (itTT != mapTower.end())
0165       for (int j = 0; j < 5; j++)
0166         (itTT->second).tpgEmul_[j] = d[j].raw();
0167   }
0168 
0169   ///////////////////////////
0170   // Get nb of crystals read out
0171   ///////////////////////////
0172 
0173   // Get EB xtal digi inputs
0174   edm::Handle<EBDigiCollection> digiEB;
0175   iEvent.getByToken(ebDigiToken_, digiEB);
0176 
0177   for (unsigned int i = 0; i < digiEB.product()->size(); i++) {
0178     const EBDataFrame& df = (*(digiEB.product()))[i];
0179     const EBDetId& id = df.id();
0180     const EcalTrigTowerDetId towid = id.tower();
0181     itTT = mapTower.find(towid);
0182     if (itTT != mapTower.end())
0183       (itTT->second).nbXtal_++;
0184   }
0185 
0186   if (useEE_) {
0187     // Get EE xtal digi inputs
0188     edm::Handle<EEDigiCollection> digiEE;
0189     iEvent.getByToken(eeDigiToken_, digiEE);
0190     for (unsigned int i = 0; i < digiEE.product()->size(); i++) {
0191       const EEDataFrame& df = (*(digiEE.product()))[i];
0192       const EEDetId& id = df.id();
0193       const EcalTrigTowerDetId towid = eTTmap_->towerOf(id);
0194       itTT = mapTower.find(towid);
0195       if (itTT != mapTower.end())
0196         (itTT->second).nbXtal_++;
0197     }
0198   }
0199 
0200   ///////////////////////////
0201   // Get rechits
0202   ///////////////////////////
0203 
0204   //... to be completed
0205 
0206   ///////////////////////////
0207   // fill tree
0208   ///////////////////////////
0209 
0210   treeVariables_.nbOfTowers = mapTower.size();
0211   int towerNb = 0;
0212   for (itTT = mapTower.begin(); itTT != mapTower.end(); ++itTT) {
0213     treeVariables_.ieta[towerNb] = (itTT->second).ieta_;
0214     treeVariables_.iphi[towerNb] = (itTT->second).iphi_;
0215     treeVariables_.nbOfXtals[towerNb] = (itTT->second).nbXtal_;
0216     treeVariables_.rawTPData[towerNb] = (itTT->second).tpgADC_;
0217     treeVariables_.rawTPEmul1[towerNb] = (itTT->second).tpgEmul_[0];
0218     treeVariables_.rawTPEmul2[towerNb] = (itTT->second).tpgEmul_[1];
0219     treeVariables_.rawTPEmul3[towerNb] = (itTT->second).tpgEmul_[2];
0220     treeVariables_.rawTPEmul4[towerNb] = (itTT->second).tpgEmul_[3];
0221     treeVariables_.rawTPEmul5[towerNb] = (itTT->second).tpgEmul_[4];
0222     treeVariables_.eRec[towerNb] = (itTT->second).eRec_;
0223     towerNb++;
0224   }
0225 
0226   tree_->Fill();
0227 }