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