Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19250501
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
10 KB
Referenced Files
None
Subscribers
None
View Options
Index: trunk/examples/sartreMain.cpp
===================================================================
--- trunk/examples/sartreMain.cpp (revision 143)
+++ trunk/examples/sartreMain.cpp (revision 144)
@@ -1,243 +1,280 @@
//==============================================================================
// sartreMain.cpp
//
// Copyright (C) 2010-2013 Tobias Toll and Thomas Ullrich
//
// This file is part of Sartre version: 1.1
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation.
// This program is distributed in the hope that it will be useful,
// but without any warranty; without even the implied warranty of
// merchantability or fitness for a particular purpose. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// Author: Thomas Ullrich
// Last update:
// $Date$
// $Author$
//==============================================================================
//
// Example main program. Use to get started.
//
//==============================================================================
#include <iostream>
#include <cmath>
#include "TTree.h"
#include "TFile.h"
#include "Sartre.h"
#include "TGenPhaseSpace.h"
#include "Settings.h"
#include "TH1D.h"
+#include "TROOT.h"
+#include "TLorentzVector.h"
+#include "TClonesArray.h"
#define PR(x) cout << #x << " = " << (x) << endl;
using namespace std;
struct rootSartreEvent {
double t;
double Q2;
double x;
double s;
double y;
double W;
double xpom;
int iEvent;
int pol; // 0=transverse or 1=longitudinal
int dmode; // 0=coherent, 1=Incoherent
};
rootSartreEvent myRootSartreEvent;
void randomlyReverseBeams(Event* myEvent){
TRandom3 *random = EventGeneratorSettings::randomGenerator();
if(random->Uniform(1) > 0.5){
for(unsigned int i=0; i<myEvent->particles.size(); i++)
myEvent->particles.at(i).p.RotateX(M_PI);
}
}
int main(int argc, char *argv[])
{
//
// Check command line arguments
//
if (! (argc == 2 || argc == 3) ) {
cout << "Usage: " << argv[0] << " runcard [rootfile]" << endl;
return 2;
}
string runcard = argv[1];
//
// Create the generator and initialize it.
// Once initialized you cannot (should not) change
// the settings w/o re-initialing sartre.
//
Sartre sartre;
bool ok = sartre.init(runcard);
if (!ok) {
cerr << "Initialization of sartre failed." << endl;
return 1;
}
EventGeneratorSettings* settings = sartre.runSettings();
settings->list();
//
// ROOT file
//
string rootfile;
if (argc == 3)
rootfile = argv[2];
else
rootfile = settings->rootfile();
TFile *hfile = 0;
if (rootfile.size()) {
hfile = new TFile(rootfile.c_str(),"RECREATE");
cout << "ROOT file is '" << rootfile.c_str() << "'." << endl;
}
-
+ // gROOT->ProcessLine("#pragma link C++ class std::vector<TLorentzVector*>+");
+ // gROOT->ProcessLine("#include <vector>");
//
// Setup ROOT tree for some basic debugging
//
+
TLorentzVector *eIn = new TLorentzVector;
TLorentzVector *pIn = new TLorentzVector;
TLorentzVector *vm = new TLorentzVector;
TLorentzVector *eOut = new TLorentzVector;
TLorentzVector *pOut = new TLorentzVector;
TLorentzVector *gamma = new TLorentzVector;
TLorentzVector *vmDaughter1 = new TLorentzVector;
TLorentzVector *vmDaughter2 = new TLorentzVector;
+ TClonesArray protons("TLorentzVector");
+ TClonesArray neutrons("TLorentzVector");
+ TClonesArray remnants("TLorentzVector");
+
TTree tree("tree","sartre");
tree.Branch("event", &myRootSartreEvent.t,
"t/D:Q2/D:x/D:s/D:y/D:W/D:xpom/D:iEvent/I:pol/I:dmode/I");
tree.Branch("eIn", "TLorentzVector", &eIn, 32000, 0);
tree.Branch("pIn", "TLorentzVector", &pIn, 32000, 0);
tree.Branch("vm", "TLorentzVector", &vm, 32000, 0);
tree.Branch("eOut", "TLorentzVector", &eOut, 32000, 0);
tree.Branch("pOut", "TLorentzVector", &pOut, 32000, 0);
tree.Branch("gamma","TLorentzVector", &gamma, 32000, 0);
tree.Branch("vmDaughter1", "TLorentzVector", &vmDaughter1, 32000, 0);
tree.Branch("vmDaughter2", "TLorentzVector", &vmDaughter2, 32000, 0);
+ if(settings->enableNuclearBreakup()){
+ tree.Branch("protons", &protons);
+ tree.Branch("neutrons", &neutrons);
+ tree.Branch("nuclearRemnants", &remnants);
+ }
//
// Prepare event generation
//
TGenPhaseSpace decay; // for VM decays
int daughterID = settings->userInt();
double daughterMasses[2] = {0, 0};
bool doPerformDecay = false;
if (daughterID && settings->vectorMesonId() != 22) {
doPerformDecay = true;
daughterMasses[0] = settings->lookupPDG(daughterID)->Mass();
daughterMasses[1] = settings->lookupPDG(-daughterID)->Mass();
cout << "Will decay vector meson: ";
cout << settings->lookupPDG(settings->vectorMesonId())->GetName();
cout << " -> ";
cout << settings->lookupPDG(daughterID)->GetName();
cout << " ";
cout << settings->lookupPDG(-daughterID)->GetName();
cout << endl;
}
int nPrint;
if (settings->timesToShow())
nPrint = settings->numberOfEvents()/settings->timesToShow();
else
nPrint = 0;
unsigned long maxEvents = settings->numberOfEvents();
cout << "Generating " << maxEvents << " events." << endl << endl;
//
// Event generation
//
for (unsigned long iEvent = 0; iEvent < maxEvents; iEvent++) {
//
// Generate one event
//
Event *event = sartre.generateEvent();
if (nPrint && (iEvent+1)%nPrint == 0 && iEvent != 0) {
cout << "processed " << iEvent+1 << " events" << endl;
}
//
// If Sartre is run in UPC mode, half of the events needs to be
// rotated around and axis perpendicular to z:
//
if(settings->UPC() and settings->A()==settings->UPCA()){
randomlyReverseBeams(event);
}
//
// Print out (here only for the first few events)
//
if (iEvent < 4) event->list();
//
// Fill ROOT tree
//
myRootSartreEvent.iEvent = event->eventNumber;
myRootSartreEvent.t = event->t;
myRootSartreEvent.Q2 = event->Q2;
myRootSartreEvent.x = event->x;
myRootSartreEvent.y = event->y;
myRootSartreEvent.s = event->s;
myRootSartreEvent.W = event->W;
myRootSartreEvent.xpom = event->xpom;
myRootSartreEvent.pol = event->polarization == transverse ? 0 : 1;
myRootSartreEvent.dmode = event->diffractiveMode == coherent ? 0 : 1;
eIn = &event->particles[0].p;
pIn = &event->particles[1].p;
eOut = &event->particles[2].p;
pOut = &event->particles[6].p;
vm = &event->particles[4].p;
gamma = &event->particles[3].p;
+ //If the event is incoherent, and nuclear breakup is enabled, fill the remnants to the tree
+ if(settings->enableNuclearBreakup() and event->diffractiveMode == incoherent){
+ protons.Clear();
+ neutrons.Clear();
+ remnants.Clear();
+ for(unsigned int iParticle=7; iParticle < event->particles.size(); iParticle++){
+ if(event->particles[iParticle].status == 1) { // Final-state particle
+ const Particle& particle = event->particles[iParticle];
+ switch (abs(particle.pdgId)) {
+ case 2212: // (Anti-)proton
+ new(protons[protons.GetEntries()]) TLorentzVector(particle.p);
+ break;
+ case 2112: // (Anti-)neutron
+ new(neutrons[neutrons.GetEntries()]) TLorentzVector(particle.p);
+ break;
+ default: // Any other remnant
+ new(remnants[remnants.GetEntries()]) TLorentzVector(particle.p);
+ break;
+ } // switch
+ } // if
+ } // for
+ } // if
+
//
// Decay the vector meson and fill the decay roducts in the tree:
//
if(doPerformDecay) {
if( decay.SetDecay(*vm, 2, daughterMasses) ){
double weight = decay.Generate(); // weight is always 1 here
if ( (weight-1) > FLT_EPSILON) {
cout << "sartreMain: Warning weight != 1, weight = " << weight << endl;
}
vmDaughter1 = decay.GetDecay(0);
vmDaughter2 = decay.GetDecay(1);
}
else {
cout << "sartreMain: Warning: Kinematics of Vector Meson does not allow decay!" << endl;
}
}
tree.Fill();
}
cout << "All events processed\n" << endl;
//
// That's it, finish up
//
double totalCS=sartre.totalCrossSection();
TH1D* histoForCSandNumberOfEvents = new TH1D("histoForCSandNumberOfEvents", "Cross-section and Number of Events", 2, 0., 1.);
histoForCSandNumberOfEvents->SetBinContent(1, totalCS);
histoForCSandNumberOfEvents->SetBinContent(2, maxEvents);
double runTime = sartre.runTime();
hfile->Write();
cout << rootfile.c_str() << " written." << endl;
cout << "Total cross-section: " << totalCS << " nb" << endl;
sartre.listStatus();
cout << "CPU Time/event: " << 1000*runTime/maxEvents << " msec/evt" << endl;
return 0;
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Sep 30, 5:41 AM (1 h, 9 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6566243
Default Alt Text
(10 KB)
Attached To
Mode
rSARTRESVN sartresvn
Attached
Detach File
Event Timeline
Log In to Comment