SISCone  2.0.5
examples/test.cpp
00001 
00002 // File: test.cpp                                                            //
00003 // Description: example program that implements tests with random particles  //
00004 //              and output various informations                              //
00005 //                                                                           //
00006 // Note: for a usage example of SISCone, we advise looking at main.cpp       //
00007 //       or http://projects.hepforge.org/siscone/usage.html                  //
00008 //                                                                           //
00009 // This file is part of the SISCone project.                                 //
00010 // For more details, see http://projects.hepforge.org/siscone                //
00011 //                                                                           //
00012 // Copyright (c) 2006 Gavin Salam and Gregory Soyez                          //
00013 //                                                                           //
00014 // This program is free software; you can redistribute it and/or modify      //
00015 // it under the terms of the GNU General Public License as published by      //
00016 // the Free Software Foundation; either version 2 of the License, or         //
00017 // (at your option) any later version.                                       //
00018 //                                                                           //
00019 // This program is distributed in the hope that it will be useful,           //
00020 // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
00021 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
00022 // GNU General Public License for more details.                              //
00023 //                                                                           //
00024 // You should have received a copy of the GNU General Public License         //
00025 // along with this program; if not, write to the Free Software               //
00026 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA //
00027 //                                                                           //
00028 // $Revision:: 324                                                          $//
00029 // $Date:: 2011-11-16 12:10:27 +0100 (Wed, 16 Nov 2011)                     $//
00031 
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <time.h>
00035 #include <sys/time.h>
00036 #include <iostream>
00037 #include <math.h>
00038 
00039 #include "siscone/momentum.h"
00040 #include "siscone/siscone.h"
00041 
00042 #define N_default  500
00043 #define R          0.7
00044 #define F          0.75
00045 
00046 using namespace std;
00047 using namespace siscone;
00048 
00049 int main(int argc, char* argv[]){
00050   vector<Cmomentum> particles;
00051   Cmomentum *v;
00052   double phi=0, eta=0, pt=1;
00053   unsigned int N;
00054 
00055   unsigned int i;
00056   FILE *flux;
00057 
00058   if (argc==1){
00059     //cout << "using default number of particles" << endl;
00060     N = N_default;
00061   } else {
00062     sscanf(argv[1], "%u", &N);
00063     //cout << "using " << N << " particles" << endl;
00064   }    
00065 
00066   // Initialise random number generator
00067   timeval timestamp;
00068   gettimeofday(&timestamp, NULL);
00069   srand(timestamp.tv_usec);
00070 
00071   // build particle list
00072   cout << "build particle list" << endl;
00073   flux = fopen("particles.dat", "w+");
00074   for (i=0;i<N;i++){
00075     // uniform eta between -5 and 5
00076     eta = -5.0+10.0*rand()/(RAND_MAX+1.0);
00077 
00078     // uniform azimuth
00079     phi = 2.0*M_PI*rand()/(RAND_MAX+1.0);
00080 
00081     // logarithmically uniform pt (between 1e-3 and 100 GeV)
00082     pt = exp(log(0.001)+log(1e5)*rand()/(RAND_MAX+1.0));
00083 
00084     particles.push_back(Cmomentum(pt*cos(phi), pt*sin(phi), pt*sinh(eta), pt*cosh(eta)));
00085 
00086     fprintf(flux, "%e\t%e\t%e\n",   particles[i].eta, particles[i].phi,particles[i].perp());
00087   }
00088   fclose(flux);
00089 
00090   cout << "SISCone: initialise engine" << endl;
00091   Csiscone siscone;
00092 
00093   // cluster the event
00094   cout << "cluster the event" << endl;
00095   siscone.compute_jets(particles, R, F);
00096 
00097 #ifdef DEBUG_STABLE_CONES 
00098   cout << "hash_candidates=" << siscone.nb_hash_cones_total << " in " << siscone.nb_hash_occupied_total << " cells" << endl;
00099 #endif
00100   // save list of stable cones
00101   cout << "save stable cone results:" << endl;
00102   unsigned int pass;
00103   flux = fopen("protocones.dat", "w+");
00104   for (pass=0;pass<siscone.protocones_list.size();pass++){
00105     cout << "    pass " << pass << " found " << siscone.protocones_list[pass].size()
00106          << " stable cones" << endl;
00107     fprintf(flux, "# pass %d: %u stable cones\n", pass, 
00108             (unsigned int) siscone.protocones_list[pass].size());
00109     for (i=0;i<siscone.protocones_list[pass].size();i++){
00110       v = &(siscone.protocones_list[pass][i]);
00111       fprintf(flux, "%e\t%e\t%e\n", v->eta, v->phi, v->perp());
00112     }
00113   }
00114   fclose(flux);
00115   
00116   cout << "bye..." << endl;
00117 
00118   return 0;
00119 }
The SISCone project has been developed by Gavin Salam and Gregory Soyez
Documentation generated on Mon Jun 4 2012 18:23:38 for SISCone by  Doxygen 1.7.6.1