All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
DistilledPFOCreator.cc
Go to the documentation of this file.
1 #include "EVENT/LCIO.h"
2 #include "EVENT/LCRunHeader.h"
3 #include "EVENT/LCCollection.h"
4 #include "EVENT/LCParameters.h"
5 #include "EVENT/ReconstructedParticle.h"
6 #include "IMPL/ReconstructedParticleImpl.h"
7 #include "DistilledPFOCreator.h"
8 #include "CLHEP/Vector/LorentzVector.h"
9 #include "CLHEP/Vector/ThreeVector.h"
10 typedef CLHEP::HepLorentzVector LorentzVector ;
11 typedef CLHEP::Hep3Vector Vector3D ;
12 
13 // Marlin stuff
14 #include <marlin/Global.h>
15 // the event display
16 
17 // ROOT stuff
18 #include "TMath.h"
19 #include "TMatrixD.h"
20 
21 #include <cstdlib>
22 
23 using namespace lcio;
24 
26 
27 DistilledPFOCreator::DistilledPFOCreator() : marlin::Processor("DistilledPFOCreator") {
28 
29  registerProcessorParameter( "Printing" ,
30  "Print certain messages" ,
31  _printing,
32  (int)1 ) ;
33 
34  std::string inputParticleCollectionName1 = "PandoraPFOs";
35  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
36  "InputParticleCollectionName1" ,
37  "Input Particle Collection Name1 " ,
39  inputParticleCollectionName1);
40 
41  std::string inputParticleCollectionName2 = "GammaGammaParticles";
42  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
43  "InputParticleCollectionName2" ,
44  "Input Particle Collection Name2 " ,
46  inputParticleCollectionName2);
47 
48  std::string outputParticleCollectionName = "DistilledPFOs";
49  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
50  "OutputParticleCollectionName" ,
51  "Output Particle Collection Name " ,
53  outputParticleCollectionName);
54 
55  return;
56 
57 }
58 
59 //===================================================================================
60 
62  if(_printing>1)printParameters();
63  return;
64 }
65 
66 //===================================================================================
67 
68 void DistilledPFOCreator::processRunHeader( LCRunHeader* /*run*/) {
69  return;
70 }
71 
72 //===================================================================================
73 
74 void DistilledPFOCreator::processEvent( LCEvent * evt ) {
75 
76  // Make a new vector of particles
77  LCCollectionVec * recparcol = new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE);
78  recparcol->setSubset(true);
79 
80  // Access PFO collection
81  bool found = this->FindPFOs(evt);
82  if(found){
83  if(_printing>1)std::cout << "Create DistilledPFOs : " << std::endl;
84  this->CreateDistilledPFOs(recparcol);
85  }
86 
87  // Add new collection to event
88  evt->addCollection( recparcol , _outputParticleCollectionName.c_str() );
89 
90  return;
91 
92 }
93 
94 //===================================================================================
95 
97  return;
98 }
99 
100 //===================================================================================
101 
102 bool DistilledPFOCreator::FindPFOs( LCEvent* evt ) {
103 
104 // Find the PandoraPFOs and the GammaGammaParticles as input PFOs and store in appropriate vectors
105 
106  bool tf = false;
107 
108  // clear old vectors
109  _pfovec.clear();
110  _ggpfovec.clear();
111  _mypfovec.clear();
112  typedef const std::vector<std::string> StringVec ;
113  StringVec* strVec = evt->getCollectionNames() ;
114 
115 // PandoraPFOs
116  for(StringVec::const_iterator name=strVec->begin(); name!=strVec->end(); name++){
118  LCCollection* col = evt->getCollection(*name);
119  unsigned int nelem = col->getNumberOfElements();
120  tf = true;
121  for(unsigned int i=0;i<nelem;i++){
122  ReconstructedParticle* recoPart = dynamic_cast<ReconstructedParticle*>(col->getElementAt(i));
123  _pfovec.push_back(recoPart);
124  }
125  }
126  }
127  if(_printing>1)std::cout << "FindPFOs : (nPFOs (PandoraPFOs) = " << _pfovec.size() << " )" << std::endl;
128 
129 // GammaGammaParticles
130  for(StringVec::const_iterator name=strVec->begin(); name!=strVec->end(); name++){
132  LCCollection* col = evt->getCollection(*name);
133  unsigned int nelem = col->getNumberOfElements();
134  tf = true;
135  for(unsigned int i=0;i<nelem;i++){
136  ReconstructedParticle* recoPart = dynamic_cast<ReconstructedParticle*>(col->getElementAt(i));
137  _ggpfovec.push_back(recoPart);
138  }
139  }
140  }
141  if(_printing>1)std::cout << "FindPFOs : (nPFOs (GammaGammaParticles) = " << _ggpfovec.size() << " )" << std::endl;
142 
143  if(_printing>1)std::cout << "Find PFOs : " << tf << std::endl;
144 
145  return tf;
146 
147 }
148 
149 //===================================================================================
150 
152 
153  // Merge PandoraPFOs and GammaGammaParticles into DistilledPFOs taking care to avoid double counting
154  //
155  // Graham W. Wilson, 15th October 2015
156 
157  // Keep track of various energy sums
158  float esumgg = 0.0; // GammaGammaParticles
159  float esump = 0.0; // PandoraPFOs
160  float esumd; // DistilledPFOs
161  float esumch = 0.0;
162  float esumph = 0.0;
163  int nphotons = 0;
164  int ncharged = 0;
165  int nothers = 0;
166  float esumothers = 0.0;
167  float chargesum = 0.0;
168  float esumNH = 0.0;
169  int nNH=0;
170  int npi0=0; int neta=0; int netap=0;
171  float epi0=0.0; float eeta=0.0; float eetap=0.0;
172  float Vpi0=0.0; float Veta=0.0; float Vetap=0.0;
173  int nppfo=0;
174 
175  if(_printing>1)std::cout << "CreateDistilledPFOs : (nPFOs initially = " << _pfovec.size() << " " << _ggpfovec.size() << " )" << std::endl;
176 
177  typedef std::set<const ReconstructedParticle*> PfoSet;
178  PfoSet particles_used; // Set with pointers to the daughter particles (photons for now) that are already used in the solution
179 
180  // For convenience sort the PandoraPFOs by energy
182 
183  // And also sort the GammaGammaParticles by energy
185 
186  for(unsigned int i = 0; i < _ggpfovec.size(); i++){
187  if(_ggpfovec[i]->getType()==111){
188  npi0++;
189  epi0 += _ggpfovec[i]->getEnergy();
190  Vpi0 += _ggpfovec[i]->getCovMatrix()[9]; // E-E term
191  }
192  if(_ggpfovec[i]->getType()==221){
193  neta++;
194  eeta += _ggpfovec[i]->getEnergy();
195  Veta += _ggpfovec[i]->getCovMatrix()[9]; // E-E term
196  }
197  if(_ggpfovec[i]->getType()==331){
198  netap++;
199  eetap += _ggpfovec[i]->getEnergy();
200  Vetap += _ggpfovec[i]->getCovMatrix()[9]; // E-E term
201  }
202  esumgg += _ggpfovec[i]->getEnergy();
203  const ReconstructedParticleVec particles = _ggpfovec[i]->getParticles();
204  if(_printing>3)std::cout << "CreateDistilledPFOs: (nparticles = " << particles.size() << " )" << std::endl;
205  for(unsigned int j = 0; j < particles.size(); j++){ // TODO - maybe double check these are indeed photons ..
206  const ReconstructedParticle *particle = particles[j];
207  particles_used.insert(particle); // Keep note of particles that are constituents of a GammaGammaParticle
208  }
209  // Add this PFO to the output
210  recparcol->addElement(_ggpfovec[i]);
211  }
212  if(_printing>3)std::cout << "CreateDistilledPFOs: (nparticles_used = " << particles_used.size() << " )" << std::endl;
213 
214  esumd = esumgg;
215  for(unsigned int i = 0; i < _pfovec.size(); i++){
216  esump += _pfovec[i]->getEnergy();
217  if(abs(_pfovec[i]->getCharge())>0.5){
218  ncharged++;
219  chargesum+=_pfovec[i]->getCharge();
220  esumch+= _pfovec[i]->getEnergy();
221  }
222  else{
223  if(_pfovec[i]->getType()==2112){
224  nNH++;
225  esumNH += _pfovec[i]->getEnergy();
226  }
227  else if(_pfovec[i]->getType()==22){
228  nphotons++;
229  esumph += _pfovec[i]->getEnergy();
230  }
231  else{
232  nothers++;
233  esumothers += _pfovec[i]->getEnergy();
234  }
235  }
236  if( particles_used.find(_pfovec[i]) == particles_used.end() ){ // Condition is true if the i'th PandoraPFO is not in the particles_used set
237  // So can add this PFO to the output
238  recparcol->addElement(_pfovec[i]);
239  esumd += _pfovec[i]->getEnergy();
240  nppfo++;
241  }
242  }
243  float V = Vpi0 + Veta + Vetap;
244  int ntot = npi0 + neta + netap;
245 
246  if(_printing>3)std::cout << "CreateDistilledPFOs : (nPFOs finally = " << recparcol->getNumberOfElements() << " )" << std::endl;
247 
248  if(_printing>3)std::cout << "CreateDistilledPFOs SUMMARY " << ntot << " " << nppfo << " "
249  << ncharged << " " << chargesum << " " << esumch << " "
250  << nphotons << " " << esumph << " "
251  << nNH << " " << esumNH << " "
252  << nothers << " " << esumothers << " "
253  << esump << " "
254  << esumd << " "
255  << esumgg << " "
256  << V << " "
257  << npi0 << " " << neta << " " << netap << " "
258  << epi0 << " " << eeta << " " << eetap << " "
259  << Vpi0 << " " << Veta << " " << Vetap << " "
260  << std::endl;
261  return;
262 }
263 
264 bool DistilledPFOCreator::PfoEnergySortFunction(ReconstructedParticle* lhs, ReconstructedParticle* rhs){
265 
266  // Sort the ReconstructedParticles by energy
267 
268  // true if lhs goes before
269 
270  const double lhs_energy = lhs->getEnergy();
271  const double rhs_energy = rhs->getEnergy();
272 
273  return (lhs_energy>rhs_energy);
274 
275 }
276 
bool FindPFOs(LCEvent *evt)
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
CLHEP::Hep3Vector Vector3D
static const float V
std::vector< ReconstructedParticle * > _mypfovec
DistilledPFOCreator aDistilledPFOCreator
std::vector< ReconstructedParticle * > _pfovec
std::string _inputParticleCollectionName2
virtual void end()
Called after data processing for clean up.
virtual void init()
Called at the beginning of the job before anything is read.
static bool PfoEnergySortFunction(ReconstructedParticle *lhs, ReconstructedParticle *rhs)
CLHEP::HepLorentzVector LorentzVector
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
std::string _outputParticleCollectionName
void CreateDistilledPFOs(LCCollectionVec *)
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
DistilledPFOCreator:
std::vector< ReconstructedParticle * > _ggpfovec
std::string _inputParticleCollectionName1
std::vector< std::string > StringVec
Definition: SiStripClus.h:56