00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "NtupleReader/MyTruthParticleManager.h"
00011
00012
00013
00014
00015
00016 using namespace std;
00017
00018
00019 bool MyTruthParticleManager::init(vector<MyParticle*> in_truth_particles){
00020
00021
00022
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
00035 for (unsigned int i=0; i<in_truth_particles.size(); i++){
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 v_truth_particles.push_back( (MyTruthParticle*)(in_truth_particles[i]));
00048 }
00049
00050 if (in_truth_particles.size()==v_truth_particles.size()){
00051 return true;
00052 }
00053
00054 else{
00055 cerr<<"Error in MyTruthParticleManager::init"<<endl;
00056 return false;
00057 }
00058 }
00059
00060
00061
00062
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;
00091 }
00092 else {
00093 cerr<<"ERROR: MyTruthParticleManager::set_generator:"<<endl
00094 <<"Unknown Generator: "<<generator<<endl;
00095 exit(1);
00096 }
00097
00098
00099
00100
00101
00102
00103 }
00104
00105
00106
00107
00108
00109
00110
00111 vector<MyParticle*> MyTruthParticleManager::getParticles_with_ID(unsigned int pdgId) const {
00112 vector<MyParticle*> tmp_v;
00113 tmp_v.clear();
00114
00115
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
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
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
00145 return NULL;
00146 }
00147
00148
00149
00150
00151
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
00160 tmp_nParents=truth_particle->nParents();
00161
00162
00163 if (tmp_nParents==0 || tmp_nParents>1){
00164 return NULL;
00165 }
00166
00167
00168 tmp_barcode=truth_particle->mother0_barcode();
00169 tmp_truth_part = getParticle_with_barcode(tmp_barcode);
00170 if (tmp_truth_part==NULL){
00171
00172 }
00173 return tmp_truth_part;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 MyTruthParticle* MyTruthParticleManager::get_primary_mother(MyTruthParticle* truth_particle) const {
00183
00184
00185 if (truth_particle->nParents()==0 || truth_particle->nParents()>1){
00186 return truth_particle;
00187 }
00188
00189 if (truth_particle->pdgId()==25){
00190 return truth_particle;
00191 }
00192
00193
00194
00195
00196
00197
00198 MyTruthParticle* truth_particle2;
00199
00200 truth_particle2 = get_mother(truth_particle);
00201 if (truth_particle2==NULL){
00202
00203 return NULL;
00204 }
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 return get_primary_mother(truth_particle2);
00215
00216 }
00217
00218
00219
00220
00221
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
00233
00234
00235
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
00244
00245
00246
00247
00248
00249 return v_tmp_truth_particles;
00250 }
00251
00252
00253
00254
00255
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
00264 v_tmp_children = get_children(part_in);
00265
00266
00267
00268 if (v_tmp_children.size() ==0 ){
00269
00270 return part_in;
00271 }
00272
00273
00274 for (unsigned int i=0; i<v_tmp_children.size(); i++){
00275
00276
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
00283
00284 if (nb_children_with_same_id==0){
00285
00286 return part_in;
00287 }
00288
00289 cerr<<"shouldn't arrive here: MyTruthParticleManager::get_last_instance"<<endl;
00290 return NULL;
00291 }
00292
00293
00294
00295
00296
00297
00298
00299 vector<MyParticle*> MyTruthParticleManager::remove_multiples_wo_using_genstat(const vector<MyParticle*> v_input){
00300
00301 MyTruthParticle* tmp_part1;
00302 tmp_part1=NULL;
00303
00304
00305 vector<MyParticle*> v_out;
00306 v_out.clear();
00307
00308
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
00316 for (int j=0; j<((int)v_input.size()); j++){
00317
00318 tmp_part1 = get_last_instance((MyTruthParticle*)v_input[j]);
00319 if (tmp_part1==NULL){
00320
00321 cerr<<"ERROR in MyTruthParticleManager::remove_multiples"<<endl;
00322 }
00323 else {
00324
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
00335 if (!already_stored){
00336 v_out.push_back(tmp_part1);
00337 }
00338
00339 }
00340
00341 }
00342
00343
00344 for (int k=v_out.size()-1; k>-1; k--){
00345
00346
00347
00348
00349
00350 if (TMath::Abs(((MyTruthParticle*)v_out[k])->pdgId())==15 &&
00351 ((MyTruthParticle*)v_out[k])->nDaughters()==0){
00352
00353 v_out.erase(v_out.begin()+k);
00354 }
00355 }
00356
00357
00358
00359
00360
00361
00362
00363 for (int j=0; j<((int)v_out.size()); ){
00364
00365
00366
00367 bool to_be_removed;
00368 to_be_removed=false;
00369
00370
00371
00372
00373
00374
00375
00376
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
00390
00391
00392
00393
00394
00395
00396
00397
00398 if (dr<2 && dE<500000 && dpdgId==0 && dstatus>0){
00399
00400
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
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 to_be_removed=true;
00422 }
00423 }
00424 if(to_be_removed){
00425
00426 v_out.erase(v_out.begin()+j);
00427 }
00428 else{
00429
00430 j++;
00431 }
00432 }
00433 return v_out;
00434 }
00435
00436
00437
00438
00439
00440
00441
00442 vector<MyParticle*> MyTruthParticleManager::remove_multiples(const vector<MyParticle*> v_input){
00443
00444
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
00452 vector<MyParticle*> v_out;
00453 v_out.clear();
00454
00455
00456 int tmp_abs_pdgId;
00457 tmp_abs_pdgId = 0;
00458 unsigned int tmp_genStat;
00459 tmp_genStat = 0;
00460
00461
00462 for (int j=0; j<((int)v_input.size()); j++){
00463
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
00468
00469
00470
00471
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
00490
00491
00492
00493 unsigned int MyTruthParticleManager::get_n_of_decay_chains(void) const {
00494 return n_of_decay_chains;
00495 }
00496
00497
00498
00499
00500
00501
00502
00503
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
00523
00524
00525
00526
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
00546
00547
00548
00549
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
00569
00570
00571 int MyTruthParticleManager::find_decay_chain_of(vector<unsigned int> interesting_pdgIds){
00572
00573 n_of_decay_chains = 0;
00574
00575
00576 vector<MyTruthParticle*> v_int_part;
00577 MyTruthParticle* tmp_truth_part;
00578 int primary_mother_barcode(0);
00579 int int_part_0_barcode(0);
00580
00581 int int_part_1_barcode(0);
00582
00583
00584
00585
00586
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
00597
00598
00599 if (v_int_part.size()==0){
00600
00601 n_of_decay_chains = 0;
00602 return 0;
00603 }
00604
00605
00606
00607
00608
00609
00610
00611 for(unsigned int i=0; i<v_int_part.size(); i++){
00612
00613
00614
00615 tmp_truth_part = get_primary_mother((v_int_part[i]));
00616
00617
00618 tmp_truth_part = get_last_instance(tmp_truth_part);
00619
00620
00621 if (tmp_truth_part==NULL){
00622
00623 n_of_decay_chains= -1;
00624 return n_of_decay_chains;
00625 }
00626
00627
00628
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
00637 if(generator=="Alpgen"){
00638 if(tmp_truth_part->pdgId()==23 && tmp_truth_part->status()!=155){
00639
00640 continue;
00641 }
00642 }
00643
00644
00645 primary_mother_barcode = tmp_truth_part->barcode();
00646
00647
00648
00649
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
00657
00658 if (int_part_0_barcode==primary_mother_barcode){
00659 continue;
00660 }
00661
00662
00663
00664
00665
00666
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
00674
00675 if (int_part_1_barcode==primary_mother_barcode){
00676 continue;
00677 }
00678
00679
00680
00681
00682
00683 n_of_decay_chains = 999;
00684 cout<<"More than 2 interesting decay chains found!!!"<<endl;
00685
00686 return n_of_decay_chains;
00687
00688 }
00689
00690
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
00707
00708
00709 bool MyTruthParticleManager::process_decay_chains(void){
00710
00711
00712
00713
00714 if (n_of_decay_chains>0){
00715
00716
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
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
00730 if (n_of_decay_chains>1){
00731
00732
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
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 }