BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
PipiJpsi.cxx
Go to the documentation of this file.
1// psi'--> J/psi pion pion, J/psi --> di-leptons
2// Kai Zhu (zhuk@ihep.ac.cn)
3#include "GaudiKernel/IDataProviderSvc.h"
4#include "GaudiKernel/ISvcLocator.h"
5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/PropertyMgr.h"
7#include "GaudiKernel/SmartDataPtr.h"
8
9#include "EventModel/Event.h"
10#include "EventModel/EventHeader.h"
11#include "EventModel/EventModel.h"
12#include "McTruth/McParticle.h"
13#include "TrigEvent/TrigData.h"
14#include "TrigEvent/TrigEvent.h"
15
16#include "DstEvent/TofHitStatus.h"
17#include "EvtRecEvent/EvtRecEvent.h"
18#include "EvtRecEvent/EvtRecTrack.h"
19
20#include "CLHEP/Vector/LorentzVector.h"
21#include "CLHEP/Vector/ThreeVector.h"
22#include "CLHEP/Vector/TwoVector.h"
23#include "GaudiKernel/Bootstrap.h"
24#include "GaudiKernel/IHistogramSvc.h"
25#include "GaudiKernel/INTupleSvc.h"
26#include "GaudiKernel/NTuple.h"
27#include "TMath.h"
28using CLHEP::Hep2Vector;
29using CLHEP::Hep3Vector;
30using CLHEP::HepLorentzVector;
31#include "CLHEP/Geometry/Point3D.h"
32#ifndef ENABLE_BACKWARDS_COMPATIBILITY
33typedef HepGeom::Point3D<double> HepPoint3D;
34#endif
35#include "MdcRecEvent/RecMdcKalTrack.h"
36#include "ParticleID/ParticleID.h"
37#include "VertexFit/KinematicFit.h"
38#include "VertexFit/SecondVertexFit.h"
39#include "VertexFit/VertexFit.h"
40#include "VertexFit/WTrackParameter.h"
41
42#include "PipiJpsi.h"
43
44#include <vector>
45// const double twopi = 6.2831853;
46
47const double me = 0.000511;
48const double mpi = 0.13957;
49const double mproton = 0.938272;
50const double mmu = 0.105658;
51const double mpsip = 3.686;
52const double xmass[5] = { 0.000511, 0.105658, 0.139570, 0.493677, 0.938272 };
53const double velc = 29.9792458; // tof_path unit in cm.
54const double PI = 3.1415926;
55// const double velc = 299.792458; // tof path unit in mm
56typedef std::vector<int> Vint;
57typedef std::vector<HepLorentzVector> Vp4;
58
59// counter for efficiency
60static long m_cout_all( 0 ), m_cout_col( 0 ), m_cout_charge( 0 ), m_cout_nGood( 0 ),
62/////////////////////////////////////////////////////////////////////////////
64PipiJpsi::PipiJpsi( const std::string& name, ISvcLocator* pSvcLocator )
65 : Algorithm( name, pSvcLocator ) {
66 // Declare the properties
67 declareProperty( "Vr0cut", m_vr0cut = 1.0 );
68 declareProperty( "Vz0cut", m_vz0cut = 5.0 );
69 declareProperty( "TrackCosThetaCut", m_cosThetaCut = 0.93 );
70 declareProperty( "PipiDangCut", m_pipi_dang_cut = 0.98 );
71
72 declareProperty( "CheckDedx", m_checkDedx = true );
73 declareProperty( "CheckTof", m_checkTof = true );
74
75 declareProperty( "Subsample", m_subsample_flag = false );
76 declareProperty( "Trigger", m_trigger_flag = false );
77 declareProperty( "DistinEMuon", m_distin_emuon = 2.0 );
78
79 declareProperty( "EventRate", m_eventrate = false );
80 declareProperty( "ChanDet", m_chan_det = 1 );
81}
82
83// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
85 MsgStream log( msgSvc(), name() );
86
87 log << MSG::INFO << "in initialize()" << endmsg;
88
89 StatusCode status;
90
91 NTuplePtr nt1( ntupleSvc(), "FILE1/vxyz" );
92 if ( nt1 ) m_tuple1 = nt1;
93 else
94 {
95 m_tuple1 = ntupleSvc()->book( "FILE1/vxyz", CLID_ColumnWiseTuple, "ks N-Tuple example" );
96 if ( m_tuple1 )
97 {
98 status = m_tuple1->addItem( "vx0", m_vx0 );
99 status = m_tuple1->addItem( "vy0", m_vy0 );
100 status = m_tuple1->addItem( "vz0", m_vz0 );
101 status = m_tuple1->addItem( "vr0", m_vr0 );
102 }
103 else
104 {
105 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple1 ) << endmsg;
106 return StatusCode::FAILURE;
107 }
108 }
109
110 NTuplePtr nt2( ntupleSvc(), "FILE1/photon" );
111 if ( nt2 ) m_tuple2 = nt2;
112 else
113 {
114 m_tuple2 = ntupleSvc()->book( "FILE1/photon", CLID_ColumnWiseTuple, "ks N-Tuple example" );
115 if ( m_tuple2 )
116 {
117 status = m_tuple2->addItem( "dthe", m_dthe );
118 status = m_tuple2->addItem( "dphi", m_dphi );
119 status = m_tuple2->addItem( "dang", m_dang );
120 status = m_tuple2->addItem( "eraw", m_eraw );
121 status = m_tuple2->addItem( "nGam", m_nGam );
122 }
123 else
124 {
125 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple2 ) << endmsg;
126 return StatusCode::FAILURE;
127 }
128 }
129
130 if ( m_checkDedx )
131 {
132 NTuplePtr nt3( ntupleSvc(), "FILE1/dedx" );
133 if ( nt3 ) m_tuple3 = nt3;
134 else
135 {
136 m_tuple3 = ntupleSvc()->book( "FILE1/dedx", CLID_ColumnWiseTuple, "ks N-Tuple example" );
137 if ( m_tuple3 )
138 {
139 status = m_tuple3->addItem( "ptrk", m_ptrk );
140 status = m_tuple3->addItem( "chie", m_chie );
141 status = m_tuple3->addItem( "chimu", m_chimu );
142 status = m_tuple3->addItem( "chipi", m_chipi );
143 status = m_tuple3->addItem( "chik", m_chik );
144 status = m_tuple3->addItem( "chip", m_chip );
145 status = m_tuple3->addItem( "probPH", m_probPH );
146 status = m_tuple3->addItem( "normPH", m_normPH );
147 status = m_tuple3->addItem( "ghit", m_ghit );
148 status = m_tuple3->addItem( "thit", m_thit );
149 }
150 else
151 {
152 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple3 ) << endmsg;
153 return StatusCode::FAILURE;
154 }
155 }
156 } // check dE/dx
157
158 if ( m_checkTof )
159 {
160 NTuplePtr nt4( ntupleSvc(), "FILE1/tofe" );
161 if ( nt4 ) m_tuple4 = nt4;
162 else
163 {
164 m_tuple4 = ntupleSvc()->book( "FILE1/tofe", CLID_ColumnWiseTuple, "ks N-Tuple example" );
165 if ( m_tuple4 )
166 {
167 status = m_tuple4->addItem( "ptrk", m_ptot_etof );
168 status = m_tuple4->addItem( "cntr", m_cntr_etof );
169 status = m_tuple4->addItem( "path", m_path_etof );
170 status = m_tuple4->addItem( "ph", m_ph_etof );
171 status = m_tuple4->addItem( "rhit", m_rhit_etof );
172 status = m_tuple4->addItem( "qual", m_qual_etof );
173 status = m_tuple4->addItem( "tof", m_tof_etof );
174 status = m_tuple4->addItem( "te", m_te_etof );
175 status = m_tuple4->addItem( "tmu", m_tmu_etof );
176 status = m_tuple4->addItem( "tpi", m_tpi_etof );
177 status = m_tuple4->addItem( "tk", m_tk_etof );
178 status = m_tuple4->addItem( "tp", m_tp_etof );
179 }
180 else
181 {
182 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple4 ) << endmsg;
183 return StatusCode::FAILURE;
184 }
185 }
186 } // check Tof:endcap
187
188 if ( m_checkTof )
189 {
190 NTuplePtr nt5( ntupleSvc(), "FILE1/tof1" );
191 if ( nt5 ) m_tuple5 = nt5;
192 else
193 {
194 m_tuple5 = ntupleSvc()->book( "FILE1/tof1", CLID_ColumnWiseTuple, "ks N-Tuple example" );
195 if ( m_tuple5 )
196 {
197 status = m_tuple5->addItem( "ptrk", m_ptot_btof1 );
198 status = m_tuple5->addItem( "cntr", m_cntr_btof1 );
199 status = m_tuple5->addItem( "path", m_path_btof1 );
200 status = m_tuple5->addItem( "ph", m_ph_btof1 );
201 status = m_tuple5->addItem( "zhit", m_zhit_btof1 );
202 status = m_tuple5->addItem( "qual", m_qual_btof1 );
203 status = m_tuple5->addItem( "tof", m_tof_btof1 );
204 status = m_tuple5->addItem( "te", m_te_btof1 );
205 status = m_tuple5->addItem( "tmu", m_tmu_btof1 );
206 status = m_tuple5->addItem( "tpi", m_tpi_btof1 );
207 status = m_tuple5->addItem( "tk", m_tk_btof1 );
208 status = m_tuple5->addItem( "tp", m_tp_btof1 );
209 }
210 else
211 {
212 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple5 ) << endmsg;
213 return StatusCode::FAILURE;
214 }
215 }
216 } // check Tof:barrel inner Tof
217
218 if ( m_checkTof )
219 {
220 NTuplePtr nt6( ntupleSvc(), "FILE1/tof2" );
221 if ( nt6 ) m_tuple6 = nt6;
222 else
223 {
224 m_tuple6 = ntupleSvc()->book( "FILE1/tof2", CLID_ColumnWiseTuple, "ks N-Tuple example" );
225 if ( m_tuple6 )
226 {
227 status = m_tuple6->addItem( "ptrk", m_ptot_btof2 );
228 status = m_tuple6->addItem( "cntr", m_cntr_btof2 );
229 status = m_tuple6->addItem( "path", m_path_btof2 );
230 status = m_tuple6->addItem( "ph", m_ph_btof2 );
231 status = m_tuple6->addItem( "zhit", m_zhit_btof2 );
232 status = m_tuple6->addItem( "qual", m_qual_btof2 );
233 status = m_tuple6->addItem( "tof", m_tof_btof2 );
234 status = m_tuple6->addItem( "te", m_te_btof2 );
235 status = m_tuple6->addItem( "tmu", m_tmu_btof2 );
236 status = m_tuple6->addItem( "tpi", m_tpi_btof2 );
237 status = m_tuple6->addItem( "tk", m_tk_btof2 );
238 status = m_tuple6->addItem( "tp", m_tp_btof2 );
239 }
240 else
241 {
242 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple6 ) << endmsg;
243 return StatusCode::FAILURE;
244 }
245 }
246 } // check Tof:barrel outter Tof
247
248 NTuplePtr nt8( ntupleSvc(), "FILE1/infmom" );
249 if ( nt8 ) m_tuple8 = nt8;
250 else
251 {
252 m_tuple8 = ntupleSvc()->book( "FILE1/infmom", CLID_ColumnWiseTuple,
253 "information with momentum method" );
254 if ( m_tuple8 )
255 {
256 status = m_tuple8->addItem( "momlepp", m_mom_lepp );
257 status = m_tuple8->addItem( "momlepmm", m_mom_lepm );
258 status = m_tuple8->addItem( "mompionm", m_mom_pionm );
259 status = m_tuple8->addItem( "mompionp", m_mom_pionp );
260 status = m_tuple8->addItem( "pipidang", m_pipi_dang );
261 status = m_tuple8->addItem( "cmslepp", m_cms_lepp );
262 status = m_tuple8->addItem( "cmslepm", m_cms_lepm );
263 status = m_tuple8->addItem( "invtwopi", m_mass_twopi );
264 status = m_tuple8->addItem( "invjpsi", m_mass_jpsi );
265 status = m_tuple8->addItem( "recoil", m_mass_recoil );
266 status = m_tuple8->addItem( "invmass", m_inv_mass );
267 status = m_tuple8->addItem( "totene", m_tot_e );
268 status = m_tuple8->addItem( "totpx", m_tot_px );
269 status = m_tuple8->addItem( "totpy", m_tot_py );
270 status = m_tuple8->addItem( "totpz", m_tot_pz );
271 status = m_tuple8->addItem( "epratio", m_ep_ratio );
272 status = m_tuple8->addItem( "eveflag", m_event_flag );
273 status = m_tuple8->addItem( "tplepratiom", m_trans_ratio_lepm );
274 status = m_tuple8->addItem( "tplepratiop", m_trans_ratio_lepp );
275 status = m_tuple8->addItem( "tppionratiom", m_trans_ratio_pionm );
276 status = m_tuple8->addItem( "tppionratiop", m_trans_ratio_pionp );
277 status = m_tuple8->addItem( "run", m_run );
278 status = m_tuple8->addItem( "event", m_event );
279 status = m_tuple8->addItem( "ntrack", m_index, 0, 4 );
280 status = m_tuple8->addIndexedItem( "costhe", m_index, m_cos_theta );
281 status = m_tuple8->addIndexedItem( "phi", m_index, m_phi );
282 status = m_tuple8->addIndexedItem( "fourmom", m_index, 4, m_four_mom );
283 status = m_tuple8->addItem( "pionmat", m_pion_matched );
284 status = m_tuple8->addItem( "lepmat", m_lep_matched );
285 // MCtruth
286 status = m_tuple8->addItem( "indexmc", m_idxmc, 0, 100 );
287 status = m_tuple8->addIndexedItem( "pdgid", m_idxmc, m_pdgid );
288 status = m_tuple8->addIndexedItem( "motheridx", m_idxmc, m_motheridx );
289 status = m_tuple8->addItem( "truepp", m_true_pionp );
290 status = m_tuple8->addItem( "truepm", m_true_pionm );
291 }
292 else
293 {
294 log << MSG::ERROR << " Cannot book N-tuple:" << long( m_tuple8 ) << endmsg;
295 return StatusCode::FAILURE;
296 }
297 }
298
299 //
300 //--------end of book--------
301 //
302
303 log << MSG::INFO << "successfully return from initialize()" << endmsg;
304 return StatusCode::SUCCESS;
305}
306
307// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
308StatusCode PipiJpsi::execute() {
309
310 // std::cout << "execute()" << std::endl;
311
312 MsgStream log( msgSvc(), name() );
313 log << MSG::INFO << "in execute()" << endmsg;
314 m_cout_all++;
315 StatusCode sc = StatusCode::SUCCESS;
316 // save the events passed selection to a new file
317 setFilterPassed( false );
318
319 SmartDataPtr<Event::EventHeader> eventHeader( eventSvc(), "/Event/EventHeader" );
320 if ( !eventHeader )
321 {
322 log << MSG::ERROR << "EventHeader not found" << endmsg;
323 return StatusCode::SUCCESS;
324 }
325 int run( eventHeader->runNumber() );
326 int event( eventHeader->eventNumber() );
327 if ( event % 1000 == 0 ) cout << "run: " << run << " event: " << event << endl;
328
329 SmartDataPtr<EvtRecEvent> evtRecEvent( eventSvc(), "/Event/EvtRec/EvtRecEvent" );
330 if ( !evtRecEvent )
331 {
332 log << MSG::ERROR << "EvtRecEvent not found" << endmsg;
333 return StatusCode::SUCCESS;
334 }
335 log << MSG::DEBUG << "ncharg, nneu, tottks = " << evtRecEvent->totalCharged() << " , "
336 << evtRecEvent->totalNeutral() << " , " << evtRecEvent->totalTracks() << endmsg;
337
338 SmartDataPtr<EvtRecTrackCol> evtRecTrkCol( eventSvc(), "/Event/EvtRec/EvtRecTrackCol" );
339 if ( !evtRecTrkCol )
340 {
341 log << MSG::ERROR << "EvtRecTrackCol" << endmsg;
342 return StatusCode::SUCCESS;
343 }
344
345 if ( m_trigger_flag )
346 {
347 SmartDataPtr<TrigData> trigData( eventSvc(), EventModel::Trig::TrigData );
348 if ( !trigData )
349 {
350 log << MSG::FATAL << "Could not find Trigger Data for physics analysis" << endmsg;
351 return StatusCode::FAILURE;
352 }
353 /// Print trigger information once:
354 log << MSG::DEBUG << "Trigger conditions: " << endmsg;
355 for ( int i = 0; i < 48; i++ )
356 {
357 log << MSG::DEBUG << "i:" << i << " name:" << trigData->getTrigCondName( i )
358 << " cond:" << trigData->getTrigCondition( i ) << endmsg;
359 }
360 // test event rate
361 int m_trig_tot( 0 ), m_trig_which( -1 );
362 if ( m_eventrate )
363 {
364 for ( int j = 0; j < 16; j++ )
365 {
366 if ( trigData->getTrigChannel( j ) )
367 {
368 m_trig_tot++;
369 m_trig_which = j + 1;
370 }
371 }
372 if ( m_trig_tot == 1 && m_trig_which == m_chan_det ) m_cout_everat++;
373 return sc;
374 }
375 }
376
377 m_cout_col++;
378 if ( evtRecEvent->totalCharged() < 3 || evtRecTrkCol->size() < 3 ||
379 evtRecEvent->totalTracks() > 99 || evtRecTrkCol->size() > 99 )
380 return StatusCode::SUCCESS;
382
383 // Asign four-momentum with KalmanTrack
384 Vint iGood;
385 iGood.clear();
386 int m_num[4] = { 0, 0, 0, 0 }; // number of different particles: pi+, pi-, l+, l-
387 int nCharge = 0;
388 m_pion_matched = 0;
389 m_lep_matched = 0;
390 HepLorentzVector m_lv_pionp, m_lv_pionm, m_lv_lepp, m_lv_lepm, m_lv_ele, m_lv_pos, m_lv_mum,
391 m_lv_mup;
392
393 for ( int i = 0; i < evtRecEvent->totalCharged(); i++ )
394 {
395 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + i;
396 if ( !( *itTrk )->isMdcKalTrackValid() ) continue;
397 RecMdcKalTrack* mdcTrk = ( *itTrk )->mdcKalTrack();
398
399 m_vx0 = mdcTrk->x();
400 m_vy0 = mdcTrk->y();
401 m_vz0 = mdcTrk->z();
402 m_vr0 = mdcTrk->r();
403 if ( fabs( m_vz0 ) >= m_vz0cut ) continue;
404 if ( m_vr0 >= m_vr0cut ) continue;
405 iGood.push_back( i );
406 nCharge += mdcTrk->charge();
407 if ( mdcTrk->p() < 1.0 )
408 {
409 if ( ( *itTrk )->isEmcShowerValid() ) m_pion_matched++;
410 }
411 else
412 {
413 if ( ( *itTrk )->isEmcShowerValid() ) m_lep_matched++;
414 }
415
416 if ( mdcTrk->charge() > 0 )
417 {
418 if ( mdcTrk->p() < 1.0 )
419 {
421 // Warning: for ones who do not modify the DstMdcKalTrack package, the following p4()
422 // function cannot be used, you should get momentum from MdcKalTrack, then calculate
423 // the energy by yourself
424 m_lv_pionp = mdcTrk->p4( xmass[2] );
425 m_num[0]++;
426 }
427 else
428 {
430 m_lv_pos = mdcTrk->p4( xmass[0] );
432 m_lv_mup = mdcTrk->p4( xmass[1] );
433 m_num[2]++;
434 }
435 }
436 else
437 {
438 if ( mdcTrk->p() < 1.0 )
439 {
441 m_lv_pionm = mdcTrk->p4( xmass[2] );
442 m_num[1]++;
443 }
444 else
445 {
447 m_lv_ele = mdcTrk->p4( xmass[0] );
449 m_lv_mum = mdcTrk->p4( xmass[1] );
450 m_num[3]++;
451 }
452 }
453 }
454
455 int nGood = iGood.size();
456 log << MSG::DEBUG << "With KalmanTrack, ngood, totcharge = " << nGood << " , " << nCharge
457 << endmsg;
458 if ( nGood < 3 || nGood > 4 ) return sc;
459 m_cout_nGood++;
460
461 m_ep_ratio = 0;
462 for ( int i = 0; i < evtRecEvent->totalTracks(); i++ )
463 {
464 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + i;
465 if ( !( *itTrk )->isEmcShowerValid() ) continue;
466 RecEmcShower* emcTrk = ( *itTrk )->emcShower();
467 m_ep_ratio += emcTrk->energy();
468 }
469
470 if ( m_ep_ratio > m_distin_emuon )
471 {
472 m_lv_lepp = m_lv_pos;
473 m_lv_lepm = m_lv_ele;
474 }
475 else
476 {
477 m_lv_lepp = m_lv_mup;
478 m_lv_lepm = m_lv_mum;
479 }
480
481 HepLorentzVector m_lv_lab( 0.04, 0, 0, 3.686 );
482 if ( nGood == 4 )
483 {
484 if ( nCharge ) return sc;
485 m_event_flag = 4;
486 }
487 else
488 {
489 if ( m_num[0] > 1 || m_num[1] > 1 || m_num[2] > 1 || m_num[3] > 1 ) return sc;
490 if ( m_num[0] == 0 )
491 {
492 if ( nCharge != -1 ) return StatusCode::SUCCESS;
493 m_lv_pionp = m_lv_lab - m_lv_pionm - m_lv_lepp - m_lv_lepm;
494 if ( m_lv_pionp.vect().cosTheta() > m_cosThetaCut ) return StatusCode::SUCCESS;
495 m_event_flag = 0;
496 }
497 if ( m_num[1] == 0 )
498 {
499 if ( nCharge != 1 ) return StatusCode::SUCCESS;
500 m_lv_pionm = m_lv_lab - m_lv_pionp - m_lv_lepp - m_lv_lepm;
501 if ( m_lv_pionm.vect().cosTheta() > m_cosThetaCut ) return StatusCode::SUCCESS;
502 m_event_flag = 1;
503 }
504 if ( m_num[2] == 0 )
505 {
506 if ( nCharge != -1 ) return StatusCode::SUCCESS;
507 m_lv_lepp = m_lv_lab - m_lv_pionp - m_lv_pionm - m_lv_lepm;
508 if ( m_lv_lepp.vect().cosTheta() > m_cosThetaCut ) return StatusCode::SUCCESS;
509 m_event_flag = 2;
510 }
511 if ( m_num[3] == 0 )
512 {
513 if ( nCharge != 1 ) return StatusCode::SUCCESS;
514 m_lv_lepm = m_lv_lab - m_lv_pionp - m_lv_pionm - m_lv_lepp;
515 if ( m_lv_lepm.vect().cosTheta() > m_cosThetaCut ) return StatusCode::SUCCESS;
516 m_event_flag = 3;
517 }
518 }
519 m_cout_mom++;
520
521 // With momentum method calculate the invariant mass of Jpsi
522 // actually we use the recoil mass
523 HepLorentzVector m_lv_recoil, m_lv_jpsi;
524 m_lv_recoil = m_lv_lab - m_lv_pionp - m_lv_pionm;
525 m_lv_jpsi = m_lv_lepp + m_lv_lepm;
526
527 m_mass_twopi = ( m_lv_pionp + m_lv_pionm ).m();
528 m_mass_recoil = m_lv_recoil.m();
529 m_mass_jpsi = m_lv_jpsi.m();
530
531 // Jpsi mass cut
532 if ( m_mass_recoil < 3.05 || m_mass_recoil > 3.15 ) return sc;
533 if ( m_mass_jpsi < 3.0 || m_mass_jpsi > 3.2 ) return sc;
535
536 HepLorentzVector m_ttm( m_lv_jpsi + m_lv_pionp + m_lv_pionm );
537 if ( m_ttm.m() > 4 || m_ttm.m() < 3 ) return sc;
538
539 // dangle between pions, suppress gamma convertion
540 m_pipi_dang = m_lv_pionp.vect().cosTheta( m_lv_pionm.vect() );
541
542 m_mom_pionp = m_lv_pionp.vect().mag();
543 m_mom_pionm = m_lv_pionm.vect().mag();
544 m_mom_lepp = m_lv_lepp.vect().mag();
545 m_mom_lepm = m_lv_lepm.vect().mag();
546 m_trans_ratio_lepp = m_lv_lepp.vect().perp() / m_lv_lepp.vect().mag();
547 m_trans_ratio_lepm = m_lv_lepm.vect().perp() / m_lv_lepm.vect().mag();
548 m_trans_ratio_pionp = m_lv_pionp.vect().perp() / m_lv_pionp.vect().mag();
549 m_trans_ratio_pionm = m_lv_pionm.vect().perp() / m_lv_pionm.vect().mag();
550
551 Hep3Vector m_boost_jpsi( m_lv_recoil.boostVector() );
552 HepLorentzVector m_lv_cms_lepp( boostOf( m_lv_lepp, -m_boost_jpsi ) );
553 HepLorentzVector m_lv_cms_lepm( boostOf( m_lv_lepm, -m_boost_jpsi ) );
554 m_cms_lepm = m_lv_cms_lepm.vect().mag();
555 m_cms_lepp = m_lv_cms_lepp.vect().mag();
556 log << MSG::DEBUG << "jpsi four momentum in cms " << m_lv_cms_lepp + m_lv_cms_lepm << endmsg;
557
558 m_inv_mass = m_ttm.m();
559 m_tot_e = m_ttm.e();
560 m_tot_px = m_ttm.px();
561 m_tot_py = m_ttm.py();
562 m_tot_pz = m_ttm.pz();
563 m_run = run;
564 m_event = event;
565 HepLorentzVector m_lv_book( 0, 0, 0, 0 ); // assume one track is missing
566 for ( m_index = 0; m_index < 4; m_index++ )
567 {
568 switch ( m_index )
569 {
570 case 0: m_lv_book = m_lv_pionp; break;
571 case 1: m_lv_book = m_lv_pionm; break;
572 case 2: m_lv_book = m_lv_lepp; break;
573 case 3: m_lv_book = m_lv_lepm; break;
574 default: m_lv_book.setE( 2008 );
575 }
576 m_cos_theta[m_index] = m_lv_book.vect().cosTheta();
577 m_phi[m_index] = m_lv_book.vect().phi();
578 m_four_mom[m_index][0] = m_lv_book.e();
579 m_four_mom[m_index][1] = m_lv_book.px();
580 m_four_mom[m_index][2] = m_lv_book.py();
581 m_four_mom[m_index][3] = m_lv_book.pz();
582 }
583
584 if ( m_subsample_flag ) setFilterPassed( true );
585 else if ( m_mass_recoil > 3.08 && m_mass_recoil < 3.12 && m_mass_jpsi > 3.0 &&
586 m_mass_jpsi < 3.2 && m_cms_lepp < 1.7 && m_cms_lepp > 1.4 && m_cms_lepm < 1.7 &&
587 m_cms_lepm > 1.4 && m_event_flag == 4 && m_pipi_dang < m_pipi_dang_cut )
588 setFilterPassed( true );
589 // cout << "passed" << endl;
590
591 // MC information
592 SmartDataPtr<Event::McParticleCol> mcParticleCol( eventSvc(), "/Event/MC/McParticleCol" );
593 if ( m_run < 0 )
594 {
595 int m_numParticle( 0 ), m_true_pid( 0 );
596 if ( !mcParticleCol )
597 {
598 log << MSG::ERROR << "Could not retrieve McParticelCol" << endmsg;
599 return StatusCode::FAILURE;
600 }
601 else
602 {
603 bool psipDecay( false );
604 int rootIndex( -1 );
605 Event::McParticleCol::iterator iter_mc = mcParticleCol->begin();
606 for ( ; iter_mc != mcParticleCol->end(); iter_mc++ )
607 {
608 if ( ( *iter_mc )->primaryParticle() ) continue;
609 if ( !( *iter_mc )->decayFromGenerator() ) continue;
610 // if ( ((*iter_mc)->mother()).trackIndex()<3 ) continue;
611 if ( ( *iter_mc )->particleProperty() == 100443 )
612 {
613 psipDecay = true;
614 rootIndex = ( *iter_mc )->trackIndex();
615 }
616 if ( !psipDecay ) continue;
617 int mcidx = ( ( *iter_mc )->mother() ).trackIndex() - rootIndex;
618 int pdgid = ( *iter_mc )->particleProperty();
619 m_pdgid[m_numParticle] = pdgid;
620 m_motheridx[m_numParticle] = mcidx;
621 m_numParticle++;
622
623 // if(!(*iter_mc)->leafParticle()) continue;
624 if ( ( *iter_mc )->particleProperty() == 211 )
625 m_true_pionp = ( *iter_mc )->initialFourMomentum().vect().mag();
626 if ( ( *iter_mc )->particleProperty() == -211 )
627 m_true_pionm = ( *iter_mc )->initialFourMomentum().vect().mag();
628 }
629 m_idxmc = m_numParticle;
630 }
631 }
632
633 m_tuple1->write();
634 m_tuple8->write();
635
636 // next is good photon selection
637 Vint iGam;
638 iGam.clear();
639 for ( int i = evtRecEvent->totalCharged(); i < evtRecEvent->totalTracks(); i++ )
640 {
641 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + i;
642 if ( !( *itTrk )->isEmcShowerValid() ) continue;
643 RecEmcShower* emcTrk = ( *itTrk )->emcShower();
644 Hep3Vector emcpos( emcTrk->x(), emcTrk->y(), emcTrk->z() );
645 // find the nearest charged track
646 double dthe = 200.;
647 double dphi = 200.;
648 double dang = 200.;
649 for ( int j = 0; j < evtRecEvent->totalCharged(); j++ )
650 {
651 EvtRecTrackIterator jtTrk = evtRecTrkCol->begin() + j;
652 if ( !( *jtTrk )->isExtTrackValid() ) continue;
653 RecExtTrack* extTrk = ( *jtTrk )->extTrack();
654 if ( extTrk->emcVolumeNumber() == -1 ) continue;
655 Hep3Vector extpos = extTrk->emcPosition();
656 // double ctht = extpos.cosTheta(emcpos);
657 double angd = extpos.angle( emcpos );
658 double thed = extpos.theta() - emcpos.theta();
659 double phid = extpos.deltaPhi( emcpos );
660 thed = fmod( thed + CLHEP::twopi + CLHEP::twopi + pi, CLHEP::twopi ) - CLHEP::pi;
661 phid = fmod( phid + CLHEP::twopi + CLHEP::twopi + pi, CLHEP::twopi ) - CLHEP::pi;
662
663 if ( fabs( thed ) < fabs( dthe ) ) dthe = thed;
664 if ( fabs( phid ) < fabs( dphi ) ) dphi = phid;
665 if ( angd < dang ) dang = angd;
666 }
667 if ( dang >= 200 ) continue;
668 double eraw = emcTrk->energy();
669 dthe = dthe * 180 / ( CLHEP::pi );
670 dphi = dphi * 180 / ( CLHEP::pi );
671 dang = dang * 180 / ( CLHEP::pi );
672 m_dthe = dthe;
673 m_dphi = dphi;
674 m_dang = dang;
675 m_eraw = eraw;
676 // if(eraw < m_energyThreshold) continue;
677 // if((fabs(dthe) < m_gammaThetaCut) && (fabs(dphi)<m_gammaPhiCut) ) continue;
678 // good photon cut will be set here
679 iGam.push_back( ( *itTrk )->trackId() );
680 }
681 // Finish Good Photon Selection
682 m_nGam = iGam.size();
683 log << MSG::DEBUG << "num Good Photon " << m_nGam << " , " << evtRecEvent->totalNeutral()
684 << endmsg;
685 m_tuple2->write();
686
687 //
688 // check dedx infomation
689 //
690 if ( m_checkDedx )
691 {
692 int m_dedx_cout( 0 );
693 for ( int i = 0; i < nGood; i++ )
694 {
695 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + iGood[i];
696 if ( !( *itTrk )->isMdcDedxValid() ) continue;
697 RecMdcKalTrack* mdcTrk = ( *itTrk )->mdcKalTrack();
698 RecMdcDedx* dedxTrk = ( *itTrk )->mdcDedx();
699
700 m_ptrk = mdcTrk->p();
701 m_chie = dedxTrk->chiE();
702 m_chimu = dedxTrk->chiMu();
703 m_chipi = dedxTrk->chiPi();
704 m_chik = dedxTrk->chiK();
705 m_chip = dedxTrk->chiP();
706 m_ghit = dedxTrk->numGoodHits();
707 m_thit = dedxTrk->numTotalHits();
708 m_probPH = dedxTrk->probPH();
709 m_normPH = dedxTrk->normPH();
710
711 m_tuple3->write();
712 }
713 }
714
715 //
716 // check TOF infomation
717 //
718 if ( m_checkTof )
719 {
720 int m_endcap_cout( 0 ), m_layer1_cout( 0 ), m_layer2_cout( 0 );
721 for ( int i = 0; i < nGood; i++ )
722 {
723 EvtRecTrackIterator itTrk = evtRecTrkCol->begin() + iGood[i];
724 if ( !( *itTrk )->isTofTrackValid() ) continue;
725
726 RecMdcKalTrack* mdcTrk = ( *itTrk )->mdcKalTrack();
727 SmartRefVector<RecTofTrack> tofTrkCol = ( *itTrk )->tofTrack();
728
729 double ptrk = mdcTrk->p();
730
731 for ( SmartRefVector<RecTofTrack>::iterator iter_tof = tofTrkCol.begin();
732 iter_tof != tofTrkCol.end(); iter_tof++ )
733 {
734 TofHitStatus* status = new TofHitStatus;
735 status->setStatus( ( *iter_tof )->status() );
736 if ( !( status->is_barrel() ) )
737 { // endcap
738 if ( !( status->is_counter() ) ) continue; // ?
739 if ( status->layer() != 0 ) continue; // layer1
740 double path = ( *iter_tof )->path(); // ? the unit is cm
741 double tof = ( *iter_tof )->tof(); // the unit is ns/100
742 double ph = ( *iter_tof )->ph();
743 double rhit = ( *iter_tof )->zrhit();
744 double qual = 0.0 + ( *iter_tof )->quality();
745 double cntr = 0.0 + ( *iter_tof )->tofID();
746 double texp[5];
747 for ( int j = 0; j < 5; j++ )
748 {
749 double gb = xmass[j] / ptrk;
750 double beta = sqrt( 1 + gb * gb );
751 texp[j] = path * beta / velc; // the unit here is ns
752 }
753 m_cntr_etof = cntr;
754 m_ptot_etof = ptrk;
755 m_path_etof = path;
756 m_ph_etof = ph;
757 m_rhit_etof = rhit;
758 m_qual_etof = qual;
759 m_tof_etof = tof;
760 m_te_etof = tof - texp[0];
761 m_tmu_etof = tof - texp[1];
762 m_tpi_etof = tof - texp[2];
763 m_tk_etof = tof - texp[3];
764 m_tp_etof = tof - texp[4];
765
766 m_tuple4->write();
767 }
768 else
769 { // barrel
770 if ( !( status->is_counter() ) ) continue; // ?
771 if ( status->layer() == 1 )
772 { // layer1
773 double path = ( *iter_tof )->path(); // ?
774 double tof = ( *iter_tof )->tof();
775 double ph = ( *iter_tof )->ph();
776 double rhit = ( *iter_tof )->zrhit();
777 double qual = 0.0 + ( *iter_tof )->quality();
778 double cntr = 0.0 + ( *iter_tof )->tofID();
779 double texp[5];
780 for ( int j = 0; j < 5; j++ )
781 {
782 double gb = xmass[j] / ptrk;
783 double beta = sqrt( 1 + gb * gb );
784 texp[j] = path * beta / velc;
785 }
786
787 m_cntr_btof1 = cntr;
788 m_ptot_btof1 = ptrk;
789 m_path_btof1 = path;
790 m_ph_btof1 = ph;
791 m_zhit_btof1 = rhit;
792 m_qual_btof1 = qual;
793 m_tof_btof1 = tof;
794 m_te_btof1 = tof - texp[0];
795 m_tmu_btof1 = tof - texp[1];
796 m_tpi_btof1 = tof - texp[2];
797 m_tk_btof1 = tof - texp[3];
798 m_tp_btof1 = tof - texp[4];
799
800 m_tuple5->write();
801 }
802
803 if ( status->layer() == 2 )
804 { // layer2
805 double path = ( *iter_tof )->path(); // ?
806 double tof = ( *iter_tof )->tof();
807 double ph = ( *iter_tof )->ph();
808 double rhit = ( *iter_tof )->zrhit();
809 double qual = 0.0 + ( *iter_tof )->quality();
810 double cntr = 0.0 + ( *iter_tof )->tofID();
811 double texp[5];
812 for ( int j = 0; j < 5; j++ )
813 {
814 double gb = xmass[j] / ptrk;
815 double beta = sqrt( 1 + gb * gb );
816 texp[j] = path * beta / velc;
817 }
818
819 m_cntr_btof2 = cntr;
820 m_ptot_btof2 = ptrk;
821 m_path_btof2 = path;
822 m_ph_btof2 = ph;
823 m_zhit_btof2 = rhit;
824 m_qual_btof2 = qual;
825 m_tof_btof2 = tof;
826 m_te_btof2 = tof - texp[0];
827 m_tmu_btof2 = tof - texp[1];
828 m_tpi_btof2 = tof - texp[2];
829 m_tk_btof2 = tof - texp[3];
830 m_tp_btof2 = tof - texp[4];
831
832 m_tuple6->write();
833 }
834 }
835
836 delete status;
837 }
838 } // loop all charged track
839 } // check tof
840
841 return StatusCode::SUCCESS;
842}
843
844// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
845StatusCode PipiJpsi::finalize() {
846
847 MsgStream log( msgSvc(), name() );
848 log << MSG::INFO << "in finalize()" << endmsg;
849 if ( m_eventrate )
850 cout << "all event: " << m_cout_all << endl
851 << "only channel " << m_chan_det << ": " << m_cout_everat << endl;
852 cout << "all event: " << m_cout_all << endl
853 << "all collection point is OK: " << m_cout_col << endl
854 << "charged tracks >=3: " << m_cout_charge << endl
855 << "good charged tracks [3,4]: " << m_cout_nGood << endl
856 << "after momentum assign: " << m_cout_mom << endl
857 << "after recoild mass cut: " << m_cout_recoil << endl;
858 return StatusCode::SUCCESS;
859}
DECLARE_COMPONENT(BesBdkRc)
HepGeom::Point3D< double > HepPoint3D
EvtRecTrackCol::iterator EvtRecTrackIterator
#define PI
double mpi
double pi
double me
double mmu
std::vector< HepLorentzVector > Vp4
Definition Gam4pikp.cxx:38
const double xmass[5]
Definition Gam4pikp.cxx:35
const double velc
Definition Gam4pikp.cxx:36
std::vector< int > Vint
Definition Gam4pikp.cxx:37
static long m_cout_col(0)
const double mpsip
Definition PipiJpsi.cxx:51
const double mproton
Definition PipiJpsi.cxx:49
static long m_cout_everat(0)
static long m_cout_charge(0)
static long m_cout_nGood(0)
static long m_cout_recoil(0)
static long m_cout_mom(0)
INTupleSvc * ntupleSvc()
IMessageSvc * msgSvc()
const HepLorentzVector p4() const
StatusCode finalize()
Definition PipiJpsi.cxx:845
StatusCode execute()
Definition PipiJpsi.cxx:308
PipiJpsi(const std::string &name, ISvcLocator *pSvcLocator)
Definition PipiJpsi.cxx:64
StatusCode initialize()
Definition PipiJpsi.cxx:84
void setStatus(unsigned int status)