CMS 3D CMS Logo

EnergyRingsTableProducer.cc
Go to the documentation of this file.
1 // system include files
2 #include <memory>
3 
4 // user include files
7 
9 
13 
16 
18 
21 
23  public:
24  explicit EnergyRingsTableProducer(const edm::ParameterSet &iConfig) :
25  name_(iConfig.getParameter<std::string>("name")),
26  srcJet_(consumes<edm::View<pat::Jet>>(iConfig.getParameter<edm::InputTag>("src")))
27  {
28  produces<nanoaod::FlatTable>();
29  }
30 
32 
33  static void fillDescriptions(edm::ConfigurationDescriptions & descriptions) {
35  desc.add<edm::InputTag>("src")->setComment("input Jet collection");
36  desc.add<std::string>("name")->setComment("name of the Jet FlatTable we are extending with energy rings");
37  descriptions.add("EnergyRingsTable", desc);
38  }
39 
40  private:
41  void produce(edm::Event&, edm::EventSetup const&) override ;
42 
45 
46 };
47 
48 // ------------ method called to produce the data ------------
49 void
51 {
53  iEvent.getByToken(srcJet_, srcJet);
54 
55 
56  float cone_boundaries[] = { 0.05, 0.1, 0.2, 0.3,0.4 };
57  size_t ncone_boundaries = sizeof(cone_boundaries)/sizeof(float);
58  unsigned int nJet = srcJet->size();
59  unsigned int ncand = 0;
60  std::vector<float> numdaughterspt03;
61  std::vector<std::vector<float>> EmFractionEnergyRings(ncone_boundaries+1,std::vector<float>(nJet, 0.));
62  std::vector<std::vector<float>> ChFractionEnergyRings(ncone_boundaries+1,std::vector<float>(nJet, 0.));
63  std::vector<std::vector<float>> NeFractionEnergyRings(ncone_boundaries+1,std::vector<float>(nJet, 0.));
64  std::vector<std::vector<float>> MuFractionEnergyRings(ncone_boundaries+1,std::vector<float>(nJet, 0.));
65 
66  for (unsigned int ij = 0; ij<nJet; ij++){
67  ++ncand;
68  auto jet = srcJet->ptrAt(ij);
69  int numDaughtersPt03=0;
70  for (unsigned int ijcone = 0; ijcone<ncone_boundaries; ijcone++){
71  EmFractionEnergyRings[ijcone][ij] = 0;
72  MuFractionEnergyRings[ijcone][ij] = 0;
73  ChFractionEnergyRings[ijcone][ij] = 0;
74  NeFractionEnergyRings[ijcone][ij] = 0;
75  }
76  for(const auto & d : jet->daughterPtrVector()){
77  float candDr = Geom::deltaR(d->p4(),jet->p4());
78  size_t icone = std::lower_bound(&cone_boundaries[0],&cone_boundaries[ncone_boundaries],candDr) - &cone_boundaries[0];
79  float candEnergy = d->energy();
80  int pdgid = abs(d->pdgId()) ;
81  if( pdgid == 22 || pdgid == 11 ) {
82  EmFractionEnergyRings[icone][ij] += candEnergy;
83  } else if ( pdgid == 13 ) {
84  MuFractionEnergyRings[icone][ij] += candEnergy;
85  } else if ( d->charge() != 0 ) {
86  ChFractionEnergyRings[icone][ij] += candEnergy;
87  } else {
88  NeFractionEnergyRings[icone][ij] += candEnergy;
89  }
90  if(d->pt()>0.3) numDaughtersPt03+=1;
91  } // end of jet daughters loop
92  numdaughterspt03.push_back(numDaughtersPt03);
93  }//end of jet loop
94  auto tab = std::make_unique<nanoaod::FlatTable>(ncand, name_, false, true);//extension to Jet collection set to true
95  tab->addColumn<int>("numDaughtersPt03", numdaughterspt03, "number of jet daughters with pT>0.3 GeV", nanoaod::FlatTable::IntColumn);
96 
97  tab->addColumn<float>("EmFractionEnergyRing0", EmFractionEnergyRings[0], "Em energy fraction in ring in dR 0-0.05", nanoaod::FlatTable::FloatColumn);
98  tab->addColumn<float>("EmFractionEnergyRing1", EmFractionEnergyRings[1], "Em energy fraction in ring in dR 0.05-0.1", nanoaod::FlatTable::FloatColumn);
99  tab->addColumn<float>("EmFractionEnergyRing2", EmFractionEnergyRings[2], "Em energy fraction in ring in dR 0.1-0.2", nanoaod::FlatTable::FloatColumn);
100  tab->addColumn<float>("EmFractionEnergyRing3", EmFractionEnergyRings[3], "Em energy fraction in ring in dR 0.2-0.3", nanoaod::FlatTable::FloatColumn);
101  tab->addColumn<float>("EmFractionEnergyRing4", EmFractionEnergyRings[4], "Em energy fraction in ring in dR 0.3-0.4", nanoaod::FlatTable::FloatColumn);
102  tab->addColumn<float>("EmFractionEnergyRing5", EmFractionEnergyRings[5], "Em energy fraction in ring in dR 0.4 overflow", nanoaod::FlatTable::FloatColumn);
103 
104  tab->addColumn<float>("ChFractionEnergyRing0", ChFractionEnergyRings[0], "Ch energy fraction in ring in dR 0-0.05", nanoaod::FlatTable::FloatColumn);
105  tab->addColumn<float>("ChFractionEnergyRing1", ChFractionEnergyRings[1], "Ch energy fraction in ring in dR 0.05-0.1", nanoaod::FlatTable::FloatColumn);
106  tab->addColumn<float>("ChFractionEnergyRing2", ChFractionEnergyRings[2], "Ch energy fraction in ring in dR 0.1-0.2", nanoaod::FlatTable::FloatColumn);
107  tab->addColumn<float>("ChFractionEnergyRing3", ChFractionEnergyRings[3], "Ch energy fraction in ring in dR 0.2-0.3", nanoaod::FlatTable::FloatColumn);
108  tab->addColumn<float>("ChFractionEnergyRing4", ChFractionEnergyRings[4], "Ch energy fraction in ring in dR 0.3-0.4", nanoaod::FlatTable::FloatColumn);
109  tab->addColumn<float>("ChFractionEnergyRing5", ChFractionEnergyRings[5], "Ch energy fraction in ring in dR 0.4 overflow", nanoaod::FlatTable::FloatColumn);
110 
111  tab->addColumn<float>("MuFractionEnergyRing0", MuFractionEnergyRings[0], "Mu energy fraction in ring in dR 0-0.05", nanoaod::FlatTable::FloatColumn);
112  tab->addColumn<float>("MuFractionEnergyRing1", MuFractionEnergyRings[1], "Mu energy fraction in ring in dR 0.05-0.1", nanoaod::FlatTable::FloatColumn);
113  tab->addColumn<float>("MuFractionEnergyRing2", MuFractionEnergyRings[2], "Mu energy fraction in ring in dR 0.1-0.2", nanoaod::FlatTable::FloatColumn);
114  tab->addColumn<float>("MuFractionEnergyRing3", MuFractionEnergyRings[3], "Mu energy fraction in ring in dR 0.2-0.3", nanoaod::FlatTable::FloatColumn);
115  tab->addColumn<float>("MuFractionEnergyRing4", MuFractionEnergyRings[4], "Mu energy fraction in ring in dR 0.3-0.4", nanoaod::FlatTable::FloatColumn);
116  tab->addColumn<float>("MuFractionEnergyRing5", MuFractionEnergyRings[5], "Mu energy fraction in ring in dR 0.4 overflow", nanoaod::FlatTable::FloatColumn);
117 
118  tab->addColumn<float>("NeFractionEnergyRing0", NeFractionEnergyRings[0], "Ne energy fraction in ring in dR 0-0.05", nanoaod::FlatTable::FloatColumn);
119  tab->addColumn<float>("NeFractionEnergyRing1", NeFractionEnergyRings[1], "Ne energy fraction in ring in dR 0.05-0.1", nanoaod::FlatTable::FloatColumn);
120  tab->addColumn<float>("NeFractionEnergyRing2", NeFractionEnergyRings[2], "Ne energy fraction in ring in dR 0.1-0.2", nanoaod::FlatTable::FloatColumn);
121  tab->addColumn<float>("NeFractionEnergyRing3", NeFractionEnergyRings[3], "Ne energy fraction in ring in dR 0.2-0.3", nanoaod::FlatTable::FloatColumn);
122  tab->addColumn<float>("NeFractionEnergyRing4", NeFractionEnergyRings[4], "Ne energy fraction in ring in dR 0.3-0.4", nanoaod::FlatTable::FloatColumn);
123  tab->addColumn<float>("NeFractionEnergyRing5", NeFractionEnergyRings[5], "Ne energy fraction in ring in dR 0.4 overflow", nanoaod::FlatTable::FloatColumn);
124 
125  iEvent.put(std::move(tab));
126 }
127 
129 //define this as a plug-in
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Definition: HeavyIon.h:7
edm::EDGetTokenT< edm::View< pat::Jet > > srcJet_
int iEvent
Definition: GenABIO.cc:230
Definition: Jet.py:1
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterDescriptionBase * add(U const &iLabel, T const &value)
EnergyRingsTableProducer(const edm::ParameterSet &iConfig)
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
void produce(edm::Event &, edm::EventSetup const &) override
void add(std::string const &label, ParameterSetDescription const &psetDescription)
HLT enums.
def move(src, dest)
Definition: eostools.py:511