CGEM BOSS 6.6.5.i
BESIII Offline Software System
Loading...
Searching...
No Matches
ManualGenerator Class Reference

#include <ManualGenerator.h>

+ Inheritance diagram for ManualGenerator:

Public Member Functions

 ManualGenerator (const string &name, ISvcLocator *pSvcLocator)
 
StatusCode initialize ()
 
StatusCode execute ()
 
StatusCode finalize ()
 

Detailed Description

Definition at line 61 of file ManualGenerator.h.

Constructor & Destructor Documentation

◆ ManualGenerator()

ManualGenerator::ManualGenerator ( const string & name,
ISvcLocator * pSvcLocator )

Definition at line 65 of file ManualGenerator.cxx.

65 :Algorithm( name, pSvcLocator ){
66
67
68 // get the name of the input file from the job options file
69
70 declareProperty("InputFile", m_inputFileName = "");
71
72}

Member Function Documentation

◆ execute()

StatusCode ManualGenerator::execute ( )

Definition at line 116 of file ManualGenerator.cxx.

116 {
117
118
119 // read an event from the input file
120
121 int nParticles;
122 int idParticles[100];
123 double pxParticle;
124 double pyParticle;
125 double pzParticle;
126 double eParticle;
127 CLHEP::HepLorentzVector pParticles[100];
128
129 if (m_inputFile >> nParticles){
130 for (int i = 0; i < nParticles; i++){
131 m_inputFile >> idParticles[i];
132 m_inputFile >> pxParticle; pParticles[i].setPx(pxParticle);
133 m_inputFile >> pyParticle; pParticles[i].setPy(pyParticle);
134 m_inputFile >> pzParticle; pParticles[i].setPz(pzParticle);
135 m_inputFile >> eParticle; pParticles[i].setE(eParticle);
136 }
137 }
138
139 else{
140 cout << "ManualGenerator: RAN OUT OF INPUT EVENTS FROM FILE "
141 << m_inputFileName << endl;
142 return StatusCode::SUCCESS;
143 }
144
145
146
147 // print out a message for this event to make sure all is well
148
149 cout << "ManualGenerator: PROCESSING EVENT " << ++m_eventCounter << endl;
150 cout << nParticles << endl;
151 for (int i = 0; i < nParticles; i++){
152 cout << idParticles[i] << "\t";
153 cout << pParticles[i].px() << "\t";
154 cout << pParticles[i].py() << "\t";
155 cout << pParticles[i].pz() << "\t";
156 cout << pParticles[i].e() << endl;
157 }
158
159
160 // retrieve the original MC event (HepMC::GenEvent) from the framework
161
162 HepMC::GenEvent* genEvent = 0;
163 SmartDataPtr<McGenEventCol> initialMcCol(eventSvc(), "/Event/Gen");
164 if (initialMcCol == 0){
165// HepMC::GenEvent* genEvent = new GenEvent();
166// genEvent->set_event_number(0);
167
168 //create a Transient store
169// McGenEventCol *mcColl = new McGenEventCol;
170// McGenEvent* mcEvent = new McGenEvent(genEvent);
171// mcColl->push_back(mcEvent);
172// StatusCode sc = eventSvc()->registerObject("/Event/Gen", mcColl);
173// if (sc != StatusCode::SUCCESS) return StatusCode::FAILURE;
174
175 cout << "ManualGenerator: COULD NOT FIND THE ORIGINAL MC EVENT COLLECTION" << endl;
176 exit(0);
177 }
178// else
179// {
180 genEvent = (*(initialMcCol->begin()))->getGenEvt();
181// }
182 //genEvent->print();
183
184
185
186 // loop over MC particles and look for the particle we want to decay
187
188 HepMC::GenParticle* decayParticle = NULL;
189 for(HepMC::GenEvent::particle_const_iterator igenParticle = genEvent->particles_begin();
190 igenParticle != genEvent->particles_end(); ++igenParticle ){
191 decayParticle = *igenParticle;
192 if (decayParticle->status() == 1 && abs(decayParticle->pdg_id()) != 22) break;
193 }
194 if (!decayParticle){
195 cout << "ManualGenerator: COULD NOT FIND A PARTICLE TO DECAY" << endl;
196 exit(0);
197 }
198
199
200 // create a new vertex from the decaying particle's production vertex
201 // and add it to the event
202
203 HepMC::GenVertex* initialVertex = decayParticle->production_vertex();
204 HepMC::GenVertex* newVertex = new HepMC::GenVertex(initialVertex->position());
205 genEvent->add_vertex(newVertex);
206 newVertex->add_particle_in(decayParticle);
207
208
209
210 // boost the input four-vectors into the decaying particle's rest frame
211
212 CLHEP::HepLorentzVector initialFourMomentum(decayParticle->momentum().px(),
213 decayParticle->momentum().py(),
214 decayParticle->momentum().pz(),
215 decayParticle->momentum().e());
216 CLHEP::HepLorentzVector finalFourMomentum(0,0,0,0);
217 for (int i = 0; i < nParticles; i++){
218 // pParticles[i].boost(initialFourMomentum.boostVector());
219 finalFourMomentum += pParticles[i];
220 }
221 if ((fabs(initialFourMomentum.px() - finalFourMomentum.px()) > 0.0001) ||
222 (fabs(initialFourMomentum.py() - finalFourMomentum.py()) > 0.0001) ||
223 (fabs(initialFourMomentum.pz() - finalFourMomentum.pz()) > 0.0001) ||
224 (fabs(initialFourMomentum.e() - finalFourMomentum.e()) > 0.01)){
225 cout << "ManualGenerator: INITIAL AND FINAL STATES HAVE INCONSISTENT 4-MOMENTA" << endl;
226 cout << "delta px = " << initialFourMomentum.px() - finalFourMomentum.px() << endl;
227 cout << "delta py = " << initialFourMomentum.py() - finalFourMomentum.py() << endl;
228 cout << "delta pz = " << initialFourMomentum.pz() - finalFourMomentum.pz() << endl;
229 cout << "delta e = " << initialFourMomentum.e() - finalFourMomentum.e() << endl;
230 // exit(0);
231 }
232
233
234 // add the input four-vectors to the new vertex
235
236 for (int i = 0; i < nParticles; i++){
237 newVertex->add_particle_out(new GenParticle(pParticles[i], idParticles[i], 1));
238 }
239 //genEvent->print();
240
241
242
243 return StatusCode::SUCCESS;
244}

◆ finalize()

StatusCode ManualGenerator::finalize ( )

Definition at line 256 of file ManualGenerator.cxx.

257{
258 m_inputFile.close();
259 return StatusCode::SUCCESS;
260}

◆ initialize()

StatusCode ManualGenerator::initialize ( )

Definition at line 83 of file ManualGenerator.cxx.

83 {
84 //MsgStream log(messageService(), name());
85 //log << MSG::INFO << "ManualGenerator initialize" << endreq;
86
87
88 // open the input file
89
90 m_inputFile.open(m_inputFileName.c_str());
91 if (!m_inputFile){
92 cout << "ManualGenerator: PROBLEMS OPENING FILE "
93 << m_inputFileName << endl;
94 exit(0);
95 }
96
97
98 // zero the event counter
99
100 m_eventCounter = 0;
101
102
103 return StatusCode::SUCCESS;
104
105}

The documentation for this class was generated from the following files: