1 #include "DSTCollectionProcessor.h"
7 #include <EVENT/LCParameters.h>
8 #include <EVENT/LCCollection.h>
9 #include <EVENT/ReconstructedParticle.h>
10 #include <EVENT/Track.h>
11 #include <EVENT/LCRelation.h>
12 #include <EVENT/MCParticle.h>
13 #include <EVENT/LCIntVec.h>
14 #include "EVENT/LCFloatVec.h"
17 #include <UTIL/LCRelationNavigator.h>
18 #include <UTIL/PIDHandler.h>
19 #include <IMPL/ParticleIDImpl.h>
20 #include <IMPL/LCCollectionVec.h>
27 using namespace marlin ;
39 DSTCollectionProcessor::DSTCollectionProcessor() : Processor(
"DSTCollectionProcessor") {
42 _description =
"DSTCollectionProcessor - Takes the flavour tag info, mc truth info, and some NN input info, and adds it as Particle ID info to the jets, for the DSTs" ;
49 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
51 "Name of the collection of ReconstructedParticles that is the jet" ,
53 std::string(
"Jets") );
56 registerInputCollection( LCIO::LCFLOATVEC,
57 "FlavourTagCollection" ,
58 "Name of the LCFloatVec Collection containing the flavour tags (in same order as jet collection)" ,
59 _FlavourTagCollectionName,
62 registerInputCollection( LCIO::LCFLOATVEC,
63 "FlavourTagInputsCollection" ,
64 "Name of the LCFloatVec Collection that contains the flavour tag inputs (in same order as jet collection)" ,
65 _FlavourTagInputsCollectionName,
66 "FlavourTagInputs" ) ;
70 registerInputCollection( LCIO::LCFLOATVEC,
71 "TrueJetFlavourCollection" ,
72 "Name of the LCIntVec collection containing the true flavour of the jets (same order as jets)" ,
73 _TrueJetFlavourColName ,
74 std::string(
"TrueJetFlavour") ) ;
76 registerProcessorParameter(
"Debug",
84 void DSTCollectionProcessor::init()
93 void DSTCollectionProcessor::processRunHeader( LCRunHeader* pRun) {
101 _lastRunHeaderProcessed=pRun->getRunNumber();
106 std::vector<std::string> VarNames;
107 (pRun->parameters()).getStringVals(_FlavourTagCollectionName,VarNames);
108 for (
size_t i = 0;i < VarNames.size();++i)
109 _IndexOfForEachTag[VarNames[i]] = i;
113 std::vector<std::string> trueJetFlavourVarNames;
114 (pRun->parameters()).getStringVals(_TrueJetFlavourColName,trueJetFlavourVarNames);
115 for (
size_t i = 0;i < trueJetFlavourVarNames.size();++i)
116 _FlavourIndex[trueJetFlavourVarNames[i]] = i;
120 std::vector<std::string> InputVarNames;
121 (pRun->parameters()).getStringVals(_FlavourTagInputsCollectionName,InputVarNames);
122 for (
size_t i = 0;i < InputVarNames.size();++i)
123 _InputsIndex[InputVarNames[i]] = i;
132 void DSTCollectionProcessor::processEvent( LCEvent* pEvent) {
135 LCCollection* JetCollection=pEvent->getCollection( _JetCollectionName );
138 LCCollection* trueJetFlavourCollection = pEvent->getCollection(_TrueJetFlavourColName);
141 LCCollection* flavourTagInputsCollection = pEvent->getCollection( _FlavourTagInputsCollectionName);
144 LCCollection* TagCollection=pEvent->getCollection( _FlavourTagCollectionName );
148 PIDHandler jetPID ( JetCollection ) ;
152 pNames.push_back(
"BTag" );
153 pNames.push_back(
"CTag" );
154 pNames.push_back(
"BCTag" ) ;
156 pNames.push_back(
"NumVertices");
157 pNames.push_back(
"JointProbRPhi");
158 pNames.push_back(
"JointProbZ");
159 pNames.push_back(
"NumTracksInVertices");
160 pNames.push_back(
"DecayLength");
161 pNames.push_back(
"DecayLengthSignificance");
162 pNames.push_back(
"RawMomentum");
163 pNames.push_back(
"PTCorrectedMass");
164 pNames.push_back(
"SecondaryVertexProbability");
170 mcNames.push_back(
"TruePDGCode");
171 mcNames.push_back(
"TruePartonCharge");
172 mcNames.push_back(
"TrueHadronCharge");
173 mcNames.push_back(
"TrueJetFlavour");
176 int ftagID = jetPID.addAlgorithm(
"LCFIFlavourTag",pNames ) ;
177 int mcID = jetPID.addAlgorithm(
"MCTruth",mcNames ) ;
180 FloatVec fv(pNames.size());
182 for(
int i = 0; i < (int)pNames.size(); i++)
185 FloatVec mcv(mcNames.size());
187 for(
int i = 0; i < (int)mcNames.size(); i++)
191 cout<<
"Number of jets in the event "<<JetCollection->getNumberOfElements()<<endl;
194 for(
int jet=0; jet<JetCollection->getNumberOfElements(); jet++ )
198 ReconstructedParticle* Jet =
dynamic_cast<ReconstructedParticle*
>( JetCollection->getElementAt(jet) );
201 LCFloatVec* flavourTags =
dynamic_cast<LCFloatVec*
>(TagCollection->getElementAt( jet ));
202 fv[0]= (*flavourTags)[_IndexOfForEachTag[
"BTag"]];
203 fv[1]= (*flavourTags)[_IndexOfForEachTag[
"CTag"]];
204 fv[2]=(*flavourTags)[_IndexOfForEachTag[
"BCTag"]];
207 LCFloatVec* tagInputs =
dynamic_cast<LCFloatVec*
>(flavourTagInputsCollection->getElementAt( jet ));
208 int NumVertices = int((*tagInputs)[_InputsIndex[
"NumVertices"]]);
213 fv[4]=(*tagInputs)[_InputsIndex[
"JointProbRPhi"]];
214 fv[5]=(*tagInputs)[_InputsIndex[
"JointProbZ"]];
215 fv[6]=(*tagInputs)[_InputsIndex[
"NumTracksInVertices"]];
216 fv[7]=(*tagInputs)[_InputsIndex[
"DecayLength"]];
217 fv[8]=(*tagInputs)[_InputsIndex[
"DecayLengthSignificance"]];
218 fv[9]=(*tagInputs)[_InputsIndex[
"RawMomentum"]];
219 fv[10]=(*tagInputs)[_InputsIndex[
"PTCorrectedMass"]];
220 fv[11]=(*tagInputs)[_InputsIndex[
"SecondaryVertexProbability"]];
225 jetPID.setParticleID( Jet , 42 ,
232 LCFloatVec* pJetFlavour =
dynamic_cast<LCFloatVec*
>(trueJetFlavourCollection->getElementAt( jet ));
233 if(pJetFlavour==0) std::cerr <<
"The wrong type of true jet flavour collection was found, dynamic cast failed" << std::endl;
234 mcv[0] = (*pJetFlavour)[_FlavourIndex[
"TruePDGCode"]];
235 mcv[1] =(*pJetFlavour)[_FlavourIndex[
"TruePartonCharge"]];
236 mcv[2]= (*pJetFlavour)[_FlavourIndex[
"TrueHadronCharge"]];
237 mcv[3]= (*pJetFlavour)[_FlavourIndex[
"TrueJetFlavour"]];
240 jetPID.setParticleID( Jet , 43 ,
249 catch(DataNotAvailableException &e){
251 std::cout <<
"Collection " <<_FlavourTagCollectionName <<
" is unavailable in event " << _nEvt << std::endl;
254 catch(DataNotAvailableException &e){
256 std::cout <<
"Collection " <<_FlavourTagInputsCollectionName <<
" is unavailable in event " << _nEvt << std::endl;
259 catch(DataNotAvailableException &e){
261 std::cout <<
"Collection " << _TrueJetFlavourColName <<
" is unavailable in event " << _nEvt << std::endl;
264 catch(DataNotAvailableException &e){
266 std::cout <<
"Collection " <<_JetCollectionName <<
" is unavailable in event " << _nEvt << std::endl;
279 void DSTCollectionProcessor::check( LCEvent * evt ) {
284 void DSTCollectionProcessor::end(){
286 std::cout <<
"DSTCollectionProcessor::end() " << name()
287 <<
" processed " << _nEvt <<
" events in " << _nRun <<
" runs "
std::string _JetCollectionName