Belle II Software  release-05-02-19
DATCONSVDSimpleClusterizerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Giulia Casarosa *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <tracking/modules/DATCON/DATCONSVDSimpleClusterizerModule.h>
12 
13 #include <svd/geometry/SensorInfo.h>
14 
15 using namespace std;
16 using namespace Belle2;
17 
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(DATCONSVDSimpleClusterizer)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
29 {
30  //Set module properties
31  setDescription("Clusterize DATCONSVDDigits");
32  setPropertyFlags(c_ParallelProcessingCertified);
33 
34  // 1. Collections.
35  addParam("DATCONSVDDigits", m_storeDATCONSVDDigitsListName,
36  "DATCONSVDDigits collection name", string("DATCONSVDDigits"));
37  addParam("DATCONSVDCluster", m_storeDATCONSVDClustersName,
38  "DATCONSVDCluster collection name", string("DATCONSVDCluster"));
39  addParam("SVDTrueHits", m_storeTrueHitsName,
40  "TrueHit collection name", string(""));
41  addParam("MCParticles", m_storeMCParticlesName,
42  "MCParticles collection name", string(""));
43 
44  // 2. Clustering
45  addParam("NoiseLevelADU", m_NoiseLevelInADU,
46  "Simple assumption of the noise level of the sensors in ADU's", (unsigned short)(5));
47  addParam("NoiseCutADU", m_NoiseCutInADU,
48  "Simple assumption of the noise level of the sensors in ADU's", (unsigned short)(5));
49  addParam("useSimpleClustering", m_useSimpleClustering,
50  "Use the simple clustering that is currently done on FPGA for phase 2", bool(true));
51  addParam("maxClusterSize", m_maxClusterSize,
52  "Maximum cluster size in count of strips.", (unsigned short)(6));
53 
54 }
55 
56 
57 void DATCONSVDSimpleClusterizerModule::initialize()
58 {
59  //Register collections
60  storeDATCONSVDCluster.registerInDataStore(m_storeDATCONSVDClustersName, DataStore::c_DontWriteOut);
61  m_storeDATCONSVDClustersName = storeDATCONSVDCluster.getName();
62 
63  storeDATCONSVDDigits.isRequired(m_storeDATCONSVDDigitsListName);
64  m_storeDATCONSVDDigitsListName = storeDATCONSVDDigits.getName();
65 
66  storeDATCONSVDCluster.registerRelationTo(storeDATCONSVDDigits, DataStore::c_Event, DataStore::c_DontWriteOut);
67 
68  storeTrueHits.isOptional(m_storeTrueHitsName);
69  if (storeTrueHits.isValid()) {
70  m_storeTrueHitsName = storeTrueHits.getName();
71  storeDATCONSVDCluster.registerRelationTo(storeTrueHits, DataStore::c_Event, DataStore::c_DontWriteOut);
72  }
73 
74  storeMCParticles.isOptional(m_storeMCParticlesName);
75  if (storeMCParticles.isValid()) {
76  m_storeMCParticlesName = storeMCParticles.getName();
77  storeDATCONSVDCluster.registerRelationTo(storeMCParticles, DataStore::c_Event, DataStore::c_DontWriteOut);
78  }
79 
80 }
81 
82 
83 
84 void DATCONSVDSimpleClusterizerModule::event()
85 {
86  int nDigits = storeDATCONSVDDigits.getEntries();
87  if (nDigits == 0)
88  return;
89 
90  storeDATCONSVDCluster.clear();
91  clusterCandidates.clear();
92 
93  //create a dummy cluster just to start
94  DATCONSVDSimpleClusterCandidate clusterCandidate(storeDATCONSVDDigits[0]->getSensorID(), storeDATCONSVDDigits[0]->isUStrip(),
95  m_maxClusterSize);
96 
97  unsigned short digitindex = 0;
98 
99  //loop over the DATCONSVDDigits
100  for (auto& datconsvddigit : storeDATCONSVDDigits) {
101 
102  if (!noiseFilter(datconsvddigit)) {
103  digitindex++;
104  continue;
105  }
106 
107 
108  //retrieve the VxdID, sensor and cellID of the current DATCONSVDDigit
109  VxdID thisSensorID = datconsvddigit.getSensorID();
110  bool thisSide = datconsvddigit.isUStrip();
111  unsigned short thisCellID = datconsvddigit.getCellID();
112  unsigned short thisCharge = datconsvddigit.getMaxSampleCharge();
113 
114  //try to add the strip to the existing cluster
115  if (! clusterCandidate.add(thisSensorID, thisSide, digitindex, thisCharge, thisCellID)) {
116  //if the strip is not added, write the cluster, if present and good:
117  if (clusterCandidate.size() > 0) {
118  if (m_useSimpleClustering) {
119  clusterCandidate.finalizeSimpleCluster();
120  } else {
121  B2WARNING("This one is not yet implemented, so no DATCONSVDCluster will be created! Skipping...");
122  }
123  if (clusterCandidate.isGoodCluster()) {
124  clusterCandidates.push_back(clusterCandidate);
125  }
126  }
127 
128  //prepare for the next cluster:
129  clusterCandidate = DATCONSVDSimpleClusterCandidate(thisSensorID, thisSide, m_maxClusterSize);
130 
131  //start another cluster:
132  if (! clusterCandidate.add(thisSensorID, thisSide, digitindex, thisCharge, thisCellID))
133  B2WARNING("this state is forbidden!!");
134  }
135  digitindex++;
136  } //exit loop on ShaperDigits
137 
138  //write the last cluster, if good
139  if (clusterCandidate.size() > 0) {
140  if (m_useSimpleClustering) {
141  clusterCandidate.finalizeSimpleCluster();
142  } else {
143  B2WARNING("This one is not yet implemented, so no DATCONSVDCluster will be created! Skipping...");
144  }
145  if (clusterCandidate.isGoodCluster())
146  clusterCandidates.push_back(clusterCandidate);
147  }
148 
149  saveClusters();
150 
151  B2DEBUG(1, "Number of clusters: " << storeDATCONSVDCluster.getEntries());
152 }
153 
154 
155 void DATCONSVDSimpleClusterizerModule::saveClusters()
156 {
157 
158  for (auto clustercandit = clusterCandidates.begin(); clustercandit != clusterCandidates.end(); clustercandit++) {
159 
160  DATCONSVDSimpleClusterCandidate clustercand = *clustercandit;
161 
162  VxdID sensorID = clustercand.getSensorID();
163  bool isU = clustercand.isUSide();
164  float clusterPosition = clustercand.getPosition();
165  unsigned short clusterSeedCharge = clustercand.getSeedCharge();
166  unsigned short clusterCharge = clustercand.getCharge();
167  unsigned short clusterSize = clustercand.size();
168  float pitch;
169  float clusterPositionError = 0;
170 
171  const SVD::SensorInfo* aSensorInfo = dynamic_cast<const SVD::SensorInfo*>(&VXD::GeoCache::get(sensorID));
172 
173  if (isU) {
174  pitch = aSensorInfo->getUPitch();
175  } else {
176  pitch = aSensorInfo->getVPitch();
177  }
178 
179  if (clusterSize == 1) {
180  clusterPositionError = pitch / sqrt(12.);
181  } else if (clusterSize == 2) {
182  clusterPositionError = pitch / 2.;
183  } else if (clusterSize > 2) {
184  clusterPositionError = pitch;
185  }
186 
187  SVDCluster* datconSVDCluster =
188  storeDATCONSVDCluster.appendNew(SVDCluster(sensorID, isU, clusterPosition, clusterPositionError,
189  0.0, 0.0, clusterCharge, clusterSeedCharge, clusterSize, 0.0, 0.0));
190 
191  vector<unsigned short> indices = clustercand.getIndexVector();
192 
193  for (auto digitindexit = indices.begin(); digitindexit != indices.end(); digitindexit++) {
194 
195  DATCONSVDDigit* datconsvddigit = storeDATCONSVDDigits[*digitindexit];
196  RelationVector<MCParticle> relatedMC = datconsvddigit->getRelationsTo<MCParticle>();
197  RelationVector<SVDTrueHit> relatedSVDTrue = datconsvddigit->getRelationsTo<SVDTrueHit>();
198 
199  // Register relation to the DATCONSVDDigits this cluster belongs to
200  datconSVDCluster->addRelationTo(datconsvddigit);
201 
202  // Register relations to the MCParticles and SVDTrueHits
203  if (relatedMC.size() > 0) {
204  for (unsigned int relmcindex = 0; relmcindex < relatedMC.size(); relmcindex++) {
205  datconSVDCluster->addRelationTo(relatedMC[relmcindex], relatedMC.weight(relmcindex));
206  }
207  }
208  if (relatedSVDTrue.size() > 0) {
209  for (unsigned int reltruehitindex = 0; reltruehitindex < relatedSVDTrue.size(); reltruehitindex++) {
210  datconSVDCluster->addRelationTo(relatedSVDTrue[reltruehitindex], relatedSVDTrue.weight(reltruehitindex));
211  }
212  }
213  }
214  }
215 }
216 
217 /*
218 * Simple noise filter.
219 * Run the noise filter over the given numbers of samples.
220 * If it fulfills the requirements true is returned.
221 * TODO: Improve!!!
222 */
223 bool DATCONSVDSimpleClusterizerModule::noiseFilter(DATCONSVDDigit datconsvddigit)
224 {
225  bool passNoiseFilter = false;
226  unsigned short maxSampleIndex = datconsvddigit.getMaxSampleIndex();
227  DATCONSVDDigit::APVRawSamples sample = datconsvddigit.getRawSamples();
228 // unsigned short noiseCut = sample[maxSampleIndex] / 2; // the initial idea was to declare a strip signal as noise if the samples neighbouring the maximum samle (i.e. maxSampleIndex-1 and maxSampleIndex+1) had a charge (in ADU) of less then getMaxSampleCharge / 2
229  unsigned short noiseCut = m_NoiseCutInADU; //sample[maxSampleIndex] / 8;
230 
231  if (sample[maxSampleIndex] <= m_NoiseLevelInADU /*|| noiseCut < m_NoiseLevelInADU*/) {
232  return false;
233  }
234 
235  /* The maximum sample is expected to be 2nd or 3rd, so maybe change the conditions
236  * in the if-clause accordingly to maxSampleIndex > 1 && maxSampleIndex < 4
237  */
238  if (maxSampleIndex > 0 && maxSampleIndex < (sample.size() - 1)) {
239  if (sample[maxSampleIndex - 1] >= noiseCut && sample[maxSampleIndex + 1] >= noiseCut) {
240  passNoiseFilter = true;
241  }
242  }
243 
244  return passNoiseFilter;
245 }
Belle2::RelationVector::size
size_t size() const
Get number of relations.
Definition: RelationVector.h:98
Belle2::VxdID
Class to uniquely identify a any structure of the PXD and SVD.
Definition: VxdID.h:43
Belle2::DATCONSVDDigit::getRawSamples
APVRawSamples getRawSamples() const
Get int-array of of 6 APV25 samples.
Definition: DATCONSVDDigit.h:123
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::DATCONSVDSimpleClusterCandidate::isGoodCluster
bool isGoodCluster()
return true if the cluster candidate can be promoted to cluster
Definition: DATCONSVDSimpleClusterCandidate.cc:103
Belle2::DATCONSVDDigit::APVRawSamples
std::array< APVRawSampleType, c_nAPVSamples > APVRawSamples
Type for array of samples received from DAQ.
Definition: DATCONSVDDigit.h:54
Belle2::SVDTrueHit
Class SVDTrueHit - Records of tracks that either enter or leave the sensitive volume.
Definition: SVDTrueHit.h:35
Belle2::RelationsInterface::addRelationTo
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).
Definition: RelationsObject.h:144
Belle2::DATCONSVDSimpleClusterCandidate::getSeedCharge
unsigned short getSeedCharge() const
Return the seed charge of the cluster.
Definition: DATCONSVDSimpleClusterCandidate.h:93
Belle2::SVD::SensorInfo
Specific implementation of SensorInfo for SVD Sensors which provides additional sensor specific infor...
Definition: SensorInfo.h:35
Belle2::RelationsInterface::getRelationsTo
RelationVector< TO > getRelationsTo(const std::string &name="", const std::string &namedRelation="") const
Get the relations that point from this object to another store array.
Definition: RelationsObject.h:199
Belle2::DATCONSVDSimpleClusterCandidate::getSensorID
VxdID getSensorID()
return the VxdID of the cluster sensor
Definition: DATCONSVDSimpleClusterCandidate.h:76
Belle2::VXD::SensorInfoBase::getVPitch
double getVPitch(double v=0) const
Return the pitch of the sensor.
Definition: SensorInfoBase.h:150
Belle2::DATCONSVDDigit
The DATCONSVDDigit class.
Definition: DATCONSVDDigit.h:44
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::RelationVector
Class for type safe access to objects that are referred to in relations.
Definition: DataStore.h:38
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DATCONSVDSimpleClusterCandidate::size
unsigned short size() const
Return the cluster size (number of strips of the cluster).
Definition: DATCONSVDSimpleClusterCandidate.h:106
Belle2::DATCONSVDSimpleClusterCandidate::getIndexVector
std::vector< unsigned short > getIndexVector() const
Get vector of indices of the DATCONSVDDigits in the DATCONSVDDigit StoreArray.
Definition: DATCONSVDSimpleClusterCandidate.h:115
Belle2::DATCONSVDSimpleClusterCandidate
Class representing a cluster candidate for DATCON during simple clustering of the SVD.
Definition: DATCONSVDSimpleClusterCandidate.h:33
Belle2::DATCONSVDSimpleClusterCandidate::isUSide
bool isUSide()
return true if the cluster is on the U/P side
Definition: DATCONSVDSimpleClusterCandidate.h:81
Belle2::DATCONSVDSimpleClusterizerModule
DATCONSVDSimpleClusterizerModule: This class performs a simple clusterisation and noise filtering of ...
Definition: DATCONSVDSimpleClusterizerModule.h:48
Belle2::DATCONSVDSimpleClusterCandidate::finalizeSimpleCluster
void finalizeSimpleCluster()
compute the simple cluster position as in phase 2 FPGA implementation
Definition: DATCONSVDSimpleClusterCandidate.cc:79
Belle2::VXD::SensorInfoBase::getUPitch
double getUPitch(double v=0) const
Return the pitch of the sensor.
Definition: SensorInfoBase.h:143
Belle2::DATCONSVDDigit::getMaxSampleIndex
unsigned short getMaxSampleIndex()
Getter for the index of the biggest sample inside the cluster (0...6)
Definition: DATCONSVDDigit.h:155
Belle2::SVDCluster
The SVD Cluster class This class stores all information about reconstructed SVD clusters.
Definition: SVDCluster.h:38
Belle2::DATCONSVDSimpleClusterCandidate::getCharge
unsigned short getCharge() const
Return the charge of the cluster.
Definition: DATCONSVDSimpleClusterCandidate.h:87
Belle2::DATCONSVDSimpleClusterCandidate::getPosition
float getPosition() const
return the position of the cluster
Definition: DATCONSVDSimpleClusterCandidate.h:98
Belle2::RelationVector::weight
float weight(int index) const
Get weight with index.
Definition: RelationVector.h:120
Belle2::MCParticle
A Class to store the Monte Carlo particle information.
Definition: MCParticle.h:43
Belle2::DATCONSVDSimpleClusterCandidate::add
bool add(VxdID vxdID, bool isUside, unsigned short index, unsigned short charge, unsigned short cellID)
Add a Strip to the current cluster.
Definition: DATCONSVDSimpleClusterCandidate.cc:32