Example code
For debug chunks:
Arrays staring with _f are defined elsewhere in the program. There
are used to fill an ntuple.
In expressions like hXXX->Fill(), hXXX is a histogram
vector<edm::THandle<L3DebugChunk> > l3debchunks;
// offline chunks
L3DebugChunkSel debugsl("offline");
edm::TKey<L3DebugChunk> l3debugkey(debugsl);
edm::THandle<L3DebugChunk> l3debughandle;
int num_chunks = l3debugkey.findAll(event,l3debchunks);
// cout << packageName() << " number of l3 debug chunks " << num_chunks << endl;
if (num_chunks != 1) {
cout << "****** Number of debug chunks is: " << num_chunks << endl;
}
else {
// You need at least one debug chunk (and in this case only one)
for this to make sense
l3debughandle = (*l3debchunks.begin());
if (!l3debughandle.isValid()) {
cout << "l3debughandle is invalid" << endl;
}
else {
L3DebugChunk::L3DebugChunkMap &debugMap
=*(const_cast<L3DebugChunk&>(*l3debughandle).getDebugInfo());
for(L3DebugChunk::map_iter it1=debugMap.begin();
it1!=debugMap.end(); it1++){
string toolid = (*it1).first;
// cout << "TOOOOOOL: " << toolid << endl;
if (toolid == "MUO_LOCAL") {
L3DebugInfo* data = (*it1).second;
L3DebugInfo *info = static_cast<L3DebugInfo*>(data);
L3TMuoLocalDebugInfo *localinfo = dynamic_cast<L3TMuoLocalDebugInfo*>(info);
if (localinfo == 0) {
cout << "Could not find local info. " << endl;
}
else {
const std::vector<Muon::Track>& muotrack = localinfo->getLocalTrackVector();
hnl3mu->Fill(Float_t(muotrack.size()));
for (int m =0; m < muotrack.size(); ++m) {
double scalefx = muotrack[m].getMomentum()/muotrack[m].getMomentA().mag();
hl3qual->Fill(muotrack[m].quality());
// at A layer
float pxa = muotrack[m].getMomentA().x();
float pya = muotrack[m].getMomentA().y();
float pza = muotrack[m].getMomentA().z();
// now I also want the local momentum
float pt = -1.0;
if (muotrack[m].getMomentA().mag() > 0.0) {
pt = muotrack[m].getMomentA().perp()/muotrack[m].getMomentA().mag()*muotrack[m].getMomentum();
}
if (_nL3Mu < 50) {
_fpxaL3Mu[_nL3Mu] = pxa;
_fpyaL3Mu[_nL3Mu] = pya;
_fpzaL3Mu[_nL3Mu] = pza;
_fqualL3Mu[_nL3Mu] = muotrack[m].quality();
_foctL3Mu[_nL3Mu] = muotrack[m].octant();
_fregL3Mu[_nL3Mu] = muotrack[m].region();
_fchargeL3Mu[_nL3Mu] = muotrack[m].getCharge();
_fptcorrL3Mu[_nL3Mu] = pt;
_fchi2L3Mu[_nL3Mu] = muotrack[m].getChi2();
_fscftrL3Mu[_nL3Mu] = scalefx;
_fawhitsL3Mu[_nL3Mu] = muotrack[m].getNwhitA();
_fashitsL3Mu[_nL3Mu] = muotrack[m].getNshitA();
_fbcwhitsL3Mu[_nL3Mu] = muotrack[m].getNwhitBC();
_fbcshitsL3Mu[_nL3Mu] = muotrack[m].getNshitBC();
++_nL3Mu;
} // (_nL3Mu < 50)
else {cout << "nL3Mu over limit !" << endl;}
} // for (int m =0; m < muotrack.size(); ++m)
} // else
} // MUO_LOCAL
} // debugMap
} // else
} // else
Note: 'find' might be more appropriate than an iterator when
using the map if you are just looking at one type of result.
Physics Results
L3ChunkSel physsel("online");
edm::TKey<L3Chunk> l3keyp(physsel);
edm::THandle<L3Chunk> thel3physchunk = l3keyp.find(event);
// check that we have found the chunk correctly
if (thel3physchunk.isValid()) {
// now get the map that points to all the L3PhysicsResults lists
L3Chunk::L3ChunkPhysToolMap l3map = thel3physchunk->getPhysToolMap();
L3Chunk::L3ChunkPhysToolMap::const_iterator l3mapIter;
for (l3mapIter = l3map.begin(); l3mapIter != l3map.end(); l3mapIter++) {
// cout << " L3 Physics Results List Instance " << l3mapIter->first << std::endl << std::endl;
string l3string toolid = (*l3mapIter).first;
// The tool I want is called 'Muon' of type L3TMuon (check in toollist.txt for your favourite tool)
if (toolid == "Muon") {
// inner loop over elements of each list
std::list<L3PhysicsResults*> l3list = l3mapIter->second;
std::list<L3PhysicsResults*>::const_iterator l3listIter;
for (l3listIter = l3list.begin(); l3listIter != l3list.end(); l3listIter++) {
L3PhysicsResults* l3PhysRes = *l3listIter;
// check that we have a valid pointer
if (l3PhysRes == 0) {
// cout << " Didn't find an L3PhsyicsResults object." <<endl;
}
else {
l3string theName = l3PhysRes->get_name();
if (theName == "L3MuonPhysicsResults") {
// cast the generic L3PhysicsResults pointer to the specific L3MuonPhysicsResults class
L3MuonPhysicsResults * l3muon = dynamic_cast<L3MuonPhysicsResults*>(l3PhysRes);
// if there was a problem, we'll get a null pointer
if (l3muon == 0) {
cout << "l3muon == 0" <<endl;
}
else {
const LorentzVector *kine = l3muon->get_kineResults();
float pxxx= kine->getX();
float pyyy= kine->getY();
float pzzz= kine->getZ();
float quality = float(l3muon->get_quality());
etc. etc. etc.
Daniela Bauer
Last modified: Wed Jan 7 18:57:36 CST 2004