00001
00002 #include <QCDAnalysis/UEAnalysis/interface/AnalysisRootpleProducer.h>
00003
00004 using namespace edm;
00005 using namespace std;
00006 using namespace reco;
00007
00008 class GreaterPt{
00009 public:
00010 bool operator()( const math::XYZTLorentzVector& a, const math::XYZTLorentzVector& b) {
00011 return a.pt() > b.pt();
00012 }
00013 };
00014
00015 class GenJetSort{
00016 public:
00017 bool operator()(const GenJet& a, const GenJet& b) {
00018 return a.pt() > b.pt();
00019 }
00020 };
00021
00022 class BasicJetSort{
00023 public:
00024 bool operator()(const BasicJet& a, const BasicJet& b) {
00025 return a.pt() > b.pt();
00026 }
00027 };
00028
00029 class CaloJetSort{
00030 public:
00031 bool operator()(const CaloJet& a, const CaloJet& b) {
00032 return a.pt() > b.pt();
00033 }
00034 };
00035
00036
00037 void AnalysisRootpleProducer::store(){
00038
00039 AnalysisTree->Fill();
00040
00041 NumberMCParticles=0;
00042 NumberTracks=0;
00043 NumberInclusiveJet=0;
00044 NumberChargedJet=0;
00045 NumberTracksJet=0;
00046 NumberCaloJet=0;
00047 }
00048
00049 void AnalysisRootpleProducer::fillEventInfo(int e){
00050 EventKind = e;
00051 }
00052
00053 void AnalysisRootpleProducer::fillMCParticles(float p, float pt, float eta, float phi){
00054 MomentumMC[NumberMCParticles]=p;
00055 TransverseMomentumMC[NumberMCParticles]=pt;
00056 EtaMC[NumberMCParticles]=eta;
00057 PhiMC[NumberMCParticles]=phi;
00058 NumberMCParticles++;
00059 }
00060
00061 void AnalysisRootpleProducer::fillTracks(float p, float pt, float eta, float phi){
00062 MomentumTK[NumberTracks]=p;
00063 TransverseMomentumTK[NumberTracks]=pt;
00064 EtaTK[NumberTracks]=eta;
00065 PhiTK[NumberTracks]=phi;
00066 NumberTracks++;
00067 }
00068
00069 void AnalysisRootpleProducer::fillInclusiveJet(float p, float pt, float eta, float phi){
00070 MomentumIJ[NumberInclusiveJet]=p;
00071 TransverseMomentumIJ[NumberInclusiveJet]=pt;
00072 EtaIJ[NumberInclusiveJet]=eta;
00073 PhiIJ[NumberInclusiveJet]=phi;
00074 NumberInclusiveJet++;
00075 }
00076
00077 void AnalysisRootpleProducer::fillChargedJet(float p, float pt, float eta, float phi){
00078 MomentumCJ[NumberChargedJet]=p;
00079 TransverseMomentumCJ[NumberChargedJet]=pt;
00080 EtaCJ[NumberChargedJet]=eta;
00081 PhiCJ[NumberChargedJet]=phi;
00082 NumberChargedJet++;
00083 }
00084
00085 void AnalysisRootpleProducer::fillTracksJet(float p, float pt, float eta, float phi){
00086 MomentumTJ[NumberTracksJet]=p;
00087 TransverseMomentumTJ[NumberTracksJet]=pt;
00088 EtaTJ[NumberTracksJet]=eta;
00089 PhiTJ[NumberTracksJet]=phi;
00090 NumberTracksJet++;
00091 }
00092
00093 void AnalysisRootpleProducer::fillCaloJet(float p, float pt, float eta, float phi){
00094 MomentumEHJ[NumberCaloJet]=p;
00095 TransverseMomentumEHJ[NumberCaloJet]=pt;
00096 EtaEHJ[NumberCaloJet]=eta;
00097 PhiEHJ[NumberCaloJet]=phi;
00098 NumberCaloJet++;
00099 }
00100
00101 AnalysisRootpleProducer::AnalysisRootpleProducer( const ParameterSet& pset )
00102 {
00103
00104 onlyRECO = pset.getUntrackedParameter<bool>("OnlyRECO",false);
00105
00106
00107 mcEvent = pset.getUntrackedParameter<InputTag>("MCEvent",std::string(""));
00108 genJetCollName = pset.getUntrackedParameter<InputTag>("GenJetCollectionName",std::string(""));
00109 chgJetCollName = pset.getUntrackedParameter<InputTag>("ChgGenJetCollectionName",std::string(""));
00110 tracksJetCollName = pset.getUntrackedParameter<InputTag>("TracksJetCollectionName",std::string(""));
00111 recoCaloJetCollName = pset.getUntrackedParameter<InputTag>("RecoCaloJetCollectionName",std::string(""));
00112 chgGenPartCollName = pset.getUntrackedParameter<InputTag>("ChgGenPartCollectionName",std::string(""));
00113 tracksCollName = pset.getUntrackedParameter<InputTag>("TracksCollectionName",std::string(""));
00114
00115
00116 triggerResultsTag = pset.getParameter<InputTag>("triggerResults");
00117
00118
00119
00120 piG = acos(-1.);
00121 NumberMCParticles=0;
00122 NumberTracks=0;
00123 NumberInclusiveJet=0;
00124 NumberChargedJet=0;
00125 NumberTracksJet=0;
00126 NumberCaloJet=0;
00127 }
00128
00129 void AnalysisRootpleProducer::beginJob( const EventSetup& )
00130 {
00131
00132
00133 AnalysisTree = fs->make<TTree>("AnalysisTree","MBUE Analysis Tree ");
00134
00135 AnalysisTree->Branch("EventKind",&EventKind,"EventKind/I");
00136
00137
00138
00139
00140 AnalysisTree->Branch("NumberMCParticles",&NumberMCParticles,"NumberMCParticles/I");
00141 AnalysisTree->Branch("MomentumMC",MomentumMC,"MomentumMC[NumberMCParticles]/F");
00142 AnalysisTree->Branch("TransverseMomentumMC",TransverseMomentumMC,"TransverseMomentumMC[NumberMCParticles]/F");
00143 AnalysisTree->Branch("EtaMC",EtaMC,"EtaMC[NumberMCParticles]/F");
00144 AnalysisTree->Branch("PhiMC",PhiMC,"PhiMC[NumberMCParticles]/F");
00145
00146
00147 AnalysisTree->Branch("NumberTracks",&NumberTracks,"NumberTracks/I");
00148 AnalysisTree->Branch("MomentumTK",MomentumTK,"MomentumTK[NumberTracks]/F");
00149 AnalysisTree->Branch("TrasverseMomentumTK",TransverseMomentumTK,"TransverseMomentumTK[NumberTracks]/F");
00150 AnalysisTree->Branch("EtaTK",EtaTK,"EtaTK[NumberTracks]/F");
00151 AnalysisTree->Branch("PhiTK",PhiTK,"PhiTK[NumberTracks]/F");
00152
00153
00154 AnalysisTree->Branch("NumberInclusiveJet",&NumberInclusiveJet,"NumberInclusiveJet/I");
00155 AnalysisTree->Branch("MomentumIJ",MomentumIJ,"MomentumIJ[NumberInclusiveJet]/F");
00156 AnalysisTree->Branch("TrasverseMomentumIJ",TransverseMomentumIJ,"TransverseMomentumIJ[NumberInclusiveJet]/F");
00157 AnalysisTree->Branch("EtaIJ",EtaIJ,"EtaIJ[NumberInclusiveJet]/F");
00158 AnalysisTree->Branch("PhiIJ",PhiIJ,"PhiIJ[NumberInclusiveJet]/F");
00159
00160
00161 AnalysisTree->Branch("NumberChargedJet",&NumberChargedJet,"NumberChargedJet/I");
00162 AnalysisTree->Branch("MomentumCJ",MomentumCJ,"MomentumCJ[NumberChargedJet]/F");
00163 AnalysisTree->Branch("TrasverseMomentumCJ",TransverseMomentumCJ,"TransverseMomentumCJ[NumberChargedJet]/F");
00164 AnalysisTree->Branch("EtaCJ",EtaCJ,"EtaCJ[NumberChargedJet]/F");
00165 AnalysisTree->Branch("PhiCJ",PhiCJ,"PhiCJ[NumberChargedJet]/F");
00166
00167
00168 AnalysisTree->Branch("NumberTracksJet",&NumberTracksJet,"NumberTracksJet/I");
00169 AnalysisTree->Branch("MomentumTJ",MomentumTJ,"MomentumTJ[NumberTracksJet]/F");
00170 AnalysisTree->Branch("TrasverseMomentumTJ",TransverseMomentumTJ,"TransverseMomentumTJ[NumberTracksJet]/F");
00171 AnalysisTree->Branch("EtaTJ",EtaTJ,"EtaTJ[NumberTracksJet]/F");
00172 AnalysisTree->Branch("PhiTJ",PhiTJ,"PhiTJ[NumberTracksJet]/F");
00173
00174
00175 AnalysisTree->Branch("NumberCaloJet",&NumberCaloJet,"NumberCaloJet/I");
00176 AnalysisTree->Branch("MomentumEHJ",MomentumEHJ,"MomentumEHJ[NumberCaloJet]/F");
00177 AnalysisTree->Branch("TrasverseMomentumEHJ",TransverseMomentumEHJ,"TransverseMomentumEHJ[NumberCaloJet]/F");
00178 AnalysisTree->Branch("EtaEHJ",EtaEHJ,"EtaEHJ[NumberCaloJet]/F");
00179 AnalysisTree->Branch("PhiEHJ",PhiEHJ,"PhiEHJ[NumberCaloJet]/F");
00180
00181
00182
00183
00184
00185
00186 MonteCarlo = new TClonesArray("TLorentzVector", 10000);
00187 AnalysisTree->Branch("MonteCarlo", "TClonesArray", &MonteCarlo, 128000, 0);
00188
00189 Track = new TClonesArray("TLorentzVector", 10000);
00190 AnalysisTree->Branch("Track", "TClonesArray", &Track, 128000, 0);
00191
00192 InclusiveJet = new TClonesArray("TLorentzVector", 10000);
00193 AnalysisTree->Branch("InclusiveJet", "TClonesArray", &InclusiveJet, 128000, 0);
00194
00195 ChargedJet = new TClonesArray("TLorentzVector", 10000);
00196 AnalysisTree->Branch("ChargedJet", "TClonesArray", &ChargedJet, 128000, 0);
00197
00198 TracksJet = new TClonesArray("TLorentzVector", 10000);
00199 AnalysisTree->Branch("TracksJet", "TClonesArray", &TracksJet, 128000, 0);
00200
00201 CalorimeterJet = new TClonesArray("TLorentzVector", 10000);
00202 AnalysisTree->Branch("CalorimeterJet", "TClonesArray", &CalorimeterJet, 128000, 0);
00203
00204 acceptedTriggers = new TClonesArray("TObjString", 10000);
00205 AnalysisTree->Branch("acceptedTriggers", "TClonesArray", &acceptedTriggers, 128000, 0);
00206
00207 }
00208
00209
00210 void AnalysisRootpleProducer::analyze( const Event& e, const EventSetup& )
00211 {
00212
00213 e.getByLabel( triggerResultsTag, triggerResults );
00214 triggerNames.init( *(triggerResults.product()) );
00215
00216 acceptedTriggers->Clear();
00217 unsigned int iAcceptedTriggers( 0 );
00218 if ( triggerResults.product()->wasrun() )
00219 {
00220
00221
00222 if ( triggerResults.product()->accept() )
00223 {
00224
00225
00226 const unsigned int n_TriggerResults( triggerResults.product()->size() );
00227 for ( unsigned int itrig( 0 ); itrig < n_TriggerResults; ++itrig )
00228 {
00229 if ( triggerResults.product()->accept( itrig ) )
00230 {
00231
00232
00233
00234
00235
00236
00237
00238 new((*acceptedTriggers)[iAcceptedTriggers]) TObjString( (triggerNames.triggerName( itrig )).c_str() );
00239 ++iAcceptedTriggers;
00240 }
00241 }
00242 }
00243 }
00244
00245
00246
00247
00248 if(!onlyRECO){
00249
00250 e.getByLabel( mcEvent , EvtHandle );
00251 e.getByLabel( chgGenPartCollName, CandHandleMC );
00252 e.getByLabel( chgJetCollName , ChgGenJetsHandle );
00253 e.getByLabel( genJetCollName , GenJetsHandle );
00254
00255 const HepMC::GenEvent* Evt = EvtHandle->GetEvent() ;
00256
00257 EventKind = Evt->signal_process_id();
00258
00259 std::vector<math::XYZTLorentzVector> GenPart;
00260 std::vector<GenJet> ChgGenJetContainer;
00261 std::vector<GenJet> GenJetContainer;
00262
00263 GenPart.clear();
00264 ChgGenJetContainer.clear();
00265 GenJetContainer.clear();
00266 MonteCarlo->Clear();
00267 InclusiveJet->Clear();
00268 ChargedJet->Clear();
00269
00270
00271 if (ChgGenJetsHandle->size()){
00272
00273 for ( GenJetCollection::const_iterator it(ChgGenJetsHandle->begin()), itEnd(ChgGenJetsHandle->end());
00274 it!=itEnd; ++it)
00275 {
00276 ChgGenJetContainer.push_back(*it);
00277 }
00278
00279 std::stable_sort(ChgGenJetContainer.begin(),ChgGenJetContainer.end(),GenJetSort());
00280
00281 std::vector<GenJet>::const_iterator it(ChgGenJetContainer.begin()), itEnd(ChgGenJetContainer.end());
00282 for ( int iChargedJet(0); it != itEnd; ++it, ++iChargedJet)
00283 {
00284 fillChargedJet(it->p(),it->pt(),it->eta(),it->phi());
00285 new((*ChargedJet)[iChargedJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
00286 }
00287 }
00288
00289
00290
00291 if (GenJetsHandle->size()){
00292
00293 for ( GenJetCollection::const_iterator it(GenJetsHandle->begin()), itEnd(GenJetsHandle->end());
00294 it!=itEnd; ++it )
00295 {
00296 GenJetContainer.push_back(*it);
00297 }
00298
00299 std::stable_sort(GenJetContainer.begin(),GenJetContainer.end(),GenJetSort());
00300
00301 std::vector<GenJet>::const_iterator it(GenJetContainer.begin()), itEnd(GenJetContainer.end());
00302 for ( int iInclusiveJet(0); it != itEnd; ++it, ++iInclusiveJet)
00303 {
00304 fillInclusiveJet(it->p(),it->pt(),it->eta(),it->phi());
00305 new((*InclusiveJet)[iInclusiveJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
00306 }
00307 }
00308
00309
00310
00311 if (CandHandleMC->size()){
00312
00313 for (vector<GenParticle>::const_iterator it(CandHandleMC->begin()), itEnd(CandHandleMC->end());
00314 it != itEnd;it++)
00315 {
00316 GenPart.push_back(it->p4());
00317 }
00318
00319 std::stable_sort(GenPart.begin(),GenPart.end(),GreaterPt());
00320
00321 std::vector<math::XYZTLorentzVector>::const_iterator it(GenPart.begin()), itEnd(GenPart.end());
00322 for( int iMonteCarlo(0); it != itEnd; ++it, ++iMonteCarlo )
00323 {
00324 fillMCParticles(it->P(),it->Pt(),it->Eta(),it->Phi());
00325 new((*MonteCarlo)[iMonteCarlo]) TLorentzVector(it->Px(), it->Py(), it->Pz(), it->E());
00326 }
00327 }
00328
00329 }
00330
00331
00332
00333
00334 e.getByLabel( tracksCollName , CandHandleRECO );
00335 e.getByLabel( recoCaloJetCollName, RecoCaloJetsHandle );
00336 e.getByLabel( tracksJetCollName , TracksJetsHandle );
00337
00338 std::vector<math::XYZTLorentzVector> Tracks;
00339 std::vector<BasicJet> TracksJetContainer;
00340 std::vector<CaloJet> RecoCaloJetContainer;
00341
00342 Tracks.clear();
00343 TracksJetContainer.clear();
00344 RecoCaloJetContainer.clear();
00345
00346 Track->Clear();
00347 TracksJet->Clear();
00348 CalorimeterJet->Clear();
00349
00350 if(RecoCaloJetsHandle->size())
00351 {
00352 for(CaloJetCollection::const_iterator it(RecoCaloJetsHandle->begin()), itEnd(RecoCaloJetsHandle->end());
00353 it!=itEnd;++it)
00354 {
00355 RecoCaloJetContainer.push_back(*it);
00356 }
00357 std::stable_sort(RecoCaloJetContainer.begin(),RecoCaloJetContainer.end(),CaloJetSort());
00358
00359 std::vector<CaloJet>::const_iterator it(RecoCaloJetContainer.begin()), itEnd(RecoCaloJetContainer.end());
00360 for( int iCalorimeterJet(0); it != itEnd; ++it, ++iCalorimeterJet)
00361 {
00362 fillCaloJet(it->p(),it->pt(),it->eta(),it->phi());
00363 new((*CalorimeterJet)[iCalorimeterJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
00364 }
00365 }
00366
00367 if(TracksJetsHandle->size())
00368 {
00369 for(BasicJetCollection::const_iterator it(TracksJetsHandle->begin()), itEnd(TracksJetsHandle->end());
00370 it!=itEnd;++it)
00371 {
00372 TracksJetContainer.push_back(*it);
00373 }
00374 std::stable_sort(TracksJetContainer.begin(),TracksJetContainer.end(),BasicJetSort());
00375
00376 std::vector<BasicJet>::const_iterator it(TracksJetContainer.begin()), itEnd(TracksJetContainer.end());
00377 for(int iTracksJet(0); it != itEnd; ++it, ++iTracksJet)
00378 {
00379 fillTracksJet(it->p(),it->pt(),it->eta(),it->phi());
00380 new((*TracksJet)[iTracksJet]) TLorentzVector(it->px(), it->py(), it->pz(), it->energy());
00381 }
00382 }
00383
00384 if(CandHandleRECO->size())
00385 {
00386 for(CandidateCollection::const_iterator it(CandHandleRECO->begin()), itEnd(CandHandleRECO->end());
00387 it!=itEnd;++it)
00388 {
00389 Tracks.push_back(it->p4());
00390 }
00391 std::stable_sort(Tracks.begin(),Tracks.end(),GreaterPt());
00392
00393 std::vector<math::XYZTLorentzVector>::const_iterator it( Tracks.begin()), itEnd(Tracks.end());
00394 for(int iTracks(0); it != itEnd; ++it, ++iTracks)
00395 {
00396 fillTracks(it->P(),it->Pt(),it->Eta(),it->Phi());
00397 new ((*Track)[iTracks]) TLorentzVector(it->Px(), it->Py(), it->Pz(), it->E());
00398 }
00399 }
00400
00401 store();
00402 }
00403
00404 void AnalysisRootpleProducer::endJob()
00405 {
00406 }
00407