All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
SatoruJetFinderProcessor.cc
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 ** This file is part of the MarlinReco Project.
4 ** Forming part of the SubPackage: SatoruJetFinder.
5 **
6 ** For the latest version download from Web CVS:
7 ** http://www-zeuthen.desy.de/lc-cgi-bin/cvsweb.cgi/marlinreco/?cvsroot=MarlinReco
8 **
9 ** $Id: SatoruJetFinderProcessor.cc,v 1.8 2008-05-20 08:48:06 aplin Exp $
10 **
11 **
12 */
13 
15 #include <iostream>
16 
17 
18 #include <algorithm>
19 #include <math.h>
20 
21 #include "EVENT/LCIO.h"
22 #include "EVENT/LCCollection.h"
23 #include "IMPL/ReconstructedParticleImpl.h"
24 #include "IMPL/LCCollectionVec.h"
25 
26 using namespace std;
27 
28 namespace marlin
29 {
30 
32 
33 
34  SatoruJetFinderProcessor::SatoruJetFinderProcessor()
35  : Processor("SatoruJetFinderProcessor")
36  {
37  _description="A multi algorithm jet finder";
38 
39  // general steering parameters
40 
41 
42  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
43  "InputCollection",
44  "Collection of reconstructed particles",
46  std::string("Unset") );
47 
48  registerOutputCollection( LCIO::RECONSTRUCTEDPARTICLE,
49  "OutputCollection",
50  "Name of collection with the found jets",
52  std::string("Unset") );
53 
54  registerOptionalParameter( "Debug",
55  "Set debug level",
56  _debug, 0 );
57 
58  registerOptionalParameter( "SuccessTag",
59  "Name of parameter added to event in case of successful jet finding",
61  std::string("JetsFound") );
62 
63 
64 
65  // mode steering parameters
66 
67  registerProcessorParameter( "Mode",
68  "Select predefined algorithms for jet finding"
69  "(or \"manual\")",
71  std::string("manual") );
72 
73 
74  registerOptionalParameter( "NJetRequested",
75  "Force everything to N jets"
76  "(if supported by current mode)",
77  _nJetRequested,4 );
78 
79  registerOptionalParameter( "YCut",
80  "YCut for jet finding algorithm"
81  "(if supported by current mode)",
82  _yCutParam, (float) 0.);
83 
84  registerOptionalParameter( "RCone",
85  "Half cone opening angle for cone jet finding "
86  "algorithm with variable number of jet",
87  _rConeParam, (float) 0.7);
88  registerOptionalParameter( "EpsCone",
89  "Jet energycut for cone jet finding algorithm "
90  "with variable number of jets",
91  _epsConeParam, (float) 7);
92 
93 
94  // steering parameters for manual mode
95  registerOptionalParameter( "GlobalMode",
96  "mode for manual alogorithm selection, "
97  "see documentation for details",
99  std::string("0A") );
100 
101  registerOptionalParameter( "Threshold",
102  "Threshold, if mode is \"manual\"",
103  _threshold, (float) 0.);
104 
105  registerOptionalParameter( "PrimaryJetFindingMode",
106  "Primary jet finding mode, if mode is \"manual\"",
108 
109  registerOptionalParameter( "SecondJetFindingMode",
110  "Secong jet finding mode, if mode is \"manual\"",
112 
113 
114  registerOptionalParameter( "MergingMode",
115  "Merging mode, if mode is \"manual\"",
116  _mergingMode, 0);
117 
118  registerOptionalParameter( "MergingThreshold",
119  "Merging threshold, if mode is \"manual\"",
120  _mergingThreshold, (float) 0.);
121 
122 
123  }
124 
125 
127 
128  streamlog_out(DEBUG4) << "SatoruJetFinderProcessor::init() " << name()
129  << std::endl
130  << " parameters: " << std::endl
131  << *parameters() ;
132 
133  // write success tag only if parameter "SuccessTag" has been set
134  _writeTag = parameters()->isParameterSet("SuccessTag");
135 
136  transform(_jetFindingMode.begin(),_jetFindingMode.end(),
137  _jetFindingMode.begin(),( int (*)(int) ) std::tolower );
138  streamlog_out(DEBUG4) << "jet finding mode:" << _jetFindingMode << endl;
139 
140 
141  //Fixme! catch wrong mode names
142  if (_jetFindingMode != "manual"){
143  if (_jetFindingMode=="durhamnjet"){
144  _globalMode="0B";
146  streamlog_out(DEBUG4) << "GlobalMode "<<_globalMode << " NJetRequested " << _nJetRequested << endl;
147  }else if(_jetFindingMode=="durhamycut"){
148  _globalMode="0A";
150  _yCut[0]=_yCutParam;
151  }else if(_jetFindingMode=="coneblanka"){
152  _nJetRequested = 0;
153  _threshold = 0.7;
155  _yCut[0]= 0.2;
156  _yCut[1]= 0.7;
157  _globalMode="0A";
158  }else if(_jetFindingMode=="satoru"){
159  _threshold = 0.01;
160  _nJetRequested= parameters()->getIntVal("NJetRequested");
162  _yCut[0] = 0.0;
163  _mergingMode = 2;
164  _mergingThreshold= 0.;
166  _globalMode = "2C";
167  }
168  }else{
169  // fixme: check whether values are set?
170  _yCut[0]=_yCutParam;
171 
172  // different meaning for _yCut[] in cone mode
174  {
175  _yCut[0]=_rConeParam;
176  _yCut[1]=_epsConeParam;
177  }
178 
179  }
180 
181  }
182 
184  // std::cout << "SatoruJetFinderProcessor::processRun() " << name()
185  // << " in run " << run->getRunNumber()
186  // << std::endl ;
187  }
188 
189  void SatoruJetFinderProcessor::processEvent( LCEvent * evt ) {
190  LCCollectionVec* JetsCol= new LCCollectionVec(LCIO::RECONSTRUCTEDPARTICLE);
191  // just a simple example
192  //first write the name of all collection included ...
193 
194  //cout << " start" << endl;
195  goSatoru(evt,JetsCol);
196  //cout << " after" << endl;
197 
198  }
199 
201 
202 
203  /* *********************************************************************** */
204 
205 
206 
207 
208  void SatoruJetFinderProcessor::goSatoru(LCEvent * evt,LCCollection* JetsCol){
209  putPartons(evt);
210  // WritePartons();
211  callSatoru(evt);
212  getJets(evt,JetsCol);
213  //GetPointerFromPartonToJet();
214  }
215 
216 
218  LCCollection* enflowcol=evt->getCollection(_inputCollection);
219  int nenflow = enflowcol->getNumberOfElements();
221  for ( int ienflow=0; ienflow<nenflow ; ienflow++){
222  ReconstructedParticle* enflow =
223  dynamic_cast<ReconstructedParticle*>
224  (enflowcol->getElementAt( ienflow ));
225  for(int i=0;i<3;i++){
226  _partonsWorkArray.Momentum[ienflow*4+i]=(enflow->getMomentum())[i]; }
227  _partonsWorkArray.Momentum[ienflow*4+3]=enflow->getEnergy();
228  }
229  }
230 
231 
232 
234  for (int iparton=0;iparton<_partonsWorkArray.NumberOfPartons;iparton++){
235  streamlog_out(DEBUG4) << "Px,Py,Pz,E: "<<
236  _partonsWorkArray.Momentum[iparton*4+0] << ", " <<
237  _partonsWorkArray.Momentum[iparton*4+1] << ", " <<
238  _partonsWorkArray.Momentum[iparton*4+2] << ", " <<
239  _partonsWorkArray.Momentum[iparton*4+3] << endl;
240  }
241  }
242 
243 
245  int DimensionOfInputArray=4;
246  int DimensionOfOutputArray=4;
247  int MaximalNumberOfJets=20;
248  // float YMinus,YPlus;
249  int IError;
250  int GlobalModusLength=_globalMode.length();
251 
252  _YMinus = -9999;
253  _YPlus = -9999;
254  syjkrn_(_globalMode.c_str(),
260  DimensionOfInputArray,_partonsWorkArray.Momentum,
261  MaximalNumberOfJets,
263  DimensionOfOutputArray,_jetsWorkArray.Momentum,
264  _YMinus,_YPlus,IError,GlobalModusLength);
265  }
266 
267  void SatoruJetFinderProcessor::getJets(LCEvent * evt,LCCollection* JetsCol){
268  LCCollection* enflowcol=evt->getCollection(_inputCollection);
269  streamlog_out(DEBUG4) << " " << endl;
270  streamlog_out(DEBUG4) << " number of jets found: " <<_jetsWorkArray.NumberOfJets << endl;
271  for( int ijets=0;ijets<_jetsWorkArray.NumberOfJets; ijets++){
272  ReconstructedParticleImpl* Jets = new ReconstructedParticleImpl;
273  float momentum[3],energy;
274  momentum[0]=_jetsWorkArray.Momentum[4*ijets+0];
275  momentum[1]=_jetsWorkArray.Momentum[4*ijets+1];
276  momentum[2]=_jetsWorkArray.Momentum[4*ijets+2];
277  energy=_jetsWorkArray.Momentum[4*ijets+3];
278  Jets->setMomentum(momentum);
279  Jets->setEnergy(energy);
280  // JL June 20, 2016: add jet mass!
281  double mass = energy*energy - momentum[0]*momentum[0] - momentum[1]*momentum[1] - momentum[2]*momentum[2];
282  mass = (mass > 0) ? sqrt(mass) : 0;
283  Jets->setMass(mass);
284  // end JL
285  for( int iobj=0;iobj<_partonsWorkArray.NumberOfPartons;iobj++){
286  if(_partonsWorkArray.PointerParticleToJets[iobj]==(ijets+1)){
287  ReconstructedParticle* enflow =
288  dynamic_cast<ReconstructedParticle*>
289  (enflowcol->getElementAt(iobj));
290  Jets->addParticle(enflow);
291  }
292  }
293  JetsCol->addElement(Jets);
294 
295  }
296 
297  JetsCol->parameters().setValue( "YMinus", _YMinus );
298  JetsCol->parameters().setValue( "YPlus" , _YPlus );
299 
300  evt->addCollection(JetsCol ,_outputCollection) ;
301  if ( _writeTag == true )
302  {
303  /// \todo fixme: check for requested number of Jets...
304  if ( JetsCol->getNumberOfElements() > 0 )
305  evt->parameters().setValue( _successTag, 1 );
306  else
307  evt->parameters().setValue( _successTag, 0 );
308  }
309 
310  }
311 
312 
315 
316 
317 } //namespace marlin
int PointerParticleToJets[450]
Definition: YThresh.h:25
void syjkrn_(const char *GlobalModus_, int &NJetRequested_, float &Threshold_, int &PrimaryJetFindingMode_, float *YCut_, int &MergingMode_, float &MergingThreshold_, int &SecondJetFindingMode_, int &NumberOfPartons_, int &DimensionOfInputArray_, float *PPartons_, int &MaximalNumberOfJets_, int &NJetsFound_, int *PointerParicleToJet_, int &DimensionOfOutputArray_, float *PJets_, float &YMinus_, float &YPlus_, int &IError_, int GlobalModusLenght_)
SatoruJetFinderProcessor aSatoruJetFinderProcessor
float Momentum[1200]
Definition: YThresh.h:24
virtual void end()
Called after data processing for clean up.
float Momentum[80]
Definition: YThresh.h:29
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
virtual void init()
Called at the begin of the job before anything is read.
A universal jetfinder module developed by Satoru Yamashita.
int NumberOfJets
Definition: YThresh.h:28
void getJets(LCEvent *evt, LCCollection *JetsCol)
void goSatoru(LCEvent *evt, LCCollection *JetsCol)
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
std::vector< LCCollection * > LCCollectionVec
Definition: SiStripClus.h:55
int NumberOfPartons
Definition: YThresh.h:23