Exemplo n.º 1
0
void IsoMuonProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup){
  auto mu_pt = make_auto(new std::vector<float>);
  auto mu_phi = make_auto(new std::vector<float>);
  auto mu_eta = make_auto(new std::vector<float>);
  auto mu_iso = make_auto(new std::vector<float>);
  
  edm::Handle<edm::ValueMap<double> > iso_handle;
  edm::Handle<std::vector<reco::RecoChargedCandidate> > muon_handle;
  iEvent.getByToken(iso_token_, iso_handle);
  iEvent.getByToken(cand_token_, muon_handle);
  
  for(auto it = iso_handle->begin(); it != iso_handle->end(); ++it){
    for(auto ite = it.begin(); ite != it.end(); ++ite){
      mu_iso->push_back(*ite);
    }
  }
  
  for(auto it = muon_handle->begin(); it != muon_handle->end(); ++it){
    mu_pt->push_back(it->pt());
    mu_phi->push_back(it->phi());
    mu_eta->push_back(it->eta());
  }

  iEvent.put(mu_pt, "mupt");
  iEvent.put(mu_phi, "muphi");
  iEvent.put(mu_eta, "mueta");
  iEvent.put(mu_iso, "muiso");
}
Exemplo n.º 2
0
void GlobalPositionRcdScan::analyze(const edm::Event& evt, const edm::EventSetup& evtSetup)
{
  lastRun_ = evt.run();
  if (0 == firstRun_) firstRun_ = lastRun_;

  if (watcher_.check(evtSetup)) {
  
    edm::ESHandle<Alignments> globalPositionRcd;
    evtSetup.get<GlobalPositionRcd>().get(globalPositionRcd);

    std::cout << "=====================================================\n" 
	      << "GlobalPositionRcd content starting from run " << evt.run() << ":" << std::endl;
  
    for (std::vector<AlignTransform>::const_iterator i = globalPositionRcd->m_align.begin();
	 i != globalPositionRcd->m_align.end();  ++i) {
      std::cout << "  Component ";
      if (i->rawId() == DetId(DetId::Tracker).rawId()) {
	std::cout << "Tracker";
      }
      else if (i->rawId() == DetId(DetId::Muon).rawId()) {
	std::cout << "Muon   ";
      }
      else if (i->rawId() == DetId(DetId::Ecal).rawId()) {
	std::cout << "Ecal   ";
      }
      else if (i->rawId() == DetId(DetId::Hcal).rawId()) {
	std::cout << "Hcal   ";
      }
      else if (i->rawId() == DetId(DetId::Calo).rawId()) {
	std::cout << "Calo   ";
      }
      else {
	std::cout << "Unknown";
      }
      std::cout << " entry " << i->rawId() 
		<< "\n     translation " << i->translation() << "\n";
      const AlignTransform::Rotation hepRot(i->rotation());
      if (eulerAngles_) {
	std::cout << "     euler angles " << hepRot.eulerAngles() << std::endl;
      }
      if (alignAngles_) {
	const align::RotationType matrix(hepRot.xx(), hepRot.xy(), hepRot.xz(),
					 hepRot.yx(), hepRot.yy(), hepRot.yz(),
					 hepRot.zx(), hepRot.zy(), hepRot.zz());
	const AlgebraicVector angles(align::toAngles(matrix));
	std::cout << "     alpha, beta, gamma (" << angles[0] << ", " << angles[1] << ", "
		  << angles[2] << ')' << std::endl;
      }
      if (matrix_) {
	std::cout << "     rotation matrix " << hepRot << std::endl;
      }
    }
  }
}
 void 
 SleepingProducer::produce(edm::Event& iEvent) {
   //printf("Producer %s\n",label().c_str());
   int sum=0;
   for(std::vector<const Getter*>::iterator it = m_getters.begin(), itEnd=m_getters.end();
       it != itEnd;
       ++it) {
     sum +=iEvent.get(*it);
     //printf("%s got %s with value %i\n",label().c_str(), (*it)->label().c_str(), iEvent.get((*it)));
   }
   wait(iEvent);
   iEvent.put(this,"",static_cast<int>(sum));
 }
Exemplo n.º 4
0
int NeroAll::analyze(const edm::Event&iEvent)
{
    if(isMc_ <0 )
    {
        isMc_ = ( iEvent.isRealData() ) ? 0 : 1;
        isRealData = ( iEvent.isRealData() ) ? 1 : 0;
    }
    if( isSkim() == 0) 
    {
        //TODO FILL all_
        isRealData = ( iEvent.isRealData() ) ? 1 : 0;	
        runNum = iEvent.id().run();
        lumiNum = iEvent.luminosityBlock(); 	
        eventNum = iEvent.id().event();  
        iEvent.getByLabel(edm::InputTag("generator"), info_handle); // USE TOKEN AND INPUT TAG ?
        iEvent.getByLabel(edm::InputTag("addPileupInfo"), pu_handle);
        mcWeight = info_handle->weight();
        //PU
        puTrueInt = 0;
        for(const auto & pu : *pu_handle)
        {
            //Intime
            if (pu.getBunchCrossing() == 0)
                puTrueInt += pu.getTrueNumInteractions();
            //Out-of-time
        }
    }
    return 0;
}
 bool 
 EventTimesPassFilterBase::filter(const edm::Event& iEvent) {
   //printf("Producer %s\n",label().c_str());
   int sum=0;
   for(std::vector<const Getter*>::iterator it = m_getters.begin(), itEnd=m_getters.end();
       it != itEnd;
       ++it) {
     sum +=iEvent.get(*it);
     //printf("%s got %s with value %i\n",label().c_str(), (*it)->label().c_str(), iEvent.get((*it)));
   }
   unsigned long index = iEvent.index() % m_eventTimes.size();
   
   wait(m_eventTimes[index]);
   return true;
 }
Exemplo n.º 6
0
int NeroPF::analyze(const edm::Event& iEvent)
{
	
    	iEvent.getByToken( token , handle);
        if ( not handle.isValid() ) cout<<"[NeroPF]::[analyze]::[ERROR] handle is not valid"<<endl;
	return 0;
}
Exemplo n.º 7
0
void UAHiggsTree::GetGenMET(const edm::Event& iEvent , const edm::EventSetup& iSetup,
                            const string GenMETCollection_ , vector<MyGenMET>& METVector )
{
   using namespace std;
   using namespace edm;
   using namespace reco;

   METVector.clear();
  
   Handle<GenMETCollection> met;
   iEvent.getByLabel(GenMETCollection_, met);

   for(reco::GenMETCollection::const_iterator met_iter=met->begin(); 
      met_iter != met->end(); met_iter++)
    {
      
      MyGenMET mymet;
     
      mymet.pt=met_iter->pt();
      mymet.phi=met_iter->phi();
      mymet.eta=met_iter->eta();
      
      
      METVector.push_back(mymet);
         

    } 

}
Exemplo n.º 8
0
EventInfo::EventInfo(const edm::Event& iEvent, const edm::Handle<reco::BeamSpot>& beamSpot, const edm::Handle<HcalNoiseSummary>& hcalNoiseSummary, const edm::Handle< std::vector<PileupSummaryInfo> >& puSummaryInfo, bool firstVertexIsGood_, float rho_):firstVertexIsGood(firstVertexIsGood_),rho(rho_)
{
  
  evt         = iEvent.id().event();
  run         = iEvent.id().run();
  lumiBlock   = iEvent.luminosityBlock();
  
  BSx = beamSpot->x0();
  BSy = beamSpot->y0();
  BSz = beamSpot->z0();
  
 
  if( hcalNoiseSummary.isValid() ){
    hcalnoiseLoose = hcalNoiseSummary->passLooseNoiseFilter();
    hcalnoiseTight = hcalNoiseSummary->passTightNoiseFilter();
  }
  
  if( puSummaryInfo.isValid() ){
    for(std::vector<PileupSummaryInfo>::const_iterator PVI = puSummaryInfo->begin(); PVI != puSummaryInfo->end(); ++PVI) {

      int BX = PVI->getBunchCrossing();

      sumNVtx  += float(PVI->getPU_NumInteractions());
      sumTrueNVtx += float(PVI->getTrueNumInteractions());

      if( BX==0 ){
	      numGenPV = PVI->getPU_NumInteractions();
	      numTruePV = PVI->getTrueNumInteractions();
      }

      if(BX == -1) { 
	      nm1 = PVI->getPU_NumInteractions();
	      nm1_true = PVI->getTrueNumInteractions();
      }
      else if(BX == 0) { 
	      n0 = PVI->getPU_NumInteractions();
	      n0_true = PVI->getTrueNumInteractions();
      }
      else if(BX == 1) { 
	      np1 = PVI->getPU_NumInteractions();
	      np1_true = PVI->getTrueNumInteractions();
      }
    }
  }
    
  
}
Exemplo n.º 9
0
 bool 
 SleepingPassFilter::filter(const edm::Event& iEvent) {
   //printf("Producer %s\n",label().c_str());
   int sum=0;
   for(std::vector<const Getter*>::iterator it = m_getters.begin(), itEnd=m_getters.end();
       it != itEnd;
       ++it) {
     sum +=iEvent.get(*it);
     //printf("%s got %s with value %i\n",label().c_str(), (*it)->label().c_str(), iEvent.get((*it)));
   }
   wait(iEvent);
   return true;
 }
Exemplo n.º 10
0
int NeroPuppiJets::analyze(const edm::Event& iEvent, const edm::EventSetup &iSetup){

    if ( mOnlyMc  ) return 0;

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);

    if ( not handle.isValid() ) cout<<"[NeroPuppiJets]::[analyze]::[ERROR] handle is not valid"<<endl;

    for (const pat::Jet& j : *handle)
    {

        if (j.pt() < mMinPt ) continue;
        if ( fabs(j.eta()) > mMinEta ) continue;
        if ( !JetId(j,mMinId) ) continue;


        float charge =  0.;
        float charge_den = 0.;

        for( size_t idx =0; idx < j.numberOfDaughters() ; ++idx)
        {
            pat::PackedCandidate *cand = ( pat::PackedCandidate* ) j.daughter(idx) ; 
            if (cand->charge() !=0 ) {  
                charge     += cand->charge() * cand->puppiWeight() * ( j.px()*cand->px() + j.py()*cand->py() + j.pz()*cand->pz()  ) ;
                charge_den +=                  cand->puppiWeight() * ( j.px()*cand->px() + j.py()*cand->py() + j.pz()*cand->pz()  ) ;
            }
        }

        if ( charge_den == 0 ) { charge=0.0 ; charge_den =1.0;}  //  guard, if no jet id

        // Fill output object	
        new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(j.px(), j.py(), j.pz(), j.energy());
        rawPt  -> push_back (j.pt()*j.jecFactor("Uncorrected"));
        bDiscr -> push_back( j.bDiscriminator("pfCombinedInclusiveSecondaryVertexV2BJetTags") );
        unsigned bits=0;
        bits |=  (1 * JetBaseline);
        bits |= JetId(j,"monojet") * mjId;
        bits |= JetId(j,"monojetloose") * mjIdLoose;
        bits |= JetId(j,"monojet2015") * mjId2015;
        bits |= JetId(j,"loose") * JetLoose;
        bits |= JetId(j,"tight") * JetTight;

        selBits -> push_back( bits);
        Q -> push_back (charge/charge_den);
    }

    if ( int(rawPt -> size()) < mMinNjets ) return 1;

    return 0;
}
Exemplo n.º 11
0
int NeroTaus::analyze(const edm::Event & iEvent)
{
    if ( mOnlyMc  ) return 0;

    iEvent.getByToken(token, handle);
    for (const pat::Tau &tau : *handle) {

        if (tau.pt() < 18 ) continue;	
        if (tau.pt() < mMinPt ) continue;	
        
        /// miniaod taus = decayModeFindingNewDMs
        if ( mMinId != "" and !(tau.tauID(mMinId)) ) continue; // minimum requirement to be saved.
        if ( mMaxIso >=0 and tau.tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits") >= mMaxIso ) continue;

        if ( fabs(tau.eta()) > mMinEta ) continue;
        
        // ------------ END SELECTION 

         float phoIso = 0.; for(auto cand : tau.isolationGammaCands() ) phoIso += cand->pt();//tau.isolationPFGammaCandsEtSum() ;
         float chIso  = 0.; for(auto cand : tau.isolationChargedHadrCands() ) chIso += cand->pt();//tau.isolationPFChargedHadrCandsPtSum();
         float nhIso  = 0.; for(auto cand : tau.isolationNeutrHadrCands() ) nhIso += cand->pt(); // PF Cands not exists in miniAOD
         float totIso = phoIso + chIso + nhIso;
        
        //FILL
        new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(tau.px(), tau.py(), tau.pz(), tau.energy());
        id -> push_back( tau.tauID("decayModeFinding"));
        Q -> push_back( tau.charge() );
        M -> push_back( tau.mass() );
        iso -> push_back( totIso ) ; 

        if (IsExtend() ){
            chargedIsoPtSum  -> push_back( tau.tauID("chargedIsoPtSum") );
            neutralIsoPtSum  -> push_back( tau.tauID("neutralIsoPtSum") );
            isoDeltaBetaCorr -> push_back( tau.tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits"));

            againstEleLoose  -> push_back( tau.tauID("againstElectronLooseMVA5") );
            againstEleMedium -> push_back( tau.tauID("againstElectronMediumMVA5") );
            
            againstMuLoose   -> push_back( tau.tauID("againstMuonLoose3"));
            againstMuTight   -> push_back( tau.tauID("againstMuonTight3"));
        }


    }
    if( int(id->size()) < mMinNtaus) return 1;
    return 0;
}
Exemplo n.º 12
0
int NeroFatJets::analyze(const edm::Event& iEvent){

	if ( mOnlyMc  ) return 0;

	// maybe handle should be taken before
	iEvent.getByToken(token, handle);

	int ijetRef = -1;
    int nsubjet = 0;
	for (const pat::Jet& j : *handle)
		{
		ijetRef++;
		if (j.pt() < 100 ) continue;

		// JET ID
		if ( !NeroJets::JetId(j,"loose") ) continue;
		
		// GET  ValueMaps
		
		// Fill output object	
		//p4 -> AddLast(new TLorentzVector(j.px(), j.py(), j.pz(), j.energy())  );
		new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(j.px(), j.py(), j.pz(), j.energy());

		rawPt -> push_back (j.pt()*j.jecFactor("Uncorrected"));
        	flavour -> push_back( j.partonFlavour() );
		tau1 -> push_back(j.userFloat("NjettinessAK8:tau1"));
		tau2 -> push_back(j.userFloat("NjettinessAK8:tau2"));
		tau3 -> push_back(j.userFloat("NjettinessAK8:tau3"));

		trimmedMass ->push_back(j.userFloat("ak8PFJetsCHSTrimmedMass"));
		prunedMass  ->push_back(j.userFloat("ak8PFJetsCHSPrunedMass"));
		filteredMass->push_back(j.userFloat("ak8PFJetsCHSFilteredMass"));
		softdropMass->push_back(j.userFloat("ak8PFJetsCHSSoftDropMass"));
        ak8jet_hasSubjet->push_back(j.hasSubjets("SoftDrop"));

        auto Subjets = j.subjets("SoftDrop");
        for ( auto const & i : Subjets ) {
            new ( (*ak8_subjet)[nsubjet]) TLorentzVector(i->px(), i->py(), i->pz(), i->energy());
            ak8subjet_btag->push_back(i->bDiscriminator("pfCombinedInclusiveSecondaryVertexV2BJetTags"));
            nsubjet++;
        }
        
		}
	return 0;
}
Exemplo n.º 13
0
int NeroPhotons::analyze(const edm::Event& iEvent){

    if ( mOnlyMc  ) return 0;

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);

    // ID and ISO
    iEvent.getByToken(loose_id_token,loose_id);
    iEvent.getByToken(medium_id_token,medium_id);
    iEvent.getByToken(tight_id_token,tight_id);
    iEvent.getByToken(iso_ch_token, iso_ch);
    iEvent.getByToken(iso_nh_token, iso_nh);
    iEvent.getByToken(iso_pho_token, iso_pho);

    int iPho = -1;	
    for (auto &pho : *handle)
    {
        ++iPho;

        if (pho.pt() <15 or pho.chargedHadronIso()/pho.pt() > 0.3) continue;		
        if (fabs(pho.eta()) > mMinEta ) continue;
        if (pho.pt() < mMinPt) continue;

        edm::RefToBase<pat::Photon> ref ( edm::Ref< pat::PhotonCollection >(handle, iPho) ) ;
        float chIso =  (*iso_ch) [ref];
        float nhIso =  (*iso_nh) [ref];
        float phIso =  (*iso_pho)[ref];	
        float totIso = chIso + nhIso + phIso;

        bool isPassLoose  = (*loose_id)[ref];	
        bool isPassMedium = (*medium_id)[ref];	
        bool isPassTight  = (*tight_id)[ref];	

        if (not isPassLoose) continue;
        if (mMaxIso >=0 and totIso > mMaxIso) continue;

        //FILL
        new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(pho.px(),pho.py(),pho.pz(),pho.energy());
        iso->push_back(totIso);	
        sieie -> push_back( pho. full5x5_sigmaIetaIeta() );


        tightid->push_back(isPassTight);
        mediumid->push_back(isPassMedium);
    }

    return 0;
}
Exemplo n.º 14
0
void ChPartTree::GetL1Trig(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
   using namespace std;

  // Tests
/*
  if (L1TrigDebug)
  {  
   edm::ESHandle<L1GtTriggerMenu> menuRcd;
   iSetup.get<L1GtTriggerMenuRcd>().get(menuRcd) ;
   const L1GtTriggerMenu* menu = menuRcd.product();

   for (CItAlgo algo = menu->gtAlgorithmMap().begin(); 
                algo!=menu->gtAlgorithmMap().end(); 
                ++algo) 
   {
     cout << "Name: " << (algo->second).algoName() 
          << " Alias: " << (algo->second).algoAlias() 
          << " Bit: " << (algo->second).algoBitNumber()
           << " Result: " << l1AlgorithmResult(iEvent, iSetup, (algo->second).algoName() )
          << std::endl;
   }
  }
*/

   edm::Handle<L1GlobalTriggerReadoutRecord> L1GTRR;
   iEvent.getByLabel("gtDigis",L1GTRR);
   for (int i=0 ; i <128 ; i++) 
   {
     if (L1TrigDebug) cout << "PhysicsTriggerWord :" << i << " " << L1GTRR->decisionWord()[i] << endl;
     L1Trig.PhysTrigWord[i] = L1GTRR->decisionWord()[i];
   }
   for (int i=0 ; i <64  ; i++)
   {
    if (L1TrigDebug) cout << "technicalTriggerWord :" << i << " " << L1GTRR->technicalTriggerWord()[i] << endl;
     L1Trig.TechTrigWord[i] = L1GTRR->technicalTriggerWord()[i]; 
   }
}
Exemplo n.º 15
0
int NeroTrigger::analyze(const edm::Event& iEvent){

	if ( mOnlyMc  ) return 0;

	iEvent.getByToken(token,handle);
	iEvent.getByToken(prescale_token,prescale_handle);

	 const pat::helper::TriggerMatchHelper matchHelper; 

	 triggerFired   ->resize( triggerNames->size(),0);
	 triggerPrescale->resize( triggerNames->size(),0);

	 const edm::TriggerNames &names = iEvent.triggerNames(*handle);

	 if ( handle.isValid() and not handle.failedToGet() ) {
		int ntrigs = (int)names.size();
		for (int i = 0; i < ntrigs; i++) {
			string name = names.triggerName(i);
			for(unsigned int j=0;j< triggerNames->size() ;++j) // destination loop
				{
				if (name.find( (*triggerNames)[j]) != string::npos)
					(*triggerFired)[j] = 1;
					(*triggerPrescale)[j] = prescale_handle -> getPrescaleForIndex(i) ;

				} // my trigger end
		} // trigger loop
	 	} // handle is valid

	 // ---- TRIGGER MATCHING ---
	 if (leps_ !=NULL) triggerLeps -> resize(leps_ -> p4 -> GetEntries()  ,0);
	 if (jets_ !=NULL) triggerJets -> resize(jets_ -> p4 -> GetEntries()  ,0);
	 if (taus_ !=NULL) triggerTaus -> resize(taus_ -> p4 -> GetEntries()  ,0);
	 if (photons_ !=NULL) triggerPhotons -> resize(photons_ -> p4 -> GetEntries()  ,0);
	

	 iEvent.getByToken(object_token,object_handle);
	 for (pat::TriggerObjectStandAlone obj : *object_handle) { 
		obj.unpackPathNames(names);

		bool isPhoton  =false;
		bool isElectron=false;
		bool isMuon    =false;
		bool isTau     =false;
		//bool isMet     =false;
		bool isJet     =false;
		bool isBJet    =false;

        	for (unsigned h = 0; h < obj.filterIds().size(); ++h)  // can be more than one
		{
			// HLT: DataFormats/HLTReco/interface/TriggerTypeDefs.h
			if      ( obj.filterIds()[h] == trigger::TriggerPhoton ) isPhoton=true;
			else if ( obj.filterIds()[h] == trigger::TriggerElectron) isElectron=true;
			else if ( obj.filterIds()[h] == trigger::TriggerMuon ) isMuon=true;
			else if ( obj.filterIds()[h] == trigger::TriggerTau ) isTau=true;
			else if ( obj.filterIds()[h] == trigger::TriggerJet ) isJet=true;
			else if ( obj.filterIds()[h] == trigger::TriggerBJet ) isBJet=true;
			//else if ( obj.filterIds()[h] == trigger::TriggerMET ) isMet=true;
		}
		std::vector<std::string> pathNamesAll  = obj.pathNames(false);
        std::vector<std::string> pathNamesLast = obj.pathNames(true);
            
		// match : if more than one ? best
		if(VERBOSE)cout<<"[NeroTrigger]::[analize] Matching"<<endl;

		int muonIndex = -1 ; if( isMuon ) muonIndex = match(leps_,obj,13);

		int eleIndex=-1 ; if (isElectron) eleIndex = match(leps_,obj,11);

		int jetIndex=-1; if (isJet or isBJet) jetIndex = match(jets_,obj);

		int tauIndex=-1; if(isTau) tauIndex = match(taus_,obj);

		int photonIndex=-1; if (isPhoton) photonIndex = match(photons_,obj);
		//
        // Print all trigger paths, for each one record also if the object is associated to a 'l3' filter (always true for the
        // definition used in the PAT trigger producer) and if it's associated to the last filter of a successfull path (which
        // means that this object did cause this trigger to succeed; however, it doesn't work on some multi-object triggers)
		if(VERBOSE)cout<<"[NeroTrigger]::[analize] Lopping on path names and filling"<<endl;
        	for (unsigned h = 0, n = pathNamesAll.size(); h < n; ++h) {
			if(VERBOSE)cout<<"[NeroTrigger]::[analize] pathNames h="<<h<<endl;
           		bool isBoth = obj.hasPathName( pathNamesAll[h], true, true ); 
           		bool isL3   = obj.hasPathName( pathNamesAll[h], false, true ); 
           		bool isLF   = obj.hasPathName( pathNamesAll[h], true, false ); 
           		bool isNone = obj.hasPathName( pathNamesAll[h], false, false ); 
            		//std::cout << "   " << pathNamesAll[h];
            		if (isNone && !isBoth && !isL3 && !isLF) continue;
			for ( unsigned i =0  ; i<triggerNames->size() ;++i)
				{
				if(VERBOSE)cout<<"[NeroTrigger]::[analize] triggerNames i="<<i<<endl;
				if (  pathNamesAll[h].find((*triggerNames)[i] ) !=string::npos )
					{
					if(VERBOSE) cout <<"Considering SUCCESS Path: eleIndex"<< eleIndex <<"/"<<triggerLeps->size()<<" :"<<pathNamesAll[h]<<" and Match string "<<(*triggerNames)[i]<<endl;
					if(VERBOSE)cout<<"[NeroTrigger]::[analize] ----- Mu "<<muonIndex<<endl;
					if (muonIndex >=0) (*triggerLeps)[muonIndex] |= 1<<i;
					if(VERBOSE)cout<<"[NeroTrigger]::[analize] ----- E "<<eleIndex<<endl;
					if (eleIndex >=0) (*triggerLeps)[eleIndex] |= 1<<i;
					if(VERBOSE)cout<<"[NeroTrigger]::[analize] ----- Tau "<<tauIndex <<endl;
					if (tauIndex >=0) (*triggerTaus)[tauIndex] |= 1<<i;
					if(VERBOSE)cout<<"[NeroTrigger]::[analize] ----- Jet "<< jetIndex<<endl;
					if (jetIndex >=0) (*triggerJets)[jetIndex] |= 1<<i;
					if(VERBOSE)cout<<"[NeroTrigger]::[analize] ----- Phot "<<photonIndex<<endl;
					if (photonIndex >=0) (*triggerPhotons)[photonIndex] |= 1<<i;
					if(VERBOSE)cout<<"[NeroTrigger]::[analize] ----------"<<endl;
					}
				} // end loop for in the trigger names I'm interested in
	    		} //end lop pathNames in trigg obj
	 } // end trigger objects loop
	if(VERBOSE)cout<<"[NeroTrigger]::[analize] === RETURN ==="<<endl;

	return 0;
}
Exemplo n.º 16
0
int NeroPhotons::analyze(const edm::Event& iEvent,const edm::EventSetup &iSetup){

    if ( mOnlyMc  ) return 0;

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);

    // ID and ISO
    iEvent.getByToken(loose_id_token,loose_id);
    iEvent.getByToken(medium_id_token,medium_id);
    iEvent.getByToken(tight_id_token,tight_id);
    iEvent.getByToken(iso_ch_token, iso_ch);
    iEvent.getByToken(iso_nh_token, iso_nh);
    iEvent.getByToken(iso_pho_token, iso_pho);

    if ( not handle.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] handle is not valid"<<endl;
    if ( not loose_id.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] loose_id is not valid"<<endl;
    if ( not medium_id.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] medium_id is not valid"<<endl;
    if ( not tight_id.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] tight_id is not valid"<<endl;
    if ( not iso_ch.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] iso_ch is not valid"<<endl;
    if ( not iso_nh.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] iso_nh is not valid"<<endl;
    if ( not iso_pho.isValid() ) cout<<"[NeroPhotons]::[analyze]::[ERROR] iso_pho is not valid"<<endl;

    int iPho = -1;	
    for (auto &pho : *handle)
    {
        ++iPho;
        #ifdef VERBOSE
        if (VERBOSE>0) cout<<"[NeroPhotons]::[analyze]::[DEBUG] analyzing photon"<<iPho<<" pt="<<pho.pt() <<" pz"<<pho.pz() <<endl;
        #endif

        //if ( not pho.passElectronVeto ()  ) continue;

        // r9()>0.8 , chargedHadronIso()<20, chargedHadronIso()<0.3*pt()
        if (pho.pt() <15 or pho.chargedHadronIso()/pho.pt() > 0.3) continue; // 10 -- 14  GeV photons are saved if chargedHadronIso()<10
        if (fabs(pho.eta()) > mMaxEta ) continue;
        if (pho.pt() < mMinPt) continue;

        #ifdef VERBOSE
        if (VERBOSE>1) cout<<"[NeroPhotons]::[analize]::[DEBUG2] photonInfo:" <<endl
            <<" \t pho.chargedHadronIso()/pho.pt() (0.3) "<<pho.chargedHadronIso()/pho.pt() <<endl
            <<" \t chargedHadronIso() (20) "<<pho.chargedHadronIso()<<endl
            <<" \t r9 (0.8) "<<pho.r9()<<endl
            <<" \t SC is non null? "<< pho.superCluster().isNonnull()<<endl
            <<endl;
        #endif

        edm::RefToBase<pat::Photon> ref ( edm::Ref< pat::PhotonCollection >(handle, iPho) ) ;
        float _chIso_ =  (*iso_ch) [ref];
        float _nhIso_ =  (*iso_nh) [ref];
        float _phIso_ =  (*iso_pho)[ref];	
        float _puIso_ =  pho.puChargedHadronIso() ;  // the other are eff area corrected, no need for this correction
        float totIso = _chIso_ + _nhIso_ + _phIso_;

        bool isPassLoose  = (*loose_id)[ref];	
        bool isPassMedium = (*medium_id)[ref];	
        bool isPassTight  = (*tight_id)[ref];	
        bool isPassVLoose50 = cutBasedPhotonId( pho, "loose_50ns", false, false); // no pho iso , no sieie
        bool isPassVLoose25 = cutBasedPhotonId( pho, "loose_25ns", false, false); // no pho iso , no sieie

        //if (not isPassVLoose) continue;
        if (mMaxIso >=0 and totIso > mMaxIso) continue;

        unsigned bits=0;

        bits |= isPassTight * PhoTight;
        bits |= isPassMedium * PhoMedium;
        bits |= isPassLoose * PhoLoose;
        bits |= isPassVLoose50 * PhoVLoose50;
        bits |= isPassVLoose25 * PhoVLoose25;

        if (not bits) continue; // even if there is some misalignment ntuples will not be corrupted

        bits |= pho.passElectronVeto() * PhoElectronVeto;

        // RC -- with FPR
        //
        float _chIsoRC_ = 0;
        float _nhIsoRC_ = 0;
        float _phIsoRC_ = 0;
        float _puIsoRC_ = 0;// not fill for the moment in the FPR TODO
        
        if (  pho.chargedHadronIso()< 20 )
        {
                                        //<<" \t r9 (0.8) "<<pho.r9()<<endl
        #ifdef VERBOSE
            if (VERBOSE >0 ) cout <<"[NeroPhotons]::[analyze]::[DEBUG] FPR START"<<endl;
        #endif

        fpr -> Config(iSetup);
        fpr -> SetHandles(
                pf  -> handle,
                handle,
                jets-> handle,
                leps->mu_handle,
                leps->el_handle
                );

        PFIsolation_struct FPR_out = fpr -> PFIsolation(pho.superCluster(), edm::Ptr<reco::Vertex>(vtx->handle,vtx->firstGoodVertexIdx) );
        _chIsoRC_ = FPR_out.chargediso_primvtx_rcone;
        _nhIsoRC_ = FPR_out.neutraliso_rcone;
        _phIsoRC_ = FPR_out.photoniso_rcone;

        #ifdef VERBOSE
            if (VERBOSE >0 ) cout <<"[NeroPhotons]::[analyze]::[DEBUG] FPR END"<<endl;
        #endif
        } else {
             _chIsoRC_ = -999.;
             _nhIsoRC_ = -999.;
             _phIsoRC_ = -999.;
             _puIsoRC_ = -999.;// not fill for the moment in the FPR TODO
        }

        // RC -- without FPR
        // allowed dphi
        // -- float dphis[] = { 0.5 * 3.14159 , -.5 *3.14159, 0.25*3.14150 , -0.25*3.14159, 0.75*3.14159,-0.75*3.14159} ;

        // -- float DR=0.3; // close obj
        // -- float DRCone=0.3; // default value for iso https://twiki.cern.ch/twiki/bin/view/CMS/EgammaPFBasedIsolationRun2

        // -- float dphi = -100;

        // -- //select dphi
        // -- for(unsigned i =0 ;i< sizeof(dphis)/sizeof(float) ;++i)
        // -- {
        // --     float dphi_cand = dphis[i];
        // --     bool close_obj = false;
        // --     for(auto &j : *jets->handle) 
        // --     {
        // --         if (j.pt() <20 or j.eta() >2.5) continue; // it's own set of jets
        // --         TLorentzVector v1,v2;
        // --         v1.SetPtEtaPhiM( pho.pt(),pho.eta(),pho.phi() + dphi_cand,0 ) ;
        // --         v2.SetPtEtaPhiM( j.pt(),j.eta(),j.phi(),j.mass() );
        // --         if (v1.DeltaR(v2) <DR ) close_obj = true; 
        // --     } 
        // --     if ( not close_obj ) 
        // --     {
        // --     dphi = dphi_cand;
        // --     break;
        // --     }
        // -- }

        // -- if (dphi <-99)
        // -- {
        // -- _chIsoRC_ = -1;
        // -- _nhIsoRC_ = -1;
        // -- _phIsoRC_ = -1;
        // -- _puIsoRC_ = -1;
        // -- }
        // -- else
        // -- {
        // --     for( auto &cand : *pf->handle )
        // --     {
        // --         TLorentzVector v1,v2;
        // --         v1.SetPtEtaPhiM( pho.pt(),pho.eta(),pho.phi() + dphi,0 ) ;
        // --         v2.SetPtEtaPhiM( cand.pt(),cand.eta(),cand.phi(),cand.mass() );
        // --         if (v1.DeltaR(v2) < DRCone )
        // --         {
        // --              // TO BE CHECKED !!! TODO FIXME
        // --         if (cand.charge() != 0  and abs(cand.pdgId())>20 and  fabs( cand.dz() ) <=0.1 and cand.fromPV()>1 and cand.trackHighPurity() ) _chIsoRC_ += cand.pt();
        // --         if (cand.charge() == 0 and cand.pdgId() == 22 ) _phIsoRC_ += cand.pt();
        // --         if (cand.charge() == 0 and cand.pdgId() != 22 ) _nhIsoRC_ += cand.pt();
        // --         if (cand.charge() != 0 and abs(cand.pdgId() )>20 and ( 
        // --                     fabs( cand.dz() ) >0.1  or cand.fromPV()<=1 or not cand.trackHighPurity() 
        // --                     ) ) _puIsoRC_ += cand.pt(); 
        // --         }

        // --     }
        // -- }
    
        //FILL
        new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(pho.px(),pho.py(),pho.pz(),pho.energy());
        iso->push_back(totIso);	
        sieie -> push_back( pho. full5x5_sigmaIetaIeta() );

        selBits -> push_back( bits);

        chIso -> push_back( _chIso_);
        phoIso -> push_back( _phIso_ ) ;
        nhIso -> push_back ( _nhIso_ ) ;
        puIso -> push_back ( _puIso_ ) ;

        chIsoRC -> push_back( _chIsoRC_);
        phoIsoRC -> push_back( _phIsoRC_ ) ;
        nhIsoRC -> push_back ( _nhIsoRC_ ) ;
        puIsoRC -> push_back ( _puIsoRC_ ) ;
    }
   
    if ( int(selBits -> size()) < mMinNpho  ) return 1;

    return 0;
}
Exemplo n.º 17
0
void AlignmentRcdScan::inspectRecord(const std::string & rcdname,
				     const edm::Event& evt, 
				     const edm::ESHandle<Alignments> & alignments)
{
  std::cout << rcdname << " content starting from run " << evt.run();
  
  if (verbose_==false) {
    std::cout << std::endl;
    return;
  }

  std::cout << " with " << alignments->m_align.size() << " entries" << std::endl;
  
  if (refAlignments_) {

    std::cout << "  Compared to previous record:" << std::endl;
    
    double meanX = 0;
    double rmsX = 0;
    double meanY = 0;
    double rmsY = 0;
    double meanZ = 0;
    double rmsZ = 0;
    double meanR = 0;
    double rmsR = 0;
    double dPhi;
    double meanPhi = 0;
    double rmsPhi = 0;
    
    std::vector<AlignTransform>::const_iterator iref = refAlignments_->m_align.begin();
    for (std::vector<AlignTransform>::const_iterator i = alignments->m_align.begin();
	 i != alignments->m_align.end();
	 ++i, ++iref) {
      
      meanX += i->translation().x() - iref->translation().x();
      rmsX += pow(i->translation().x() - iref->translation().x(), 2);
 
      meanY += i->translation().y() - iref->translation().y();
      rmsY += pow(i->translation().y() - iref->translation().y(), 2);
      
      meanZ += i->translation().z() - iref->translation().z();
      rmsZ += pow(i->translation().z() - iref->translation().z(), 2);
      
      meanR += i->translation().perp() - iref->translation().perp();
      rmsR += pow(i->translation().perp() - iref->translation().perp(), 2);

      dPhi = i->translation().phi() - iref->translation().phi();
      if (dPhi>TMath::Pi()) dPhi -= 2.0*TMath::Pi();
      if (dPhi<-TMath::Pi()) dPhi += 2.0*TMath::Pi();

      meanPhi += dPhi;
      rmsPhi += dPhi*dPhi;
    }

    meanX /= alignments->m_align.size();
    rmsX /= alignments->m_align.size();
    meanY /= alignments->m_align.size();
    rmsY /= alignments->m_align.size();
    meanZ /= alignments->m_align.size();
    rmsZ /= alignments->m_align.size();
    meanR /= alignments->m_align.size();
    rmsR /= alignments->m_align.size();
    meanPhi /= alignments->m_align.size();
    rmsPhi /= alignments->m_align.size();
    
    std::cout << "    mean X shift:   " 
	      << std::setw(12) << std::scientific << std::setprecision(3) << meanX
	      << " (RMS = " << sqrt(rmsX) << ")" << std::endl;
    std::cout << "    mean Y shift:   " 
	      << std::setw(12) << std::scientific << std::setprecision(3) << meanY
	      << " (RMS = " << sqrt(rmsY) << ")" << std::endl;
    std::cout << "    mean Z shift:   " 
	      << std::setw(12) << std::scientific << std::setprecision(3) << meanZ
	      << " (RMS = " << sqrt(rmsZ) << ")" << std::endl;
    std::cout << "    mean R shift:   " 
	      << std::setw(12) << std::scientific << std::setprecision(3) << meanR
	      << " (RMS = " << sqrt(rmsR) << ")" << std::endl;
    std::cout << "    mean Phi shift: " 
	      << std::setw(12) << std::scientific << std::setprecision(3) << meanPhi
	      << " (RMS = " << sqrt(rmsPhi) << ")" << std::endl;
    
    delete refAlignments_;
  }

  refAlignments_ = new Alignments(*alignments);

  std::cout << std::endl;
}
Exemplo n.º 18
0
void
TreeWriter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
   // get gen particles before photons for the truth match
   edm::Handle<edm::View<reco::GenParticle>> prunedGenParticles;
   iEvent.getByToken(prunedGenToken_,prunedGenParticles);

   edm::Handle<edm::ValueMap<bool>> loose_id_dec;
   edm::Handle<edm::ValueMap<bool>> medium_id_dec;
   edm::Handle<edm::ValueMap<bool>> tight_id_dec;
   edm::Handle<edm::ValueMap<float>> mva_value;
   edm::Handle<edm::ValueMap<vid::CutFlowResult>> loose_id_cutflow;
   iEvent.getByToken(photonLooseIdMapToken_, loose_id_dec);
   iEvent.getByToken(photonMediumIdMapToken_, medium_id_dec);
   iEvent.getByToken(photonTightIdMapToken_, tight_id_dec);
   iEvent.getByToken(photonMvaValuesMapToken_, mva_value);
   iEvent.getByToken(phoLooseIdFullInfoMapToken_, loose_id_cutflow);

   // photon collection
   edm::Handle<edm::View<pat::Photon>> photonColl;
   iEvent.getByToken(photonCollectionToken_, photonColl);

   for (edm::View<pat::Photon>::const_iterator pho = photonColl->begin(); pho != photonColl->end(); pho++) {
      // some basic selections
      if (pho->pt() < 15 || pho->hadTowOverEm() > 0.15) continue;
      const edm::Ptr<pat::Photon> phoPtr(photonColl, pho - photonColl->begin());

      pt = pho->pt();
      eta = pho->eta();
      sigmaIetaIeta=pho->full5x5_sigmaIetaIeta();
      hOverE=pho->hadTowOverEm() ;
      hasPixelSeed=pho->hasPixelSeed() ;
      passElectronVeto= pho->passElectronVeto() ;
      r9  = pho->r9();

      vid::CutFlowResult cutFlow = (*loose_id_cutflow)[phoPtr];
      cIso = cutFlow.getValueCutUpon(4);
      nIso = cutFlow.getValueCutUpon(5);
      pIso = cutFlow.getValueCutUpon(6);

      mvaValue = (*mva_value)    [phoPtr];
      isLoose  = (*loose_id_dec) [phoPtr];
      isMedium = (*medium_id_dec)[phoPtr];
      isTight  = (*tight_id_dec) [phoPtr];

      // mc matching
      bool foundPhoton = false;
      bool vetoPhoton = false;
      for (auto& genP: *prunedGenParticles) {
         if (fabs(genP.pdgId()) == 22
            && genP.statusFlags().fromHardProcess()
            && genP.status() == 1
            && ROOT::Math::VectorUtil::DeltaR(pho->p4(), genP.p4())<0.1) {
            foundPhoton = true;
         } else if (fabs(genP.pdgId()) == 22
            && ROOT::Math::VectorUtil::DeltaR(pho->p4(), genP.p4())<0.4) {
            vetoPhoton = true;
         }
      }
      if (foundPhoton) {
         isTrue = true;
         eventTree_->Fill();
      }
      if (!vetoPhoton) {
         isTrue = false;
         eventTree_->Fill();
      }

   }

   // Get the electron ID data from the event stream
   edm::Handle<edm::ValueMap<bool>> veto_id_decisions;
   edm::Handle<edm::ValueMap<bool>> loose_id_decisions;
   edm::Handle<edm::ValueMap<bool>> medium_id_decisions;
   edm::Handle<edm::ValueMap<bool>> tight_id_decisions;
   iEvent.getByToken(electronVetoIdMapToken_, veto_id_decisions);
   iEvent.getByToken(electronLooseIdMapToken_, loose_id_decisions);
   iEvent.getByToken(electronMediumIdMapToken_, medium_id_decisions);
   iEvent.getByToken(electronTightIdMapToken_, tight_id_decisions);

   edm::Handle<edm::View<pat::Electron>> electronColl;
   iEvent.getByToken(electronCollectionToken_, electronColl);

   for (edm::View<pat::Electron>::const_iterator el = electronColl->begin();el != electronColl->end(); el++) {
      const edm::Ptr<pat::Electron> elPtr (electronColl, el - electronColl->begin() );
      bool isLoose = (*loose_id_decisions) [elPtr];
      if (isLoose && false ) std::cout << el->pt() << std::endl;
   }
}
Exemplo n.º 19
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 ;
*/
}
Exemplo n.º 20
0
int NeroMonteCarlo::analyze(const edm::Event& iEvent){

    if ( iEvent.isRealData() ) return 0;
    isRealData = iEvent.isRealData() ? 1 : 0 ; // private, not the one in the tree

    TStopwatch sw;
    if(VERBOSE)sw.Start();
    // maybe handle should be taken before
    iEvent.getByToken(info_token, info_handle);
    iEvent.getByToken(packed_token, packed_handle);
    iEvent.getByToken(pruned_token, pruned_handle);
    iEvent.getByToken(pu_token, pu_handle);
    iEvent.getByToken(jet_token, jet_handle);

    if ( not info_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] info_handle is not valid"<<endl;
    if ( not packed_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] packed_handle is not valid"<<endl;
    if ( not pruned_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] pruned_handle is not valid"<<endl;
    if ( not pu_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] pu_handle is not valid"<<endl;
    if ( not jet_handle.isValid() ) cout<<"[NeroMonteCarlo]::[analyze]::[ERROR] jet_handle is not valid"<<endl;

    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] getToken took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // INFO
    if(VERBOSE>1) cout<<"[NeroMonteCarlo]::[analyze]::[DEBUG] mcWeight="<<endl;
    mcWeight = info_handle -> weight();
    if(VERBOSE>1) cout<<"                                     mcWeight="<<mcWeight<<endl;
    //weights() 
    //---  scale
    if ( info_handle -> weights()  .size() >= 9){
        r1f2 = info_handle -> weights() [1] ;   
        r1f5 = info_handle -> weights() [2] ;   
        r2f1 = info_handle -> weights() [3] ;   
        r2f2 = info_handle -> weights() [4] ;   
        r5f1 = info_handle -> weights() [6] ;    
        r5f5 = info_handle -> weights() [8] ;     
    }

    if (info_handle -> weights().size() > 109)
        for( int pdfw = 9 ; pdfw<109 ;++pdfw)
        {
        pdfRwgt -> push_back( info_handle -> weights() [pdfw] );    
        }
    // --- fill pdf Weights
    //
    if(VERBOSE>1) cout<<"[NeroMonteCarlo]::[analyze]::[DEBUG] PDF="<<endl;
    if ( mParticleGun ) {
        qScale   = -999 ;
        alphaQED = -999 ;
        alphaQCD = -999 ;
        x1       = -999 ;
        x2       = -999 ;
        pdf1Id   = -999 ;
        pdf2Id   = -999 ;
        scalePdf = -999 ;
    }
    else {
        qScale   = info_handle -> qScale();
        alphaQED = info_handle -> alphaQED();
        alphaQCD = info_handle -> alphaQCD();
        x1       = info_handle -> pdf() -> x.first;
        x2       = info_handle -> pdf() -> x.second;
        pdf1Id   = info_handle -> pdf() -> id.first;
        pdf2Id   = info_handle -> pdf() -> id.second;
        scalePdf = info_handle -> pdf() -> scalePDF;
    }
    if(VERBOSE>1) cout<<"                                     PDF="<<qScale<<" "<< alphaQED<<endl;

    //PU
    if(VERBOSE>1){ cout<<endl<<"[NeroMonteCarlo]::[analyze] PU LOOP"<<endl;}
    puTrueInt = 0;
    for(const auto & pu : *pu_handle)
    {
        //Intime
        if (pu.getBunchCrossing() == 0)
            puTrueInt += pu.getTrueNumInteractions();
        //puInt += getPU_NumInteractions(); //old
        //Out-of-time
    }

    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] pu&info took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // GEN PARTICLES
    //TLorentzVector genmet(0,0,0,0);
    //for ( auto & gen : *packed_handle)
    for ( unsigned int i=0;i < packed_handle->size() ;++i)
    {
        const auto gen  = & (*packed_handle)[i];
        if (gen->pt()  < 5 ) continue;
        if (gen->pt() < mMinGenParticlePt ) continue;
        int pdg = gen->pdgId();
        int apdg = abs(pdg);

        //neutrinos
        // --- if ( (apdg != 12 and apdg !=14 and apdg != 16
        // ---       and apdg > 1000000  neutrinos and neutralinos
        // ---      )//SUSY
        // ---         and fabs(gen->eta() ) <4.7 
        // ---    )
        // --- { 
        // ---     TLorentzVector tmp( gen->px(),gen->py(),gen->pz(),gen->energy() ); 
        // ---     genmet += tmp;
        // --- }
        // --- genmet = -genmet;


        //FILL
        //    e mu photons
        if ( apdg == 11 or apdg == 13 or apdg == 22  // e - mu - gamma
                or (apdg >=12 and apdg<=16) // neutrinos
                or apdg > 1000000  // susy neutrinos and neutralinos
            )
        {
            new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(gen->px(), gen->py(), gen->pz(), gen->energy());
            pdgId -> push_back( pdg );
            flags -> push_back( ComputeFlags( *gen ) );
            // compute ISOLATION
            float iso=0;
            float isoFx=0;

            if (apdg == 22 or apdg ==11 or apdg ==13)
            {

                    TLorentzVector g1(gen->px(),gen->py(),gen->pz(),gen->energy());
                    vector< pair<float,float> > inIsoFx ; //isoFx, dR, pT
                    for ( unsigned int j=0;j < packed_handle->size() ;++j)
                    {
                        if (i==j) continue;
                        const auto gen2  = & (*packed_handle)[j];
                        if ( gen2->pt() ==0 ) continue;
                        if (gen2->pz() > 10e8 ) continue; // inf
                        TLorentzVector g2(gen2->px(),gen2->py(),gen2->pz(),gen2->energy());
                        if (g2.DeltaR(g1) <0.4){
                            iso += g2.Pt();
                            // isoFx containes the epsilon 
                            inIsoFx.push_back( pair<float,float>(g2.DeltaR(g1) ,g2.Pt() ) );
                         }
                    }

                    if (apdg==22){ // ONLY for photon Frixione isolation
                        sort(inIsoFx.begin(), inIsoFx.end() );  // sort in DR, first entry

                        float sumEtFx=0;
                        for( const auto & p : inIsoFx )
                        {
                               const float& pt= p.second ;
                               const float& delta = p.first;
                               sumEtFx += pt / gen->pt(); // relative iso
                               if (delta == 0 ) continue; // guard
                               float isoCandidate = sumEtFx * TMath::Power(  (1. - TMath::Cos(0.4) ) / (1. - TMath::Cos(delta ) ), 2) ;// n=2
                               if (isoFx < isoCandidate) isoFx = isoCandidate;
                        }
                    }
            
            }
            genIso -> push_back(iso);
            genIsoFrixione -> push_back(isoFx);
            // computed dressed objects
            //

            if (apdg == 11 or apdg == 13) { // only for final state muons and electrons
                    TLorentzVector dressedLepton(gen->px(),gen->py(),gen->pz(),gen->energy());
                    TLorentzVector lepton(dressedLepton); //original lepton for dR
                    for ( unsigned int j=0;j < packed_handle->size() ;++j)
                    {
                        const auto gen2  = & (*packed_handle)[j];
                        TLorentzVector photon(gen2->px(),gen2->py(),gen2->pz(),gen2->energy());
                        if (i != j and abs( gen->pdgId() ) ==22  and lepton.DeltaR( photon ) <0.1 ) dressedLepton += photon;
                    }
                    new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( dressedLepton );
                    pdgId -> push_back( pdg );
                    flags -> push_back( Dressed );
                    genIso -> push_back (0.) ;
                    genIsoFrixione -> push_back (0.) ;
                    // --- end of dressing
            }
             
        }

    } //end packed


    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] packed took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // LOOP over PRUNED PARTICLES
    //for (auto & gen : *pruned_handle)
    for (unsigned int i=0;i<pruned_handle->size() ;++i)
    {
        const auto gen = &(*pruned_handle)[i];
        if (gen->pt()  < 5 ) continue;
        if (gen->pt()  < mMinGenParticlePt ) continue;
        int pdg = gen->pdgId();
        int apdg = abs(pdg);
        if (gen->status() == 1) continue; //packed

        unsigned flag = ComputeFlags(*gen);

    
        if ( apdg == 15 or  // tau (15)
                (apdg >= 23 and apdg <26 ) or   // Z(23) W(24) H(25)
                apdg == 37 or // chHiggs: H+(37)
                apdg <= 6 or // quarks up (2) down (1)  charm (4) strange (3) top (6) bottom (5)
                apdg == 21 or // gluons (21)
                apdg > 1000000 // susy neutrinos,neutralinos, charginos ...  lightest neutralinos (1000022)
                or ( apdg == 11 and  ( flag &  HardProcessBeforeFSR) )
                or ( apdg == 11 and  ( flag &  HardProcess) )
                or ( apdg == 13 and  ( flag &  HardProcessBeforeFSR) )
                or ( apdg == 13 and  ( flag &  HardProcess) )
                )
        {
            new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(gen->px(), gen->py(), gen->pz(), gen->energy());
            pdgId -> push_back( pdg );
            flags -> push_back( flag );
            genIso -> push_back (0.) ;
            genIsoFrixione -> push_back (0.) ;
        }
    }

    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] pruned took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset(); sw.Start();}
    // GEN JETS
    for (const auto & j : *jet_handle)
    {
        if (j.pt() < 20 ) continue;
        if (j.pt() < mMinGenJetPt ) continue;
        // --- FILL
        new ( (*jetP4)[jetP4->GetEntriesFast()]) TLorentzVector(j.px(), j.py(), j.pz(), j.energy());
    }
    if(VERBOSE){ sw.Stop() ; cout<<"[NeroMonteCarlo]::[analyze] jets took "<<sw.CpuTime()<<" Cpu and "<<sw.RealTime()<<" RealTime"<<endl; sw.Reset();}
    return 0;
}
Exemplo n.º 21
0
int NeroPuppiFatJets::analyze(const edm::Event& iEvent)
{

    if ( mOnlyMc  ) return 0;

    if ( mMinId == "none" ) return 0;

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);
    iEvent.getByToken(rho_token,rho_handle);
    
    TString tPrefix(cachedPrefix);

    edm::Handle<reco::PFJetCollection> subjets_handle;
    edm::InputTag subjetLabel("PFJetsSoftDrop"+tPrefix,"SubJets");
    //iEvent.getByLabel(subjetLabel,subjets_handle);
    iEvent.getByToken(subjets_token,subjets_handle);
    const reco::PFJetCollection *subjetCol = subjets_handle.product();
    assert(subjets_handle.isValid());

    edm::Handle<reco::JetTagCollection> btags_handle;
    //iEvent.getByLabel(edm::InputTag((tPrefix+"PFCombinedInclusiveSecondaryVertexV2BJetTags").Data()),btags_handle);
    iEvent.getByToken(btags_token,btags_handle);
    assert((btags_handle.isValid()));

    FactorizedJetCorrector *corrector = ( iEvent.isRealData() ) ? mDataJetCorrector : mMCJetCorrector;

    int ijetRef = -1;
    int nsubjet = 0;
    
          
    for (const pat::Jet& j : *handle)
    {
        ijetRef++;

        if (fabs(j.eta() ) > mMaxEta)  continue; 
        if ( !NeroPuppiJets::JetId(j,mMinId) ) continue;
        // pT cut applied after applying JEC if necessary

        // GET  ValueMaps

        // Fill output object   

          // this was reclustered from mini AOD, so we have to apply JEC, etc

          edm::RefToBase<pat::Jet> jetRef(edm::Ref<pat::JetCollection>(handle,ijetRef));

          double jecFactor=0;
          if (fabs(j.eta())<5.191) {
            corrector->setJetPt(j.pt());
            corrector->setJetEta(j.eta());
            corrector->setJetPhi(j.phi());
            corrector->setJetE(j.energy());
            corrector->setRho(*rho_handle);
            corrector->setJetA(j.jetArea());
            corrector->setJetEMF(-99.0);
            jecFactor = corrector->getCorrection();
          }

          if (j.pt()*jecFactor < mMinPt)  continue;
          rawPt -> push_back (j.pt());
          new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(j.px()*jecFactor, j.py()*jecFactor, j.pz()*jecFactor, j.energy()*jecFactor);

          tau1 -> push_back(j.userFloat(tPrefix+"Njettiness:tau1"));
          tau2 -> push_back(j.userFloat(tPrefix+"Njettiness:tau2"));
          tau3 -> push_back(j.userFloat(tPrefix+"Njettiness:tau3"));
  
          softdropMass->push_back(j.userFloat(tPrefix+"SDKinematics:Mass")*jecFactor);
    
          unsigned int nsubjetThisJet=0;
          firstSubjet->push_back(nsubjet);

          for (reco::PFJetCollection::const_iterator i = subjetCol->begin(); i!=subjetCol->end(); ++i) {
            if (reco::deltaR(i->eta(),i->phi(),j.eta(),j.phi())>jetRadius) continue;
            nsubjetThisJet++;
           
            new ( (*subjet)[nsubjet]) TLorentzVector(i->px(), i->py(), i->pz(), i->energy());
            nsubjet++;

            reco::JetBaseRef sjBaseRef(reco::PFJetRef(subjets_handle,i-subjetCol->begin()));
            subjet_btag->push_back((float)(*(btags_handle.product()))[sjBaseRef]);
          }

          nSubjets->push_back(nsubjetThisJet);

    }
    return 0;
}
Exemplo n.º 22
0
void UAHiggsTree::GetGenPart(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
   using namespace std;
   using namespace edm;
   using namespace reco;

   // Clear GenPart List
   // (evt->GenPart).clear();
   GenPart.clear();
   GenElec.clear();
   GenMu.clear();
   GenNu.clear();

   // Handle to access PDG data from iSetup
   ESHandle <ParticleDataTable> pdt;
   iSetup.getData( pdt );

   // Handle to access GenParticleCollection
   Handle<GenParticleCollection> genParticles;
   iEvent.getByLabel(genPartColl_, genParticles);
   if (!genParticles.isValid()) {
     cerr << "[UAHiggsTree::GetGenPart] Error: non valid GenParticleCollection " << endl;
     return;
   }

   // List for Daugther/Mother Search
   vector<const reco::Candidate *> cands;
   vector<const Candidate *>::const_iterator found = cands.begin();
   for(GenParticleCollection::const_iterator p = genParticles->begin();
     p != genParticles->end(); ++ p) {
     cands.push_back(&*p);
   }

   // Loop on generated particle and store if status=3
   if ( GenPartDebug )
     cout << "GenPart # : " << genParticles->size() << endl;
   
   for(GenParticleCollection::const_iterator p = genParticles->begin();
     p != genParticles->end(); ++ p) {
     int st = p->status();

       MyGenPart genpart;

      if ( GenPartDebug )
      {
       if(( fabs(p->pdgId())==11 || fabs(p->pdgId())== 13) && st==1) 
         cout    << p-genParticles->begin()
                 << " " << st  
                 << " " << p->pdgId()
                 << " " << (pdt->particle(p->pdgId()))->name()
                 << " " << p->pt()
                 << " " << p->eta()
                 << " " << p->phi()
                 << " " << p->charge()
                 << endl ;

       if(( fabs(p->pdgId())==11 || fabs(p->pdgId())== 13) && st==3)
         cout    << p-genParticles->begin()
                 << " " << st
                 << " " << p->pdgId()
                 << " " << (pdt->particle(p->pdgId()))->name()
                 << " " << p->pt()
                 << " " << p->eta()
                 << " " << p->phi()
                 << " " << p->charge()
                 << endl ;
       }

       // Four vector

       genpart.pt   = p->pt();
       genpart.eta  = p->eta();
       genpart.phi  = p->phi();
       genpart.e    = p->energy();
       genpart.px   = p->px();
       genpart.py   = p->py();
       genpart.pz   = p->pz();
       genpart.m    = p->mass();

       //genpart.v.SetPxPyPzE( p->px() , p->py() , p->pz() , p->energy() );
       genpart.Part.v.SetPxPyPzE( p->px() , p->py() , p->pz() , p->energy() );

       // Extra properties

       genpart.Part.charge  = p->charge();
       genpart.charge  = p->charge();
       genpart.pdgId   = p->pdgId();
       genpart.name    = (pdt->particle(p->pdgId()))->name();
       genpart.status  = p->status();

       // Mother Daughter relations

       int nMo = p->numberOfMothers();
       int nDa = p->numberOfDaughters();
       int iMo1 = -1 , iMo2 = -1 ; 
       int iDa1 = -1 , iDa2 = -1 ; 

       found = find(cands.begin(), cands.end(), p->mother(0));
       if(found != cands.end()) iMo1 = found - cands.begin() ;
 
       found = find(cands.begin(), cands.end(), p->mother(nMo-1));
       if(found != cands.end()) iMo2 = found - cands.begin() ;

       found = find(cands.begin(), cands.end(), p->daughter(0));
       if(found != cands.end()) iDa1 = found - cands.begin() ;
 
       found = find(cands.begin(), cands.end(), p->daughter(nDa-1));
       if(found != cands.end()) iDa2 = found - cands.begin() ;

       if ( GenPartDebug )
       {
         cout << "Mother : " << iMo1 << " " << iMo2 << endl;
         cout << "Daugther: " << iDa1 << " " << iDa2 << endl;
       }

       genpart.mo1     = iMo1 ;
       genpart.mo2     = iMo2 ;
       genpart.da1     = iDa1 ;
       genpart.da2     = iDa2 ;

       // Store




       if(st==3)
       GenPart.push_back(genpart);

       if(fabs(genpart.pdgId)==11 && st==1)
	 GenElec.push_back(genpart);

       if(fabs(genpart.pdgId)==13 && st==1)
	 GenMu.push_back(genpart);
     
       if((fabs(genpart.pdgId)==12 && st==1)||(fabs(genpart.pdgId)==14 && st==1))
	 GenNu.push_back(genpart);
   }

}
Exemplo n.º 23
0
int NeroTaus::analyze(const edm::Event & iEvent)
{
    if ( mOnlyMc  ) return 0;

    iEvent.getByToken(token, handle);
    if ( not handle.isValid() ) cout<<"[NeroTaus]::[analyze]::[ERROR] handle is not valid"<<endl;

    for (const pat::Tau &tau : *handle) {

        if (tau.pt() < 18 ) continue;
        if (tau.pt() < mMinPt ) continue;

        /// miniaod taus = decayModeFindingNewDMs
        if ( mMinId != "" and !(tau.tauID(mMinId)) ) continue; // minimum requirement to be saved.
        if ( mMaxIso >=0 and tau.tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits") >= mMaxIso ) continue;

        if ( fabs(tau.eta()) > mMinEta ) continue;

        // ------------ END SELECTION

        float phoIso = 0.;
        for(auto cand : tau.isolationGammaCands() ) phoIso += cand->pt();//tau.isolationPFGammaCandsEtSum() ;
        float chIso  = 0.;
        for(auto cand : tau.isolationChargedHadrCands() ) chIso += cand->pt();//tau.isolationPFChargedHadrCandsPtSum();
        float nhIso  = 0.;
        for(auto cand : tau.isolationNeutrHadrCands() ) nhIso += cand->pt(); // PF Cands not exists in miniAOD
        float totIso = phoIso + chIso + nhIso;

        //FILL
        new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector(tau.px(), tau.py(), tau.pz(), tau.energy());

        unsigned bits = 0;
        bits |= bool(tau.tauID("decayModeFindingNewDMs") ) * TauDecayModeFindingNewDMs;
        bits |= bool(tau.tauID("decayModeFinding") ) * TauDecayModeFinding;
        bits |= bool(tau.tauID("againstElectronLooseMVA6") )* AgainstEleLoose  ; // FIXME 76 MVA 6
        bits |= bool(tau.tauID("againstElectronMediumMVA6"))* AgainstEleMedium ;
        bits |= bool(tau.tauID("againstMuonLoose3"))        * AgainstMuLoose   ;
        bits |= bool(tau.tauID("againstMuonTight3"))        * AgainstMuTight   ;
        // old id the following only in 76 v2
        bits |= bool(tau.tauID("byLooseIsolationMVArun2v1DBoldDMwLT")) * byLooseIsolationMVArun2v1DBoldDMwLT;
        bits |= bool(tau.tauID("byMediumIsolationMVArun2v1DBoldDMwLT")) * byMediumIsolationMVArun2v1DBoldDMwLT;
        bits |= bool(tau.tauID("byTightIsolationMVArun2v1DBoldDMwLT")) * byTightIsolationMVArun2v1DBoldDMwLT;
        bits |= bool(tau.tauID("byVTightIsolationMVArun2v1DBoldDMwLT")) * byVTightIsolationMVArun2v1DBoldDMwLT;
        // new id
        bits |= bool(tau.tauID("byLooseIsolationMVArun2v1DBnewDMwLT")) * byLooseIsolationMVArun2v1DBnewDMwLT;
        bits |= bool(tau.tauID("byMediumIsolationMVArun2v1DBnewDMwLT")) * byMediumIsolationMVArun2v1DBnewDMwLT;
        bits |= bool(tau.tauID("byTightIsolationMVArun2v1DBnewDMwLT")) * byTightIsolationMVArun2v1DBnewDMwLT;
        bits |= bool(tau.tauID("byVTightIsolationMVArun2v1DBnewDMwLT")) * byVTightIsolationMVArun2v1DBnewDMwLT;
        // DB ISO WP
        bits |= bool(tau.tauID("byLooseCombinedIsolationDeltaBetaCorr3Hits")) * byLooseCombinedIsolationDeltaBetaCorr3Hits;
        bits |= bool(tau.tauID("byMediumCombinedIsolationDeltaBetaCorr3Hits")) * byMediumCombinedIsolationDeltaBetaCorr3Hits;
        bits |= bool(tau.tauID("byTightCombinedIsolationDeltaBetaCorr3Hits")) * byTightCombinedIsolationDeltaBetaCorr3Hits;

        switch (tau.decayMode() ) {
        case reco::PFTau::kOneProng0PiZero : {
            bits |= OneProng;
            bits |= ZeroPiZero;
            break;
        }
        case reco::PFTau::kOneProng1PiZero : {
            bits |= OneProng;
            bits |= OnePiZero;
            break;
        }
        case reco::PFTau::kOneProng2PiZero : {
            bits |= OneProng;
            bits |= TwoPiZero;
            break;
        }
        case reco::PFTau::kOneProng3PiZero : {
            bits |= OneProng;
            bits |= ThreePiZero;
            break;
        }
        case reco::PFTau::kOneProngNPiZero : {
            bits |= OneProng;
            bits |= ThreePiZero;
            break;
        }

        case reco::PFTau::kTwoProng0PiZero : {
            bits |= TwoProng;
            bits |= ZeroPiZero;
            break;
        }
        case reco::PFTau::kTwoProng1PiZero : {
            bits |= TwoProng;
            bits |= OnePiZero;
            break;
        }
        case reco::PFTau::kTwoProng2PiZero : {
            bits |= TwoProng;
            bits |= TwoPiZero;
            break;
        }
        case reco::PFTau::kTwoProng3PiZero : {
            bits |= TwoProng;
            bits |= ThreePiZero;
            break;
        }
        case reco::PFTau::kTwoProngNPiZero : {
            bits |= TwoProng;    // three or moreY
            bits |= ThreePiZero;
            break;
        }

        case reco::PFTau::kThreeProng0PiZero : {
            bits |= ThreeProng;
            bits |= ZeroPiZero;
            break;
        }
        case reco::PFTau::kThreeProng1PiZero : {
            bits |= ThreeProng;
            bits |= OnePiZero;
            break;
        }
        case reco::PFTau::kThreeProng2PiZero : {
            bits |= ThreeProng;
            bits |= TwoPiZero;
            break;
        }
        case reco::PFTau::kThreeProng3PiZero : {
            bits |= ThreeProng;
            bits |= ThreePiZero;
            break;
        }
        case reco::PFTau::kThreeProngNPiZero : {
            bits |= ThreeProng;    // three or moreY
            bits |= ThreePiZero;
            break;
        }

        case reco::PFTau::kNull : {
            break;
        }
        case reco::PFTau::kRareDecayMode : {
            break;
        }
        }

        selBits -> push_back(bits);
        Q -> push_back( tau.charge() );
        M -> push_back( tau.mass() );
        iso -> push_back( totIso ) ;

        if (IsExtend() ) {
            chargedIsoPtSum  -> push_back( tau.tauID("chargedIsoPtSum") );
            neutralIsoPtSum  -> push_back( tau.tauID("neutralIsoPtSum") );
            isoDeltaBetaCorr -> push_back( tau.tauID("byCombinedIsolationDeltaBetaCorrRaw3Hits"));
            //isoPileupWeightedRaw -> push_back( tau.tauID("byPileupWeightedIsolationRaw3Hits")); // not in 80X
            isoMva -> push_back(tau.tauID("byIsolationMVArun2v1DBnewDMwLTraw") );
        }


    }
    if( int(selBits->size()) < mMinNtaus) return 1;
    return 0;
}
Exemplo n.º 24
0
int NeroMet::analyze(const edm::Event& iEvent){

    if ( mOnlyMc  ) return 0; // in principle I would like to have the gen met: TODO

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);
    const pat::MET &met = handle->front();

    // FILL
    new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( met.px(),met.py(),met.pz(),met.energy()  );

    ptJESUP -> push_back( met.shiftedPt(pat::MET::JetEnUp) );
    ptJESDOWN -> push_back( met.shiftedPt(pat::MET::JetEnDown) );


    if (IsExtend())
    {
        //MetNoMu
        TLorentzVector metnomu(met.px(),met.py(),met.pz(),met.energy());
        TLorentzVector pfmet_e3p0(0,0,0,0);
        TLorentzVector chMet(0,0,0,0); 
        TLorentzVector nhMet(0,0,0,0); 
        TLorentzVector phoMet(0,0,0,0); 
        
    
        if ( pf == NULL ) cout<<"[NeroMet]::[analyze]::[ERROR] PF pointer is null. Run NeroPF. "<<endl; 
        
        for (unsigned int i = 0, n = pf->handle->size(); i < n; ++i) {
            const pat::PackedCandidate &cand = (*pf->handle)[i];
            
            // only up to eta 3
            if (std::abs(cand.eta()) < 3.0)
                pfmet_e3p0 += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
            
            if (std::abs(cand.pdgId()) == 13)
                metnomu += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());  
            
            // only charge hadrons
            if ( cand.charge() != 0 and cand.pdgId() > 20 )
                chMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
            if ( cand.charge() == 0 and cand.pdgId() == 22 ) 
                phoMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
            if ( cand.charge() == 0 and cand.pdgId() != 22 ) 
                nhMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
        }
        
        *metNoMu = TLorentzVector(metnomu);    
        *metChargedHadron = TLorentzVector(chMet);
        *metNeutralHadron = TLorentzVector(nhMet);
        *metNeutralEM = TLorentzVector(phoMet);
        *pfMet_e3p0 = TLorentzVector(pfmet_e3p0);
    
    }    
    // GEN INFO
    if ( not iEvent.isRealData () ){
        new ( (*genP4)[genP4->GetEntriesFast()]) TLorentzVector( met.genMET()->px(),met.genMET()->py(),met.genMET()->pz(),met.genMET()->energy()  );
    }


    return 0;
}
Exemplo n.º 25
0
void UAHiggsTree::GetRecoMuon(const edm::Event& iEvent, const edm::EventSetup& iSetup,
                                                       const string globalMuonCollection_, vector<MyMuon>& MuonVector )
{
   using namespace std;
   using namespace edm;
   using namespace reco;

   // BORIS 3D IP stuff: Declaration
   ESHandle<TransientTrackBuilder> theTTBuilder;
   iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",theTTBuilder);


   MuonVector.clear();

   Handle<MuonCollection> muonsHandle;
   try {
     iEvent.getByLabel(globalMuonCollection_,muonsHandle);
   } catch ( cms::Exception& ex ) {
    printf("Error! can't get globalMuon collection\n");
   }
   const MuonCollection & muons = *(muonsHandle.product());

   for (reco::MuonCollection::const_iterator iMuon = muons.begin(); 
        iMuon != muons.end(); iMuon++) {

     MyMuon muon;     
     
     // Global Muon
   
     muon.pt  = iMuon->pt(); 
     muon.px  = iMuon->px(); 
     muon.py  = iMuon->py(); 
     muon.pz  = iMuon->pz(); 
     muon.e   = sqrt(iMuon->momentum().mag2()+MASS_MU*MASS_MU); 
     muon.eta = iMuon->eta(); 
     muon.phi = iMuon->phi(); 
     
     
     muon.Part.v.SetPxPyPzE(iMuon->px(),
                            iMuon->py(),
                            iMuon->pz(), 
                            sqrt(iMuon->momentum().mag2()+MASS_MU*MASS_MU));
     muon.Part.charge = iMuon->charge();

     // Global Properties

     muon.nChambers             = iMuon -> numberOfChambers();
     muon.nChambersMatched      = iMuon -> numberOfMatches();
     
     muon.AllGlobalMuons                          =  muon::isGoodMuon(*iMuon,muon::AllGlobalMuons);
     muon.AllStandAloneMuons                      =  muon::isGoodMuon(*iMuon,muon::AllStandAloneMuons);
     muon.AllTrackerMuons                         =  muon::isGoodMuon(*iMuon,muon::AllTrackerMuons);
     muon.TrackerMuonArbitrated                   =  muon::isGoodMuon(*iMuon,muon::TrackerMuonArbitrated);
     muon.AllArbitrated                           =  muon::isGoodMuon(*iMuon,muon::AllArbitrated);
     muon.GlobalMuonPromptTight                   =  muon::isGoodMuon(*iMuon,muon::GlobalMuonPromptTight);
     muon.TMLastStationLoose                      =  muon::isGoodMuon(*iMuon,muon::TMLastStationLoose);
     muon.TMLastStationTight                      =  muon::isGoodMuon(*iMuon,muon::TMLastStationTight);
     muon.TM2DCompatibilityLoose                  =  muon::isGoodMuon(*iMuon,muon::TM2DCompatibilityLoose);
     muon.TM2DCompatibilityTight                  =  muon::isGoodMuon(*iMuon,muon::TM2DCompatibilityTight);
     muon.TMOneStationLoose                       =  muon::isGoodMuon(*iMuon,muon::TMOneStationLoose);
     muon.TMOneStationTight                       =  muon::isGoodMuon(*iMuon,muon::TMOneStationTight);
     muon.TMLastStationOptimizedLowPtLoose        =  muon::isGoodMuon(*iMuon,muon::TMLastStationOptimizedLowPtLoose);
     muon.TMLastStationOptimizedLowPtTight        =  muon::isGoodMuon(*iMuon,muon::TMLastStationOptimizedLowPtTight);
     muon.GMTkChiCompatibility                    =  muon::isGoodMuon(*iMuon,muon::GMTkChiCompatibility);
     muon.GMStaChiCompatibility                   =  muon::isGoodMuon(*iMuon,muon::GMStaChiCompatibility);
     muon.GMTkKinkTight                           =  muon::isGoodMuon(*iMuon,muon::GMTkKinkTight);
     muon.TMLastStationAngLoose                   =  muon::isGoodMuon(*iMuon,muon::TMLastStationAngLoose);
     muon.TMLastStationAngTight                   =  muon::isGoodMuon(*iMuon,muon::TMLastStationAngTight);
     muon.TMOneStationAngLoose                    =  muon::isGoodMuon(*iMuon,muon::TMOneStationAngLoose);
     muon.TMOneStationAngTight                    =  muon::isGoodMuon(*iMuon,muon::TMOneStationAngTight);
     muon.TMLastStationOptimizedBarrelLowPtLoose  =  muon::isGoodMuon(*iMuon,muon::TMLastStationOptimizedBarrelLowPtLoose);
     muon.TMLastStationOptimizedBarrelLowPtTight  =  muon::isGoodMuon(*iMuon,muon::TMLastStationOptimizedBarrelLowPtTight);
     
 
     muon.isoR03sumPt   = iMuon->isolationR03().sumPt   ;
     muon.isoR03emEt    = iMuon->isolationR03().emEt    ;
     muon.isoR03hadEt   = iMuon->isolationR03().hadEt   ;
     muon.isoR03hoEt    = iMuon->isolationR03().hoEt    ;
     muon.isoR03nTracks = iMuon->isolationR03().nTracks ;
     muon.isoR03nJets   = iMuon->isolationR03().nJets   ;

     muon.isoR05sumPt   = iMuon->isolationR05().sumPt   ;
     muon.isoR05emEt    = iMuon->isolationR05().emEt    ;
     muon.isoR05hadEt   = iMuon->isolationR05().hadEt   ;
     muon.isoR05hoEt    = iMuon->isolationR05().hoEt    ;
     muon.isoR05nTracks = iMuon->isolationR05().nTracks ;
     muon.isoR05nJets   = iMuon->isolationR05().nJets   ;

     muon.calEnergyEm   = iMuon->calEnergy().em   ; 
     muon.calEnergyHad  = iMuon->calEnergy().had  ;
     muon.calEnergyHo   = iMuon->calEnergy().ho   ;
     muon.calEnergyEmS9 = iMuon->calEnergy().emS9 ;
     muon.calEnergyHadS9= iMuon->calEnergy().hadS9;
     muon.calEnergyHoS9 = iMuon->calEnergy().hoS9 ;

     muon.IsGlobalMuon      = iMuon->isGlobalMuon()     ;
     muon.IsTrackerMuon     = iMuon->isTrackerMuon()    ;
     muon.IsStandaloneMuon  = iMuon->isStandAloneMuon() ;
     muon.IsCaloMuon        = iMuon->isCaloMuon()       ;

     
     
 

     // Global Muon Track
   
   if(iMuon->globalTrack().isAvailable()){
    
    reco::TrackRef glTrack = iMuon->globalTrack();
   
    muon.globalTrack.Part.v.SetPxPyPzE(glTrack->momentum().x(),
                                         glTrack->momentum().y(),
                                         glTrack->momentum().z(),
                                         sqrt(glTrack->momentum().mag2()+MASS_MU*MASS_MU));

     muon.globalTrack.Part.charge = glTrack->charge();
     muon.globalTrack.numberOfValidTkHits    =  glTrack->hitPattern().numberOfValidTrackerHits();
     muon.globalTrack.numberOfValidMuonHits  =  glTrack->hitPattern().numberOfValidMuonHits();
     
   //  cout<<glTrack->hitPattern().numberOfValidTrackerHits()<<endl;
   //  cout<<glTrack->hitPattern().numberOfValidMuonHits()<<endl;
     
     
     muon.globalTrack.numberOfValidStripHits    =  glTrack->hitPattern().numberOfValidStripHits();
     muon.globalTrack.numberOfValidPixelHits    =  glTrack->hitPattern().numberOfValidPixelHits();
     muon.globalTrack.numberOfValidMuonRPCHits  =  glTrack->hitPattern().numberOfValidMuonRPCHits();
     muon.globalTrack.numberOfValidMuonCSCHits  =  glTrack->hitPattern().numberOfValidMuonCSCHits();
     muon.globalTrack.numberOfValidMuonDTHits   =  glTrack->hitPattern().numberOfValidMuonDTHits();
     
    
    
     muon.globalTrack.nhit  =  glTrack->hitPattern().numberOfValidHits();
     muon.globalTrack.chi2n =  glTrack->normalizedChi2();
     muon.globalTrack.dz    =  glTrack->dz();

     muon.globalTrack.d0    =  glTrack->d0();

     muon.globalTrack.edz   =  glTrack->dzError();
     muon.globalTrack.ed0   =  glTrack->d0Error();
     muon.globalTrack.ept   =  glTrack->ptError();

     muon.globalTrack.vx    =  glTrack->vertex().x();
     muon.globalTrack.vy    =  glTrack->vertex().y();
     muon.globalTrack.vz    =  glTrack->vertex().z();

     muon.globalTrack.quality[0] = glTrack->quality(reco::TrackBase::qualityByName("loose"));
     muon.globalTrack.quality[1] = glTrack->quality(reco::TrackBase::qualityByName("tight"));
     muon.globalTrack.quality[2] = glTrack->quality(reco::TrackBase::qualityByName("highPurity"));

     muon.globalTrack.vtxid.clear();
     muon.globalTrack.vtxdxy.clear();
     muon.globalTrack.vtxdz.clear();

     for ( int i = 0 ; i != vtxid ; i++ )
     {
        muon.globalTrack.vtxid.push_back( i );
        muon.globalTrack.vtxdxy.push_back( glTrack->dxy( vtxid_xyz[i] ) );
        muon.globalTrack.vtxdz.push_back(  glTrack->dz( vtxid_xyz[i] )  );
     }

    }
    
    else {
     
      muon.globalTrack.d0 = -999;
      for ( int i = 0 ; i != vtxid ; i++ )
       {
         
	  muon.globalTrack.vtxid.push_back( i );
          muon.globalTrack.vtxdxy.push_back( -999 );
          muon.globalTrack.vtxdz.push_back( -999 );
       }
     
    }
    
    
   
    
     // Inner Muon Track
     
   if(iMuon->innerTrack().isAvailable()){
     
     reco::TrackRef inTrack = iMuon->innerTrack();
     muon.innerTrack.Part.v.SetPxPyPzE(inTrack->momentum().x(),
                                         inTrack->momentum().y(),
                                         inTrack->momentum().z(),
                                         sqrt(inTrack->momentum().mag2()+MASS_MU*MASS_MU));
     muon.innerTrack.Part.charge = inTrack->charge();
     
     muon.innerTrack.numberOfValidTkHits    =  inTrack->hitPattern().numberOfValidTrackerHits();
     muon.innerTrack.numberOfValidMuonHits  =  inTrack->hitPattern().numberOfValidMuonHits();
    
     muon.innerTrack.numberOfValidStripHits    =  inTrack->hitPattern().numberOfValidStripHits();
     muon.innerTrack.numberOfValidPixelHits    =  inTrack->hitPattern().numberOfValidPixelHits();
     muon.innerTrack.numberOfValidMuonRPCHits  =  inTrack->hitPattern().numberOfValidMuonRPCHits();
     muon.innerTrack.numberOfValidMuonCSCHits  =  inTrack->hitPattern().numberOfValidMuonCSCHits();
     muon.innerTrack.numberOfValidMuonDTHits   =  inTrack->hitPattern().numberOfValidMuonDTHits();
     
     muon.innerTrack.nhit  =  inTrack->hitPattern().numberOfValidHits();
     muon.innerTrack.chi2n =  inTrack->normalizedChi2();
     muon.innerTrack.dz    =  inTrack->dz();
     muon.innerTrack.d0    =  inTrack->d0();
     muon.innerTrack.edz   =  inTrack->dzError();
     muon.innerTrack.ed0   =  inTrack->d0Error();
     muon.innerTrack.ept   =  inTrack->ptError();

     muon.innerTrack.vx    =  inTrack->vertex().x();
     muon.innerTrack.vy    =  inTrack->vertex().y();
     muon.innerTrack.vz    =  inTrack->vertex().z();

     muon.innerTrack.quality[0] = inTrack->quality(reco::TrackBase::qualityByName("loose"));
     muon.innerTrack.quality[1] = inTrack->quality(reco::TrackBase::qualityByName("tight"));
     muon.innerTrack.quality[2] = inTrack->quality(reco::TrackBase::qualityByName("highPurity"));

     muon.innerTrack.vtxid.clear();
     muon.innerTrack.vtxdxy.clear();
     muon.innerTrack.vtxdz.clear();

     for ( int i = 0 ; i != vtxid ; i++ )
     {
        muon.innerTrack.vtxid.push_back( i );
        muon.innerTrack.vtxdxy.push_back( inTrack->dxy( vtxid_xyz[i] ) );
        muon.innerTrack.vtxdz.push_back(  inTrack->dz( vtxid_xyz[i] )  );
     }

     // Boris 3D IP Stuff
     int iVtx = 0;
     muon.vtxid.clear();
     muon.tip.clear();
     muon.tipErr.clear();
     muon.ip.clear();
     muon.ipErr.clear();
     muon.tip2.clear();
     muon.tip2Err.clear();
     muon.ip2.clear();
     muon.ip2Err.clear();

     // ... redo muon trajectory
     reco::TransientTrack tt = theTTBuilder->build(iMuon->innerTrack());
     // ... get beamspot + first entry in IP respecting BS
     edm::Handle<reco::BeamSpot> bs;
     iEvent.getByLabel(edm::InputTag("offlineBeamSpot"),bs);
     reco::Vertex bsvtx = reco::Vertex(reco::Vertex::Point(bs->position().x(),bs->position().y(),bs->position().z()),reco::Vertex::Error());
          Measurement1D ip     = IPTools::absoluteTransverseImpactParameter(tt,bsvtx).second;
          Measurement1D ip3D   = IPTools::absoluteImpactParameter3D(tt,bsvtx).second;
          muon.vtxid.push_back( iVtx );
          ++iVtx;
          muon.tip.push_back(    ip.value()  );
          muon.tipErr.push_back( ip.error() );
          muon.ip.push_back(     ip3D.value() );
          muon.ipErr.push_back(  ip3D.error() );
          muon.tip2.push_back(    ip.value()  );
          muon.tip2Err.push_back( ip.error() );
          muon.ip2.push_back(     ip3D.value() );
          muon.ip2Err.push_back(  ip3D.error() );


     // ... Loop on vtx collections
     for (unsigned int ivc=0; ivc!= vertexs.size(); ivc++){

       // ... get vertex collection
       edm::Handle<reco::VertexCollection> vertices;
       iEvent.getByLabel(vertexs.at(ivc),vertices);
       //cout << vertexs.at(ivc) << " -> size = " << vertices->end()-vertices->begin() <<  endl;  

       // ... prepare refitting
       VertexReProducer revertex(vertices, iEvent); 
       Handle<reco::BeamSpot>        pvbeamspot; 
       iEvent.getByLabel(revertex.inputBeamSpot(), pvbeamspot);
   
         // ... Loop on vtx in curent collection
         for(VertexCollection::const_iterator pvtx=vertices->begin(); pvtx!= vertices->end() ; ++pvtx)
         {

           reco::Vertex vertexYesB;
           reco::Vertex vertexNoB;
           reco::TrackCollection newTkCollection;

           vertexYesB = *pvtx ;   

           // ... Remove lepton track
           bool foundMatch(false);
           for (reco::Vertex::trackRef_iterator itk = pvtx->tracks_begin(); itk!=pvtx->tracks_end(); ++itk) 
           {
              bool refMatching = (itk->get() == &*(iMuon->innerTrack()) );
              if(refMatching){
                foundMatch = true;
              }else{
                newTkCollection.push_back(*itk->get());
              }     
           }//track collection for vertexNoB is set

          //cout << "checking mu matching" << endl;
          if(!foundMatch) {
	    //cout << "WARNING: no muon matching found" << endl;
	    vertexNoB = vertexYesB;
          }else{      
            vector<TransientVertex> pvs = revertex.makeVertices(newTkCollection, *pvbeamspot, iSetup) ;
            //cout << pvs.size() << endl;
            if(pvs.empty()) {
                vertexNoB = reco::Vertex(reco::Vertex::Point(bs->position().x(),bs->position().y(),bs->position().z()),
                        reco::Vertex::Error());
            } else {
	      //vertexNoB = findClosestVertex<TransientVertex>(zPos,pvs);
	      vertexNoB = pvs.front(); //take the first in the list
            }
          }

          // ... Compute 3D IP
 
          Measurement1D ip     = IPTools::absoluteTransverseImpactParameter(tt,vertexYesB).second;
          Measurement1D ip3D   = IPTools::absoluteImpactParameter3D(tt,vertexYesB).second;
          Measurement1D ip_2   = IPTools::absoluteTransverseImpactParameter(tt,vertexNoB).second;
          Measurement1D ip3D_2 = IPTools::absoluteImpactParameter3D(tt,vertexNoB).second;

          muon.vtxid.push_back( iVtx );
          ++iVtx;
          muon.tip.push_back(    ip.value()  );
          muon.tipErr.push_back( ip.error() );
          muon.ip.push_back(     ip3D.value() );
          muon.ipErr.push_back(  ip3D.error() );
          muon.tip2.push_back(    ip_2.value()  );
          muon.tip2Err.push_back( ip_2.error() );
          muon.ip2.push_back(     ip3D_2.value() );
          muon.ip2Err.push_back(  ip3D_2.error() );
/*
          if (foundMatch){
            cout << ip3D.value() << " " << ip3D_2.value() << endl;
          } 
*/
         } // END ... Loop on vtx in curent collection

       } // END ... Loop on vtx collections

     } else {
     
      muon.innerTrack.d0 = -999;
      for ( int i = 0 ; i != vtxid ; i++ )
       {
          muon.innerTrack.vtxid.push_back( i );
          muon.innerTrack.vtxdxy.push_back( -999 ) ;
          muon.innerTrack.vtxdz.push_back( -999 );
          muon.vtxid.push_back( i ) ;
          muon.tip.push_back(    -999 ) ;
          muon.tipErr.push_back( -999 ) ;
          muon.ip.push_back(     -999 ) ;
          muon.ipErr.push_back(  -999 ) ;
          muon.tip2.push_back(   -999 ) ; 
          muon.tip2Err.push_back(-999 ) ; 
          muon.ip2.push_back(    -999 ) ; 
          muon.ip2Err.push_back( -999 ) ; 


       }
     
    }
     
     // Outer Muon Track
     
   if(iMuon->outerTrack().isAvailable()){
     
     reco::TrackRef outTrack = iMuon->outerTrack();
     muon.outerTrack.Part.v.SetPxPyPzE(outTrack->momentum().x(),
                                         outTrack->momentum().y(),
                                         outTrack->momentum().z(),
                                         sqrt(outTrack->momentum().mag2()+MASS_MU*MASS_MU));
     muon.outerTrack.Part.charge = outTrack->charge();
     muon.outerTrack.numberOfValidTkHits    =  outTrack->hitPattern().numberOfValidTrackerHits();
     muon.outerTrack.numberOfValidMuonHits  =  outTrack->hitPattern().numberOfValidMuonHits();
     
     muon.outerTrack.numberOfValidStripHits    =  outTrack->hitPattern().numberOfValidStripHits();
     muon.outerTrack.numberOfValidPixelHits    =  outTrack->hitPattern().numberOfValidPixelHits();
     muon.outerTrack.numberOfValidMuonRPCHits  =  outTrack->hitPattern().numberOfValidMuonRPCHits();
     muon.outerTrack.numberOfValidMuonCSCHits  =  outTrack->hitPattern().numberOfValidMuonCSCHits();
     muon.outerTrack.numberOfValidMuonDTHits   =  outTrack->hitPattern().numberOfValidMuonDTHits();
     
     
     
     muon.outerTrack.nhit  =  outTrack->hitPattern().numberOfValidHits();
     muon.outerTrack.chi2n =  outTrack->normalizedChi2();
     muon.outerTrack.dz    =  outTrack->dz();
     muon.outerTrack.d0    =  outTrack->d0();
     muon.outerTrack.edz   =  outTrack->dzError();
     muon.outerTrack.ed0   =  outTrack->d0Error();
     muon.outerTrack.ept   =  outTrack->ptError();

     muon.outerTrack.vx    =  outTrack->vertex().x();
     muon.outerTrack.vy    =  outTrack->vertex().y();
     muon.outerTrack.vz    =  outTrack->vertex().z();

     muon.outerTrack.quality[0] = outTrack->quality(reco::TrackBase::qualityByName("loose"));
     muon.outerTrack.quality[1] = outTrack->quality(reco::TrackBase::qualityByName("tight"));
     muon.outerTrack.quality[2] = outTrack->quality(reco::TrackBase::qualityByName("highPurity"));

     muon.outerTrack.vtxid.clear();
     muon.outerTrack.vtxdxy.clear();
     muon.outerTrack.vtxdz.clear();

     for ( int i = 0 ; i != vtxid ; i++ )
     {
        muon.outerTrack.vtxid.push_back( i );
        muon.outerTrack.vtxdxy.push_back( outTrack->dxy( vtxid_xyz[i] ) );
        muon.outerTrack.vtxdz.push_back(  outTrack->dz( vtxid_xyz[i] )  );
     }
    }

    else {
      
      muon.outerTrack.d0 = -999;
      for ( int i = 0 ; i != vtxid ; i++ )
       {
          muon.outerTrack.vtxid.push_back( i );
          muon.outerTrack.vtxdxy.push_back( -999 );
          muon.outerTrack.vtxdz.push_back( -999 );
       }
     
    }
     
     
     
     MuonVector.push_back(muon);

   } // end for MuonCollection 

}
Exemplo n.º 26
0
void UAHiggsTree::GetGenKin(const edm::Event& iEvent)
{
   using namespace std;
   using namespace edm;
   using namespace reco;

/* 
   // MC Process Id and PtHat for AOD

   Handle< int > genProcessID;
   iEvent.getByLabel( "genEventProcID", genProcessID );
   int processId = *genProcessID;
   cout<<"Process ID : "<<processId<<endl;

*/

   //K Factor For Signal
   edm::Handle<double> KFactor;
   try {
    iEvent.getByLabel("KFactorProducer",KFactor);
    double kfactor = *KFactor;
    GenKin.kfactor=kfactor;
   }
   catch (...){;}

   /*
   // MC Process Id and PtHat for RECO
   Handle<HepMCProduct> hepMCHandle;
   iEvent.getByLabel(hepMCColl_, hepMCHandle ) ;
   const HepMC::GenEvent* GenEvt = hepMCHandle->GetEvent() ;
   int processId = GenEvt->signal_process_id();
   if (GenKinDebug) cout<<"Process ID2: "<<processId<<endl; 
   double ptHat  = GenEvt->event_scale();
   if (GenKinDebug) cout<<"PtHat MC : "<<ptHat<<endl; 

   GenKin.MCProcId  = processId ; 
   GenKin.Scale     = ptHat ;

   // PDF Info -> x,Q, parton id's -> see HepMC manual
   const HepMC::PdfInfo* PdfInfo = GenEvt->pdf_info();
   double x1 = PdfInfo->x1();
   double x2 = PdfInfo->x2();
   double Q  = PdfInfo->scalePDF(); 

   int id1 = PdfInfo->id1();
   int id2 = PdfInfo->id2();

   GenKin.x1 = x1 ;
   GenKin.x2 = x2 ;
   GenKin.Q  = Q  ;
   GenKin.Part1Id = id1 ; 
   GenKin.Part2Id = id2 ; */

   // Gen MET: From GenMETCollection  

   Handle<GenMETCollection> genmet;
//   iEvent.getByLabel(GenMetColl_ , genmet);
   iEvent.getByLabel("genMetTrue" , genmet);

   if (GenKinDebug) 
   { 
     cout << "GenMET et()  = " << (genmet->front()).et() << endl ;
     cout << "GenMET px()  = " << (genmet->front()).px() << endl ;
     cout << "GenMET py()  = " << (genmet->front()).py() << endl ;
     cout << "GenMET phi() = " << (genmet->front()).phi() << endl;
   }

   GenKin.Met    = (genmet->front()).et() ; 
   GenKin.MetX   = (genmet->front()).px() ; 
   GenKin.MetY   = (genmet->front()).py() ; 
   GenKin.MetPhi = (genmet->front()).phi() ; 

   // Gen MET: From GenPart Neutrinos ( no SUSY !!! )

   // ... Handle to access GenParticleCollection
   Handle<GenParticleCollection> genParticles;
   iEvent.getByLabel(genPartColl_, genParticles);
   if (!genParticles.isValid()) {
     cerr << "[UAHiggsTree::GetGenKin] Error: non valid GenParticleCollection " << endl;
     return;
   }
 
   double met1Px = 0 ;
   double met1Py = 0 ;
   double met1Pz = 0 ;
   double met1E  = 0 ;

   double met3Px = 0 ;
   double met3Py = 0 ;
   double met3Pz = 0 ;
   double met3E  = 0 ;

   // ... Loop on stable (final) particles
   for(GenParticleCollection::const_iterator p = genParticles->begin(); p != genParticles->end(); ++ p) 
   {
     int st  = p->status();
     int pid = p->pdgId();
     if ( st == 1 && ( abs(pid)==12 || abs(pid)==14 || abs(pid)==16 ) )
     {
       met1Px += p->px();
       met1Py += p->py();
       met1Pz += p->pz();
       met1E  += p->energy();
     } 
     else if ( st == 3 && ( abs(pid)==12 || abs(pid)==14 || abs(pid)==16 ) )
     {
       met3Px += p->px();
       met3Py += p->py();
       met3Pz += p->pz();
       met3E  += p->energy();
     }
   }

   // ... Set Missing Et 4-Vector
   GenKin.MetGP1.SetPxPyPzE( met1Px , met1Py , met1Pz , met1E ) ;
   GenKin.MetGP3.SetPxPyPzE( met3Px , met3Py , met3Pz , met3E ) ;

}
Exemplo n.º 27
0
void ChPartTree::GetEvtId(const edm::Event& iEvent)
{
   using namespace std;

   if ( EvtIdDebug )
   {
     cout << "XJ: EvdId: " << iEvent.id() << endl ;
     cout << "XJ: Run  : " << iEvent.id().run() << endl ;
     cout << "XJ: Evt  : " << iEvent.id().event() << endl ;
     cout << "XJ: Lumbl: " << iEvent.luminosityBlock() << endl ;
//   cout << "XJ: proID: " << iEvent.processHistoryID() << endl;
//   cout << "XJ: GUID : " << iEvent.processGUID() << endl;
     edm::Timestamp Time=iEvent.time();
     cout << "XJ: time : " << Time.value() << endl;
     cout << "XJ: isDa : " << iEvent.isRealData() << endl;
     cout << "XJ: expTy: " << iEvent.experimentType() << endl ;
     cout << "XJ: Bx   : " << iEvent.bunchCrossing() << endl;
     cout << "XJ: Orbit: " << iEvent.orbitNumber() << endl;
//   cout << "XJ: Store: " << iEvent.storeNumber() << endl; 
   }

   EvtId.Reset();

   EvtId.Run       = iEvent.id().run() ;   
   EvtId.Evt       = iEvent.id().event() ;
   EvtId.LumiSect  = iEvent.luminosityBlock();
   edm::Timestamp Time=iEvent.time();
   EvtId.Time      = Time.value(); 
   EvtId.IsData    = iEvent.isRealData();
   EvtId.ExpType   = iEvent.experimentType();
   EvtId.Bunch     = iEvent.bunchCrossing();
   EvtId.Orbit     = iEvent.orbitNumber();

}
// ------------ method called for each event  ------------
void
ThreePointCorrelatorEtaTest::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
{
  using namespace edm;
  using namespace std;

  edm::Handle<reco::VertexCollection> vertices;
  iEvent.getByLabel(vertexSrc_,vertices);
  double bestvz=-999.9, bestvx=-999.9, bestvy=-999.9;
  double bestvzError=-999.9, bestvxError=-999.9, bestvyError=-999.9;
  const reco::Vertex & vtx = (*vertices)[0];
  bestvz = vtx.z(); bestvx = vtx.x(); bestvy = vtx.y();
  bestvzError = vtx.zError(); bestvxError = vtx.xError(); bestvyError = vtx.yError();
  
  //first selection; vertices
  if(bestvz < vzLow_ || bestvz > vzHigh_ ) return;
  
  Handle<CaloTowerCollection> towers;
  iEvent.getByLabel(towerSrc_, towers);

  Handle<reco::TrackCollection> tracks;
  iEvent.getByLabel(trackSrc_, tracks);
  
  if( useCentrality_ ){

    CentralityProvider * centProvider = 0;
    if (!centProvider) centProvider = new CentralityProvider(iSetup);
    centProvider->newEvent(iEvent,iSetup);
    int hiBin = centProvider->getBin();
    cbinHist->Fill( hiBin );
    if( hiBin < Nmin_ || hiBin >= Nmax_ ) return;

  }

  const int NetaBins = etaBins_.size() - 1 ;

// initialize Qcos and Qsin

  double QcosTRK = 0.;
  double QsinTRK = 0.;
  double QcountsTrk = 0;

  double Q1[NetaBins][2][2];
  double Q1_count[NetaBins][2];

  double Q2[NetaBins][2][2];
  double Q2_count[NetaBins][2];

  for(int i = 0; i < NetaBins; i++){
    for(int j = 0; j < 2; j++){
      Q1_count[i][j] = 0.0;
      Q2_count[i][j] = 0.0;
      for(int k = 0; k < 2; k++){
        Q1[i][j][k] = 0.0;
        Q2[i][j][k] = 0.0;
      }
    }
  }

  int nTracks = 0;
  for(unsigned it = 0; it < tracks->size(); it++){

     const reco::Track & trk = (*tracks)[it];

     math::XYZPoint bestvtx(bestvx,bestvy,bestvz);
        
        double dzvtx = trk.dz(bestvtx);
        double dxyvtx = trk.dxy(bestvtx);
        double dzerror = sqrt(trk.dzError()*trk.dzError()+bestvzError*bestvzError);
        double dxyerror = sqrt(trk.d0Error()*trk.d0Error()+bestvxError*bestvyError);
        double nhits = trk.numberOfValidHits();
        double chi2n = trk.normalizedChi2();
        double nlayers = trk.hitPattern().trackerLayersWithMeasurement();
        chi2n = chi2n/nlayers;

        double weight = 1.0;

        if(!trk.quality(reco::TrackBase::highPurity)) continue;
        if(fabs(trk.ptError())/trk.pt() > offlineptErr_ ) continue;
        if(fabs(dzvtx/dzerror) > offlineDCA_) continue;
        if(fabs(dxyvtx/dxyerror) > offlineDCA_) continue;
        if(fabs(trk.eta()) < 2.4 && trk.pt() > 0.4 ){nTracks++;}// NtrkOffline        
        if(fabs(trk.eta()) > 2.4 || trk.pt() < ptLow_ || trk.pt() > ptHigh_) continue;
        if(chi2n > offlineChi2_) continue;
        if(nhits < offlinenhits_) continue;
        if( messAcceptance_ ) { if( trk.phi() < holeRight_ && trk.phi() > holeLeft_ ) continue;}
        if( doEffCorrection_ ){ weight = 1.0/effTable->GetBinContent( effTable->FindBin(trk.eta(), trk.pt()) );}
        else{ weight = 1.0; }
       
        trkPhi->Fill( trk.phi() );//make sure if messAcceptance is on or off

        QcosTRK += weight*cos( 2*trk.phi() );
        QsinTRK += weight*sin( 2*trk.phi() );
        QcountsTrk += weight;

        for(int eta = 0; eta < NetaBins; eta++){
          if( trk.eta() > etaBins_[eta] && trk.eta() < etaBins_[eta+1] ){

            if( trk.charge() == 1){
              Q1[eta][0][0] += weight*cos( trk.phi() );
              Q1[eta][0][1] += weight*sin( trk.phi() );
              Q1_count[eta][0] += weight;

              Q2[eta][0][0] += weight*weight*cos( 2*trk.phi() );
              Q2[eta][0][1] += weight*weight*sin( 2*trk.phi() );
              Q2_count[eta][0] += weight*weight;

            }
            else if( trk.charge() == -1){
              Q1[eta][1][0] += weight*cos( trk.phi() );
              Q1[eta][1][1] += weight*sin( trk.phi() );
              Q1_count[eta][1] += weight;

              Q2[eta][1][0] += weight*weight*cos( 2*trk.phi() );
              Q2[eta][1][1] += weight*weight*sin( 2*trk.phi() );
              Q2_count[eta][1] += weight*weight;

            }
          }
        }    


  } 

  if( !useCentrality_ ) if( nTracks < Nmin_ || nTracks >= Nmax_ ) return;
  
  Ntrk->Fill(nTracks);

//loop over calo towers (HF)

  double Q3[2][2];
  double ETT[2];

  for(int i = 0; i < 2; i++){
    ETT[i] = 0.;
    for(int j = 0; j < 2; j++){
      Q3[i][j] = 0.;
    }
  }

  int HFside = 2;
  if( useBothSide_ ) HFside = 1;

  for(unsigned i = 0; i < towers->size(); ++i){

        const CaloTower & hit= (*towers)[i];

        double caloEta = hit.eta();
        double caloPhi = hit.phi();
        double w = hit.hadEt( vtx.z() ) + hit.emEt( vtx.z() );
        
        if( reverseBeam_ ) caloEta = -hit.eta();
        if( messAcceptance_ ){if( caloPhi < holeRight_ && caloPhi > holeLeft_ ) continue;} hfPhi->Fill( caloPhi );//make sure if messAcceptance is on or off
        
        if( caloEta < etaHighHF_ && caloEta > etaLowHF_ ){
          
            Q3[0][0] += w*cos( -2*caloPhi );
            Q3[0][1] += w*sin( -2*caloPhi );
            ETT[0] += w;
        }
        else if( caloEta < -etaLowHF_ && caloEta > -etaHighHF_ ){

            Q3[1][0] += w*cos( -2*caloPhi );
            Q3[1][1] += w*sin( -2*caloPhi );
            ETT[1] += w;

        }
        else{continue;}
  }

  for(int ieta = 0; ieta < NetaBins; ieta++){
    for(int HF = 0; HF < HFside; HF++){
      for(int sign = 0; sign < 2; sign++){
        
        if( Q1_count[ieta][sign] == 0.0 || ETT[HF] == 0.0 ) continue;

          double Q_real = get3RealOverlap(Q1[ieta][sign][0], Q2[ieta][sign][0], Q3[HF][0], Q1[ieta][sign][1], Q2[ieta][sign][1], Q3[HF][1], Q1_count[ieta][sign], Q2_count[ieta][sign], ETT[HF] );
          QvsdEta[ieta][sign][HF]->Fill( Q_real, (Q1_count[ieta][sign]*Q1_count[ieta][sign] - Q2_count[ieta][sign])*ETT[HF] );

        } 
      if( Q1_count[ieta][0] == 0.0 || Q1_count[ieta][1] == 0.0 || ETT[HF] == 0.0 ) continue;

      double Q_real = get3Real(Q1[ieta][0][0]/Q1_count[ieta][0],Q1[ieta][1][0]/Q1_count[ieta][1],Q3[HF][0]/ETT[HF], Q1[ieta][0][1]/Q1_count[ieta][0], Q1[ieta][1][1]/Q1_count[ieta][1], Q3[HF][1]/ETT[HF]);
      QvsdEta[ieta][2][HF]->Fill( Q_real, Q1_count[ieta][0]*Q1_count[ieta][1]*ETT[HF] );  

    } 
  }

/*
calculate v2 using 3 sub-events method:
 */

  aveQ3[0][0]->Fill( Q3[0][0]/ETT[0], ETT[0] );//HF+ cos
  aveQ3[0][1]->Fill( Q3[0][1]/ETT[0], ETT[0] );//HF+ sin
  
  aveQ3[1][0]->Fill( Q3[1][0]/ETT[1], ETT[1] );//HF- cos
  aveQ3[1][1]->Fill( Q3[1][1]/ETT[1], ETT[1] );//HF- sin

  QcosTRK = QcosTRK/QcountsTrk;
  QsinTRK = QsinTRK/QcountsTrk;

  double QaQc = get2Real(Q3[1][0]/ETT[1], QcosTRK/QcountsTrk, Q3[1][1]/ETT[1], QsinTRK/QcountsTrk );
  double QaQb = get2Real(Q3[1][0]/ETT[1], Q3[0][0]/ETT[0], Q3[1][1]/ETT[1], -Q3[0][1]/ETT[0]);//an extra minus sign 
  double QcQb = get2Real(QcosTRK/QcountsTrk, Q3[0][0]/ETT[0], QsinTRK/QcountsTrk, Q3[0][1]/ETT[0]);

  c2_ac->Fill( QaQc, ETT[1]*QcountsTrk );
  c2_cb->Fill( QcQb, ETT[1]*ETT[0]  );
  c2_ab->Fill( QaQb, ETT[0]*QcountsTrk );

}
Exemplo n.º 29
0
int NeroMetRecluster::analyze(const edm::Event& iEvent){

    if ( mOnlyMc  ) return 0; // in principle I would like to have the gen met: TODO

    // maybe handle should be taken before
    iEvent.getByToken(token, handle);
    if ( not handle.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle is not valid"<<endl;

    iEvent.getByToken(token_puppi,handle_puppi);
    if ( not handle_puppi.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle_puppi is not valid"<<endl;

    iEvent.getByToken(token_puppiUncorr,handle_puppiUncorr);
    if ( not handle_puppiUncorr.isValid() ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] handle_puppiUncorr is not valid"<<endl;
    //--

    const pat::MET &met = handle->front();

    caloMet_Pt = met.caloMETPt();
    caloMet_Phi = met.caloMETPhi();
    caloMet_SumEt = met.caloMETSumEt();


    // FILL
    new ( (*p4)[p4->GetEntriesFast()]) TLorentzVector( met.px(),met.py(),met.pz(),met.energy()  );

    sumEtRaw = met.uncorSumEt();

    ptJESUP -> push_back( met.shiftedPt(pat::MET::JetEnUp) );
    ptJESDOWN -> push_back( met.shiftedPt(pat::MET::JetEnDown) );

    rawMet_Pt = met.uncorPt(); 
    rawMet_Phi = met.uncorPhi();


    if (IsExtend())
    {
        //MetNoMu
        TLorentzVector metnomu(met.px(),met.py(),met.pz(),met.energy());
        TLorentzVector tkMet(0,0,0,0); 
        TLorentzVector pfmet_3p0(0,0,0,0); 

        if ( pf == NULL ) cout<<"[NeroMetRecluster]::[analyze]::[ERROR] PF pointer is null. Run NeroPF. "<<endl; 

        for (unsigned int i = 0, n = pf->handle->size(); i < n; ++i) {
            const pat::PackedCandidate &cand = (*pf->handle)[i];

            // only up to eta 3
            if (std::abs(cand.pdgId()) == 13)
                metnomu += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());  

            // only charge hadrons
            if ( cand.charge() != 0 )
                tkMet += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());

            if (std::abs(cand.eta()) < 3.0 ) 
                pfmet_3p0 += TLorentzVector(cand.px(),cand.py(),cand.pz(),cand.energy());
        }

        *pfMet_e3p0 = TLorentzVector( -pfmet_3p0 );
        *metNoMu = TLorentzVector(metnomu);  // no minus
        *trackMet = TLorentzVector( -tkMet );

        auto &puppi = handle_puppi->front(); 
        *metPuppi =  TLorentzVector( puppi.px(), puppi.py(),puppi.pz(),puppi.energy() );
        sumEtRawPuppi = handle_puppiUncorr->front().sumEt();

    }    
    // GEN INFO
    if ( not iEvent.isRealData () ){
        new ( (*genP4)[genP4->GetEntriesFast()]) TLorentzVector( met.genMET()->px(),met.genMET()->py(),met.genMET()->pz(),met.genMET()->energy()  );
    }


    return 0;
}
// ------------ method called to skim the data  ------------
bool MCBarrelEndcapFilter::filter(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
    using namespace edm;
    bool accepted = false;
    Handle<HepMCProduct> evt;
    iEvent.getByLabel(label_, evt);

    vector<HepMC::GenParticle*> barrel_passed;
    vector<HepMC::GenParticle*> endcap_passed;


    const HepMC::GenEvent * myGenEvent = evt->GetEvent();

    if(verbose) cout << "Start Event\n";

    for ( HepMC::GenEvent::particle_const_iterator p = myGenEvent->particles_begin();
            p != myGenEvent->particles_end(); ++p ) {


        if(verbose) cout << abs((*p)->pdg_id()) << ' ' 
            << (*p)->momentum().perp() << ' ' 
            << (*p)->momentum().eta() << ' ' 
            << (*p)->status() << endl;
        // check for barrel conditions
        if ((abs((*p)->pdg_id()) == abs(barrelID) || barrelID == 0) &&
                (*p)->momentum().perp() > ptMinBarrel && (*p)->momentum().eta() > etaMinBarrel 
                && (*p)->momentum().eta() < etaMaxBarrel && ((*p)->status() == statusBarrel || statusBarrel == 0))
        { 
            if(verbose) cout << "Found Barrel\n";
            // passed barrel conditions ...
            // ... now check pair-conditions with endcap passed particles
            //
            unsigned int i=0;
            double invmass =0.;
            while(!accepted && i<endcap_passed.size()) {
                invmass = ( math::PtEtaPhiMLorentzVector((*p)->momentum()) + math::PtEtaPhiMLorentzVector(endcap_passed[i]->momentum())).mass();
                if(verbose) cout << "Invariant Mass is" << invmass << endl;
                if(invmass > minInvMass && invmass < maxInvMass) {
                    accepted = true;
                }
                i++;
            }    
            // if we found a matching pair quit the loop
            if(accepted) break;
            else{
                barrel_passed.push_back(*p);   // else remember the particle to have passed barrel conditions
            }
        }

        // check for endcap conditions

        if ((abs((*p)->pdg_id()) == abs(endcapID) || endcapID == 0) && 
                (*p)->momentum().perp() > ptMinEndcap && (*p)->momentum().eta() > etaMinEndcap
                && (*p)->momentum().eta() < etaMaxEndcap && ((*p)->status() == statusEndcap || statusEndcap == 0)) { 
            if(verbose) cout << "Found Endcap\n";
            // passed endcap conditions ...
            // ... now check pair-conditions with barrel passed particles vector
            unsigned int i=0;
            double invmass =0.;
            while(!accepted && i<barrel_passed.size()) {
                if((*p) != barrel_passed[i]) {
                    if(verbose) cout << "Checking to match Barrel\n";
                    invmass = ( math::PtEtaPhiMLorentzVector((*p)->momentum()) + math::PtEtaPhiMLorentzVector(barrel_passed[i]->momentum())).mass();
                    if(verbose) cout << "Invariant Mass is" << invmass << endl;
                    if(invmass > minInvMass && invmass < maxInvMass) {
                        accepted = true;
                    }
                    i++;
                }
            }    
            // if we found a matching pair quit the loop
            if(accepted) break;
            else {
                endcap_passed.push_back(*p);   // else remember the particle to have passed endcap conditions
            }
        }
    }

    if(verbose)
    {
        cout << "This event ";
        if (accepted){ cout <<  "passed "; } else {cout << "failed ";}
        cout << "the filter\n";
    }

    return accepted;

}