00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "AtlfastAlgs/EventHeaderMaker.h"
00011 #include "AtlfastAlgs/MissingMomentum.h"
00012 #include "AtlfastAlgs/GlobalEventData.h"
00013
00014 #include "AtlfastEvent/EventHeader.h"
00015 #include "AtlfastEvent/IKinematic.h"
00016 #include "AtlfastEvent/MsgStreamDefs.h"
00017 #include "AtlfastEvent/ReconstructedParticle.h"
00018 #include "AtlfastEvent/Cell.h"
00019 #include "AtlfastEvent/Cluster.h"
00020 #include "AtlfastEvent/ParticleCodes.h"
00021 #include "AtlfastEvent/CollectionDefs.h"
00022 #include "AtlfastEvent/MCparticleCollection.h"
00023 #include "AtlfastEvent/ReconstructedParticle.h"
00024 #include "AtlfastEvent/Jet.h"
00025
00026 #include "AtlfastUtils/HeaderPrinter.h"
00027 #include "AtlfastUtils/TesIO.h"
00028
00029
00030 #include <cmath>
00031 #include <string>
00032 #include <vector>
00033 #include <algorithm>
00034 #include <assert.h>
00035
00036
00037 #include "GaudiKernel/DataSvc.h"
00038 #include "StoreGate/DataHandle.h"
00039 #include "GaudiKernel/ISvcLocator.h"
00040 #include "GaudiKernel/MsgStream.h"
00041
00042
00043
00044 #include "GeneratorObjects/McEventCollection.h"
00045
00046 namespace Atlfast {
00047
00048
00049
00050 EventHeaderMaker::EventHeaderMaker
00051 ( const std::string& name, ISvcLocator* pSvcLocator )
00052 : Algorithm( name, pSvcLocator ){
00053
00054
00055 m_electronLocation = "/Event/AtlfastIsolatedElectrons";
00056 m_photonLocation = "/Event/AtlfastIsolatedPhotons";
00057 m_isolatedMuonLocation = "/Event/AtlfastIsolatedMuons";
00058 m_nonIsolatedMuonLocation = "/Event/AtlfastNonIsolatedMuons";
00059 m_jetLocation = "/Event/AtlfastJets";
00060 m_cellLocation = "/Event/AtlfastCells";
00061 m_clusterLocation = "/Event/AtlfastClusters";
00062 m_mcTruthLocation = "/Event/McEventCollection";
00063 m_outputLocation = "/Event/AtlfastEventHeader";
00064 m_missingMomentumLocation = "/Event/AtlfastMissingMomentum";
00065 m_beamEnergy = 7000.0;
00066 m_testMode = false;
00067
00068
00069
00070 declareProperty( "MissingMomentumLocation", m_missingMomentumLocation ) ;
00071 declareProperty( "ElectronLocation", m_electronLocation ) ;
00072 declareProperty( "PhotonLocation", m_photonLocation );
00073 declareProperty( "IsolatedMuonLocation", m_isolatedMuonLocation );
00074 declareProperty( "NonIsolatedMuonLocation", m_nonIsolatedMuonLocation );
00075 declareProperty( "JetLocation", m_jetLocation );
00076 declareProperty( "McTruthLocation", m_mcTruthLocation );
00077 declareProperty( "OutputLocation", m_outputLocation );
00078 declareProperty( "BeamEnergy", m_beamEnergy );
00079
00080 declareProperty( "TestMode", m_testMode ) ;
00081
00082
00083
00084 }
00085
00086
00087
00088
00089
00090 EventHeaderMaker::~EventHeaderMaker(){
00091 delete m_tesIO;
00092 }
00093
00094
00095
00096
00097 StatusCode EventHeaderMaker::initialize()
00098 {
00099
00100 MsgStream log(messageService(), name());
00101 log << MSG::DEBUG << "in initialize()" << endreq;
00102
00103
00104 m_escapingParticles.push_back(ParticleCodes::NU_E);
00105 m_escapingParticles.push_back(ParticleCodes::NU_MU);
00106 m_escapingParticles.push_back(ParticleCodes::NU_TAU);
00107
00108
00109 m_tesIO = new TesIO();
00110
00111
00112 GlobalEventData* ged = GlobalEventData::Instance();
00113 m_visibleToAtlas = ged -> visibleToAtlas();
00114 m_lumi = ged -> lumi();
00115 m_barrelForwardEta = ged -> barrelForwardEta();
00116 HeaderPrinter hp("Atlfast EventHeader Maker:", log);
00117 hp.add("TestMode ", m_testMode);
00118 hp.add("EndCap Begins at (eta) ", m_barrelForwardEta);
00119 hp.add("Luminosity ", m_lumi);
00120 hp.add("Beam Energy ", m_beamEnergy);
00121 hp.add("MC location ", m_mcTruthLocation);
00122 hp.add("Electron Location ", m_electronLocation);
00123 hp.add("Photon Location ", m_photonLocation);
00124 hp.add("Isolated Muon Location ", m_isolatedMuonLocation);
00125 hp.add("Non-Isolated Muon Location ", m_nonIsolatedMuonLocation);
00126 hp.add("Jet Location ", m_jetLocation);
00127 hp.add("Cell Location ", m_cellLocation);
00128 hp.add("Cluster Location ", m_clusterLocation);
00129 hp.add("Unused cell+cluster sum ", m_missingMomentumLocation);
00130 hp.add("Output Location ", m_outputLocation);
00131 hp.print();
00132
00133
00134
00135
00136 return StatusCode::SUCCESS ;
00137 }
00138
00139
00140
00141
00142 StatusCode EventHeaderMaker::finalize()
00143 {
00144
00145 MsgStream log( messageService(), name() ) ;
00146 log << MSG::INFO << "finalizing " << endreq;
00147
00148 return StatusCode::SUCCESS ;
00149 }
00150
00151
00152
00153
00154 StatusCode EventHeaderMaker::execute( )
00155 {
00156
00157
00158
00159
00160 MsgStream log( messageService(), name() ) ;
00161 log << MSG::DEBUG << "Executing " << endreq;
00162 std::string mess;
00163
00164
00165
00166
00167
00168
00169 int nElectrons =
00170 numberInList<ReconstructedParticleCollection>(m_electronLocation);
00171 int nPhotons =
00172 numberInList<ReconstructedParticleCollection>(m_photonLocation);
00173 int nIsolatedMuons =
00174 numberInList<ReconstructedParticleCollection>(m_isolatedMuonLocation);
00175 int nNonIsolatedMuons =
00176 numberInList<ReconstructedParticleCollection>(m_nonIsolatedMuonLocation);
00177 int nJets = numberInList<JetCollection>(m_jetLocation);
00178 int nBJets = numberJetFlavor(m_jetLocation,
00179 ParticleCodes::BQUARK);
00180 int nCJets = numberJetFlavor(m_jetLocation,
00181 ParticleCodes::CQUARK);
00182 int nTauJets = numberJetFlavor(m_jetLocation,
00183 ParticleCodes::TAU);
00184 nTauJets += numberJetFlavor(m_jetLocation,
00185 -ParticleCodes::TAU);
00186
00187 log << MSG::DEBUG << "Electrons: " << nElectrons << endreq;
00188 log << MSG::DEBUG << "Photons: " << nPhotons << endreq;
00189 log << MSG::DEBUG << "IsolatedMuons: " << nIsolatedMuons << endreq;
00190 log << MSG::DEBUG << "NonIsolatedMuons: " << nNonIsolatedMuons << endreq;
00191 log << MSG::DEBUG << "Jets: " << nJets << endreq;
00192
00193
00194
00195
00196 double jetCircularity = 0.0;
00197 double eventCircularity = 0.0;
00198 double thrust = 0.0;
00199 double oblateness = 0.0;
00200
00201
00202 HepLorentzVector pMiss = missingMomentum(log);
00203
00204 log << MSG::DEBUG << "Missing momentum " <<pMiss<<endreq;
00205
00206 HepLorentzVector pEscaped = escapedMomentum(log);
00207
00208 log << MSG::DEBUG << "Escaped momentum " << pEscaped<<endreq;
00209
00210 EventHeader* header =
00211 new EventHeader(
00212 nElectrons,
00213 nIsolatedMuons,
00214 nNonIsolatedMuons,
00215 nPhotons,
00216 nJets,
00217 nBJets,
00218 nCJets,
00219 nTauJets,
00220 jetCircularity,
00221 eventCircularity,
00222 thrust,
00223 oblateness,
00224 pMiss,
00225 pEscaped);
00226
00227 TesIoStat stat = m_tesIO->store(header,m_outputLocation) ;
00228 std::string message = stat? "Stored Evt Header":"Failed to Evt Header";
00229 log<<MSG::DEBUG<<message<<endreq;
00230 return stat;
00231
00232 }
00233
00234
00235
00236 HepLorentzVector EventHeaderMaker::missingMomentum(MsgStream& log) {
00237
00238 HepLorentzVector unused(0., 0., 0., 0.);
00239 const DataHandle<MissingMomentum> mm;
00240 TesIoStat stat = m_tesIO->getDH(mm,m_missingMomentumLocation );
00241 if(!stat){
00242 log << MSG::WARNING<<"Could Not Find Missing momentum in TES"<<endreq;
00243 return unused;
00244 }
00245 log << MSG::DEBUG<<"Found Missing Momentum in TES"<<endreq;
00246
00247 unused = mm->momentum();
00248
00249 HepLorentzVector temp(0.0,0.0,0.0,0.0);
00250
00251
00252 temp = unused
00253 + momentumSum<ReconstructedParticleCollection> (m_electronLocation)
00254 + momentumSum<ReconstructedParticleCollection> (m_photonLocation)
00255 + momentumSum<ReconstructedParticleCollection> (m_isolatedMuonLocation)
00256 + momentumSum<JetCollection> (m_jetLocation)
00257 + momentumSum<ReconstructedParticleCollection> (m_nonIsolatedMuonLocation)
00258 - assocMomentumSum<JetCollection, ReconstructedParticle> (m_jetLocation)
00259 ;
00260
00261 log<<MSG::DEBUG
00262 <<"Total Imbalanced momentum "
00263 <<temp
00264 <<endreq;
00265
00266
00267
00268 if(m_testMode){
00269 HepLorentzVector totCluster =
00270 momentumSum<ClusterCollection> (m_clusterLocation);
00271
00272 HepLorentzVector clusterAssE =
00273 assocMomentumSum<ReconstructedParticleCollection, Cluster>
00274 (m_electronLocation);
00275
00276 HepLorentzVector clusterAssP =
00277 assocMomentumSum<ReconstructedParticleCollection, Cluster>
00278 (m_photonLocation);
00279
00280 HepLorentzVector clusterAssM =
00281 assocMomentumSum<ReconstructedParticleCollection, Cluster>
00282 (m_isolatedMuonLocation);
00283
00284 HepLorentzVector clusterAssJ =
00285 assocMomentumSum<JetCollection, Cluster>(m_jetLocation);
00286
00287 HepLorentzVector clusterDiff = totCluster-
00288 clusterAssJ-
00289 clusterAssE-
00290 clusterAssM-
00291 clusterAssP;
00292
00293 HepLorentzVector totCell =
00294 momentumSum<ITwoCptCellCollection>(m_cellLocation);
00295
00296 HepLorentzVector cellAssCluster =
00297 assocMomentumSum<ClusterCollection, Cell>(m_clusterLocation);
00298
00299 HepLorentzVector cellDiff = totCell-cellAssCluster;
00300
00301 HepLorentzVector diffS = clusterDiff+cellDiff-unused;
00302
00303
00304
00305 log<<MSG::DEBUG<<"Total cluster "<<totCluster<<endreq;
00306 log<<MSG::DEBUG<<"Clus Ass Jet "<<clusterAssJ<<endreq;
00307 log<<MSG::DEBUG<<"Clus Ass El "<<clusterAssE<<endreq;
00308 log<<MSG::DEBUG<<"Clus Ass Mu "<<clusterAssM<<endreq;
00309 log<<MSG::DEBUG<<"Clus Ass Ph "<<clusterAssP<<endreq;
00310 log<<MSG::DEBUG<<"Clus diff "<<clusterDiff<<endreq;
00311 log<<MSG::DEBUG<<"Total Cell "<<totCell<<endreq;
00312 log<<MSG::DEBUG<<"Cell Ass Clus "<<cellAssCluster<<endreq;
00313 log<<MSG::DEBUG<<"Clus diff "<<cellDiff<<endreq;
00314 log<<MSG::DEBUG<<"Cell+Clus diff "<<cellDiff<<endreq;
00315 log<<MSG::DEBUG<<"Unused "<<unused<<endreq;
00316 log<<MSG::DEBUG<<"diff "<<diffS<<endreq;
00317
00318 log<<MSG::DEBUG<<endreq;
00319
00320 assert( diffS.rho() <0.001);
00321
00322
00323
00324
00325
00326 HepLorentzVector temp2 =
00327 momentumSum<ReconstructedParticleCollection> (m_electronLocation)
00328 + momentumSum<ReconstructedParticleCollection> (m_photonLocation)
00329 + momentumSum<ReconstructedParticleCollection> (m_isolatedMuonLocation)
00330 + momentumSum<JetCollection> (m_jetLocation)
00331 + momentumSum<ClusterCollection> (m_clusterLocation)
00332 + momentumSum<ITwoCptCellCollection> (m_cellLocation)
00333 + momentumSum<ReconstructedParticleCollection> (m_nonIsolatedMuonLocation)
00334
00335 - assocMomentumSum<ReconstructedParticleCollection, Cluster>
00336 (m_electronLocation)
00337
00338 - assocMomentumSum<ReconstructedParticleCollection, Cluster>
00339 (m_photonLocation)
00340
00341 - assocMomentumSum<ReconstructedParticleCollection, Cluster>
00342 (m_nonIsolatedMuonLocation)
00343
00344 - assocMomentumSum<JetCollection, Cluster>
00345 (m_jetLocation)
00346
00347 - assocMomentumSum<JetCollection, ReconstructedParticle>
00348 (m_jetLocation)
00349
00350 - assocMomentumSum<ClusterCollection, Cell>
00351 (m_clusterLocation);
00352
00353
00354 assert( (temp-temp2).rho() <0.001);
00355 }
00356
00357
00358
00359 temp.setPx( -temp.px() );
00360 temp.setPy( -temp.py() );
00361 temp.setPz( -temp.pz() );
00362 temp.setE( 2.0*m_beamEnergy - temp.e() );
00363
00364 return temp;
00365 }
00366
00367
00368
00369
00370
00371
00372 HepLorentzVector EventHeaderMaker::escapedMomentum(MsgStream& log) {
00373
00374 HepLorentzVector temp(0.0,0.0,0.0,0.0);
00375
00376 MCparticleCollection mcParticles;
00377 TesIoStat stat = m_tesIO->getMC( mcParticles, m_visibleToAtlas ) ;
00378 std::string mess =
00379 stat? "MC particles retrieved":"MC particles retrieve failed";
00380 log<<MSG::DEBUG<<mess<<endreq;
00381
00382
00383 MCparticleCollection::const_iterator part = mcParticles.begin();
00384 for (;part != mcParticles.end(); ++part) {
00385 temp += (*part)->momentum();
00386 }
00387
00388 return temp;
00389 }
00390
00391 }
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403