CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFRootEventManagerColin.cc
Go to the documentation of this file.
3 
4 #include "TTree.h"
5 #include "TFile.h"
6 
7 #include <iostream>
8 
9 using namespace std;
10 
12  : PFRootEventManager(file) {
13 
14  tauEvent_ = 0;
15  neutralEvent_ = 0;
16  outTreeMy_ = 0;
17 
18  // readOptions(file, false, false);
19 
20  // book histos here
21  // neutralEvent_ = new NeutralEvent();
22 
23 
24  // tauEvent_ = new TauEvent();
25  // outTree_ = new TTree("Tau","");
26  // outTree_->Branch("event","TauEvent", &tauEvent_,32000,2);
27 
28  readSpecificOptions(file);
29 
30 }
31 
33 
34  // delete event_;
35  // delete outTree_;
36 }
37 
38 
40 
41 
42 
43  cout<<"calling PFRootEventManagerColin::readSpecificOptions"<<endl;
44  // PFRootEventManager::readOptions(file, refresh, reconnect);
45 
46 
47  options_->GetOpt("colin", "mode", mode_);
48 
49  if(outTreeMy_) delete outTreeMy_;
50 
51  outFile_->cd();
52  switch(mode_) {
53  case Neutral:
54  cout<<"colin: Neutral mode"<<endl;
55  neutralEvent_ = new NeutralEvent();
56  outTreeMy_ = new TTree("Neutral","");
57  outTreeMy_->Branch("event","NeutralEvent", &neutralEvent_,32000,2);
58  gDirectory->ls();
59  break;
60  case HIGH_E_TAUS:
61  cout<<"colin: highETaus mode"<<endl;
62  tauEvent_ = new TauEvent();
63  outTreeMy_ = new TTree("Tau","");
64  outTreeMy_->Branch("event","TauEvent", &tauEvent_,32000,2);
65  gDirectory->ls();
66  break;
67  default:
68  cerr<<"colin: undefined mode"<<endl;
69  exit(1);
70  }
71 }
72 
73 
74 
75 
76 
78 
79  tauEvent_->reset();
80 
81  if( ! PFRootEventManager::processEntry(entry) ) {
82  // cerr<<"event was not accepted"<<endl;
83  // print();
84  tauEvent_->rCode = 10;
85  return false; // event not accepted
86  }
87 
88  bool rvalue = false;
89  switch(mode_) {
90  case Neutral:
91  // cout<<"colin: process Neutral"<<endl;
92  rvalue = processNeutral();
93  break;
94  case HIGH_E_TAUS:
95  // cout<<"colin: process highETaus"<<endl;
96  rvalue = processHIGH_E_TAUS();
97  break;
98  default:
99  cerr<<"colin: undefined mode"<<endl;
100  assert(0);
101  }
102  outTreeMy_->Fill();
103 
104 
105  outTreeMy_->Fill();
106 
107 
108  outTreeMy_->Fill();
109 
110 
111  return rvalue;
112 }
113 
114 
115 
116 
118  // else {
119  // cerr<<"event accepted"<<endl;
120  // }
121 
122  // if( ! ( (*clustersECAL_).size() <= 1 &&
123  // (*clustersHCAL_).size() <= 1 ) ) {
124  // cerr<<"wrong number of ECAL or HCAL clusters :"
125  // <<(*clustersECAL_).size()<<","<<(*clustersHCAL_).size()<<endl;
126  // return false;
127  // }
128  // 1 HCAL cluster
129 
130  neutralEvent_->reset();
131 
132  // particle
133 
134  const HepMC::GenEvent* myGenEvent = MCTruth_.GetEvent();
135  if(!myGenEvent) {
136  assert(0);
137  }
138 
139  if( myGenEvent->particles_size() != 1 ) {
140  cerr<<"wrong number of particles:"
141  <<myGenEvent->particles_size()<<endl;
142  return 0;
143  }
144 
145  // take first particle
146  const HepMC::GenParticle* particle = *(myGenEvent->particles_begin() );
147 
148  // and check that it's a K0L
149  if( particle->pdg_id() != 130 ) {
150  cerr<<"not a K0L : "<<particle->pdg_id()<<endl;
151  return false;
152  }
153 
154  neutralEvent_->eNeutral = particle->momentum().e();
155 
156  double eta = particle->momentum().eta();
157  double phi = particle->momentum().phi();
159 
160 
161  neutralEvent_->nECAL = (*clustersECAL_).size();
162 
163  // look for the closest ECAL cluster from the particle.
164 
165  double minDist2 = 9999999;
166  // int iClosest = -1;
167  for( unsigned i=0; i<(*clustersECAL_).size(); ++i) {
168  double deta = (*clustersECAL_)[i].position().Eta() - eta;
169  double dphi = (*clustersECAL_)[i].position().Phi() - phi;
170  double dist2 = deta*deta + dphi*dphi;
171  if(dist2 < minDist2) {
172  minDist2 = dist2;
173  neutralEvent_->eECAL = (*clustersECAL_)[i].energy();
174  }
175  }
176 
177 
178  neutralEvent_->nHCAL = (*clustersHCAL_).size();
179  if( (*clustersHCAL_).size() == 1 ) {
180  neutralEvent_->eHCAL = (*clustersHCAL_)[0].energy();
181  }
182 
183 
184  outTreeMy_->Fill();
185 
187  return true;
188  else return false;
189 }
190 
191 
193 
194 
195  // true info
196  // 1 charged hadron, 2 photons
197  // save charged part mom, save sum E photons
198 
199 
200  int iHadron = -1;
201  int iPi0 = -1;
202  unsigned nStableChargedHadrons=0;
203  unsigned nPi0=0;
204  for(unsigned i=0; i<trueParticles_.size(); i++) {
205 
207 
208  int pdgCode = part.pdgCode();
209  double charge = part.charge();
210 
211  if( std::abs(pdgCode) > 100 &&
212  charge !=0 &&
213  part.daughterIds().empty() ) {
214  nStableChargedHadrons++;
215  iHadron = i;
216  }
217  else if( std::abs(pdgCode)==111) {
218  nPi0++;
219  iPi0 = i;
220  }
221 
222  // cout<<i<<" "<<part<<endl;
223  }
224 
225 
226  // one has to select 1 charged and 2 photons
227  // to use this function.
228 
229  // even after filtering events with one stable charged particle,
230  // this particle can be a lepton (eg leptonic pion decay)
231  if( nStableChargedHadrons==0 ) {
232  tauEvent_->rCode = 4;
233  return false;
234  }
235  assert( nStableChargedHadrons==1 );
236 
237 
238 
239  double pHadron = trueParticles_[iHadron].extrapolatedPoint(reco::PFTrajectoryPoint::ClosestApproach ).momentum().P();
240  tauEvent_->pHadron = pHadron;
241 
242  // tauEvent_->eEcalHadron = trueParticles_[iHadron].ecalEnergy();
243 
244  if(nPi0 == 1) {
245  math::XYZTLorentzVector pi0mom = trueParticles_[iPi0].extrapolatedPoint(reco::PFTrajectoryPoint::ClosestApproach ).momentum();
246  tauEvent_->eNeutral = pi0mom.E();
247  tauEvent_->etaNeutral = pi0mom.Eta();
248  }
249  else {
250  tauEvent_->eNeutral = 0;
251  }
252 
253  // if( tauEvent_->eNeutral > 0.1* tauEvent_->pHadron ) {
254  // print();
255  // }
256 
257 
258  // check that there is
259  // only one track
260  // 0 or 1 ecal cluster
261  // 0 or 1 hcal cluster
262 
263  if( recTracks_.size() != 1 ) {
264  // cout<<"more than 1 track"<<endl;
265  tauEvent_->rCode = 1;
266  return false;
267  }
268  if( clustersECAL_->size() > 1 ) {
269  // cout<<"more than 1 ecal cluster"<<endl;
270  tauEvent_->rCode = 2;
271  // return false;
272  }
273  if( clustersHCAL_->size() > 1 ) {
274  // cout<<"more than 1 hcal cluster"<<endl;
275  tauEvent_->rCode = 3;
276  return false;
277  }
278  // save track mom + neutral info.
279 
280  tauEvent_->pTrack = recTracks_[0].extrapolatedPoint(reco::PFTrajectoryPoint::ClosestApproach ).momentum().P();
281  tauEvent_->ptTrack = recTracks_[0].extrapolatedPoint(reco::PFTrajectoryPoint::ClosestApproach ).momentum().Pt();
282  tauEvent_->etaTrack = recTracks_[0].extrapolatedPoint(reco::PFTrajectoryPoint::ClosestApproach ).momentum().Eta();
283 
284  // access blocks
285 
286  // take the track block
287 
288  // look for the closest associated ecal and hcal clusters
289 
290  // fill the tree
291 
292 
293 
294 
295  for(unsigned i=0; i<pfBlocks_->size(); i++) {
296  const reco::PFBlock& block = (*pfBlocks_)[i];
297 
299  elements = block.elements();
300 
301  // look for the track
302  int iTrack = -1;
303  unsigned nTracks = 0;
304  for(unsigned ie=0; ie<elements.size(); ie++) {
305  if(elements[ie].type() == reco::PFBlockElement::TRACK ) {
306  iTrack = ie;
307  nTracks++;
308  }
309  }
310 
311  if(nTracks!=1) continue; // no track, or too many tracks in the block
312 
313  std::multimap<double, unsigned> sortedElems;
314  block.associatedElements( iTrack,
315  block.linkData(),
316  sortedElems );
317 
318  tauEvent_->nECAL=0;
319  tauEvent_->nHCAL=0;
320 
321  typedef std::multimap<double, unsigned>::iterator IE;
322  for(IE ie = sortedElems.begin(); ie != sortedElems.end(); ++ie ) {
323 
324 
325  double chi2 = ie->first;
326  unsigned index = ie->second;
327 
328  reco::PFBlockElement::Type type = elements[index].type();
329 
330  reco::PFClusterRef clusterRef = elements[index].clusterRef();
331 
332 
333 
334 
335  if( type == reco::PFBlockElement::ECAL ) {
336  if(!tauEvent_->nECAL ) { // closest ecal
337  assert( !clusterRef.isNull() );
338  tauEvent_->eECAL = clusterRef->energy();
339  tauEvent_->etaECAL = clusterRef->position().Eta();
340  tauEvent_->chi2ECAL = chi2;
341  tauEvent_->nECAL++;
342  }
343  }
344 
345 
346  else if( type == reco::PFBlockElement::HCAL ) {
347  if(!tauEvent_->nHCAL ) { // closest hcal
348  assert( !clusterRef.isNull() );
349  tauEvent_->eHCAL = clusterRef->energy();
350  tauEvent_->etaHCAL = clusterRef->position().Eta();
351  tauEvent_->nHCAL++;
352  }
353  }
354  } // eles associated to the track
355  } // blocks
356 
357 
358 
359 
360  return false;
361 }
362 
363 
364 
365 
367  // write histos here
368  outFile_->cd();
369  outTreeMy_->Write();
370 
372 }
373 
virtual void reset()
std::auto_ptr< reco::PFBlockCollection > pfBlocks_
reconstructed pfblocks
const std::vector< int > & daughterIds() const
Definition: PFSimParticle.h:44
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
void readSpecificOptions(const char *file)
IO * options_
options file parser
std::auto_ptr< reco::PFClusterCollection > clustersECAL_
size_type size() const
Definition: OwnVector.h:247
#define abs(x)
Definition: mlp_lapack.h:159
list elements
Definition: asciidump.py:414
const edm::OwnVector< reco::PFBlockElement > & elements() const
Definition: PFBlock.h:107
int pdgCode() const
Definition: PFSimParticle.h:35
const LinkData & linkData() const
Definition: PFBlock.h:112
std::auto_ptr< reco::PFClusterCollection > clustersHCAL_
PFRootEventManagerColin(const char *file)
T eta() const
reco::PFRecTrackCollection recTracks_
double charge(const std::vector< uint8_t > &Ampls)
bool GetOpt(const char *tag, const char *key, std::vector< T > &values) const
reads a vector of T
Definition: IO.h:106
reco::PFSimParticleCollection trueParticles_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
Definition: LorentzVector.h:30
bool processEntry(int entry)
process one entry (pass the TTree entry)
bool isNull() const
Checks for null.
Definition: Ref.h:247
Point of closest approach from beam axis (initial point in the case of PFSimParticle) ...
TFile * outFile_
output file
std::pair< std::string, MonitorElement * > entry
Definition: ME_MAP.h:8
virtual bool processEntry(int entry)
process one entry (pass the TTree entry)
true particle for particle flow
Definition: PFSimParticle.h:19
const HepMC::GenEvent * GetEvent() const
Definition: HepMCProduct.h:35
void associatedElements(unsigned i, const LinkData &linkData, std::multimap< double, unsigned > &sortedAssociates, reco::PFBlockElement::Type type=PFBlockElement::NONE, LinkTest test=LINKTEST_RECHIT) const
Definition: PFBlock.cc:75
part
Definition: HCALResponse.h:21
edm::HepMCProduct MCTruth_
tuple cout
Definition: gather_cfg.py:121
ROOT interface to particle flow package.
double charge() const
Definition: PFTrack.h:87
Definition: DDAxes.h:10
Block of elements.
Definition: PFBlock.h:30