Difference: WorkBookPATExampleFWLite (1 vs. 21)

Revision 212010-09-16 - ColinBernet

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATTutorial"
Changed:
<
<

PAT Examples: FWLite Example

>
>

PAT Examples: FWLite Example in a Compiled Analyzer

 

Contents

<!-- Keep the list of contents in this format - it is important for the pdf rendering of the workbook -->
Changed:
<
<
>
>
 
Line: 21 to 21
 
  • how to book and fill histograms with plain root.
  • how to access and loop the pat::Muon collection within a FWLiteAnalyzer.
Changed:
<
<
ALERT! Note: This example is based on the PAT tutorials.
>
>
ALERT! Notes:
  • This example is based on the PAT tutorials.
  • FWLite is not supported in a non-compiled CINT macro.
  If you are using this for the PAT tutorials, use these tags:
Line: 45 to 46
 

Changed:
<
<

How to run the code

>
>

How to compile and run the code

  Warning, important Note: For this example you will need to have produced PATLayer1_Output.fromAOD_full.root (see WorkBookPATAccessExercise fro more details).

Revision 202010-05-11 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATTutorial"

PAT Examples: FWLite Example

Revision 192010-05-11 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATTutorial"

PAT Examples: FWLite Example

Revision 182010-04-28 - RogerWolf

Line: 1 to 1
Changed:
<
<
META TOPICPARENT name="WorkBookPATExamples"
>
>
META TOPICPARENT name="WorkBookPATTutorial"
 

PAT Examples: FWLite Example

Contents

Revision 172010-04-27 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 47 to 47
 

How to run the code

Changed:
<
<
Warning, important Note: For this example you will need to have produced PATLayer1_Output.fromAOD_full.root (see WorkBookPATExampleBasic fro more details).
>
>
Warning, important Note: For this example you will need to have produced PATLayer1_Output.fromAOD_full.root (see WorkBookPATAccessExercise fro more details).
  Compile and run the example as given below:
Line: 207 to 207
 </>
<!--/twistyPlugin-->

ALERT! Note:

Changed:
<
<
We also create a directory in the root file. In this way the file structure is the same as for the WorkBookPATExampleBasic.
>
>
We also create a directory in the root file. In this way the file structure is the same as for the WorkBookPATAccessExercise.
 

Revision 162010-03-29 - SalvatoreRRappoccio

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 22 to 22
 
  • how to access and loop the pat::Muon collection within a FWLiteAnalyzer.

ALERT! Note:

Changed:
<
<
This example currently is supported on the following CMSSW versions:
>
>
This example is based on the PAT tutorials.
 
Changed:
<
<
Development Branch cvs tag
>
>
If you are using this for the PAT tutorials, use these tags:

Tutorial Branch cvs tag
 
CMSSW_2_2_X patTutorial_june09_module1
CMSSW_3_1_X patTutorial_sept09_module1
CMSSW_3_3_X patTutorial_dec09_module1
CMSSW_3_5_X patTutorial_mar10_module1
Added:
>
>
For at-home users, please see here for most up-to-date prescriptions! This tutorial assumes you are using the 3_5_X branch.
 
Changed:
<
<
The actual example is given for CMSSW_3_5_3. For other software versions follow the recipes given for these software versions accordingly.
>
>
In the following we assume that the CMSSW environment is setup (cmsenv) and you are in the $CMSSW_BASE/src directory.
 

How to get the code

Changed:
<
<
To run the example checkout the following tags:
>
>
To run the example follow the procedure here:
 
Changed:
<
<
addpkg PhysicsTools/PatExamples patTutorial_mar10_module1
>
>
https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATReleaseNotes35X
 

Revision 152010-03-07 - BenediktHegner

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 123 to 123
 </>
<!--/twistyPlugin-->

ALERT! Note:

Changed:
<
<
Before doing anything you always have to enable the AutoLibraryLoader. Take care where you book the histograms not to get mixed up with root file directories. In this example we book the histograms before opening any file. Then we open the input file, loop the events and close it again. Only after that we open a new output file and write the histograms there.
>
>
Before doing anything you always have to enable the AutoLibraryLoader. Take care where you book the histograms not to get mixed up with root file directories. In this example we book the histograms before opening any file. Then we open the input file, loop the events and close it again.
 
Changed:
<
<
In the second part the events are looped, within one event the pat::Muon collection for selectedLayer1Muons is recieved from the input file and the muon collection is looped. A few simple histograms are filled. After the loop the input file is closed again:
>
>
In the second part the events are looped, within one event the pat::Muon collection for cleanPatMuons is received from the input file and the muon collection is looped. A few simple histograms are filled. After the loop the input file is closed again:
  %TWISTY{mode="div" showlink="Show " hidelink="Hide " firststart="show" showimgright="/twiki/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif"
Line: 211 to 211
 
Changed:
<
<
Finally you should never forget to free the allocated memory, there's nothing to be done ere tohugh when using the TFileService:
>
>
Finally you should never forget to free the allocated memory, there's nothing to be done here though when using the TFileService:
  %TWISTY{mode="div" showlink="Show " hidelink="Hide " firststart="show" showimgright="/twiki/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif"

Revision 142010-03-07 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 71 to 71
 hideimgright="/twiki/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"}%

%SYNTAX{ syntax="cpp"}%

Changed:
<
<
>
>
 
Line: 105 to 111
  AutoLibraryLoader::enable();

// book a set of histograms

Changed:
<
<
TH1F* muonPt_ = new TH1F("muonPt", "pt", 100, 0.,300.); TH1F* muonEta_ = new TH1F("muonEta","eta", 100, -3., 3.); TH1F* muonPhi_ = new TH1F("muonPhi","phi", 100, -5., 5.);
>
>
fwlite::TFileService fs = fwlite::TFileService("analyzePatBasics.root"); TFileDirectory theDir = fs.mkdir("analyzeBasicPat"); TH1F* muonPt_ = theDir.make("muonPt", "pt", 100, 0.,300.); TH1F* muonEta_ = theDir.make("muonEta","eta", 100, -3., 3.); TH1F* muonPhi_ = theDir.make("muonPhi","phi", 100, -5., 5.);
  // open input file (can be located on castor) TFile* inFile = TFile::Open( "file:PATLayer1_Output.fromAOD_full.root" );
Line: 137 to 145
  // loop the events unsigned int iEvent=0;
Changed:
<
<
fwlite::Event event(inFile); for(event.toBegin(); event.atEnd(); ++event, ++iEvent){
>
>
fwlite::Event ev(inFile); for(ev.toBegin(); ev.atEnd(); ++ev, ++iEvent){ edm::EventBase const & event = ev;
  // break loop after end of file is reached // or after 1000 events have been processed if( iEvent==1000 ) break;
Line: 148 to 158
  std::cout << " processing event: " << iEvent << std::endl; }
Changed:
<
<
// fwlite::Handle to to muon collection fwlite::Handle<std::vector<pat::Muon> > muons; muons.getByLabel(event, "cleanPatMuons");
>
>
// Handle to the muon collection edm::Handle<std::vector<pat::Muon> > muons; edm::InputTag muonLabel("cleanPatMuons"); event.getByLabel(muonLabel, muons);
  // loop muon collection and fill histograms for(unsigned i=0; i<muons->size(); ++i){
Line: 200 to 211
 
Changed:
<
<
Finally you should never forget to free the allocated memory:
>
>
Finally you should never forget to free the allocated memory, there's nothing to be done ere tohugh when using the TFileService:
  %TWISTY{mode="div" showlink="Show " hidelink="Hide " firststart="show" showimgright="/twiki/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif"
Line: 208 to 219
  %SYNTAX{ syntax="cpp"}% // ----------------------------------------------------------------------
Changed:
<
<
// Fourth Part:
>
>
// Third Part:
  //
Changed:
<
<
// * never forgett to free the memory of the histograms
>
>
// * never forget to free the memory of objects you created
  // ----------------------------------------------------------------------
Changed:
<
<
// free allocated space delete muonPt_; delete muonEta_; delete muonPhi_;
>
>
// in this example there is nothing to do
  // that's it! return 0;

Revision 132010-03-07 - BenediktHegner

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 40 to 40
 To run the example checkout the following tags:
Changed:
<
<
cvs co -r patTutorial_mar10_module1 PhysicsTools/PatExamples
>
>
addpkg PhysicsTools/PatExamples patTutorial_mar10_module1
 

Revision 122010-03-07 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 31 to 31
 
CMSSW_3_5_X patTutorial_mar10_module1
Changed:
<
<
The actual example is given for CMSSW_3_5_3. For other software versions follow the recipes given for these software versions accordingly.
>
>
The actual example is given for CMSSW_3_5_3. For other software versions follow the recipes given for these software versions accordingly.
 

Revision 112010-03-06 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 28 to 28
 
CMSSW_2_2_X patTutorial_june09_module1
CMSSW_3_1_X patTutorial_sept09_module1
CMSSW_3_3_X patTutorial_dec09_module1
Added:
>
>
CMSSW_3_5_X patTutorial_mar10_module1
 
Changed:
<
<
The actual example is given for CMSSW_3_3_4. For other software versions follow the recipes given for these software versions accordingly.
>
>
The actual example is given for CMSSW_3_5_3. For other software versions follow the recipes given for these software versions accordingly.
 

Line: 38 to 40
 To run the example checkout the following tags:
Changed:
<
<
cvs co -r patTutorial_dec09_module1 PhysicsTools/PatExamples
>
>
cvs co -r patTutorial_mar10_module1 PhysicsTools/PatExamples
 
Line: 148 to 150
  // fwlite::Handle to to muon collection fwlite::Handle<std::vector<pat::Muon> > muons;
Changed:
<
<
muons.getByLabel(event, "cleanLayer1Muons");
>
>
muons.getByLabel(event, "cleanPatMuons");
  // loop muon collection and fill histograms for(unsigned i=0; i<muons->size(); ++i){
Line: 239 to 241
 hideimgright="/twiki/pub/TWiki/TWikiDocGraphics/toggleclose-small.gif"}%

Reviewer/Editor and Date (copy from screen) Comments
Changed:
<
<
RogerWolf - 11 june 2009 Moved from SWGuidePATExamples
RogerWolf - 13 May 2009 Updated to CMSSW_3_1_X
RogerWolf - 26 Nov 2009 Updated to CMSSW_3_3_X
>
>
RogerWolf - 06 Mar 2010 Updated to CMSSW_3_5_X
  Responsible: RogerWolf
Last reviewed by: most recent reviewer and date </>
<!--/twistyPlugin-->
Deleted:
<
<

-- RogerWolf - 11 Jun 2009

 \ No newline at end of file

Revision 102010-03-02 - AreshVedaee

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 249 to 249
 

-- RogerWolf - 11 Jun 2009

Deleted:
<
<
META PREFERENCE name="ALLOWTOPICVIEW" title="ALLOWTOPICVIEW" type="Set" value="cms-web-access, cms-cern-it-web-access"

Revision 92010-01-01 - KatiLassilaPerini

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 249 to 249
 

-- RogerWolf - 11 Jun 2009 \ No newline at end of file

Added:
>
>
META PREFERENCE name="ALLOWTOPICVIEW" title="ALLOWTOPICVIEW" type="Set" value="cms-web-access, cms-cern-it-web-access"

Revision 82009-12-10 - KatiLassilaPerini

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 227 to 227
 

How to get more information

Changed:
<
<
To learn more about creating and using FWLite executables have a look at PhysicsToolsFWLiteExecutable.
>
>
To learn more about creating and using FWLite executables have a look at WorkBookFWLiteExecutable.
 You have more questions? Don't hesitate to contact the SWGuidePAT#Support.

Revision 72009-11-30 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Revision 62009-11-26 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 22 to 22
 
  • how to access and loop the pat::Muon collection within a FWLiteAnalyzer.

ALERT! Note:

Changed:
<
<
This example currently is only supported on the following develpment branches:
>
>
This example currently is supported on the following CMSSW versions:
 
Development Branch cvs tag
Changed:
<
<
B2_2_X patTutorial_june09_module1
HEAD patTutorial_sept09_module1
>
>
CMSSW_2_2_X patTutorial_june09_module1
CMSSW_3_1_X patTutorial_sept09_module1
CMSSW_3_3_X patTutorial_dec09_module1

The actual example is given for CMSSW_3_3_4. For other software versions follow the recipes given for these software versions accordingly.

 
Deleted:
<
<
The actual example is given for CMSSW_3_1_2. For other software versions follow the recipes given for these software versions accordingly.
 

How to get the code

Changed:
<
<
To run the example check out the latest tags for PAT as given on the https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATRecipes#CMSSW_3_1_X and checkout the following tags in addition:
>
>
To run the example checkout the following tags:
 
Changed:
<
<
cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/src cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/interface cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/BuildFile cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/bin/BuildFile cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.cc
>
>
cvs co -r patTutorial_dec09_module1 PhysicsTools/PatExamples
 
Added:
>
>
 

How to run the code

Line: 46 to 45
 

How to run the code

Added:
>
>
Warning, important Note: For this example you will need to have produced PATLayer1_Output.fromAOD_full.root (see WorkBookPATExampleBasic fro more details).
 Compile and run the example as given below:

scram b 
Added:
>
>
cmsenv
 PatBasicFWLiteAnalyzer
Deleted:
<
<
rehash
 
Changed:
<
<
ALERT! Note 1: You might have to rehash after compiling to get the executable tab completion.

Warning, important Note 2: For this example you will need to have produced PATLayer1_Output.fromAOD_full.root (see previous exercise: WorkBookPATExampleBasic ).

>
>
ALERT! Note: You might have to rehash after compiling to get the executable tab completion. Instead of rehash you also just retype cmsenv in your working directory.
 

Line: 114 to 113
 </>
<!--/twistyPlugin-->

ALERT! Note:

Changed:
<
<
Before doing anything you always have to enable the AutoLibraryLoader. Take care where you book the histograms not to get mixed up with root file directories. In this example we book the histograms before opening any file. Then we open the input file, loop the events and close it again. ONly after that we open a new output file and write the histograms there.
>
>
Before doing anything you always have to enable the AutoLibraryLoader. Take care where you book the histograms not to get mixed up with root file directories. In this example we book the histograms before opening any file. Then we open the input file, loop the events and close it again. Only after that we open a new output file and write the histograms there.
 
Changed:
<
<
In the second part the events are looped, within one event the pat::Muon collection for selectedLayer1Muons is recieved from the input file and the muon collection is looped. A few simple histograms are filled. After the loop the iput file is closed again:
>
>
In the second part the events are looped, within one event the pat::Muon collection for selectedLayer1Muons is recieved from the input file and the muon collection is looped. A few simple histograms are filled. After the loop the input file is closed again:
  %TWISTY{mode="div" showlink="Show " hidelink="Hide " firststart="show" showimgright="/twiki/pub/TWiki/TWikiDocGraphics/toggleopen-small.gif"
Line: 164 to 163
 </>
<!--/twistyPlugin-->

ALERT! Note:

Changed:
<
<
The fwlite::Handle looks very similar to the edm::Handle. The functionality is all the same. The pat::Muon collection was just taken as an example. For any other collection you can proceed in a similar way. Have a look to WorkBookPATDataFormats to find out what collection labels available (after running the default workflow). Have a look to WorkBookPATWorkflow to find out how they are produced and what they mean. As this is a very simple example we stop after 1000 events.
>
>
The fwlite::Handle looks very similar to the edm::Handle. The functionality is all the same. The pat::Muon collection was just taken as an example. For any other collection you can proceed in a similar way. Have a look to WorkBookPATDataFormats to find out what collection labels are available (after running the default workflow). Have a look to WorkBookPATWorkflow to find out how they are produced and what they mean. As this is a very simple example we stop after 1000 events.
 
Line: 228 to 227
 

How to get more information

Added:
>
>
To learn more about creating and using FWLite executables have a look at PhysicsToolsFWLiteExecutable.
 You have more questions? Don't hesitate to contact the SWGuidePAT#Support.

Review status

Added:
>
>
<!--/twistyPlugin twikiMakeVisibleInline-->
 
Reviewer/Editor and Date (copy from screen) Comments
Changed:
<
<
RogerWolf - 13 May 2009 Created the page
>
>
RogerWolf - 11 june 2009 Moved from SWGuidePATExamples
 
RogerWolf - 13 May 2009 Updated to CMSSW_3_1_X
Added:
>
>
RogerWolf - 26 Nov 2009 Updated to CMSSW_3_3_X
  Responsible: RogerWolf
Last reviewed by: most recent reviewer and date
Changed:
<
<
>
>
<!--/twistyPlugin-->
 

-- RogerWolf - 11 Jun 2009

Revision 52009-11-25 - KatiLassilaPerini

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 164 to 164
 </>
<!--/twistyPlugin-->

ALERT! Note:

Changed:
<
<
The fwlite::Handle looks very similar to the edm::Handle. The functionality is all the same. The pat::Muon collection was just taken as an example. For any other collection you can proceed in a similar way. Have a look to SWGuidePATDataFormats to find out what collection labels available (after running the default workflow). Have a look to SWGuidePATWorkflow to find out how they are produced and what they mean. As this is a very simple example we stop after 1000 events.
>
>
The fwlite::Handle looks very similar to the edm::Handle. The functionality is all the same. The pat::Muon collection was just taken as an example. For any other collection you can proceed in a similar way. Have a look to WorkBookPATDataFormats to find out what collection labels available (after running the default workflow). Have a look to WorkBookPATWorkflow to find out how they are produced and what they mean. As this is a very simple example we stop after 1000 events.
 

Revision 42009-08-31 - AndresOsorio

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 54 to 54
 rehash
Changed:
<
<
ALERT! Note:
>
>
ALERT! Note 1:
 You might have to rehash after compiling to get the executable tab completion.
Added:
>
>
Warning, important Note 2: For this example you will need to have produced PATLayer1_Output.fromAOD_full.root (see previous exercise: WorkBookPATExampleBasic ).
 

Find out more about the details

Revision 32009-08-31 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 22 to 22
 
  • how to access and loop the pat::Muon collection within a FWLiteAnalyzer.

ALERT! Note:

Changed:
<
<
This example currently is only supported on the B2_2_X development branch of PAT.
>
>
This example currently is only supported on the following develpment branches:

Development Branch cvs tag
B2_2_X patTutorial_june09_module1
HEAD patTutorial_sept09_module1

The actual example is given for CMSSW_3_1_2. For other software versions follow the recipes given for these software versions accordingly.

 

How to get the code

Changed:
<
<
To run the example check out the latest tags for PAT as given on the SWGuidePATRecipes#CMSSW_2_2_X_with_PAT_version_2 and checkout the following tags in addition:
>
>
To run the example check out the latest tags for PAT as given on the https://twiki.cern.ch/twiki/bin/view/CMS/SWGuidePATRecipes#CMSSW_3_1_X and checkout the following tags in addition:
 
Changed:
<
<
cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/src cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/interface cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/BuildFile cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/bin/BuildFile cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.cc
>
>
cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/src cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/interface cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/BuildFile cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/bin/BuildFile cvs co -r patTutorial_sept09_module1 PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.cc
 

Line: 227 to 233
 
Reviewer/Editor and Date (copy from screen) Comments
RogerWolf - 13 May 2009 Created the page
Added:
>
>
RogerWolf - 13 May 2009 Updated to CMSSW_3_1_X
  Responsible: RogerWolf
Last reviewed by: most recent reviewer and date

Revision 22009-06-15 - RogerWolf

Line: 1 to 1
 
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Line: 30 to 30
 To run the example check out the latest tags for PAT as given on the SWGuidePATRecipes#CMSSW_2_2_X_with_PAT_version_2 and checkout the following tags in addition:
Changed:
<
<
cd CMSSW_2_2_13/src cmsenv cvs co -A PhysicsTools/PatExamples/BuildFile cvs co -A PhysicsTools/PatExamples/bin/BuildFile cvs co -A PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.cc
>
>
cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/src cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/interface cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/BuildFile cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/bin/BuildFile cvs co -r patTutorial_june09_module1 PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.cc
 

Line: 45 to 45
 
scram b 
PatBasicFWLiteAnalyzer
Added:
>
>
rehash
 

ALERT! Note:

Line: 99 to 100
  TH1F* muonPhi_ = new TH1F("muonPhi","phi", 100, -5., 5.);

// open input file (can be located on castor)

Changed:
<
<
TFile* inFile = TFile::Open( "dcap://dcache-ses-cms.desy.de/pnfs/desy.de/cms/tier2/store/user/rwolf/ttbar/patTuple_PATv2_ttbar_madgraph_1.root" );
>
>
TFile* inFile = TFile::Open( "file:PATLayer1_Output.fromAOD_full.root" );
 %ENDSYNTAX% </>
<!--/twistyPlugin-->
Line: 133 to 134
  if( iEvent==1000 ) break;

// simple event counter

Changed:
<
<
if(iEvent>0 && iEvent%100==0){
>
>
if(iEvent>0 && iEvent%1==0){
  std::cout << " processing event: " << iEvent << std::endl; }

// fwlite::Handle to to muon collection fwlite::Handle<std::vector<pat::Muon> > muons;

Changed:
<
<
muons.getByLabel(event, "selectedLayer1Muons");
>
>
muons.getByLabel(event, "cleanLayer1Muons");
  // loop muon collection and fill histograms for(unsigned i=0; i<muons->size(); ++i){

Revision 12009-06-11 - RogerWolf

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="WorkBookPATExamples"

PAT Examples: FWLite Example

Contents

<!-- Keep the list of contents in this format - it is important for the pdf rendering of the workbook -->

Introduction

In this example you will find how to access the pat::Muon collection within a simple FWLiteAnalyzer. You can find the FWLiteAnalyzer in the bin directory of the PatExamples package. It will provide you with the following information:

  • how to create an executable within a CMSSW package.
  • how to book and fill histograms with plain root.
  • how to access and loop the pat::Muon collection within a FWLiteAnalyzer.

ALERT! Note: This example currently is only supported on the B2_2_X development branch of PAT.

How to get the code

To run the example check out the latest tags for PAT as given on the SWGuidePATRecipes#CMSSW_2_2_X_with_PAT_version_2 and checkout the following tags in addition:

cd CMSSW_2_2_13/src
cmsenv
cvs co -A PhysicsTools/PatExamples/BuildFile  
cvs co -A PhysicsTools/PatExamples/bin/BuildFile  
cvs co -A PhysicsTools/PatExamples/bin/PatBasicFWLiteAnalyzer.cc  

How to run the code

Compile and run the example as given below:

scram b 
PatBasicFWLiteAnalyzer

ALERT! Note: You might have to rehash after compiling to get the executable tab completion.

Find out more about the details

You can find the compilation description for the executable in the bin/BuildFile:

<!--/twistyPlugin twikiMakeVisibleInline-->

<!-- SyntaxHighlightingPlugin -->
<use name=DataFormats/PatCandidates>
<use name=DataFormats/FWLite>
<use name=FWCore/Framework>
<use name=FWCore/FWLite>
<use name=rootcintex>
<use name=root> 
<environment>
 <bin file="PatBasicFWLiteAnalyzer.cc"> </bin>
</environment>
<!-- end SyntaxHighlightingPlugin -->
<!--/twistyPlugin-->


The FWLiteAnalyzer itself only consists of a main function. In the first part the histograms are booked and the file is opened:

<!--/twistyPlugin twikiMakeVisibleInline-->

<!-- SyntaxHighlightingPlugin -->
// ----------------------------------------------------------------------
  // First Part: 
  //
  //  * enable the AutoLibraryLoader 
  //  * book the histograms of interest 
  //  * open the input file
  // ----------------------------------------------------------------------

  // load framework libraries
  gSystem->Load( "libFWCoreFWLite" );
  AutoLibraryLoader::enable();
  
  // book a set of histograms
  TH1F* muonPt_  = new TH1F("muonPt", "pt",    100,  0.,300.);
  TH1F* muonEta_ = new TH1F("muonEta","eta",   100, -3.,  3.);
  TH1F* muonPhi_ = new TH1F("muonPhi","phi",   100, -5.,  5.);  
  
  // open input file (can be located on castor)
  TFile* inFile = TFile::Open( "dcap://dcache-ses-cms.desy.de/pnfs/desy.de/cms/tier2/store/user/rwolf/ttbar/patTuple_PATv2_ttbar_madgraph_1.root" );
<!-- end SyntaxHighlightingPlugin -->
<!--/twistyPlugin-->

ALERT! Note: Before doing anything you always have to enable the AutoLibraryLoader. Take care where you book the histograms not to get mixed up with root file directories. In this example we book the histograms before opening any file. Then we open the input file, loop the events and close it again. ONly after that we open a new output file and write the histograms there.


In the second part the events are looped, within one event the pat::Muon collection for selectedLayer1Muons is recieved from the input file and the muon collection is looped. A few simple histograms are filled. After the loop the iput file is closed again:

<!--/twistyPlugin twikiMakeVisibleInline-->

<!-- SyntaxHighlightingPlugin -->
// ----------------------------------------------------------------------
  // Second Part: 
  //
  //  * loop the events in the input file 
  //  * receive the collections of interest via fwlite::Handle
  //  * fill the histograms
  //  * after the loop close the input file
  // ----------------------------------------------------------------------

  // loop the events
  unsigned int iEvent=0;
  fwlite::Event event(inFile);
  for(event.toBegin(); !event.atEnd(); ++event, ++iEvent){
    // break loop after end of file is reached 
    // or after 1000 events have been processed
    if( iEvent==1000 ) break;
    
    // simple event counter
    if(iEvent>0 && iEvent%100==0){
      std::cout << "  processing event: " << iEvent << std::endl;
    }

    // fwlite::Handle to to muon collection
    fwlite::Handle<std::vector<pat::Muon> > muons;
    muons.getByLabel(event, "selectedLayer1Muons");
    
    // loop muon collection and fill histograms
    for(unsigned i=0; i<muons->size(); ++i){
      muonPt_ ->Fill( (*muons)[i].pt()  );
      muonEta_->Fill( (*muons)[i].eta() );
      muonPhi_->Fill( (*muons)[i].phi() );
    }
  }  
  // close input file
  inFile->Close();
<!-- end SyntaxHighlightingPlugin -->
<!--/twistyPlugin-->

ALERT! Note: The fwlite::Handle looks very similar to the edm::Handle. The functionality is all the same. The pat::Muon collection was just taken as an example. For any other collection you can proceed in a similar way. Have a look to SWGuidePATDataFormats to find out what collection labels available (after running the default workflow). Have a look to SWGuidePATWorkflow to find out how they are produced and what they mean. As this is a very simple example we stop after 1000 events.


In the third part a new output file is opened and the histograms are written to file:

<!--/twistyPlugin twikiMakeVisibleInline-->

<!-- SyntaxHighlightingPlugin -->
// ----------------------------------------------------------------------
  // Third Part: 
  //
  //  * open the output file 
  //  * write the histograms to the output file
  //  * close the output file
  // ----------------------------------------------------------------------
  
  //open output file
  TFile outFile( "analyzePatBasics.root", "recreate" );
  outFile.mkdir(".analyzeBasicPat");
  outFile.cd(".analyzeBasicPat");
  muonPt_ ->Write( );
  muonEta_->Write( );
  muonPhi_->Write( );
  outFile.Close();
<!-- end SyntaxHighlightingPlugin -->
<!--/twistyPlugin-->

ALERT! Note: We also create a directory in the root file. In this way the file structure is the same as for the WorkBookPATExampleBasic.


Finally you should never forget to free the allocated memory:

<!--/twistyPlugin twikiMakeVisibleInline-->

<!-- SyntaxHighlightingPlugin -->
// ----------------------------------------------------------------------
  // Fourth Part: 
  //
  //  * never forgett to free the memory of the histograms
  // ----------------------------------------------------------------------

  // free allocated space
  delete muonPt_;
  delete muonEta_;
  delete muonPhi_;
  
  // that's it!
  return 0;
<!-- end SyntaxHighlightingPlugin -->
<!--/twistyPlugin-->

ALERT! Note: Make sure that the executable contains all header files you need. Also do not forget to re-compiled whenever you change something (like the name of the input file).

How to get more information

You have more questions? Don't hesitate to contact the SWGuidePAT#Support.

Review status

Reviewer/Editor and Date (copy from screen) Comments
RogerWolf - 13 May 2009 Created the page

Responsible: RogerWolf
Last reviewed by: most recent reviewer and date

-- RogerWolf - 11 Jun 2009

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback