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 // JetMaker class Implementation
003 // ================================================
004 //
005 // THIS TEXT TO BE REPLACED BY ATLAS STANDARD FORMAT
006 //
007 // Namespace Atlfast::
008 //
009 #include "AtlfastAlgs/JetMaker.h"
010 #include "AtlfastAlgs/JetSmearer.h"
011 #include "AtlfastAlgs/MissingMomentum.h"
012 #include "AtlfastAlgs/GlobalEventData.h"
013 
014 #include "AtlfastEvent/ContainerAssocsDispatcher.h"
015 #include "AtlfastEvent/Jet.h"
016 #include "AtlfastEvent/ICell.h"
017 #include "AtlfastEvent/CollectionDefs.h"
018 #include "AtlfastEvent/ReconstructedParticle.h"
019 #include "AtlfastEvent/ParticleCodes.h"
020 #include "AtlfastEvent/MsgStreamDefs.h"
021 #include "AtlfastEvent/ICluster.h"
022 #include "AtlfastEvent/MCparticleCollection.h"
023 #include "AtlfastEvent/SimpleKinematic.h"
024 #include "AtlfastEvent/Phi.h"
025 
026 #include "AtlfastUtils/TesIO.h"
027 #include "AtlfastUtils/HeaderPrinter.h"
028 #include "AtlfastUtils/FunctionObjects.h"
029 #include "AtlfastUtils/IsAssociated.h"
030 #include "AtlfastUtils/SmearCell.h"
031 
032 #include "TruthHelper/GenIMCselector.h"
033 #include "TruthHelper/IsGenType.h"
034 #include "TruthHelper/IsGenStable.h"
035 #include "TruthHelper/NCutter.h"
036 
037 #include <cmath> 
038 #include <algorithm>
039 #include <numeric>
040 #include <assert.h> 
041 
042 // Gaudi includes
043 #include "GaudiKernel/DataSvc.h"
044 #include "GaudiKernel/ISvcLocator.h"
045 #include "GaudiKernel/MsgStream.h"
046 
047 // CLHEP,HepMC
048 #include "GeneratorObjects/McEventCollection.h"
049 #include "HepMC/GenEvent.h"
050 #include "HepMC/GenVertex.h"
051 
052 #include "CLHEP/Units/SystemOfUnits.h"
053 
054   /** @brief Makes Atlfast::Jets from acceptable Atlfast::Clusters
055    *
056    * Acceptability is based on ET and eta cuts. Once accepted as a jet,
057    * the energy is smeared. Initial labelling is performed by searching
058    * in the truth block for proximity to b, c and hadronic taus.
059    *
060    * @image html JetMaker.jpg "JetMaker sequence"
061    */
062 
063 namespace Atlfast{
064 
065 //--------------------------------
066 // Constructors and destructors
067 //--------------------------------
068   using std::abs;
069   using std::sort;
070   using std::partition;
071   
072   JetMaker::JetMaker 
073   ( const std::string& name, ISvcLocator* pSvcLocator ) 
074     : Algorithm( name, pSvcLocator ),
075       m_bSelector(0),
076       m_cSelector(0),
077       m_tauSelector(0),
078       m_smearer(0),
079       m_cellSmearer(0),
080       m_tesIO(0)
081   {
082     
083     // Setting the parameter defaults.
084     m_minPT            = 10*GeV;     // Min jet trans momentum
085     m_maxEta           = 5.0;          //Max jet eta 
086     m_doSmearing       = true;       //smearing is done
087     m_rconeb           = 0.400;
088     m_rconef           = 0.400;
089     
090     m_bPtMin           = 5.0*GeV;    //min pt for bquark to label jet
091     m_bMaxDeltaR       = 0.3;        //max dR for bquark to label jet
092     
093     m_cPtMin           = 5.0*GeV;    //min pt for cquark to label jet
094     m_cMaxDeltaR       = 0.3;
095     
096     m_tauPtMin         = 10.0*GeV;
097     m_tauMaxDeltaR     = 0.3;
098     
099     m_etaTagMax        = 2.5;
100 
101     m_tauJetPtRatio    = 0;
102     
103     m_adjustMissETForIsolation = true;
104 
105     // Default paths for entities in the TES
106     m_inputLocation             = "/Event/AtlfastClusters";
107     m_outputLocation            = "/Event/AtlfastJets";
108     m_muonLocation              = "/Event/AtlfastNonIsolatedMuons";
109     m_unusedCellLocation        = "/Event/AtlfastUnusedCells";
110     m_missingMomentumLocation   = "/Event/AtlfastMissingMomentum";
111     m_isolatedElectronLocation  = "/Event/AtlfastIsolatedElectrons";
112     m_isolatedPhotonLocation    = "/Event/AtlfastIsolatedPhotons";
113     
114     // This is how you declare the paramemters to Gaudi so that
115     // they can be over-written via the job options file
116     declareProperty( "MinimumPT",                m_minPT ) ;
117     declareProperty( "MaximumEta",               m_maxEta ) ;
118     declareProperty( "DoSmearing",               m_doSmearing ); 
119     declareProperty( "RconeB",                   m_rconeb );
120     declareProperty( "RconeF",                   m_rconef );
121     declareProperty( "bPtMin",                   m_bPtMin );
122     declareProperty( "bMaxDeltaR",               m_bMaxDeltaR );
123     declareProperty( "cPtMin",                   m_cPtMin );
124     declareProperty( "cMaxDeltaR",               m_cMaxDeltaR );
125     declareProperty( "tauPtMin",                 m_tauPtMin );
126     declareProperty( "tauMaxDeltaR",             m_tauMaxDeltaR );
127     declareProperty( "etaTagMax",                m_etaTagMax );
128     declareProperty( "tauJetPtRatio",            m_tauJetPtRatio);
129     declareProperty( "adjustMissETForIsolation", m_adjustMissETForIsolation);
130 
131     declareProperty( "InputLocation",            m_inputLocation ) ;
132     declareProperty( "OutputLocation",           m_outputLocation ) ;
133     declareProperty( "UnusedCellLocation",       m_unusedCellLocation ) ;
134     declareProperty( "MuonLocation",             m_muonLocation );
135     declareProperty( "MissingMomentumLocation",  m_missingMomentumLocation );
136     declareProperty( "IsolatedElectronLocation", m_isolatedElectronLocation );
137     declareProperty( "IsolatedPhotonLocation",   m_isolatedPhotonLocation );
138 
139   }
140   
141   JetMaker::~JetMaker() {
142     
143     MsgStream log( messageService(), name() ) ;
144     log << MSG::INFO << "Destructor Called" << endreq;
145     
146     if (m_smearer) {
147       log << MSG::INFO << "Deleting jet Smearer" << endreq;
148       delete m_smearer;
149     }
150     if (m_cellSmearer) {
151       log << MSG::INFO << "Deleting Cell Smearer" << endreq;
152       delete m_cellSmearer;
153     }
154     if (m_tesIO) {
155       delete m_tesIO;
156     }
157   } 
158   
159   //---------------------------------
160   // initialise() 
161   //---------------------------------
162   
163   StatusCode JetMaker::initialize(){
164     MsgStream log( messageService(), name() ) ;
165     
166     log << MSG::DEBUG << "instantiating a JetSmearer" << endreq;
167     
168     
169     //get the Global Event Data using singleton pattern
170     GlobalEventData* ged = GlobalEventData::Instance();
171     int lumi                  = ged->lumi();
172     int randSeed              = ged->randSeed() ;
173     m_barrelForwardEta        = ged->barrelForwardEta();
174     m_mcLocation              = ged->mcLocation();
175 
176     // Pass this into GlobalEventData for EventHeaderMaker to read later
177     ged->set_adjustMissEtForIsolation(m_adjustMissETForIsolation);
178 
179     //    m_tesIO = new TesIO(eventDataService());
180     m_tesIO = new TesIO(m_mcLocation, ged->justHardScatter());
181     
182     if(m_doSmearing){
183       m_smearer                 = new JetSmearer(randSeed, 
184                                                  lumi,
185                                                  m_rconeb, 
186                                                  m_rconef, 
187                                                  m_barrelForwardEta);    
188       m_cellSmearer             = new JetSmearer(randSeed, 
189                                                  lumi,
190                                                  0., 
191                                                  0., 
192                                                  m_barrelForwardEta);    
193     } else {
194       m_smearer = 0;
195       m_cellSmearer = 0;
196     }
197 
198     const int BQUARK(ParticleCodes::BQUARK);
199     const int CQUARK(ParticleCodes::CQUARK);
200 
201     //.........................................................
202     // Construct objects to select b, c and tau quarks with kine conditions
203     
204     TruthHelper::GenIMCselector* selector;
205     
206     std::vector<TruthHelper::GenIMCselector*> bSelectors;
207     selector = new HepMC_helper::SelectJetTag(BQUARK, m_bPtMin, m_etaTagMax);
208     bSelectors.push_back( selector );
209       m_bSelector = new TruthHelper::NCutter(bSelectors);
210 
211     std::vector<TruthHelper::GenIMCselector*> cSelectors;
212     selector = new HepMC_helper::SelectJetTag(CQUARK, m_cPtMin, m_etaTagMax);
213     cSelectors.push_back( selector );
214      m_cSelector = new TruthHelper::NCutter(cSelectors);
215 
216     std::vector<TruthHelper::GenIMCselector*> tauSelectors;
217     selector = new HepMC_helper::SelectTauTag(m_tauPtMin, m_etaTagMax);
218     tauSelectors.push_back( selector );
219     m_tauSelector = new TruthHelper::NCutter(tauSelectors);
220 
221     //.........................................................
222     // Tidy up selectors
223     std::vector<TruthHelper::GenIMCselector*>::iterator iter;
224     for(iter=bSelectors.begin();   iter!=bSelectors.end();   delete *iter, ++iter);
225     for(iter=cSelectors.begin();   iter!=cSelectors.end();   delete *iter, ++iter);
226     for(iter=tauSelectors.begin(); iter!=tauSelectors.end(); delete *iter, ++iter);
227     
228     
229 
230     HeaderPrinter hp("Atlfast JetMaker:", log);
231     
232     hp.add("TES Locations:              ");
233     hp.add(" Muons from                 ", m_muonLocation); 
234     hp.add(" Clusters from              ", m_inputLocation); 
235     hp.add(" MC Input Location          ", m_mcLocation);
236     hp.add(" Jets to                    ", m_outputLocation);
237     hp.add(" unused cell,cluster sum to ", m_missingMomentumLocation);
238     hp.add("Smearing on                 ", m_doSmearing);
239     hp.add("Cluster min Pt              ", m_minPT);
240     hp.add("Cluster max Eta             ", m_maxEta);           
241     hp.add("Luminosity                  ", lumi);
242     hp.add("Initial random seed         ", randSeed);      
243     hp.add("End cap Cone size           ", m_rconef);
244     hp.add("Barrel  Cone size           ", m_rconeb);
245     hp.add("Eta of start of end cap     ", m_barrelForwardEta);
246     hp.add("Parameters for labels       ", "       ");
247     hp.add(" Max eta                    ", m_etaTagMax);
248     hp.add(" b-quark min pt             ", m_bPtMin);
249     hp.add(" b-quark max DeltaR         ", m_bMaxDeltaR);
250     hp.add(" c-quark min pt             ", m_cPtMin);
251     hp.add(" c-quark max DeltaR         ", m_cMaxDeltaR);
252     hp.add(" tau lep min pt             ", m_tauPtMin);
253     hp.add(" tau lep max DeltaR         ", m_tauMaxDeltaR);
254     hp.add(" tau/Jet Pt Ratio           ", m_tauJetPtRatio);
255     hp.print();
256     
257 
258 
259     return StatusCode::SUCCESS ;
260   }
261   
262   //---------------------------------
263   // finalise() 
264   //---------------------------------
265   
266   StatusCode JetMaker::finalize(){
267 
268     MsgStream log( messageService(), name() ) ;
269     log << MSG::INFO << "finalizing" << endreq;    
270 
271     if (m_bSelector)    delete m_bSelector;
272     if (m_cSelector)    delete m_cSelector;
273     if (m_tauSelector)  delete m_tauSelector;
274 
275     return StatusCode::SUCCESS ;
276   }
277   
278   
279   //----------------------------------------------
280   // execute() method called once per event
281   //----------------------------------------------
282   //
283   //  This algorithm creates smeared Jets passing cuts. 
284   //  It scans the list of Clusters from the Monte Carlo truth. 
285   //  If a Cluster of the right flavour is found it creates 
286   //  a candidate Jet object by smearing the four vector
287   //  of the Cluster and adding non-isolated muons. 
288   // 
289   //  It then applies kinematic criteria on the properties of the Jet
290   //  Those which pass the cuts are kept.
291   //  Finally all successful Jets are added to the event store.
292   //
293   //    //
294   
295   StatusCode JetMaker::execute( ){
296     
297     MsgStream log( messageService(), name() ) ;    
298 
299     std::string mess;
300     // make a message logging stream
301     
302     //.............................
303     // Make some locals stores which be used to keep pointers to
304     // all of the entities from the event store which are needed by
305     // this algorithm. These are all local and are typedefed in this class
306     
307     localClusterCollection      my_Clusters ;
308     MuonCollection              my_Muons ;
309     //................................
310     
311     //    if( ! m_tesIO->copy( my_Clusters, m_inputLocation ) ) {
312     if( ! m_tesIO->copy<IClusterCollection> ( my_Clusters, m_inputLocation ) ) {
313       log << MSG::INFO << "No Clusters in TES " << endreq;
314     } else {
315       log << MSG::DEBUG << my_Clusters.size()<<" Clusters from TES " << endreq;
316     }
317     // get non-isolated muons for jet construction
318     
319     if( ! m_tesIO->copy<ReconstructedParticleCollection>
320         ( my_Muons, m_muonLocation ) ) {
321       log << MSG::DEBUG << "No muons in TES " << endreq;
322     }  
323 
324     // ......................
325     // Make a container object which will store pointers to all isolated 
326     // Jetss which are successfully created.  Since it is going to go 
327     // into the event store, it has to be a special Gaudi type of container. 
328     // This is typedefined in the entity include file
329     // As it is going into the TES it needs to be created on the heap with new.
330     
331     JetCollection* myJets = new JetCollection ;
332     
333     //.........................................................
334     // From each Cluster create a reconstructed Jet. 
335     // If all requirements are satisfied add to the collection
336     
337     Jet* candidate ;
338     localClusterIterator src ;
339     m_sumET = 0.;
340     HepLorentzVector missingMomentum(0.,0.,0.,0.);
341     
342     MCparticleCollection  mcParticles_b ;
343     MCparticleCollection  mcParticles_c ;
344     MCparticleCollection  mcParticles_tau ;
345 
346     //.........................................................
347     // Get quarks used in tagging from TES using tesio
348 
349     TesIoStat stat = m_tesIO->getMC( mcParticles_b, m_bSelector ) ;
350     if(!stat){
351       log << MSG::ERROR <<"Problem getting b-quarks" << endreq; 
352       return stat;
353     }
354     stat = m_tesIO->getMC( mcParticles_c, m_cSelector ) ;
355     if(!stat){
356       log << MSG::ERROR <<"Problem getting c-quarks" << endreq; 
357       return stat;
358     }
359     stat = m_tesIO->getMC( mcParticles_tau, m_tauSelector ) ;
360     if(!stat){
361       log << MSG::ERROR <<"Problem getting taus" << endreq; 
362       return stat;
363     }
364  
365     for( src = my_Clusters.begin() ; src != my_Clusters.end() ; ++src ) { 
366       //
367       //      ReconstructedParticle rp;
368       //      std::vector<IAOO*> v;
369       //      v.push_back(*src);
370       //      AssocTypeRecoverer atr(v.begin(), v.end());
371       //      if ((atr.typeVector(rp))->size() == 0){
372       if ( !IsAssociated<ReconstructedParticle>( *src ) ){
373         // Make a new jet
374         candidate = this->create( *src );
375         
376         //Make a temp HepLorentzVector from candidates 4-mom
377         //before muon is added in
378         HepLorentzVector temp4Vec = candidate->momentum();
379         
380         // add isolated muons
381         this->addMuons(candidate, my_Muons);
382         
383         
384         // add to missing momentum vector if not used in a jet.
385         // remember, these are smeared momenta if smearing is enabled
386         if( this->isAcceptable( candidate ) ) {    
387           
388           // if the jet is acceptable label the jet
389           this->label(candidate,mcParticles_b,mcParticles_c,mcParticles_tau);
390           
391           log << MSG::DEBUG << "Pushing back a Jet" << endreq;
392           myJets->push_back( candidate ) ; 
393           log<<MSG::DEBUG<<"jet "<<*candidate<<endreq;
394         }else {
395           log << MSG::DEBUG << "Jet fails cuts" << endreq;
396           //add in temp4Vec to avoid muon double counting
397           missingMomentum += temp4Vec;
398           m_sumET += temp4Vec.perp();
399           delete candidate;
400         }
401       }else{
402         log << MSG::DEBUG << "Cluster is associated, so ignored" << endreq;
403       }
404     }
405     
406     log<<MSG::DEBUG<<"Missing momentum: clusters "<<missingMomentum<<endreq;
407     missingMomentum += addCells(log);
408     log << MSG::DEBUG << "sumET after adding cells: " << m_sumET << endreq;
409     log<<MSG::DEBUG<<"Missing momentum: cells+clstrs "
410        <<missingMomentum<<endreq;
411 
412     //......................................
413     // Register any Jets which have been successfilly created in the 
414     // transient event store. Allow modification further along the line
415     // for tagging routines.
416     log<<MSG::DEBUG<<"Storing "<< myJets->size() <<" Jets"<<endreq;
417     stat = m_tesIO->store( myJets, m_outputLocation, true) ;
418     if(!stat){
419       log<<MSG::ERROR<<"Could not store jets"<<endreq;
420       return stat;
421     }
422 
423 
424     MissingMomentum* mm = new MissingMomentum(missingMomentum,m_sumET);
425     stat = m_tesIO->store(mm,m_missingMomentumLocation ) ;
426     std::string message = stat? "Stored missing mom":"Failed to store missing mom";
427     log<<MSG::DEBUG<<message<<endreq;
428   
429 
430     return StatusCode::SUCCESS;
431   }
432   
433   
434   
435   //----------------------------------
436   // create()
437   //----------------------------------
438   
439   // Takes a single Cluster and creates a Jet
440   // according to the desired criteria
441   //
442   // Note that we must NEW these jets so they can go to the TES
443   // and if we decide that we do not want them, we must DELETE them
444   // Once they are put to the TES, they are no longer our responsibility to delete
445   
446   Jet* JetMaker::create ( ICluster* src )
447   {
448     Jet* jet;
449     MsgStream log( messageService(), name() ) ;
450     HepLorentzVector vec = src->momentum();
451     
452     if (m_doSmearing) 
453       {
454         // Ask our Smearer make a smeared 4-vector
455         vec = m_smearer->smear(vec);      
456       }
457     
458     jet = new Jet(vec, *src);
459     log << MSG::DEBUG << "Unsmeared Cluster: " << *src << endreq;
460     log << MSG::DEBUG << "Smeared Jet      : " << jet << endreq ;
461     
462     //IAOO* js = jet;
463     //assert(!js->unAssociated());
464     // return Jet
465     return jet;
466     
467     
468   }
469   //-------------------------------------------
470   // addmuons
471   //-------------------------------------------
472   
473   // adds non-isolated muons to the jets
474   
475   void JetMaker::addMuons(Jet* jet, MuonCollection& muons )
476   {
477     
478     MsgStream log( messageService(), name() ) ;
479     
480     if (muons.size() == 0) return;
481     
482     MuonIterator first = muons.begin() ;
483     MuonIterator last  = muons.end() ;
484     
485     // Partition muons to get those that satisfy the dR condition in either 
486     // eta region
487     MuonIterator partitionLast = 
488       partition(first,last,PartitionCondition::BelowThresholdDeltaR
489       (jet,m_rconeb,m_rconef,m_barrelForwardEta));
490     
491     if (partitionLast == first){
492       log << MSG::DEBUG << "No muons in R cone" << endreq;
493       return;
494     }
495 
496     log << MSG::DEBUG << "Adding " << partitionLast-first << " muons to Jet" << endreq;
497 
498     // Add muon momenta to jet
499     for (MuonIterator muItr = first; muItr != partitionLast;++muItr) jet->addMuon(*muItr);
500     
501     // Remove muons from list
502     muons.erase(first,partitionLast);
503     
504   }
505   
506   
507   //-------------------------------------------
508   // isAcceptable
509   //------------------------------------------
510   
511   // Decides whether a candidate is acceptable to this Maker, i.e. whether
512   // it wants to proceed and add it to its output product collection
513   
514   bool JetMaker::isAcceptable ( Jet* candidate)
515   {
516     
517     MsgStream log( messageService(), name() ) ;
518     
519     // Apply kinematic criteria to the candidate jet
520     
521     if( candidate->pT() < m_minPT ) {        
522       log << MSG::DEBUG << "Candidate failed pt cut: pt " << candidate->pT() 
523           << " min was " << m_minPT << endreq;
524       return false ;
525     }
526     
527     if( abs(candidate->eta()) > m_maxEta ) {
528       log << MSG::DEBUG << "Candidate failed max eta cut: eta " 
529           << candidate->eta() 
530           << " max was " << m_maxEta << endreq;
531       return false ;
532     }
533     
534     return true ;
535   }
536   
537   //-------------------------------------------
538   // label
539   //------------------------------------------
540   //
541   
542   void JetMaker::label(Jet* jet, 
543                        MCparticleCollection& mcParticles_b, 
544                        MCparticleCollection& mcParticles_c, 
545                        MCparticleCollection& mcParticles_tau)const {
546     
547     MsgStream log( messageService(), name() ) ;
548     
549     double dR = 0.;
550 
551     // The getJetLabel and getTauLabel functions loop over the input particle collections
552     // and return the PDGID of a particle if within maxdeltaR of the jet (0 otherwise). 
553     // dR is also set to the lowest found particle-jet delta R value
554 
555     int bLabel = getJetLabel(mcParticles_b, jet, m_bMaxDeltaR, dR);
556     jet->setdRbquark(dR);
557     int cLabel = getJetLabel(mcParticles_c, jet, m_cMaxDeltaR, dR);
558     jet->setdRcquark(dR);
559     int tauLabel = getTauLabel( mcParticles_tau, jet, m_tauMaxDeltaR, dR);
560     jet->setdRhadtau(dR);
561 
562     // Set jet label (order dependent)
563     if(bLabel){
564       jet->setPdg_id(bLabel);
565       return;
566     }
567     if(cLabel){
568       jet->setPdg_id(cLabel);
569       return;
570     }
571     if(tauLabel){
572       jet->setPdg_id(tauLabel);
573       return;
574     }
575 
576     jet->setPdg_id(0);
577     return; 
578 
579   }
580   //-------------------------------------------
581   // getJetLabel
582   //------------------------------------------
583   int JetMaker::getJetLabel(MCparticleCollection&  mcParticles, 
584                             Jet* jet,
585                             double maxDeltaR,
586                             double &deltaR) const {
587     
588     MsgStream log( messageService(), name() ) ;
589 
590     int pdgId    = 0;
591     double drMin = 999.;
592     
593     //Construct an object to select IKinematics within DeltaR of the current jet
594     PartitionCondition::BelowThresholdDeltaR labelSelector(jet, maxDeltaR); 
595     MCparticleCollectionCIter src ;
596     for( src = mcParticles.begin(); src != mcParticles.end(); ++src ){
597       SimpleKinematic sk(*src);
598       if(labelSelector(sk)){
599         pdgId = (*src)->pdg_id();
600       }      
601       Phi dPhi( sk.phi() - jet->phi() );
602       double dR = sqrt((dPhi*dPhi) + 
603                        (sk.eta()-jet->eta())*(sk.eta()-jet->eta()));
604       if (dR < drMin) drMin = dR;
605     }
606     deltaR = drMin;
607     return pdgId;
608   }
609   //-------------------------------------------
610   // getTauLabel
611   //------------------------------------------
612   int JetMaker::getTauLabel(MCparticleCollection&  mcParticles,
613                             Jet* jet,
614                             double maxDeltaR,
615                             double &deltaR) const {
616     
617     MsgStream log( messageService(), name() ) ;
618     
619     int pdgId    = 0;
620     double drMin = 999.;
621 
622     //Construct an object to select IKinematics within DeltaR of the current jet
623     PartitionCondition::BelowThresholdDeltaR labelSelector(jet, maxDeltaR);
624     MCparticleCollectionCIter src ;
625     for( src = mcParticles.begin() ; src != mcParticles.end() ; ++src )
626       {
627         HepLorentzVector tauHlv((*src)->momentum().px(),(*src)->momentum().py()
628         ,(*src)->momentum().pz(),(*src)->momentum().e());
629         HepLorentzVector neuHlv;
630 
631         // Find Tau children
632         HepMC::GenVertex*  endVertex = (*src)->end_vertex();
633         if(!endVertex) continue;
634 
635         HepMC::GenVertex::particle_iterator firstChild = 
636           endVertex->particles_begin(HepMC::children);
637         
638         HepMC::GenVertex::particle_iterator endChild = 
639           endVertex->particles_end(HepMC::children);
640         
641         HepMC::GenVertex::particle_iterator thisChild = firstChild; 
642         
643         // Find Pt of Taus tau-neutrino
644         for(; thisChild!=endChild; ++thisChild){
645           if(  abs((*thisChild)->pdg_id()) == 16){
646             neuHlv.setPx((*thisChild)->momentum().px());
647             neuHlv.setPy((*thisChild)->momentum().py());
648             neuHlv.setPz((*thisChild)->momentum().pz());
649             neuHlv.setE((*thisChild)->momentum().e());
650           }
651         }
652         double sigma;
653         double sqrtene = sqrt(jet->momentum().e()/GeV);
654         if ( fabs(jet->eta()) < m_barrelForwardEta )
655           sigma = 0.5/sqrtene;
656         else
657           sigma = 1.0/sqrtene;
658 
659         double cutQuantity = (m_tauJetPtRatio) ? m_tauJetPtRatio : 1.0 - 2*sigma;
660 
661         log << MSG::DEBUG << "m_tauJetPtRatio = " << m_tauJetPtRatio
662             << ", cutQuantity = " << cutQuantity << endreq;
663 
664         HepMC::GenParticle trueHadSystem;
665         trueHadSystem.set_momentum(tauHlv-neuHlv); 
666         SimpleKinematic sk(trueHadSystem);
667         if (labelSelector(sk) &&
668             (tauHlv-neuHlv).perp()/jet->pT() >= cutQuantity){
669           Phi dPhi( sk.phi() - jet->phi() );
670           deltaR = sqrt((dPhi*dPhi) +
671                         (sk.eta()-jet->eta())*(sk.eta()-jet->eta()));
672           pdgId = (*src)->pdg_id();
673         }
674         Phi dPhi( sk.phi() - jet->phi() );
675         double dR = sqrt((dPhi*dPhi) + 
676                          (sk.eta()-jet->eta())*(sk.eta()-jet->eta()));
677         if (dR < drMin) drMin = dR;
678       }
679     
680     deltaR = drMin;
681     return pdgId;
682   }   
683   
684   HepLorentzVector JetMaker::addCells(MsgStream& log){
685     
686     std::vector<const ITwoCptCell*> cellsToSmear(0);
687     std::vector<const ITwoCptCell*> newCellsVector(0);
688     
689     getUnusedCells(cellsToSmear,log);
690     
691     if (m_adjustMissETForIsolation){
692       getIsolationCorrectionCells(cellsToSmear,newCellsVector,m_isolatedElectronLocation,log);
693       getIsolationCorrectionCells(cellsToSmear,newCellsVector,m_isolatedPhotonLocation,log);
694     }
695     
696     log << MSG::DEBUG << "Smearing a total of " << cellsToSmear.size() << " cells" << endreq;
697     log << MSG::DEBUG << "sumET before adding cells: " << m_sumET << endreq;
698     
699     // accumulate used to compute vectorial sum of Cell HepLorentzVectors
700     // m_sumET also passed into SmearCell to compute sum of smeared cell ETs
701     HepLorentzVector temp(0., 0., 0., 0.);
702     HepLorentzVector sum = std::accumulate(cellsToSmear.begin(),
703                                            cellsToSmear.end(),
704                                            temp,
705                                            SmearCell(m_cellSmearer,&m_sumET));
706     //if (eHitCellPtr) delete eHitCellPtr;
707 
708     std::vector<const ITwoCptCell*>::iterator itccItr   = newCellsVector.begin();
709     std::vector<const ITwoCptCell*>::iterator itccItrE  = newCellsVector.end();
710 
711     for (;itccItr!=itccItrE;++itccItr) delete *itccItr;
712     newCellsVector.clear();
713 
714     return sum;
715   }
716   
717   void JetMaker::getUnusedCells(std::vector<const ITwoCptCell*> &cellsToSmear, MsgStream& log){
718     
719     std::vector<const TwoCptCell*> unusedCells(0);
720     if( !m_tesIO->copy<std::vector<const TwoCptCell*> >(unusedCells,
721                                                         m_unusedCellLocation)){
722       log << MSG::INFO << "No unused cells  in TES " << endreq;
723       return;
724     }
725     
726     log << MSG::DEBUG << unusedCells.size() << " unused cells in TES" << endreq;
727     
728     std::copy(unusedCells.begin(),unusedCells.end(),std::back_inserter(cellsToSmear));
729     
730     log << MSG::DEBUG  << "Added " << unusedCells.size() << " unused cells to cellToSmear" << endreq;
731     
732     return;
733     
734   }
735   
736   void JetMaker::getIsolationCorrectionCells(std::vector<const ITwoCptCell*> &cellsToSmear, 
737                                              std::vector<const ITwoCptCell*> &newcellsVector,
738                                              std::string tesAddress,
739                                              MsgStream& log){
740     
741     
742     std::vector<const ITwoCptCell*> isolationCorrectionCells(0);
743     
744     const ReconstructedParticleCollection* dh(0);
745     if( !m_tesIO->getDH(dh, tesAddress) ) throw "Error in numberInList";
746     
747     ReconstructedParticleCollection::const_iterator iter = dh->begin();
748     
749     for (; iter != dh->end(); ++iter){
750       
751       const HepMC::GenParticle* gp = (*iter)->truth();
752 
753       // Get associations of ReconstructedParticle associations 
754       const IAOO* iaooRP = (*iter);
755       TypeVisitor tv =
756         ContainerAssocsDispatcher( iaooRP->begin(), iaooRP->end(), TypeVisitor() );
757       
758       // Select the TwoCptCells
759       std::vector<const TwoCptCell*> tccv = tv.typeVector(TwoCptCell());
760       log << MSG::DEBUG << "TypeVisitor found " << tccv.size() 
761           << " TwoCptCells in this cluster" << endreq;
762       
763       std::vector<const TwoCptCell*>::iterator tccvi;
764 
765       for ( tccvi = tccv.begin(); tccvi != tccv.end();){
766         const ICell* ic = (*tccvi);
767 
768         // See if this TwoCptCell contains the GenParticle that made the
769         // original ReconstructedParticle
770         std::vector<const GenParticle*> gpv = ic->particles();
771         std::vector<const GenParticle*>::iterator gpi;
772         gpi = std::find(gpv.begin(),gpv.end(),gp);
773 
774         if ( gpi == gpv.end() ) ++tccvi;     // If not, go onto next TwoCptCell
775         else{                                // It's in this one
776           log << MSG::DEBUG << "GenParticle found in this cell, one of " 
777               << gpv.size() << " GenParticles" << endreq;
778           log << MSG::DEBUG << "GenParticle momentum = " << (*gpi)->momentum() << endreq;
779           log << MSG::DEBUG << "Cell momentum = " << ic->momentum() << endreq;
780 
781           if ( gpv.size() > 1){
782             // Make a new cell with pT reduced by that of the originating GenParticle
783             ITwoCptCell* newcell_itcc = (*tccvi)->cloneITCC();
784             newcell_itcc->resetCell();
785             ICell* newcell = newcell_itcc;
786             double newpT = ic->momentum().perp() - (*gpi)->momentum().perp();
787 //          newpT = ( fabs(newpT) < 1e-10 ) ? 0 : newpT; // problem with precision
788 //          newcell->newHit( newpT );
789 
790 
791             // The above commented out lines have been updated with the lines below.
792             // This is because the calculation of the extra energy (not belonging to the GenParticle)
793             // namely:
794             //         double newpT = ic->momentum().perp() - (*gpi)->momentum().perp();
795             // crashes and is not valid if a detector effect like scaling energy is applied to a cell
796             // since the cell energy (ic->momentum().perp()) will be scaled (possible lower that original)
797             // but the GenParticle energy ((*gpi)->momentum().perp()) will not be, resulting in a new pt
798             // being set that is <0 for this now correction cell. This causes a crash as might be expected.
799             // Solution here is to have the subtraction performed by the cell. This way the scaling is done
800             // on the fly by the cell which knows its scale factor (which incidently we don't know here and
801             // so couldn't scale the GenParticle properly)
802             if( fabs(newpT) < 1e-10 ){ newcell->newHit( 0. ); }// there seems to have bee a problem with precision
803             else{                                              // so keep this check just in case.
804               newcell->setPtSum( ic->momentum().perp() ); //add back the original momentum not with newHit as that would scale it at the cell energy is already scaled... thats the problem
805               newcell->newHit( -1*((*gpi)->momentum().perp()) ); //subtract the GenParticle momentum
806             }
807             
808             // Add the new, adjusted hit cell
809             isolationCorrectionCells.push_back(newcell_itcc);
810             newcellsVector.push_back(newcell_itcc);
811           }
812           
813           // Remove the pointer to the hit cell
814           tccvi = tccv.erase(tccvi);
815           
816         }
817       }
818       // After adjustment, copy all cells into isolationCorrectionCells
819       std::copy(tccv.begin(),tccv.end(),std::back_inserter(isolationCorrectionCells));
820     }
821     
822     log << MSG::DEBUG << "Added " << isolationCorrectionCells.size() 
823         << " isolation correction cells to cellsToSmear" << endreq;
824    
825     // Add isolationCorrectionCells cells to vector of cells for smearing
826     std::copy(isolationCorrectionCells.begin(),
827               isolationCorrectionCells.end(),
828               std::back_inserter(cellsToSmear));
829     
830     return;
831     
832   }
833   
834 } // end namespace bracket
835 

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!