147 {
148
149 MsgStream msglog(
msgSvc(), name() );
150 msglog << MSG::INFO << ">>> HistSample from execute" << endmsg;
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167 // (*it)->pGenEvt()->print();
168
169 // fix the STDHEP mess for the Z status
170 int properStatus = 2;
171 // switch ( (*it)->generatorName()[0] ) {
172 // case 'P':
173 // properStatus = 2;
174 // break;
175 // case 'I':
176 // properStatus = 12;
177 // break;
178 // case 'H':
179 // properStatus = 195;
180 // break;
181 // default:
182 // properStatus = 2;
183 // break;
184 // }
185 HepMC::GenEvent* genEvt = (*it);
186 int g_id = genEvt->signal_process_id();
187 switch ( first_generator(g_id) ) {
188 case PYTHIA:
189 properStatus = 2;
190 break;
191 case ISAJET:
192 properStatus = 12;
193 break;
194 case HERWIG:
195 properStatus = 195;
196 break;
197 default:
198 properStatus = 2;
199 break;
200 }
201
202
203 int number_particles = 0;
204 int final_state = 0;
205 int number_charged = 0;
206 // Iterate over MC particles
207 for(HepMC::GenEvent::particle_iterator pitr=genEvt->particles_begin();
208 pitr!=genEvt->particles_end(); ++pitr ){
209 ++number_particles;
210 // cout << "particle " << ((*pitr)->pdg_id()) << " status " <<
211 ((*pitr)->status()) << endl;
212
213 // Z decays
214 if( ((*pitr)->pdg_id()) == 23 && ((*pitr)->status()) == properStatus ){
215 HepMC::GenVertex::particle_iterator firstChild =
216 (*pitr)->end_vertex()->particles_begin(HepMC::children);
217 HepMC::GenVertex::particle_iterator endChild =
218 (*pitr)->end_vertex()->particles_end(HepMC::children);
219 // plot Pt and mass of the Z (generator values)
220 if( ((*firstChild)->pdg_id()) != 23 ){
221 double ZPt = (*pitr)->momentum().perp();
222 m_hZPtall->fill( ZPt, 1.);
223 double Zmass = (*pitr)->momentum().m();
224 m_massZall->fill(Zmass, 1.);
225 }
226 // Z decays to l+l-
227 double sumx = 0.0;
228 double sumy = 0.0;
229 double sumz = 0.0;
230 double sume = 0.0;
231 int nelds = 0;
232 int nmuds = 0;
233 int ntauds = 0;
234 int Zchild = 0;
235 HepMC::GenVertex::particle_iterator thisChild = firstChild;
236 for(; thisChild != endChild++; ++thisChild){
237 if( ((*thisChild)->pdg_id()) != 23 ){
238 // cout << "Zchild id " << (*thisChild)->pdg_id() << endl;
239 ++Zchild;
240 if( abs((*thisChild)->pdg_id()) == 11 || abs((*thisChild)->pdg_id()) ==
241 13 || abs((*thisChild)->pdg_id()) == 15 ){ if( abs((*thisChild)->pdg_id()) == 11 )++nelds;
242 if( abs((*thisChild)->pdg_id()) == 13 )++nmuds;
243 if( abs((*thisChild)->pdg_id()) == 15 )++ntauds;
244 sumx += (*thisChild)->momentum().x();
245 sumy += (*thisChild)->momentum().y();
246 sumz += (*thisChild)->momentum().z();
247 sume += (*thisChild)->momentum().e();
248 }
249 }
250 }
251 // cout << "Zchildren " << Zchild << " nelds " << nelds << " nmuds " << nmuds
252 << " ntauds " << ntauds << endl; if( Zchild != 0 ){ double PtZ2 = sumx*sumx + sumy*sumy;
253 double PtZ = 0.;
254 if(PtZ2 > 0.) PtZ = sqrt(PtZ2);
255 if(PtZ != 0.)m_hZPt->fill( PtZ, 1.);
256 double massZ2 = sume*sume - sumx*sumx - sumy*sumy - sumz*sumz;
257 double massZ = 0.;
258 if(massZ2 > 0.) massZ = sqrt(massZ2);
259 if(massZ != 0.)m_massZ->fill( massZ, 1.);
260 if(nelds == 2){
261 m_hZPte->fill( PtZ, 1.);
262 m_massZe->fill( massZ, 1.);
263 }
264 if(nmuds == 2){
265 m_hZPtm->fill( PtZ, 1.);
266 m_massZm->fill( massZ, 1.);
267 }
268 if(ntauds == 2){
269 m_hZPtt->fill( PtZ, 1.);
270 m_massZt->fill( massZ, 1.);
271 }
272 }
273 }
274 // all decays to l+l- pairs in the event
275 if( (*pitr)->end_vertex() ){
276 HepMC::GenVertex::particle_iterator fstChild =
277 (*pitr)->end_vertex()->particles_begin(HepMC::children);
278 HepMC::GenVertex::particle_iterator lstChild =
279 (*pitr)->end_vertex()->particles_end(HepMC::children);
280 double sumpx = 0.0;
281 double sumpy = 0.0;
282 double sumpz = 0.0;
283 double sumpe = 0.0;
284 int nel = 0;
285 int nmu = 0;
286 int ntau = 0;
287 HepMC::GenVertex::particle_iterator aChild = fstChild;
288 for(; aChild != lstChild++; ++aChild){
289 if( abs((*aChild)->pdg_id()) == 11 || abs((*aChild)->pdg_id()) == 13 ||
290 abs((*aChild)->pdg_id()) == 15 ){
291 if( abs((*aChild)->pdg_id()) == 11 )++nel;
292 if( abs((*aChild)->pdg_id()) == 13 )++nmu;
293 if( abs((*aChild)->pdg_id()) == 15 )++ntau;
294 sumpx += (*aChild)->momentum().x();
295 sumpy += (*aChild)->momentum().y();
296 sumpz += (*aChild)->momentum().z();
297 sumpe += (*aChild)->momentum().e();
298 }
299 }
300 if(nel == 2 || nmu == 2 || ntau == 2 ){
301 double PtPair2 = sumpx*sumpx + sumpy*sumpy;
302 double PtPair = 0.;
303 if(PtPair2 > 0.) PtPair = sqrt(PtPair2);
304 double massPair2 = sumpe*sumpe - sumpx*sumpx - sumpy*sumpy - sumpz*sumpz;
305 double massPair = 0.;
306 if(massPair2 > 0.) massPair = sqrt(massPair2);
307 if(nel == 2){
308 m_hPtPaire->fill( PtPair, 1.);
309 m_massPaire->fill( massPair, 1.);
310 }
311 if(nmu == 2){
312 m_hPtPairm->fill( PtPair, 1.);
313 m_massPairm->fill( massPair, 1.);
314 }
315 if(ntau == 2){
316 m_hPtPairt->fill( PtPair, 1.);
317 m_massPairt->fill( massPair, 1.);
318 }
319 }
320 }
321 // charged tracks
322 double c = 0.;
323 HepPDT::ParticleData* ap = m_particleTable->particle( abs( (*pitr)->pdg_id() )
324 );
325
326 if(!ap){
327 // std::cout << "ChargeService WARNING: abs(id) "
328 // << abs((*pitr)->pdg_id())
329 // << " is not in particle data table" << std::endl;
330 }
331 else
332 {
333 c = ap->charge();
334 }
335
336 if( ((*pitr)->status() == 1) && ( ! (*pitr)->end_vertex()) ) {
337 ++final_state;
338 if( ((*pitr)->pdg_id()) == 11 ){
339 double ePt = (*pitr)->momentum().perp();
340 m_hpte->fill( ePt, 1.);
341 }
342 if(c!=0.){
343 ++number_charged;
344 double chargedPt = (*pitr)->momentum().perp();
345 double chargedEta = (*pitr)->momentum().pseudoRapidity();
346 m_hChargedPt->fill( chargedPt, 1.);
347 m_hChargedEta->fill( chargedEta, 1.);
348
349 double px = (*pitr)->momentum().x();
350 double py = (*pitr)->momentum().y();
351 double pz = (*pitr)->momentum().z();
352 double pe = (*pitr)->momentum().e();
353 double pp2 = px*px + py*py + pz*pz;
354 double pp3 = 0.;
355 if(pp2 > 0.) pp3 = sqrt(pp2);
356 double y = -999.;
357 if( (pe-pz) != 0. && (pe+pz)/(pe-pz) > 0. ) y =
358 (1./2.)*log((pe+pz)/(pe-pz)); double eta = -999.; if( (pp3-pz) != 0. && (pp3+pz)/(pp3-pz) >
359 0. ) eta = (1./2.)*log((pp3+pz)/(pp3-pz)); m_rapidity->fill( y, 1.); m_pseudorapidity->fill(
360 eta, 1.);
361 }
362 }
363 }
364 m_hgenerated->fill( number_particles, 1.);
365 m_hfinal->fill( final_state, 1.);
366 m_ncharged->fill( number_charged, 1.);
367
368 }
369 */
370
371 return StatusCode::SUCCESS;
372}