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 ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ]   [ 15.*.* ] 

001 // ================================================
002 // DefaultReconstructedParticleMaker class Implementation
003 // ================================================
004 //
005 // THIS TEXT TO BE REPLACED BY ATLAS STANDARD FORMAT
006 //
007 // Namespace Atlfast
008 //
009 
010 #include "AtlfastAlgs/DefaultReconstructedParticleMaker.h"
011 #include "AtlfastAlgs/ReconstructorFactory.h"
012 #include "AtlfastAlgs/GlobalEventData.h" 
013 
014 //#include "AtlfastAlgs/CorrectionFactor.h"
015 
016 #include "AtlfastAlgs/MuonAcceptor.h"
017 
018 #include "AtlfastEvent/MsgStreamDefs.h"
019 #include "AtlfastEvent/MCparticleCollection.h"
020 
021 #include "AtlfastUtils/HeaderPrinter.h"
022 #include "TruthHelper/GenIMCselector.h"
023 #include "TruthHelper/IsGenType.h"
024 #include "TruthHelper/IsGenStable.h" 
025 #include "AtlfastUtils/HepMC_helper/MCCuts.h"
026 #include "TruthHelper/NCutter.h"
027 #include "AtlfastUtils/FunctionObjects.h"
028 
029 #include <cmath> 
030 
031 // Generic algorithms
032 #include <algorithm>
033 
034 // Gaudi includes
035 #include "GaudiKernel/DataSvc.h"
036 
037 // CLHEP,HepMC
038 #include "GeneratorObjects/McEventCollection.h"
039 #include "CLHEP/Units/SystemOfUnits.h"
040 
041 namespace Atlfast {
042   using std::abs;
043   using std::vector;
044   using std::sort;
045   //--------------------------------
046   // Constructor 
047   //--------------------------------
048   
049   DefaultReconstructedParticleMaker::DefaultReconstructedParticleMaker 
050   ( const std::string& name, ISvcLocator* pSvcLocator )
051     : Algorithm( name, pSvcLocator ),
052       m_ncutter(0),
053       m_reconstructor(0),
054       m_acceptor(0),
055       m_lnkReconstructedParticle(0),
056       m_tesIO(0),
057       m_log( messageService(), name )
058   {
059     
060     // Set the parameter defaults.
061     m_particleType      = 11;
062     m_mcPtMin           = 0.0*GeV;
063     m_mcEtaMax          = 100.0;
064     m_PtMin             = 5.0*GeV;
065     m_EtaMax            = 2.5;
066     m_doSmearing        = true;
067     m_muSmearKey        = 1;
068     m_outputLocation    = "/Event/AtlfastReconstructedParticle" ;
069     m_muonResFile       = "atlfastDatafiles/MuonResolutionTable.xml" ;
070     m_smearParamSchema  = 1;
071     m_applyEfficiencies = false;
072     m_schemaUsesParameters = false;
073     m_detEffectsFile    = "";
074     
075     // Declare the parameters to Gaudi so that
076     // they can be over-written via the job options file
077     declareProperty( "ParticleType",     m_particleType ) ;
078     declareProperty( "mcMinimumPt",      m_mcPtMin ) ;
079     declareProperty( "mcMaximumEta",     m_mcEtaMax ) ;
080     declareProperty( "MinimumPt",        m_PtMin ) ;
081     declareProperty( "MaximumEta",       m_EtaMax ) ;
082     declareProperty( "DoSmearing",       m_doSmearing ); 
083     declareProperty( "OutputLocation",   m_outputLocation ) ;
084     declareProperty( "MuonResFile",      m_muonResFile ) ;
085     declareProperty( "MuonSmearKey",     m_muSmearKey ); 
086         
087     //cct: declare the smearing parameters and schema.
088     // It is possible these JOs will not be found
089     // (say, if someone uses AtlfastKStandardOptions.py).
090     // In this case, the smearer would overwrite its constructor
091     // defaults with -9999 and an STL vector of size 0, which will mess up
092     // the smearing. Therefore if nothing is found, we stop athena running.
093     //
094     // I had originally thought it would be enough to just omit calling
095     // the setSmearParamArray and/or setSmearParamSchema methods if no JOs
096     // are found, but I decided it is not enough. This is because if, in the future,
097     // the defaults change (in AtlfastStandardOptions, for example) then someone
098     // runs using AtlfastKStandardOptions, the code picks up the defaults from the
099     // constructor in the smearer. Unless someone has maintained the default values
100     // in the smearer .h file, the defaults used will be the old, wrong ones.
101     // in short, it is hard to maintain!
102     //
103     // The only assumption we make by having smearParamArray and smearParamSchema
104     // in the jobOptions and failing if they are not fould is that if the defaults change,
105     // they should be changed in ALL jobOptions.
106     // Currently, this is:
107     //  share/Atlfast_CBNT.py
108     //  share/AtlfastIKinematicDumperStandardOptions.py
109     //  share/AtlfastKStandardOptions.py
110     //  share/AtlfastStandardOptions.py
111     //
112     //NB: the reason for all this is that the smearer is NOT an algorithm,
113     //so can not have Gaudi Properties.
114     //DefaultReconstructedParticleMaker is an algorithm so can have properties.
115     //Defaults must be set before properties are declared.
116     //Different particle smearers have different defaults, so we can not set these
117     //to any sensible values before the properties are loaded. We can only set defaults
118     //inside the smearer and these are then overridden by the 'set' method to potentially
119     //give junk physics...
120     declareProperty( "SmearParamArray", m_smearParamArray );
121     declareProperty( "SmearParamSchema",m_smearParamSchema );
122     declareProperty( "SchemaUsesParameters", m_schemaUsesParameters );
123 
124     // Option to apply efficiencies at particle creation stage
125     declareProperty( "ApplyEfficiencies", m_applyEfficiencies );
126 
127   }
128   
129   //--------------------
130   // Destructor
131   //--------------------
132   
133   DefaultReconstructedParticleMaker::~DefaultReconstructedParticleMaker() {
134 
135     m_log << MSG::INFO << "Destructor Called" << endreq;
136     
137     if (m_reconstructor) {
138       m_log << MSG::INFO << "Deleting reconstructor" << endreq;
139       delete m_reconstructor;
140     }
141     if (m_acceptor) {
142       m_log << MSG::INFO << "Deleting acceptor" << endreq;
143       delete m_acceptor;
144     }
145     if (m_tesIO) {
146       m_log << MSG::INFO << "Deleting tesIO" << endreq;
147       delete m_tesIO;
148     }
149     if (m_ncutter) {
150       m_log << MSG::INFO << "Deleting truth helpers" << endreq;
151       delete m_ncutter;
152     }
153 
154     if (m_lnkReconstructedParticle) delete m_lnkReconstructedParticle;
155 
156   }
157   
158   
159   //---------------------------------
160   // initialise() 
161   //---------------------------------
162   
163   StatusCode DefaultReconstructedParticleMaker::initialize()
164   {
165     
166     // This method is called by Athena once only, after all 
167     // properties have been set.
168     
169     // Set up NCutter to select the required HepMC::GenParticles
170     typedef TruthHelper::GenIMCselector Selector;
171 
172     Selector* typeSelector = new TruthHelper::IsGenType( m_particleType);
173     Selector* kineSelector = new HepMC_helper::MCCuts(m_mcPtMin, m_mcEtaMax);
174     Selector* fstaSelector = new TruthHelper::IsGenStable();
175 
176     vector<TruthHelper::GenIMCselector*> selectors;
177     selectors.push_back(fstaSelector);
178     selectors.push_back(typeSelector);
179     selectors.push_back(kineSelector);
180     
181      m_ncutter = new TruthHelper::NCutter(selectors);
182     
183     delete typeSelector;
184     delete kineSelector;
185     delete fstaSelector;
186     //=======================================================
187     
188     
189     
190 
191     //get the Global Event Data using singleton pattern
192     GlobalEventData*   ged = GlobalEventData::Instance();
193     int lumi =         ged->lumi();
194     int randSeed =     ged->randSeed();
195     m_detEffectsFile = ged->detEffectsFileName();
196 
197     m_tesIO = new TesIO(ged->mcLocation(), ged->justHardScatter());
198     
199     //=====================
200     if (m_doSmearing){
201       ReconstructorFactory rf(m_detEffectsFile, m_log);
202       m_reconstructor = rf.makeReconstructor( m_particleType,
203                                               randSeed,
204                                               lumi,
205                                               m_muSmearKey,
206                                               m_muonResFile,
207                                               m_smearParamArray,
208                                               m_smearParamSchema );
209     } else {
210       m_reconstructor = 0;
211     }
212     
213     //=====================
214     if (m_applyEfficiencies) this->getAcceptor();
215     else m_acceptor = 0;
216     
217     HeaderPrinter hp("Atlfast ReconstructedParticle Maker:", m_log);
218     hp.add("Particle Type           ", m_particleType);
219     hp.add("Luminosity              ", lumi);        
220     hp.add("Minimum four-vector Pt  ", m_mcPtMin);
221     hp.add("Maximum four-vector Eta ", m_mcEtaMax);
222     hp.add("Minimum particle    Pt  ", m_PtMin);
223     hp.add("Maximum particle    Eta ", m_EtaMax);
224     hp.add("Do Smearing             ", m_doSmearing);
225     hp.add("Muon  Smearing Flag     ", m_muSmearKey);
226     hp.add("Random Number Seed      ", randSeed);
227     hp.add("MC location             ", ged->mcLocation());
228     hp.add("Output Location         ", m_outputLocation);
229     hp.add("Muon Resolution File    ", m_muonResFile);
230     hp.print();
231     
232     //stop execution if no smearparamschema or smearParamArray are found.
233    if(m_schemaUsesParameters){
234        if(m_smearParamArray.size() == 0){
235             m_log << MSG::WARNING <<"No smearing parameters found in ATLFAST jobOptions..."<< endreq;
236        }else{
237             m_log << MSG::INFO << "Smearing Array m_smearParamArray set to: "<< 
238             m_smearParamArray << endreq;
239        }
240    }else{
241         m_log << MSG::INFO << "Schema requires no input parameters"<< endreq;
242    }
243  
244     return StatusCode::SUCCESS;
245   }
246   
247   //---------------------------------
248   // finalise() 
249   //---------------------------------
250   
251   StatusCode DefaultReconstructedParticleMaker::finalize()
252   {
253     
254     m_log << MSG::INFO << "Finalizing" << endreq;  
255     return StatusCode::SUCCESS ;
256   }
257   
258   
259   //----------------------------------------------
260   // execute() method called once per event
261   //----------------------------------------------
262   //
263   //  This algorithm creates smeared ReconstructedParticles.
264   // 
265   //  It takes HepMC::GenParticles from the TES as input. 
266   //  Only HepMC::GenParticles satisfying the selection requirements
267   //  are used.
268   //
269   //  A candidate ReconstructedParticle object is made by smearing the 
270   //  four vector of the HepMC::GenParticle. 
271   // 
272   //  It then applies kinematic selection criteria to the properties of the 
273   //  ReconstructedParticle. Only those which pass the cuts are kept.
274   //
275   //  Finally, all surviving ReconstructedParticles are added to the event 
276   //  store.
277   //
278   //
279   
280   StatusCode DefaultReconstructedParticleMaker::execute( )
281   {
282     
283     std::string mess;
284     m_log << MSG::DEBUG << "Execute() " << endreq;
285     
286 
287     //.............................
288     // Obtain the truth HepMC::GenParticles which we want to process.
289     // We fill a local collection with pointers to these Particles.
290     // The private method which is used applies selection criteria
291     // to the HepMC::GenParticles before placing them in the collection
292     
293     MCparticleCollection  my_MC_particles ;
294     MCparticleCollectionCIter src ;
295     
296     TesIoStat stat = m_tesIO->getMC( my_MC_particles, m_ncutter ) ;
297     mess = stat? "Retrieved MC from TES ":"Failed MC retrieve from TES";
298     m_log << MSG::DEBUG << mess << endreq;
299     
300     // ......................
301     // Make a container object which will store pointers to all  
302     // ReconstructedParticles which are successfully created.  
303     // Since it is going into the TES, it has to be a special Athena type 
304     // of container. This is defined in an include file.
305     
306     ReconstructedParticleCollection* myReconstructedParticles 
307       = new ReconstructedParticleCollection ;
308     
309     
310     //.........................................................
311     // From each mc truth Particle, create a ReconstructedParticle candidate.
312     // If it satisfies requirements add to the output collection
313     
314     ReconstructedParticle* candidate ;
315 
316     // Booleans for overall accept decision and kinematic and 
317     // pre-defined efficiency accept decisions separately
318     bool accept = true, accept_kinematic = true, accept_efficiency = true;
319     
320     for(src = my_MC_particles.begin() ; src != my_MC_particles.end() ; ++src){ 
321       
322       candidate = this->create( *src ); 
323       
324       // Accept decision based on pre-defined efficiency function
325       if (m_applyEfficiencies){ 
326         bool instance_check = m_acceptor ? true : false;
327         m_log << MSG::DEBUG << "Does m_acceptor point to anything sensible?: " << instance_check << endreq;
328         accept_efficiency = ( m_acceptor && m_acceptor->accept( *candidate, m_log ) ) ? true : false;
329         m_log << MSG::DEBUG << "m_acceptor && m_acceptor->accept( *candidate ) = " 
330             << accept_efficiency << endreq;
331       }
332       // Accept decision based on kinematic cuts
333       accept_kinematic = this->isAcceptable( candidate );
334       
335       accept = m_applyEfficiencies ? 
336         accept_efficiency && accept_kinematic : 
337         accept_kinematic;
338       
339       if ( accept ) {
340         m_log << MSG::DEBUG << "Accepted" << endreq;
341         myReconstructedParticles->push_back( candidate );     
342       }else{
343         m_log << MSG::DEBUG << "Rejected" << endreq;
344         delete candidate;
345       }
346       
347     }
348     
349     
350     //.....................................
351     // Sort into ascending order of pT
352     
353     if( myReconstructedParticles->size() > 0 ){
354       sort( myReconstructedParticles->begin(),
355             myReconstructedParticles->end(),
356             SortAttribute::DescendingPT()
357             ) ;
358     }
359     
360     
361     //......................................
362     // Deal with resulting ReconstructedParticles (if any)
363     
364     stat =m_tesIO->store( myReconstructedParticles, m_outputLocation );
365     mess = stat? "Store to TES success":"Store to TES failure";    
366     m_log << MSG::DEBUG << mess << endreq;
367 
368     m_log << MSG::DEBUG << "Ending<-------- " << endreq;
369     
370     StatusCode sc=StatusCode::SUCCESS;  
371     return sc ;
372     
373   }
374   
375   
376   
377   //----------------------------------
378   // create()
379   //----------------------------------
380   
381   // Takes a single MC Particle and creates a reconstructed
382   // ReconstructedParticle according to the desired criteria
383   //
384   // Note that we must NEW these particles so they can go to the TES
385   // and if we decide that we do not want them, we must DELETE them
386   // Once they are put to the TES, they are no longer our responsibility to 
387   // delete
388   
389   ReconstructedParticle* DefaultReconstructedParticleMaker::create ( const HepMC::GenParticle* src ){
390     HepLorentzVector evec(src->momentum().px(),
391                           src->momentum().py(),
392                           src->momentum().pz(),
393                           src->momentum().e());
394     
395     ReconstructedParticle tmpStackParticle(src->pdg_id(),evec,src);
396     ReconstructedParticle *candidate;
397 
398     if(m_doSmearing){
399       candidate = new ReconstructedParticle(m_reconstructor->reconstruct(tmpStackParticle));
400       m_log << MSG::DEBUG 
401             << "\n\t"
402               << "Unsmeared four-vector: " 
403             << src->momentum()
404             << "\n\t" 
405             << "Smeared four-vector  : " 
406             << candidate->momentum()
407             << endreq;
408     }
409     else{
410       candidate = new ReconstructedParticle(tmpStackParticle);
411     }
412 
413     m_log << MSG::DEBUG 
414           << "Created ReconstructedParticle: \n\t " 
415           << candidate 
416           << endreq;
417     
418     return candidate ;
419   }
420   
421   
422   //-------------------------------------------
423   // isAcceptable
424   //------------------------------------------
425   
426   // Decides whether a candidate is acceptable to this Maker, i.e. whether
427   // it wants to proceed and add it to its output product collection
428   
429   bool DefaultReconstructedParticleMaker::isAcceptable 
430   (const ReconstructedParticle* candidate ){
431     
432     // Apply kinematic criteria to the candidate DefaultReconstructedParticle
433     
434     if( candidate->pT() < m_PtMin ) {        
435       m_log << MSG::DEBUG 
436           << "Candidate failed pt cut: pt was " 
437           << candidate->pT() 
438           << " cut was " 
439           << m_PtMin 
440           << endreq;
441       return false ;
442     }
443     
444     if( abs(candidate->eta()) > m_EtaMax ) {
445       m_log << MSG::DEBUG 
446           << "Candidate failed max eta cut: eta was " 
447           << candidate->eta() 
448           << " cut was " 
449           << m_EtaMax 
450           << endreq;
451       return false ;
452     }
453     
454     m_log << MSG::DEBUG 
455         << "Candidate passed selection cuts "
456         << endreq ;
457     
458     return true ;
459   }
460   
461   //-------------------------------------------
462   // getAcceptor
463   //------------------------------------------
464   void DefaultReconstructedParticleMaker::getAcceptor(){
465 
466     m_log << MSG::DEBUG << "Getting an acceptor" << endreq;
467 
468     if (m_particleType == 13){
469       m_acceptor = new MuonAcceptor(m_muSmearKey,m_log);
470     }else{
471       m_log << MSG::ERROR << "No Acceptor exists for this particle type!" << endreq;
472       m_acceptor = 0;
473     }
474 
475   }
476   
477 } // end namespace bracket
478 
479 

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!