Fork me on GitHub

Changes in / [a0f2226:a7c9002] in git


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • readers/DelphesCMSFWLite.cpp

    ra0f2226 ra7c9002  
    5353#include "DataFormats/FWLite/interface/Handle.h"
    5454#include "DataFormats/HepMCCandidate/interface/GenParticle.h"
     55#include "DataFormats/PatCandidates/interface/PackedGenParticle.h"
    5556#include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
    5657#include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
     
    6364
    6465void ConvertInput(fwlite::Event &event, Long64_t eventCounter,
    65   ExRootTreeBranch *branchEvent, ExRootTreeBranch *branchRwgt,
    66   DelphesFactory *factory, TObjArray *allParticleOutputArray,
    67   TObjArray *stableParticleOutputArray, TObjArray *partonOutputArray, Bool_t firstEvent)
     66    ExRootTreeBranch *branchEvent, ExRootTreeBranch *branchRwgt,
     67    DelphesFactory *factory, TObjArray *allParticleOutputArray,
     68    TObjArray *stableParticleOutputArray, TObjArray *partonOutputArray, Bool_t firstEvent)
    6869{
    6970
     
    7172  fwlite::Handle< LHEEventProduct > handleLHEEvent;
    7273  fwlite::Handle< vector< reco::GenParticle > > handleParticle;
     74  fwlite::Handle< vector< pat::PackedGenParticle > > handlePackedParticle;
    7375
    7476  vector< reco::GenParticle >::const_iterator itParticle;
     77  vector< pat::PackedGenParticle >::const_iterator itPackedParticle;
    7578
    7679  vector< const reco::Candidate * > vectorCandidate;
     
    9699    handleParticle.getByLabel(event, "genParticles");
    97100  }
    98   else if (!((handleParticle.getBranchNameFor(event, "prunedGenParticles")).empty()))
     101  else if (!((handlePackedParticle.getBranchNameFor(event, "packedGenParticles")).empty()) && !((handleParticle.getBranchNameFor(event,"prunedGenParticles")).empty()))
    99102  {
    100103    handleParticle.getByLabel(event, "prunedGenParticles");
     104    handlePackedParticle.getByLabel(event, "packedGenParticles");
    101105  }
    102106  else
     
    107111
    108112  Bool_t foundLHE = !((handleLHEEvent.getBranchNameFor(event, "source")).empty()) || !((handleLHEEvent.getBranchNameFor(event, "externalLHEProducer")).empty());
     113  Bool_t isMiniAOD = !((handlePackedParticle.getBranchNameFor(event, "packedGenParticles")).empty()) && ((handleParticle.getBranchNameFor(event, "genParticles")).empty()) ;
    109114
    110115  HepMCEvent *element;
     
    146151    const vector< gen::WeightsInfo > &vectorWeightsInfo = handleLHEEvent->weights();
    147152    vector< gen::WeightsInfo >::const_iterator itWeightsInfo;
    148    
     153
    149154    for(itWeightsInfo = vectorWeightsInfo.begin(); itWeightsInfo != vectorWeightsInfo.end(); ++itWeightsInfo)
    150155    {
     
    158163  for(itParticle = handleParticle->begin(); itParticle != handleParticle->end(); ++itParticle)
    159164  {
    160     vectorCandidate.push_back(&*itParticle);
     165    const reco::GenParticle &particle = *itParticle;
     166    if( !isMiniAOD || particle.status() != 1 ) vectorCandidate.push_back(&*itParticle);
    161167  }
    162168
     
    164170  {
    165171    const reco::GenParticle &particle = *itParticle;
     172
     173    pid = particle.pdgId();
     174    status = particle.status();
     175    if( isMiniAOD && particle.status() == 1 ) continue;
     176    px = particle.px(); py = particle.py(); pz = particle.pz(); e = particle.energy(); mass = particle.mass();
     177    x = particle.vx(); y = particle.vy(); z = particle.vz();
     178
     179    candidate = factory->NewCandidate();
     180
     181    candidate->PID = pid;
     182    pdgCode = TMath::Abs(candidate->PID);
     183
     184    candidate->Status = status;
     185
     186    if(particle.mother())
     187    {
     188      itCandidate = find(vectorCandidate.begin(), vectorCandidate.end(), particle.mother());
     189      if(itCandidate != vectorCandidate.end()) candidate->M1 = distance(vectorCandidate.begin(), itCandidate);
     190    }
     191
     192    itCandidate = find(vectorCandidate.begin(), vectorCandidate.end(), particle.daughter(0));
     193    if(itCandidate != vectorCandidate.end()) candidate->D1 = distance(vectorCandidate.begin(), itCandidate);
     194
     195    itCandidate = find(vectorCandidate.begin(), vectorCandidate.end(), particle.daughter(particle.numberOfDaughters() - 1));
     196    if(itCandidate != vectorCandidate.end()) candidate->D2 = distance(vectorCandidate.begin(), itCandidate);
     197
     198    pdgParticle = pdg->GetParticle(pid);
     199    candidate->Charge = pdgParticle ? Int_t(pdgParticle->Charge()/3.0) : -999;
     200    candidate->Mass = mass;
     201
     202    candidate->Momentum.SetPxPyPzE(px, py, pz, e);
     203
     204    candidate->Position.SetXYZT(x*10.0, y*10.0, z*10.0, 0.0);
     205
     206    allParticleOutputArray->Add(candidate);
     207
     208    if(!pdgParticle) continue;
     209
     210    if( status == 1)
     211    {
     212      // Prevent duplicated particle.
     213      if ( !isMiniAOD ) stableParticleOutputArray->Add(candidate);
     214    }
     215    else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
     216    {
     217      partonOutputArray->Add(candidate);
     218    }
     219  }
     220  if ( !isMiniAOD) return ;
     221  // For MiniAOD sample,
     222  // Only status==1 particles are saved to packedGenParticles.
     223  for(itPackedParticle = handlePackedParticle->begin(); itPackedParticle != handlePackedParticle->end(); ++itPackedParticle)
     224  {
     225    vectorCandidate.push_back(&*itPackedParticle);
     226  }
     227
     228  for(itPackedParticle = handlePackedParticle->begin(); itPackedParticle != handlePackedParticle->end(); ++itPackedParticle)
     229  {
     230    const pat::PackedGenParticle &particle = *itPackedParticle;
    166231
    167232    pid = particle.pdgId();
     
    177242    candidate->Status = status;
    178243
    179     if(particle.mother())
    180     {
    181       itCandidate = find(vectorCandidate.begin(), vectorCandidate.end(), particle.mother());
     244    if(particle.mother(0))
     245    {
     246      itCandidate = find(vectorCandidate.begin(), vectorCandidate.end(), particle.mother(0));
    182247      if(itCandidate != vectorCandidate.end()) candidate->M1 = distance(vectorCandidate.begin(), itCandidate);
    183248    }
     
    204269    {
    205270      stableParticleOutputArray->Add(candidate);
    206     }
    207     else if(pdgCode <= 5 || pdgCode == 21 || pdgCode == 15)
    208     {
    209       partonOutputArray->Add(candidate);
    210271    }
    211272  }
     
    258319
    259320  FWLiteEnabler::enable();
    260  
     321
    261322  try
    262323  {
     
    317378      {
    318379        ConvertInput(event, eventCounter, branchEvent, branchRwgt, factory,
    319           allParticleOutputArray, stableParticleOutputArray, partonOutputArray, firstEvent);
     380            allParticleOutputArray, stableParticleOutputArray, partonOutputArray, firstEvent);
    320381        modularDelphes->ProcessTask();
    321          
     382
    322383        firstEvent = kFALSE;
    323384
Note: See TracChangeset for help on using the changeset viewer.