CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/L1Trigger/RegionalCaloTrigger/plugins/L1RCTTestAnalyzer.cc

Go to the documentation of this file.
00001 // system include files
00002 #include <memory>
00003 
00004 // user include files
00005 #include "FWCore/Framework/interface/Frameworkfwd.h"
00006 #include "FWCore/Framework/interface/EDAnalyzer.h"
00007 
00008 #include "FWCore/Framework/interface/Event.h"
00009 #include "FWCore/Framework/interface/MakerMacros.h"
00010 
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 
00013 
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 
00016 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
00017 
00018 #include "L1Trigger/RegionalCaloTrigger/interface/L1RCTTestAnalyzer.h"
00019 
00020 using std::string;
00021 using std::cout;
00022 using std::endl;
00023 
00024 //
00025 // constructors and destructor
00026 //
00027 L1RCTTestAnalyzer::L1RCTTestAnalyzer(const edm::ParameterSet& iConfig) :
00028   showEmCands(iConfig.getUntrackedParameter<bool>("showEmCands")),
00029   showRegionSums(iConfig.getUntrackedParameter<bool>("showRegionSums")),
00030   ecalDigisLabel(iConfig.getParameter<edm::InputTag>("ecalDigisLabel")),
00031   hcalDigisLabel(iConfig.getParameter<edm::InputTag>("hcalDigisLabel")),
00032   rctDigisLabel(iConfig.getParameter<edm::InputTag>("rctDigisLabel"))
00033 {
00034    //now do what ever initialization is needed
00035 
00036   edm::Service<TFileService> fs;
00037   h_emRank = fs->make<TH1F>( "emRank", "emRank", 64, 0., 64. );
00038   h_emRankOutOfTime = fs->make<TH1F>( "emRankOutOfTime", "emRankOutOfTime",
00039                                       64, 0., 64. );
00040   h_emIeta = fs->make<TH1F>( "emIeta", "emIeta", 22, 0., 22. );
00041   h_emIphi = fs->make<TH1F>( "emIphi", "emIphi", 18, 0., 18. );
00042   h_emIso = fs->make<TH1F>( "emIso", "emIso", 2, 0., 2. );
00043   h_emRankInIetaIphi = fs->make<TH2F>( "emRank2D", "emRank2D", 22, 0., 22.,
00044                                        18, 0., 18. );
00045   h_emIsoInIetaIphi = fs->make<TH2F>( "emIso2D", "emIso2D", 22, 0., 22.,
00046                                       18, 0., 18. );
00047   h_emNonIsoInIetaIphi = fs->make<TH2F>( "emNonIso2D", "emNonIso2D", 22, 0., 
00048                                          22., 18, 0., 18. );
00049   h_emCandTimeSample = fs->make<TH1F>( "emCandTimeSample", "emCandTimeSample",
00050                                        5, -2., 2.);
00051 
00052   h_regionSum = fs->make<TH1F>( "regionSum", "regionSum", 100, 0., 100. );
00053   h_regionIeta = fs->make<TH1F>( "regionIeta", "regionIeta", 22, 0., 22. );
00054   h_regionIphi = fs->make<TH1F>( "regionIphi", "regionIphi", 18, 0., 18. );
00055   h_regionMip = fs->make<TH1F>( "regionMip", "regionMipBit", 2, 0., 2. );
00056   h_regionSumInIetaIphi = fs->make<TH2F>( "regionSum2D", "regionSum2D", 22, 
00057                                           0., 22., 18, 0., 18. );
00058   h_regionFGInIetaIphi = fs->make<TH2F>( "regionFG2D", "regionFG2D", 22, 0.,
00059                                          22., 18, 0., 18. );
00060 
00061   h_towerMip = fs->make<TH1F>( "towerMip", "towerMipBit", 2, 0., 2. );
00062 
00063   h_ecalTimeSample = fs->make<TH1F>( "ecalTimeSample", "ecalTimeSample",
00064                                      10, 0., 10. );
00065   h_hcalTimeSample = fs->make<TH1F>( "hcalTimeSample", "hcalTimeSample",
00066                                      10, 0., 10. );
00067 
00068   // get names of modules, producing object collections
00069 }
00070 
00071 
00072 L1RCTTestAnalyzer::~L1RCTTestAnalyzer()
00073 {
00074 
00075    // do anything here that needs to be done at destruction time
00076    // (e.g. close files, deallocate resources etc.)
00077 
00078 }
00079 
00080 
00081 //
00082 // member functions
00083 //
00084 
00085 // ------------ method called to produce the data  ------------
00086 void
00087 L1RCTTestAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00088 {
00089    using namespace edm;
00090 #ifdef THIS_IS_AN_EVENT_EXAMPLE
00091    Handle<ExampleData> pIn;
00092    iEvent.getByLabel("example",pIn);
00093 #endif
00094 
00095 #ifdef THIS_IS_AN_EVENTSETUP_EXAMPLE
00096    ESHandle<SetupData> pSetup;
00097    iSetup.get<SetupRecord>().get(pSetup);
00098 #endif
00099 
00100    // as in L1GctTestAnalyzer.cc
00101    Handle<L1CaloEmCollection> rctEmCands;
00102    Handle<L1CaloRegionCollection> rctRegions;
00103    Handle<EcalTrigPrimDigiCollection> ecalColl;
00104    Handle<HcalTrigPrimDigiCollection> hcalColl;
00105 
00106    L1CaloEmCollection::const_iterator em;
00107    L1CaloRegionCollection::const_iterator rgn;
00108    EcalTrigPrimDigiCollection::const_iterator ecal;
00109    HcalTrigPrimDigiCollection::const_iterator hcal;
00110 
00111    iEvent.getByLabel(rctDigisLabel, rctEmCands);
00112    iEvent.getByLabel(rctDigisLabel, rctRegions);
00113    iEvent.getByLabel(ecalDigisLabel, ecalColl);
00114    iEvent.getByLabel(hcalDigisLabel, hcalColl);
00115 
00116    for (ecal=ecalColl->begin(); ecal!=ecalColl->end(); ecal++)
00117      {
00118        for (unsigned short sample = 0; sample < (*ecal).size(); sample++)
00119          {
00120            h_ecalTimeSample->Fill(sample);
00121          }
00122      }
00123 
00124    for (hcal=hcalColl->begin(); hcal!=hcalColl->end(); hcal++)
00125      {
00126        h_towerMip->Fill( (*hcal).SOI_fineGrain() );
00127        for (unsigned short sample = 0; sample < (*hcal).size(); sample++)
00128          {
00129            h_hcalTimeSample->Fill(sample);
00130          }
00131      }
00132 
00133    if(showEmCands)
00134      {
00135        std::cout << std::endl << "L1 RCT EmCand objects" << std::endl;
00136      }
00137    for (em=rctEmCands->begin(); em!=rctEmCands->end(); em++){
00138      //  std::cout << "(Analyzer)\n" << (*em) << std::endl;
00139      h_emCandTimeSample->Fill((*em).bx());
00140      if ((*em).bx() == 0)
00141        {
00142          unsigned short n_emcands = 0;
00143          //std::cout << std::endl << "rank: " << (*em).rank() ;
00144          
00145          if ((*em).rank() > 0)
00146            {
00147              h_emRank->Fill( (*em).rank() );
00148              h_emIeta->Fill( (*em).regionId().ieta() );
00149              h_emIphi->Fill( (*em).regionId().iphi() );
00150              h_emIso->Fill( (*em).isolated() );
00151              h_emRankInIetaIphi->Fill( (*em).regionId().ieta(), 
00152                                        (*em).regionId().iphi(),
00153                                        (*em).rank() );
00154              if ((*em).isolated())
00155                {
00156                  h_emIsoInIetaIphi->Fill( (*em).regionId().ieta(),
00157                                           (*em).regionId().iphi() );
00158                }
00159              else
00160                {
00161                  h_emNonIsoInIetaIphi->Fill( (*em).regionId().ieta(),
00162                                              (*em).regionId().iphi() );
00163                }
00164            }
00165          
00166          if (showEmCands)
00167            {
00168              if ((*em).rank() > 0)
00169                {
00170                  std::cout << std::endl << "rank: " << (*em).rank();
00171                  unsigned short rgnPhi = 999;
00172                  unsigned short rgn = (unsigned short) (*em).rctRegion();
00173                  unsigned short card = (unsigned short) (*em).rctCard();
00174                  unsigned short crate = (unsigned short) (*em).rctCrate();
00175                  
00176                  if (card == 6)
00177                    {
00178                      rgnPhi = rgn;
00179                    }
00180                  else if (card < 6)
00181                    {
00182                      rgnPhi = (card % 2);
00183                    }
00184                  else 
00185                    {
00186                      std::cout << "rgnPhi not assigned (still " << rgnPhi << ") -- Weird card number! " << card ;
00187                    }
00188                  unsigned short phi_bin = ((crate % 9) * 2) + rgnPhi;
00189                  short eta_bin = (card/2) * 2 + 1;
00190                  if (card < 6)
00191                    {
00192                      eta_bin = eta_bin + rgn;
00193                    }
00194                  if (crate < 9)
00195                    {
00196                      eta_bin = -eta_bin;
00197                    }
00198                  n_emcands++;
00199                  
00200                    std::cout << /* "rank: " << (*em).rank() << */ "  eta_bin: " << eta_bin << "  phi_bin: " << phi_bin << ".  crate: " << crate << "  card: " << card << "  region: " << rgn << ".  isolated: " << (*em).isolated();
00201                }
00202            }
00203        }
00204      else
00205        {
00206          h_emRankOutOfTime->Fill( (*em).rank() );
00207        }
00208    }
00209    if(showEmCands)
00210      {
00211        std::cout << std::endl;
00212      }
00213 
00214    if(showRegionSums)
00215      {
00216        std::cout << "Regions" << std::endl;
00217      }
00218    for (rgn=rctRegions->begin(); rgn!=rctRegions->end(); rgn++)
00219      {
00220        if ((*rgn).bx() == 0)
00221          {
00222            if(showRegionSums&&(*rgn).et()>0)
00223              {
00224                std::cout << /* "(Analyzer)\n" << */ (*rgn) << std::endl;
00225              }
00226            if ( (*rgn).et() > 0 )
00227              {
00228                h_regionSum->Fill( (*rgn).et() );
00229                h_regionIeta->Fill( (*rgn).gctEta() );
00230                h_regionIphi->Fill( (*rgn).gctPhi() );
00231                h_regionSumInIetaIphi->Fill( (*rgn).gctEta(), (*rgn).gctPhi(),
00232                                             (*rgn).et() );
00233                h_regionFGInIetaIphi->Fill( (*rgn).gctEta(), (*rgn).gctPhi(),
00234                                            (*rgn).fineGrain() );
00235              }
00236            h_regionMip->Fill( (*rgn).mip() );
00237          }
00238      }
00239    if(showRegionSums)
00240      {
00241        std::cout << std::endl;
00242      }
00243 
00244 }