00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "AtlfastAlgs/TrackNtupleMaker.h"
00015 #include "AtlfastEvent/CollectionDefs.h"
00016 #include "AtlfastUtils/HeaderPrinter.h"
00017
00018
00019 #include "GaudiKernel/PropertyMgr.h"
00020 #include "GaudiKernel/INTupleSvc.h"
00021 #include "GaudiKernel/ISvcLocator.h"
00022 #include "GaudiKernel/IDataProviderSvc.h"
00023 #include "GaudiKernel/MsgStream.h"
00024 #include "GaudiKernel/NTuple.h"
00025 #include "GaudiKernel/ObjectList.h"
00026 #include "GaudiKernel/SmartDataPtr.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <cmath>
00036
00041 namespace Atlfast {
00042 TrackNtupleMaker::TrackNtupleMaker(const std::string& name,
00043 ISvcLocator* pSvcLocator)
00044 :Algorithm(name, pSvcLocator){
00045
00046 m_trackLocation = "/Event/AtlfastTracks";
00047 declareProperty( "TrackLocation", m_trackLocation );
00048 }
00049
00050
00051
00052 StatusCode TrackNtupleMaker::initialize() {
00053 MsgStream log(msgSvc(), name());
00054 log << MSG::DEBUG << "Initialising SNM" << endreq;
00055 StatusCode status;
00056
00057 m_nEvents = 0;
00058
00059
00060 log << MSG::DEBUG << "Ntuple call 52" << endreq;
00061 NTuple::Directory* col = 0;
00062 log << MSG::DEBUG << "About to open ntuple file" << endreq;
00063 NTupleFilePtr file2(ntupleSvc(), "/NTUPLES/FILE1");
00064 if ( file2 ) {
00065 log << MSG::DEBUG << "Opened ntuple file" << endreq;
00066 if ( !(col=ntupleSvc()->createDirectory("/NTUPLES/FILE1/Atlfast")) ) {
00067 log << MSG::ERROR << "Cannot create directory /NTUPLES/FILE1/Atlfast"
00068 << endreq;
00069 return StatusCode::FAILURE;
00070 }else{
00071 log << MSG::DEBUG << "Created ntuple directory" << endreq;
00072 }
00073 }
00074 else {
00075 log << MSG::ERROR << "Cannot access file /NTUPLES/FILE1" << endreq;
00076 return StatusCode::FAILURE;
00077 }
00078
00079 NTuplePtr nt1(ntupleSvc(), "/NTUPLES/FILE1/Atlfast/52");
00080 if ( !nt1 ) {
00081 nt1 = ntupleSvc()->book (col, 52, CLID_ColumnWiseTuple, "Tracks52");
00082 if ( nt1 ) {
00083 log << MSG::DEBUG << "booked ntuple " << endreq;
00084
00085
00086 status = nt1->addItem ("PTRACKS/NTRA" , m_ntra, 0, 500 );
00087 status = nt1->addItem ("PTRACKS/KPTRA" , m_ntra, m_kpTruth);
00088 status = nt1->addItem ("PTRACKS/KFTRA" , m_ntra, m_kfTruth);
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 status = nt1->addItem ("PTRACKS/D0TRA " , m_ntra, m_d0Truth);
00104 status = nt1->addItem ("PTRACKS/Z0TRA " , m_ntra, m_z0Truth);
00105 status = nt1->addItem ("PTRACKS/PHITRA " , m_ntra, m_phiTruth);
00106 status = nt1->addItem ("PTRACKS/COTTRA " , m_ntra, m_cotTruth);
00107 status = nt1->addItem ("PTRACKS/PTINVTRA " , m_ntra, m_ptInvTruth);
00108 status = nt1->addItem ("PTRACKS/RADTRA " , m_ntra, m_radiusTruth);
00109 status = nt1->addItem ("PTRACKS/CURVTRA " , m_ntra, m_curvTruth);
00110
00111 status = nt1->addItem ("PTRACKS/D0TRACRU " , m_ntra, m_d0Track);
00112 status = nt1->addItem ("PTRACKS/Z0TRACRU " , m_ntra, m_z0Track);
00113 status = nt1->addItem ("PTRACKS/PHITRACRU " , m_ntra, m_phiTrack);
00114 status = nt1->addItem ("PTRACKS/COTTRACRU " , m_ntra, m_cotTrack);
00115 status = nt1->addItem ("PTRACKS/PTINVTRACRU " , m_ntra, m_ptInvTrack);
00116 status = nt1->addItem ("PTRACKS/RADTRACRU " , m_ntra, m_radiusTrack);
00117 status = nt1->addItem ("PTRACKS/CURVTRACRU " , m_ntra, m_curvTrack);
00118
00119 status = nt1->addItem ("PTRACKS/CORR11TRA " , m_ntra, m_corr11tra);
00120 status = nt1->addItem ("PTRACKS/CORR21TRA " , m_ntra, m_corr12tra);
00121 status = nt1->addItem ("PTRACKS/CORR31TRA " , m_ntra, m_corr13tra);
00122 status = nt1->addItem ("PTRACKS/CORR41TRA " , m_ntra, m_corr14tra);
00123 status = nt1->addItem ("PTRACKS/CORR51TRA " , m_ntra, m_corr15tra);
00124 status = nt1->addItem ("PTRACKS/CORR22TRA " , m_ntra, m_corr22tra);
00125 status = nt1->addItem ("PTRACKS/CORR23TRA " , m_ntra, m_corr23tra);
00126 status = nt1->addItem ("PTRACKS/CORR24TRA " , m_ntra, m_corr24tra);
00127 status = nt1->addItem ("PTRACKS/CORR25TRA " , m_ntra, m_corr25tra);
00128 status = nt1->addItem ("PTRACKS/CORR33TRA " , m_ntra, m_corr33tra);
00129 status = nt1->addItem ("PTRACKS/CORR34TRA " , m_ntra, m_corr34tra);
00130 status = nt1->addItem ("PTRACKS/CORR35TRA " , m_ntra, m_corr35tra);
00131 status = nt1->addItem ("PTRACKS/CORR44TRA " , m_ntra, m_corr44tra);
00132 status = nt1->addItem ("PTRACKS/CORR45TRA " , m_ntra, m_corr45tra);
00133 status = nt1->addItem ("PTRACKS/CORR55TRA " , m_ntra, m_corr55tra);
00134 }
00135 else {
00136 return StatusCode::FAILURE;
00137 }
00138 }
00139
00140 log<<MSG::DEBUG<<"returning with status"<< status<<endreq;
00141 m_tesIO = new TesIO();
00142
00143 HeaderPrinter hp("Atlfast TrackNtupleMaker:", log);
00144 hp.add("Track Location ", m_trackLocation);
00145 hp.print();
00146
00147 return StatusCode::SUCCESS;
00148 }
00149
00150
00151 StatusCode TrackNtupleMaker::execute() {
00152
00153 MsgStream log(msgSvc(), name());
00154
00155
00156 if( m_nEvents % 50 == 0) {
00157 log << MSG::INFO << " processing event number "
00158 << m_nEvents << endreq;
00159 }
00160
00161 m_nEvents++;
00162
00163 StatusCode status;
00164
00165
00166
00167
00168
00169 std::vector<Track*> tr;
00170 if( !m_tesIO->copy<TrackCollection> (tr, m_trackLocation) ){
00171 log <<MSG::DEBUG << "Could not find Tracks"<<endreq;
00172 }
00173 log << MSG::DEBUG << "Processing tracks" <<tr.size()<< endreq;
00174
00175 std::vector<Track*>::const_iterator itr = tr.begin();
00176
00177 m_ntra = 0;
00178 for (;itr != tr.end(); ++itr ) {
00179 log<<MSG::DEBUG<< " dumping track: "<<m_ntra<<endreq;
00180 log<<MSG::DEBUG<<(*itr)<<endreq<<endreq;
00181
00182 const HepMC::GenParticle* particle = (*itr)->truth();
00183
00184 m_kpTruth[m_ntra]= 0;
00185 m_kfTruth[m_ntra]= particle->pdg_id();
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 TrackTrajectory truthTraj = (*itr)->truthTrajectory();
00202 TrackTrajectory traj = (*itr)->trajectory();
00203 TrackParameters truthParam = truthTraj.parameters();
00204 TrackParameters smearParam = traj.parameters();
00205
00206 m_d0Truth[m_ntra] = truthParam.impactParameter();
00207 m_z0Truth[m_ntra] = truthParam.zPerigee();
00208 m_phiTruth[m_ntra] = truthParam.phi();
00209 m_cotTruth[m_ntra] = truthParam.cotTheta();
00210 m_ptInvTruth[m_ntra] = truthParam.invPtCharge();
00211 m_radiusTruth[m_ntra] = truthTraj.radius();
00212 m_curvTruth[m_ntra] = truthTraj.curvature();
00213
00214 m_d0Track[m_ntra] = smearParam.impactParameter();
00215 m_z0Track[m_ntra] = smearParam.zPerigee();
00216 m_phiTrack[m_ntra] = smearParam.phi();
00217 m_cotTrack[m_ntra] = smearParam.cotTheta();
00218 m_ptInvTrack[m_ntra] = smearParam.invPtCharge();
00219 m_radiusTrack[m_ntra] = traj.radius();
00220 m_curvTrack[m_ntra] = traj.curvature();
00221
00222 m_corr11tra[m_ntra]= ( (*itr)->smearMatrix() )(1,1);
00223 m_corr12tra[m_ntra]= ( (*itr)->smearMatrix() )(1,2);
00224 m_corr13tra[m_ntra]= ( (*itr)->smearMatrix() )(1,3);
00225 m_corr14tra[m_ntra]= ( (*itr)->smearMatrix() )(1,4);
00226 m_corr15tra[m_ntra]= ( (*itr)->smearMatrix() )(1,5);
00227 m_corr22tra[m_ntra]= ( (*itr)->smearMatrix() )(2,2);
00228 m_corr23tra[m_ntra]= ( (*itr)->smearMatrix() )(2,3);
00229 m_corr24tra[m_ntra]= ( (*itr)->smearMatrix() )(2,4);
00230 m_corr25tra[m_ntra]= ( (*itr)->smearMatrix() )(2,5);
00231 m_corr33tra[m_ntra]= ( (*itr)->smearMatrix() )(3,3);
00232 m_corr34tra[m_ntra]= ( (*itr)->smearMatrix() )(3,4);
00233 m_corr35tra[m_ntra]= ( (*itr)->smearMatrix() )(3,5);
00234 m_corr44tra[m_ntra]= ( (*itr)->smearMatrix() )(4,4);
00235 m_corr45tra[m_ntra]= ( (*itr)->smearMatrix() )(4,5);
00236 m_corr55tra[m_ntra]= ( (*itr)->smearMatrix() )(5,5);
00237
00238 if ( ++m_ntra == m_ntra->range().distance() ) break;
00239 }
00240
00241
00242
00243 log << MSG::DEBUG << "Writing ntuple part 52" << endreq;
00244 status = ntupleSvc()->writeRecord("/NTUPLES/FILE1/Atlfast/52");
00245 if ( !status.isSuccess() ) log <<MSG::ERROR
00246 <<"Cannot fill id 52"
00247 <<endreq;
00248 log << MSG::DEBUG << "Done all the ntuple writing" << endreq;
00249 return StatusCode::SUCCESS;
00250 }
00251
00252
00253 StatusCode TrackNtupleMaker::finalize() {
00254
00255 MsgStream log(msgSvc(), name());
00256 log << MSG::DEBUG
00257 << " Number of events processed = "
00258 << m_nEvents << endreq;
00259
00260 return StatusCode::SUCCESS;
00261 }
00262
00263
00264 }
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275