Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]

001 ////////////////////////////////////////////////////////////////////////////////// 
002 /// Analysis skeleton
003 /// also for distributed analysis examples
004 /// Author: Ketevi A. Assamagan
005 /// BNL, July 22, 2004
006 ///
007 /// DESCRIPTION:
008 ///
009 /// This class is an analysis skeleton - The user can implement his analysis here
010 /// This class is also used for the demonstration of the distributed analysis
011 /// Some electron histograms are used for the distributed case. The user may
012 /// remove the histograms and the electron stuff if not needed.
013 /// Note t:he single algorithm structure as an analysis code does not scale
014 /// For detailed analysis examples, look in CVS: PhysicsAnalysis/AnalysisCommon/AnalysisExamples/
015 /// Ketevi A. Assamagan on June 22, 2004
016 ///
017 ///////////////////////////////////////////////////////////////////////////////////////////////////////
018 
019 
020 //////////////////////////////////////////////////////////////////////////////////
021 
022 #include "GaudiKernel/MsgStream.h"
023 #include "GaudiKernel/AlgFactory.h"
024 #include "GaudiKernel/IToolSvc.h"
025 
026 #include "StoreGate/StoreGateSvc.h"
027 
028 #include "egammaEvent/ElectronContainer.h"
029 #include "egammaEvent/EMShower.h"
030 #include "egammaEvent/egammaParamDefs.h"
031 
032 #include "McParticleEvent/TruthParticleContainer.h"
033 
034 #include "VxVertex/VxContainer.h"
035 #include "Particle/TrackParticleContainer.h"
036 #include "CaloEvent/CaloClusterContainer.h"
037 
038 #include "muonEvent/MuonContainer.h"
039 #include "egammaEvent/PhotonContainer.h"
040 #include "tauEvent/TauJetContainer.h"
041 #include "JetEvent/JetCollection.h"
042 #include "MissingETEvent/MissingET.h"
043 
044 #include "NavFourMom/IParticleContainer.h"
045 #include "NavFourMom/INavigable4MomentumCollection.h"
046 
047 #include "GaudiKernel/ITHistSvc.h"
048 #include "TTree.h"
049 #include "CLHEP/Vector/LorentzVector.h"
050 
051 //#include "JetTagInfo/TruthInfo.h"
052 
053 #include "UserAnalysis/AnalysisSkeleton.h"
054 
055 #include <algorithm>
056 #include <math.h>
057 #include <functional>
058 #include <iostream>
059 
060 static const double mZ = 91.19*GeV;
061 static const int  MAX_PARTICLES = 20;
062 
063 using namespace Analysis;
064 using namespace Rec;
065 
066 //////////////////////////////////////////////////////////////////////////////////////
067 /// Constructor
068 
069 AnalysisSkeleton::AnalysisSkeleton(const std::string& name,
070   ISvcLocator* pSvcLocator) : CBNT_AthenaAwareBase(name, pSvcLocator),
071   m_analysisTools( "AnalysisTools" ),
072   m_analysisSelectionTool( "UserAnalysisSelectionTool" ),
073   m_analysisPreparationTool( "UserAnalysisPreparationTool" ),
074   m_analysisOverlapCheckingTool( "UserAnalysisOverlapCheckingTool" ),
075   m_analysisOverlapRemovalTool( "UserAnalysisOverlapRemovalTool" ),
076   m_trigDec("TrigDec::TrigDecisionTool"){
077 
078   /** switches to control the analysis through job options */
079 
080   declareProperty( "AnalysisTools",               m_analysisTools );
081   declareProperty( "AnalysisSelectionTool",       m_analysisSelectionTool);
082   declareProperty( "AnalysisPreparationTool",     m_analysisPreparationTool);
083   declareProperty( "AnalysisOverlapCheckingTool", m_analysisOverlapCheckingTool);
084   declareProperty( "AnalysisOverlapRemovalTool",  m_analysisOverlapRemovalTool);
085   declareProperty( "TrigDecisionTool",            m_trigDec, 
086                    "The tool to access TrigDecision");
087 
088   declareProperty("ElectronContainer", m_electronContainerName="ElectronAODCollection"); 
089   declareProperty("McParticleContainer", m_truthParticleContainerName = "SpclMC");
090   declareProperty("MissingETObject",m_missingETObjectName="MET_RefFinal");
091 
092   /** the cuts - default values - to be modified in job options */
093 
094   declareProperty("DeltaRMatchCut", m_deltaRMatchCut = 0.2);
095   declareProperty("MaxDeltaR", m_maxDeltaR = 0.9999);
096 
097   /** additiona cuts for electrons */
098   declareProperty("ElectronEtCut", m_etElecCut = 10.0*GeV);
099   declareProperty("ElectronEtaCut", m_etaElecCut = 2.5);
100   declareProperty("ElectronCone", m_elecCone = 0.9);
101 
102   /** additional cuts for bjet tagging */
103   declareProperty("bjetWt_IP3DSV1Cut", m_bjetWt_ip3dsv1Cut = 6);
104   declareProperty("bjet_etaCut", m_bjet_etaCut = 2.5);
105   declareProperty("bjet_etCut", m_bjet_etCut = 15.0*GeV);
106 
107   /** missing ET options */
108   declareProperty("MissingETCut",m_missingETCut=20.0*GeV);
109 
110   /** is this AtlFast */
111   declareProperty("IsAtlFastData",m_isAtlFastData="False");
112 
113   /** count number of jets with ET > min value - for SUSY studies */
114   declareProperty("SusyJetMinEt", m_SusyJetMinEt = 50*GeV);
115 
116 
117   declareProperty("DoTrigger", m_doTrigger = true, "enable trigger example");
118 }
119 
120 /////////////////////////////////////////////////////////////////////////////////////
121 /// Destructor - check up memory allocation
122 /// delete any memory allocation on the heap
123 
124 AnalysisSkeleton::~AnalysisSkeleton() {}
125 
126 ////////////////////////////////////////////////////////////////////////////////////
127 /// Initialize
128 /// initialize StoreGate
129 /// get a handle on the analysis tools
130 /// book histograms
131 
132 StatusCode AnalysisSkeleton::CBNT_initializeBeforeEventLoop() {
133   MsgStream mLog( messageService(), name() );
134 
135   mLog << MSG::DEBUG << "Initializing AnalysisSkeleton (before eventloop)" << endreq;
136 
137   // retrieve trigger decision tool
138   // needs to be done before the first run/event since a number of
139   // BeginRun/BeginEvents are registered by dependent services
140   StatusCode sc = StatusCode::SUCCESS;
141 
142 /*
143   if ( m_doTrigger ) {
144      sc = m_trigDec.retrieve();
145      if ( sc.isFailure() ){
146         mLog << MSG::ERROR << "Can't get handle on TrigDecisionTool" << endreq;
147      } else {
148        mLog << MSG::DEBUG << "Got handle on TrigDecisionTool" << endreq;
149      }
150   }
151 */
152 
153   return sc;
154 } 
155 
156 StatusCode AnalysisSkeleton::CBNT_initialize() {
157 
158   MsgStream mLog( messageService(), name() );
159 
160   mLog << MSG::DEBUG << "Initializing AnalysisSkeleton" << endreq;
161 
162   /** get a handle of StoreGate for access to the Event Store */
163   StatusCode sc = service("StoreGateSvc", m_storeGate);
164   if (sc.isFailure()) {
165      mLog << MSG::ERROR
166           << "Unable to retrieve pointer to StoreGateSvc"
167           << endreq;
168      return sc;
169   }
170   
171   /// get a handle on the analysis tools
172   sc = m_analysisTools.retrieve();
173   if ( sc.isFailure() ) {
174       mLog << MSG::ERROR << "Can't get handle on analysis tools" << endreq;
175       return sc;
176   }
177 
178   /// get a handle on the preparartion analysis tools
179   sc = m_analysisSelectionTool.retrieve();
180   if ( sc.isFailure() ) {
181       mLog << MSG::ERROR << "Can't get handle on analysis selection tool" << endreq;
182       return sc;
183   }
184 
185   sc = m_analysisPreparationTool.retrieve();
186   if ( sc.isFailure() ) {
187       mLog << MSG::ERROR << "Can't get handle on analysis preparation tool" << endreq;
188       return sc;
189   }
190 
191   sc = m_analysisOverlapCheckingTool.retrieve();
192   if ( sc.isFailure() ) {
193       mLog << MSG::ERROR << "Can't get handle on analysis overlap checking tool" << endreq;
194       return sc;
195   }
196 
197   sc = m_analysisOverlapRemovalTool.retrieve();
198   if ( sc.isFailure() ) {
199       mLog << MSG::ERROR << "Can't get handle on analysis overlap removal tool" << endreq;
200       return sc;
201   }
202 
203   if ( m_doTrigger ) {
204     sc = m_trigDec.retrieve();
205     if ( sc.isFailure() ){
206       mLog << MSG::ERROR << "Can't get handle on TrigDecisionTool" << endreq;
207       return sc;
208     }
209   }
210 
211   /** get a handle on the NTuple and histogramming service */
212   sc = service("THistSvc", m_thistSvc);
213   if (sc.isFailure()) {
214      mLog << MSG::ERROR
215           << "Unable to retrieve pointer to THistSvc"
216           << endreq;
217      return sc;
218   }
219 
220   /** Print out bjet cut values */
221   mLog << MSG::DEBUG << "b jet cuts: Et/eta/IP3DSV1 wt. "<<m_bjet_etCut<< ","<<m_bjet_etaCut <<","<<m_bjetWt_ip3dsv1Cut<<endreq;
222 
223 
224   /** now add branches and leaves to the AAN tree */
225 
226   addBranch("NElectrons",    m_aan_size, "NElectrons/i");
227   addBranch("ElectronEta",   m_aan_eta);
228   addBranch("ElectronPt",    m_aan_pt);
229   addBranch("ElecPtRatio",   m_aan_elecetres);
230 
231   addBranch("NJets",          m_aan_njets, "NJets/i");
232   addBranch("NJets_etaLT25",  m_aan_njets_etaLT25, "NJets_etaLT25/i");
233   addBranch("NJets_SusyETCut",m_aan_njets_SusyETCut, "NJets_SusyETCut/i");
234   addBranch("JetsEta"        ,m_aan_JetEta);
235   addBranch("JetsEt"         ,m_aan_JetEt);
236   addBranch("JetsBTagWt"     ,m_aan_JetBTagWt);
237   addBranch("MissingET",      m_aan_ptMiss, "MissingET/d");
238   addBranch("EffMass",        m_aan_effmass, "EffMass/d");
239   addBranch("HT",             m_aan_ht,"HT/d");
240   addBranch("NBJets",         m_aan_nbjets, "NBJets/i");
241   addBranch("MaxJetET",       m_aan_maxJetET, "MaxJetET/d");
242 
243   addBranch("NFinalEl",       m_aan_NFinalEl, "NFinalEl/i");
244   addBranch("FinalElEta",     m_aan_FinalElEta);
245   addBranch("FinalElPt",      m_aan_FinalElPt);
246   addBranch("FinalElEtCone20",m_aan_FinalElEtCone20);
247 
248   addBranch("NFinalMu",       m_aan_NFinalMu, "NFinalMu/i");
249   addBranch("FinalMuEta",     m_aan_FinalMuEta);
250   addBranch("FinalMuPt",      m_aan_FinalMuPt);
251   addBranch("FinalMuEtCone20",m_aan_FinalMuEtCone20);
252   addBranch("FinalMuBestMat", m_aan_FinalMuBestMat);
253   addBranch("FinalMuMatChi2", m_aan_FinalMuMatChi2);
254 
255   addBranch("FinalLepEtSum",  m_aan_FinalLepEtSum, "FinalLepEtSum/d");
256   addBranch("FinalElEtSum",   m_aan_FinalElEtSum, "FinalElEtSum/d");
257   addBranch("FinalMuEtSum",   m_aan_FinalMuEtSum, "FinalMuEtSum/d");
258 
259   addBranch("NumberTopQ",     m_aan_NumTopQ, "NumberTopQ/i");
260   addBranch("pTtop1",         m_aan_pTtop1,  "pTtop1/d");
261   addBranch("pTtop2",         m_aan_pTtop2,  "pTtop2/d");
262 
263 
264   /// ROOT histograms ---------------------------------------
265 
266   /// electrons
267   m_h_elecpt     = new TH1F("elec_pt","pt el",50,0,250.*GeV);
268   sc = m_thistSvc->regHist("/AANT/Electron/elec_pt",m_h_elecpt);
269 
270   m_h_eleceta    = new TH1F("elec_eta","eta el",70,-3.5,3.5);
271   sc = m_thistSvc->regHist("/AANT/Electron/elec_eta",m_h_eleceta);
272 
273   m_h_elec_deltaRMatch    = new TH1F("elec_deltaRMatch","elec reco/MC deltaR",50,0.,1.);
274   sc = m_thistSvc->regHist("/AANT/Electron/elec_deltaRMatch",m_h_elec_deltaRMatch);
275 
276   /// jets - before OverlapRemoval
277   m_h_jet_eta_beforeOR = new TH1F("jet_eta_beforeOR","jet_eta before OR",50,-5.,5.);
278   sc = m_thistSvc->regHist("/AANT/Jet/jet_eta_beforeOR",m_h_jet_eta_beforeOR);
279 
280   m_h_jet_et_beforeOR = new TH1F("jet_et_beforeOR","jet_et before OR",100,0.,500.);
281   sc = m_thistSvc->regHist("/AANT/Jet/jet_et_beforeOR",m_h_jet_et_beforeOR);
282 
283   m_h_jet_ip3dsv1Wt_beforeOR = new TH1F("jet_ip3dsv1Wt_beforeOR","jet_ip3dsv1Wt before OR",120,-20.,40.);
284   sc = m_thistSvc->regHist("/AANT/Jet/jet_ip3dsv1Wt_beforeOR",m_h_jet_ip3dsv1Wt_beforeOR);
285 
286   m_h_jet_label_beforeOR = new TH1F("jet_label_beforeOR","jet_label before OR",20,0.,20.);
287   sc = m_thistSvc->regHist("/AANT/Jet/jet_label_beforeOR",m_h_jet_label_beforeOR);
288 
289   m_h_jet_ip3dsv1Wt_bjet_beforeOR = new TH1F("jet_ip3dsv1Wt_bjet_beforeOR","b jet_ip3dsv1Wt before OR",120,-20.,40.);
290   sc = m_thistSvc->regHist("/AANT/Jet/jet_ip3dsv1Wt_bjet_beforeOR",m_h_jet_ip3dsv1Wt_bjet_beforeOR);
291 
292   m_h_jet_ip3dsv1Wt_ujet_beforeOR = new TH1F("jet_ip3dsv1Wt_ujet_beforeOR","u jet_ip3dsv1Wt before OR",120,-20.,40.);
293   sc = m_thistSvc->regHist("/AANT/Jet/jet_ip3dsv1Wt_ujet_beforeOR",m_h_jet_ip3dsv1Wt_ujet_beforeOR);
294 
295   /// jets - after OverlapRemoval
296   m_h_jet_eta_afterOR = new TH1F("jet_eta_afterOR","jet_eta after OR",50,-5.,5.);
297   sc = m_thistSvc->regHist("/AANT/Jet/jet_eta_afterOR",m_h_jet_eta_afterOR);
298 
299   m_h_jet_et_afterOR = new TH1F("jet_et_afterOR","jet_et after OR",100,0.,500.);
300   sc = m_thistSvc->regHist("/AANT/Jet/jet_et_afterOR",m_h_jet_et_afterOR);
301 
302   m_h_jet_ip3dsv1Wt_afterOR = new TH1F("jet_ip3dsv1Wt_afterOR","jet_ip3dsv1Wt after OR",120,-20.,40.);
303   sc = m_thistSvc->regHist("/AANT/Jet/jet_ip3dsv1Wt_afterOR",m_h_jet_ip3dsv1Wt_afterOR);
304 
305   m_h_jet_label_afterOR = new TH1F("jet_label_afterOR","jet_label after OR",20,0.,20.);
306   sc = m_thistSvc->regHist("/AANT/Jet/jet_label_afterOR",m_h_jet_label_afterOR);
307 
308   m_h_jet_ip3dsv1Wt_bjet_afterOR = new TH1F("jet_ip3dsv1Wt_bjet_afterOR","b jet_ip3dsv1Wt after OR",120,-20.,40.);
309   sc = m_thistSvc->regHist("/AANT/Jet/jet_ip3dsv1Wt_bjet_afterOR",m_h_jet_ip3dsv1Wt_bjet_afterOR);
310 
311   m_h_jet_ip3dsv1Wt_ujet_afterOR = new TH1F("jet_ip3dsv1Wt_ujet_afterOR","u jet_ip3dsv1Wt after OR",120,-20.,40.);
312   sc = m_thistSvc->regHist("/AANT/Jet/jet_ip3dsv1Wt_ujet_afterOR",m_h_jet_ip3dsv1Wt_ujet_afterOR);
313 
314   /// missing ET
315 
316   m_pxMis   = new TH1F("MissingPx", "MissingPx",200,-500.0*GeV,500.*GeV);
317   sc = m_thistSvc->regHist("/AANT/MissingET/MissingPx", m_pxMis);
318   m_pyMis   = new TH1F("MissingPy","MissingPy",200,-500.0*GeV,500.*GeV);
319   sc = m_thistSvc->regHist("/AANT/MissingET/MissingPy", m_pyMis);
320   m_ptMis   = new TH1F("MissingPt","MissingPt",100,0.0,500.*GeV);
321   sc = m_thistSvc->regHist("/AANT/MissingET/MissingPt", m_ptMis);
322 
323 
324   if (sc.isFailure()) { 
325      mLog << MSG::ERROR << "ROOT Hist registration failed" << endreq; 
326      return sc; 
327   }
328   /// end ROOT Histograms ------------------------------------------
329 
330   return StatusCode::SUCCESS;
331 }                
332 
333 ///////////////////////////////////////////////////////////////////////////////////
334 /// Finalize - delete any memory allocation from the heap
335 
336 StatusCode AnalysisSkeleton::CBNT_finalize() {
337   MsgStream mLog( messageService(), name() );
338   
339   return StatusCode::SUCCESS;
340 
341 }
342 
343 ///////////////////////////////////////////////////////////////////////////////////
344 /// Clear - clear CBNT members
345 StatusCode AnalysisSkeleton::CBNT_clear() {
346   /// For Athena-Aware NTuple
347 
348   m_aan_size = 0;
349   m_aan_eta->clear();
350   m_aan_pt->clear();
351   m_aan_elecetres->clear();
352 
353   m_aan_njets=0;
354   m_aan_maxJetET = -1000.;
355   m_aan_JetEta->clear();
356   m_aan_JetEt->clear();
357   m_aan_JetBTagWt->clear();  
358   //
359   m_aan_njets_etaLT25=0;
360   m_aan_njets_SusyETCut = 0;
361 
362   m_aan_ptMiss = -1.;
363   m_aan_effmass = 0.;
364   m_aan_ht = 0;
365   m_aan_nbjets = 0;
366 
367   //
368   m_aan_NFinalEl = 0;
369   m_aan_FinalElPt->clear();
370   m_aan_FinalElEta->clear();
371   m_aan_FinalElEtCone20->clear();
372 
373 
374   m_aan_NFinalMu = 0;
375   m_aan_FinalMuPt->clear();
376   m_aan_FinalMuBestMat->clear();
377   m_aan_FinalMuEta->clear();
378   m_aan_FinalMuEtCone20->clear();
379   m_aan_FinalMuMatChi2->clear();
380 
381   //
382   m_aan_FinalLepEtSum = 0.;
383   m_aan_FinalElEtSum  = 0.;
384   m_aan_FinalMuEtSum  = 0.;
385 
386   // 
387   m_aan_NumTopQ=0;
388   m_aan_pTtop1=-1;
389   m_aan_pTtop2=-1;
390 
391   return StatusCode::SUCCESS;
392 }
393 
394 //////////////////////////////////////////////////////////////////////////////////
395 /// Execute - on event by event
396 
397 StatusCode AnalysisSkeleton::CBNT_execute() {
398   MsgStream mLog( messageService(), name() );
399   
400   mLog << MSG::DEBUG << "in execute()" << endreq;
401 
402   StatusCode sc;
403 
404   /** it shows how to get the Electron and the TruthParticle
405       containers shows matching between reconstructed and MC electrons
406 
407       Can be commented out if you want to do so If you do so, some of
408       the electron histograms/ntuple variables will be unfilled */
409 
410   /*
411   sc = electronSkeleton();
412   if (sc.isFailure()) {
413     mLog << MSG::WARNING << "The method electronSkeleton() failed" << endreq;
414     return StatusCode::SUCCESS;
415   }
416   */
417 
418   /** an minimal example using the TrigDecisionTool */
419   if ( m_doTrigger ) {
420     sc = triggerSkeleton();
421     if (sc.isFailure()) {
422       mLog << MSG::WARNING << "The method triggerSkeleton() failed" << endreq;
423       return StatusCode::SUCCESS;
424     }
425   }
426  
427   /** an example of analysis preparation, including:
428       - pre-selections based on the reocmmendations of performance groups
429       - overlap checking
430       - overlap removal */
431 
432   /** Do not comment the next method. This is where we do all the
433       selection/overlap removal Those results are then used in the
434       methods later on */
435 
436   sc = analysisPreparation();
437   if ( sc.isFailure() ) {
438      mLog << MSG::WARNING << "Analysis Preparation Failed " << endreq;
439      return StatusCode::SUCCESS;
440   }
441 
442   /** The following methods were added by Vivek Jain They just show
443       you how to access different variables and store them in
444       histograms and/or ntuples */
445 
446   /** look at bjet tagging information in the jets after overlap
447       removal */
448 
449   sc = bjetInfo();
450   if ( sc.isFailure() ) {
451      mLog << MSG::WARNING << "Failure in bjetInfo " << endreq;
452      return StatusCode::SUCCESS;
453   } 
454 
455   /** get missing Et information */
456 
457   sc = getMissingET();
458   if( sc.isFailure() ) {
459     mLog << MSG::WARNING
460          << "Failed to retrieve Et object found in TDS"
461          << endreq; 
462     return StatusCode::SUCCESS;
463   }  
464 
465   /** do SUSY studies */
466 
467   sc = SusyStudies();
468   if( sc.isFailure() ) {
469     mLog << MSG::WARNING
470          << "Failed to do SUSY studies"
471          << endreq; 
472     return StatusCode::SUCCESS;
473   }  
474 
475 
476 
477   return StatusCode::SUCCESS;
478 }
479 
480 //////////////////////////////////////////////////////////////////////////////////
481 /// Trigger method - called by execute() on event by event
482 /// to be removed if not needed
483 
484 StatusCode AnalysisSkeleton::triggerSkeleton() {
485   MsgStream mLog( messageService(), name() );
486   mLog << MSG::DEBUG << "in triggerSkeleton()" << endreq;
487 
488   // for example, did event pass Event Filter ?
489   // needs to be changed to m_trigDec->isPhysicsPassed
490   mLog << MSG::INFO << "Pass state EF = " << m_trigDec->isPassed(TrigDec::EF) << endreq;
491 
492   // for example, did event pass !L2_e25i chain? 
493   // needs to be changed to m_trigDec->isPhysicsPassed
494   std::string mychain("L2_e25i");
495   const HLT::Chain* chain = m_trigDec->getHLTChain(mychain);
496   if (0 == chain){
497     mLog << MSG::INFO << "Chain " << mychain << " is not defined";
498   } else {
499     mLog << MSG::INFO << "Chain " << mychain << ": " << *chain << " passed: " << chain->chainPassed() << endreq;
500     
501     mLog << MSG::DEBUG << "triggerSkeleton() succeeded" << endreq;
502     
503     return StatusCode::SUCCESS;
504   }
505   return StatusCode::SUCCESS;
506 }
507 
508 //////////////////////////////////////////////////////////////////////////////////
509 /// Electron method - called by execute() on event by event
510 /// to be removed if not needed
511 
512 StatusCode AnalysisSkeleton::electronSkeleton() {
513   MsgStream mLog( messageService(), name() );
514   
515   mLog << MSG::DEBUG << "in electronSkeleton()" << endreq;
516 
517   /** get the MC truth particle AOD container from StoreGate */
518   const TruthParticleContainer*  mcpartTES = 0;
519   StatusCode sc=m_storeGate->retrieve( mcpartTES,