All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
RecoMCTruthLinker.h
Go to the documentation of this file.
1 #ifndef RecoMCTruthLinker_h
2 #define RecoMCTruthLinker_h
3 
4 #include "marlin/Processor.h"
5 
6 #include <EVENT/MCParticle.h>
7 #include <IMPL/LCCollectionVec.h>
8 #include "lcio.h"
9 #include "EVENT/TrackerHit.h"
10 //#include <UTIL/BitField64.h>
11 #include "UTIL/LCTrackerConf.h"
12 #include "UTIL/ILDConf.h"
13 
14 
15 #include <set>
16 
17 
18 namespace UTIL{
19  class BitField64 ;
20  class LCRelationNavigator ;
21 }
22 
23 using namespace lcio ;
24 
25 
26 
27 /** Optionally creates four collections of LCRelations ("recoMCTruthLink", "trackMCTruthLink", "mcTruthTrackLink", "clusterMCTruthLink",
28  * ""clusterMCTruthLink" and "calohitMCTruthLink") with weighetd relations between true particles
29  * and reconstructed particles, tracks, clusters, and calorimeter hits, respectively.
30  * If the corresponding parameter for the output collection name is empty the collection is not created.
31  *
32  * This relation is based on the number of hits for tracks, for hits weighted with the
33  * SimHit-energy for clusters and calorimeter hits. For tracks and clusters, the weight
34  * is the sum of hits from the considered true particle divided by the sum of all hits,
35  * for calorimter hits, it's simply the simHit energy of the hit.
36  * For the reconstructed particles, the relation could either be only to the true particle
37  * having the largest weight, or to all contributing true particles. In the former case,
38  * the pointer (and weight) will concern the true particle creating hits in the tracker,
39  * if there are any. Only for track-less seen particles would it point to the main
40  * contributor to the cluster. In the latter case, pointers are set up to all contributing
41  * true particles, and the weight is givean as (fractional contribution to track)+
42  * 10000* (fractional contribution to cluster), with fractions given in permil (int).
43  * Hence: trackwgt = (int(wgt)%10000)/1000. and clusterwgt = (int(wgt)/10000)/1000.
44  * Which of the two is used is selected by the processor flag "FullRecoRelation" (default=true)
45  *
46  * For example a weight of 0.95 for a charged particle link implies that 95 percent of the
47  * SimTrackerHits used in the particles' track fit have been caused by the linked MCParticle.<br>
48  * If a neutral particle with one cluster has no MC contribution assigned the MCParticle
49  * pointing closest to the cluster is assigned and the weight is set to the negative scalar product
50  * of the MCParticle's momentum direction and the direction to the Cluster position.
51  * (This fixes a bug in the Mokka LCal driver ov mokka-v06-06-p03).
52  *
53  * <p>
54  * A skimmed MCParticle subset collection is created. It containes all particles created by the generator
55  * program and all particles that have been reconstructed including all their parents.
56  * Additionally, the daughters of all decays in flight of particles specified in 'KeepDaughtersPDG'
57  * (default: gamma, K0s and pi0) are kept in the skimmed list if the original particle
58  * is in the skim ( either from the generator or from reconstruction).
59  *
60  *
61  * <h4>Output</h4>
62  * <ul>
63  * <li><b>trackMCTruthLink</b>: holds LCRelations that map the tracks to the
64  * corresponding MCParticle - the weight is the fraction of all hits on the the track that have contributions from this MCParticle
65  * <li><b>mcTruthTrackLink</b>: holds LCRelations that map MCParticles to tracks - the weight is the fraction of all sim-hits from the MCParticle that contributed to this track
66  * <li><b>clusterMCTruthLink</b>: holds LCRelations that map the clusters to the
67  * corresponding MCParticle
68  * <li><b>recoMCTruthLink</b>: holds LCRelations that map the reconstructed particles to the
69  * corresponding MCParticle
70  * <li><b>calohitMCTruthLink</b>: holds LCRelations that map the calorimeter hits to the
71  * corresponding MCParticle
72  * </li>
73  * <li><b>MCParticlesSkimmed</b>: skimmed MCParticle collection
74  * </li>
75  * </ul>
76  *
77  * @param MCParticleCollectionName the MCParticle input collection
78  * @param trackCollectionName the ReconstructedParticles input collection
79  * @param clusterCollectionName the ReconstructedParticles input collection
80 
81  * @param UseTrackerHitRelations use the rel collection for TrackerHits default true (false only for very old files)
82 
83  * @param TrackerHitsRelInputCollections the rel collection for TrackerHit collection
84 
85  * @param SimClusterHitRelation relation betweeen simulated and digitized cluster hits
86  * @param KeepDaughtersPDG absolute PDG code of particles where daughter are to be kept (default: gamma,pi0,K0_S)
87  * @param FullRecoRelation Select which option to use for the reconstructed link ( default: full relation)
88  *
89  *
90  * @param TrackMCTruthLinkName name of output collection - default is ""
91  * @param MCTruthTrackLinkName name of output collection - default is ""
92  * @param ClusterMCTruthLinkName name of output collection - default is ""
93  * @param RecoMCTruthLinkName name of output collection - default is ""
94  * @param CalohitMCTruthLinkName name of output collection - default is ""
95  * @param MCParticlesSkimmedName skimmed MCParticle collection - default is ""
96  *
97 
98  * @param UsingParticleGun If Using Particle Gun Ignore Gen Stat - default is false
99 
100  *
101  * @author M. Berggren, DESY, based on RecoMCTruthLinker v 1.0 by F. Gaede, DESY.
102  * changelog F.Gaede, 02/2012 modified logic for optional output collections (collection name not empty) and added mcTruthTrackLink
103  * @version $Id$
104  */
105 
106 class RecoMCTruthLinker : public marlin::Processor {
107 
108 
109  typedef std::set< unsigned > PDGSet ;
110 
111 public:
112 
113  RecoMCTruthLinker(const RecoMCTruthLinker&) = delete;
114  RecoMCTruthLinker& operator=(const RecoMCTruthLinker&) = delete;
115 
116  virtual Processor* newProcessor() { return new RecoMCTruthLinker ; }
117 
118 
120 
121  /** Called at the begin of the job before anything is read.
122  * Use to initialize the processor, e.g. book histograms.
123  */
124  virtual void init() ;
125 
126  /** Called for every run.
127  */
128  virtual void processRunHeader( LCRunHeader* run ) ;
129 
130 
131  /** Called for every event - the working horse.
132  */
133  virtual void processEvent( LCEvent * evt ) ;
134 
135  virtual void trackLinker( LCEvent * evt, LCCollection* mcpCol , LCCollection* trackCol, LCCollection** ttrcol , LCCollection** trtcol ) ;
136  virtual void clusterLinker( LCEvent * evt, LCCollection* mcpCol , LCCollection* clusterCol,
137  LCCollection** ctrcol, LCCollection** trccol,LCCollection** chittrlcol) ;
138  virtual void particleLinker( LCCollection* mcpCol , LCCollection* particleCol ,
139  LCCollection* ttrcol, LCCollection* ctrlcol,
140  LCCollection* trtlcol, LCCollection* trclcol,
141  LCCollection** ptrlcol , LCCollection** trplcol ) ;
142  virtual void linkPrinter ( LCCollection* mcpCol, LCCollection* particleCol, LCCollection* ptrlcol, LCCollection* trplcol) ;
143  virtual void check( LCEvent * evt ) ;
144 
145  virtual void makeSkim( LCCollection* mcpCol , LCCollection* ttrcol, LCCollection* ctrcol ,LCCollectionVec** skimVec) ;
146  /** Called after data processing for clean up.
147  */
148  virtual void end() ;
149 
150 
151 
152 protected:
153 
154  virtual void mergeTrackerHitRelations(LCEvent * evt);
155  virtual void mergeCaloHitRelations(LCEvent * evt);
156 
157  void keepMCParticle( MCParticle* mcp ) ;
158 
159  const LCObjectVec* getSimHits( TrackerHit* trkhit, const FloatVec* weights = NULL);
160  const LCObjectVec* getCaloHits( CalorimeterHit* calohit, const FloatVec* weights = NULL);
161 
162  int getDetectorID(TrackerHit* hit) {
163  static UTIL::BitField64 _encoder = UTIL::BitField64(lcio::LCTrackerCellID::encoding_string());
164  _encoder.setValue(hit->getCellID0());
165  return _encoder[lcio::LCTrackerCellID::subdet()];
166  }
167 
168 
169  /** input collection names */
170 
171  std::string _mcParticleCollectionName{};
172  std::string _trackCollectionName{};
173  std::string _clusterCollectionName{};
174  std::string _recoParticleCollectionName{};
175 
176  StringVec _simTrkHitCollectionNames{};
177  StringVec _simCaloHitCollectionNames{};
178 
179  StringVec _colNamesTrackerHitRelations{};
180  StringVec _caloHitRelationNames{};
181 
182  LCCollectionVec* _mergedTrackerHitRelCol=nullptr;
183  LCRelationNavigator* _navMergedTrackerHitRel=nullptr;
184  LCCollectionVec* _mergedCaloHitRelCol=nullptr;
185  LCRelationNavigator* _navMergedCaloHitRel=nullptr;
186 
187  bool _use_tracker_hit_relations{};
188 
189  /** output collection names */
190  std::string _trackMCTruthLinkName{};
191  std::string _mCTruthTrackLinkName{};
192  std::string _clusterMCTruthLinkName{};
193  std::string _mCTruthClusterLinkName{};
194  std::string _recoMCTruthLinkName{};
195  std::string _mCTruthRecoLinkName{};
196  std::string _mcParticlesSkimmedName{};
197  std::string _calohitMCTruthLinkName{};
198  /** output collection steering */
199  bool _FullRecoRelation{};
200  bool _OutputTrackTruthRelation{};
201  bool _OutputTruthTrackRelation{};
202  bool _OutputClusterTruthRelation{};
203  bool _OutputTruthClusterRelation{};
204  bool _OutputCalohitRelation{};
205  bool _OutputTruthRecoRelation{};
206  float _eCutMeV{};
207  bool _saveBremsstrahlungPhotons{};
208  float _bremsstrahlungEnergyCut{};
209  bool _invertedNonDestructiveInteractionLogic{};
210 
211  bool _using_particle_gun{};
212 
213  IntVec _pdgVec{};
214 
215  int _nRun{};
216  int _nEvt{};
217 
218  PDGSet _pdgSet{};
219 
220 } ;
221 
222 
223 
224 #endif
virtual Processor * newProcessor()
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
Optionally creates four collections of LCRelations (&quot;recoMCTruthLink&quot;, &quot;trackMCTruthLink&quot;, &quot;mcTruthTrackLink&quot;, &quot;clusterMCTruthLink&quot;, &quot;&quot;clusterMCTruthLink&quot; and &quot;calohitMCTruthLink") with weighetd relations between true particles and reconstructed particles, tracks, clusters, and calorimeter hits, respectively.
int getDetectorID(TrackerHit *hit)
std::set< unsigned > PDGSet
std::vector< std::string > StringVec
Definition: SiStripClus.h:56