CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackingTruthValid.cc
Go to the documentation of this file.
2 
4 
13 
16 
21 
22 #include <cmath>
23 
25 
31 
32 
34 
36  : outputFile( conf.getParameter<std::string>( "outputFile" ) )
37  , dbe_( NULL )
38  , vec_TrackingParticle_Token_( consumes<TrackingParticleCollection>( conf.getParameter<edm::InputTag>( "src" ) ) ) {}
39 
42  dbe_->setCurrentFolder("Tracking/TrackingMCTruth/TrackingParticle");
43 
44 
45  meTPMass = dbe_->book1D("TPMass","Tracking Particle Mass",100, -1,+5.);
46  meTPCharge = dbe_->book1D("TPCharge","Tracking Particle Charge",10, -5, 5);
47  meTPId = dbe_->book1D("TPId","Tracking Particle Id",500, -5000, 5000);
48  meTPProc = dbe_->book1D("TPProc","Tracking Particle Proc",20, -0.5, 19.5);
49  meTPAllHits = dbe_->book1D("TPAllHits", "Tracking Particle All Hits", 200, -0.5, 199.5);
50  meTPMatchedHits = dbe_->book1D("TPMatchedHits", "Tracking Particle Matched Hits", 100, -0.5, 99.5);
51  meTPPt = dbe_->book1D("TPPt", "Tracking Particle Pt",100, 0, 100.);
52  meTPEta = dbe_->book1D("TPEta", "Tracking Particle Eta",100, -7., 7.);
53  meTPPhi = dbe_->book1D("TPPhi", "Tracking Particle Phi",100, -4., 4);
54  meTPVtxX = dbe_->book1D("TPVtxX", "Tracking Particle VtxX",100, -100, 100.);
55  meTPVtxY = dbe_->book1D("TPVtxY", "Tracking Particle VtxY",100, -100, 100.);
56  meTPVtxZ = dbe_->book1D("TPVtxZ", "Tracking Particle VtxZ",100, -100, 100.);
57  meTPtip = dbe_->book1D("TPtip", "Tracking Particle tip",100, 0, 1000.);
58  meTPlip = dbe_->book1D("TPlip", "Tracking Particle lip",100, 0, 100.);
59 
60 
61  // Prepare Axes Labels for Processes
62  meTPProc->setBinLabel( 1,"Undefined"); // value = 0
63  meTPProc->setBinLabel( 2,"Unknown"); // value = 1
64  meTPProc->setBinLabel( 3,"Primary"); // value = 2
65  meTPProc->setBinLabel( 4,"Hadronic"); // value = 3
66  meTPProc->setBinLabel( 5,"Decay"); // value = 4
67  meTPProc->setBinLabel( 6,"Compton"); // value = 5
68  meTPProc->setBinLabel( 7,"Annihilation"); // value = 6
69  meTPProc->setBinLabel( 8,"EIoni"); // value = 7
70  meTPProc->setBinLabel( 9,"HIoni"); // value = 8
71  meTPProc->setBinLabel(10,"MuIoni"); // value = 9
72  meTPProc->setBinLabel(11,"Photon"); // value = 10
73  meTPProc->setBinLabel(12,"MuPairProd"); // value = 11
74  meTPProc->setBinLabel(13,"Conversions"); // value = 12
75  meTPProc->setBinLabel(14,"EBrem"); // value = 13
76  meTPProc->setBinLabel(15,"SynchrotronRadiation"); // value = 14
77  meTPProc->setBinLabel(16,"MuBrem"); // value = 15
78  meTPProc->setBinLabel(17,"MuNucl"); // value = 16
79  meTPProc->setBinLabel(18,"");
80  meTPProc->setBinLabel(19,"");
81  meTPProc->setBinLabel(20,"");
82 }
83 
85 
86  edm::Handle<TrackingParticleCollection> TruthTrackContainer ;
87  // edm::Handle<TrackingVertexCollection> TruthVertexContainer;
88 
89  event.getByToken( vec_TrackingParticle_Token_, TruthTrackContainer );
90 
91  const TrackingParticleCollection *tPC = TruthTrackContainer.product();
92  // const TrackingVertexCollection *tVC = TruthVertexContainer.product();
93 
94  /*
95  // Get and print HepMC event for comparison
96  edm::Handle<edm::HepMCProduct> hepMC;
97  event.getByLabel("source",hepMC);
98  const edm::HepMCProduct *mcp = hepMC.product();
99  // const HepMC::GenEvent *genEvent = mcp -> GetEvent();
100  */
101  // cout << "Found " << tPC -> size() << " tracks and " << tVC -> size() << " vertices." <<endl;
102 
103 
104 // Loop over TrackingParticle's
105 
106  for (TrackingParticleCollection::const_iterator t = tPC -> begin(); t != tPC -> end(); ++t) {
107  //if(t -> trackerPSimHit().size() ==0) cout << " Track with 0 SimHit " << endl;
108 
109  meTPMass->Fill(t->mass());
110  meTPCharge->Fill(t->charge() );
111  meTPId->Fill(t->pdgId());
112  meTPPt->Fill(sqrt(t->momentum().perp2()));
113  meTPEta->Fill(t->momentum().eta());
114  meTPPhi->Fill(t->momentum().Phi());
115  //#warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
116  //#ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
117  // std::vector<PSimHit> trackerPSimHit( t->trackPSimHit(DetId::Tracker) );
118  //#endif
119  meTPAllHits->Fill(t->numberOfTrackerHits());
120  //get the process of the first hit
121  //#warning "This file has been modified just to get it to compile without any regard as to whether it still functions as intended"
122  //#ifdef REMOVED_JUST_TO_GET_IT_TO_COMPILE__THIS_CODE_NEEDS_TO_BE_CHECKED
123  // if(trackerPSimHit.size() !=0) meTPProc->Fill( trackerPSimHit.front().processType());
124  //#endif
125 
126  // there is no more the PSimHits collection !!! how to deal w/ the processType ?
127  // if(t->numberOfTrackerHits() !=0) meTPProc->Fill( trackerPSimHit.front().processType());
128 
129  meTPMatchedHits->Fill(t->numberOfTrackerLayers());
130  meTPVtxX->Fill(t->vx());
131  meTPVtxY->Fill(t->vy());
132  meTPVtxZ->Fill(t->vz());
133  meTPtip->Fill(sqrt(t->vertex().perp2()));
134  meTPlip->Fill(t->vz());
135 
136  /*
137  // Compare momenta from sources
138  cout << "T.P. Track mass, Momentum, q , ID, & Event # "
139  << t -> mass() << " "
140  << t -> p4() << " " << t -> charge() << " "
141  << t -> pdgId() << " "
142  << t -> eventId().bunchCrossing() << "." << t -> eventId().event() << endl;
143 
144  if(t->mass() < 0) cout << "======= WARNING, this particle has negative mass: " << t->mass()
145  << " and pdgId: " << t->pdgId() << endl;
146  if(t->pdgId() == 0) cout << "======= WARNING, this particle has pdgId = 0: " << t->pdgId() << endl;
147  cout << " Hits for this track: " << t -> trackerPSimHit().size() << endl;
148  */
149 
150  /*
151  std::cout << std::endl << "### Tracking Particle ###" << std::endl;
152  std::cout << (*t) << std::endl;
153  std::cout << "\t Tracker: " << t->trackerPSimHit().size() << std::endl;
154  std::cout << "\t Muon: " << t->muonPSimHit().size() << std::endl;
155  std::cout << (*t) << std::endl;
156  */
157  } // End loop over TrackingParticle
158 
159  // Loop over TrackingVertex's
160  /*
161  cout << "Dumping sample vertex info" << endl;
162  for (TrackingVertexCollection::const_iterator v = tVC -> begin(); v != tVC -> end(); ++v) {
163  cout << " Vertex Position & Event #" << v -> position() << " " << v -> eventId().bunchCrossing() << "." << v -> eventId().event() << endl;
164  cout << " Associated with " << v -> daughterTracks().size() << " tracks" << endl;
165  // Get Geant and HepMC positions
166  for (genv_iterator genV = v -> genVertices_begin(); genV != v -> genVertices_end(); ++genV) {
167  cout << " HepMC vertex position " << (*(*genV)).position() << endl;
168  }
169  for (g4v_iterator g4V = v -> g4Vertices_begin(); g4V != v -> g4Vertices_end(); ++g4V) {
170  cout << " Geant vertex position " << (*g4V).position() << endl;
171  // Probably empty all the time, currently
172  }
173 
174  // Loop over daughter track(s)
175  for (tp_iterator iTP = v -> daughterTracks_begin(); iTP != v -> daughterTracks_end(); ++iTP) {
176  cout << " Daughter starts: " << (*(*iTP)).vertex();
177  for (g4t_iterator g4T = (*(*iTP)).g4Track_begin(); g4T != (*(*iTP)).g4Track_end(); ++g4T) {
178  cout << " p " << g4T->momentum();
179  }
180  cout << endl;
181  }
182 
183  // Loop over source track(s) (can be multiple since vertices are collapsed)
184  for (tp_iterator iTP = v -> sourceTracks_begin(); iTP != v -> sourceTracks_end(); ++iTP) {
185  cout << " Source starts: " << (*(*iTP)).vertex();
186  for (g4t_iterator g4T = (*iTP)->g4Track_begin(); g4T != (*iTP)->g4Track_end(); ++g4T) {
187  cout << ", p " << g4T ->momentum();
188  }
189  cout << endl;
190  }
191  } // End loop over TrackingVertex
192  */
193 
194 
195 }
196 
198 
199  if ( outputFile.size() != 0 && dbe_ ) dbe_->save(outputFile);
200 
201 }
virtual void beginJob()
Definition: EDAnalyzer.h:63
MonitorElement * meTPAllHits
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:872
MonitorElement * meTPVtxX
TrackingVertex::g4v_iterator g4v_iterator
std::vector< SimVertex >::const_iterator g4v_iterator
MonitorElement * meTPtip
MonitorElement * meTPPhi
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
TrackingParticleRefVector::iterator tp_iterator
MonitorElement * meTPVtxZ
#define NULL
Definition: scimark2.h:8
MonitorElement * meTPVtxY
TrackingParticle::genp_iterator genp_iterator
void Fill(long long x)
MonitorElement * meTPEta
edm::EDGetTokenT< TrackingParticleCollection > vec_TrackingParticle_Token_
TrackingVertex::genv_iterator genv_iterator
T sqrt(T t)
Definition: SSEVec.h:48
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", const uint32_t run=0, SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:2296
std::vector< TrackingParticle > TrackingParticleCollection
MonitorElement * meTPProc
#define end
Definition: vmac.h:37
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
edm::RefVector< TrackingParticleCollection > TrackingParticleContainer
DQMStore * dbe_
tuple conf
Definition: dbtoconf.py:185
std::vector< SimTrack >::const_iterator g4t_iterator
MonitorElement * meTPMatchedHits
virtual void analyze(const edm::Event &, const edm::EventSetup &)
T const * product() const
Definition: Handle.h:81
MonitorElement * meTPCharge
void beginRun(const edm::Run &, const edm::EventSetup &)
#define begin
Definition: vmac.h:30
MonitorElement * meTPMass
MonitorElement * meTPlip
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:584
MonitorElement * meTPPt
Definition: Run.h:41
TrackingTruthValid(const edm::ParameterSet &conf)
MonitorElement * meTPId
TrackingParticle::g4t_iterator g4t_iterator