NtupleReader/src/MyTruthParticleManager.cxx

00001 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00002 // 07.12.2006, AUTHOR: MANFRED GROH
00003 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00004 
00005 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00006 //:: IMPLEMENTATION OF METHODS DEFINED IN THE CLASS MyTruthParticleManager ::
00007 //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
00008 
00009 //*****************************************************************************
00010 #include "NtupleReader/MyTruthParticleManager.h"
00011 
00012 //:::::::::::::::::::::::::
00013 //:: NAME SPACE SETTINGS ::
00014 //:::::::::::::::::::::::::
00015 
00016 using namespace std;
00017 
00018 
00019 bool MyTruthParticleManager::init(vector<MyParticle*> in_truth_particles){
00020     // temporary variable
00021 //    unsigned int tmp_barcode(0);
00022     // reset data
00023     n_of_decay_chains = 0;
00024     primary_intpart_0 = NULL;
00025     v_intpart_0_children_gen1.clear();
00026     vv_intpart_0_children_gen2.clear();
00027     primary_intpart_1 = NULL;
00028     v_intpart_1_children_gen1.clear();
00029     vv_intpart_1_children_gen2.clear();
00030         genstat_e=9999;
00031         genstat_mu=9999;
00032         genstat_tau=9999;
00033      
00034     // loop over given vector
00035     for (unsigned int i=0; i<in_truth_particles.size(); i++){
00036          // check if a barcode is stored twice
00037 /*
00038          tmp_barcode=(unsigned int)( (MyTruthParticle*)(in_truth_particles[i]))->barcode();
00039          if (getParticle_with_barcode(tmp_barcode)!=NULL){
00040              cerr<<"Error in MyTruthParticleManager::init"<<endl
00041                  <<"vector of TruthParticles contains barcode "
00042                  <<tmp_barcode<<" twice"<<endl;
00043              return false;
00044          }
00045 //*/
00046          // store the particle
00047          v_truth_particles.push_back( (MyTruthParticle*)(in_truth_particles[i]));
00048     }
00049     // return true if all particles were stored
00050     if (in_truth_particles.size()==v_truth_particles.size()){
00051         return true;
00052     }
00053     // return false otherwise
00054     else{
00055         cerr<<"Error in MyTruthParticleManager::init"<<endl;
00056         return false;
00057     }
00058 }
00059 //*****************************************************************************
00060 
00061 //:::::::::::::::::::::::::::::::::
00062 //:: METHOD set_generator ::
00063 //:::::::::::::::::::::::::::::::::
00064 
00065 void MyTruthParticleManager::set_generator(string gen){
00066         generator = gen;
00067     if (generator=="Alpgen"){
00068                 genstat_e = 1;
00069                 genstat_mu = 1;
00070                 genstat_tau = 195;
00071         }
00072         else if (generator=="Herwig"){
00073                 genstat_e = 1;
00074                 genstat_mu = 1;
00075                 genstat_tau = 195;
00076         }
00077         else if (generator=="Pythia"){
00078                 genstat_e = 1;
00079                 genstat_mu = 1;
00080                 genstat_tau = 2;
00081         }
00082         else if (generator=="McAtNlo"){
00083                 genstat_e = 1;
00084                 genstat_mu = 1;
00085                 genstat_tau = 195;
00086         }
00087         else if (generator=="Sherpa"){
00088                 genstat_e = 1;
00089                 genstat_mu = 1;
00090                 genstat_tau = 2; //has to be checked !!!
00091         }
00092         else {
00093                 cerr<<"ERROR: MyTruthParticleManager::set_generator:"<<endl
00094                 <<"Unknown Generator: "<<generator<<endl;
00095                 exit(1);
00096         }
00097 //* debug info */       cout<<"Set Genstats to:"<<endl
00098 //* debug info */           <<"e:   "<<genstat_e<<endl
00099 //* debug info */           <<"mu:  "<<genstat_mu<<endl
00100 //* debug info */           <<"tau: "<<genstat_tau<<endl;
00101                 
00102         
00103 }
00104 
00105 //*****************************************************************************
00106 
00107 //:::::::::::::::::::::::::::::::::
00108 //:: METHOD getParticles_with_ID ::
00109 //:::::::::::::::::::::::::::::::::
00110 
00111 vector<MyParticle*> MyTruthParticleManager::getParticles_with_ID(unsigned int pdgId) const {
00112         vector<MyParticle*> tmp_v;
00113         tmp_v.clear();
00114         
00115         // if given ID==0, return all particles
00116         if (pdgId==0){
00117                 for (unsigned int i=0; i<v_truth_particles.size(); i++){
00118                         tmp_v.push_back(v_truth_particles[i]);
00119                 }
00120                 return tmp_v;
00121         }
00122         
00123         // scan full truth info for the given ID
00124         for (unsigned int i=0; i<v_truth_particles.size(); i++){
00125                 if ( (unsigned int)TMath::Abs((v_truth_particles[i])->pdgId())==pdgId){
00126                         tmp_v.push_back(v_truth_particles[i]);
00127                 }
00128         }
00129         return tmp_v;
00130 }
00131 
00132 //*****************************************************************************
00133 
00134 //:::::::::::::::::::::::::::::::::::::
00135 //:: METHOD getParticle_with_barcode ::
00136 //:::::::::::::::::::::::::::::::::::::
00137 
00138 MyTruthParticle* MyTruthParticleManager::getParticle_with_barcode(unsigned int tmp_barcode) const {
00139     for (unsigned int i=0; i<v_truth_particles.size(); i++){
00140                 if ( (unsigned int)((v_truth_particles[i])->barcode())==tmp_barcode){
00141             return (v_truth_particles[i]);
00142         }
00143     }
00144     // if no particle with the given barcode found, return NULL
00145     return NULL;
00146 }
00147 
00148 //*****************************************************************************
00149 
00150 //:::::::::::::::::::::::
00151 //:: METHOD get_mother ::
00152 //:::::::::::::::::::::::
00153 
00154 MyTruthParticle* MyTruthParticleManager::get_mother(MyTruthParticle* truth_particle) const {
00155     int tmp_nParents(0);
00156     int tmp_barcode(0);
00157     MyTruthParticle* tmp_truth_part;
00158 
00159     // get number of parents
00160     tmp_nParents=truth_particle->nParents();
00161 
00162     // if number == 0, or >1 return NULL
00163     if (tmp_nParents==0 || tmp_nParents>1){
00164         return NULL;
00165     }
00166 
00167     // if number == 1, search for the barcode of the mother
00168     tmp_barcode=truth_particle->mother0_barcode();
00169     tmp_truth_part = getParticle_with_barcode(tmp_barcode);
00170     if (tmp_truth_part==NULL){
00171         //cerr<<"ERROR: Mother not found!"<<endl;
00172     }
00173     return tmp_truth_part;
00174 }
00175 
00176 //*****************************************************************************
00177 
00178 //:::::::::::::::::::::::::::::::
00179 //:: METHOD get_primary_mother ::
00180 //:::::::::::::::::::::::::::::::
00181 
00182 MyTruthParticle* MyTruthParticleManager::get_primary_mother(MyTruthParticle* truth_particle) const {
00183     // check number of parents
00184     // return particle itself if no mother, or more than 1 mother
00185     if (truth_particle->nParents()==0 || truth_particle->nParents()>1){
00186         return truth_particle;
00187     }
00188     // stop at a Higgs
00189     if (truth_particle->pdgId()==25){
00190         return truth_particle;
00191     }
00192 
00193 //* debug info */ cerr<<"truth_particle->pdgId()"<<truth_particle->pdgId()<<endl;
00194 //* debug info */ cerr<<""<<endl;
00195 //* debug info */ cerr<<""<<endl;
00196 
00197     // if number of parents equals 1, get mother particle
00198     MyTruthParticle* truth_particle2;
00199 //* debug info */ cerr<<"in MyTruthParticleManager::get_primary_mother: before get_mother"<<endl;
00200     truth_particle2 = get_mother(truth_particle);
00201     if (truth_particle2==NULL){
00202         //cerr<<"ERROR: Mother not found!"<<endl;
00203         return NULL;
00204     }
00205 //     // If mother is a quark: 
00206 //     if (TMath::Abs(truth_particle2->pdgId())<9){
00207 //         return truth_particle;
00208 //     }
00209 
00210 
00211 
00212     // call this routine recoursively with this particle
00213     // return output
00214     return get_primary_mother(truth_particle2);
00215 
00216 }
00217 
00218 //*****************************************************************************
00219 
00220 //:::::::::::::::::::::::::
00221 //:: METHOD  get_children::
00222 //:::::::::::::::::::::::::
00223 
00224 vector<MyTruthParticle*>
00225     MyTruthParticleManager::get_children(MyTruthParticle* truth_particle)const{
00226     unsigned int tmp_barcode(0);
00227     vector<MyTruthParticle*> v_tmp_truth_particles;
00228     v_tmp_truth_particles.clear();
00229     tmp_barcode = truth_particle->barcode();
00230     int mother_pdgId(0);
00231     mother_pdgId = truth_particle->pdgId();
00232     // loop over all stored truth particles
00233     // if mother0_barcode of a particle==barcode
00234     // of the given particle, store the particle 
00235     // in a vector
00236     for (unsigned int i=0; i<v_truth_particles.size(); i++){
00237         if ((unsigned int)((v_truth_particles[i])->mother0_barcode())
00238             ==tmp_barcode){
00239             v_tmp_truth_particles.push_back(v_truth_particles[i]);
00240         }
00241     }
00242 /*      
00243     for (unsigned int i=0; i<v_tmp_truth_particles.size(); i++){
00244         cout<<"child "<<i<<" ID: "
00245             <<(v_tmp_truth_particles[i])->pdgId()<<endl;
00246     }
00247     //*/
00248     // return the vector
00249     return v_tmp_truth_particles;
00250 }
00251 
00252 //*****************************************************************************
00253 
00254 //::::::::::::::::::::::::::::::
00255 //:: METHOD get_last_instance ::
00256 //::::::::::::::::::::::::::::::
00257 
00258 MyTruthParticle* MyTruthParticleManager::get_last_instance(MyTruthParticle* part_in){
00259     vector<MyTruthParticle*> v_tmp_children;
00260     int nb_children_with_same_id;
00261      nb_children_with_same_id = 0;
00262    
00263     // get the direct children of the given particle
00264     v_tmp_children = get_children(part_in);
00265 
00266     // if the given particle has no children
00267     // return given particle
00268     if (v_tmp_children.size() ==0 ){
00269         //cerr<<"No more children"<<endl;
00270         return part_in;
00271     }
00272 
00273     // loop over children
00274     for (unsigned int i=0; i<v_tmp_children.size(); i++){
00275         // if a child has the same ID like the given particle,
00276         // call this method recursive
00277         if ( ((v_tmp_children[i])->pdgId())==part_in->pdgId()){
00278             nb_children_with_same_id++;
00279             return get_last_instance(v_tmp_children[i]);
00280         }
00281     }
00282     // if there was no child with the same ID like the given particle
00283     // return the given particle
00284     if (nb_children_with_same_id==0){
00285         //cerr<<"No more particles of same type within children"<<endl;
00286         return part_in;
00287     }
00288     // one should not arrive here...
00289     cerr<<"shouldn't arrive here: MyTruthParticleManager::get_last_instance"<<endl;
00290     return NULL;
00291 }
00292 
00293 //*****************************************************************************
00294 
00295 //::::::::::::::::::::::::::::::::::::::::::::::
00296 //:: METHOD remove_multiples_wo_using_genstat ::
00297 //::::::::::::::::::::::::::::::::::::::::::::::
00298 
00299 vector<MyParticle*> MyTruthParticleManager::remove_multiples_wo_using_genstat(const vector<MyParticle*> v_input){
00300     // a temporary particle
00301     MyTruthParticle* tmp_part1;
00302     tmp_part1=NULL;
00303 
00304     // a new vector that contains the cleaned up sample of particles
00305     vector<MyParticle*> v_out;
00306     v_out.clear();
00307     
00308     // tmeporary variables
00309     int child_bc, tmp_part1_bc;
00310     child_bc = 0;
00311     tmp_part1_bc = 0;
00312     bool already_stored;
00313     already_stored = false;
00314 
00315     // iterate over vector from the beginning
00316     for (int j=0; j<((int)v_input.size()); j++){
00317         // get the last instance of this particle
00318         tmp_part1 = get_last_instance((MyTruthParticle*)v_input[j]);
00319         if (tmp_part1==NULL){
00320             // error
00321             cerr<<"ERROR in MyTruthParticleManager::remove_multiples"<<endl;
00322         }
00323         else {
00324             // check if particle was already stored in the output vector
00325             already_stored = false;
00326             for (unsigned int k=0; k<v_out.size(); k++){
00327                 child_bc = ((MyTruthParticle*)v_out[k])->barcode();
00328                 tmp_part1_bc = tmp_part1->barcode();
00329                 if( child_bc==tmp_part1_bc ){
00330                     already_stored = true;
00331                 }
00332             }
00333             
00334             // if not, store it
00335             if (!already_stored){
00336                 v_out.push_back(tmp_part1);
00337             }
00338             // if yes, go on to the next particle
00339         }
00340 
00341     }
00342 
00343     // remove taus with no daughters:
00344     for (int k=v_out.size()-1; k>-1; k--){
00345 //        if (TMath::Abs(((MyTruthParticle*)v_out[k])->pdgId())==15){
00346 //            cerr<<"Id: "<<<<"nDaughters: "
00347 //                <<((MyTruthParticle*)v_out[k])->nDaughters()<<endl;
00348 //        }
00349         // check if it is a tau and has no daughters
00350         if (TMath::Abs(((MyTruthParticle*)v_out[k])->pdgId())==15 &&
00351                 ((MyTruthParticle*)v_out[k])->nDaughters()==0){
00352             // remove this tau
00353             v_out.erase(v_out.begin()+k);
00354             }
00355         }
00356 //        return v_out;
00357 
00358 // check isolation of particles:
00359 // inform user about content of vector
00360 
00361         
00362         // iterate over vector from the beginning
00363         for (int j=0; j<((int)v_out.size()); ){
00364         // j is not increased automaitcally, only if particle is not removed
00365         // if the particle is removed, the non increased index
00366         // automaically points to the next particle
00367             bool to_be_removed;
00368             to_be_removed=false;
00369 /*
00370             cerr<<"part1-Id: "<<((MyTruthParticle*)(v_out[j]))->pdgId()
00371                 <<", BC: "<<((MyTruthParticle*)(v_out[j]))->barcode()
00372                 <<", Status: "<<((MyTruthParticle*)(v_out[j]))->status()
00373                 <<", nP: "<<((MyTruthParticle*)(v_out[j]))->nParents()
00374                 <<", PId: "<<((MyTruthParticle*)(v_out[j]))->mother0_pdgId()
00375                 <<", PBC: "<<((MyTruthParticle*)(v_out[j]))->mother0_barcode()
00376                 <<", nD: "<<((MyTruthParticle*)(v_out[j]))->nDaughters()<<endl;
00377 //*/    
00378             
00379             for (int k=1; k<((int)v_out.size()); k++){
00380                 double dr(100000000);
00381                 double dE(100000000);
00382                 double dpdgId(1);
00383                 double dstatus(0);
00384                 dr = (v_out[j])->tlv().DeltaR((v_out[k])->tlv());
00385                 dE = TMath::Abs((v_out[j])->tlv().E()-(v_out[k])->tlv().E());
00386                 dpdgId = ((MyTruthParticle*)(v_out[j]))->pdgId()-((MyTruthParticle*)(v_out[k]))->pdgId();
00387                 dstatus = ((MyTruthParticle*)(v_out[j]))->status()-((MyTruthParticle*)(v_out[k]))->status();
00388 /*              
00389                 cerr<<"part2-Id: "<<((MyTruthParticle*)(v_out[k]))->pdgId()
00390                     <<", BC: "<<((MyTruthParticle*)(v_out[k]))->barcode()
00391                     <<", Status: "<<((MyTruthParticle*)(v_out[k]))->status()
00392                     <<", nP: "<<((MyTruthParticle*)(v_out[k]))->nParents()
00393                     <<", PId: "<<((MyTruthParticle*)(v_out[k]))->mother0_pdgId()
00394                     <<", PBC: "<<((MyTruthParticle*)(v_out[k]))->mother0_barcode()
00395                     <<", nD: "<<((MyTruthParticle*)(v_out[k]))->nDaughters()<<endl;
00396                     cerr<<"dR: "<<dr<<", dE: "<<dE<<endl;
00397 //*/
00398                 if (dr<2 && dE<500000 && dpdgId==0 && dstatus>0){
00399                     //*
00400 //                  cerr<<"found double, pos 1,2: "<<j<<", "<<k<<endl;
00401                 if (((MyTruthParticle*)(v_out[j]))->status()==1 || ((MyTruthParticle*)(v_out[j]))->status()==195){
00402                     cerr<<"Removing a truth particle with status 1 or 195"<<endl;
00403                 }
00404 /*
00405                     cerr<<"dR: "<<dr<<", dE: "<<dE<<", dstatus: "<<dstatus<<endl;
00406                     cerr<<"part1-Id: "<<((MyTruthParticle*)(v_out[j]))->pdgId()
00407                         <<", BC: "<<((MyTruthParticle*)(v_out[j]))->barcode()
00408                         <<", Status: "<<((MyTruthParticle*)(v_out[j]))->status()
00409                         <<", nP: "<<((MyTruthParticle*)(v_out[j]))->nParents()
00410                         <<", PId: "<<((MyTruthParticle*)(v_out[j]))->mother0_pdgId()
00411                         <<", PBC: "<<((MyTruthParticle*)(v_out[j]))->mother0_barcode()
00412                         <<", nD: "<<((MyTruthParticle*)(v_out[j]))->nDaughters()<<endl;
00413                     cerr<<"part2-Id: "<<((MyTruthParticle*)(v_out[k]))->pdgId()
00414                         <<", BC: "<<((MyTruthParticle*)(v_out[k]))->barcode()
00415                         <<", Status: "<<((MyTruthParticle*)(v_out[k]))->status()
00416                         <<", nP: "<<((MyTruthParticle*)(v_out[k]))->nParents()
00417                         <<", PId: "<<((MyTruthParticle*)(v_out[k]))->mother0_pdgId()
00418                         <<", PBC: "<<((MyTruthParticle*)(v_out[k]))->mother0_barcode()
00419                         <<", nD: "<<((MyTruthParticle*)(v_out[k]))->nDaughters()<<endl;
00420                     //*/
00421                     to_be_removed=true;
00422                 }
00423             }
00424             if(to_be_removed){
00425                 // remove this pair
00426                 v_out.erase(v_out.begin()+j);
00427                 }
00428             else{
00429                 // check the next particle
00430                 j++;
00431             }
00432         }
00433         return v_out;
00434 }
00435 
00436 //*****************************************************************************
00437 
00438 //:::::::::::::::::::::::::::::
00439 //:: METHOD remove_multiples ::
00440 //:::::::::::::::::::::::::::::
00441 
00442 vector<MyParticle*> MyTruthParticleManager::remove_multiples(const vector<MyParticle*> v_input){
00443     
00444     // check if generator was set
00445     if(genstat_e==9999 || genstat_mu==9999 || genstat_tau==9999){
00446         cerr<<"Generator not set!"<<endl
00447             <<"Set it before using remove_multiples!"<<endl;
00448         exit(1);
00449     }
00450     
00451     // a new vector that contains the cleaned up sample of particles
00452     vector<MyParticle*> v_out;
00453     v_out.clear();
00454     
00455     // tmeporary variables
00456     int tmp_abs_pdgId;
00457     tmp_abs_pdgId = 0;
00458     unsigned int tmp_genStat;
00459     tmp_genStat = 0;
00460 
00461     // iterate over vector from the beginning
00462     for (int j=0; j<((int)v_input.size()); j++){
00463         // get the abs(pdgId) and status of the particle
00464         tmp_abs_pdgId = TMath::Abs(((MyTruthParticle*)v_input[j])->pdgId());
00465         tmp_genStat = (unsigned int)TMath::Abs(((MyTruthParticle*)v_input[j])->status());
00466         
00467 //      cout<<"genstat_e required: "<<genstat_e<<endl;
00468 //      cout<<"genstat_mu required: "<<genstat_mu<<endl;
00469 //      cout<<"genstat_tau required: "<<genstat_tau<<endl;
00470 //      cout<<"genstat: "<<tmp_genStat<<endl;
00471 //      cout<<"pdgId: "<<tmp_abs_pdgId<<endl;
00472         
00473         if((tmp_abs_pdgId == 11) && (tmp_genStat == genstat_e)){
00474             v_out.push_back(v_input[j]);
00475         }
00476         if((tmp_abs_pdgId == 13) && (tmp_genStat == genstat_mu)){
00477             v_out.push_back(v_input[j]);
00478         }
00479         if((tmp_abs_pdgId == 15) && (tmp_genStat == genstat_tau)){
00480             v_out.push_back(v_input[j]);
00481         }
00482     }
00483     return v_out;
00484 }
00485 
00486 //*****************************************************************************
00487 
00488 //::::::::::::::::::::::::::::::::::
00489 //:: METHOD get_n_of_decay_chains ::
00490 //::::::::::::::::::::::::::::::::::
00491 
00492 // get number of interesting decay chains
00493 unsigned int MyTruthParticleManager::get_n_of_decay_chains(void) const {
00494     return n_of_decay_chains;
00495 }
00496 
00497 //*****************************************************************************
00498 
00499 //::::::::::::::::::::::::::::::::
00500 //:: METHOD get_primary_intpart ::
00501 //::::::::::::::::::::::::::::::::
00502 
00503 // get the primary interesting particle of decay chain n_decay_chain
00504 MyTruthParticle* 
00505     MyTruthParticleManager::get_primary_intpart(int n_decay_chain) const {
00506     if (n_decay_chain>n_of_decay_chains){
00507         cerr<<"decay chain "<<n_decay_chain<<" does not exist"<<endl;
00508         return primary_intpart_0;
00509     }
00510     if (n_decay_chain==0){
00511         return primary_intpart_0;
00512     }
00513     if (n_decay_chain==1){
00514         return primary_intpart_1;
00515     }
00516     return primary_intpart_0;
00517 }
00518 
00519 //*****************************************************************************
00520 
00521 //::::::::::::::::::::::::::::::::::::::
00522 //:: METHOD get_gen1_children_intpart ::
00523 //::::::::::::::::::::::::::::::::::::::
00524 
00525 // get the 1st generation children of the
00526 // primary interesting particle of decay chain n_decay_chain
00527 vector<MyTruthParticle*> 
00528     MyTruthParticleManager::get_gen1_children_intpart(int n_decay_chain) const {
00529     if (n_decay_chain>n_of_decay_chains){
00530         cerr<<"decay chain "<<n_decay_chain<<" does not exist"<<endl;
00531         return v_intpart_0_children_gen1;
00532     }
00533     if (n_decay_chain==0){
00534         return v_intpart_0_children_gen1;
00535     }
00536     if (n_decay_chain==1){
00537         return v_intpart_1_children_gen1;
00538     }
00539     return v_intpart_0_children_gen1;
00540 }
00541 
00542 //*****************************************************************************
00543 
00544 //::::::::::::::::::::::::::::::::::::::
00545 //:: METHOD get_gen2_children_intpart ::
00546 //::::::::::::::::::::::::::::::::::::::
00547 
00548 // get the 2nd generation children of the
00549 // primary interesting particle of decay chain n_decay_chain
00550 vector< vector<MyTruthParticle*> > 
00551     MyTruthParticleManager::get_gen2_children_intpart(int n_decay_chain) const {
00552     if (n_decay_chain>n_of_decay_chains){
00553         cerr<<"decay chain "<<n_decay_chain<<" does not exist"<<endl;
00554         return vv_intpart_0_children_gen2;
00555     }
00556     if (n_decay_chain==0){
00557         return vv_intpart_0_children_gen2;
00558     }
00559     if (n_decay_chain==1){
00560         return vv_intpart_1_children_gen2;
00561     }
00562     return vv_intpart_0_children_gen2;
00563 }
00564 
00565 //*****************************************************************************
00566 
00567 //::::::::::::::::::::::::::::::::
00568 //:: METHOD find_decay_chain_of ::
00569 //::::::::::::::::::::::::::::::::
00570 
00571 int MyTruthParticleManager::find_decay_chain_of(vector<unsigned int> interesting_pdgIds){
00572     // reset the number of interesting decay chains
00573     n_of_decay_chains = 0;
00574 
00575     // temporary variables
00576     vector<MyTruthParticle*> v_int_part;
00577     MyTruthParticle* tmp_truth_part;
00578     int primary_mother_barcode(0);
00579     int int_part_0_barcode(0);  // barcode of the primary mother 
00580                                 // of first decay chain
00581     int int_part_1_barcode(0);  // and of second chain
00582 
00583 
00584     // scan through all the truth particles for interesting PDG-IDs
00585     // store the pointers to all the particles with an interesting ID
00586     // in a temporary vector
00587     for (unsigned int i=0; i<interesting_pdgIds.size(); i++){
00588         for (unsigned int j=0; j<v_truth_particles.size(); j++){
00589             if ( (unsigned int)TMath::Abs((v_truth_particles[j])->pdgId())==interesting_pdgIds[i]
00590                 && (v_truth_particles[j])->barcode()<50){
00591                 v_int_part.push_back(v_truth_particles[j]);
00592             }
00593         }
00594     }
00595 
00596     // check wether there were interesting particles
00597     // by checking the size of the temporary vector
00598     // that was just built
00599     if (v_int_part.size()==0){
00600         //cout<<"No interesting particle found"<<endl;
00601         n_of_decay_chains = 0;
00602         return 0;
00603     }
00604 
00605 //* debug info */       for (unsigned int i=0; i<v_int_part.size(); i++){
00606 //* debug info */               cout<<"found PDG-ID: "<<(v_int_part[i])->pdgId()<<endl;
00607 //* debug info */       }
00608 
00609     // loop over the temporary vector, assign the particles to decay chains
00610     // store the primary particle of each found deacy chain
00611     for(unsigned int i=0; i<v_int_part.size(); i++){
00612 //* debug info */ cerr<<"in MyTruthParticleManager::find_decay_chain_of: tempvector loop"<<endl;
00613         
00614         // get the primary mother of the current particle
00615         tmp_truth_part = get_primary_mother((v_int_part[i]));
00616 //* debug info */ cerr<<"in MyTruthParticleManager::find_decay_chain_of: after get_primary_mother"<<endl;
00617 
00618         tmp_truth_part = get_last_instance(tmp_truth_part);
00619         
00620         // throw a warning if no mother was found
00621         if (tmp_truth_part==NULL){
00622            //cerr<<"ERROR: Mother not found!"<<endl;
00623            n_of_decay_chains= -1;
00624            return n_of_decay_chains;
00625         }
00626     
00627         
00628         // check if generator was set
00629         if(genstat_e==9999 || genstat_mu==9999 || genstat_tau==9999){
00630             cerr<<"Generator not set!"<<endl
00631                 <<"Set it before using find_decay_chain_of!"<<endl;
00632                 exit(1);
00633         }
00634 
00635 
00636         // Fix to get only one Z in Alpgen samples:
00637         if(generator=="Alpgen"){
00638             if(tmp_truth_part->pdgId()==23 && tmp_truth_part->status()!=155){
00639 //                cout<<"Generator is Alpgen and found Z with status!=155: skipping..."<<endl;
00640                 continue;
00641             }
00642         }
00643         
00644         // get the barcode of the primary mother
00645         primary_mother_barcode = tmp_truth_part->barcode();
00646 //* debug info */ cout<<"primary_mother_barcode: "<<primary_mother_barcode<<endl;
00647     
00648         // if there is no primary particle stored yet,
00649         // store this particle as first one
00650         if (int_part_0_barcode==0){
00651             int_part_0_barcode=primary_mother_barcode;
00652             primary_intpart_0=tmp_truth_part;
00653             continue;
00654         }
00655     
00656         // continue if this primary particle was already stored
00657         // as first interesting particle
00658         if (int_part_0_barcode==primary_mother_barcode){
00659             continue;
00660         }
00661     
00662         // from here on the current particle does NOT belong
00663         // to the first decay chain
00664     
00665         // if there is no second interesting primary particle
00666         // stored yet, store this particle as second one
00667         if (int_part_1_barcode==0){
00668             int_part_1_barcode=primary_mother_barcode;
00669             primary_intpart_1=tmp_truth_part;
00670             continue;
00671         }
00672     
00673         // continue if this primary particle was already stored
00674         // as second interesting particle
00675         if (int_part_1_barcode==primary_mother_barcode){
00676             continue;
00677         }
00678     
00679         // since from here on an interesting particle was found
00680         // that does not belong to a decay chain of the two found
00681         // interesting decay chains, throw a warning that more than
00682         // 2 interesting decay chains found
00683         n_of_decay_chains = 999;
00684         cout<<"More than 2 interesting decay chains found!!!"<<endl;
00685         // end method here
00686         return n_of_decay_chains;
00687     
00688     } // end of loop over all interesting truth particles
00689 
00690     // evaluate the number of decay chains
00691     if (int_part_0_barcode==0 && int_part_1_barcode==0){
00692         n_of_decay_chains=0;
00693     }       
00694     if (int_part_0_barcode>0 && int_part_1_barcode==0){
00695         n_of_decay_chains=1;
00696     }       
00697     if (int_part_0_barcode>0 && int_part_1_barcode>0){
00698         n_of_decay_chains=2;
00699     }
00700     return n_of_decay_chains;
00701 }
00702 
00703 //*****************************************************************************
00704 
00705 //:::::::::::::::::::::::::::::::::
00706 //:: METHOD process_decay_chains ::
00707 //:::::::::::::::::::::::::::::::::
00708 
00709 bool MyTruthParticleManager::process_decay_chains(void){
00710     // fills the first and second generation children
00711     // for the primary interesting particles found
00712 
00713     // first chain
00714     if (n_of_decay_chains>0){
00715     /*
00716         cout<<"primary particle 0 ID: "<<primary_intpart_0->pdgId()<<endl;
00717         //*/
00718         v_intpart_0_children_gen1.clear();
00719         MyTruthParticle* primary_intpart_0_li;
00720         primary_intpart_0_li = get_last_instance(primary_intpart_0);
00721         v_intpart_0_children_gen1=get_children(primary_intpart_0_li);
00722         // 2nd generation
00723         for (unsigned int i=0; i<v_intpart_0_children_gen1.size(); i++){
00724             vv_intpart_0_children_gen2.push_back(
00725             get_children(get_last_instance(v_intpart_0_children_gen1[i])) );
00726         }
00727     }
00728 
00729     // second chain
00730     if (n_of_decay_chains>1){
00731     /*
00732         cout<<"primary particle 1 ID: "<<primary_intpart_1->pdgId()<<endl;
00733         //*/
00734         v_intpart_1_children_gen1.clear();
00735         MyTruthParticle* primary_intpart_1_li;
00736         primary_intpart_1_li = get_last_instance(primary_intpart_1);
00737         v_intpart_1_children_gen1=get_children(primary_intpart_1_li);
00738         // 2nd generation
00739         for (unsigned int i=0; i<v_intpart_1_children_gen1.size(); i++){
00740             vv_intpart_1_children_gen2.push_back( get_children(get_last_instance(v_intpart_1_children_gen1[i])) );
00741         }
00742     }
00743     return true;
00744 }

Generated on Tue Oct 21 11:50:46 2008 for NtupleAnalysis by  doxygen 1.5.1