6 #include "TLorentzVector.h" 8 #include "EVGCore/EventRecord.h" 9 #include "nusystematics/artless/response_helper.hh" 13 const double mmu = 0.1056583745;
35 caf.
Elep_reco = sqrt(reco_p*reco_p + mmu*mmu);
40 if( evalTsmear < 0. ) evalTsmear = 0.;
41 double reco_tx = true_tx +
rando->Gaus(0., evalTsmear/sqrt(2.));
42 double reco_ty = true_ty +
rando->Gaus(0., evalTsmear/sqrt(2.));
43 caf.
theta_reco = 0.001*sqrt( reco_tx*reco_tx + reco_ty*reco_ty );
65 if( evalTsmear < 0. ) evalTsmear = 0.;
66 double reco_tx = true_tx +
rando->Gaus(0., evalTsmear/sqrt(2.));
67 double reco_ty = true_ty +
rando->Gaus(0., evalTsmear/sqrt(2.));
68 caf.
theta_reco = 0.001*sqrt( reco_tx*reco_tx + reco_ty*reco_ty );
96 if( evalTsmear < 0. ) evalTsmear = 0.;
97 double reco_tx = true_tx +
rando->Gaus(0., evalTsmear/sqrt(2.));
98 double reco_ty = true_ty +
rando->Gaus(0., evalTsmear/sqrt(2.));
99 caf.
theta_reco = 0.001*sqrt( reco_tx*reco_tx + reco_ty*reco_ty );
118 if(
rando->Rndm() > (caf.
LepE-0.3)*2.5 ) {
131 if( evalTsmear < 0. ) evalTsmear = 0.;
132 double reco_tx = true_tx +
rando->Gaus(0., evalTsmear/sqrt(2.));
133 double reco_ty = true_ty +
rando->Gaus(0., evalTsmear/sqrt(2.));
134 caf.
theta_reco = 0.001*sqrt( reco_tx*reco_tx + reco_ty*reco_ty );
138 void decayPi0( TLorentzVector pi0, TVector3 &gamma1, TVector3 &gamma2 )
141 double mp = 134.9766;
143 double beta = sqrt( 1. - (mp*mp)/(e*e) );
145 double phi = 2.*3.1416*
rando->Rndm();
148 TLorentzVector g1( 0., 0., p, p );
149 TLorentzVector
g2( 0., 0., -p, p );
158 g1.Boost( 0., 0., beta );
159 g2.Boost( 0., 0., beta );
162 if( g1.E() > g2.E() ) {
171 TVector3 pi0dir = pi0.Vect().Unit();
172 gamma1.RotateUz( pi0dir );
173 gamma2.RotateUz( pi0dir );
180 int ievt, lepPdg, muonReco, nFS;
181 float lepKE, muGArLen, muECalLen, hadTot, hadCollar;
182 float hadP, hadN, hadPip, hadPim, hadPi0, hadOther;
183 float p3lep[3], vtx[3], muonExitPt[3], muonExitMom[3];
185 float fsPx[100], fsPy[100], fsPz[100], fsE[100], fsTrkLen[100], fsTrkLenPerp[100];
186 tree->SetBranchAddress(
"ievt", &ievt );
187 tree->SetBranchAddress(
"lepPdg", &lepPdg );
188 tree->SetBranchAddress(
"muonReco", &muonReco );
189 tree->SetBranchAddress(
"lepKE", &lepKE );
190 tree->SetBranchAddress(
"muGArLen", &muGArLen );
191 tree->SetBranchAddress(
"muECalLen", &muECalLen );
192 tree->SetBranchAddress(
"hadTot", &hadTot );
193 tree->SetBranchAddress(
"hadCollar", &hadCollar );
194 tree->SetBranchAddress(
"hadP", &hadP );
195 tree->SetBranchAddress(
"hadN", &hadN );
196 tree->SetBranchAddress(
"hadPip", &hadPip );
197 tree->SetBranchAddress(
"hadPim", &hadPim );
198 tree->SetBranchAddress(
"hadPi0", &hadPi0 );
199 tree->SetBranchAddress(
"hadOther", &hadOther );
200 tree->SetBranchAddress(
"p3lep", p3lep );
201 tree->SetBranchAddress(
"vtx", vtx );
202 tree->SetBranchAddress(
"muonExitPt", muonExitPt );
203 tree->SetBranchAddress(
"muonExitMom", muonExitMom );
206 tree->SetBranchAddress(
"nFS", &nFS );
207 tree->SetBranchAddress(
"fsPdg", fsPdg );
208 tree->SetBranchAddress(
"fsPx", fsPx );
209 tree->SetBranchAddress(
"fsPy", fsPy );
210 tree->SetBranchAddress(
"fsPz", fsPz );
211 tree->SetBranchAddress(
"fsE", fsE );
212 tree->SetBranchAddress(
"fsTrkLen", fsTrkLen );
213 tree->SetBranchAddress(
"fsTrkLenPerp", fsTrkLenPerp );
218 nusyst::response_helper rh( fhicl_filename );
220 std::vector<unsigned int> parIds = rh.GetParameters();
221 for(
unsigned int i = 0; i < parIds.size(); ++i ) {
222 systtools::SystParamHeader head = rh.GetHeader(parIds[i]);
223 printf(
"Adding reweight branch %u for %s with %lu shifts\n", parIds[i], head.prettyName.c_str(), head.paramVariations.size() );
224 bool is_wgt = head.isWeightSystematicVariation;
226 caf.
addRWbranch( parIds[i], head.prettyName, wgt_var, head.paramVariations );
227 caf.
iswgt[parIds[i]] = is_wgt;
230 caf.
pot = gtree->GetWeight();
231 gtree->SetBranchAddress(
"gmcrec", &caf.
mcrec );
234 int N = tree->GetEntries();
235 for(
int ii = par.
first; ii < N; ++ii ) {
238 if( ii % 100 == 0 ) printf(
"Event %d of %d...\n", ii, N );
243 for(
int j = 0; j < 100; ++j ) {
246 for(
unsigned int k = 0;
k < 100; ++
k ) {
247 caf.
wgt[j][
k] = ( caf.
iswgt[j] ? 1. : 0. );
264 gtree->GetEntry( ievt );
276 TLorentzVector lepP4;
304 for(
int i = 0; i < nFS; ++i ) {
305 double ke = 0.001*(fsE[i] - sqrt(fsE[i]*fsE[i] - fsPx[i]*fsPx[i] - fsPy[i]*fsPy[i] - fsPz[i]*fsPz[i]));
306 if( fsPdg[i] == caf.
LepPDG ) {
307 lepP4.SetPxPyPzE( fsPx[i]*0.001, fsPy[i]*0.001, fsPz[i]*0.001, fsE[i]*0.001 );
308 caf.
LepE = fsE[i]*0.001;
310 else if( fsPdg[i] == 2212 ) {caf.
nP++; caf.
eP += ke;}
311 else if( fsPdg[i] == 2112 ) {caf.
nN++; caf.
eN += ke;}
312 else if( fsPdg[i] == 211 ) {caf.
nipip++; caf.
ePip += ke;}
313 else if( fsPdg[i] == -211 ) {caf.
nipim++; caf.
ePim += ke;}
314 else if( fsPdg[i] == 111 ) {caf.
nipi0++; caf.
ePi0 += ke;}
315 else if( fsPdg[i] == 321 ) {caf.
nikp++; caf.
eOther += ke;}
316 else if( fsPdg[i] == -321 ) {caf.
nikm++; caf.
eOther += ke;}
317 else if( fsPdg[i] == 311 || fsPdg[i] == -311 || fsPdg[i] == 130 || fsPdg[i] == 310 ) {caf.
nik0++; caf.
eOther += ke;}
318 else if( fsPdg[i] == 22 ) {caf.
niem++; caf.
eOther += ke;}
319 else if( fsPdg[i] > 1000000000 ) caf.
nNucleus++;
324 TLorentzVector q = nuP4-lepP4;
328 caf.
W = sqrt(0.939*0.939 + 2.*q.E()*0.939 + q.Mag2());
329 caf.
X = -q.Mag2()/(2*0.939*q.E());
330 caf.
Y = q.E()/caf.
Ev;
340 caf.
LepE = lepP4.E();
345 systtools::event_unit_response_w_cv_t resp = rh.GetEventVariationAndCVResponse(*
event);
347 caf.
nwgt[(*it).pid] = (*it).responses.size();
348 caf.
cvwgt[(*it).pid] = (*it).CV_response;
349 for(
unsigned int i = 0; i < (*it).responses.size(); ++i ) {
350 caf.
wgt[(*it).pid][i] = (*it).responses[i];
359 double longest_mip = 0.;
360 double longest_mip_KE = 0.;
361 int longest_mip_charge = 0;
364 double electron_energy = 0.;
365 int reco_electron_pdg = 0;
366 for(
int i = 0; i < nFS; ++i ) {
368 double p = sqrt(fsPx[i]*fsPx[i] + fsPy[i]*fsPy[i] + fsPz[i]*fsPz[i]);
369 double KE = fsE[i] - sqrt(fsE[i]*fsE[i] - p*p);
371 if( (
abs(pdg) == 13 ||
abs(pdg) == 211) && fsTrkLen[i] > longest_mip ) {
372 longest_mip = fsTrkLen[i];
375 if( pdg == 13 || pdg == -211 ) longest_mip_charge = -1;
376 else longest_mip_charge = 1;
382 TLorentzVector pi0( fsPx[i], fsPy[i], fsPz[i], fsE[i] );
384 double g1conv =
rando->Exp( 14. );
385 bool compton = (
rando->Rndm() < 0.15);
387 if( g1conv < 2.0 && compton && (g2.Mag() < 50. || g1.Angle(g2) < 0.01) ) electrons++;
388 electron_energy = g1.Mag();
389 reco_electron_pdg = 111;
394 if(
abs(lepPdg) == 11 ) {
397 reco_electron_pdg = lepPdg;
398 }
else if(
abs(lepPdg) == 13 ) {
401 else if( muonReco == 3 && muECalLen > 5. )
recoMuonECAL( caf, par );
411 if( evalTsmear < 0. ) evalTsmear = 0.;
412 double reco_tx = true_tx +
rando->Gaus(0., evalTsmear/sqrt(2.));
413 double reco_ty = true_ty +
rando->Gaus(0., evalTsmear/sqrt(2.));
414 caf.
theta_reco = 0.001*sqrt( reco_tx*reco_tx + reco_ty*reco_ty );
424 if( electrons == 1 && muonReco <= 1 ) {
430 }
else if( muonReco <= 1 && !(
abs(lepPdg) == 11 && caf.
Elep_reco > 0.) && (longest_mip < par.CC_trk_length || longest_mip_KE/longest_mip > 3.) ) {
437 }
else if( (
abs(lepPdg) == 12 ||
abs(lepPdg) == 14) && longest_mip > par.
CC_trk_length && longest_mip_KE/longest_mip < 3. ) {
442 if( longest_mip_charge == 1 && michel < par.
michelEff ) caf.
reco_q = 1;
467 for(
int i = 0; i < nFS; ++i ) {
468 double ptrue = 0.001*sqrt(fsPx[i]*fsPx[i] + fsPy[i]*fsPy[i] + fsPz[i]*fsPz[i]);
469 double mass = 0.001*sqrt(fsE[i]*fsE[i] - fsPx[i]*fsPx[i] - fsPy[i]*fsPy[i] - fsPz[i]*fsPz[i]);
470 caf.
pdg[i] = fsPdg[i];
471 caf.
ptrue[i] = ptrue;
472 caf.
trkLen[i] = fsTrkLen[i];
475 if( fsTrkLen[i] > 0. && fsPdg[i] != 2112 ) {
476 double pT = 0.001*sqrt(fsPy[i]*fsPy[i] + fsPz[i]*fsPz[i]);
479 double fracSig_meas = sqrt(720./(nHits+4)) * (0.01*par.
gastpc_padPitch/sqrt(12.)) * pT / (0.3 * par.
gastpc_B * 0.0001 * fsTrkLenPerp[i]*fsTrkLenPerp[i]);
481 double fracSig_MCS = 0.052 / (par.
gastpc_B * sqrt(par.
gastpc_X0*fsTrkLenPerp[i]*0.0001));
483 double sigmaP = ptrue * sqrt( fracSig_meas*fracSig_meas + fracSig_MCS*fracSig_MCS );
484 double preco =
rando->Gaus( ptrue, sigmaP );
485 double ereco = sqrt( preco*preco + mass*mass ) - mass;
486 if(
abs(fsPdg[i]) == 211 ) ereco += mass;
487 else if( fsPdg[i] == 2212 && preco > 1.5 ) ereco += 0.1395;
493 if( fsPdg[i] == 211 || (fsPdg[i] == 2212 && preco > 1.5) ) caf.
gastpc_pi_pl_mult++;
497 if( (fsPdg[i] == 13 || fsPdg[i] == -13) && fsTrkLen[i] > 100. ) {
499 caf.
Elep_reco = sqrt(preco*preco + mass*mass);
504 if( evalTsmear < 0. ) evalTsmear = 0.;
505 double reco_tx = true_tx +
rando->Gaus(0., evalTsmear/sqrt(2.));
506 double reco_ty = true_ty +
rando->Gaus(0., evalTsmear/sqrt(2.));
507 caf.
theta_reco = 0.001*sqrt( reco_tx*reco_tx + reco_ty*reco_ty );
509 caf.
reco_q = (fsPdg[i] > 0 ? -1 : 1);
513 }
else if( fsPdg[i] == 111 || fsPdg[i] == 22 ) {
514 double ereco = 0.001 *
rando->Gaus( fsE[i], 0.1*fsE[i] );
534 std::cout <<
"Help yourself by looking at the source code to see what the options are." <<
std::endl;
539 gInterpreter->GenerateDictionary(
"vector<vector<vector<uint64_t> > >",
"vector");
583 fhicl_filename = argv[i+1];
586 par.
seed = atoi(argv[i+1]);
605 tsmear =
new TF1(
"tsmear",
"0.162 + 3.407*pow(x,-1.) + 3.129*pow(x,-0.5)", 0., 999.9 );
607 TFile *
tf =
new TFile( infile.c_str() );
608 TTree *
tree = (TTree*) tf->Get(
"tree" );
610 TFile *
gf =
new TFile( gfile.c_str() );
611 TTree * gtree = (TTree*) gf->Get(
"gtree" );
613 loop( caf, par, tree, gtree, fhicl_filename );
616 printf(
"Run %d POT %g\n", caf.
meta_run, caf.
pot );
620 std::cout <<
"Copying geometric efficiency throws TTree to output file" <<
std::endl;
623 tGeoEfficiencyThrowsOut->CloneTree()->Write();
void addRWbranch(int parId, std::string name, std::string wgt_var, std::vector< double > &vars)
double beta(double KE, const simb::MCParticle *part)
void recoMuonLAr(CAF &caf, params &par)
genie::NtpMCEventRecord * mcrec
std::vector< double > trkLen
std::vector< double > trkLenPerp
void recoElectron(CAF &caf, params &par)
int main(int argc, char const *argv[])
int FSPrimLeptonPdg(void) const
final state primary lepton pdg
Summary information for an interaction.
TFile * cafFile
The output TFile pointer */.
std::string * muon_endVolName
void recoMuonECAL(CAF &caf, params &par)
ScatteringType_t ScatteringTypeId(void) const
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
void loop(CAF &caf, params &par, TTree *tree, TTree *gtree, std::string fhicl_filename)
const InitialState & InitState(void) const
const ProcessInfo & ProcInfo(void) const
std::vector< std::vector< std::vector< uint64_t > > > * geoEffThrowResults
void decayPi0(TLorentzVector pi0, TVector3 &gamma1, TVector3 &gamma2)
double ProbeE(RefFrame_t rf) const
QTextStream & endl(QTextStream &s)
TLorentzVector * GetProbeP4(RefFrame_t rf=kRfHitNucRest) const
Event finding and building.
void recoMuonTracker(CAF &caf, params &par)