Fork me on GitHub

Changeset 341014c in git for modules/StatusPidFilter.cc


Ignore:
Timestamp:
Feb 12, 2019, 9:29:17 PM (6 years ago)
Author:
Pavel Demin <pavel-demin@…>
Branches:
ImprovedOutputFile, Timing, llp, master
Children:
6455202
Parents:
45e58be
Message:

apply .clang-format to all .h, .cc and .cpp files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/StatusPidFilter.cc

    r45e58be r341014c  
    3232#include "classes/DelphesFormula.h"
    3333
     34#include "ExRootAnalysis/ExRootClassifier.h"
     35#include "ExRootAnalysis/ExRootFilter.h"
    3436#include "ExRootAnalysis/ExRootResult.h"
    35 #include "ExRootAnalysis/ExRootFilter.h"
    36 #include "ExRootAnalysis/ExRootClassifier.h"
    37 
     37
     38#include "TDatabasePDG.h"
     39#include "TFormula.h"
     40#include "TLorentzVector.h"
    3841#include "TMath.h"
     42#include "TObjArray.h"
     43#include "TRandom3.h"
    3944#include "TString.h"
    40 #include "TFormula.h"
    41 #include "TRandom3.h"
    42 #include "TObjArray.h"
    43 #include "TDatabasePDG.h"
    44 #include "TLorentzVector.h"
    4545
    4646#include <algorithm>
    47 #include <stdexcept>
    4847#include <iostream>
    4948#include <sstream>
     49#include <stdexcept>
    5050
    5151using namespace std;
    5252
    53 namespace {
    54   // integer power (faster than TMath::Pow() + cast to integer)
    55   int ipow(int base, int exp)
    56   {
    57       int result = 1;
    58       while (exp)
    59       {
    60           if (exp & 1)
    61               result *= base;
    62           exp >>= 1;
    63           base *= base;
    64       }
    65 
    66       return result;
    67   }
    68 
    69   // standalone function to extract the i-th digit from a number (counting from 0 = rightmost, etc..)
    70   int digit(int val, int i)
    71   {
    72       int y    = ipow(10,i);
    73       int z    = val/y;
    74       int val2 = val / (y * 10);
    75       return (z - val2*10);
    76   }
    77 
    78   //  return the first two digits if this is a "fundamental" particle
    79   //  ID = 100 is a special case (internal generator ID's are 81-100)
    80   //  also, 101 and 102 are now used (by HepPID) for geantinos
    81   int fundamentalID(int pdgCode)
    82   {
    83       pdgCode = abs(pdgCode);
    84       if( ( digit(pdgCode, 9) == 1 ) && ( digit(pdgCode, 8) == 0 ) ) { return 0; }
    85       if( digit(pdgCode, 2) == 0 && digit(pdgCode, 3) == 0) {
    86           return pdgCode%10000;
    87       } else if( pdgCode <= 102 ) {
    88           return pdgCode;
    89       } else {
    90           return 0;
    91       }
    92   }
    93 
    94   bool hasBottom(int pdgCode)
    95   {
    96       if ( (pdgCode/10000000) > 0)
    97         return false;
    98       if (pdgCode <= 100)
    99         return false;
    100       if (fundamentalID(pdgCode) <= 100 && fundamentalID(pdgCode) > 0)
    101         return false;
    102       if( digit(pdgCode, 3) == 5 || digit(pdgCode, 2) == 5 || digit(pdgCode, 1) == 5 )
    103         return true;     
    104       return false;
    105   }
    106 
    107   bool isTauDaughter(int pdgCode, int M1, const TObjArray *fInputArray){
    108     //not needed, just to speed up the code - can be further refined but gives only negligible improvement:
    109     if ( pdgCode==15 || pdgCode<11 || (pdgCode > 22 && pdgCode < 100) || pdgCode>1000 )
    110       return false;
    111 
    112     if ( M1 < 0 )
    113       return false;
    114 
    115     Candidate *mother;
    116     mother = static_cast<Candidate*>(fInputArray->At( M1 ));
    117     if ( TMath::Abs(mother->PID) == 15 )
    118       return true;
    119 
    120     return false;
    121   }
    122 
    123   bool isWDaughter(int M1, const TObjArray *fInputArray)
    124   {
    125      if ( M1 < 0 ) return false;
    126 
    127      Candidate *mother;
    128      mother = static_cast<Candidate*>(fInputArray->At( M1 ));
    129      if ( TMath::Abs(mother->PID) == 24 ) return true;
    130 
    131      return false;
    132   }
    133 
    134 }
    135 
     53namespace
     54{
     55// integer power (faster than TMath::Pow() + cast to integer)
     56int ipow(int base, int exp)
     57{
     58  int result = 1;
     59  while(exp)
     60  {
     61    if(exp & 1)
     62      result *= base;
     63    exp >>= 1;
     64    base *= base;
     65  }
     66
     67  return result;
     68}
     69
     70// standalone function to extract the i-th digit from a number (counting from 0 = rightmost, etc..)
     71int digit(int val, int i)
     72{
     73  int y = ipow(10, i);
     74  int z = val / y;
     75  int val2 = val / (y * 10);
     76  return (z - val2 * 10);
     77}
     78
     79//  return the first two digits if this is a "fundamental" particle
     80//  ID = 100 is a special case (internal generator ID's are 81-100)
     81//  also, 101 and 102 are now used (by HepPID) for geantinos
     82int fundamentalID(int pdgCode)
     83{
     84  pdgCode = abs(pdgCode);
     85  if((digit(pdgCode, 9) == 1) && (digit(pdgCode, 8) == 0))
     86  {
     87    return 0;
     88  }
     89  if(digit(pdgCode, 2) == 0 && digit(pdgCode, 3) == 0)
     90  {
     91    return pdgCode % 10000;
     92  }
     93  else if(pdgCode <= 102)
     94  {
     95    return pdgCode;
     96  }
     97  else
     98  {
     99    return 0;
     100  }
     101}
     102
     103bool hasBottom(int pdgCode)
     104{
     105  if((pdgCode / 10000000) > 0)
     106    return false;
     107  if(pdgCode <= 100)
     108    return false;
     109  if(fundamentalID(pdgCode) <= 100 && fundamentalID(pdgCode) > 0)
     110    return false;
     111  if(digit(pdgCode, 3) == 5 || digit(pdgCode, 2) == 5 || digit(pdgCode, 1) == 5)
     112    return true;
     113  return false;
     114}
     115
     116bool isTauDaughter(int pdgCode, int M1, const TObjArray *fInputArray)
     117{
     118  //not needed, just to speed up the code - can be further refined but gives only negligible improvement:
     119  if(pdgCode == 15 || pdgCode < 11 || (pdgCode > 22 && pdgCode < 100) || pdgCode > 1000)
     120    return false;
     121
     122  if(M1 < 0)
     123    return false;
     124
     125  Candidate *mother;
     126  mother = static_cast<Candidate *>(fInputArray->At(M1));
     127  if(TMath::Abs(mother->PID) == 15)
     128    return true;
     129
     130  return false;
     131}
     132
     133bool isWDaughter(int M1, const TObjArray *fInputArray)
     134{
     135  if(M1 < 0) return false;
     136
     137  Candidate *mother;
     138  mother = static_cast<Candidate *>(fInputArray->At(M1));
     139  if(TMath::Abs(mother->PID) == 24) return true;
     140
     141  return false;
     142}
     143
     144} // namespace
    136145
    137146//------------------------------------------------------------------------------
     
    183192
    184193  fItInputArray->Reset();
    185   while((candidate = static_cast<Candidate*>(fItInputArray->Next())))
     194  while((candidate = static_cast<Candidate *>(fItInputArray->Next())))
    186195  {
    187196    status = candidate->Status;
     
    195204    // hard scattering particles (first condition for Py6, second for Py8)
    196205    if(status == 3) pass = kTRUE;
    197     if(status > 20 && status < 30 ) pass = kTRUE;
     206    if(status > 20 && status < 30) pass = kTRUE;
    198207
    199208    // electrons, muons, taus and neutrinos
     
    201210
    202211    // heavy quarks
    203     if(pdgCode == 4 ||pdgCode == 5 || pdgCode == 6) pass = kTRUE;
     212    if(pdgCode == 4 || pdgCode == 5 || pdgCode == 6) pass = kTRUE;
    204213
    205214    // Gauge bosons and other fundamental bosons
    206215    if(pdgCode > 22 && pdgCode < 43) pass = kTRUE;
    207216
    208     //Stable photons 
    209     if(pdgCode == 22 && status==1) pass = kTRUE;
     217    //Stable photons
     218    if(pdgCode == 22 && status == 1) pass = kTRUE;
    210219
    211220    // logic ported from HepPDF: http://lcgapp.cern.ch/project/simu/HepPDT/HepPDT.2.05.02/html/ParticleID_8cc-source.html#l00081
    212221    bool is_b_hadron = hasBottom(pdgCode);
    213     bool is_b_quark  = (pdgCode == 5);
     222    bool is_b_quark = (pdgCode == 5);
    214223
    215224    bool is_tau_daughter = isTauDaughter(pdgCode, candidate->M1, fInputArray);
    216225
    217     if (is_b_hadron)
     226    if(is_b_hadron)
    218227      pass = kTRUE;
    219228
    220     if (is_tau_daughter)
     229    if(is_tau_daughter)
    221230      pass = kTRUE;
    222231
    223232    bool is_W_daughter = isWDaughter(candidate->M1, fInputArray);
    224     if (is_W_daughter)
     233    if(is_W_daughter)
    225234      pass = kTRUE;
    226235
    227236    // fPTMin not applied to b_hadrons / b_quarks to allow for b-enriched sample stitching
    228237    // fPTMin not applied to tau decay products to allow visible-tau four momentum determination
    229     if(!pass || (candidate->Momentum.Pt() < fPTMin && !(is_b_hadron || is_b_quark || is_tau_daughter || is_W_daughter)) ) continue;
     238    if(!pass || (candidate->Momentum.Pt() < fPTMin && !(is_b_hadron || is_b_quark || is_tau_daughter || is_W_daughter))) continue;
    230239
    231240    // not pileup particles
    232     if(fRequireNotPileup && (candidate->IsPU >0)) continue;
     241    if(fRequireNotPileup && (candidate->IsPU > 0)) continue;
    233242
    234243    fOutputArray->Add(candidate);
    235244  }
    236245}
    237 
Note: See TracChangeset for help on using the changeset viewer.