My first analyzer
I'll start by trying to follow the instructions at <https://twiki.cern.ch/twiki/bin/view/CMS/WorkBookWriteFrameworkModule>. After the standard start-up stuff, and moving to the src directory, I did:
mkdir Demo
cd Demo
mkedanlzr FirstAnalyzer
This created the file FirstAnalyzer/src/FirstAnalyzer.cc. Note that there is no corresponding
file in the interface directory; it appears that the full class delcaration is done in the .cc
file. You can do that, I guess, although maybe not easily extensible. Should look at coding
rules.
Here is a config file that I was able to put together, starting from the suggested one.
process Demo = {
#keep the logging output to a nice level
include "FWCore/MessageLogger/data/MessageLogger.cfi"
source = PoolSource
{
untracked int32 maxEvents = 1
untracked vstring fileNames = { "file:///opt/cms/Higgs_ZZ.root"}
}
#untracked vstring fileNames =
# {"/store/RelVal/2006/12/16/RelVal120Higgs-ZZ-4Mu/0000/B8EBDCD5-578D-DB11-99D6-0017312B554B.root"}
module demo = FirstAnalyzer { }
module dump = EventContentAnalyzer {}
path p = {demo & dump}
}
Sure enough, it does dump out a ton of stuff. In particular, in the big dump, I get
a line that says
++recoMuons "globalMuons" ""
These are presumably the muons I want. However, before I can get to that, I have to
do the nasty re-reco of 120 data, I believe. Now, everyone else has been doing this
by writing out a file of re-recoed stuff, but I wonder if it can be done on the fly.
Why write out a new file? Maybe I will explore that, although I shouldn't spend too
much time on it.
But first, maybe I'll just work on coding up something that gets the muons and
plots some stuff, just to have that. And hey, by putting in the lines
//Get the muons
Handle<MuonCollection> muons;
iEvent.getByLabel("globalMuons",muons);
std::cout << "Number of muons: " << muons->size() << std::endl;
I can in fact print out the number of muons in each event. Maybe you don't have to
re-reco too much? I'll soon find out (I hope).
Later:
I managed to write out my first histogram! In the delcaration of my class, I put
TFile* hFile;
TH1F* hAllMuonPt;
and then in the analyze method I had
for (MuonCollection::const_iterator imu = muons->begin();
imu != muons->end(); imu++) {
hAllMuonPt->Fill(imu->pt());
}
and I wrote and closed the file at end job, and sure enough, I got a plot
of what I believe is the muon pT. Mind you, I had to add the appropriate
header file includes, and I had to change my BuildFile to have a dependency
on ROOT. But it wasn't too hard.

Then I tried something more interesting. A muon has three different possible
momenta -- the one from the silicon track, the one from the muon system, and
the one from a combined fit of some sort. It would be fun to compare these.
I coded this as follows:
std::cout << "combined pT " << imu->combinedMuon()->pt() <<
" standalone pT " << imu->standAloneMuon()->pt() <<
" track pT " << imu->track()->pt() << std::endl;
Unfortunately, all the pT's in question came back as zero. For all I
know, this is where I have to do the re-reco....
In fact, that turned out to be the case. Fortunately, Jia Fu had done
the re-reco already and written out the output. It's in his home
area as rereco.root. Now I was able to get the following output:
Number of muons: 4
combined pT 41.5383 standalone pT 43.3298 track pT 41.5306
combined pT 60.1341 standalone pT 61.605 track pT 60.0624
combined pT 44.0719 standalone pT 45.0048 track pT 44.0706
combined pT 51.1004 standalone pT 62.9869 track pT 51.0571
Number of muons: 4
combined pT 35.5072 standalone pT 38.4574 track pT 35.6901
combined pT 49.351 standalone pT 42.6805 track pT 49.5279
combined pT 55.7431 standalone pT 56.3819 track pT 55.9071
combined pT 34.4881 standalone pT 34.2533 track pT 34.5378
Number of muons: 2
combined pT 51.9391 standalone pT 28.5807 track pT 52.0099
combined pT 36.3055 standalone pT 30.3299 track pT 36.217
Number of muons: 4
combined pT 31.9863 standalone pT 31.7618 track pT 31.9387
combined pT 31.356 standalone pT 35.2338 track pT 31.359
combined pT 41.5018 standalone pT 45.7689 track pT 41.4562
combined pT 39.7872 standalone pT 42.6279 track pT 40.0371
and so forth. And here are some resulting plots:


So we can see that the track pT completely dominates the combined fit; there is good correlation
with the standalone muon, but the track is better if you can get it. There, my first useful plot!