00001 #include "HLTriggerOffline/Tau/interface/HLTTauMCProducer.h"
00002
00003 using namespace edm;
00004 using namespace std;
00005 using namespace reco;
00006
00007 HLTTauMCProducer::HLTTauMCProducer(const edm::ParameterSet& mc)
00008 {
00009
00010
00011
00012 MC_ = mc.getUntrackedParameter<edm::InputTag>("GenParticles");
00013 ptMinMCTau_ = mc.getUntrackedParameter<double>("ptMinTau",5.);
00014 ptMinMCMuon_ = mc.getUntrackedParameter<double>("ptMinMuon",2.);
00015 ptMinMCElectron_ = mc.getUntrackedParameter<double>("ptMinElectron",5.);
00016 m_PDG_ = mc.getUntrackedParameter<std::vector<int> >("BosonID");
00017 etaMax = mc.getUntrackedParameter<double>("EtaMax",2.5);
00018
00019 produces<LorentzVectorCollection>("LeptonicTauLeptons");
00020 produces<LorentzVectorCollection>("LeptonicTauElectrons");
00021 produces<LorentzVectorCollection>("LeptonicTauMuons");
00022 produces<LorentzVectorCollection>("HadronicTauOneProng");
00023 produces<LorentzVectorCollection>("HadronicTauThreeProng");
00024 produces<LorentzVectorCollection>("HadronicTauOneAndThreeProng");
00025 produces<LorentzVectorCollection>("TauOther");
00026 produces<LorentzVectorCollection>("Neutrina");
00027
00028 }
00029
00030 HLTTauMCProducer::~HLTTauMCProducer(){ }
00031
00032 void HLTTauMCProducer::produce(edm::Event& iEvent, const edm::EventSetup& iES)
00033 {
00034
00035
00036 auto_ptr<LorentzVectorCollection> product_Electrons(new LorentzVectorCollection);
00037 auto_ptr<LorentzVectorCollection> product_Muons(new LorentzVectorCollection);
00038 auto_ptr<LorentzVectorCollection> product_Leptons(new LorentzVectorCollection);
00039 auto_ptr<LorentzVectorCollection> product_OneProng(new LorentzVectorCollection);
00040 auto_ptr<LorentzVectorCollection> product_ThreeProng(new LorentzVectorCollection);
00041 auto_ptr<LorentzVectorCollection> product_OneAndThreeProng(new LorentzVectorCollection);
00042 auto_ptr<LorentzVectorCollection> product_Other(new LorentzVectorCollection);
00043 auto_ptr<LorentzVectorCollection> product_Neutrina(new LorentzVectorCollection);
00044
00045 edm::Handle<GenParticleCollection> genParticles;
00046 iEvent.getByLabel(MC_, genParticles);
00047
00048 GenParticleCollection::const_iterator p = genParticles->begin();
00049
00050 for (;p != genParticles->end(); ++p ) {
00051
00052 bool pdg_ok = true;
00053 for(size_t pi =0;pi<m_PDG_.size();++pi)
00054 {
00055 if(abs((*p).pdgId())== m_PDG_[pi] && abs((*p).status()) == 3 ){
00056 pdg_ok = true;
00057
00058 }
00059 }
00060
00061
00062 if( pdg_ok )
00063 {
00064
00065 std::vector<GenParticle*> decayProducts;
00066
00067 TLorentzVector Boson((*p).px(),(*p).py(),(*p).pz(),(*p).energy());
00068
00069 for (GenParticle::const_iterator BosonIt=(*p).begin(); BosonIt != (*p).end(); BosonIt++){
00070
00071
00072 if (abs((*BosonIt).pdgId()) == 15 && ((*BosonIt).status()==3))
00073 {
00074 decayProducts.clear();
00075
00076 for (GenParticle::const_iterator TauIt = (*BosonIt).begin(); TauIt != (*BosonIt).end(); TauIt++) {
00077
00078
00079 if (abs((*TauIt).pdgId()) == 15 && ((*TauIt).status()==2))
00080 {
00081 decayProducts = getGenStableDecayProducts((reco::GenParticle*) & (*TauIt));
00082
00083
00084
00085 }
00086 }
00087
00088
00089 if ( !decayProducts.empty() )
00090 {
00091
00092 LorentzVector Visible_Taus(0.,0.,0.,0.);
00093 LorentzVector TauDecayProduct(0.,0.,0.,0.);
00094 LorentzVector Neutrino(0.,0.,0.,0.);
00095
00096 int numElectrons = 0;
00097 int numMuons = 0;
00098 int numChargedPions = 0;
00099 int numNeutralPions = 0;
00100 int numNeutrinos = 0;
00101 int numOtherParticles = 0;
00102
00103
00104 for (std::vector<GenParticle*>::iterator pit = decayProducts.begin(); pit != decayProducts.end(); pit++)
00105 {
00106 int pdg_id = abs((*pit)->pdgId());
00107 if (pdg_id == 11) numElectrons++;
00108 else if (pdg_id == 13) numMuons++;
00109 else if (pdg_id == 211) numChargedPions++;
00110 else if (pdg_id == 111) numNeutralPions++;
00111 else if (pdg_id == 12 ||
00112 pdg_id == 14 ||
00113 pdg_id == 16) {
00114 numNeutrinos++;
00115 if (pdg_id == 16) {
00116 Neutrino.SetPxPyPzE((*pit)->px(),(*pit)->py(),(*pit)->pz(),(*pit)->energy());
00117 }
00118 }
00119 else if (pdg_id != 22) {
00120 numOtherParticles++;
00121 }
00122
00123 if (pdg_id != 12 &&
00124 pdg_id != 14 &&
00125 pdg_id != 16){
00126 TauDecayProduct.SetPxPyPzE((*pit)->px(),(*pit)->py(),(*pit)->pz(),(*pit)->energy());
00127 Visible_Taus+=TauDecayProduct;
00128 }
00129
00130 }
00131
00132 int tauDecayMode = kOther;
00133
00134 if ( numOtherParticles == 0 ){
00135 if ( numElectrons == 1 ){
00136
00137 tauDecayMode = kElectron;
00138 } else if ( numMuons == 1 ){
00139
00140 tauDecayMode = kMuon;
00141 } else {
00142
00143 switch ( numChargedPions ){
00144 case 1 :
00145 switch ( numNeutralPions ){
00146 case 0 :
00147 tauDecayMode = kOneProng0pi0;
00148 break;
00149 case 1 :
00150 tauDecayMode = kOneProng1pi0;
00151 break;
00152 case 2 :
00153 tauDecayMode = kOneProng2pi0;
00154 break;
00155 }
00156 break;
00157 case 3 :
00158 switch ( numNeutralPions ){
00159 case 0 :
00160 tauDecayMode = kThreeProng0pi0;
00161 break;
00162 case 1 :
00163 tauDecayMode = kThreeProng1pi0;
00164 break;
00165 }
00166 break;
00167 }
00168 }
00169 }
00170
00171
00172
00173
00174 if(tauDecayMode == kElectron)
00175 {
00176 if((abs(Visible_Taus.eta())<etaMax)&&(Visible_Taus.pt()>ptMinMCElectron_)){
00177 product_Electrons->push_back(Visible_Taus);
00178 product_Leptons->push_back(Visible_Taus);
00179 }
00180 }
00181 else if (tauDecayMode == kMuon)
00182 {
00183
00184 if((abs(Visible_Taus.eta())<etaMax)&&(Visible_Taus.pt()>ptMinMCMuon_)){
00185 product_Muons->push_back(Visible_Taus);
00186 product_Leptons->push_back(Visible_Taus);
00187 }
00188 }
00189 else if(tauDecayMode == kOneProng0pi0 ||
00190 tauDecayMode == kOneProng1pi0 ||
00191 tauDecayMode == kOneProng2pi0 )
00192 {
00193 if ((abs(Visible_Taus.eta()) < etaMax) && (Visible_Taus.pt() > ptMinMCElectron_)){
00194 product_OneProng->push_back(Visible_Taus);
00195 product_OneAndThreeProng->push_back(Visible_Taus);
00196 product_Neutrina->push_back(Neutrino);
00197 }
00198 }
00199 else if (tauDecayMode == kThreeProng0pi0 ||
00200 tauDecayMode == kThreeProng1pi0 )
00201 {
00202 if((abs(Visible_Taus.eta())<etaMax)&&(Visible_Taus.pt()>ptMinMCTau_)) {
00203 product_ThreeProng->push_back(Visible_Taus);
00204 product_OneAndThreeProng->push_back(Visible_Taus);
00205 product_Neutrina->push_back(Neutrino);
00206 }
00207 }
00208 else if (tauDecayMode == kOther)
00209 {
00210 if((abs(Visible_Taus.eta())<etaMax)&&(Visible_Taus.pt()>ptMinMCTau_)) {
00211 product_Other->push_back(Visible_Taus);
00212 }
00213 }
00214 }
00215 }
00216 }
00217
00218 }
00219 }
00220 iEvent.put(product_Leptons,"LeptonicTauLeptons");
00221 iEvent.put(product_Electrons,"LeptonicTauElectrons");
00222 iEvent.put(product_Muons,"LeptonicTauMuons");
00223 iEvent.put(product_OneProng,"HadronicTauOneProng");
00224 iEvent.put(product_ThreeProng,"HadronicTauThreeProng");
00225 iEvent.put(product_OneAndThreeProng,"HadronicTauOneAndThreeProng");
00226 iEvent.put(product_Other, "TauOther");
00227 iEvent.put(product_Neutrina,"Neutrina");
00228
00229
00230 }
00231
00232
00233 std::vector<reco::GenParticle*> HLTTauMCProducer::getGenStableDecayProducts(const reco::GenParticle* particle)
00234 {
00235 std::vector<GenParticle*> decayProducts;
00236 decayProducts.clear();
00237
00238
00239 for ( GenParticle::const_iterator daughter_particle = (*particle).begin();daughter_particle != (*particle).end(); ++daughter_particle ){
00240
00241 int pdg_id = abs((*daughter_particle).pdgId());
00242
00243
00244 if ( pdg_id == 11 || pdg_id == 12 || pdg_id == 13 || pdg_id == 14 || pdg_id == 16 || pdg_id == 111 || pdg_id == 211 ){
00245
00246 decayProducts.push_back((reco::GenParticle*) &(* daughter_particle));
00247 }
00248 else {
00249
00250 std::vector<GenParticle*> addDecayProducts = getGenStableDecayProducts((reco::GenParticle*) &(*daughter_particle));
00251 for ( std::vector<GenParticle*>::const_iterator adddaughter_particle = addDecayProducts.begin(); adddaughter_particle != addDecayProducts.end(); ++adddaughter_particle ){
00252 decayProducts.push_back((*adddaughter_particle));
00253 }
00254 }
00255 }
00256 return decayProducts;
00257 }