Anp::FillFlux Class Reference

#include <FillFlux.h>

Inheritance diagram for Anp::FillFlux:
Anp::AlgSnarl Anp::Base

List of all members.

Public Member Functions

 FillFlux ()
virtual ~FillFlux ()
bool Run (Record &record)
void Config (const Registry &reg)
bool Init (const Header &)
void End (const DataBlock &)

Private Member Functions

bool Fill (Truth &truth, const Record &record, const BeamType::BeamType_t beamtype)
bool Fill (Event &event, const Record &record, const BeamType::BeamType_t beamtype)

Private Attributes

std::string fName
std::string fFLUX
std::string fRUNCYCLE
bool fFluxDet
int fNSigma
SKZPWeightCalculatorfCalc

Detailed Description

Definition at line 20 of file FillFlux.h.


Constructor & Destructor Documentation

Anp::FillFlux::FillFlux (  ) 

Definition at line 16 of file FillFlux.cxx.

00017    :fName("PiMinus_CedarDaikon"),
00018     fFLUX(""),
00019     fRUNCYCLE(""),
00020     fFluxDet(false),
00021     fNSigma(0),
00022     fCalc(0)
00023 {
00024 }

Anp::FillFlux::~FillFlux (  )  [virtual]

Definition at line 27 of file FillFlux.cxx.

References fCalc.

00028 {
00029    if(fCalc)
00030    {
00031       delete fCalc;
00032       fCalc = 0;
00033    }
00034 }


Member Function Documentation

void Anp::FillFlux::Config ( const Registry reg  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 85 of file FillFlux.cxx.

References fFLUX, fFluxDet, fName, fNSigma, fRUNCYCLE, Registry::Get(), Registry::KeyExists(), and Anp::Read().

00086 {
00087    //
00088    // Get fit name and FLUX type
00089    //
00090 
00091    const char *value_name = 0;
00092    if(reg.Get("FillFluxName", value_name) && value_name)
00093    {
00094       fName = value_name;
00095    }
00096 
00097    const char *value_flux = 0;
00098    if(reg.Get("FillFlux", value_flux) && value_flux)
00099    {
00100       fFLUX = value_flux;
00101    }
00102    else if(reg.Get("FLUX", value_flux) && value_flux)
00103    {
00104       fFLUX = value_flux;
00105    }
00106 
00107    const char *value_runc = 0;
00108    if(reg.Get("RUNCYCLE", value_runc) && value_runc)
00109    {
00110       fRUNCYCLE = value_runc;
00111    }
00112 
00113    Anp::Read(reg, "FillFluxDet", fFluxDet);
00114    reg.Get("FillFluxNSigma", fNSigma);
00115    
00116    if(reg.KeyExists("PrintConfig"))
00117    {
00118       cout << "FillFlux::Config" << endl
00119            << "   Name = " << fName << endl
00120            << "   FLUX = " << fFLUX << endl
00121            << "   RUNCYCLE = " << fRUNCYCLE << endl
00122            << "   FluxDet = " << fFluxDet << endl
00123            << "   NSigma = " << fNSigma << endl;
00124    }
00125 }

void Anp::FillFlux::End ( const DataBlock  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 151 of file FillFlux.cxx.

References fCalc.

00152 {
00153    //
00154    // Done with data processing
00155    //
00156 
00157    if(fCalc)
00158    {
00159       delete fCalc;
00160       fCalc = 0;
00161    }
00162 }

bool Anp::FillFlux::Fill ( Event event,
const Record record,
const BeamType::BeamType_t  beamtype 
) [private]

Definition at line 223 of file FillFlux.cxx.

References fCalc, Anp::Record::FindTruth(), Anp::Record::GetHeader(), MCEventInfo::had_fs, MCEventInfo::iaction, MCEventInfo::initial_state, MCEventInfo::inu, MCEventInfo::iresonance, Anp::Header::IsFar(), Anp::Header::IsNear(), BeamType::kUnknown, MCEventInfo::nucleus, MCEventInfo::nuE, MCEventInfo::nuPx, MCEventInfo::nuPy, MCEventInfo::nuPz, MCEventInfo::q2, MCEventInfo::tarE, MCEventInfo::tarPx, MCEventInfo::tarPy, MCEventInfo::tarPz, Anp::Record::TruthEnd(), MCEventInfo::w2, Anp::Event::Weight(), MCEventInfo::x, and MCEventInfo::y.

00224 {
00225    //
00226    // Get beam weight using database as a source for the fit parameters.
00227    //
00228    if(!fCalc || beamtype == BeamType::kUnknown)
00229    {
00230       return false;
00231    }
00232 
00233    int detector = 0;
00234    if     (record.GetHeader().IsNear()) detector = 1;
00235    else if(record.GetHeader().IsFar())  detector = 2;  
00236    
00237    const TruthIter itruth = record.FindTruth(event);
00238    if(itruth == record.TruthEnd())
00239    {
00240       return false;
00241    }
00242 
00243    double ehad = event.GetNu().EHad();
00244    double elep = event.GetNu().ELep();
00245 
00246    MCEventInfo mcinfo;
00247    mcinfo.initial_state = itruth -> InitState();
00248    mcinfo.nucleus       = itruth -> Nucleus();
00249    mcinfo.had_fs        = itruth -> HadFS();
00250    mcinfo.iaction       = itruth -> Interaction();
00251    mcinfo.inu           = itruth -> INu();
00252    mcinfo.iresonance    = itruth -> Resonance();
00253 
00254    mcinfo.nuE  = itruth -> ENeu();
00255    mcinfo.nuPx = itruth -> Px();
00256    mcinfo.nuPy = itruth -> Py();
00257    mcinfo.nuPz = itruth -> Pz();
00258    
00259    mcinfo.tarE  = itruth -> TgtE();
00260    mcinfo.tarPx = itruth -> TgtPx();
00261    mcinfo.tarPy = itruth -> TgtPy();
00262    mcinfo.tarPz = itruth -> TgtPz();
00263    
00264    mcinfo.x  = itruth -> TrueX();
00265    mcinfo.y  = itruth -> TrueY();
00266    mcinfo.q2 = itruth -> TrueQ2();
00267    mcinfo.w2 = itruth -> TrueW2();
00268    
00269 
00270    const double weight = fCalc -> GetDetWeight(itruth -> Interaction(),
00271                                                itruth -> ENeu(),
00272                                                itruth -> INu(),
00273                                                elep,
00274                                                ehad,
00275                                                elep,
00276                                                ehad,
00277                                                itruth -> EHad(),
00278                                                &mcinfo);
00279    
00280    //
00281    // Reset hadronic energy and muon energy
00282    //
00283    event.GetRecoNu().SetEHad(ehad);
00284    event.GetRecoNu().SetELep(elep);
00285    
00286    //
00287    // Multiply new and previous weights
00288    //
00289    event.SetWeight(weight*event.Weight());
00290 
00291    return true;
00292 }

bool Anp::FillFlux::Fill ( Truth truth,
const Record record,
const BeamType::BeamType_t  beamtype 
) [private]

Definition at line 165 of file FillFlux.cxx.

References Anp::Truth::ENeu(), fCalc, Anp::Truth::Flux(), fNSigma, fRUNCYCLE, Anp::Record::GetHeader(), Anp::Truth::INu(), Anp::Header::IsFar(), Anp::Header::IsNear(), SKZPWeightCalculator::kNone, SKZPWeightCalculator::kRunI, SKZPWeightCalculator::kRunII, SKZPWeightCalculator::kTotalErrorAfterTune, BeamType::kUnknown, Anp::Truth::SetWeight(), BeamType::ToZarko(), Anp::FluxInfo::tptype, Anp::FluxInfo::tpx, Anp::FluxInfo::tpy, Anp::FluxInfo::tpz, and Anp::Truth::Weight().

Referenced by Run().

00166 {
00167    //
00168    // Get beam weight using database as a source for the fit parameters.
00169    //
00170    if(!fCalc || beamtype == BeamType::kUnknown)
00171    {
00172       return false;
00173    }
00174 
00175    SKZPWeightCalculator::RunPeriod_t runperiod = SKZPWeightCalculator::kNone;
00176    if     (fRUNCYCLE == "run-1") runperiod = SKZPWeightCalculator::kRunI;
00177    else if(fRUNCYCLE == "run-2") runperiod = SKZPWeightCalculator::kRunII;
00178    else
00179    {
00180       cerr << "FillFlux::Fill - unknown run period" << endl;
00181       return false;
00182    }
00183 
00184    int detector = 0;
00185    if     (record.GetHeader().IsNear()) detector = 1;
00186    else if(record.GetHeader().IsFar())  detector = 2;
00187    else
00188    {
00189       cerr << "FillFlux::Fill - unknown detector" << endl;
00190       return false;
00191    }
00192    
00193    const FluxInfo &flux = truth.Flux();
00194    const double pt = std::sqrt(flux.tpy*flux.tpy + flux.tpx*flux.tpx);
00195 
00196    double weight = truth.Weight() * fCalc -> GetBeamWeight(detector,
00197                                                            BeamType::ToZarko(beamtype),
00198                                                            flux.tptype,
00199                                                            pt,
00200                                                            flux.tpz,
00201                                                            truth.ENeu(),
00202                                                            truth.INu(),
00203                                                            runperiod);
00204    
00205    if(fNSigma != 0)
00206    {
00207       weight *= fCalc -> GetFluxError(detector,
00208                                       BeamType::ToZarko(beamtype),
00209                                       truth.INu(),
00210                                       truth.ENeu(),
00211                                       SKZPWeightCalculator::kTotalErrorAfterTune,
00212                                       static_cast<double>(fNSigma));
00213    }
00214    
00215    //
00216    // !!!Set new weight and ERASE previous weight!!!
00217    //
00218    truth.SetWeight(weight);
00219 
00220    return true;
00221 }

bool Anp::FillFlux::Init ( const Header  )  [virtual]

Reimplemented from Anp::AlgSnarl.

Definition at line 128 of file FillFlux.cxx.

References fCalc, fName, Anp::GetMainMutex(), and Anp::GetROOTMutex().

00129 {   
00130    if(fCalc)
00131    {
00132       cerr << "FillFlux::Init - SKZPWeightCalculator already exists" << endl;
00133       return false;
00134    }
00135 
00136    if(fName.empty() || fName == "Unknown")
00137    {
00138       cerr << "FillFlux::Init - unknown beam fit type" << endl;
00139       return false;
00140    }
00141    
00142    Anp::Lock<Mutex> lockM(Anp::GetMainMutex());
00143    Anp::Lock<Mutex> lockR(Anp::GetROOTMutex());
00144 
00145    fCalc = new SKZPWeightCalculator(fName.c_str(), true);
00146 
00147    return true;
00148 }

bool Anp::FillFlux::Run ( Record record  )  [virtual]

Implements Anp::AlgSnarl.

Definition at line 37 of file FillFlux.cxx.

References Anp::ApplyTrueWeights(), Anp::Record::EventBegIterator(), Anp::Record::EventEndIterator(), fFluxDet, Fill(), Anp::Header::GetBEAMTYPE(), Anp::Record::GetHeader(), Anp::GetMainMutex(), Anp::GetROOTMutex(), Anp::Header::IsData(), BeamType::kUnknown, BeamType::TagToEnum(), Anp::Record::TruthBeg(), Anp::Record::TruthBegIterator(), Anp::Record::TruthEnd(), and Anp::Record::TruthEndIterator().

00038 {
00039    //
00040    // Apply beam weights to all reconstructed and true objects
00041    //
00042    if(record.GetHeader().IsData() || record.TruthBeg() == record.TruthEnd())
00043    {
00044       return true;
00045    }
00046 
00047    //
00048    // Lock main PhysicsNtuple mutex
00049    //
00050    Anp::Lock<Mutex> lockM(Anp::GetMainMutex());
00051    Anp::Lock<Mutex> lockR(Anp::GetROOTMutex());
00052 
00053    //
00054    // Check for valid beam type
00055    //
00056    const BeamType::BeamType_t beam = BeamType::TagToEnum(record.GetHeader().GetBEAMTYPE().c_str());
00057    if(beam == BeamType::kUnknown)
00058    {
00059       cerr << "FillFlux::Run - unknown beam type: " << beam << endl;
00060       return false;
00061    }
00062 
00063    for(TruthIterator itruth = record.TruthBegIterator(); itruth != record.TruthEndIterator(); ++itruth)
00064    {
00065       FillFlux::Fill(*itruth, record, beam);
00066    }
00067 
00068    //
00069    // Apply true weights to reconstructed objects
00070    //
00071    Anp::ApplyTrueWeights(record);
00072 
00073    if(fFluxDet)
00074    {
00075       for(EventIterator ievent = record.EventBegIterator(); ievent != record.EventEndIterator(); ++ievent)
00076       {
00077          FillFlux::Fill(*ievent, record, beam);
00078       }
00079    }
00080 
00081    return true;
00082 }


Member Data Documentation

Definition at line 49 of file FillFlux.h.

Referenced by End(), Fill(), Init(), and ~FillFlux().

std::string Anp::FillFlux::fFLUX [private]

Definition at line 43 of file FillFlux.h.

Referenced by Config().

bool Anp::FillFlux::fFluxDet [private]

Definition at line 46 of file FillFlux.h.

Referenced by Config(), and Run().

std::string Anp::FillFlux::fName [private]

Reimplemented from Anp::AlgSnarl.

Definition at line 42 of file FillFlux.h.

Referenced by Config(), and Init().

int Anp::FillFlux::fNSigma [private]

Definition at line 47 of file FillFlux.h.

Referenced by Config(), and Fill().

std::string Anp::FillFlux::fRUNCYCLE [private]

Definition at line 44 of file FillFlux.h.

Referenced by Config(), and Fill().


The documentation for this class was generated from the following files:

Generated on 3 Oct 2018 for loon by  doxygen 1.6.1