Exemple #1
0
void fwliteExample(bool debug=false){

  // event cuts
  const unsigned int maxEvents = -1;
  const double hfEThreshold = 3.0;
  const int nTowerThreshold = 1;

  // track cuts
  const double normD0Cut = 5.0;
  const double normDZCut = 5.0;
  const double ptDebug = 3.0;

  // trigger names
  const int nTrigs = 4;
  const char *hltNames[nTrigs] = {"HLT_MinBiasBSC","HLT_L1Jet6U","HLT_Jet15U","HLT_Jet30U"};

  //----- input files (900 GeV data) -----
  vector<string> fileNames;
  fileNames.push_back("./hiCommonSkimAOD.root");
  //fileNames.push_back("../test/hiCommonSkimAOD.root");
  fwlite::ChainEvent event(fileNames);
  
  //----- define output hists/trees in directories of output file -----
  TFile *outFile = new TFile("output_fwlite.root","recreate");
  TH1D::SetDefaultSumw2();

  // evt hists
  outFile->cd(); outFile->mkdir("evt"); outFile->cd("evt");
  TH1D *hL1TechBits = new TH1D("hL1TechBits","L1 technical trigger bits before mask",64,-0.5,63.5);
  TH2D *hHfTowers   = new TH2D("hHfTowers","Number of HF tower above threshold; positive side; negative side",80,-0.5,79.5,80,-0.5,79.5);
  TH1D *hHLTPaths   = new TH1D("hHLTPaths","HLT Paths",3,0,3);
  hHLTPaths->SetCanExtend(TH1::kAllAxes);

  // vtx hists
  outFile->cd(); outFile->mkdir("vtx"); outFile->cd("vtx");
  TH1D *hVtxTrks    = new TH1D("hVtxTrks","number of tracks used to fit pixel vertex",50,-0.5,49.5);
  TH1D *hVtxZ       = new TH1D("hVtxZ","z position of best reconstructed pixel vertex", 80,-20,20);
 
  // track hists
  outFile->cd(); outFile->mkdir("trk"); outFile->cd("trk");
  TH1D *hTrkPt      = new TH1D("hTrkPt","track p_{T}; p_{T} [GeV/c]", 80, 0.0, 20.0);
  TH1D *hTrkEta     = new TH1D("hTrkEta","track #eta; #eta", 60, -3.0, 3.0);
  TH1D *hTrkPhi     = new TH1D("hTrkPhi","track #phi; #phi [radians]", 56, -3.5, 3.5);

  // correlation hists
  outFile->cd(); outFile->mkdir("corr"); outFile->cd("corr");
  TH2D *hDetaDphi   = new TH2D("hDetaDphi","raw two-particle correlation; #Delta#eta; #Delta#phi",50,-5.0,5.0,50,-3.1416,3.1416);

  // debug ntuple
  outFile->cd();
  TNtuple *nt=0;
  if(debug) nt = new TNtuple("nt","track debug ntuple",
			     "pt:eta:phi:hits:pterr:d0:d0err:dz:dzerr:jet6:jet15:jet30");

  //----- loop over events -----
  unsigned int iEvent=0;
  for(event.toBegin(); !event.atEnd(); ++event, ++iEvent){

    if( iEvent == maxEvents ) break;
    if( iEvent % 1000 == 0 ) cout << "Processing " << iEvent<< "th event: "
				  << "run " << event.id().run() 
				  << ", lumi " << event.luminosityBlock() 
				  << ", evt " << event.id().event() << endl;

    // select on L1 trigger bits
    fwlite::Handle<L1GlobalTriggerReadoutRecord> gt;
    gt.getByLabel(event, "gtDigis");
    const TechnicalTriggerWord&  word = gt->technicalTriggerWord(); //before mask
    for(int bit=0; bit<64; bit++) hL1TechBits->Fill(bit,word.at(bit));
    if(!word.at(0)) continue;  // BPTX coincidence
    if(!(word.at(40) || word.at(41))) continue; // BSC coincidence
    if(word.at(36) || word.at(37) || word.at(38) || word.at(39)) continue; // BSC halo
    
    // select on coincidence of HF towers above threshold
    fwlite::Handle<CaloTowerCollection> towers;
    towers.getByLabel(event, "towerMaker");
    int nHfTowersN=0, nHfTowersP=0;
    for(CaloTowerCollection::const_iterator calo = towers->begin(); calo != towers->end(); ++calo) {
      if(calo->energy() < hfEThreshold) continue;
      if(calo->eta()>3) nHfTowersP++;
      if(calo->eta()<-3) nHfTowersN++;
    }
    hHfTowers->Fill(nHfTowersP,nHfTowersN);
    if(nHfTowersP < nTowerThreshold || nHfTowersN < nTowerThreshold) continue;
    

    // get hlt bits
    bool accept[nTrigs]={};
    fwlite::Handle<edm::TriggerResults> triggerResults;
    triggerResults.getByLabel(event, "TriggerResults","","HLT");
    const edm::TriggerNames triggerNames = event.triggerNames(*triggerResults);
    for(int i=0; i<nTrigs; i++) {
      accept[i] = triggerResults->accept(triggerNames.triggerIndex(hltNames[i]));
      if(accept[i]) hHLTPaths->Fill(hltNames[i],1);
    }

    // select on requirement of valid vertex
    math::XYZPoint vtxpoint(0,0,0);
    fwlite::Handle<std::vector<reco::Vertex> > vertices;
    vertices.getByLabel(event, "hiSelectedVertex");
    if(!vertices->size()) continue;
    const reco::Vertex & vtx = (*vertices)[0];
    vtxpoint.SetCoordinates(vtx.x(),vtx.y(),vtx.z());
    hVtxTrks->Fill(vtx.tracksSize());
    hVtxZ->Fill(vtx.z());

    // get beamspot 
    fwlite::Handle<reco::BeamSpot> beamspot;
    beamspot.getByLabel(event, "offlineBeamSpot");

    //----- loop over tracks -----

    fwlite::Handle<std::vector<reco::Track> > tracks;
    tracks.getByLabel(event, "hiSelectedTracks");

    for(unsigned it=0; it<tracks->size(); ++it){
      
      const reco::Track & trk = (*tracks)[it];

      // select tracks based on transverse proximity to beamspot
      double dxybeam = trk.dxy(beamspot->position());
      if(fabs(dxybeam/trk.d0Error()) > normD0Cut) continue;

      // select tracks based on z-proximity to best vertex 
      double dzvtx = trk.dz(vtxpoint);
      if(fabs(dzvtx/trk.dzError()) > normDZCut) continue;

      // fill selected track histograms and debug ntuple
      hTrkPt->Fill(trk.pt());
      hTrkEta->Fill(trk.eta());
      hTrkPhi->Fill(trk.phi());
      if(debug && trk.pt() > ptDebug) // fill debug ntuple for selection of tracks
	nt->Fill(trk.pt(),trk.eta(),trk.phi(),trk.numberOfValidHits(),trk.ptError(),
		 dxybeam,trk.d0Error(),dzvtx,trk.dzError(),accept[1],accept[2],accept[3]);
    
    }

    //----- loop over jets -----

    fwlite::Handle<vector<reco::CaloJet> > jets;
    jets.getByLabel(event, "iterativeConePu5CaloJets");

    //----- loop over muons -----

    //----- loop over photons -----

    //----- loop over charged candidates -----
    
    fwlite::Handle<vector<reco::RecoChargedCandidate> > candidates;
    candidates.getByLabel(event, "allTracks");
    
    for(unsigned it1=0; it1<candidates->size(); ++it1) {
      const reco::RecoChargedCandidate & c1 = (*candidates)[it1];
      for(unsigned it2=0; it2<candidates->size(); ++it2) {
	if(it1==it2) continue;
	const reco::RecoChargedCandidate & c2 = (*candidates)[it2];	
	hDetaDphi->Fill(c1.eta()-c2.eta(),deltaPhi(c1.phi(),c2.phi()));
      }
    }

  } //end loop over events
  
  cout << "Number of events processed : " << iEvent << endl;
  cout << "Number passing all event selection cuts: " << hVtxZ->GetEntries() << endl;

  // write to output file
  hHLTPaths->LabelsDeflate();
  outFile->Write();
  outFile->ls();
  outFile->Close();

}
Exemple #2
0
void ChPartTree::GetFwdGap(const edm::Event& iEvent , const edm::EventSetup& iSetup )
{
   using namespace std;


  int nTowersHF_plus = 0;
  int nTowersHF_minus = 0;
  int nTowersHE_plus = 0;
  int nTowersHE_minus = 0;
  int nTowersHB_plus = 0;
  int nTowersHB_minus = 0;
  int nTowersEE_plus = 0;
  int nTowersEE_minus = 0;
  int nTowersEB_plus = 0;
  int nTowersEB_minus = 0; 
  //Sum(E)
  double sumEHF_plus = 0.;
  double sumEHF_minus = 0.;
  double sumEHE_plus = 0.;
  double sumEHE_minus = 0.;
  double sumEHB_plus = 0.;
  double sumEHB_minus = 0.;
  double sumEEE_plus = 0.;
  double sumEEE_minus = 0.;
  double sumEEB_plus = 0.;
  double sumEEB_minus = 0.;
  // Sum(ET)
  double sumETHF_plus = 0.;
  double sumETHF_minus = 0.;
  double sumETHE_plus = 0.;
  double sumETHE_minus = 0.;
  double sumETHB_plus = 0.;
  double sumETHB_minus = 0.;
  double sumETEE_plus = 0.;
  double sumETEE_minus = 0.;
  double sumETEB_plus = 0.;
  double sumETEB_minus = 0.;

  FwdGap.Reset();

  // Calo tower collection from event
  edm::Handle<CaloTowerCollection> towerCollectionH;
  iEvent.getByLabel(caloTowerTag_,towerCollectionH);
  const CaloTowerCollection& towerCollection = *towerCollectionH;

  // Loop over calo towers
  CaloTowerCollection::const_iterator calotower = towerCollection.begin();
  CaloTowerCollection::const_iterator calotowers_end = towerCollection.end();
  for(; calotower != calotowers_end; ++calotower) {
     bool hasHCAL = false;
     bool hasHF = false;
     bool hasHE = false;
     bool hasHB = false;
     bool hasHO = false;
     bool hasECAL = false;
     bool hasEE = false;
     bool hasEB = false;     
     for(size_t iconst = 0; iconst < calotower->constituentsSize(); iconst++){
        DetId detId = calotower->constituent(iconst);
        if(detId.det()==DetId::Hcal){
           hasHCAL = true;
           HcalDetId hcalDetId(detId);
           if(hcalDetId.subdet()==HcalForward) hasHF = true;
           else if(hcalDetId.subdet()==HcalEndcap) hasHE = true;
           else if(hcalDetId.subdet()==HcalBarrel) hasHB = true;
           else if(hcalDetId.subdet()==HcalOuter) hasHO = true;  
        } else if(detId.det()==DetId::Ecal){
           hasECAL = true;
           EcalSubdetector ecalSubDet = (EcalSubdetector)detId.subdetId();
           if(ecalSubDet == EcalEndcap) hasEE = true;
           else if(ecalSubDet == EcalBarrel) hasEB = true;
        }
     }

     int zside = calotower->zside();
     double caloTowerEnergy = calotower->energy();
     // FIXME
     //double caloTowerET = calotower->et(primVtx.position());
     //double caloTowerET = calotower->et(primVtx.z());
     double caloTowerET = calotower->et();

     // HCAL: Towers made of at least one component from HB,HE,HF
     if( hasHF && !hasHE ){
        if( caloTowerEnergy >= energyThresholdHF_ ){
           if(zside >= 0){
              ++nTowersHF_plus;
              sumEHF_plus += caloTowerEnergy; 
              sumETHF_plus += caloTowerET;
           } else{
              ++nTowersHF_minus;
              sumEHF_minus += caloTowerEnergy;
              sumETHF_minus += caloTowerET;
           } 
        }
     } else if( hasHE && !hasHF && !hasHB ){
        if( caloTowerEnergy >= energyThresholdHE_ ){
           if(zside >= 0){
              ++nTowersHE_plus;
              sumEHE_plus += caloTowerEnergy;
              sumETHE_plus += caloTowerET;
           } else{
              ++nTowersHE_minus;
              sumEHE_minus += caloTowerEnergy;
              sumETHE_minus += caloTowerET;
           }
        }
     } else if( hasHB && !hasHE ){
        if( caloTowerEnergy >= energyThresholdHB_ ){
           if(zside >= 0){
              ++nTowersHB_plus;
              sumEHB_plus += caloTowerEnergy;
              sumETHB_plus += caloTowerET;
           } else{
              ++nTowersHB_minus;
              sumEHB_minus += caloTowerEnergy;
              sumETHB_minus += caloTowerET;
           }
        }
     }

     // ECAL: Towers made of at least one component from EB,EE
     if( hasEE && !hasEB ){
        if( caloTowerEnergy >= energyThresholdEE_ ){
           if(zside >= 0){
              ++nTowersEE_plus;
              sumEEE_plus += caloTowerEnergy;
              sumETEE_plus += caloTowerET;
           } else{
              ++nTowersEE_minus;
              sumEEE_minus += caloTowerEnergy;
              sumETEE_minus += caloTowerET;
           }
        }
     } else if( hasEB && !hasEE ){
        if( caloTowerEnergy >= energyThresholdEB_ ){
           if(zside >= 0){
              ++nTowersEB_plus;
              sumEEB_plus += caloTowerEnergy;
              sumETEB_plus += caloTowerET;
           } else{
              ++nTowersEB_minus;
              sumEEB_minus += caloTowerEnergy;
              sumETEB_minus += caloTowerET;
           }
        }
     }
  }

   FwdGap.nTowersHF_plus = nTowersHF_plus ;
   FwdGap.nTowersHF_minus = nTowersHF_minus ;
   FwdGap.nTowersHE_plus = nTowersHE_plus ;
   FwdGap.nTowersHE_minus = nTowersHE_minus ;
   FwdGap.nTowersHB_plus = nTowersHB_plus ;
   FwdGap.nTowersHB_minus = nTowersHB_minus ;
   FwdGap.nTowersEE_plus = nTowersEE_plus ;
   FwdGap.nTowersEE_minus = nTowersEE_minus ;
   FwdGap.nTowersEB_plus = nTowersEB_plus ;
   FwdGap.nTowersEB_minus = nTowersEB_minus ;
   FwdGap.sumEHF_plus = sumEHF_plus ;
   FwdGap.sumEHF_minus = sumEHF_minus ;
   FwdGap.sumEHE_plus = sumEHE_plus ;
   FwdGap.sumEHE_minus = sumEHE_minus ;
   FwdGap.sumEHB_plus = sumEHB_plus ;
   FwdGap.sumEHB_minus = sumEHB_minus ;
   FwdGap.sumEEE_plus = sumEEE_plus ;
   FwdGap.sumEEE_minus = sumEEE_minus ;
   FwdGap.sumEEB_plus = sumEEB_plus ;
   FwdGap.sumEEB_minus = sumEEB_minus ;
   FwdGap.sumETHF_plus = sumETHF_plus ;
   FwdGap.sumETHF_minus = sumETHF_minus ;
   FwdGap.sumETHE_plus = sumETHE_plus ;
   FwdGap.sumETHE_minus = sumETHE_minus ;
   FwdGap.sumETHB_plus = sumETHB_plus ;
   FwdGap.sumETHB_minus = sumETHB_minus ;
   FwdGap.sumETEE_plus = sumETEE_plus ;
   FwdGap.sumETEE_minus = sumETEE_minus ;
   FwdGap.sumETEB_plus = sumETEB_plus ;
   FwdGap.sumETEB_minus = sumETEB_minus ;


/*
   cout << "[FwdGap]: " << sumEHF_plus << " " << sumEHF_minus << " " 
                        << sumEHE_plus << " " << sumEHE_minus << " "
                        << sumEHB_plus << " " << sumEHB_minus << " "
                        << sumEEE_plus << " " << sumEEE_minus << " "
                        << sumEEB_plus << " " << sumEEB_minus << " " << endl ;
*/
}