]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STARLIGHT/starlight/src/.svn/text-base/starlightStandalone.cpp.svn-base
STARLIGHT code and interface
[u/mrichter/AliRoot.git] / STARLIGHT / starlight / src / .svn / text-base / starlightStandalone.cpp.svn-base
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 //    Copyright 2010
4 //
5 //    This file is part of starlight.
6 //
7 //    starlight is free software: you can redistribute it and/or modify
8 //    it under the terms of the GNU General Public License as published by
9 //    the Free Software Foundation, either version 3 of the License, or
10 //    (at your option) any later version.
11 //
12 //    starlight is distributed in the hope that it will be useful,
13 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //    GNU General Public License for more details.
16 //
17 //    You should have received a copy of the GNU General Public License
18 //    along with starlight. If not, see <http://www.gnu.org/licenses/>.
19 //
20 ///////////////////////////////////////////////////////////////////////////
21 //
22 // File and Version Information:
23 // $Rev:: 102                         $: revision of last commit
24 // $Author:: odjuvsla                 $: author of last commit
25 // $Date:: 2012-10-22 16:25:54 -0500 #$: date of last commit
26 //
27 // Description:
28 //
29 //
30 //
31 ///////////////////////////////////////////////////////////////////////////
32
33
34 #include <iostream>
35
36 #include "reportingUtils.h"
37 #include "starlight.h"
38 #include "inputParameters.h"
39 #include "eventfilewriter.h"
40 #include "starlightStandalone.h"
41
42
43 using namespace std;
44
45
46 starlightStandalone::starlightStandalone()
47         :       _configFileName   ("slight.in"),
48                 _eventDataFileName("slight.out"),
49                 _starlight        (0),
50                 _inputParameters  (0),
51                 _nmbEventsTot     (1),
52                 _nmbEventsPerFile (_nmbEventsTot)
53 { }
54
55
56 starlightStandalone::~starlightStandalone()
57 { }
58
59
60 bool
61 starlightStandalone::init()
62 {
63         // read input parameters from config file
64         inputParametersInstance.configureFromFile(_configFileName);
65         if (!inputParametersInstance.init()) {
66                 printWarn << "problems initializing input parameters. cannot initialize starlight." << endl;
67                 return false;
68         }
69
70         // get the number of events
71         // for now we write everything to one file
72         _nmbEventsTot     = inputParametersInstance.nmbEvents();
73         _nmbEventsPerFile = _nmbEventsTot;
74
75         // create the starlight object
76         _starlight = new starlight();
77         
78         // initialize starlight
79         return _starlight->init();
80 }
81
82
83 bool
84 starlightStandalone::run()
85 {
86         if (!_starlight) {
87                 printWarn << "null pointer to starlight object. make sure that init() was called. "
88                           << "cannot generate events." << endl;
89                 return false;
90         }
91
92         // open output file
93         eventFileWriter fileWriter;
94         fileWriter.writeFullPythiaInfo(inputParametersInstance.pythiaFullEventRecord());
95         fileWriter.open(_eventDataFileName);
96
97         printInfo << "generating events:" << endl;
98         unsigned int nmbEvents = 0;
99         while (nmbEvents < _nmbEventsTot) {
100                 for (unsigned int iEvent = 0; (iEvent < _nmbEventsPerFile) && (nmbEvents < _nmbEventsTot);
101                      ++iEvent, ++nmbEvents) {
102                         progressIndicator(iEvent, _nmbEventsTot, true, 4);
103                         upcEvent event = _starlight->produceEvent();
104                         // Boost event from CMS system to lab system
105                         boostEvent(event);
106                         fileWriter.writeEvent(event, iEvent);
107                 }
108         }
109         printInfo << "number of attempts = " << _starlight->nmbAttempts() << ", "
110                   << "number of accepted events = " << _starlight->nmbAccepted() << endl;
111         fileWriter.close();
112
113         return true;
114 }
115 void starlightStandalone::boostEvent(upcEvent &event)
116 {
117   
118   // Should probably move this calculation to inputParameters (and remove from bbs)
119    // Calculate CMS boost 
120    double rap1 = acosh(inputParametersInstance.beam1LorentzGamma());
121    double rap2 = -acosh(inputParametersInstance.beam2LorentzGamma());
122    double boost = (rap1+rap2)/2.;
123
124    event.boost(boost);
125 }
126