ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/src/MyVirtualJetProducer.cc
Revision: 1.9
Committed: Wed Sep 5 18:53:34 2012 UTC (12 years, 8 months ago) by yilmaz
Content type: text/plain
Branch: MAIN
CVS Tags: HiForest_V02_85, HiForest_V02_84, HiForest_V02_83, HiForest_V02_82, HiForest_V02_81, HiForest_V02_80, HiForest_V02_79, HiForest_V02_78, HiForest_V02_77, HiForest_V02_76, HiForest_V02_75, HiForest_V02_74, HiForest_V02_73, HiForest_V02_72, HiForest_V02_71, HiForest_V02_70, HiForest_V02_69, HiForest_V02_68, HiForest_V02_67, HiForest_V02_66, HiForest_V02_65, HiForest_V02_64, HiForest_V02_63, HiForest_V02_62, HiForest_V02_61, HiForest_V02_60, HiForest_V02_59, HiForest_V02_58, HiForest_V02_57, HiForest_V02_56, HiForest_V02_55, HiForest_V02_54, HiForest_V02_53, HiForest_V02_52, HiForest_V02_51, HiForest_V02_50, HiForest_V02_49, HiForest_V02_48, HiForest_V02_47, HiForest_V02_46, HiForest_V02_45, HiForest_V02_44, HiForest_V02_43, HiForest_V02_42, HiForest_V02_41, HiForest_V02_40, HiForest_V02_39, HiForest_V02_38, HiForest_V02_37, HiForest_V02_36, HiForest_V02_35, HiForest_V02_34, HiForest_V02_33, HiForest_V02_32, HiForest_V02_31, HiForest_V02_30, HiForest_V02_27, HiForest_V02_26, HEAD
Changes since 1.8: +11 -9 lines
Log Message:
update to 52x

File Contents

# User Rev Content
1 yilmaz 1.1 ////////////////////////////////////////////////////////////////////////////////
2     //
3     // MyVirtualJetProducer
4     // ------------------
5     //
6     // 04/21/2009 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
7     ////////////////////////////////////////////////////////////////////////////////
8    
9     #include "MyVirtualJetProducer.h"
10     #include "RecoJets/JetProducers/interface/JetSpecific.h"
11    
12     #include "FWCore/Framework/interface/Event.h"
13     #include "FWCore/Framework/interface/EventSetup.h"
14     #include "FWCore/Framework/interface/ESHandle.h"
15 frankma 1.7 #include "FWCore/Utilities/interface/Exception.h"
16 yilmaz 1.1 #include "FWCore/MessageLogger/interface/MessageLogger.h"
17     #include "FWCore/Framework/interface/MakerMacros.h"
18    
19     #include "DataFormats/Common/interface/View.h"
20     #include "DataFormats/Common/interface/Handle.h"
21     #include "DataFormats/VertexReco/interface/Vertex.h"
22     #include "DataFormats/VertexReco/interface/VertexFwd.h"
23     #include "DataFormats/JetReco/interface/CaloJetCollection.h"
24     #include "DataFormats/JetReco/interface/GenJetCollection.h"
25     #include "DataFormats/JetReco/interface/PFJetCollection.h"
26     #include "DataFormats/JetReco/interface/BasicJetCollection.h"
27     #include "DataFormats/JetReco/interface/TrackJetCollection.h"
28     #include "DataFormats/Candidate/interface/CandidateFwd.h"
29     #include "DataFormats/Candidate/interface/LeafCandidate.h"
30 yilmaz 1.2 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
31     #include "Geometry/Records/interface/CaloGeometryRecord.h"
32    
33     #include "DataFormats/Math/interface/Vector3D.h"
34 yilmaz 1.1
35     #include "fastjet/SISConePlugin.hh"
36     #include "fastjet/CMSIterativeConePlugin.hh"
37     #include "fastjet/ATLASConePlugin.hh"
38     #include "fastjet/CDFMidPointPlugin.hh"
39    
40     #include <iostream>
41     #include <memory>
42     #include <algorithm>
43     #include <limits>
44     #include <cmath>
45    
46     using namespace std;
47    
48    
49     namespace reco {
50     namespace helper {
51     struct GreaterByPtPseudoJet {
52     bool operator()( const fastjet::PseudoJet & t1, const fastjet::PseudoJet & t2 ) const {
53     return t1.perp() > t2.perp();
54     }
55     };
56    
57     }
58     }
59    
60     //______________________________________________________________________________
61     const char *MyVirtualJetProducer::JetType::names[] = {
62     "BasicJet","GenJet","CaloJet","PFJet","TrackJet"
63     };
64    
65    
66     //______________________________________________________________________________
67     MyVirtualJetProducer::JetType::Type
68     MyVirtualJetProducer::JetType::byName(const string &name)
69     {
70     const char **pos = std::find(names, names + LastJetType, name);
71     if (pos == names + LastJetType) {
72     std::string errorMessage="Requested jetType not supported: "+name+"\n";
73     throw cms::Exception("Configuration",errorMessage);
74     }
75     return (Type)(pos-names);
76     }
77    
78    
79     void MyVirtualJetProducer::makeProduces( std::string alias, std::string tag )
80     {
81     if (makeCaloJet(jetTypeE)) {
82     produces<reco::CaloJetCollection>(tag).setBranchAlias(alias);
83     }
84     else if (makePFJet(jetTypeE)) {
85     produces<reco::PFJetCollection>(tag).setBranchAlias(alias);
86     }
87     else if (makeGenJet(jetTypeE)) {
88     produces<reco::GenJetCollection>(tag).setBranchAlias(alias);
89     }
90     else if (makeTrackJet(jetTypeE)) {
91     produces<reco::TrackJetCollection>(tag).setBranchAlias(alias);
92     }
93     else if (makeBasicJet(jetTypeE)) {
94     produces<reco::BasicJetCollection>(tag).setBranchAlias(alias);
95     }
96     }
97    
98     ////////////////////////////////////////////////////////////////////////////////
99     // construction / destruction
100     ////////////////////////////////////////////////////////////////////////////////
101    
102     //______________________________________________________________________________
103     MyVirtualJetProducer::MyVirtualJetProducer(const edm::ParameterSet& iConfig)
104     : moduleLabel_ (iConfig.getParameter<string> ("@module_label"))
105     , src_ (iConfig.getParameter<edm::InputTag>("src"))
106     , srcPVs_ (iConfig.getParameter<edm::InputTag>("srcPVs"))
107     , jetType_ (iConfig.getParameter<string> ("jetType"))
108     , jetAlgorithm_ (iConfig.getParameter<string> ("jetAlgorithm"))
109     , rParam_ (iConfig.getParameter<double> ("rParam"))
110     , inputEtMin_ (iConfig.getParameter<double> ("inputEtMin"))
111     , inputEMin_ (iConfig.getParameter<double> ("inputEMin"))
112     , jetPtMin_ (iConfig.getParameter<double> ("jetPtMin"))
113     , doPVCorrection_(iConfig.getParameter<bool> ("doPVCorrection"))
114     , restrictInputs_(false)
115     , maxInputs_(99999999)
116     , doAreaFastjet_ (iConfig.getParameter<bool> ("doAreaFastjet"))
117     , doRhoFastjet_ (iConfig.getParameter<bool> ("doRhoFastjet"))
118     , doPUOffsetCorr_(iConfig.getParameter<bool> ("doPUOffsetCorr"))
119     , maxBadEcalCells_ (iConfig.getParameter<unsigned>("maxBadEcalCells"))
120     , maxRecoveredEcalCells_ (iConfig.getParameter<unsigned>("maxRecoveredEcalCells"))
121     , maxProblematicEcalCells_(iConfig.getParameter<unsigned>("maxProblematicEcalCells"))
122     , maxBadHcalCells_ (iConfig.getParameter<unsigned>("maxBadHcalCells"))
123     , maxRecoveredHcalCells_ (iConfig.getParameter<unsigned>("maxRecoveredHcalCells"))
124     , maxProblematicHcalCells_(iConfig.getParameter<unsigned>("maxProblematicHcalCells"))
125     , jetCollInstanceName_ ("")
126     {
127 yilmaz 1.2 // ntuple = new TNtuple("nt","debug","ieta:eta:iphi:phi");
128    
129 yilmaz 1.1 //
130     // additional parameters to think about:
131     // - overlap threshold (set to 0.75 for the time being)
132     // - p parameter for generalized kT (set to -2 for the time being)
133     // - fastjet PU subtraction parameters (not yet considered)
134     //
135     if (jetAlgorithm_=="SISCone") {
136     fjPlugin_ = PluginPtr( new fastjet::SISConePlugin(rParam_,0.75,0,0.0,false,
137     fastjet::SISConePlugin::SM_pttilde) );
138     fjJetDefinition_= JetDefPtr( new fastjet::JetDefinition(&*fjPlugin_) );
139     }
140     else if (jetAlgorithm_=="IterativeCone") {
141     fjPlugin_ = PluginPtr(new fastjet::CMSIterativeConePlugin(rParam_,1.0));
142     fjJetDefinition_= JetDefPtr(new fastjet::JetDefinition(&*fjPlugin_));
143     }
144     else if (jetAlgorithm_=="CDFMidPoint") {
145     fjPlugin_ = PluginPtr(new fastjet::CDFMidPointPlugin(rParam_,0.75));
146     fjJetDefinition_= JetDefPtr(new fastjet::JetDefinition(&*fjPlugin_));
147     }
148     else if (jetAlgorithm_=="ATLASCone") {
149     fjPlugin_ = PluginPtr(new fastjet::ATLASConePlugin(rParam_));
150     fjJetDefinition_= JetDefPtr(new fastjet::JetDefinition(&*fjPlugin_));
151     }
152     else if (jetAlgorithm_=="Kt")
153     fjJetDefinition_= JetDefPtr(new fastjet::JetDefinition(fastjet::kt_algorithm,rParam_));
154     else if (jetAlgorithm_=="CambridgeAachen")
155     fjJetDefinition_= JetDefPtr(new fastjet::JetDefinition(fastjet::cambridge_algorithm,
156     rParam_) );
157     else if (jetAlgorithm_=="AntiKt")
158     fjJetDefinition_= JetDefPtr( new fastjet::JetDefinition(fastjet::antikt_algorithm,rParam_) );
159     else if (jetAlgorithm_=="GeneralizedKt")
160     fjJetDefinition_= JetDefPtr( new fastjet::JetDefinition(fastjet::genkt_algorithm,
161     rParam_,-2) );
162     else
163     throw cms::Exception("Invalid jetAlgorithm")
164     <<"Jet algorithm for MyVirtualJetProducer is invalid, Abort!\n";
165    
166     jetTypeE=JetType::byName(jetType_);
167    
168     if ( iConfig.exists("jetCollInstanceName") ) {
169     jetCollInstanceName_ = iConfig.getParameter<string>("jetCollInstanceName");
170     }
171    
172     if ( doPUOffsetCorr_ ) {
173 yilmaz 1.8 if ( jetTypeE != JetType::CaloJet && jetTypeE != JetType::BasicJet) {
174     throw cms::Exception("InvalidInput") << "Can only offset correct jets of type CaloJet or BasicJet";
175     }
176 yilmaz 1.4
177 yilmaz 1.3 puSubtractorName_ = iConfig.getParameter<string> ("subtractorName");
178 yilmaz 1.5
179     cout<<"puSubtractorName_ is : "<<puSubtractorName_.data()<<endl;
180 yilmaz 1.3 if(puSubtractorName_.empty()){
181     edm::LogWarning("VirtualJetProducer") << "Pile Up correction on; however, pile up type is not specified. Using default... \n";
182 yilmaz 1.5 cout<<"Pile Up correction on; however, pile up type is not specified. Using default A.K... \n";
183 yilmaz 1.3 subtractor_ = boost::shared_ptr<PileUpSubtractor>(new PileUpSubtractor(iConfig));
184 yilmaz 1.5
185 yilmaz 1.3 }else{
186 yilmaz 1.5 cout<<"getting subtractor "<<endl;
187 yilmaz 1.3 subtractor_ = boost::shared_ptr<PileUpSubtractor>(PileUpSubtractorFactory::get()->create( puSubtractorName_, iConfig));
188     }
189 yilmaz 1.1 }
190    
191     // do fasjet area / rho calcluation? => accept corresponding parameters
192     if ( doAreaFastjet_ || doRhoFastjet_ ) {
193     // default Ghost_EtaMax should be 5
194     double ghostEtaMax = iConfig.getParameter<double>("Ghost_EtaMax");
195     // default Active_Area_Repeats 1
196     int activeAreaRepeats = iConfig.getParameter<int> ("Active_Area_Repeats");
197     // default GhostArea 0.01
198     double ghostArea = iConfig.getParameter<double> ("GhostArea");
199 yilmaz 1.9 // fjActiveArea_ = ActiveAreaSpecPtr(new fastjet::ActiveAreaSpec(ghostEtaMax,
200     // activeAreaRepeats,
201     // ghostArea));
202     // fjRangeDef_ = RangeDefPtr( new fastjet::RangeDefinition(ghostEtaMax) );
203 yilmaz 1.4
204     }
205    
206     if ( doRhoFastjet_ ) {
207     doFastJetNonUniform_ = iConfig.getParameter<bool> ("doFastJetNonUniform");
208     if(doFastJetNonUniform_){
209     puCenters_ = iConfig.getParameter<std::vector<double> >("puCenters");
210     puWidth_ = iConfig.getParameter<double>("puWidth");
211     produces<std::vector<double> >("rhos");
212     produces<std::vector<double> >("sigmas");
213     }else{
214     produces<double>("rho");
215     produces<double>("sigma");
216     }
217    
218     }
219 yilmaz 1.1
220     // restrict inputs to first "maxInputs" towers?
221     if ( iConfig.exists("restrictInputs") ) {
222     restrictInputs_ = iConfig.getParameter<bool>("restrictInputs");
223     maxInputs_ = iConfig.getParameter<unsigned int>("maxInputs");
224     }
225    
226    
227     string alias=iConfig.getUntrackedParameter<string>("alias",moduleLabel_);
228    
229     // make the "produces" statements
230     makeProduces( alias, jetCollInstanceName_ );
231    
232     if(doRhoFastjet_){
233     produces<double>("rho");
234     produces<double>("sigma");
235     }
236     }
237    
238    
239     //______________________________________________________________________________
240     MyVirtualJetProducer::~MyVirtualJetProducer()
241     {
242     }
243    
244    
245     ////////////////////////////////////////////////////////////////////////////////
246     // implementation of member functions
247     ////////////////////////////////////////////////////////////////////////////////
248    
249     //______________________________________________________________________________
250     void MyVirtualJetProducer::produce(edm::Event& iEvent,const edm::EventSetup& iSetup)
251     {
252 yilmaz 1.2
253     if(!geo){
254     edm::ESHandle<CaloGeometry> pGeo;
255     iSetup.get<CaloGeometryRecord>().get(pGeo);
256     geo = pGeo.product();
257     }
258    
259 yilmaz 1.1 LogDebug("MyVirtualJetProducer") << "Entered produce\n";
260     //determine signal vertex
261     vertex_=reco::Jet::Point(0,0,0);
262     if (makeCaloJet(jetTypeE)&&doPVCorrection_) {
263     LogDebug("MyVirtualJetProducer") << "Adding PV info\n";
264     edm::Handle<reco::VertexCollection> pvCollection;
265     iEvent.getByLabel(srcPVs_,pvCollection);
266     if (pvCollection->size()>0) vertex_=pvCollection->begin()->position();
267     }
268    
269     // For Pileup subtraction using offset correction:
270     // set up geometry map
271     if ( doPUOffsetCorr_ ) {
272     subtractor_->setupGeometryMap(iEvent, iSetup);
273     }
274    
275     // clear data
276     LogDebug("MyVirtualJetProducer") << "Clear data\n";
277     fjInputs_.clear();
278     fjJets_.clear();
279     inputs_.clear();
280    
281     // get inputs and convert them to the fastjet format (fastjet::PeudoJet)
282     edm::Handle<reco::CandidateView> inputsHandle;
283     iEvent.getByLabel(src_,inputsHandle);
284     for (size_t i = 0; i < inputsHandle->size(); ++i) {
285     inputs_.push_back(inputsHandle->ptrAt(i));
286     }
287     LogDebug("MyVirtualJetProducer") << "Got inputs\n";
288    
289     // Convert candidates to fastjet::PseudoJets.
290     // Also correct to Primary Vertex. Will modify fjInputs_
291     // and use inputs_
292     fjInputs_.reserve(inputs_.size());
293     inputTowers();
294     LogDebug("MyVirtualJetProducer") << "Inputted towers\n";
295    
296     // For Pileup subtraction using offset correction:
297     // Subtract pedestal.
298     if ( doPUOffsetCorr_ ) {
299 yilmaz 1.9 subtractor_->setDefinition(fjJetDefinition_);
300 yilmaz 1.4 subtractor_->reset(inputs_,fjInputs_,fjJets_);
301 yilmaz 1.1 subtractor_->calculatePedestal(fjInputs_);
302     subtractor_->subtractPedestal(fjInputs_);
303     LogDebug("MyVirtualJetProducer") << "Subtracted pedestal\n";
304     }
305    
306     // Run algorithm. Will modify fjJets_ and allocate fjClusterSeq_.
307     // This will use fjInputs_
308 yilmaz 1.9 // runAlgorithm( iEvent, iSetup );
309     /// if ( doPUOffsetCorr_ ) {
310     /// subtractor_->setAlgorithm(fjClusterSeq_);
311     /// }
312 yilmaz 1.1
313     LogDebug("MyVirtualJetProducer") << "Ran algorithm\n";
314    
315     // For Pileup subtraction using offset correction:
316     // Now we find jets and need to recalculate their energy,
317     // mark towers participated in jet,
318     // remove occupied towers from the list and recalculate mean and sigma
319     // put the initial towers collection to the jet,
320     // and subtract from initial towers in jet recalculated mean and sigma of towers
321     if ( doPUOffsetCorr_ ) {
322     vector<fastjet::PseudoJet> orphanInput;
323     subtractor_->calculateOrphanInput(orphanInput);
324     subtractor_->calculatePedestal(orphanInput);
325     subtractor_->offsetCorrectJets();
326     }
327    
328     // Write the output jets.
329     // This will (by default) call the member function template
330     // "writeJets", but can be overridden.
331     // this will use inputs_
332     output( iEvent, iSetup );
333     LogDebug("MyVirtualJetProducer") << "Wrote jets\n";
334    
335     return;
336     }
337    
338     //______________________________________________________________________________
339    
340     void MyVirtualJetProducer::inputTowers( )
341     {
342     std::vector<edm::Ptr<reco::Candidate> >::const_iterator inBegin = inputs_.begin(),
343     inEnd = inputs_.end(), i = inBegin;
344     for (; i != inEnd; ++i ) {
345     reco::CandidatePtr input = *i;
346 yilmaz 1.9 //if (isnan(input->pt())) continue;
347     if (std::isnan(input->pt())) continue;
348 yilmaz 1.1 if (input->et() <inputEtMin_) continue;
349     if (input->energy()<inputEMin_) continue;
350     if (isAnomalousTower(input)) continue;
351 yilmaz 1.2
352     //Check consistency of kinematics
353     const CaloTower* ctc = dynamic_cast<const CaloTower*>(input.get());
354     if(ctc){
355     int ieta = ctc->id().ieta();
356     int iphi = ctc->id().iphi();
357    
358 yilmaz 1.6 if(0 && ntuple)ntuple->Fill(ieta, input->eta(), iphi, input->phi(),input->et(),ctc->emEt(),ctc->hadEt());
359 yilmaz 1.2
360     if(abs(ieta) < 5){
361    
362     if(0){
363     math::RhoEtaPhiVector v(1.4,input->eta(),input->phi());
364     GlobalPoint point(v.x(),v.y(),v.z());
365     // const DetId d = geo->getClosestCell(point);
366     // HcalDetId hd(d);
367     HcalDetId hd(0);
368     if(hd.ieta() != ieta || hd.iphi() != iphi){
369     cout<<"Inconsistent kinematics!!! ET = "<<input->pt()<<endl;
370     cout<<"ieta candidate : "<<ieta<<" ieta detid : "<<hd.ieta()<<endl;
371     cout<<"iphi candidate : "<<iphi<<" iphi detid : "<<hd.iphi()<<endl;
372     }
373    
374     }
375    
376     if(0){
377     HcalDetId det(HcalBarrel,ieta,iphi,1);
378    
379     if(geo->present(det)){
380     double eta = geo->getPosition(det).eta();
381     double phi = geo->getPosition(det).phi();
382    
383     if(input->eta() != eta || input->phi() != phi){
384     cout<<"Inconsistent kinematics!!! ET = "<<input->pt()<<endl;
385     cout<<"eta candidate : "<<input->eta()<<" eta detid : "<<eta<<endl;
386     cout<<"phi candidate : "<<input->phi()<<" phi detid : "<<phi<<endl;
387     }
388     }else{
389     cout<<"DetId not present in the Calo Geometry : ieta = "<<ieta<<" iphi = "<<iphi<<endl;
390     }
391     }
392     }
393    
394     }
395    
396 yilmaz 1.1 if (makeCaloJet(jetTypeE)&&doPVCorrection_) {
397     const CaloTower* tower=dynamic_cast<const CaloTower*>(input.get());
398     math::PtEtaPhiMLorentzVector ct(tower->p4(vertex_));
399     fjInputs_.push_back(fastjet::PseudoJet(ct.px(),ct.py(),ct.pz(),ct.energy()));
400     }
401     else {
402     fjInputs_.push_back(fastjet::PseudoJet(input->px(),input->py(),input->pz(),
403     input->energy()));
404     }
405     fjInputs_.back().set_user_index(i - inBegin);
406     }
407    
408     if ( restrictInputs_ && fjInputs_.size() > maxInputs_ ) {
409     reco::helper::GreaterByPtPseudoJet pTComparator;
410     std::sort(fjInputs_.begin(), fjInputs_.end(), pTComparator);
411     fjInputs_.resize(maxInputs_);
412     edm::LogWarning("JetRecoTooManyEntries") << "Too many inputs in the event, limiting to first " << maxInputs_ << ". Output is suspect.";
413     }
414     }
415    
416     //______________________________________________________________________________
417     bool MyVirtualJetProducer::isAnomalousTower(reco::CandidatePtr input)
418     {
419     if (!makeCaloJet(jetTypeE)) return false;
420     const CaloTower* tower=dynamic_cast<const CaloTower*>(input.get());
421     if (0==tower) return false;
422     if (tower->numBadEcalCells() >maxBadEcalCells_ ||
423     tower->numRecoveredEcalCells() >maxRecoveredEcalCells_ ||
424     tower->numProblematicEcalCells()>maxProblematicEcalCells_||
425     tower->numBadHcalCells() >maxBadHcalCells_ ||
426     tower->numRecoveredHcalCells() >maxRecoveredHcalCells_ ||
427     tower->numProblematicHcalCells()>maxProblematicHcalCells_) return true;
428     return false;
429     }
430    
431    
432     //------------------------------------------------------------------------------
433     // This is pure virtual.
434     //______________________________________________________________________________
435     // void MyVirtualJetProducer::runAlgorithm( edm::Event & iEvent, edm::EventSetup const& iSetup,
436     // std::vector<edm::Ptr<reco::Candidate> > const & inputs_);
437    
438     //______________________________________________________________________________
439     void MyVirtualJetProducer::copyConstituents(const vector<fastjet::PseudoJet>& fjConstituents,
440     reco::Jet* jet)
441     {
442     for (unsigned int i=0;i<fjConstituents.size();++i)
443     jet->addDaughter(inputs_[fjConstituents[i].user_index()]);
444     }
445    
446    
447     //______________________________________________________________________________
448     vector<reco::CandidatePtr>
449     MyVirtualJetProducer::getConstituents(const vector<fastjet::PseudoJet>&fjConstituents)
450     {
451     vector<reco::CandidatePtr> result;
452     for (unsigned int i=0;i<fjConstituents.size();i++) {
453     int index = fjConstituents[i].user_index();
454     reco::CandidatePtr candidate = inputs_[index];
455     result.push_back(candidate);
456     }
457     return result;
458     }
459    
460     void MyVirtualJetProducer::output(edm::Event & iEvent, edm::EventSetup const& iSetup)
461     {
462     // Write jets and constitutents. Will use fjJets_, inputs_
463     // and fjClusterSeq_
464     switch( jetTypeE ) {
465     case JetType::CaloJet :
466     writeJets<reco::CaloJet>( iEvent, iSetup);
467     break;
468     case JetType::PFJet :
469     writeJets<reco::PFJet>( iEvent, iSetup);
470     break;
471     case JetType::GenJet :
472     writeJets<reco::GenJet>( iEvent, iSetup);
473     break;
474     case JetType::TrackJet :
475     writeJets<reco::TrackJet>( iEvent, iSetup);
476     break;
477     case JetType::BasicJet :
478     writeJets<reco::BasicJet>( iEvent, iSetup);
479     break;
480     default:
481     throw cms::Exception("InvalidInput") << "invalid jet type in MyVirtualJetProducer\n";
482     break;
483     };
484    
485     }
486    
487     template< typename T >
488     void MyVirtualJetProducer::writeJets( edm::Event & iEvent, edm::EventSetup const& iSetup )
489     {
490     // produce output jet collection
491    
492     using namespace reco;
493    
494     std::auto_ptr<std::vector<T> > jets(new std::vector<T>() );
495     jets->reserve(fjJets_.size());
496    
497     for (unsigned int ijet=0;ijet<fjJets_.size();++ijet) {
498     // allocate this jet
499     T jet;
500     // get the fastjet jet
501     const fastjet::PseudoJet& fjJet = fjJets_[ijet];
502     // get the constituents from fastjet
503     std::vector<fastjet::PseudoJet> fjConstituents =
504     sorted_by_pt(fjClusterSeq_->constituents(fjJet));
505     // convert them to CandidatePtr vector
506     std::vector<CandidatePtr> constituents =
507     getConstituents(fjConstituents);
508    
509     // calcuate the jet area
510     double jetArea=0.0;
511     if ( doAreaFastjet_ ) {
512     fastjet::ClusterSequenceArea const * clusterSequenceWithArea =
513     dynamic_cast<fastjet::ClusterSequenceArea const *>(&*fjClusterSeq_);
514     jetArea = clusterSequenceWithArea->area(fjJet);
515     }
516    
517     // write the specifics to the jet (simultaneously sets 4-vector, vertex).
518     // These are overridden functions that will call the appropriate
519     // specific allocator.
520     writeSpecific(jet,
521     Particle::LorentzVector(fjJet.px(),
522     fjJet.py(),
523     fjJet.pz(),
524     fjJet.E()),
525     vertex_,
526     constituents, iSetup);
527    
528     jet.setJetArea (jetArea);
529    
530     if(doPUOffsetCorr_){
531     jet.setPileup(subtractor_->getPileUpEnergy(ijet));
532     }else{
533     jet.setPileup (0.0);
534     }
535    
536     // add to the list
537     jets->push_back(jet);
538     }
539    
540     // put the jets in the collection
541     iEvent.put(jets);
542    
543     // calculate rho (median pT per unit area, for PU&UE subtraction down the line
544     if (doRhoFastjet_) {
545 yilmaz 1.4 if(doFastJetNonUniform_){
546     std::auto_ptr<std::vector<double> > rhos(new std::vector<double>);
547     std::auto_ptr<std::vector<double> > sigmas(new std::vector<double>);
548     int nEta = puCenters_.size();
549     rhos->reserve(nEta);
550     sigmas->reserve(nEta);
551     fastjet::ClusterSequenceArea const * clusterSequenceWithArea =
552     dynamic_cast<fastjet::ClusterSequenceArea const *> ( &*fjClusterSeq_ );
553     for(int ie = 0; ie < nEta; ++ie){
554     double eta = puCenters_[ie];
555     double rho = 0;
556     double sigma = 0;
557     double etamin=eta-puWidth_;
558     double etamax=eta+puWidth_;
559     fastjet::RangeDefinition range_rho(etamin,etamax);
560     clusterSequenceWithArea->get_median_rho_and_sigma(range_rho, true, rho, sigma);
561     rhos->push_back(rho);
562     sigmas->push_back(sigma);
563     }
564     iEvent.put(rhos,"rhos");
565     iEvent.put(sigmas,"sigmas");
566     }else{
567     std::auto_ptr<double> rho(new double(0.0));
568     std::auto_ptr<double> sigma(new double(0.0));
569     double mean_area = 0;
570     fastjet::ClusterSequenceArea const * clusterSequenceWithArea =
571     dynamic_cast<fastjet::ClusterSequenceArea const *> ( &*fjClusterSeq_ );
572     clusterSequenceWithArea->get_median_rho_and_sigma(*fjRangeDef_,false,*rho,*sigma,mean_area);
573     iEvent.put(rho,"rho");
574     iEvent.put(sigma,"sigma");
575     }
576 yilmaz 1.1 }
577     }
578    
579 yilmaz 1.4