Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JPostfit2F.cc File Reference

Example program to compare fit results from two files. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "km3net-dataformat/offline/Head.hh"
#include "km3net-dataformat/offline/Evt.hh"
#include "JAAnet/JAAnetToolkit.hh"
#include "JDAQ/JDAQEventIO.hh"
#include "JSupport/JTriggeredFileScanner.hh"
#include "JSupport/JMonteCarloFileSupportkit.hh"
#include "JSupport/JSupport.hh"
#include "JReconstruction/JEvt.hh"
#include "JReconstruction/JEvtToolkit.hh"
#include "JMath/JMathToolkit.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Macros

#define make_key(PARAMETER)
 Make key.
 

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to compare fit results from two files.

Author
mdejong

Definition in file JPostfit2F.cc.

Macro Definition Documentation

◆ make_key

#define make_key ( PARAMETER)
Value:
JKey(#PARAMETER, PARAMETER)

Make key.

Parameters
PARAMETERparameter
Returns
key

Definition at line 72 of file JPostfit2F.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 267 of file JPostfit2F.cc.

268{
269 using namespace std;
270 using namespace JPP;
271
272 typedef JTriggeredFileScanner<JEvt> JTriggeredFileScanner_t;
273 typedef JTriggeredFileScanner_t::multi_pointer_type multi_pointer_type;
274
275 JTriggeredFileScanner_t inputFileA;
276 JTriggeredFileScanner_t inputFileB;
277 JLimit_t numberOfEvents;
278 string outputFile;
279 double angle_Deg;
280 int debug;
281
282 try {
283
284 JParser<> zap("Example program to compare fit results from two files.");
285
286 zap['a'] = make_field(inputFileA);
287 zap['b'] = make_field(inputFileB);
288 zap['o'] = make_field(outputFile) = "postfit2f.root";
289 zap['n'] = make_field(numberOfEvents) = JLimit::max();
290 zap['A'] = make_field(angle_Deg) = 0.0;
291 zap['d'] = make_field(debug) = 2;
292
293 zap(argc, argv);
294 }
295 catch(const exception& error) {
296 FATAL(error.what() << endl);
297 }
298
299 JHead head;
300
301 try {
302 head = getHeader(inputFileA);
303 }
304 catch(const JException& error) {
305 FATAL(error);
306 }
307 const double E_nu_min = head.cut_nu.E.getLowerLimit(); //neutrino minimum energy
308 const double E_nu_max = head.cut_nu.E.getUpperLimit(); //neutrino maximum energy
309
310 inputFileA.setLimit(numberOfEvents);
311 inputFileB.setLimit(numberOfEvents);
312
313
314 TFile out(outputFile.c_str(), "recreate");
315
316 JManager manager;
317
318 manager.insert(make_key(JQUALITY), 501, 0.0, 1.0e3);
319 manager.insert(make_key(JGANDALF_BETA0_RAD), 501, 0.0, 2.0e-2);
320 manager.insert(make_key(JGANDALF_BETA1_RAD), 501, 0.0, 2.0e-2);
321 manager.insert(make_key(JGANDALF_NUMBER_OF_HITS), 500, 0.0, 500.0);
322 manager.insert(make_key(JSTART_NPE_MIP), 501, 0.0, 500.0);
323 manager.insert(make_key(JSTART_NPE_MIP_TOTAL), 501, 0.0, 500.0);
324 manager.insert(make_key(JSTART_LENGTH_METRES), 501, 0.0, 2.0e3);
325 manager.insert(make_key(JENERGY_ENERGY), 501, 1.0, 8.0, true);
326 manager.insert(make_key(JENERGY_CHI2), 501, 0.0, 500.0);
327
328 TH1D hA("h[A]", NULL, 100, -3.0, +2.3); // [log(deg)]
329 TH1D hB("h[B]", NULL, 100, -3.0, +2.3); // [log(deg)]
330 TH2D hA_angle_E("hA_angle_E", NULL, 20, E_nu_min, E_nu_max, 100, 0,90); //energy vs angular deviation between true and reco muon direction
331 TH2D hB_angle_E("hB_angle_E", NULL, 20, E_nu_min, E_nu_max, 100, 0,90); //energy vs angular deviation between true and reco muon direction
332 TH2D h2("h2", NULL,
333 100, -100.0, +100.0, // quality
334 360, -180.0, +180.0); // deg
335
336 while (inputFileA.hasNext() && inputFileB.hasNext()) {
337
338 STATUS("event: " << setw(10) << inputFileA.getCounter() << '\r'); DEBUG(endl);
339
340 multi_pointer_type psA = inputFileA.next();
341 multi_pointer_type psB = inputFileB.next();
342
343 // find the same corresponding Monte Carlo true event based on the event identifier.
344
345 while (psA.get<Evt>()->mc_id < psB.get<Evt>()->mc_id && inputFileA.hasNext()) { psA = inputFileA.next(); }
346 while (psB.get<Evt>()->mc_id < psA.get<Evt>()->mc_id && inputFileB.hasNext()) { psB = inputFileB.next(); }
347
348 if (!psA.is_valid()) { continue; }
349 if (!psB.is_valid()) { continue; }
350
351 if (psA.get<Evt>()->mc_id == psB.get<Evt>()->mc_id) {
352
353 Evt* event = psA;
354 JEvt* evtA = psA;
355 JEvt* evtB = psB;
356
357 const Trk neutrino = get_neutrino(*event);
358
359 vector<Trk>::const_iterator muon = find_if(event->mc_trks.begin(), event->mc_trks.end(), is_muon);
360
361 if (muon == event->mc_trks.end()) { continue; }
362
363 if (evtA->empty()) { continue; }
364 if (evtB->empty()) { continue; }
365
366 JEvt::const_iterator fitA = evtA->begin();
367 JEvt::const_iterator fitB = evtB->begin();
368
369 const Double_t angleA = getAngle(getDirection(*muon), getDirection(*fitA));
370 const Double_t angleB = getAngle(getDirection(*muon), getDirection(*fitB));
371
372 hA.Fill(log10(angleA));
373 hB.Fill(log10(angleB));
374
375 h2.Fill(fitB->getQ() - fitA->getQ(), angleB - angleA);
376
377 const double Enu = neutrino.E; //true neutrino E
378 hA_angle_E.Fill(Enu, angleA);
379 hB_angle_E.Fill(Enu, angleB);
380
381 if (angleA >= angle_Deg) {
382 manager.Fill(*fitA, *fitB, angleB < angle_Deg);
383 }
384 }
385 }
386 STATUS(endl);
387
388 out.Write();
389 out.Close();
390}
string outputFile
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define STATUS(A)
Definition JMessage.hh:63
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
#define make_key(PARAMETER)
Make key.
Definition JPostfit2F.cc:72
Monte Carlo run header.
Definition JHead.hh:1236
JAANET::cut_nu cut_nu
Definition JHead.hh:1596
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
Definition JManager.hh:47
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
static const int JENERGY_ENERGY
uncorrected energy [GeV] from JEnergy.cc
static const int JENERGY_CHI2
chi2 from JEnergy.cc
static const int JSTART_NPE_MIP_TOTAL
number of photo-electrons along the whole track from JStart.cc
static const int JSTART_LENGTH_METRES
distance between projected positions on the track of optical modules for which the response does not ...
static const int JGANDALF_BETA0_RAD
KM3NeT Data Definitions v3.5.1-1-gd514d72 https://git.km3net.de/common/km3net-dataformat.
static const int JGANDALF_BETA1_RAD
angular resolution [rad] from JGandalf.cc
static const int JSTART_NPE_MIP
number of photo-electrons up to the barycentre from JStart.cc
static const int JGANDALF_NUMBER_OF_HITS
number of hits from JGandalf.cc
JDirection3D getDirection(const Vec &dir)
Get direction.
bool is_muon(const Trk &track)
Test whether given track is a (anti-)muon.
const Trk & get_neutrino(const Evt &evt)
Get incoming neutrino.
double getAngle(const JQuaternion3D &first, const JQuaternion3D &second)
Get space angle between quanternions.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Head getHeader(const JMultipleFileScanner_t &file_list)
Get Monte Carlo header.
The Evt class respresent a Monte Carlo (MC) event as well as an offline event.
Definition Evt.hh:21
int mc_id
identifier of the MC event (as found in ascii or antcc file).
Definition Evt.hh:24
JRange_t E
Energy range [GeV].
Definition JHead.hh:419
Acoustic event fit.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
static counter_type max()
Get maximum counter value.
Definition JLimit.hh:128
Auxiliary class to synchronously read DAQ events and Monte Carlo events (and optionally other events)...
The Trk class represents a Monte Carlo (MC) particle as well as a reconstructed track/shower.
Definition Trk.hh:15
double E
Energy [GeV] (either MC truth or reconstructed)
Definition Trk.hh:20