All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
YThresh.cc
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------------------------------
2 // The YThresh module calculates the yThresh variable, which is the crossover value of the yCut jet finding
3 // variable from NMin to NMin+1 jets found using durhamycut. For example, if NMin=2 the yThresh variable is
4 // the value of yCut above which durhamycut returns 2 jets, below which it returns 3 jets. The value of
5 // yThresh will be stored as a parameter in the ReconstructedParticle collection with name y[NMin][NMin+1],
6 // ie y23 for NMin=2. SatoruJetFinder must be installed for this package to run.
7 // For questions/comments please email Ben Hooberman at benhooberman@berkeley.edu
8 //-------------------------------------------------------------------------------------------------------------
9 
10 #include "YThresh.h"
11 #include <iostream>
12 #include <math.h>
13 #include <EVENT/LCCollection.h>
14 #include <IMPL/LCCollectionVec.h>
15 #include <IMPL/ReconstructedParticleImpl.h>
16 #include <EVENT/MCParticle.h>
17 #include <EVENT/Cluster.h>
18 #include <EVENT/Track.h>
19 #include <UTIL/LCTOOLS.h>
20 #include <EVENT/ReconstructedParticle.h>
21 
22 using namespace lcio ;
23 using namespace marlin ;
24 using namespace std;
25 
27 
28 YThresh::YThresh() : Processor("YThresh") {
29 
30  // modify processor description
31  _description = "YThresh finds the crossover value of the yCut variable from NMin to NMin+1 jets found using durhamycut";
32 
33  // register steering parameters: name, description, class-variable, default value
34  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
35  "RecoParticleCollection",
36  "Name of the input ReconstructedParticle collection",
38  std::string("RecoParticles"));
39 
40  registerProcessorParameter("NMin",
41  "min number of jets, ie. NMin=2 will give y23 variable",
42  _nMin,
43  int(2));
44 
45  registerProcessorParameter("PrintOutput",
46  "toggle print text output",
47  _output,
48  int(0));
49 
50  registerProcessorParameter("NIterations",
51  "number of iterations",
52  _nIter,
53  int(20));
54 
55  registerProcessorParameter("NMinParticles",
56  "min num particles for ythresh calculation",
58  int(3));
59 
60  registerProcessorParameter("YStart",
61  "starting value for yCut",
62  _yStart,
63  float(0.1));
64 
65 }
66 
67 void YThresh::init() {
68 
69  printParameters() ;
70 
71  _nRun = 0 ;
72  _nEvt = 0 ;
73 
74  _globalMode="0A";
76 
77 }
78 
79 void YThresh::processRunHeader( LCRunHeader* run) {
80  _nRun++ ;
81 }
82 
83 void YThresh::processEvent( LCEvent * evt ) {
84 
85  try{
86 
87  LCCollection * recoColl=evt->getCollection(_inputCollection.c_str());
88  _nRecoParticles=recoColl->getNumberOfElements();
89 
90  float ymax=0;
91 
93 
94  putPartons(evt);
95 
96  //Phase 1: find yCut value for which NJets<=NMin
97  //start with yCut=YStart, increase yCut until this condition is satisfied
98  _yCut[0]=_yStart;
99 
100  do{
101  callSatoru(evt);
102  if(_jetsWorkArray.NumberOfJets<=_nMin) break;
103  else _yCut[0]=_yCut[0]*2;
104  }while(true);
105 
106  //Phase 2: Start with yCut value determined in Phase 1 (ymax)
107  //Find yThresh value between 0,ymax satisfying NJets=NMin for yCut>yThresh, NJets=NMin+1 for yCut<yThresh
108  ymax=(float)_yCut[0];
109  _yCut[0]=_yCut[0]/2;
110 
111  for(int i=1;i<=_nIter;i++){
112  callSatoru(evt);
113  if(_jetsWorkArray.NumberOfJets>_nMin) _yCut[0]+=ymax/(pow(2.,i+1));
114  else _yCut[0]-=ymax/(pow(2.,i+1));
115  }
116  }
117  else{
118  streamlog_out( WARNING ) <<"YThresh Error "<<_nRecoParticles<<" particles<"<<_nMinParticles<<endl;
119  _yCut[0]=-1.;
120  }
121 
122  //Store yThresh value with name y[NMin][NMin+1] (ie y23 for NMin=2) as parameter in RecoParticleCollection
123  stringstream tempStream;
124  tempStream<<'y'<<_nMin<<_nMin+1;
125  string yname=tempStream.str();
126  recoColl->parameters().setValue(yname.c_str(),_yCut[0]);
127 
128  if(_output>0)
129  streamlog_out( DEBUG4 ) <<"YThresh Event "<<_nEvt<<" "<<yname<<"="<<_yCut[0]<<endl;
130 
131  if(_yCut[0]>=0){
132 
133  //Check to make sure that NJets=NMin for yCut=yThresh+epsilon, NJets=NMin+1 for yCut=yThresh-epsilon
134  float epsilon=ymax/(pow(2.,_nIter));
135 
136  _yCut[0]+=epsilon;
137  callSatoru(evt);
139 
140  _yCut[0]-=2*epsilon;
141  callSatoru(evt);
143 
144  if(!(n1==_nMin && n2==_nMin+1))
145  streamlog_out( WARNING ) <<"ERROR INCORRECT YTHRESH VALUE OBTAINED"<<endl;
146 
147  }
148 
149  }catch(DataNotAvailableException &e){
150  streamlog_out( WARNING ) << "YThresh: cannot find collection "<<_inputCollection.c_str()<<endl;
151  }
152 
153  _nEvt ++ ;
154 }
155 
156 void YThresh::putPartons(LCEvent * evt){
157 
158  LCCollection* enflowcol=evt->getCollection(_inputCollection);
159  int nenflow = enflowcol->getNumberOfElements();
161  for ( int ienflow=0; ienflow<nenflow ; ienflow++){
162  ReconstructedParticle* enflow =
163  dynamic_cast<ReconstructedParticle*>
164  (enflowcol->getElementAt( ienflow ));
165  for(int i=0;i<3;i++){
166  _partonsWorkArray.Momentum[ienflow*4+i]=(enflow->getMomentum())[i]; }
167  _partonsWorkArray.Momentum[ienflow*4+3]=enflow->getEnergy();
168  }
169 }
170 
171 void YThresh::callSatoru(LCEvent * evt){
172 
173  int DimensionOfInputArray=4;
174  int DimensionOfOutputArray=4;
175  int MaximalNumberOfJets=20;
176  float YMinus,YPlus;
177  int IError;
178  int GlobalModusLength=_globalMode.length();
179 
180  syjkrn_(_globalMode.c_str(),
182  _threshold,
184  _yCut,
185  _mergingMode,
189  DimensionOfInputArray,
191  MaximalNumberOfJets,
194  DimensionOfOutputArray,
196  YMinus,
197  YPlus,
198  IError,
199  GlobalModusLength);
200 
201 
202 }
203 
204 void YThresh::check( LCEvent * evt ) {
205  // nothing to check here - could be used to fill checkplots in reconstruction processor
206 }
207 
208 
209 void YThresh::end(){
210 
211  streamlog_out( DEBUG4 ) << "YThresh::end() " << name()
212  << " processed " << _nEvt << " events in " << _nRun << " runs "
213  << std::endl ;
214 
215 }
int _primaryJetFindingMode
Definition: YThresh.h:87
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_)
float _yCut[2]
Definition: YThresh.h:91
float _threshold
Definition: YThresh.h:86
virtual void processRunHeader(LCRunHeader *run)
Definition: YThresh.cc:79
float Momentum[1200]
Definition: YThresh.h:24
float Momentum[80]
Definition: YThresh.h:29
virtual void init()
Definition: YThresh.cc:67
SatoruJetsArray _jetsWorkArray
Definition: YThresh.h:81
int _nEvt
Definition: YThresh.h:75
int _output
Definition: YThresh.h:84
YThresh()
Definition: YThresh.cc:28
float _yStart
Definition: YThresh.h:95
int _nJetRequested
Definition: YThresh.h:85
int _nRun
Definition: YThresh.h:75
std::string _inputCollection
Definition: YThresh.h:78
int NumberOfJets
Definition: YThresh.h:28
virtual void end()
Definition: YThresh.cc:209
virtual void processEvent(LCEvent *evt)
Definition: YThresh.cc:83
int _nMinParticles
Definition: YThresh.h:83
int _mergingMode
Definition: YThresh.h:92
SatoruPartonArray _partonsWorkArray
Definition: YThresh.h:80
static const float e
std::string _globalMode
Definition: YThresh.h:82
YThresh aYThresh
Definition: YThresh.cc:26
void putPartons(LCEvent *evt)
Definition: YThresh.cc:156
int _nMin
Definition: YThresh.h:77
void callSatoru(LCEvent *evt)
Definition: YThresh.cc:171
int _nIter
Definition: YThresh.h:77
int _secondJetFindingMode
Definition: YThresh.h:94
virtual void check(LCEvent *evt)
Definition: YThresh.cc:204
int NumberOfPartons
Definition: YThresh.h:23
int _nRecoParticles
Definition: YThresh.h:76
float _mergingThreshold
Definition: YThresh.h:93