Belle II Software development
SVDEventT0PerformanceTTreeModule.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
9#include <svd/modules/svdPerformance/SVDEventT0PerformanceTTreeModule.h>
10#include <framework/gearbox/Unit.h>
11#include <framework/core/Environment.h>
12#include <framework/dataobjects/EventMetaData.h>
13#include <svd/dataobjects/SVDShaperDigit.h>
14#include <svd/dataobjects/SVDTrueHit.h>
15#include <svd/dataobjects/SVDEventInfo.h>
16#include <vxd/dataobjects/VxdID.h>
17#include <vxd/geometry/SensorInfoBase.h>
18#include <tracking/dataobjects/RecoTrack.h>
19#include <tracking/dataobjects/RecoHitInformation.h>
20#include <genfit/TrackPoint.h>
21#include <TDirectory.h>
22#include <Math/Boost.h>
23#include <math.h>
24#include <iostream>
25#include <algorithm>
26#include <mdst/dataobjects/Track.h>
27#include <mdst/dataobjects/TrackFitResult.h>
28#include <mdst/dataobjects/MCParticle.h>
29#include <framework/datastore/RelationArray.h>
30
31// Unpackers
32#include <trg/ecl/dataobjects/TRGECLUnpackerStore.h>
33
34// OnlineEventT0
35#include <hlt/dataobjects/OnlineEventT0.h>
36
37using namespace Belle2;
38using namespace std;
39
40
41//-----------------------------------------------------------------
42// Register the Module
43//-----------------------------------------------------------------
44REG_MODULE(SVDEventT0PerformanceTTree);
45
46//-----------------------------------------------------------------
47// Implementation
48//-----------------------------------------------------------------
49
51{
52 //Set module properties
53 setDescription("This module is used to create a TTree to study SVD eventT0 using clusters associated to tracks.");
54 //Parameter to take only specific RecoTracks as input
55 addParam("outputFileName", m_rootFileName, "Name of output root file.", std::string("SVDEventT0PerformanceTTree.root"));
56 addParam("recoTracksStoreArrayName", m_recoTracksStoreArrayName, "StoreArray name of the input and output RecoTracks.",
58}
59
61{
63 recoTracks.isOptional();
65 m_EventT0.isOptional();
66
67 TDirectory::TContext context;
68
69 m_rootFilePtr = new TFile(m_rootFileName.c_str(), "RECREATE");
70
71 //Tree for SVD clusters
72 //one fill per event!
73 m_t = new TTree("tree", "Tree for SVD clusters related to tracks");
74 m_t->Branch("exp", &m_exp, "exp/i");
75 m_t->Branch("run", &m_run, "run/i");
76 m_t->Branch("event", &m_event, "event/i");
77 m_t->Branch("trueEventT0", &m_trueEventT0, "trueEventT0/F");
78 m_t->Branch("eventT0", &m_eventT0, "eventT0/F");
79 m_t->Branch("eventT0Err", &m_eventT0Err, "eventT0Err/F");
80 m_t->Branch("svdEventT0", &m_svdEventT0, "svdEventT0/F");
81 m_t->Branch("svdEventT0Err", &m_svdEventT0Err, "svdEventT0Err/F");
82 m_t->Branch("svdOnlineEventT0", &m_svdOnlineEventT0, "svdOnlineEventT0/F");
83 m_t->Branch("svdOnlineEventT0Err", &m_svdOnlineEventT0Err, "svdOnlineEventT0Err/F");
84 m_t->Branch("cdcEventT0", &m_cdcEventT0, "cdcEventT0/F");
85 m_t->Branch("cdcEventT0Err", &m_cdcEventT0Err, "cdcEventT0Err/F");
86 m_t->Branch("cdcOnlineEventT0", &m_cdcOnlineEventT0, "cdcOnlineEventT0/F");
87 m_t->Branch("cdcOnlineEventT0Err", &m_cdcOnlineEventT0Err, "cdcOnlineEventT0Err/F");
88 m_t->Branch("topEventT0", &m_topEventT0, "topEventT0/F");
89 m_t->Branch("topEventT0Err", &m_topEventT0Err, "topEventT0Err/F");
90 m_t->Branch("topOnlineEventT0", &m_topOnlineEventT0, "topOnlineEventT0/F");
91 m_t->Branch("topOnlineEventT0Err", &m_topOnlineEventT0Err, "topOnlineEventT0Err/F");
92 m_t->Branch("eclEventT0", &m_eclEventT0, "eclEventT0/F");
93 m_t->Branch("eclEventT0Err", &m_eclEventT0Err, "eclEventT0Err/F");
94 m_t->Branch("eclOnlineEventT0", &m_eclOnlineEventT0, "eclOnlineEventT0/F");
95 m_t->Branch("eclOnlineEventT0Err", &m_eclOnlineEventT0Err, "eclOnlineEventT0Err/F");
96 m_t->Branch("eclTCEmax", &m_eclTCEmax, "eclTCEmax/I");
97 m_t->Branch("eclTCid", &m_eclTCid, "eclTCid/I");
98 m_t->Branch("totTracks", &m_nTracks, "totTracks/i");
99 m_t->Branch("TB", &m_svdTB, "TB/i");
100 m_t->Branch("trkNumb", &m_trkNumber);
101 m_t->Branch("trkd0", &m_svdTrkd0);
102 m_t->Branch("trkz0", &m_svdTrkz0);
103 m_t->Branch("trkp", &m_svdTrkp);
104 m_t->Branch("trkpT", &m_svdTrkpT);
105 m_t->Branch("trkpCM", &m_svdTrkpCM);
106 m_t->Branch("trkTheta", &m_svdTrkTheta);
107 m_t->Branch("trkPhi", &m_svdTrkPhi);
108 m_t->Branch("trkCharge", &m_svdTrkCharge);
109 m_t->Branch("trkPValue", &m_svdTrkPValue);
110 m_t->Branch("trkNDF", &m_svdTrkNDF);
111 m_t->Branch("trkPXDHits", &m_svdTrkPXDHits);
112 m_t->Branch("trkSVDHits", &m_svdTrkSVDHits);
113 m_t->Branch("trkCDCHits", &m_svdTrkCDCHits);
114 m_t->Branch("layer", &m_svdLayer);
115 m_t->Branch("ladder", &m_svdLadder);
116 m_t->Branch("sensor", &m_svdSensor);
117 m_t->Branch("clsSize", &m_svdSize);
118 m_t->Branch("clsIsU", &m_svdisUside);
119 m_t->Branch("clsCharge", &m_svdClCharge);
120 m_t->Branch("clsSNR", &m_svdClSNR);
121 m_t->Branch("clsPos", &m_svdClPos);
122 m_t->Branch("clsPosErr", &m_svdClPosErr);
123 m_t->Branch("clsTime", &m_svdClTime);
124 m_t->Branch("clsTimeErr", &m_svdClTimeErr);
125 m_t->Branch("trueTime", &m_svdTrueTime);
126
127
128
129}
130
132{
133 m_trueEventT0 = std::numeric_limits<float>::quiet_NaN();
134 m_eventT0 = std::numeric_limits<float>::quiet_NaN();
135 m_eventT0Err = std::numeric_limits<float>::quiet_NaN();
136 m_svdEventT0 = std::numeric_limits<float>::quiet_NaN();
137 m_svdEventT0Err = std::numeric_limits<float>::quiet_NaN();
138 m_svdOnlineEventT0 = std::numeric_limits<float>::quiet_NaN();
139 m_svdOnlineEventT0Err = std::numeric_limits<float>::quiet_NaN();
140 m_cdcEventT0 = std::numeric_limits<float>::quiet_NaN();
141 m_cdcEventT0Err = std::numeric_limits<float>::quiet_NaN();
142 m_cdcOnlineEventT0 = std::numeric_limits<float>::quiet_NaN();
143 m_cdcOnlineEventT0Err = std::numeric_limits<float>::quiet_NaN();
144 m_topEventT0 = std::numeric_limits<float>::quiet_NaN();
145 m_topEventT0Err = std::numeric_limits<float>::quiet_NaN();
146 m_topOnlineEventT0 = std::numeric_limits<float>::quiet_NaN();
147 m_topOnlineEventT0Err = std::numeric_limits<float>::quiet_NaN();
148 m_eclEventT0 = std::numeric_limits<float>::quiet_NaN();
149 m_eclEventT0Err = std::numeric_limits<float>::quiet_NaN();
150 m_eclOnlineEventT0 = std::numeric_limits<float>::quiet_NaN();
151 m_eclOnlineEventT0Err = std::numeric_limits<float>::quiet_NaN();
152 m_eclTCEmax = std::numeric_limits<int>::quiet_NaN();
153 m_eclTCid = std::numeric_limits<int>::quiet_NaN();
154
155 StoreObjPtr<EventMetaData> evtMetaData;
156 m_exp = evtMetaData->getExperiment();
157 m_run = evtMetaData->getRun();
158 m_event = evtMetaData->getEvent();
159
160 if (m_EventT0.isValid())
161 if (m_EventT0->hasEventT0()) {
162 m_eventT0 = (float)m_EventT0->getEventT0();
163 m_eventT0Err = (float)m_EventT0->getEventT0Uncertainty();
164
165 if (m_EventT0->hasTemporaryEventT0(Const::EDetector::SVD)) {
166 const auto bestSVDEvtT0 = m_EventT0->getBestSVDTemporaryEventT0();
167 m_svdEventT0 = bestSVDEvtT0->eventT0 ;
168 m_svdEventT0Err = bestSVDEvtT0->eventT0Uncertainty;
169 }
170
171 if (m_EventT0->hasTemporaryEventT0(Const::EDetector::CDC)) {
172 const auto bestCDCEvtT0 = m_EventT0->getBestCDCTemporaryEventT0();
173 m_cdcEventT0 = bestCDCEvtT0->eventT0 ;
174 m_cdcEventT0Err = bestCDCEvtT0->eventT0Uncertainty;
175 }
176
177 if (m_EventT0->hasTemporaryEventT0(Const::EDetector::TOP)) {
178 const auto bestTOPEvtT0 = m_EventT0->getBestTOPTemporaryEventT0();
179 m_topEventT0 = bestTOPEvtT0->eventT0 ;
180 m_topEventT0Err = bestTOPEvtT0->eventT0Uncertainty;
181 }
182
183 if (m_EventT0->hasTemporaryEventT0(Const::EDetector::ECL)) {
184 const auto bestECLEvtT0 = m_EventT0->getBestECLTemporaryEventT0();
185 m_eclEventT0 = bestECLEvtT0->eventT0 ;
186 m_eclEventT0Err = bestECLEvtT0->eventT0Uncertainty;
187 }
188 }
189
190 StoreArray<OnlineEventT0> onlineEventT0;
191 for (auto& evt : onlineEventT0) {
192 if (evt.getOnlineEventT0Detector() == Const::EDetector::SVD) {
193 B2DEBUG(40, "OnlineEventT0 given by SVD");
194 m_svdOnlineEventT0 = evt.getOnlineEventT0();
195 m_svdOnlineEventT0Err = evt.getOnlineEventT0Uncertainty();
196 }
197
198 if (evt.getOnlineEventT0Detector() == Const::EDetector::CDC) {
199 B2DEBUG(40, "OnlineEventT0 given by CDC");
200 m_cdcOnlineEventT0 = evt.getOnlineEventT0();
201 m_cdcOnlineEventT0Err = evt.getOnlineEventT0Uncertainty();
202 }
203
204 if (evt.getOnlineEventT0Detector() == Const::EDetector::ECL) {
205 B2DEBUG(40, "OnlineEventT0 given by ECL");
206 m_eclOnlineEventT0 = evt.getOnlineEventT0();
207 m_eclOnlineEventT0Err = evt.getOnlineEventT0Uncertainty();
208 }
209
210 if (evt.getOnlineEventT0Detector() == Const::EDetector::TOP) {
211 B2DEBUG(40, "OnlineEventT0 given by TOP");
212 m_topOnlineEventT0 = evt.getOnlineEventT0();
213 m_topOnlineEventT0Err = evt.getOnlineEventT0Uncertainty();
214 }
215 }
216
217
218 // clear all vectors
219 m_trkNumber.clear();
220 m_svdisUside.clear();
221 m_svdSize.clear();
222 m_svdSensor.clear();
223 m_svdLadder.clear();
224 m_svdLadder.clear();
225 m_svdTrkPhi.clear();
226 m_svdTrkTheta.clear();
227 m_svdTrkpCM.clear();
228 m_svdTrkp.clear();
229 m_svdTrkpT.clear();
230 m_svdTrkz0.clear();
231 m_svdTrkd0.clear();
232 m_svdTrkPValue.clear();
233 m_svdTrkCharge.clear();
234 m_svdTrkNDF.clear();
235 m_svdTrkCDCHits.clear();
236 m_svdTrkSVDHits.clear();
237 m_svdTrkPXDHits.clear();
238 m_svdTrueTime.clear();
239 m_svdClPosErr.clear();
240 m_svdClPos.clear();
241 m_svdClTimeErr.clear();
242 m_svdClTime.clear();
243 m_svdClSNR.clear();
244 m_svdClCharge.clear();
245
246
247 //first check SVDEventInfo name
248 StoreObjPtr<SVDEventInfo> temp_eventinfo("SVDEventInfo");
249 std::string m_svdEventInfoName = "SVDEventInfo";
250 if (!temp_eventinfo.isValid())
251 m_svdEventInfoName = "SVDEventInfoSim";
252 StoreObjPtr<SVDEventInfo> eventinfo(m_svdEventInfoName);
253 if (!eventinfo) B2ERROR("No SVDEventInfo!");
254 m_svdTB = eventinfo->getModeByte().getTriggerBin();
255
256 bool isMC = Environment::Instance().isMC();
257
258 int trkNumber = 0;
260 m_nTracks = recoTracks.getEntries();
261 for (const auto& trk : recoTracks) {
262 if (! trk.wasFitSuccessful()) {
263 m_nTracks -= 1;
264 continue;
265 }
266
267
268 RelationVector<Track> theTK = DataStore::getRelationsWithObj<Track>(&trk);
269
270 if (theTK.size() == 0) {
271 m_nTracks -= 1;
272 continue;
273 }
274
275 trkNumber ++;
276
277 const vector<SVDCluster* > svdClusters = trk.getSVDHitList();
278 B2DEBUG(40, "FITTED TRACK: NUMBER OF SVD HITS = " << svdClusters.size());
279
280 for (unsigned int i = 0; i < svdClusters.size(); i++) {
281
282 const TrackFitResult* tfr = theTK[0]->getTrackFitResultWithClosestMass(Const::pion);
283
284 if (tfr) {
285 m_svdTrkTheta.push_back(tfr->getMomentum().Theta());
286 m_svdTrkPhi.push_back(tfr->getMomentum().Phi());
287 m_svdTrkd0.push_back(tfr->getD0());
288 m_svdTrkz0.push_back(tfr->getZ0());
289 m_svdTrkp.push_back(tfr->getMomentum().R());
290 m_svdTrkpT.push_back(tfr->getMomentum().Rho());
291 m_svdTrkPValue.push_back(tfr->getPValue());
292 m_svdTrkCharge.push_back(tfr->getChargeSign());
293 m_svdTrkNDF.push_back(tfr->getNDF());
294 ROOT::Math::PxPyPzEVector pStar = tfr->get4Momentum();
295 ROOT::Math::BoostZ boost(3. / 11);
296 pStar = boost(pStar);
297 m_svdTrkpCM.push_back(pStar.P());
298 }
299
300
301
302 m_svdTrkPXDHits.push_back((trk.getPXDHitList()).size());
303 m_svdTrkSVDHits.push_back((trk.getSVDHitList()).size());
304 m_svdTrkCDCHits.push_back((trk.getCDCHitList()).size());
305 m_trkNumber.push_back(trkNumber);
306
307 const SVDCluster* svd_1 = svdClusters[i];
308
309 //get true hits, used only if isMC
310 RelationVector<SVDTrueHit> trueHit_1 = DataStore::getRelationsWithObj<SVDTrueHit>(svd_1);
311
312
313
314
315 const RecoHitInformation* infoSVD_1 = trk.getRecoHitInformation(svd_1);
316 if (!infoSVD_1) {
317 continue;
318 }
319
320 const VxdID svd_id_1 = svd_1->getSensorID();
321 m_svdLayer.push_back(svd_id_1.getLayerNumber());
322 m_svdLadder.push_back(svd_id_1.getLadderNumber());
323 m_svdSensor.push_back(svd_id_1.getSensorNumber());
324
325 m_svdisUside.push_back(svd_1->isUCluster());
326
327 m_svdSize.push_back(svd_1->getSize());
328
329 m_svdClTime.push_back(svd_1->getClsTime());
330 m_svdClTimeErr.push_back(svd_1->getClsTimeSigma());
331 m_svdClSNR.push_back(svd_1->getSNR());
332 m_svdClCharge.push_back(svd_1->getCharge());
333 m_svdClPos.push_back(svd_1->getPosition());
334 m_svdClPosErr.push_back(svd_1->getPositionSigma());
335 if (isMC && trueHit_1.size() > 0) {
336
337 m_svdTrueTime.push_back(trueHit_1[0]->getGlobalTime());
338
339 RelationVector<MCParticle> mcParticle_1 = trueHit_1[0]->getRelationsFrom<MCParticle>();
340 if (mcParticle_1.size() > 0) {
341 if (mcParticle_1[0]->isPrimaryParticle())
342 m_trueEventT0 = mcParticle_1[0]->getProductionTime();
343 }
344 } else
345 m_svdTrueTime.push_back(std::numeric_limits<float>::quiet_NaN());
346 }
347 }
348
350 for (const auto& trgHit : TRGECLData) {
351 int hitWin = trgHit.getHitWin();
352 B2DEBUG(40, "hitWin = " << hitWin);
353 if (hitWin != 3 && hitWin != 4) { continue; }
354 if (trgHit.getTCEnergy() > m_eclTCEmax) {
355 m_eclTCid = trgHit.getTCId();
356 m_eclTCEmax = trgHit.getTCEnergy();
357 }
358 }
359
360 m_t->Fill();
361
362}
363
364
366{
367
368 if (m_rootFilePtr != nullptr) {
369
370 TDirectory::TContext context;
371
372 m_rootFilePtr->cd();
373 m_t->Write();
374 m_rootFilePtr->Close();
375 }
376}
static const ChargedStable pion
charged pion particle
Definition: Const.h:661
bool isMC() const
Do we have generated, not real data?
Definition: Environment.cc:54
static Environment & Instance()
Static method to get a reference to the Environment instance.
Definition: Environment.cc:28
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:32
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
This class stores additional information to every CDC/SVD/PXD hit stored in a RecoTrack.
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:29
float getClsTime() const
Get average of waveform maximum times of cluster strip signals.
Definition: SVDCluster.h:134
float getSNR() const
Get cluster SNR.
Definition: SVDCluster.h:159
unsigned short getSize() const
Get cluster size.
Definition: SVDCluster.h:154
float getCharge() const
Get collected charge.
Definition: SVDCluster.h:144
VxdID getSensorID() const
Get the sensor ID.
Definition: SVDCluster.h:102
bool isUCluster() const
Get the direction of strips.
Definition: SVDCluster.h:110
float getPosition(double v=0) const
Get the coordinate of reconstructed hit.
Definition: SVDCluster.h:117
float getClsTimeSigma() const
Get the error of the reconstructed hit time.
Definition: SVDCluster.h:139
float getPositionSigma() const
Get the error of the reconstructed hit coordinate.
Definition: SVDCluster.h:129
std::vector< float > m_svdTrkTheta
polar angle of the track
std::vector< float > m_svdTrkPValue
pValue of the track
std::vector< float > m_svdTrkCharge
charge of the track
std::vector< float > m_svdClPosErr
cluster position error
std::vector< int > m_svdTrkSVDHits
number of SVD hits on the track
void initialize() override
Register input and output data.
std::vector< float > m_svdTrkPhi
azimuthal angle of the track
void event() override
Compute the variables and fill the tree.
std::vector< int > m_svdTrkPXDHits
number of PXD hits on the track
void terminate() override
Write the TTree to the file.
std::vector< float > m_svdTrkpCM
pCM of the track
std::vector< float > m_svdTrkNDF
pValue of the track
std::vector< int > m_svdTrkCDCHits
number of CDC hits on the track
std::vector< float > m_svdClTimeErr
cluster time error
TTree * m_t
tree containing info related to the clusters related to tracks
std::string m_recoTracksStoreArrayName
storeArray name of the input and output RecoTracks
TFile * m_rootFilePtr
pointer at root file used for storing histograms
std::vector< int > m_trkNumber
track number in the event
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.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
Values of the result of a track fit with a given particle hypothesis.
float getNDF() const
Getter for number of degrees of freedom of the track fit.
short getChargeSign() const
Return track charge (1 or -1).
double getPValue() const
Getter for Chi2 Probability of the track fit.
ROOT::Math::PxPyPzEVector get4Momentum() const
Getter for the 4Momentum at the closest approach of the track in the r/phi projection.
double getD0() const
Getter for d0.
double getZ0() const
Getter for z0.
ROOT::Math::XYZVector getMomentum() const
Getter for vector of momentum at closest approach of track in r/phi projection.
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:33
baseType getSensorNumber() const
Get the sensor id.
Definition: VxdID.h:100
baseType getLadderNumber() const
Get the ladder id.
Definition: VxdID.h:98
baseType getLayerNumber() const
Get the layer id.
Definition: VxdID.h:96
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#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.
STL namespace.