CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/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: 2012/11/13 12:33:29 $
00006  *  $Revision: 1.22 $
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 #include "Validation/EventGenerator/interface/TauDecay_CMSSW.h"
00018 #include "Validation/EventGenerator/interface/PdtPdgMini.h"
00019 
00020 using namespace edm;
00021 
00022 TauValidation::TauValidation(const edm::ParameterSet& iPSet): 
00023   _wmanager(iPSet)
00024   ,hepmcCollection_(iPSet.getParameter<edm::InputTag>("hepmcCollection"))
00025   ,tauEtCut(iPSet.getParameter<double>("tauEtCutForRtau"))
00026   ,NJAKID(22)
00027 {    
00028   dbe = 0;
00029   dbe = edm::Service<DQMStore>().operator->();
00030 }
00031 
00032 TauValidation::~TauValidation() {}
00033 
00034 void TauValidation::beginJob()
00035 {
00036   if(dbe){
00038     dbe->setCurrentFolder("Generator/Tau");
00039     
00040     // Number of analyzed events
00041     nTaus = dbe->book1D("nTaus", "n analyzed Taus", 1, 0., 1.);
00042     nPrimeTaus = dbe->book1D("nPrimeTaus", "n analyzed prime Taus", 1, 0., 1.);
00043 
00044     //Kinematics
00045     TauPt            = dbe->book1D("TauPt","Tau pT", 100 ,0,100);
00046     TauEta           = dbe->book1D("TauEta","Tau eta", 100 ,-2.5,2.5);
00047     TauPhi           = dbe->book1D("TauPhi","Tau phi", 100 ,-3.14,3.14);
00048     TauProngs        = dbe->book1D("TauProngs","Tau n prongs", 7 ,0,7);
00049     TauDecayChannels = dbe->book1D("TauDecayChannels","Tau decay channels", 13 ,0,13);
00050         TauDecayChannels->setBinLabel(1+undetermined,"?");
00051         TauDecayChannels->setBinLabel(1+electron,"e");
00052         TauDecayChannels->setBinLabel(1+muon,"mu");
00053         TauDecayChannels->setBinLabel(1+pi,"#pi^{#pm}");
00054         TauDecayChannels->setBinLabel(1+rho,"#rho^{#pm}");
00055         TauDecayChannels->setBinLabel(1+a1,"a_{1}^{#pm}");
00056         TauDecayChannels->setBinLabel(1+pi1pi0,"#pi^{#pm}#pi^{0}");
00057         TauDecayChannels->setBinLabel(1+pinpi0,"#pi^{#pm}n#pi^{0}");
00058         TauDecayChannels->setBinLabel(1+tripi,"3#pi^{#pm}");
00059         TauDecayChannels->setBinLabel(1+tripinpi0,"3#pi^{#pm}n#pi^{0}");
00060         TauDecayChannels->setBinLabel(1+K,"K");
00061         TauDecayChannels->setBinLabel(1+Kstar,"K^{*}");
00062         TauDecayChannels->setBinLabel(1+stable,"Stable");
00063 
00064     TauMothers        = dbe->book1D("TauMothers","Tau mother particles", 10 ,0,10);
00065         TauMothers->setBinLabel(1+other,"?");
00066         TauMothers->setBinLabel(1+B,"B Decays");
00067         TauMothers->setBinLabel(1+D,"D Decays");
00068         TauMothers->setBinLabel(1+gamma,"#gamma");
00069         TauMothers->setBinLabel(1+Z,"Z");
00070         TauMothers->setBinLabel(1+W,"W");
00071         TauMothers->setBinLabel(1+HSM,"H_{SM}/h^{0}");
00072         TauMothers->setBinLabel(1+H0,"H^{0}");
00073         TauMothers->setBinLabel(1+A0,"A^{0}");
00074         TauMothers->setBinLabel(1+Hpm,"H^{#pm}");
00075 
00076     TauRtauW          = dbe->book1D("TauRtauW","W->Tau p(leading track)/E(visible tau)", 50 ,0,1);
00077         TauRtauW->setAxisTitle("rtau");
00078     TauRtauHpm        = dbe->book1D("TauRtauHpm","Hpm->Tau p(leading track)/E(visible tau)", 50 ,0,1);
00079         TauRtauHpm->setAxisTitle("rtau");
00080     TauSpinEffectsW   = dbe->book1D("TauSpinEffectsW","Pion energy in W rest frame", 50 ,0,1);
00081         TauSpinEffectsW->setAxisTitle("Energy");
00082     TauSpinEffectsHpm = dbe->book1D("TauSpinEffectsHpm","Pion energy in Hpm rest frame", 50 ,0,1);
00083         TauSpinEffectsHpm->setAxisTitle("Energy");
00084     TauSpinEffectsZ   = dbe->book1D("TauSpinEffectsZ","Mass of pi+ pi-", 22 ,0,1.1);
00085     TauSpinEffectsZ->setAxisTitle("M_{#pi^{+}#pi^{-}}");
00086 
00087     TauFSRPhotonsN=dbe->book1D("TauFSRPhotonsN","FSR Photons radiating from/with tau (Gauge Boson)", 5 ,-0.5,4.5);
00088     TauFSRPhotonsN->setAxisTitle("N FSR Photons radiating from/with tau");
00089     TauFSRPhotonsPt=dbe->book1D("TauFSRPhotonsPt","Pt of FSR Photons radiating from/with tau (Gauge Boson)", 100 ,0,100);
00090     TauFSRPhotonsPt->setAxisTitle("P_{t} of FSR Photons radiating from/with tau [per tau]");
00091     TauFSRPhotonsPtSum=dbe->book1D("TauFSRPhotonsPtSum","Pt of FSR Photons radiating from/with tau (Gauge Boson)", 100 ,0,100);
00092     TauFSRPhotonsPtSum->setAxisTitle("P_{t} of FSR Photons radiating from/with tau [per tau]");
00093 
00094     TauBremPhotonsN=dbe->book1D("TauBremPhotonsN","Brem. Photons radiating in tau decay", 5 ,-0.5,4.5);
00095     TauBremPhotonsN->setAxisTitle("N FSR Photons radiating from/with tau");
00096     TauBremPhotonsPt=dbe->book1D("TauBremPhotonsPt","Sum Brem Pt ", 100 ,0,100);
00097     TauFSRPhotonsPt->setAxisTitle("P_{t} of Brem. Photons radiating in tau decay");    
00098     TauBremPhotonsPtSum =dbe->book1D("TauBremPhotonsPtSum","Sum of Brem Pt ", 100 ,0,100);
00099     TauFSRPhotonsPtSum->setAxisTitle("Sum P_{t} of Brem. Photons radiating in tau decay");
00100 
00101     JAKID =dbe->book1D("JAKID","JAK ID",NJAKID+1,-0.5,NJAKID+0.5);
00102     for(unsigned int i=0; i<NJAKID+1;i++){
00103       JAKInvMass.push_back(std::vector<MonitorElement *>());
00104       TString tmp="JAKID";
00105       tmp+=i;
00106       JAKInvMass.at(i).push_back(dbe->book1D("M"+tmp,"M_{"+tmp+"} (GeV)", 80 ,0,2.0));
00107       if(i==TauDecay::JAK_A1_3PI ||
00108          i==TauDecay::JAK_KPIK ||
00109          i==TauDecay::JAK_KPIPI ){
00110         JAKInvMass.at(i).push_back(dbe->book1D("M13"+tmp,"M_{13,"+tmp+"} (GeV)", 80 ,0,2.0));
00111         JAKInvMass.at(i).push_back(dbe->book1D("M23"+tmp,"M_{23,"+tmp+"} (GeV)", 80 ,0,2.0));
00112         JAKInvMass.at(i).push_back(dbe->book1D("M12"+tmp,"M_{12,"+tmp+"} (GeV)", 80 ,0,2.0));
00113       }
00114     }
00115   }
00116   
00117   return;
00118 }
00119 
00120 void TauValidation::endJob(){
00121   return;
00122 }
00123 
00124 void TauValidation::beginRun(const edm::Run& iRun,const edm::EventSetup& iSetup)
00125 {
00127   iSetup.getData( fPDGTable );
00128   return;
00129 }
00130 void TauValidation::endRun(const edm::Run& iRun,const edm::EventSetup& iSetup){return;}
00131 void TauValidation::analyze(const edm::Event& iEvent,const edm::EventSetup& iSetup)
00132 { 
00133   
00135   edm::Handle<HepMCProduct> evt;
00136   iEvent.getByLabel(hepmcCollection_, evt);
00137 
00138   //Get EVENT
00139   HepMC::GenEvent *myGenEvent = new HepMC::GenEvent(*(evt->GetEvent()));
00140 
00141   double weight = _wmanager.weight(iEvent);
00142 
00143   // find taus
00144   for(HepMC::GenEvent::particle_const_iterator iter = myGenEvent->particles_begin(); iter != myGenEvent->particles_end(); iter++) {
00145     if(abs((*iter)->pdg_id())==23){
00146       spinEffectsZ(*iter,weight);
00147     }
00148     if(abs((*iter)->pdg_id())==15){
00149       if(isLastTauinChain(*iter)){
00150         nTaus->Fill(0.5,weight);
00151         int mother  = tauMother(*iter,weight);
00152         int decaychannel = tauDecayChannel(*iter,weight);
00153         tauProngs(*iter, weight);
00154         if(mother>-1){ // exclude B, D and other non-signal decay modes
00155           nPrimeTaus->Fill(0.5,weight);
00156           TauPt->Fill((*iter)->momentum().perp(),weight);
00157           TauEta->Fill((*iter)->momentum().eta(),weight);
00158           TauPhi->Fill((*iter)->momentum().phi(),weight);
00159           rtau(*iter,mother,decaychannel,weight);
00160           spinEffects(*iter,mother,decaychannel,weight);
00161           photons(*iter,weight);
00162         }
00164         //Adding JAKID and Mass information
00165         //
00166         TauDecay_CMSSW TD;
00167         unsigned int jak_id, TauBitMask;
00168         TD.AnalyzeTau((*iter),jak_id,TauBitMask,false,false);
00169         JAKID->Fill(jak_id,weight);
00170         if(jak_id<=NJAKID){
00171           int tcharge=(*iter)->pdg_id()/abs((*iter)->pdg_id());
00172           std::vector<HepMC::GenParticle*> part=TD.Get_TauDecayProducts();
00173           TLorentzVector LVQ(0,0,0,0);
00174           TLorentzVector LVS12(0,0,0,0);
00175           TLorentzVector LVS13(0,0,0,0);
00176           TLorentzVector LVS23(0,0,0,0);
00177           bool haspart1=false;
00178           for(unsigned int i=0;i<part.size();i++){
00179             if(TD.isTauFinalStateParticle(part.at(i)->pdg_id()) &&
00180                abs(part.at(i)->pdg_id())!=PdtPdgMini::nu_e &&
00181              abs(part.at(i)->pdg_id())!=PdtPdgMini::nu_mu &&
00182                abs(part.at(i)->pdg_id())!=PdtPdgMini::nu_tau ){
00183               TLorentzVector LV(part.at(i)->momentum().px(),part.at(i)->momentum().py(),part.at(i)->momentum().pz(),part.at(i)->momentum().e());
00184               LVQ+=LV;
00185               if(jak_id==TauDecay::JAK_A1_3PI ||
00186                  jak_id==TauDecay::JAK_KPIK ||
00187                  jak_id==TauDecay::JAK_KPIPI
00188                  ){
00189                 if((tcharge==part.at(i)->pdg_id()/abs(part.at(i)->pdg_id()) && TD.nProng(TauBitMask)==3) || (jak_id==TauDecay::JAK_A1_3PI && TD.nProng(TauBitMask)==1 && abs(part.at(i)->pdg_id())==PdtPdgMini::pi_plus) ){
00190                   LVS13+=LV;
00191                   LVS23+=LV;
00192                 }
00193                 else{
00194                   LVS12+=LV;
00195                   if(!haspart1 && ((jak_id==TauDecay::JAK_A1_3PI)  || (jak_id!=TauDecay::JAK_A1_3PI && abs(part.at(i)->pdg_id())==PdtPdgMini::K_plus) )){
00196                     LVS13+=LV;
00197                     haspart1=true;
00198                   }
00199                   else{
00200                     LVS23+=LV;
00201                   }
00202                 }
00203               }
00204             }
00205           }
00206           part.clear();
00207           JAKInvMass.at(jak_id).at(0)->Fill(LVQ.M(),weight);
00208           if(jak_id==TauDecay::JAK_A1_3PI ||
00209              jak_id==TauDecay::JAK_KPIK ||
00210              jak_id==TauDecay::JAK_KPIPI
00211              ){
00212             JAKInvMass.at(jak_id).at(1)->Fill(LVS13.M(),weight);
00213             JAKInvMass.at(jak_id).at(2)->Fill(LVS23.M(),weight);
00214             JAKInvMass.at(jak_id).at(3)->Fill(LVS12.M(),weight);
00215           }
00216         }
00217       }
00218     }
00219   }
00220   delete myGenEvent;
00221 }//analyze
00222 
00223 const HepMC::GenParticle* TauValidation::GetMother(const HepMC::GenParticle* tau){
00224   if ( tau->production_vertex() ) {
00225     HepMC::GenVertex::particle_iterator mother;
00226     for (mother = tau->production_vertex()->particles_begin(HepMC::parents); mother!= tau->production_vertex()->particles_end(HepMC::parents); mother++ ) {
00227       if((*mother)->pdg_id() == tau->pdg_id()) return GetMother(*mother);
00228       return (*mother);
00229     }
00230   }
00231   return tau;
00232 }
00233 
00234 int TauValidation::findMother(const HepMC::GenParticle* tau){
00235   int mother_pid = 0;
00236   if ( tau->production_vertex() ) {
00237     HepMC::GenVertex::particle_iterator mother;
00238     for (mother = tau->production_vertex()->particles_begin(HepMC::parents); mother!= tau->production_vertex()->particles_end(HepMC::parents); mother++ ) {
00239       mother_pid = (*mother)->pdg_id();
00240       if(mother_pid == tau->pdg_id()) return findMother(*mother); //mother_pid = -1; Make recursive to look for last tau in chain
00241     }
00242   }
00243   return mother_pid;
00244 }
00245 
00246 
00247 bool TauValidation::isLastTauinChain(const HepMC::GenParticle* tau){
00248   if ( tau->end_vertex() ) {
00249     HepMC::GenVertex::particle_iterator dau;
00250     for (dau = tau->end_vertex()->particles_begin(HepMC::children); dau!= tau->end_vertex()->particles_end(HepMC::children); dau++ ) {
00251       int dau_pid = (*dau)->pdg_id();
00252       if(dau_pid == tau->pdg_id()) return false;
00253     }
00254   }
00255   return true;
00256 }
00257 
00258 
00259 void TauValidation::findTauList(const HepMC::GenParticle* tau,std::vector<const HepMC::GenParticle*> &TauList){
00260   TauList.insert(TauList.begin(),tau);
00261   if ( tau->production_vertex() ) {
00262     HepMC::GenVertex::particle_iterator mother;
00263     for (mother = tau->production_vertex()->particles_begin(HepMC::parents); mother!= tau->production_vertex()->particles_end(HepMC::parents);mother++) {
00264       if((*mother)->pdg_id() == tau->pdg_id()){
00265         findTauList(*mother,TauList);
00266       }
00267     }
00268   }
00269 }
00270 
00271 void TauValidation::findFSRandBrem(const HepMC::GenParticle* p, bool doBrem, std::vector<const HepMC::GenParticle*> &ListofFSR,
00272                                   std::vector<const HepMC::GenParticle*> &ListofBrem){
00273   // note this code split the FSR and Brem based one if the tau decays into a tau+photon or not with the Fortran Tauola Interface, this is not 100% correct because photos puts the tau with the regular tau decay products. 
00274   if(abs(p->pdg_id())==15){
00275     if(isLastTauinChain(p)){ doBrem=true;}
00276     else{ doBrem=false;}
00277   }
00278     int photo_ID=22;
00279   if ( p->end_vertex() ) {
00280     HepMC::GenVertex::particle_iterator dau;
00281     for (dau = p->end_vertex()->particles_begin(HepMC::children); dau!= p->end_vertex()->particles_end(HepMC::children); dau++ ) {
00282       //if(doBrem) std::cout << "true " << (*dau)->pdg_id() << " "  << std::endl;
00283       //else std::cout << "false " << (*dau)->pdg_id() << " " << std::endl;
00284       if(abs((*dau)->pdg_id()) == abs(photo_ID) && !doBrem){ListofFSR.push_back(*dau);}
00285       if(abs((*dau)->pdg_id()) == abs(photo_ID) && doBrem){ListofBrem.push_back(*dau);}
00286       if((*dau)->end_vertex() && (*dau)->end_vertex()->particles_out_size()>0 && abs((*dau)->pdg_id()) != 111 && abs((*dau)->pdg_id()) != 221/* remove pi0 and eta decays*/){
00287         findFSRandBrem(*dau,doBrem,ListofFSR,ListofBrem);
00288       }
00289     }
00290   }
00291 }
00292 
00293 
00294 
00295 void TauValidation::FindPhotosFSR(const HepMC::GenParticle* p,std::vector<const HepMC::GenParticle*> &ListofFSR,double &BosonScale){
00296   BosonScale=0.0;
00297   const HepMC::GenParticle* m=GetMother(p);
00298   double mother_pid=m->pdg_id();
00299   if(m->end_vertex() && mother_pid!=p->pdg_id()){
00300     HepMC::GenVertex::particle_iterator dau;
00301     for (dau = m->end_vertex()->particles_begin(HepMC::children); dau!= m->end_vertex()->particles_end(HepMC::children); dau++ ) {
00302       int dau_pid = (*dau)->pdg_id();
00303       if(fabs(dau_pid) == 22) {
00304         ListofFSR.push_back(*dau);
00305       }
00306     }
00307   }
00308   if(abs(mother_pid) == 24) BosonScale=1.0; // W
00309   if(abs(mother_pid) == 23) BosonScale=2.0; // Z;
00310   if(abs(mother_pid) == 22) BosonScale=2.0; // gamma;
00311   if(abs(mother_pid) == 25) BosonScale=2.0; // HSM;
00312   if(abs(mother_pid) == 35) BosonScale=2.0; // H0;
00313   if(abs(mother_pid) == 36) BosonScale=2.0; // A0;
00314   if(abs(mother_pid) == 37) BosonScale=1.0; //Hpm;
00315 }
00316 
00317 
00318 int TauValidation::tauMother(const HepMC::GenParticle* tau, double weight){
00319 
00320   if(abs(tau->pdg_id()) != 15 ) return -3;
00321   
00322   int mother_pid = findMother(tau);
00323   if(mother_pid == -2) return -2;
00324   
00325   int label = other;
00326   if(abs(mother_pid) == 24) label = W;
00327   if(abs(mother_pid) == 23) label = Z;
00328   if(abs(mother_pid) == 22) label = gamma;
00329   if(abs(mother_pid) == 25) label = HSM;
00330   if(abs(mother_pid) == 35) label = H0;
00331   if(abs(mother_pid) == 36) label = A0;
00332   if(abs(mother_pid) == 37) label = Hpm;
00333   
00334   int mother_shortpid=(abs(mother_pid)%10000);
00335   if(mother_shortpid>500 && mother_shortpid<600 )label = B;
00336   if(mother_shortpid>400 && mother_shortpid<500)label = D;
00337   TauMothers->Fill(label,weight);
00338   if(label==B || label == D || label == other) return -1;
00339   
00340   return mother_pid;
00341 }
00342 
00343 int TauValidation::tauProngs(const HepMC::GenParticle* tau, double weight){
00344   int nProngs = 0;
00345   if ( tau->end_vertex() ) {
00346     HepMC::GenVertex::particle_iterator des;
00347     for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00348         des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00349       int pid = (*des)->pdg_id();
00350       if(abs(pid) == 15) return tauProngs(*des, weight);
00351       if((*des)->status() != 1) continue; // dont count unstable particles
00352       
00353       const HepPDT::ParticleData*  pd = fPDGTable->particle((*des)->pdg_id ());
00354       int charge = (int) pd->charge();
00355       if(charge == 0) continue;
00356       nProngs++;
00357     }
00358   }
00359   TauProngs->Fill(nProngs,weight);
00360   return nProngs;
00361 }
00362 
00363 int TauValidation::tauDecayChannel(const HepMC::GenParticle* tau, double weight){
00364 
00365   int channel = undetermined;
00366   if(tau->status() == 1) channel = stable;
00367   int allCount   = 0,
00368     eCount     = 0,
00369     muCount    = 0,
00370     pi0Count   = 0,
00371     piCount    = 0,
00372     rhoCount   = 0,
00373     a1Count    = 0,
00374     KCount     = 0,
00375     KstarCount = 0;
00376   
00377   if ( tau->end_vertex() ) {
00378     HepMC::GenVertex::particle_iterator des;
00379     for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00380         des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00381       int pid = (*des)->pdg_id();
00382       if(abs(pid) == 15) return tauDecayChannel(*des,weight);
00383       
00384       allCount++;
00385       if(abs(pid) == 11)    eCount++;
00386       if(abs(pid) == 13)    muCount++;
00387       if(abs(pid) == 111)   pi0Count++;
00388       if(abs(pid) == 211)   piCount++;
00389       if(abs(pid) == 213)   rhoCount++;
00390       if(abs(pid) == 20213) a1Count++;
00391       if(abs(pid) == 321)   KCount++;
00392       if(abs(pid) == 323)   KstarCount++;
00393       
00394     }
00395   }
00396   // resonances  
00397   if(KCount >= 1)     channel = K;
00398   if(KstarCount >= 1) channel = Kstar;
00399   if(a1Count >= 1)    channel = a1;
00400   if(rhoCount >= 1)   channel = rho;
00401   if(channel!=undetermined && weight!=0.0) TauDecayChannels->Fill(channel,weight);
00402   
00403   // final state products
00404   if(piCount == 1 && pi0Count == 0) channel = pi;
00405   if(piCount == 1 && pi0Count == 1) channel = pi1pi0;
00406   if(piCount == 1 && pi0Count > 1)  channel = pinpi0;
00407   if(piCount == 3 && pi0Count == 0) channel = tripi;
00408   if(piCount == 3 && pi0Count > 0)  channel = tripinpi0;
00409   if(eCount == 1)                   channel = electron;
00410   if(muCount == 1)                  channel = muon;
00411   if(weight!=0.0) TauDecayChannels->Fill(channel,weight);
00412   return channel;
00413 }
00414 
00415 
00416 void TauValidation::rtau(const HepMC::GenParticle* tau,int mother, int decay, double weight){
00417 
00418         if(decay != pi1pi0) return; // polarization only for 1-prong hadronic taus with one neutral pion to make a clean case
00419 
00420         if(tau->momentum().perp() < tauEtCut) return; // rtau visible only for boosted taus
00421         
00422         double rTau = 0;
00423         double ltrack = leadingPionMomentum(tau, weight);
00424         double visibleTauE = visibleTauEnergy(tau);
00425 
00426         if(visibleTauE != 0) rTau = ltrack/visibleTauE;
00427 
00428         if(abs(mother) == 24) TauRtauW->Fill(rTau,weight);
00429         if(abs(mother) == 37) TauRtauHpm->Fill(rTau,weight); 
00430 }
00431 
00432 void TauValidation::spinEffects(const HepMC::GenParticle* tau,int mother, int decay, double weight){
00433 
00434         if(decay != pi) return; // polarization only for 1-prong hadronic taus with no neutral pions
00435 
00436         TLorentzVector momP4 = motherP4(tau);
00437         TLorentzVector pionP4 = leadingPionP4(tau);
00438 
00439         pionP4.Boost(-1*momP4.BoostVector());
00440 
00441         double energy = pionP4.E()/(momP4.M()/2);
00442 
00443         if(abs(mother) == 24) TauSpinEffectsW->Fill(energy,weight);     
00444         if(abs(mother) == 37) TauSpinEffectsHpm->Fill(energy,weight);
00445 }
00446 
00447 void TauValidation::spinEffectsZ(const HepMC::GenParticle* boson, double weight){
00448 
00449   TLorentzVector tautau(0,0,0,0);
00450   TLorentzVector pipi(0,0,0,0);
00451   
00452   int nSinglePionDecays = 0;
00453   if ( boson->end_vertex() ) {
00454     HepMC::GenVertex::particle_iterator des;
00455     for(des = boson->end_vertex()->particles_begin(HepMC::descendants);
00456         des!= boson->end_vertex()->particles_end(HepMC::descendants);++des ) {
00457       
00458       int pid = (*des)->pdg_id();
00459       if(abs(findMother(*des)) != 15 &&
00460          abs(pid) == 15 && tauDecayChannel(*des) == pi){
00461         nSinglePionDecays++;
00462         tautau += TLorentzVector((*des)->momentum().px(),
00463                                  (*des)->momentum().py(),
00464                                  (*des)->momentum().pz(),
00465                                  (*des)->momentum().e());
00466         pipi += leadingPionP4(*des);
00467       }
00468     }
00469   }
00470   if(nSinglePionDecays == 2 && tautau.M() != 0) {
00471     TauSpinEffectsZ->Fill(pipi.M()/tautau.M(),weight);
00472   }
00473 }
00474 
00475 double TauValidation::leadingPionMomentum(const HepMC::GenParticle* tau, double weight){
00476         return leadingPionP4(tau).P();
00477 }
00478 
00479 TLorentzVector TauValidation::leadingPionP4(const HepMC::GenParticle* tau){
00480 
00481         TLorentzVector p4(0,0,0,0);
00482 
00483         if ( tau->end_vertex() ) {
00484               HepMC::GenVertex::particle_iterator des;
00485               for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00486                   des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00487                         int pid = (*des)->pdg_id();
00488 
00489                         if(abs(pid) == 15) return leadingPionP4(*des);
00490 
00491                         if(abs(pid) != 211) continue;
00492  
00493                         if((*des)->momentum().rho() > p4.P()) {
00494                                 p4 = TLorentzVector((*des)->momentum().px(),
00495                                                     (*des)->momentum().py(),
00496                                                     (*des)->momentum().pz(),
00497                                                     (*des)->momentum().e());
00498                         } 
00499                 }
00500         }
00501 
00502         return p4;
00503 }
00504 
00505 TLorentzVector TauValidation::motherP4(const HepMC::GenParticle* tau){
00506 
00507   TLorentzVector p4(0,0,0,0);
00508   
00509   if ( tau->production_vertex() ) {
00510     HepMC::GenVertex::particle_iterator mother;
00511     for (mother = tau->production_vertex()->particles_begin(HepMC::parents);
00512          mother!= tau->production_vertex()->particles_end(HepMC::parents); ++mother ) {
00513       p4 = TLorentzVector((*mother)->momentum().px(),
00514                           (*mother)->momentum().py(),
00515                           (*mother)->momentum().pz(),
00516                           (*mother)->momentum().e());
00517     }
00518   }
00519   
00520   return p4;
00521 }
00522 
00523 double TauValidation::visibleTauEnergy(const HepMC::GenParticle* tau){
00524         TLorentzVector p4(tau->momentum().px(),
00525                           tau->momentum().py(),
00526                           tau->momentum().pz(),
00527                           tau->momentum().e());
00528 
00529         if ( tau->end_vertex() ) {
00530               HepMC::GenVertex::particle_iterator des;
00531               for(des = tau->end_vertex()->particles_begin(HepMC::descendants);
00532                   des!= tau->end_vertex()->particles_end(HepMC::descendants);++des ) {
00533                         int pid = (*des)->pdg_id();
00534 
00535                         if(abs(pid) == 15) return visibleTauEnergy(*des);
00536 
00537                         if(abs(pid) == 12 || abs(pid) == 14 || abs(pid) == 16) {
00538                                 p4 -= TLorentzVector((*des)->momentum().px(),
00539                                                      (*des)->momentum().py(),
00540                                                      (*des)->momentum().pz(),
00541                                                      (*des)->momentum().e());
00542                         }
00543                 }
00544         }
00545 
00546         return p4.E();
00547 }
00548 
00549 void TauValidation::photons(const HepMC::GenParticle* tau, double weight){
00550   // Find First tau in chain
00551   std::vector<const HepMC::GenParticle*> TauList;
00552   findTauList(tau,TauList);
00553 
00554   // Get List of Gauge Boson to tau(s) FSR and Brem
00555   bool passedW=false;
00556   std::vector<const HepMC::GenParticle*> ListofFSR;  ListofFSR.clear();
00557   std::vector<const HepMC::GenParticle*> ListofBrem; ListofBrem.clear();
00558   std::vector<const HepMC::GenParticle*> FSR_photos; FSR_photos.clear();
00559   double BosonScale(1);
00560   if(TauList.size()>0){
00561     TauValidation::findFSRandBrem(TauList.at(0),passedW,ListofFSR,ListofBrem);
00562     TauValidation::FindPhotosFSR(TauList.at(0),FSR_photos,BosonScale);
00563 
00564     // Add the Tau Brem. information
00565     TauBremPhotonsN->Fill(ListofBrem.size(),weight);
00566     double photonPtSum=0;
00567     for(unsigned int i=0;i<ListofBrem.size();i++){
00568       photonPtSum+=ListofBrem.at(i)->momentum().perp();
00569       TauBremPhotonsPt->Fill(ListofBrem.at(i)->momentum().perp(),weight);
00570     }
00571     TauBremPhotonsPtSum->Fill(photonPtSum,weight);
00572         
00573     // Now add the Gauge Boson FSR information
00574     if(BosonScale!=0){
00575       TauFSRPhotonsN->Fill(ListofFSR.size(),weight);
00576       photonPtSum=0;
00577       for(unsigned int i=0;i<ListofFSR.size();i++){
00578         photonPtSum+=ListofFSR.at(i)->momentum().perp();
00579         TauFSRPhotonsPt->Fill(ListofFSR.at(i)->momentum().perp(),weight);
00580       }
00581       double FSR_photosSum(0);
00582       for(unsigned int i=0;i<FSR_photos.size();i++){
00583         FSR_photosSum+=FSR_photos.at(i)->momentum().perp();
00584         TauFSRPhotonsPt->Fill(FSR_photos.at(i)->momentum().perp()/BosonScale,weight*BosonScale);
00585       }
00586       TauFSRPhotonsPtSum->Fill(photonPtSum+FSR_photosSum/BosonScale,weight);
00587     }
00588   }
00589 }
00590