CMS 3D CMS Logo

Public Member Functions | Private Attributes | Static Private Attributes

ElectronStudy Class Reference

#include <ElectronStudy.h>

Inheritance diagram for ElectronStudy:
edm::EDAnalyzer edm::EDConsumerBase

List of all members.

Public Member Functions

void analyze (const edm::Event &e, const edm::EventSetup &c)
 ElectronStudy (const edm::ParameterSet &ps)
 ~ElectronStudy ()

Private Attributes

double etaBins [NEtaBins+1]
std::string g4Label
TH1F * histoE1x1 [NPBins+1][NEtaBins+1]
TH1F * histoE3x3 [NPBins+1][NEtaBins+1]
TH1F * histoE5x5 [NPBins+1][NEtaBins+1]
TH1F * histoR1 [NPBins+1][NEtaBins+1]
TH1F * histoR2 [NPBins+1][NEtaBins+1]
TH1F * histoR3 [NPBins+1][NEtaBins+1]
bool histos
std::string hitLabEB
std::string hitLabEE
int hotZone
double pBins [NPBins+1]
std::string sourceLabel
int verbose

Static Private Attributes

static const int NEtaBins = 3
static const int NPBins = 8

Detailed Description

Definition at line 33 of file ElectronStudy.h.


Constructor & Destructor Documentation

ElectronStudy::ElectronStudy ( const edm::ParameterSet ps)

Definition at line 15 of file ElectronStudy.cc.

References etaBins, g4Label, edm::ParameterSet::getUntrackedParameter(), histoE1x1, histoE3x3, histoE5x5, histoR1, histoR2, histoR3, histos, hitLabEB, hitLabEE, hotZone, i, edm::Service< T >::isAvailable(), j, mergeVDriftHistosByStation::name, NEtaBins, NPBins, pBins, sourceLabel, AlCaHLTBitMon_QueryRunRegistry::string, and indexGen::title.

                                                      {

  sourceLabel = ps.getUntrackedParameter<std::string>("SourceLabel","generator");
  g4Label = ps.getUntrackedParameter<std::string>("ModuleLabel","g4SimHits");
  hitLabEB= ps.getUntrackedParameter<std::string>("EBCollection","EcalHitsEB");
  hitLabEE= ps.getUntrackedParameter<std::string>("EECollection","EcalHitsEE");
  hotZone = ps.getUntrackedParameter<int>("HotZone",0);
  verbose = ps.getUntrackedParameter<int>("Verbosity",0);
  edm::LogInfo("ElectronStudy") << "Module Label: " << g4Label << "   Hits: "
                                << hitLabEB << ", " << hitLabEE;

  double tempPBins[NPBins+1] = {   0.0,   10.0,   20.0,  40.0,  60.0,  
                                   100.0,  500.0, 1000.0, 10000.0};
  double tempEta[NEtaBins+1] = {0.0, 1.2, 1.6, 3.0};

  for (int i=0; i<NPBins+1; i++)  pBins[i]   = tempPBins[i];
  for(int i=0; i<NEtaBins+1; i++) etaBins[i] = tempEta[i];

  edm::Service<TFileService> tfile;
  if ( !tfile.isAvailable() ) {
    edm::LogInfo("ElectronStudy") << "TFileService unavailable: no histograms";
    histos = false;
  } else {
    char  name[20], title[200], cpbin[30], cebin[30];
    histos = true;
    for (unsigned int i=0; i<NPBins+1; ++i) {
      if (i == 0) sprintf (cpbin, " All p");
      else        sprintf (cpbin, " p (%6.0f:%6.0f)", pBins[i-1], pBins[i]);
      for (unsigned int j=0; j<NEtaBins+1; ++j) {
        if (j == 0) sprintf (cebin, " All #eta");
        else        sprintf (cebin, " #eta (%4.1f:%4.1f)", etaBins[j-1], etaBins[j]);
        sprintf (name, "R1%d%d", i, j);
        sprintf (title,"E1/E9 for %s%s", cpbin, cebin);
        histoR1[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
        histoR1[i][j]->GetXaxis()->SetTitle(title);
        histoR1[i][j]->GetYaxis()->SetTitle("Tracks");
        sprintf (name, "R2%d%d", i, j);
        sprintf (title,"E1/E25 for %s%s", cpbin, cebin);
        histoR2[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
        histoR2[i][j]->GetXaxis()->SetTitle(title);
        histoR2[i][j]->GetYaxis()->SetTitle("Tracks");
        sprintf (name, "R3%d%d", i, j);
        sprintf (title,"E9/E25 for %s%s", cpbin, cebin);
        histoR3[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
        histoR3[i][j]->GetXaxis()->SetTitle(title);
        histoR3[i][j]->GetYaxis()->SetTitle("Tracks");
        sprintf (name, "E1x1%d%d", i, j);
        sprintf (title,"E1/P for %s%s", cpbin, cebin);
        histoE1x1[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
        histoE1x1[i][j]->GetXaxis()->SetTitle(title);
        histoE1x1[i][j]->GetYaxis()->SetTitle("Tracks");
        sprintf (name, "E3x3%d%d", i, j);
        sprintf (title,"E9/P for %s%s", cpbin, cebin);
        histoE3x3[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
        histoE3x3[i][j]->GetXaxis()->SetTitle(title);
        histoE3x3[i][j]->GetYaxis()->SetTitle("Tracks");
        sprintf (name, "E5x5%d%d", i, j);
        sprintf (title,"E25/P for %s%s", cpbin, cebin);
        histoE5x5[i][j] = tfile->make<TH1F>(name, title, 100, 0., 2.);
        histoE5x5[i][j]->GetXaxis()->SetTitle(title);
        histoE5x5[i][j]->GetYaxis()->SetTitle("Tracks");
      }
    }
  } 
}
ElectronStudy::~ElectronStudy ( ) [inline]

Definition at line 38 of file ElectronStudy.h.

{}

Member Function Documentation

void ElectronStudy::analyze ( const edm::Event e,
const edm::EventSetup c 
) [virtual]

Implements edm::EDAnalyzer.

Definition at line 81 of file ElectronStudy.cc.

References abs, ecalTB2006H4_GenSimDigiReco_cfg::bField, gather_cfg::cout, spr::propagatedTrackDirection::detIdECAL, EcalBarrel, EcalEndcap, spr::eECALmatrix(), eta(), etaBins, edm::EventID::event(), g4Label, edm::EventSetup::get(), edm::Event::getByLabel(), histoE1x1, histoE3x3, histoE5x5, histoR1, histoR2, histoR3, histos, hitLabEB, hitLabEE, spr::hotCrystal(), hotZone, edm::EventBase::id(), edm::HandleBase::isValid(), NEtaBins, NPBins, spr::propagatedTrackDirection::okECAL, AlCaHLTBitMon_ParallelJobs::p, pBins, edm::ESHandle< T >::product(), spr::propagateCALO(), diffTwoXMLs::r1, diffTwoXMLs::r2, edm::EventID::run(), and DetId::subdetId().

                                                                               {

  if (verbose > 1) std::cout << "Run = " << iEvent.id().run() << " Event = " 
                             << iEvent.id().event() << std::endl;

  // get Geometry, B-field, Topology
  edm::ESHandle<MagneticField> bFieldH;
  iSetup.get<IdealMagneticFieldRecord>().get(bFieldH);
  const MagneticField* bField = bFieldH.product();

  edm::ESHandle<CaloGeometry> pG;
  iSetup.get<CaloGeometryRecord>().get(pG);
  const CaloGeometry* geo = pG.product();
  
  edm::ESHandle<CaloTopology> theCaloTopology;
  iSetup.get<CaloTopologyRecord>().get(theCaloTopology); 
  const CaloTopology* caloTopology = theCaloTopology.product();

  // get PCaloHits for ecal barrel
  edm::Handle<edm::PCaloHitContainer> caloHitEB;
  iEvent.getByLabel(g4Label,hitLabEB,caloHitEB); 

  // get PCaloHits for ecal endcap
  edm::Handle<edm::PCaloHitContainer> caloHitEE;
  iEvent.getByLabel(g4Label,hitLabEE,caloHitEE); 

  // get sim tracks
  edm::Handle<edm::SimTrackContainer>  SimTk;
  iEvent.getByLabel(g4Label, SimTk);
  
  // get sim vertices
  edm::Handle<edm::SimVertexContainer> SimVtx;
  iEvent.getByLabel(g4Label, SimVtx);
  
  if (verbose>0) 
    std::cout << "ElectronStudy: hits valid[EB]: " << caloHitEB.isValid() 
              << " valid[EE]: " << caloHitEE.isValid() << std::endl;
  
  if (caloHitEB.isValid() && caloHitEE.isValid()) {
    unsigned int indx;
    if (verbose>2) {
      edm::PCaloHitContainer::const_iterator ihit;
      for (ihit=caloHitEB->begin(),indx=0; ihit!=caloHitEB->end(); ihit++,indx++) {
        EBDetId id = ihit->id();
        std::cout << "Hit[" << indx << "] " << id << " E " << ihit->energy() 
                  << " T " << ihit->time() << std::endl;
      }
      for (ihit=caloHitEE->begin(),indx=0; ihit!=caloHitEE->end(); ihit++,indx++) {
        EEDetId id = ihit->id();
        std::cout << "Hit[" << indx << "] " << id << " E " << ihit->energy() 
                  << " T " << ihit->time() << std::endl;
      }
    }
    edm::SimTrackContainer::const_iterator simTrkItr=SimTk->begin();
    for (indx=0; simTrkItr!= SimTk->end(); simTrkItr++,indx++) {
      if (verbose>0) std::cout << "ElectronStudy: Track[" << indx << "] ID "
                               << simTrkItr->trackId() << " type " 
                               << simTrkItr->type()    << " charge " 
                               << simTrkItr->charge()  << " p "
                               << simTrkItr->momentum()<< " Generator Index "
                               << simTrkItr->genpartIndex() << " vertex "
                               << simTrkItr->vertIndex() << std::endl;
      if (std::abs(simTrkItr->type()) == 11 && simTrkItr->vertIndex() != -1) {
        int thisTrk = simTrkItr->trackId();
        spr::propagatedTrackDirection trkD = spr::propagateCALO(thisTrk, SimTk, SimVtx, geo, bField, (verbose>1));
        if (trkD.okECAL) {
          const DetId isoCell = trkD.detIdECAL;
          DetId hotCell = isoCell;
          if (hotZone > 0) hotCell = spr::hotCrystal(isoCell, caloHitEB, caloHitEE, geo, caloTopology, hotZone, hotZone, -500.0, 500.0, (verbose>1));
          double e1x1 = spr::eECALmatrix(hotCell, caloHitEB, caloHitEE, geo, caloTopology, 0, 0, -100.0, -100.0,-500.0, 500.0, (verbose>2));
          double e3x3 = spr::eECALmatrix(hotCell, caloHitEB, caloHitEE, geo, caloTopology, 1, 1, -100.0, -100.0,-500.0, 500.0, (verbose>2));
          double e5x5 = spr::eECALmatrix(hotCell, caloHitEB, caloHitEE, geo, caloTopology, 2, 2, -100.0, -100.0,-500.0, 500.0, (verbose>2));
          double p    = simTrkItr->momentum().P();
          double eta  = std::abs(simTrkItr->momentum().eta());
          int etaBin=-1, momBin=-1;
          for (int ieta=0; ieta<NEtaBins; ieta++)   {
            if (eta>etaBins[ieta] && eta<etaBins[ieta+1] ) etaBin = ieta+1;
          }
          for (int ipt=0;  ipt<NPBins;   ipt++)  {
            if (p>pBins[ipt]      &&  p<pBins[ipt+1] )     momBin = ipt+1;
          }
          double r1=-1, r2=-1, r3=-1;
          if (e3x3 > 0) r1 = e1x1/e3x3;
          if (e5x5 > 0) {r2 = e1x1/e5x5; r3 = e3x3/e5x5;}
          if (verbose>0) {
            std::cout << "ElectronStudy: p " << p << " [" << momBin << "] eta "
                      << eta << " [" << etaBin << "]";
            if (isoCell.subdetId() == EcalBarrel) {
              EBDetId id = isoCell;
              std::cout << " Cell 0x" << std::hex << isoCell() << std::dec 
                        << " " << id;
            } else if (isoCell.subdetId() == EcalEndcap) {
              EEDetId id = isoCell;
              std::cout << " Cell 0x" << std::hex << isoCell() << std::dec
                        << " " << id;
            } else {
              std::cout << " Cell 0x" << std::hex << isoCell() << std::dec
                        << " Unknown Type";
            }
            std::cout << " e1x1 " << e1x1 << "|" << r1 << "|" << r2 << " e3x3 "
                      << e3x3 << "|" << r3 << " e5x5 " << e5x5 << std::endl;
          }
          if (histos) {
            histoR1[0][0]->Fill(r1);
            histoR2[0][0]->Fill(r2);
            histoR3[0][0]->Fill(r3);
            histoE1x1[0][0]->Fill(e1x1/p);
            histoE3x3[0][0]->Fill(e3x3/p);
            histoE5x5[0][0]->Fill(e5x5/p);
            if (momBin>0) {
              histoR1[momBin][0]->Fill(r1);
              histoR2[momBin][0]->Fill(r2);
              histoR3[momBin][0]->Fill(r3);
              histoE1x1[momBin][0]->Fill(e1x1/p);
              histoE3x3[momBin][0]->Fill(e3x3/p);
              histoE5x5[momBin][0]->Fill(e5x5/p);
            }
            if (etaBin>0) {
              histoR1[0][etaBin]->Fill(r1);
              histoR2[0][etaBin]->Fill(r2);
              histoR3[0][etaBin]->Fill(r3);
              histoE1x1[0][etaBin]->Fill(e1x1/p);
              histoE3x3[0][etaBin]->Fill(e3x3/p);
              histoE5x5[0][etaBin]->Fill(e5x5/p);
              if (momBin>0) {
                histoR1[momBin][etaBin]->Fill(r1);
                histoR2[momBin][etaBin]->Fill(r2);
                histoR3[momBin][etaBin]->Fill(r3);
                histoE1x1[momBin][etaBin]->Fill(e1x1/p);
                histoE3x3[momBin][etaBin]->Fill(e3x3/p);
                histoE5x5[momBin][etaBin]->Fill(e5x5/p);
              }
            }
          }
        }
      }
    }
  }

}

Member Data Documentation

double ElectronStudy::etaBins[NEtaBins+1] [private]

Definition at line 46 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

std::string ElectronStudy::g4Label [private]

Definition at line 48 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

TH1F * ElectronStudy::histoE1x1[NPBins+1][NEtaBins+1] [private]

Definition at line 52 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

TH1F* ElectronStudy::histoE3x3[NPBins+1][NEtaBins+1] [private]

Definition at line 53 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

TH1F * ElectronStudy::histoE5x5[NPBins+1][NEtaBins+1] [private]

Definition at line 53 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

TH1F* ElectronStudy::histoR1[NPBins+1][NEtaBins+1] [private]

Definition at line 51 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

TH1F * ElectronStudy::histoR2[NPBins+1][NEtaBins+1] [private]

Definition at line 51 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

TH1F* ElectronStudy::histoR3[NPBins+1][NEtaBins+1] [private]

Definition at line 52 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

bool ElectronStudy::histos [private]

Definition at line 50 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

std::string ElectronStudy::hitLabEB [private]

Definition at line 48 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

std::string ElectronStudy::hitLabEE [private]

Definition at line 48 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

int ElectronStudy::hotZone [private]

Definition at line 49 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

const int ElectronStudy::NEtaBins = 3 [static, private]

Definition at line 44 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

const int ElectronStudy::NPBins = 8 [static, private]

Definition at line 45 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

double ElectronStudy::pBins[NPBins+1] [private]

Definition at line 46 of file ElectronStudy.h.

Referenced by analyze(), and ElectronStudy().

std::string ElectronStudy::sourceLabel [private]

Definition at line 48 of file ElectronStudy.h.

Referenced by ElectronStudy().

int ElectronStudy::verbose [private]

Definition at line 49 of file ElectronStudy.h.