CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CaloOnlineTools/EcalTools/plugins/EcalTPGAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Class:      EcalTPGAnalyzer
00004 //
00005 //
00006 // Original Author:  Pascal Paganini
00007 //
00008 //
00009 
00010 
00011 // system include files
00012 #include <memory>
00013 #include <utility>
00014 
00015 // user include files
00016 #include "FWCore/Framework/interface/EDAnalyzer.h"
00017 #include "FWCore/Framework/interface/Event.h"
00018 #include "FWCore/Framework/interface/MakerMacros.h"
00019 
00020 #include "FWCore/Framework/interface/EventSetup.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 
00024 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00025 #include "DataFormats/EcalDigi/interface/EcalTriggerPrimitiveDigi.h"
00026 
00027 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00028 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00029 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00030 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00031 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00032 
00033 #include "CondFormats/L1TObjects/interface/L1GtTriggerMenu.h"
00034 #include "CondFormats/DataRecord/interface/L1GtTriggerMenuRcd.h"
00035 #include "CondFormats/L1TObjects/interface/L1GtTriggerMask.h"
00036 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskAlgoTrigRcd.h"
00037 #include "CondFormats/DataRecord/interface/L1GtTriggerMaskTechTrigRcd.h"
00038 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00039 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00040 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00041 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerRecord.h"
00042 
00043 #include "EcalTPGAnalyzer.h"
00044 
00045 #include <TMath.h>
00046 #include <sstream>
00047 
00048 using namespace edm;
00049 class CaloSubdetectorGeometry;
00050 
00051 EcalTPGAnalyzer::EcalTPGAnalyzer(const edm::ParameterSet&  iConfig)
00052 {
00053   tpCollection_ = iConfig.getParameter<edm::InputTag>("TPCollection") ;
00054   tpEmulatorCollection_ = iConfig.getParameter<edm::InputTag>("TPEmulatorCollection") ;
00055   digiCollectionEB_ = iConfig.getParameter<edm::InputTag>("DigiCollectionEB") ;
00056   digiCollectionEE_ = iConfig.getParameter<edm::InputTag>("DigiCollectionEE") ;
00057   gtRecordCollectionTag_ = iConfig.getParameter<std::string>("GTRecordCollection") ;
00058 
00059   allowTP_ = iConfig.getParameter<bool>("ReadTriggerPrimitives");
00060   useEE_ = iConfig.getParameter<bool>("UseEndCap");
00061   print_ = iConfig.getParameter<bool>("Print");
00062 
00063   // file
00064   file_ = new TFile("ECALTPGtree.root","RECREATE");
00065   file_->cd() ;
00066 
00067   // tree
00068   tree_ = new TTree( "EcalTPGAnalysis","EcalTPGAnalysis" );
00069 
00070   tree_->Branch("runNb",&treeVariables_.runNb,"runNb/i"); //
00071   tree_->Branch("evtNb",&treeVariables_.evtNb,"evtNb/i"); //
00072   tree_->Branch("bxNb",&treeVariables_.bxNb,"bxNb/i"); //
00073   tree_->Branch("orbitNb",&treeVariables_.orbitNb,"orbitNb/i"); //
00074   tree_->Branch("nbOfActiveTriggers",&treeVariables_.nbOfActiveTriggers,"nbOfActiveTriggers/i"); //
00075   tree_->Branch("activeTriggers",treeVariables_.activeTriggers,"activeTriggers[nbOfActiveTriggers]/I"); //
00076 
00077   tree_->Branch("nbOfTowers",&treeVariables_.nbOfTowers,"nbOfTowers/i"); //
00078   tree_->Branch("ieta", treeVariables_.ieta,"ieta[nbOfTowers]/I");//
00079   tree_->Branch("iphi", treeVariables_.iphi,"iphi[nbOfTowers]/I");//
00080   tree_->Branch("nbOfXtals", treeVariables_.nbOfXtals,"nbOfXtals[nbOfTowers]/I");//
00081   tree_->Branch("rawTPData", treeVariables_.rawTPData,"rawTPData[nbOfTowers]/I");//
00082   tree_->Branch("rawTPEmul1", treeVariables_.rawTPEmul1,"rawTPEmul1[nbOfTowers]/I");//
00083   tree_->Branch("rawTPEmul2", treeVariables_.rawTPEmul2,"rawTPEmul2[nbOfTowers]/I");//
00084   tree_->Branch("rawTPEmul3", treeVariables_.rawTPEmul3,"rawTPEmul3[nbOfTowers]/I");//
00085   tree_->Branch("rawTPEmul4", treeVariables_.rawTPEmul4,"rawTPEmul4[nbOfTowers]/I");//
00086   tree_->Branch("rawTPEmul5", treeVariables_.rawTPEmul5,"rawTPEmul5[nbOfTowers]/I");//
00087   tree_->Branch("eRec", treeVariables_.eRec,"eRec[nbOfTowers]/F");//
00088 }
00089 
00090 
00091 EcalTPGAnalyzer::~EcalTPGAnalyzer()
00092 {
00093   file_->cd();
00094   tree_->Write();
00095   file_->Close();
00096 }
00097 
00098 void EcalTPGAnalyzer::beginRun(edm::Run const &, edm::EventSetup const & evtSetup)
00099 {
00100   // geometry
00101   ESHandle<CaloGeometry> theGeometry;
00102   ESHandle<CaloSubdetectorGeometry> theEndcapGeometry_handle, theBarrelGeometry_handle;
00103 
00104   evtSetup.get<CaloGeometryRecord>().get( theGeometry );
00105   evtSetup.get<EcalEndcapGeometryRecord>().get("EcalEndcap",theEndcapGeometry_handle);
00106   evtSetup.get<EcalBarrelGeometryRecord>().get("EcalBarrel",theBarrelGeometry_handle);
00107 
00108   evtSetup.get<IdealGeometryRecord>().get(eTTmap_);
00109   theEndcapGeometry_ = &(*theEndcapGeometry_handle);
00110   theBarrelGeometry_ = &(*theBarrelGeometry_handle);
00111 }
00112 
00113 
00114 void EcalTPGAnalyzer::analyze(edm::Event const & iEvent, edm::EventSetup const & iSetup)
00115 {
00116 
00117 
00118   using namespace edm;
00119   using namespace std;
00120 
00121   if (print_) std::cout<<"==========="<<iEvent.id()<<std::endl ;
00122 
00123 
00124   map<EcalTrigTowerDetId, towerEner> mapTower ;
00125   map<EcalTrigTowerDetId, towerEner>::iterator itTT ;
00126 
00127 
00128 
00130   // get Evts info
00132 
00133   treeVariables_.runNb = iEvent.id().run() ;
00134   treeVariables_.evtNb = iEvent.id().event() ;
00135   treeVariables_.bxNb = iEvent.bunchCrossing() ;
00136   treeVariables_.orbitNb = iEvent.orbitNumber() ;
00137   
00138 
00140   // get L1 info
00142   
00143   edm::Handle< L1GlobalTriggerReadoutRecord > gtRecord;
00144   iEvent.getByLabel( edm::InputTag(gtRecordCollectionTag_), gtRecord);
00145   DecisionWord dWord = gtRecord->decisionWord();   // this will get the decision word *before* masking disabled bits
00146 
00147   edm::ESHandle< L1GtTriggerMask > l1GtTmAlgo;
00148   iSetup.get< L1GtTriggerMaskAlgoTrigRcd >().get( l1GtTmAlgo );        
00149   std::vector<unsigned int> triggerMaskAlgoTrig = l1GtTmAlgo.product()->gtTriggerMask();
00150 
00151   // apply masks on algo    
00152   int iDaq = 0;
00153   int iBit = -1;
00154   treeVariables_.nbOfActiveTriggers = 0 ;
00155   for (std::vector<bool>::iterator itBit = dWord.begin(); itBit != dWord.end(); ++itBit) {        
00156     iBit++;
00157     int maskBit = triggerMaskAlgoTrig[iBit] & (1 << iDaq);
00158     if (maskBit) *itBit = false;
00159     if (*itBit) {
00160       treeVariables_.activeTriggers[treeVariables_.nbOfActiveTriggers] = iBit ;
00161       treeVariables_.nbOfActiveTriggers++ ;      
00162     }
00163   }
00164 
00165 
00166 
00167 
00168 
00170   // Get TP data  
00172 
00173   edm::Handle<EcalTrigPrimDigiCollection> tp;
00174   iEvent.getByLabel(tpCollection_,tp);
00175   if (print_) std::cout<<"TP collection size="<<tp.product()->size()<<std::endl ;
00176 
00177   for (unsigned int i=0;i<tp.product()->size();i++) {
00178     EcalTriggerPrimitiveDigi d = (*(tp.product()))[i];
00179     const EcalTrigTowerDetId TPtowid= d.id();
00180     towerEner tE ;
00181     tE.iphi_ = TPtowid.iphi() ;
00182     tE.ieta_ = TPtowid.ieta() ;
00183     tE.tpgADC_ = d[0].raw() ;
00184     mapTower[TPtowid] = tE ;
00185   }
00186 
00187 
00188 
00190   // Get Emulators TP
00192 
00193   edm::Handle<EcalTrigPrimDigiCollection> tpEmul ;
00194   iEvent.getByLabel(tpEmulatorCollection_, tpEmul);
00195   if (print_) std::cout<<"TPEmulator collection size="<<tpEmul.product()->size()<<std::endl ;
00196 
00197   for (unsigned int i=0;i<tpEmul.product()->size();i++) {
00198     EcalTriggerPrimitiveDigi d = (*(tpEmul.product()))[i];
00199     const EcalTrigTowerDetId TPtowid= d.id();
00200     itTT = mapTower.find(TPtowid) ;
00201     if (itTT != mapTower.end())
00202       for (int j=0 ; j<5 ; j++) (itTT->second).tpgEmul_[j] = d[j].raw() ;
00203   }
00204 
00205 
00206 
00208   // Get nb of crystals read out
00210 
00211   // Get EB xtal digi inputs
00212   edm::Handle<EBDigiCollection> digiEB;
00213   iEvent.getByLabel(digiCollectionEB_, digiEB);
00214 
00215   for (unsigned int i=0;i<digiEB.product()->size();i++) {
00216     const EBDataFrame & df = (*(digiEB.product()))[i];    
00217     const EBDetId & id = df.id();
00218     const EcalTrigTowerDetId towid = id.tower();
00219     itTT = mapTower.find(towid) ;
00220     if (itTT != mapTower.end()) (itTT->second).nbXtal_++ ;
00221   }
00222 
00223   if (useEE_) {
00224     // Get EE xtal digi inputs
00225     edm::Handle<EEDigiCollection> digiEE;
00226     iEvent.getByLabel(digiCollectionEE_, digiEE);
00227     for (unsigned int i=0;i<digiEE.product()->size();i++) {
00228       const EEDataFrame & df = (*(digiEE.product()))[i];
00229       const EEDetId & id = df.id();
00230       const EcalTrigTowerDetId towid = (*eTTmap_).towerOf(id);
00231       itTT = mapTower.find(towid) ;
00232       if (itTT != mapTower.end()) (itTT->second).nbXtal_++ ;
00233     }
00234   }
00235 
00237   // Get rechits
00239 
00240   //... to be completed
00241 
00242 
00243 
00244 
00245 
00247   // fill tree
00249 
00250   treeVariables_.nbOfTowers = mapTower.size() ;
00251   int towerNb = 0 ;
00252   for (itTT = mapTower.begin() ; itTT != mapTower.end() ; ++itTT) {
00253     treeVariables_.ieta[towerNb] = (itTT->second).ieta_ ;
00254     treeVariables_.iphi[towerNb] = (itTT->second).iphi_ ;
00255     treeVariables_.nbOfXtals[towerNb] = (itTT->second).nbXtal_ ;
00256     treeVariables_.rawTPData[towerNb] = (itTT->second).tpgADC_ ;
00257     treeVariables_.rawTPEmul1[towerNb] = (itTT->second).tpgEmul_[0] ;
00258     treeVariables_.rawTPEmul2[towerNb] = (itTT->second).tpgEmul_[1] ;
00259     treeVariables_.rawTPEmul3[towerNb] = (itTT->second).tpgEmul_[2] ;
00260     treeVariables_.rawTPEmul4[towerNb] = (itTT->second).tpgEmul_[3] ;
00261     treeVariables_.rawTPEmul5[towerNb] = (itTT->second).tpgEmul_[4] ;
00262     treeVariables_.eRec[towerNb] = (itTT->second).eRec_ ;
00263     towerNb++ ;
00264   }
00265 
00266   tree_->Fill() ;
00267 
00268 }
00269 
00270