All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
IsolatedPhotonTaggingProcessor.cc
Go to the documentation of this file.
1 // *****************************************************
2 // Processor for isolated photon tagging
3 // ----originally developped by S.Kawada and J.Tian
4 // ----for miniDST analysis
5 // *****************************************************
7 
8 #include <EVENT/LCCollection.h>
9 #include <IMPL/LCCollectionVec.h>
10 #include <EVENT/ReconstructedParticle.h>
11 #include <EVENT/Cluster.h>
12 #include <UTIL/LCTypedVector.h>
13 #include <EVENT/Track.h>
14 #include <marlin/Exceptions.h>
15 #include <EVENT/Vertex.h>
16 
17 // ----- include for verbosity dependend logging ---------
18 #include "marlin/VerbosityLevels.h"
19 
20 //root
21 #include "TVector3.h"
22 #include "TLorentzVector.h"
23 #include "TMath.h"
24 #include "TMVA/Reader.h"
25 //local
26 #include "Utilities.h"
27 
28 #include <memory>
29 #include <algorithm>
30 
31 using namespace lcio ;
32 using namespace marlin ;
33 using namespace std;
34 
35 using namespace TMVA;
36 using namespace isolep;
37 
39 
40 
41 IsolatedPhotonTaggingProcessor::IsolatedPhotonTaggingProcessor() : Processor("IsolatedPhotonTaggingProcessor") {
42 
43  // modify processor description
44  _description = "IsolatedPhotonTaggingProcessor does whatever it does ..." ;
45 
46 
47  // register steering parameters: name, description, class-variable, default value
48 
49  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
50  "InputPandoraPFOsCollection" ,
51  "Name of the PandoraPFOs collection" ,
52  _colPFOs ,
53  std::string("PandoraPFOs") ) ;
54 
55  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
56  "OutputPFOsWithoutIsoPhotonCollection",
57  "Name of the new PFOs collection without isolated photon",
59  std::string("PandoraPFOsWithoutIsoPhoton") );
60 
61  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
62  "OutputIsoPhotonsCollection",
63  "Name of collection with the selected isolated photon",
65  std::string("ISOPhotons") );
66 
67  registerProcessorParameter("DirOfISOPhotonWeights",
68  "Directory of Weights for the Isolated Photon MVA Classification" ,
70  std::string("isolated_photon_weights") ) ;
71 
72  registerProcessorParameter("CutOnTheISOPhotonMVA",
73  "Cut on the mva output of isolated photon selection" ,
74  _mvaCut,
75  float(0.5) ) ;
76 
77  registerProcessorParameter("IsSelectingOneIsoPhoton",
78  "flag to select one most like isolated photon" ,
80  bool(false) ) ;
81 
82  registerProcessorParameter("MinEForPhoton",
83  "Minimum energy for photon" ,
84  _minE,
85  float(5.) ) ;
86 
87  registerProcessorParameter("CosConeSmall",
88  "cosine of the smaller cone" ,
90  float(0.98) ) ;
91 
92  registerProcessorParameter("CosConeLarge",
93  "cosine of the larger cone" ,
95  float(0.95) ) ;
96 
97  registerProcessorParameter("RatioNeutralConeEnergy",
98  "Cut on the ratio of Neutral Cone Energy over Photon Energy" ,
100  float(0.2) ) ;
101 
102  registerProcessorParameter("RatioChargedConeEnergy",
103  "Cut on the ratio of Charged Cone Energy over Photon Energy" ,
105  float(0.1) ) ;
106 }
107 
109 
110  streamlog_out(DEBUG) << "IsolatedPhotonTagging init called "
111  << std::endl ;
112 
113 
114  // usually a good idea to
115  printParameters() ;
116 
117 
118 }
119 
121 }
122 
124  auto pPFOsWithoutIsoPhotonCollection = std::make_unique<LCCollectionVec>(LCIO::RECONSTRUCTEDPARTICLE);
125  auto pIsoPhotonCollection = std::make_unique<LCCollectionVec>(LCIO::RECONSTRUCTEDPARTICLE);
126  pPFOsWithoutIsoPhotonCollection->setSubset(true);
127  pIsoPhotonCollection->setSubset(true);
128 
129  streamlog_out(DEBUG) << "Hello, Isolated Photon Tagging!" << endl;
130 
131  // -- get PFO collection --
132  LCCollection *colPFO = evt->getCollection(_colPFOs);
133 
134  Int_t nPFOs = colPFO->getNumberOfElements();
135  std::vector<lcio::ReconstructedParticle*> newPFOs;
136  std::vector<lcio::ReconstructedParticle*> isoPhotons;
137  FloatVec isoPhotonTagging;
138 
139  // loop all the PFOs
140  float energy_photon_max = -1.;
141  for (Int_t i=0;i<nPFOs;i++) {
142  ReconstructedParticle *recPart = dynamic_cast<ReconstructedParticle*>(colPFO->getElementAt(i));
143  // here in principle can add any precut on each PFO
144  newPFOs.push_back(recPart);
145  Double_t energy = recPart->getEnergy();
146  Double_t charge = recPart->getCharge();
147  TVector3 momentum = TVector3(recPart->getMomentum());
148  TLorentzVector lortz = TLorentzVector(momentum,energy);
149  Double_t momentumMagnitude = momentum.Mag();
150  // get cone information
151  // double cone based isolation algorithm
152  Double_t coneEnergy0[3] = {0.,0.,0.}; // {total, neutral, charged} cone energy
153  Double_t pLargeCone[4] = {0.,0.,0.,0.}; // 4-momentum of all particles inside the larger cone
154  getConeEnergy(recPart,colPFO,_cosConeSmall,coneEnergy0,_cosConeLarge,pLargeCone);
155  Double_t coneEN = coneEnergy0[1];
156  Double_t coneEC = coneEnergy0[2];
157  TLorentzVector lortzLargeCone = TLorentzVector(pLargeCone[0],pLargeCone[1],pLargeCone[2],pLargeCone[3]);
158  TVector3 momentumLargeCone = lortzLargeCone.Vect();
159  Double_t cosThetaWithLargeCone = 1.;
160  if (momentumLargeCone.Mag() > 0.0000001) {
161  cosThetaWithLargeCone = momentum.Dot(momentumLargeCone)/momentumMagnitude/momentumLargeCone.Mag();
162  }
163  Double_t energyRatioWithLargeCone = energy/(energy+lortzLargeCone.E());
164  Double_t pandoraID = recPart->getType();
165  if (TMath::Abs(charge) < 0.5 && pandoraID == 22) {
166  if (energy < _minE) continue; // cut on the minimum energy
167  // default option to select all isolated photons
168  if (coneEC/energy < _coneChargedRatio && coneEN/energy < _coneNeutralRatio) { // simple charged and neutral cone energy ratio cut
169  if (!_is_one_isophoton) {
170  isoPhotons.push_back(recPart);
171  }
172  else {
173  if (energy > energy_photon_max) {
174  energy_photon_max = energy;
175  isoPhotons.clear();
176  isoPhotons.push_back(recPart);
177  }
178  }
179  }
180  }
181  }
182 
183  // save the selected photon to a new collection
184  for (auto* obj : isoPhotons) {
185  pIsoPhotonCollection->addElement(obj);
186  }
187 
188  // save other PFOs to a new collection
189  for (auto * obj : newPFOs) {
190  if (std::find(isoPhotons.cbegin(), isoPhotons.cend(), obj) == isoPhotons.cend()) {
191  pPFOsWithoutIsoPhotonCollection->addElement(obj);
192  }
193  }
194 
195  // add new collections
196  evt->addCollection(pPFOsWithoutIsoPhotonCollection.release(), _colNewPFOs.c_str());
197  evt->addCollection(pIsoPhotonCollection.release(), _colPhotons.c_str());
198 }
199 
200 
201 
202 void IsolatedPhotonTaggingProcessor::check( LCEvent * /*evt*/ ) {
203 }
204 
205 
207 
208  for (std::vector<TMVA::Reader*>::const_iterator ireader=_readers.begin();ireader!=_readers.end();++ireader) {
209  delete *ireader;
210  }
211 
212 }
213 
virtual void end()
Called after data processing for clean up.
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
std::vector< TMVA::Reader * > _readers
Double_t getConeEnergy(ReconstructedParticle *recPart, LCCollection *colPFO, Double_t cosCone)
Definition: Utilities.cc:361
IsolatedPhotonTaggingProcessor aIsolatedPhotonTaggingProcessor
virtual void init()
Called at the begin of the job before anything is read.
processor for isolated photon tagging.
std::string _colPFOs
Input collection name.
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.