13 #include <TDatabasePDG.h>
28 #include "fastjet/ClusterSequence.hh"
29 #include "fastjet/PseudoJet.hh"
33 #include "fastjet/contrib/Recluster.hh"
34 #include "fastjet/contrib/SoftDrop.hh"
39 using namespace fastjet;
42 int main(
int argc,
char* argv[]){
46 TString truthname=
"truth.root";
47 TString smearedname =
"";
48 TString outfilebase =
"jets";
51 vector<string> arguments(argv + 1, argv + argc);
53 for (
auto parg = arguments.begin() ; parg!=arguments.end() ; ++parg){
56 if (++parg == arguments.end() ){ argsokay=
false;
break; }
58 }
else if ( arg ==
"-t" ){
59 if (++parg ==arguments.end() ){ argsokay=
false;
break; }
61 }
else if ( arg ==
"-s" ){
62 if (++parg ==arguments.end() ){ argsokay=
false;
break; }
64 }
else if ( arg ==
"-N" ){
65 if (++parg==arguments.end() ){ argsokay=
false;
break; }
66 nevents=std::stoi(parg->data());
74 cerr <<
"usage: " << argv[0] << endl
75 <<
" [-t truthname] (root file)" << endl
76 <<
" [-s smearedname] (root file)" << endl
77 <<
" [-o OutFileBase] (extension will be added)" << endl
78 <<
" [-N Nevents] (<0 for all)" << endl
83 if (smearedname ==
"" ){
84 smearedname = truthname;
85 smearedname.ReplaceAll (
".root",
".smeared.root" );
95 JetDefinition jet_def = JetDefinition(kt_algorithm, R);
98 double ConstEtaMax = 3.5;
99 double ConstEtaMin = -ConstEtaMax;
101 double JetEtaMax = ConstEtaMax -
R;
102 double JetEtaMin = -JetEtaMax;
104 auto select_jet_eta = fastjet::SelectorEtaRange ( JetEtaMin + R, JetEtaMax -R );
105 auto select_jet_pt = SelectorPtRange( jetPtCut, 1000 );
106 auto select_jet = select_jet_eta * select_jet_pt;
116 double Q2max = 1000000;
122 TF1* eff =
new TF1(
"eff",
"(x>[2]) * [0]*TMath::Erf(x-[1])",0, 100);
125 eff->SetParameters (0.99,-0.8, 0.2);
130 TChain* inTree =
new TChain(
"EICTree");
131 inTree->Add(truthname);
132 inTree->AddFriend(
"Smeared",smearedname);
137 inTree->SetBranchAddress(
"event",&inEvent);
138 inTree->SetBranchAddress(
"eventS",&inEventS);
142 TFile * outfile =
new TFile ( outfilebase +
".root",
"RECREATE");
144 TH1::SetDefaultSumw2(
true);
148 TH1D* truthpt=
new TH1D(
"truthpt",
";p_{T}^{truth} [GeV/c];counts", ptbins, ptmin, ptmax );
149 TH1D* smearpt=
new TH1D(
"smearpt",
";p_{T}^{smear} [GeV/c];counts", ptbins, ptmin, ptmax );
150 TH2D* smearvtruept=
new TH2D(
"smearvtruept",
";p_{T}^{truth} [GeV/c];p_{T}^{smear} [GeV/c];counts", ptbins, ptmin, ptmax, ptbins, ptmin, ptmax );
157 TH2D* smearvtruezg=
new TH2D(
"smearvtruezg",
";z_{g}^{truth};z_{g}^{smear};counts", zgbins, zgmin, zgmax, zgbins, zgmin, zgmax );
160 contrib::SoftDrop sd( beta, z_cut);
180 vector<PseudoJet> TruthConstituents;
181 vector<PseudoJet> SmearedConstituents;
182 if ( nevents < 0 ) nevents = inTree->GetEntries();
184 for(
long iEvent=0; iEvent<
nevents; iEvent++){
187 if(inTree->GetEntry(iEvent) <=0)
break;
188 if(iEvent%10000 == 0) cout <<
"Event " << iEvent << endl;
193 bool truthacceptev =
true;
194 bool smearacceptev =
true;
198 if ( inEvent->
GetX() < xmin || inEvent->
GetX() >
xmax ) truthacceptev =
false;
199 if ( inEvent->
GetY() < ymin || inEvent->
GetY() >
ymax ) truthacceptev =
false;
200 if ( inEvent->
GetQ2() < Q2min || inEvent->
GetQ2() > Q2max ) truthacceptev =
false;
208 if ( xS < xmin || xS > xmax ) smearacceptev =
false;
209 if ( yS < ymin || yS > ymax ) smearacceptev =
false;
210 if ( Q2S < Q2min || Q2S > Q2max ) smearacceptev =
false;
212 if ( !truthacceptev ) rejectevent++;
214 if ( !truthacceptev && !smearacceptev )
continue;
226 if ( truthacceptev && smearacceptev ) keptevent++;
227 if ( truthacceptev && !smearacceptev ) lostevent++;
228 if ( !truthacceptev && smearacceptev ) fakeevent++;
233 TruthConstituents.clear();
234 SmearedConstituents.clear();
236 for(
unsigned int j=0; j<inEventS->
GetNTracks(); j++){
244 if ( inParticle->
GetStatus() != 1 )
continue;
248 bool truthacceptp = truthacceptev;
250 if ( inParticle->
GetEta() < ConstEtaMin || inParticle->
GetEta() > ConstEtaMax) truthacceptp=
false;
254 bool smearacceptp = smearacceptev;
255 if ( !inParticleS ) smearacceptp=
false;
270 double E = inParticleS->
GetE();
271 double px = inParticleS->
GetPx();
272 double py = inParticleS->
GetPy();
273 double pz = inParticleS->
GetPz();
274 double P = inParticleS->
GetP();
276 bool charged=( fabs(P)>
epsilon );
280 auto ran = gRandom->Uniform (0,1);
281 auto pt = std::sqrt ( px*px + py*py );
282 if (
ran > eff->Eval ( pt ) ) {
291 if ( fabs(P) <= epsilon && fabs(E) <=
epsilon ){
298 if ( fabs(P) > epsilon && fabs(E) >
epsilon ){
314 if ( fabs(P) > epsilon && fabs(E) <=
epsilon ){
323 bool IsElectroMagnetic = ( abspid==22 || abspid == 11);
325 if (IsElectroMagnetic){
328 E = std::sqrt(P*P + m*m);
332 E = std::sqrt(P*P + m*m);
337 if ( fabs(P) <= epsilon && fabs(E) > epsilon ){
346 smearacceptp =
false;
395 pj = PseudoJet (px, py, pz, E);
404 if ( pj.eta() < ConstEtaMin || pj.eta() > ConstEtaMax) smearacceptp=
false;
410 TruthConstituents.push_back ( PseudoJet (inParticle->
GetPx(),
413 inParticle->
GetE()) );
416 SmearedConstituents.push_back ( pj );
423 ClusterSequence truthcs(TruthConstituents, jet_def);
424 vector<PseudoJet> truthjets = sorted_by_pt( select_jet(truthcs.inclusive_jets()) );
426 ClusterSequence smearcs(SmearedConstituents, jet_def);
427 vector<PseudoJet> smearjets = sorted_by_pt( select_jet(smearcs.inclusive_jets()) );
432 for (
auto tj : truthjets ){
433 truthpt->Fill ( tj.pt() );
436 for (
auto sj : smearjets ){
437 smearpt->Fill ( sj.pt() );
443 fastjet::Selector SelectClose = fastjet::SelectorCircle( R );
444 for (
auto tj : truthjets ){
445 SelectClose.set_reference (tj);
446 vector<PseudoJet> matchedjets = sorted_by_pt( SelectClose (smearjets) );
448 if ( matchedjets.size() > 1 ) {
449 cout <<
"Warning: multiple matches. Skipping." << endl;
452 if ( matchedjets.size() > 0 ){
453 auto sj = matchedjets.at(0);
454 smearvtruept->Fill ( tj.pt(), sj.pt() );
457 PseudoJet sd_truth = sd( tj );
458 PseudoJet sd_smear = sd( sj );
459 double tzg = sd_truth.structure_of<contrib::SoftDrop>().symmetry();
460 double szg = sd_smear.structure_of<contrib::SoftDrop>().symmetry();
461 smearvtruezg->Fill ( tzg, szg );
468 cout <<
" Done." << endl;
469 cout <<
"Processed " << nevents <<
" events. Of these, " << endl;
470 cout <<
" --- " << keptevent <<
" were ACCEPTED in both truth and smeared tree," << endl;
471 cout <<
" --- " << lostevent <<
" were LOST due to cuts," << endl;
472 cout <<
" --- " << rejectevent <<
" were REJECTED at truth level, and " << endl;
473 cout <<
" --- " << fakeevent <<
" were recovered as FAKEs, i.e. they passed the cuts only after smearing." << endl;
477 truthpt->SetLineColor( kBlack );
479 smearpt->SetLineColor( kRed );
480 smearpt->Draw(
"same");
481 gPad->SaveAs( outfilebase +
"_pt.png");
485 smearvtruept->Draw(
"colz");
486 gPad->SaveAs( outfilebase +
"_responsept.png");
490 smearvtruezg->Draw(
"colz");
491 gPad->SaveAs( outfilebase +
"_responsezg.png");