Go to the documentation of this file.00001 #include "ForIA/AnalysisTools/TruthSelection.hh"
00002 #include "ForIA/Event.hh"
00003 #include "ForIA/Units.hh"
00004 #include <cmath>
00005
00006 namespace ForIA{
00007
00008 TruthSelection::TruthSelection(): FourVectorSelection(), m_charge(ANY), m_haveSetPT(false),
00009 m_haveSetEta(false), m_haveSetCharged(false), m_haveSetBarcode(false), m_haveSetIsPrimary(true){
00010
00011 }
00012
00013 const TruthParticleVector &TruthSelection::particles()const{
00014 if(m_freshEvent) fillVectors();
00015 return m_passedParticles;
00016 }
00017
00018 const TruthParticleVector &TruthSelection::rejectedParticles()const{
00019 if(m_freshEvent) fillVectors();
00020 return m_rejectedParticles;
00021 }
00022
00023 bool TruthSelection::setSelection(DefinedSelection selection){
00024
00025 if(!m_canSetCuts) return false;
00026
00027 m_haveSetPT = false;
00028 m_haveSetEta = false;
00029 m_haveSetCharged = false;
00030 m_haveSetBarcode = false;
00031 m_haveSetIsPrimary = false;
00032
00033 bool success = true;
00034
00035 switch (selection){
00036
00037 case MINBIAS_2:
00038
00039 success = success && setCharged(TruthSelection::CHARGED);
00040 success = success && setPTMin(100. * MeV);
00041 success = success && setEtaMax(2.5);
00042 success = success && setIsPrimary(true);
00043
00044 break;
00045 case UE:
00046
00047 success = success && setSelection(MINBIAS_2);
00048 success = success && setPTMin(500. * MeV);
00049 break;
00050 }
00051 return success;
00052 }
00053
00054 bool TruthSelection::setPTMin(double pt){
00055 if(!m_canSetCuts) return false;
00056 m_haveSetPT = true;
00057 m_ptMin = pt;
00058 return true;
00059 }
00060
00061 bool TruthSelection::setEtaMax(double eta){
00062 if(!m_canSetCuts) return false;
00063 m_haveSetEta = true;
00064 m_etaMax = eta;
00065 return true;
00066 }
00067
00068 bool TruthSelection::setCharged(charge chrg){
00069 if(!m_canSetCuts) return false;
00070 m_haveSetCharged = true;
00071 m_charge = chrg;
00072 return true;
00073 }
00074
00075 bool TruthSelection::setBarcodeMax(int bcode){
00076 if(!m_canSetCuts) return false;
00077 m_haveSetBarcode = true;
00078 m_barcodeMax = bcode;
00079 return true;
00080 }
00081
00082 bool TruthSelection::setIsPrimary(bool isPrimary){
00083 if(!m_canSetCuts) return false;
00084 m_haveSetIsPrimary = true;
00085 m_isPrimary = isPrimary;
00086 return true;
00087 }
00088
00089 void TruthSelection::fillVectors()const{
00090
00091 m_freshEvent = false;
00092
00093 m_passedParticles.clear();
00094 m_passedFourVectors.clear();
00095 m_rejectedParticles.clear();
00096 m_rejectedFourVectors.clear();
00097
00098 if(m_event == 0) return;
00099
00100 TruthParticleVector input = m_event->truthParticles();
00101
00102 for(TruthParticleVector::const_iterator particle = input.begin();
00103 particle != input.end(); ++particle){
00104 bool passedCuts = true;
00105
00106 if(m_haveSetPT && passedCuts) passedCuts = ((*particle)->PT() > m_ptMin);
00107 if(m_haveSetEta && passedCuts) passedCuts = (fabs((*particle)->eta()) < m_etaMax);
00108 if(m_haveSetBarcode && passedCuts) passedCuts = ((*particle)->barcode() < m_barcodeMax);
00109 if(m_haveSetIsPrimary && passedCuts) passedCuts = (m_isPrimary == ((*particle)->barcode() < 200000 && (*particle)->barcode() != 0));
00110
00111 if(m_haveSetCharged && passedCuts){
00112
00113 switch(m_charge){
00114 case NEUTRAL:
00115 if((*particle)->charge() != 0) passedCuts = false;
00116 break;
00117 case CHARGED:
00118 if((*particle)->charge() == 0) passedCuts = false;
00119 break;
00120 case POSITIVE:
00121 if((*particle)->charge() <= 0) passedCuts = false;
00122 break;
00123 case NEGATIVE:
00124 if((*particle)->charge() >= 0) passedCuts = false;
00125 break;
00126
00127 case ANY:
00128
00129 default:
00130 break;
00131 }
00132 }
00133 if(passedCuts){
00134 m_passedParticles.push_back(*particle);
00135 m_passedFourVectors.push_back(*particle);
00136 }else{
00137 m_rejectedParticles.push_back(*particle);
00138 m_rejectedFourVectors.push_back(*particle);
00139 }
00140 }
00141
00142 return;
00143 }
00144
00145 }