Belle II Software  release-06-01-15
ARICHReconstructorModule.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 // Own include
9 
10 #include <arich/modules/arichReconstruction/ARICHReconstructorModule.h>
11 #include <time.h>
12 
13 // Hit classes
14 #include <mdst/dataobjects/Track.h>
15 #include <tracking/dataobjects/ExtHit.h>
16 #include <mdst/dataobjects/MCParticle.h>
17 #include <arich/dataobjects/ARICHAeroHit.h>
18 #include <arich/dataobjects/ARICHLikelihood.h>
19 #include <arich/dataobjects/ARICHTrack.h>
20 #include <arich/dataobjects/ARICHHit.h>
21 
22 // framework - DataStore
23 #include <framework/datastore/DataStore.h>
24 #include <framework/datastore/StoreArray.h>
25 
26 // framework aux
27 #include <framework/gearbox/Unit.h>
28 #include <framework/gearbox/Const.h>
29 #include <framework/logging/Logger.h>
30 
31 // ROOT
32 #include <TVector3.h>
33 
34 using namespace std;
35 using namespace boost;
36 
37 namespace Belle2 {
43 //-----------------------------------------------------------------
44 // Register the Module
45 //-----------------------------------------------------------------
46  REG_MODULE(ARICHReconstructor)
47 
48 
49 //-----------------------------------------------------------------
50 // Implementation
51 //-----------------------------------------------------------------
52 
54  m_ana(NULL)
55  {
56  // Set description()
57  setDescription("This module calculates the ARICHLikelihood values for all particle id. hypotheses, for all tracks that enter ARICH in the event.");
58 
59  // Set property flags
60  setPropertyFlags(c_ParallelProcessingCertified);
61 
62  // Add parameters
63  addParam("trackPositionResolution", m_trackPositionResolution,
64  "Resolution of track position on aerogel plane (for additional smearing of MC tracks)", 1.0 * Unit::mm);
65  addParam("trackAngleResolution", m_trackAngleResolution,
66  "Resolution of track direction angle on aerogel plane (for additional smearing of MC tracks)", 2.0 * Unit::mrad);
67  addParam("inputTrackType", m_inputTrackType, "Input tracks switch: tracking (0), from AeroHits - MC info (1)", 0);
68  addParam("storePhotons", m_storePhot, "Set to 1 to store reconstructed photon information (Ch. angle,...)", 0);
69  addParam("useAlignment", m_align, "Use ARICH global position alignment constants", true);
70  addParam("useMirrorAlignment", m_alignMirrors, "Use ARICH mirror alignment constants", true);
71  }
72 
73  ARICHReconstructorModule::~ARICHReconstructorModule()
74  {
75  if (m_ana) delete m_ana;
76  }
77 
78  void ARICHReconstructorModule::initialize()
79  {
80  // Initialize variables
81  if (m_ana) delete m_ana;
82  m_ana = new ARICHReconstruction(m_storePhot);
83  m_ana->setTrackPositionResolution(m_trackPositionResolution);
84  m_ana->setTrackAngleResolution(m_trackAngleResolution);
85  m_ana->useMirrorAlignment(m_alignMirrors);
86 
87  StoreArray<ARICHHit> arichHits;
88  arichHits.isRequired();
89 
90  StoreArray<Track> tracks;
91  StoreArray<ExtHit> extHits;
92  StoreArray<ARICHAeroHit> aeroHits;
93  tracks.isOptional();
94  extHits.isOptional();
95  aeroHits.isOptional();
96 
97  if (!aeroHits.isOptional()) {
98  tracks.isRequired();
99  extHits.isRequired();
100  }
101 
102  StoreArray<MCParticle> mcParticles;
103  mcParticles.isOptional();
104 
105  StoreArray<ARICHLikelihood> likelihoods;
106  likelihoods.registerInDataStore();
107 
108  StoreArray<ARICHTrack> arichTracks;
109  arichTracks.registerInDataStore();
110 
111  if (m_inputTrackType) arichTracks.registerRelationTo(likelihoods);
112  else {
113  arichTracks.registerRelationTo(extHits);
114  tracks.registerRelationTo(likelihoods);
115  }
116  //arichTracks.registerInDataStore(DataStore::c_DontWriteOut);
117  //arichTracks.registerRelationTo(likelihoods, DataStore::c_Event, DataStore::c_DontWriteOut);
118  arichTracks.registerRelationTo(aeroHits);
119  printModuleParams();
120  }
121 
122  void ARICHReconstructorModule::beginRun()
123  {
124  m_ana->initialize();
125  }
126 
127  void ARICHReconstructorModule::event()
128  {
129 
130  // Output - log likelihoods
131  StoreArray<ARICHLikelihood> arichLikelihoods;
132 
133  // input AeroHits
134  StoreArray<ARICHTrack> arichTracks;
135 
136  // Input: ARICHDigits
137  StoreArray<ARICHHit> arichHits;
138 
139  // using track information form tracking system (mdst Track)
140  if (m_inputTrackType == 0) {
141 
142  StoreArray<Track> Tracks;
143 
144  Const::EDetector myDetID = Const::EDetector::ARICH; // arich
145  Const::ChargedStable hypothesis = Const::pion;
146  int pdgCode = abs(hypothesis.getPDGCode());
147 
148  for (int itrk = 0; itrk < Tracks.getEntries(); ++itrk) {
149 
150  const Track* track = Tracks[itrk];
151  const TrackFitResult* fitResult = track->getTrackFitResultWithClosestMass(hypothesis);
152  if (!fitResult) {
153  B2ERROR("No TrackFitResult for " << hypothesis.getPDGCode());
154  continue;
155  }
156 
157  const MCParticle* particle = track->getRelated<MCParticle>();
158 
159  ARICHAeroHit* aeroHit = NULL;
160  if (particle) aeroHit = particle->getRelated<ARICHAeroHit>();
161 
162  RelationVector<ExtHit> extHits = DataStore::getRelationsWithObj<ExtHit>(track);
163  ARICHTrack* arichTrack = NULL;
164 
165  //const ExtHit* arich1stHit = NULL;
166  const ExtHit* arich2ndHit = NULL;
167  const ExtHit* arichWinHit = NULL;
168 
169  for (unsigned i = 0; i < extHits.size(); i++) {
170  const ExtHit* extHit = extHits[i];
171  if (abs(extHit->getPdgCode()) != pdgCode) continue;
172  if (extHit->getDetectorID() != myDetID) continue;
173  if (extHit->getStatus() != EXT_EXIT) continue; // particles registered at the EXIT of the Al plate
174  if (extHit->getMomentum().Z() < 0.0) continue; // track passes in backward
175  if (extHit->getCopyID() == 12345) { continue;}
176  if (extHit->getCopyID() == 6789) { arich2ndHit = extHit; continue;}
177  arichWinHit = extHit;
178  }
179 
180  if (arich2ndHit) {
181  // if aeroHit cannot be found using MCParticle check if it was already related to the extHit (by ARICHRelate module)
182  if (!aeroHit) aeroHit = arich2ndHit->getRelated<ARICHAeroHit>();
183 
184  // make new ARICHTrack
185  arichTrack = arichTracks.appendNew(arich2ndHit);
186  if (arichWinHit) arichTrack->setHapdWindowHit(arichWinHit);
187  }
188 
189  // skip if track has no extHit in ARICH
190  if (!arichTrack) continue;
191  // transform track parameters to ARICH local frame
192  m_ana->transformTrackToLocal(*arichTrack, m_align);
193  // make new ARICHLikelihood
194  ARICHLikelihood* like = arichLikelihoods.appendNew();
195  // calculate and set likelihood values
196  m_ana->likelihood2(*arichTrack, arichHits, *like);
197  // make relations
198  track->addRelationTo(like);
199  arichTrack->addRelationTo(arich2ndHit);
200  if (aeroHit) arichTrack->addRelationTo(aeroHit);
201 
202  } // Tracks loop
203  } // input type if
204 
205 
206  // using track information form MC (stored in ARICHAeroHit)
207  else {
208 
209  StoreArray<ARICHAeroHit> aeroHits;
210  int nTracks = aeroHits.getEntries();
211 
212  // Loop over all ARICHAeroHits
213  for (int iTrack = 0; iTrack < nTracks; ++iTrack) {
214  ARICHAeroHit* aeroHit = aeroHits[iTrack];
215 
216  // make new ARICHTrack
217  ARICHTrack* arichTrack = arichTracks.appendNew(aeroHit);
218  // smearing of track parameters (to mimic tracking system resolutions)
219  m_ana->smearTrack(*arichTrack);
220  // transform track parameters to ARICH local frame
221  m_ana->transformTrackToLocal(*arichTrack, m_align);
222  // make associated ARICHLikelihood
223  ARICHLikelihood* like = arichLikelihoods.appendNew();
224  // calculate and set likelihood values
225  m_ana->likelihood2(*arichTrack, arichHits, *like);
226  // make relation
227  arichTrack->addRelationTo(like);
228  arichTrack->addRelationTo(aeroHit);
229  } // for iTrack
230 
231  }
232  }
233 
234  void ARICHReconstructorModule::endRun()
235  {
236  }
237 
238  void ARICHReconstructorModule::terminate()
239  {
240  }
241 
242  void ARICHReconstructorModule::printModuleParams()
243  {
244  if (m_inputTrackType == 0) { B2DEBUG(100, "ARICHReconstructorModule: track infromation is taken from mdst Tracks.");}
245  else B2DEBUG(100, "ARICHReconstructorModule: track information is taken from MC (ARICHAeroHit).");
246  }
247 
249 } // namespace Belle2
Datastore class that holds information on track parameters at the entrance in aerogel.
Definition: ARICHAeroHit.h:27
This is a class to store ARICH likelihoods in the datastore.
Internal ARICH track reconstruction.
ARICH subdetector main module.
Datastore class that holds position and momentum information of tracks that hit ARICH.
Definition: ARICHTrack.h:32
Provides a type-safe way to pass members of the chargedStableSet set.
Definition: Const.h:470
int getPDGCode() const
PDG code.
Definition: Const.h:354
EDetector
Enum for identifying the detector components (detector and subdetector).
Definition: Const.h:42
Store one Ext hit as a ROOT object.
Definition: ExtHit.h:30
int getPdgCode() const
Get PDG code of this extrapolation's hypothesis.
Definition: ExtHit.h:116
ExtHitStatus getStatus() const
Get state of extrapolation at this hit.
Definition: ExtHit.h:128
TVector3 getMomentum() const
Get momentum at this extrapolation hit.
Definition: ExtHit.h:147
int getCopyID() const
Get detector-element ID of sensitive element within detector.
Definition: ExtHit.h:124
Const::EDetector getDetectorID() const
Get detector ID of this extrapolation hit.
Definition: ExtHit.h:120
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Class for type safe access to objects that are referred to in relations.
void addRelationTo(const RelationsInterface< BASE > *object, float weight=1.0, const std::string &namedRelation="") const
Add a relation from this object to another object (with caching).
T * getRelated(const std::string &name="", const std::string &namedRelation="") const
Get the object to or from which this object has a relation.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool isOptional(const std::string &name="")
Tell the DataStore about an optional input.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
T * appendNew()
Construct a new T object at the end of the array.
Definition: StoreArray.h:246
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
bool registerRelationTo(const StoreArray< TO > &toArray, DataStore::EDurability durability=DataStore::c_Event, DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut, const std::string &namedRelation="") const
Register a relation to the given StoreArray.
Definition: StoreArray.h:140
Values of the result of a track fit with a given particle hypothesis.
Class that bundles various TrackFitResults.
Definition: Track.h:25
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.