All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
CLICDstChecker.cc
Go to the documentation of this file.
1 #include "CLICDstChecker.h"
2 #include <CalorimeterHitType.h>
3 #include <EVENT/LCCollection.h>
4 #include <EVENT/LCObject.h>
5 #include <EVENT/MCParticle.h>
6 #include <EVENT/SimTrackerHit.h>
7 #include <EVENT/Track.h>
8 #include <EVENT/TrackerHit.h>
9 #include <IMPL/LCCollectionVec.h>
10 #include <IMPL/LCFlagImpl.h>
11 #include <IMPL/LCRelationImpl.h>
12 #include <IMPL/ReconstructedParticleImpl.h>
13 #include <IMPL/TrackImpl.h>
14 #include <UTIL/LCRelationNavigator.h>
15 #include <UTIL/LCTOOLS.h>
16 #include <gear/BField.h>
17 #include <gear/CalorimeterParameters.h>
18 #include <gear/GEAR.h>
19 #include <gear/GearParameters.h>
20 #include <gear/PadRowLayout2D.h>
21 #include <gear/TPCParameters.h>
22 #include <gear/VXDLayerLayout.h>
23 #include <gear/VXDParameters.h>
24 #include <marlin/Global.h>
25 #include <math.h>
26 #include <iostream>
27 #include <iostream>
28 #include <map>
29 #include "ClusterShapes.h"
30 #include "PfoUtilities.h"
31 
32 #include <limits>
33 
34 using namespace lcio;
35 using namespace marlin;
36 
37 const int precision = 2;
38 const int widthFloat = 7;
39 const int widthInt = 5;
40 const int widthSmallInt = 3;
41 const float radiansToDegrees = 57.2957;
42 
44 
45 CLICDstChecker::CLICDstChecker() : Processor("CLICDstChecker") {
46  _description = "Prints out information in DST in a useful format";
47 
48  registerProcessorParameter("Debug", "Activate debugging?", m_debug, int(0));
49 
50  registerProcessorParameter("Monitoring", "Monitoring", m_monitoring, int(1));
51 
52  registerProcessorParameter("ShowBackground", "Show background pfo information", m_showBackground, int(1));
53 
54  registerInputCollection(LCIO::RECONSTRUCTEDPARTICLE, "InputPfoCollection", "Input PFO Collection", m_inputPfoCollection,
55  std::string("PandoraPFANewPFOs"));
56 
57  registerProcessorParameter("PfoToMcRelationCollection", "Input PFO to MC particle relation Collection",
58  m_inputPfoToMcRelationCollection, std::string("RecoMCTruthLink"));
59 
60  registerInputCollection(LCIO::MCPARTICLE, "McParticleCollection", "Input MC particle collection",
61  m_inputMcParticleCollection, std::string("MCParticlesSkimmed"));
62 }
63 
65  printParameters();
66  m_nRun = -1;
67  m_nEvt = 0;
68 }
69 
71  m_nRun++;
72  m_nEvt = 0;
73  streamlog_out(MESSAGE) << std::endl;
74  streamlog_out(MESSAGE) << "CLICDstChecker ---> new run : run number = " << m_nRun << std::endl;
75 }
76 
77 void CLICDstChecker::processEvent(LCEvent* evt) {
78  if (m_debug >= 1) {
79  streamlog_out(MESSAGE) << std::endl;
80  streamlog_out(MESSAGE) << "CLICDstChecker -> run = " << m_nRun << " event = " << m_nEvt << std::endl;
81  streamlog_out(MESSAGE) << std::endl;
82  }
83 
84  std::vector<ReconstructedParticle*> physicsPfos;
85  std::vector<MCParticle*> physicsMatchedMcParticle;
86  std::vector<ReconstructedParticle*> backgroundPfos;
87 
88  try {
89  LCCollection* col = evt->getCollection(m_inputPfoCollection.c_str());
90  const int nelem = col->getNumberOfElements();
91  for (int iPfo = 0; iPfo < nelem; ++iPfo)
92  m_pfoVector.push_back(static_cast<ReconstructedParticle*>(col->getElementAt(iPfo)));
93  std::sort(m_pfoVector.begin(), m_pfoVector.end(), PfoUtil::PfoSortFunction);
94  } catch (DataNotAvailableException& e) {
95  streamlog_out(MESSAGE) << m_inputPfoCollection.c_str() << " collection is unavailable" << std::endl;
96  };
97 
98  try {
99  LCCollection* col = evt->getCollection(m_inputMcParticleCollection.c_str());
100  int nelem = col->getNumberOfElements();
101  for (int iMc = 0; iMc < nelem; ++iMc) {
102  MCParticle* pMc = static_cast<MCParticle*>(col->getElementAt(iMc));
103  // insert all existing mc pointers into set *** MUST CHECK THIS BEFORE USING RELATION ***
104  m_mcSet.insert(pMc);
105  const float px(pMc->getMomentum()[0]);
106  const float py(pMc->getMomentum()[1]);
107  const float pz(pMc->getMomentum()[2]);
108  const float p = sqrt(px * px + py * py + pz * pz);
109  const float cosThetaMc = fabs(pz) / p;
110  float thetaMc = 0.;
111  if (cosThetaMc < 1.0)
112  thetaMc = acos(cosThetaMc) * radiansToDegrees;
113  if ((pMc->getParents()).size() == 0)
114  streamlog_out(MESSAGE) << " Primary MC particle : " << pMc->getPDG() << " E = " << pMc->getEnergy()
115  << " cosT = " << cosThetaMc << " theta = " << thetaMc << std::endl;
116  }
117  } catch (DataNotAvailableException& e) {
118  streamlog_out(MESSAGE) << m_inputMcParticleCollection.c_str() << " collection is unavailable" << std::endl;
119  };
120 
121  m_pfoToMcNavigator = NULL;
122  try {
123  m_pfoToMcNavigator = new LCRelationNavigator(evt->getCollection(m_inputPfoToMcRelationCollection.c_str()));
124  } catch (DataNotAvailableException& e) {
125  streamlog_out(MESSAGE) << m_inputPfoToMcRelationCollection.c_str() << " collection is unavailable" << std::endl;
126  }
127 
128  for (unsigned int iPfo = 0; iPfo < m_pfoVector.size(); ++iPfo) {
129  ReconstructedParticle* pPfo = m_pfoVector[iPfo];
130  LCObjectVec objectVec = m_pfoToMcNavigator->getRelatedToObjects(pPfo);
131  if (objectVec.size() > 0) {
132  for (unsigned int imc = 0; imc < objectVec.size(); imc++) {
133  MCParticle* pMC = static_cast<MCParticle*>(objectVec[imc]);
134  // since only saving skimmed set of MC particles, check pMC points to an existing object
135  if (m_mcSet.count(pMC) != 0) {
136  physicsPfos.push_back(pPfo);
137  physicsMatchedMcParticle.push_back(pMC);
138  } else {
139  backgroundPfos.push_back(pPfo);
140  }
141  }
142  }
143  }
144 
145  float eSignal = 0;
146  float eBackground = 0;
147  float eMc = 0;
148 
149  for (unsigned int ipass = 0; ipass < 2; ipass++) {
150  unsigned int nPfos;
151  (ipass == 0) ? nPfos = physicsPfos.size() : nPfos = backgroundPfos.size();
152  for (unsigned int iPfo = 0; iPfo < nPfos; ++iPfo) {
153  if (iPfo == 0) {
154  if (m_monitoring == 1 && ipass == 0) {
155  streamlog_out(MESSAGE) << " *********************** Physics Pfos ************************" << std::endl;
156  streamlog_out(MESSAGE) << " pfo E pT cost nt nc mc Emc " << std::endl;
157  } else {
158  if (m_monitoring == 1 && m_showBackground == 1 && ipass == 1)
159  streamlog_out(MESSAGE) << " ********************** Background Pfos ************************" << std::endl;
160  streamlog_out(MESSAGE) << " pfo E pT cost nt nc " << std::endl;
161  }
162  }
163 
164  ReconstructedParticle* pPfo;
165  (ipass == 0) ? pPfo = physicsPfos[iPfo] : pPfo = backgroundPfos[iPfo];
166  MCParticle* pMc = NULL;
167  if (ipass == 0) {
168  pMc = physicsMatchedMcParticle[iPfo];
169  eMc += pMc->getEnergy();
170  }
171  // const int id = pPfo->id();
172  const int type = pPfo->getType();
173  // const bool isCompound = pPfo->isCompound();
174  float momentum[3];
175  for (unsigned int i = 0; i < 3; i++)
176  momentum[i] = pPfo->getMomentum()[i];
177  const float pT = sqrt(momentum[0] * momentum[0] + momentum[1] * momentum[1]);
178  const float p = sqrt(pT * pT + momentum[2] * momentum[2]);
179  const float cosTheta = fabs(momentum[2]) / p;
180  const float energy = pPfo->getEnergy();
181  //eTotalInput+=energy;
182  // const float mass = pPfo->getMass();
183  // const float charge = pPfo->getCharge();
184  const ParticleIDVec particleIDs = pPfo->getParticleIDs();
185  // ParticleID *particleIDUsed = pPfo->getParticleIDUsed();
186  // const float goodnessOfPID = pPfo->getGoodnessOfPID();
187  const ReconstructedParticleVec particles = pPfo->getParticles();
188  const ClusterVec clusters = pPfo->getClusters();
189  const TrackVec tracks = pPfo->getTracks();
190 
191  // for(unsigned int i = 0; i< tracks.size(); i++){
192  // Track *track = tracks[i];
193  // const int nHitsVTX = track->getSubdetectorHitNumbers()[6];
194  // const int nHitsFTD = track->getSubdetectorHitNumbers()[7];
195  // const int nHitsSIT = track->getSubdetectorHitNumbers()[8];
196  // const int nHitsTPC = track->getSubdetectorHitNumbers()[9];
197  // const int nHitsSET = track->getSubdetectorHitNumbers()[10];
198  // const int nHitsETD = track->getSubdetectorHitNumbers()[11];
199  // const float d0 = track->getD0();
200  // const float z0 = track->getZ0();
201  // const float omega = track->getOmega();
202  // const float tanL = track->getTanLambda();
203  // const float phi0 = track->getPhi();
204  // }
205 
206  // for(unsigned int i = 0; i< clusters.size(); i++){
207  // const Cluster *cluster = clusters[i];
208  // }
209 
210  (ipass == 0) ? eSignal += energy : eBackground += energy;
211 
212  if (m_monitoring && (ipass == 0 || (ipass == 1 && m_showBackground))) {
213  std::stringstream output;
214  output << std::fixed;
215  output << std::setprecision(precision);
216  if (clusters.size() == 0)
217  FORMATTED_OUTPUT_TRACK(output, type, energy, pT, cosTheta, tracks.size(), 0);
218  if (tracks.size() == 0)
219  FORMATTED_OUTPUT_CLUSTER(output, type, energy, pT, cosTheta, 0, clusters.size());
220 
221  if (tracks.size() > 0 && clusters.size() > 0)
222  FORMATTED_OUTPUT_TRACK_CLUSTER(output, type, energy, pT, cosTheta, tracks.size(), clusters.size());
223  if (pMc != NULL)
224  FORMATTED_OUTPUT_MC(output, pMc->getPDG(), pMc->getEnergy());
225 
226  streamlog_out(MESSAGE) << output.str();
227  streamlog_out(MESSAGE) << std::endl;
228  }
229  }
230  }
231 
232  if (m_monitoring) {
233  streamlog_out(MESSAGE) << " ESignal = " << eSignal << "( " << eMc << " )" << std::endl;
234  streamlog_out(MESSAGE) << " EBack = " << eBackground << std::endl;
235  }
236 
237  CleanUp();
238 
239  m_nEvt++;
240 }
241 
243  m_pfoVector.clear();
244  m_mcSet.clear();
245  delete m_pfoToMcNavigator;
246  m_pfoToMcNavigator = NULL;
247 }
248 
249 void CLICDstChecker::check(LCEvent*) {}
250 
virtual void init()
const int precision
=== CLICDstChecker Processor === Processor to check DST Pfos
#define FORMATTED_OUTPUT_MC(out, N1, E1)
Definition: PfoUtilities.h:43
const int widthInt
#define FORMATTED_OUTPUT_CLUSTER(out, N1, E1, E2, E3, N2, N3)
Definition: PfoUtilities.h:38
virtual void processRunHeader(LCRunHeader *run)
std::string m_inputMcParticleCollection
const float radiansToDegrees
std::set< MCParticle * > m_mcSet
#define FORMATTED_OUTPUT_TRACK_CLUSTER(out, N1, E1, E2, E3, N2, N3)
Definition: PfoUtilities.h:28
virtual void end()
virtual void processEvent(LCEvent *evt)
int m_monitoring
Whether to display monitoring information.
int m_showBackground
Whether to display background information.
virtual void check(LCEvent *evt)
std::vector< ReconstructedParticle * > m_pfoVector
static const float e
std::string m_inputPfoToMcRelationCollection
const int widthFloat
#define FORMATTED_OUTPUT_TRACK(out, N1, E1, E2, E3, N2, N3)
Definition: PfoUtilities.h:33
static bool PfoSortFunction(EVENT::ReconstructedParticle *lhs, EVENT::ReconstructedParticle *rhs)
Definition: PfoUtilities.h:50
CLICDstChecker aCLICDstChecker
LCRelationNavigator * m_pfoToMcNavigator
std::string m_inputPfoCollection
Input PFO collection name.
const int widthSmallInt