Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:30:30

0001 // system include files
0002 #include <memory>
0003 
0004 // user include files
0005 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0006 #include "FWCore/Framework/interface/EDAnalyzer.h"
0007 #include "FWCore/Framework/interface/Frameworkfwd.h"
0008 
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 
0012 #include "FWCore/ServiceRegistry/interface/Service.h"
0013 
0014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0015 
0016 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
0017 
0018 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTTestAnalyzer.h"
0019 
0020 using std::cout;
0021 using std::endl;
0022 using std::string;
0023 
0024 //
0025 // constructors and destructor
0026 //
0027 L1RCTTestAnalyzer::L1RCTTestAnalyzer(const edm::ParameterSet &iConfig)
0028     : showEmCands(iConfig.getUntrackedParameter<bool>("showEmCands")),
0029       showRegionSums(iConfig.getUntrackedParameter<bool>("showRegionSums")),
0030       ecalDigisLabel(iConfig.getParameter<edm::InputTag>("ecalDigisLabel")),
0031       hcalDigisLabel(iConfig.getParameter<edm::InputTag>("hcalDigisLabel")),
0032       rctDigisLabel(iConfig.getParameter<edm::InputTag>("rctDigisLabel")) {
0033   // now do what ever initialization is needed
0034 
0035   edm::Service<TFileService> fs;
0036 
0037   emTree = fs->make<TTree>("emTree", "L1 RCT EM tree");
0038   //   emTree->Branch("emRank",emRank,"emRank/I");
0039   //   emTree->Branch("emIeta",emIeta,"emIeta/I");
0040   //   emTree->Branch("emIphi",emIphi,"emIphi/I");
0041   //   emTree->Branch("emIso" ,emIso ,"emIso/I");
0042   emTree->Branch("emRank", &emRank);
0043   emTree->Branch("emIeta", &emIeta);
0044   emTree->Branch("emIphi", &emIphi);
0045   emTree->Branch("emIso", &emIso);
0046 
0047   h_emRank = fs->make<TH1F>("emRank", "emRank", 64, 0., 64.);
0048   h_emRankOutOfTime = fs->make<TH1F>("emRankOutOfTime", "emRankOutOfTime", 64, 0., 64.);
0049   h_emIeta = fs->make<TH1F>("emIeta", "emIeta", 22, 0., 22.);
0050   h_emIphi = fs->make<TH1F>("emIphi", "emIphi", 18, 0., 18.);
0051   h_emIso = fs->make<TH1F>("emIso", "emIso", 2, 0., 2.);
0052   h_emRankInIetaIphi = fs->make<TH2F>("emRank2D", "emRank2D", 22, 0., 22., 18, 0., 18.);
0053   h_emIsoInIetaIphi = fs->make<TH2F>("emIso2D", "emIso2D", 22, 0., 22., 18, 0., 18.);
0054   h_emNonIsoInIetaIphi = fs->make<TH2F>("emNonIso2D", "emNonIso2D", 22, 0., 22., 18, 0., 18.);
0055   h_emCandTimeSample = fs->make<TH1F>("emCandTimeSample", "emCandTimeSample", 5, -2., 2.);
0056 
0057   h_regionSum = fs->make<TH1F>("regionSum", "regionSum", 100, 0., 100.);
0058   h_regionIeta = fs->make<TH1F>("regionIeta", "regionIeta", 22, 0., 22.);
0059   h_regionIphi = fs->make<TH1F>("regionIphi", "regionIphi", 18, 0., 18.);
0060   h_regionMip = fs->make<TH1F>("regionMip", "regionMipBit", 2, 0., 2.);
0061   h_regionSumInIetaIphi = fs->make<TH2F>("regionSum2D", "regionSum2D", 22, 0., 22., 18, 0., 18.);
0062   h_regionFGInIetaIphi = fs->make<TH2F>("regionFG2D", "regionFG2D", 22, 0., 22., 18, 0., 18.);
0063 
0064   h_towerMip = fs->make<TH1F>("towerMip", "towerMipBit", 2, 0., 2.);
0065 
0066   h_ecalTimeSample = fs->make<TH1F>("ecalTimeSample", "ecalTimeSample", 10, 0., 10.);
0067   h_hcalTimeSample = fs->make<TH1F>("hcalTimeSample", "hcalTimeSample", 10, 0., 10.);
0068 
0069   // get names of modules, producing object collections
0070 }
0071 
0072 L1RCTTestAnalyzer::~L1RCTTestAnalyzer() {
0073   // do anything here that needs to be done at destruction time
0074   // (e.g. close files, deallocate resources etc.)
0075 }
0076 
0077 //
0078 // member functions
0079 //
0080 
0081 // ------------ method called to produce the data  ------------
0082 void L1RCTTestAnalyzer::analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) {
0083   using namespace edm;
0084 #ifdef THIS_IS_AN_EVENT_EXAMPLE
0085   Handle<ExampleData> pIn;
0086   iEvent.getByLabel("example", pIn);
0087 #endif
0088 
0089 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
0090   ESHandle<SetupData> pSetup;
0091   iSetup.get<SetupRecord>().get(pSetup);
0092 #endif
0093 
0094   // as in L1GctTestAnalyzer.cc
0095   Handle<L1CaloEmCollection> rctEmCands;
0096   Handle<L1CaloRegionCollection> rctRegions;
0097   Handle<EcalTrigPrimDigiCollection> ecalColl;
0098   Handle<HcalTrigPrimDigiCollection> hcalColl;
0099 
0100   L1CaloEmCollection::const_iterator em;
0101   L1CaloRegionCollection::const_iterator rgn;
0102   EcalTrigPrimDigiCollection::const_iterator ecal;
0103   HcalTrigPrimDigiCollection::const_iterator hcal;
0104 
0105   iEvent.getByLabel(rctDigisLabel, rctEmCands);
0106   iEvent.getByLabel(rctDigisLabel, rctRegions);
0107   iEvent.getByLabel(ecalDigisLabel, ecalColl);
0108   iEvent.getByLabel(hcalDigisLabel, hcalColl);
0109 
0110   // for sorting later
0111   L1CaloEmCollection *myL1EmColl = new L1CaloEmCollection;
0112 
0113   for (ecal = ecalColl->begin(); ecal != ecalColl->end(); ecal++) {
0114     for (unsigned short sample = 0; sample < (*ecal).size(); sample++) {
0115       h_ecalTimeSample->Fill(sample);
0116     }
0117   }
0118 
0119   for (hcal = hcalColl->begin(); hcal != hcalColl->end(); hcal++) {
0120     h_towerMip->Fill((*hcal).SOI_fineGrain());
0121     for (unsigned short sample = 0; sample < (*hcal).size(); sample++) {
0122       h_hcalTimeSample->Fill(sample);
0123     }
0124   }
0125 
0126   if (showEmCands) {
0127     //       std::cout << std::endl << "L1 RCT EmCand objects" << std::endl;
0128   }
0129   for (em = rctEmCands->begin(); em != rctEmCands->end(); em++) {
0130     //  std::cout << "(Analyzer)\n" << (*em) << std::endl;
0131 
0132     L1CaloEmCand *myL1EmCand = new L1CaloEmCand(*em);
0133     (*myL1EmColl).push_back(*myL1EmCand);
0134     delete myL1EmCand;
0135 
0136     h_emCandTimeSample->Fill((*em).bx());
0137     if ((*em).bx() == 0) {
0138       unsigned short n_emcands = 0;
0139       // std::cout << std::endl << "rank: " << (*em).rank() ;
0140 
0141       if ((*em).rank() > 0) {
0142         h_emRank->Fill((*em).rank());
0143         h_emIeta->Fill((*em).regionId().ieta());
0144         h_emIphi->Fill((*em).regionId().iphi());
0145         h_emIso->Fill((*em).isolated());
0146         h_emRankInIetaIphi->Fill((*em).regionId().ieta(), (*em).regionId().iphi(), (*em).rank());
0147         if ((*em).isolated()) {
0148           h_emIsoInIetaIphi->Fill((*em).regionId().ieta(), (*em).regionId().iphi());
0149         } else {
0150           h_emNonIsoInIetaIphi->Fill((*em).regionId().ieta(), (*em).regionId().iphi());
0151         }
0152       }
0153 
0154       if (showEmCands) {
0155         if ((*em).rank() > 0) {
0156           //         std::cout << std::endl << "rank: " << (*em).rank();
0157           unsigned short rgnPhi = 999;
0158           unsigned short rgn = (unsigned short)(*em).rctRegion();
0159           unsigned short card = (unsigned short)(*em).rctCard();
0160           unsigned short crate = (unsigned short)(*em).rctCrate();
0161 
0162           if (card == 6) {
0163             rgnPhi = rgn;
0164           } else if (card < 6) {
0165             rgnPhi = (card % 2);
0166           } else {
0167             std::cout << "rgnPhi not assigned (still " << rgnPhi << ") -- Weird card number! " << card;
0168           }
0169 
0170           // unsigned short phi_bin = ((crate % 9) * 2) + rgnPhi;
0171           short eta_bin = (card / 2) * 2 + 1;
0172           if (card < 6) {
0173             eta_bin = eta_bin + rgn;
0174           }
0175           if (crate < 9) {
0176             eta_bin = -eta_bin;
0177           }
0178           n_emcands++;
0179 
0180           //           std::cout << /* "rank: " << (*em).rank() << */ "
0181           // eta_bin: " << eta_bin << "  phi_bin: " << phi_bin << ".  crate: "
0182           // << crate << "  card: " << card << "  region: " << rgn << ".
0183           // isolated: " << (*em).isolated();
0184         }
0185       }
0186     } else {
0187       h_emRankOutOfTime->Fill((*em).rank());
0188     }
0189   }
0190   if (showEmCands) {
0191     //       std::cout << std::endl;
0192   }
0193 
0194   // next: SORT THESE GUYS so they're entered into the tree highest first
0195   //    std::sort(rctEmCands->begin(),rctEmCands->end(),compareEmCands);
0196   //    for (em=rctEmCands->begin(); em!=rctEmCands->end(); em++)
0197   std::sort(myL1EmColl->begin(), myL1EmColl->end(), compareEmCands);
0198   std::reverse(myL1EmColl->begin(), myL1EmColl->end());  // whoops!
0199   for (em = myL1EmColl->begin(); em != myL1EmColl->end(); em++) {
0200     emRank.push_back((*em).rank());
0201     emIeta.push_back((*em).regionId().ieta());
0202     emIphi.push_back((*em).regionId().iphi());
0203     emIso.push_back((*em).isolated());
0204   }
0205   emTree->Fill();
0206 
0207   if (showRegionSums) {
0208     std::cout << "Regions" << std::endl;
0209   }
0210   for (rgn = rctRegions->begin(); rgn != rctRegions->end(); rgn++) {
0211     if ((*rgn).bx() == 0) {
0212       if (showRegionSums && (*rgn).et() > 0) {
0213         std::cout << /* "(Analyzer)\n" << */ (*rgn) << std::endl;
0214       }
0215       if ((*rgn).et() > 0) {
0216         h_regionSum->Fill((*rgn).et());
0217         h_regionIeta->Fill((*rgn).gctEta());
0218         h_regionIphi->Fill((*rgn).gctPhi());
0219         h_regionSumInIetaIphi->Fill((*rgn).gctEta(), (*rgn).gctPhi(), (*rgn).et());
0220         h_regionFGInIetaIphi->Fill((*rgn).gctEta(), (*rgn).gctPhi(), (*rgn).fineGrain());
0221       }
0222       h_regionMip->Fill((*rgn).mip());
0223     }
0224   }
0225   if (showRegionSums) {
0226     std::cout << std::endl;
0227   }
0228 
0229   emRank.clear();
0230   emIeta.clear();
0231   emIphi.clear();
0232   emIso.clear();
0233 
0234   delete myL1EmColl;
0235 }
0236 
0237 bool L1RCTTestAnalyzer::compareEmCands(const L1CaloEmCand &cand1, const L1CaloEmCand &cand2) {
0238   return (cand1.rank() < cand2.rank());
0239 }