00001 #include "DataFormats/DetId/interface/DetId.h"
00002 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00003 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00004 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00005 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00006 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00007 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00008 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00009 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011
00012
00013 #include "FWCore/Framework/interface/MakerMacros.h"
00014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00015
00016 #include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h"
00017 #include "SimDataFormats/CrossingFrame/interface/MixCollection.h"
00018 #include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h"
00019 #include "SimDataFormats/HepMCProduct/interface/HepMCProduct.h"
00020 #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticleFwd.h"
00021 #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h"
00022
00023 #include "SimGeneral/TrackingAnalysis/interface/EncodedTruthId.h"
00024 #include "SimGeneral/TrackingAnalysis/interface/TrackingElectronProducer.h"
00025 #include "SimGeneral/TrackingAnalysis/interface/TkNavigableSimElectronAssembler.h"
00026
00027 #include <map>
00028
00029 using namespace edm;
00030 using namespace std;
00031
00032 typedef TkNavigableSimElectronAssembler::VertexPtr VertexPtr;
00033 typedef math::XYZTLorentzVectorD LorentzVector;
00034
00035 TrackingElectronProducer::TrackingElectronProducer(const edm::ParameterSet &conf) {
00036 produces<TrackingParticleCollection>("ElectronTrackTruth");
00037
00038
00039
00040
00041 conf_ = conf;
00042 }
00043
00044
00045 void TrackingElectronProducer::produce(Event &event, const EventSetup &) {
00046
00047
00048
00049 edm::Handle<TrackingParticleCollection> TruthTrackContainer ;
00050 event.getByType(TruthTrackContainer );
00051
00052 TkNavigableSimElectronAssembler assembler;
00053 std::vector<TrackingParticle*> particles;
00054
00055 for (TrackingParticleCollection::const_iterator t = TruthTrackContainer->begin();
00056 t != TruthTrackContainer->end(); ++t) {
00057 particles.push_back(const_cast<TrackingParticle*>(&(*t)));
00058 }
00059
00060 TkNavigableSimElectronAssembler::ElectronList electrons = assembler.assemble(particles);
00061
00062
00063
00064
00065
00066
00067 std::auto_ptr<TrackingParticleCollection> trackingParticles(new TrackingParticleCollection);
00068
00069 edm::RefProd<TrackingParticleCollection> refTPC =
00070 event.getRefBeforePut<TrackingParticleCollection>("ElectronTrackTruth");
00071
00072
00073
00074
00075
00076 int totsimhit = 0;
00077
00078 for ( TkNavigableSimElectronAssembler::ElectronList::const_iterator ie
00079 = electrons.begin(); ie != electrons.end(); ie++ ) {
00080
00081
00082 TrackingParticle * tk = (*ie).front();
00083 LorentzVector hep4Pos = (*(*tk).parentVertex()).position();
00084 TrackingParticle::Point pos(hep4Pos.x(), hep4Pos.y(), hep4Pos.z());
00085 TrackingParticle tkp( (*tk).charge(), (*tk).p4(), pos, hep4Pos.t(),
00086 (*tk).pdgId(), (*tk).status(), (*tk).eventId() );
00087
00088
00089 int ngenp = 0;
00090 totsimhit = 0;
00091 for (TkNavigableSimElectronAssembler::TrackList::const_iterator it = (*ie).begin();
00092 it != (*ie).end(); it++ ) {
00093
00094 for (TrackingParticle::genp_iterator uz=(*it)->genParticle_begin();
00095 uz!=(*it)->genParticle_end();uz++) {
00096 tkp.addGenParticle(*uz);
00097 ngenp++;
00098 }
00099 addG4Track(tkp, *it);
00100 totsimhit +=(*tk).matchedHit();
00101
00102
00103
00104
00105
00106
00107
00108
00109 }
00110
00111
00112 tkp.setMatchedHit(totsimhit);
00113
00114
00115
00116
00117 TrackingVertexRef parentV = (*(*ie).front()).parentVertex();
00118 if (parentV.isNonnull()) {
00119 tkp.setParentVertex(parentV);
00120 }
00121
00122 TrackingVertexRefVector decayVertices = (*(*ie).back()).decayVertices();
00123 if ( !decayVertices.empty() ) {
00124
00125 TrackingVertexRef decayV = decayVertices.at(0);
00126 tkp.addDecayVertex(decayV);
00127 }
00128
00129
00130
00131
00132 (*trackingParticles).push_back(tkp);
00133 }
00134
00135 event.put(trackingParticles,"ElectronTrackTruth");
00136
00137 }
00138
00139
00140 void TrackingElectronProducer::listElectrons(
00141 const TrackingParticleCollection & tPC) const
00142 {
00143
00144
00145 for (TrackingParticleCollection::const_iterator it = tPC.begin();
00146 it != tPC.end(); it++) {
00147 if (abs((*it).pdgId()) == 11) {
00148
00149
00150
00151 TrackingVertexRef parentV = (*it).parentVertex();
00152
00153
00154
00155
00156
00157
00158 TrackingVertexRefVector decayVertices = (*it).decayVertices();
00159
00160
00161
00162
00163
00164
00165 }
00166 }
00167 }
00168
00169
00170 void
00171 TrackingElectronProducer::addG4Track(TrackingParticle& e,
00172 const TrackingParticle * s) const
00173 {
00174
00175
00176 std::vector<SimTrack> g4Tracks = (*s).g4Tracks();
00177 for ( std::vector<SimTrack>::const_iterator ig4 = g4Tracks.begin();
00178 ig4 != g4Tracks.end(); ig4++ ) {
00179 e.addG4Track(*ig4);
00180 }
00181
00182
00183
00184 std::vector< PSimHit > hits = (*s).trackPSimHit();
00185 for ( std::vector<PSimHit>::const_iterator ih = hits.begin();
00186 ih != hits.end(); ih++ ) {
00187 e.addPSimHit(*ih);
00188 }
00189 }
00190
00191
00192 int TrackingElectronProducer::layerFromDetid(const unsigned int& detid ) {
00193 DetId detId = DetId(detid);
00194 int layerNumber=0;
00195 unsigned int subdetId = static_cast<unsigned int>(detId.subdetId());
00196 if ( subdetId == StripSubdetector::TIB)
00197 {
00198 TIBDetId tibid(detId.rawId());
00199 layerNumber = tibid.layer();
00200 }
00201 else if ( subdetId == StripSubdetector::TOB )
00202 {
00203 TOBDetId tobid(detId.rawId());
00204 layerNumber = tobid.layer();
00205 }
00206 else if ( subdetId == StripSubdetector::TID)
00207 {
00208 TIDDetId tidid(detId.rawId());
00209 layerNumber = tidid.wheel();
00210 }
00211 else if ( subdetId == StripSubdetector::TEC )
00212 {
00213 TECDetId tecid(detId.rawId());
00214 layerNumber = tecid.wheel();
00215 }
00216 else if ( subdetId == PixelSubdetector::PixelBarrel )
00217 {
00218 PXBDetId pxbid(detId.rawId());
00219 layerNumber = pxbid.layer();
00220 }
00221 else if ( subdetId == PixelSubdetector::PixelEndcap )
00222 {
00223 PXFDetId pxfid(detId.rawId());
00224 layerNumber = pxfid.disk();
00225 }
00226 else
00227 edm::LogVerbatim("TrackingTruthProducer") << "Unknown subdetid: " << subdetId;
00228
00229 return layerNumber;
00230 }
00231
00232
00233