CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/Validation/EventGenerator/plugins/TauValidation.cc

Go to the documentation of this file.
00001 /*class TauValidation
00002  *  
00003  *  Class to fill dqm monitor elements from existing EDM file
00004  *
00005  *  $Date: 2010/12/06 14:05:52 $
00006  *  $Revision: 1.5 $
00007  */
00008  
00009 #include "Validation/EventGenerator/interface/TauValidation.h"
00010 
00011 #include "CLHEP/Units/defs.h"
00012 #include "CLHEP/Units/PhysicalConstants.h"
00013 
00014 #include "DataFormats/Math/interface/LorentzVector.h"
00015 
00016 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
00017 
00018 using namespace edm;
00019 
00020 TauValidation::TauValidation(const edm::ParameterSet& iPSet):  
00021   hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection")),
00022   tauEtCut(iPSet.getParameter<double>("tauEtCutForRtau"))
00023 {    
00024   dbe = 0;
00025   dbe = edm::Service<DQMStore>().operator->();
00026 }
00027 
00028 TauValidation::~TauValidation() {}
00029 
00030 void TauValidation::beginJob()
00031 {
00032   if(dbe){
00034     dbe->setCurrentFolder("Generator/Tau");
00035     
00036     // Number of analyzed events
00037     nEvt = dbe->book1D("nEvt", "n analyzed Events", 1, 0., 1.);
00038 
00039     //Kinematics
00040     TauPt            = dbe->book1D("TauPt","Tau pT", 100 ,0,100);
00041     TauEta           = dbe->book1D("TauEta","Tau eta", 100 ,-2.5,2.5);
00042     TauProngs        = dbe->book1D("TauProngs","Tau n prongs", 7 ,0,7);
00043     TauDecayChannels = dbe->book1D("TauDecayChannels","Tau decay channels", 10 ,0,10);
00044         TauDecayChannels->setBinLabel(1+undetermined,"?");
00045         TauDecayChannels->setBinLabel(1+electron,"e");
00046         TauDecayChannels->setBinLabel(1+muon,"mu");
00047         TauDecayChannels->setBinLabel(1+pi,"#pi^{#pm}");
00048         TauDecayChannels->setBinLabel(1+pi1pi0,"#pi^{#pm}#pi^{0}");
00049         TauDecayChannels->setBinLabel(1+pinpi0,"#pi^{#pm}n#pi^{0}");
00050         TauDecayChannels->setBinLabel(1+tripi,"3#pi^{#pm}");
00051         TauDecayChannels->setBinLabel(1+tripinpi0,"3#pi^{#pm}n#pi^{0}");
00052         TauDecayChannels->setBinLabel(1+K,"K");
00053         TauDecayChannels->setBinLabel(1+stable,"Stable");
00054 
00055     TauMothers        = dbe->book1D("TauMothers","Tau mother particles", 10 ,0,10);
00056         TauMothers->setBinLabel(1+other,"?");
00057         TauMothers->setBinLabel(1+gamma,"#gamma");
00058         TauMothers->setBinLabel(1+Z,"Z");
00059         TauMothers->setBinLabel(1+W,"W");
00060         TauMothers->setBinLabel(1+HSM,"H_{SM}/h^{0}");
00061         TauMothers->setBinLabel(1+H0,"H^{0}");
00062         TauMothers->setBinLabel(1+A0,"A^{0}");
00063         TauMothers->setBinLabel(1+Hpm,"H^{#pm}");
00064 
00065     TauRtauW          = dbe->book1D("TauRtauW","W->Tau p(leading track)/E(visible tau)", 50 ,0,1);
00066         TauRtauW->setAxisTitle("rtau");
00067     TauRtauHpm        = dbe->book1D("TauRtauHpm","Hpm->Tau p(leading track)/E(visible tau)", 50 ,0,1);
00068         TauRtauHpm->setAxisTitle("rtau");
00069     TauSpinEffectsW   = dbe->book1D("TauSpinEffectsW","Pion energy in W rest frame", 50 ,0,1);
00070         TauSpinEffectsW->setAxisTitle("Energy");
00071     TauSpinEffectsHpm = dbe->book1D("TauSpinEffectsHpm","Pion energy in Hpm rest frame", 50 ,0,1);
00072         TauSpinEffectsHpm->setAxisTitle("Energy");
00073 
00074     TauPhotons        = dbe->book1D("TauPhoton","Photons radiating from tau", 2 ,0,2);
00075         TauPhotons->setBinLabel(1,"Fraction of taus radiating photons");
00076         TauPhotons->setBinLabel(2,"Fraction of tau pt radiated by photons");
00077   }
00078 
00079   nTaus              = 0;
00080   nTausWithPhotons   = 0;
00081   tauPtSum           = 0;
00082   photonFromTauPtSum = 0;
00083 
00084   return;
00085 }
00086 
00087 void TauValidation::endJob(){
00088   return;
00089 }
00090 
00091 void TauValidation::beginRun(const edm::Run& iRun,const edm::EventSetup& iSetup)
00092 {
00094   iSetup.getData( fPDGTable );
00095   return;
00096 }
00097 void TauValidation::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){return;}
00098 void TauValidation::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00099 { 
00100   
00102   edm::Handle<HepMCProduct> evt;
00103   iEvent.getByLabel(hepmcCollection_, evt);
00104 
00105   //Get EVENT
00106   HepMC::GenEvent *myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
00107 
00108   nEvt->Fill(0.5);
00109 
00110   // find taus
00111   for(HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin(); iter != myGenEvent->particles_end(); ++iter) {
00112     if((*iter)->status()==3) {
00113       if(abs((*iter)->pdg_id())==15){
00114         TauPt->Fill((*iter)->momentum().perp());
00115         TauEta->Fill((*iter)->momentum().eta());
00116         int mother  = tauMother(*iter);
00117         int decaychannel = tauDecayChannel(*iter);
00118         tauProngs(*iter);
00119         rtau(*iter,mother,decaychannel);
00120         spinEffects(*iter,mother,decaychannel);
00121         photons(*iter);
00122       }
00123     }
00124   }
00125 
00126   delete myGenEvent;
00127 }//analyze
00128 
00129 int TauValidation::tauMother(const HepMC::GenParticle* tau){
00130         int mother_pid = 0;
00131 
00132         if ( tau->production_vertex() ) {
00133                 HepMC::GenVertex::particle_iterator mother;
00134                 for (mother = tau->production_vertex()->particles_begin(HepMC::parents);
00135                      mother!= tau->production_vertex()->particles_end(HepMC::parents); ++mother ) {
00136                         mother_pid = (*mother)->pdg_id();
00137                         //std::cout << " parent " << mother_pid << std::endl;
00138                 }
00139         }
00140 
00141         int label = other;
00142         if(abs(mother_pid) == 24) label = W;
00143         if(abs(mother_pid) == 23) label = Z;
00144         if(abs(mother_pid) == 22) label = gamma;
00145         if(abs(mother_pid) == 25) label = HSM;
00146         if(abs(mother_pid) == 35) label = H0;
00147         if(abs(mother_pid) == 36) label = A0;
00148         if(abs(mother_pid) == 37) label = Hpm;
00149 
00150         TauMothers->Fill(label);
00151 
00152         return mother_pid;
00153 }
00154 
00155 int TauValidation::tauProngs(const HepMC::GenParticle* tau){
00156 
00157         int nProngs = 0;
00158         if ( tau->end_vertex() ) {
00159                 HepMC::GenVertex::particle_iterator des;
00160                 for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00161                     des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00162                         int pid = (*des)->pdg_id();
00163                         if(abs(pid) == 15) return tauProngs(*des);
00164                         if((*des)->status() != 1) continue; // dont count unstable particles
00165 
00166                         const HepPDT::ParticleData*  pd = fPDGTable->particle((*des)->pdg_id ());
00167                         int charge = (int) pd->charge();
00168                         if(charge == 0) continue;
00169                         //std::cout << "TauValidation::tauProngs barcode=" << (*des)->barcode() << " pid=" 
00170                         //          << pid << " mom=" << tauMother(*des) << " status=" 
00171                         //          << (*des)->status() << " charge=" << charge << std::endl;
00172                         nProngs++;
00173                 }
00174         }
00175         TauProngs->Fill(nProngs);
00176         return nProngs;
00177 }
00178 
00179 int TauValidation::tauDecayChannel(const HepMC::GenParticle* tau){
00180 
00181         int channel = undetermined;
00182         if(tau->status() == 1) channel = stable;
00183 
00184         int eCount   = 0,
00185             muCount  = 0,
00186             pi0Count = 0,
00187             piCount  = 0;
00188 
00189         if ( tau->end_vertex() ) {
00190               HepMC::GenVertex::particle_iterator des;
00191               for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00192                   des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00193 
00194                         //if(abs(tauMother(*des)) != 15) continue;
00195                         int pid = (*des)->pdg_id();
00196                         //std::cout << " barcode=" << (*des)->barcode() << " pid="
00197                         //          << pid << " mom=" << tauMother(*des) << " status="
00198                         //          << (*des)->status() << std::endl;
00199 
00200                         if(abs(pid) == 15) return tauDecayChannel(*des);
00201 
00202                         if(abs(pid) == 11)  eCount++;
00203                         if(abs(pid) == 13)  muCount++;
00204                         if(abs(pid) == 111) pi0Count++;
00205                         if(abs(pid) == 211) piCount++; 
00206 
00207                 }
00208         }
00209 
00210         if(piCount == 1 && pi0Count == 0) channel = pi;
00211         if(piCount == 1 && pi0Count == 1)  channel = pi1pi0;
00212         if(piCount == 1 && pi0Count > 1)  channel = pinpi0;
00213 
00214         if(piCount == 3 && pi0Count == 0) channel = tripi;
00215         if(piCount == 3 && pi0Count > 0)  channel = tripinpi0;
00216 
00217         if(eCount == 1)                   channel = electron;
00218         if(muCount == 1)                  channel = muon;
00219 
00220         TauDecayChannels->Fill(channel);
00221         return channel;
00222 }
00223 
00224 void TauValidation::rtau(const HepMC::GenParticle* tau,int mother, int decay){
00225 
00226         if(decay != pi1pi0) return; // polarization only for 1-prong hadronic taus with one neutral pion to make a clean case
00227 
00228         if(tau->momentum().perp() < tauEtCut) return; // rtau visible only for boosted taus
00229         
00230         double rTau = 0;
00231         double ltrack = leadingPionMomentum(tau);
00232         double visibleTauE = visibleTauEnergy(tau);
00233 
00234         if(visibleTauE != 0) rTau = ltrack/visibleTauE;
00235 
00236         if(abs(mother) == 23) TauRtauW->Fill(rTau);
00237         if(abs(mother) == 37) TauRtauHpm->Fill(rTau); 
00238 }
00239 
00240 void TauValidation::spinEffects(const HepMC::GenParticle* tau,int mother, int decay){
00241 
00242         if(decay != pi) return; // polarization only for 1-prong hadronic taus with no neutral pions
00243 
00244         TLorentzVector momP4 = motherP4(tau);
00245         TLorentzVector pionP4 = leadingPionP4(tau);
00246 
00247         pionP4.Boost(-1*momP4.BoostVector());
00248 
00249         double energy = pionP4.E()/(momP4.M()/2);
00250 
00251         if(abs(mother) == 23) TauSpinEffectsW->Fill(energy);    
00252         if(abs(mother) == 37) TauSpinEffectsHpm->Fill(energy);
00253 }
00254 
00255 double TauValidation::leadingPionMomentum(const HepMC::GenParticle* tau){
00256         return leadingPionP4(tau).P();
00257 }
00258 
00259 TLorentzVector TauValidation::leadingPionP4(const HepMC::GenParticle* tau){
00260 
00261         TLorentzVector p4(0,0,0,0);
00262 
00263         if ( tau->end_vertex() ) {
00264               HepMC::GenVertex::particle_iterator des;
00265               for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00266                   des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00267                         int pid = (*des)->pdg_id();
00268 
00269                         if(abs(pid) == 15) return leadingPionP4(*des);
00270 
00271                         if(abs(pid) != 211) continue;
00272  
00273                         if((*des)->momentum().rho() > p4.P()) {
00274                                 p4 = TLorentzVector((*des)->momentum().px(),
00275                                                     (*des)->momentum().py(),
00276                                                     (*des)->momentum().pz(),
00277                                                     (*des)->momentum().e());
00278                         } 
00279                 }
00280         }
00281 
00282         return p4;
00283 }
00284 
00285 TLorentzVector TauValidation::motherP4(const HepMC::GenParticle* tau){
00286 
00287         TLorentzVector p4(0,0,0,0);
00288 
00289         if ( tau->production_vertex() ) {
00290                 HepMC::GenVertex::particle_iterator mother;
00291                 for (mother = tau->production_vertex()->particles_begin(HepMC::parents);
00292                      mother!= tau->production_vertex()->particles_end(HepMC::parents); ++mother ) {
00293                         //mother_pid = (*mother)->pdg_id();
00294                         //std::cout << " parent " << mother_pid << std::endl;
00295                         p4 = TLorentzVector((*mother)->momentum().px(),
00296                                             (*mother)->momentum().py(),
00297                                             (*mother)->momentum().pz(),
00298                                             (*mother)->momentum().e());
00299                 }
00300         }
00301 
00302         return p4;
00303 }
00304 
00305 double TauValidation::visibleTauEnergy(const HepMC::GenParticle* tau){
00306         TLorentzVector p4(tau->momentum().px(),
00307                           tau->momentum().py(),
00308                           tau->momentum().pz(),
00309                           tau->momentum().e());
00310 
00311         if ( tau->end_vertex() ) {
00312               HepMC::GenVertex::particle_iterator des;
00313               for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00314                   des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00315                         int pid = (*des)->pdg_id();
00316 
00317                         if(abs(pid) == 15) return visibleTauEnergy(*des);
00318 
00319                         if(abs(pid) == 12 || abs(pid) == 14 || abs(pid) == 16) {
00320                                 p4 -= TLorentzVector((*des)->momentum().px(),
00321                                                      (*des)->momentum().py(),
00322                                                      (*des)->momentum().pz(),
00323                                                      (*des)->momentum().e());
00324                         }
00325                 }
00326         }
00327 
00328         return p4.E();
00329 }
00330 
00331 void TauValidation::photons(const HepMC::GenParticle* tau){
00332 
00333         if ( tau->end_vertex() ) {
00334               bool photonFromTau = false;
00335               HepMC::GenVertex::particle_iterator des;
00336               for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00337                   des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00338                         int pid = (*des)->pdg_id();
00339                         if(pid == 22) {
00340                                 photonFromTauPtSum += (*des)->momentum().perp();
00341                                 photonFromTau = true;
00342                         } 
00343               }
00344               nTaus++;
00345               if(photonFromTau) {
00346                 tauPtSum += tau->momentum().perp();
00347                 nTausWithPhotons++;
00348               }
00349 
00350               double nFrac = double(nTausWithPhotons)/nTaus;
00351               double ptFrac = 0;
00352               if(tauPtSum > 0) ptFrac = photonFromTauPtSum/tauPtSum;
00353 
00354               TauPhotons->setBinContent(1,nFrac);
00355               TauPhotons->setBinContent(2,ptFrac);
00356         }
00357 }
00358