All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
QuarkJetPairing.cc
Go to the documentation of this file.
1 #include "QuarkJetPairing.h"
2 
3 #include <vector>
4 #include <iostream>
5 #include <string>
6 
7 #include <EVENT/LCCollection.h>
8 #include <UTIL/LCTOOLS.h>
9 #include <UTIL/Operators.h>
10 
11 #define _USE_MATH_DEFINES
12 
13 // ----- include for verbosity dependend logging ---------
14 #include "marlin/VerbosityLevels.h"
15 #include <TROOT.h>
16 #include <TFile.h>
17 #include <TH1.h>
18 #include <TH2.h>
19 #include "TNtupleD.h"
20 #include <TProfile.h>
21 #include "TMVA/Reader.h"
22 #include <TMath.h>
23 #include <TLorentzVector.h>
24 #include <CLHEP/Vector/LorentzVector.h>
25 #include <TVector3.h>
26 #include <cmath>
27 #include <math.h>
28 
29 #include "UTIL/LCRelationNavigator.h"
30 #include "EVENT/LCIO.h"
31 #include "marlin/Exceptions.h"
32 
33 #include <EVENT/MCParticle.h>
34 #include <EVENT/SimTrackerHit.h>
35 #include <EVENT/ReconstructedParticle.h>
36 #include "IMPL/ReconstructedParticleImpl.h"
37 #include "IMPL/LCCollectionVec.h"
38 //#include <root/TLorentzVector.h>
39 #include "IMPL/LCCollectionVec.h"
40 
41 
42 using namespace lcio ;
43 using namespace marlin ;
44 using namespace CLHEP ;
45 using namespace std;
46 using namespace TMVA;
47 
49 
50 QuarkJetPairing::QuarkJetPairing() : Processor("QuarkJetPairing") {
51  // modify processor description
52  _description = "" ;
53  // register steering parameters: name, description, class-variable, default value
54 
55  registerInputCollection( LCIO::RECONSTRUCTEDPARTICLE,
56  "InputJetCollection" ,
57  "Input collection of jets",
59  std::string("NewJets"));
60 
61 
62  registerInputCollection( LCIO::MCPARTICLE,
63  "InputMCPCollection" ,
64  "Input collection of MCParticles",
66  std::string("MCParticlesSkimmed"));
67 
68 }
69 
70 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
71 
73  streamlog_out(DEBUG) << " " << std::endl ;
74  printParameters() ;
75 
76  _nRun = 0;
77  _nEvt = 0;
78 
79  /////////////////////////creates outputfile//////////////////////////
80  // TFile *outRootFile = new TFile ("output.root", "RECREATE");
81  /////////////////////////////////////////////////////////////////////
82 
83 
84 
85 }
86 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
87 
88 void QuarkJetPairing::processRunHeader( LCRunHeader* /*run*/) {
89 
90  _nRun++;
91 }
92 
93 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
94 
95 void QuarkJetPairing::processEvent( LCEvent * evt ) {
96 
97 
98 
99  _nEvt++;
100  ///////////////////////////////////frequency distribution////////////////////////////////////
101  static int counter_events=0;
102  static int counter_alpha = 0;
103  static int counter_energy = 0;
104  static int counter_theta = 0;
105 
106  counter_events++;
107  //////////////////////////////////////////////////set variables to zero/////////////////////////////////////////////////
108 
109  float energy = 0;
110 
111  float jet_ene[4];
112  float quark_ene[4];
113 
114  float jet_theta[4];
115  float quark_theta[4];
116 
117  float jet_px[4];
118  float quark_px[4];
119 
120  float jet_py[4];
121  float quark_py[4];
122 
123  float jet_pz[4];
124  float quark_pz[4];
125 
126  float jet_ptot[4];
127  float quark_ptot[4];
128 
129  int quark[4][24];
130  int jet[4][24];
131 
132  for(int i=0; i<4; i++){
133 
134  jet_ene[i]=0;
135  quark_ene[i]=0;
136 
137  jet_theta[i]=0;
138  quark_theta[i]=0;
139 
140  jet_px[i]=0;
141  quark_px[i]=0;
142  jet_py[i]=0;
143  quark_py[i]=0;
144  jet_pz[i]=0;
145  quark_pz[i]=0;
146  jet_ptot[i]=0;
147  quark_ptot[i]=0;
148  }
149 
150 
151  ///////////////////////////////JET COLLECTION//////////////////////////////////
152 
153  LCCollection* jetcol = evt->getCollection( _inputJetCollection ) ;
154 
155 
156  if (jetcol != 0) {
157 
158  int nJETS = jetcol->getNumberOfElements() ;
159 
160  if (nJETS != 4) return;
161 
162  for(int i=0; i< nJETS ; i++){
163 
164 
165  ReconstructedParticle* j = dynamic_cast<ReconstructedParticle*>( jetcol->getElementAt( i ) ) ;
166 
167  if (j) {
168 
169  jet_px[i]=j->getMomentum()[0];
170  jet_py[i]=j->getMomentum()[1];
171  jet_pz[i]=j->getMomentum()[2];
172  jet_ene[i]=j->getEnergy();
173 
174  }
175  jet_ptot[i]=sqrt(pow(jet_px[i], 2)+pow(jet_py[i], 2)+pow(jet_pz[i], 2));
176  }
177  }
178 
179  ////////////////////////////MCParticle Collection/////////////////////////////
180 
181  LCCollection* mcpcol = evt->getCollection( _inputMCPCollection ) ;
182  if (mcpcol != 0) {
183 
184  for(int e=6; e<10 ; e++){
185 
186  MCParticle* q = dynamic_cast<MCParticle*>( mcpcol->getElementAt( e ) ) ;
187 
188  if (q) {
189 
190  quark_px[e-6]=q->getMomentum()[0];
191  quark_py[e-6]=q->getMomentum()[1];
192  quark_pz[e-6]=q->getMomentum()[2];
193  quark_ene[e-6]=q->getEnergy();
194  }
195  quark_ptot[e-6]=sqrt(pow(quark_px[e-6], 2)+pow(quark_py[e-6], 2)+pow(quark_pz[e-6], 2));
196  }
197  }
198 
199  /////////////////////////////////////////////set variables////////////////////////////////////////////////
200 
201  ipair = 0;
202  iperm = 0;
203 
204  int counter_jets = 0;
205 
206  Float_t theta[4];
207 
208  Float_t alpha[24];
209  Float_t alpha_min = 9999;
210  int iperm_min = 0;
211 
212  //////////////////////////////////////////permutation algorithm///////////////////////////////////////////
213 
214  for(int i=0; i<4; i++){
215  energy+=quark_ene[i];
216  }
217 
218  if(energy >495){
219  counter_energy++;
220 
221  for (int index1=0; index1<4; index1++) {
222  for (int index2=0; index2<4; index2++) {
223  if (index2 != index1) {
224  for (int index3=0; index3<4; index3++) {
225  if ((index3 != index2) && (index3 != index1)) {
226  for (int index4=0; index4<4; index4++) {
227  if ((index4 != index3) && (index4 != index2) && (index4 != index1)) {
228  quark[0][iperm]=index1;
229  quark[1][iperm]=index2;
230  quark[2][iperm]=index3;
231  quark[3][iperm]=index4;
232  jet[0][iperm]=0;
233  jet[1][iperm]=1;
234  jet[2][iperm]=2;
235  jet[3][iperm]=3;
236  iperm++;
237  }
238  }
239  }
240  }
241  }
242  }
243  }
244 
245  for(int n = 0; n < iperm; n++){
246  alpha[n] = 0;
247  for (int ijet=0; ijet<4; ijet++) {
248  alpha[n]+= acos(((jet_px[jet[ijet][n]]*quark_px[quark[ijet][n]])+(jet_py[jet[ijet][n]]*quark_py[quark[ijet][n]])+(jet_pz[jet[ijet][n]]*quark_pz[quark[ijet][n]]))/(jet_ptot[jet[ijet][n]]*quark_ptot[quark[ijet][n]]));
249  }
250  if(alpha[n] < alpha_min){
251  alpha_min = alpha[n];
252  iperm_min=n;
253  }
254  alpha[n]=0;
255  }
256 
257  // message<DEBUG>( log() << "alpha_min: " << alpha_min ) ;
258 
259  if(alpha_min < 1){
260  counter_alpha++;
261 
262  for(int ijet = 0; ijet<4; ijet++){
263 
264  //////////////////////////////////////////// Determination of theta //////////////////////////
265 
266  theta[ijet]=0;
267  quark_theta[ijet] = atan((sqrt((pow(quark_px[quark[ijet][iperm_min]],2))+(pow(quark_py[quark[ijet][iperm_min]],2))))/quark_pz[quark[ijet][iperm_min]]);
268  jet_theta[ijet] = atan((sqrt((pow(jet_px[jet[ijet][iperm_min]],2))+(pow(jet_py[jet[ijet][iperm_min]],2))))/jet_pz[jet[ijet][iperm_min]]);
269  if(quark_theta[ijet] < 0){
270  quark_theta[ijet] = M_PI+quark_theta[ijet];
271  }
272  if(jet_theta[ijet] < 0){
273  jet_theta[ijet] = M_PI+jet_theta[ijet];
274  }
275 
276  if(((quark_theta[ijet] > 0.14) && (quark_theta[ijet]<3)) &&((jet_theta[ijet] > 0.14) && (jet_theta[ijet]<3)) ){
277  counter_jets++;
278 
279  }
280  else{
281  throw marlin::SkipEventException(this);
282  counter_jets = 0;
283  }
284  }
285  }
286  else{
287  throw marlin::SkipEventException(this);
288  }
289  }
290  else{
291  throw marlin::SkipEventException(this);
292  }
293 
294  if(counter_jets == 4){
295 
296  counter_theta++;
297  }
298 
299  streamlog_out(DEBUG) << "Counter_events: " << counter_events << std::endl ;
300  streamlog_out(DEBUG) << "Counter_energy: " << counter_energy << std::endl ;
301  streamlog_out(DEBUG) << "Counter_alpha: " << counter_alpha << std::endl ;
302  streamlog_out(DEBUG) << "Counter_theta: " << counter_theta << std::endl ;
303 
304  counter_jets = 0;
305  streamlog_out(DEBUG) << "Event: " << evt->getEventNumber() << std::endl ;
306 
307 
308 }
309 
310 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
311 
312 void QuarkJetPairing::check( LCEvent * /*evt*/ ) {
313 
314 
315 }
316 
317 
318 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
319 
321 
322  std::cout << "Finish run" <<std::endl;
323 }
virtual void init()
QuarkJetPairing aQuarkJetPairing
virtual void check(LCEvent *evt)
virtual void processRunHeader(LCRunHeader *run)
Processor for marlin to find the smallest deviation between reconstructed jets and jet initialized qu...
std::string _inputJetCollection
static const float e
virtual void end()
virtual void processEvent(LCEvent *evt)
std::string _inputMCPCollection