116 {
117
118
119
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
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
161
162 HepMC::GenEvent* genEvent = 0;
163 SmartDataPtr<McGenEventCol> initialMcCol(eventSvc(), "/Event/Gen");
164 if (initialMcCol == 0){
165
166
167
168
169
170
171
172
173
174
175 cout << "ManualGenerator: COULD NOT FIND THE ORIGINAL MC EVENT COLLECTION" << endl;
176 exit(0);
177 }
178
179
180 genEvent = (*(initialMcCol->begin()))->getGenEvt();
181
182
183
184
185
186
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
201
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
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
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
231 }
232
233
234
235
236 for (int i = 0; i < nParticles; i++){
237 newVertex->add_particle_out(new GenParticle(pParticles[i], idParticles[i], 1));
238 }
239
240
241
242
243 return StatusCode::SUCCESS;
244}