stablejet is hosted by Hepforge, IPPP Durham
StableJet
stableTest.cc
1 //a program to analyze jet stability
4 
5 
6 #include <iostream>
7 #include <fstream>
8 #include <cstdlib>
9 #include <unistd.h>
10 #include <vector>
11 #include <algorithm>
12 
13 #include "fastjet/ClusterSequence.hh"
14 #include "fastjet/PseudoJet.hh"
15 
16 #include "JetStabilityDefs.h"
17 #include "JetStability.h"
18 #include "DiffusionDistFastJet.h"
19 #include "SimpleSmear.h"
20 #include "SimpleEvent.hh"
21 #include "SimulatedEvent.hh"
22 #include "QCDandCmsLikeSmear.h"
23 
24 #include "PythiaJetGun.hh"
25 
26 #include "geners/BinaryFileArchive.hh"
27 #include "geners/Reference.hh"
28 
29 
30 //-------- teypdefs and stuff -------------------
31 using namespace gs;
32 
33 bool oddSort ( const std::pair<unsigned,double> & a, const std::pair<unsigned,double> &b ) {
34  return a.second > b.second;
35 }
36 
37 
38 void printUsage(int argc, char **argv ) {
39  if ( argv[0] )
40  std::cout << argv[0] << " -a archive [-A nEvents] [-C nCycles] [-o outputFile] [-q fuzzyFile] [-m scanMin] [-M scanMax] [-n nScan] [-f fixedVar] [-E (set exclusive)] [-d distCut] [-N nJets] [-r R]" << std::endl;
41 }
42 
43 
44 int main (int argc, char **argv ) {
45 
46 
47  // options loaded from command line options
48  char *archiveName = 0;
49  unsigned nEvents = 0;
50  char *outFile = 0;
51  char *fuzzyFile = 0;
52  bool exclusive = false;
53  double distCut=1.;
54  unsigned N = 2U;
55  double R = 0.5;
56  unsigned nCycles=100;
57 
58  double scanMin = 0.1;
59  double scanMax = 1.;
60  unsigned scanN = 10;
61 
62  double fixed = 1.;
63 
64  //double qcdCutOff = exp(3.);
65  //double qcdCutOff = 0.01;
66  double qcdCutOff = 0.705796; // 75% quantile of dist for FluctuateQCD2_geom
67  bool doFlatPhaseSpace = true;
68 
69  int c;
70 
71  while (( c = getopt(argc,argv,"a:A:o:r:C:N:m:M:n:f:Ed:q:")) != -1 )
72  switch (c) {
73  case 'a':
74  archiveName = optarg;
75  break;
76  case 'A':
77  nEvents = atoi(optarg);
78  break;
79  case 'N':
80  N = atoi(optarg);
81  break;
82  case 'r':
83  R = atof(optarg);
84  break;
85  case 'o':
86  outFile = optarg;
87  break;
88  case 'C':
89  nCycles = atoi(optarg);
90  break;
91  case 'm':
92  scanMin = atof(optarg);
93  break;
94  case 'M':
95  scanMax = atof(optarg);
96  break;
97  case 'n':
98  scanN = atoi(optarg);
99  break;
100  case 'f':
101  fixed = atof(optarg);
102  break;
103  case 'E':
104  exclusive = true;
105  break;
106  case 'd':
107  distCut = atof(optarg);
108  break;
109  case 'q':
110  fuzzyFile = optarg;
111  break;
112  default:
113  printUsage(argc,argv);
114  return 0;
115  }
116 
117  //---------------- the program ----------------------------
118 
119  // stability output stream
120  std::ofstream out;
121  if ( outFile )
122  out.open(outFile,std::ios_base::out);
123 
124  // fuzzyness output stream
125  std::ofstream fout;
126  if ( fuzzyFile )
127  fout.open(fuzzyFile,std::ios_base::out);
128 
129 
130  std::cout << "Opening archive.......";
131  // Open the archive
132  BinaryFileArchive ar(archiveName, "r");
133  if (!ar.isOpen())
134  {
135  std::cerr << ar.error() << std::endl;
136  return 1;
137  }
138  std::cout << "done" << std::endl;
139 
140  // Find all events in the archive with the given category and process them
141  std::cout << "Finding events.......";
142  Reference<SimulatedEvent> ref(ar, Regex(".*"), "dijet");
143  if ( !nEvents ) nEvents = ref.size();
144  std::cout << "done found: " << ref.size() << " events" << std::endl;
145 
146  // fastjet jet definition
147  stab::DiffusionDistFastJet fjDiffDist(R);
148  stab::JetStability jstab((fastjet::JetDefinition*)&fjDiffDist);
149  jstab.setScan(scanN,scanMin,scanMax);
150  jstab.setNCycles(nCycles);
151 
152  // simple smearing agent
153  stab::SimpleSmear smear(0.087,0.15);
154  //stab::QCDandCmsLikeSmear smear;
155 
156 
157  SimulatedEvent ev;
158  // loop over so many events
159  for ( unsigned evNum=0; evNum != nEvents; evNum++ ) {
160 
161  stab::Event event;
162  stab::StabilityEventInfo evInfo;
163 
164  // restore event evNum from archive
165  ref.restore(evNum, &ev);
166  SimpleEvent & evs = ev.sim;
167  const unsigned nSimulatedJets = evs.size();
168  for ( unsigned j=0; j != nSimulatedJets; j++ ) {
169  const std::vector<PythiaJetGun::Particle> & constituents = evs[j].jetParticles;
170  const unsigned nConstituents = constituents.size();
171  for ( unsigned c=0; c != nConstituents; c++ ) {
172  const PythiaJetGun::Particle & part = constituents[c];
173  const rk::P4 & p4 = part.p4();
174  const geom3::Vector3 & mom = p4.momentum();
175  stab::PseudoJet pj(mom.x(),mom.y(),mom.z(),p4.e());
176  //stab::StabilityUserInfo *pjInfo = new stab::StabilityUserInfo(part.code(),part.charge());
177  //pj.set_user_info( pjInfo );
178  evInfo.push_back( stab::StabilityUserInfo(part.code(),part.charge()) );
179  event.push_back( pj );
180  }
181  }
182 
183  jstab.reset(event,evInfo);
184  jstab.run(smear);
185 
186  }
187 
188  const std::vector<std::vector<double> > & stability = jstab.pairwiseRandStability();
189  const std::vector<std::vector<double> > & fuzziness = jstab.fuzzinessNJet();
190 
191  const double sMax = jstab.scanMax();
192  const double sMin = jstab.scanMin();
193  const unsigned sN = jstab.nScan();
194  const double dScan = (sMax-sMin)/sN;
195 
196  const unsigned nStab = stability.size();
197  assert( nStab == sN );
198  assert( stability.size() == fuzziness.size() );
199  for ( unsigned s=0; s != nStab; s++ ) {
200  const double dCut = sMin + dScan*s;
201  const std::vector<double> & stabPoints = stability[s];
202  const std::vector<double> & fuzzPoints = fuzziness[s];
203  const unsigned nPoints = stabPoints.size();
204  long double avg = 0.L;
205  long double favg = 0.L;
206  for ( unsigned p=0; p != nPoints; p++ ) {
207  avg += stabPoints[p];
208  favg += fuzzPoints[p];
209  }
210  avg /= nPoints;
211  favg /= nPoints;
212  out << dCut << " " << avg << std::endl;
213  fout << dCut << " " << favg << std::endl;
214  }
215 
216 return 0;
217 }