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"
8 #include "CLHEP/Vector/LorentzVector.h"
9 #include "CLHEP/Vector/ThreeVector.h"
14 #include "JetFitObject.h"
15 #include "OPALFitterGSL.h"
16 #include "NewFitterGSL.h"
17 #include "NewtonFitterGSL.h"
18 #include "MassConstraint.h"
21 #include <marlin/Global.h>
36 registerProcessorParameter(
"Printing" ,
37 "Print certain messages" ,
41 std::string ggResonanceName =
"Pi0";
42 registerProcessorParameter(
"GammaGammaResonanceName" ,
43 "Particle decaying to Gamma Gamma" ,
47 std::string inputParticleCollectionName =
"PandoraPFOs";
48 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
49 "InputParticleCollectionName" ,
50 "Input Particle Collection Name " ,
52 inputParticleCollectionName);
54 std::string outputParticleCollectionName =
"GammaGammaCandidates";
55 registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
56 "OutputParticleCollectionName" ,
57 "Output Particle Collection Name " ,
59 outputParticleCollectionName);
61 registerProcessorParameter(
"GammaMomentumCut" ,
62 "Minimum Momentum Cut for Photon (GeV)" ,
66 registerProcessorParameter(
"GammaGammaResonanceMass" ,
67 "Nominal Mass of Particle Decaying to Gamma Gamma (GeV)" ,
71 registerProcessorParameter(
"MaxDeltaMgg" ,
72 "Maximum difference between candidate mass and GammaGama Resonance mass (GeV)" ,
76 registerProcessorParameter(
"FitProbabilityCut" ,
77 "Minimum fit probability" ,
81 registerProcessorParameter(
"fitter" ,
82 "0 = OPALFitter, 1 = NewFitter, 2 = NewtonFitter",
139 typedef const std::vector<std::string>
StringVec ;
140 StringVec* strVec = evt->getCollectionNames() ;
141 for(StringVec::const_iterator name=strVec->begin(); name!=strVec->end(); name++){
143 LCCollection* col = evt->getCollection(*name);
144 unsigned int nelem = col->getNumberOfElements();
146 for(
unsigned int i=0;i<nelem;i++){
147 ReconstructedParticle* recoPart =
dynamic_cast<ReconstructedParticle*
>(col->getElementAt(i));
153 if(
_printing>1)std::cout <<
"Find PFOs : " << tf << std::endl;
167 if(
_printing>1)std::cout <<
"FindGammaGammaCandidates : (nPFOs = " <<
_pfovec.size() <<
" )" << std::endl;
170 std::vector<LorentzVector>pgamma;
171 std::vector<ReconstructedParticle*>pGammaPfoVec;
173 for(
unsigned int i=0;i<
_pfovec.size();i++){
176 if( fabs(
_pfovec[i]->getCharge() - 0.0) < 0.5 ){
179 if(
_pfovec[i]->getType()!=22)photon=
false;
183 if(
_printing>1)std::cout <<
"FindGammaGammaCandidates : Photon " <<
_pfovec[i]->getType() << std::endl;
185 pgamma.push_back(pgam);
186 pGammaPfoVec.push_back(
_pfovec[i]);
191 if(
_printing>1)std::cout <<
"FindGammaGammaCandidates : (nphotons = " << pGammaPfoVec.size() <<
" " << pgamma.size() <<
" )" << std::endl;
195 ReconstructedParticle* pGammai = NULL;
196 ReconstructedParticle* pGammaj = NULL;
198 if(pgamma.size() >=2 ){
199 for(
unsigned int i=0;i<pgamma.size()-1;i++){
200 for(
unsigned int j=i+1;j<pgamma.size();j++){
207 pGammai = pGammaPfoVec[i];
208 pGammaj = pGammaPfoVec[j];
213 MassConstraint mc(mass_constraint);
222 JetFitObject j1(pgi.e(), pgi.theta(), pgi.phi(),
223 0.16*std::sqrt(pgi.e()), 0.001/std::sqrt(pgi.e()), 0.001/std::sqrt(pgi.e()), 0.0);
225 JetFitObject j2(pgj.e(), pgj.theta(), pgj.phi(),
226 0.16*std::sqrt(pgj.e()), 0.001/std::sqrt(pgj.e()), 0.001/std::sqrt(pgj.e()), 0.0);
236 pfitter =
new NewFitterGSL();
239 pfitter =
new NewtonFitterGSL();
242 pfitter =
new OPALFitterGSL();
244 BaseFitter &fitter = *pfitter;
246 fitter.addFitObject(j1);
247 fitter.addFitObject(j2);
248 fitter.addConstraint(mc);
250 double fit_probability = 0.0;
251 fit_probability = fitter.fit();
253 int nIterations = fitter.getIterations();
255 int errorCode = fitter.getError();
258 double * cov = fitter.getGlobalCovarianceMatrix(cov_dim);
261 std::cout <<
"Constrained fit results RC: " << errorCode << std::endl;
262 std::cout <<
"Measured mass = " << mgg << std::endl;
263 std::cout <<
"No. of iterations " << nIterations << std::endl;
264 std::cout <<
"Fit probability = " << fit_probability << std::endl;
265 std::cout <<
"Covariance matrix dimension " << cov_dim << std::endl;
267 for (
unsigned int i=0; i<6*6; i++){
268 std::cout <<
"Covariance matrix element " << i <<
" " << cov[i] << std::endl;
275 ReconstructedParticleImpl * recoPart =
new ReconstructedParticleImpl();
276 recoPart->addParticle(pGammai);
277 recoPart->addParticle(pGammaj);
283 double Mom1[3],Mom2[3];
288 Mom1[0] = j1.getPx();
289 Mom1[1] = j1.getPy();
290 Mom1[2] = j1.getPz();
291 pT1 = sqrt(Mom1[0]*Mom1[0] + Mom1[1]*Mom1[1]);
294 Mom2[0] = j2.getPx();
295 Mom2[1] = j2.getPy();
296 Mom2[2] = j2.getPz();
297 pT2 = sqrt(Mom2[0]*Mom2[0] + Mom2[1]*Mom2[1]);
300 Mom[0] = Mom1[0] + Mom2[0];
301 Mom[1] = Mom1[1] + Mom2[1];
302 Mom[2] = Mom1[2] + Mom2[2];
304 FloatVec covP(10, 0.0);
312 const int ncolumns = 4;
315 double jacobian_by_columns[nrows*ncolumns] = {
316 Mom1[0]/E1, Mom1[0]*Mom1[2]/pT1, -Mom1[1], Mom2[0]/E2, Mom2[0]*Mom2[2]/pT2, -Mom2[1],
317 Mom1[1]/E1, Mom1[1]*Mom1[2]/pT1, Mom1[0], Mom2[1]/E2, Mom2[1]*Mom2[2]/pT2, Mom2[0],
318 Mom1[2]/E1, -pT1 , 0.0 , Mom2[2]/E2, -pT2 , 0.0 ,
319 1.0 , 0.0 , 0.0 , 1.0 , 0.0 , 0.0 };
322 TMatrixD Dmatrix(nrows,ncolumns, jacobian_by_columns,
"F");
323 TMatrixD Vmatrix(nrows,nrows, cov,
"F");
324 TMatrixD Covmatrix(ncolumns,ncolumns);
326 Covmatrix.Mult( TMatrixD( Dmatrix, TMatrixD::kTransposeMult, Vmatrix) ,Dmatrix);
328 for(
int ii=0;ii<4;ii++){
329 for(
int jj=0;jj<4;jj++){
330 if(
_printing>3)std::cout <<
"4-vector cov. " << ii <<
" " << jj <<
" " << Covmatrix(ii,jj) << std::endl;
334 covP[0] = Covmatrix(0,0);
335 covP[1] = Covmatrix(0,1);
336 covP[2] = Covmatrix(1,1);
337 covP[3] = Covmatrix(0,2);
338 covP[4] = Covmatrix(1,2);
339 covP[5] = Covmatrix(2,2);
340 covP[6] = Covmatrix(0,3);
341 covP[7] = Covmatrix(1,3);
342 covP[8] = Covmatrix(2,3);
343 covP[9] = Covmatrix(3,3);
346 if(
_printing>1)std::cout <<
" Fit has no valid covariance information (cov_dim = " << cov_dim <<
" )" << std::endl;
349 recoPart->setEnergy( Energy );
350 recoPart->setMomentum( Mom );
351 recoPart->setMass( mass_constraint );
352 recoPart->setCharge( 0.0 );
353 recoPart->setCovMatrix( covP );
356 float goodnessOfPID = float(fit_probability);
358 recoPart->setGoodnessOfPID( goodnessOfPID );
361 recoPart->setType( 111 );
366 << mgg <<
" " << i <<
" " << j <<
" " << pgi.e() <<
" " << pgj.e() <<
367 " Fitted energies: " << j1.getE() <<
" " << j2.getE()
368 <<
" Fit probability = " << fit_probability << std::endl;
372 if(
_printing>1)std::cout <<
"GG candidate passes fit probability cut - KEEP" << std::endl;
373 recparcol->addElement( recoPart );
std::string _ggResonanceName
double _fitProbabilityCut
virtual void end()
Called after data processing for clean up.
CLHEP::Hep3Vector Vector3D
GammaGammaCandidateFinder aGammaGammaCandidateFinder
void FindGammaGammaCandidates(LCCollectionVec *)
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
GammaGammaCandidateFinder()
GammaGammaCandidateFinder:
virtual void init()
Called at the beginning of the job before anything is read.
CLHEP::HepLorentzVector LorentzVector
std::string _outputParticleCollectionName
std::vector< LCCollection * > LCCollectionVec
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
std::vector< ReconstructedParticle * > _pfovec
bool FindPFOs(LCEvent *evt)
std::string _inputParticleCollectionName
std::vector< std::string > StringVec