9 #include <EVENT/LCCollection.h>
10 #include <EVENT/LCIO.h>
11 #include <EVENT/MCParticle.h>
12 #include <IMPL/LCCollectionVec.h>
13 #include <IMPL/ReconstructedParticleImpl.h>
14 #include <IMPL/LCTOOLS.h>
17 using namespace lcio ;
18 using namespace marlin ;
26 : Processor(
"ThrustReconstruction") {
29 _description =
"Calculates thrust axis and thrust value of event using different algorithms" ;
34 registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
35 "inputCollectionName" ,
36 "Name of collection of reconstructed particles used for thrust reconstruction" ,
38 std::string(
"SelectedReconstructedParticle") ) ;
40 registerProcessorParameter(
"typeOfThrustFinder" ,
41 "Type of thrust reconstruction algorithm to be used:\n#\t1 : Tasso algorithm\n#\t2 : JetSet algorithm" ,
53 ifstream rndcfgfile(
filename.c_str() );
57 myrnd.setSeeds(&ss,4);
78 if (
_inParVec->getTypeName()!=LCIO::RECONSTRUCTEDPARTICLE)
80 std::stringstream errorMsg;
81 errorMsg <<
"\nProcessor: ThrustReconstruction \n" <<
82 "Collection is of wrong type (" <<
_inParVec->getTypeName() <<
83 "). Processor requires collection tpye " << LCIO::RECONSTRUCTEDPARTICLE
85 throw Exception(errorMsg.str());
91 for (
int n=0;n<
_inParVec->getNumberOfElements() ;n++)
93 ReconstructedParticle* aPart =
dynamic_cast<ReconstructedParticle*
>(
_inParVec->getElementAt(n) );
95 throw Exception( std::string(
"Particle in ReconstructedParticle collection is not ReconstructedParticle") );
97 const double* partMom = aPart->getMomentum();
98 _partMom.push_back( Hep3Vector(partMom[0], partMom[1], partMom[2]) );
133 _inParVec->parameters().setValues(
"principleThrustAxis",thrax);
143 _inParVec->parameters().setValues(
"majorThrustAxis",thrax);
151 _inParVec->parameters().setValues(
"minorThrustAxis",thrax);
155 _inParVec->parameters().setValue(
"Oblateness",Oblateness);
158 _inParVec->parameters().setValue(
"Oblateness",-1);
189 else if (
_inParVec->getNumberOfElements()==1)
196 Hep3Vector ptm, ptot, pt;
197 std::vector<Hep3Vector> pc;
198 float sp,u, pp, tmax, t;
201 for (
int i=0;i <
_inParVec->getNumberOfElements();i++)
208 for (
int m = 0;
m <= 2;
m++ )
211 for (
int k = 1;
k <
_inParVec->getNumberOfElements();
k++)
213 for (
int j = 0; j <=
k-1;j++)
218 for (
int l = 0; l <
_inParVec->getNumberOfElements(); l++)
236 for (
int m = 0;
m <= 3;
m++ )
239 if (t <= tmax)
continue;
267 const int nwork=11,iFastMax = 4,iGood=2;
268 const float dConv=0.0001;
270 double theta=0,phi=0;
271 double thp,thps,tds,tmax,dOblateness;
272 vector<Hep3Vector> TAxes(3),Fast(iFastMax+1),Workv(nwork);
273 vector<double> Workf(nwork),dThrust(3);
274 Hep3Vector tdi,tpr,mytest;
277 for (
unsigned int i=0; i <
_partMom.size(); i++)
282 for (
int pass=0; pass <= 1; pass++ )
286 phi = TAxes[0].phi();
287 theta = TAxes[0].theta();
288 for (
unsigned int i = 0;i <
_partMom.size(); i++)
300 for (
unsigned int i = 0; i < Fast.size(); i++ )
303 for (
unsigned int i = 0; i <
_partMom.size(); i++ )
305 for (
int ifast = iFastMax -1; ifast >= 0 ; ifast-- )
307 if (
_partMom[i].mag2() > Fast[ifast].mag2() )
309 Fast[ifast + 1] = Fast[ifast];
310 if (ifast == 0) Fast[ifast] =
_partMom[i];
322 for (
unsigned int iw = 0; iw < Workv.size(); iw++ )
326 int p = (int)
min( iFastMax,
_partMom.size() ) - 1 ;
328 for (
int n = 0; n < nc; n++ )
331 for (
int i = 0; i <
min(iFastMax,nc) ; i++)
333 if ( (1 << (i+1)) * ( (n + (1<<i)) / (1<<(i+1)) ) >= n+1)
334 { sgn = -1;}
else {sgn = 1;}
336 if (pass==1) tdi.setZ(0);
339 for (
int iw = (
int)
min(n,9); iw >= 0; iw-- )
343 Workf[iw+1] = Workf[iw];
344 Workv[iw+1] = Workv[iw];
346 { Workv[iw] = tdi; Workf[iw] = tds;}
360 for (
int iw = 0; iw <
min(nc,10) && nagree < iGood; iw++ )
364 while ( thp > thps + dConv )
368 { tdi = Workv[iw]; }
else { tdi=tpr; }
370 for (
unsigned int i = 0; i <
_partMom.size(); i++ )
374 if (pass == 1) { tpr.setZ(0); }
376 thp = tpr.mag()/tmax;
380 if ( thp < dThrust[pass] - dConv )
continue;
381 if ( thp > dThrust[pass] + dConv )
387 TAxes[pass] = sgn*tpr/(tmax*thp);
395 if (
myrnd.flat() > 0.49999)
396 {sgn = 1;}
else {sgn=-1;}
397 TAxes[2].set( -sgn*TAxes[1].y(), sgn*TAxes[1].x(), 0);
399 for (
unsigned int i = 0; i <
_partMom.size(); i++ )
401 thp += fabs(TAxes[2].dot(
_partMom[i]) );
403 dThrust[2] = thp/tmax;
406 for (
unsigned int i = 0;i < TAxes.size(); i++)
408 TAxes[i].rotateY(theta);
409 TAxes[i].rotateZ(phi);
411 dOblateness = dThrust[1] - dThrust[2];
429 {
return -fabs(a); }
else {
return fabs(a); }
435 {
return a; }
else {
return b; }
std::vector< Hep3Vector > _partMom
Thrust processor for marlin.
Hep3Vector _majorThrustAxis
virtual void init()
Called at the begin of the job before anything is read.
ThrustReconstruction aThrustReconstruction
virtual void processRunHeader(LCRunHeader *run)
Called for every run.
double min(double a, double b)
std::string _inputCollectionName
Input collection name.
double sign(double a, double b)
Hep3Vector _principleThrustAxis
virtual void end()
Called after data processing for clean up.
virtual void processEvent(LCEvent *evt)
Called for every event - the working horse.
Hep3Vector _minorThrustAxis
float _principleThrustValue